summaryrefslogtreecommitdiff
path: root/framework
diff options
context:
space:
mode:
Diffstat (limited to 'framework')
-rw-r--r--framework/3rdParty/PhpShell/PHP/Shell.php2182
-rw-r--r--framework/3rdParty/PhpShell/php-shell-init.php174
-rw-r--r--framework/3rdParty/SafeHtml/HTMLSax3.php1388
-rw-r--r--framework/3rdParty/SafeHtml/HTMLSax3/Decorators.php724
-rw-r--r--framework/3rdParty/SafeHtml/HTMLSax3/States.php574
-rw-r--r--framework/3rdParty/SafeHtml/TSafeHtmlParser.php1344
-rw-r--r--framework/3rdParty/TextHighlighter/Text/Highlighter.php792
-rw-r--r--framework/3rdParty/TextHighlighter/Text/Highlighter/ABAP.php98
-rw-r--r--framework/3rdParty/TextHighlighter/Text/Highlighter/CPP.php90
-rw-r--r--framework/3rdParty/TextHighlighter/Text/Highlighter/CSS.php90
-rw-r--r--framework/3rdParty/TextHighlighter/Text/Highlighter/DIFF.php90
-rw-r--r--framework/3rdParty/TextHighlighter/Text/Highlighter/DTD.php90
-rw-r--r--framework/3rdParty/TextHighlighter/Text/Highlighter/Generator.php2508
-rw-r--r--framework/3rdParty/TextHighlighter/Text/Highlighter/HTML.php98
-rw-r--r--framework/3rdParty/TextHighlighter/Text/Highlighter/JAVA.php90
-rw-r--r--framework/3rdParty/TextHighlighter/Text/Highlighter/JAVASCRIPT.php90
-rw-r--r--framework/3rdParty/TextHighlighter/Text/Highlighter/MYSQL.php90
-rw-r--r--framework/3rdParty/TextHighlighter/Text/Highlighter/PERL.php90
-rw-r--r--framework/3rdParty/TextHighlighter/Text/Highlighter/PHP.php2176
-rw-r--r--framework/3rdParty/TextHighlighter/Text/Highlighter/PRADO.php506
-rw-r--r--framework/3rdParty/TextHighlighter/Text/Highlighter/PYTHON.php90
-rw-r--r--framework/3rdParty/TextHighlighter/Text/Highlighter/RUBY.php90
-rw-r--r--framework/3rdParty/TextHighlighter/Text/Highlighter/Renderer.php302
-rw-r--r--framework/3rdParty/TextHighlighter/Text/Highlighter/Renderer/Array.php396
-rw-r--r--framework/3rdParty/TextHighlighter/Text/Highlighter/Renderer/BB.php474
-rw-r--r--framework/3rdParty/TextHighlighter/Text/Highlighter/Renderer/Console.php414
-rw-r--r--framework/3rdParty/TextHighlighter/Text/Highlighter/Renderer/Html.php890
-rw-r--r--framework/3rdParty/TextHighlighter/Text/Highlighter/Renderer/HtmlTags.php372
-rw-r--r--framework/3rdParty/TextHighlighter/Text/Highlighter/Renderer/JSON.php170
-rw-r--r--framework/3rdParty/TextHighlighter/Text/Highlighter/Renderer/XML.php204
-rw-r--r--framework/3rdParty/TextHighlighter/Text/Highlighter/SQL.php90
-rw-r--r--framework/3rdParty/TextHighlighter/Text/Highlighter/XML.php90
-rw-r--r--framework/Caching/TAPCCache.php266
-rw-r--r--framework/Caching/TCache.php1440
-rw-r--r--framework/Caching/TDbCache.php1156
-rw-r--r--framework/Caching/TSqliteCache.php448
-rw-r--r--framework/Caching/TXCache.php262
-rw-r--r--framework/Collections/TAttributeCollection.php342
-rw-r--r--framework/Collections/TDummyDataSource.php290
-rw-r--r--framework/Collections/TList.php972
-rw-r--r--framework/Collections/TListItemCollection.php328
-rw-r--r--framework/Collections/TMap.php704
-rw-r--r--framework/Collections/TPagedDataSource.php890
-rw-r--r--framework/Collections/TPagedList.php952
-rw-r--r--framework/Collections/TPriorityList.php1486
-rw-r--r--framework/Collections/TQueue.php526
-rw-r--r--framework/Collections/TStack.php524
-rw-r--r--framework/Data/ActiveRecord/Exceptions/TActiveRecordException.php98
-rw-r--r--framework/Data/ActiveRecord/Relations/TActiveRecordBelongsTo.php274
-rw-r--r--framework/Data/ActiveRecord/Relations/TActiveRecordHasMany.php240
-rw-r--r--framework/Data/ActiveRecord/Relations/TActiveRecordHasManyAssociation.php750
-rw-r--r--framework/Data/ActiveRecord/Relations/TActiveRecordHasOne.php288
-rw-r--r--framework/Data/ActiveRecord/Relations/TActiveRecordRelation.php508
-rw-r--r--framework/Data/ActiveRecord/Relations/TActiveRecordRelationContext.php458
-rw-r--r--framework/Data/ActiveRecord/Scaffold/TScaffoldBase.php414
-rw-r--r--framework/Data/ActiveRecord/Scaffold/TScaffoldEditView.php616
-rw-r--r--framework/Data/ActiveRecord/Scaffold/TScaffoldListView.php608
-rw-r--r--framework/Data/ActiveRecord/Scaffold/TScaffoldSearch.php296
-rw-r--r--framework/Data/ActiveRecord/Scaffold/TScaffoldView.php286
-rw-r--r--framework/Data/ActiveRecord/TActiveRecordConfig.php400
-rw-r--r--framework/Data/ActiveRecord/TActiveRecordCriteria.php72
-rw-r--r--framework/Data/ActiveRecord/TActiveRecordManager.php324
-rw-r--r--framework/Data/Common/Mssql/TMssqlCommandBuilder.php346
-rw-r--r--framework/Data/Common/Mssql/TMssqlTableColumn.php126
-rw-r--r--framework/Data/Common/Mssql/TMssqlTableInfo.php126
-rw-r--r--framework/Data/Common/Mysql/TMysqlCommandBuilder.php50
-rw-r--r--framework/Data/Common/Mysql/TMysqlMetaData.php772
-rw-r--r--framework/Data/Common/Mysql/TMysqlTableColumn.php142
-rw-r--r--framework/Data/Common/Mysql/TMysqlTableInfo.php116
-rw-r--r--framework/Data/Common/Pgsql/TPgsqlCommandBuilder.php136
-rw-r--r--framework/Data/Common/Pgsql/TPgsqlMetaData.php844
-rw-r--r--framework/Data/Common/Pgsql/TPgsqlTableColumn.php92
-rw-r--r--framework/Data/Common/Pgsql/TPgsqlTableInfo.php110
-rw-r--r--framework/Data/Common/Sqlite/TSqliteCommandBuilder.php92
-rw-r--r--framework/Data/Common/Sqlite/TSqliteMetaData.php420
-rw-r--r--framework/Data/Common/Sqlite/TSqliteTableColumn.php126
-rw-r--r--framework/Data/Common/Sqlite/TSqliteTableInfo.php92
-rw-r--r--framework/Data/Common/TDbCommandBuilder.php1014
-rw-r--r--framework/Data/Common/TDbMetaData.php364
-rw-r--r--framework/Data/Common/TDbTableColumn.php396
-rw-r--r--framework/Data/Common/TDbTableInfo.php310
-rw-r--r--framework/Data/DataGateway/TDataGatewayCommand.php1082
-rw-r--r--framework/Data/DataGateway/TSqlCriteria.php566
-rw-r--r--framework/Data/DataGateway/TTableGateway.php948
-rw-r--r--framework/Data/SqlMap/Configuration/TDiscriminator.php462
-rw-r--r--framework/Data/SqlMap/Configuration/TInlineParameterMapParser.php156
-rw-r--r--framework/Data/SqlMap/Configuration/TParameterMap.php420
-rw-r--r--framework/Data/SqlMap/Configuration/TParameterProperty.php298
-rw-r--r--framework/Data/SqlMap/Configuration/TResultMap.php400
-rw-r--r--framework/Data/SqlMap/Configuration/TResultProperty.php688
-rw-r--r--framework/Data/SqlMap/Configuration/TSimpleDynamicParser.php88
-rw-r--r--framework/Data/SqlMap/Configuration/TSqlMapCacheModel.php492
-rw-r--r--framework/Data/SqlMap/Configuration/TSqlMapStatement.php902
-rw-r--r--framework/Data/SqlMap/Configuration/TSqlMapXmlConfiguration.php1610
-rw-r--r--framework/Data/SqlMap/DataMapper/TFastSqlMapApplicationCache.php178
-rw-r--r--framework/Data/SqlMap/DataMapper/TLazyLoadList.php286
-rw-r--r--framework/Data/SqlMap/DataMapper/TPropertyAccess.php312
-rw-r--r--framework/Data/SqlMap/DataMapper/TSqlMapCache.php590
-rw-r--r--framework/Data/SqlMap/DataMapper/TSqlMapException.php230
-rw-r--r--framework/Data/SqlMap/DataMapper/TSqlMapPagedList.php416
-rw-r--r--framework/Data/SqlMap/DataMapper/TSqlMapTypeHandlerRegistry.php382
-rw-r--r--framework/Data/SqlMap/Statements/IMappedStatement.php164
-rw-r--r--framework/Data/SqlMap/Statements/TCachingStatement.php216
-rw-r--r--framework/Data/SqlMap/Statements/TDeleteMappedStatement.php46
-rw-r--r--framework/Data/SqlMap/Statements/TInsertMappedStatement.php96
-rw-r--r--framework/Data/SqlMap/Statements/TMappedStatement.php2484
-rw-r--r--framework/Data/SqlMap/Statements/TPreparedCommand.php132
-rw-r--r--framework/Data/SqlMap/Statements/TPreparedStatement.php112
-rw-r--r--framework/Data/SqlMap/Statements/TPreparedStatementFactory.php98
-rw-r--r--framework/Data/SqlMap/Statements/TSelectMappedStatement.php70
-rw-r--r--framework/Data/SqlMap/Statements/TSimpleDynamicSql.php78
-rw-r--r--framework/Data/SqlMap/Statements/TStaticSql.php70
-rw-r--r--framework/Data/SqlMap/Statements/TUpdateMappedStatement.php96
-rw-r--r--framework/Data/SqlMap/TSqlMapConfig.php360
-rw-r--r--framework/Data/SqlMap/TSqlMapGateway.php516
-rw-r--r--framework/Data/SqlMap/TSqlMapManager.php546
-rw-r--r--framework/Data/TDataSourceConfig.php334
-rw-r--r--framework/Data/TDbCommand.php616
-rw-r--r--framework/Data/TDbConnection.php1366
-rw-r--r--framework/Data/TDbDataReader.php448
-rw-r--r--framework/Data/TDbTransaction.php222
-rw-r--r--framework/Exceptions/TErrorHandler.php826
-rw-r--r--framework/Exceptions/TException.php832
-rw-r--r--framework/I18N/TChoiceFormat.php220
-rw-r--r--framework/I18N/TDateFormat.php506
-rw-r--r--framework/I18N/TGlobalization.php598
-rw-r--r--framework/I18N/TGlobalizationAutoDetect.php96
-rw-r--r--framework/I18N/TI18NControl.php180
-rw-r--r--framework/I18N/TNumberFormat.php502
-rw-r--r--framework/I18N/TTranslate.php510
-rw-r--r--framework/I18N/TTranslateParameter.php236
-rw-r--r--framework/I18N/core/ChoiceFormat.php452
-rw-r--r--framework/I18N/core/CultureInfo.php1264
-rw-r--r--framework/I18N/core/DateFormat.php1304
-rw-r--r--framework/I18N/core/DateTimeFormatInfo.php1032
-rw-r--r--framework/I18N/core/Gettext/MO.php710
-rw-r--r--framework/I18N/core/Gettext/PO.php320
-rw-r--r--framework/I18N/core/Gettext/TGettext.php572
-rw-r--r--framework/I18N/core/HTTPNegotiator.php258
-rw-r--r--framework/I18N/core/IMessageSource.php244
-rw-r--r--framework/I18N/core/MessageCache.php342
-rw-r--r--framework/I18N/core/MessageFormat.php510
-rw-r--r--framework/I18N/core/MessageSource.php672
-rw-r--r--framework/I18N/core/MessageSource_Database.php646
-rw-r--r--framework/I18N/core/MessageSource_MySQL.php836
-rw-r--r--framework/I18N/core/MessageSource_SQLite.php708
-rw-r--r--framework/I18N/core/MessageSource_XLIFF.php1058
-rw-r--r--framework/I18N/core/MessageSource_gettext.php914
-rw-r--r--framework/I18N/core/NumberFormat.php612
-rw-r--r--framework/I18N/core/NumberFormatInfo.php1300
-rw-r--r--framework/I18N/core/TCache_Lite.php1258
-rw-r--r--framework/I18N/core/util.php374
-rw-r--r--framework/IO/TTarFileExtractor.php1146
-rw-r--r--framework/IO/TTextWriter.php116
-rw-r--r--framework/Security/IUserManager.php114
-rw-r--r--framework/Security/TAuthManager.php914
-rw-r--r--framework/Security/TAuthorizationRule.php590
-rw-r--r--framework/Security/TDbUserManager.php638
-rw-r--r--framework/Security/TUser.php442
-rw-r--r--framework/Security/TUserManager.php802
-rw-r--r--framework/TApplicationComponent.php234
-rw-r--r--framework/TModule.php110
-rw-r--r--framework/TShellApplication.php96
-rw-r--r--framework/Util/TDataFieldAccessor.php164
-rw-r--r--framework/Util/TDateTimeStamp.php1406
-rw-r--r--framework/Util/TLogRouter.php2414
-rw-r--r--framework/Util/TLogger.php472
-rw-r--r--framework/Util/TParameterModule.php346
-rw-r--r--framework/Util/TSimpleDateFormatter.php752
-rw-r--r--framework/Util/TVarDumper.php254
-rw-r--r--framework/Web/Javascripts/JSMin.php580
-rw-r--r--framework/Web/Javascripts/TJavaScript.php566
-rw-r--r--framework/Web/Javascripts/packages.php242
-rw-r--r--framework/Web/Javascripts/source/prado/activecontrols/activecontrols3.js820
-rwxr-xr-xframework/Web/Javascripts/source/prado/activecontrols/activedatepicker.js174
-rw-r--r--framework/Web/Javascripts/source/prado/activecontrols/ajax3.js2288
-rwxr-xr-xframework/Web/Javascripts/source/prado/activecontrols/dragdrop.js122
-rw-r--r--framework/Web/Javascripts/source/prado/activecontrols/inlineeditor.js602
-rw-r--r--framework/Web/Javascripts/source/prado/colorpicker/colorpicker.js1560
-rw-r--r--framework/Web/Javascripts/source/prado/controls/controls.js1034
-rw-r--r--framework/Web/Javascripts/source/prado/controls/htmlarea.js298
-rw-r--r--framework/Web/Javascripts/source/prado/controls/keyboard.js322
-rw-r--r--framework/Web/Javascripts/source/prado/controls/tabpanel.js120
-rw-r--r--framework/Web/Javascripts/source/prado/datepicker/datepicker.js1578
-rw-r--r--framework/Web/Javascripts/source/prado/logger/logger.js1506
-rw-r--r--framework/Web/Javascripts/source/prado/prado.js188
-rw-r--r--framework/Web/Javascripts/source/prado/ratings/ratings.js412
-rw-r--r--framework/Web/Javascripts/source/prado/scriptaculous-adapter.js2792
-rw-r--r--framework/Web/Javascripts/source/prado/validator/validation3.js3886
-rw-r--r--framework/Web/Services/TFeedService.php374
-rw-r--r--framework/Web/Services/TJsonService.php426
-rw-r--r--framework/Web/Services/TPageService.php1786
-rw-r--r--framework/Web/TAssetManager.php714
-rw-r--r--framework/Web/THttpResponse.php1438
-rw-r--r--framework/Web/THttpSession.php1460
-rw-r--r--framework/Web/THttpUtility.php124
-rw-r--r--framework/Web/TUrlManager.php280
-rw-r--r--framework/Web/TUrlMapping.php1768
-rw-r--r--framework/Web/UI/ActiveControls/TActiveButton.php264
-rwxr-xr-xframework/Web/UI/ActiveControls/TActiveClientScript.php164
-rw-r--r--framework/Web/UI/ActiveControls/TActiveControlAdapter.php1150
-rw-r--r--framework/Web/UI/ActiveControls/TActiveCustomValidator.php530
-rw-r--r--framework/Web/UI/ActiveControls/TActiveLabel.php2
-rw-r--r--framework/Web/UI/ActiveControls/TActivePageAdapter.php802
-rw-r--r--framework/Web/UI/ActiveControls/TActivePanel.php200
-rw-r--r--framework/Web/UI/ActiveControls/TActiveRatingList.php266
-rw-r--r--framework/Web/UI/ActiveControls/TActiveTextBox.php250
-rw-r--r--framework/Web/UI/ActiveControls/TAutoComplete.php880
-rw-r--r--framework/Web/UI/ActiveControls/TBaseActiveControl.php784
-rw-r--r--framework/Web/UI/ActiveControls/TCallback.php202
-rw-r--r--framework/Web/UI/ActiveControls/TCallbackClientScript.php1410
-rw-r--r--framework/Web/UI/ActiveControls/TCallbackClientSide.php644
-rw-r--r--framework/Web/UI/ActiveControls/TCallbackEventParameter.php174
-rw-r--r--framework/Web/UI/ActiveControls/TCallbackOptions.php106
-rw-r--r--framework/Web/UI/ActiveControls/TEventTriggeredCallback.php190
-rw-r--r--framework/Web/UI/ActiveControls/TInPlaceTextBox.php580
-rw-r--r--framework/Web/UI/ActiveControls/TTriggeredCallback.php142
-rw-r--r--framework/Web/UI/ActiveControls/TValueTriggeredCallback.php240
-rw-r--r--framework/Web/UI/TCachePageStatePersister.php400
-rw-r--r--framework/Web/UI/TCompositeControl.php74
-rw-r--r--framework/Web/UI/TControl.php4790
-rw-r--r--framework/Web/UI/TControlAdapter.php286
-rw-r--r--framework/Web/UI/TForm.php342
-rw-r--r--framework/Web/UI/THtmlWriter.php458
-rw-r--r--framework/Web/UI/TPage.php2682
-rw-r--r--framework/Web/UI/TPageStatePersister.php140
-rw-r--r--framework/Web/UI/TSessionPageStatePersister.php260
-rw-r--r--framework/Web/UI/TTemplateControl.php484
-rw-r--r--framework/Web/UI/TTemplateManager.php2150
-rw-r--r--framework/Web/UI/TThemeManager.php1034
-rw-r--r--framework/Web/UI/WebControls/TAccordion.php1488
-rw-r--r--framework/Web/UI/WebControls/TBaseDataList.php378
-rw-r--r--framework/Web/UI/WebControls/TBoundColumn.php498
-rw-r--r--framework/Web/UI/WebControls/TBulletedList.php982
-rw-r--r--framework/Web/UI/WebControls/TButton.php734
-rw-r--r--framework/Web/UI/WebControls/TButtonColumn.php554
-rw-r--r--framework/Web/UI/WebControls/TCaptcha.php990
-rw-r--r--framework/Web/UI/WebControls/TCaptchaValidator.php254
-rw-r--r--framework/Web/UI/WebControls/TCheckBox.php1026
-rw-r--r--framework/Web/UI/WebControls/TCheckBoxColumn.php244
-rw-r--r--framework/Web/UI/WebControls/TCheckBoxList.php998
-rw-r--r--framework/Web/UI/WebControls/TColorPicker.php580
-rw-r--r--framework/Web/UI/WebControls/TCompareValidator.php528
-rw-r--r--framework/Web/UI/WebControls/TConditional.php284
-rw-r--r--framework/Web/UI/WebControls/TContent.php92
-rw-r--r--framework/Web/UI/WebControls/TContentPlaceHolder.php94
-rw-r--r--framework/Web/UI/WebControls/TCustomValidator.php414
-rw-r--r--framework/Web/UI/WebControls/TDataBoundControl.php1174
-rw-r--r--framework/Web/UI/WebControls/TDataGrid.php4516
-rw-r--r--framework/Web/UI/WebControls/TDataGridColumn.php1134
-rw-r--r--framework/Web/UI/WebControls/TDataGridItemRenderer.php58
-rw-r--r--framework/Web/UI/WebControls/TDataGridPagerStyle.php510
-rw-r--r--framework/Web/UI/WebControls/TDataList.php3530
-rw-r--r--framework/Web/UI/WebControls/TDataListItemRenderer.php342
-rw-r--r--framework/Web/UI/WebControls/TDataRenderer.php102
-rw-r--r--framework/Web/UI/WebControls/TDataSourceControl.php234
-rw-r--r--framework/Web/UI/WebControls/TDataSourceView.php410
-rw-r--r--framework/Web/UI/WebControls/TDataTypeValidator.php280
-rw-r--r--framework/Web/UI/WebControls/TDatePicker.php1986
-rw-r--r--framework/Web/UI/WebControls/TDropDownList.php308
-rw-r--r--framework/Web/UI/WebControls/TDropDownListColumn.php640
-rw-r--r--framework/Web/UI/WebControls/TEditCommandColumn.php528
-rw-r--r--framework/Web/UI/WebControls/TEmailAddressValidator.php192
-rw-r--r--framework/Web/UI/WebControls/TExpression.php122
-rw-r--r--framework/Web/UI/WebControls/TFileUpload.php562
-rw-r--r--framework/Web/UI/WebControls/TFlushOutput.php170
-rw-r--r--framework/Web/UI/WebControls/TFont.php634
-rw-r--r--framework/Web/UI/WebControls/THead.php754
-rw-r--r--framework/Web/UI/WebControls/THiddenField.php410
-rw-r--r--framework/Web/UI/WebControls/THtmlElement.php136
-rw-r--r--framework/Web/UI/WebControls/THyperLink.php454
-rw-r--r--framework/Web/UI/WebControls/THyperLinkColumn.php546
-rw-r--r--framework/Web/UI/WebControls/TImage.php312
-rw-r--r--framework/Web/UI/WebControls/TImageButton.php882
-rw-r--r--framework/Web/UI/WebControls/TImageMap.php1672
-rw-r--r--framework/Web/UI/WebControls/TItemDataRenderer.php164
-rw-r--r--framework/Web/UI/WebControls/TJavascriptLogger.php186
-rw-r--r--framework/Web/UI/WebControls/TKeyboard.php378
-rw-r--r--framework/Web/UI/WebControls/TLabel.php306
-rw-r--r--framework/Web/UI/WebControls/TLinkButton.php666
-rw-r--r--framework/Web/UI/WebControls/TListBox.php486
-rw-r--r--framework/Web/UI/WebControls/TListControl.php1846
-rw-r--r--framework/Web/UI/WebControls/TListControlValidator.php448
-rw-r--r--framework/Web/UI/WebControls/TListItem.php366
-rw-r--r--framework/Web/UI/WebControls/TLiteral.php222
-rw-r--r--framework/Web/UI/WebControls/TLiteralColumn.php306
-rw-r--r--framework/Web/UI/WebControls/TMarkdown.php148
-rw-r--r--framework/Web/UI/WebControls/TMultiView.php756
-rw-r--r--framework/Web/UI/WebControls/TOutputCache.php1240
-rw-r--r--framework/Web/UI/WebControls/TPager.php1582
-rw-r--r--framework/Web/UI/WebControls/TPanel.php492
-rw-r--r--framework/Web/UI/WebControls/TPanelStyle.php554
-rw-r--r--framework/Web/UI/WebControls/TPlaceHolder.php54
-rw-r--r--framework/Web/UI/WebControls/TRadioButton.php638
-rw-r--r--framework/Web/UI/WebControls/TRangeValidator.php716
-rw-r--r--framework/Web/UI/WebControls/TRatingList.php718
-rw-r--r--framework/Web/UI/WebControls/TReCaptcha.php464
-rw-r--r--framework/Web/UI/WebControls/TReCaptchaValidator.php244
-rw-r--r--framework/Web/UI/WebControls/TRegularExpressionValidator.php288
-rw-r--r--framework/Web/UI/WebControls/TRepeatInfo.php1118
-rw-r--r--framework/Web/UI/WebControls/TRepeater.php2048
-rw-r--r--framework/Web/UI/WebControls/TRepeaterItemRenderer.php98
-rw-r--r--framework/Web/UI/WebControls/TRequiredFieldValidator.php274
-rw-r--r--framework/Web/UI/WebControls/TSafeHtml.php170
-rw-r--r--framework/Web/UI/WebControls/TSlider.php1148
-rw-r--r--framework/Web/UI/WebControls/TStatements.php124
-rw-r--r--framework/Web/UI/WebControls/TStyle.php1786
-rw-r--r--framework/Web/UI/WebControls/TTable.php818
-rw-r--r--framework/Web/UI/WebControls/TTableCell.php442
-rw-r--r--framework/Web/UI/WebControls/TTableFooterRow.php92
-rw-r--r--framework/Web/UI/WebControls/TTableHeaderCell.php246
-rw-r--r--framework/Web/UI/WebControls/TTableHeaderRow.php92
-rw-r--r--framework/Web/UI/WebControls/TTableRow.php414
-rw-r--r--framework/Web/UI/WebControls/TTemplateColumn.php510
-rw-r--r--framework/Web/UI/WebControls/TTextBox.php1304
-rw-r--r--framework/Web/UI/WebControls/TTextProcessor.php170
-rw-r--r--framework/Web/UI/WebControls/TValidationSummary.php1072
-rw-r--r--framework/Web/UI/WebControls/TWebControlAdapter.php140
-rw-r--r--framework/Web/UI/WebControls/TWizard.php4290
-rw-r--r--framework/Web/UI/WebControls/TWizardNavigationButtonStyle.php308
-rw-r--r--framework/Web/UI/WebControls/assets/captcha.php448
-rw-r--r--framework/interfaces.php760
-rw-r--r--framework/prado.php132
323 files changed, 100892 insertions, 100892 deletions
diff --git a/framework/3rdParty/PhpShell/PHP/Shell.php b/framework/3rdParty/PhpShell/PHP/Shell.php
index bf8c86c3..8012475e 100644
--- a/framework/3rdParty/PhpShell/PHP/Shell.php
+++ b/framework/3rdParty/PhpShell/PHP/Shell.php
@@ -1,1091 +1,1091 @@
-<?php
-/* vim: set expandtab tabstop=4 shiftwidth=4 softtabstop=4: */
-
-/*
-(c) 2006 Jan Kneschke <jan@kneschke.de>
-
-Permission is hereby granted, free of charge, to any person obtaining a copy of
-this software and associated documentation files (the "Software"), to deal in
-the Software without restriction, including without limitation the rights to
-use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies
-of the Software, and to permit persons to whom the Software is furnished to do
-so, subject to the following conditions:
-
-The above copyright notice and this permission notice shall be included in all
-copies or substantial portions of the Software.
-
-THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
-IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
-FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
-AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
-LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
-OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
-SOFTWARE.
-*/
-
-/**
-* A interactive PHP Shell
-*
-* The more I work with other languages like python and ruby I like their way how they
-* work on problems. While PHP is very forgiving on errors, it is weak on the debugging
-* side. It was missing a simple to use interactive shell for years. Python and Ruby have
-* their ipython and iruby shell which give you a direct way to interact with the objects.
-* No need to write a script and execute it afterwards.
-*
-* Starting the Shell:
-*
-* The package contains a shell wrapper for windows and unix:
-* <pre>
-* sh> php-shell.sh
-* win> php-shell
-* </pre>
-*
-* Both are calling the wrapper script <code>php -q php-shell-cmd.php</code>
-*
-* Inline Help
-*
-* <pre>
-* PHP-Shell - Version 0.2.0, with readline() support
-* (c) 2006, Jan Kneschke <jan@kneschke.de>
-*
-* >> use '?' to open the inline help
-*
-* >> ?
-* "inline help for the PHP-shell
-*
-* >> ?
-* print this help
-* >> ? <topic>
-* get the doccomment for a class, method, property or function
-* >> p <var>
-* execute a verbose print (if implemented)
-* >> quit
-* leave shell
-* "
-* >> ? PHP_Shell
-* </pre>
-* Alternatives
-*
-* - http://david.acz.org/phpa/
-* - http://www.hping.org/phpinteractive/
-* - the embedded interactive php-shell: $ php -a
-*
-* @package PHP
-*/
-
-/**
-* PHP_Shell
-*
-* a interactive PHP Shell with tab-completion and history
-* it can catch FATAL errors before executing the code
-*
-* Extensions are provided through three side-classes:
-*
-* - PHP_Shell_Commands
-* - PHP_Shell_Options
-* - PHP_Shell_Extensions
-*
-* @package PHP
-*/
-
-require_once(dirname(__FILE__)."/Shell/Commands.php");
-require_once(dirname(__FILE__)."/Shell/Options.php"); /* for the tab-complete */
-
-class PHP_Shell {
- /**
- * current code-buffer
- * @var string
- */
- protected $code;
-
- /**
- * set if readline support is enabled
- * @var bool
- */
- protected $have_readline;
-
- /**
- * current version of the class
- * @var string
- */
- protected $version = '0.3.1';
-
- /**
- *
- */
- protected $stdin;
-
- protected $code_buffer;
-
- public $has_semicolon=false;
-
- /**
- * init the shell and change if readline support is available
- */
- public function __construct() {
- $this->code = '';
-
- $this->stdin = null;
-
- $this->have_readline = function_exists('readline');
-
- if ($this->have_readline) {
- readline_completion_function('__shell_readline_complete');
- }
-
- $this->use_readline = true;
-
- $cmd = PHP_Shell_Commands::getInstance();
-
- $cmd->registerCommand('#^quit$#', $this, 'cmdQuit', 'quit', 'leaves the shell');
- $cmd->registerCommand('#^\?$#', $this, 'cmdHelp', '?', 'show this help');
- $cmd->registerCommand('#^\?\s+license$#', $this, 'cmdLicense', '? license', 'show license of the shell');
- }
-
-
- /**
- * parse the PHP code
- *
- * we parse before we eval() the code to
- * - fetch fatal errors before they come up
- * - know about where we have to wait for closing braces
- *
- * @return int 0 if a executable statement is in the code-buffer, non-zero otherwise
- */
- public function parse() {
- ## remove empty lines
- if (trim($this->code) == '') return 1;
-
- $t = token_get_all('<?php '.$this->code.' ?>');
-
- $need_semicolon = 1; /* do we need a semicolon to complete the statement ? */
- $need_return = 1; /* can we prepend a return to the eval-string ? */
- $open_comment = 0; /* a open multi-line comment */
- $eval = ''; /* code to be eval()'ed later */
- $braces = array(); /* to track if we need more closing braces */
-
- $methods = array(); /* to track duplicate methods in a class declaration */
- $ts = array(); /* tokens without whitespaces */
-
- foreach ($t as $ndx => $token) {
- if (is_array($token)) {
- $ignore = 0;
-
- switch($token[0]) {
- case T_WHITESPACE:
- case T_OPEN_TAG:
- case T_CLOSE_TAG:
- $ignore = 1;
- break;
- case T_FOREACH:
- case T_DO:
- case T_WHILE:
- case T_FOR:
-
- case T_IF:
- case T_RETURN:
-
- case T_CLASS:
- case T_FUNCTION:
- case T_INTERFACE:
-
- case T_PRINT:
- case T_ECHO:
-
- case T_COMMENT:
- case T_UNSET:
-
- case T_INCLUDE:
- case T_REQUIRE:
- case T_INCLUDE_ONCE:
- case T_REQUIRE_ONCE:
- case T_TRY:
- case T_SWITCH:
- case T_DEFAULT:
- case T_CASE:
- case T_BREAK:
- case T_DOC_COMMENT:
- $need_return = 0;
- break;
- case T_EMPTY:
- case T_ISSET:
- case T_EVAL:
- case T_EXIT:
-
- case T_VARIABLE:
- case T_STRING:
- case T_NEW:
- case T_EXTENDS:
- case T_IMPLEMENTS:
- case T_OBJECT_OPERATOR:
- case T_DOUBLE_COLON:
- case T_INSTANCEOF:
-
- case T_CATCH:
- case T_THROW:
-
- case T_ELSE:
- case T_AS:
- case T_LNUMBER:
- case T_DNUMBER:
- case T_CONSTANT_ENCAPSED_STRING:
- case T_ENCAPSED_AND_WHITESPACE:
- case T_CHARACTER:
- case T_ARRAY:
- case T_DOUBLE_ARROW:
-
- case T_CONST:
- case T_PUBLIC:
- case T_PROTECTED:
- case T_PRIVATE:
- case T_ABSTRACT:
- case T_STATIC:
- case T_VAR:
-
- case T_INC:
- case T_DEC:
- case T_SL:
- case T_SL_EQUAL:
- case T_SR:
- case T_SR_EQUAL:
-
- case T_IS_EQUAL:
- case T_IS_IDENTICAL:
- case T_IS_GREATER_OR_EQUAL:
- case T_IS_SMALLER_OR_EQUAL:
-
- case T_BOOLEAN_OR:
- case T_LOGICAL_OR:
- case T_BOOLEAN_AND:
- case T_LOGICAL_AND:
- case T_LOGICAL_XOR:
- case T_MINUS_EQUAL:
- case T_PLUS_EQUAL:
- case T_MUL_EQUAL:
- case T_DIV_EQUAL:
- case T_MOD_EQUAL:
- case T_XOR_EQUAL:
- case T_AND_EQUAL:
- case T_OR_EQUAL:
-
- case T_FUNC_C:
- case T_CLASS_C:
- case T_LINE:
- case T_FILE:
-
- case T_BOOL_CAST:
- case T_INT_CAST:
- case T_STRING_CAST:
-
- /* just go on */
- break;
- default:
- /* debug unknown tags*/
- error_log(sprintf("unknown tag: %d (%s): %s".PHP_EOL, $token[0], token_name($token[0]), $token[1]));
-
- break;
- }
- if (!$ignore) {
- $eval .= $token[1]." ";
- $ts[] = array("token" => $token[0], "value" => $token[1]);
- }
- } else {
- $ts[] = array("token" => $token, "value" => '');
-
- $last = count($ts) - 1;
-
- switch ($token) {
- case '(':
- /* walk backwards through the tokens */
-
- if ($last >= 4 &&
- $ts[$last - 1]['token'] == T_STRING &&
- $ts[$last - 2]['token'] == T_OBJECT_OPERATOR &&
- $ts[$last - 3]['token'] == ')' ) {
- /* func()->method()
- *
- * we can't know what func() is return, so we can't
- * say if the method() exists or not
- *
- */
- } else if ($last >= 3 &&
- $ts[0]['token'] != T_CLASS && /* if we are not in a class definition */
- $ts[0]['token'] != T_ABSTRACT && /* if we are not in a class definition */
- $ts[1]['token'] != T_CLASS && /* if we are not in a class definition */
- $ts[$last - 1]['token'] == T_STRING &&
- $ts[$last - 2]['token'] == T_OBJECT_OPERATOR &&
- $ts[$last - 3]['token'] == T_VARIABLE ) {
-
- /* $object->method( */
-
- /* catch (Exception $e) does not set $e in $GLOBALS[] */
- $in_catch = 0;
-
- foreach ($ts as $v) {
- if ($v['token'] == T_CATCH) {
- $in_catch = 1;
- }
- }
-
- if (!$in_catch) {
- /* $object has to exist and has to be a object */
- $objname = $ts[$last - 3]['value'];
-
- if (!isset($GLOBALS[ltrim($objname, '$')])) {
- throw new Exception(sprintf('Variable \'%s\' is not set', $objname));
- }
- $object = $GLOBALS[ltrim($objname, '$')];
-
- if (!is_object($object)) {
- throw new Exception(sprintf('Variable \'%s\' is not a class', $objname));
- }
-
- $method = $ts[$last - 1]['value'];
-
- /* obj */
-
- if (!method_exists($object, $method)) {
- throw new Exception(sprintf("Variable %s (Class '%s') doesn't have a method named '%s'",
- $objname, get_class($object), $method));
- }
- }
- } else if ($last >= 3 &&
- $ts[0]['token'] != T_CLASS && /* if we are not in a class definition */
- $ts[$last - 1]['token'] == T_VARIABLE &&
- $ts[$last - 2]['token'] == T_OBJECT_OPERATOR &&
- $ts[$last - 3]['token'] == T_VARIABLE ) {
-
- /* $object->$method( */
-
- /* $object has to exist and has to be a object */
- $objname = $ts[$last - 3]['value'];
-
- if (!isset($GLOBALS[ltrim($objname, '$')])) {
- throw new Exception(sprintf('Variable \'%s\' is not set', $objname));
- }
- $object = $GLOBALS[ltrim($objname, '$')];
-
- if (!is_object($object)) {
- throw new Exception(sprintf('Variable \'%s\' is not a class', $objname));
- }
-
- $methodname = $ts[$last - 1]['value'];
-
- if (!isset($GLOBALS[ltrim($methodname, '$')])) {
- throw new Exception(sprintf('Variable \'%s\' is not set', $methodname));
- }
- $method = $GLOBALS[ltrim($methodname, '$')];
-
- /* obj */
-
- if (!method_exists($object, $method)) {
- throw new Exception(sprintf("Variable %s (Class '%s') doesn't have a method named '%s'",
- $objname, get_class($object), $method));
- }
-
- } else if ($last >= 6 &&
- $ts[0]['token'] != T_CLASS && /* if we are not in a class definition */
- $ts[$last - 1]['token'] == T_STRING &&
- $ts[$last - 2]['token'] == T_OBJECT_OPERATOR &&
- $ts[$last - 3]['token'] == ']' &&
- /* might be anything as index */
- $ts[$last - 5]['token'] == '[' &&
- $ts[$last - 6]['token'] == T_VARIABLE ) {
-
- /* $object[...]->method( */
-
- /* $object has to exist and has to be a object */
- $objname = $ts[$last - 6]['value'];
-
- if (!isset($GLOBALS[ltrim($objname, '$')])) {
- throw new Exception(sprintf('Variable \'%s\' is not set', $objname));
- }
- $array = $GLOBALS[ltrim($objname, '$')];
-
- if (!is_array($array)) {
- throw new Exception(sprintf('Variable \'%s\' is not a array', $objname));
- }
-
- $andx = $ts[$last - 4]['value'];
-
- if (!isset($array[$andx])) {
- throw new Exception(sprintf('%s[\'%s\'] is not set', $objname, $andx));
- }
-
- $object = $array[$andx];
-
- if (!is_object($object)) {
- throw new Exception(sprintf('Variable \'%s\' is not a class', $objname));
- }
-
- $method = $ts[$last - 1]['value'];
-
- /* obj */
-
- if (!method_exists($object, $method)) {
- throw new Exception(sprintf("Variable %s (Class '%s') doesn't have a method named '%s'",
- $objname, get_class($object), $method));
- }
-
- } else if ($last >= 3 &&
- $ts[0]['token'] != T_CLASS && /* if we are not in a class definition */
- $ts[$last - 1]['token'] == T_STRING &&
- $ts[$last - 2]['token'] == T_DOUBLE_COLON &&
- $ts[$last - 3]['token'] == T_STRING ) {
-
- /* Class::method() */
-
- /* $object has to exist and has to be a object */
- $classname = $ts[$last - 3]['value'];
-
- if (!class_exists($classname)) {
- throw new Exception(sprintf('Class \'%s\' doesn\'t exist', $classname));
- }
-
- $method = $ts[$last - 1]['value'];
-
- if (!in_array($method, get_class_methods($classname))) {
- throw new Exception(sprintf("Class '%s' doesn't have a method named '%s'",
- $classname, $method));
- }
- } else if ($last >= 3 &&
- $ts[0]['token'] != T_CLASS && /* if we are not in a class definition */
- $ts[$last - 1]['token'] == T_VARIABLE &&
- $ts[$last - 2]['token'] == T_DOUBLE_COLON &&
- $ts[$last - 3]['token'] == T_STRING ) {
-
- /* $var::method() */
-
- /* $object has to exist and has to be a object */
- $classname = $ts[$last - 3]['value'];
-
- if (!class_exists($classname)) {
- throw new Exception(sprintf('Class \'%s\' doesn\'t exist', $classname));
- }
-
- $methodname = $ts[$last - 1]['value'];
-
- if (!isset($GLOBALS[ltrim($methodname, '$')])) {
- throw new Exception(sprintf('Variable \'%s\' is not set', $methodname));
- }
- $method = $GLOBALS[ltrim($methodname, '$')];
-
- if (!in_array($method, get_class_methods($classname))) {
- throw new Exception(sprintf("Class '%s' doesn't have a method named '%s'",
- $classname, $method));
- }
-
- } else if ($last >= 2 &&
- $ts[0]['token'] != T_CLASS && /* if we are not in a class definition */
- $ts[$last - 1]['token'] == T_STRING &&
- $ts[$last - 2]['token'] == T_NEW ) {
-
- /* new Class() */
-
- /* don't care about this in a class ... { ... } */
-
- $classname = $ts[$last - 1]['value'];
-
- if (!class_exists($classname)) {
- throw new Exception(sprintf('Class \'%s\' doesn\'t exist', $classname));
- }
-
- $r = new ReflectionClass($classname);
-
- if ($r->isAbstract()) {
- throw new Exception(sprintf("Can't instantiate abstract Class '%s'", $classname));
- }
-
- if (!$r->isInstantiable()) {
- throw new Exception(sprintf('Class \'%s\' can\'t be instantiated. Is the class abstract ?', $classname));
- }
-
- } else if ($last >= 2 &&
- $ts[0]['token'] != T_CLASS && /* if we are not in a class definition */
- $ts[$last - 1]['token'] == T_STRING &&
- $ts[$last - 2]['token'] == T_FUNCTION ) {
-
- /* make sure we are not a in class definition */
-
- /* function a() */
-
- $func = $ts[$last - 1]['value'];
-
- if (function_exists($func)) {
- throw new Exception(sprintf('Function \'%s\' is already defined', $func));
- }
- } else if ($last >= 4 &&
- $ts[0]['token'] == T_CLASS &&
- $ts[1]['token'] == T_STRING &&
- $ts[$last - 1]['token'] == T_STRING &&
- $ts[$last - 2]['token'] == T_FUNCTION ) {
-
- /* make sure we are not a in class definition */
-
- /* class a { .. function a() ... } */
-
- $func = $ts[$last - 1]['value'];
- $classname = $ts[1]['value'];
-
- if (isset($methods[$func])) {
- throw new Exception(sprintf("Can't redeclare method '%s' in Class '%s'", $func, $classname));
- }
-
- $methods[$func] = 1;
-
- } else if ($last >= 1 &&
- $ts[0]['token'] != T_CLASS && /* if we are not in a class definition */
- $ts[0]['token'] != T_ABSTRACT && /* if we are not in a class definition */
- $ts[1]['token'] != T_CLASS && /* if we are not in a class definition */
- $ts[$last - 1]['token'] == T_STRING ) {
- /* func() */
- $funcname = $ts[$last - 1]['value'];
-
- if (!function_exists($funcname)) {
- throw new Exception(sprintf("Function %s() doesn't exist", $funcname));
- }
- } else if ($last >= 1 &&
- $ts[0]['token'] != T_CLASS && /* if we are not in a class definition */
- $ts[$last - 1]['token'] == T_VARIABLE ) {
-
- /* $object has to exist and has to be a object */
- $funcname = $ts[$last - 1]['value'];
-
- if (!isset($GLOBALS[ltrim($funcname, '$')])) {
- throw new Exception(sprintf('Variable \'%s\' is not set', $funcname));
- }
- $func = $GLOBALS[ltrim($funcname, '$')];
-
- if (!function_exists($func)) {
- throw new Exception(sprintf("Function %s() doesn't exist", $func));
- }
-
- }
-
- array_push($braces, $token);
- break;
- case '{':
- $need_return = 0;
-
- if ($last >= 2 &&
- $ts[$last - 1]['token'] == T_STRING &&
- $ts[$last - 2]['token'] == T_CLASS ) {
-
- /* class name { */
-
- $classname = $ts[$last - 1]['value'];
-
- if (class_exists($classname, false)) {
- throw new Exception(sprintf("Class '%s' can't be redeclared", $classname));
- }
- } else if ($last >= 4 &&
- $ts[$last - 1]['token'] == T_STRING &&
- $ts[$last - 2]['token'] == T_EXTENDS &&
- $ts[$last - 3]['token'] == T_STRING &&
- $ts[$last - 4]['token'] == T_CLASS ) {
-
- /* class classname extends classname { */
-
- $classname = $ts[$last - 3]['value'];
- $extendsname = $ts[$last - 1]['value'];
-
- if (class_exists($classname, false)) {
- throw new Exception(sprintf("Class '%s' can't be redeclared",
- $classname));
- }
- if (!class_exists($extendsname, true)) {
- throw new Exception(sprintf("Can't extend '%s' ... from not existing Class '%s'",
- $classname, $extendsname));
- }
- } else if ($last >= 4 &&
- $ts[$last - 1]['token'] == T_STRING &&
- $ts[$last - 2]['token'] == T_IMPLEMENTS &&
- $ts[$last - 3]['token'] == T_STRING &&
- $ts[$last - 4]['token'] == T_CLASS ) {
-
- /* class name implements interface { */
-
- $classname = $ts[$last - 3]['value'];
- $implements = $ts[$last - 1]['value'];
-
- if (class_exists($classname, false)) {
- throw new Exception(sprintf("Class '%s' can't be redeclared",
- $classname));
- }
- if (!interface_exists($implements, false)) {
- throw new Exception(sprintf("Can't implement not existing Interface '%s' for Class '%s'",
- $implements, $classname));
- }
- }
-
- array_push($braces, $token);
- break;
- case '}':
- $need_return = 0;
- case ')':
- array_pop($braces);
- break;
- case '[':
- if ($ts[0]['token'] != T_CLASS && /* if we are not in a class definition */
- $ts[0]['token'] != T_ABSTRACT && /* if we are not in a class definition */
- $ts[1]['token'] != T_CLASS && /* if we are not in a class definition */
- $ts[$last - 1]['token'] == T_VARIABLE) {
- /* $a[] only works on array and string */
-
- /* $object has to exist and has to be a object */
- $objname = $ts[$last - 1]['value'];
-
- if (!isset($GLOBALS[ltrim($objname, '$')])) {
- throw new Exception(sprintf('Variable \'%s\' is not set', $objname));
- }
- $obj = $GLOBALS[ltrim($objname, '$')];
-
- if (is_object($obj)) {
- throw new Exception(sprintf('Objects (%s) don\'t support array access operators', $objname));
- }
- }
- break;
- }
-
- $eval .= $token;
- }
- }
-
- $last = count($ts) - 1;
- if ($last >= 2 &&
- $ts[$last - 0]['token'] == T_STRING &&
- $ts[$last - 1]['token'] == T_DOUBLE_COLON &&
- $ts[$last - 2]['token'] == T_STRING ) {
-
- /* Class::constant */
-
- /* $object has to exist and has to be a object */
- $classname = $ts[$last - 2]['value'];
-
- if (!class_exists($classname)) {
- throw new Exception(sprintf('Class \'%s\' doesn\'t exist', $classname));
- }
-
- $constname = $ts[$last - 0]['value'];
-
- $c = new ReflectionClass($classname);
- if (!$c->hasConstant($constname)) {
- throw new Exception(sprintf("Class '%s' doesn't have a constant named '%s'",
- $classname, $constname));
- }
- } else if ($last == 0 &&
- $ts[$last - 0]['token'] == T_VARIABLE ) {
-
- /* $var */
-
- $varname = $ts[$last - 0]['value'];
-
- if (!isset($GLOBALS[ltrim($varname, '$')])) {
- throw new Exception(sprintf('Variable \'%s\' is not set', $varname));
- }
- }
-
-
- $need_more = (count($braces) > 0) || $open_comment;
-
- if ($need_more || ';' === $token) {
- $need_semicolon = 0;
- }
-
- if ($need_return) {
- $eval = "return ".$eval;
- }
-
- /* add a traling ; if necessary */
- if ($need_semicolon)
- {
- $this->has_semicolon = preg_match('/;\s*$/', $eval);
- $eval .= ';';
- }
-
- if (!$need_more) {
- $this->code = $eval;
- }
-
- return $need_more;
- }
-
- /**
- * show the prompt and fetch a single line
- *
- * uses readline() if avaialbe
- *
- * @return string a input-line
- */
- public function readline() {
- if (empty($this->code)) print PHP_EOL;
-
- $prompt = (empty($this->code)) ? '>> ' : '.. ';
-
- if (count($this->code_buffer) > 0) {
- print $prompt;
-
- $line = array_shift($this->code_buffer);
-
- print $line.PHP_EOL;
-
- return $line.PHP_EOL;
- }
-
- if ($this->have_readline) {
- $l = readline($prompt);
-
- readline_add_history($l);
- } else {
- print $prompt;
-
- if (is_null($this->stdin)) {
- if (false === ($this->stdin = fopen("php://stdin", "r"))) {
- return false;
- }
- }
- $l = fgets($this->stdin);
- }
- return $l;
- }
-
- /**
- * get the inline help
- *
- * @return string the inline help as string
- */
- public function cmdHelp($l) {
- $o = 'Inline Help:'.PHP_EOL;
-
- $cmds = PHP_Shell_Commands::getInstance()->getCommands();
-
- $help = array();
- foreach ($cmds as $cmd) {
- $help[] = sprintf(' >> %s'.PHP_EOL.' %s'.PHP_EOL,
- $cmd['command'],
- $cmd['description']
- );
- }
-
- return var_export(implode("\n", $help), 1);
- }
-
- /**
- * get the license string
- *
- * @return string the inline help as string
- */
- public function cmdLicense($l) {
- $o = <<<EOF
-(c) 2006 Jan Kneschke <jan@kneschke.de>
-
-Permission is hereby granted, free of charge, to any person obtaining a copy of
-this software and associated documentation files (the "Software"), to deal in
-the Software without restriction, including without limitation the rights to
-use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies
-of the Software, and to permit persons to whom the Software is furnished to do
-so, subject to the following conditions:
-
-The above copyright notice and this permission notice shall be included in all
-copies or substantial portions of the Software.
-
-THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
-IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
-FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
-AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
-LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
-OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
-SOFTWARE.
-EOF;
-
- return var_export($o, 1);
- }
-
- /**
- * handle the 'quit' command
- *
- * @return bool false to leave the input() call
- * @see input
- */
- protected function cmdQuit($l) {
- return false;
- }
-
- /**
- * handle the input line
- *
- * read the input and handle the commands of the shell
- *
- * @return bool false on 'quit' or EOF, true otherwise
- */
- public function input() {
- $l = $this->readline();
-
- /* got EOF ? */
- if (false === $l) return false;
-
- $l = trim($l);
-
- if (empty($this->code)) {
- $this->verbose = 0;
-
- $cmds = PHP_Shell_Commands::getInstance()->getCommands();
-
- foreach ($cmds as $cmd) {
- if (preg_match($cmd['regex'], $l)) {
- $obj = $cmd['obj'];
- $func = $cmd['method'];
-
- if (false === ($l = $obj->$func($l))) {
- ## quit
- return false;
- }
-
- if (is_array($l)) {
- $this->code_buffer = $l;
- $l = '';
- }
- break;
- }
- }
- }
-
- $this->appendCode($l);
-
- return true;
- }
-
- /**
- * get the code-buffer
- *
- * @return string the code-buffer
- */
- public function getCode() {
- return $this->code;
- return $code;
- }
-
- /**
- * reset the code-buffer
- */
- public function resetCode() {
- $this->has_semicolon=false;
- $this->code = '';
- }
-
- /**
- * append code to the code-buffer
- *
- * @param string $code input buffer
- */
- public function appendCode($code) {
- if (strlen($code)) $code .= PHP_EOL;
-
- $this->code .= $code;
- }
-
- /**
- * check if readline support is enabled
- *
- * @return bool true if enabled, false otherwise
- */
- public function hasReadline() {
- return $this->have_readline;
- }
-
- /**
- * get version of the class
- *
- * @return string version-string
- */
- public function getVersion() {
- return $this->version;
- }
-}
-
-/**
-* a readline completion callback
-*
-* @param string $str linebuffer
-* @param integer $pos position in linebuffer
-* @return array list of possible matches
-*/
-function __shell_readline_complete($str, $pos) {
- $in = readline_info('line_buffer');
-
- /**
- * parse the line-buffer backwards to see if we have a
- * - constant
- * - function
- * - variable
- */
-
- $m = array();
-
- if (preg_match('#\$([A-Za-z0-9_]+)->#', $in, $a)) {
- /* check for $o->... */
- $name = $a[1];
-
- if (isset($GLOBALS[$name]) && is_object($GLOBALS[$name])) {
- $c = get_class_methods($GLOBALS[$name]);
-
- foreach ($c as $v) {
- $m[] = $v.'(';
- }
- $c = get_class_vars(get_class($GLOBALS[$name]));
-
- foreach ($c as $k => $v) {
- $m[] = $k;
- }
-
- return $m;
- }
- } else if (preg_match('#\$([A-Za-z0-9_]+)\[([^\]]+)\]->#', $in, $a)) {
- /* check for $o[...]->... */
- $name = $a[1];
-
- if (isset($GLOBALS[$name]) &&
- is_array($GLOBALS[$name]) &&
- isset($GLOBALS[$name][$a[2]])) {
-
- $c = get_class_methods($GLOBALS[$name][$a[2]]);
-
- foreach ($c as $v) {
- $m[] = $v.'(';
- }
- $c = get_class_vars(get_class($GLOBALS[$name][$a[2]]));
-
- foreach ($c as $k => $v) {
- $m[] = $k;
- }
- return $m;
- }
-
- } else if (preg_match('#([A-Za-z0-9_]+)::#', $in, $a)) {
- /* check for Class:: */
- $name = $a[1];
-
- if (class_exists($name, false)) {
- $c = get_class_methods($name);
-
- foreach ($c as $v) {
- $m[] = sprintf('%s::%s(', $name, $v);
- }
-
- $cl = new ReflectionClass($name);
- $c = $cl->getConstants();
-
- foreach ($c as $k => $v) {
- $m[] = sprintf('%s::%s', $name, $k);
- }
-
- return $m;
- }
- } else if (preg_match('#\$([a-zA-Z]?[a-zA-Z0-9_]*)$#', $in)) {
- $m = array_keys($GLOBALS);
-
- return $m;
- } else if (preg_match('#new #', $in)) {
- $c = get_declared_classes();
-
- foreach ($c as $v) {
- $m[] = $v.'(';
- }
-
- return $m;
- } else if (preg_match('#^:set #', $in)) {
- foreach (PHP_Shell_Options::getInstance()->getOptions() as $v) {
- $m[] = $v;
- }
-
- return $m;
- }
-
- $f = get_defined_functions();
-
- foreach ($f['internal'] as $v) {
- $m[] = $v.'(';
- }
-
- foreach ($f['user'] as $v) {
- $m[] = $v.'(';
- }
-
- $c = get_declared_classes();
-
- foreach ($c as $v) {
- $m[] = $v.'::';
- }
-
- $c = get_defined_constants();
-
- foreach ($c as $k => $v) {
- $m[] = $k;
- }
-
- /* taken from http://de3.php.net/manual/en/reserved.php */
- $m[] = 'abstract';
- $m[] = 'and';
- $m[] = 'array(';
- $m[] = 'as';
- $m[] = 'break';
- $m[] = 'case';
- $m[] = 'catch';
- $m[] = 'class';
- $m[] = 'const';
- $m[] = 'continue';
- # $m[] = 'declare';
- $m[] = 'default';
- $m[] = 'die(';
- $m[] = 'do';
- $m[] = 'echo(';
- $m[] = 'else';
- $m[] = 'elseif';
- $m[] = 'empty(';
- # $m[] = 'enddeclare';
- $m[] = 'eval(';
- $m[] = 'exception';
- $m[] = 'extends';
- $m[] = 'exit(';
- $m[] = 'extends';
- $m[] = 'final';
- $m[] = 'for (';
- $m[] = 'foreach (';
- $m[] = 'function';
- $m[] = 'global';
- $m[] = 'if';
- $m[] = 'implements';
- $m[] = 'include "';
- $m[] = 'include_once "';
- $m[] = 'interface';
- $m[] = 'isset(';
- $m[] = 'list(';
- $m[] = 'new';
- $m[] = 'or';
- $m[] = 'print(';
- $m[] = 'private';
- $m[] = 'protected';
- $m[] = 'public';
- $m[] = 'require "';
- $m[] = 'require_once "';
- $m[] = 'return';
- $m[] = 'static';
- $m[] = 'switch (';
- $m[] = 'throw';
- $m[] = 'try';
- $m[] = 'unset(';
- # $m[] = 'use';
- $m[] = 'var';
- $m[] = 'while';
- $m[] = 'xor';
- $m[] = '__FILE__';
- $m[] = '__FUNCTION__';
- $m[] = '__CLASS__';
- $m[] = '__LINE__';
- $m[] = '__METHOD__';
-
- # printf("%s ... %s\n", $str, $pos);
- return $m;
-}
-
-
+<?php
+/* vim: set expandtab tabstop=4 shiftwidth=4 softtabstop=4: */
+
+/*
+(c) 2006 Jan Kneschke <jan@kneschke.de>
+
+Permission is hereby granted, free of charge, to any person obtaining a copy of
+this software and associated documentation files (the "Software"), to deal in
+the Software without restriction, including without limitation the rights to
+use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies
+of the Software, and to permit persons to whom the Software is furnished to do
+so, subject to the following conditions:
+
+The above copyright notice and this permission notice shall be included in all
+copies or substantial portions of the Software.
+
+THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
+IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
+FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
+AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
+LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
+OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
+SOFTWARE.
+*/
+
+/**
+* A interactive PHP Shell
+*
+* The more I work with other languages like python and ruby I like their way how they
+* work on problems. While PHP is very forgiving on errors, it is weak on the debugging
+* side. It was missing a simple to use interactive shell for years. Python and Ruby have
+* their ipython and iruby shell which give you a direct way to interact with the objects.
+* No need to write a script and execute it afterwards.
+*
+* Starting the Shell:
+*
+* The package contains a shell wrapper for windows and unix:
+* <pre>
+* sh> php-shell.sh
+* win> php-shell
+* </pre>
+*
+* Both are calling the wrapper script <code>php -q php-shell-cmd.php</code>
+*
+* Inline Help
+*
+* <pre>
+* PHP-Shell - Version 0.2.0, with readline() support
+* (c) 2006, Jan Kneschke <jan@kneschke.de>
+*
+* >> use '?' to open the inline help
+*
+* >> ?
+* "inline help for the PHP-shell
+*
+* >> ?
+* print this help
+* >> ? <topic>
+* get the doccomment for a class, method, property or function
+* >> p <var>
+* execute a verbose print (if implemented)
+* >> quit
+* leave shell
+* "
+* >> ? PHP_Shell
+* </pre>
+* Alternatives
+*
+* - http://david.acz.org/phpa/
+* - http://www.hping.org/phpinteractive/
+* - the embedded interactive php-shell: $ php -a
+*
+* @package PHP
+*/
+
+/**
+* PHP_Shell
+*
+* a interactive PHP Shell with tab-completion and history
+* it can catch FATAL errors before executing the code
+*
+* Extensions are provided through three side-classes:
+*
+* - PHP_Shell_Commands
+* - PHP_Shell_Options
+* - PHP_Shell_Extensions
+*
+* @package PHP
+*/
+
+require_once(dirname(__FILE__)."/Shell/Commands.php");
+require_once(dirname(__FILE__)."/Shell/Options.php"); /* for the tab-complete */
+
+class PHP_Shell {
+ /**
+ * current code-buffer
+ * @var string
+ */
+ protected $code;
+
+ /**
+ * set if readline support is enabled
+ * @var bool
+ */
+ protected $have_readline;
+
+ /**
+ * current version of the class
+ * @var string
+ */
+ protected $version = '0.3.1';
+
+ /**
+ *
+ */
+ protected $stdin;
+
+ protected $code_buffer;
+
+ public $has_semicolon=false;
+
+ /**
+ * init the shell and change if readline support is available
+ */
+ public function __construct() {
+ $this->code = '';
+
+ $this->stdin = null;
+
+ $this->have_readline = function_exists('readline');
+
+ if ($this->have_readline) {
+ readline_completion_function('__shell_readline_complete');
+ }
+
+ $this->use_readline = true;
+
+ $cmd = PHP_Shell_Commands::getInstance();
+
+ $cmd->registerCommand('#^quit$#', $this, 'cmdQuit', 'quit', 'leaves the shell');
+ $cmd->registerCommand('#^\?$#', $this, 'cmdHelp', '?', 'show this help');
+ $cmd->registerCommand('#^\?\s+license$#', $this, 'cmdLicense', '? license', 'show license of the shell');
+ }
+
+
+ /**
+ * parse the PHP code
+ *
+ * we parse before we eval() the code to
+ * - fetch fatal errors before they come up
+ * - know about where we have to wait for closing braces
+ *
+ * @return int 0 if a executable statement is in the code-buffer, non-zero otherwise
+ */
+ public function parse() {
+ ## remove empty lines
+ if (trim($this->code) == '') return 1;
+
+ $t = token_get_all('<?php '.$this->code.' ?>');
+
+ $need_semicolon = 1; /* do we need a semicolon to complete the statement ? */
+ $need_return = 1; /* can we prepend a return to the eval-string ? */
+ $open_comment = 0; /* a open multi-line comment */
+ $eval = ''; /* code to be eval()'ed later */
+ $braces = array(); /* to track if we need more closing braces */
+
+ $methods = array(); /* to track duplicate methods in a class declaration */
+ $ts = array(); /* tokens without whitespaces */
+
+ foreach ($t as $ndx => $token) {
+ if (is_array($token)) {
+ $ignore = 0;
+
+ switch($token[0]) {
+ case T_WHITESPACE:
+ case T_OPEN_TAG:
+ case T_CLOSE_TAG:
+ $ignore = 1;
+ break;
+ case T_FOREACH:
+ case T_DO:
+ case T_WHILE:
+ case T_FOR:
+
+ case T_IF:
+ case T_RETURN:
+
+ case T_CLASS:
+ case T_FUNCTION:
+ case T_INTERFACE:
+
+ case T_PRINT:
+ case T_ECHO:
+
+ case T_COMMENT:
+ case T_UNSET:
+
+ case T_INCLUDE:
+ case T_REQUIRE:
+ case T_INCLUDE_ONCE:
+ case T_REQUIRE_ONCE:
+ case T_TRY:
+ case T_SWITCH:
+ case T_DEFAULT:
+ case T_CASE:
+ case T_BREAK:
+ case T_DOC_COMMENT:
+ $need_return = 0;
+ break;
+ case T_EMPTY:
+ case T_ISSET:
+ case T_EVAL:
+ case T_EXIT:
+
+ case T_VARIABLE:
+ case T_STRING:
+ case T_NEW:
+ case T_EXTENDS:
+ case T_IMPLEMENTS:
+ case T_OBJECT_OPERATOR:
+ case T_DOUBLE_COLON:
+ case T_INSTANCEOF:
+
+ case T_CATCH:
+ case T_THROW:
+
+ case T_ELSE:
+ case T_AS:
+ case T_LNUMBER:
+ case T_DNUMBER:
+ case T_CONSTANT_ENCAPSED_STRING:
+ case T_ENCAPSED_AND_WHITESPACE:
+ case T_CHARACTER:
+ case T_ARRAY:
+ case T_DOUBLE_ARROW:
+
+ case T_CONST:
+ case T_PUBLIC:
+ case T_PROTECTED:
+ case T_PRIVATE:
+ case T_ABSTRACT:
+ case T_STATIC:
+ case T_VAR:
+
+ case T_INC:
+ case T_DEC:
+ case T_SL:
+ case T_SL_EQUAL:
+ case T_SR:
+ case T_SR_EQUAL:
+
+ case T_IS_EQUAL:
+ case T_IS_IDENTICAL:
+ case T_IS_GREATER_OR_EQUAL:
+ case T_IS_SMALLER_OR_EQUAL:
+
+ case T_BOOLEAN_OR:
+ case T_LOGICAL_OR:
+ case T_BOOLEAN_AND:
+ case T_LOGICAL_AND:
+ case T_LOGICAL_XOR:
+ case T_MINUS_EQUAL:
+ case T_PLUS_EQUAL:
+ case T_MUL_EQUAL:
+ case T_DIV_EQUAL:
+ case T_MOD_EQUAL:
+ case T_XOR_EQUAL:
+ case T_AND_EQUAL:
+ case T_OR_EQUAL:
+
+ case T_FUNC_C:
+ case T_CLASS_C:
+ case T_LINE:
+ case T_FILE:
+
+ case T_BOOL_CAST:
+ case T_INT_CAST:
+ case T_STRING_CAST:
+
+ /* just go on */
+ break;
+ default:
+ /* debug unknown tags*/
+ error_log(sprintf("unknown tag: %d (%s): %s".PHP_EOL, $token[0], token_name($token[0]), $token[1]));
+
+ break;
+ }
+ if (!$ignore) {
+ $eval .= $token[1]." ";
+ $ts[] = array("token" => $token[0], "value" => $token[1]);
+ }
+ } else {
+ $ts[] = array("token" => $token, "value" => '');
+
+ $last = count($ts) - 1;
+
+ switch ($token) {
+ case '(':
+ /* walk backwards through the tokens */
+
+ if ($last >= 4 &&
+ $ts[$last - 1]['token'] == T_STRING &&
+ $ts[$last - 2]['token'] == T_OBJECT_OPERATOR &&
+ $ts[$last - 3]['token'] == ')' ) {
+ /* func()->method()
+ *
+ * we can't know what func() is return, so we can't
+ * say if the method() exists or not
+ *
+ */
+ } else if ($last >= 3 &&
+ $ts[0]['token'] != T_CLASS && /* if we are not in a class definition */
+ $ts[0]['token'] != T_ABSTRACT && /* if we are not in a class definition */
+ $ts[1]['token'] != T_CLASS && /* if we are not in a class definition */
+ $ts[$last - 1]['token'] == T_STRING &&
+ $ts[$last - 2]['token'] == T_OBJECT_OPERATOR &&
+ $ts[$last - 3]['token'] == T_VARIABLE ) {
+
+ /* $object->method( */
+
+ /* catch (Exception $e) does not set $e in $GLOBALS[] */
+ $in_catch = 0;
+
+ foreach ($ts as $v) {
+ if ($v['token'] == T_CATCH) {
+ $in_catch = 1;
+ }
+ }
+
+ if (!$in_catch) {
+ /* $object has to exist and has to be a object */
+ $objname = $ts[$last - 3]['value'];
+
+ if (!isset($GLOBALS[ltrim($objname, '$')])) {
+ throw new Exception(sprintf('Variable \'%s\' is not set', $objname));
+ }
+ $object = $GLOBALS[ltrim($objname, '$')];
+
+ if (!is_object($object)) {
+ throw new Exception(sprintf('Variable \'%s\' is not a class', $objname));
+ }
+
+ $method = $ts[$last - 1]['value'];
+
+ /* obj */
+
+ if (!method_exists($object, $method)) {
+ throw new Exception(sprintf("Variable %s (Class '%s') doesn't have a method named '%s'",
+ $objname, get_class($object), $method));
+ }
+ }
+ } else if ($last >= 3 &&
+ $ts[0]['token'] != T_CLASS && /* if we are not in a class definition */
+ $ts[$last - 1]['token'] == T_VARIABLE &&
+ $ts[$last - 2]['token'] == T_OBJECT_OPERATOR &&
+ $ts[$last - 3]['token'] == T_VARIABLE ) {
+
+ /* $object->$method( */
+
+ /* $object has to exist and has to be a object */
+ $objname = $ts[$last - 3]['value'];
+
+ if (!isset($GLOBALS[ltrim($objname, '$')])) {
+ throw new Exception(sprintf('Variable \'%s\' is not set', $objname));
+ }
+ $object = $GLOBALS[ltrim($objname, '$')];
+
+ if (!is_object($object)) {
+ throw new Exception(sprintf('Variable \'%s\' is not a class', $objname));
+ }
+
+ $methodname = $ts[$last - 1]['value'];
+
+ if (!isset($GLOBALS[ltrim($methodname, '$')])) {
+ throw new Exception(sprintf('Variable \'%s\' is not set', $methodname));
+ }
+ $method = $GLOBALS[ltrim($methodname, '$')];
+
+ /* obj */
+
+ if (!method_exists($object, $method)) {
+ throw new Exception(sprintf("Variable %s (Class '%s') doesn't have a method named '%s'",
+ $objname, get_class($object), $method));
+ }
+
+ } else if ($last >= 6 &&
+ $ts[0]['token'] != T_CLASS && /* if we are not in a class definition */
+ $ts[$last - 1]['token'] == T_STRING &&
+ $ts[$last - 2]['token'] == T_OBJECT_OPERATOR &&
+ $ts[$last - 3]['token'] == ']' &&
+ /* might be anything as index */
+ $ts[$last - 5]['token'] == '[' &&
+ $ts[$last - 6]['token'] == T_VARIABLE ) {
+
+ /* $object[...]->method( */
+
+ /* $object has to exist and has to be a object */
+ $objname = $ts[$last - 6]['value'];
+
+ if (!isset($GLOBALS[ltrim($objname, '$')])) {
+ throw new Exception(sprintf('Variable \'%s\' is not set', $objname));
+ }
+ $array = $GLOBALS[ltrim($objname, '$')];
+
+ if (!is_array($array)) {
+ throw new Exception(sprintf('Variable \'%s\' is not a array', $objname));
+ }
+
+ $andx = $ts[$last - 4]['value'];
+
+ if (!isset($array[$andx])) {
+ throw new Exception(sprintf('%s[\'%s\'] is not set', $objname, $andx));
+ }
+
+ $object = $array[$andx];
+
+ if (!is_object($object)) {
+ throw new Exception(sprintf('Variable \'%s\' is not a class', $objname));
+ }
+
+ $method = $ts[$last - 1]['value'];
+
+ /* obj */
+
+ if (!method_exists($object, $method)) {
+ throw new Exception(sprintf("Variable %s (Class '%s') doesn't have a method named '%s'",
+ $objname, get_class($object), $method));
+ }
+
+ } else if ($last >= 3 &&
+ $ts[0]['token'] != T_CLASS && /* if we are not in a class definition */
+ $ts[$last - 1]['token'] == T_STRING &&
+ $ts[$last - 2]['token'] == T_DOUBLE_COLON &&
+ $ts[$last - 3]['token'] == T_STRING ) {
+
+ /* Class::method() */
+
+ /* $object has to exist and has to be a object */
+ $classname = $ts[$last - 3]['value'];
+
+ if (!class_exists($classname)) {
+ throw new Exception(sprintf('Class \'%s\' doesn\'t exist', $classname));
+ }
+
+ $method = $ts[$last - 1]['value'];
+
+ if (!in_array($method, get_class_methods($classname))) {
+ throw new Exception(sprintf("Class '%s' doesn't have a method named '%s'",
+ $classname, $method));
+ }
+ } else if ($last >= 3 &&
+ $ts[0]['token'] != T_CLASS && /* if we are not in a class definition */
+ $ts[$last - 1]['token'] == T_VARIABLE &&
+ $ts[$last - 2]['token'] == T_DOUBLE_COLON &&
+ $ts[$last - 3]['token'] == T_STRING ) {
+
+ /* $var::method() */
+
+ /* $object has to exist and has to be a object */
+ $classname = $ts[$last - 3]['value'];
+
+ if (!class_exists($classname)) {
+ throw new Exception(sprintf('Class \'%s\' doesn\'t exist', $classname));
+ }
+
+ $methodname = $ts[$last - 1]['value'];
+
+ if (!isset($GLOBALS[ltrim($methodname, '$')])) {
+ throw new Exception(sprintf('Variable \'%s\' is not set', $methodname));
+ }
+ $method = $GLOBALS[ltrim($methodname, '$')];
+
+ if (!in_array($method, get_class_methods($classname))) {
+ throw new Exception(sprintf("Class '%s' doesn't have a method named '%s'",
+ $classname, $method));
+ }
+
+ } else if ($last >= 2 &&
+ $ts[0]['token'] != T_CLASS && /* if we are not in a class definition */
+ $ts[$last - 1]['token'] == T_STRING &&
+ $ts[$last - 2]['token'] == T_NEW ) {
+
+ /* new Class() */
+
+ /* don't care about this in a class ... { ... } */
+
+ $classname = $ts[$last - 1]['value'];
+
+ if (!class_exists($classname)) {
+ throw new Exception(sprintf('Class \'%s\' doesn\'t exist', $classname));
+ }
+
+ $r = new ReflectionClass($classname);
+
+ if ($r->isAbstract()) {
+ throw new Exception(sprintf("Can't instantiate abstract Class '%s'", $classname));
+ }
+
+ if (!$r->isInstantiable()) {
+ throw new Exception(sprintf('Class \'%s\' can\'t be instantiated. Is the class abstract ?', $classname));
+ }
+
+ } else if ($last >= 2 &&
+ $ts[0]['token'] != T_CLASS && /* if we are not in a class definition */
+ $ts[$last - 1]['token'] == T_STRING &&
+ $ts[$last - 2]['token'] == T_FUNCTION ) {
+
+ /* make sure we are not a in class definition */
+
+ /* function a() */
+
+ $func = $ts[$last - 1]['value'];
+
+ if (function_exists($func)) {
+ throw new Exception(sprintf('Function \'%s\' is already defined', $func));
+ }
+ } else if ($last >= 4 &&
+ $ts[0]['token'] == T_CLASS &&
+ $ts[1]['token'] == T_STRING &&
+ $ts[$last - 1]['token'] == T_STRING &&
+ $ts[$last - 2]['token'] == T_FUNCTION ) {
+
+ /* make sure we are not a in class definition */
+
+ /* class a { .. function a() ... } */
+
+ $func = $ts[$last - 1]['value'];
+ $classname = $ts[1]['value'];
+
+ if (isset($methods[$func])) {
+ throw new Exception(sprintf("Can't redeclare method '%s' in Class '%s'", $func, $classname));
+ }
+
+ $methods[$func] = 1;
+
+ } else if ($last >= 1 &&
+ $ts[0]['token'] != T_CLASS && /* if we are not in a class definition */
+ $ts[0]['token'] != T_ABSTRACT && /* if we are not in a class definition */
+ $ts[1]['token'] != T_CLASS && /* if we are not in a class definition */
+ $ts[$last - 1]['token'] == T_STRING ) {
+ /* func() */
+ $funcname = $ts[$last - 1]['value'];
+
+ if (!function_exists($funcname)) {
+ throw new Exception(sprintf("Function %s() doesn't exist", $funcname));
+ }
+ } else if ($last >= 1 &&
+ $ts[0]['token'] != T_CLASS && /* if we are not in a class definition */
+ $ts[$last - 1]['token'] == T_VARIABLE ) {
+
+ /* $object has to exist and has to be a object */
+ $funcname = $ts[$last - 1]['value'];
+
+ if (!isset($GLOBALS[ltrim($funcname, '$')])) {
+ throw new Exception(sprintf('Variable \'%s\' is not set', $funcname));
+ }
+ $func = $GLOBALS[ltrim($funcname, '$')];
+
+ if (!function_exists($func)) {
+ throw new Exception(sprintf("Function %s() doesn't exist", $func));
+ }
+
+ }
+
+ array_push($braces, $token);
+ break;
+ case '{':
+ $need_return = 0;
+
+ if ($last >= 2 &&
+ $ts[$last - 1]['token'] == T_STRING &&
+ $ts[$last - 2]['token'] == T_CLASS ) {
+
+ /* class name { */
+
+ $classname = $ts[$last - 1]['value'];
+
+ if (class_exists($classname, false)) {
+ throw new Exception(sprintf("Class '%s' can't be redeclared", $classname));
+ }
+ } else if ($last >= 4 &&
+ $ts[$last - 1]['token'] == T_STRING &&
+ $ts[$last - 2]['token'] == T_EXTENDS &&
+ $ts[$last - 3]['token'] == T_STRING &&
+ $ts[$last - 4]['token'] == T_CLASS ) {
+
+ /* class classname extends classname { */
+
+ $classname = $ts[$last - 3]['value'];
+ $extendsname = $ts[$last - 1]['value'];
+
+ if (class_exists($classname, false)) {
+ throw new Exception(sprintf("Class '%s' can't be redeclared",
+ $classname));
+ }
+ if (!class_exists($extendsname, true)) {
+ throw new Exception(sprintf("Can't extend '%s' ... from not existing Class '%s'",
+ $classname, $extendsname));
+ }
+ } else if ($last >= 4 &&
+ $ts[$last - 1]['token'] == T_STRING &&
+ $ts[$last - 2]['token'] == T_IMPLEMENTS &&
+ $ts[$last - 3]['token'] == T_STRING &&
+ $ts[$last - 4]['token'] == T_CLASS ) {
+
+ /* class name implements interface { */
+
+ $classname = $ts[$last - 3]['value'];
+ $implements = $ts[$last - 1]['value'];
+
+ if (class_exists($classname, false)) {
+ throw new Exception(sprintf("Class '%s' can't be redeclared",
+ $classname));
+ }
+ if (!interface_exists($implements, false)) {
+ throw new Exception(sprintf("Can't implement not existing Interface '%s' for Class '%s'",
+ $implements, $classname));
+ }
+ }
+
+ array_push($braces, $token);
+ break;
+ case '}':
+ $need_return = 0;
+ case ')':
+ array_pop($braces);
+ break;
+ case '[':
+ if ($ts[0]['token'] != T_CLASS && /* if we are not in a class definition */
+ $ts[0]['token'] != T_ABSTRACT && /* if we are not in a class definition */
+ $ts[1]['token'] != T_CLASS && /* if we are not in a class definition */
+ $ts[$last - 1]['token'] == T_VARIABLE) {
+ /* $a[] only works on array and string */
+
+ /* $object has to exist and has to be a object */
+ $objname = $ts[$last - 1]['value'];
+
+ if (!isset($GLOBALS[ltrim($objname, '$')])) {
+ throw new Exception(sprintf('Variable \'%s\' is not set', $objname));
+ }
+ $obj = $GLOBALS[ltrim($objname, '$')];
+
+ if (is_object($obj)) {
+ throw new Exception(sprintf('Objects (%s) don\'t support array access operators', $objname));
+ }
+ }
+ break;
+ }
+
+ $eval .= $token;
+ }
+ }
+
+ $last = count($ts) - 1;
+ if ($last >= 2 &&
+ $ts[$last - 0]['token'] == T_STRING &&
+ $ts[$last - 1]['token'] == T_DOUBLE_COLON &&
+ $ts[$last - 2]['token'] == T_STRING ) {
+
+ /* Class::constant */
+
+ /* $object has to exist and has to be a object */
+ $classname = $ts[$last - 2]['value'];
+
+ if (!class_exists($classname)) {
+ throw new Exception(sprintf('Class \'%s\' doesn\'t exist', $classname));
+ }
+
+ $constname = $ts[$last - 0]['value'];
+
+ $c = new ReflectionClass($classname);
+ if (!$c->hasConstant($constname)) {
+ throw new Exception(sprintf("Class '%s' doesn't have a constant named '%s'",
+ $classname, $constname));
+ }
+ } else if ($last == 0 &&
+ $ts[$last - 0]['token'] == T_VARIABLE ) {
+
+ /* $var */
+
+ $varname = $ts[$last - 0]['value'];
+
+ if (!isset($GLOBALS[ltrim($varname, '$')])) {
+ throw new Exception(sprintf('Variable \'%s\' is not set', $varname));
+ }
+ }
+
+
+ $need_more = (count($braces) > 0) || $open_comment;
+
+ if ($need_more || ';' === $token) {
+ $need_semicolon = 0;
+ }
+
+ if ($need_return) {
+ $eval = "return ".$eval;
+ }
+
+ /* add a traling ; if necessary */
+ if ($need_semicolon)
+ {
+ $this->has_semicolon = preg_match('/;\s*$/', $eval);
+ $eval .= ';';
+ }
+
+ if (!$need_more) {
+ $this->code = $eval;
+ }
+
+ return $need_more;
+ }
+
+ /**
+ * show the prompt and fetch a single line
+ *
+ * uses readline() if avaialbe
+ *
+ * @return string a input-line
+ */
+ public function readline() {
+ if (empty($this->code)) print PHP_EOL;
+
+ $prompt = (empty($this->code)) ? '>> ' : '.. ';
+
+ if (count($this->code_buffer) > 0) {
+ print $prompt;
+
+ $line = array_shift($this->code_buffer);
+
+ print $line.PHP_EOL;
+
+ return $line.PHP_EOL;
+ }
+
+ if ($this->have_readline) {
+ $l = readline($prompt);
+
+ readline_add_history($l);
+ } else {
+ print $prompt;
+
+ if (is_null($this->stdin)) {
+ if (false === ($this->stdin = fopen("php://stdin", "r"))) {
+ return false;
+ }
+ }
+ $l = fgets($this->stdin);
+ }
+ return $l;
+ }
+
+ /**
+ * get the inline help
+ *
+ * @return string the inline help as string
+ */
+ public function cmdHelp($l) {
+ $o = 'Inline Help:'.PHP_EOL;
+
+ $cmds = PHP_Shell_Commands::getInstance()->getCommands();
+
+ $help = array();
+ foreach ($cmds as $cmd) {
+ $help[] = sprintf(' >> %s'.PHP_EOL.' %s'.PHP_EOL,
+ $cmd['command'],
+ $cmd['description']
+ );
+ }
+
+ return var_export(implode("\n", $help), 1);
+ }
+
+ /**
+ * get the license string
+ *
+ * @return string the inline help as string
+ */
+ public function cmdLicense($l) {
+ $o = <<<EOF
+(c) 2006 Jan Kneschke <jan@kneschke.de>
+
+Permission is hereby granted, free of charge, to any person obtaining a copy of
+this software and associated documentation files (the "Software"), to deal in
+the Software without restriction, including without limitation the rights to
+use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies
+of the Software, and to permit persons to whom the Software is furnished to do
+so, subject to the following conditions:
+
+The above copyright notice and this permission notice shall be included in all
+copies or substantial portions of the Software.
+
+THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
+IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
+FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
+AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
+LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
+OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
+SOFTWARE.
+EOF;
+
+ return var_export($o, 1);
+ }
+
+ /**
+ * handle the 'quit' command
+ *
+ * @return bool false to leave the input() call
+ * @see input
+ */
+ protected function cmdQuit($l) {
+ return false;
+ }
+
+ /**
+ * handle the input line
+ *
+ * read the input and handle the commands of the shell
+ *
+ * @return bool false on 'quit' or EOF, true otherwise
+ */
+ public function input() {
+ $l = $this->readline();
+
+ /* got EOF ? */
+ if (false === $l) return false;
+
+ $l = trim($l);
+
+ if (empty($this->code)) {
+ $this->verbose = 0;
+
+ $cmds = PHP_Shell_Commands::getInstance()->getCommands();
+
+ foreach ($cmds as $cmd) {
+ if (preg_match($cmd['regex'], $l)) {
+ $obj = $cmd['obj'];
+ $func = $cmd['method'];
+
+ if (false === ($l = $obj->$func($l))) {
+ ## quit
+ return false;
+ }
+
+ if (is_array($l)) {
+ $this->code_buffer = $l;
+ $l = '';
+ }
+ break;
+ }
+ }
+ }
+
+ $this->appendCode($l);
+
+ return true;
+ }
+
+ /**
+ * get the code-buffer
+ *
+ * @return string the code-buffer
+ */
+ public function getCode() {
+ return $this->code;
+ return $code;
+ }
+
+ /**
+ * reset the code-buffer
+ */
+ public function resetCode() {
+ $this->has_semicolon=false;
+ $this->code = '';
+ }
+
+ /**
+ * append code to the code-buffer
+ *
+ * @param string $code input buffer
+ */
+ public function appendCode($code) {
+ if (strlen($code)) $code .= PHP_EOL;
+
+ $this->code .= $code;
+ }
+
+ /**
+ * check if readline support is enabled
+ *
+ * @return bool true if enabled, false otherwise
+ */
+ public function hasReadline() {
+ return $this->have_readline;
+ }
+
+ /**
+ * get version of the class
+ *
+ * @return string version-string
+ */
+ public function getVersion() {
+ return $this->version;
+ }
+}
+
+/**
+* a readline completion callback
+*
+* @param string $str linebuffer
+* @param integer $pos position in linebuffer
+* @return array list of possible matches
+*/
+function __shell_readline_complete($str, $pos) {
+ $in = readline_info('line_buffer');
+
+ /**
+ * parse the line-buffer backwards to see if we have a
+ * - constant
+ * - function
+ * - variable
+ */
+
+ $m = array();
+
+ if (preg_match('#\$([A-Za-z0-9_]+)->#', $in, $a)) {
+ /* check for $o->... */
+ $name = $a[1];
+
+ if (isset($GLOBALS[$name]) && is_object($GLOBALS[$name])) {
+ $c = get_class_methods($GLOBALS[$name]);
+
+ foreach ($c as $v) {
+ $m[] = $v.'(';
+ }
+ $c = get_class_vars(get_class($GLOBALS[$name]));
+
+ foreach ($c as $k => $v) {
+ $m[] = $k;
+ }
+
+ return $m;
+ }
+ } else if (preg_match('#\$([A-Za-z0-9_]+)\[([^\]]+)\]->#', $in, $a)) {
+ /* check for $o[...]->... */
+ $name = $a[1];
+
+ if (isset($GLOBALS[$name]) &&
+ is_array($GLOBALS[$name]) &&
+ isset($GLOBALS[$name][$a[2]])) {
+
+ $c = get_class_methods($GLOBALS[$name][$a[2]]);
+
+ foreach ($c as $v) {
+ $m[] = $v.'(';
+ }
+ $c = get_class_vars(get_class($GLOBALS[$name][$a[2]]));
+
+ foreach ($c as $k => $v) {
+ $m[] = $k;
+ }
+ return $m;
+ }
+
+ } else if (preg_match('#([A-Za-z0-9_]+)::#', $in, $a)) {
+ /* check for Class:: */
+ $name = $a[1];
+
+ if (class_exists($name, false)) {
+ $c = get_class_methods($name);
+
+ foreach ($c as $v) {
+ $m[] = sprintf('%s::%s(', $name, $v);
+ }
+
+ $cl = new ReflectionClass($name);
+ $c = $cl->getConstants();
+
+ foreach ($c as $k => $v) {
+ $m[] = sprintf('%s::%s', $name, $k);
+ }
+
+ return $m;
+ }
+ } else if (preg_match('#\$([a-zA-Z]?[a-zA-Z0-9_]*)$#', $in)) {
+ $m = array_keys($GLOBALS);
+
+ return $m;
+ } else if (preg_match('#new #', $in)) {
+ $c = get_declared_classes();
+
+ foreach ($c as $v) {
+ $m[] = $v.'(';
+ }
+
+ return $m;
+ } else if (preg_match('#^:set #', $in)) {
+ foreach (PHP_Shell_Options::getInstance()->getOptions() as $v) {
+ $m[] = $v;
+ }
+
+ return $m;
+ }
+
+ $f = get_defined_functions();
+
+ foreach ($f['internal'] as $v) {
+ $m[] = $v.'(';
+ }
+
+ foreach ($f['user'] as $v) {
+ $m[] = $v.'(';
+ }
+
+ $c = get_declared_classes();
+
+ foreach ($c as $v) {
+ $m[] = $v.'::';
+ }
+
+ $c = get_defined_constants();
+
+ foreach ($c as $k => $v) {
+ $m[] = $k;
+ }
+
+ /* taken from http://de3.php.net/manual/en/reserved.php */
+ $m[] = 'abstract';
+ $m[] = 'and';
+ $m[] = 'array(';
+ $m[] = 'as';
+ $m[] = 'break';
+ $m[] = 'case';
+ $m[] = 'catch';
+ $m[] = 'class';
+ $m[] = 'const';
+ $m[] = 'continue';
+ # $m[] = 'declare';
+ $m[] = 'default';
+ $m[] = 'die(';
+ $m[] = 'do';
+ $m[] = 'echo(';
+ $m[] = 'else';
+ $m[] = 'elseif';
+ $m[] = 'empty(';
+ # $m[] = 'enddeclare';
+ $m[] = 'eval(';
+ $m[] = 'exception';
+ $m[] = 'extends';
+ $m[] = 'exit(';
+ $m[] = 'extends';
+ $m[] = 'final';
+ $m[] = 'for (';
+ $m[] = 'foreach (';
+ $m[] = 'function';
+ $m[] = 'global';
+ $m[] = 'if';
+ $m[] = 'implements';
+ $m[] = 'include "';
+ $m[] = 'include_once "';
+ $m[] = 'interface';
+ $m[] = 'isset(';
+ $m[] = 'list(';
+ $m[] = 'new';
+ $m[] = 'or';
+ $m[] = 'print(';
+ $m[] = 'private';
+ $m[] = 'protected';
+ $m[] = 'public';
+ $m[] = 'require "';
+ $m[] = 'require_once "';
+ $m[] = 'return';
+ $m[] = 'static';
+ $m[] = 'switch (';
+ $m[] = 'throw';
+ $m[] = 'try';
+ $m[] = 'unset(';
+ # $m[] = 'use';
+ $m[] = 'var';
+ $m[] = 'while';
+ $m[] = 'xor';
+ $m[] = '__FILE__';
+ $m[] = '__FUNCTION__';
+ $m[] = '__CLASS__';
+ $m[] = '__LINE__';
+ $m[] = '__METHOD__';
+
+ # printf("%s ... %s\n", $str, $pos);
+ return $m;
+}
+
+
diff --git a/framework/3rdParty/PhpShell/php-shell-init.php b/framework/3rdParty/PhpShell/php-shell-init.php
index 20c6af75..6ae8e8fe 100644
--- a/framework/3rdParty/PhpShell/php-shell-init.php
+++ b/framework/3rdParty/PhpShell/php-shell-init.php
@@ -1,88 +1,88 @@
-<?php
-@ob_end_clean();
-error_reporting(E_ALL);
-set_time_limit(0);
-
-/**
-* the wrapper around the PHP_Shell class
-*
-* - load extensions
-* - set default error-handler
-* - add exec-hooks for the extensions
-*
-* To keep the namespace clashing between shell and your program
-* as small as possible all public variables and functions from
-* the shell are prefixed with __shell:
-*
-* - $__shell is the object of the shell
-* can be read, this is the shell object itself, don't touch it
-* - $__shell_retval is the return value of the eval() before
-* it is printed
-* can't be read, but overwrites existing vars with this name
-* - $__shell_exception is the catched Exception on Warnings, Notices, ..
-* can't be read, but overwrites existing vars with this name
-*/
-
-//try loading it from PEAR
-@require_once('PHP/Shell.php');
-if(class_exists('PHP_Shell', false))
-{
- require_once "PHP/Shell/Extensions/Autoload.php";
- require_once "PHP/Shell/Extensions/AutoloadDebug.php";
- require_once "PHP/Shell/Extensions/Colour.php";
- require_once "PHP/Shell/Extensions/ExecutionTime.php";
- require_once "PHP/Shell/Extensions/InlineHelp.php";
- require_once "PHP/Shell/Extensions/VerbosePrint.php";
- require_once "PHP/Shell/Extensions/LoadScript.php";
-}
-else
-{
- require_once(dirname(__FILE__)."/PHP/Shell.php");
- require_once(dirname(__FILE__)."/PHP/Shell/Extensions/Autoload.php");
- require_once(dirname(__FILE__)."/PHP/Shell/Extensions/AutoloadDebug.php");
- require_once(dirname(__FILE__)."/PHP/Shell/Extensions/Colour.php");
- require_once(dirname(__FILE__)."/PHP/Shell/Extensions/ExecutionTime.php");
- require_once(dirname(__FILE__)."/PHP/Shell/Extensions/InlineHelp.php");
- require_once(dirname(__FILE__)."/PHP/Shell/Extensions/VerbosePrint.php");
- require_once(dirname(__FILE__)."/PHP/Shell/Extensions/LoadScript.php");
-}
-
-/**
-* default error-handler
-*
-* Instead of printing the NOTICE or WARNING from php we wan't the turn non-FATAL
-* messages into exceptions and handle them in our own way.
-*
-* you can set your own error-handler by createing a function named
-* __shell_error_handler
-*
-* @param integer $errno Error-Number
-* @param string $errstr Error-Message
-* @param string $errfile Filename where the error was raised
-* @param interger $errline Line-Number in the File
-* @param mixed $errctx ...
-*/
-function __shell_default_error_handler($errno, $errstr, $errfile, $errline, $errctx) {
- ## ... what is this errno again ?
- if ($errno == 2048) return;
-
- throw new Exception(sprintf("%s:%d\r\n%s", $errfile, $errline, $errstr));
-}
-
-//set_error_handler("__shell_default_error_handler");
-
-$__shell = new PHP_Shell();
-$__shell_exts = PHP_Shell_Extensions::getInstance();
-$__shell_exts->registerExtensions(array(
- "options" => PHP_Shell_Options::getInstance(), /* the :set command */
-
- "autoload" => new PHP_Shell_Extensions_Autoload(),
- "autoload_debug" => new PHP_Shell_Extensions_AutoloadDebug(),
- "colour" => new PHP_Shell_Extensions_Colour(),
- "exectime" => new PHP_Shell_Extensions_ExecutionTime(),
- "inlinehelp" => new PHP_Shell_Extensions_InlineHelp(),
- "verboseprint" => new PHP_Shell_Extensions_VerbosePrint()
- // "loadscript" => new PHP_Shell_Extensions_LoadScript()
-));
-
+<?php
+@ob_end_clean();
+error_reporting(E_ALL);
+set_time_limit(0);
+
+/**
+* the wrapper around the PHP_Shell class
+*
+* - load extensions
+* - set default error-handler
+* - add exec-hooks for the extensions
+*
+* To keep the namespace clashing between shell and your program
+* as small as possible all public variables and functions from
+* the shell are prefixed with __shell:
+*
+* - $__shell is the object of the shell
+* can be read, this is the shell object itself, don't touch it
+* - $__shell_retval is the return value of the eval() before
+* it is printed
+* can't be read, but overwrites existing vars with this name
+* - $__shell_exception is the catched Exception on Warnings, Notices, ..
+* can't be read, but overwrites existing vars with this name
+*/
+
+//try loading it from PEAR
+@require_once('PHP/Shell.php');
+if(class_exists('PHP_Shell', false))
+{
+ require_once "PHP/Shell/Extensions/Autoload.php";
+ require_once "PHP/Shell/Extensions/AutoloadDebug.php";
+ require_once "PHP/Shell/Extensions/Colour.php";
+ require_once "PHP/Shell/Extensions/ExecutionTime.php";
+ require_once "PHP/Shell/Extensions/InlineHelp.php";
+ require_once "PHP/Shell/Extensions/VerbosePrint.php";
+ require_once "PHP/Shell/Extensions/LoadScript.php";
+}
+else
+{
+ require_once(dirname(__FILE__)."/PHP/Shell.php");
+ require_once(dirname(__FILE__)."/PHP/Shell/Extensions/Autoload.php");
+ require_once(dirname(__FILE__)."/PHP/Shell/Extensions/AutoloadDebug.php");
+ require_once(dirname(__FILE__)."/PHP/Shell/Extensions/Colour.php");
+ require_once(dirname(__FILE__)."/PHP/Shell/Extensions/ExecutionTime.php");
+ require_once(dirname(__FILE__)."/PHP/Shell/Extensions/InlineHelp.php");
+ require_once(dirname(__FILE__)."/PHP/Shell/Extensions/VerbosePrint.php");
+ require_once(dirname(__FILE__)."/PHP/Shell/Extensions/LoadScript.php");
+}
+
+/**
+* default error-handler
+*
+* Instead of printing the NOTICE or WARNING from php we wan't the turn non-FATAL
+* messages into exceptions and handle them in our own way.
+*
+* you can set your own error-handler by createing a function named
+* __shell_error_handler
+*
+* @param integer $errno Error-Number
+* @param string $errstr Error-Message
+* @param string $errfile Filename where the error was raised
+* @param interger $errline Line-Number in the File
+* @param mixed $errctx ...
+*/
+function __shell_default_error_handler($errno, $errstr, $errfile, $errline, $errctx) {
+ ## ... what is this errno again ?
+ if ($errno == 2048) return;
+
+ throw new Exception(sprintf("%s:%d\r\n%s", $errfile, $errline, $errstr));
+}
+
+//set_error_handler("__shell_default_error_handler");
+
+$__shell = new PHP_Shell();
+$__shell_exts = PHP_Shell_Extensions::getInstance();
+$__shell_exts->registerExtensions(array(
+ "options" => PHP_Shell_Options::getInstance(), /* the :set command */
+
+ "autoload" => new PHP_Shell_Extensions_Autoload(),
+ "autoload_debug" => new PHP_Shell_Extensions_AutoloadDebug(),
+ "colour" => new PHP_Shell_Extensions_Colour(),
+ "exectime" => new PHP_Shell_Extensions_ExecutionTime(),
+ "inlinehelp" => new PHP_Shell_Extensions_InlineHelp(),
+ "verboseprint" => new PHP_Shell_Extensions_VerbosePrint()
+ // "loadscript" => new PHP_Shell_Extensions_LoadScript()
+));
+
?> \ No newline at end of file
diff --git a/framework/3rdParty/SafeHtml/HTMLSax3.php b/framework/3rdParty/SafeHtml/HTMLSax3.php
index 1be7aede..80d166e9 100644
--- a/framework/3rdParty/SafeHtml/HTMLSax3.php
+++ b/framework/3rdParty/SafeHtml/HTMLSax3.php
@@ -1,695 +1,695 @@
-<?php
-/* vim: set expandtab tabstop=4 shiftwidth=4: */
-//
-// +----------------------------------------------------------------------+
-// | PHP Version 4 |
-// +----------------------------------------------------------------------+
-// | Copyright (c) 1997-2002 The PHP Group |
-// +----------------------------------------------------------------------+
-// | This source file is subject to version 2.02 of the PHP license, |
-// | that is bundled with this package in the file LICENSE, and is |
-// | available at through the world-wide-web at |
-// | http://www.php.net/license/3_0.txt. |
-// | If you did not receive a copy of the PHP license and are unable to |
-// | obtain it through the world-wide-web, please send a note to |
-// | license@php.net so we can mail you a copy immediately. |
-// +----------------------------------------------------------------------+
-// | Authors: Alexander Zhukov <alex@veresk.ru> Original port from Python |
-// | Authors: Harry Fuecks <hfuecks@phppatterns.com> Port to PEAR + more |
-// | Authors: Many @ Sitepointforums Advanced PHP Forums |
-// +----------------------------------------------------------------------+
-//
-// $Id$
-//
-/**
-* Main parser components
-* @package System.Security.SafeHtml
-* @version $Id$
-*/
-/**
-* Required classes
-*/
-
-require_once(dirname(__FILE__).'/HTMLSax3/States.php');
-require_once(dirname(__FILE__).'/HTMLSax3/Decorators.php');
-
-/**
-* Base State Parser
-* @package System.Security.SafeHtml
-* @access protected
-* @abstract
-*/
-class TSax3_StateParser {
- /**
- * Instance of user front end class to be passed to callbacks
- * @var TSax3
- * @access private
- */
- public $htmlsax;
- /**
- * User defined object for handling elements
- * @var object
- * @access private
- */
- public $handler_object_element;
- /**
- * User defined open tag handler method
- * @var string
- * @access private
- */
- public $handler_method_opening;
- /**
- * User defined close tag handler method
- * @var string
- * @access private
- */
- public $handler_method_closing;
- /**
- * User defined object for handling data in elements
- * @var object
- * @access private
- */
- public $handler_object_data;
- /**
- * User defined data handler method
- * @var string
- * @access private
- */
- public $handler_method_data;
- /**
- * User defined object for handling processing instructions
- * @var object
- * @access private
- */
- public $handler_object_pi;
- /**
- * User defined processing instruction handler method
- * @var string
- * @access private
- */
- public $handler_method_pi;
- /**
- * User defined object for handling JSP/ASP tags
- * @var object
- * @access private
- */
- public $handler_object_jasp;
- /**
- * User defined JSP/ASP handler method
- * @var string
- * @access private
- */
- public $handler_method_jasp;
- /**
- * User defined object for handling XML escapes
- * @var object
- * @access private
- */
- public $handler_object_escape;
- /**
- * User defined XML escape handler method
- * @var string
- * @access private
- */
- public $handler_method_escape;
- /**
- * User defined handler object or NullHandler
- * @var object
- * @access private
- */
- public $handler_default;
- /**
- * Parser options determining parsing behavior
- * @var array
- * @access private
- */
- protected $parser_options = array();
- /**
- * XML document being parsed
- * @var string
- * @access private
- */
- protected $rawtext;
- /**
- * Position in XML document relative to start (0)
- * @var int
- * @access private
- */
- protected $position;
- /**
- * Length of the XML document in characters
- * @var int
- * @access private
- */
- protected $length;
- /**
- * Array of state objects
- * @var array
- * @access private
- */
- protected $State = array();
-
- const TSAX3_STATE_STOP = 0;
- const TSAX3_STATE_START = 1;
- const TSAX3_STATE_TAG = 2;
- const TSAX3_STATE_OPENING_TAG = 3;
- const TSAX3_STATE_CLOSING_TAG = 4;
- const TSAX3_STATE_ESCAPE = 6;
- const TSAX3_STATE_JASP = 7;
- const TSAX3_STATE_PI = 8;
-
- /**
- * Constructs TSax3_StateParser setting up states
- * @var TSax3 instance of user front end class
- * @access protected
- */
- protected function __construct($htmlsax) {
- $this->htmlsax = $htmlsax;
- $this->State[self::TSAX3_STATE_START] = new TSax3_StartingState();
-
- $this->State[self::TSAX3_STATE_CLOSING_TAG] = new TSax3_ClosingTagState();
- $this->State[self::TSAX3_STATE_TAG] = new TSax3_TagState();
- $this->State[self::TSAX3_STATE_OPENING_TAG] = new TSax3_OpeningTagState();
-
- $this->State[self::TSAX3_STATE_PI] = new TSax3_PiState();
- $this->State[self::TSAX3_STATE_JASP] = new TSax3_JaspState();
- $this->State[self::TSAX3_STATE_ESCAPE] = new TSax3_EscapeState();
- }
-
- /**
- * Moves the position back one character
- * @access protected
- * @return void
- */
- function unscanCharacter() {
- $this->position -= 1;
- }
-
- /**
- * Moves the position forward one character
- * @access protected
- * @return void
- */
- function ignoreCharacter() {
- $this->position += 1;
- }
-
- /**
- * Returns the next character from the XML document or void if at end
- * @access protected
- * @return mixed
- */
- function scanCharacter() {
- if ($this->position < $this->length) {
- return $this->rawtext{$this->position++};
- }
- }
-
- /**
- * Returns a string from the current position to the next occurance
- * of the supplied string
- * @param string string to search until
- * @access protected
- * @return string
- */
- function scanUntilString($string) {
- $start = $this->position;
- $this->position = strpos($this->rawtext, $string, $start);
- if ($this->position === FALSE) {
- $this->position = $this->length;
- }
- return substr($this->rawtext, $start, $this->position - $start);
- }
-
- /**
- * Returns a string from the current position until the first instance of
- * one of the characters in the supplied string argument
- * @param string string to search until
- * @access protected
- * @return string
- * @abstract
- */
- function scanUntilCharacters($string) {}
-
- /**
- * Moves the position forward past any whitespace characters
- * @access protected
- * @return void
- * @abstract
- */
- function ignoreWhitespace() {}
-
- /**
- * Begins the parsing operation, setting up any decorators, depending on
- * parse options invoking _parse() to execute parsing
- * @param string XML document to parse
- * @access protected
- * @return void
- */
- function parse($data) {
- if ($this->parser_options['XML_OPTION_TRIM_DATA_NODES']==1) {
- $decorator = new TSax3_Trim(
- $this->handler_object_data,
- $this->handler_method_data);
- $this->handler_object_data =& $decorator;
- $this->handler_method_data = 'trimData';
- }
- if ($this->parser_options['XML_OPTION_CASE_FOLDING']==1) {
- $open_decor = new TSax3_CaseFolding(
- $this->handler_object_element,
- $this->handler_method_opening,
- $this->handler_method_closing);
- $this->handler_object_element =& $open_decor;
- $this->handler_method_opening ='foldOpen';
- $this->handler_method_closing ='foldClose';
- }
- if ($this->parser_options['XML_OPTION_LINEFEED_BREAK']==1) {
- $decorator = new TSax3_Linefeed(
- $this->handler_object_data,
- $this->handler_method_data);
- $this->handler_object_data =& $decorator;
- $this->handler_method_data = 'breakData';
- }
- if ($this->parser_options['XML_OPTION_TAB_BREAK']==1) {
- $decorator = new TSax3_Tab(
- $this->handler_object_data,
- $this->handler_method_data);
- $this->handler_object_data =& $decorator;
- $this->handler_method_data = 'breakData';
- }
- if ($this->parser_options['XML_OPTION_ENTITIES_UNPARSED']==1) {
- $decorator = new TSax3_Entities_Unparsed(
- $this->handler_object_data,
- $this->handler_method_data);
- $this->handler_object_data =& $decorator;
- $this->handler_method_data = 'breakData';
- }
- if ($this->parser_options['XML_OPTION_ENTITIES_PARSED']==1) {
- $decorator = new TSax3_Entities_Parsed(
- $this->handler_object_data,
- $this->handler_method_data);
- $this->handler_object_data =& $decorator;
- $this->handler_method_data = 'breakData';
- }
- // Note switched on by default
- if ($this->parser_options['XML_OPTION_STRIP_ESCAPES']==1) {
- $decorator = new TSax3_Escape_Stripper(
- $this->handler_object_escape,
- $this->handler_method_escape);
- $this->handler_object_escape =& $decorator;
- $this->handler_method_escape = 'strip';
- }
- $this->rawtext = $data;
- $this->length = strlen($data);
- $this->position = 0;
- $this->_parse();
- }
-
- /**
- * Performs the parsing itself, delegating calls to a specific parser
- * state
- * @param constant state object to parse with
- * @access protected
- * @return void
- */
- function _parse($state = self::TSAX3_STATE_START) {
- do {
- $state = $this->State[$state]->parse($this);
- } while ($state != self::TSAX3_STATE_STOP &&
- $this->position < $this->length);
- }
-}
-
-/**
-* Parser for PHP Versions below 4.3.0. Uses a slower parsing mechanism than
-* the equivalent PHP 4.3.0+ subclass of StateParser
-* @package System.Security.SafeHtml
-* @access protected
-* @see TSax3_StateParser_Gtet430
-*/
-class TSax3_StateParser_Lt430 extends TSax3_StateParser {
- /**
- * Constructs TSax3_StateParser_Lt430 defining available
- * parser options
- * @var TSax3 instance of user front end class
- * @access protected
- */
- function __construct(& $htmlsax) {
- parent::__construct($htmlsax);
- $this->parser_options['XML_OPTION_TRIM_DATA_NODES'] = 0;
- $this->parser_options['XML_OPTION_CASE_FOLDING'] = 0;
- $this->parser_options['XML_OPTION_LINEFEED_BREAK'] = 0;
- $this->parser_options['XML_OPTION_TAB_BREAK'] = 0;
- $this->parser_options['XML_OPTION_ENTITIES_PARSED'] = 0;
- $this->parser_options['XML_OPTION_ENTITIES_UNPARSED'] = 0;
- $this->parser_options['XML_OPTION_STRIP_ESCAPES'] = 0;
- //var_dump($this->parser_options);
- }
-
- /**
- * Returns a string from the current position until the first instance of
- * one of the characters in the supplied string argument
- * @param string string to search until
- * @access protected
- * @return string
- */
- function scanUntilCharacters($string) {
- $startpos = $this->position;
- while ($this->position < $this->length && strpos($string, $this->rawtext{$this->position}) === FALSE) {
- $this->position++;
- }
- return substr($this->rawtext, $startpos, $this->position - $startpos);
- }
-
- /**
- * Moves the position forward past any whitespace characters
- * @access protected
- * @return void
- */
- function ignoreWhitespace() {
- while ($this->position < $this->length &&
- strpos(" \n\r\t", $this->rawtext{$this->position}) !== FALSE) {
- $this->position++;
- }
- }
-
- /**
- * Begins the parsing operation, setting up the unparsed XML entities
- * decorator if necessary then delegating further work to parent
- * @param string XML document to parse
- * @access protected
- * @return void
- */
- function parse($data) {
- parent::parse($data);
- }
-}
-
-/**
-* Parser for PHP Versions equal to or greater than 4.3.0. Uses a faster
-* parsing mechanism than the equivalent PHP < 4.3.0 subclass of StateParser
-* @package System.Security.SafeHtml
-* @access protected
-* @see TSax3_StateParser_Lt430
-*/
-class TSax3_StateParser_Gtet430 extends TSax3_StateParser {
- /**
- * Constructs TSax3_StateParser_Gtet430 defining available
- * parser options
- * @var TSax3 instance of user front end class
- * @access protected
- */
- function __construct(& $htmlsax) {
- parent::__construct($htmlsax);
- $this->parser_options['XML_OPTION_TRIM_DATA_NODES'] = 0;
- $this->parser_options['XML_OPTION_CASE_FOLDING'] = 0;
- $this->parser_options['XML_OPTION_LINEFEED_BREAK'] = 0;
- $this->parser_options['XML_OPTION_TAB_BREAK'] = 0;
- $this->parser_options['XML_OPTION_ENTITIES_PARSED'] = 0;
- $this->parser_options['XML_OPTION_ENTITIES_UNPARSED'] = 0;
- $this->parser_options['XML_OPTION_STRIP_ESCAPES'] = 0;
- }
- /**
- * Returns a string from the current position until the first instance of
- * one of the characters in the supplied string argument.
- * @param string string to search until
- * @access protected
- * @return string
- */
- function scanUntilCharacters($string) {
- $startpos = $this->position;
- $length = strcspn($this->rawtext, $string, $startpos);
- $this->position += $length;
- return substr($this->rawtext, $startpos, $length);
- }
-
- /**
- * Moves the position forward past any whitespace characters
- * @access protected
- * @return void
- */
- function ignoreWhitespace() {
- $this->position += strspn($this->rawtext, " \n\r\t", $this->position);
- }
-
- /**
- * Begins the parsing operation, setting up the parsed and unparsed
- * XML entity decorators if necessary then delegating further work
- * to parent
- * @param string XML document to parse
- * @access protected
- * @return void
- */
- function parse($data) {
- parent::parse($data);
- }
-}
-
-/**
-* Default NullHandler for methods which were not set by user
-* @package System.Security.SafeHtml
-* @access protected
-*/
-class TSax3_NullHandler {
- /**
- * Generic handler method which does nothing
- * @access protected
- * @return void
- */
- function DoNothing() {
- }
-}
-
-/**
-* User interface class. All user calls should only be made to this class
-* @package System.Security.SafeHtml
-* @access public
-*/
-class TSax3 {
- /**
- * Instance of concrete subclass of TSax3_StateParser
- * @var TSax3_StateParser
- * @access private
- */
- private $state_parser;
-
- /**
- * Constructs TSax3 selecting concrete StateParser subclass
- * depending on PHP version being used as well as setting the default
- * NullHandler for all callbacks<br />
- * <b>Example:</b>
- * <pre>
- * $myHandler = & new MyHandler();
- * $parser = new TSax3();
- * $parser->set_object($myHandler);
- * $parser->set_option('XML_OPTION_CASE_FOLDING');
- * $parser->set_element_handler('myOpenHandler','myCloseHandler');
- * $parser->set_data_handler('myDataHandler');
- * $parser->parser($xml);
- * </pre>
- * @access public
- */
- function __construct() {
- if (version_compare(phpversion(), '4.3', 'ge')) {
- $this->state_parser = new TSax3_StateParser_Gtet430($this);
- } else {
- $this->state_parser = new TSax3_StateParser_Lt430($this);
- }
- $nullhandler = new TSax3_NullHandler();
- $this->set_object($nullhandler);
- $this->set_element_handler('DoNothing', 'DoNothing');
- $this->set_data_handler('DoNothing');
- $this->set_pi_handler('DoNothing');
- $this->set_jasp_handler('DoNothing');
- $this->set_escape_handler('DoNothing');
- }
-
- /**
- * Sets the user defined handler object. Returns a PEAR Error
- * if supplied argument is not an object.
- * @param object handler object containing SAX callback methods
- * @access public
- * @return mixed
- */
- function set_object(&$object) {
- if ( is_object($object) ) {
- $this->state_parser->handler_default =& $object;
- return true;
- } else {
- require_once('PEAR.php');
- PEAR::raiseError('TSax3::set_object requires '.
- 'an object instance');
- }
- }
-
- /**
- * Sets a parser option. By default all options are switched off.
- * Returns a PEAR Error if option is invalid<br />
- * <b>Available options:</b>
- * <ul>
- * <li>XML_OPTION_TRIM_DATA_NODES: trim whitespace off the beginning
- * and end of data passed to the data handler</li>
- * <li>XML_OPTION_LINEFEED_BREAK: linefeeds result in additional data
- * handler calls</li>
- * <li>XML_OPTION_TAB_BREAK: tabs result in additional data handler
- * calls</li>
- * <li>XML_OPTION_ENTITIES_UNPARSED: XML entities are returned as
- * seperate data handler calls in unparsed form</li>
- * <li>XML_OPTION_ENTITIES_PARSED: (PHP 4.3.0+ only) XML entities are
- * returned as seperate data handler calls and are parsed with
- * PHP's html_entity_decode() function</li>
- * <li>XML_OPTION_STRIP_ESCAPES: strips out the -- -- comment markers
- * or CDATA markup inside an XML escape, if found.</li>
- * </ul>
- * To get HTMLSax to behave in the same way as the native PHP SAX parser,
- * using it's default state, you need to switch on XML_OPTION_LINEFEED_BREAK,
- * XML_OPTION_ENTITIES_PARSED and XML_OPTION_CASE_FOLDING
- * @param string name of parser option
- * @param int (optional) 1 to switch on, 0 for off
- * @access public
- * @return boolean
- */
- function set_option($name, $value=1) {
- if ( array_key_exists($name,$this->state_parser->parser_options) ) {
- $this->state_parser->parser_options[$name] = $value;
- return true;
- } else {
- require_once('PEAR.php');
- PEAR::raiseError('TSax3::set_option('.$name.') illegal');
- }
- }
-
- /**
- * Sets the data handler method which deals with the contents of XML
- * elements.<br />
- * The handler method must accept two arguments, the first being an
- * instance of TSax3 and the second being the contents of an
- * XML element e.g.
- * <pre>
- * function myDataHander(& $parser,$data){}
- * </pre>
- * @param string name of method
- * @access public
- * @return void
- * @see set_object
- */
- function set_data_handler($data_method) {
- $this->state_parser->handler_object_data =& $this->state_parser->handler_default;
- $this->state_parser->handler_method_data = $data_method;
- }
-
- /**
- * Sets the open and close tag handlers
- * <br />The open handler method must accept three arguments; the parser,
- * the tag name and an array of attributes e.g.
- * <pre>
- * function myOpenHander(& $parser,$tagname,$attrs=array()){}
- * </pre>
- * The close handler method must accept two arguments; the parser and
- * the tag name e.g.
- * <pre>
- * function myCloseHander(& $parser,$tagname){}
- * </pre>
- * @param string name of open method
- * @param string name of close method
- * @access public
- * @return void
- * @see set_object
- */
- function set_element_handler($opening_method, $closing_method) {
- $this->state_parser->handler_object_element =& $this->state_parser->handler_default;
- $this->state_parser->handler_method_opening = $opening_method;
- $this->state_parser->handler_method_closing = $closing_method;
- }
-
- /**
- * Sets the processing instruction handler method e.g. for PHP open
- * and close tags<br />
- * The handler method must accept three arguments; the parser, the
- * PI target and data inside the PI
- * <pre>
- * function myPIHander(& $parser,$target, $data){}
- * </pre>
- * @param string name of method
- * @access public
- * @return void
- * @see set_object
- */
- function set_pi_handler($pi_method) {
- $this->state_parser->handler_object_pi =& $this->state_parser->handler_default;
- $this->state_parser->handler_method_pi = $pi_method;
- }
-
- /**
- * Sets the XML escape handler method e.g. for comments and doctype
- * declarations<br />
- * The handler method must accept two arguments; the parser and the
- * contents of the escaped section
- * <pre>
- * function myEscapeHander(& $parser, $data){}
- * </pre>
- * @param string name of method
- * @access public
- * @return void
- * @see set_object
- */
- function set_escape_handler($escape_method) {
- $this->state_parser->handler_object_escape =& $this->state_parser->handler_default;
- $this->state_parser->handler_method_escape = $escape_method;
- }
-
- /**
- * Sets the JSP/ASP markup handler<br />
- * The handler method must accept two arguments; the parser and
- * body of the JASP tag
- * <pre>
- * function myJaspHander(& $parser, $data){}
- * </pre>
- * @param string name of method
- * @access public
- * @return void
- * @see set_object
- */
- function set_jasp_handler ($jasp_method) {
- $this->state_parser->handler_object_jasp =& $this->state_parser->handler_default;
- $this->state_parser->handler_method_jasp = $jasp_method;
- }
-
- /**
- * Returns the current string position of the "cursor" inside the XML
- * document
- * <br />Intended for use from within a user defined handler called
- * via the $parser reference e.g.
- * <pre>
- * function myDataHandler(& $parser,$data) {
- * echo( 'Current position: '.$parser->get_current_position() );
- * }
- * </pre>
- * @access public
- * @return int
- * @see get_length
- */
- function get_current_position() {
- return $this->state_parser->position;
- }
-
- /**
- * Returns the string length of the XML document being parsed
- * @access public
- * @return int
- */
- function get_length() {
- return $this->state_parser->length;
- }
-
- /**
- * Start parsing some XML
- * @param string XML document
- * @access public
- * @return void
- */
- function parse($data) {
- $this->state_parser->parse($data);
- }
-}
+<?php
+/* vim: set expandtab tabstop=4 shiftwidth=4: */
+//
+// +----------------------------------------------------------------------+
+// | PHP Version 4 |
+// +----------------------------------------------------------------------+
+// | Copyright (c) 1997-2002 The PHP Group |
+// +----------------------------------------------------------------------+
+// | This source file is subject to version 2.02 of the PHP license, |
+// | that is bundled with this package in the file LICENSE, and is |
+// | available at through the world-wide-web at |
+// | http://www.php.net/license/3_0.txt. |
+// | If you did not receive a copy of the PHP license and are unable to |
+// | obtain it through the world-wide-web, please send a note to |
+// | license@php.net so we can mail you a copy immediately. |
+// +----------------------------------------------------------------------+
+// | Authors: Alexander Zhukov <alex@veresk.ru> Original port from Python |
+// | Authors: Harry Fuecks <hfuecks@phppatterns.com> Port to PEAR + more |
+// | Authors: Many @ Sitepointforums Advanced PHP Forums |
+// +----------------------------------------------------------------------+
+//
+// $Id$
+//
+/**
+* Main parser components
+* @package System.Security.SafeHtml
+* @version $Id$
+*/
+/**
+* Required classes
+*/
+
+require_once(dirname(__FILE__).'/HTMLSax3/States.php');
+require_once(dirname(__FILE__).'/HTMLSax3/Decorators.php');
+
+/**
+* Base State Parser
+* @package System.Security.SafeHtml
+* @access protected
+* @abstract
+*/
+class TSax3_StateParser {
+ /**
+ * Instance of user front end class to be passed to callbacks
+ * @var TSax3
+ * @access private
+ */
+ public $htmlsax;
+ /**
+ * User defined object for handling elements
+ * @var object
+ * @access private
+ */
+ public $handler_object_element;
+ /**
+ * User defined open tag handler method
+ * @var string
+ * @access private
+ */
+ public $handler_method_opening;
+ /**
+ * User defined close tag handler method
+ * @var string
+ * @access private
+ */
+ public $handler_method_closing;
+ /**
+ * User defined object for handling data in elements
+ * @var object
+ * @access private
+ */
+ public $handler_object_data;
+ /**
+ * User defined data handler method
+ * @var string
+ * @access private
+ */
+ public $handler_method_data;
+ /**
+ * User defined object for handling processing instructions
+ * @var object
+ * @access private
+ */
+ public $handler_object_pi;
+ /**
+ * User defined processing instruction handler method
+ * @var string
+ * @access private
+ */
+ public $handler_method_pi;
+ /**
+ * User defined object for handling JSP/ASP tags
+ * @var object
+ * @access private
+ */
+ public $handler_object_jasp;
+ /**
+ * User defined JSP/ASP handler method
+ * @var string
+ * @access private
+ */
+ public $handler_method_jasp;
+ /**
+ * User defined object for handling XML escapes
+ * @var object
+ * @access private
+ */
+ public $handler_object_escape;
+ /**
+ * User defined XML escape handler method
+ * @var string
+ * @access private
+ */
+ public $handler_method_escape;
+ /**
+ * User defined handler object or NullHandler
+ * @var object
+ * @access private
+ */
+ public $handler_default;
+ /**
+ * Parser options determining parsing behavior
+ * @var array
+ * @access private
+ */
+ protected $parser_options = array();
+ /**
+ * XML document being parsed
+ * @var string
+ * @access private
+ */
+ protected $rawtext;
+ /**
+ * Position in XML document relative to start (0)
+ * @var int
+ * @access private
+ */
+ protected $position;
+ /**
+ * Length of the XML document in characters
+ * @var int
+ * @access private
+ */
+ protected $length;
+ /**
+ * Array of state objects
+ * @var array
+ * @access private
+ */
+ protected $State = array();
+
+ const TSAX3_STATE_STOP = 0;
+ const TSAX3_STATE_START = 1;
+ const TSAX3_STATE_TAG = 2;
+ const TSAX3_STATE_OPENING_TAG = 3;
+ const TSAX3_STATE_CLOSING_TAG = 4;
+ const TSAX3_STATE_ESCAPE = 6;
+ const TSAX3_STATE_JASP = 7;
+ const TSAX3_STATE_PI = 8;
+
+ /**
+ * Constructs TSax3_StateParser setting up states
+ * @var TSax3 instance of user front end class
+ * @access protected
+ */
+ protected function __construct($htmlsax) {
+ $this->htmlsax = $htmlsax;
+ $this->State[self::TSAX3_STATE_START] = new TSax3_StartingState();
+
+ $this->State[self::TSAX3_STATE_CLOSING_TAG] = new TSax3_ClosingTagState();
+ $this->State[self::TSAX3_STATE_TAG] = new TSax3_TagState();
+ $this->State[self::TSAX3_STATE_OPENING_TAG] = new TSax3_OpeningTagState();
+
+ $this->State[self::TSAX3_STATE_PI] = new TSax3_PiState();
+ $this->State[self::TSAX3_STATE_JASP] = new TSax3_JaspState();
+ $this->State[self::TSAX3_STATE_ESCAPE] = new TSax3_EscapeState();
+ }
+
+ /**
+ * Moves the position back one character
+ * @access protected
+ * @return void
+ */
+ function unscanCharacter() {
+ $this->position -= 1;
+ }
+
+ /**
+ * Moves the position forward one character
+ * @access protected
+ * @return void
+ */
+ function ignoreCharacter() {
+ $this->position += 1;
+ }
+
+ /**
+ * Returns the next character from the XML document or void if at end
+ * @access protected
+ * @return mixed
+ */
+ function scanCharacter() {
+ if ($this->position < $this->length) {
+ return $this->rawtext{$this->position++};
+ }
+ }
+
+ /**
+ * Returns a string from the current position to the next occurance
+ * of the supplied string
+ * @param string string to search until
+ * @access protected
+ * @return string
+ */
+ function scanUntilString($string) {
+ $start = $this->position;
+ $this->position = strpos($this->rawtext, $string, $start);
+ if ($this->position === FALSE) {
+ $this->position = $this->length;
+ }
+ return substr($this->rawtext, $start, $this->position - $start);
+ }
+
+ /**
+ * Returns a string from the current position until the first instance of
+ * one of the characters in the supplied string argument
+ * @param string string to search until
+ * @access protected
+ * @return string
+ * @abstract
+ */
+ function scanUntilCharacters($string) {}
+
+ /**
+ * Moves the position forward past any whitespace characters
+ * @access protected
+ * @return void
+ * @abstract
+ */
+ function ignoreWhitespace() {}
+
+ /**
+ * Begins the parsing operation, setting up any decorators, depending on
+ * parse options invoking _parse() to execute parsing
+ * @param string XML document to parse
+ * @access protected
+ * @return void
+ */
+ function parse($data) {
+ if ($this->parser_options['XML_OPTION_TRIM_DATA_NODES']==1) {
+ $decorator = new TSax3_Trim(
+ $this->handler_object_data,
+ $this->handler_method_data);
+ $this->handler_object_data =& $decorator;
+ $this->handler_method_data = 'trimData';
+ }
+ if ($this->parser_options['XML_OPTION_CASE_FOLDING']==1) {
+ $open_decor = new TSax3_CaseFolding(
+ $this->handler_object_element,
+ $this->handler_method_opening,
+ $this->handler_method_closing);
+ $this->handler_object_element =& $open_decor;
+ $this->handler_method_opening ='foldOpen';
+ $this->handler_method_closing ='foldClose';
+ }
+ if ($this->parser_options['XML_OPTION_LINEFEED_BREAK']==1) {
+ $decorator = new TSax3_Linefeed(
+ $this->handler_object_data,
+ $this->handler_method_data);
+ $this->handler_object_data =& $decorator;
+ $this->handler_method_data = 'breakData';
+ }
+ if ($this->parser_options['XML_OPTION_TAB_BREAK']==1) {
+ $decorator = new TSax3_Tab(
+ $this->handler_object_data,
+ $this->handler_method_data);
+ $this->handler_object_data =& $decorator;
+ $this->handler_method_data = 'breakData';
+ }
+ if ($this->parser_options['XML_OPTION_ENTITIES_UNPARSED']==1) {
+ $decorator = new TSax3_Entities_Unparsed(
+ $this->handler_object_data,
+ $this->handler_method_data);
+ $this->handler_object_data =& $decorator;
+ $this->handler_method_data = 'breakData';
+ }
+ if ($this->parser_options['XML_OPTION_ENTITIES_PARSED']==1) {
+ $decorator = new TSax3_Entities_Parsed(
+ $this->handler_object_data,
+ $this->handler_method_data);
+ $this->handler_object_data =& $decorator;
+ $this->handler_method_data = 'breakData';
+ }
+ // Note switched on by default
+ if ($this->parser_options['XML_OPTION_STRIP_ESCAPES']==1) {
+ $decorator = new TSax3_Escape_Stripper(
+ $this->handler_object_escape,
+ $this->handler_method_escape);
+ $this->handler_object_escape =& $decorator;
+ $this->handler_method_escape = 'strip';
+ }
+ $this->rawtext = $data;
+ $this->length = strlen($data);
+ $this->position = 0;
+ $this->_parse();
+ }
+
+ /**
+ * Performs the parsing itself, delegating calls to a specific parser
+ * state
+ * @param constant state object to parse with
+ * @access protected
+ * @return void
+ */
+ function _parse($state = self::TSAX3_STATE_START) {
+ do {
+ $state = $this->State[$state]->parse($this);
+ } while ($state != self::TSAX3_STATE_STOP &&
+ $this->position < $this->length);
+ }
+}
+
+/**
+* Parser for PHP Versions below 4.3.0. Uses a slower parsing mechanism than
+* the equivalent PHP 4.3.0+ subclass of StateParser
+* @package System.Security.SafeHtml
+* @access protected
+* @see TSax3_StateParser_Gtet430
+*/
+class TSax3_StateParser_Lt430 extends TSax3_StateParser {
+ /**
+ * Constructs TSax3_StateParser_Lt430 defining available
+ * parser options
+ * @var TSax3 instance of user front end class
+ * @access protected
+ */
+ function __construct(& $htmlsax) {
+ parent::__construct($htmlsax);
+ $this->parser_options['XML_OPTION_TRIM_DATA_NODES'] = 0;
+ $this->parser_options['XML_OPTION_CASE_FOLDING'] = 0;
+ $this->parser_options['XML_OPTION_LINEFEED_BREAK'] = 0;
+ $this->parser_options['XML_OPTION_TAB_BREAK'] = 0;
+ $this->parser_options['XML_OPTION_ENTITIES_PARSED'] = 0;
+ $this->parser_options['XML_OPTION_ENTITIES_UNPARSED'] = 0;
+ $this->parser_options['XML_OPTION_STRIP_ESCAPES'] = 0;
+ //var_dump($this->parser_options);
+ }
+
+ /**
+ * Returns a string from the current position until the first instance of
+ * one of the characters in the supplied string argument
+ * @param string string to search until
+ * @access protected
+ * @return string
+ */
+ function scanUntilCharacters($string) {
+ $startpos = $this->position;
+ while ($this->position < $this->length && strpos($string, $this->rawtext{$this->position}) === FALSE) {
+ $this->position++;
+ }
+ return substr($this->rawtext, $startpos, $this->position - $startpos);
+ }
+
+ /**
+ * Moves the position forward past any whitespace characters
+ * @access protected
+ * @return void
+ */
+ function ignoreWhitespace() {
+ while ($this->position < $this->length &&
+ strpos(" \n\r\t", $this->rawtext{$this->position}) !== FALSE) {
+ $this->position++;
+ }
+ }
+
+ /**
+ * Begins the parsing operation, setting up the unparsed XML entities
+ * decorator if necessary then delegating further work to parent
+ * @param string XML document to parse
+ * @access protected
+ * @return void
+ */
+ function parse($data) {
+ parent::parse($data);
+ }
+}
+
+/**
+* Parser for PHP Versions equal to or greater than 4.3.0. Uses a faster
+* parsing mechanism than the equivalent PHP < 4.3.0 subclass of StateParser
+* @package System.Security.SafeHtml
+* @access protected
+* @see TSax3_StateParser_Lt430
+*/
+class TSax3_StateParser_Gtet430 extends TSax3_StateParser {
+ /**
+ * Constructs TSax3_StateParser_Gtet430 defining available
+ * parser options
+ * @var TSax3 instance of user front end class
+ * @access protected
+ */
+ function __construct(& $htmlsax) {
+ parent::__construct($htmlsax);
+ $this->parser_options['XML_OPTION_TRIM_DATA_NODES'] = 0;
+ $this->parser_options['XML_OPTION_CASE_FOLDING'] = 0;
+ $this->parser_options['XML_OPTION_LINEFEED_BREAK'] = 0;
+ $this->parser_options['XML_OPTION_TAB_BREAK'] = 0;
+ $this->parser_options['XML_OPTION_ENTITIES_PARSED'] = 0;
+ $this->parser_options['XML_OPTION_ENTITIES_UNPARSED'] = 0;
+ $this->parser_options['XML_OPTION_STRIP_ESCAPES'] = 0;
+ }
+ /**
+ * Returns a string from the current position until the first instance of
+ * one of the characters in the supplied string argument.
+ * @param string string to search until
+ * @access protected
+ * @return string
+ */
+ function scanUntilCharacters($string) {
+ $startpos = $this->position;
+ $length = strcspn($this->rawtext, $string, $startpos);
+ $this->position += $length;
+ return substr($this->rawtext, $startpos, $length);
+ }
+
+ /**
+ * Moves the position forward past any whitespace characters
+ * @access protected
+ * @return void
+ */
+ function ignoreWhitespace() {
+ $this->position += strspn($this->rawtext, " \n\r\t", $this->position);
+ }
+
+ /**
+ * Begins the parsing operation, setting up the parsed and unparsed
+ * XML entity decorators if necessary then delegating further work
+ * to parent
+ * @param string XML document to parse
+ * @access protected
+ * @return void
+ */
+ function parse($data) {
+ parent::parse($data);
+ }
+}
+
+/**
+* Default NullHandler for methods which were not set by user
+* @package System.Security.SafeHtml
+* @access protected
+*/
+class TSax3_NullHandler {
+ /**
+ * Generic handler method which does nothing
+ * @access protected
+ * @return void
+ */
+ function DoNothing() {
+ }
+}
+
+/**
+* User interface class. All user calls should only be made to this class
+* @package System.Security.SafeHtml
+* @access public
+*/
+class TSax3 {
+ /**
+ * Instance of concrete subclass of TSax3_StateParser
+ * @var TSax3_StateParser
+ * @access private
+ */
+ private $state_parser;
+
+ /**
+ * Constructs TSax3 selecting concrete StateParser subclass
+ * depending on PHP version being used as well as setting the default
+ * NullHandler for all callbacks<br />
+ * <b>Example:</b>
+ * <pre>
+ * $myHandler = & new MyHandler();
+ * $parser = new TSax3();
+ * $parser->set_object($myHandler);
+ * $parser->set_option('XML_OPTION_CASE_FOLDING');
+ * $parser->set_element_handler('myOpenHandler','myCloseHandler');
+ * $parser->set_data_handler('myDataHandler');
+ * $parser->parser($xml);
+ * </pre>
+ * @access public
+ */
+ function __construct() {
+ if (version_compare(phpversion(), '4.3', 'ge')) {
+ $this->state_parser = new TSax3_StateParser_Gtet430($this);
+ } else {
+ $this->state_parser = new TSax3_StateParser_Lt430($this);
+ }
+ $nullhandler = new TSax3_NullHandler();
+ $this->set_object($nullhandler);
+ $this->set_element_handler('DoNothing', 'DoNothing');
+ $this->set_data_handler('DoNothing');
+ $this->set_pi_handler('DoNothing');
+ $this->set_jasp_handler('DoNothing');
+ $this->set_escape_handler('DoNothing');
+ }
+
+ /**
+ * Sets the user defined handler object. Returns a PEAR Error
+ * if supplied argument is not an object.
+ * @param object handler object containing SAX callback methods
+ * @access public
+ * @return mixed
+ */
+ function set_object(&$object) {
+ if ( is_object($object) ) {
+ $this->state_parser->handler_default =& $object;
+ return true;
+ } else {
+ require_once('PEAR.php');
+ PEAR::raiseError('TSax3::set_object requires '.
+ 'an object instance');
+ }
+ }
+
+ /**
+ * Sets a parser option. By default all options are switched off.
+ * Returns a PEAR Error if option is invalid<br />
+ * <b>Available options:</b>
+ * <ul>
+ * <li>XML_OPTION_TRIM_DATA_NODES: trim whitespace off the beginning
+ * and end of data passed to the data handler</li>
+ * <li>XML_OPTION_LINEFEED_BREAK: linefeeds result in additional data
+ * handler calls</li>
+ * <li>XML_OPTION_TAB_BREAK: tabs result in additional data handler
+ * calls</li>
+ * <li>XML_OPTION_ENTITIES_UNPARSED: XML entities are returned as
+ * seperate data handler calls in unparsed form</li>
+ * <li>XML_OPTION_ENTITIES_PARSED: (PHP 4.3.0+ only) XML entities are
+ * returned as seperate data handler calls and are parsed with
+ * PHP's html_entity_decode() function</li>
+ * <li>XML_OPTION_STRIP_ESCAPES: strips out the -- -- comment markers
+ * or CDATA markup inside an XML escape, if found.</li>
+ * </ul>
+ * To get HTMLSax to behave in the same way as the native PHP SAX parser,
+ * using it's default state, you need to switch on XML_OPTION_LINEFEED_BREAK,
+ * XML_OPTION_ENTITIES_PARSED and XML_OPTION_CASE_FOLDING
+ * @param string name of parser option
+ * @param int (optional) 1 to switch on, 0 for off
+ * @access public
+ * @return boolean
+ */
+ function set_option($name, $value=1) {
+ if ( array_key_exists($name,$this->state_parser->parser_options) ) {
+ $this->state_parser->parser_options[$name] = $value;
+ return true;
+ } else {
+ require_once('PEAR.php');
+ PEAR::raiseError('TSax3::set_option('.$name.') illegal');
+ }
+ }
+
+ /**
+ * Sets the data handler method which deals with the contents of XML
+ * elements.<br />
+ * The handler method must accept two arguments, the first being an
+ * instance of TSax3 and the second being the contents of an
+ * XML element e.g.
+ * <pre>
+ * function myDataHander(& $parser,$data){}
+ * </pre>
+ * @param string name of method
+ * @access public
+ * @return void
+ * @see set_object
+ */
+ function set_data_handler($data_method) {
+ $this->state_parser->handler_object_data =& $this->state_parser->handler_default;
+ $this->state_parser->handler_method_data = $data_method;
+ }
+
+ /**
+ * Sets the open and close tag handlers
+ * <br />The open handler method must accept three arguments; the parser,
+ * the tag name and an array of attributes e.g.
+ * <pre>
+ * function myOpenHander(& $parser,$tagname,$attrs=array()){}
+ * </pre>
+ * The close handler method must accept two arguments; the parser and
+ * the tag name e.g.
+ * <pre>
+ * function myCloseHander(& $parser,$tagname){}
+ * </pre>
+ * @param string name of open method
+ * @param string name of close method
+ * @access public
+ * @return void
+ * @see set_object
+ */
+ function set_element_handler($opening_method, $closing_method) {
+ $this->state_parser->handler_object_element =& $this->state_parser->handler_default;
+ $this->state_parser->handler_method_opening = $opening_method;
+ $this->state_parser->handler_method_closing = $closing_method;
+ }
+
+ /**
+ * Sets the processing instruction handler method e.g. for PHP open
+ * and close tags<br />
+ * The handler method must accept three arguments; the parser, the
+ * PI target and data inside the PI
+ * <pre>
+ * function myPIHander(& $parser,$target, $data){}
+ * </pre>
+ * @param string name of method
+ * @access public
+ * @return void
+ * @see set_object
+ */
+ function set_pi_handler($pi_method) {
+ $this->state_parser->handler_object_pi =& $this->state_parser->handler_default;
+ $this->state_parser->handler_method_pi = $pi_method;
+ }
+
+ /**
+ * Sets the XML escape handler method e.g. for comments and doctype
+ * declarations<br />
+ * The handler method must accept two arguments; the parser and the
+ * contents of the escaped section
+ * <pre>
+ * function myEscapeHander(& $parser, $data){}
+ * </pre>
+ * @param string name of method
+ * @access public
+ * @return void
+ * @see set_object
+ */
+ function set_escape_handler($escape_method) {
+ $this->state_parser->handler_object_escape =& $this->state_parser->handler_default;
+ $this->state_parser->handler_method_escape = $escape_method;
+ }
+
+ /**
+ * Sets the JSP/ASP markup handler<br />
+ * The handler method must accept two arguments; the parser and
+ * body of the JASP tag
+ * <pre>
+ * function myJaspHander(& $parser, $data){}
+ * </pre>
+ * @param string name of method
+ * @access public
+ * @return void
+ * @see set_object
+ */
+ function set_jasp_handler ($jasp_method) {
+ $this->state_parser->handler_object_jasp =& $this->state_parser->handler_default;
+ $this->state_parser->handler_method_jasp = $jasp_method;
+ }
+
+ /**
+ * Returns the current string position of the "cursor" inside the XML
+ * document
+ * <br />Intended for use from within a user defined handler called
+ * via the $parser reference e.g.
+ * <pre>
+ * function myDataHandler(& $parser,$data) {
+ * echo( 'Current position: '.$parser->get_current_position() );
+ * }
+ * </pre>
+ * @access public
+ * @return int
+ * @see get_length
+ */
+ function get_current_position() {
+ return $this->state_parser->position;
+ }
+
+ /**
+ * Returns the string length of the XML document being parsed
+ * @access public
+ * @return int
+ */
+ function get_length() {
+ return $this->state_parser->length;
+ }
+
+ /**
+ * Start parsing some XML
+ * @param string XML document
+ * @access public
+ * @return void
+ */
+ function parse($data) {
+ $this->state_parser->parse($data);
+ }
+}
?> \ No newline at end of file
diff --git a/framework/3rdParty/SafeHtml/HTMLSax3/Decorators.php b/framework/3rdParty/SafeHtml/HTMLSax3/Decorators.php
index ac82d073..2e2b6590 100644
--- a/framework/3rdParty/SafeHtml/HTMLSax3/Decorators.php
+++ b/framework/3rdParty/SafeHtml/HTMLSax3/Decorators.php
@@ -1,363 +1,363 @@
-<?php
-/* vim: set expandtab tabstop=4 shiftwidth=4: */
-//
-// +----------------------------------------------------------------------+
-// | PHP Version 4 |
-// +----------------------------------------------------------------------+
-// | Copyright (c) 1997-2002 The PHP Group |
-// +----------------------------------------------------------------------+
-// | This source file is subject to version 2.02 of the PHP license, |
-// | that is bundled with this package in the file LICENSE, and is |
-// | available at through the world-wide-web at |
-// | http://www.php.net/license/3_0.txt. |
-// | If you did not receive a copy of the PHP license and are unable to |
-// | obtain it through the world-wide-web, please send a note to |
-// | license@php.net so we can mail you a copy immediately. |
-// +----------------------------------------------------------------------+
-// | Authors: Alexander Zhukov <alex@veresk.ru> Original port from Python |
-// | Authors: Harry Fuecks <hfuecks@phppatterns.com> Port to PEAR + more |
-// | Authors: Many @ Sitepointforums Advanced PHP Forums |
-// +----------------------------------------------------------------------+
-//
-// $Id$
-//
-/**
-* Decorators for dealing with parser options
-* @package System.Security.SafeHtml
-* @version $Id$
-* @see TSax3::set_option
-*/
-/**
-* Trims the contents of element data from whitespace at start and end
-* @package System.Security.SafeHtml
-* @access protected
-*/
-class TSax3_Trim {
- /**
- * Original handler object
- * @var object
- * @access private
- */
- private $orig_obj;
- /**
- * Original handler method
- * @var string
- * @access private
- */
- private $orig_method;
- /**
- * Constructs TSax3_Trim
- * @param object handler object being decorated
- * @param string original handler method
- * @access protected
- */
- function __construct(&$orig_obj, $orig_method) {
- $this->orig_obj =& $orig_obj;
- $this->orig_method = $orig_method;
- }
- /**
- * Trims the data
- * @param TSax3
- * @param string element data
- * @access protected
- */
- function trimData(&$parser, $data) {
- $data = trim($data);
- if ($data != '') {
- $this->orig_obj->{$this->orig_method}($parser, $data);
- }
- }
-}
-/**
-* Coverts tag names to upper case
-* @package System.Security.SafeHtml
-* @access protected
-*/
-class TSax3_CaseFolding {
- /**
- * Original handler object
- * @var object
- * @access private
- */
- private $orig_obj;
- /**
- * Original open handler method
- * @var string
- * @access private
- */
- private $orig_open_method;
- /**
- * Original close handler method
- * @var string
- * @access private
- */
- private $orig_close_method;
- /**
- * Constructs TSax3_CaseFolding
- * @param object handler object being decorated
- * @param string original open handler method
- * @param string original close handler method
- * @access protected
- */
- function __construct(&$orig_obj, $orig_open_method, $orig_close_method) {
- $this->orig_obj =& $orig_obj;
- $this->orig_open_method = $orig_open_method;
- $this->orig_close_method = $orig_close_method;
- }
- /**
- * Folds up open tag callbacks
- * @param TSax3
- * @param string tag name
- * @param array tag attributes
- * @access protected
- */
- function foldOpen(&$parser, $tag, $attrs=array(), $empty = FALSE) {
- $this->orig_obj->{$this->orig_open_method}($parser, strtoupper($tag), $attrs, $empty);
- }
- /**
- * Folds up close tag callbacks
- * @param TSax3
- * @param string tag name
- * @access protected
- */
- function foldClose(&$parser, $tag, $empty = FALSE) {
- $this->orig_obj->{$this->orig_close_method}($parser, strtoupper($tag), $empty);
- }
-}
-/**
-* Breaks up data by linefeed characters, resulting in additional
-* calls to the data handler
-* @package System.Security.SafeHtml
-* @access protected
-*/
-class TSax3_Linefeed {
- /**
- * Original handler object
- * @var object
- * @access private
- */
- private $orig_obj;
- /**
- * Original handler method
- * @var string
- * @access private
- */
- private $orig_method;
- /**
- * Constructs TSax3_LineFeed
- * @param object handler object being decorated
- * @param string original handler method
- * @access protected
- */
- function __construct(&$orig_obj, $orig_method) {
- $this->orig_obj =& $orig_obj;
- $this->orig_method = $orig_method;
- }
- /**
- * Breaks the data up by linefeeds
- * @param TSax3
- * @param string element data
- * @access protected
- */
- function breakData(&$parser, $data) {
- $data = explode("\n",$data);
- foreach ( $data as $chunk ) {
- $this->orig_obj->{$this->orig_method}($parser, $chunk);
- }
- }
-}
-/**
-* Breaks up data by tab characters, resulting in additional
-* calls to the data handler
-* @package System.Security.SafeHtml
-* @access protected
-*/
-class TSax3_Tab {
- /**
- * Original handler object
- * @var object
- * @access private
- */
- private $orig_obj;
- /**
- * Original handler method
- * @var string
- * @access private
- */
- private $orig_method;
- /**
- * Constructs TSax3_Tab
- * @param object handler object being decorated
- * @param string original handler method
- * @access protected
- */
- function __construct(&$orig_obj, $orig_method) {
- $this->orig_obj =& $orig_obj;
- $this->orig_method = $orig_method;
- }
- /**
- * Breaks the data up by linefeeds
- * @param TSax3
- * @param string element data
- * @access protected
- */
- function breakData(&$parser, $data) {
- $data = explode("\t",$data);
- foreach ( $data as $chunk ) {
- $this->orig_obj->{$this->orig_method}($this, $chunk);
- }
- }
-}
-/**
-* Breaks up data by XML entities and parses them with html_entity_decode(),
-* resulting in additional calls to the data handler<br />
-* Requires PHP 4.3.0+
-* @package System.Security.SafeHtml
-* @access protected
-*/
-class TSax3_Entities_Parsed {
- /**
- * Original handler object
- * @var object
- * @access private
- */
- private $orig_obj;
- /**
- * Original handler method
- * @var string
- * @access private
- */
- private $orig_method;
- /**
- * Constructs TSax3_Entities_Parsed
- * @param object handler object being decorated
- * @param string original handler method
- * @access protected
- */
- function __construct(&$orig_obj, $orig_method) {
- $this->orig_obj =& $orig_obj;
- $this->orig_method = $orig_method;
- }
- /**
- * Breaks the data up by XML entities
- * @param TSax3
- * @param string element data
- * @access protected
- */
- function breakData(&$parser, $data) {
- $data = preg_split('/(&.+?;)/',$data,-1,PREG_SPLIT_DELIM_CAPTURE | PREG_SPLIT_NO_EMPTY);
- foreach ( $data as $chunk ) {
- $chunk = html_entity_decode($chunk,ENT_NOQUOTES);
- $this->orig_obj->{$this->orig_method}($this, $chunk);
- }
- }
-}
-/**
-* Compatibility with older PHP versions
-*/
-if (version_compare(phpversion(), '4.3', '<') && !function_exists('html_entity_decode') ) {
- function html_entity_decode($str, $style=ENT_NOQUOTES) {
- return strtr($str,
- array_flip(get_html_translation_table(HTML_ENTITIES,$style)));
- }
-}
-/**
-* Breaks up data by XML entities but leaves them unparsed,
-* resulting in additional calls to the data handler<br />
-* @package System.Security.SafeHtml
-* @access protected
-*/
-class TSax3_Entities_Unparsed {
- /**
- * Original handler object
- * @var object
- * @access private
- */
- private $orig_obj;
- /**
- * Original handler method
- * @var string
- * @access private
- */
- private $orig_method;
- /**
- * Constructs TSax3_Entities_Unparsed
- * @param object handler object being decorated
- * @param string original handler method
- * @access protected
- */
- function __construct(&$orig_obj, $orig_method) {
- $this->orig_obj =& $orig_obj;
- $this->orig_method = $orig_method;
- }
- /**
- * Breaks the data up by XML entities
- * @param TSax3
- * @param string element data
- * @access protected
- */
- function breakData(&$parser, $data) {
- $data = preg_split('/(&.+?;)/',$data,-1,PREG_SPLIT_DELIM_CAPTURE | PREG_SPLIT_NO_EMPTY);
- foreach ( $data as $chunk ) {
- $this->orig_obj->{$this->orig_method}($this, $chunk);
- }
- }
-}
-
-/**
-* Strips the HTML comment markers or CDATA sections from an escape.
-* If XML_OPTIONS_FULL_ESCAPES is on, this decorator is not used.<br />
-* @package System.Security.SafeHtml
-* @access protected
-*/
-class TSax3_Escape_Stripper {
- /**
- * Original handler object
- * @var object
- * @access private
- */
- private $orig_obj;
- /**
- * Original handler method
- * @var string
- * @access private
- */
- private $orig_method;
- /**
- * Constructs TSax3_Entities_Unparsed
- * @param object handler object being decorated
- * @param string original handler method
- * @access protected
- */
- function __construct(&$orig_obj, $orig_method) {
- $this->orig_obj =& $orig_obj;
- $this->orig_method = $orig_method;
- }
- /**
- * Breaks the data up by XML entities
- * @param TSax3
- * @param string element data
- * @access protected
- */
- function strip(&$parser, $data) {
- // Check for HTML comments first
- if ( substr($data,0,2) == '--' ) {
- $patterns = array(
- '/^\-\-/', // Opening comment: --
- '/\-\-$/', // Closing comment: --
- );
- $data = preg_replace($patterns,'',$data);
-
- // Check for XML CDATA sections (note: don't do both!)
- } else if ( substr($data,0,1) == '[' ) {
- $patterns = array(
- '/^\[.*CDATA.*\[/s', // Opening CDATA
- '/\].*\]$/s', // Closing CDATA
- );
- $data = preg_replace($patterns,'',$data);
- }
-
- $this->orig_obj->{$this->orig_method}($this, $data);
- }
-}
+<?php
+/* vim: set expandtab tabstop=4 shiftwidth=4: */
+//
+// +----------------------------------------------------------------------+
+// | PHP Version 4 |
+// +----------------------------------------------------------------------+
+// | Copyright (c) 1997-2002 The PHP Group |
+// +----------------------------------------------------------------------+
+// | This source file is subject to version 2.02 of the PHP license, |
+// | that is bundled with this package in the file LICENSE, and is |
+// | available at through the world-wide-web at |
+// | http://www.php.net/license/3_0.txt. |
+// | If you did not receive a copy of the PHP license and are unable to |
+// | obtain it through the world-wide-web, please send a note to |
+// | license@php.net so we can mail you a copy immediately. |
+// +----------------------------------------------------------------------+
+// | Authors: Alexander Zhukov <alex@veresk.ru> Original port from Python |
+// | Authors: Harry Fuecks <hfuecks@phppatterns.com> Port to PEAR + more |
+// | Authors: Many @ Sitepointforums Advanced PHP Forums |
+// +----------------------------------------------------------------------+
+//
+// $Id$
+//
+/**
+* Decorators for dealing with parser options
+* @package System.Security.SafeHtml
+* @version $Id$
+* @see TSax3::set_option
+*/
+/**
+* Trims the contents of element data from whitespace at start and end
+* @package System.Security.SafeHtml
+* @access protected
+*/
+class TSax3_Trim {
+ /**
+ * Original handler object
+ * @var object
+ * @access private
+ */
+ private $orig_obj;
+ /**
+ * Original handler method
+ * @var string
+ * @access private
+ */
+ private $orig_method;
+ /**
+ * Constructs TSax3_Trim
+ * @param object handler object being decorated
+ * @param string original handler method
+ * @access protected
+ */
+ function __construct(&$orig_obj, $orig_method) {
+ $this->orig_obj =& $orig_obj;
+ $this->orig_method = $orig_method;
+ }
+ /**
+ * Trims the data
+ * @param TSax3
+ * @param string element data
+ * @access protected
+ */
+ function trimData(&$parser, $data) {
+ $data = trim($data);
+ if ($data != '') {
+ $this->orig_obj->{$this->orig_method}($parser, $data);
+ }
+ }
+}
+/**
+* Coverts tag names to upper case
+* @package System.Security.SafeHtml
+* @access protected
+*/
+class TSax3_CaseFolding {
+ /**
+ * Original handler object
+ * @var object
+ * @access private
+ */
+ private $orig_obj;
+ /**
+ * Original open handler method
+ * @var string
+ * @access private
+ */
+ private $orig_open_method;
+ /**
+ * Original close handler method
+ * @var string
+ * @access private
+ */
+ private $orig_close_method;
+ /**
+ * Constructs TSax3_CaseFolding
+ * @param object handler object being decorated
+ * @param string original open handler method
+ * @param string original close handler method
+ * @access protected
+ */
+ function __construct(&$orig_obj, $orig_open_method, $orig_close_method) {
+ $this->orig_obj =& $orig_obj;
+ $this->orig_open_method = $orig_open_method;
+ $this->orig_close_method = $orig_close_method;
+ }
+ /**
+ * Folds up open tag callbacks
+ * @param TSax3
+ * @param string tag name
+ * @param array tag attributes
+ * @access protected
+ */
+ function foldOpen(&$parser, $tag, $attrs=array(), $empty = FALSE) {
+ $this->orig_obj->{$this->orig_open_method}($parser, strtoupper($tag), $attrs, $empty);
+ }
+ /**
+ * Folds up close tag callbacks
+ * @param TSax3
+ * @param string tag name
+ * @access protected
+ */
+ function foldClose(&$parser, $tag, $empty = FALSE) {
+ $this->orig_obj->{$this->orig_close_method}($parser, strtoupper($tag), $empty);
+ }
+}
+/**
+* Breaks up data by linefeed characters, resulting in additional
+* calls to the data handler
+* @package System.Security.SafeHtml
+* @access protected
+*/
+class TSax3_Linefeed {
+ /**
+ * Original handler object
+ * @var object
+ * @access private
+ */
+ private $orig_obj;
+ /**
+ * Original handler method
+ * @var string
+ * @access private
+ */
+ private $orig_method;
+ /**
+ * Constructs TSax3_LineFeed
+ * @param object handler object being decorated
+ * @param string original handler method
+ * @access protected
+ */
+ function __construct(&$orig_obj, $orig_method) {
+ $this->orig_obj =& $orig_obj;
+ $this->orig_method = $orig_method;
+ }
+ /**
+ * Breaks the data up by linefeeds
+ * @param TSax3
+ * @param string element data
+ * @access protected
+ */
+ function breakData(&$parser, $data) {
+ $data = explode("\n",$data);
+ foreach ( $data as $chunk ) {
+ $this->orig_obj->{$this->orig_method}($parser, $chunk);
+ }
+ }
+}
+/**
+* Breaks up data by tab characters, resulting in additional
+* calls to the data handler
+* @package System.Security.SafeHtml
+* @access protected
+*/
+class TSax3_Tab {
+ /**
+ * Original handler object
+ * @var object
+ * @access private
+ */
+ private $orig_obj;
+ /**
+ * Original handler method
+ * @var string
+ * @access private
+ */
+ private $orig_method;
+ /**
+ * Constructs TSax3_Tab
+ * @param object handler object being decorated
+ * @param string original handler method
+ * @access protected
+ */
+ function __construct(&$orig_obj, $orig_method) {
+ $this->orig_obj =& $orig_obj;
+ $this->orig_method = $orig_method;
+ }
+ /**
+ * Breaks the data up by linefeeds
+ * @param TSax3
+ * @param string element data
+ * @access protected
+ */
+ function breakData(&$parser, $data) {
+ $data = explode("\t",$data);
+ foreach ( $data as $chunk ) {
+ $this->orig_obj->{$this->orig_method}($this, $chunk);
+ }
+ }
+}
+/**
+* Breaks up data by XML entities and parses them with html_entity_decode(),
+* resulting in additional calls to the data handler<br />
+* Requires PHP 4.3.0+
+* @package System.Security.SafeHtml
+* @access protected
+*/
+class TSax3_Entities_Parsed {
+ /**
+ * Original handler object
+ * @var object
+ * @access private
+ */
+ private $orig_obj;
+ /**
+ * Original handler method
+ * @var string
+ * @access private
+ */
+ private $orig_method;
+ /**
+ * Constructs TSax3_Entities_Parsed
+ * @param object handler object being decorated
+ * @param string original handler method
+ * @access protected
+ */
+ function __construct(&$orig_obj, $orig_method) {
+ $this->orig_obj =& $orig_obj;
+ $this->orig_method = $orig_method;
+ }
+ /**
+ * Breaks the data up by XML entities
+ * @param TSax3
+ * @param string element data
+ * @access protected
+ */
+ function breakData(&$parser, $data) {
+ $data = preg_split('/(&.+?;)/',$data,-1,PREG_SPLIT_DELIM_CAPTURE | PREG_SPLIT_NO_EMPTY);
+ foreach ( $data as $chunk ) {
+ $chunk = html_entity_decode($chunk,ENT_NOQUOTES);
+ $this->orig_obj->{$this->orig_method}($this, $chunk);
+ }
+ }
+}
+/**
+* Compatibility with older PHP versions
+*/
+if (version_compare(phpversion(), '4.3', '<') && !function_exists('html_entity_decode') ) {
+ function html_entity_decode($str, $style=ENT_NOQUOTES) {
+ return strtr($str,
+ array_flip(get_html_translation_table(HTML_ENTITIES,$style)));
+ }
+}
+/**
+* Breaks up data by XML entities but leaves them unparsed,
+* resulting in additional calls to the data handler<br />
+* @package System.Security.SafeHtml
+* @access protected
+*/
+class TSax3_Entities_Unparsed {
+ /**
+ * Original handler object
+ * @var object
+ * @access private
+ */
+ private $orig_obj;
+ /**
+ * Original handler method
+ * @var string
+ * @access private
+ */
+ private $orig_method;
+ /**
+ * Constructs TSax3_Entities_Unparsed
+ * @param object handler object being decorated
+ * @param string original handler method
+ * @access protected
+ */
+ function __construct(&$orig_obj, $orig_method) {
+ $this->orig_obj =& $orig_obj;
+ $this->orig_method = $orig_method;
+ }
+ /**
+ * Breaks the data up by XML entities
+ * @param TSax3
+ * @param string element data
+ * @access protected
+ */
+ function breakData(&$parser, $data) {
+ $data = preg_split('/(&.+?;)/',$data,-1,PREG_SPLIT_DELIM_CAPTURE | PREG_SPLIT_NO_EMPTY);
+ foreach ( $data as $chunk ) {
+ $this->orig_obj->{$this->orig_method}($this, $chunk);
+ }
+ }
+}
+
+/**
+* Strips the HTML comment markers or CDATA sections from an escape.
+* If XML_OPTIONS_FULL_ESCAPES is on, this decorator is not used.<br />
+* @package System.Security.SafeHtml
+* @access protected
+*/
+class TSax3_Escape_Stripper {
+ /**
+ * Original handler object
+ * @var object
+ * @access private
+ */
+ private $orig_obj;
+ /**
+ * Original handler method
+ * @var string
+ * @access private
+ */
+ private $orig_method;
+ /**
+ * Constructs TSax3_Entities_Unparsed
+ * @param object handler object being decorated
+ * @param string original handler method
+ * @access protected
+ */
+ function __construct(&$orig_obj, $orig_method) {
+ $this->orig_obj =& $orig_obj;
+ $this->orig_method = $orig_method;
+ }
+ /**
+ * Breaks the data up by XML entities
+ * @param TSax3
+ * @param string element data
+ * @access protected
+ */
+ function strip(&$parser, $data) {
+ // Check for HTML comments first
+ if ( substr($data,0,2) == '--' ) {
+ $patterns = array(
+ '/^\-\-/', // Opening comment: --
+ '/\-\-$/', // Closing comment: --
+ );
+ $data = preg_replace($patterns,'',$data);
+
+ // Check for XML CDATA sections (note: don't do both!)
+ } else if ( substr($data,0,1) == '[' ) {
+ $patterns = array(
+ '/^\[.*CDATA.*\[/s', // Opening CDATA
+ '/\].*\]$/s', // Closing CDATA
+ );
+ $data = preg_replace($patterns,'',$data);
+ }
+
+ $this->orig_obj->{$this->orig_method}($this, $data);
+ }
+}
?> \ No newline at end of file
diff --git a/framework/3rdParty/SafeHtml/HTMLSax3/States.php b/framework/3rdParty/SafeHtml/HTMLSax3/States.php
index 6dfead17..7d7b9b34 100644
--- a/framework/3rdParty/SafeHtml/HTMLSax3/States.php
+++ b/framework/3rdParty/SafeHtml/HTMLSax3/States.php
@@ -1,288 +1,288 @@
-<?php
-/* vim: set expandtab tabstop=4 shiftwidth=4: */
-//
-// +----------------------------------------------------------------------+
-// | PHP Version 4 |
-// +----------------------------------------------------------------------+
-// | Copyright (c) 1997-2002 The PHP Group |
-// +----------------------------------------------------------------------+
-// | This source file is subject to version 2.02 of the PHP license, |
-// | that is bundled with this package in the file LICENSE, and is |
-// | available at through the world-wide-web at |
-// | http://www.php.net/license/3_0.txt. |
-// | If you did not receive a copy of the PHP license and are unable to |
-// | obtain it through the world-wide-web, please send a note to |
-// | license@php.net so we can mail you a copy immediately. |
-// +----------------------------------------------------------------------+
-// | Authors: Alexander Zhukov <alex@veresk.ru> Original port from Python |
-// | Authors: Harry Fuecks <hfuecks@phppatterns.com> Port to PEAR + more |
-// | Authors: Many @ Sitepointforums Advanced PHP Forums |
-// +----------------------------------------------------------------------+
-//
-// $Id$
-//
-/**
-* Parsing states.
-* @package System.Security.SafeHtml
-* @version $Id$
-*/
-/**
-* Define parser states
-*/
-/*define('TSAX3_STATE_STOP', 0);
-define('TSAX3_STATE_START', 1);
-define('TSAX3_STATE_TAG', 2);
-define('TSAX3_STATE_OPENING_TAG', 3);
-define('TSAX3_STATE_CLOSING_TAG', 4);
-define('TSAX3_STATE_ESCAPE', 6);
-define('TSAX3_STATE_JASP', 7);
-define('TSAX3_STATE_PI', 8);
-*/
-/**
-* StartingState searches for the start of any XML tag
-* @package System.Security.SafeHtml
-* @access protected
-*/
-class TSax3_StartingState {
- /**
- * @param TSax3_StateParser subclass
- * @return constant TSAX3_STATE_TAG
- * @access protected
- */
- function parse(&$context) {
- $data = $context->scanUntilString('<');
- if ($data != '') {
- $context->handler_object_data->
- {$context->handler_method_data}($context->htmlsax, $data);
- }
- $context->IgnoreCharacter();
- return TSax3_StateParser::TSAX3_STATE_TAG;
- }
-}
-/**
-* Decides which state to move one from after StartingState
-* @package System.Security.SafeHtml
-* @access protected
-*/
-class TSax3_TagState {
- /**
- * @param TSax3_StateParser subclass
- * @return constant the next state to move into
- * @access protected
- */
- function parse(&$context) {
- switch($context->ScanCharacter()) {
- case '/':
- return TSax3_StateParser::TSAX3_STATE_CLOSING_TAG;
- break;
- case '?':
- return TSax3_StateParser::TSAX3_STATE_PI;
- break;
- case '%':
- return TSax3_StateParser::TSAX3_STATE_JASP;
- break;
- case '!':
- return TSax3_StateParser::TSAX3_STATE_ESCAPE;
- break;
- default:
- $context->unscanCharacter();
- return TSax3_StateParser::TSAX3_STATE_OPENING_TAG;
- }
- }
-}
-/**
-* Dealing with closing XML tags
-* @package System.Security.SafeHtml
-* @access protected
-*/
-class TSax3_ClosingTagState {
- /**
- * @param TSax3_StateParser subclass
- * @return constant TSAX3_STATE_START
- * @access protected
- */
- function parse(&$context) {
- $tag = $context->scanUntilCharacters('/>');
- if ($tag != '') {
- $char = $context->scanCharacter();
- if ($char == '/') {
- $char = $context->scanCharacter();
- if ($char != '>') {
- $context->unscanCharacter();
- }
- }
- $context->handler_object_element->
- {$context->handler_method_closing}($context->htmlsax, $tag, FALSE);
- }
- return TSax3_StateParser::TSAX3_STATE_START;
- }
-}
-/**
-* Dealing with opening XML tags
-* @package System.Security.SafeHtml
-* @access protected
-*/
-class TSax3_OpeningTagState {
- /**
- * Handles attributes
- * @param string attribute name
- * @param string attribute value
- * @return void
- * @access protected
- * @see TSax3_AttributeStartState
- */
- function parseAttributes(&$context) {
- $Attributes = array();
-
- $context->ignoreWhitespace();
- $attributename = $context->scanUntilCharacters("=/> \n\r\t");
- while ($attributename != '') {
- $attributevalue = NULL;
- $context->ignoreWhitespace();
- $char = $context->scanCharacter();
- if ($char == '=') {
- $context->ignoreWhitespace();
- $char = $context->ScanCharacter();
- if ($char == '"') {
- $attributevalue= $context->scanUntilString('"');
- $context->IgnoreCharacter();
- } else if ($char == "'") {
- $attributevalue = $context->scanUntilString("'");
- $context->IgnoreCharacter();
- } else {
- $context->unscanCharacter();
- $attributevalue =
- $context->scanUntilCharacters("> \n\r\t");
- }
- } else if ($char !== NULL) {
- $attributevalue = NULL;
- $context->unscanCharacter();
- }
- $Attributes[$attributename] = $attributevalue;
-
- $context->ignoreWhitespace();
- $attributename = $context->scanUntilCharacters("=/> \n\r\t");
- }
- return $Attributes;
- }
-
- /**
- * @param TSax3_StateParser subclass
- * @return constant TSAX3_STATE_START
- * @access protected
- */
- function parse(&$context) {
- $tag = $context->scanUntilCharacters("/> \n\r\t");
- if ($tag != '') {
- $this->attrs = array();
- $Attributes = $this->parseAttributes($context);
- $char = $context->scanCharacter();
- if ($char == '/') {
- $char = $context->scanCharacter();
- if ($char != '>') {
- $context->unscanCharacter();
- }
- $context->handler_object_element->
- {$context->handler_method_opening}($context->htmlsax, $tag,
- $Attributes, TRUE);
- $context->handler_object_element->
- {$context->handler_method_closing}($context->htmlsax, $tag,
- TRUE);
- } else {
- $context->handler_object_element->
- {$context->handler_method_opening}($context->htmlsax, $tag,
- $Attributes, FALSE);
- }
- }
- return TSax3_StateParser::TSAX3_STATE_START;
- }
-}
-
-/**
-* Deals with XML escapes handling comments and CDATA correctly
-* @package System.Security.SafeHtml
-* @access protected
-*/
-class TSax3_EscapeState {
- /**
- * @param TSax3_StateParser subclass
- * @return constant TSAX3_STATE_START
- * @access protected
- */
- function parse(&$context) {
- $char = $context->ScanCharacter();
- if ($char == '-') {
- $char = $context->ScanCharacter();
- if ($char == '-') {
- $context->unscanCharacter();
- $context->unscanCharacter();
- $text = $context->scanUntilString('-->');
- $text .= $context->scanCharacter();
- $text .= $context->scanCharacter();
- } else {
- $context->unscanCharacter();
- $text = $context->scanUntilString('>');
- }
- } else if ( $char == '[') {
- $context->unscanCharacter();
- $text = $context->scanUntilString(']>');
- $text.= $context->scanCharacter();
- } else {
- $context->unscanCharacter();
- $text = $context->scanUntilString('>');
- }
-
- $context->IgnoreCharacter();
- if ($text != '') {
- $context->handler_object_escape->
- {$context->handler_method_escape}($context->htmlsax, $text);
- }
- return TSax3_StateParser::TSAX3_STATE_START;
- }
-}
-/**
-* Deals with JASP/ASP markup
-* @package System.Security.SafeHtml
-* @access protected
-*/
-class TSax3_JaspState {
- /**
- * @param TSax3_StateParser subclass
- * @return constant TSAX3_STATE_START
- * @access protected
- */
- function parse(&$context) {
- $text = $context->scanUntilString('%>');
- if ($text != '') {
- $context->handler_object_jasp->
- {$context->handler_method_jasp}($context->htmlsax, $text);
- }
- $context->IgnoreCharacter();
- $context->IgnoreCharacter();
- return TSax3_StateParser::TSAX3_STATE_START;
- }
-}
-/**
-* Deals with XML processing instructions
-* @package System.Security.SafeHtml
-* @access protected
-*/
-class TSax3_PiState {
- /**
- * @param TSax3_StateParser subclass
- * @return constant TSAX3_STATE_START
- * @access protected
- */
- function parse(&$context) {
- $target = $context->scanUntilCharacters(" \n\r\t");
- $data = $context->scanUntilString('?>');
- if ($data != '') {
- $context->handler_object_pi->
- {$context->handler_method_pi}($context->htmlsax, $target, $data);
- }
- $context->IgnoreCharacter();
- $context->IgnoreCharacter();
- return TSax3_StateParser::TSAX3_STATE_START;
- }
-}
+<?php
+/* vim: set expandtab tabstop=4 shiftwidth=4: */
+//
+// +----------------------------------------------------------------------+
+// | PHP Version 4 |
+// +----------------------------------------------------------------------+
+// | Copyright (c) 1997-2002 The PHP Group |
+// +----------------------------------------------------------------------+
+// | This source file is subject to version 2.02 of the PHP license, |
+// | that is bundled with this package in the file LICENSE, and is |
+// | available at through the world-wide-web at |
+// | http://www.php.net/license/3_0.txt. |
+// | If you did not receive a copy of the PHP license and are unable to |
+// | obtain it through the world-wide-web, please send a note to |
+// | license@php.net so we can mail you a copy immediately. |
+// +----------------------------------------------------------------------+
+// | Authors: Alexander Zhukov <alex@veresk.ru> Original port from Python |
+// | Authors: Harry Fuecks <hfuecks@phppatterns.com> Port to PEAR + more |
+// | Authors: Many @ Sitepointforums Advanced PHP Forums |
+// +----------------------------------------------------------------------+
+//
+// $Id$
+//
+/**
+* Parsing states.
+* @package System.Security.SafeHtml
+* @version $Id$
+*/
+/**
+* Define parser states
+*/
+/*define('TSAX3_STATE_STOP', 0);
+define('TSAX3_STATE_START', 1);
+define('TSAX3_STATE_TAG', 2);
+define('TSAX3_STATE_OPENING_TAG', 3);
+define('TSAX3_STATE_CLOSING_TAG', 4);
+define('TSAX3_STATE_ESCAPE', 6);
+define('TSAX3_STATE_JASP', 7);
+define('TSAX3_STATE_PI', 8);
+*/
+/**
+* StartingState searches for the start of any XML tag
+* @package System.Security.SafeHtml
+* @access protected
+*/
+class TSax3_StartingState {
+ /**
+ * @param TSax3_StateParser subclass
+ * @return constant TSAX3_STATE_TAG
+ * @access protected
+ */
+ function parse(&$context) {
+ $data = $context->scanUntilString('<');
+ if ($data != '') {
+ $context->handler_object_data->
+ {$context->handler_method_data}($context->htmlsax, $data);
+ }
+ $context->IgnoreCharacter();
+ return TSax3_StateParser::TSAX3_STATE_TAG;
+ }
+}
+/**
+* Decides which state to move one from after StartingState
+* @package System.Security.SafeHtml
+* @access protected
+*/
+class TSax3_TagState {
+ /**
+ * @param TSax3_StateParser subclass
+ * @return constant the next state to move into
+ * @access protected
+ */
+ function parse(&$context) {
+ switch($context->ScanCharacter()) {
+ case '/':
+ return TSax3_StateParser::TSAX3_STATE_CLOSING_TAG;
+ break;
+ case '?':
+ return TSax3_StateParser::TSAX3_STATE_PI;
+ break;
+ case '%':
+ return TSax3_StateParser::TSAX3_STATE_JASP;
+ break;
+ case '!':
+ return TSax3_StateParser::TSAX3_STATE_ESCAPE;
+ break;
+ default:
+ $context->unscanCharacter();
+ return TSax3_StateParser::TSAX3_STATE_OPENING_TAG;
+ }
+ }
+}
+/**
+* Dealing with closing XML tags
+* @package System.Security.SafeHtml
+* @access protected
+*/
+class TSax3_ClosingTagState {
+ /**
+ * @param TSax3_StateParser subclass
+ * @return constant TSAX3_STATE_START
+ * @access protected
+ */
+ function parse(&$context) {
+ $tag = $context->scanUntilCharacters('/>');
+ if ($tag != '') {
+ $char = $context->scanCharacter();
+ if ($char == '/') {
+ $char = $context->scanCharacter();
+ if ($char != '>') {
+ $context->unscanCharacter();
+ }
+ }
+ $context->handler_object_element->
+ {$context->handler_method_closing}($context->htmlsax, $tag, FALSE);
+ }
+ return TSax3_StateParser::TSAX3_STATE_START;
+ }
+}
+/**
+* Dealing with opening XML tags
+* @package System.Security.SafeHtml
+* @access protected
+*/
+class TSax3_OpeningTagState {
+ /**
+ * Handles attributes
+ * @param string attribute name
+ * @param string attribute value
+ * @return void
+ * @access protected
+ * @see TSax3_AttributeStartState
+ */
+ function parseAttributes(&$context) {
+ $Attributes = array();
+
+ $context->ignoreWhitespace();
+ $attributename = $context->scanUntilCharacters("=/> \n\r\t");
+ while ($attributename != '') {
+ $attributevalue = NULL;
+ $context->ignoreWhitespace();
+ $char = $context->scanCharacter();
+ if ($char == '=') {
+ $context->ignoreWhitespace();
+ $char = $context->ScanCharacter();
+ if ($char == '"') {
+ $attributevalue= $context->scanUntilString('"');
+ $context->IgnoreCharacter();
+ } else if ($char == "'") {
+ $attributevalue = $context->scanUntilString("'");
+ $context->IgnoreCharacter();
+ } else {
+ $context->unscanCharacter();
+ $attributevalue =
+ $context->scanUntilCharacters("> \n\r\t");
+ }
+ } else if ($char !== NULL) {
+ $attributevalue = NULL;
+ $context->unscanCharacter();
+ }
+ $Attributes[$attributename] = $attributevalue;
+
+ $context->ignoreWhitespace();
+ $attributename = $context->scanUntilCharacters("=/> \n\r\t");
+ }
+ return $Attributes;
+ }
+
+ /**
+ * @param TSax3_StateParser subclass
+ * @return constant TSAX3_STATE_START
+ * @access protected
+ */
+ function parse(&$context) {
+ $tag = $context->scanUntilCharacters("/> \n\r\t");
+ if ($tag != '') {
+ $this->attrs = array();
+ $Attributes = $this->parseAttributes($context);
+ $char = $context->scanCharacter();
+ if ($char == '/') {
+ $char = $context->scanCharacter();
+ if ($char != '>') {
+ $context->unscanCharacter();
+ }
+ $context->handler_object_element->
+ {$context->handler_method_opening}($context->htmlsax, $tag,
+ $Attributes, TRUE);
+ $context->handler_object_element->
+ {$context->handler_method_closing}($context->htmlsax, $tag,
+ TRUE);
+ } else {
+ $context->handler_object_element->
+ {$context->handler_method_opening}($context->htmlsax, $tag,
+ $Attributes, FALSE);
+ }
+ }
+ return TSax3_StateParser::TSAX3_STATE_START;
+ }
+}
+
+/**
+* Deals with XML escapes handling comments and CDATA correctly
+* @package System.Security.SafeHtml
+* @access protected
+*/
+class TSax3_EscapeState {
+ /**
+ * @param TSax3_StateParser subclass
+ * @return constant TSAX3_STATE_START
+ * @access protected
+ */
+ function parse(&$context) {
+ $char = $context->ScanCharacter();
+ if ($char == '-') {
+ $char = $context->ScanCharacter();
+ if ($char == '-') {
+ $context->unscanCharacter();
+ $context->unscanCharacter();
+ $text = $context->scanUntilString('-->');
+ $text .= $context->scanCharacter();
+ $text .= $context->scanCharacter();
+ } else {
+ $context->unscanCharacter();
+ $text = $context->scanUntilString('>');
+ }
+ } else if ( $char == '[') {
+ $context->unscanCharacter();
+ $text = $context->scanUntilString(']>');
+ $text.= $context->scanCharacter();
+ } else {
+ $context->unscanCharacter();
+ $text = $context->scanUntilString('>');
+ }
+
+ $context->IgnoreCharacter();
+ if ($text != '') {
+ $context->handler_object_escape->
+ {$context->handler_method_escape}($context->htmlsax, $text);
+ }
+ return TSax3_StateParser::TSAX3_STATE_START;
+ }
+}
+/**
+* Deals with JASP/ASP markup
+* @package System.Security.SafeHtml
+* @access protected
+*/
+class TSax3_JaspState {
+ /**
+ * @param TSax3_StateParser subclass
+ * @return constant TSAX3_STATE_START
+ * @access protected
+ */
+ function parse(&$context) {
+ $text = $context->scanUntilString('%>');
+ if ($text != '') {
+ $context->handler_object_jasp->
+ {$context->handler_method_jasp}($context->htmlsax, $text);
+ }
+ $context->IgnoreCharacter();
+ $context->IgnoreCharacter();
+ return TSax3_StateParser::TSAX3_STATE_START;
+ }
+}
+/**
+* Deals with XML processing instructions
+* @package System.Security.SafeHtml
+* @access protected
+*/
+class TSax3_PiState {
+ /**
+ * @param TSax3_StateParser subclass
+ * @return constant TSAX3_STATE_START
+ * @access protected
+ */
+ function parse(&$context) {
+ $target = $context->scanUntilCharacters(" \n\r\t");
+ $data = $context->scanUntilString('?>');
+ if ($data != '') {
+ $context->handler_object_pi->
+ {$context->handler_method_pi}($context->htmlsax, $target, $data);
+ }
+ $context->IgnoreCharacter();
+ $context->IgnoreCharacter();
+ return TSax3_StateParser::TSAX3_STATE_START;
+ }
+}
?> \ No newline at end of file
diff --git a/framework/3rdParty/SafeHtml/TSafeHtmlParser.php b/framework/3rdParty/SafeHtml/TSafeHtmlParser.php
index b80f31a6..ad14baf9 100644
--- a/framework/3rdParty/SafeHtml/TSafeHtmlParser.php
+++ b/framework/3rdParty/SafeHtml/TSafeHtmlParser.php
@@ -1,673 +1,673 @@
-<?php
-/* vim: set expandtab tabstop=4 shiftwidth=4 softtabstop=4: */
-
-/**
- * SafeHTML Parser
- *
- * PHP versions 4 and 5
- *
- * @category HTML
- * @package System.Security
- * @author Roman Ivanov <thingol@mail.ru>
- * @copyright 2004-2005 Roman Ivanov
- * @license http://www.debian.org/misc/bsd.license BSD License (3 Clause)
- * @version 1.3.7
- * @link http://pixel-apes.com/safehtml/
- */
-
-
-/**
- * This package requires HTMLSax3 package
- */
-Prado::using('System.3rdParty.SafeHtml.HTMLSax3');
-
-
-/**
- *
- * TSafeHtmlParser
- *
- * This parser strips down all potentially dangerous content within HTML:
- * <ul>
- * <li>opening tag without its closing tag</li>
- * <li>closing tag without its opening tag</li>
- * <li>any of these tags: "base", "basefont", "head", "html", "body", "applet",
- * "object", "iframe", "frame", "frameset", "script", "layer", "ilayer", "embed",
- * "bgsound", "link", "meta", "style", "title", "blink", "xml" etc.</li>
- * <li>any of these attributes: on*, data*, dynsrc</li>
- * <li>javascript:/vbscript:/about: etc. protocols</li>
- * <li>expression/behavior etc. in styles</li>
- * <li>any other active content</li>
- * </ul>
- * It also tries to convert code to XHTML valid, but htmltidy is far better
- * solution for this task.
- *
- * <b>Example:</b>
- * <pre>
- * $parser = Prado::createComponent('System.3rdParty.SafeHtml.TSafeHtmlParser');
- * $result = $parser->parse($doc);
- * </pre>
- *
- * @category HTML
- * @package System.Security
- * @author Roman Ivanov <thingol@mail.ru>
- * @copyright 1997-2005 Roman Ivanov
- * @license http://www.debian.org/misc/bsd.license BSD License (3 Clause)
- * @version Release: @package_version@
- * @link http://pear.php.net/package/SafeHTML
- */
-class TSafeHtmlParser
-{
- /**
- * Storage for resulting HTML output
- *
- * @var string
- * @access private
- */
- private $_xhtml = '';
-
- /**
- * Array of counters for each tag
- *
- * @var array
- * @access private
- */
- private $_counter = array();
-
- /**
- * Stack of unclosed tags
- *
- * @var array
- * @access private
- */
- private $_stack = array();
-
- /**
- * Array of counters for tags that must be deleted with all content
- *
- * @var array
- * @access private
- */
- private $_dcCounter = array();
-
- /**
- * Stack of unclosed tags that must be deleted with all content
- *
- * @var array
- * @access private
- */
- private $_dcStack = array();
-
- /**
- * Stores level of list (ol/ul) nesting
- *
- * @var int
- * @access private
- */
- private $_listScope = 0;
-
- /**
- * Stack of unclosed list tags
- *
- * @var array
- * @access private
- */
- private $_liStack = array();
-
- /**
- * Array of prepared regular expressions for protocols (schemas) matching
- *
- * @var array
- * @access private
- */
- private $_protoRegexps = array();
-
- /**
- * Array of prepared regular expressions for CSS matching
- *
- * @var array
- * @access private
- */
- private $_cssRegexps = array();
-
- /**
- * List of single tags ("<tag />")
- *
- * @var array
- * @access public
- */
- public $singleTags = array('area', 'br', 'img', 'input', 'hr', 'wbr', );
-
- /**
- * List of dangerous tags (such tags will be deleted)
- *
- * @var array
- * @access public
- */
- public $deleteTags = array(
- 'applet', 'base', 'basefont', 'bgsound', 'blink', 'body',
- 'embed', 'frame', 'frameset', 'head', 'html', 'ilayer',
- 'iframe', 'layer', 'link', 'meta', 'object', 'style',
- 'title', 'script',
- );
-
- /**
- * List of dangerous tags (such tags will be deleted, and all content
- * inside this tags will be also removed)
- *
- * @var array
- * @access public
- */
- public $deleteTagsContent = array('script', 'style', 'title', 'xml', );
-
- /**
- * Type of protocols filtering ('white' or 'black')
- *
- * @var string
- * @access public
- */
- public $protocolFiltering = 'white';
-
- /**
- * List of "dangerous" protocols (used for blacklist-filtering)
- *
- * @var array
- * @access public
- */
- public $blackProtocols = array(
- 'about', 'chrome', 'data', 'disk', 'hcp',
- 'help', 'javascript', 'livescript', 'lynxcgi', 'lynxexec',
- 'ms-help', 'ms-its', 'mhtml', 'mocha', 'opera',
- 'res', 'resource', 'shell', 'vbscript', 'view-source',
- 'vnd.ms.radio', 'wysiwyg',
- );
-
- /**
- * List of "safe" protocols (used for whitelist-filtering)
- *
- * @var array
- * @access public
- */
- public $whiteProtocols = array(
- 'ed2k', 'file', 'ftp', 'gopher', 'http', 'https',
- 'irc', 'mailto', 'news', 'nntp', 'telnet', 'webcal',
- 'xmpp', 'callto',
- );
-
- /**
- * List of attributes that can contain protocols
- *
- * @var array
- * @access public
- */
- public $protocolAttributes = array(
- 'action', 'background', 'codebase', 'dynsrc', 'href', 'lowsrc', 'src',
- );
-
- /**
- * List of dangerous CSS keywords
- *
- * Whole style="" attribute will be removed, if parser will find one of
- * these keywords
- *
- * @var array
- * @access public
- */
- public $cssKeywords = array(
- 'absolute', 'behavior', 'behaviour', 'content', 'expression',
- 'fixed', 'include-source', 'moz-binding',
- );
-
- /**
- * List of tags that can have no "closing tag"
- *
- * @var array
- * @access public
- * @deprecated XHTML does not allow such tags
- */
- public $noClose = array();
-
- /**
- * List of block-level tags that terminates paragraph
- *
- * Paragraph will be closed when this tags opened
- *
- * @var array
- * @access public
- */
- public $closeParagraph = array(
- 'address', 'blockquote', 'center', 'dd', 'dir', 'div',
- 'dl', 'dt', 'h1', 'h2', 'h3', 'h4',
- 'h5', 'h6', 'hr', 'isindex', 'listing', 'marquee',
- 'menu', 'multicol', 'ol', 'p', 'plaintext', 'pre',
- 'table', 'ul', 'xmp',
- );
-
- /**
- * List of table tags, all table tags outside a table will be removed
- *
- * @var array
- * @access public
- */
- public $tableTags = array(
- 'caption', 'col', 'colgroup', 'tbody', 'td', 'tfoot', 'th',
- 'thead', 'tr',
- );
-
- /**
- * List of list tags
- *
- * @var array
- * @access public
- */
- public $listTags = array('dir', 'menu', 'ol', 'ul', 'dl', );
-
- /**
- * List of dangerous attributes
- *
- * @var array
- * @access public
- */
- public $attributes = array('dynsrc');
- //public $attributes = array('dynsrc', 'id', 'name', ); //id and name are dangerous?
-
- /**
- * List of allowed "namespaced" attributes
- *
- * @var array
- * @access public
- */
- public $attributesNS = array('xml:lang', );
-
- /**
- * Constructs class
- *
- * @access public
- */
- public function __construct()
- {
- //making regular expressions based on Proto & CSS arrays
- foreach ($this->blackProtocols as $proto) {
- $preg = "/[\s\x01-\x1F]*";
- for ($i=0; $i<strlen($proto); $i++) {
- $preg .= $proto{$i} . "[\s\x01-\x1F]*";
- }
- $preg .= ":/i";
- $this->_protoRegexps[] = $preg;
- }
-
- foreach ($this->cssKeywords as $css) {
- $this->_cssRegexps[] = '/' . $css . '/i';
- }
- return true;
- }
-
- /**
- * Handles the writing of attributes - called from $this->_openHandler()
- *
- * @param array $attrs array of attributes $name => $value
- * @return boolean
- * @access private
- */
- private function _writeAttrs ($attrs)
- {
- if (is_array($attrs)) {
- foreach ($attrs as $name => $value) {
-
- $name = strtolower($name);
-
- if (strpos($name, 'on') === 0) {
- continue;
- }
- if (strpos($name, 'data') === 0) {
- continue;
- }
- if (in_array($name, $this->attributes)) {
- continue;
- }
- if (!preg_match("/^[a-z0-9]+$/i", $name)) {
- if (!in_array($name, $this->attributesNS))
- {
- continue;
- }
- }
-
- if (($value === TRUE) || (is_null($value))) {
- $value = $name;
- }
-
- if ($name == 'style') {
-
- // removes insignificant backslahes
- $value = str_replace("\\", '', $value);
-
- // removes CSS comments
- while (1)
- {
- $_value = preg_replace("!/\*.*?\*/!s", '', $value);
- if ($_value == $value) break;
- $value = $_value;
- }
-
- // replace all & to &amp;
- $value = str_replace('&amp;', '&', $value);
- $value = str_replace('&', '&amp;', $value);
-
- foreach ($this->_cssRegexps as $css) {
- if (preg_match($css, $value)) {
- continue 2;
- }
- }
- foreach ($this->_protoRegexps as $proto) {
- if (preg_match($proto, $value)) {
- continue 2;
- }
- }
- }
-
- $tempval = preg_replace('/&#(\d+);?/me', "chr('\\1')", $value); //"'
- $tempval = preg_replace('/&#x([0-9a-f]+);?/mei', "chr(hexdec('\\1'))", $tempval);
-
- if ((in_array($name, $this->protocolAttributes)) &&
- (strpos($tempval, ':') !== false))
- {
- if ($this->protocolFiltering == 'black') {
- foreach ($this->_protoRegexps as $proto) {
- if (preg_match($proto, $tempval)) continue 2;
- }
- } else {
- $_tempval = explode(':', $tempval);
- $proto = $_tempval[0];
- if (!in_array($proto, $this->whiteProtocols)) {
- continue;
- }
- }
- }
-
- $value = str_replace("\"", "&quot;", $value);
- $this->_xhtml .= ' ' . $name . '="' . $value . '"';
- }
- }
- return true;
- }
-
- /**
- * Opening tag handler - called from HTMLSax
- *
- * @param object $parser HTML Parser
- * @param string $name tag name
- * @param array $attrs tag attributes
- * @return boolean
- * @access private
- */
- public function _openHandler(&$parser, $name, $attrs)
- {
- $name = strtolower($name);
-
- if (in_array($name, $this->deleteTagsContent)) {
- array_push($this->_dcStack, $name);
- $this->_dcCounter[$name] = isset($this->_dcCounter[$name]) ? $this->_dcCounter[$name]+1 : 1;
- }
- if (count($this->_dcStack) != 0) {
- return true;
- }
-
- if (in_array($name, $this->deleteTags)) {
- return true;
- }
-
- if (!preg_match("/^[a-z0-9]+$/i", $name)) {
- if (preg_match("!(?:\@|://)!i", $name)) {
- $this->_xhtml .= '&lt;' . $name . '&gt;';
- }
- return true;
- }
-
- if (in_array($name, $this->singleTags)) {
- $this->_xhtml .= '<' . $name;
- $this->_writeAttrs($attrs);
- $this->_xhtml .= ' />';
- return true;
- }
-
- // TABLES: cannot open table elements when we are not inside table
- if ((isset($this->_counter['table'])) && ($this->_counter['table'] <= 0)
- && (in_array($name, $this->tableTags)))
- {
- return true;
- }
-
- // PARAGRAPHS: close paragraph when closeParagraph tags opening
- if ((in_array($name, $this->closeParagraph)) && (in_array('p', $this->_stack))) {
- $this->_closeHandler($parser, 'p');
- }
-
- // LISTS: we should close <li> if <li> of the same level opening
- if ($name == 'li' && count($this->_liStack) &&
- $this->_listScope == $this->_liStack[count($this->_liStack)-1])
- {
- $this->_closeHandler($parser, 'li');
- }
-
- // LISTS: we want to know on what nesting level of lists we are
- if (in_array($name, $this->listTags)) {
- $this->_listScope++;
- }
- if ($name == 'li') {
- array_push($this->_liStack, $this->_listScope);
- }
-
- $this->_xhtml .= '<' . $name;
- $this->_writeAttrs($attrs);
- $this->_xhtml .= '>';
- array_push($this->_stack,$name);
- $this->_counter[$name] = isset($this->_counter[$name]) ? $this->_counter[$name]+1 : 1;
- return true;
- }
-
- /**
- * Closing tag handler - called from HTMLSax
- *
- * @param object $parsers HTML parser
- * @param string $name tag name
- * @return boolean
- * @access private
- */
- public function _closeHandler(&$parser, $name)
- {
-
- $name = strtolower($name);
-
- if (isset($this->_dcCounter[$name]) && ($this->_dcCounter[$name] > 0) &&
- (in_array($name, $this->deleteTagsContent)))
- {
- while ($name != ($tag = array_pop($this->_dcStack))) {
- $this->_dcCounter[$tag]--;
- }
-
- $this->_dcCounter[$name]--;
- }
-
- if (count($this->_dcStack) != 0) {
- return true;
- }
-
- if ((isset($this->_counter[$name])) && ($this->_counter[$name] > 0)) {
- while ($name != ($tag = array_pop($this->_stack))) {
- $this->_closeTag($tag);
- }
-
- $this->_closeTag($name);
- }
- return true;
- }
-
- /**
- * Closes tag
- *
- * @param string $tag tag name
- * @return boolean
- * @access private
- */
- public function _closeTag($tag)
- {
- if (!in_array($tag, $this->noClose)) {
- $this->_xhtml .= '</' . $tag . '>';
- }
-
- $this->_counter[$tag]--;
-
- if (in_array($tag, $this->listTags)) {
- $this->_listScope--;
- }
-
- if ($tag == 'li') {
- array_pop($this->_liStack);
- }
- return true;
- }
-
- /**
- * Character data handler - called from HTMLSax
- *
- * @param object $parser HTML parser
- * @param string $data textual data
- * @return boolean
- * @access private
- */
- public function _dataHandler(&$parser, $data)
- {
- if (count($this->_dcStack) == 0) {
- $this->_xhtml .= $data;
- }
- return true;
- }
-
- /**
- * Escape handler - called from HTMLSax
- *
- * @param object $parser HTML parser
- * @param string $data comments or other type of data
- * @return boolean
- * @access private
- */
- public function _escapeHandler(&$parser, $data)
- {
- return true;
- }
-
- /**
- * Returns the XHTML document
- *
- * @return string Processed (X)HTML document
- * @access public
- */
- public function getXHTML ()
- {
- while ($tag = array_pop($this->_stack)) {
- $this->_closeTag($tag);
- }
-
- return $this->_xhtml;
- }
-
- /**
- * Clears current document data
- *
- * @return boolean
- * @access public
- */
- public function clear()
- {
- $this->_xhtml = '';
- return true;
- }
-
- /**
- * Main parsing fuction
- *
- * @param string $doc HTML document for processing
- * @return string Processed (X)HTML document
- * @access public
- */
- public function parse($doc, $isUTF7=false)
- {
- $this->clear();
-
- // Save all '<' symbols
- $doc = preg_replace("/<(?=[^a-zA-Z\/\!\?\%])/", '&lt;', (string)$doc);
-
- // Web documents shouldn't contains \x00 symbol
- $doc = str_replace("\x00", '', $doc);
-
- // Opera6 bug workaround
- $doc = str_replace("\xC0\xBC", '&lt;', $doc);
-
- // UTF-7 encoding ASCII decode
- if($isUTF7)
- $doc = $this->repackUTF7($doc);
-
- // Instantiate the parser
- $parser= new TSax3();
-
- // Set up the parser
- $parser->set_object($this);
-
- $parser->set_element_handler('_openHandler','_closeHandler');
- $parser->set_data_handler('_dataHandler');
- $parser->set_escape_handler('_escapeHandler');
-
- $parser->parse($doc);
-
- return $this->getXHTML();
-
- }
-
-
- /**
- * UTF-7 decoding fuction
- *
- * @param string $str HTML document for recode ASCII part of UTF-7 back to ASCII
- * @return string Decoded document
- * @access private
- */
- private function repackUTF7($str)
- {
- return preg_replace_callback('!\+([0-9a-zA-Z/]+)\-!', array($this, 'repackUTF7Callback'), $str);
- }
-
- /**
- * Additional UTF-7 decoding fuction
- *
- * @param string $str String for recode ASCII part of UTF-7 back to ASCII
- * @return string Recoded string
- * @access private
- */
- private function repackUTF7Callback($str)
- {
- $str = base64_decode($str[1]);
- $str = preg_replace_callback('/^((?:\x00.)*)((?:[^\x00].)+)/', array($this, 'repackUTF7Back'), $str);
- return preg_replace('/\x00(.)/', '$1', $str);
- }
-
- /**
- * Additional UTF-7 encoding fuction
- *
- * @param string $str String for recode ASCII part of UTF-7 back to ASCII
- * @return string Recoded string
- * @access private
- */
- private function repackUTF7Back($str)
- {
- return $str[1].'+'.rtrim(base64_encode($str[2]), '=').'-';
- }
-}
-
-/*
- * Local variables:
- * tab-width: 4
- * c-basic-offset: 4
- * c-hanging-comment-ender-p: nil
- * End:
- */
-
+<?php
+/* vim: set expandtab tabstop=4 shiftwidth=4 softtabstop=4: */
+
+/**
+ * SafeHTML Parser
+ *
+ * PHP versions 4 and 5
+ *
+ * @category HTML
+ * @package System.Security
+ * @author Roman Ivanov <thingol@mail.ru>
+ * @copyright 2004-2005 Roman Ivanov
+ * @license http://www.debian.org/misc/bsd.license BSD License (3 Clause)
+ * @version 1.3.7
+ * @link http://pixel-apes.com/safehtml/
+ */
+
+
+/**
+ * This package requires HTMLSax3 package
+ */
+Prado::using('System.3rdParty.SafeHtml.HTMLSax3');
+
+
+/**
+ *
+ * TSafeHtmlParser
+ *
+ * This parser strips down all potentially dangerous content within HTML:
+ * <ul>
+ * <li>opening tag without its closing tag</li>
+ * <li>closing tag without its opening tag</li>
+ * <li>any of these tags: "base", "basefont", "head", "html", "body", "applet",
+ * "object", "iframe", "frame", "frameset", "script", "layer", "ilayer", "embed",
+ * "bgsound", "link", "meta", "style", "title", "blink", "xml" etc.</li>
+ * <li>any of these attributes: on*, data*, dynsrc</li>
+ * <li>javascript:/vbscript:/about: etc. protocols</li>
+ * <li>expression/behavior etc. in styles</li>
+ * <li>any other active content</li>
+ * </ul>
+ * It also tries to convert code to XHTML valid, but htmltidy is far better
+ * solution for this task.
+ *
+ * <b>Example:</b>
+ * <pre>
+ * $parser = Prado::createComponent('System.3rdParty.SafeHtml.TSafeHtmlParser');
+ * $result = $parser->parse($doc);
+ * </pre>
+ *
+ * @category HTML
+ * @package System.Security
+ * @author Roman Ivanov <thingol@mail.ru>
+ * @copyright 1997-2005 Roman Ivanov
+ * @license http://www.debian.org/misc/bsd.license BSD License (3 Clause)
+ * @version Release: @package_version@
+ * @link http://pear.php.net/package/SafeHTML
+ */
+class TSafeHtmlParser
+{
+ /**
+ * Storage for resulting HTML output
+ *
+ * @var string
+ * @access private
+ */
+ private $_xhtml = '';
+
+ /**
+ * Array of counters for each tag
+ *
+ * @var array
+ * @access private
+ */
+ private $_counter = array();
+
+ /**
+ * Stack of unclosed tags
+ *
+ * @var array
+ * @access private
+ */
+ private $_stack = array();
+
+ /**
+ * Array of counters for tags that must be deleted with all content
+ *
+ * @var array
+ * @access private
+ */
+ private $_dcCounter = array();
+
+ /**
+ * Stack of unclosed tags that must be deleted with all content
+ *
+ * @var array
+ * @access private
+ */
+ private $_dcStack = array();
+
+ /**
+ * Stores level of list (ol/ul) nesting
+ *
+ * @var int
+ * @access private
+ */
+ private $_listScope = 0;
+
+ /**
+ * Stack of unclosed list tags
+ *
+ * @var array
+ * @access private
+ */
+ private $_liStack = array();
+
+ /**
+ * Array of prepared regular expressions for protocols (schemas) matching
+ *
+ * @var array
+ * @access private
+ */
+ private $_protoRegexps = array();
+
+ /**
+ * Array of prepared regular expressions for CSS matching
+ *
+ * @var array
+ * @access private
+ */
+ private $_cssRegexps = array();
+
+ /**
+ * List of single tags ("<tag />")
+ *
+ * @var array
+ * @access public
+ */
+ public $singleTags = array('area', 'br', 'img', 'input', 'hr', 'wbr', );
+
+ /**
+ * List of dangerous tags (such tags will be deleted)
+ *
+ * @var array
+ * @access public
+ */
+ public $deleteTags = array(
+ 'applet', 'base', 'basefont', 'bgsound', 'blink', 'body',
+ 'embed', 'frame', 'frameset', 'head', 'html', 'ilayer',
+ 'iframe', 'layer', 'link', 'meta', 'object', 'style',
+ 'title', 'script',
+ );
+
+ /**
+ * List of dangerous tags (such tags will be deleted, and all content
+ * inside this tags will be also removed)
+ *
+ * @var array
+ * @access public
+ */
+ public $deleteTagsContent = array('script', 'style', 'title', 'xml', );
+
+ /**
+ * Type of protocols filtering ('white' or 'black')
+ *
+ * @var string
+ * @access public
+ */
+ public $protocolFiltering = 'white';
+
+ /**
+ * List of "dangerous" protocols (used for blacklist-filtering)
+ *
+ * @var array
+ * @access public
+ */
+ public $blackProtocols = array(
+ 'about', 'chrome', 'data', 'disk', 'hcp',
+ 'help', 'javascript', 'livescript', 'lynxcgi', 'lynxexec',
+ 'ms-help', 'ms-its', 'mhtml', 'mocha', 'opera',
+ 'res', 'resource', 'shell', 'vbscript', 'view-source',
+ 'vnd.ms.radio', 'wysiwyg',
+ );
+
+ /**
+ * List of "safe" protocols (used for whitelist-filtering)
+ *
+ * @var array
+ * @access public
+ */
+ public $whiteProtocols = array(
+ 'ed2k', 'file', 'ftp', 'gopher', 'http', 'https',
+ 'irc', 'mailto', 'news', 'nntp', 'telnet', 'webcal',
+ 'xmpp', 'callto',
+ );
+
+ /**
+ * List of attributes that can contain protocols
+ *
+ * @var array
+ * @access public
+ */
+ public $protocolAttributes = array(
+ 'action', 'background', 'codebase', 'dynsrc', 'href', 'lowsrc', 'src',
+ );
+
+ /**
+ * List of dangerous CSS keywords
+ *
+ * Whole style="" attribute will be removed, if parser will find one of
+ * these keywords
+ *
+ * @var array
+ * @access public
+ */
+ public $cssKeywords = array(
+ 'absolute', 'behavior', 'behaviour', 'content', 'expression',
+ 'fixed', 'include-source', 'moz-binding',
+ );
+
+ /**
+ * List of tags that can have no "closing tag"
+ *
+ * @var array
+ * @access public
+ * @deprecated XHTML does not allow such tags
+ */
+ public $noClose = array();
+
+ /**
+ * List of block-level tags that terminates paragraph
+ *
+ * Paragraph will be closed when this tags opened
+ *
+ * @var array
+ * @access public
+ */
+ public $closeParagraph = array(
+ 'address', 'blockquote', 'center', 'dd', 'dir', 'div',
+ 'dl', 'dt', 'h1', 'h2', 'h3', 'h4',
+ 'h5', 'h6', 'hr', 'isindex', 'listing', 'marquee',
+ 'menu', 'multicol', 'ol', 'p', 'plaintext', 'pre',
+ 'table', 'ul', 'xmp',
+ );
+
+ /**
+ * List of table tags, all table tags outside a table will be removed
+ *
+ * @var array
+ * @access public
+ */
+ public $tableTags = array(
+ 'caption', 'col', 'colgroup', 'tbody', 'td', 'tfoot', 'th',
+ 'thead', 'tr',
+ );
+
+ /**
+ * List of list tags
+ *
+ * @var array
+ * @access public
+ */
+ public $listTags = array('dir', 'menu', 'ol', 'ul', 'dl', );
+
+ /**
+ * List of dangerous attributes
+ *
+ * @var array
+ * @access public
+ */
+ public $attributes = array('dynsrc');
+ //public $attributes = array('dynsrc', 'id', 'name', ); //id and name are dangerous?
+
+ /**
+ * List of allowed "namespaced" attributes
+ *
+ * @var array
+ * @access public
+ */
+ public $attributesNS = array('xml:lang', );
+
+ /**
+ * Constructs class
+ *
+ * @access public
+ */
+ public function __construct()
+ {
+ //making regular expressions based on Proto & CSS arrays
+ foreach ($this->blackProtocols as $proto) {
+ $preg = "/[\s\x01-\x1F]*";
+ for ($i=0; $i<strlen($proto); $i++) {
+ $preg .= $proto{$i} . "[\s\x01-\x1F]*";
+ }
+ $preg .= ":/i";
+ $this->_protoRegexps[] = $preg;
+ }
+
+ foreach ($this->cssKeywords as $css) {
+ $this->_cssRegexps[] = '/' . $css . '/i';
+ }
+ return true;
+ }
+
+ /**
+ * Handles the writing of attributes - called from $this->_openHandler()
+ *
+ * @param array $attrs array of attributes $name => $value
+ * @return boolean
+ * @access private
+ */
+ private function _writeAttrs ($attrs)
+ {
+ if (is_array($attrs)) {
+ foreach ($attrs as $name => $value) {
+
+ $name = strtolower($name);
+
+ if (strpos($name, 'on') === 0) {
+ continue;
+ }
+ if (strpos($name, 'data') === 0) {
+ continue;
+ }
+ if (in_array($name, $this->attributes)) {
+ continue;
+ }
+ if (!preg_match("/^[a-z0-9]+$/i", $name)) {
+ if (!in_array($name, $this->attributesNS))
+ {
+ continue;
+ }
+ }
+
+ if (($value === TRUE) || (is_null($value))) {
+ $value = $name;
+ }
+
+ if ($name == 'style') {
+
+ // removes insignificant backslahes
+ $value = str_replace("\\", '', $value);
+
+ // removes CSS comments
+ while (1)
+ {
+ $_value = preg_replace("!/\*.*?\*/!s", '', $value);
+ if ($_value == $value) break;
+ $value = $_value;
+ }
+
+ // replace all & to &amp;
+ $value = str_replace('&amp;', '&', $value);
+ $value = str_replace('&', '&amp;', $value);
+
+ foreach ($this->_cssRegexps as $css) {
+ if (preg_match($css, $value)) {
+ continue 2;
+ }
+ }
+ foreach ($this->_protoRegexps as $proto) {
+ if (preg_match($proto, $value)) {
+ continue 2;
+ }
+ }
+ }
+
+ $tempval = preg_replace('/&#(\d+);?/me', "chr('\\1')", $value); //"'
+ $tempval = preg_replace('/&#x([0-9a-f]+);?/mei', "chr(hexdec('\\1'))", $tempval);
+
+ if ((in_array($name, $this->protocolAttributes)) &&
+ (strpos($tempval, ':') !== false))
+ {
+ if ($this->protocolFiltering == 'black') {
+ foreach ($this->_protoRegexps as $proto) {
+ if (preg_match($proto, $tempval)) continue 2;
+ }
+ } else {
+ $_tempval = explode(':', $tempval);
+ $proto = $_tempval[0];
+ if (!in_array($proto, $this->whiteProtocols)) {
+ continue;
+ }
+ }
+ }
+
+ $value = str_replace("\"", "&quot;", $value);
+ $this->_xhtml .= ' ' . $name . '="' . $value . '"';
+ }
+ }
+ return true;
+ }
+
+ /**
+ * Opening tag handler - called from HTMLSax
+ *
+ * @param object $parser HTML Parser
+ * @param string $name tag name
+ * @param array $attrs tag attributes
+ * @return boolean
+ * @access private
+ */
+ public function _openHandler(&$parser, $name, $attrs)
+ {
+ $name = strtolower($name);
+
+ if (in_array($name, $this->deleteTagsContent)) {
+ array_push($this->_dcStack, $name);
+ $this->_dcCounter[$name] = isset($this->_dcCounter[$name]) ? $this->_dcCounter[$name]+1 : 1;
+ }
+ if (count($this->_dcStack) != 0) {
+ return true;
+ }
+
+ if (in_array($name, $this->deleteTags)) {
+ return true;
+ }
+
+ if (!preg_match("/^[a-z0-9]+$/i", $name)) {
+ if (preg_match("!(?:\@|://)!i", $name)) {
+ $this->_xhtml .= '&lt;' . $name . '&gt;';
+ }
+ return true;
+ }
+
+ if (in_array($name, $this->singleTags)) {
+ $this->_xhtml .= '<' . $name;
+ $this->_writeAttrs($attrs);
+ $this->_xhtml .= ' />';
+ return true;
+ }
+
+ // TABLES: cannot open table elements when we are not inside table
+ if ((isset($this->_counter['table'])) && ($this->_counter['table'] <= 0)
+ && (in_array($name, $this->tableTags)))
+ {
+ return true;
+ }
+
+ // PARAGRAPHS: close paragraph when closeParagraph tags opening
+ if ((in_array($name, $this->closeParagraph)) && (in_array('p', $this->_stack))) {
+ $this->_closeHandler($parser, 'p');
+ }
+
+ // LISTS: we should close <li> if <li> of the same level opening
+ if ($name == 'li' && count($this->_liStack) &&
+ $this->_listScope == $this->_liStack[count($this->_liStack)-1])
+ {
+ $this->_closeHandler($parser, 'li');
+ }
+
+ // LISTS: we want to know on what nesting level of lists we are
+ if (in_array($name, $this->listTags)) {
+ $this->_listScope++;
+ }
+ if ($name == 'li') {
+ array_push($this->_liStack, $this->_listScope);
+ }
+
+ $this->_xhtml .= '<' . $name;
+ $this->_writeAttrs($attrs);
+ $this->_xhtml .= '>';
+ array_push($this->_stack,$name);
+ $this->_counter[$name] = isset($this->_counter[$name]) ? $this->_counter[$name]+1 : 1;
+ return true;
+ }
+
+ /**
+ * Closing tag handler - called from HTMLSax
+ *
+ * @param object $parsers HTML parser
+ * @param string $name tag name
+ * @return boolean
+ * @access private
+ */
+ public function _closeHandler(&$parser, $name)
+ {
+
+ $name = strtolower($name);
+
+ if (isset($this->_dcCounter[$name]) && ($this->_dcCounter[$name] > 0) &&
+ (in_array($name, $this->deleteTagsContent)))
+ {
+ while ($name != ($tag = array_pop($this->_dcStack))) {
+ $this->_dcCounter[$tag]--;
+ }
+
+ $this->_dcCounter[$name]--;
+ }
+
+ if (count($this->_dcStack) != 0) {
+ return true;
+ }
+
+ if ((isset($this->_counter[$name])) && ($this->_counter[$name] > 0)) {
+ while ($name != ($tag = array_pop($this->_stack))) {
+ $this->_closeTag($tag);
+ }
+
+ $this->_closeTag($name);
+ }
+ return true;
+ }
+
+ /**
+ * Closes tag
+ *
+ * @param string $tag tag name
+ * @return boolean
+ * @access private
+ */
+ public function _closeTag($tag)
+ {
+ if (!in_array($tag, $this->noClose)) {
+ $this->_xhtml .= '</' . $tag . '>';
+ }
+
+ $this->_counter[$tag]--;
+
+ if (in_array($tag, $this->listTags)) {
+ $this->_listScope--;
+ }
+
+ if ($tag == 'li') {
+ array_pop($this->_liStack);
+ }
+ return true;
+ }
+
+ /**
+ * Character data handler - called from HTMLSax
+ *
+ * @param object $parser HTML parser
+ * @param string $data textual data
+ * @return boolean
+ * @access private
+ */
+ public function _dataHandler(&$parser, $data)
+ {
+ if (count($this->_dcStack) == 0) {
+ $this->_xhtml .= $data;
+ }
+ return true;
+ }
+
+ /**
+ * Escape handler - called from HTMLSax
+ *
+ * @param object $parser HTML parser
+ * @param string $data comments or other type of data
+ * @return boolean
+ * @access private
+ */
+ public function _escapeHandler(&$parser, $data)
+ {
+ return true;
+ }
+
+ /**
+ * Returns the XHTML document
+ *
+ * @return string Processed (X)HTML document
+ * @access public
+ */
+ public function getXHTML ()
+ {
+ while ($tag = array_pop($this->_stack)) {
+ $this->_closeTag($tag);
+ }
+
+ return $this->_xhtml;
+ }
+
+ /**
+ * Clears current document data
+ *
+ * @return boolean
+ * @access public
+ */
+ public function clear()
+ {
+ $this->_xhtml = '';
+ return true;
+ }
+
+ /**
+ * Main parsing fuction
+ *
+ * @param string $doc HTML document for processing
+ * @return string Processed (X)HTML document
+ * @access public
+ */
+ public function parse($doc, $isUTF7=false)
+ {
+ $this->clear();
+
+ // Save all '<' symbols
+ $doc = preg_replace("/<(?=[^a-zA-Z\/\!\?\%])/", '&lt;', (string)$doc);
+
+ // Web documents shouldn't contains \x00 symbol
+ $doc = str_replace("\x00", '', $doc);
+
+ // Opera6 bug workaround
+ $doc = str_replace("\xC0\xBC", '&lt;', $doc);
+
+ // UTF-7 encoding ASCII decode
+ if($isUTF7)
+ $doc = $this->repackUTF7($doc);
+
+ // Instantiate the parser
+ $parser= new TSax3();
+
+ // Set up the parser
+ $parser->set_object($this);
+
+ $parser->set_element_handler('_openHandler','_closeHandler');
+ $parser->set_data_handler('_dataHandler');
+ $parser->set_escape_handler('_escapeHandler');
+
+ $parser->parse($doc);
+
+ return $this->getXHTML();
+
+ }
+
+
+ /**
+ * UTF-7 decoding fuction
+ *
+ * @param string $str HTML document for recode ASCII part of UTF-7 back to ASCII
+ * @return string Decoded document
+ * @access private
+ */
+ private function repackUTF7($str)
+ {
+ return preg_replace_callback('!\+([0-9a-zA-Z/]+)\-!', array($this, 'repackUTF7Callback'), $str);
+ }
+
+ /**
+ * Additional UTF-7 decoding fuction
+ *
+ * @param string $str String for recode ASCII part of UTF-7 back to ASCII
+ * @return string Recoded string
+ * @access private
+ */
+ private function repackUTF7Callback($str)
+ {
+ $str = base64_decode($str[1]);
+ $str = preg_replace_callback('/^((?:\x00.)*)((?:[^\x00].)+)/', array($this, 'repackUTF7Back'), $str);
+ return preg_replace('/\x00(.)/', '$1', $str);
+ }
+
+ /**
+ * Additional UTF-7 encoding fuction
+ *
+ * @param string $str String for recode ASCII part of UTF-7 back to ASCII
+ * @return string Recoded string
+ * @access private
+ */
+ private function repackUTF7Back($str)
+ {
+ return $str[1].'+'.rtrim(base64_encode($str[2]), '=').'-';
+ }
+}
+
+/*
+ * Local variables:
+ * tab-width: 4
+ * c-basic-offset: 4
+ * c-hanging-comment-ender-p: nil
+ * End:
+ */
+
?> \ No newline at end of file
diff --git a/framework/3rdParty/TextHighlighter/Text/Highlighter.php b/framework/3rdParty/TextHighlighter/Text/Highlighter.php
index b597b909..9ec09cdb 100644
--- a/framework/3rdParty/TextHighlighter/Text/Highlighter.php
+++ b/framework/3rdParty/TextHighlighter/Text/Highlighter.php
@@ -1,397 +1,397 @@
-<?php
-/* vim: set expandtab tabstop=4 shiftwidth=4 softtabstop=4: */
-/**
- * Highlighter base class
- *
- * PHP versions 4 and 5
- *
- * LICENSE: This source file is subject to version 3.0 of the PHP license
- * that is available through the world-wide-web at the following URI:
- * http://www.php.net/license/3_0.txt. If you did not receive a copy of
- * the PHP License and are unable to obtain it through the web, please
- * send a note to license@php.net so we can mail you a copy immediately.
- *
- * @category Text
- * @package Text_Highlighter
- * @author Andrey Demenev <demenev@gmail.com>
- * @copyright 2004-2006 Andrey Demenev
- * @license http://www.php.net/license/3_0.txt PHP License
- * @version CVS: $Id: Highlighter.php,v 1.1 2007/06/03 02:35:28 ssttoo Exp $
- * @link http://pear.php.net/package/Text_Highlighter
- */
-
-// {{{ BC constants
-
-// BC trick : define constants related to default
-// renderer if needed
-if (!defined('HL_NUMBERS_LI')) {
- /**#@+
- * Constant for use with $options['numbers']
- * @see Text_Highlighter_Renderer_Html::_init()
- */
- /**
- * use numbered list
- */
- define ('HL_NUMBERS_LI' , 1);
- /**
- * Use 2-column table with line numbers in left column and code in right column.
- * Forces $options['tag'] = HL_TAG_PRE
- */
- define ('HL_NUMBERS_TABLE' , 2);
- /**#@-*/
-}
-
-// }}}
-// {{{ constants
-/**
- * for our purpose, it is infinity
- */
-define ('HL_INFINITY', 1000000000);
-
-// }}}
-
-/**
- * Text highlighter base class
- *
- * @author Andrey Demenev <demenev@gmail.com>
- * @copyright 2004-2006 Andrey Demenev
- * @license http://www.php.net/license/3_0.txt PHP License
- * @version Release: 0.7.0
- * @link http://pear.php.net/package/Text_Highlighter
- */
-
-// {{{ Text_Highlighter
-
-/**
- * Text highlighter base class
- *
- * This class implements all functions necessary for highlighting,
- * but it does not contain highlighting rules. Actual highlighting is
- * done using a descendent of this class.
- *
- * One is not supposed to manually create descendent classes.
- * Instead, describe highlighting rules in XML format and
- * use {@link Text_Highlighter_Generator} to create descendent class.
- * Alternatively, an instance of a descendent class can be created
- * directly.
- *
- * Use {@link Text_Highlighter::factory()} to create an
- * object for particular language highlighter
- *
- * Usage example
- * <code>
- *require_once 'Text/Highlighter.php';
- *$hlSQL =& Text_Highlighter::factory('SQL',array('numbers'=>true));
- *echo $hlSQL->highlight('SELECT * FROM table a WHERE id = 12');
- * </code>
- *
- * @author Andrey Demenev <demenev@gmail.com>
- * @package Text_Highlighter
- * @access public
- */
-
-class Text_Highlighter
-{
- // {{{ members
-
- /**
- * Syntax highlighting rules.
- * Auto-generated classes set this var
- *
- * @access protected
- * @see _init
- * @var array
- */
- var $_syntax;
-
- /**
- * Renderer object.
- *
- * @access private
- * @var array
- */
- var $_renderer;
-
- /**
- * Options. Keeped for BC
- *
- * @access protected
- * @var array
- */
- var $_options = array();
-
- /**
- * Conditionds
- *
- * @access protected
- * @var array
- */
- var $_conditions = array();
-
- /**
- * Disabled keywords
- *
- * @access protected
- * @var array
- */
- var $_disabled = array();
-
- /**
- * Language
- *
- * @access protected
- * @var string
- */
- var $_language = '';
-
- // }}}
- // {{{ _checkDefines
-
- /**
- * Called by subclssses' constructors to enable/disable
- * optional highlighter rules
- *
- * @param array $defines Conditional defines
- *
- * @access protected
- */
- function _checkDefines()
- {
- if (isset($this->_options['defines'])) {
- $defines = $this->_options['defines'];
- } else {
- $defines = array();
- }
- foreach ($this->_conditions as $name => $actions) {
- foreach($actions as $action) {
- $present = in_array($name, $defines);
- if (!$action[1]) {
- $present = !$present;
- }
- if ($present) {
- unset($this->_disabled[$action[0]]);
- } else {
- $this->_disabled[$action[0]] = true;
- }
- }
- }
- }
-
- // }}}
- // {{{ factory
-
- /**
- * Create a new Highlighter object for specified language
- *
- * @param string $lang language, for example "SQL"
- * @param array $options Rendering options. This
- * parameter is only keeped for BC reasons, use
- * {@link Text_Highlighter::setRenderer()} instead
- *
- * @return mixed a newly created Highlighter object, or
- * a PEAR error object on error
- *
- * @static
- * @access public
- */
- public static function factory($lang, $options = array())
- {
- $lang = strtoupper($lang);
- $langFile = dirname(__FILE__)."/Highlighter/$lang.php";
- if (is_file($langFile))
- include_once $langFile;
- else
- return false;
-
- $classname = 'Text_Highlighter_' . $lang;
-
- if (!class_exists($classname))
- return false;
-
- return new $classname($options);
- }
-
- // }}}
- // {{{ setRenderer
-
- /**
- * Set renderer object
- *
- * @param object $renderer Text_Highlighter_Renderer
- *
- * @access public
- */
- function setRenderer($renderer)
- {
- $this->_renderer = $renderer;
- }
-
- // }}}
-
- /**
- * Helper function to find matching brackets
- *
- * @access private
- */
- function _matchingBrackets($str)
- {
- return strtr($str, '()<>[]{}', ')(><][}{');
- }
-
-
-
-
- function _getToken()
- {
- if (!empty($this->_tokenStack)) {
- return array_pop($this->_tokenStack);
- }
- if ($this->_pos >= $this->_len) {
- return NULL;
- }
-
- if ($this->_state != -1 && preg_match($this->_endpattern, $this->_str, $m, PREG_OFFSET_CAPTURE, $this->_pos)) {
- $endpos = $m[0][1];
- $endmatch = $m[0][0];
- } else {
- $endpos = -1;
- }
- preg_match ($this->_regs[$this->_state], $this->_str, $m, PREG_OFFSET_CAPTURE, $this->_pos);
- $n = 1;
-
-
- foreach ($this->_counts[$this->_state] as $i=>$count) {
- if (!isset($m[$n])) {
- break;
- }
- if ($m[$n][1]>-1 && ($endpos == -1 || $m[$n][1] < $endpos)) {
- if ($this->_states[$this->_state][$i] != -1) {
- $this->_tokenStack[] = array($this->_delim[$this->_state][$i], $m[$n][0]);
- } else {
- $inner = $this->_inner[$this->_state][$i];
- if (isset($this->_parts[$this->_state][$i])) {
- $parts = array();
- $partpos = $m[$n][1];
- for ($j=1; $j<=$count; $j++) {
- if ($m[$j+$n][1] < 0) {
- continue;
- }
- if (isset($this->_parts[$this->_state][$i][$j])) {
- if ($m[$j+$n][1] > $partpos) {
- array_unshift($parts, array($inner, substr($this->_str, $partpos, $m[$j+$n][1]-$partpos)));
- }
- array_unshift($parts, array($this->_parts[$this->_state][$i][$j], $m[$j+$n][0]));
- }
- $partpos = $m[$j+$n][1] + strlen($m[$j+$n][0]);
- }
- if ($partpos < $m[$n][1] + strlen($m[$n][0])) {
- array_unshift($parts, array($inner, substr($this->_str, $partpos, $m[$n][1] - $partpos + strlen($m[$n][0]))));
- }
- $this->_tokenStack = array_merge($this->_tokenStack, $parts);
- } else {
- foreach ($this->_keywords[$this->_state][$i] as $g => $re) {
- if (isset($this->_disabled[$g])) {
- continue;
- }
- if (preg_match($re, $m[$n][0])) {
- $inner = $this->_kwmap[$g];
- break;
- }
- }
- $this->_tokenStack[] = array($inner, $m[$n][0]);
- }
- }
- if ($m[$n][1] > $this->_pos) {
- $this->_tokenStack[] = array($this->_lastinner, substr($this->_str, $this->_pos, $m[$n][1]-$this->_pos));
- }
- $this->_pos = $m[$n][1] + strlen($m[$n][0]);
- if ($this->_states[$this->_state][$i] != -1) {
- $this->_stack[] = array($this->_state, $this->_lastdelim, $this->_lastinner, $this->_endpattern);
- $this->_lastinner = $this->_inner[$this->_state][$i];
- $this->_lastdelim = $this->_delim[$this->_state][$i];
- $l = $this->_state;
- $this->_state = $this->_states[$this->_state][$i];
- $this->_endpattern = $this->_end[$this->_state];
- if ($this->_subst[$l][$i]) {
- for ($k=0; $k<=$this->_counts[$l][$i]; $k++) {
- if (!isset($m[$i+$k])) {
- break;
- }
- $quoted = preg_quote($m[$n+$k][0], '/');
- $this->_endpattern = str_replace('%'.$k.'%', $quoted, $this->_endpattern);
- $this->_endpattern = str_replace('%b'.$k.'%', $this->_matchingBrackets($quoted), $this->_endpattern);
- }
- }
- }
- return array_pop($this->_tokenStack);
- }
- $n += $count + 1;
- }
-
- if ($endpos > -1) {
- $this->_tokenStack[] = array($this->_lastdelim, $endmatch);
- if ($endpos > $this->_pos) {
- $this->_tokenStack[] = array($this->_lastinner, substr($this->_str, $this->_pos, $endpos-$this->_pos));
- }
- list($this->_state, $this->_lastdelim, $this->_lastinner, $this->_endpattern) = array_pop($this->_stack);
- $this->_pos = $endpos + strlen($endmatch);
- return array_pop($this->_tokenStack);
- }
- $p = $this->_pos;
- $this->_pos = HL_INFINITY;
- return array($this->_lastinner, substr($this->_str, $p));
- }
-
-
-
-
- // {{{ highlight
-
- /**
- * Highlights code
- *
- * @param string $str Code to highlight
- * @access public
- * @return string Highlighted text
- *
- */
-
- function highlight($str)
- {
- if (!($this->_renderer)) {
- include_once('Text/Highlighter/Renderer/Html.php');
- $this->_renderer = new Text_Highlighter_Renderer_Html($this->_options);
- }
- $this->_state = -1;
- $this->_pos = 0;
- $this->_stack = array();
- $this->_tokenStack = array();
- $this->_lastinner = $this->_defClass;
- $this->_lastdelim = $this->_defClass;
- $this->_endpattern = '';
- $this->_renderer->reset();
- $this->_renderer->setCurrentLanguage($this->_language);
- $this->_str = $this->_renderer->preprocess($str);
- $this->_len = strlen($this->_str);
- while ($token = $this->_getToken()) {
- $this->_renderer->acceptToken($token[0], $token[1]);
- }
- $this->_renderer->finalize();
- return $this->_renderer->getOutput();
- }
-
- // }}}
-
-}
-
-// }}}
-
-/*
- * Local variables:
- * tab-width: 4
- * c-basic-offset: 4
- * c-hanging-comment-ender-p: nil
- * End:
- */
-
+<?php
+/* vim: set expandtab tabstop=4 shiftwidth=4 softtabstop=4: */
+/**
+ * Highlighter base class
+ *
+ * PHP versions 4 and 5
+ *
+ * LICENSE: This source file is subject to version 3.0 of the PHP license
+ * that is available through the world-wide-web at the following URI:
+ * http://www.php.net/license/3_0.txt. If you did not receive a copy of
+ * the PHP License and are unable to obtain it through the web, please
+ * send a note to license@php.net so we can mail you a copy immediately.
+ *
+ * @category Text
+ * @package Text_Highlighter
+ * @author Andrey Demenev <demenev@gmail.com>
+ * @copyright 2004-2006 Andrey Demenev
+ * @license http://www.php.net/license/3_0.txt PHP License
+ * @version CVS: $Id: Highlighter.php,v 1.1 2007/06/03 02:35:28 ssttoo Exp $
+ * @link http://pear.php.net/package/Text_Highlighter
+ */
+
+// {{{ BC constants
+
+// BC trick : define constants related to default
+// renderer if needed
+if (!defined('HL_NUMBERS_LI')) {
+ /**#@+
+ * Constant for use with $options['numbers']
+ * @see Text_Highlighter_Renderer_Html::_init()
+ */
+ /**
+ * use numbered list
+ */
+ define ('HL_NUMBERS_LI' , 1);
+ /**
+ * Use 2-column table with line numbers in left column and code in right column.
+ * Forces $options['tag'] = HL_TAG_PRE
+ */
+ define ('HL_NUMBERS_TABLE' , 2);
+ /**#@-*/
+}
+
+// }}}
+// {{{ constants
+/**
+ * for our purpose, it is infinity
+ */
+define ('HL_INFINITY', 1000000000);
+
+// }}}
+
+/**
+ * Text highlighter base class
+ *
+ * @author Andrey Demenev <demenev@gmail.com>
+ * @copyright 2004-2006 Andrey Demenev
+ * @license http://www.php.net/license/3_0.txt PHP License
+ * @version Release: 0.7.0
+ * @link http://pear.php.net/package/Text_Highlighter
+ */
+
+// {{{ Text_Highlighter
+
+/**
+ * Text highlighter base class
+ *
+ * This class implements all functions necessary for highlighting,
+ * but it does not contain highlighting rules. Actual highlighting is
+ * done using a descendent of this class.
+ *
+ * One is not supposed to manually create descendent classes.
+ * Instead, describe highlighting rules in XML format and
+ * use {@link Text_Highlighter_Generator} to create descendent class.
+ * Alternatively, an instance of a descendent class can be created
+ * directly.
+ *
+ * Use {@link Text_Highlighter::factory()} to create an
+ * object for particular language highlighter
+ *
+ * Usage example
+ * <code>
+ *require_once 'Text/Highlighter.php';
+ *$hlSQL =& Text_Highlighter::factory('SQL',array('numbers'=>true));
+ *echo $hlSQL->highlight('SELECT * FROM table a WHERE id = 12');
+ * </code>
+ *
+ * @author Andrey Demenev <demenev@gmail.com>
+ * @package Text_Highlighter
+ * @access public
+ */
+
+class Text_Highlighter
+{
+ // {{{ members
+
+ /**
+ * Syntax highlighting rules.
+ * Auto-generated classes set this var
+ *
+ * @access protected
+ * @see _init
+ * @var array
+ */
+ var $_syntax;
+
+ /**
+ * Renderer object.
+ *
+ * @access private
+ * @var array
+ */
+ var $_renderer;
+
+ /**
+ * Options. Keeped for BC
+ *
+ * @access protected
+ * @var array
+ */
+ var $_options = array();
+
+ /**
+ * Conditionds
+ *
+ * @access protected
+ * @var array
+ */
+ var $_conditions = array();
+
+ /**
+ * Disabled keywords
+ *
+ * @access protected
+ * @var array
+ */
+ var $_disabled = array();
+
+ /**
+ * Language
+ *
+ * @access protected
+ * @var string
+ */
+ var $_language = '';
+
+ // }}}
+ // {{{ _checkDefines
+
+ /**
+ * Called by subclssses' constructors to enable/disable
+ * optional highlighter rules
+ *
+ * @param array $defines Conditional defines
+ *
+ * @access protected
+ */
+ function _checkDefines()
+ {
+ if (isset($this->_options['defines'])) {
+ $defines = $this->_options['defines'];
+ } else {
+ $defines = array();
+ }
+ foreach ($this->_conditions as $name => $actions) {
+ foreach($actions as $action) {
+ $present = in_array($name, $defines);
+ if (!$action[1]) {
+ $present = !$present;
+ }
+ if ($present) {
+ unset($this->_disabled[$action[0]]);
+ } else {
+ $this->_disabled[$action[0]] = true;
+ }
+ }
+ }
+ }
+
+ // }}}
+ // {{{ factory
+
+ /**
+ * Create a new Highlighter object for specified language
+ *
+ * @param string $lang language, for example "SQL"
+ * @param array $options Rendering options. This
+ * parameter is only keeped for BC reasons, use
+ * {@link Text_Highlighter::setRenderer()} instead
+ *
+ * @return mixed a newly created Highlighter object, or
+ * a PEAR error object on error
+ *
+ * @static
+ * @access public
+ */
+ public static function factory($lang, $options = array())
+ {
+ $lang = strtoupper($lang);
+ $langFile = dirname(__FILE__)."/Highlighter/$lang.php";
+ if (is_file($langFile))
+ include_once $langFile;
+ else
+ return false;
+
+ $classname = 'Text_Highlighter_' . $lang;
+
+ if (!class_exists($classname))
+ return false;
+
+ return new $classname($options);
+ }
+
+ // }}}
+ // {{{ setRenderer
+
+ /**
+ * Set renderer object
+ *
+ * @param object $renderer Text_Highlighter_Renderer
+ *
+ * @access public
+ */
+ function setRenderer($renderer)
+ {
+ $this->_renderer = $renderer;
+ }
+
+ // }}}
+
+ /**
+ * Helper function to find matching brackets
+ *
+ * @access private
+ */
+ function _matchingBrackets($str)
+ {
+ return strtr($str, '()<>[]{}', ')(><][}{');
+ }
+
+
+
+
+ function _getToken()
+ {
+ if (!empty($this->_tokenStack)) {
+ return array_pop($this->_tokenStack);
+ }
+ if ($this->_pos >= $this->_len) {
+ return NULL;
+ }
+
+ if ($this->_state != -1 && preg_match($this->_endpattern, $this->_str, $m, PREG_OFFSET_CAPTURE, $this->_pos)) {
+ $endpos = $m[0][1];
+ $endmatch = $m[0][0];
+ } else {
+ $endpos = -1;
+ }
+ preg_match ($this->_regs[$this->_state], $this->_str, $m, PREG_OFFSET_CAPTURE, $this->_pos);
+ $n = 1;
+
+
+ foreach ($this->_counts[$this->_state] as $i=>$count) {
+ if (!isset($m[$n])) {
+ break;
+ }
+ if ($m[$n][1]>-1 && ($endpos == -1 || $m[$n][1] < $endpos)) {
+ if ($this->_states[$this->_state][$i] != -1) {
+ $this->_tokenStack[] = array($this->_delim[$this->_state][$i], $m[$n][0]);
+ } else {
+ $inner = $this->_inner[$this->_state][$i];
+ if (isset($this->_parts[$this->_state][$i])) {
+ $parts = array();
+ $partpos = $m[$n][1];
+ for ($j=1; $j<=$count; $j++) {
+ if ($m[$j+$n][1] < 0) {
+ continue;
+ }
+ if (isset($this->_parts[$this->_state][$i][$j])) {
+ if ($m[$j+$n][1] > $partpos) {
+ array_unshift($parts, array($inner, substr($this->_str, $partpos, $m[$j+$n][1]-$partpos)));
+ }
+ array_unshift($parts, array($this->_parts[$this->_state][$i][$j], $m[$j+$n][0]));
+ }
+ $partpos = $m[$j+$n][1] + strlen($m[$j+$n][0]);
+ }
+ if ($partpos < $m[$n][1] + strlen($m[$n][0])) {
+ array_unshift($parts, array($inner, substr($this->_str, $partpos, $m[$n][1] - $partpos + strlen($m[$n][0]))));
+ }
+ $this->_tokenStack = array_merge($this->_tokenStack, $parts);
+ } else {
+ foreach ($this->_keywords[$this->_state][$i] as $g => $re) {
+ if (isset($this->_disabled[$g])) {
+ continue;
+ }
+ if (preg_match($re, $m[$n][0])) {
+ $inner = $this->_kwmap[$g];
+ break;
+ }
+ }
+ $this->_tokenStack[] = array($inner, $m[$n][0]);
+ }
+ }
+ if ($m[$n][1] > $this->_pos) {
+ $this->_tokenStack[] = array($this->_lastinner, substr($this->_str, $this->_pos, $m[$n][1]-$this->_pos));
+ }
+ $this->_pos = $m[$n][1] + strlen($m[$n][0]);
+ if ($this->_states[$this->_state][$i] != -1) {
+ $this->_stack[] = array($this->_state, $this->_lastdelim, $this->_lastinner, $this->_endpattern);
+ $this->_lastinner = $this->_inner[$this->_state][$i];
+ $this->_lastdelim = $this->_delim[$this->_state][$i];
+ $l = $this->_state;
+ $this->_state = $this->_states[$this->_state][$i];
+ $this->_endpattern = $this->_end[$this->_state];
+ if ($this->_subst[$l][$i]) {
+ for ($k=0; $k<=$this->_counts[$l][$i]; $k++) {
+ if (!isset($m[$i+$k])) {
+ break;
+ }
+ $quoted = preg_quote($m[$n+$k][0], '/');
+ $this->_endpattern = str_replace('%'.$k.'%', $quoted, $this->_endpattern);
+ $this->_endpattern = str_replace('%b'.$k.'%', $this->_matchingBrackets($quoted), $this->_endpattern);
+ }
+ }
+ }
+ return array_pop($this->_tokenStack);
+ }
+ $n += $count + 1;
+ }
+
+ if ($endpos > -1) {
+ $this->_tokenStack[] = array($this->_lastdelim, $endmatch);
+ if ($endpos > $this->_pos) {
+ $this->_tokenStack[] = array($this->_lastinner, substr($this->_str, $this->_pos, $endpos-$this->_pos));
+ }
+ list($this->_state, $this->_lastdelim, $this->_lastinner, $this->_endpattern) = array_pop($this->_stack);
+ $this->_pos = $endpos + strlen($endmatch);
+ return array_pop($this->_tokenStack);
+ }
+ $p = $this->_pos;
+ $this->_pos = HL_INFINITY;
+ return array($this->_lastinner, substr($this->_str, $p));
+ }
+
+
+
+
+ // {{{ highlight
+
+ /**
+ * Highlights code
+ *
+ * @param string $str Code to highlight
+ * @access public
+ * @return string Highlighted text
+ *
+ */
+
+ function highlight($str)
+ {
+ if (!($this->_renderer)) {
+ include_once('Text/Highlighter/Renderer/Html.php');
+ $this->_renderer = new Text_Highlighter_Renderer_Html($this->_options);
+ }
+ $this->_state = -1;
+ $this->_pos = 0;
+ $this->_stack = array();
+ $this->_tokenStack = array();
+ $this->_lastinner = $this->_defClass;
+ $this->_lastdelim = $this->_defClass;
+ $this->_endpattern = '';
+ $this->_renderer->reset();
+ $this->_renderer->setCurrentLanguage($this->_language);
+ $this->_str = $this->_renderer->preprocess($str);
+ $this->_len = strlen($this->_str);
+ while ($token = $this->_getToken()) {
+ $this->_renderer->acceptToken($token[0], $token[1]);
+ }
+ $this->_renderer->finalize();
+ return $this->_renderer->getOutput();
+ }
+
+ // }}}
+
+}
+
+// }}}
+
+/*
+ * Local variables:
+ * tab-width: 4
+ * c-basic-offset: 4
+ * c-hanging-comment-ender-p: nil
+ * End:
+ */
+
?> \ No newline at end of file
diff --git a/framework/3rdParty/TextHighlighter/Text/Highlighter/ABAP.php b/framework/3rdParty/TextHighlighter/Text/Highlighter/ABAP.php
index adeaabf9..153ce9fe 100644
--- a/framework/3rdParty/TextHighlighter/Text/Highlighter/ABAP.php
+++ b/framework/3rdParty/TextHighlighter/Text/Highlighter/ABAP.php
@@ -1,53 +1,53 @@
-<?php
-/**
- * Auto-generated class. ABAP syntax highlighting
- *
- * PHP version 4 and 5
- *
- * LICENSE: This source file is subject to version 3.0 of the PHP license
- * that is available through the world-wide-web at the following URI:
- * http://www.php.net/license/3_0.txt. If you did not receive a copy of
- * the PHP License and are unable to obtain it through the web, please
- * send a note to license@php.net so we can mail you a copy immediately.
- *
- * @copyright 2004-2006 Andrey Demenev
- * @license http://www.php.net/license/3_0.txt PHP License
- * @link http://pear.php.net/package/Text_Highlighter
- * @category Text
- * @package Text_Highlighter
+<?php
+/**
+ * Auto-generated class. ABAP syntax highlighting
+ *
+ * PHP version 4 and 5
+ *
+ * LICENSE: This source file is subject to version 3.0 of the PHP license
+ * that is available through the world-wide-web at the following URI:
+ * http://www.php.net/license/3_0.txt. If you did not receive a copy of
+ * the PHP License and are unable to obtain it through the web, please
+ * send a note to license@php.net so we can mail you a copy immediately.
+ *
+ * @copyright 2004-2006 Andrey Demenev
+ * @license http://www.php.net/license/3_0.txt PHP License
+ * @link http://pear.php.net/package/Text_Highlighter
+ * @category Text
+ * @package Text_Highlighter
* @version generated from: : abap.xml,v 1.1 2007/06/03 02:35:28 ssttoo Exp
* @author Stoyan Stefanov <ssttoo@gmail.com>
- *
- */
-
-/**
- * @ignore
- */
-
-/**
- * Auto-generated class. ABAP syntax highlighting
- *
+ *
+ */
+
+/**
+ * @ignore
+ */
+
+/**
+ * Auto-generated class. ABAP syntax highlighting
+ *
* @author Stoyan Stefanov <ssttoo@gmail.com>
- * @category Text
- * @package Text_Highlighter
- * @copyright 2004-2006 Andrey Demenev
- * @license http://www.php.net/license/3_0.txt PHP License
- * @version Release: 0.7.0
- * @link http://pear.php.net/package/Text_Highlighter
- */
-class Text_Highlighter_ABAP extends Text_Highlighter
-{
+ * @category Text
+ * @package Text_Highlighter
+ * @copyright 2004-2006 Andrey Demenev
+ * @license http://www.php.net/license/3_0.txt PHP License
+ * @version Release: 0.7.0
+ * @link http://pear.php.net/package/Text_Highlighter
+ */
+class Text_Highlighter_ABAP extends Text_Highlighter
+{
var $_language = 'abap';
- /**
- * Constructor
- *
- * @param array $options
- * @access public
- */
- function __construct($options=array())
- {
-
+ /**
+ * Constructor
+ *
+ * @param array $options
+ * @access public
+ */
+ function __construct($options=array())
+ {
+
$this->_options = $options;
$this->_regs = array (
-1 => '/((?i)\\{)|((?i)\\()|((?i)\\[)|((?i)^\\*|")|((?i)\')|((?i)[a-z_\\-]\\w*)/',
@@ -498,8 +498,8 @@ class Text_Highlighter_ABAP extends Text_Highlighter
'reserved' => 'reserved',
'constants' => 'reserved',
);
- $this->_defClass = 'code';
- $this->_checkDefines();
- }
-
+ $this->_defClass = 'code';
+ $this->_checkDefines();
+ }
+
} \ No newline at end of file
diff --git a/framework/3rdParty/TextHighlighter/Text/Highlighter/CPP.php b/framework/3rdParty/TextHighlighter/Text/Highlighter/CPP.php
index 7be6add9..761297ac 100644
--- a/framework/3rdParty/TextHighlighter/Text/Highlighter/CPP.php
+++ b/framework/3rdParty/TextHighlighter/Text/Highlighter/CPP.php
@@ -1,56 +1,56 @@
-<?php
-/**
+<?php
+/**
* Auto-generated class. CPP syntax highlighting
*
*
* Thanks to Aaron Kalin for initial
* implementation of this highlighter
- *
- *
- * PHP version 4 and 5
- *
- * LICENSE: This source file is subject to version 3.0 of the PHP license
- * that is available through the world-wide-web at the following URI:
- * http://www.php.net/license/3_0.txt. If you did not receive a copy of
- * the PHP License and are unable to obtain it through the web, please
- * send a note to license@php.net so we can mail you a copy immediately.
- *
- * @copyright 2004-2006 Andrey Demenev
- * @license http://www.php.net/license/3_0.txt PHP License
- * @link http://pear.php.net/package/Text_Highlighter
- * @category Text
- * @package Text_Highlighter
+ *
+ *
+ * PHP version 4 and 5
+ *
+ * LICENSE: This source file is subject to version 3.0 of the PHP license
+ * that is available through the world-wide-web at the following URI:
+ * http://www.php.net/license/3_0.txt. If you did not receive a copy of
+ * the PHP License and are unable to obtain it through the web, please
+ * send a note to license@php.net so we can mail you a copy immediately.
+ *
+ * @copyright 2004-2006 Andrey Demenev
+ * @license http://www.php.net/license/3_0.txt PHP License
+ * @link http://pear.php.net/package/Text_Highlighter
+ * @category Text
+ * @package Text_Highlighter
* @version generated from: : cpp.xml,v 1.1 2007/06/03 02:35:28 ssttoo Exp
* @author Aaron Kalin
* @author Andrey Demenev <demenev@gmail.com>
- *
- */
-
-/**
- * Auto-generated class. CPP syntax highlighting
- *
+ *
+ */
+
+/**
+ * Auto-generated class. CPP syntax highlighting
+ *
* @author Aaron Kalin
* @author Andrey Demenev <demenev@gmail.com>
- * @category Text
- * @package Text_Highlighter
- * @copyright 2004-2006 Andrey Demenev
- * @license http://www.php.net/license/3_0.txt PHP License
- * @version Release: 0.7.0
- * @link http://pear.php.net/package/Text_Highlighter
- */
-class Text_Highlighter_CPP extends Text_Highlighter
-{
+ * @category Text
+ * @package Text_Highlighter
+ * @copyright 2004-2006 Andrey Demenev
+ * @license http://www.php.net/license/3_0.txt PHP License
+ * @version Release: 0.7.0
+ * @link http://pear.php.net/package/Text_Highlighter
+ */
+class Text_Highlighter_CPP extends Text_Highlighter
+{
var $_language = 'cpp';
- /**
- * Constructor
- *
- * @param array $options
- * @access public
- */
- function __construct($options=array())
- {
-
+ /**
+ * Constructor
+ *
+ * @param array $options
+ * @access public
+ */
+ function __construct($options=array())
+ {
+
$this->_options = $options;
$this->_regs = array (
-1 => '/((?i)")|((?i)\\{)|((?i)\\()|((?i)\\[)|((?i)[a-z_]\\w*)|((?mi)^[ \\t]*#include)|((?mii)^[ \\t]*#[ \\t]*[a-z]+)|((?i)\\d*\\.?\\d+)|((?i)\\/\\*)|((?i)\\/\\/.+)/',
@@ -833,8 +833,8 @@ class Text_Highlighter_CPP extends Text_Highlighter
'types' => 'types',
'Common Macros' => 'prepro',
);
- $this->_defClass = 'code';
- $this->_checkDefines();
- }
-
+ $this->_defClass = 'code';
+ $this->_checkDefines();
+ }
+
} \ No newline at end of file
diff --git a/framework/3rdParty/TextHighlighter/Text/Highlighter/CSS.php b/framework/3rdParty/TextHighlighter/Text/Highlighter/CSS.php
index 04705ff6..28f92f34 100644
--- a/framework/3rdParty/TextHighlighter/Text/Highlighter/CSS.php
+++ b/framework/3rdParty/TextHighlighter/Text/Highlighter/CSS.php
@@ -1,49 +1,49 @@
-<?php
-/**
- * Auto-generated class. CSS syntax highlighting
- *
- * PHP version 4 and 5
- *
- * LICENSE: This source file is subject to version 3.0 of the PHP license
- * that is available through the world-wide-web at the following URI:
- * http://www.php.net/license/3_0.txt. If you did not receive a copy of
- * the PHP License and are unable to obtain it through the web, please
- * send a note to license@php.net so we can mail you a copy immediately.
- *
- * @copyright 2004-2006 Andrey Demenev
- * @license http://www.php.net/license/3_0.txt PHP License
- * @link http://pear.php.net/package/Text_Highlighter
- * @category Text
- * @package Text_Highlighter
+<?php
+/**
+ * Auto-generated class. CSS syntax highlighting
+ *
+ * PHP version 4 and 5
+ *
+ * LICENSE: This source file is subject to version 3.0 of the PHP license
+ * that is available through the world-wide-web at the following URI:
+ * http://www.php.net/license/3_0.txt. If you did not receive a copy of
+ * the PHP License and are unable to obtain it through the web, please
+ * send a note to license@php.net so we can mail you a copy immediately.
+ *
+ * @copyright 2004-2006 Andrey Demenev
+ * @license http://www.php.net/license/3_0.txt PHP License
+ * @link http://pear.php.net/package/Text_Highlighter
+ * @category Text
+ * @package Text_Highlighter
* @version generated from: : css.xml,v 1.1 2007/06/03 02:35:28 ssttoo Exp
* @author Andrey Demenev <demenev@gmail.com>
- *
- */
-
-/**
- * Auto-generated class. CSS syntax highlighting
- *
+ *
+ */
+
+/**
+ * Auto-generated class. CSS syntax highlighting
+ *
* @author Andrey Demenev <demenev@gmail.com>
- * @category Text
- * @package Text_Highlighter
- * @copyright 2004-2006 Andrey Demenev
- * @license http://www.php.net/license/3_0.txt PHP License
- * @version Release: 0.7.0
- * @link http://pear.php.net/package/Text_Highlighter
- */
-class Text_Highlighter_CSS extends Text_Highlighter
-{
+ * @category Text
+ * @package Text_Highlighter
+ * @copyright 2004-2006 Andrey Demenev
+ * @license http://www.php.net/license/3_0.txt PHP License
+ * @version Release: 0.7.0
+ * @link http://pear.php.net/package/Text_Highlighter
+ */
+class Text_Highlighter_CSS extends Text_Highlighter
+{
var $_language = 'css';
- /**
- * Constructor
- *
- * @param array $options
- * @access public
- */
- function __construct($options=array())
- {
-
+ /**
+ * Constructor
+ *
+ * @param array $options
+ * @access public
+ */
+ function __construct($options=array())
+ {
+
$this->_options = $options;
$this->_regs = array (
-1 => '/((?i)(@[a-z\\d]+))|((?i)(((\\.|#)?[a-z]+[a-z\\d\\-]*(?![a-z\\d\\-]))|(\\*))(?!\\s*:\\s*[\\s\\{]))|((?i):[a-z][a-z\\d\\-]*)|((?i)\\[)|((?i)\\{)/',
@@ -376,8 +376,8 @@ class Text_Highlighter_CSS extends Text_Highlighter
'propertyValue' => 'string',
'namedcolor' => 'var',
);
- $this->_defClass = 'code';
- $this->_checkDefines();
- }
-
+ $this->_defClass = 'code';
+ $this->_checkDefines();
+ }
+
} \ No newline at end of file
diff --git a/framework/3rdParty/TextHighlighter/Text/Highlighter/DIFF.php b/framework/3rdParty/TextHighlighter/Text/Highlighter/DIFF.php
index c27301f5..21e97087 100644
--- a/framework/3rdParty/TextHighlighter/Text/Highlighter/DIFF.php
+++ b/framework/3rdParty/TextHighlighter/Text/Highlighter/DIFF.php
@@ -1,49 +1,49 @@
-<?php
-/**
- * Auto-generated class. DIFF syntax highlighting
- *
- * PHP version 4 and 5
- *
- * LICENSE: This source file is subject to version 3.0 of the PHP license
- * that is available through the world-wide-web at the following URI:
- * http://www.php.net/license/3_0.txt. If you did not receive a copy of
- * the PHP License and are unable to obtain it through the web, please
- * send a note to license@php.net so we can mail you a copy immediately.
- *
- * @copyright 2004-2006 Andrey Demenev
- * @license http://www.php.net/license/3_0.txt PHP License
- * @link http://pear.php.net/package/Text_Highlighter
- * @category Text
- * @package Text_Highlighter
+<?php
+/**
+ * Auto-generated class. DIFF syntax highlighting
+ *
+ * PHP version 4 and 5
+ *
+ * LICENSE: This source file is subject to version 3.0 of the PHP license
+ * that is available through the world-wide-web at the following URI:
+ * http://www.php.net/license/3_0.txt. If you did not receive a copy of
+ * the PHP License and are unable to obtain it through the web, please
+ * send a note to license@php.net so we can mail you a copy immediately.
+ *
+ * @copyright 2004-2006 Andrey Demenev
+ * @license http://www.php.net/license/3_0.txt PHP License
+ * @link http://pear.php.net/package/Text_Highlighter
+ * @category Text
+ * @package Text_Highlighter
* @version generated from: : diff.xml,v 1.1 2007/06/03 02:35:28 ssttoo Exp
* @author Andrey Demenev <demenev@gmail.com>
- *
- */
-
-/**
- * Auto-generated class. DIFF syntax highlighting
- *
+ *
+ */
+
+/**
+ * Auto-generated class. DIFF syntax highlighting
+ *
* @author Andrey Demenev <demenev@gmail.com>
- * @category Text
- * @package Text_Highlighter
- * @copyright 2004-2006 Andrey Demenev
- * @license http://www.php.net/license/3_0.txt PHP License
- * @version Release: 0.7.0
- * @link http://pear.php.net/package/Text_Highlighter
- */
-class Text_Highlighter_DIFF extends Text_Highlighter
-{
+ * @category Text
+ * @package Text_Highlighter
+ * @copyright 2004-2006 Andrey Demenev
+ * @license http://www.php.net/license/3_0.txt PHP License
+ * @version Release: 0.7.0
+ * @link http://pear.php.net/package/Text_Highlighter
+ */
+class Text_Highlighter_DIFF extends Text_Highlighter
+{
var $_language = 'diff';
- /**
- * Constructor
- *
- * @param array $options
- * @access public
- */
- function __construct($options=array())
- {
-
+ /**
+ * Constructor
+ *
+ * @param array $options
+ * @access public
+ */
+ function __construct($options=array())
+ {
+
$this->_options = $options;
$this->_regs = array (
-1 => '/((?m)^\\\\\\sNo\\snewline.+$)|((?m)^\\-\\-\\-$)|((?m)^(diff\\s+\\-|Only\\s+|Index).*$)|((?m)^(\\-\\-\\-|\\+\\+\\+)\\s.+$)|((?m)^\\*.*$)|((?m)^\\+.*$)|((?m)^!.*$)|((?m)^\\<\\s.*$)|((?m)^\\>\\s.*$)|((?m)^\\d+(\\,\\d+)?[acd]\\d+(,\\d+)?$)|((?m)^\\-.*$)|((?m)^\\+.*$)|((?m)^@@.+@@$)|((?m)^d\\d+\\s\\d+$)|((?m)^a\\d+\\s\\d+$)|((?m)^(\\d+)(,\\d+)?(a)$)|((?m)^(\\d+)(,\\d+)?(c)$)|((?m)^(\\d+)(,\\d+)?(d)$)|((?m)^a(\\d+)(\\s\\d+)?$)|((?m)^c(\\d+)(\\s\\d+)?$)|((?m)^d(\\d+)(\\s\\d+)?$)/',
@@ -359,8 +359,8 @@ class Text_Highlighter_DIFF extends Text_Highlighter
);
$this->_kwmap = array (
);
- $this->_defClass = 'default';
- $this->_checkDefines();
- }
-
+ $this->_defClass = 'default';
+ $this->_checkDefines();
+ }
+
} \ No newline at end of file
diff --git a/framework/3rdParty/TextHighlighter/Text/Highlighter/DTD.php b/framework/3rdParty/TextHighlighter/Text/Highlighter/DTD.php
index ad33e528..1d4a403e 100644
--- a/framework/3rdParty/TextHighlighter/Text/Highlighter/DTD.php
+++ b/framework/3rdParty/TextHighlighter/Text/Highlighter/DTD.php
@@ -1,49 +1,49 @@
-<?php
-/**
- * Auto-generated class. DTD syntax highlighting
- *
- * PHP version 4 and 5
- *
- * LICENSE: This source file is subject to version 3.0 of the PHP license
- * that is available through the world-wide-web at the following URI:
- * http://www.php.net/license/3_0.txt. If you did not receive a copy of
- * the PHP License and are unable to obtain it through the web, please
- * send a note to license@php.net so we can mail you a copy immediately.
- *
- * @copyright 2004-2006 Andrey Demenev
- * @license http://www.php.net/license/3_0.txt PHP License
- * @link http://pear.php.net/package/Text_Highlighter
- * @category Text
- * @package Text_Highlighter
+<?php
+/**
+ * Auto-generated class. DTD syntax highlighting
+ *
+ * PHP version 4 and 5
+ *
+ * LICENSE: This source file is subject to version 3.0 of the PHP license
+ * that is available through the world-wide-web at the following URI:
+ * http://www.php.net/license/3_0.txt. If you did not receive a copy of
+ * the PHP License and are unable to obtain it through the web, please
+ * send a note to license@php.net so we can mail you a copy immediately.
+ *
+ * @copyright 2004-2006 Andrey Demenev
+ * @license http://www.php.net/license/3_0.txt PHP License
+ * @link http://pear.php.net/package/Text_Highlighter
+ * @category Text
+ * @package Text_Highlighter
* @version generated from: : dtd.xml,v 1.1 2007/06/03 02:35:28 ssttoo Exp
* @author Andrey Demenev <demenev@gmail.com>
- *
- */
-
-/**
- * Auto-generated class. DTD syntax highlighting
- *
+ *
+ */
+
+/**
+ * Auto-generated class. DTD syntax highlighting
+ *
* @author Andrey Demenev <demenev@gmail.com>
- * @category Text
- * @package Text_Highlighter
- * @copyright 2004-2006 Andrey Demenev
- * @license http://www.php.net/license/3_0.txt PHP License
- * @version Release: 0.7.0
- * @link http://pear.php.net/package/Text_Highlighter
- */
-class Text_Highlighter_DTD extends Text_Highlighter
-{
+ * @category Text
+ * @package Text_Highlighter
+ * @copyright 2004-2006 Andrey Demenev
+ * @license http://www.php.net/license/3_0.txt PHP License
+ * @version Release: 0.7.0
+ * @link http://pear.php.net/package/Text_Highlighter
+ */
+class Text_Highlighter_DTD extends Text_Highlighter
+{
var $_language = 'dtd';
- /**
- * Constructor
- *
- * @param array $options
- * @access public
- */
- function __construct($options=array())
- {
-
+ /**
+ * Constructor
+ *
+ * @param array $options
+ * @access public
+ */
+ function __construct($options=array())
+ {
+
$this->_options = $options;
$this->_regs = array (
-1 => '/(\\<!--)|(\\<\\!\\[)|((\\&|\\%)[\\w\\-\\.]+;)/',
@@ -401,8 +401,8 @@ class Text_Highlighter_DTD extends Text_Highlighter
);
$this->_kwmap = array (
);
- $this->_defClass = 'code';
- $this->_checkDefines();
- }
-
+ $this->_defClass = 'code';
+ $this->_checkDefines();
+ }
+
} \ No newline at end of file
diff --git a/framework/3rdParty/TextHighlighter/Text/Highlighter/Generator.php b/framework/3rdParty/TextHighlighter/Text/Highlighter/Generator.php
index 896af078..c9bca6aa 100644
--- a/framework/3rdParty/TextHighlighter/Text/Highlighter/Generator.php
+++ b/framework/3rdParty/TextHighlighter/Text/Highlighter/Generator.php
@@ -1,1254 +1,1254 @@
-<?php
-/* vim: set expandtab tabstop=4 shiftwidth=4 softtabstop=4: */
-/**
-* Syntax highlighter class generator
-*
-* To simplify the process of creating new syntax highlighters
-* for different languages, {@link Text_Highlighter_Generator} class is
-* provided. It takes highlighting rules from XML file and generates
-* a code of a class inherited from {@link Text_Highlighter}.
-*
-* PHP versions 4 and 5
-*
-* LICENSE: This source file is subject to version 3.0 of the PHP license
-* that is available through the world-wide-web at the following URI:
-* http://www.php.net/license/3_0.txt. If you did not receive a copy of
-* the PHP License and are unable to obtain it through the web, please
-* send a note to license@php.net so we can mail you a copy immediately.
-*
-* @category Text
-* @package Text_Highlighter
-* @author Andrey Demenev <demenev@gmail.com>
-* @copyright 2004-2006 Andrey Demenev
-* @license http://www.php.net/license/3_0.txt PHP License
-* @version CVS: $Id: Generator.php,v 1.1 2007/06/03 02:36:35 ssttoo Exp $
-* @link http://pear.php.net/package/Text_Highlighter
-*/
-
-// {{{ error codes
-
-define ('TEXT_HIGHLIGHTER_EMPTY_RE', 1);
-define ('TEXT_HIGHLIGHTER_INVALID_RE', 2);
-define ('TEXT_HIGHLIGHTER_EMPTY_OR_MISSING', 3);
-define ('TEXT_HIGHLIGHTER_EMPTY', 4);
-define ('TEXT_HIGHLIGHTER_REGION_REGION', 5);
-define ('TEXT_HIGHLIGHTER_REGION_BLOCK', 6);
-define ('TEXT_HIGHLIGHTER_BLOCK_REGION', 7);
-define ('TEXT_HIGHLIGHTER_KEYWORD_BLOCK', 8);
-define ('TEXT_HIGHLIGHTER_KEYWORD_INHERITS', 9);
-define ('TEXT_HIGHLIGHTER_PARSE', 10);
-define ('TEXT_HIGHLIGHTER_FILE_WRITE', 11);
-define ('TEXT_HIGHLIGHTER_FILE_READ', 12);
-// }}}
-
-/**
-* Syntax highliter class generator class
-*
-* This class is used to generate PHP classes
-* from XML files with highlighting rules
-*
-* Usage example
-* <code>
-*require_once 'Text/Highlighter/Generator.php';
-*$generator =& new Text_Highlighter_Generator('php.xml');
-*$generator->generate();
-*$generator->saveCode('PHP.php');
-* </code>
-*
-* A command line script <b>generate</b> is provided for
-* class generation (installs in scripts/Text/Highlighter).
-*
-* @author Andrey Demenev <demenev@gmail.com>
-* @copyright 2004-2006 Andrey Demenev
-* @license http://www.php.net/license/3_0.txt PHP License
-* @version Release: 0.7.0
-* @link http://pear.php.net/package/Text_Highlighter
-*/
-
-class Text_Highlighter_Generator extends XML_Parser
-{
- // {{{ properties
- /**
- * Whether to do case folding.
- * We have to declare it here, because XML_Parser
- * sets case folding in constructor
- *
- * @var boolean
- */
- var $folding = false;
-
- /**
- * Holds name of file with highlighting rules
- *
- * @var string
- * @access private
- */
- var $_syntaxFile;
-
- /**
- * Current element being processed
- *
- * @var array
- * @access private
- */
- var $_element;
-
- /**
- * List of regions
- *
- * @var array
- * @access private
- */
- var $_regions = array();
-
- /**
- * List of blocks
- *
- * @var array
- * @access private
- */
- var $_blocks = array();
-
- /**
- * List of keyword groups
- *
- * @var array
- * @access private
- */
- var $_keywords = array();
-
- /**
- * List of authors
- *
- * @var array
- * @access private
- */
- var $_authors = array();
-
- /**
- * Name of language
- *
- * @var string
- * @access public
- */
- var $language = '';
-
- /**
- * Generated code
- *
- * @var string
- * @access private
- */
- var $_code = '';
-
- /**
- * Default class
- *
- * @var string
- * @access private
- */
- var $_defClass = 'default';
-
- /**
- * Comment
- *
- * @var string
- * @access private
- */
- var $_comment = '';
-
- /**
- * Flag for comment processing
- *
- * @var boolean
- * @access private
- */
- var $_inComment = false;
-
- /**
- * Sorting order of current block/region
- *
- * @var integer
- * @access private
- */
- var $_blockOrder = 0;
-
- /**
- * Generation errors
- *
- * @var array
- * @access private
- */
- var $_errors;
-
- // }}}
- // {{{ constructor
-
- /**
- * Constructor
- *
- * @param string $syntaxFile Name of XML file
- * with syntax highlighting rules
- *
- * @access public
- */
-
- function __construct($syntaxFile = '')
- {
- XML_Parser::XML_Parser(null, 'func');
- $this->_errors = array();
- $this->_declareErrorMessages();
- if ($syntaxFile) {
- $this->setInputFile($syntaxFile);
- }
- }
-
- // }}}
- // {{{ _formatError
-
- /**
- * Format error message
- *
- * @param int $code error code
- * @param string $params parameters
- * @param string $fileName file name
- * @param int $lineNo line number
- * @return array
- * @access public
- */
- function _formatError($code, $params, $fileName, $lineNo)
- {
- $template = $this->_templates[$code];
- $ret = call_user_func_array('sprintf', array_merge(array($template), $params));
- if ($fileName) {
- $ret = '[' . $fileName . '] ' . $ret;
- }
- if ($lineNo) {
- $ret .= ' (line ' . $lineNo . ')';
- }
- return $ret;
- }
-
- // }}}
- // {{{ declareErrorMessages
-
- /**
- * Set up error message templates
- *
- * @access private
- */
- function _declareErrorMessages()
- {
- $this->_templates = array (
- TEXT_HIGHLIGHTER_EMPTY_RE => 'Empty regular expression',
- TEXT_HIGHLIGHTER_INVALID_RE => 'Invalid regular expression : %s',
- TEXT_HIGHLIGHTER_EMPTY_OR_MISSING => 'Empty or missing %s',
- TEXT_HIGHLIGHTER_EMPTY => 'Empty %s',
- TEXT_HIGHLIGHTER_REGION_REGION => 'Region %s refers undefined region %s',
- TEXT_HIGHLIGHTER_REGION_BLOCK => 'Region %s refers undefined block %s',
- TEXT_HIGHLIGHTER_BLOCK_REGION => 'Block %s refers undefined region %s',
- TEXT_HIGHLIGHTER_KEYWORD_BLOCK => 'Keyword group %s refers undefined block %s',
- TEXT_HIGHLIGHTER_KEYWORD_INHERITS => 'Keyword group %s inherits undefined block %s',
- TEXT_HIGHLIGHTER_PARSE => '%s',
- TEXT_HIGHLIGHTER_FILE_WRITE => 'Error writing file %s',
- TEXT_HIGHLIGHTER_FILE_READ => '%s'
- );
- }
-
- // }}}
- // {{{ setInputFile
-
- /**
- * Sets the input xml file to be parsed
- *
- * @param string Filename (full path)
- * @return boolean
- * @access public
- */
- function setInputFile($file)
- {
- $this->_syntaxFile = $file;
- $ret = parent::setInputFile($file);
- if (PEAR::isError($ret)) {
- $this->_error(TEXT_HIGHLIGHTER_FILE_READ, $ret->message);
- return false;
- }
- return true;
- }
-
- // }}}
- // {{{ generate
-
- /**
- * Generates class code
- *
- * @access public
- */
-
- function generate()
- {
- $this->_regions = array();
- $this->_blocks = array();
- $this->_keywords = array();
- $this->language = '';
- $this->_code = '';
- $this->_defClass = 'default';
- $this->_comment = '';
- $this->_inComment = false;
- $this->_authors = array();
- $this->_blockOrder = 0;
- $this->_errors = array();
-
- $ret = $this->parse();
- if (PEAR::isError($ret)) {
- $this->_error(TEXT_HIGHLIGHTER_PARSE, $ret->message);
- return false;
- }
- return true;
- }
-
- // }}}
- // {{{ getCode
-
- /**
- * Returns generated code as a string.
- *
- * @return string Generated code
- * @access public
- */
-
- function getCode()
- {
- return $this->_code;
- }
-
- // }}}
- // {{{ saveCode
-
- /**
- * Saves generated class to file. Note that {@link Text_Highlighter::factory()}
- * assumes that filename is uppercase (SQL.php, DTD.php, etc), and file
- * is located in Text/Highlighter
- *
- * @param string $filename Name of file to write the code to
- * @return boolean true on success, false on failure
- * @access public
- */
-
- function saveCode($filename)
- {
- $f = @fopen($filename, 'wb');
- if (!$f) {
- $this->_error(TEXT_HIGHLIGHTER_FILE_WRITE, array('outfile'=>$filename));
- return false;
- }
- fwrite ($f, $this->_code);
- fclose($f);
- return true;
- }
-
- // }}}
- // {{{ hasErrors
-
- /**
- * Reports if there were errors
- *
- * @return boolean
- * @access public
- */
-
- function hasErrors()
- {
- return count($this->_errors) > 0;
- }
-
- // }}}
- // {{{ getErrors
-
- /**
- * Returns errors
- *
- * @return array
- * @access public
- */
-
- function getErrors()
- {
- return $this->_errors;
- }
-
- // }}}
- // {{{ _sortBlocks
-
- /**
- * Sorts blocks
- *
- * @access private
- */
-
- function _sortBlocks($b1, $b2) {
- return $b1['order'] - $b2['order'];
- }
-
- // }}}
- // {{{ _sortLookFor
- /**
- * Sort 'look for' list
- * @return int
- * @param string $b1
- * @param string $b2
- */
- function _sortLookFor($b1, $b2) {
- $o1 = isset($this->_blocks[$b1]) ? $this->_blocks[$b1]['order'] : $this->_regions[$b1]['order'];
- $o2 = isset($this->_blocks[$b2]) ? $this->_blocks[$b2]['order'] : $this->_regions[$b2]['order'];
- return $o1 - $o2;
- }
-
- // }}}
- // {{{ _makeRE
-
- /**
- * Adds delimiters and modifiers to regular expression if necessary
- *
- * @param string $text Original RE
- * @return string Final RE
- * @access private
- */
- function _makeRE($text, $case = false)
- {
- if (!strlen($text)) {
- $this->_error(TEXT_HIGHLIGHTER_EMPTY_RE);
- }
- if (!strlen($text) || $text{0} != '/') {
- $text = '/' . $text . '/';
- }
- if (!$case) {
- $text .= 'i';
- }
- $php_errormsg = '';
- @preg_match($text, '');
- if ($php_errormsg) {
- $this->_error(TEXT_HIGHLIGHTER_INVALID_RE, $php_errormsg);
- }
- preg_match ('#^/(.+)/(.*)$#', $text, $m);
- if (@$m[2]) {
- $text = '(?' . $m[2] . ')' . $m[1];
- } else {
- $text = $m[1];
- }
- return $text;
- }
-
- // }}}
- // {{{ _exportArray
-
- /**
- * Exports array as PHP code
- *
- * @param array $array
- * @return string Code
- * @access private
- */
- function _exportArray($array)
- {
- $array = var_export($array, true);
- return trim(preg_replace('~^(\s*)~m',' \1\1',$array));
- }
-
- // }}}
- // {{{ _countSubpatterns
- /**
- * Find number of capturing suppaterns in regular expression
- * @return int
- * @param string $re Regular expression (without delimiters)
- */
- function _countSubpatterns($re)
- {
- preg_match_all('/' . $re . '/', '', $m);
- return count($m)-1;
- }
-
- // }}}
-
- /**#@+
- * @access private
- * @param resource $xp XML parser resource
- * @param string $elem XML element name
- * @param array $attribs XML element attributes
- */
-
- // {{{ xmltag_Default
-
- /**
- * start handler for <default> element
- */
- function xmltag_Default($xp, $elem, $attribs)
- {
- $this->_aliasAttributes($attribs);
- if (!isset($attribs['innerGroup']) || $attribs['innerGroup'] === '') {
- $this->_error(TEXT_HIGHLIGHTER_EMPTY_OR_MISSING, 'innerGroup');
- }
- $this->_defClass = @$attribs['innerGroup'];
- }
-
- // }}}
- // {{{ xmltag_Region
-
- /**
- * start handler for <region> element
- */
- function xmltag_Region($xp, $elem, $attribs)
- {
- $this->_aliasAttributes($attribs);
- if (!isset($attribs['name']) || $attribs['name'] === '') {
- $this->_error(TEXT_HIGHLIGHTER_EMPTY_OR_MISSING, 'region name');
- }
- if (!isset($attribs['innerGroup']) || $attribs['innerGroup'] === '') {
- $this->_error(TEXT_HIGHLIGHTER_EMPTY_OR_MISSING, 'innerGroup');
- }
- $this->_element = array('name' => $attribs['name']);
- $this->_element['line'] = xml_get_current_line_number($this->parser);
- if (isset($attribs['case'])) {
- $this->_element['case'] = $attribs['case'] == 'yes';
- } else {
- $this->_element['case'] = $this->_case;
- }
- $this->_element['innerGroup'] = $attribs['innerGroup'];
- $this->_element['delimGroup'] = isset($attribs['delimGroup']) ?
- $attribs['delimGroup'] :
- $attribs['innerGroup'];
- $this->_element['start'] = $this->_makeRE(@$attribs['start'], $this->_element['case']);
- $this->_element['end'] = $this->_makeRE(@$attribs['end'], $this->_element['case']);
- $this->_element['contained'] = @$attribs['contained'] == 'yes';
- $this->_element['never-contained'] = @$attribs['never-contained'] == 'yes';
- $this->_element['remember'] = @$attribs['remember'] == 'yes';
- if (isset($attribs['startBOL']) && $attribs['startBOL'] == 'yes') {
- $this->_element['startBOL'] = true;
- }
- if (isset($attribs['endBOL']) && $attribs['endBOL'] == 'yes') {
- $this->_element['endBOL'] = true;
- }
- if (isset($attribs['neverAfter'])) {
- $this->_element['neverafter'] = $this->_makeRE($attribs['neverAfter']);
- }
- }
-
- // }}}
- // {{{ xmltag_Block
-
- /**
- * start handler for <block> element
- */
- function xmltag_Block($xp, $elem, $attribs)
- {
- $this->_aliasAttributes($attribs);
- if (!isset($attribs['name']) || $attribs['name'] === '') {
- $this->_error(TEXT_HIGHLIGHTER_EMPTY_OR_MISSING, 'block name');
- }
- if (isset($attribs['innerGroup']) && $attribs['innerGroup'] === '') {
- $this->_error(TEXT_HIGHLIGHTER_EMPTY, 'innerGroup');
- }
- $this->_element = array('name' => $attribs['name']);
- $this->_element['line'] = xml_get_current_line_number($this->parser);
- if (isset($attribs['case'])) {
- $this->_element['case'] = $attribs['case'] == 'yes';
- } else {
- $this->_element['case'] = $this->_case;
- }
- if (isset($attribs['innerGroup'])) {
- $this->_element['innerGroup'] = @$attribs['innerGroup'];
- }
- $this->_element['match'] = $this->_makeRE($attribs['match'], $this->_element['case']);
- $this->_element['contained'] = @$attribs['contained'] == 'yes';
- $this->_element['multiline'] = @$attribs['multiline'] == 'yes';
- if (isset($attribs['BOL']) && $attribs['BOL'] == 'yes') {
- $this->_element['BOL'] = true;
- }
- if (isset($attribs['neverAfter'])) {
- $this->_element['neverafter'] = $this->_makeRE($attribs['neverAfter']);
- }
- }
-
- // }}}
- // {{{ cdataHandler
-
- /**
- * Character data handler. Used for comment
- */
- function cdataHandler($xp, $cdata)
- {
- if ($this->_inComment) {
- $this->_comment .= $cdata;
- }
- }
-
- // }}}
- // {{{ xmltag_Comment
-
- /**
- * start handler for <comment> element
- */
- function xmltag_Comment($xp, $elem, $attribs)
- {
- $this->_comment = '';
- $this->_inComment = true;
- }
-
- // }}}
- // {{{ xmltag_PartGroup
-
- /**
- * start handler for <partgroup> element
- */
- function xmltag_PartGroup($xp, $elem, $attribs)
- {
- $this->_aliasAttributes($attribs);
- if (!isset($attribs['innerGroup']) || $attribs['innerGroup'] === '') {
- $this->_error(TEXT_HIGHLIGHTER_EMPTY_OR_MISSING, 'innerGroup');
- }
- $this->_element['partClass'][$attribs['index']] = @$attribs['innerGroup'];
- }
-
- // }}}
- // {{{ xmltag_PartClass
-
- /**
- * start handler for <partclass> element
- */
- function xmltag_PartClass($xp, $elem, $attribs)
- {
- $this->xmltag_PartGroup($xp, $elem, $attribs);
- }
-
- // }}}
- // {{{ xmltag_Keywords
-
- /**
- * start handler for <keywords> element
- */
- function xmltag_Keywords($xp, $elem, $attribs)
- {
- $this->_aliasAttributes($attribs);
- if (!isset($attribs['name']) || $attribs['name'] === '') {
- $this->_error(TEXT_HIGHLIGHTER_EMPTY_OR_MISSING, 'keyword group name');
- }
- if (!isset($attribs['innerGroup']) || $attribs['innerGroup'] === '') {
- $this->_error(TEXT_HIGHLIGHTER_EMPTY_OR_MISSING, 'innerGroup');
- }
- if (!isset($attribs['inherits']) || $attribs['inherits'] === '') {
- $this->_error(TEXT_HIGHLIGHTER_EMPTY_OR_MISSING, 'inherits');
- }
- $this->_element = array('name'=>@$attribs['name']);
- $this->_element['line'] = xml_get_current_line_number($this->parser);
- $this->_element['innerGroup'] = @$attribs['innerGroup'];
- if (isset($attribs['case'])) {
- $this->_element['case'] = $attribs['case'] == 'yes';
- } else {
- $this->_element['case'] = $this->_case;
- }
- $this->_element['inherits'] = @$attribs['inherits'];
- if (isset($attribs['otherwise'])) {
- $this->_element['otherwise'] = $attribs['otherwise'];
- }
- if (isset($attribs['ifdef'])) {
- $this->_element['ifdef'] = $attribs['ifdef'];
- }
- if (isset($attribs['ifndef'])) {
- $this->_element['ifndef'] = $attribs['ifndef'];
- }
- }
-
- // }}}
- // {{{ xmltag_Keyword
-
- /**
- * start handler for <keyword> element
- */
- function xmltag_Keyword($xp, $elem, $attribs)
- {
- if (!isset($attribs['match']) || $attribs['match'] === '') {
- $this->_error(TEXT_HIGHLIGHTER_EMPTY_OR_MISSING, 'match');
- }
- $keyword = @$attribs['match'];
- if (!$this->_element['case']) {
- $keyword = strtolower($keyword);
- }
- $this->_element['match'][$keyword] = true;
- }
-
- // }}}
- // {{{ xmltag_Contains
-
- /**
- * start handler for <contains> element
- */
- function xmltag_Contains($xp, $elem, $attribs)
- {
- $this->_element['contains-all'] = @$attribs['all'] == 'yes';
- if (isset($attribs['region'])) {
- $this->_element['contains']['region'][$attribs['region']] =
- xml_get_current_line_number($this->parser);
- }
- if (isset($attribs['block'])) {
- $this->_element['contains']['block'][$attribs['block']] =
- xml_get_current_line_number($this->parser);
- }
- }
-
- // }}}
- // {{{ xmltag_But
-
- /**
- * start handler for <but> element
- */
- function xmltag_But($xp, $elem, $attribs)
- {
- if (isset($attribs['region'])) {
- $this->_element['not-contains']['region'][$attribs['region']] = true;
- }
- if (isset($attribs['block'])) {
- $this->_element['not-contains']['block'][$attribs['block']] = true;
- }
- }
-
- // }}}
- // {{{ xmltag_Onlyin
-
- /**
- * start handler for <onlyin> element
- */
- function xmltag_Onlyin($xp, $elem, $attribs)
- {
- if (!isset($attribs['region']) || $attribs['region'] === '') {
- $this->_error(TEXT_HIGHLIGHTER_EMPTY_OR_MISSING, 'region');
- }
- $this->_element['onlyin'][$attribs['region']] = xml_get_current_line_number($this->parser);
- }
-
- // }}}
- // {{{ xmltag_Author
-
- /**
- * start handler for <author> element
- */
- function xmltag_Author($xp, $elem, $attribs)
- {
- if (!isset($attribs['name']) || $attribs['name'] === '') {
- $this->_error(TEXT_HIGHLIGHTER_EMPTY_OR_MISSING, 'author name');
- }
- $this->_authors[] = array(
- 'name' => @$attribs['name'],
- 'email' => (string)@$attribs['email']
- );
- }
-
- // }}}
- // {{{ xmltag_Highlight
-
- /**
- * start handler for <highlight> element
- */
- function xmltag_Highlight($xp, $elem, $attribs)
- {
- if (!isset($attribs['lang']) || $attribs['lang'] === '') {
- $this->_error(TEXT_HIGHLIGHTER_EMPTY_OR_MISSING, 'language name');
- }
- $this->_code = '';
- $this->language = strtoupper(@$attribs['lang']);
- $this->_case = @$attribs['case'] == 'yes';
- }
-
- // }}}
-
- /**#@-*/
-
- // {{{ _error
-
- /**
- * Add an error message
- *
- * @param integer $code Error code
- * @param mixed $message Error message or array with error message parameters
- * @param integer $lineNo Source code line number
- * @access private
- */
- function _error($code, $params = array(), $lineNo = 0)
- {
- if (!$lineNo && !empty($this->parser)) {
- $lineNo = xml_get_current_line_number($this->parser);
- }
- $this->_errors[] = $this->_formatError($code, $params, $this->_syntaxFile, $lineNo);
- }
-
- // }}}
- // {{{ _aliasAttributes
-
- /**
- * BC trick
- *
- * @param array $attrs attributes
- */
- function _aliasAttributes(&$attrs)
- {
- if (isset($attrs['innerClass']) && !isset($attrs['innerGroup'])) {
- $attrs['innerGroup'] = $attrs['innerClass'];
- }
- if (isset($attrs['delimClass']) && !isset($attrs['delimGroup'])) {
- $attrs['delimGroup'] = $attrs['delimClass'];
- }
- if (isset($attrs['partClass']) && !isset($attrs['partGroup'])) {
- $attrs['partGroup'] = $attrs['partClass'];
- }
- }
-
- // }}}
-
- /**#@+
- * @access private
- * @param resource $xp XML parser resource
- * @param string $elem XML element name
- */
-
- // {{{ xmltag_Comment_
-
- /**
- * end handler for <comment> element
- */
- function xmltag_Comment_($xp, $elem)
- {
- $this->_inComment = false;
- }
-
- // }}}
- // {{{ xmltag_Region_
-
- /**
- * end handler for <region> element
- */
- function xmltag_Region_($xp, $elem)
- {
- $this->_element['type'] = 'region';
- $this->_element['order'] = $this->_blockOrder ++;
- $this->_regions[$this->_element['name']] = $this->_element;
- }
-
- // }}}
- // {{{ xmltag_Keywords_
-
- /**
- * end handler for <keywords> element
- */
- function xmltag_Keywords_($xp, $elem)
- {
- $this->_keywords[$this->_element['name']] = $this->_element;
- }
-
- // }}}
- // {{{ xmltag_Block_
-
- /**
- * end handler for <block> element
- */
- function xmltag_Block_($xp, $elem)
- {
- $this->_element['type'] = 'block';
- $this->_element['order'] = $this->_blockOrder ++;
- $this->_blocks[$this->_element['name']] = $this->_element;
- }
-
- // }}}
- // {{{ xmltag_Highlight_
-
- /**
- * end handler for <highlight> element
- */
- function xmltag_Highlight_($xp, $elem)
- {
- $conditions = array();
- $toplevel = array();
- foreach ($this->_blocks as $i => $current) {
- if (!$current['contained'] && !isset($current['onlyin'])) {
- $toplevel[] = $i;
- }
- foreach ((array)@$current['onlyin'] as $region => $lineNo) {
- if (!isset($this->_regions[$region])) {
- $this->_error(TEXT_HIGHLIGHTER_BLOCK_REGION,
- array(
- 'block' => $current['name'],
- 'region' => $region
- ));
- }
- }
- }
- foreach ($this->_regions as $i=>$current) {
- if (!$current['contained'] && !isset($current['onlyin'])) {
- $toplevel[] = $i;
- }
- foreach ((array)@$current['contains']['region'] as $region => $lineNo) {
- if (!isset($this->_regions[$region])) {
- $this->_error(TEXT_HIGHLIGHTER_REGION_REGION,
- array(
- 'region1' => $current['name'],
- 'region2' => $region
- ));
- }
- }
- foreach ((array)@$current['contains']['block'] as $region => $lineNo) {
- if (!isset($this->_blocks[$region])) {
- $this->_error(TEXT_HIGHLIGHTER_REGION_BLOCK,
- array(
- 'block' => $current['name'],
- 'region' => $region
- ));
- }
- }
- foreach ((array)@$current['onlyin'] as $region => $lineNo) {
- if (!isset($this->_regions[$region])) {
- $this->_error(TEXT_HIGHLIGHTER_REGION_REGION,
- array(
- 'region1' => $current['name'],
- 'region2' => $region
- ));
- }
- }
- foreach ($this->_regions as $j => $region) {
- if (isset($region['onlyin'])) {
- $suits = isset($region['onlyin'][$current['name']]);
- } elseif (isset($current['not-contains']['region'][$region['name']])) {
- $suits = false;
- } elseif (isset($current['contains']['region'][$region['name']])) {
- $suits = true;
- } else {
- $suits = @$current['contains-all'] && @!$region['never-contained'];
- }
- if ($suits) {
- $this->_regions[$i]['lookfor'][] = $j;
- }
- }
- foreach ($this->_blocks as $j=>$region) {
- if (isset($region['onlyin'])) {
- $suits = isset($region['onlyin'][$current['name']]);
- } elseif (isset($current['not-contains']['block'][$region['name']])) {
- $suits = false;
- } elseif (isset($current['contains']['block'][$region['name']])) {
- $suits = true;
- } else {
- $suits = @$current['contains-all'] && @!$region['never-contained'];
- }
- if ($suits) {
- $this->_regions[$i]['lookfor'][] = $j;
- }
- }
- }
- foreach ($this->_blocks as $i=>$current) {
- unset ($this->_blocks[$i]['never-contained']);
- unset ($this->_blocks[$i]['contained']);
- unset ($this->_blocks[$i]['contains-all']);
- unset ($this->_blocks[$i]['contains']);
- unset ($this->_blocks[$i]['onlyin']);
- unset ($this->_blocks[$i]['line']);
- }
-
- foreach ($this->_regions as $i=>$current) {
- unset ($this->_regions[$i]['never-contained']);
- unset ($this->_regions[$i]['contained']);
- unset ($this->_regions[$i]['contains-all']);
- unset ($this->_regions[$i]['contains']);
- unset ($this->_regions[$i]['onlyin']);
- unset ($this->_regions[$i]['line']);
- }
-
- foreach ($this->_keywords as $name => $keyword) {
- if (isset($keyword['ifdef'])) {
- $conditions[$keyword['ifdef']][] = array($name, true);
- }
- if (isset($keyword['ifndef'])) {
- $conditions[$keyword['ifndef']][] = array($name, false);
- }
- unset($this->_keywords[$name]['line']);
- if (!isset($this->_blocks[$keyword['inherits']])) {
- $this->_error(TEXT_HIGHLIGHTER_KEYWORD_INHERITS,
- array(
- 'keyword' => $keyword['name'],
- 'block' => $keyword['inherits']
- ));
- }
- if (isset($keyword['otherwise']) && !isset($this->_blocks[$keyword['otherwise']]) ) {
- $this->_error(TEXT_HIGHLIGHTER_KEYWORD_BLOCK,
- array(
- 'keyword' => $keyword['name'],
- 'block' => $keyword['inherits']
- ));
- }
- }
-
- $syntax=array(
- 'keywords' => $this->_keywords,
- 'blocks' => array_merge($this->_blocks, $this->_regions),
- 'toplevel' => $toplevel,
- );
- uasort($syntax['blocks'], array(&$this, '_sortBlocks'));
- foreach ($syntax['blocks'] as $name => $block) {
- if ($block['type'] == 'block') {
- continue;
- }
- if (is_array(@$syntax['blocks'][$name]['lookfor'])) {
- usort($syntax['blocks'][$name]['lookfor'], array(&$this, '_sortLookFor'));
- }
- }
- usort($syntax['toplevel'], array(&$this, '_sortLookFor'));
- $syntax['case'] = $this->_case;
- $this->_code = <<<CODE
-<?php
-/**
- * Auto-generated class. {$this->language} syntax highlighting
-CODE;
-
- if ($this->_comment) {
- $comment = preg_replace('~^~m',' * ',$this->_comment);
- $this->_code .= "\n * \n" . $comment;
- }
-
- $this->_code .= <<<CODE
-
- *
- * PHP version 4 and 5
- *
- * LICENSE: This source file is subject to version 3.0 of the PHP license
- * that is available through the world-wide-web at the following URI:
- * http://www.php.net/license/3_0.txt. If you did not receive a copy of
- * the PHP License and are unable to obtain it through the web, please
- * send a note to license@php.net so we can mail you a copy immediately.
- *
- * @copyright 2004-2006 Andrey Demenev
- * @license http://www.php.net/license/3_0.txt PHP License
- * @link http://pear.php.net/package/Text_Highlighter
- * @category Text
- * @package Text_Highlighter
- * @version generated from: $this->_syntaxFile
-
-CODE;
-
- foreach ($this->_authors as $author) {
- $this->_code .= ' * @author ' . $author['name'];
- if ($author['email']) {
- $this->_code .= ' <' . $author['email'] . '>';
- }
- $this->_code .= "\n";
- }
-
- $this->_code .= <<<CODE
- *
- */
-
-/**
- * Auto-generated class. {$this->language} syntax highlighting
- *
-
-CODE;
- foreach ($this->_authors as $author) {
- $this->_code .= ' * @author ' . $author['name'];
- if ($author['email']) {
- $this->_code .= ' <' . $author['email']. '>';
- }
- $this->_code .= "\n";
- }
-
-
- $this->_code .= <<<CODE
- * @category Text
- * @package Text_Highlighter
- * @copyright 2004-2006 Andrey Demenev
- * @license http://www.php.net/license/3_0.txt PHP License
- * @version Release: 0.7.0
- * @link http://pear.php.net/package/Text_Highlighter
- */
-class Text_Highlighter_{$this->language} extends Text_Highlighter
-{
-
-CODE;
- $this->_code .= 'var $_language = \'' . strtolower($this->language) . "';\n\n";
- $array = var_export($syntax, true);
- $array = trim(preg_replace('~^(\s*)~m',' \1\1',$array));
- // \$this->_syntax = $array;
- $this->_code .= <<<CODE
-
- /**
- * Constructor
- *
- * @param array \$options
- * @access public
- */
- function __construct(\$options=array())
- {
-
-CODE;
- $this->_code .= <<<CODE
-
- \$this->_options = \$options;
-CODE;
- $states = array();
- $i = 0;
- foreach ($syntax['blocks'] as $name => $block) {
- if ($block['type'] == 'region') {
- $states[$name] = $i++;
- }
- }
- $regs = array();
- $counts = array();
- $delim = array();
- $inner = array();
- $end = array();
- $stat = array();
- $keywords = array();
- $parts = array();
- $kwmap = array();
- $subst = array();
- $re = array();
- $ce = array();
- $rd = array();
- $in = array();
- $st = array();
- $kw = array();
- $sb = array();
- foreach ($syntax['toplevel'] as $name) {
- $block = $syntax['blocks'][$name];
- if ($block['type'] == 'block') {
- $kwm = array();
- $re[] = '(' . $block['match'] . ')';
- $ce[] = $this->_countSubpatterns($block['match']);
- $rd[] = '';
- $sb[] = false;;
- $st[] = -1;
- foreach ($syntax['keywords'] as $kwname => $kwgroup) {
- if ($kwgroup['inherits'] != $name) {
- continue;
- }
- $gre = implode('|', array_keys($kwgroup['match']));
- if (!$kwgroup['case']) {
- $gre = '(?i)' . $gre;
- }
- $kwm[$kwname][] = $gre;
- $kwmap[$kwname] = $kwgroup['innerGroup'];
- }
- foreach ($kwm as $g => $ma) {
- $kwm[$g] = '/^(' . implode(')|(', $ma) . ')$/';
- }
- $kw[] = $kwm;
- } else {
- $kw[] = -1;
- $re[] = '(' . $block['start'] . ')';
- $ce[] = $this->_countSubpatterns($block['start']);
- $rd[] = $block['delimGroup'];
- $st[] = $states[$name];
- $sb[] = $block['remember'];
- }
- $in[] = $block['innerGroup'];
- }
- $re = implode('|', $re);
- $regs[-1] = '/' . $re . '/';
- $counts[-1] = $ce;
- $delim[-1] = $rd;
- $inner[-1] = $in;
- $stat[-1] = $st;
- $keywords[-1] = $kw;
- $subst[-1] = $sb;
-
- foreach ($syntax['blocks'] as $ablock) {
- if ($ablock['type'] != 'region') {
- continue;
- }
- $end[] = '/' . $ablock['end'] . '/';
- $re = array();
- $ce = array();
- $rd = array();
- $in = array();
- $st = array();
- $kw = array();
- $pc = array();
- $sb = array();
- foreach ((array)@$ablock['lookfor'] as $name) {
- $block = $syntax['blocks'][$name];
- if (isset($block['partClass'])) {
- $pc[] = $block['partClass'];
- } else {
- $pc[] = null;
- }
- if ($block['type'] == 'block') {
- $kwm = array();;
- $re[] = '(' . $block['match'] . ')';
- $ce[] = $this->_countSubpatterns($block['match']);
- $rd[] = '';
- $sb[] = false;
- $st[] = -1;
- foreach ($syntax['keywords'] as $kwname => $kwgroup) {
- if ($kwgroup['inherits'] != $name) {
- continue;
- }
- $gre = implode('|', array_keys($kwgroup['match']));
- if (!$kwgroup['case']) {
- $gre = '(?i)' . $gre;
- }
- $kwm[$kwname][] = $gre;
- $kwmap[$kwname] = $kwgroup['innerGroup'];
- }
- foreach ($kwm as $g => $ma) {
- $kwm[$g] = '/^(' . implode(')|(', $ma) . ')$/';
- }
- $kw[] = $kwm;
- } else {
- $sb[] = $block['remember'];
- $kw[] = -1;
- $re[] = '(' . $block['start'] . ')';
- $ce[] = $this->_countSubpatterns($block['start']);
- $rd[] = $block['delimGroup'];
- $st[] = $states[$name];
- }
- $in[] = $block['innerGroup'];
- }
- $re = implode('|', $re);
- $regs[] = '/' . $re . '/';
- $counts[] = $ce;
- $delim[] = $rd;
- $inner[] = $in;
- $stat[] = $st;
- $keywords[] = $kw;
- $parts[] = $pc;
- $subst[] = $sb;
- }
-
-
- $this->_code .= "\n \$this->_regs = " . $this->_exportArray($regs);
- $this->_code .= ";\n \$this->_counts = " .$this->_exportArray($counts);
- $this->_code .= ";\n \$this->_delim = " .$this->_exportArray($delim);
- $this->_code .= ";\n \$this->_inner = " .$this->_exportArray($inner);
- $this->_code .= ";\n \$this->_end = " .$this->_exportArray($end);
- $this->_code .= ";\n \$this->_states = " .$this->_exportArray($stat);
- $this->_code .= ";\n \$this->_keywords = " .$this->_exportArray($keywords);
- $this->_code .= ";\n \$this->_parts = " .$this->_exportArray($parts);
- $this->_code .= ";\n \$this->_subst = " .$this->_exportArray($subst);
- $this->_code .= ";\n \$this->_conditions = " .$this->_exportArray($conditions);
- $this->_code .= ";\n \$this->_kwmap = " .$this->_exportArray($kwmap);
- $this->_code .= ";\n \$this->_defClass = '" .$this->_defClass . '\'';
- $this->_code .= <<<CODE
-;
- \$this->_checkDefines();
- }
-
-}
-CODE;
-}
-
-// }}}
-}
-
-
-/*
-* Local variables:
-* tab-width: 4
-* c-basic-offset: 4
-* c-hanging-comment-ender-p: nil
-* End:
-*/
-
-?>
+<?php
+/* vim: set expandtab tabstop=4 shiftwidth=4 softtabstop=4: */
+/**
+* Syntax highlighter class generator
+*
+* To simplify the process of creating new syntax highlighters
+* for different languages, {@link Text_Highlighter_Generator} class is
+* provided. It takes highlighting rules from XML file and generates
+* a code of a class inherited from {@link Text_Highlighter}.
+*
+* PHP versions 4 and 5
+*
+* LICENSE: This source file is subject to version 3.0 of the PHP license
+* that is available through the world-wide-web at the following URI:
+* http://www.php.net/license/3_0.txt. If you did not receive a copy of
+* the PHP License and are unable to obtain it through the web, please
+* send a note to license@php.net so we can mail you a copy immediately.
+*
+* @category Text
+* @package Text_Highlighter
+* @author Andrey Demenev <demenev@gmail.com>
+* @copyright 2004-2006 Andrey Demenev
+* @license http://www.php.net/license/3_0.txt PHP License
+* @version CVS: $Id: Generator.php,v 1.1 2007/06/03 02:36:35 ssttoo Exp $
+* @link http://pear.php.net/package/Text_Highlighter
+*/
+
+// {{{ error codes
+
+define ('TEXT_HIGHLIGHTER_EMPTY_RE', 1);
+define ('TEXT_HIGHLIGHTER_INVALID_RE', 2);
+define ('TEXT_HIGHLIGHTER_EMPTY_OR_MISSING', 3);
+define ('TEXT_HIGHLIGHTER_EMPTY', 4);
+define ('TEXT_HIGHLIGHTER_REGION_REGION', 5);
+define ('TEXT_HIGHLIGHTER_REGION_BLOCK', 6);
+define ('TEXT_HIGHLIGHTER_BLOCK_REGION', 7);
+define ('TEXT_HIGHLIGHTER_KEYWORD_BLOCK', 8);
+define ('TEXT_HIGHLIGHTER_KEYWORD_INHERITS', 9);
+define ('TEXT_HIGHLIGHTER_PARSE', 10);
+define ('TEXT_HIGHLIGHTER_FILE_WRITE', 11);
+define ('TEXT_HIGHLIGHTER_FILE_READ', 12);
+// }}}
+
+/**
+* Syntax highliter class generator class
+*
+* This class is used to generate PHP classes
+* from XML files with highlighting rules
+*
+* Usage example
+* <code>
+*require_once 'Text/Highlighter/Generator.php';
+*$generator =& new Text_Highlighter_Generator('php.xml');
+*$generator->generate();
+*$generator->saveCode('PHP.php');
+* </code>
+*
+* A command line script <b>generate</b> is provided for
+* class generation (installs in scripts/Text/Highlighter).
+*
+* @author Andrey Demenev <demenev@gmail.com>
+* @copyright 2004-2006 Andrey Demenev
+* @license http://www.php.net/license/3_0.txt PHP License
+* @version Release: 0.7.0
+* @link http://pear.php.net/package/Text_Highlighter
+*/
+
+class Text_Highlighter_Generator extends XML_Parser
+{
+ // {{{ properties
+ /**
+ * Whether to do case folding.
+ * We have to declare it here, because XML_Parser
+ * sets case folding in constructor
+ *
+ * @var boolean
+ */
+ var $folding = false;
+
+ /**
+ * Holds name of file with highlighting rules
+ *
+ * @var string
+ * @access private
+ */
+ var $_syntaxFile;
+
+ /**
+ * Current element being processed
+ *
+ * @var array
+ * @access private
+ */
+ var $_element;
+
+ /**
+ * List of regions
+ *
+ * @var array
+ * @access private
+ */
+ var $_regions = array();
+
+ /**
+ * List of blocks
+ *
+ * @var array
+ * @access private
+ */
+ var $_blocks = array();
+
+ /**
+ * List of keyword groups
+ *
+ * @var array
+ * @access private
+ */
+ var $_keywords = array();
+
+ /**
+ * List of authors
+ *
+ * @var array
+ * @access private
+ */
+ var $_authors = array();
+
+ /**
+ * Name of language
+ *
+ * @var string
+ * @access public
+ */
+ var $language = '';
+
+ /**
+ * Generated code
+ *
+ * @var string
+ * @access private
+ */
+ var $_code = '';
+
+ /**
+ * Default class
+ *
+ * @var string
+ * @access private
+ */
+ var $_defClass = 'default';
+
+ /**
+ * Comment
+ *
+ * @var string
+ * @access private
+ */
+ var $_comment = '';
+
+ /**
+ * Flag for comment processing
+ *
+ * @var boolean
+ * @access private
+ */
+ var $_inComment = false;
+
+ /**
+ * Sorting order of current block/region
+ *
+ * @var integer
+ * @access private
+ */
+ var $_blockOrder = 0;
+
+ /**
+ * Generation errors
+ *
+ * @var array
+ * @access private
+ */
+ var $_errors;
+
+ // }}}
+ // {{{ constructor
+
+ /**
+ * Constructor
+ *
+ * @param string $syntaxFile Name of XML file
+ * with syntax highlighting rules
+ *
+ * @access public
+ */
+
+ function __construct($syntaxFile = '')
+ {
+ XML_Parser::XML_Parser(null, 'func');
+ $this->_errors = array();
+ $this->_declareErrorMessages();
+ if ($syntaxFile) {
+ $this->setInputFile($syntaxFile);
+ }
+ }
+
+ // }}}
+ // {{{ _formatError
+
+ /**
+ * Format error message
+ *
+ * @param int $code error code
+ * @param string $params parameters
+ * @param string $fileName file name
+ * @param int $lineNo line number
+ * @return array
+ * @access public
+ */
+ function _formatError($code, $params, $fileName, $lineNo)
+ {
+ $template = $this->_templates[$code];
+ $ret = call_user_func_array('sprintf', array_merge(array($template), $params));
+ if ($fileName) {
+ $ret = '[' . $fileName . '] ' . $ret;
+ }
+ if ($lineNo) {
+ $ret .= ' (line ' . $lineNo . ')';
+ }
+ return $ret;
+ }
+
+ // }}}
+ // {{{ declareErrorMessages
+
+ /**
+ * Set up error message templates
+ *
+ * @access private
+ */
+ function _declareErrorMessages()
+ {
+ $this->_templates = array (
+ TEXT_HIGHLIGHTER_EMPTY_RE => 'Empty regular expression',
+ TEXT_HIGHLIGHTER_INVALID_RE => 'Invalid regular expression : %s',
+ TEXT_HIGHLIGHTER_EMPTY_OR_MISSING => 'Empty or missing %s',
+ TEXT_HIGHLIGHTER_EMPTY => 'Empty %s',
+ TEXT_HIGHLIGHTER_REGION_REGION => 'Region %s refers undefined region %s',
+ TEXT_HIGHLIGHTER_REGION_BLOCK => 'Region %s refers undefined block %s',
+ TEXT_HIGHLIGHTER_BLOCK_REGION => 'Block %s refers undefined region %s',
+ TEXT_HIGHLIGHTER_KEYWORD_BLOCK => 'Keyword group %s refers undefined block %s',
+ TEXT_HIGHLIGHTER_KEYWORD_INHERITS => 'Keyword group %s inherits undefined block %s',
+ TEXT_HIGHLIGHTER_PARSE => '%s',
+ TEXT_HIGHLIGHTER_FILE_WRITE => 'Error writing file %s',
+ TEXT_HIGHLIGHTER_FILE_READ => '%s'
+ );
+ }
+
+ // }}}
+ // {{{ setInputFile
+
+ /**
+ * Sets the input xml file to be parsed
+ *
+ * @param string Filename (full path)
+ * @return boolean
+ * @access public
+ */
+ function setInputFile($file)
+ {
+ $this->_syntaxFile = $file;
+ $ret = parent::setInputFile($file);
+ if (PEAR::isError($ret)) {
+ $this->_error(TEXT_HIGHLIGHTER_FILE_READ, $ret->message);
+ return false;
+ }
+ return true;
+ }
+
+ // }}}
+ // {{{ generate
+
+ /**
+ * Generates class code
+ *
+ * @access public
+ */
+
+ function generate()
+ {
+ $this->_regions = array();
+ $this->_blocks = array();
+ $this->_keywords = array();
+ $this->language = '';
+ $this->_code = '';
+ $this->_defClass = 'default';
+ $this->_comment = '';
+ $this->_inComment = false;
+ $this->_authors = array();
+ $this->_blockOrder = 0;
+ $this->_errors = array();
+
+ $ret = $this->parse();
+ if (PEAR::isError($ret)) {
+ $this->_error(TEXT_HIGHLIGHTER_PARSE, $ret->message);
+ return false;
+ }
+ return true;
+ }
+
+ // }}}
+ // {{{ getCode
+
+ /**
+ * Returns generated code as a string.
+ *
+ * @return string Generated code
+ * @access public
+ */
+
+ function getCode()
+ {
+ return $this->_code;
+ }
+
+ // }}}
+ // {{{ saveCode
+
+ /**
+ * Saves generated class to file. Note that {@link Text_Highlighter::factory()}
+ * assumes that filename is uppercase (SQL.php, DTD.php, etc), and file
+ * is located in Text/Highlighter
+ *
+ * @param string $filename Name of file to write the code to
+ * @return boolean true on success, false on failure
+ * @access public
+ */
+
+ function saveCode($filename)
+ {
+ $f = @fopen($filename, 'wb');
+ if (!$f) {
+ $this->_error(TEXT_HIGHLIGHTER_FILE_WRITE, array('outfile'=>$filename));
+ return false;
+ }
+ fwrite ($f, $this->_code);
+ fclose($f);
+ return true;
+ }
+
+ // }}}
+ // {{{ hasErrors
+
+ /**
+ * Reports if there were errors
+ *
+ * @return boolean
+ * @access public
+ */
+
+ function hasErrors()
+ {
+ return count($this->_errors) > 0;
+ }
+
+ // }}}
+ // {{{ getErrors
+
+ /**
+ * Returns errors
+ *
+ * @return array
+ * @access public
+ */
+
+ function getErrors()
+ {
+ return $this->_errors;
+ }
+
+ // }}}
+ // {{{ _sortBlocks
+
+ /**
+ * Sorts blocks
+ *
+ * @access private
+ */
+
+ function _sortBlocks($b1, $b2) {
+ return $b1['order'] - $b2['order'];
+ }
+
+ // }}}
+ // {{{ _sortLookFor
+ /**
+ * Sort 'look for' list
+ * @return int
+ * @param string $b1
+ * @param string $b2
+ */
+ function _sortLookFor($b1, $b2) {
+ $o1 = isset($this->_blocks[$b1]) ? $this->_blocks[$b1]['order'] : $this->_regions[$b1]['order'];
+ $o2 = isset($this->_blocks[$b2]) ? $this->_blocks[$b2]['order'] : $this->_regions[$b2]['order'];
+ return $o1 - $o2;
+ }
+
+ // }}}
+ // {{{ _makeRE
+
+ /**
+ * Adds delimiters and modifiers to regular expression if necessary
+ *
+ * @param string $text Original RE
+ * @return string Final RE
+ * @access private
+ */
+ function _makeRE($text, $case = false)
+ {
+ if (!strlen($text)) {
+ $this->_error(TEXT_HIGHLIGHTER_EMPTY_RE);
+ }
+ if (!strlen($text) || $text{0} != '/') {
+ $text = '/' . $text . '/';
+ }
+ if (!$case) {
+ $text .= 'i';
+ }
+ $php_errormsg = '';
+ @preg_match($text, '');
+ if ($php_errormsg) {
+ $this->_error(TEXT_HIGHLIGHTER_INVALID_RE, $php_errormsg);
+ }
+ preg_match ('#^/(.+)/(.*)$#', $text, $m);
+ if (@$m[2]) {
+ $text = '(?' . $m[2] . ')' . $m[1];
+ } else {
+ $text = $m[1];
+ }
+ return $text;
+ }
+
+ // }}}
+ // {{{ _exportArray
+
+ /**
+ * Exports array as PHP code
+ *
+ * @param array $array
+ * @return string Code
+ * @access private
+ */
+ function _exportArray($array)
+ {
+ $array = var_export($array, true);
+ return trim(preg_replace('~^(\s*)~m',' \1\1',$array));
+ }
+
+ // }}}
+ // {{{ _countSubpatterns
+ /**
+ * Find number of capturing suppaterns in regular expression
+ * @return int
+ * @param string $re Regular expression (without delimiters)
+ */
+ function _countSubpatterns($re)
+ {
+ preg_match_all('/' . $re . '/', '', $m);
+ return count($m)-1;
+ }
+
+ // }}}
+
+ /**#@+
+ * @access private
+ * @param resource $xp XML parser resource
+ * @param string $elem XML element name
+ * @param array $attribs XML element attributes
+ */
+
+ // {{{ xmltag_Default
+
+ /**
+ * start handler for <default> element
+ */
+ function xmltag_Default($xp, $elem, $attribs)
+ {
+ $this->_aliasAttributes($attribs);
+ if (!isset($attribs['innerGroup']) || $attribs['innerGroup'] === '') {
+ $this->_error(TEXT_HIGHLIGHTER_EMPTY_OR_MISSING, 'innerGroup');
+ }
+ $this->_defClass = @$attribs['innerGroup'];
+ }
+
+ // }}}
+ // {{{ xmltag_Region
+
+ /**
+ * start handler for <region> element
+ */
+ function xmltag_Region($xp, $elem, $attribs)
+ {
+ $this->_aliasAttributes($attribs);
+ if (!isset($attribs['name']) || $attribs['name'] === '') {
+ $this->_error(TEXT_HIGHLIGHTER_EMPTY_OR_MISSING, 'region name');
+ }
+ if (!isset($attribs['innerGroup']) || $attribs['innerGroup'] === '') {
+ $this->_error(TEXT_HIGHLIGHTER_EMPTY_OR_MISSING, 'innerGroup');
+ }
+ $this->_element = array('name' => $attribs['name']);
+ $this->_element['line'] = xml_get_current_line_number($this->parser);
+ if (isset($attribs['case'])) {
+ $this->_element['case'] = $attribs['case'] == 'yes';
+ } else {
+ $this->_element['case'] = $this->_case;
+ }
+ $this->_element['innerGroup'] = $attribs['innerGroup'];
+ $this->_element['delimGroup'] = isset($attribs['delimGroup']) ?
+ $attribs['delimGroup'] :
+ $attribs['innerGroup'];
+ $this->_element['start'] = $this->_makeRE(@$attribs['start'], $this->_element['case']);
+ $this->_element['end'] = $this->_makeRE(@$attribs['end'], $this->_element['case']);
+ $this->_element['contained'] = @$attribs['contained'] == 'yes';
+ $this->_element['never-contained'] = @$attribs['never-contained'] == 'yes';
+ $this->_element['remember'] = @$attribs['remember'] == 'yes';
+ if (isset($attribs['startBOL']) && $attribs['startBOL'] == 'yes') {
+ $this->_element['startBOL'] = true;
+ }
+ if (isset($attribs['endBOL']) && $attribs['endBOL'] == 'yes') {
+ $this->_element['endBOL'] = true;
+ }
+ if (isset($attribs['neverAfter'])) {
+ $this->_element['neverafter'] = $this->_makeRE($attribs['neverAfter']);
+ }
+ }
+
+ // }}}
+ // {{{ xmltag_Block
+
+ /**
+ * start handler for <block> element
+ */
+ function xmltag_Block($xp, $elem, $attribs)
+ {
+ $this->_aliasAttributes($attribs);
+ if (!isset($attribs['name']) || $attribs['name'] === '') {
+ $this->_error(TEXT_HIGHLIGHTER_EMPTY_OR_MISSING, 'block name');
+ }
+ if (isset($attribs['innerGroup']) && $attribs['innerGroup'] === '') {
+ $this->_error(TEXT_HIGHLIGHTER_EMPTY, 'innerGroup');
+ }
+ $this->_element = array('name' => $attribs['name']);
+ $this->_element['line'] = xml_get_current_line_number($this->parser);
+ if (isset($attribs['case'])) {
+ $this->_element['case'] = $attribs['case'] == 'yes';
+ } else {
+ $this->_element['case'] = $this->_case;
+ }
+ if (isset($attribs['innerGroup'])) {
+ $this->_element['innerGroup'] = @$attribs['innerGroup'];
+ }
+ $this->_element['match'] = $this->_makeRE($attribs['match'], $this->_element['case']);
+ $this->_element['contained'] = @$attribs['contained'] == 'yes';
+ $this->_element['multiline'] = @$attribs['multiline'] == 'yes';
+ if (isset($attribs['BOL']) && $attribs['BOL'] == 'yes') {
+ $this->_element['BOL'] = true;
+ }
+ if (isset($attribs['neverAfter'])) {
+ $this->_element['neverafter'] = $this->_makeRE($attribs['neverAfter']);
+ }
+ }
+
+ // }}}
+ // {{{ cdataHandler
+
+ /**
+ * Character data handler. Used for comment
+ */
+ function cdataHandler($xp, $cdata)
+ {
+ if ($this->_inComment) {
+ $this->_comment .= $cdata;
+ }
+ }
+
+ // }}}
+ // {{{ xmltag_Comment
+
+ /**
+ * start handler for <comment> element
+ */
+ function xmltag_Comment($xp, $elem, $attribs)
+ {
+ $this->_comment = '';
+ $this->_inComment = true;
+ }
+
+ // }}}
+ // {{{ xmltag_PartGroup
+
+ /**
+ * start handler for <partgroup> element
+ */
+ function xmltag_PartGroup($xp, $elem, $attribs)
+ {
+ $this->_aliasAttributes($attribs);
+ if (!isset($attribs['innerGroup']) || $attribs['innerGroup'] === '') {
+ $this->_error(TEXT_HIGHLIGHTER_EMPTY_OR_MISSING, 'innerGroup');
+ }
+ $this->_element['partClass'][$attribs['index']] = @$attribs['innerGroup'];
+ }
+
+ // }}}
+ // {{{ xmltag_PartClass
+
+ /**
+ * start handler for <partclass> element
+ */
+ function xmltag_PartClass($xp, $elem, $attribs)
+ {
+ $this->xmltag_PartGroup($xp, $elem, $attribs);
+ }
+
+ // }}}
+ // {{{ xmltag_Keywords
+
+ /**
+ * start handler for <keywords> element
+ */
+ function xmltag_Keywords($xp, $elem, $attribs)
+ {
+ $this->_aliasAttributes($attribs);
+ if (!isset($attribs['name']) || $attribs['name'] === '') {
+ $this->_error(TEXT_HIGHLIGHTER_EMPTY_OR_MISSING, 'keyword group name');
+ }
+ if (!isset($attribs['innerGroup']) || $attribs['innerGroup'] === '') {
+ $this->_error(TEXT_HIGHLIGHTER_EMPTY_OR_MISSING, 'innerGroup');
+ }
+ if (!isset($attribs['inherits']) || $attribs['inherits'] === '') {
+ $this->_error(TEXT_HIGHLIGHTER_EMPTY_OR_MISSING, 'inherits');
+ }
+ $this->_element = array('name'=>@$attribs['name']);
+ $this->_element['line'] = xml_get_current_line_number($this->parser);
+ $this->_element['innerGroup'] = @$attribs['innerGroup'];
+ if (isset($attribs['case'])) {
+ $this->_element['case'] = $attribs['case'] == 'yes';
+ } else {
+ $this->_element['case'] = $this->_case;
+ }
+ $this->_element['inherits'] = @$attribs['inherits'];
+ if (isset($attribs['otherwise'])) {
+ $this->_element['otherwise'] = $attribs['otherwise'];
+ }
+ if (isset($attribs['ifdef'])) {
+ $this->_element['ifdef'] = $attribs['ifdef'];
+ }
+ if (isset($attribs['ifndef'])) {
+ $this->_element['ifndef'] = $attribs['ifndef'];
+ }
+ }
+
+ // }}}
+ // {{{ xmltag_Keyword
+
+ /**
+ * start handler for <keyword> element
+ */
+ function xmltag_Keyword($xp, $elem, $attribs)
+ {
+ if (!isset($attribs['match']) || $attribs['match'] === '') {
+ $this->_error(TEXT_HIGHLIGHTER_EMPTY_OR_MISSING, 'match');
+ }
+ $keyword = @$attribs['match'];
+ if (!$this->_element['case']) {
+ $keyword = strtolower($keyword);
+ }
+ $this->_element['match'][$keyword] = true;
+ }
+
+ // }}}
+ // {{{ xmltag_Contains
+
+ /**
+ * start handler for <contains> element
+ */
+ function xmltag_Contains($xp, $elem, $attribs)
+ {
+ $this->_element['contains-all'] = @$attribs['all'] == 'yes';
+ if (isset($attribs['region'])) {
+ $this->_element['contains']['region'][$attribs['region']] =
+ xml_get_current_line_number($this->parser);
+ }
+ if (isset($attribs['block'])) {
+ $this->_element['contains']['block'][$attribs['block']] =
+ xml_get_current_line_number($this->parser);
+ }
+ }
+
+ // }}}
+ // {{{ xmltag_But
+
+ /**
+ * start handler for <but> element
+ */
+ function xmltag_But($xp, $elem, $attribs)
+ {
+ if (isset($attribs['region'])) {
+ $this->_element['not-contains']['region'][$attribs['region']] = true;
+ }
+ if (isset($attribs['block'])) {
+ $this->_element['not-contains']['block'][$attribs['block']] = true;
+ }
+ }
+
+ // }}}
+ // {{{ xmltag_Onlyin
+
+ /**
+ * start handler for <onlyin> element
+ */
+ function xmltag_Onlyin($xp, $elem, $attribs)
+ {
+ if (!isset($attribs['region']) || $attribs['region'] === '') {
+ $this->_error(TEXT_HIGHLIGHTER_EMPTY_OR_MISSING, 'region');
+ }
+ $this->_element['onlyin'][$attribs['region']] = xml_get_current_line_number($this->parser);
+ }
+
+ // }}}
+ // {{{ xmltag_Author
+
+ /**
+ * start handler for <author> element
+ */
+ function xmltag_Author($xp, $elem, $attribs)
+ {
+ if (!isset($attribs['name']) || $attribs['name'] === '') {
+ $this->_error(TEXT_HIGHLIGHTER_EMPTY_OR_MISSING, 'author name');
+ }
+ $this->_authors[] = array(
+ 'name' => @$attribs['name'],
+ 'email' => (string)@$attribs['email']
+ );
+ }
+
+ // }}}
+ // {{{ xmltag_Highlight
+
+ /**
+ * start handler for <highlight> element
+ */
+ function xmltag_Highlight($xp, $elem, $attribs)
+ {
+ if (!isset($attribs['lang']) || $attribs['lang'] === '') {
+ $this->_error(TEXT_HIGHLIGHTER_EMPTY_OR_MISSING, 'language name');
+ }
+ $this->_code = '';
+ $this->language = strtoupper(@$attribs['lang']);
+ $this->_case = @$attribs['case'] == 'yes';
+ }
+
+ // }}}
+
+ /**#@-*/
+
+ // {{{ _error
+
+ /**
+ * Add an error message
+ *
+ * @param integer $code Error code
+ * @param mixed $message Error message or array with error message parameters
+ * @param integer $lineNo Source code line number
+ * @access private
+ */
+ function _error($code, $params = array(), $lineNo = 0)
+ {
+ if (!$lineNo && !empty($this->parser)) {
+ $lineNo = xml_get_current_line_number($this->parser);
+ }
+ $this->_errors[] = $this->_formatError($code, $params, $this->_syntaxFile, $lineNo);
+ }
+
+ // }}}
+ // {{{ _aliasAttributes
+
+ /**
+ * BC trick
+ *
+ * @param array $attrs attributes
+ */
+ function _aliasAttributes(&$attrs)
+ {
+ if (isset($attrs['innerClass']) && !isset($attrs['innerGroup'])) {
+ $attrs['innerGroup'] = $attrs['innerClass'];
+ }
+ if (isset($attrs['delimClass']) && !isset($attrs['delimGroup'])) {
+ $attrs['delimGroup'] = $attrs['delimClass'];
+ }
+ if (isset($attrs['partClass']) && !isset($attrs['partGroup'])) {
+ $attrs['partGroup'] = $attrs['partClass'];
+ }
+ }
+
+ // }}}
+
+ /**#@+
+ * @access private
+ * @param resource $xp XML parser resource
+ * @param string $elem XML element name
+ */
+
+ // {{{ xmltag_Comment_
+
+ /**
+ * end handler for <comment> element
+ */
+ function xmltag_Comment_($xp, $elem)
+ {
+ $this->_inComment = false;
+ }
+
+ // }}}
+ // {{{ xmltag_Region_
+
+ /**
+ * end handler for <region> element
+ */
+ function xmltag_Region_($xp, $elem)
+ {
+ $this->_element['type'] = 'region';
+ $this->_element['order'] = $this->_blockOrder ++;
+ $this->_regions[$this->_element['name']] = $this->_element;
+ }
+
+ // }}}
+ // {{{ xmltag_Keywords_
+
+ /**
+ * end handler for <keywords> element
+ */
+ function xmltag_Keywords_($xp, $elem)
+ {
+ $this->_keywords[$this->_element['name']] = $this->_element;
+ }
+
+ // }}}
+ // {{{ xmltag_Block_
+
+ /**
+ * end handler for <block> element
+ */
+ function xmltag_Block_($xp, $elem)
+ {
+ $this->_element['type'] = 'block';
+ $this->_element['order'] = $this->_blockOrder ++;
+ $this->_blocks[$this->_element['name']] = $this->_element;
+ }
+
+ // }}}
+ // {{{ xmltag_Highlight_
+
+ /**
+ * end handler for <highlight> element
+ */
+ function xmltag_Highlight_($xp, $elem)
+ {
+ $conditions = array();
+ $toplevel = array();
+ foreach ($this->_blocks as $i => $current) {
+ if (!$current['contained'] && !isset($current['onlyin'])) {
+ $toplevel[] = $i;
+ }
+ foreach ((array)@$current['onlyin'] as $region => $lineNo) {
+ if (!isset($this->_regions[$region])) {
+ $this->_error(TEXT_HIGHLIGHTER_BLOCK_REGION,
+ array(
+ 'block' => $current['name'],
+ 'region' => $region
+ ));
+ }
+ }
+ }
+ foreach ($this->_regions as $i=>$current) {
+ if (!$current['contained'] && !isset($current['onlyin'])) {
+ $toplevel[] = $i;
+ }
+ foreach ((array)@$current['contains']['region'] as $region => $lineNo) {
+ if (!isset($this->_regions[$region])) {
+ $this->_error(TEXT_HIGHLIGHTER_REGION_REGION,
+ array(
+ 'region1' => $current['name'],
+ 'region2' => $region
+ ));
+ }
+ }
+ foreach ((array)@$current['contains']['block'] as $region => $lineNo) {
+ if (!isset($this->_blocks[$region])) {
+ $this->_error(TEXT_HIGHLIGHTER_REGION_BLOCK,
+ array(
+ 'block' => $current['name'],
+ 'region' => $region
+ ));
+ }
+ }
+ foreach ((array)@$current['onlyin'] as $region => $lineNo) {
+ if (!isset($this->_regions[$region])) {
+ $this->_error(TEXT_HIGHLIGHTER_REGION_REGION,
+ array(
+ 'region1' => $current['name'],
+ 'region2' => $region
+ ));
+ }
+ }
+ foreach ($this->_regions as $j => $region) {
+ if (isset($region['onlyin'])) {
+ $suits = isset($region['onlyin'][$current['name']]);
+ } elseif (isset($current['not-contains']['region'][$region['name']])) {
+ $suits = false;
+ } elseif (isset($current['contains']['region'][$region['name']])) {
+ $suits = true;
+ } else {
+ $suits = @$current['contains-all'] && @!$region['never-contained'];
+ }
+ if ($suits) {
+ $this->_regions[$i]['lookfor'][] = $j;
+ }
+ }
+ foreach ($this->_blocks as $j=>$region) {
+ if (isset($region['onlyin'])) {
+ $suits = isset($region['onlyin'][$current['name']]);
+ } elseif (isset($current['not-contains']['block'][$region['name']])) {
+ $suits = false;
+ } elseif (isset($current['contains']['block'][$region['name']])) {
+ $suits = true;
+ } else {
+ $suits = @$current['contains-all'] && @!$region['never-contained'];
+ }
+ if ($suits) {
+ $this->_regions[$i]['lookfor'][] = $j;
+ }
+ }
+ }
+ foreach ($this->_blocks as $i=>$current) {
+ unset ($this->_blocks[$i]['never-contained']);
+ unset ($this->_blocks[$i]['contained']);
+ unset ($this->_blocks[$i]['contains-all']);
+ unset ($this->_blocks[$i]['contains']);
+ unset ($this->_blocks[$i]['onlyin']);
+ unset ($this->_blocks[$i]['line']);
+ }
+
+ foreach ($this->_regions as $i=>$current) {
+ unset ($this->_regions[$i]['never-contained']);
+ unset ($this->_regions[$i]['contained']);
+ unset ($this->_regions[$i]['contains-all']);
+ unset ($this->_regions[$i]['contains']);
+ unset ($this->_regions[$i]['onlyin']);
+ unset ($this->_regions[$i]['line']);
+ }
+
+ foreach ($this->_keywords as $name => $keyword) {
+ if (isset($keyword['ifdef'])) {
+ $conditions[$keyword['ifdef']][] = array($name, true);
+ }
+ if (isset($keyword['ifndef'])) {
+ $conditions[$keyword['ifndef']][] = array($name, false);
+ }
+ unset($this->_keywords[$name]['line']);
+ if (!isset($this->_blocks[$keyword['inherits']])) {
+ $this->_error(TEXT_HIGHLIGHTER_KEYWORD_INHERITS,
+ array(
+ 'keyword' => $keyword['name'],
+ 'block' => $keyword['inherits']
+ ));
+ }
+ if (isset($keyword['otherwise']) && !isset($this->_blocks[$keyword['otherwise']]) ) {
+ $this->_error(TEXT_HIGHLIGHTER_KEYWORD_BLOCK,
+ array(
+ 'keyword' => $keyword['name'],
+ 'block' => $keyword['inherits']
+ ));
+ }
+ }
+
+ $syntax=array(
+ 'keywords' => $this->_keywords,
+ 'blocks' => array_merge($this->_blocks, $this->_regions),
+ 'toplevel' => $toplevel,
+ );
+ uasort($syntax['blocks'], array(&$this, '_sortBlocks'));
+ foreach ($syntax['blocks'] as $name => $block) {
+ if ($block['type'] == 'block') {
+ continue;
+ }
+ if (is_array(@$syntax['blocks'][$name]['lookfor'])) {
+ usort($syntax['blocks'][$name]['lookfor'], array(&$this, '_sortLookFor'));
+ }
+ }
+ usort($syntax['toplevel'], array(&$this, '_sortLookFor'));
+ $syntax['case'] = $this->_case;
+ $this->_code = <<<CODE
+<?php
+/**
+ * Auto-generated class. {$this->language} syntax highlighting
+CODE;
+
+ if ($this->_comment) {
+ $comment = preg_replace('~^~m',' * ',$this->_comment);
+ $this->_code .= "\n * \n" . $comment;
+ }
+
+ $this->_code .= <<<CODE
+
+ *
+ * PHP version 4 and 5
+ *
+ * LICENSE: This source file is subject to version 3.0 of the PHP license
+ * that is available through the world-wide-web at the following URI:
+ * http://www.php.net/license/3_0.txt. If you did not receive a copy of
+ * the PHP License and are unable to obtain it through the web, please
+ * send a note to license@php.net so we can mail you a copy immediately.
+ *
+ * @copyright 2004-2006 Andrey Demenev
+ * @license http://www.php.net/license/3_0.txt PHP License
+ * @link http://pear.php.net/package/Text_Highlighter
+ * @category Text
+ * @package Text_Highlighter
+ * @version generated from: $this->_syntaxFile
+
+CODE;
+
+ foreach ($this->_authors as $author) {
+ $this->_code .= ' * @author ' . $author['name'];
+ if ($author['email']) {
+ $this->_code .= ' <' . $author['email'] . '>';
+ }
+ $this->_code .= "\n";
+ }
+
+ $this->_code .= <<<CODE
+ *
+ */
+
+/**
+ * Auto-generated class. {$this->language} syntax highlighting
+ *
+
+CODE;
+ foreach ($this->_authors as $author) {
+ $this->_code .= ' * @author ' . $author['name'];
+ if ($author['email']) {
+ $this->_code .= ' <' . $author['email']. '>';
+ }
+ $this->_code .= "\n";
+ }
+
+
+ $this->_code .= <<<CODE
+ * @category Text
+ * @package Text_Highlighter
+ * @copyright 2004-2006 Andrey Demenev
+ * @license http://www.php.net/license/3_0.txt PHP License
+ * @version Release: 0.7.0
+ * @link http://pear.php.net/package/Text_Highlighter
+ */
+class Text_Highlighter_{$this->language} extends Text_Highlighter
+{
+
+CODE;
+ $this->_code .= 'var $_language = \'' . strtolower($this->language) . "';\n\n";
+ $array = var_export($syntax, true);
+ $array = trim(preg_replace('~^(\s*)~m',' \1\1',$array));
+ // \$this->_syntax = $array;
+ $this->_code .= <<<CODE
+
+ /**
+ * Constructor
+ *
+ * @param array \$options
+ * @access public
+ */
+ function __construct(\$options=array())
+ {
+
+CODE;
+ $this->_code .= <<<CODE
+
+ \$this->_options = \$options;
+CODE;
+ $states = array();
+ $i = 0;
+ foreach ($syntax['blocks'] as $name => $block) {
+ if ($block['type'] == 'region') {
+ $states[$name] = $i++;
+ }
+ }
+ $regs = array();
+ $counts = array();
+ $delim = array();
+ $inner = array();
+ $end = array();
+ $stat = array();
+ $keywords = array();
+ $parts = array();
+ $kwmap = array();
+ $subst = array();
+ $re = array();
+ $ce = array();
+ $rd = array();
+ $in = array();
+ $st = array();
+ $kw = array();
+ $sb = array();
+ foreach ($syntax['toplevel'] as $name) {
+ $block = $syntax['blocks'][$name];
+ if ($block['type'] == 'block') {
+ $kwm = array();
+ $re[] = '(' . $block['match'] . ')';
+ $ce[] = $this->_countSubpatterns($block['match']);
+ $rd[] = '';
+ $sb[] = false;;
+ $st[] = -1;
+ foreach ($syntax['keywords'] as $kwname => $kwgroup) {
+ if ($kwgroup['inherits'] != $name) {
+ continue;
+ }
+ $gre = implode('|', array_keys($kwgroup['match']));
+ if (!$kwgroup['case']) {
+ $gre = '(?i)' . $gre;
+ }
+ $kwm[$kwname][] = $gre;
+ $kwmap[$kwname] = $kwgroup['innerGroup'];
+ }
+ foreach ($kwm as $g => $ma) {
+ $kwm[$g] = '/^(' . implode(')|(', $ma) . ')$/';
+ }
+ $kw[] = $kwm;
+ } else {
+ $kw[] = -1;
+ $re[] = '(' . $block['start'] . ')';
+ $ce[] = $this->_countSubpatterns($block['start']);
+ $rd[] = $block['delimGroup'];
+ $st[] = $states[$name];
+ $sb[] = $block['remember'];
+ }
+ $in[] = $block['innerGroup'];
+ }
+ $re = implode('|', $re);
+ $regs[-1] = '/' . $re . '/';
+ $counts[-1] = $ce;
+ $delim[-1] = $rd;
+ $inner[-1] = $in;
+ $stat[-1] = $st;
+ $keywords[-1] = $kw;
+ $subst[-1] = $sb;
+
+ foreach ($syntax['blocks'] as $ablock) {
+ if ($ablock['type'] != 'region') {
+ continue;
+ }
+ $end[] = '/' . $ablock['end'] . '/';
+ $re = array();
+ $ce = array();
+ $rd = array();
+ $in = array();
+ $st = array();
+ $kw = array();
+ $pc = array();
+ $sb = array();
+ foreach ((array)@$ablock['lookfor'] as $name) {
+ $block = $syntax['blocks'][$name];
+ if (isset($block['partClass'])) {
+ $pc[] = $block['partClass'];
+ } else {
+ $pc[] = null;
+ }
+ if ($block['type'] == 'block') {
+ $kwm = array();;
+ $re[] = '(' . $block['match'] . ')';
+ $ce[] = $this->_countSubpatterns($block['match']);
+ $rd[] = '';
+ $sb[] = false;
+ $st[] = -1;
+ foreach ($syntax['keywords'] as $kwname => $kwgroup) {
+ if ($kwgroup['inherits'] != $name) {
+ continue;
+ }
+ $gre = implode('|', array_keys($kwgroup['match']));
+ if (!$kwgroup['case']) {
+ $gre = '(?i)' . $gre;
+ }
+ $kwm[$kwname][] = $gre;
+ $kwmap[$kwname] = $kwgroup['innerGroup'];
+ }
+ foreach ($kwm as $g => $ma) {
+ $kwm[$g] = '/^(' . implode(')|(', $ma) . ')$/';
+ }
+ $kw[] = $kwm;
+ } else {
+ $sb[] = $block['remember'];
+ $kw[] = -1;
+ $re[] = '(' . $block['start'] . ')';
+ $ce[] = $this->_countSubpatterns($block['start']);
+ $rd[] = $block['delimGroup'];
+ $st[] = $states[$name];
+ }
+ $in[] = $block['innerGroup'];
+ }
+ $re = implode('|', $re);
+ $regs[] = '/' . $re . '/';
+ $counts[] = $ce;
+ $delim[] = $rd;
+ $inner[] = $in;
+ $stat[] = $st;
+ $keywords[] = $kw;
+ $parts[] = $pc;
+ $subst[] = $sb;
+ }
+
+
+ $this->_code .= "\n \$this->_regs = " . $this->_exportArray($regs);
+ $this->_code .= ";\n \$this->_counts = " .$this->_exportArray($counts);
+ $this->_code .= ";\n \$this->_delim = " .$this->_exportArray($delim);
+ $this->_code .= ";\n \$this->_inner = " .$this->_exportArray($inner);
+ $this->_code .= ";\n \$this->_end = " .$this->_exportArray($end);
+ $this->_code .= ";\n \$this->_states = " .$this->_exportArray($stat);
+ $this->_code .= ";\n \$this->_keywords = " .$this->_exportArray($keywords);
+ $this->_code .= ";\n \$this->_parts = " .$this->_exportArray($parts);
+ $this->_code .= ";\n \$this->_subst = " .$this->_exportArray($subst);
+ $this->_code .= ";\n \$this->_conditions = " .$this->_exportArray($conditions);
+ $this->_code .= ";\n \$this->_kwmap = " .$this->_exportArray($kwmap);
+ $this->_code .= ";\n \$this->_defClass = '" .$this->_defClass . '\'';
+ $this->_code .= <<<CODE
+;
+ \$this->_checkDefines();
+ }
+
+}
+CODE;
+}
+
+// }}}
+}
+
+
+/*
+* Local variables:
+* tab-width: 4
+* c-basic-offset: 4
+* c-hanging-comment-ender-p: nil
+* End:
+*/
+
+?>
diff --git a/framework/3rdParty/TextHighlighter/Text/Highlighter/HTML.php b/framework/3rdParty/TextHighlighter/Text/Highlighter/HTML.php
index 163288a7..eaf001e2 100644
--- a/framework/3rdParty/TextHighlighter/Text/Highlighter/HTML.php
+++ b/framework/3rdParty/TextHighlighter/Text/Highlighter/HTML.php
@@ -1,53 +1,53 @@
-<?php
-/**
- * Auto-generated class. HTML syntax highlighting
- *
- * PHP version 4 and 5
- *
- * LICENSE: This source file is subject to version 3.0 of the PHP license
- * that is available through the world-wide-web at the following URI:
- * http://www.php.net/license/3_0.txt. If you did not receive a copy of
- * the PHP License and are unable to obtain it through the web, please
- * send a note to license@php.net so we can mail you a copy immediately.
- *
- * @copyright 2004-2006 Andrey Demenev
- * @license http://www.php.net/license/3_0.txt PHP License
- * @link http://pear.php.net/package/Text_Highlighter
- * @category Text
- * @package Text_Highlighter
+<?php
+/**
+ * Auto-generated class. HTML syntax highlighting
+ *
+ * PHP version 4 and 5
+ *
+ * LICENSE: This source file is subject to version 3.0 of the PHP license
+ * that is available through the world-wide-web at the following URI:
+ * http://www.php.net/license/3_0.txt. If you did not receive a copy of
+ * the PHP License and are unable to obtain it through the web, please
+ * send a note to license@php.net so we can mail you a copy immediately.
+ *
+ * @copyright 2004-2006 Andrey Demenev
+ * @license http://www.php.net/license/3_0.txt PHP License
+ * @link http://pear.php.net/package/Text_Highlighter
+ * @category Text
+ * @package Text_Highlighter
* @version generated from: : html.xml,v 1.1 2007/06/03 02:35:28 ssttoo Exp
* @author Andrey Demenev <demenev@gmail.com>
- *
- */
-
-/**
- * @ignore
- */
-
-/**
- * Auto-generated class. HTML syntax highlighting
- *
+ *
+ */
+
+/**
+ * @ignore
+ */
+
+/**
+ * Auto-generated class. HTML syntax highlighting
+ *
* @author Andrey Demenev <demenev@gmail.com>
- * @category Text
- * @package Text_Highlighter
- * @copyright 2004-2006 Andrey Demenev
- * @license http://www.php.net/license/3_0.txt PHP License
- * @version Release: 0.7.0
- * @link http://pear.php.net/package/Text_Highlighter
- */
-class Text_Highlighter_HTML extends Text_Highlighter
-{
+ * @category Text
+ * @package Text_Highlighter
+ * @copyright 2004-2006 Andrey Demenev
+ * @license http://www.php.net/license/3_0.txt PHP License
+ * @version Release: 0.7.0
+ * @link http://pear.php.net/package/Text_Highlighter
+ */
+class Text_Highlighter_HTML extends Text_Highlighter
+{
var $_language = 'html';
- /**
- * Constructor
- *
- * @param array $options
- * @access public
- */
- function __construct($options=array())
- {
-
+ /**
+ * Constructor
+ *
+ * @param array $options
+ * @access public
+ */
+ function __construct($options=array())
+ {
+
$this->_options = $options;
$this->_regs = array (
-1 => '/((?i)\\<!--)|((?i)\\<[\\?\\/]?)|((?i)(&)[\\w\\-\\.]+;)/',
@@ -213,8 +213,8 @@ class Text_Highlighter_HTML extends Text_Highlighter
);
$this->_kwmap = array (
);
- $this->_defClass = 'code';
- $this->_checkDefines();
- }
-
+ $this->_defClass = 'code';
+ $this->_checkDefines();
+ }
+
} \ No newline at end of file
diff --git a/framework/3rdParty/TextHighlighter/Text/Highlighter/JAVA.php b/framework/3rdParty/TextHighlighter/Text/Highlighter/JAVA.php
index ef1e8e29..53c02680 100644
--- a/framework/3rdParty/TextHighlighter/Text/Highlighter/JAVA.php
+++ b/framework/3rdParty/TextHighlighter/Text/Highlighter/JAVA.php
@@ -1,49 +1,49 @@
-<?php
-/**
- * Auto-generated class. JAVA syntax highlighting
- *
- * PHP version 4 and 5
- *
- * LICENSE: This source file is subject to version 3.0 of the PHP license
- * that is available through the world-wide-web at the following URI:
- * http://www.php.net/license/3_0.txt. If you did not receive a copy of
- * the PHP License and are unable to obtain it through the web, please
- * send a note to license@php.net so we can mail you a copy immediately.
- *
- * @copyright 2004-2006 Andrey Demenev
- * @license http://www.php.net/license/3_0.txt PHP License
- * @link http://pear.php.net/package/Text_Highlighter
- * @category Text
- * @package Text_Highlighter
+<?php
+/**
+ * Auto-generated class. JAVA syntax highlighting
+ *
+ * PHP version 4 and 5
+ *
+ * LICENSE: This source file is subject to version 3.0 of the PHP license
+ * that is available through the world-wide-web at the following URI:
+ * http://www.php.net/license/3_0.txt. If you did not receive a copy of
+ * the PHP License and are unable to obtain it through the web, please
+ * send a note to license@php.net so we can mail you a copy immediately.
+ *
+ * @copyright 2004-2006 Andrey Demenev
+ * @license http://www.php.net/license/3_0.txt PHP License
+ * @link http://pear.php.net/package/Text_Highlighter
+ * @category Text
+ * @package Text_Highlighter
* @version generated from: : java.xml,v 1.1 2007/06/03 02:35:28 ssttoo Exp
* @author Andrey Demenev <demenev@gmail.com>
- *
- */
-
-/**
- * Auto-generated class. JAVA syntax highlighting
- *
+ *
+ */
+
+/**
+ * Auto-generated class. JAVA syntax highlighting
+ *
* @author Andrey Demenev <demenev@gmail.com>
- * @category Text
- * @package Text_Highlighter
- * @copyright 2004-2006 Andrey Demenev
- * @license http://www.php.net/license/3_0.txt PHP License
- * @version Release: 0.7.0
- * @link http://pear.php.net/package/Text_Highlighter
- */
-class Text_Highlighter_JAVA extends Text_Highlighter
-{
+ * @category Text
+ * @package Text_Highlighter
+ * @copyright 2004-2006 Andrey Demenev
+ * @license http://www.php.net/license/3_0.txt PHP License
+ * @version Release: 0.7.0
+ * @link http://pear.php.net/package/Text_Highlighter
+ */
+class Text_Highlighter_JAVA extends Text_Highlighter
+{
var $_language = 'java';
- /**
- * Constructor
- *
- * @param array $options
- * @access public
- */
- function __construct($options=array())
- {
-
+ /**
+ * Constructor
+ *
+ * @param array $options
+ * @access public
+ */
+ function __construct($options=array())
+ {
+
$this->_options = $options;
$this->_regs = array (
-1 => '/((?i)\\{)|((?i)\\()|((?i)\\[)|((?i)\\/\\*)|((?i)")|((?i)\')|((?i)\\/\\/)|((?i)[a-z_]\\w*)|((?i)0[xX][\\da-f]+)|((?i)\\d\\d*|\\b0\\b)|((?i)0[0-7]+)|((?i)(\\d*\\.\\d+)|(\\d+\\.\\d*))|((?i)((\\d+|((\\d*\\.\\d+)|(\\d+\\.\\d*)))[eE][+-]?\\d+))/',
@@ -777,8 +777,8 @@ class Text_Highlighter_JAVA extends Text_Highlighter
'reserved' => 'reserved',
'builtin' => 'builtin',
);
- $this->_defClass = 'code';
- $this->_checkDefines();
- }
-
+ $this->_defClass = 'code';
+ $this->_checkDefines();
+ }
+
} \ No newline at end of file
diff --git a/framework/3rdParty/TextHighlighter/Text/Highlighter/JAVASCRIPT.php b/framework/3rdParty/TextHighlighter/Text/Highlighter/JAVASCRIPT.php
index d29a4f64..2055c94e 100644
--- a/framework/3rdParty/TextHighlighter/Text/Highlighter/JAVASCRIPT.php
+++ b/framework/3rdParty/TextHighlighter/Text/Highlighter/JAVASCRIPT.php
@@ -1,49 +1,49 @@
-<?php
-/**
- * Auto-generated class. JAVASCRIPT syntax highlighting
- *
- * PHP version 4 and 5
- *
- * LICENSE: This source file is subject to version 3.0 of the PHP license
- * that is available through the world-wide-web at the following URI:
- * http://www.php.net/license/3_0.txt. If you did not receive a copy of
- * the PHP License and are unable to obtain it through the web, please
- * send a note to license@php.net so we can mail you a copy immediately.
- *
- * @copyright 2004-2006 Andrey Demenev
- * @license http://www.php.net/license/3_0.txt PHP License
- * @link http://pear.php.net/package/Text_Highlighter
- * @category Text
- * @package Text_Highlighter
+<?php
+/**
+ * Auto-generated class. JAVASCRIPT syntax highlighting
+ *
+ * PHP version 4 and 5
+ *
+ * LICENSE: This source file is subject to version 3.0 of the PHP license
+ * that is available through the world-wide-web at the following URI:
+ * http://www.php.net/license/3_0.txt. If you did not receive a copy of
+ * the PHP License and are unable to obtain it through the web, please
+ * send a note to license@php.net so we can mail you a copy immediately.
+ *
+ * @copyright 2004-2006 Andrey Demenev
+ * @license http://www.php.net/license/3_0.txt PHP License
+ * @link http://pear.php.net/package/Text_Highlighter
+ * @category Text
+ * @package Text_Highlighter
* @version generated from: : javascript.xml,v 1.2 2007/06/05 21:57:21 ssttoo Exp
* @author Andrey Demenev <demenev@gmail.com>
- *
- */
-
-/**
- * Auto-generated class. JAVASCRIPT syntax highlighting
- *
+ *
+ */
+
+/**
+ * Auto-generated class. JAVASCRIPT syntax highlighting
+ *
* @author Andrey Demenev <demenev@gmail.com>
- * @category Text
- * @package Text_Highlighter
- * @copyright 2004-2006 Andrey Demenev
- * @license http://www.php.net/license/3_0.txt PHP License
- * @version Release: 0.7.0
- * @link http://pear.php.net/package/Text_Highlighter
- */
-class Text_Highlighter_JAVASCRIPT extends Text_Highlighter
-{
+ * @category Text
+ * @package Text_Highlighter
+ * @copyright 2004-2006 Andrey Demenev
+ * @license http://www.php.net/license/3_0.txt PHP License
+ * @version Release: 0.7.0
+ * @link http://pear.php.net/package/Text_Highlighter
+ */
+class Text_Highlighter_JAVASCRIPT extends Text_Highlighter
+{
var $_language = 'javascript';
- /**
- * Constructor
- *
- * @param array $options
- * @access public
- */
- function __construct($options=array())
- {
-
+ /**
+ * Constructor
+ *
+ * @param array $options
+ * @access public
+ */
+ function __construct($options=array())
+ {
+
$this->_options = $options;
$this->_regs = array (
-1 => '/((?i)\\{)|((?i)\\()|((?i)\\[)|((?i)\\/\\*)|((?i)")|((?i)\')|((?i)\\/\\/)|((?i)[a-z_]\\w*)|((?i)\\d*\\.?\\d+)/',
@@ -606,8 +606,8 @@ class Text_Highlighter_JAVASCRIPT extends Text_Highlighter
'builtin' => 'builtin',
'reserved' => 'reserved',
);
- $this->_defClass = 'code';
- $this->_checkDefines();
- }
-
+ $this->_defClass = 'code';
+ $this->_checkDefines();
+ }
+
} \ No newline at end of file
diff --git a/framework/3rdParty/TextHighlighter/Text/Highlighter/MYSQL.php b/framework/3rdParty/TextHighlighter/Text/Highlighter/MYSQL.php
index 0fc75eb2..ba240512 100644
--- a/framework/3rdParty/TextHighlighter/Text/Highlighter/MYSQL.php
+++ b/framework/3rdParty/TextHighlighter/Text/Highlighter/MYSQL.php
@@ -1,49 +1,49 @@
-<?php
-/**
- * Auto-generated class. MYSQL syntax highlighting
- *
- * PHP version 4 and 5
- *
- * LICENSE: This source file is subject to version 3.0 of the PHP license
- * that is available through the world-wide-web at the following URI:
- * http://www.php.net/license/3_0.txt. If you did not receive a copy of
- * the PHP License and are unable to obtain it through the web, please
- * send a note to license@php.net so we can mail you a copy immediately.
- *
- * @copyright 2004-2006 Andrey Demenev
- * @license http://www.php.net/license/3_0.txt PHP License
- * @link http://pear.php.net/package/Text_Highlighter
- * @category Text
- * @package Text_Highlighter
+<?php
+/**
+ * Auto-generated class. MYSQL syntax highlighting
+ *
+ * PHP version 4 and 5
+ *
+ * LICENSE: This source file is subject to version 3.0 of the PHP license
+ * that is available through the world-wide-web at the following URI:
+ * http://www.php.net/license/3_0.txt. If you did not receive a copy of
+ * the PHP License and are unable to obtain it through the web, please
+ * send a note to license@php.net so we can mail you a copy immediately.
+ *
+ * @copyright 2004-2006 Andrey Demenev
+ * @license http://www.php.net/license/3_0.txt PHP License
+ * @link http://pear.php.net/package/Text_Highlighter
+ * @category Text
+ * @package Text_Highlighter
* @version generated from: : mysql.xml,v 1.1 2007/06/03 02:35:28 ssttoo Exp
* @author Andrey Demenev <demenev@gmail.com>
- *
- */
-
-/**
- * Auto-generated class. MYSQL syntax highlighting
- *
+ *
+ */
+
+/**
+ * Auto-generated class. MYSQL syntax highlighting
+ *
* @author Andrey Demenev <demenev@gmail.com>
- * @category Text
- * @package Text_Highlighter
- * @copyright 2004-2006 Andrey Demenev
- * @license http://www.php.net/license/3_0.txt PHP License
- * @version Release: 0.7.0
- * @link http://pear.php.net/package/Text_Highlighter
- */
-class Text_Highlighter_MYSQL extends Text_Highlighter
-{
+ * @category Text
+ * @package Text_Highlighter
+ * @copyright 2004-2006 Andrey Demenev
+ * @license http://www.php.net/license/3_0.txt PHP License
+ * @version Release: 0.7.0
+ * @link http://pear.php.net/package/Text_Highlighter
+ */
+class Text_Highlighter_MYSQL extends Text_Highlighter
+{
var $_language = 'mysql';
- /**
- * Constructor
- *
- * @param array $options
- * @access public
- */
- function __construct($options=array())
- {
-
+ /**
+ * Constructor
+ *
+ * @param array $options
+ * @access public
+ */
+ function __construct($options=array())
+ {
+
$this->_options = $options;
$this->_regs = array (
-1 => '/((?i)`)|((?i)\\/\\*)|((?i)(#|--\\s).*)|((?i)[a-z_]\\w*(?=\\s*\\())|((?i)[a-z_]\\w*)|((?i)")|((?i)\\()|((?i)\')|((?i)((\\d+|((\\d*\\.\\d+)|(\\d+\\.\\d*)))[eE][+-]?\\d+))|((?i)(\\d*\\.\\d+)|(\\d+\\.\\d*))|((?i)\\d+l?|\\b0l?\\b)|((?i)0[xX][\\da-f]+l?)/',
@@ -409,8 +409,8 @@ class Text_Highlighter_MYSQL extends Text_Highlighter
'function' => 'reserved',
'reserved' => 'reserved',
);
- $this->_defClass = 'code';
- $this->_checkDefines();
- }
-
+ $this->_defClass = 'code';
+ $this->_checkDefines();
+ }
+
} \ No newline at end of file
diff --git a/framework/3rdParty/TextHighlighter/Text/Highlighter/PERL.php b/framework/3rdParty/TextHighlighter/Text/Highlighter/PERL.php
index ace0d37c..9e8bd752 100644
--- a/framework/3rdParty/TextHighlighter/Text/Highlighter/PERL.php
+++ b/framework/3rdParty/TextHighlighter/Text/Highlighter/PERL.php
@@ -1,56 +1,56 @@
-<?php
-/**
+<?php
+/**
* Auto-generated class. PERL syntax highlighting
*
* This highlighter is EXPERIMENTAL, so that it may work incorrectly.
* Most rules were created by Mariusz Jakubowski, and extended by me.
* My knowledge of Perl is poor, and Perl syntax seems too
- * complicated to me.
- *
- * PHP version 4 and 5
- *
- * LICENSE: This source file is subject to version 3.0 of the PHP license
- * that is available through the world-wide-web at the following URI:
- * http://www.php.net/license/3_0.txt. If you did not receive a copy of
- * the PHP License and are unable to obtain it through the web, please
- * send a note to license@php.net so we can mail you a copy immediately.
- *
- * @copyright 2004-2006 Andrey Demenev
- * @license http://www.php.net/license/3_0.txt PHP License
- * @link http://pear.php.net/package/Text_Highlighter
- * @category Text
- * @package Text_Highlighter
+ * complicated to me.
+ *
+ * PHP version 4 and 5
+ *
+ * LICENSE: This source file is subject to version 3.0 of the PHP license
+ * that is available through the world-wide-web at the following URI:
+ * http://www.php.net/license/3_0.txt. If you did not receive a copy of
+ * the PHP License and are unable to obtain it through the web, please
+ * send a note to license@php.net so we can mail you a copy immediately.
+ *
+ * @copyright 2004-2006 Andrey Demenev
+ * @license http://www.php.net/license/3_0.txt PHP License
+ * @link http://pear.php.net/package/Text_Highlighter
+ * @category Text
+ * @package Text_Highlighter
* @version generated from: : perl.xml,v 1.1 2007/06/03 02:35:28 ssttoo Exp
* @author Mariusz 'kg' Jakubowski <kg@alternatywa.info>
* @author Andrey Demenev <demenev@gmail.com>
- *
- */
-
-/**
- * Auto-generated class. PERL syntax highlighting
- *
+ *
+ */
+
+/**
+ * Auto-generated class. PERL syntax highlighting
+ *
* @author Mariusz 'kg' Jakubowski <kg@alternatywa.info>
* @author Andrey Demenev <demenev@gmail.com>
- * @category Text
- * @package Text_Highlighter
- * @copyright 2004-2006 Andrey Demenev
- * @license http://www.php.net/license/3_0.txt PHP License
- * @version Release: 0.7.0
- * @link http://pear.php.net/package/Text_Highlighter
- */
-class Text_Highlighter_PERL extends Text_Highlighter
-{
+ * @category Text
+ * @package Text_Highlighter
+ * @copyright 2004-2006 Andrey Demenev
+ * @license http://www.php.net/license/3_0.txt PHP License
+ * @version Release: 0.7.0
+ * @link http://pear.php.net/package/Text_Highlighter
+ */
+class Text_Highlighter_PERL extends Text_Highlighter
+{
var $_language = 'perl';
- /**
- * Constructor
- *
- * @param array $options
- * @access public
- */
- function __construct($options=array())
- {
-
+ /**
+ * Constructor
+ *
+ * @param array $options
+ * @access public
+ */
+ function __construct($options=array())
+ {
+
$this->_options = $options;
$this->_regs = array (
-1 => '/((?m)^(#!)(.*))|((?m)^=\\w+)|(\\{)|(\\()|(\\[)|((use)\\s+([\\w:]*))|([& ](\\w{2,}::)+\\w{2,})|((?Us)\\b(q[wq]\\s*((\\{)|(\\()|(\\[)|(\\<)|([\\W\\S])))(?=(.*)((?(3)\\})(?(4)\\))(?(5)\\])(?(6)\\>)(?(7)\\7))))|((?Us)\\b(q\\s*((\\{)|(\\()|(\\[)|(\\<)|([\\W\\S])))(?=(.*)((?(3)\\})(?(4)\\))(?(5)\\])(?(6)\\>)(?(7)\\7))))|(#.*)|((?x)(s|tr) ([|#~`!@$%^&*-+=\\\\;:\'",.\\/?]) ((\\\\.|[^\\\\])*?) (\\2)((\\\\.|[^\\\\])*?)(\\2[ecgimosx]*))|((?x)(m) ([|#~`!@$%^&*-+=\\\\;:\'",.\\/?]) ((\\\\.|[^\\\\])*?) (\\2[ecgimosx]*))|( \\/)|(\\$#?[1-9\'`@!])|((?i)(\\$#?|[@%*])([a-z1-9_]+::)*([a-z1-9_]+|\\^(?-i)[A-Z]?(?i)))|((?i)\\$([a-z1-9_]+|\\^(?-i)[A-Z]?(?i)))|((?i)(&|\\w+)\'[\\w_\']+\\b)|((?i)(\\{)([a-z1-9]+)(\\}))|((?i)[\\$@%]#?\\{[a-z1-9]+\\})|(`)|(\')|(")|((?i)[a-z_]\\w*)|(\\d*\\.?\\d+)/',
@@ -1327,8 +1327,8 @@ class Text_Highlighter_PERL extends Text_Highlighter
'missingreserved' => 'reserved',
'flowcontrol' => 'reserved',
);
- $this->_defClass = 'code';
- $this->_checkDefines();
- }
-
+ $this->_defClass = 'code';
+ $this->_checkDefines();
+ }
+
} \ No newline at end of file
diff --git a/framework/3rdParty/TextHighlighter/Text/Highlighter/PHP.php b/framework/3rdParty/TextHighlighter/Text/Highlighter/PHP.php
index ee49951e..be504b65 100644
--- a/framework/3rdParty/TextHighlighter/Text/Highlighter/PHP.php
+++ b/framework/3rdParty/TextHighlighter/Text/Highlighter/PHP.php
@@ -1,1089 +1,1089 @@
-<?php
-/**
- * Auto-generated class. PHP syntax highlighting
- *
- * PHP version 4 and 5
- *
- * LICENSE: This source file is subject to version 3.0 of the PHP license
- * that is available through the world-wide-web at the following URI:
- * http://www.php.net/license/3_0.txt. If you did not receive a copy of
- * the PHP License and are unable to obtain it through the web, please
- * send a note to license@php.net so we can mail you a copy immediately.
- *
- * @copyright 2004-2006 Andrey Demenev
- * @license http://www.php.net/license/3_0.txt PHP License
- * @link http://pear.php.net/package/Text_Highlighter
- * @category Text
- * @package Text_Highlighter
- * @version generated from: Text/php.xml
- * @author Andrey Demenev <demenev@gmail.com>
- *
- */
-
-/**
- * Auto-generated class. PHP syntax highlighting
- *
- * @author Andrey Demenev <demenev@gmail.com>
- * @category Text
- * @package Text_Highlighter
- * @copyright 2004-2006 Andrey Demenev
- * @license http://www.php.net/license/3_0.txt PHP License
- * @version Release: 0.7.0
- * @link http://pear.php.net/package/Text_Highlighter
- */
-class Text_Highlighter_PHP extends Text_Highlighter
-{
- var $_language = 'php';
-
- /**
- * Constructor
- *
- * @param array $options
- * @access public
- */
- function __construct($options=array())
- {
-
- $this->_options = $options;
- $this->_regs = array (
- -1 => '/((?i)(\\<\\?(php|=)?)?)/',
- 0 => '/((?i)\\{)|((?i)\\()|((?i)\\[)|((?i)\\/\\*)|((?i)")|((?i)`)|((?mi)\\<\\<\\<[\\x20\\x09]*(\\w+)$)|((?i)\')|((?i)(#|\\/\\/))|((?i)[a-z_]\\w*)|((?i)\\((array|int|integer|string|bool|boolean|object|float|double)\\))|((?i)0[xX][\\da-f]+)|((?i)\\$[a-z_]\\w*)|((?i)\\d\\d*|\\b0\\b)|((?i)0[0-7]+)|((?i)(\\d*\\.\\d+)|(\\d+\\.\\d*))|((?i)((\\d+|((\\d*\\.\\d+)|(\\d+\\.\\d*)))[eE][+-]?\\d+))/',
- 1 => '/((?i)\\{)|((?i)\\()|((?i)\\[)|((?i)\\/\\*)|((?i)")|((?i)`)|((?mi)\\<\\<\\<[\\x20\\x09]*(\\w+)$)|((?i)\')|((?i)(#|\\/\\/))|((?i)[a-z_]\\w*)|((?i)\\((array|int|integer|string|bool|boolean|object|float|double)\\))|((?i)\\?\\>)|((?i)0[xX][\\da-f]+)|((?i)\\$[a-z_]\\w*)|((?i)\\d\\d*|\\b0\\b)|((?i)0[0-7]+)|((?i)(\\d*\\.\\d+)|(\\d+\\.\\d*))|((?i)((\\d+|((\\d*\\.\\d+)|(\\d+\\.\\d*)))[eE][+-]?\\d+))/',
- 2 => '/((?i)\\{)|((?i)\\()|((?i)\\[)|((?i)\\/\\*)|((?i)")|((?i)`)|((?mi)\\<\\<\\<[\\x20\\x09]*(\\w+)$)|((?i)\')|((?i)(#|\\/\\/))|((?i)[a-z_]\\w*)|((?i)\\((array|int|integer|string|bool|boolean|object|float|double)\\))|((?i)0[xX][\\da-f]+)|((?i)\\$[a-z_]\\w*)|((?i)\\d\\d*|\\b0\\b)|((?i)0[0-7]+)|((?i)(\\d*\\.\\d+)|(\\d+\\.\\d*))|((?i)((\\d+|((\\d*\\.\\d+)|(\\d+\\.\\d*)))[eE][+-]?\\d+))/',
- 3 => '/((?i)\\{)|((?i)\\()|((?i)\\[)|((?i)\\/\\*)|((?i)")|((?i)`)|((?mi)\\<\\<\\<[\\x20\\x09]*(\\w+)$)|((?i)\')|((?i)(#|\\/\\/))|((?i)[a-z_]\\w*)|((?i)\\((array|int|integer|string|bool|boolean|object|float|double)\\))|((?i)0[xX][\\da-f]+)|((?i)\\$[a-z_]\\w*)|((?i)\\d\\d*|\\b0\\b)|((?i)0[0-7]+)|((?i)(\\d*\\.\\d+)|(\\d+\\.\\d*))|((?i)((\\d+|((\\d*\\.\\d+)|(\\d+\\.\\d*)))[eE][+-]?\\d+))/',
- 4 => '/((?i)\\s@\\w+\\s)|((?i)((https?|ftp):\\/\\/[\\w\\?\\.\\-\\&=\\/%+]+)|(^|[\\s,!?])www\\.\\w+\\.\\w+[\\w\\?\\.\\&=\\/%+]*)|((?i)\\w+[\\.\\w\\-]+@(\\w+[\\.\\w\\-])+)|((?i)\\bnote:)|((?i)\\$\\w+\\s*:.*\\$)/',
- 5 => '/((?i)\\\\[\\\\"\'`tnr\\$\\{])|((?i)\\{\\$[a-z_].*\\})|((?i)\\$[a-z_]\\w*)/',
- 6 => '/((?i)\\\\\\\\|\\\\"|\\\\\'|\\\\`)|((?i)\\{\\$[a-z_].*\\})|((?i)\\$[a-z_]\\w*)/',
- 7 => '/((?i)\\\\[\\\\"\'`tnr\\$\\{])|((?i)\\{\\$[a-z_].*\\})|((?i)\\$[a-z_]\\w*)/',
- 8 => '/((?i)\\\\\\\\|\\\\"|\\\\\'|\\\\`)/',
- 9 => '/((?i)\\s@\\w+\\s)|((?i)((https?|ftp):\\/\\/[\\w\\?\\.\\-\\&=\\/%+]+)|(^|[\\s,!?])www\\.\\w+\\.\\w+[\\w\\?\\.\\&=\\/%+]*)|((?i)\\w+[\\.\\w\\-]+@(\\w+[\\.\\w\\-])+)|((?i)\\bnote:)|((?i)\\$\\w+\\s*:.*\\$)/',
- 10 => '//',
- );
- $this->_counts = array (
- -1 =>
- array (
- 0 => 2,
- ),
- 0 =>
- array (
- 0 => 0,
- 1 => 0,
- 2 => 0,
- 3 => 0,
- 4 => 0,
- 5 => 0,
- 6 => 1,
- 7 => 0,
- 8 => 1,
- 9 => 0,
- 10 => 1,
- 11 => 0,
- 12 => 0,
- 13 => 0,
- 14 => 0,
- 15 => 2,
- 16 => 5,
- ),
- 1 =>
- array (
- 0 => 0,
- 1 => 0,
- 2 => 0,
- 3 => 0,
- 4 => 0,
- 5 => 0,
- 6 => 1,
- 7 => 0,
- 8 => 1,
- 9 => 0,
- 10 => 1,
- 11 => 0,
- 12 => 0,
- 13 => 0,
- 14 => 0,
- 15 => 0,
- 16 => 2,
- 17 => 5,
- ),
- 2 =>
- array (
- 0 => 0,
- 1 => 0,
- 2 => 0,
- 3 => 0,
- 4 => 0,
- 5 => 0,
- 6 => 1,
- 7 => 0,
- 8 => 1,
- 9 => 0,
- 10 => 1,
- 11 => 0,
- 12 => 0,
- 13 => 0,
- 14 => 0,
- 15 => 2,
- 16 => 5,
- ),
- 3 =>
- array (
- 0 => 0,
- 1 => 0,
- 2 => 0,
- 3 => 0,
- 4 => 0,
- 5 => 0,
- 6 => 1,
- 7 => 0,
- 8 => 1,
- 9 => 0,
- 10 => 1,
- 11 => 0,
- 12 => 0,
- 13 => 0,
- 14 => 0,
- 15 => 2,
- 16 => 5,
- ),
- 4 =>
- array (
- 0 => 0,
- 1 => 3,
- 2 => 1,
- 3 => 0,
- 4 => 0,
- ),
- 5 =>
- array (
- 0 => 0,
- 1 => 0,
- 2 => 0,
- ),
- 6 =>
- array (
- 0 => 0,
- 1 => 0,
- 2 => 0,
- ),
- 7 =>
- array (
- 0 => 0,
- 1 => 0,
- 2 => 0,
- ),
- 8 =>
- array (
- 0 => 0,
- ),
- 9 =>
- array (
- 0 => 0,
- 1 => 3,
- 2 => 1,
- 3 => 0,
- 4 => 0,
- ),
- 10 =>
- array (
- ),
- );
- $this->_delim = array (
- -1 =>
- array (
- 0 => 'inlinetags',
- ),
- 0 =>
- array (
- 0 => 'brackets',
- 1 => 'brackets',
- 2 => 'brackets',
- 3 => 'comment',
- 4 => 'quotes',
- 5 => 'quotes',
- 6 => 'quotes',
- 7 => 'quotes',
- 8 => 'comment',
- 9 => '',
- 10 => '',
- 11 => '',
- 12 => '',
- 13 => '',
- 14 => '',
- 15 => '',
- 16 => '',
- ),
- 1 =>
- array (
- 0 => 'brackets',
- 1 => 'brackets',
- 2 => 'brackets',
- 3 => 'comment',
- 4 => 'quotes',
- 5 => 'quotes',
- 6 => 'quotes',
- 7 => 'quotes',
- 8 => 'comment',
- 9 => '',
- 10 => '',
- 11 => 'inlinetags',
- 12 => '',
- 13 => '',
- 14 => '',
- 15 => '',
- 16 => '',
- 17 => '',
- ),
- 2 =>
- array (
- 0 => 'brackets',
- 1 => 'brackets',
- 2 => 'brackets',
- 3 => 'comment',
- 4 => 'quotes',
- 5 => 'quotes',
- 6 => 'quotes',
- 7 => 'quotes',
- 8 => 'comment',
- 9 => '',
- 10 => '',
- 11 => '',
- 12 => '',
- 13 => '',
- 14 => '',
- 15 => '',
- 16 => '',
- ),
- 3 =>
- array (
- 0 => 'brackets',
- 1 => 'brackets',
- 2 => 'brackets',
- 3 => 'comment',
- 4 => 'quotes',
- 5 => 'quotes',
- 6 => 'quotes',
- 7 => 'quotes',
- 8 => 'comment',
- 9 => '',
- 10 => '',
- 11 => '',
- 12 => '',
- 13 => '',
- 14 => '',
- 15 => '',
- 16 => '',
- ),
- 4 =>
- array (
- 0 => '',
- 1 => '',
- 2 => '',
- 3 => '',
- 4 => '',
- ),
- 5 =>
- array (
- 0 => '',
- 1 => '',
- 2 => '',
- ),
- 6 =>
- array (
- 0 => '',
- 1 => '',
- 2 => '',
- ),
- 7 =>
- array (
- 0 => '',
- 1 => '',
- 2 => '',
- ),
- 8 =>
- array (
- 0 => '',
- ),
- 9 =>
- array (
- 0 => '',
- 1 => '',
- 2 => '',
- 3 => '',
- 4 => '',
- ),
- 10 =>
- array (
- ),
- );
- $this->_inner = array (
- -1 =>
- array (
- 0 => 'code',
- ),
- 0 =>
- array (
- 0 => 'code',
- 1 => 'code',
- 2 => 'code',
- 3 => 'comment',
- 4 => 'string',
- 5 => 'string',
- 6 => 'string',
- 7 => 'string',
- 8 => 'comment',
- 9 => 'identifier',
- 10 => 'reserved',
- 11 => 'number',
- 12 => 'var',
- 13 => 'number',
- 14 => 'number',
- 15 => 'number',
- 16 => 'number',
- ),
- 1 =>
- array (
- 0 => 'code',
- 1 => 'code',
- 2 => 'code',
- 3 => 'comment',
- 4 => 'string',
- 5 => 'string',
- 6 => 'string',
- 7 => 'string',
- 8 => 'comment',
- 9 => 'identifier',
- 10 => 'reserved',
- 11 => 'default',
- 12 => 'number',
- 13 => 'var',
- 14 => 'number',
- 15 => 'number',
- 16 => 'number',
- 17 => 'number',
- ),
- 2 =>
- array (
- 0 => 'code',
- 1 => 'code',
- 2 => 'code',
- 3 => 'comment',
- 4 => 'string',
- 5 => 'string',
- 6 => 'string',
- 7 => 'string',
- 8 => 'comment',
- 9 => 'identifier',
- 10 => 'reserved',
- 11 => 'number',
- 12 => 'var',
- 13 => 'number',
- 14 => 'number',
- 15 => 'number',
- 16 => 'number',
- ),
- 3 =>
- array (
- 0 => 'code',
- 1 => 'code',
- 2 => 'code',
- 3 => 'comment',
- 4 => 'string',
- 5 => 'string',
- 6 => 'string',
- 7 => 'string',
- 8 => 'comment',
- 9 => 'identifier',
- 10 => 'reserved',
- 11 => 'number',
- 12 => 'var',
- 13 => 'number',
- 14 => 'number',
- 15 => 'number',
- 16 => 'number',
- ),
- 4 =>
- array (
- 0 => 'inlinedoc',
- 1 => 'url',
- 2 => 'url',
- 3 => 'inlinedoc',
- 4 => 'inlinedoc',
- ),
- 5 =>
- array (
- 0 => 'special',
- 1 => 'var',
- 2 => 'var',
- ),
- 6 =>
- array (
- 0 => 'special',
- 1 => 'var',
- 2 => 'var',
- ),
- 7 =>
- array (
- 0 => 'special',
- 1 => 'var',
- 2 => 'var',
- ),
- 8 =>
- array (
- 0 => 'special',
- ),
- 9 =>
- array (
- 0 => 'inlinedoc',
- 1 => 'url',
- 2 => 'url',
- 3 => 'inlinedoc',
- 4 => 'inlinedoc',
- ),
- 10 =>
- array (
- ),
- );
- $this->_end = array (
- 0 => '/(?i)\\?\\>/',
- 1 => '/(?i)\\}/',
- 2 => '/(?i)\\)/',
- 3 => '/(?i)\\]/',
- 4 => '/(?i)\\*\\//',
- 5 => '/(?i)"/',
- 6 => '/(?i)`/',
- 7 => '/(?mi)^%1%;?$/',
- 8 => '/(?i)\'/',
- 9 => '/(?mi)$|(?=\\?\\>)/',
- 10 => '/(?i)\\<\\?(php|=)?/',
- );
- $this->_states = array (
- -1 =>
- array (
- 0 => 0,
- ),
- 0 =>
- array (
- 0 => 1,
- 1 => 2,
- 2 => 3,
- 3 => 4,
- 4 => 5,
- 5 => 6,
- 6 => 7,
- 7 => 8,
- 8 => 9,
- 9 => -1,
- 10 => -1,
- 11 => -1,
- 12 => -1,
- 13 => -1,
- 14 => -1,
- 15 => -1,
- 16 => -1,
- ),
- 1 =>
- array (
- 0 => 1,
- 1 => 2,
- 2 => 3,
- 3 => 4,
- 4 => 5,
- 5 => 6,
- 6 => 7,
- 7 => 8,
- 8 => 9,
- 9 => -1,
- 10 => -1,
- 11 => 10,
- 12 => -1,
- 13 => -1,
- 14 => -1,
- 15 => -1,
- 16 => -1,
- 17 => -1,
- ),
- 2 =>
- array (
- 0 => 1,
- 1 => 2,
- 2 => 3,
- 3 => 4,
- 4 => 5,
- 5 => 6,
- 6 => 7,
- 7 => 8,
- 8 => 9,
- 9 => -1,
- 10 => -1,
- 11 => -1,
- 12 => -1,
- 13 => -1,
- 14 => -1,
- 15 => -1,
- 16 => -1,
- ),
- 3 =>
- array (
- 0 => 1,
- 1 => 2,
- 2 => 3,
- 3 => 4,
- 4 => 5,
- 5 => 6,
- 6 => 7,
- 7 => 8,
- 8 => 9,
- 9 => -1,
- 10 => -1,
- 11 => -1,
- 12 => -1,
- 13 => -1,
- 14 => -1,
- 15 => -1,
- 16 => -1,
- ),
- 4 =>
- array (
- 0 => -1,
- 1 => -1,
- 2 => -1,
- 3 => -1,
- 4 => -1,
- ),
- 5 =>
- array (
- 0 => -1,
- 1 => -1,
- 2 => -1,
- ),
- 6 =>
- array (
- 0 => -1,
- 1 => -1,
- 2 => -1,
- ),
- 7 =>
- array (
- 0 => -1,
- 1 => -1,
- 2 => -1,
- ),
- 8 =>
- array (
- 0 => -1,
- ),
- 9 =>
- array (
- 0 => -1,
- 1 => -1,
- 2 => -1,
- 3 => -1,
- 4 => -1,
- ),
- 10 =>
- array (
- ),
- );
- $this->_keywords = array (
- -1 =>
- array (
- 0 => -1,
- ),
- 0 =>
- array (
- 0 => -1,
- 1 => -1,
- 2 => -1,
- 3 => -1,
- 4 => -1,
- 5 => -1,
- 6 => -1,
- 7 => -1,
- 8 => -1,
- 9 =>
- array (
- 'constants' => '/^(DIRECTORY_SEPARATOR|PATH_SEPARATOR)$/',
- 'reserved' => '/^((?i)echo|foreach|else|if|elseif|for|as|while|break|continue|class|const|declare|switch|case|endfor|endswitch|endforeach|endif|array|default|do|enddeclare|eval|exit|die|extends|function|global|include|include_once|require|require_once|isset|empty|list|new|static|unset|var|return|try|catch|final|throw|public|private|protected|abstract|interface|implements|define|__file__|__line__|__class__|__method__|__function__|null|true|false|and|or|xor)$/',
- ),
- 10 =>
- array (
- ),
- 11 =>
- array (
- ),
- 12 =>
- array (
- ),
- 13 =>
- array (
- ),
- 14 =>
- array (
- ),
- 15 =>
- array (
- ),
- 16 =>
- array (
- ),
- ),
- 1 =>
- array (
- 0 => -1,
- 1 => -1,
- 2 => -1,
- 3 => -1,
- 4 => -1,
- 5 => -1,
- 6 => -1,
- 7 => -1,
- 8 => -1,
- 9 =>
- array (
- 'constants' => '/^(DIRECTORY_SEPARATOR|PATH_SEPARATOR)$/',
- 'reserved' => '/^((?i)echo|foreach|else|if|elseif|for|as|while|break|continue|class|const|declare|switch|case|endfor|endswitch|endforeach|endif|array|default|do|enddeclare|eval|exit|die|extends|function|global|include|include_once|require|require_once|isset|empty|list|new|static|unset|var|return|try|catch|final|throw|public|private|protected|abstract|interface|implements|define|__file__|__line__|__class__|__method__|__function__|null|true|false|and|or|xor)$/',
- ),
- 10 =>
- array (
- ),
- 11 => -1,
- 12 =>
- array (
- ),
- 13 =>
- array (
- ),
- 14 =>
- array (
- ),
- 15 =>
- array (
- ),
- 16 =>
- array (
- ),
- 17 =>
- array (
- ),
- ),
- 2 =>
- array (
- 0 => -1,
- 1 => -1,
- 2 => -1,
- 3 => -1,
- 4 => -1,
- 5 => -1,
- 6 => -1,
- 7 => -1,
- 8 => -1,
- 9 =>
- array (
- 'constants' => '/^(DIRECTORY_SEPARATOR|PATH_SEPARATOR)$/',
- 'reserved' => '/^((?i)echo|foreach|else|if|elseif|for|as|while|break|continue|class|const|declare|switch|case|endfor|endswitch|endforeach|endif|array|default|do|enddeclare|eval|exit|die|extends|function|global|include|include_once|require|require_once|isset|empty|list|new|static|unset|var|return|try|catch|final|throw|public|private|protected|abstract|interface|implements|define|__file__|__line__|__class__|__method__|__function__|null|true|false|and|or|xor)$/',
- ),
- 10 =>
- array (
- ),
- 11 =>
- array (
- ),
- 12 =>
- array (
- ),
- 13 =>
- array (
- ),
- 14 =>
- array (
- ),
- 15 =>
- array (
- ),
- 16 =>
- array (
- ),
- ),
- 3 =>
- array (
- 0 => -1,
- 1 => -1,
- 2 => -1,
- 3 => -1,
- 4 => -1,
- 5 => -1,
- 6 => -1,
- 7 => -1,
- 8 => -1,
- 9 =>
- array (
- 'constants' => '/^(DIRECTORY_SEPARATOR|PATH_SEPARATOR)$/',
- 'reserved' => '/^((?i)echo|foreach|else|if|elseif|for|as|while|break|continue|class|const|declare|switch|case|endfor|endswitch|endforeach|endif|array|default|do|enddeclare|eval|exit|die|extends|function|global|include|include_once|require|require_once|isset|empty|list|new|static|unset|var|return|try|catch|final|throw|public|private|protected|abstract|interface|implements|define|__file__|__line__|__class__|__method__|__function__|null|true|false|and|or|xor)$/',
- ),
- 10 =>
- array (
- ),
- 11 =>
- array (
- ),
- 12 =>
- array (
- ),
- 13 =>
- array (
- ),
- 14 =>
- array (
- ),
- 15 =>
- array (
- ),
- 16 =>
- array (
- ),
- ),
- 4 =>
- array (
- 0 =>
- array (
- ),
- 1 =>
- array (
- ),
- 2 =>
- array (
- ),
- 3 =>
- array (
- ),
- 4 =>
- array (
- ),
- ),
- 5 =>
- array (
- 0 =>
- array (
- ),
- 1 =>
- array (
- ),
- 2 =>
- array (
- ),
- ),
- 6 =>
- array (
- 0 =>
- array (
- ),
- 1 =>
- array (
- ),
- 2 =>
- array (
- ),
- ),
- 7 =>
- array (
- 0 =>
- array (
- ),
- 1 =>
- array (
- ),
- 2 =>
- array (
- ),
- ),
- 8 =>
- array (
- 0 =>
- array (
- ),
- ),
- 9 =>
- array (
- 0 =>
- array (
- ),
- 1 =>
- array (
- ),
- 2 =>
- array (
- ),
- 3 =>
- array (
- ),
- 4 =>
- array (
- ),
- ),
- 10 =>
- array (
- ),
- );
- $this->_parts = array (
- 0 =>
- array (
- 0 => NULL,
- 1 => NULL,
- 2 => NULL,
- 3 => NULL,
- 4 => NULL,
- 5 => NULL,
- 6 => NULL,
- 7 => NULL,
- 8 => NULL,
- 9 => NULL,
- 10 => NULL,
- 11 => NULL,
- 12 => NULL,
- 13 => NULL,
- 14 => NULL,
- 15 => NULL,
- 16 => NULL,
- ),
- 1 =>
- array (
- 0 => NULL,
- 1 => NULL,
- 2 => NULL,
- 3 => NULL,
- 4 => NULL,
- 5 => NULL,
- 6 => NULL,
- 7 => NULL,
- 8 => NULL,
- 9 => NULL,
- 10 => NULL,
- 11 => NULL,
- 12 => NULL,
- 13 => NULL,
- 14 => NULL,
- 15 => NULL,
- 16 => NULL,
- 17 => NULL,
- ),
- 2 =>
- array (
- 0 => NULL,
- 1 => NULL,
- 2 => NULL,
- 3 => NULL,
- 4 => NULL,
- 5 => NULL,
- 6 => NULL,
- 7 => NULL,
- 8 => NULL,
- 9 => NULL,
- 10 => NULL,
- 11 => NULL,
- 12 => NULL,
- 13 => NULL,
- 14 => NULL,
- 15 => NULL,
- 16 => NULL,
- ),
- 3 =>
- array (
- 0 => NULL,
- 1 => NULL,
- 2 => NULL,
- 3 => NULL,
- 4 => NULL,
- 5 => NULL,
- 6 => NULL,
- 7 => NULL,
- 8 => NULL,
- 9 => NULL,
- 10 => NULL,
- 11 => NULL,
- 12 => NULL,
- 13 => NULL,
- 14 => NULL,
- 15 => NULL,
- 16 => NULL,
- ),
- 4 =>
- array (
- 0 => NULL,
- 1 => NULL,
- 2 => NULL,
- 3 => NULL,
- 4 => NULL,
- ),
- 5 =>
- array (
- 0 => NULL,
- 1 => NULL,
- 2 => NULL,
- ),
- 6 =>
- array (
- 0 => NULL,
- 1 => NULL,
- 2 => NULL,
- ),
- 7 =>
- array (
- 0 => NULL,
- 1 => NULL,
- 2 => NULL,
- ),
- 8 =>
- array (
- 0 => NULL,
- ),
- 9 =>
- array (
- 0 => NULL,
- 1 => NULL,
- 2 => NULL,
- 3 => NULL,
- 4 => NULL,
- ),
- 10 =>
- array (
- ),
- );
- $this->_subst = array (
- -1 =>
- array (
- 0 => false,
- ),
- 0 =>
- array (
- 0 => false,
- 1 => false,
- 2 => false,
- 3 => false,
- 4 => false,
- 5 => false,
- 6 => true,
- 7 => false,
- 8 => false,
- 9 => false,
- 10 => false,
- 11 => false,
- 12 => false,
- 13 => false,
- 14 => false,
- 15 => false,
- 16 => false,
- ),
- 1 =>
- array (
- 0 => false,
- 1 => false,
- 2 => false,
- 3 => false,
- 4 => false,
- 5 => false,
- 6 => true,
- 7 => false,
- 8 => false,
- 9 => false,
- 10 => false,
- 11 => false,
- 12 => false,
- 13 => false,
- 14 => false,
- 15 => false,
- 16 => false,
- 17 => false,
- ),
- 2 =>
- array (
- 0 => false,
- 1 => false,
- 2 => false,
- 3 => false,
- 4 => false,
- 5 => false,
- 6 => true,
- 7 => false,
- 8 => false,
- 9 => false,
- 10 => false,
- 11 => false,
- 12 => false,
- 13 => false,
- 14 => false,
- 15 => false,
- 16 => false,
- ),
- 3 =>
- array (
- 0 => false,
- 1 => false,
- 2 => false,
- 3 => false,
- 4 => false,
- 5 => false,
- 6 => true,
- 7 => false,
- 8 => false,
- 9 => false,
- 10 => false,
- 11 => false,
- 12 => false,
- 13 => false,
- 14 => false,
- 15 => false,
- 16 => false,
- ),
- 4 =>
- array (
- 0 => false,
- 1 => false,
- 2 => false,
- 3 => false,
- 4 => false,
- ),
- 5 =>
- array (
- 0 => false,
- 1 => false,
- 2 => false,
- ),
- 6 =>
- array (
- 0 => false,
- 1 => false,
- 2 => false,
- ),
- 7 =>
- array (
- 0 => false,
- 1 => false,
- 2 => false,
- ),
- 8 =>
- array (
- 0 => false,
- ),
- 9 =>
- array (
- 0 => false,
- 1 => false,
- 2 => false,
- 3 => false,
- 4 => false,
- ),
- 10 =>
- array (
- ),
- );
- $this->_conditions = array (
- );
- $this->_kwmap = array (
- 'constants' => 'reserved',
- 'reserved' => 'reserved',
- );
- $this->_defClass = 'code';
- $this->_checkDefines();
- }
-
+<?php
+/**
+ * Auto-generated class. PHP syntax highlighting
+ *
+ * PHP version 4 and 5
+ *
+ * LICENSE: This source file is subject to version 3.0 of the PHP license
+ * that is available through the world-wide-web at the following URI:
+ * http://www.php.net/license/3_0.txt. If you did not receive a copy of
+ * the PHP License and are unable to obtain it through the web, please
+ * send a note to license@php.net so we can mail you a copy immediately.
+ *
+ * @copyright 2004-2006 Andrey Demenev
+ * @license http://www.php.net/license/3_0.txt PHP License
+ * @link http://pear.php.net/package/Text_Highlighter
+ * @category Text
+ * @package Text_Highlighter
+ * @version generated from: Text/php.xml
+ * @author Andrey Demenev <demenev@gmail.com>
+ *
+ */
+
+/**
+ * Auto-generated class. PHP syntax highlighting
+ *
+ * @author Andrey Demenev <demenev@gmail.com>
+ * @category Text
+ * @package Text_Highlighter
+ * @copyright 2004-2006 Andrey Demenev
+ * @license http://www.php.net/license/3_0.txt PHP License
+ * @version Release: 0.7.0
+ * @link http://pear.php.net/package/Text_Highlighter
+ */
+class Text_Highlighter_PHP extends Text_Highlighter
+{
+ var $_language = 'php';
+
+ /**
+ * Constructor
+ *
+ * @param array $options
+ * @access public
+ */
+ function __construct($options=array())
+ {
+
+ $this->_options = $options;
+ $this->_regs = array (
+ -1 => '/((?i)(\\<\\?(php|=)?)?)/',
+ 0 => '/((?i)\\{)|((?i)\\()|((?i)\\[)|((?i)\\/\\*)|((?i)")|((?i)`)|((?mi)\\<\\<\\<[\\x20\\x09]*(\\w+)$)|((?i)\')|((?i)(#|\\/\\/))|((?i)[a-z_]\\w*)|((?i)\\((array|int|integer|string|bool|boolean|object|float|double)\\))|((?i)0[xX][\\da-f]+)|((?i)\\$[a-z_]\\w*)|((?i)\\d\\d*|\\b0\\b)|((?i)0[0-7]+)|((?i)(\\d*\\.\\d+)|(\\d+\\.\\d*))|((?i)((\\d+|((\\d*\\.\\d+)|(\\d+\\.\\d*)))[eE][+-]?\\d+))/',
+ 1 => '/((?i)\\{)|((?i)\\()|((?i)\\[)|((?i)\\/\\*)|((?i)")|((?i)`)|((?mi)\\<\\<\\<[\\x20\\x09]*(\\w+)$)|((?i)\')|((?i)(#|\\/\\/))|((?i)[a-z_]\\w*)|((?i)\\((array|int|integer|string|bool|boolean|object|float|double)\\))|((?i)\\?\\>)|((?i)0[xX][\\da-f]+)|((?i)\\$[a-z_]\\w*)|((?i)\\d\\d*|\\b0\\b)|((?i)0[0-7]+)|((?i)(\\d*\\.\\d+)|(\\d+\\.\\d*))|((?i)((\\d+|((\\d*\\.\\d+)|(\\d+\\.\\d*)))[eE][+-]?\\d+))/',
+ 2 => '/((?i)\\{)|((?i)\\()|((?i)\\[)|((?i)\\/\\*)|((?i)")|((?i)`)|((?mi)\\<\\<\\<[\\x20\\x09]*(\\w+)$)|((?i)\')|((?i)(#|\\/\\/))|((?i)[a-z_]\\w*)|((?i)\\((array|int|integer|string|bool|boolean|object|float|double)\\))|((?i)0[xX][\\da-f]+)|((?i)\\$[a-z_]\\w*)|((?i)\\d\\d*|\\b0\\b)|((?i)0[0-7]+)|((?i)(\\d*\\.\\d+)|(\\d+\\.\\d*))|((?i)((\\d+|((\\d*\\.\\d+)|(\\d+\\.\\d*)))[eE][+-]?\\d+))/',
+ 3 => '/((?i)\\{)|((?i)\\()|((?i)\\[)|((?i)\\/\\*)|((?i)")|((?i)`)|((?mi)\\<\\<\\<[\\x20\\x09]*(\\w+)$)|((?i)\')|((?i)(#|\\/\\/))|((?i)[a-z_]\\w*)|((?i)\\((array|int|integer|string|bool|boolean|object|float|double)\\))|((?i)0[xX][\\da-f]+)|((?i)\\$[a-z_]\\w*)|((?i)\\d\\d*|\\b0\\b)|((?i)0[0-7]+)|((?i)(\\d*\\.\\d+)|(\\d+\\.\\d*))|((?i)((\\d+|((\\d*\\.\\d+)|(\\d+\\.\\d*)))[eE][+-]?\\d+))/',
+ 4 => '/((?i)\\s@\\w+\\s)|((?i)((https?|ftp):\\/\\/[\\w\\?\\.\\-\\&=\\/%+]+)|(^|[\\s,!?])www\\.\\w+\\.\\w+[\\w\\?\\.\\&=\\/%+]*)|((?i)\\w+[\\.\\w\\-]+@(\\w+[\\.\\w\\-])+)|((?i)\\bnote:)|((?i)\\$\\w+\\s*:.*\\$)/',
+ 5 => '/((?i)\\\\[\\\\"\'`tnr\\$\\{])|((?i)\\{\\$[a-z_].*\\})|((?i)\\$[a-z_]\\w*)/',
+ 6 => '/((?i)\\\\\\\\|\\\\"|\\\\\'|\\\\`)|((?i)\\{\\$[a-z_].*\\})|((?i)\\$[a-z_]\\w*)/',
+ 7 => '/((?i)\\\\[\\\\"\'`tnr\\$\\{])|((?i)\\{\\$[a-z_].*\\})|((?i)\\$[a-z_]\\w*)/',
+ 8 => '/((?i)\\\\\\\\|\\\\"|\\\\\'|\\\\`)/',
+ 9 => '/((?i)\\s@\\w+\\s)|((?i)((https?|ftp):\\/\\/[\\w\\?\\.\\-\\&=\\/%+]+)|(^|[\\s,!?])www\\.\\w+\\.\\w+[\\w\\?\\.\\&=\\/%+]*)|((?i)\\w+[\\.\\w\\-]+@(\\w+[\\.\\w\\-])+)|((?i)\\bnote:)|((?i)\\$\\w+\\s*:.*\\$)/',
+ 10 => '//',
+ );
+ $this->_counts = array (
+ -1 =>
+ array (
+ 0 => 2,
+ ),
+ 0 =>
+ array (
+ 0 => 0,
+ 1 => 0,
+ 2 => 0,
+ 3 => 0,
+ 4 => 0,
+ 5 => 0,
+ 6 => 1,
+ 7 => 0,
+ 8 => 1,
+ 9 => 0,
+ 10 => 1,
+ 11 => 0,
+ 12 => 0,
+ 13 => 0,
+ 14 => 0,
+ 15 => 2,
+ 16 => 5,
+ ),
+ 1 =>
+ array (
+ 0 => 0,
+ 1 => 0,
+ 2 => 0,
+ 3 => 0,
+ 4 => 0,
+ 5 => 0,
+ 6 => 1,
+ 7 => 0,
+ 8 => 1,
+ 9 => 0,
+ 10 => 1,
+ 11 => 0,
+ 12 => 0,
+ 13 => 0,
+ 14 => 0,
+ 15 => 0,
+ 16 => 2,
+ 17 => 5,
+ ),
+ 2 =>
+ array (
+ 0 => 0,
+ 1 => 0,
+ 2 => 0,
+ 3 => 0,
+ 4 => 0,
+ 5 => 0,
+ 6 => 1,
+ 7 => 0,
+ 8 => 1,
+ 9 => 0,
+ 10 => 1,
+ 11 => 0,
+ 12 => 0,
+ 13 => 0,
+ 14 => 0,
+ 15 => 2,
+ 16 => 5,
+ ),
+ 3 =>
+ array (
+ 0 => 0,
+ 1 => 0,
+ 2 => 0,
+ 3 => 0,
+ 4 => 0,
+ 5 => 0,
+ 6 => 1,
+ 7 => 0,
+ 8 => 1,
+ 9 => 0,
+ 10 => 1,
+ 11 => 0,
+ 12 => 0,
+ 13 => 0,
+ 14 => 0,
+ 15 => 2,
+ 16 => 5,
+ ),
+ 4 =>
+ array (
+ 0 => 0,
+ 1 => 3,
+ 2 => 1,
+ 3 => 0,
+ 4 => 0,
+ ),
+ 5 =>
+ array (
+ 0 => 0,
+ 1 => 0,
+ 2 => 0,
+ ),
+ 6 =>
+ array (
+ 0 => 0,
+ 1 => 0,
+ 2 => 0,
+ ),
+ 7 =>
+ array (
+ 0 => 0,
+ 1 => 0,
+ 2 => 0,
+ ),
+ 8 =>
+ array (
+ 0 => 0,
+ ),
+ 9 =>
+ array (
+ 0 => 0,
+ 1 => 3,
+ 2 => 1,
+ 3 => 0,
+ 4 => 0,
+ ),
+ 10 =>
+ array (
+ ),
+ );
+ $this->_delim = array (
+ -1 =>
+ array (
+ 0 => 'inlinetags',
+ ),
+ 0 =>
+ array (
+ 0 => 'brackets',
+ 1 => 'brackets',
+ 2 => 'brackets',
+ 3 => 'comment',
+ 4 => 'quotes',
+ 5 => 'quotes',
+ 6 => 'quotes',
+ 7 => 'quotes',
+ 8 => 'comment',
+ 9 => '',
+ 10 => '',
+ 11 => '',
+ 12 => '',
+ 13 => '',
+ 14 => '',
+ 15 => '',
+ 16 => '',
+ ),
+ 1 =>
+ array (
+ 0 => 'brackets',
+ 1 => 'brackets',
+ 2 => 'brackets',
+ 3 => 'comment',
+ 4 => 'quotes',
+ 5 => 'quotes',
+ 6 => 'quotes',
+ 7 => 'quotes',
+ 8 => 'comment',
+ 9 => '',
+ 10 => '',
+ 11 => 'inlinetags',
+ 12 => '',
+ 13 => '',
+ 14 => '',
+ 15 => '',
+ 16 => '',
+ 17 => '',
+ ),
+ 2 =>
+ array (
+ 0 => 'brackets',
+ 1 => 'brackets',
+ 2 => 'brackets',
+ 3 => 'comment',
+ 4 => 'quotes',
+ 5 => 'quotes',
+ 6 => 'quotes',
+ 7 => 'quotes',
+ 8 => 'comment',
+ 9 => '',
+ 10 => '',
+ 11 => '',
+ 12 => '',
+ 13 => '',
+ 14 => '',
+ 15 => '',
+ 16 => '',
+ ),
+ 3 =>
+ array (
+ 0 => 'brackets',
+ 1 => 'brackets',
+ 2 => 'brackets',
+ 3 => 'comment',
+ 4 => 'quotes',
+ 5 => 'quotes',
+ 6 => 'quotes',
+ 7 => 'quotes',
+ 8 => 'comment',
+ 9 => '',
+ 10 => '',
+ 11 => '',
+ 12 => '',
+ 13 => '',
+ 14 => '',
+ 15 => '',
+ 16 => '',
+ ),
+ 4 =>
+ array (
+ 0 => '',
+ 1 => '',
+ 2 => '',
+ 3 => '',
+ 4 => '',
+ ),
+ 5 =>
+ array (
+ 0 => '',
+ 1 => '',
+ 2 => '',
+ ),
+ 6 =>
+ array (
+ 0 => '',
+ 1 => '',
+ 2 => '',
+ ),
+ 7 =>
+ array (
+ 0 => '',
+ 1 => '',
+ 2 => '',
+ ),
+ 8 =>
+ array (
+ 0 => '',
+ ),
+ 9 =>
+ array (
+ 0 => '',
+ 1 => '',
+ 2 => '',
+ 3 => '',
+ 4 => '',
+ ),
+ 10 =>
+ array (
+ ),
+ );
+ $this->_inner = array (
+ -1 =>
+ array (
+ 0 => 'code',
+ ),
+ 0 =>
+ array (
+ 0 => 'code',
+ 1 => 'code',
+ 2 => 'code',
+ 3 => 'comment',
+ 4 => 'string',
+ 5 => 'string',
+ 6 => 'string',
+ 7 => 'string',
+ 8 => 'comment',
+ 9 => 'identifier',
+ 10 => 'reserved',
+ 11 => 'number',
+ 12 => 'var',
+ 13 => 'number',
+ 14 => 'number',
+ 15 => 'number',
+ 16 => 'number',
+ ),
+ 1 =>
+ array (
+ 0 => 'code',
+ 1 => 'code',
+ 2 => 'code',
+ 3 => 'comment',
+ 4 => 'string',
+ 5 => 'string',
+ 6 => 'string',
+ 7 => 'string',
+ 8 => 'comment',
+ 9 => 'identifier',
+ 10 => 'reserved',
+ 11 => 'default',
+ 12 => 'number',
+ 13 => 'var',
+ 14 => 'number',
+ 15 => 'number',
+ 16 => 'number',
+ 17 => 'number',
+ ),
+ 2 =>
+ array (
+ 0 => 'code',
+ 1 => 'code',
+ 2 => 'code',
+ 3 => 'comment',
+ 4 => 'string',
+ 5 => 'string',
+ 6 => 'string',
+ 7 => 'string',
+ 8 => 'comment',
+ 9 => 'identifier',
+ 10 => 'reserved',
+ 11 => 'number',
+ 12 => 'var',
+ 13 => 'number',
+ 14 => 'number',
+ 15 => 'number',
+ 16 => 'number',
+ ),
+ 3 =>
+ array (
+ 0 => 'code',
+ 1 => 'code',
+ 2 => 'code',
+ 3 => 'comment',
+ 4 => 'string',
+ 5 => 'string',
+ 6 => 'string',
+ 7 => 'string',
+ 8 => 'comment',
+ 9 => 'identifier',
+ 10 => 'reserved',
+ 11 => 'number',
+ 12 => 'var',
+ 13 => 'number',
+ 14 => 'number',
+ 15 => 'number',
+ 16 => 'number',
+ ),
+ 4 =>
+ array (
+ 0 => 'inlinedoc',
+ 1 => 'url',
+ 2 => 'url',
+ 3 => 'inlinedoc',
+ 4 => 'inlinedoc',
+ ),
+ 5 =>
+ array (
+ 0 => 'special',
+ 1 => 'var',
+ 2 => 'var',
+ ),
+ 6 =>
+ array (
+ 0 => 'special',
+ 1 => 'var',
+ 2 => 'var',
+ ),
+ 7 =>
+ array (
+ 0 => 'special',
+ 1 => 'var',
+ 2 => 'var',
+ ),
+ 8 =>
+ array (
+ 0 => 'special',
+ ),
+ 9 =>
+ array (
+ 0 => 'inlinedoc',
+ 1 => 'url',
+ 2 => 'url',
+ 3 => 'inlinedoc',
+ 4 => 'inlinedoc',
+ ),
+ 10 =>
+ array (
+ ),
+ );
+ $this->_end = array (
+ 0 => '/(?i)\\?\\>/',
+ 1 => '/(?i)\\}/',
+ 2 => '/(?i)\\)/',
+ 3 => '/(?i)\\]/',
+ 4 => '/(?i)\\*\\//',
+ 5 => '/(?i)"/',
+ 6 => '/(?i)`/',
+ 7 => '/(?mi)^%1%;?$/',
+ 8 => '/(?i)\'/',
+ 9 => '/(?mi)$|(?=\\?\\>)/',
+ 10 => '/(?i)\\<\\?(php|=)?/',
+ );
+ $this->_states = array (
+ -1 =>
+ array (
+ 0 => 0,
+ ),
+ 0 =>
+ array (
+ 0 => 1,
+ 1 => 2,
+ 2 => 3,
+ 3 => 4,
+ 4 => 5,
+ 5 => 6,
+ 6 => 7,
+ 7 => 8,
+ 8 => 9,
+ 9 => -1,
+ 10 => -1,
+ 11 => -1,
+ 12 => -1,
+ 13 => -1,
+ 14 => -1,
+ 15 => -1,
+ 16 => -1,
+ ),
+ 1 =>
+ array (
+ 0 => 1,
+ 1 => 2,
+ 2 => 3,
+ 3 => 4,
+ 4 => 5,
+ 5 => 6,
+ 6 => 7,
+ 7 => 8,
+ 8 => 9,
+ 9 => -1,
+ 10 => -1,
+ 11 => 10,
+ 12 => -1,
+ 13 => -1,
+ 14 => -1,
+ 15 => -1,
+ 16 => -1,
+ 17 => -1,
+ ),
+ 2 =>
+ array (
+ 0 => 1,
+ 1 => 2,
+ 2 => 3,
+ 3 => 4,
+ 4 => 5,
+ 5 => 6,
+ 6 => 7,
+ 7 => 8,
+ 8 => 9,
+ 9 => -1,
+ 10 => -1,
+ 11 => -1,
+ 12 => -1,
+ 13 => -1,
+ 14 => -1,
+ 15 => -1,
+ 16 => -1,
+ ),
+ 3 =>
+ array (
+ 0 => 1,
+ 1 => 2,
+ 2 => 3,
+ 3 => 4,
+ 4 => 5,
+ 5 => 6,
+ 6 => 7,
+ 7 => 8,
+ 8 => 9,
+ 9 => -1,
+ 10 => -1,
+ 11 => -1,
+ 12 => -1,
+ 13 => -1,
+ 14 => -1,
+ 15 => -1,
+ 16 => -1,
+ ),
+ 4 =>
+ array (
+ 0 => -1,
+ 1 => -1,
+ 2 => -1,
+ 3 => -1,
+ 4 => -1,
+ ),
+ 5 =>
+ array (
+ 0 => -1,
+ 1 => -1,
+ 2 => -1,
+ ),
+ 6 =>
+ array (
+ 0 => -1,
+ 1 => -1,
+ 2 => -1,
+ ),
+ 7 =>
+ array (
+ 0 => -1,
+ 1 => -1,
+ 2 => -1,
+ ),
+ 8 =>
+ array (
+ 0 => -1,
+ ),
+ 9 =>
+ array (
+ 0 => -1,
+ 1 => -1,
+ 2 => -1,
+ 3 => -1,
+ 4 => -1,
+ ),
+ 10 =>
+ array (
+ ),
+ );
+ $this->_keywords = array (
+ -1 =>
+ array (
+ 0 => -1,
+ ),
+ 0 =>
+ array (
+ 0 => -1,
+ 1 => -1,
+ 2 => -1,
+ 3 => -1,
+ 4 => -1,
+ 5 => -1,
+ 6 => -1,
+ 7 => -1,
+ 8 => -1,
+ 9 =>
+ array (
+ 'constants' => '/^(DIRECTORY_SEPARATOR|PATH_SEPARATOR)$/',
+ 'reserved' => '/^((?i)echo|foreach|else|if|elseif|for|as|while|break|continue|class|const|declare|switch|case|endfor|endswitch|endforeach|endif|array|default|do|enddeclare|eval|exit|die|extends|function|global|include|include_once|require|require_once|isset|empty|list|new|static|unset|var|return|try|catch|final|throw|public|private|protected|abstract|interface|implements|define|__file__|__line__|__class__|__method__|__function__|null|true|false|and|or|xor)$/',
+ ),
+ 10 =>
+ array (
+ ),
+ 11 =>
+ array (
+ ),
+ 12 =>
+ array (
+ ),
+ 13 =>
+ array (
+ ),
+ 14 =>
+ array (
+ ),
+ 15 =>
+ array (
+ ),
+ 16 =>
+ array (
+ ),
+ ),
+ 1 =>
+ array (
+ 0 => -1,
+ 1 => -1,
+ 2 => -1,
+ 3 => -1,
+ 4 => -1,
+ 5 => -1,
+ 6 => -1,
+ 7 => -1,
+ 8 => -1,
+ 9 =>
+ array (
+ 'constants' => '/^(DIRECTORY_SEPARATOR|PATH_SEPARATOR)$/',
+ 'reserved' => '/^((?i)echo|foreach|else|if|elseif|for|as|while|break|continue|class|const|declare|switch|case|endfor|endswitch|endforeach|endif|array|default|do|enddeclare|eval|exit|die|extends|function|global|include|include_once|require|require_once|isset|empty|list|new|static|unset|var|return|try|catch|final|throw|public|private|protected|abstract|interface|implements|define|__file__|__line__|__class__|__method__|__function__|null|true|false|and|or|xor)$/',
+ ),
+ 10 =>
+ array (
+ ),
+ 11 => -1,
+ 12 =>
+ array (
+ ),
+ 13 =>
+ array (
+ ),
+ 14 =>
+ array (
+ ),
+ 15 =>
+ array (
+ ),
+ 16 =>
+ array (
+ ),
+ 17 =>
+ array (
+ ),
+ ),
+ 2 =>
+ array (
+ 0 => -1,
+ 1 => -1,
+ 2 => -1,
+ 3 => -1,
+ 4 => -1,
+ 5 => -1,
+ 6 => -1,
+ 7 => -1,
+ 8 => -1,
+ 9 =>
+ array (
+ 'constants' => '/^(DIRECTORY_SEPARATOR|PATH_SEPARATOR)$/',
+ 'reserved' => '/^((?i)echo|foreach|else|if|elseif|for|as|while|break|continue|class|const|declare|switch|case|endfor|endswitch|endforeach|endif|array|default|do|enddeclare|eval|exit|die|extends|function|global|include|include_once|require|require_once|isset|empty|list|new|static|unset|var|return|try|catch|final|throw|public|private|protected|abstract|interface|implements|define|__file__|__line__|__class__|__method__|__function__|null|true|false|and|or|xor)$/',
+ ),
+ 10 =>
+ array (
+ ),
+ 11 =>
+ array (
+ ),
+ 12 =>
+ array (
+ ),
+ 13 =>
+ array (
+ ),
+ 14 =>
+ array (
+ ),
+ 15 =>
+ array (
+ ),
+ 16 =>
+ array (
+ ),
+ ),
+ 3 =>
+ array (
+ 0 => -1,
+ 1 => -1,
+ 2 => -1,
+ 3 => -1,
+ 4 => -1,
+ 5 => -1,
+ 6 => -1,
+ 7 => -1,
+ 8 => -1,
+ 9 =>
+ array (
+ 'constants' => '/^(DIRECTORY_SEPARATOR|PATH_SEPARATOR)$/',
+ 'reserved' => '/^((?i)echo|foreach|else|if|elseif|for|as|while|break|continue|class|const|declare|switch|case|endfor|endswitch|endforeach|endif|array|default|do|enddeclare|eval|exit|die|extends|function|global|include|include_once|require|require_once|isset|empty|list|new|static|unset|var|return|try|catch|final|throw|public|private|protected|abstract|interface|implements|define|__file__|__line__|__class__|__method__|__function__|null|true|false|and|or|xor)$/',
+ ),
+ 10 =>
+ array (
+ ),
+ 11 =>
+ array (
+ ),
+ 12 =>
+ array (
+ ),
+ 13 =>
+ array (
+ ),
+ 14 =>
+ array (
+ ),
+ 15 =>
+ array (
+ ),
+ 16 =>
+ array (
+ ),
+ ),
+ 4 =>
+ array (
+ 0 =>
+ array (
+ ),
+ 1 =>
+ array (
+ ),
+ 2 =>
+ array (
+ ),
+ 3 =>
+ array (
+ ),
+ 4 =>
+ array (
+ ),
+ ),
+ 5 =>
+ array (
+ 0 =>
+ array (
+ ),
+ 1 =>
+ array (
+ ),
+ 2 =>
+ array (
+ ),
+ ),
+ 6 =>
+ array (
+ 0 =>
+ array (
+ ),
+ 1 =>
+ array (
+ ),
+ 2 =>
+ array (
+ ),
+ ),
+ 7 =>
+ array (
+ 0 =>
+ array (
+ ),
+ 1 =>
+ array (
+ ),
+ 2 =>
+ array (
+ ),
+ ),
+ 8 =>
+ array (
+ 0 =>
+ array (
+ ),
+ ),
+ 9 =>
+ array (
+ 0 =>
+ array (
+ ),
+ 1 =>
+ array (
+ ),
+ 2 =>
+ array (
+ ),
+ 3 =>
+ array (
+ ),
+ 4 =>
+ array (
+ ),
+ ),
+ 10 =>
+ array (
+ ),
+ );
+ $this->_parts = array (
+ 0 =>
+ array (
+ 0 => NULL,
+ 1 => NULL,
+ 2 => NULL,
+ 3 => NULL,
+ 4 => NULL,
+ 5 => NULL,
+ 6 => NULL,
+ 7 => NULL,
+ 8 => NULL,
+ 9 => NULL,
+ 10 => NULL,
+ 11 => NULL,
+ 12 => NULL,
+ 13 => NULL,
+ 14 => NULL,
+ 15 => NULL,
+ 16 => NULL,
+ ),
+ 1 =>
+ array (
+ 0 => NULL,
+ 1 => NULL,
+ 2 => NULL,
+ 3 => NULL,
+ 4 => NULL,
+ 5 => NULL,
+ 6 => NULL,
+ 7 => NULL,
+ 8 => NULL,
+ 9 => NULL,
+ 10 => NULL,
+ 11 => NULL,
+ 12 => NULL,
+ 13 => NULL,
+ 14 => NULL,
+ 15 => NULL,
+ 16 => NULL,
+ 17 => NULL,
+ ),
+ 2 =>
+ array (
+ 0 => NULL,
+ 1 => NULL,
+ 2 => NULL,
+ 3 => NULL,
+ 4 => NULL,
+ 5 => NULL,
+ 6 => NULL,
+ 7 => NULL,
+ 8 => NULL,
+ 9 => NULL,
+ 10 => NULL,
+ 11 => NULL,
+ 12 => NULL,
+ 13 => NULL,
+ 14 => NULL,
+ 15 => NULL,
+ 16 => NULL,
+ ),
+ 3 =>
+ array (
+ 0 => NULL,
+ 1 => NULL,
+ 2 => NULL,
+ 3 => NULL,
+ 4 => NULL,
+ 5 => NULL,
+ 6 => NULL,
+ 7 => NULL,
+ 8 => NULL,
+ 9 => NULL,
+ 10 => NULL,
+ 11 => NULL,
+ 12 => NULL,
+ 13 => NULL,
+ 14 => NULL,
+ 15 => NULL,
+ 16 => NULL,
+ ),
+ 4 =>
+ array (
+ 0 => NULL,
+ 1 => NULL,
+ 2 => NULL,
+ 3 => NULL,
+ 4 => NULL,
+ ),
+ 5 =>
+ array (
+ 0 => NULL,
+ 1 => NULL,
+ 2 => NULL,
+ ),
+ 6 =>
+ array (
+ 0 => NULL,
+ 1 => NULL,
+ 2 => NULL,
+ ),
+ 7 =>
+ array (
+ 0 => NULL,
+ 1 => NULL,
+ 2 => NULL,
+ ),
+ 8 =>
+ array (
+ 0 => NULL,
+ ),
+ 9 =>
+ array (
+ 0 => NULL,
+ 1 => NULL,
+ 2 => NULL,
+ 3 => NULL,
+ 4 => NULL,
+ ),
+ 10 =>
+ array (
+ ),
+ );
+ $this->_subst = array (
+ -1 =>
+ array (
+ 0 => false,
+ ),
+ 0 =>
+ array (
+ 0 => false,
+ 1 => false,
+ 2 => false,
+ 3 => false,
+ 4 => false,
+ 5 => false,
+ 6 => true,
+ 7 => false,
+ 8 => false,
+ 9 => false,
+ 10 => false,
+ 11 => false,
+ 12 => false,
+ 13 => false,
+ 14 => false,
+ 15 => false,
+ 16 => false,
+ ),
+ 1 =>
+ array (
+ 0 => false,
+ 1 => false,
+ 2 => false,
+ 3 => false,
+ 4 => false,
+ 5 => false,
+ 6 => true,
+ 7 => false,
+ 8 => false,
+ 9 => false,
+ 10 => false,
+ 11 => false,
+ 12 => false,
+ 13 => false,
+ 14 => false,
+ 15 => false,
+ 16 => false,
+ 17 => false,
+ ),
+ 2 =>
+ array (
+ 0 => false,
+ 1 => false,
+ 2 => false,
+ 3 => false,
+ 4 => false,
+ 5 => false,
+ 6 => true,
+ 7 => false,
+ 8 => false,
+ 9 => false,
+ 10 => false,
+ 11 => false,
+ 12 => false,
+ 13 => false,
+ 14 => false,
+ 15 => false,
+ 16 => false,
+ ),
+ 3 =>
+ array (
+ 0 => false,
+ 1 => false,
+ 2 => false,
+ 3 => false,
+ 4 => false,
+ 5 => false,
+ 6 => true,
+ 7 => false,
+ 8 => false,
+ 9 => false,
+ 10 => false,
+ 11 => false,
+ 12 => false,
+ 13 => false,
+ 14 => false,
+ 15 => false,
+ 16 => false,
+ ),
+ 4 =>
+ array (
+ 0 => false,
+ 1 => false,
+ 2 => false,
+ 3 => false,
+ 4 => false,
+ ),
+ 5 =>
+ array (
+ 0 => false,
+ 1 => false,
+ 2 => false,
+ ),
+ 6 =>
+ array (
+ 0 => false,
+ 1 => false,
+ 2 => false,
+ ),
+ 7 =>
+ array (
+ 0 => false,
+ 1 => false,
+ 2 => false,
+ ),
+ 8 =>
+ array (
+ 0 => false,
+ ),
+ 9 =>
+ array (
+ 0 => false,
+ 1 => false,
+ 2 => false,
+ 3 => false,
+ 4 => false,
+ ),
+ 10 =>
+ array (
+ ),
+ );
+ $this->_conditions = array (
+ );
+ $this->_kwmap = array (
+ 'constants' => 'reserved',
+ 'reserved' => 'reserved',
+ );
+ $this->_defClass = 'code';
+ $this->_checkDefines();
+ }
+
} \ No newline at end of file
diff --git a/framework/3rdParty/TextHighlighter/Text/Highlighter/PRADO.php b/framework/3rdParty/TextHighlighter/Text/Highlighter/PRADO.php
index 2bd402c2..dab4a4bc 100644
--- a/framework/3rdParty/TextHighlighter/Text/Highlighter/PRADO.php
+++ b/framework/3rdParty/TextHighlighter/Text/Highlighter/PRADO.php
@@ -1,254 +1,254 @@
-<?php
-/**
- * Auto-generated class. PRADO syntax highlighting
- *
- * PHP version 4 and 5
- *
- * LICENSE: This source file is subject to version 3.0 of the PHP license
- * that is available through the world-wide-web at the following URI:
- * http://www.php.net/license/3_0.txt. If you did not receive a copy of
- * the PHP License and are unable to obtain it through the web, please
- * send a note to license@php.net so we can mail you a copy immediately.
- *
- * @copyright 2004-2006 Andrey Demenev
- * @license http://www.php.net/license/3_0.txt PHP License
- * @link http://pear.php.net/package/Text_Highlighter
- * @category Text
- * @package Text_Highlighter
- * @version generated from: Text/prado.xml
- * @author Andrey Demenev <demenev@gmail.com>
- *
- */
-
-/**
- * Auto-generated class. PRADO syntax highlighting
- *
- * @author Andrey Demenev <demenev@gmail.com>
- * @category Text
- * @package Text_Highlighter
- * @copyright 2004-2006 Andrey Demenev
- * @license http://www.php.net/license/3_0.txt PHP License
- * @version Release: 0.7.0
- * @link http://pear.php.net/package/Text_Highlighter
- */
-class Text_Highlighter_PRADO extends Text_Highlighter
-{
- var $_language = 'prado';
-
- /**
- * Constructor
- *
- * @param array $options
- * @access public
- */
- function __construct($options=array())
- {
-
- $this->_options = $options;
- $this->_regs = array (
- -1 => '/((?i)\\<\\!\\[CDATA\\[)|((?i)\\<!--)|((?i)\\<[\\?\\/]?)|((?i)(&|%)[\\w\\-\\.]+;)/',
- 0 => '//',
- 1 => '//',
- 2 => '/((?i)(?<=[\\<\\/?])com:\\w+)|((?i)(?<=[\\<\\/?])[\\w\\-\\:]+)|((?i)[\\w\\-\\:]+)|((?i)")/',
- 3 => '/((?i)(&|%)[\\w\\-\\.]+;)/',
- );
- $this->_counts = array (
- -1 =>
- array (
- 0 => 0,
- 1 => 0,
- 2 => 0,
- 3 => 1,
- ),
- 0 =>
- array (
- ),
- 1 =>
- array (
- ),
- 2 =>
- array (
- 0 => 0,
- 1 => 0,
- 2 => 0,
- 3 => 0,
- ),
- 3 =>
- array (
- 0 => 1,
- ),
- );
- $this->_delim = array (
- -1 =>
- array (
- 0 => 'comment',
- 1 => 'comment',
- 2 => 'brackets',
- 3 => '',
- ),
- 0 =>
- array (
- ),
- 1 =>
- array (
- ),
- 2 =>
- array (
- 0 => '',
- 1 => '',
- 2 => '',
- 3 => 'quotes',
- ),
- 3 =>
- array (
- 0 => '',
- ),
- );
- $this->_inner = array (
- -1 =>
- array (
- 0 => 'comment',
- 1 => 'comment',
- 2 => 'code',
- 3 => 'special',
- ),
- 0 =>
- array (
- ),
- 1 =>
- array (
- ),
- 2 =>
- array (
- 0 => 'special',
- 1 => 'reserved',
- 2 => 'var',
- 3 => 'string',
- ),
- 3 =>
- array (
- 0 => 'special',
- ),
- );
- $this->_end = array (
- 0 => '/(?i)\\]\\]\\>/',
- 1 => '/(?i)--\\>/',
- 2 => '/(?i)[\\/\\?]?\\>/',
- 3 => '/(?i)"/',
- );
- $this->_states = array (
- -1 =>
- array (
- 0 => 0,
- 1 => 1,
- 2 => 2,
- 3 => -1,
- ),
- 0 =>
- array (
- ),
- 1 =>
- array (
- ),
- 2 =>
- array (
- 0 => -1,
- 1 => -1,
- 2 => -1,
- 3 => 3,
- ),
- 3 =>
- array (
- 0 => -1,
- ),
- );
- $this->_keywords = array (
- -1 =>
- array (
- 0 => -1,
- 1 => -1,
- 2 => -1,
- 3 =>
- array (
- ),
- ),
- 0 =>
- array (
- ),
- 1 =>
- array (
- ),
- 2 =>
- array (
- 0 =>
- array (
- ),
- 1 =>
- array (
- ),
- 2 =>
- array (
- ),
- 3 => -1,
- ),
- 3 =>
- array (
- 0 =>
- array (
- ),
- ),
- );
- $this->_parts = array (
- 0 =>
- array (
- ),
- 1 =>
- array (
- ),
- 2 =>
- array (
- 0 => NULL,
- 1 => NULL,
- 2 => NULL,
- 3 => NULL,
- ),
- 3 =>
- array (
- 0 => NULL,
- ),
- );
- $this->_subst = array (
- -1 =>
- array (
- 0 => false,
- 1 => false,
- 2 => false,
- 3 => false,
- ),
- 0 =>
- array (
- ),
- 1 =>
- array (
- ),
- 2 =>
- array (
- 0 => false,
- 1 => false,
- 2 => false,
- 3 => false,
- ),
- 3 =>
- array (
- 0 => false,
- ),
- );
- $this->_conditions = array (
- );
- $this->_kwmap = array (
- );
- $this->_defClass = 'code';
- $this->_checkDefines();
- }
-
+<?php
+/**
+ * Auto-generated class. PRADO syntax highlighting
+ *
+ * PHP version 4 and 5
+ *
+ * LICENSE: This source file is subject to version 3.0 of the PHP license
+ * that is available through the world-wide-web at the following URI:
+ * http://www.php.net/license/3_0.txt. If you did not receive a copy of
+ * the PHP License and are unable to obtain it through the web, please
+ * send a note to license@php.net so we can mail you a copy immediately.
+ *
+ * @copyright 2004-2006 Andrey Demenev
+ * @license http://www.php.net/license/3_0.txt PHP License
+ * @link http://pear.php.net/package/Text_Highlighter
+ * @category Text
+ * @package Text_Highlighter
+ * @version generated from: Text/prado.xml
+ * @author Andrey Demenev <demenev@gmail.com>
+ *
+ */
+
+/**
+ * Auto-generated class. PRADO syntax highlighting
+ *
+ * @author Andrey Demenev <demenev@gmail.com>
+ * @category Text
+ * @package Text_Highlighter
+ * @copyright 2004-2006 Andrey Demenev
+ * @license http://www.php.net/license/3_0.txt PHP License
+ * @version Release: 0.7.0
+ * @link http://pear.php.net/package/Text_Highlighter
+ */
+class Text_Highlighter_PRADO extends Text_Highlighter
+{
+ var $_language = 'prado';
+
+ /**
+ * Constructor
+ *
+ * @param array $options
+ * @access public
+ */
+ function __construct($options=array())
+ {
+
+ $this->_options = $options;
+ $this->_regs = array (
+ -1 => '/((?i)\\<\\!\\[CDATA\\[)|((?i)\\<!--)|((?i)\\<[\\?\\/]?)|((?i)(&|%)[\\w\\-\\.]+;)/',
+ 0 => '//',
+ 1 => '//',
+ 2 => '/((?i)(?<=[\\<\\/?])com:\\w+)|((?i)(?<=[\\<\\/?])[\\w\\-\\:]+)|((?i)[\\w\\-\\:]+)|((?i)")/',
+ 3 => '/((?i)(&|%)[\\w\\-\\.]+;)/',
+ );
+ $this->_counts = array (
+ -1 =>
+ array (
+ 0 => 0,
+ 1 => 0,
+ 2 => 0,
+ 3 => 1,
+ ),
+ 0 =>
+ array (
+ ),
+ 1 =>
+ array (
+ ),
+ 2 =>
+ array (
+ 0 => 0,
+ 1 => 0,
+ 2 => 0,
+ 3 => 0,
+ ),
+ 3 =>
+ array (
+ 0 => 1,
+ ),
+ );
+ $this->_delim = array (
+ -1 =>
+ array (
+ 0 => 'comment',
+ 1 => 'comment',
+ 2 => 'brackets',
+ 3 => '',
+ ),
+ 0 =>
+ array (
+ ),
+ 1 =>
+ array (
+ ),
+ 2 =>
+ array (
+ 0 => '',
+ 1 => '',
+ 2 => '',
+ 3 => 'quotes',
+ ),
+ 3 =>
+ array (
+ 0 => '',
+ ),
+ );
+ $this->_inner = array (
+ -1 =>
+ array (
+ 0 => 'comment',
+ 1 => 'comment',
+ 2 => 'code',
+ 3 => 'special',
+ ),
+ 0 =>
+ array (
+ ),
+ 1 =>
+ array (
+ ),
+ 2 =>
+ array (
+ 0 => 'special',
+ 1 => 'reserved',
+ 2 => 'var',
+ 3 => 'string',
+ ),
+ 3 =>
+ array (
+ 0 => 'special',
+ ),
+ );
+ $this->_end = array (
+ 0 => '/(?i)\\]\\]\\>/',
+ 1 => '/(?i)--\\>/',
+ 2 => '/(?i)[\\/\\?]?\\>/',
+ 3 => '/(?i)"/',
+ );
+ $this->_states = array (
+ -1 =>
+ array (
+ 0 => 0,
+ 1 => 1,
+ 2 => 2,
+ 3 => -1,
+ ),
+ 0 =>
+ array (
+ ),
+ 1 =>
+ array (
+ ),
+ 2 =>
+ array (
+ 0 => -1,
+ 1 => -1,
+ 2 => -1,
+ 3 => 3,
+ ),
+ 3 =>
+ array (
+ 0 => -1,
+ ),
+ );
+ $this->_keywords = array (
+ -1 =>
+ array (
+ 0 => -1,
+ 1 => -1,
+ 2 => -1,
+ 3 =>
+ array (
+ ),
+ ),
+ 0 =>
+ array (
+ ),
+ 1 =>
+ array (
+ ),
+ 2 =>
+ array (
+ 0 =>
+ array (
+ ),
+ 1 =>
+ array (
+ ),
+ 2 =>
+ array (
+ ),
+ 3 => -1,
+ ),
+ 3 =>
+ array (
+ 0 =>
+ array (
+ ),
+ ),
+ );
+ $this->_parts = array (
+ 0 =>
+ array (
+ ),
+ 1 =>
+ array (
+ ),
+ 2 =>
+ array (
+ 0 => NULL,
+ 1 => NULL,
+ 2 => NULL,
+ 3 => NULL,
+ ),
+ 3 =>
+ array (
+ 0 => NULL,
+ ),
+ );
+ $this->_subst = array (
+ -1 =>
+ array (
+ 0 => false,
+ 1 => false,
+ 2 => false,
+ 3 => false,
+ ),
+ 0 =>
+ array (
+ ),
+ 1 =>
+ array (
+ ),
+ 2 =>
+ array (
+ 0 => false,
+ 1 => false,
+ 2 => false,
+ 3 => false,
+ ),
+ 3 =>
+ array (
+ 0 => false,
+ ),
+ );
+ $this->_conditions = array (
+ );
+ $this->_kwmap = array (
+ );
+ $this->_defClass = 'code';
+ $this->_checkDefines();
+ }
+
} \ No newline at end of file
diff --git a/framework/3rdParty/TextHighlighter/Text/Highlighter/PYTHON.php b/framework/3rdParty/TextHighlighter/Text/Highlighter/PYTHON.php
index 8625ee8b..a1f381cb 100644
--- a/framework/3rdParty/TextHighlighter/Text/Highlighter/PYTHON.php
+++ b/framework/3rdParty/TextHighlighter/Text/Highlighter/PYTHON.php
@@ -1,49 +1,49 @@
-<?php
-/**
- * Auto-generated class. PYTHON syntax highlighting
- *
- * PHP version 4 and 5
- *
- * LICENSE: This source file is subject to version 3.0 of the PHP license
- * that is available through the world-wide-web at the following URI:
- * http://www.php.net/license/3_0.txt. If you did not receive a copy of
- * the PHP License and are unable to obtain it through the web, please
- * send a note to license@php.net so we can mail you a copy immediately.
- *
- * @copyright 2004-2006 Andrey Demenev
- * @license http://www.php.net/license/3_0.txt PHP License
- * @link http://pear.php.net/package/Text_Highlighter
- * @category Text
- * @package Text_Highlighter
+<?php
+/**
+ * Auto-generated class. PYTHON syntax highlighting
+ *
+ * PHP version 4 and 5
+ *
+ * LICENSE: This source file is subject to version 3.0 of the PHP license
+ * that is available through the world-wide-web at the following URI:
+ * http://www.php.net/license/3_0.txt. If you did not receive a copy of
+ * the PHP License and are unable to obtain it through the web, please
+ * send a note to license@php.net so we can mail you a copy immediately.
+ *
+ * @copyright 2004-2006 Andrey Demenev
+ * @license http://www.php.net/license/3_0.txt PHP License
+ * @link http://pear.php.net/package/Text_Highlighter
+ * @category Text
+ * @package Text_Highlighter
* @version generated from: : python.xml,v 1.1 2007/06/03 02:35:28 ssttoo Exp
* @author Andrey Demenev <demenev@gmail.com>
- *
- */
-
-/**
- * Auto-generated class. PYTHON syntax highlighting
- *
+ *
+ */
+
+/**
+ * Auto-generated class. PYTHON syntax highlighting
+ *
* @author Andrey Demenev <demenev@gmail.com>
- * @category Text
- * @package Text_Highlighter
- * @copyright 2004-2006 Andrey Demenev
- * @license http://www.php.net/license/3_0.txt PHP License
- * @version Release: 0.7.0
- * @link http://pear.php.net/package/Text_Highlighter
- */
-class Text_Highlighter_PYTHON extends Text_Highlighter
-{
+ * @category Text
+ * @package Text_Highlighter
+ * @copyright 2004-2006 Andrey Demenev
+ * @license http://www.php.net/license/3_0.txt PHP License
+ * @version Release: 0.7.0
+ * @link http://pear.php.net/package/Text_Highlighter
+ */
+class Text_Highlighter_PYTHON extends Text_Highlighter
+{
var $_language = 'python';
- /**
- * Constructor
- *
- * @param array $options
- * @access public
- */
- function __construct($options=array())
- {
-
+ /**
+ * Constructor
+ *
+ * @param array $options
+ * @access public
+ */
+ function __construct($options=array())
+ {
+
$this->_options = $options;
$this->_regs = array (
-1 => '/((?i)\'\'\')|((?i)""")|((?i)")|((?i)\')|((?i)\\()|((?i)\\[)|((?i)[a-z_]\\w*(?=\\s*\\())|((?i)[a-z_]\\w*)|((?i)((\\d+|((\\d*\\.\\d+)|(\\d+\\.\\d*)))[eE][+-]?\\d+))|((?i)((\\d*\\.\\d+)|(\\d+\\.\\d*)|(\\d+))j)|((?i)(\\d*\\.\\d+)|(\\d+\\.\\d*))|((?i)\\d+l?|\\b0l?\\b)|((?i)0[xX][\\da-f]+l?)|((?i)0[0-7]+l?)|((?i)#.+)/',
@@ -622,8 +622,8 @@ class Text_Highlighter_PYTHON extends Text_Highlighter
'builtin' => 'builtin',
'reserved' => 'reserved',
);
- $this->_defClass = 'code';
- $this->_checkDefines();
- }
-
+ $this->_defClass = 'code';
+ $this->_checkDefines();
+ }
+
} \ No newline at end of file
diff --git a/framework/3rdParty/TextHighlighter/Text/Highlighter/RUBY.php b/framework/3rdParty/TextHighlighter/Text/Highlighter/RUBY.php
index 80f21d03..3deaa376 100644
--- a/framework/3rdParty/TextHighlighter/Text/Highlighter/RUBY.php
+++ b/framework/3rdParty/TextHighlighter/Text/Highlighter/RUBY.php
@@ -1,5 +1,5 @@
-<?php
-/**
+<?php
+/**
* Auto-generated class. RUBY syntax highlighting
*
*
@@ -9,50 +9,50 @@
* start of RE), making highlighting improper
*
* %q(a (nested) string) does not get highlighted correctly
- *
- *
- * PHP version 4 and 5
- *
- * LICENSE: This source file is subject to version 3.0 of the PHP license
- * that is available through the world-wide-web at the following URI:
- * http://www.php.net/license/3_0.txt. If you did not receive a copy of
- * the PHP License and are unable to obtain it through the web, please
- * send a note to license@php.net so we can mail you a copy immediately.
- *
- * @copyright 2004-2006 Andrey Demenev
- * @license http://www.php.net/license/3_0.txt PHP License
- * @link http://pear.php.net/package/Text_Highlighter
- * @category Text
- * @package Text_Highlighter
+ *
+ *
+ * PHP version 4 and 5
+ *
+ * LICENSE: This source file is subject to version 3.0 of the PHP license
+ * that is available through the world-wide-web at the following URI:
+ * http://www.php.net/license/3_0.txt. If you did not receive a copy of
+ * the PHP License and are unable to obtain it through the web, please
+ * send a note to license@php.net so we can mail you a copy immediately.
+ *
+ * @copyright 2004-2006 Andrey Demenev
+ * @license http://www.php.net/license/3_0.txt PHP License
+ * @link http://pear.php.net/package/Text_Highlighter
+ * @category Text
+ * @package Text_Highlighter
* @version generated from: : ruby.xml,v 1.1 2007/06/03 02:35:28 ssttoo Exp
* @author Andrey Demenev <demenev@gmail.com>
- *
- */
-
-/**
- * Auto-generated class. RUBY syntax highlighting
- *
+ *
+ */
+
+/**
+ * Auto-generated class. RUBY syntax highlighting
+ *
* @author Andrey Demenev <demenev@gmail.com>
- * @category Text
- * @package Text_Highlighter
- * @copyright 2004-2006 Andrey Demenev
- * @license http://www.php.net/license/3_0.txt PHP License
- * @version Release: 0.7.0
- * @link http://pear.php.net/package/Text_Highlighter
- */
-class Text_Highlighter_RUBY extends Text_Highlighter
-{
+ * @category Text
+ * @package Text_Highlighter
+ * @copyright 2004-2006 Andrey Demenev
+ * @license http://www.php.net/license/3_0.txt PHP License
+ * @version Release: 0.7.0
+ * @link http://pear.php.net/package/Text_Highlighter
+ */
+class Text_Highlighter_RUBY extends Text_Highlighter
+{
var $_language = 'ruby';
- /**
- * Constructor
- *
- * @param array $options
- * @access public
- */
- function __construct($options=array())
- {
-
+ /**
+ * Constructor
+ *
+ * @param array $options
+ * @access public
+ */
+ function __construct($options=array())
+ {
+
$this->_options = $options;
$this->_regs = array (
-1 => '/((?mi)^__END__$)|((?i)")|((?i)%[Qx]([!"#\\$%&\'+\\-*.\\/:;=?@^`|~{<\\[(]))|((?i)\')|((?i)%[wq]([!"#\\$%&\'+\\-*.\\/:;=?@^`|~{<\\[(]))|((?i)\\$(\\W|\\w+))|((?ii)@@?[_a-z][\\d_a-z]*)|((?i)\\()|((?i)\\[)|((?i)[a-z_]\\w*)|((?i)((\\d+|((\\d*\\.\\d+)|(\\d+\\.\\d*)))[eE][+-]?\\d+))|((?i)(\\d*\\.\\d+)|(\\d+\\.\\d*))|((?i)0[xX][\\da-f]+l?)|((?i)\\d+l?|\\b0l?\\b)|((?i)0[0-7]+l?)|((?mi)^=begin$)|((?i)#)|((?i)\\s*\\/)/',
@@ -800,8 +800,8 @@ class Text_Highlighter_RUBY extends Text_Highlighter
$this->_kwmap = array (
'reserved' => 'reserved',
);
- $this->_defClass = 'code';
- $this->_checkDefines();
- }
-
+ $this->_defClass = 'code';
+ $this->_checkDefines();
+ }
+
} \ No newline at end of file
diff --git a/framework/3rdParty/TextHighlighter/Text/Highlighter/Renderer.php b/framework/3rdParty/TextHighlighter/Text/Highlighter/Renderer.php
index 87b89156..9fcafe2e 100644
--- a/framework/3rdParty/TextHighlighter/Text/Highlighter/Renderer.php
+++ b/framework/3rdParty/TextHighlighter/Text/Highlighter/Renderer.php
@@ -1,152 +1,152 @@
-<?php
-/* vim: set expandtab tabstop=4 shiftwidth=4 softtabstop=4: */
-/**
- * Abstract base class for Highlighter renderers
- *
- * PHP versions 4 and 5
- *
- * LICENSE: This source file is subject to version 3.0 of the PHP license
- * that is available through the world-wide-web at the following URI:
- * http://www.php.net/license/3_0.txt. If you did not receive a copy of
- * the PHP License and are unable to obtain it through the web, please
- * send a note to license@php.net so we can mail you a copy immediately.
- *
- * @category Text
- * @package Text_Highlighter
- * @author Andrey Demenev <demenev@gmail.com>
- * @copyright 2004-2006 Andrey Demenev
- * @license http://www.php.net/license/3_0.txt PHP License
- * @version CVS: $Id: Renderer.php,v 1.1 2007/06/03 02:36:35 ssttoo Exp $
- * @link http://pear.php.net/package/Text_Highlighter
- */
-
-/**
- * Abstract base class for Highlighter renderers
- *
- * @author Andrey Demenev <demenev@gmail.com>
- * @category Text
- * @package Text_Highlighter
- * @copyright 2004-2006 Andrey Demenev
- * @license http://www.php.net/license/3_0.txt PHP License
- * @version Release: 0.7.0
- * @link http://pear.php.net/package/Text_Highlighter
- * @abstract
- */
-
-class Text_Highlighter_Renderer
-{
- /**
- * Renderer options
- *
- * @var array
- * @access protected
- */
- public $_options = array();
-
- /**
- * Current language
- *
- * @var string
- * @access protected
- */
- public $_language = '';
-
- /**
- * Constructor
- *
- * @access public
- *
- * @param array $options Rendering options. Renderer-specific.
- */
- function __construct($options = array())
- {
- $this->_options = $options;
- }
-
- /**
- * Resets renderer state
- *
- * @access public
- *
- * @param array $options Rendering options. Renderer-specific.
- */
- function reset()
- {
- return;
- }
-
- /**
- * Preprocesses code
- *
- * @access public
- *
- * @param string $str Code to preprocess
- * @return string Preprocessed code
- */
- function preprocess($str)
- {
- return $str;
- }
-
- /**
- * Accepts next token
- *
- * @abstract
- * @access public
- *
- * @param string $class Token class
- * @param string $content Token content
- */
- function acceptToken($class, $content)
- {
- return;
- }
-
- /**
- * Signals that no more tokens are available
- *
- * @access public
- *
- */
- function finalize()
- {
- return;
- }
-
- /**
- * Get generated output
- *
- * @abstract
- * @return mixed Renderer-specific
- * @access public
- *
- */
- function getOutput()
- {
- return;
- }
-
- /**
- * Set current language
- *
- * @abstract
- * @return void
- * @access public
- *
- */
- function setCurrentLanguage($lang)
- {
- $this->_language = $lang;
- }
-
-}
-
-/*
- * Local variables:
- * tab-width: 4
- * c-basic-offset: 4
- * c-hanging-comment-ender-p: nil
- * End:
- */
-
+<?php
+/* vim: set expandtab tabstop=4 shiftwidth=4 softtabstop=4: */
+/**
+ * Abstract base class for Highlighter renderers
+ *
+ * PHP versions 4 and 5
+ *
+ * LICENSE: This source file is subject to version 3.0 of the PHP license
+ * that is available through the world-wide-web at the following URI:
+ * http://www.php.net/license/3_0.txt. If you did not receive a copy of
+ * the PHP License and are unable to obtain it through the web, please
+ * send a note to license@php.net so we can mail you a copy immediately.
+ *
+ * @category Text
+ * @package Text_Highlighter
+ * @author Andrey Demenev <demenev@gmail.com>
+ * @copyright 2004-2006 Andrey Demenev
+ * @license http://www.php.net/license/3_0.txt PHP License
+ * @version CVS: $Id: Renderer.php,v 1.1 2007/06/03 02:36:35 ssttoo Exp $
+ * @link http://pear.php.net/package/Text_Highlighter
+ */
+
+/**
+ * Abstract base class for Highlighter renderers
+ *
+ * @author Andrey Demenev <demenev@gmail.com>
+ * @category Text
+ * @package Text_Highlighter
+ * @copyright 2004-2006 Andrey Demenev
+ * @license http://www.php.net/license/3_0.txt PHP License
+ * @version Release: 0.7.0
+ * @link http://pear.php.net/package/Text_Highlighter
+ * @abstract
+ */
+
+class Text_Highlighter_Renderer
+{
+ /**
+ * Renderer options
+ *
+ * @var array
+ * @access protected
+ */
+ public $_options = array();
+
+ /**
+ * Current language
+ *
+ * @var string
+ * @access protected
+ */
+ public $_language = '';
+
+ /**
+ * Constructor
+ *
+ * @access public
+ *
+ * @param array $options Rendering options. Renderer-specific.
+ */
+ function __construct($options = array())
+ {
+ $this->_options = $options;
+ }
+
+ /**
+ * Resets renderer state
+ *
+ * @access public
+ *
+ * @param array $options Rendering options. Renderer-specific.
+ */
+ function reset()
+ {
+ return;
+ }
+
+ /**
+ * Preprocesses code
+ *
+ * @access public
+ *
+ * @param string $str Code to preprocess
+ * @return string Preprocessed code
+ */
+ function preprocess($str)
+ {
+ return $str;
+ }
+
+ /**
+ * Accepts next token
+ *
+ * @abstract
+ * @access public
+ *
+ * @param string $class Token class
+ * @param string $content Token content
+ */
+ function acceptToken($class, $content)
+ {
+ return;
+ }
+
+ /**
+ * Signals that no more tokens are available
+ *
+ * @access public
+ *
+ */
+ function finalize()
+ {
+ return;
+ }
+
+ /**
+ * Get generated output
+ *
+ * @abstract
+ * @return mixed Renderer-specific
+ * @access public
+ *
+ */
+ function getOutput()
+ {
+ return;
+ }
+
+ /**
+ * Set current language
+ *
+ * @abstract
+ * @return void
+ * @access public
+ *
+ */
+ function setCurrentLanguage($lang)
+ {
+ $this->_language = $lang;
+ }
+
+}
+
+/*
+ * Local variables:
+ * tab-width: 4
+ * c-basic-offset: 4
+ * c-hanging-comment-ender-p: nil
+ * End:
+ */
+
?> \ No newline at end of file
diff --git a/framework/3rdParty/TextHighlighter/Text/Highlighter/Renderer/Array.php b/framework/3rdParty/TextHighlighter/Text/Highlighter/Renderer/Array.php
index 5a0c9c09..ef3ffec1 100644
--- a/framework/3rdParty/TextHighlighter/Text/Highlighter/Renderer/Array.php
+++ b/framework/3rdParty/TextHighlighter/Text/Highlighter/Renderer/Array.php
@@ -1,199 +1,199 @@
-<?php
-/* vim: set expandtab tabstop=4 shiftwidth=4 softtabstop=4: */
-/**
- * Array renderer.
- *
- * Produces an array that contains class names and content pairs.
- * The array can be enumerated or associative. Associative means
- * <code>class =&gt; content</code> pairs.
- * Based on the HTML renderer by Andrey Demenev.
- *
- * LICENSE: This source file is subject to version 3.0 of the PHP license
- * that is available through the world-wide-web at the following URI:
- * http://www.php.net/license/3_0.txt. If you did not receive a copy of
- * the PHP License and are unable to obtain it through the web, please
- * send a note to license@php.net so we can mail you a copy immediately.
- *
- * @category Text
- * @package Text_Highlighter
- * @author Stoyan Stefanov <ssttoo@gmail.com>
- * @copyright 2006 Stoyan Stefanov
- * @license http://www.php.net/license/3_0.txt PHP License
- * @version CVS: $Id: Array.php,v 1.1 2007/06/03 02:37:08 ssttoo Exp $
- * @link http://pear.php.net/package/Text_Highlighter
- */
-
-/**
- * @ignore
- */
-
-require_once dirname(__FILE__).'/../Renderer.php';
-
-/**
- * Array renderer, based on Andrey Demenev's HTML renderer.
- *
- * In addition to the options supported by the HTML renderer,
- * the following options were also introduced:
- * <ul><li>htmlspecialchars - whether or not htmlspecialchars() will
- * be called on the content, default TRUE</li>
- * <li>enumerated - type of array produced, default FALSE,
- * meaning associative array</li>
- * </ul>
- *
- *
- * @author Stoyan Stefanov <ssttoo@gmail.com>
- * @category Text
- * @package Text_Highlighter
- * @copyright 2006 Stoyan Stefanov
- * @license http://www.php.net/license/3_0.txt PHP License
- * @version Release: 0.5.0
- * @link http://pear.php.net/package/Text_Highlighter
- */
-
-class Text_Highlighter_Renderer_Array extends Text_Highlighter_Renderer
-{
-
- /**#@+
- * @access private
- */
-
- /**
- * Tab size
- *
- * @var integer
- */
- var $_tabsize = 4;
-
- /**
- * Should htmlentities() will be called
- *
- * @var boolean
- */
- var $_htmlspecialchars = true;
-
- /**
- * Enumerated or associative array
- *
- * @var integer
- */
- var $_enumerated = false;
-
- /**
- * Array containing highlighting rules
- *
- * @var array
- */
- var $_output = array();
-
- /**#@-*/
-
- /**
- * Preprocesses code
- *
- * @access public
- *
- * @param string $str Code to preprocess
- * @return string Preprocessed code
- */
- function preprocess($str)
- {
- // normalize whitespace and tabs
- $str = str_replace("\r\n","\n", $str);
- // some browsers refuse to display empty lines
- $str = preg_replace('~^$~m'," ", $str);
- $str = str_replace("\t",str_repeat(' ', $this->_tabsize), $str);
- return rtrim($str);
- }
-
-
- /**
- * Resets renderer state
- *
- * Descendents of Text_Highlighter call this method from the constructor,
- * passing $options they get as parameter.
- *
- * @access protected
- */
- function reset()
- {
- $this->_output = array();
- $this->_lastClass = 'default';
- if (isset($this->_options['tabsize'])) {
- $this->_tabsize = $this->_options['tabsize'];
- }
- if (isset($this->_options['htmlspecialchars'])) {
- $this->_htmlspecialchars = $this->_options['htmlspecialchars'];
- }
- if (isset($this->_options['enumerated'])) {
- $this->_enumerated = $this->_options['enumerated'];
- }
- }
-
-
-
- /**
- * Accepts next token
- *
- * @abstract
- * @access public
- * @param string $class Token class
- * @param string $content Token content
- */
- function acceptToken($class, $content)
- {
-
-
- $theClass = $this->_getFullClassName($class);
- if ($this->_htmlspecialchars) {
- $content = htmlspecialchars($content);
- }
- if ($this->_enumerated) {
- $this->_output[] = array($class, $content);
- } else {
- $this->_output[][$class] = $content;
- }
- $this->_lastClass = $class;
-
- }
-
-
- /**
- * Given a CSS class name, returns the class name
- * with language name prepended, if necessary
- *
- * @access private
- *
- * @param string $class Token class
- */
- function _getFullClassName($class)
- {
- if (!empty($this->_options['use_language'])) {
- $theClass = $this->_language . '-' . $class;
- } else {
- $theClass = $class;
- }
- return $theClass;
- }
-
- /**
- * Get generated output
- *
- * @abstract
- * @return array Highlighted code as an array
- * @access public
- */
- function getOutput()
- {
- return $this->_output;
- }
-}
-
-/*
- * Local variables:
- * tab-width: 4
- * c-basic-offset: 4
- * c-hanging-comment-ender-p: nil
- * End:
- */
-
+<?php
+/* vim: set expandtab tabstop=4 shiftwidth=4 softtabstop=4: */
+/**
+ * Array renderer.
+ *
+ * Produces an array that contains class names and content pairs.
+ * The array can be enumerated or associative. Associative means
+ * <code>class =&gt; content</code> pairs.
+ * Based on the HTML renderer by Andrey Demenev.
+ *
+ * LICENSE: This source file is subject to version 3.0 of the PHP license
+ * that is available through the world-wide-web at the following URI:
+ * http://www.php.net/license/3_0.txt. If you did not receive a copy of
+ * the PHP License and are unable to obtain it through the web, please
+ * send a note to license@php.net so we can mail you a copy immediately.
+ *
+ * @category Text
+ * @package Text_Highlighter
+ * @author Stoyan Stefanov <ssttoo@gmail.com>
+ * @copyright 2006 Stoyan Stefanov
+ * @license http://www.php.net/license/3_0.txt PHP License
+ * @version CVS: $Id: Array.php,v 1.1 2007/06/03 02:37:08 ssttoo Exp $
+ * @link http://pear.php.net/package/Text_Highlighter
+ */
+
+/**
+ * @ignore
+ */
+
+require_once dirname(__FILE__).'/../Renderer.php';
+
+/**
+ * Array renderer, based on Andrey Demenev's HTML renderer.
+ *
+ * In addition to the options supported by the HTML renderer,
+ * the following options were also introduced:
+ * <ul><li>htmlspecialchars - whether or not htmlspecialchars() will
+ * be called on the content, default TRUE</li>
+ * <li>enumerated - type of array produced, default FALSE,
+ * meaning associative array</li>
+ * </ul>
+ *
+ *
+ * @author Stoyan Stefanov <ssttoo@gmail.com>
+ * @category Text
+ * @package Text_Highlighter
+ * @copyright 2006 Stoyan Stefanov
+ * @license http://www.php.net/license/3_0.txt PHP License
+ * @version Release: 0.5.0
+ * @link http://pear.php.net/package/Text_Highlighter
+ */
+
+class Text_Highlighter_Renderer_Array extends Text_Highlighter_Renderer
+{
+
+ /**#@+
+ * @access private
+ */
+
+ /**
+ * Tab size
+ *
+ * @var integer
+ */
+ var $_tabsize = 4;
+
+ /**
+ * Should htmlentities() will be called
+ *
+ * @var boolean
+ */
+ var $_htmlspecialchars = true;
+
+ /**
+ * Enumerated or associative array
+ *
+ * @var integer
+ */
+ var $_enumerated = false;
+
+ /**
+ * Array containing highlighting rules
+ *
+ * @var array
+ */
+ var $_output = array();
+
+ /**#@-*/
+
+ /**
+ * Preprocesses code
+ *
+ * @access public
+ *
+ * @param string $str Code to preprocess
+ * @return string Preprocessed code
+ */
+ function preprocess($str)
+ {
+ // normalize whitespace and tabs
+ $str = str_replace("\r\n","\n", $str);
+ // some browsers refuse to display empty lines
+ $str = preg_replace('~^$~m'," ", $str);
+ $str = str_replace("\t",str_repeat(' ', $this->_tabsize), $str);
+ return rtrim($str);
+ }
+
+
+ /**
+ * Resets renderer state
+ *
+ * Descendents of Text_Highlighter call this method from the constructor,
+ * passing $options they get as parameter.
+ *
+ * @access protected
+ */
+ function reset()
+ {
+ $this->_output = array();
+ $this->_lastClass = 'default';
+ if (isset($this->_options['tabsize'])) {
+ $this->_tabsize = $this->_options['tabsize'];
+ }
+ if (isset($this->_options['htmlspecialchars'])) {
+ $this->_htmlspecialchars = $this->_options['htmlspecialchars'];
+ }
+ if (isset($this->_options['enumerated'])) {
+ $this->_enumerated = $this->_options['enumerated'];
+ }
+ }
+
+
+
+ /**
+ * Accepts next token
+ *
+ * @abstract
+ * @access public
+ * @param string $class Token class
+ * @param string $content Token content
+ */
+ function acceptToken($class, $content)
+ {
+
+
+ $theClass = $this->_getFullClassName($class);
+ if ($this->_htmlspecialchars) {
+ $content = htmlspecialchars($content);
+ }
+ if ($this->_enumerated) {
+ $this->_output[] = array($class, $content);
+ } else {
+ $this->_output[][$class] = $content;
+ }
+ $this->_lastClass = $class;
+
+ }
+
+
+ /**
+ * Given a CSS class name, returns the class name
+ * with language name prepended, if necessary
+ *
+ * @access private
+ *
+ * @param string $class Token class
+ */
+ function _getFullClassName($class)
+ {
+ if (!empty($this->_options['use_language'])) {
+ $theClass = $this->_language . '-' . $class;
+ } else {
+ $theClass = $class;
+ }
+ return $theClass;
+ }
+
+ /**
+ * Get generated output
+ *
+ * @abstract
+ * @return array Highlighted code as an array
+ * @access public
+ */
+ function getOutput()
+ {
+ return $this->_output;
+ }
+}
+
+/*
+ * Local variables:
+ * tab-width: 4
+ * c-basic-offset: 4
+ * c-hanging-comment-ender-p: nil
+ * End:
+ */
+
?> \ No newline at end of file
diff --git a/framework/3rdParty/TextHighlighter/Text/Highlighter/Renderer/BB.php b/framework/3rdParty/TextHighlighter/Text/Highlighter/Renderer/BB.php
index 84bc67c0..3536260b 100644
--- a/framework/3rdParty/TextHighlighter/Text/Highlighter/Renderer/BB.php
+++ b/framework/3rdParty/TextHighlighter/Text/Highlighter/Renderer/BB.php
@@ -1,238 +1,238 @@
-<?php
-/* vim: set expandtab tabstop=4 shiftwidth=4 softtabstop=4: */
-/**
- * BB code renderer.
- *
- * This BB renderer produces BB code, ready to be pasted in bulletin boards and
- * other applications that accept BB code. Based on the HTML renderer by Andrey Demenev.
- *
- * LICENSE: This source file is subject to version 3.0 of the PHP license
- * that is available through the world-wide-web at the following URI:
- * http://www.php.net/license/3_0.txt. If you did not receive a copy of
- * the PHP License and are unable to obtain it through the web, please
- * send a note to license@php.net so we can mail you a copy immediately.
- *
- * @category Text
- * @package Text_Highlighter
- * @author Stoyan Stefanov <ssttoo@gmail.com>
- * @copyright 2005 Stoyan Stefanov
- * @license http://www.php.net/license/3_0.txt PHP License
- * @version CVS: $Id: BB.php,v 1.1 2007/06/03 02:37:08 ssttoo Exp $
- * @link http://pear.php.net/package/Text_Highlighter
- */
-
-/**
- * @ignore
- */
-
-require_once dirname(__FILE__).'/../Renderer.php';
-
-/**
- * BB code renderer, based on Andrey Demenev's HTML renderer.
- *
- * Elements of $options argument of constructor (each being optional):
- *
- * - 'numbers' - Line numbering TRUE or FALSE
- * - 'tabsize' - Tab size, default is 4
- * - 'bb_tags' - An array containing three BB tags, see below
- * - 'tag_brackets' - An array that conains opening and closing tags, [ and ]
- * - 'colors' - An array with all the colors to be used for highlighting
- *
- * The default BB tags are:
- * - 'color' => 'color'
- * - 'list' => 'list'
- * - 'list_item' => '*'
- *
- * The default colors for the highlighter are:
- * - 'default' => 'Black',
- * - 'code' => 'Gray',
- * - 'brackets' => 'Olive',
- * - 'comment' => 'Orange',
- * - 'mlcomment' => 'Orange',
- * - 'quotes' => 'Darkred',
- * - 'string' => 'Red',
- * - 'identifier' => 'Blue',
- * - 'builtin' => 'Teal',
- * - 'reserved' => 'Green',
- * - 'inlinedoc' => 'Blue',
- * - 'var' => 'Darkblue',
- * - 'url' => 'Blue',
- * - 'special' => 'Navy',
- * - 'number' => 'Maroon',
- * - 'inlinetags' => 'Blue',
- *
- *
- * @author Stoyan Stefanov <ssttoo@gmail.com>
- * @category Text
- * @package Text_Highlighter
- * @copyright 20045 Stoyan Stefanov
- * @license http://www.php.net/license/3_0.txt PHP License
- * @version Release: 0.5.0
- * @link http://pear.php.net/package/Text_Highlighter
- */
-
-class Text_Highlighter_Renderer_BB extends Text_Highlighter_Renderer_Array
-{
-
- /**#@+
- * @access private
- */
-
- /**
- * Line numbering - will use the specified BB tag for listings
- *
- * @var boolean
- */
- var $_numbers = false;
-
- /**
- * BB tags to be used
- *
- * @var array
- */
- var $_bb_tags = array (
- 'color' => 'color',
- 'list' => 'list',
- 'list_item' => '*',
- 'code' => 'code',
- );
-
- /**
- * BB brackets - [ and ]
- *
- * @var array
- */
- var $_tag_brackets = array ('start' => '[', 'end' => ']');
-
- /**
- * Colors map
- *
- * @var boolean
- */
- var $_colors = array(
- 'default' => 'Black',
- 'code' => 'Gray',
- 'brackets' => 'Olive',
- 'comment' => 'Orange',
- 'mlcomment' => 'Orange',
- 'quotes' => 'Darkred',
- 'string' => 'Red',
- 'identifier' => 'Blue',
- 'builtin' => 'Teal',
- 'reserved' => 'Green',
- 'inlinedoc' => 'Blue',
- 'var' => 'Darkblue',
- 'url' => 'Blue',
- 'special' => 'Navy',
- 'number' => 'Maroon',
- 'inlinetags' => 'Blue',
- );
-
- /**#@-*/
-
- /**
- * Resets renderer state
- *
- * @access protected
- *
- *
- * Descendents of Text_Highlighter call this method from the constructor,
- * passing $options they get as parameter.
- */
- function reset()
- {
- parent::reset();
- if (isset($this->_options['numbers'])) {
- $this->_numbers = $this->_options['numbers'];
- }
- if (isset($this->_options['bb_tags'])) {
- $this->_bb_tags = array_merge($this->_bb_tags, $this->_options['bb_tags']);
- }
- if (isset($this->_options['tag_brackets'])) {
- $this->_tag_brackets = array_merge($this->_tag_brackets, $this->_options['tag_brackets']);
- }
- if (isset($this->_options['colors'])) {
- $this->_colors = array_merge($this->_colors, $this->_options['colors']);
- }
- }
-
-
- /**
- * Signals that no more tokens are available
- *
- * @abstract
- * @access public
- *
- */
- function finalize()
- {
-
- // get parent's output
- parent::finalize();
- $output = parent::getOutput();
-
- $bb_output = '';
-
- $color_start = $this->_tag_brackets['start'] . $this->_bb_tags['color'] . '=%s' . $this->_tag_brackets['end'];
- $color_end = $this->_tag_brackets['start'] . '/' . $this->_bb_tags['color'] . $this->_tag_brackets['end'];
-
- // loop through each class=>content pair
- foreach ($output AS $token) {
-
- if ($this->_enumerated) {
- $class = $token[0];
- $content = $token[1];
- } else {
- $key = key($token);
- $class = $key;
- $content = $token[$key];
- }
-
- $iswhitespace = ctype_space($content);
- if (!$iswhitespace && !empty($this->_colors[$class])) {
- $bb_output .= sprintf($color_start, $this->_colors[$class]);
- $bb_output .= $content;
- $bb_output .= $color_end;
- } else {
- $bb_output .= $content;
- }
- }
-
- if ($this->_numbers) {
-
- $item_tag = $this->_tag_brackets['start'] .
- $this->_bb_tags['list_item'] .
- $this->_tag_brackets['end'];
- $this->_output = $item_tag . str_replace("\n", "\n". $item_tag .' ', $bb_output);
- $this->_output = $this->_tag_brackets['start'] .
- $this->_bb_tags['list'] .
- $this->_tag_brackets['end'] .
- $this->_output .
- $this->_tag_brackets['start'] .
- '/'.
- $this->_bb_tags['list'] .
- $this->_tag_brackets['end']
- ;
- } else {
- $this->_output = $this->_tag_brackets['start'] .
- $this->_bb_tags['code'] .
- $this->_tag_brackets['end'] .
- $bb_output .
- $this->_tag_brackets['start'] .
- '/' .
- $this->_bb_tags['code'] .
- $this->_tag_brackets['end'];
- }
- }
-
-}
-
-/*
- * Local variables:
- * tab-width: 4
- * c-basic-offset: 4
- * c-hanging-comment-ender-p: nil
- * End:
- */
-
+<?php
+/* vim: set expandtab tabstop=4 shiftwidth=4 softtabstop=4: */
+/**
+ * BB code renderer.
+ *
+ * This BB renderer produces BB code, ready to be pasted in bulletin boards and
+ * other applications that accept BB code. Based on the HTML renderer by Andrey Demenev.
+ *
+ * LICENSE: This source file is subject to version 3.0 of the PHP license
+ * that is available through the world-wide-web at the following URI:
+ * http://www.php.net/license/3_0.txt. If you did not receive a copy of
+ * the PHP License and are unable to obtain it through the web, please
+ * send a note to license@php.net so we can mail you a copy immediately.
+ *
+ * @category Text
+ * @package Text_Highlighter
+ * @author Stoyan Stefanov <ssttoo@gmail.com>
+ * @copyright 2005 Stoyan Stefanov
+ * @license http://www.php.net/license/3_0.txt PHP License
+ * @version CVS: $Id: BB.php,v 1.1 2007/06/03 02:37:08 ssttoo Exp $
+ * @link http://pear.php.net/package/Text_Highlighter
+ */
+
+/**
+ * @ignore
+ */
+
+require_once dirname(__FILE__).'/../Renderer.php';
+
+/**
+ * BB code renderer, based on Andrey Demenev's HTML renderer.
+ *
+ * Elements of $options argument of constructor (each being optional):
+ *
+ * - 'numbers' - Line numbering TRUE or FALSE
+ * - 'tabsize' - Tab size, default is 4
+ * - 'bb_tags' - An array containing three BB tags, see below
+ * - 'tag_brackets' - An array that conains opening and closing tags, [ and ]
+ * - 'colors' - An array with all the colors to be used for highlighting
+ *
+ * The default BB tags are:
+ * - 'color' => 'color'
+ * - 'list' => 'list'
+ * - 'list_item' => '*'
+ *
+ * The default colors for the highlighter are:
+ * - 'default' => 'Black',
+ * - 'code' => 'Gray',
+ * - 'brackets' => 'Olive',
+ * - 'comment' => 'Orange',
+ * - 'mlcomment' => 'Orange',
+ * - 'quotes' => 'Darkred',
+ * - 'string' => 'Red',
+ * - 'identifier' => 'Blue',
+ * - 'builtin' => 'Teal',
+ * - 'reserved' => 'Green',
+ * - 'inlinedoc' => 'Blue',
+ * - 'var' => 'Darkblue',
+ * - 'url' => 'Blue',
+ * - 'special' => 'Navy',
+ * - 'number' => 'Maroon',
+ * - 'inlinetags' => 'Blue',
+ *
+ *
+ * @author Stoyan Stefanov <ssttoo@gmail.com>
+ * @category Text
+ * @package Text_Highlighter
+ * @copyright 20045 Stoyan Stefanov
+ * @license http://www.php.net/license/3_0.txt PHP License
+ * @version Release: 0.5.0
+ * @link http://pear.php.net/package/Text_Highlighter
+ */
+
+class Text_Highlighter_Renderer_BB extends Text_Highlighter_Renderer_Array
+{
+
+ /**#@+
+ * @access private
+ */
+
+ /**
+ * Line numbering - will use the specified BB tag for listings
+ *
+ * @var boolean
+ */
+ var $_numbers = false;
+
+ /**
+ * BB tags to be used
+ *
+ * @var array
+ */
+ var $_bb_tags = array (
+ 'color' => 'color',
+ 'list' => 'list',
+ 'list_item' => '*',
+ 'code' => 'code',
+ );
+
+ /**
+ * BB brackets - [ and ]
+ *
+ * @var array
+ */
+ var $_tag_brackets = array ('start' => '[', 'end' => ']');
+
+ /**
+ * Colors map
+ *
+ * @var boolean
+ */
+ var $_colors = array(
+ 'default' => 'Black',
+ 'code' => 'Gray',
+ 'brackets' => 'Olive',
+ 'comment' => 'Orange',
+ 'mlcomment' => 'Orange',
+ 'quotes' => 'Darkred',
+ 'string' => 'Red',
+ 'identifier' => 'Blue',
+ 'builtin' => 'Teal',
+ 'reserved' => 'Green',
+ 'inlinedoc' => 'Blue',
+ 'var' => 'Darkblue',
+ 'url' => 'Blue',
+ 'special' => 'Navy',
+ 'number' => 'Maroon',
+ 'inlinetags' => 'Blue',
+ );
+
+ /**#@-*/
+
+ /**
+ * Resets renderer state
+ *
+ * @access protected
+ *
+ *
+ * Descendents of Text_Highlighter call this method from the constructor,
+ * passing $options they get as parameter.
+ */
+ function reset()
+ {
+ parent::reset();
+ if (isset($this->_options['numbers'])) {
+ $this->_numbers = $this->_options['numbers'];
+ }
+ if (isset($this->_options['bb_tags'])) {
+ $this->_bb_tags = array_merge($this->_bb_tags, $this->_options['bb_tags']);
+ }
+ if (isset($this->_options['tag_brackets'])) {
+ $this->_tag_brackets = array_merge($this->_tag_brackets, $this->_options['tag_brackets']);
+ }
+ if (isset($this->_options['colors'])) {
+ $this->_colors = array_merge($this->_colors, $this->_options['colors']);
+ }
+ }
+
+
+ /**
+ * Signals that no more tokens are available
+ *
+ * @abstract
+ * @access public
+ *
+ */
+ function finalize()
+ {
+
+ // get parent's output
+ parent::finalize();
+ $output = parent::getOutput();
+
+ $bb_output = '';
+
+ $color_start = $this->_tag_brackets['start'] . $this->_bb_tags['color'] . '=%s' . $this->_tag_brackets['end'];
+ $color_end = $this->_tag_brackets['start'] . '/' . $this->_bb_tags['color'] . $this->_tag_brackets['end'];
+
+ // loop through each class=>content pair
+ foreach ($output AS $token) {
+
+ if ($this->_enumerated) {
+ $class = $token[0];
+ $content = $token[1];
+ } else {
+ $key = key($token);
+ $class = $key;
+ $content = $token[$key];
+ }
+
+ $iswhitespace = ctype_space($content);
+ if (!$iswhitespace && !empty($this->_colors[$class])) {
+ $bb_output .= sprintf($color_start, $this->_colors[$class]);
+ $bb_output .= $content;
+ $bb_output .= $color_end;
+ } else {
+ $bb_output .= $content;
+ }
+ }
+
+ if ($this->_numbers) {
+
+ $item_tag = $this->_tag_brackets['start'] .
+ $this->_bb_tags['list_item'] .
+ $this->_tag_brackets['end'];
+ $this->_output = $item_tag . str_replace("\n", "\n". $item_tag .' ', $bb_output);
+ $this->_output = $this->_tag_brackets['start'] .
+ $this->_bb_tags['list'] .
+ $this->_tag_brackets['end'] .
+ $this->_output .
+ $this->_tag_brackets['start'] .
+ '/'.
+ $this->_bb_tags['list'] .
+ $this->_tag_brackets['end']
+ ;
+ } else {
+ $this->_output = $this->_tag_brackets['start'] .
+ $this->_bb_tags['code'] .
+ $this->_tag_brackets['end'] .
+ $bb_output .
+ $this->_tag_brackets['start'] .
+ '/' .
+ $this->_bb_tags['code'] .
+ $this->_tag_brackets['end'];
+ }
+ }
+
+}
+
+/*
+ * Local variables:
+ * tab-width: 4
+ * c-basic-offset: 4
+ * c-hanging-comment-ender-p: nil
+ * End:
+ */
+
?> \ No newline at end of file
diff --git a/framework/3rdParty/TextHighlighter/Text/Highlighter/Renderer/Console.php b/framework/3rdParty/TextHighlighter/Text/Highlighter/Renderer/Console.php
index 30e4ed69..224cf71d 100644
--- a/framework/3rdParty/TextHighlighter/Text/Highlighter/Renderer/Console.php
+++ b/framework/3rdParty/TextHighlighter/Text/Highlighter/Renderer/Console.php
@@ -1,208 +1,208 @@
-<?php
-/* vim: set expandtab tabstop=4 shiftwidth=4 softtabstop=4: */
-/**
- * Console renderer
- *
- * PHP versions 4 and 5
- *
- * LICENSE: This source file is subject to version 3.0 of the PHP license
- * that is available through the world-wide-web at the following URI:
- * http://www.php.net/license/3_0.txt. If you did not receive a copy of
- * the PHP License and are unable to obtain it through the web, please
- * send a note to license@php.net so we can mail you a copy immediately.
- *
- * @category Text
- * @package Text_Highlighter
- * @author Andrey Demenev <demenev@gmail.com>
- * @copyright 2004-2006 Andrey Demenev
- * @license http://www.php.net/license/3_0.txt PHP License
- * @version CVS: $Id: Console.php,v 1.1 2007/06/03 02:37:08 ssttoo Exp $
- * @link http://pear.php.net/package/Text_Highlighter
- */
-
-/**
- * @ignore
- */
-
-require_once dirname(__FILE__).'/../Renderer.php';
-
-define ('HL_CONSOLE_DEFCOLOR', "\033[0m");
-
-/**
- * Console renderer
- *
- * Suitable for displaying text on color-capable terminals, directly
- * or trough less -r
- *
- * Elements of $options argument of constructor (each being optional):
- *
- * - 'numbers' - whether to add line numbers
- * - 'tabsize' - Tab size
- * - 'colors' - additional colors
- *
- * @author Andrey Demenev <demenev@gmail.com>
- * @category Text
- * @package Text_Highlighter
- * @copyright 2004-2006 Andrey Demenev
- * @license http://www.php.net/license/3_0.txt PHP License
- * @version Release: 0.7.0
- * @link http://pear.php.net/package/Text_Highlighter
- */
-
-class Text_Highlighter_Renderer_Console extends Text_Highlighter_Renderer
-{
-
- /**#@+
- * @access private
- */
-
- /**
- * class of last outputted text chunk
- *
- * @var string
- */
- var $_lastClass;
-
- /**
- * Line numbering
- *
- * @var boolean
- */
- var $_numbers = false;
-
- /**
- * Tab size
- *
- * @var integer
- */
- var $_tabsize = 4;
-
- /**
- * Highlighted code
- *
- * @var string
- */
- var $_output = '';
-
- /**#@-*/
-
- var $_colors = array();
-
- var $_defColors = array(
- 'default' => "\033[0m",
- 'inlinetags' => "\033[31m",
- 'brackets' => "\033[36m",
- 'quotes' => "\033[34m",
- 'inlinedoc' => "\033[34m",
- 'var' => "\033[1m",
- 'types' => "\033[32m",
- 'number' => "\033[32m",
- 'string' => "\033[31m",
- 'reserved' => "\033[35m",
- 'comment' => "\033[33m",
- 'mlcomment' => "\033[33m",
- );
-
- function preprocess($str)
- {
- // normalize whitespace and tabs
- $str = str_replace("\r\n","\n", $str);
- $str = str_replace("\t",str_repeat(' ', $this->_tabsize), $str);
- return rtrim($str);
- }
-
-
- /**
- * Resets renderer state
- *
- * @access protected
- *
- *
- * Descendents of Text_Highlighter call this method from the constructor,
- * passing $options they get as parameter.
- */
- function reset()
- {
- $this->_lastClass = '';
- if (isset($this->_options['numbers'])) {
- $this->_numbers = (bool)$this->_options['numbers'];
- } else {
- $this->_numbers = false;
- }
- if (isset($this->_options['tabsize'])) {
- $this->_tabsize = $this->_options['tabsize'];
- } else {
- $this->_tabsize = 4;
- }
- if (isset($this->_options['colors'])) {
- $this->_colors = array_merge($this->_defColors, $this->_options['colors']);
- } else {
- $this->_colors = $this->_defColors;
- }
- $this->_output = '';
- }
-
-
-
- /**
- * Accepts next token
- *
- * @access public
- *
- * @param string $class Token class
- * @param string $content Token content
- */
- function acceptToken($class, $content)
- {
- if (isset($this->_colors[$class])) {
- $color = $this->_colors[$class];
- } else {
- $color = $this->_colors['default'];
- }
- if ($this->_lastClass != $class) {
- $this->_output .= $color;
- }
- $content = str_replace("\n", $this->_colors['default'] . "\n" . $color, $content);
- $content .= $this->_colors['default'];
- $this->_output .= $content;
- }
-
- /**
- * Signals that no more tokens are available
- *
- * @access public
- *
- */
- function finalize()
- {
- if ($this->_numbers) {
- $nlines = substr_count($this->_output, "\n") + 1;
- $len = strlen($nlines);
- $i = 1;
- $this->_output = preg_replace('~^~em', '" " . str_pad($i++, $len, " ", STR_PAD_LEFT) . ": "', $this->_output);
- }
- $this->_output .= HL_CONSOLE_DEFCOLOR . "\n";
- }
-
- /**
- * Get generated output
- *
- * @return string Highlighted code
- * @access public
- *
- */
- function getOutput()
- {
- return $this->_output;
- }
-}
-
-/*
- * Local variables:
- * tab-width: 4
- * c-basic-offset: 4
- * c-hanging-comment-ender-p: nil
- * End:
- */
-
+<?php
+/* vim: set expandtab tabstop=4 shiftwidth=4 softtabstop=4: */
+/**
+ * Console renderer
+ *
+ * PHP versions 4 and 5
+ *
+ * LICENSE: This source file is subject to version 3.0 of the PHP license
+ * that is available through the world-wide-web at the following URI:
+ * http://www.php.net/license/3_0.txt. If you did not receive a copy of
+ * the PHP License and are unable to obtain it through the web, please
+ * send a note to license@php.net so we can mail you a copy immediately.
+ *
+ * @category Text
+ * @package Text_Highlighter
+ * @author Andrey Demenev <demenev@gmail.com>
+ * @copyright 2004-2006 Andrey Demenev
+ * @license http://www.php.net/license/3_0.txt PHP License
+ * @version CVS: $Id: Console.php,v 1.1 2007/06/03 02:37:08 ssttoo Exp $
+ * @link http://pear.php.net/package/Text_Highlighter
+ */
+
+/**
+ * @ignore
+ */
+
+require_once dirname(__FILE__).'/../Renderer.php';
+
+define ('HL_CONSOLE_DEFCOLOR', "\033[0m");
+
+/**
+ * Console renderer
+ *
+ * Suitable for displaying text on color-capable terminals, directly
+ * or trough less -r
+ *
+ * Elements of $options argument of constructor (each being optional):
+ *
+ * - 'numbers' - whether to add line numbers
+ * - 'tabsize' - Tab size
+ * - 'colors' - additional colors
+ *
+ * @author Andrey Demenev <demenev@gmail.com>
+ * @category Text
+ * @package Text_Highlighter
+ * @copyright 2004-2006 Andrey Demenev
+ * @license http://www.php.net/license/3_0.txt PHP License
+ * @version Release: 0.7.0
+ * @link http://pear.php.net/package/Text_Highlighter
+ */
+
+class Text_Highlighter_Renderer_Console extends Text_Highlighter_Renderer
+{
+
+ /**#@+
+ * @access private
+ */
+
+ /**
+ * class of last outputted text chunk
+ *
+ * @var string
+ */
+ var $_lastClass;
+
+ /**
+ * Line numbering
+ *
+ * @var boolean
+ */
+ var $_numbers = false;
+
+ /**
+ * Tab size
+ *
+ * @var integer
+ */
+ var $_tabsize = 4;
+
+ /**
+ * Highlighted code
+ *
+ * @var string
+ */
+ var $_output = '';
+
+ /**#@-*/
+
+ var $_colors = array();
+
+ var $_defColors = array(
+ 'default' => "\033[0m",
+ 'inlinetags' => "\033[31m",
+ 'brackets' => "\033[36m",
+ 'quotes' => "\033[34m",
+ 'inlinedoc' => "\033[34m",
+ 'var' => "\033[1m",
+ 'types' => "\033[32m",
+ 'number' => "\033[32m",
+ 'string' => "\033[31m",
+ 'reserved' => "\033[35m",
+ 'comment' => "\033[33m",
+ 'mlcomment' => "\033[33m",
+ );
+
+ function preprocess($str)
+ {
+ // normalize whitespace and tabs
+ $str = str_replace("\r\n","\n", $str);
+ $str = str_replace("\t",str_repeat(' ', $this->_tabsize), $str);
+ return rtrim($str);
+ }
+
+
+ /**
+ * Resets renderer state
+ *
+ * @access protected
+ *
+ *
+ * Descendents of Text_Highlighter call this method from the constructor,
+ * passing $options they get as parameter.
+ */
+ function reset()
+ {
+ $this->_lastClass = '';
+ if (isset($this->_options['numbers'])) {
+ $this->_numbers = (bool)$this->_options['numbers'];
+ } else {
+ $this->_numbers = false;
+ }
+ if (isset($this->_options['tabsize'])) {
+ $this->_tabsize = $this->_options['tabsize'];
+ } else {
+ $this->_tabsize = 4;
+ }
+ if (isset($this->_options['colors'])) {
+ $this->_colors = array_merge($this->_defColors, $this->_options['colors']);
+ } else {
+ $this->_colors = $this->_defColors;
+ }
+ $this->_output = '';
+ }
+
+
+
+ /**
+ * Accepts next token
+ *
+ * @access public
+ *
+ * @param string $class Token class
+ * @param string $content Token content
+ */
+ function acceptToken($class, $content)
+ {
+ if (isset($this->_colors[$class])) {
+ $color = $this->_colors[$class];
+ } else {
+ $color = $this->_colors['default'];
+ }
+ if ($this->_lastClass != $class) {
+ $this->_output .= $color;
+ }
+ $content = str_replace("\n", $this->_colors['default'] . "\n" . $color, $content);
+ $content .= $this->_colors['default'];
+ $this->_output .= $content;
+ }
+
+ /**
+ * Signals that no more tokens are available
+ *
+ * @access public
+ *
+ */
+ function finalize()
+ {
+ if ($this->_numbers) {
+ $nlines = substr_count($this->_output, "\n") + 1;
+ $len = strlen($nlines);
+ $i = 1;
+ $this->_output = preg_replace('~^~em', '" " . str_pad($i++, $len, " ", STR_PAD_LEFT) . ": "', $this->_output);
+ }
+ $this->_output .= HL_CONSOLE_DEFCOLOR . "\n";
+ }
+
+ /**
+ * Get generated output
+ *
+ * @return string Highlighted code
+ * @access public
+ *
+ */
+ function getOutput()
+ {
+ return $this->_output;
+ }
+}
+
+/*
+ * Local variables:
+ * tab-width: 4
+ * c-basic-offset: 4
+ * c-hanging-comment-ender-p: nil
+ * End:
+ */
+
?> \ No newline at end of file
diff --git a/framework/3rdParty/TextHighlighter/Text/Highlighter/Renderer/Html.php b/framework/3rdParty/TextHighlighter/Text/Highlighter/Renderer/Html.php
index 40cb3f59..a0bcfec2 100644
--- a/framework/3rdParty/TextHighlighter/Text/Highlighter/Renderer/Html.php
+++ b/framework/3rdParty/TextHighlighter/Text/Highlighter/Renderer/Html.php
@@ -1,446 +1,446 @@
-<?php
-/* vim: set expandtab tabstop=4 shiftwidth=4 softtabstop=4: */
-/**
- * HTML renderer
- *
- * PHP versions 4 and 5
- *
- * LICENSE: This source file is subject to version 3.0 of the PHP license
- * that is available through the world-wide-web at the following URI:
- * http://www.php.net/license/3_0.txt. If you did not receive a copy of
- * the PHP License and are unable to obtain it through the web, please
- * send a note to license@php.net so we can mail you a copy immediately.
- *
- * @category Text
- * @package Text_Highlighter
- * @author Andrey Demenev <demenev@gmail.com>
- * @copyright 2004-2006 Andrey Demenev
- * @license http://www.php.net/license/3_0.txt PHP License
- * @version CVS: $Id: Html.php,v 1.1 2007/06/03 02:37:09 ssttoo Exp $
- * @link http://pear.php.net/package/Text_Highlighter
- */
-
-/**
- * @ignore
- */
-
-require_once dirname(__FILE__).'/../Renderer.php';
-require_once dirname(__FILE__).'/../Renderer/Array.php';
-
-// BC trick : only define constants if Text/Highlighter.php
-// is not yet included
-if (!defined('HL_NUMBERS_LI')) {
- /**#@+
- * Constant for use with $options['numbers']
- */
- /**
- * use numbered list, deprecated, use HL_NUMBERS_OL instaed
- * @deprecated
- */
- define ('HL_NUMBERS_LI' , 1);
- /**
- * Use 2-column table with line numbers in left column and code in right column.
- */
- define ('HL_NUMBERS_TABLE' , 2);
- /**#@-*/
-}
-
-
-/**#@+
- * Constant for use with $options['numbers']
- */
-/**
- * Use numbered list
- */
-define ('HL_NUMBERS_OL', 1);
-/**
- * Use non-numbered list
- */
-define ('HL_NUMBERS_UL', 3);
-/**#@-*/
-
-
-/**
- * HTML renderer
- *
- * Elements of $options argument of constructor (each being optional):
- *
- * - 'numbers' - Line numbering style 0 or {@link HL_NUMBERS_TABLE}
- * or {@link HL_NUMBERS_UL} or {@link HL_NUMBERS_OL}
- * - 'numbers_start' - starting number for numbered lines
- * - 'tabsize' - Tab size
- * - 'style_map' - Mapping of keywords to formatting rules using inline styles
- * - 'class_map' - Mapping of keywords to formatting rules using class names
- * - 'doclinks' - array that has keys "url", "target" and "elements", used for
- * generating links to online documentation
- * - 'use_language' - class names will be prefixed with language, like "php-reserved" or "css-code"
- *
- * Example of setting documentation links:
- * $options['doclinks'] = array(
- * 'url' => 'http://php.net/%s',
- * 'target' => '_blank',
- * 'elements' => array('reserved', 'identifier')
- * );
- *
- * Example of setting class names map:
- * $options['class_map'] = array(
- * 'main' => 'my-main',
- * 'table' => 'my-table',
- * 'gutter' => 'my-gutter',
- * 'brackets' => 'my-brackets',
- * 'builtin' => 'my-builtin',
- * 'code' => 'my-code',
- * 'comment' => 'my-comment',
- * 'default' => 'my-default',
- * 'identifier' => 'my-identifier',
- * 'inlinedoc' => 'my-inlinedoc',
- * 'inlinetags' => 'my-inlinetags',
- * 'mlcomment' => 'my-mlcomment',
- * 'number' => 'my-number',
- * 'quotes' => 'my-quotes',
- * 'reserved' => 'my-reserved',
- * 'special' => 'my-special',
- * 'string' => 'my-string',
- * 'url' => 'my-url',
- * 'var' => 'my-var',
- * );
- *
- * Example of setting styles mapping:
- * $options['style_map'] = array(
- * 'main' => 'color: black',
- * 'table' => 'border: 1px solid black',
- * 'gutter' => 'background-color: yellow',
- * 'brackets' => 'color: blue',
- * 'builtin' => 'color: red',
- * 'code' => 'color: green',
- * 'comment' => 'color: orange',
- * // ....
- * );
- *
- *
- * @author Andrey Demenev <demenev@gmail.com>
- * @category Text
- * @package Text_Highlighter
- * @copyright 2004-2006 Andrey Demenev
- * @license http://www.php.net/license/3_0.txt PHP License
- * @version Release: 0.7.0
- * @link http://pear.php.net/package/Text_Highlighter
- */
-
-class Text_Highlighter_Renderer_Html extends Text_Highlighter_Renderer_Array
-{
-
- /**#@+
- * @access private
- */
-
- /**
- * Line numbering style
- *
- * @var integer
- */
- var $_numbers = 0;
-
- /**
- * For numberered lines - where to start
- *
- * @var integer
- */
- var $_numbers_start = 0;
-
- /**
- * Tab size
- *
- * @var integer
- */
- var $_tabsize = 4;
-
- /**
- * Highlighted code
- *
- * @var string
- */
- var $_output = '';
-
- /**
- * Mapping of keywords to formatting rules using inline styles
- *
- * @var array
- */
- var $_style_map = array();
-
- /**
- * Mapping of keywords to formatting rules using class names
- *
- * @var array
- */
- var $_class_map = array(
- 'main' => 'hl-main',
- 'table' => 'hl-table',
- 'gutter' => 'hl-gutter',
- 'brackets' => 'hl-brackets',
- 'builtin' => 'hl-builtin',
- 'code' => 'hl-code',
- 'comment' => 'hl-comment',
- 'default' => 'hl-default',
- 'identifier' => 'hl-identifier',
- 'inlinedoc' => 'hl-inlinedoc',
- 'inlinetags' => 'hl-inlinetags',
- 'mlcomment' => 'hl-mlcomment',
- 'number' => 'hl-number',
- 'quotes' => 'hl-quotes',
- 'reserved' => 'hl-reserved',
- 'special' => 'hl-special',
- 'string' => 'hl-string',
- 'url' => 'hl-url',
- 'var' => 'hl-var',
- );
-
- /**
- * Setup for links to online documentation
- *
- * This is an array with keys:
- * - url, ex. http://php.net/%s
- * - target, ex. _blank, default - no target
- * - elements, default is <code>array('reserved', 'identifier')</code>
- *
- * @var array
- */
- var $_doclinks = array();
-
- /**#@-*/
-
- /**
- * Resets renderer state
- *
- * @access protected
- *
- *
- * Descendents of Text_Highlighter call this method from the constructor,
- * passing $options they get as parameter.
- */
- function reset()
- {
- $this->_output = '';
- if (isset($this->_options['numbers'])) {
- $this->_numbers = (int)$this->_options['numbers'];
- if ($this->_numbers != HL_NUMBERS_LI
- && $this->_numbers != HL_NUMBERS_UL
- && $this->_numbers != HL_NUMBERS_OL
- && $this->_numbers != HL_NUMBERS_TABLE
- ) {
- $this->_numbers = 0;
- }
- }
- if (isset($this->_options['tabsize'])) {
- $this->_tabsize = $this->_options['tabsize'];
- }
- if (isset($this->_options['numbers_start'])) {
- $this->_numbers_start = intval($this->_options['numbers_start']);
- }
- if (isset($this->_options['doclinks']) &&
- is_array($this->_options['doclinks']) &&
- !empty($this->_options['doclinks']['url'])
- ) {
-
- $this->_doclinks = $this->_options['doclinks']; // keys: url, target, elements array
-
- if (empty($this->_options['doclinks']['elements'])) {
- $this->_doclinks['elements'] = array('reserved', 'identifier');
- }
- }
- if (isset($this->_options['style_map'])) {
- $this->_style_map = $this->_options['style_map'];
- }
- if (isset($this->_options['class_map'])) {
- $this->_class_map = array_merge($this->_class_map, $this->_options['class_map']);
- }
- $this->_htmlspecialchars = true;
-
- }
-
-
- /**
- * Given a CSS class name, returns the class name
- * with language name prepended, if necessary
- *
- * @access private
- *
- * @param string $class Token class
- */
- function _getFullClassName($class)
- {
- if (!empty($this->_options['use_language'])) {
- $the_class = $this->_language . '-' . $class;
- } else {
- $the_class = $class;
- }
- return $the_class;
- }
-
- /**
- * Signals that no more tokens are available
- *
- * @access public
- */
- function finalize()
- {
-
- // get parent's output
- parent::finalize();
- $output = parent::getOutput();
- if(empty($output))
- return;
-
- $html_output = '';
- // loop through each class=>content pair
- foreach ($output AS $token) {
-
- if ($this->_enumerated) {
- $the_class = $token[0];
- $content = $token[1];
- } else {
- $key = key($token);
- $the_class = $key;
- $content = $token[$key];
- }
-
- $span = $this->_getStyling($the_class);
- $decorated_output = $this->_decorate($content, $key);
- //print "<pre> token = ".var_export($token, true)." -- span = " . htmlentities($span). "-- deco = ".$decorated_output."</pre>\n";
- $html_output .= sprintf($span, $decorated_output);
- }
-
- // format lists
- if (!empty($this->_numbers) &&
- (
- $this->_numbers == HL_NUMBERS_LI ||
- $this->_numbers == HL_NUMBERS_UL ||
- $this->_numbers == HL_NUMBERS_OL
- )
- ) {
- //$html_output = "<pre>".$html_output."</pre>";
- // additional whitespace for browsers that do not display
- // empty list items correctly
- $this->_output = '<li><pre>&nbsp;' . str_replace("\n", "</pre></li>\n<li><pre>&nbsp;", $html_output) . '</pre></li>';
-
-
- $start = '';
- if ($this->_numbers == HL_NUMBERS_OL && intval($this->_numbers_start) > 0) {
- $start = ' start="' . $this->_numbers_start . '"';
- }
-
- $list_tag = 'ol';
- if ($this->_numbers == HL_NUMBERS_UL) {
- $list_tag = 'ul';
- }
-
-
- $this->_output = '<' . $list_tag . $start
- . ' ' . $this->_getStyling('main', false) . '>'
- . $this->_output . '</'. $list_tag .'>';
-
- // render a table
- } else if ($this->_numbers == HL_NUMBERS_TABLE) {
-
-
- $start_number = 0;
- if (intval($this->_numbers_start)) {
- $start_number = $this->_numbers_start - 1;
- }
-
- $numbers = '';
-
- $nlines = substr_count($html_output,"\n")+1;
- for ($i=1; $i <= $nlines; $i++) {
- $numbers .= ($start_number + $i) . "\n";
- }
- $this->_output = '<table ' . $this->_getStyling('table', false) . ' width="100%"><tr>' .
- '<td '. $this->_getStyling('gutter', false) .' align="right" valign="top">' .
- '<pre>' . $numbers . '</pre></td><td '. $this->_getStyling('main', false) .
- ' valign="top"><pre>' .
- $html_output . '</pre></td></tr></table>';
- }
- if (!$this->_numbers) {
- $this->_output = '<pre>' . $html_output . '</pre>';
- }
- $this->_output = '<div ' . $this->_getStyling('main', false) . '>' . $this->_output . '</div>';
- }
-
-
- /**
- * Provides additional formatting to a keyword
- *
- * @param string $content Keyword
- * @return string Keyword with additional formatting
- * @access public
- *
- */
- function _decorate($content, $key)
- {
- // links to online documentation
- if (!empty($this->_doclinks) &&
- !empty($this->_doclinks['url']) &&
- in_array($key, $this->_doclinks['elements'])
- ) {
-
- $link = '<a href="'. sprintf($this->_doclinks['url'], $content) . '"';
- if (!empty($this->_doclinks['target'])) {
- $link.= ' target="' . $this->_doclinks['target'] . '"';
- }
- $link .= '>';
- $link.= $content;
- $link.= '</a>';
-
- $content = $link;
-
- }
-
- return $content;
- }
-
- /**
- * Returns <code>class</code> and/or <code>style</code> attribute,
- * optionally enclosed in a <code>span</code> tag
- *
- * @param string $class Class name
- * @paran boolean $span_tag Whether or not to return styling attributes in a <code>&gt;span&lt;</code> tag
- * @return string <code>span</code> tag or just a <code>class</code> and/or <code>style</code> attributes
- * @access private
- */
- function _getStyling($class, $span_tag = true)
- {
- $attrib = '';
- if (!empty($this->_style_map) &&
- !empty($this->_style_map[$class])
- ) {
- $attrib = 'style="'. $this->_style_map[$class] .'"';
- }
- if (!empty($this->_class_map) &&
- !empty($this->_class_map[$class])
- ) {
- if ($attrib) {
- $attrib .= ' ';
- }
- $attrib .= 'class="'. $this->_getFullClassName($this->_class_map[$class]) .'"';
- }
-
- if ($span_tag) {
- $span = '<span ' . $attrib . '>%s</span>';
- return $span;
- } else {
- return $attrib;
- }
-
- }
-}
-
-/*
- * Local variables:
- * tab-width: 4
- * c-basic-offset: 4
- * c-hanging-comment-ender-p: nil
- * End:
- */
-
+<?php
+/* vim: set expandtab tabstop=4 shiftwidth=4 softtabstop=4: */
+/**
+ * HTML renderer
+ *
+ * PHP versions 4 and 5
+ *
+ * LICENSE: This source file is subject to version 3.0 of the PHP license
+ * that is available through the world-wide-web at the following URI:
+ * http://www.php.net/license/3_0.txt. If you did not receive a copy of
+ * the PHP License and are unable to obtain it through the web, please
+ * send a note to license@php.net so we can mail you a copy immediately.
+ *
+ * @category Text
+ * @package Text_Highlighter
+ * @author Andrey Demenev <demenev@gmail.com>
+ * @copyright 2004-2006 Andrey Demenev
+ * @license http://www.php.net/license/3_0.txt PHP License
+ * @version CVS: $Id: Html.php,v 1.1 2007/06/03 02:37:09 ssttoo Exp $
+ * @link http://pear.php.net/package/Text_Highlighter
+ */
+
+/**
+ * @ignore
+ */
+
+require_once dirname(__FILE__).'/../Renderer.php';
+require_once dirname(__FILE__).'/../Renderer/Array.php';
+
+// BC trick : only define constants if Text/Highlighter.php
+// is not yet included
+if (!defined('HL_NUMBERS_LI')) {
+ /**#@+
+ * Constant for use with $options['numbers']
+ */
+ /**
+ * use numbered list, deprecated, use HL_NUMBERS_OL instaed
+ * @deprecated
+ */
+ define ('HL_NUMBERS_LI' , 1);
+ /**
+ * Use 2-column table with line numbers in left column and code in right column.
+ */
+ define ('HL_NUMBERS_TABLE' , 2);
+ /**#@-*/
+}
+
+
+/**#@+
+ * Constant for use with $options['numbers']
+ */
+/**
+ * Use numbered list
+ */
+define ('HL_NUMBERS_OL', 1);
+/**
+ * Use non-numbered list
+ */
+define ('HL_NUMBERS_UL', 3);
+/**#@-*/
+
+
+/**
+ * HTML renderer
+ *
+ * Elements of $options argument of constructor (each being optional):
+ *
+ * - 'numbers' - Line numbering style 0 or {@link HL_NUMBERS_TABLE}
+ * or {@link HL_NUMBERS_UL} or {@link HL_NUMBERS_OL}
+ * - 'numbers_start' - starting number for numbered lines
+ * - 'tabsize' - Tab size
+ * - 'style_map' - Mapping of keywords to formatting rules using inline styles
+ * - 'class_map' - Mapping of keywords to formatting rules using class names
+ * - 'doclinks' - array that has keys "url", "target" and "elements", used for
+ * generating links to online documentation
+ * - 'use_language' - class names will be prefixed with language, like "php-reserved" or "css-code"
+ *
+ * Example of setting documentation links:
+ * $options['doclinks'] = array(
+ * 'url' => 'http://php.net/%s',
+ * 'target' => '_blank',
+ * 'elements' => array('reserved', 'identifier')
+ * );
+ *
+ * Example of setting class names map:
+ * $options['class_map'] = array(
+ * 'main' => 'my-main',
+ * 'table' => 'my-table',
+ * 'gutter' => 'my-gutter',
+ * 'brackets' => 'my-brackets',
+ * 'builtin' => 'my-builtin',
+ * 'code' => 'my-code',
+ * 'comment' => 'my-comment',
+ * 'default' => 'my-default',
+ * 'identifier' => 'my-identifier',
+ * 'inlinedoc' => 'my-inlinedoc',
+ * 'inlinetags' => 'my-inlinetags',
+ * 'mlcomment' => 'my-mlcomment',
+ * 'number' => 'my-number',
+ * 'quotes' => 'my-quotes',
+ * 'reserved' => 'my-reserved',
+ * 'special' => 'my-special',
+ * 'string' => 'my-string',
+ * 'url' => 'my-url',
+ * 'var' => 'my-var',
+ * );
+ *
+ * Example of setting styles mapping:
+ * $options['style_map'] = array(
+ * 'main' => 'color: black',
+ * 'table' => 'border: 1px solid black',
+ * 'gutter' => 'background-color: yellow',
+ * 'brackets' => 'color: blue',
+ * 'builtin' => 'color: red',
+ * 'code' => 'color: green',
+ * 'comment' => 'color: orange',
+ * // ....
+ * );
+ *
+ *
+ * @author Andrey Demenev <demenev@gmail.com>
+ * @category Text
+ * @package Text_Highlighter
+ * @copyright 2004-2006 Andrey Demenev
+ * @license http://www.php.net/license/3_0.txt PHP License
+ * @version Release: 0.7.0
+ * @link http://pear.php.net/package/Text_Highlighter
+ */
+
+class Text_Highlighter_Renderer_Html extends Text_Highlighter_Renderer_Array
+{
+
+ /**#@+
+ * @access private
+ */
+
+ /**
+ * Line numbering style
+ *
+ * @var integer
+ */
+ var $_numbers = 0;
+
+ /**
+ * For numberered lines - where to start
+ *
+ * @var integer
+ */
+ var $_numbers_start = 0;
+
+ /**
+ * Tab size
+ *
+ * @var integer
+ */
+ var $_tabsize = 4;
+
+ /**
+ * Highlighted code
+ *
+ * @var string
+ */
+ var $_output = '';
+
+ /**
+ * Mapping of keywords to formatting rules using inline styles
+ *
+ * @var array
+ */
+ var $_style_map = array();
+
+ /**
+ * Mapping of keywords to formatting rules using class names
+ *
+ * @var array
+ */
+ var $_class_map = array(
+ 'main' => 'hl-main',
+ 'table' => 'hl-table',
+ 'gutter' => 'hl-gutter',
+ 'brackets' => 'hl-brackets',
+ 'builtin' => 'hl-builtin',
+ 'code' => 'hl-code',
+ 'comment' => 'hl-comment',
+ 'default' => 'hl-default',
+ 'identifier' => 'hl-identifier',
+ 'inlinedoc' => 'hl-inlinedoc',
+ 'inlinetags' => 'hl-inlinetags',
+ 'mlcomment' => 'hl-mlcomment',
+ 'number' => 'hl-number',
+ 'quotes' => 'hl-quotes',
+ 'reserved' => 'hl-reserved',
+ 'special' => 'hl-special',
+ 'string' => 'hl-string',
+ 'url' => 'hl-url',
+ 'var' => 'hl-var',
+ );
+
+ /**
+ * Setup for links to online documentation
+ *
+ * This is an array with keys:
+ * - url, ex. http://php.net/%s
+ * - target, ex. _blank, default - no target
+ * - elements, default is <code>array('reserved', 'identifier')</code>
+ *
+ * @var array
+ */
+ var $_doclinks = array();
+
+ /**#@-*/
+
+ /**
+ * Resets renderer state
+ *
+ * @access protected
+ *
+ *
+ * Descendents of Text_Highlighter call this method from the constructor,
+ * passing $options they get as parameter.
+ */
+ function reset()
+ {
+ $this->_output = '';
+ if (isset($this->_options['numbers'])) {
+ $this->_numbers = (int)$this->_options['numbers'];
+ if ($this->_numbers != HL_NUMBERS_LI
+ && $this->_numbers != HL_NUMBERS_UL
+ && $this->_numbers != HL_NUMBERS_OL
+ && $this->_numbers != HL_NUMBERS_TABLE
+ ) {
+ $this->_numbers = 0;
+ }
+ }
+ if (isset($this->_options['tabsize'])) {
+ $this->_tabsize = $this->_options['tabsize'];
+ }
+ if (isset($this->_options['numbers_start'])) {
+ $this->_numbers_start = intval($this->_options['numbers_start']);
+ }
+ if (isset($this->_options['doclinks']) &&
+ is_array($this->_options['doclinks']) &&
+ !empty($this->_options['doclinks']['url'])
+ ) {
+
+ $this->_doclinks = $this->_options['doclinks']; // keys: url, target, elements array
+
+ if (empty($this->_options['doclinks']['elements'])) {
+ $this->_doclinks['elements'] = array('reserved', 'identifier');
+ }
+ }
+ if (isset($this->_options['style_map'])) {
+ $this->_style_map = $this->_options['style_map'];
+ }
+ if (isset($this->_options['class_map'])) {
+ $this->_class_map = array_merge($this->_class_map, $this->_options['class_map']);
+ }
+ $this->_htmlspecialchars = true;
+
+ }
+
+
+ /**
+ * Given a CSS class name, returns the class name
+ * with language name prepended, if necessary
+ *
+ * @access private
+ *
+ * @param string $class Token class
+ */
+ function _getFullClassName($class)
+ {
+ if (!empty($this->_options['use_language'])) {
+ $the_class = $this->_language . '-' . $class;
+ } else {
+ $the_class = $class;
+ }
+ return $the_class;
+ }
+
+ /**
+ * Signals that no more tokens are available
+ *
+ * @access public
+ */
+ function finalize()
+ {
+
+ // get parent's output
+ parent::finalize();
+ $output = parent::getOutput();
+ if(empty($output))
+ return;
+
+ $html_output = '';
+ // loop through each class=>content pair
+ foreach ($output AS $token) {
+
+ if ($this->_enumerated) {
+ $the_class = $token[0];
+ $content = $token[1];
+ } else {
+ $key = key($token);
+ $the_class = $key;
+ $content = $token[$key];
+ }
+
+ $span = $this->_getStyling($the_class);
+ $decorated_output = $this->_decorate($content, $key);
+ //print "<pre> token = ".var_export($token, true)." -- span = " . htmlentities($span). "-- deco = ".$decorated_output."</pre>\n";
+ $html_output .= sprintf($span, $decorated_output);
+ }
+
+ // format lists
+ if (!empty($this->_numbers) &&
+ (
+ $this->_numbers == HL_NUMBERS_LI ||
+ $this->_numbers == HL_NUMBERS_UL ||
+ $this->_numbers == HL_NUMBERS_OL
+ )
+ ) {
+ //$html_output = "<pre>".$html_output."</pre>";
+ // additional whitespace for browsers that do not display
+ // empty list items correctly
+ $this->_output = '<li><pre>&nbsp;' . str_replace("\n", "</pre></li>\n<li><pre>&nbsp;", $html_output) . '</pre></li>';
+
+
+ $start = '';
+ if ($this->_numbers == HL_NUMBERS_OL && intval($this->_numbers_start) > 0) {
+ $start = ' start="' . $this->_numbers_start . '"';
+ }
+
+ $list_tag = 'ol';
+ if ($this->_numbers == HL_NUMBERS_UL) {
+ $list_tag = 'ul';
+ }
+
+
+ $this->_output = '<' . $list_tag . $start
+ . ' ' . $this->_getStyling('main', false) . '>'
+ . $this->_output . '</'. $list_tag .'>';
+
+ // render a table
+ } else if ($this->_numbers == HL_NUMBERS_TABLE) {
+
+
+ $start_number = 0;
+ if (intval($this->_numbers_start)) {
+ $start_number = $this->_numbers_start - 1;
+ }
+
+ $numbers = '';
+
+ $nlines = substr_count($html_output,"\n")+1;
+ for ($i=1; $i <= $nlines; $i++) {
+ $numbers .= ($start_number + $i) . "\n";
+ }
+ $this->_output = '<table ' . $this->_getStyling('table', false) . ' width="100%"><tr>' .
+ '<td '. $this->_getStyling('gutter', false) .' align="right" valign="top">' .
+ '<pre>' . $numbers . '</pre></td><td '. $this->_getStyling('main', false) .
+ ' valign="top"><pre>' .
+ $html_output . '</pre></td></tr></table>';
+ }
+ if (!$this->_numbers) {
+ $this->_output = '<pre>' . $html_output . '</pre>';
+ }
+ $this->_output = '<div ' . $this->_getStyling('main', false) . '>' . $this->_output . '</div>';
+ }
+
+
+ /**
+ * Provides additional formatting to a keyword
+ *
+ * @param string $content Keyword
+ * @return string Keyword with additional formatting
+ * @access public
+ *
+ */
+ function _decorate($content, $key)
+ {
+ // links to online documentation
+ if (!empty($this->_doclinks) &&
+ !empty($this->_doclinks['url']) &&
+ in_array($key, $this->_doclinks['elements'])
+ ) {
+
+ $link = '<a href="'. sprintf($this->_doclinks['url'], $content) . '"';
+ if (!empty($this->_doclinks['target'])) {
+ $link.= ' target="' . $this->_doclinks['target'] . '"';
+ }
+ $link .= '>';
+ $link.= $content;
+ $link.= '</a>';
+
+ $content = $link;
+
+ }
+
+ return $content;
+ }
+
+ /**
+ * Returns <code>class</code> and/or <code>style</code> attribute,
+ * optionally enclosed in a <code>span</code> tag
+ *
+ * @param string $class Class name
+ * @paran boolean $span_tag Whether or not to return styling attributes in a <code>&gt;span&lt;</code> tag
+ * @return string <code>span</code> tag or just a <code>class</code> and/or <code>style</code> attributes
+ * @access private
+ */
+ function _getStyling($class, $span_tag = true)
+ {
+ $attrib = '';
+ if (!empty($this->_style_map) &&
+ !empty($this->_style_map[$class])
+ ) {
+ $attrib = 'style="'. $this->_style_map[$class] .'"';
+ }
+ if (!empty($this->_class_map) &&
+ !empty($this->_class_map[$class])
+ ) {
+ if ($attrib) {
+ $attrib .= ' ';
+ }
+ $attrib .= 'class="'. $this->_getFullClassName($this->_class_map[$class]) .'"';
+ }
+
+ if ($span_tag) {
+ $span = '<span ' . $attrib . '>%s</span>';
+ return $span;
+ } else {
+ return $attrib;
+ }
+
+ }
+}
+
+/*
+ * Local variables:
+ * tab-width: 4
+ * c-basic-offset: 4
+ * c-hanging-comment-ender-p: nil
+ * End:
+ */
+
?> \ No newline at end of file
diff --git a/framework/3rdParty/TextHighlighter/Text/Highlighter/Renderer/HtmlTags.php b/framework/3rdParty/TextHighlighter/Text/Highlighter/Renderer/HtmlTags.php
index a75e659e..b085d535 100644
--- a/framework/3rdParty/TextHighlighter/Text/Highlighter/Renderer/HtmlTags.php
+++ b/framework/3rdParty/TextHighlighter/Text/Highlighter/Renderer/HtmlTags.php
@@ -1,187 +1,187 @@
-<?php
-/* vim: set expandtab tabstop=4 shiftwidth=4 softtabstop=4: */
-/**
- * HTML renderer that uses only basic html tags
- *
- * PHP versions 4 and 5. Based on the "normal" HTML renderer by Andrey Demenev.
- * It's designed to work with user agents that support only a limited number of
- * HTML tags. Like the iPod which supports only b, i, u and a.
- *
- * LICENSE: This source file is subject to version 3.0 of the PHP license
- * that is available through the world-wide-web at the following URI:
- * http://www.php.net/license/3_0.txt. If you did not receive a copy of
- * the PHP License and are unable to obtain it through the web, please
- * send a note to license@php.net so we can mail you a copy immediately.
- *
- * @category Text
- * @package Text_Highlighter
- * @author Stoyan Stefanov <ssttoo@gmail.com>
- * @copyright 2005 Stoyan Stefanov
- * @license http://www.php.net/license/3_0.txt PHP License
- * @version CVS: $Id: HtmlTags.php,v 1.1 2007/06/03 02:37:09 ssttoo Exp $
- * @link http://pear.php.net/package/Text_Highlighter
- */
-
-/**
- * @ignore
- */
-
-require_once dirname(__FILE__).'/../Renderer.php';
-require_once dirname(__FILE__).'/../Renderer/Array.php';
-
-/**
- * HTML basic tags renderer, based on Andrey Demenev's HTML renderer.
- *
- * Elements of $options argument of constructor (each being optional):
- *
- * - 'numbers' - Line numbering TRUE or FALSE. Default is FALSE.
- * - 'tabsize' - Tab size, default is 4.
- * - 'tags' - Array, containing the tags to be used for highlighting
- *
- * Here's the listing of the default tags:
- * - 'default' => '',
- * - 'code' => '',
- * - 'brackets' => 'b',
- * - 'comment' => 'i',
- * - 'mlcomment' => 'i',
- * - 'quotes' => '',
- * - 'string' => 'i',
- * - 'identifier' => 'b',
- * - 'builtin' => 'b',
- * - 'reserved' => 'u',
- * - 'inlinedoc' => 'i',
- * - 'var' => 'b',
- * - 'url' => 'i',
- * - 'special' => '',
- * - 'number' => '',
- * - 'inlinetags' => ''
- *
- * @author Stoyan Stefanov <ssttoo@gmail.com>
- * @category Text
- * @package Text_Highlighter
- * @copyright 2005 Stoyan Stefanov
- * @license http://www.php.net/license/3_0.txt PHP License
- * @version Release: 0.5.0
- * @link http://pear.php.net/package/Text_Highlighter
- */
-
-class Text_Highlighter_Renderer_HtmlTags extends Text_Highlighter_Renderer_Array
-{
-
- /**#@+
- * @access private
- */
-
- /**
- * Line numbering - will use 'ol' tag
- *
- * @var boolean
- */
- var $_numbers = false;
-
- /**
- * HTML tags map
- *
- * @var array
- */
- var $_hilite_tags = array(
- 'default' => '',
- 'code' => '',
- 'brackets' => 'b',
- 'comment' => 'i',
- 'mlcomment' => 'i',
- 'quotes' => '',
- 'string' => 'i',
- 'identifier' => 'b',
- 'builtin' => 'b',
- 'reserved' => 'u',
- 'inlinedoc' => 'i',
- 'var' => 'b',
- 'url' => 'i',
- 'special' => '',
- 'number' => '',
- 'inlinetags' => '',
- );
-
- /**#@-*/
-
- /**
- * Resets renderer state
- *
- * @access protected
- *
- *
- * Descendents of Text_Highlighter call this method from the constructor,
- * passing $options they get as parameter.
- */
- function reset()
- {
- parent::reset();
- if (isset($this->_options['numbers'])) {
- $this->_numbers = $this->_options['numbers'];
- }
- if (isset($this->_options['tags'])) {
- $this->_hilite_tags = array_merge($this->_tags, $this->_options['tags']);
- }
- }
-
-
- /**
- * Signals that no more tokens are available
- *
- * @abstract
- * @access public
- *
- */
- function finalize()
- {
-
- // get parent's output
- parent::finalize();
- $output = parent::getOutput();
-
- $html_output = '';
-
- // loop through each class=>content pair
- foreach ($output AS $token) {
-
- if ($this->_enumerated) {
- $class = $token[0];
- $content = $token[1];
- } else {
- $key = key($token);
- $class = $key;
- $content = $token[$key];
- }
-
- $iswhitespace = ctype_space($content);
- if (!$iswhitespace && !empty($this->_hilite_tags[$class])) {
- $html_output .= '<'. $this->_hilite_tags[$class] . '>' . $content . '</'. $this->_hilite_tags[$class] . '>';
- } else {
- $html_output .= $content;
- }
- }
-
-
- if ($this->_numbers) {
- /* additional whitespace for browsers that do not display
- empty list items correctly */
- $html_output = '<li>&nbsp;' . str_replace("\n", "</li>\n<li>&nbsp;", $html_output) . '</li>';
- $this->_output = '<ol>' . str_replace(' ', '&nbsp;', $html_output) . '</ol>';
- } else {
- $this->_output = '<pre>' . $html_output . '</pre>';
- }
- }
-
-
-}
-
-/*
- * Local variables:
- * tab-width: 4
- * c-basic-offset: 4
- * c-hanging-comment-ender-p: nil
- * End:
- */
-
+<?php
+/* vim: set expandtab tabstop=4 shiftwidth=4 softtabstop=4: */
+/**
+ * HTML renderer that uses only basic html tags
+ *
+ * PHP versions 4 and 5. Based on the "normal" HTML renderer by Andrey Demenev.
+ * It's designed to work with user agents that support only a limited number of
+ * HTML tags. Like the iPod which supports only b, i, u and a.
+ *
+ * LICENSE: This source file is subject to version 3.0 of the PHP license
+ * that is available through the world-wide-web at the following URI:
+ * http://www.php.net/license/3_0.txt. If you did not receive a copy of
+ * the PHP License and are unable to obtain it through the web, please
+ * send a note to license@php.net so we can mail you a copy immediately.
+ *
+ * @category Text
+ * @package Text_Highlighter
+ * @author Stoyan Stefanov <ssttoo@gmail.com>
+ * @copyright 2005 Stoyan Stefanov
+ * @license http://www.php.net/license/3_0.txt PHP License
+ * @version CVS: $Id: HtmlTags.php,v 1.1 2007/06/03 02:37:09 ssttoo Exp $
+ * @link http://pear.php.net/package/Text_Highlighter
+ */
+
+/**
+ * @ignore
+ */
+
+require_once dirname(__FILE__).'/../Renderer.php';
+require_once dirname(__FILE__).'/../Renderer/Array.php';
+
+/**
+ * HTML basic tags renderer, based on Andrey Demenev's HTML renderer.
+ *
+ * Elements of $options argument of constructor (each being optional):
+ *
+ * - 'numbers' - Line numbering TRUE or FALSE. Default is FALSE.
+ * - 'tabsize' - Tab size, default is 4.
+ * - 'tags' - Array, containing the tags to be used for highlighting
+ *
+ * Here's the listing of the default tags:
+ * - 'default' => '',
+ * - 'code' => '',
+ * - 'brackets' => 'b',
+ * - 'comment' => 'i',
+ * - 'mlcomment' => 'i',
+ * - 'quotes' => '',
+ * - 'string' => 'i',
+ * - 'identifier' => 'b',
+ * - 'builtin' => 'b',
+ * - 'reserved' => 'u',
+ * - 'inlinedoc' => 'i',
+ * - 'var' => 'b',
+ * - 'url' => 'i',
+ * - 'special' => '',
+ * - 'number' => '',
+ * - 'inlinetags' => ''
+ *
+ * @author Stoyan Stefanov <ssttoo@gmail.com>
+ * @category Text
+ * @package Text_Highlighter
+ * @copyright 2005 Stoyan Stefanov
+ * @license http://www.php.net/license/3_0.txt PHP License
+ * @version Release: 0.5.0
+ * @link http://pear.php.net/package/Text_Highlighter
+ */
+
+class Text_Highlighter_Renderer_HtmlTags extends Text_Highlighter_Renderer_Array
+{
+
+ /**#@+
+ * @access private
+ */
+
+ /**
+ * Line numbering - will use 'ol' tag
+ *
+ * @var boolean
+ */
+ var $_numbers = false;
+
+ /**
+ * HTML tags map
+ *
+ * @var array
+ */
+ var $_hilite_tags = array(
+ 'default' => '',
+ 'code' => '',
+ 'brackets' => 'b',
+ 'comment' => 'i',
+ 'mlcomment' => 'i',
+ 'quotes' => '',
+ 'string' => 'i',
+ 'identifier' => 'b',
+ 'builtin' => 'b',
+ 'reserved' => 'u',
+ 'inlinedoc' => 'i',
+ 'var' => 'b',
+ 'url' => 'i',
+ 'special' => '',
+ 'number' => '',
+ 'inlinetags' => '',
+ );
+
+ /**#@-*/
+
+ /**
+ * Resets renderer state
+ *
+ * @access protected
+ *
+ *
+ * Descendents of Text_Highlighter call this method from the constructor,
+ * passing $options they get as parameter.
+ */
+ function reset()
+ {
+ parent::reset();
+ if (isset($this->_options['numbers'])) {
+ $this->_numbers = $this->_options['numbers'];
+ }
+ if (isset($this->_options['tags'])) {
+ $this->_hilite_tags = array_merge($this->_tags, $this->_options['tags']);
+ }
+ }
+
+
+ /**
+ * Signals that no more tokens are available
+ *
+ * @abstract
+ * @access public
+ *
+ */
+ function finalize()
+ {
+
+ // get parent's output
+ parent::finalize();
+ $output = parent::getOutput();
+
+ $html_output = '';
+
+ // loop through each class=>content pair
+ foreach ($output AS $token) {
+
+ if ($this->_enumerated) {
+ $class = $token[0];
+ $content = $token[1];
+ } else {
+ $key = key($token);
+ $class = $key;
+ $content = $token[$key];
+ }
+
+ $iswhitespace = ctype_space($content);
+ if (!$iswhitespace && !empty($this->_hilite_tags[$class])) {
+ $html_output .= '<'. $this->_hilite_tags[$class] . '>' . $content . '</'. $this->_hilite_tags[$class] . '>';
+ } else {
+ $html_output .= $content;
+ }
+ }
+
+
+ if ($this->_numbers) {
+ /* additional whitespace for browsers that do not display
+ empty list items correctly */
+ $html_output = '<li>&nbsp;' . str_replace("\n", "</li>\n<li>&nbsp;", $html_output) . '</li>';
+ $this->_output = '<ol>' . str_replace(' ', '&nbsp;', $html_output) . '</ol>';
+ } else {
+ $this->_output = '<pre>' . $html_output . '</pre>';
+ }
+ }
+
+
+}
+
+/*
+ * Local variables:
+ * tab-width: 4
+ * c-basic-offset: 4
+ * c-hanging-comment-ender-p: nil
+ * End:
+ */
+
?> \ No newline at end of file
diff --git a/framework/3rdParty/TextHighlighter/Text/Highlighter/Renderer/JSON.php b/framework/3rdParty/TextHighlighter/Text/Highlighter/Renderer/JSON.php
index 7f1158fb..6a6ff71e 100644
--- a/framework/3rdParty/TextHighlighter/Text/Highlighter/Renderer/JSON.php
+++ b/framework/3rdParty/TextHighlighter/Text/Highlighter/Renderer/JSON.php
@@ -1,86 +1,86 @@
-<?php
-/* vim: set expandtab tabstop=4 shiftwidth=4 softtabstop=4: */
-/**
- * JSON renderer.
- *
- * Based on the HTML renderer by Andrey Demenev.
- *
- * LICENSE: This source file is subject to version 3.0 of the PHP license
- * that is available through the world-wide-web at the following URI:
- * http://www.php.net/license/3_0.txt. If you did not receive a copy of
- * the PHP License and are unable to obtain it through the web, please
- * send a note to license@php.net so we can mail you a copy immediately.
- *
- * @category Text
- * @package Text_Highlighter
- * @author Stoyan Stefanov <ssttoo@gmail.com>
- * @copyright 2006 Stoyan Stefanov
- * @license http://www.php.net/license/3_0.txt PHP License
- * @version CVS: $Id: JSON.php,v 1.1 2007/06/03 02:37:09 ssttoo Exp $
- * @link http://pear.php.net/package/Text_Highlighter
- */
-
-/**
- * @ignore
- */
-
-require_once dirname(__FILE__).'/../Renderer.php';
-require_once dirname(__FILE__).'/../Renderer/Array.php';
-
-/**
- * JSON renderer, based on Andrey Demenev's HTML renderer.
- *
- * @author Stoyan Stefanov <ssttoo@gmail.com>
- * @category Text
- * @package Text_Highlighter
- * @copyright 2006 Stoyan Stefanov
- * @license http://www.php.net/license/3_0.txt PHP License
- * @version Release: 0.5.0
- * @link http://pear.php.net/package/Text_Highlighter
- */
-
-class Text_Highlighter_Renderer_JSON extends Text_Highlighter_Renderer_Array
-{
-
- /**
- * Signals that no more tokens are available
- *
- * @abstract
- * @access public
- */
- function finalize()
- {
-
- parent::finalize();
- $output = parent::getOutput();
-
- $json_array = array();
-
- foreach ($output AS $token) {
-
- if ($this->_enumerated) {
- $json_array[] = '["' . $token[0] . '","' . $token[1] . '"]';
- } else {
- $key = key($token);
- $json_array[] = '{"class": "' . $key . '","content":"' . $token[$key] . '"}';
- }
-
- }
-
- $this->_output = '['. implode(',', $json_array) .']';
- $this->_output = str_replace("\n", '\n', $this->_output);
-
- }
-
-
-}
-
-/*
- * Local variables:
- * tab-width: 4
- * c-basic-offset: 4
- * c-hanging-comment-ender-p: nil
- * End:
- */
-
+<?php
+/* vim: set expandtab tabstop=4 shiftwidth=4 softtabstop=4: */
+/**
+ * JSON renderer.
+ *
+ * Based on the HTML renderer by Andrey Demenev.
+ *
+ * LICENSE: This source file is subject to version 3.0 of the PHP license
+ * that is available through the world-wide-web at the following URI:
+ * http://www.php.net/license/3_0.txt. If you did not receive a copy of
+ * the PHP License and are unable to obtain it through the web, please
+ * send a note to license@php.net so we can mail you a copy immediately.
+ *
+ * @category Text
+ * @package Text_Highlighter
+ * @author Stoyan Stefanov <ssttoo@gmail.com>
+ * @copyright 2006 Stoyan Stefanov
+ * @license http://www.php.net/license/3_0.txt PHP License
+ * @version CVS: $Id: JSON.php,v 1.1 2007/06/03 02:37:09 ssttoo Exp $
+ * @link http://pear.php.net/package/Text_Highlighter
+ */
+
+/**
+ * @ignore
+ */
+
+require_once dirname(__FILE__).'/../Renderer.php';
+require_once dirname(__FILE__).'/../Renderer/Array.php';
+
+/**
+ * JSON renderer, based on Andrey Demenev's HTML renderer.
+ *
+ * @author Stoyan Stefanov <ssttoo@gmail.com>
+ * @category Text
+ * @package Text_Highlighter
+ * @copyright 2006 Stoyan Stefanov
+ * @license http://www.php.net/license/3_0.txt PHP License
+ * @version Release: 0.5.0
+ * @link http://pear.php.net/package/Text_Highlighter
+ */
+
+class Text_Highlighter_Renderer_JSON extends Text_Highlighter_Renderer_Array
+{
+
+ /**
+ * Signals that no more tokens are available
+ *
+ * @abstract
+ * @access public
+ */
+ function finalize()
+ {
+
+ parent::finalize();
+ $output = parent::getOutput();
+
+ $json_array = array();
+
+ foreach ($output AS $token) {
+
+ if ($this->_enumerated) {
+ $json_array[] = '["' . $token[0] . '","' . $token[1] . '"]';
+ } else {
+ $key = key($token);
+ $json_array[] = '{"class": "' . $key . '","content":"' . $token[$key] . '"}';
+ }
+
+ }
+
+ $this->_output = '['. implode(',', $json_array) .']';
+ $this->_output = str_replace("\n", '\n', $this->_output);
+
+ }
+
+
+}
+
+/*
+ * Local variables:
+ * tab-width: 4
+ * c-basic-offset: 4
+ * c-hanging-comment-ender-p: nil
+ * End:
+ */
+
?> \ No newline at end of file
diff --git a/framework/3rdParty/TextHighlighter/Text/Highlighter/Renderer/XML.php b/framework/3rdParty/TextHighlighter/Text/Highlighter/Renderer/XML.php
index e86f620a..ab8a4e3e 100644
--- a/framework/3rdParty/TextHighlighter/Text/Highlighter/Renderer/XML.php
+++ b/framework/3rdParty/TextHighlighter/Text/Highlighter/Renderer/XML.php
@@ -1,103 +1,103 @@
-<?php
-/* vim: set expandtab tabstop=4 shiftwidth=4 softtabstop=4: */
-/**
- * XML renderer.
- *
- * Based on the HTML renderer by Andrey Demenev.
- *
- * LICENSE: This source file is subject to version 3.0 of the PHP license
- * that is available through the world-wide-web at the following URI:
- * http://www.php.net/license/3_0.txt. If you did not receive a copy of
- * the PHP License and are unable to obtain it through the web, please
- * send a note to license@php.net so we can mail you a copy immediately.
- *
- * @category Text
- * @package Text_Highlighter
- * @author Stoyan Stefanov <ssttoo@gmail.com>
- * @copyright 2006 Stoyan Stefanov
- * @license http://www.php.net/license/3_0.txt PHP License
- * @version CVS: $Id: XML.php,v 1.1 2007/06/03 02:37:09 ssttoo Exp $
- * @link http://pear.php.net/package/Text_Highlighter
- */
-
-/**
- * @ignore
- */
-
-require_once dirname(__FILE__).'/../Renderer.php';
-require_once dirname(__FILE__).'/../Renderer/Array.php';
-
-/**
- * XML renderer, based on Andrey Demenev's HTML renderer.
- *
- * @author Stoyan Stefanov <ssttoo@gmail.com>
- * @category Text
- * @package Text_Highlighter
- * @copyright 2006 Stoyan Stefanov
- * @license http://www.php.net/license/3_0.txt PHP License
- * @version Release: 0.5.0
- * @link http://pear.php.net/package/Text_Highlighter
- */
-
-class Text_Highlighter_Renderer_XML extends Text_Highlighter_Renderer_Array
-{
-
-
- /**
- * Options for XML_Serializer
- *
- * @access private
- * @var array
- */
- var $_serializer_options = array();
-
-
- /**
- * Resets renderer state
- *
- * Descendents of Text_Highlighter call this method from the constructor,
- * passing $options they get as parameter.
- *
- * @access protected
- */
- function reset()
- {
- parent::reset();
- if (isset($this->_options['xml_serializer'])) {
- $this->_serializer_options = $this->_options['xml_serializer'];
- }
- }
-
-
- /**
- * Signals that no more tokens are available
- *
- * @abstract
- * @access public
- */
- function finalize()
- {
-
- // call parent's finalize(), then serialize array into XML
- parent::finalize();
- $output = parent::getOutput();
-
- $serializer = new XML_Serializer($this->_serializer_options);
- $result = $serializer->serialize($output);
- if ($result === true) {
- $this->_output = $serializer->getSerializedData();
- }
- }
-
-
-}
-
-/*
- * Local variables:
- * tab-width: 4
- * c-basic-offset: 4
- * c-hanging-comment-ender-p: nil
- * End:
- */
-
+<?php
+/* vim: set expandtab tabstop=4 shiftwidth=4 softtabstop=4: */
+/**
+ * XML renderer.
+ *
+ * Based on the HTML renderer by Andrey Demenev.
+ *
+ * LICENSE: This source file is subject to version 3.0 of the PHP license
+ * that is available through the world-wide-web at the following URI:
+ * http://www.php.net/license/3_0.txt. If you did not receive a copy of
+ * the PHP License and are unable to obtain it through the web, please
+ * send a note to license@php.net so we can mail you a copy immediately.
+ *
+ * @category Text
+ * @package Text_Highlighter
+ * @author Stoyan Stefanov <ssttoo@gmail.com>
+ * @copyright 2006 Stoyan Stefanov
+ * @license http://www.php.net/license/3_0.txt PHP License
+ * @version CVS: $Id: XML.php,v 1.1 2007/06/03 02:37:09 ssttoo Exp $
+ * @link http://pear.php.net/package/Text_Highlighter
+ */
+
+/**
+ * @ignore
+ */
+
+require_once dirname(__FILE__).'/../Renderer.php';
+require_once dirname(__FILE__).'/../Renderer/Array.php';
+
+/**
+ * XML renderer, based on Andrey Demenev's HTML renderer.
+ *
+ * @author Stoyan Stefanov <ssttoo@gmail.com>
+ * @category Text
+ * @package Text_Highlighter
+ * @copyright 2006 Stoyan Stefanov
+ * @license http://www.php.net/license/3_0.txt PHP License
+ * @version Release: 0.5.0
+ * @link http://pear.php.net/package/Text_Highlighter
+ */
+
+class Text_Highlighter_Renderer_XML extends Text_Highlighter_Renderer_Array
+{
+
+
+ /**
+ * Options for XML_Serializer
+ *
+ * @access private
+ * @var array
+ */
+ var $_serializer_options = array();
+
+
+ /**
+ * Resets renderer state
+ *
+ * Descendents of Text_Highlighter call this method from the constructor,
+ * passing $options they get as parameter.
+ *
+ * @access protected
+ */
+ function reset()
+ {
+ parent::reset();
+ if (isset($this->_options['xml_serializer'])) {
+ $this->_serializer_options = $this->_options['xml_serializer'];
+ }
+ }
+
+
+ /**
+ * Signals that no more tokens are available
+ *
+ * @abstract
+ * @access public
+ */
+ function finalize()
+ {
+
+ // call parent's finalize(), then serialize array into XML
+ parent::finalize();
+ $output = parent::getOutput();
+
+ $serializer = new XML_Serializer($this->_serializer_options);
+ $result = $serializer->serialize($output);
+ if ($result === true) {
+ $this->_output = $serializer->getSerializedData();
+ }
+ }
+
+
+}
+
+/*
+ * Local variables:
+ * tab-width: 4
+ * c-basic-offset: 4
+ * c-hanging-comment-ender-p: nil
+ * End:
+ */
+
?> \ No newline at end of file
diff --git a/framework/3rdParty/TextHighlighter/Text/Highlighter/SQL.php b/framework/3rdParty/TextHighlighter/Text/Highlighter/SQL.php
index 9679b230..6b0b4b7c 100644
--- a/framework/3rdParty/TextHighlighter/Text/Highlighter/SQL.php
+++ b/framework/3rdParty/TextHighlighter/Text/Highlighter/SQL.php
@@ -1,51 +1,51 @@
-<?php
-/**
+<?php
+/**
* Auto-generated class. SQL syntax highlighting
*
- * Based on SQL-99
- *
- * PHP version 4 and 5
- *
- * LICENSE: This source file is subject to version 3.0 of the PHP license
- * that is available through the world-wide-web at the following URI:
- * http://www.php.net/license/3_0.txt. If you did not receive a copy of
- * the PHP License and are unable to obtain it through the web, please
- * send a note to license@php.net so we can mail you a copy immediately.
- *
- * @copyright 2004-2006 Andrey Demenev
- * @license http://www.php.net/license/3_0.txt PHP License
- * @link http://pear.php.net/package/Text_Highlighter
- * @category Text
- * @package Text_Highlighter
+ * Based on SQL-99
+ *
+ * PHP version 4 and 5
+ *
+ * LICENSE: This source file is subject to version 3.0 of the PHP license
+ * that is available through the world-wide-web at the following URI:
+ * http://www.php.net/license/3_0.txt. If you did not receive a copy of
+ * the PHP License and are unable to obtain it through the web, please
+ * send a note to license@php.net so we can mail you a copy immediately.
+ *
+ * @copyright 2004-2006 Andrey Demenev
+ * @license http://www.php.net/license/3_0.txt PHP License
+ * @link http://pear.php.net/package/Text_Highlighter
+ * @category Text
+ * @package Text_Highlighter
* @version generated from: : sql.xml,v 1.1 2007/06/03 02:35:28 ssttoo Exp
* @author Andrey Demenev <demenev@gmail.com>
- *
- */
-
-/**
- * Auto-generated class. SQL syntax highlighting
- *
+ *
+ */
+
+/**
+ * Auto-generated class. SQL syntax highlighting
+ *
* @author Andrey Demenev <demenev@gmail.com>
- * @category Text
- * @package Text_Highlighter
- * @copyright 2004-2006 Andrey Demenev
- * @license http://www.php.net/license/3_0.txt PHP License
- * @version Release: 0.7.0
- * @link http://pear.php.net/package/Text_Highlighter
- */
-class Text_Highlighter_SQL extends Text_Highlighter
-{
+ * @category Text
+ * @package Text_Highlighter
+ * @copyright 2004-2006 Andrey Demenev
+ * @license http://www.php.net/license/3_0.txt PHP License
+ * @version Release: 0.7.0
+ * @link http://pear.php.net/package/Text_Highlighter
+ */
+class Text_Highlighter_SQL extends Text_Highlighter
+{
var $_language = 'sql';
- /**
- * Constructor
- *
- * @param array $options
- * @access public
- */
- function __construct($options=array())
- {
-
+ /**
+ * Constructor
+ *
+ * @param array $options
+ * @access public
+ */
+ function __construct($options=array())
+ {
+
$this->_options = $options;
$this->_regs = array (
-1 => '/((?i)`)|((?i)\\/\\*)|((?i)(#|--\\s).*)|((?i)[a-z_]\\w*)|((?i)")|((?i)\\()|((?i)\')|((?i)((\\d+|((\\d*\\.\\d+)|(\\d+\\.\\d*)))[eE][+-]?\\d+))|((?i)(\\d*\\.\\d+)|(\\d+\\.\\d*))|((?i)\\d+l?|\\b0l?\\b)|((?i)0[xX][\\da-f]+l?)/',
@@ -394,8 +394,8 @@ class Text_Highlighter_SQL extends Text_Highlighter
'reserved' => 'reserved',
'keyword' => 'var',
);
- $this->_defClass = 'code';
- $this->_checkDefines();
- }
-
+ $this->_defClass = 'code';
+ $this->_checkDefines();
+ }
+
} \ No newline at end of file
diff --git a/framework/3rdParty/TextHighlighter/Text/Highlighter/XML.php b/framework/3rdParty/TextHighlighter/Text/Highlighter/XML.php
index 8dc3b881..3c454c77 100644
--- a/framework/3rdParty/TextHighlighter/Text/Highlighter/XML.php
+++ b/framework/3rdParty/TextHighlighter/Text/Highlighter/XML.php
@@ -1,49 +1,49 @@
-<?php
-/**
- * Auto-generated class. XML syntax highlighting
- *
- * PHP version 4 and 5
- *
- * LICENSE: This source file is subject to version 3.0 of the PHP license
- * that is available through the world-wide-web at the following URI:
- * http://www.php.net/license/3_0.txt. If you did not receive a copy of
- * the PHP License and are unable to obtain it through the web, please
- * send a note to license@php.net so we can mail you a copy immediately.
- *
- * @copyright 2004-2006 Andrey Demenev
- * @license http://www.php.net/license/3_0.txt PHP License
- * @link http://pear.php.net/package/Text_Highlighter
- * @category Text
- * @package Text_Highlighter
+<?php
+/**
+ * Auto-generated class. XML syntax highlighting
+ *
+ * PHP version 4 and 5
+ *
+ * LICENSE: This source file is subject to version 3.0 of the PHP license
+ * that is available through the world-wide-web at the following URI:
+ * http://www.php.net/license/3_0.txt. If you did not receive a copy of
+ * the PHP License and are unable to obtain it through the web, please
+ * send a note to license@php.net so we can mail you a copy immediately.
+ *
+ * @copyright 2004-2006 Andrey Demenev
+ * @license http://www.php.net/license/3_0.txt PHP License
+ * @link http://pear.php.net/package/Text_Highlighter
+ * @category Text
+ * @package Text_Highlighter
* @version generated from: : xml.xml,v 1.1 2007/06/03 02:35:28 ssttoo Exp
* @author Andrey Demenev <demenev@gmail.com>
- *
- */
-
-/**
- * Auto-generated class. XML syntax highlighting
- *
+ *
+ */
+
+/**
+ * Auto-generated class. XML syntax highlighting
+ *
* @author Andrey Demenev <demenev@gmail.com>
- * @category Text
- * @package Text_Highlighter
- * @copyright 2004-2006 Andrey Demenev
- * @license http://www.php.net/license/3_0.txt PHP License
- * @version Release: 0.7.0
- * @link http://pear.php.net/package/Text_Highlighter
- */
-class Text_Highlighter_XML extends Text_Highlighter
-{
+ * @category Text
+ * @package Text_Highlighter
+ * @copyright 2004-2006 Andrey Demenev
+ * @license http://www.php.net/license/3_0.txt PHP License
+ * @version Release: 0.7.0
+ * @link http://pear.php.net/package/Text_Highlighter
+ */
+class Text_Highlighter_XML extends Text_Highlighter
+{
var $_language = 'xml';
- /**
- * Constructor
- *
- * @param array $options
- * @access public
- */
- function __construct($options=array())
- {
-
+ /**
+ * Constructor
+ *
+ * @param array $options
+ * @access public
+ */
+ function __construct($options=array())
+ {
+
$this->_options = $options;
$this->_regs = array (
-1 => '/((?i)\\<\\!\\[CDATA\\[)|((?i)\\<!--)|((?i)\\<[\\?\\/]?)|((?i)(&|%)[\\w\\-\\.]+;)/',
@@ -238,8 +238,8 @@ class Text_Highlighter_XML extends Text_Highlighter
);
$this->_kwmap = array (
);
- $this->_defClass = 'code';
- $this->_checkDefines();
- }
-
+ $this->_defClass = 'code';
+ $this->_checkDefines();
+ }
+
} \ No newline at end of file
diff --git a/framework/Caching/TAPCCache.php b/framework/Caching/TAPCCache.php
index 49cbd137..e0117a0c 100644
--- a/framework/Caching/TAPCCache.php
+++ b/framework/Caching/TAPCCache.php
@@ -1,133 +1,133 @@
-<?php
-/**
- * TAPCCache class file
- *
- * @author Alban Hanry <compte_messagerie@hotmail.com>
- * @link http://www.pradosoft.com/
- * @copyright Copyright &copy; 2005-2012 PradoSoft
- * @license http://www.pradosoft.com/license/
- * @version $Id$
- * @package System.Caching
- */
-
-/**
- * TAPCCache class
- *
- * TAPCCache implements a cache application module based on {@link http://www.php.net/apc APC}.
- *
- * By definition, cache does not ensure the existence of a value
- * even if it never expires. Cache is not meant to be an persistent storage.
- *
- * To use this module, the APC PHP extension must be loaded and set in the php.ini file the following:
- * <code>
- * apc.cache_by_default=0
- * </code>
- *
- * Some usage examples of TAPCCache are as follows,
- * <code>
- * $cache=new TAPCCache; // TAPCCache may also be loaded as a Prado application module
- * $cache->init(null);
- * $cache->add('object',$object);
- * $object2=$cache->get('object');
- * </code>
- *
- * If loaded, TAPCCache will register itself with {@link TApplication} as the
- * cache module. It can be accessed via {@link TApplication::getCache()}.
- *
- * TAPCCache may be configured in application configuration file as follows
- * <code>
- * <module id="cache" class="System.Caching.TAPCCache" />
- * </code>
- *
- * @author Alban Hanry <compte_messagerie@hotmail.com>
- * @author Knut Urdalen <knut.urdalen@gmail.com>
- * @version $Id$
- * @package System.Caching
- * @since 3.0b
- */
-class TAPCCache extends TCache
-{
- /**
- * Initializes this module.
- * This method is required by the IModule interface.
- * @param TXmlElement configuration for this module, can be null
- * @throws TConfigurationException if apc extension is not installed or not started, check your php.ini
- */
- public function init($config)
- {
- if(!extension_loaded('apc'))
- throw new TConfigurationException('apccache_extension_required');
-
- if(ini_get('apc.enabled') == false)
- throw new TConfigurationException('apccache_extension_not_enabled');
-
- if(substr(php_sapi_name(), 0, 3) === 'cli' and ini_get('apc.enable_cli') == false)
- throw new TConfigurationException('apccache_extension_not_enabled_cli');
-
- parent::init($config);
- }
-
- /**
- * Retrieves a value from cache with a specified key.
- * This is the implementation of the method declared in the parent class.
- * @param string a unique key identifying the cached value
- * @return string the value stored in cache, false if the value is not in the cache or expired.
- */
- protected function getValue($key)
- {
- return apc_fetch($key);
- }
-
- /**
- * Stores a value identified by a key in cache.
- * This is the implementation of the method declared in the parent class.
- *
- * @param string the key identifying the value to be cached
- * @param string the value to be cached
- * @param integer the number of seconds in which the cached value will expire. 0 means never expire.
- * @return boolean true if the value is successfully stored into cache, false otherwise
- */
- protected function setValue($key,$value,$expire)
- {
- return apc_store($key,$value,$expire);
- }
-
- /**
- * Stores a value identified by a key into cache if the cache does not contain this key.
- * This is the implementation of the method declared in the parent class.
- *
- * @param string the key identifying the value to be cached
- * @param string the value to be cached
- * @param integer the number of seconds in which the cached value will expire. 0 means never expire.
- * @return boolean true if the value is successfully stored into cache, false otherwise
- */
- protected function addValue($key,$value,$expire)
- {
- if(function_exists('apc_add')) {
- return apc_add($key,$value,$expire);
- } else {
- throw new TNotSupportedException('apccache_add_unsupported');
- }
- }
-
- /**
- * Deletes a value with the specified key from cache
- * This is the implementation of the method declared in the parent class.
- * @param string the key of the value to be deleted
- * @return boolean if no error happens during deletion
- */
- protected function deleteValue($key)
- {
- return apc_delete($key);
- }
-
- /**
- * Deletes all values from cache.
- * Be careful of performing this operation if the cache is shared by multiple applications.
- */
- public function flush()
- {
- return apc_clear_cache('user');
- }
-}
-
+<?php
+/**
+ * TAPCCache class file
+ *
+ * @author Alban Hanry <compte_messagerie@hotmail.com>
+ * @link http://www.pradosoft.com/
+ * @copyright Copyright &copy; 2005-2012 PradoSoft
+ * @license http://www.pradosoft.com/license/
+ * @version $Id$
+ * @package System.Caching
+ */
+
+/**
+ * TAPCCache class
+ *
+ * TAPCCache implements a cache application module based on {@link http://www.php.net/apc APC}.
+ *
+ * By definition, cache does not ensure the existence of a value
+ * even if it never expires. Cache is not meant to be an persistent storage.
+ *
+ * To use this module, the APC PHP extension must be loaded and set in the php.ini file the following:
+ * <code>
+ * apc.cache_by_default=0
+ * </code>
+ *
+ * Some usage examples of TAPCCache are as follows,
+ * <code>
+ * $cache=new TAPCCache; // TAPCCache may also be loaded as a Prado application module
+ * $cache->init(null);
+ * $cache->add('object',$object);
+ * $object2=$cache->get('object');
+ * </code>
+ *
+ * If loaded, TAPCCache will register itself with {@link TApplication} as the
+ * cache module. It can be accessed via {@link TApplication::getCache()}.
+ *
+ * TAPCCache may be configured in application configuration file as follows
+ * <code>
+ * <module id="cache" class="System.Caching.TAPCCache" />
+ * </code>
+ *
+ * @author Alban Hanry <compte_messagerie@hotmail.com>
+ * @author Knut Urdalen <knut.urdalen@gmail.com>
+ * @version $Id$
+ * @package System.Caching
+ * @since 3.0b
+ */
+class TAPCCache extends TCache
+{
+ /**
+ * Initializes this module.
+ * This method is required by the IModule interface.
+ * @param TXmlElement configuration for this module, can be null
+ * @throws TConfigurationException if apc extension is not installed or not started, check your php.ini
+ */
+ public function init($config)
+ {
+ if(!extension_loaded('apc'))
+ throw new TConfigurationException('apccache_extension_required');
+
+ if(ini_get('apc.enabled') == false)
+ throw new TConfigurationException('apccache_extension_not_enabled');
+
+ if(substr(php_sapi_name(), 0, 3) === 'cli' and ini_get('apc.enable_cli') == false)
+ throw new TConfigurationException('apccache_extension_not_enabled_cli');
+
+ parent::init($config);
+ }
+
+ /**
+ * Retrieves a value from cache with a specified key.
+ * This is the implementation of the method declared in the parent class.
+ * @param string a unique key identifying the cached value
+ * @return string the value stored in cache, false if the value is not in the cache or expired.
+ */
+ protected function getValue($key)
+ {
+ return apc_fetch($key);
+ }
+
+ /**
+ * Stores a value identified by a key in cache.
+ * This is the implementation of the method declared in the parent class.
+ *
+ * @param string the key identifying the value to be cached
+ * @param string the value to be cached
+ * @param integer the number of seconds in which the cached value will expire. 0 means never expire.
+ * @return boolean true if the value is successfully stored into cache, false otherwise
+ */
+ protected function setValue($key,$value,$expire)
+ {
+ return apc_store($key,$value,$expire);
+ }
+
+ /**
+ * Stores a value identified by a key into cache if the cache does not contain this key.
+ * This is the implementation of the method declared in the parent class.
+ *
+ * @param string the key identifying the value to be cached
+ * @param string the value to be cached
+ * @param integer the number of seconds in which the cached value will expire. 0 means never expire.
+ * @return boolean true if the value is successfully stored into cache, false otherwise
+ */
+ protected function addValue($key,$value,$expire)
+ {
+ if(function_exists('apc_add')) {
+ return apc_add($key,$value,$expire);
+ } else {
+ throw new TNotSupportedException('apccache_add_unsupported');
+ }
+ }
+
+ /**
+ * Deletes a value with the specified key from cache
+ * This is the implementation of the method declared in the parent class.
+ * @param string the key of the value to be deleted
+ * @return boolean if no error happens during deletion
+ */
+ protected function deleteValue($key)
+ {
+ return apc_delete($key);
+ }
+
+ /**
+ * Deletes all values from cache.
+ * Be careful of performing this operation if the cache is shared by multiple applications.
+ */
+ public function flush()
+ {
+ return apc_clear_cache('user');
+ }
+}
+
diff --git a/framework/Caching/TCache.php b/framework/Caching/TCache.php
index d4f74bf0..00d69c3c 100644
--- a/framework/Caching/TCache.php
+++ b/framework/Caching/TCache.php
@@ -1,720 +1,720 @@
-<?php
-/**
- * TCache and cache dependency classes.
- *
- * @author Qiang Xue <qiang.xue@gmail.com>
- * @link http://www.pradosoft.com/
- * @copyright Copyright &copy; 2005-2012 PradoSoft
- * @license http://www.pradosoft.com/license/
- * @version $Id$
- * @package System.Caching
- */
-
-Prado::using('System.Collections.TList');
-
-/**
- * TCache class
- *
- * TCache is the base class for cache classes with different cache storage implementation.
- *
- * TCache implements the interface {@link ICache} with the following methods,
- * - {@link get} : retrieve the value with a key (if any) from cache
- * - {@link set} : store the value with a key into cache
- * - {@link add} : store the value only if cache does not have this key
- * - {@link delete} : delete the value with the specified key from cache
- * - {@link flush} : delete all values from cache
- *
- * Each value is associated with an expiration time. The {@link get} operation
- * ensures that any expired value will not be returned. The expiration time by
- * the number of seconds. A expiration time 0 represents never expire.
- *
- * By definition, cache does not ensure the existence of a value
- * even if it never expires. Cache is not meant to be an persistent storage.
- *
- * Child classes must implement the following methods:
- * - {@link getValue}
- * - {@link setValue}
- * - {@link addValue}
- * - {@link deleteValue}
- * and optionally {@link flush}
- *
- * Since version 3.1.2, TCache implements the ArrayAccess interface such that
- * the cache acts as an array.
- *
- * @author Qiang Xue <qiang.xue@gmail.com>
- * @version $Id$
- * @package System.Caching
- * @since 3.0
- */
-abstract class TCache extends TModule implements ICache, ArrayAccess
-{
- private $_prefix=null;
- private $_primary=true;
-
- /**
- * Initializes the cache module.
- * This method initializes the cache key prefix and registers the cache module
- * with the application if the cache is primary.
- * @param TXmlElement the module configuration
- */
- public function init($config)
- {
- if($this->_prefix===null)
- $this->_prefix=$this->getApplication()->getUniqueID();
- if($this->_primary)
- {
- if($this->getApplication()->getCache()===null)
- $this->getApplication()->setCache($this);
- else
- throw new TConfigurationException('cache_primary_duplicated',get_class($this));
- }
- }
-
- /**
- * @return boolean whether this cache module is used as primary/system cache.
- * A primary cache is used by PRADO core framework to cache data such as
- * parsed templates, themes, etc.
- */
- public function getPrimaryCache()
- {
- return $this->_primary;
- }
-
- /**
- * @param boolean whether this cache module is used as primary/system cache. Defaults to false.
- * @see getPrimaryCache
- */
- public function setPrimaryCache($value)
- {
- $this->_primary=TPropertyValue::ensureBoolean($value);
- }
-
- /**
- * @return string a unique prefix for the keys of cached values.
- * If it is not explicitly set, it will take the value of {@link TApplication::getUniqueID}.
- */
- public function getKeyPrefix()
- {
- return $this->_prefix;
- }
-
- /**
- * @param string a unique prefix for the keys of cached values
- */
- public function setKeyPrefix($value)
- {
- $this->_prefix=$value;
- }
-
- /**
- * @param string a key identifying a value to be cached
- * @return sring a key generated from the provided key which ensures the uniqueness across applications
- */
- protected function generateUniqueKey($key)
- {
- return md5($this->_prefix.$key);
- }
-
- /**
- * Retrieves a value from cache with a specified key.
- * @param string a key identifying the cached value
- * @return mixed the value stored in cache, false if the value is not in the cache or expired.
- */
- public function get($id)
- {
- if(($data=$this->getValue($this->generateUniqueKey($id)))!==false)
- {
- if(!is_array($data))
- return false;
- if(!($data[1] instanceof ICacheDependency) || !$data[1]->getHasChanged())
- return $data[0];
- }
- return false;
- }
-
- /**
- * Stores a value identified by a key into cache.
- * If the cache already contains such a key, the existing value and
- * expiration time will be replaced with the new ones. If the value is
- * empty, the cache key will be deleted.
- *
- * @param string the key identifying the value to be cached
- * @param mixed the value to be cached
- * @param integer the number of seconds in which the cached value will expire. 0 means never expire.
- * @param ICacheDependency dependency of the cached item. If the dependency changes, the item is labeled invalid.
- * @return boolean true if the value is successfully stored into cache, false otherwise
- */
- public function set($id,$value,$expire=0,$dependency=null)
- {
- if(empty($value) && $expire === 0)
- $this->delete($id);
- else
- {
- $data=array($value,$dependency);
- return $this->setValue($this->generateUniqueKey($id),$data,$expire);
- }
- }
-
- /**
- * Stores a value identified by a key into cache if the cache does not contain this key.
- * Nothing will be done if the cache already contains the key or if value is empty.
- * @param string the key identifying the value to be cached
- * @param mixed the value to be cached
- * @param integer the number of seconds in which the cached value will expire. 0 means never expire.
- * @param ICacheDependency dependency of the cached item. If the dependency changes, the item is labeled invalid.
- * @return boolean true if the value is successfully stored into cache, false otherwise
- */
- public function add($id,$value,$expire=0,$dependency=null)
- {
- if(empty($value) && $expire === 0)
- return false;
- $data=array($value,$dependency);
- return $this->addValue($this->generateUniqueKey($id),$data,$expire);
- }
-
- /**
- * Deletes a value with the specified key from cache
- * @param string the key of the value to be deleted
- * @return boolean if no error happens during deletion
- */
- public function delete($id)
- {
- return $this->deleteValue($this->generateUniqueKey($id));
- }
-
- /**
- * Deletes all values from cache.
- * Be careful of performing this operation if the cache is shared by multiple applications.
- * Child classes may implement this method to realize the flush operation.
- * @throws TNotSupportedException if this method is not overridden by child classes
- */
- public function flush()
- {
- throw new TNotSupportedException('cache_flush_unsupported');
- }
-
- /**
- * Retrieves a value from cache with a specified key.
- * This method should be implemented by child classes to store the data
- * in specific cache storage. The uniqueness and dependency are handled
- * in {@link get()} already. So only the implementation of data retrieval
- * is needed.
- * @param string a unique key identifying the cached value
- * @return string the value stored in cache, false if the value is not in the cache or expired.
- */
- abstract protected function getValue($key);
-
- /**
- * Stores a value identified by a key in cache.
- * This method should be implemented by child classes to store the data
- * in specific cache storage. The uniqueness and dependency are handled
- * in {@link set()} already. So only the implementation of data storage
- * is needed.
- *
- * @param string the key identifying the value to be cached
- * @param string the value to be cached
- * @param integer the number of seconds in which the cached value will expire. 0 means never expire.
- * @return boolean true if the value is successfully stored into cache, false otherwise
- */
- abstract protected function setValue($key,$value,$expire);
-
- /**
- * Stores a value identified by a key into cache if the cache does not contain this key.
- * This method should be implemented by child classes to store the data
- * in specific cache storage. The uniqueness and dependency are handled
- * in {@link add()} already. So only the implementation of data storage
- * is needed.
- *
- * @param string the key identifying the value to be cached
- * @param string the value to be cached
- * @param integer the number of seconds in which the cached value will expire. 0 means never expire.
- * @return boolean true if the value is successfully stored into cache, false otherwise
- */
- abstract protected function addValue($key,$value,$expire);
-
- /**
- * Deletes a value with the specified key from cache
- * This method should be implemented by child classes to delete the data from actual cache storage.
- * @param string the key of the value to be deleted
- * @return boolean if no error happens during deletion
- */
- abstract protected function deleteValue($key);
-
- /**
- * Returns whether there is a cache entry with a specified key.
- * This method is required by the interface ArrayAccess.
- * @param string a key identifying the cached value
- * @return boolean
- */
- public function offsetExists($id)
- {
- return $this->get($id) !== false;
- }
-
- /**
- * Retrieves the value from cache with a specified key.
- * This method is required by the interface ArrayAccess.
- * @param string a key identifying the cached value
- * @return mixed the value stored in cache, false if the value is not in the cache or expired.
- */
- public function offsetGet($id)
- {
- return $this->get($id);
- }
-
- /**
- * Stores the value identified by a key into cache.
- * If the cache already contains such a key, the existing value will be
- * replaced with the new ones. To add expiration and dependencies, use the set() method.
- * This method is required by the interface ArrayAccess.
- * @param string the key identifying the value to be cached
- * @param mixed the value to be cached
- */
- public function offsetSet($id, $value)
- {
- $this->set($id, $value);
- }
-
- /**
- * Deletes the value with the specified key from cache
- * This method is required by the interface ArrayAccess.
- * @param string the key of the value to be deleted
- * @return boolean if no error happens during deletion
- */
- public function offsetUnset($id)
- {
- $this->delete($id);
- }
-}
-
-
-/**
- * TCacheDependency class.
- *
- * TCacheDependency is the base class implementing {@link ICacheDependency} interface.
- * Descendant classes must implement {@link getHasChanged()} to provide
- * actual dependency checking logic.
- *
- * The property value of {@link getHasChanged HasChanged} tells whether
- * the dependency is changed or not.
- *
- * You may disable the dependency checking by setting {@link setEnabled Enabled}
- * to false.
- *
- * Note, since the dependency objects often need to be serialized so that
- * they can persist across requests, you may need to implement __sleep() and
- * __wakeup() if the dependency objects contain resource handles which are
- * not serializable.
- *
- * Currently, the following dependency classes are provided in the PRADO release:
- * - {@link TFileCacheDependency}: checks whether a file is changed or not
- * - {@link TDirectoryCacheDependency}: checks whether a directory is changed or not
- * - {@link TGlobalStateCacheDependency}: checks whether a global state is changed or not
- * - {@link TChainedCacheDependency}: checks whether any of a list of dependencies is changed or not
- *
- * @author Qiang Xue <qiang.xue@gmail.com>
- * @version $Id$
- * @package System.Caching
- * @since 3.1.0
- */
-abstract class TCacheDependency extends TComponent implements ICacheDependency
-{
-}
-
-
-/**
- * TFileCacheDependency class.
- *
- * TFileCacheDependency performs dependency checking based on the
- * last modification time of the file specified via {@link setFileName FileName}.
- * The dependency is reported as unchanged if and only if the file's
- * last modification time remains unchanged.
- *
- * @author Qiang Xue <qiang.xue@gmail.com>
- * @version $Id$
- * @package System.Caching
- * @since 3.1.0
- */
-class TFileCacheDependency extends TCacheDependency
-{
- private $_fileName;
- private $_timestamp;
-
- /**
- * Constructor.
- * @param string name of the file whose change is to be checked.
- */
- public function __construct($fileName)
- {
- $this->setFileName($fileName);
- }
-
- /**
- * @return string the name of the file whose change is to be checked
- */
- public function getFileName()
- {
- return $this->_fileName;
- }
-
- /**
- * @param string the name of the file whose change is to be checked
- */
- public function setFileName($value)
- {
- $this->_fileName=$value;
- $this->_timestamp=@filemtime($value);
- }
-
- /**
- * @return int the last modification time of the file
- */
- public function getTimestamp()
- {
- return $this->_timestamp;
- }
-
- /**
- * Performs the actual dependency checking.
- * This method returns true if the last modification time of the file is changed.
- * @return boolean whether the dependency is changed or not.
- */
- public function getHasChanged()
- {
- return @filemtime($this->_fileName)!==$this->_timestamp;
- }
-}
-
-/**
- * TDirectoryCacheDependency class.
- *
- * TDirectoryCacheDependency performs dependency checking based on the
- * modification time of the files contained in the specified directory.
- * The directory being checked is specified via {@link setDirectory Directory}.
- *
- * By default, all files under the specified directory and subdirectories
- * will be checked. If the last modification time of any of them is changed
- * or if different number of files are contained in a directory, the dependency
- * is reported as changed. By specifying {@link setRecursiveCheck RecursiveCheck}
- * and {@link setRecursiveLevel RecursiveLevel}, one can limit the checking
- * to a certain depth of the subdirectories.
- *
- * @author Qiang Xue <qiang.xue@gmail.com>
- * @version $Id$
- * @package System.Caching
- * @since 3.1.0
- */
-class TDirectoryCacheDependency extends TCacheDependency
-{
- private $_recursiveCheck=true;
- private $_recursiveLevel=-1;
- private $_timestamps;
- private $_directory;
-
- /**
- * Constructor.
- * @param string the directory to be checked
- */
- public function __construct($directory)
- {
- $this->setDirectory($directory);
- }
-
- /**
- * @return string the directory to be checked
- */
- public function getDirectory()
- {
- return $this->_directory;
- }
-
- /**
- * @param string the directory to be checked
- * @throws TInvalidDataValueException if the directory does not exist
- */
- public function setDirectory($directory)
- {
- if(($path=realpath($directory))===false || !is_dir($path))
- throw new TInvalidDataValueException('directorycachedependency_directory_invalid',$directory);
- $this->_directory=$path;
- $this->_timestamps=$this->generateTimestamps($path);
- }
-
- /**
- * @return boolean whether the subdirectories of the directory will also be checked.
- * It defaults to true.
- */
- public function getRecursiveCheck()
- {
- return $this->_recursiveCheck;
- }
-
- /**
- * @param boolean whether the subdirectories of the directory will also be checked.
- */
- public function setRecursiveCheck($value)
- {
- $this->_recursiveCheck=TPropertyValue::ensureBoolean($value);
- }
-
- /**
- * @return int the depth of the subdirectories to be checked.
- * It defaults to -1, meaning unlimited depth.
- */
- public function getRecursiveLevel()
- {
- return $this->_recursiveLevel;
- }
-
- /**
- * Sets a value indicating the depth of the subdirectories to be checked.
- * This is meaningful only when {@link getRecursiveCheck RecursiveCheck}
- * is true.
- * @param int the depth of the subdirectories to be checked.
- * If the value is less than 0, it means unlimited depth.
- * If the value is 0, it means checking the files directly under the specified directory.
- */
- public function setRecursiveLevel($value)
- {
- $this->_recursiveLevel=TPropertyValue::ensureInteger($value);
- }
-
- /**
- * Performs the actual dependency checking.
- * This method returns true if the directory is changed.
- * @return boolean whether the dependency is changed or not.
- */
- public function getHasChanged()
- {
- return $this->generateTimestamps($this->_directory)!=$this->_timestamps;
- }
-
- /**
- * Checks to see if the file should be checked for dependency.
- * This method is invoked when dependency of the whole directory is being checked.
- * By default, it always returns true, meaning the file should be checked.
- * You may override this method to check only certain files.
- * @param string the name of the file that may be checked for dependency.
- * @return boolean whether this file should be checked.
- */
- protected function validateFile($fileName)
- {
- return true;
- }
-
- /**
- * Checks to see if the specified subdirectory should be checked for dependency.
- * This method is invoked when dependency of the whole directory is being checked.
- * By default, it always returns true, meaning the subdirectory should be checked.
- * You may override this method to check only certain subdirectories.
- * @param string the name of the subdirectory that may be checked for dependency.
- * @return boolean whether this subdirectory should be checked.
- */
- protected function validateDirectory($directory)
- {
- return true;
- }
-
- /**
- * Determines the last modification time for files under the directory.
- * This method may go recursively into subdirectories if
- * {@link setRecursiveCheck RecursiveCheck} is set true.
- * @param string the directory name
- * @param int level of the recursion
- * @return array list of file modification time indexed by the file path
- */
- protected function generateTimestamps($directory,$level=0)
- {
- if(($dir=opendir($directory))===false)
- throw new TIOException('directorycachedependency_directory_invalid',$directory);
- $timestamps=array();
- while(($file=readdir($dir))!==false)
- {
- $path=$directory.DIRECTORY_SEPARATOR.$file;
- if($file==='.' || $file==='..')
- continue;
- else if(is_dir($path))
- {
- if(($this->_recursiveLevel<0 || $level<$this->_recursiveLevel) && $this->validateDirectory($path))
- $timestamps=array_merge($this->generateTimestamps($path,$level+1));
- }
- else if($this->validateFile($path))
- $timestamps[$path]=filemtime($path);
- }
- closedir($dir);
- return $timestamps;
- }
-}
-
-
-/**
- * TGlobalStateCacheDependency class.
- *
- * TGlobalStateCacheDependency checks if a global state is changed or not.
- * If the global state is changed, the dependency is reported as changed.
- * To specify which global state this dependency should check with,
- * set {@link setStateName StateName} to the name of the global state.
- *
- * @author Qiang Xue <qiang.xue@gmail.com>
- * @version $Id$
- * @package System.Caching
- * @since 3.1.0
- */
-class TGlobalStateCacheDependency extends TCacheDependency
-{
- private $_stateName;
- private $_stateValue;
-
- /**
- * Constructor.
- * @param string the name of the global state
- */
- public function __construct($name)
- {
- $this->setStateName($name);
- }
-
- /**
- * @return string the name of the global state
- */
- public function getStateName()
- {
- return $this->_stateName;
- }
-
- /**
- * @param string the name of the global state
- * @see TApplication::setGlobalState
- */
- public function setStateName($value)
- {
- $this->_stateName=$value;
- $this->_stateValue=Prado::getApplication()->getGlobalState($value);
- }
-
- /**
- * Performs the actual dependency checking.
- * This method returns true if the specified global state is changed.
- * @return boolean whether the dependency is changed or not.
- */
- public function getHasChanged()
- {
- return $this->_stateValue!==Prado::getApplication()->getGlobalState($this->_stateName);
- }
-}
-
-
-/**
- * TChainedCacheDependency class.
- *
- * TChainedCacheDependency represents a list of cache dependency objects
- * and performs the dependency checking based on the checking results of
- * these objects. If any of them reports a dependency change, TChainedCacheDependency
- * will return true for the checking.
- *
- * To add dependencies to TChainedCacheDependency, use {@link getDependencies Dependencies}
- * which gives a {@link TCacheDependencyList} instance and can be used like an array
- * (see {@link TList} for more details}).
- *
- * @author Qiang Xue <qiang.xue@gmail.com>
- * @version $Id$
- * @package System.Caching
- * @since 3.1.0
- */
-class TChainedCacheDependency extends TCacheDependency
-{
- private $_dependencies=null;
-
- /**
- * @return TCacheDependencyList list of dependency objects
- */
- public function getDependencies()
- {
- if($this->_dependencies===null)
- $this->_dependencies=new TCacheDependencyList;
- return $this->_dependencies;
- }
-
- /**
- * Performs the actual dependency checking.
- * This method returns true if any of the dependency objects
- * reports a dependency change.
- * @return boolean whether the dependency is changed or not.
- */
- public function getHasChanged()
- {
- if($this->_dependencies!==null)
- {
- foreach($this->_dependencies as $dependency)
- if($dependency->getHasChanged())
- return true;
- }
- return false;
- }
-}
-
-
-/**
- * TApplicationStateCacheDependency class.
- *
- * TApplicationStateCacheDependency performs dependency checking based on
- * the mode of the currently running PRADO application.
- * The dependency is reportedly as unchanged if and only if the application
- * is running in performance mode.
- *
- * You may chain this dependency together with other dependencies
- * so that only when the application is not in performance mode the other dependencies
- * will be checked.
- *
- * @author Qiang Xue <qiang.xue@gmail.com>
- * @version $Id$
- * @package System.Caching
- * @since 3.1.0
- */
-class TApplicationStateCacheDependency extends TCacheDependency
-{
- /**
- * Performs the actual dependency checking.
- * This method returns true if the currently running application is not in performance mode.
- * @return boolean whether the dependency is changed or not.
- */
- public function getHasChanged()
- {
- return Prado::getApplication()->getMode()!==TApplicationMode::Performance;
- }
-}
-
-/**
- * TCacheDependencyList class.
- *
- * TCacheDependencyList represents a list of cache dependency objects.
- * Only objects implementing {@link ICacheDependency} can be added into this list.
- *
- * TCacheDependencyList can be used like an array. See {@link TList}
- * for more details.
- *
- * @author Qiang Xue <qiang.xue@gmail.com>
- * @version $Id$
- * @package System.Caching
- * @since 3.1.0
- */
-class TCacheDependencyList extends TList
-{
- /**
- * Inserts an item at the specified position.
- * This overrides the parent implementation by performing additional type checking
- * for each newly added item.
- * @param integer the specified position.
- * @param mixed new item
- * @throws TInvalidDataTypeException if the item to be inserted is not a dependency instance
- */
- public function insertAt($index,$item)
- {
- if($item instanceof ICacheDependency)
- parent::insertAt($index,$item);
- else
- throw new TInvalidDataTypeException('cachedependencylist_cachedependency_required');
- }
-}
-
-?>
+<?php
+/**
+ * TCache and cache dependency classes.
+ *
+ * @author Qiang Xue <qiang.xue@gmail.com>
+ * @link http://www.pradosoft.com/
+ * @copyright Copyright &copy; 2005-2012 PradoSoft
+ * @license http://www.pradosoft.com/license/
+ * @version $Id$
+ * @package System.Caching
+ */
+
+Prado::using('System.Collections.TList');
+
+/**
+ * TCache class
+ *
+ * TCache is the base class for cache classes with different cache storage implementation.
+ *
+ * TCache implements the interface {@link ICache} with the following methods,
+ * - {@link get} : retrieve the value with a key (if any) from cache
+ * - {@link set} : store the value with a key into cache
+ * - {@link add} : store the value only if cache does not have this key
+ * - {@link delete} : delete the value with the specified key from cache
+ * - {@link flush} : delete all values from cache
+ *
+ * Each value is associated with an expiration time. The {@link get} operation
+ * ensures that any expired value will not be returned. The expiration time by
+ * the number of seconds. A expiration time 0 represents never expire.
+ *
+ * By definition, cache does not ensure the existence of a value
+ * even if it never expires. Cache is not meant to be an persistent storage.
+ *
+ * Child classes must implement the following methods:
+ * - {@link getValue}
+ * - {@link setValue}
+ * - {@link addValue}
+ * - {@link deleteValue}
+ * and optionally {@link flush}
+ *
+ * Since version 3.1.2, TCache implements the ArrayAccess interface such that
+ * the cache acts as an array.
+ *
+ * @author Qiang Xue <qiang.xue@gmail.com>
+ * @version $Id$
+ * @package System.Caching
+ * @since 3.0
+ */
+abstract class TCache extends TModule implements ICache, ArrayAccess
+{
+ private $_prefix=null;
+ private $_primary=true;
+
+ /**
+ * Initializes the cache module.
+ * This method initializes the cache key prefix and registers the cache module
+ * with the application if the cache is primary.
+ * @param TXmlElement the module configuration
+ */
+ public function init($config)
+ {
+ if($this->_prefix===null)
+ $this->_prefix=$this->getApplication()->getUniqueID();
+ if($this->_primary)
+ {
+ if($this->getApplication()->getCache()===null)
+ $this->getApplication()->setCache($this);
+ else
+ throw new TConfigurationException('cache_primary_duplicated',get_class($this));
+ }
+ }
+
+ /**
+ * @return boolean whether this cache module is used as primary/system cache.
+ * A primary cache is used by PRADO core framework to cache data such as
+ * parsed templates, themes, etc.
+ */
+ public function getPrimaryCache()
+ {
+ return $this->_primary;
+ }
+
+ /**
+ * @param boolean whether this cache module is used as primary/system cache. Defaults to false.
+ * @see getPrimaryCache
+ */
+ public function setPrimaryCache($value)
+ {
+ $this->_primary=TPropertyValue::ensureBoolean($value);
+ }
+
+ /**
+ * @return string a unique prefix for the keys of cached values.
+ * If it is not explicitly set, it will take the value of {@link TApplication::getUniqueID}.
+ */
+ public function getKeyPrefix()
+ {
+ return $this->_prefix;
+ }
+
+ /**
+ * @param string a unique prefix for the keys of cached values
+ */
+ public function setKeyPrefix($value)
+ {
+ $this->_prefix=$value;
+ }
+
+ /**
+ * @param string a key identifying a value to be cached
+ * @return sring a key generated from the provided key which ensures the uniqueness across applications
+ */
+ protected function generateUniqueKey($key)
+ {
+ return md5($this->_prefix.$key);
+ }
+
+ /**
+ * Retrieves a value from cache with a specified key.
+ * @param string a key identifying the cached value
+ * @return mixed the value stored in cache, false if the value is not in the cache or expired.
+ */
+ public function get($id)
+ {
+ if(($data=$this->getValue($this->generateUniqueKey($id)))!==false)
+ {
+ if(!is_array($data))
+ return false;
+ if(!($data[1] instanceof ICacheDependency) || !$data[1]->getHasChanged())
+ return $data[0];
+ }
+ return false;
+ }
+
+ /**
+ * Stores a value identified by a key into cache.
+ * If the cache already contains such a key, the existing value and
+ * expiration time will be replaced with the new ones. If the value is
+ * empty, the cache key will be deleted.
+ *
+ * @param string the key identifying the value to be cached
+ * @param mixed the value to be cached
+ * @param integer the number of seconds in which the cached value will expire. 0 means never expire.
+ * @param ICacheDependency dependency of the cached item. If the dependency changes, the item is labeled invalid.
+ * @return boolean true if the value is successfully stored into cache, false otherwise
+ */
+ public function set($id,$value,$expire=0,$dependency=null)
+ {
+ if(empty($value) && $expire === 0)
+ $this->delete($id);
+ else
+ {
+ $data=array($value,$dependency);
+ return $this->setValue($this->generateUniqueKey($id),$data,$expire);
+ }
+ }
+
+ /**
+ * Stores a value identified by a key into cache if the cache does not contain this key.
+ * Nothing will be done if the cache already contains the key or if value is empty.
+ * @param string the key identifying the value to be cached
+ * @param mixed the value to be cached
+ * @param integer the number of seconds in which the cached value will expire. 0 means never expire.
+ * @param ICacheDependency dependency of the cached item. If the dependency changes, the item is labeled invalid.
+ * @return boolean true if the value is successfully stored into cache, false otherwise
+ */
+ public function add($id,$value,$expire=0,$dependency=null)
+ {
+ if(empty($value) && $expire === 0)
+ return false;
+ $data=array($value,$dependency);
+ return $this->addValue($this->generateUniqueKey($id),$data,$expire);
+ }
+
+ /**
+ * Deletes a value with the specified key from cache
+ * @param string the key of the value to be deleted
+ * @return boolean if no error happens during deletion
+ */
+ public function delete($id)
+ {
+ return $this->deleteValue($this->generateUniqueKey($id));
+ }
+
+ /**
+ * Deletes all values from cache.
+ * Be careful of performing this operation if the cache is shared by multiple applications.
+ * Child classes may implement this method to realize the flush operation.
+ * @throws TNotSupportedException if this method is not overridden by child classes
+ */
+ public function flush()
+ {
+ throw new TNotSupportedException('cache_flush_unsupported');
+ }
+
+ /**
+ * Retrieves a value from cache with a specified key.
+ * This method should be implemented by child classes to store the data
+ * in specific cache storage. The uniqueness and dependency are handled
+ * in {@link get()} already. So only the implementation of data retrieval
+ * is needed.
+ * @param string a unique key identifying the cached value
+ * @return string the value stored in cache, false if the value is not in the cache or expired.
+ */
+ abstract protected function getValue($key);
+
+ /**
+ * Stores a value identified by a key in cache.
+ * This method should be implemented by child classes to store the data
+ * in specific cache storage. The uniqueness and dependency are handled
+ * in {@link set()} already. So only the implementation of data storage
+ * is needed.
+ *
+ * @param string the key identifying the value to be cached
+ * @param string the value to be cached
+ * @param integer the number of seconds in which the cached value will expire. 0 means never expire.
+ * @return boolean true if the value is successfully stored into cache, false otherwise
+ */
+ abstract protected function setValue($key,$value,$expire);
+
+ /**
+ * Stores a value identified by a key into cache if the cache does not contain this key.
+ * This method should be implemented by child classes to store the data
+ * in specific cache storage. The uniqueness and dependency are handled
+ * in {@link add()} already. So only the implementation of data storage
+ * is needed.
+ *
+ * @param string the key identifying the value to be cached
+ * @param string the value to be cached
+ * @param integer the number of seconds in which the cached value will expire. 0 means never expire.
+ * @return boolean true if the value is successfully stored into cache, false otherwise
+ */
+ abstract protected function addValue($key,$value,$expire);
+
+ /**
+ * Deletes a value with the specified key from cache
+ * This method should be implemented by child classes to delete the data from actual cache storage.
+ * @param string the key of the value to be deleted
+ * @return boolean if no error happens during deletion
+ */
+ abstract protected function deleteValue($key);
+
+ /**
+ * Returns whether there is a cache entry with a specified key.
+ * This method is required by the interface ArrayAccess.
+ * @param string a key identifying the cached value
+ * @return boolean
+ */
+ public function offsetExists($id)
+ {
+ return $this->get($id) !== false;
+ }
+
+ /**
+ * Retrieves the value from cache with a specified key.
+ * This method is required by the interface ArrayAccess.
+ * @param string a key identifying the cached value
+ * @return mixed the value stored in cache, false if the value is not in the cache or expired.
+ */
+ public function offsetGet($id)
+ {
+ return $this->get($id);
+ }
+
+ /**
+ * Stores the value identified by a key into cache.
+ * If the cache already contains such a key, the existing value will be
+ * replaced with the new ones. To add expiration and dependencies, use the set() method.
+ * This method is required by the interface ArrayAccess.
+ * @param string the key identifying the value to be cached
+ * @param mixed the value to be cached
+ */
+ public function offsetSet($id, $value)
+ {
+ $this->set($id, $value);
+ }
+
+ /**
+ * Deletes the value with the specified key from cache
+ * This method is required by the interface ArrayAccess.
+ * @param string the key of the value to be deleted
+ * @return boolean if no error happens during deletion
+ */
+ public function offsetUnset($id)
+ {
+ $this->delete($id);
+ }
+}
+
+
+/**
+ * TCacheDependency class.
+ *
+ * TCacheDependency is the base class implementing {@link ICacheDependency} interface.
+ * Descendant classes must implement {@link getHasChanged()} to provide
+ * actual dependency checking logic.
+ *
+ * The property value of {@link getHasChanged HasChanged} tells whether
+ * the dependency is changed or not.
+ *
+ * You may disable the dependency checking by setting {@link setEnabled Enabled}
+ * to false.
+ *
+ * Note, since the dependency objects often need to be serialized so that
+ * they can persist across requests, you may need to implement __sleep() and
+ * __wakeup() if the dependency objects contain resource handles which are
+ * not serializable.
+ *
+ * Currently, the following dependency classes are provided in the PRADO release:
+ * - {@link TFileCacheDependency}: checks whether a file is changed or not
+ * - {@link TDirectoryCacheDependency}: checks whether a directory is changed or not
+ * - {@link TGlobalStateCacheDependency}: checks whether a global state is changed or not
+ * - {@link TChainedCacheDependency}: checks whether any of a list of dependencies is changed or not
+ *
+ * @author Qiang Xue <qiang.xue@gmail.com>
+ * @version $Id$
+ * @package System.Caching
+ * @since 3.1.0
+ */
+abstract class TCacheDependency extends TComponent implements ICacheDependency
+{
+}
+
+
+/**
+ * TFileCacheDependency class.
+ *
+ * TFileCacheDependency performs dependency checking based on the
+ * last modification time of the file specified via {@link setFileName FileName}.
+ * The dependency is reported as unchanged if and only if the file's
+ * last modification time remains unchanged.
+ *
+ * @author Qiang Xue <qiang.xue@gmail.com>
+ * @version $Id$
+ * @package System.Caching
+ * @since 3.1.0
+ */
+class TFileCacheDependency extends TCacheDependency
+{
+ private $_fileName;
+ private $_timestamp;
+
+ /**
+ * Constructor.
+ * @param string name of the file whose change is to be checked.
+ */
+ public function __construct($fileName)
+ {
+ $this->setFileName($fileName);
+ }
+
+ /**
+ * @return string the name of the file whose change is to be checked
+ */
+ public function getFileName()
+ {
+ return $this->_fileName;
+ }
+
+ /**
+ * @param string the name of the file whose change is to be checked
+ */
+ public function setFileName($value)
+ {
+ $this->_fileName=$value;
+ $this->_timestamp=@filemtime($value);
+ }
+
+ /**
+ * @return int the last modification time of the file
+ */
+ public function getTimestamp()
+ {
+ return $this->_timestamp;
+ }
+
+ /**
+ * Performs the actual dependency checking.
+ * This method returns true if the last modification time of the file is changed.
+ * @return boolean whether the dependency is changed or not.
+ */
+ public function getHasChanged()
+ {
+ return @filemtime($this->_fileName)!==$this->_timestamp;
+ }
+}
+
+/**
+ * TDirectoryCacheDependency class.
+ *
+ * TDirectoryCacheDependency performs dependency checking based on the
+ * modification time of the files contained in the specified directory.
+ * The directory being checked is specified via {@link setDirectory Directory}.
+ *
+ * By default, all files under the specified directory and subdirectories
+ * will be checked. If the last modification time of any of them is changed
+ * or if different number of files are contained in a directory, the dependency
+ * is reported as changed. By specifying {@link setRecursiveCheck RecursiveCheck}
+ * and {@link setRecursiveLevel RecursiveLevel}, one can limit the checking
+ * to a certain depth of the subdirectories.
+ *
+ * @author Qiang Xue <qiang.xue@gmail.com>
+ * @version $Id$
+ * @package System.Caching
+ * @since 3.1.0
+ */
+class TDirectoryCacheDependency extends TCacheDependency
+{
+ private $_recursiveCheck=true;
+ private $_recursiveLevel=-1;
+ private $_timestamps;
+ private $_directory;
+
+ /**
+ * Constructor.
+ * @param string the directory to be checked
+ */
+ public function __construct($directory)
+ {
+ $this->setDirectory($directory);
+ }
+
+ /**
+ * @return string the directory to be checked
+ */
+ public function getDirectory()
+ {
+ return $this->_directory;
+ }
+
+ /**
+ * @param string the directory to be checked
+ * @throws TInvalidDataValueException if the directory does not exist
+ */
+ public function setDirectory($directory)
+ {
+ if(($path=realpath($directory))===false || !is_dir($path))
+ throw new TInvalidDataValueException('directorycachedependency_directory_invalid',$directory);
+ $this->_directory=$path;
+ $this->_timestamps=$this->generateTimestamps($path);
+ }
+
+ /**
+ * @return boolean whether the subdirectories of the directory will also be checked.
+ * It defaults to true.
+ */
+ public function getRecursiveCheck()
+ {
+ return $this->_recursiveCheck;
+ }
+
+ /**
+ * @param boolean whether the subdirectories of the directory will also be checked.
+ */
+ public function setRecursiveCheck($value)
+ {
+ $this->_recursiveCheck=TPropertyValue::ensureBoolean($value);
+ }
+
+ /**
+ * @return int the depth of the subdirectories to be checked.
+ * It defaults to -1, meaning unlimited depth.
+ */
+ public function getRecursiveLevel()
+ {
+ return $this->_recursiveLevel;
+ }
+
+ /**
+ * Sets a value indicating the depth of the subdirectories to be checked.
+ * This is meaningful only when {@link getRecursiveCheck RecursiveCheck}
+ * is true.
+ * @param int the depth of the subdirectories to be checked.
+ * If the value is less than 0, it means unlimited depth.
+ * If the value is 0, it means checking the files directly under the specified directory.
+ */
+ public function setRecursiveLevel($value)
+ {
+ $this->_recursiveLevel=TPropertyValue::ensureInteger($value);
+ }
+
+ /**
+ * Performs the actual dependency checking.
+ * This method returns true if the directory is changed.
+ * @return boolean whether the dependency is changed or not.
+ */
+ public function getHasChanged()
+ {
+ return $this->generateTimestamps($this->_directory)!=$this->_timestamps;
+ }
+
+ /**
+ * Checks to see if the file should be checked for dependency.
+ * This method is invoked when dependency of the whole directory is being checked.
+ * By default, it always returns true, meaning the file should be checked.
+ * You may override this method to check only certain files.
+ * @param string the name of the file that may be checked for dependency.
+ * @return boolean whether this file should be checked.
+ */
+ protected function validateFile($fileName)
+ {
+ return true;
+ }
+
+ /**
+ * Checks to see if the specified subdirectory should be checked for dependency.
+ * This method is invoked when dependency of the whole directory is being checked.
+ * By default, it always returns true, meaning the subdirectory should be checked.
+ * You may override this method to check only certain subdirectories.
+ * @param string the name of the subdirectory that may be checked for dependency.
+ * @return boolean whether this subdirectory should be checked.
+ */
+ protected function validateDirectory($directory)
+ {
+ return true;
+ }
+
+ /**
+ * Determines the last modification time for files under the directory.
+ * This method may go recursively into subdirectories if
+ * {@link setRecursiveCheck RecursiveCheck} is set true.
+ * @param string the directory name
+ * @param int level of the recursion
+ * @return array list of file modification time indexed by the file path
+ */
+ protected function generateTimestamps($directory,$level=0)
+ {
+ if(($dir=opendir($directory))===false)
+ throw new TIOException('directorycachedependency_directory_invalid',$directory);
+ $timestamps=array();
+ while(($file=readdir($dir))!==false)
+ {
+ $path=$directory.DIRECTORY_SEPARATOR.$file;
+ if($file==='.' || $file==='..')
+ continue;
+ else if(is_dir($path))
+ {
+ if(($this->_recursiveLevel<0 || $level<$this->_recursiveLevel) && $this->validateDirectory($path))
+ $timestamps=array_merge($this->generateTimestamps($path,$level+1));
+ }
+ else if($this->validateFile($path))
+ $timestamps[$path]=filemtime($path);
+ }
+ closedir($dir);
+ return $timestamps;
+ }
+}
+
+
+/**
+ * TGlobalStateCacheDependency class.
+ *
+ * TGlobalStateCacheDependency checks if a global state is changed or not.
+ * If the global state is changed, the dependency is reported as changed.
+ * To specify which global state this dependency should check with,
+ * set {@link setStateName StateName} to the name of the global state.
+ *
+ * @author Qiang Xue <qiang.xue@gmail.com>
+ * @version $Id$
+ * @package System.Caching
+ * @since 3.1.0
+ */
+class TGlobalStateCacheDependency extends TCacheDependency
+{
+ private $_stateName;
+ private $_stateValue;
+
+ /**
+ * Constructor.
+ * @param string the name of the global state
+ */
+ public function __construct($name)
+ {
+ $this->setStateName($name);
+ }
+
+ /**
+ * @return string the name of the global state
+ */
+ public function getStateName()
+ {
+ return $this->_stateName;
+ }
+
+ /**
+ * @param string the name of the global state
+ * @see TApplication::setGlobalState
+ */
+ public function setStateName($value)
+ {
+ $this->_stateName=$value;
+ $this->_stateValue=Prado::getApplication()->getGlobalState($value);
+ }
+
+ /**
+ * Performs the actual dependency checking.
+ * This method returns true if the specified global state is changed.
+ * @return boolean whether the dependency is changed or not.
+ */
+ public function getHasChanged()
+ {
+ return $this->_stateValue!==Prado::getApplication()->getGlobalState($this->_stateName);
+ }
+}
+
+
+/**
+ * TChainedCacheDependency class.
+ *
+ * TChainedCacheDependency represents a list of cache dependency objects
+ * and performs the dependency checking based on the checking results of
+ * these objects. If any of them reports a dependency change, TChainedCacheDependency
+ * will return true for the checking.
+ *
+ * To add dependencies to TChainedCacheDependency, use {@link getDependencies Dependencies}
+ * which gives a {@link TCacheDependencyList} instance and can be used like an array
+ * (see {@link TList} for more details}).
+ *
+ * @author Qiang Xue <qiang.xue@gmail.com>
+ * @version $Id$
+ * @package System.Caching
+ * @since 3.1.0
+ */
+class TChainedCacheDependency extends TCacheDependency
+{
+ private $_dependencies=null;
+
+ /**
+ * @return TCacheDependencyList list of dependency objects
+ */
+ public function getDependencies()
+ {
+ if($this->_dependencies===null)
+ $this->_dependencies=new TCacheDependencyList;
+ return $this->_dependencies;
+ }
+
+ /**
+ * Performs the actual dependency checking.
+ * This method returns true if any of the dependency objects
+ * reports a dependency change.
+ * @return boolean whether the dependency is changed or not.
+ */
+ public function getHasChanged()
+ {
+ if($this->_dependencies!==null)
+ {
+ foreach($this->_dependencies as $dependency)
+ if($dependency->getHasChanged())
+ return true;
+ }
+ return false;
+ }
+}
+
+
+/**
+ * TApplicationStateCacheDependency class.
+ *
+ * TApplicationStateCacheDependency performs dependency checking based on
+ * the mode of the currently running PRADO application.
+ * The dependency is reportedly as unchanged if and only if the application
+ * is running in performance mode.
+ *
+ * You may chain this dependency together with other dependencies
+ * so that only when the application is not in performance mode the other dependencies
+ * will be checked.
+ *
+ * @author Qiang Xue <qiang.xue@gmail.com>
+ * @version $Id$
+ * @package System.Caching
+ * @since 3.1.0
+ */
+class TApplicationStateCacheDependency extends TCacheDependency
+{
+ /**
+ * Performs the actual dependency checking.
+ * This method returns true if the currently running application is not in performance mode.
+ * @return boolean whether the dependency is changed or not.
+ */
+ public function getHasChanged()
+ {
+ return Prado::getApplication()->getMode()!==TApplicationMode::Performance;
+ }
+}
+
+/**
+ * TCacheDependencyList class.
+ *
+ * TCacheDependencyList represents a list of cache dependency objects.
+ * Only objects implementing {@link ICacheDependency} can be added into this list.
+ *
+ * TCacheDependencyList can be used like an array. See {@link TList}
+ * for more details.
+ *
+ * @author Qiang Xue <qiang.xue@gmail.com>
+ * @version $Id$
+ * @package System.Caching
+ * @since 3.1.0
+ */
+class TCacheDependencyList extends TList
+{
+ /**
+ * Inserts an item at the specified position.
+ * This overrides the parent implementation by performing additional type checking
+ * for each newly added item.
+ * @param integer the specified position.
+ * @param mixed new item
+ * @throws TInvalidDataTypeException if the item to be inserted is not a dependency instance
+ */
+ public function insertAt($index,$item)
+ {
+ if($item instanceof ICacheDependency)
+ parent::insertAt($index,$item);
+ else
+ throw new TInvalidDataTypeException('cachedependencylist_cachedependency_required');
+ }
+}
+
+?>
diff --git a/framework/Caching/TDbCache.php b/framework/Caching/TDbCache.php
index 7a149346..b4ddd086 100644
--- a/framework/Caching/TDbCache.php
+++ b/framework/Caching/TDbCache.php
@@ -1,578 +1,578 @@
-<?php
-/**
- * TDbCache class file
- *
- * @author Qiang Xue <qiang.xue@gmail.com>
- * @link http://www.pradosoft.com/
- * @copyright Copyright &copy; 2005-2012 PradoSoft
- * @license http://www.pradosoft.com/license/
- * @version $Id$
- * @package System.Caching
- */
-
-Prado::using('System.Data.TDbConnection');
-
-/**
- * TDbCache class
- *
- * TDbCache implements a cache application module by storing cached data in a database.
- *
- * TDbCache relies on {@link http://www.php.net/manual/en/ref.pdo.php PDO} to retrieve
- * data from databases. In order to use TDbCache, you need to enable the PDO extension
- * as well as the corresponding PDO DB driver. For example, to use SQLite database
- * to store cached data, you need both php_pdo and php_pdo_sqlite extensions.
- *
- * By default, TDbCache creates and uses an SQLite database under the application
- * runtime directory. You may change this default setting by specifying the following
- * properties:
- * - {@link setConnectionID ConnectionID} or
- * - {@link setConnectionString ConnectionString}, {@link setUsername Username} and {@link setPassword Pasword}.
- *
- * The cached data is stored in a table in the specified database.
- * By default, the name of the table is called 'pradocache'. If the table does not
- * exist in the database, it will be automatically created with the following structure:
- * <code>
- * CREATE TABLE pradocache (itemkey CHAR(128), value BLOB, expire INT)
- * CREATE INDEX IX_itemkey ON pradocache (itemkey)
- * CREATE INDEX IX_expire ON pradocache (expire)
- * </code>
- *
- * Note, some DBMS might not support BLOB type. In this case, replace 'BLOB' with a suitable
- * binary data type (e.g. LONGBLOB in MySQL, BYTEA in PostgreSQL.)
- *
- * Important: Make sure that the indices are non-unique!
- *
- * If you want to change the cache table name, or if you want to create the table by yourself,
- * you may set {@link setCacheTableName CacheTableName} and {@link setAutoCreateCacheTable AutoCreateCacheTableName} properties.
- *
- * {@link setFlushInterval FlushInterval} control how often expired items will be removed from cache.
- * If you prefer to remove expired items manualy e.g. via cronjob you can disable automatic deletion by setting FlushInterval to '0'.
- *
- * The following basic cache operations are implemented:
- * - {@link get} : retrieve the value with a key (if any) from cache
- * - {@link set} : store the value with a key into cache
- * - {@link add} : store the value only if cache does not have this key
- * - {@link delete} : delete the value with the specified key from cache
- * - {@link flush} : delete all values from cache
- *
- * Each value is associated with an expiration time. The {@link get} operation
- * ensures that any expired value will not be returned. The expiration time by
- * the number of seconds. A expiration time 0 represents never expire.
- *
- * By definition, cache does not ensure the existence of a value
- * even if it never expires. Cache is not meant to be an persistent storage.
- *
- * Do not use the same database file for multiple applications using TDbCache.
- * Also note, cache is shared by all user sessions of an application.
- *
- * Some usage examples of TDbCache are as follows,
- * <code>
- * $cache=new TDbCache; // TDbCache may also be loaded as a Prado application module
- * $cache->init(null);
- * $cache->add('object',$object);
- * $object2=$cache->get('object');
- * </code>
- *
- * If loaded, TDbCache will register itself with {@link TApplication} as the
- * cache module. It can be accessed via {@link TApplication::getCache()}.
- *
- * TDbCache may be configured in application configuration file as follows
- * <code>
- * <module id="cache" class="System.Caching.TDbCache" />
- * </code>
- *
- * @author Qiang Xue <qiang.xue@gmail.com>
- * @version $Id$
- * @package System.Caching
- * @since 3.1.0
- */
-class TDbCache extends TCache
-{
- /**
- * @var string the ID of TDataSourceConfig module
- */
- private $_connID='';
- /**
- * @var TDbConnection the DB connection instance
- */
- private $_db;
- /**
- * @var string name of the DB cache table
- */
- private $_cacheTable='pradocache';
- /**
- * @var integer Interval expired items will be removed from cache
- */
- private $_flushInterval=60;
- /**
- * @var boolean
- */
- private $_cacheInitialized = false;
- /**
- * @var boolean
- */
- private $_createCheck= false;
- /**
- * @var boolean whether the cache DB table should be created automatically
- */
- private $_autoCreate=true;
- private $_username='';
- private $_password='';
- private $_connectionString='';
-
- /**
- * Destructor.
- * Disconnect the db connection.
- */
- public function __destruct()
- {
- if($this->_db!==null)
- $this->_db->setActive(false);
- }
-
- /**
- * Initializes this module.
- * This method is required by the IModule interface.
- * attach {@link doInitializeCache} to TApplication.OnLoadStateComplete event
- * attach {@link doFlushCacheExpired} to TApplication.OnSaveState event
- *
- * @param TXmlElement configuration for this module, can be null
- */
- public function init($config)
- {
- $this -> getApplication() -> attachEventHandler('OnLoadStateComplete', array($this, 'doInitializeCache'));
- $this -> getApplication() -> attachEventHandler('OnSaveState', array($this, 'doFlushCacheExpired'));
- parent::init($config);
- }
-
- /**
- * Event listener for TApplication.OnSaveState
- * @return void
- * @since 3.1.5
- * @see flushCacheExpired
- */
- public function doFlushCacheExpired()
- {
- $this->flushCacheExpired(false);
- }
-
- /**
- * Event listener for TApplication.OnLoadStateComplete
- *
- * @return void
- * @since 3.1.5
- * @see initializeCache
- */
- public function doInitializeCache()
- {
- $this->initializeCache();
- }
-
- /**
- * Initialize TDbCache
- *
- * If {@link setAutoCreateCacheTable AutoCreateCacheTableName} is 'true' check existence of cache table
- * and create table if does not exist.
- *
- * @param boolean Force override global state check
- * @return void
- * @throws TConfigurationException if any error happens during creating database or cache table.
- * @since 3.1.5
- */
- protected function initializeCache($force=false)
- {
- if($this->_cacheInitialized && !$force) return;
- $db=$this->getDbConnection();
- try
- {
- $key = 'TDbCache:' . $this->_cacheTable . ':created';
- if($force)
- $this -> _createCheck = false;
- else
- $this -> _createCheck = $this -> getApplication() -> getGlobalState($key, 0);
-
- if($this->_autoCreate && !$this -> _createCheck) {
-
- Prado::trace(($force ? 'Force initializing: ' : 'Initializing: ') . $this -> id . ', ' . $this->_cacheTable, 'System.Caching.TDbCache');
-
- $sql='SELECT 1 FROM '.$this->_cacheTable.' WHERE 0=1';
- $db->createCommand($sql)->queryScalar();
-
- $this -> _createCheck = true;
- $this -> getApplication() -> setGlobalState($key, time());
- }
- }
- catch(Exception $e)
- {
- // DB table not exists
- if($this->_autoCreate)
- {
- Prado::trace('Autocreate: ' . $this->_cacheTable, 'System.Caching.TDbCache');
-
- $driver=$db->getDriverName();
- if($driver==='mysql')
- $blob='LONGBLOB';
- else if($driver==='pgsql')
- $blob='BYTEA';
- else
- $blob='BLOB';
-
- $sql='CREATE TABLE '.$this->_cacheTable." (itemkey CHAR(128) PRIMARY KEY, value $blob, expire INTEGER)";
- $db->createCommand($sql)->execute();
-
- $sql='CREATE INDEX IX_expire ON ' . $this->_cacheTable . ' (expire)';
- $db->createCommand($sql)->execute();
-
- $this -> _createCheck = true;
- $this -> getApplication() -> setGlobalState($key, time());
- }
- else
- throw new TConfigurationException('db_cachetable_inexistent',$this->_cacheTable);
- }
- $this->_cacheInitialized = true;
- }
-
- /**
- * Flush expired values from cache depending on {@link setFlushInterval FlushInterval}
- * @param boolean override {@link setFlushInterval FlushInterval} and force deletion of expired items
- * @return void
- * @since 3.1.5
- */
- public function flushCacheExpired($force=false)
- {
- $interval = $this -> getFlushInterval();
- if(!$force && $interval === 0) return;
-
- $key = 'TDbCache:' . $this->_cacheTable . ':flushed';
- $now = time();
- $next = $interval + (integer)$this -> getApplication() -> getGlobalState($key, 0);
-
- if($force || $next <= $now)
- {
- if(!$this->_cacheInitialized) $this->initializeCache();
- Prado::trace(($force ? 'Force flush of expired items: ' : 'Flush expired items: ') . $this -> id . ', ' . $this->_cacheTable, 'System.Caching.TDbCache');
- $sql='DELETE FROM '.$this->_cacheTable.' WHERE expire<>0 AND expire<'.$now;
- $this->getDbConnection()->createCommand($sql)->execute();
- $this -> getApplication() -> setGlobalState($key, $now);
- }
- }
-
- /**
- * @return integer Interval in sec expired items will be removed from cache. Default to 60
- * @since 3.1.5
- */
- public function getFlushInterval()
- {
- return $this->_flushInterval;
- }
-
- /**
- * Sets interval expired items will be removed from cache
- *
- * To disable automatic deletion of expired items,
- * e.g. for external flushing via cron you can set value to '0'
- *
- * @param integer Interval in sec
- * @since 3.1.5
- */
- public function setFlushInterval($value)
- {
- $this->_flushInterval = (integer) $value;
- }
-
- /**
- * Creates the DB connection.
- * @param string the module ID for TDataSourceConfig
- * @return TDbConnection the created DB connection
- * @throws TConfigurationException if module ID is invalid or empty
- */
- protected function createDbConnection()
- {
- if($this->_connID!=='')
- {
- $config=$this->getApplication()->getModule($this->_connID);
- if($config instanceof TDataSourceConfig)
- return $config->getDbConnection();
- else
- throw new TConfigurationException('dbcache_connectionid_invalid',$this->_connID);
- }
- else
- {
- $db=new TDbConnection;
- if($this->_connectionString!=='')
- {
- $db->setConnectionString($this->_connectionString);
- if($this->_username!=='')
- $db->setUsername($this->_username);
- if($this->_password!=='')
- $db->setPassword($this->_password);
- }
- else
- {
- // default to SQLite3 database
- $dbFile=$this->getApplication()->getRuntimePath().'/sqlite3.cache';
- $db->setConnectionString('sqlite:'.$dbFile);
- }
- return $db;
- }
- }
-
- /**
- * @return TDbConnection the DB connection instance
- */
- public function getDbConnection()
- {
- if($this->_db===null)
- $this->_db=$this->createDbConnection();
-
- $this->_db->setActive(true);
- return $this->_db;
- }
-
- /**
- * @return string the ID of a {@link TDataSourceConfig} module. Defaults to empty string, meaning not set.
- * @since 3.1.1
- */
- public function getConnectionID()
- {
- return $this->_connID;
- }
-
- /**
- * Sets the ID of a TDataSourceConfig module.
- * The datasource module will be used to establish the DB connection for this cache module.
- * The database connection can also be specified via {@link setConnectionString ConnectionString}.
- * When both ConnectionID and ConnectionString are specified, the former takes precedence.
- * @param string ID of the {@link TDataSourceConfig} module
- * @since 3.1.1
- */
- public function setConnectionID($value)
- {
- $this->_connID=$value;
- }
-
- /**
- * @return string The Data Source Name, or DSN, contains the information required to connect to the database.
- */
- public function getConnectionString()
- {
- return $this->_connectionString;
- }
-
- /**
- * @param string The Data Source Name, or DSN, contains the information required to connect to the database.
- * @see http://www.php.net/manual/en/function.pdo-construct.php
- */
- public function setConnectionString($value)
- {
- $this->_connectionString=$value;
- }
-
- /**
- * @return string the username for establishing DB connection. Defaults to empty string.
- */
- public function getUsername()
- {
- return $this->_username;
- }
-
- /**
- * @param string the username for establishing DB connection
- */
- public function setUsername($value)
- {
- $this->_username=$value;
- }
-
- /**
- * @return string the password for establishing DB connection. Defaults to empty string.
- */
- public function getPassword()
- {
- return $this->_password;
- }
-
- /**
- * @param string the password for establishing DB connection
- */
- public function setPassword($value)
- {
- $this->_password=$value;
- }
-
- /**
- * @return string the name of the DB table to store cache content. Defaults to 'pradocache'.
- * @see setAutoCreateCacheTable
- */
- public function getCacheTableName()
- {
- return $this->_cacheTable;
- }
-
- /**
- * Sets the name of the DB table to store cache content.
- * Note, if {@link setAutoCreateCacheTable AutoCreateCacheTable} is false
- * and you want to create the DB table manually by yourself,
- * you need to make sure the DB table is of the following structure:
- * <code>
- * CREATE TABLE pradocache (itemkey CHAR(128), value BLOB, expire INT)
- * CREATE INDEX IX_itemkey ON pradocache (itemkey)
- * CREATE INDEX IX_expire ON pradocache (expire)
- * </code>
- *
- * Note, some DBMS might not support BLOB type. In this case, replace 'BLOB' with a suitable
- * binary data type (e.g. LONGBLOB in MySQL, BYTEA in PostgreSQL.)
- *
- * Important: Make sure that the indices are non-unique!
- *
- * @param string the name of the DB table to store cache content
- * @see setAutoCreateCacheTable
- */
- public function setCacheTableName($value)
- {
- $this->_cacheTable=$value;
- }
-
- /**
- * @return boolean whether the cache DB table should be automatically created if not exists. Defaults to true.
- * @see setAutoCreateCacheTable
- */
- public function getAutoCreateCacheTable()
- {
- return $this->_autoCreate;
- }
-
- /**
- * @param boolean whether the cache DB table should be automatically created if not exists.
- * @see setCacheTableName
- */
- public function setAutoCreateCacheTable($value)
- {
- $this->_autoCreate=TPropertyValue::ensureBoolean($value);
- }
-
- /**
- * Retrieves a value from cache with a specified key.
- * This is the implementation of the method declared in the parent class.
- * @param string a unique key identifying the cached value
- * @return string the value stored in cache, false if the value is not in the cache or expired.
- */
- protected function getValue($key)
- {
- if(!$this->_cacheInitialized) $this->initializeCache();
- try {
- $sql='SELECT value FROM '.$this->_cacheTable.' WHERE itemkey=\''.$key.'\' AND (expire=0 OR expire>'.time().') ORDER BY expire DESC';
- $command=$this->getDbConnection()->createCommand($sql);
- return Prado::unserialize($command->queryScalar());
- }
- catch(Exception $e)
- {
- $this->initializeCache(true);
- return Prado::unserialize($command->queryScalar());
- }
- }
-
- /**
- * Stores a value identified by a key in cache.
- * This is the implementation of the method declared in the parent class.
- *
- * @param string the key identifying the value to be cached
- * @param string the value to be cached
- * @param integer the number of seconds in which the cached value will expire. 0 means never expire.
- * @return boolean true if the value is successfully stored into cache, false otherwise
- */
- protected function setValue($key,$value,$expire)
- {
- $this->deleteValue($key);
- return $this->addValue($key,$value,$expire);
- }
-
- /**
- * Stores a value identified by a key into cache if the cache does not contain this key.
- * This is the implementation of the method declared in the parent class.
- *
- * @param string the key identifying the value to be cached
- * @param string the value to be cached
- * @param integer the number of seconds in which the cached value will expire. 0 means never expire.
- * @return boolean true if the value is successfully stored into cache, false otherwise
- */
- protected function addValue($key,$value,$expire)
- {
- if(!$this->_cacheInitialized) $this->initializeCache();
- $expire=($expire<=0)?0:time()+$expire;
- $sql="INSERT INTO {$this->_cacheTable} (itemkey,value,expire) VALUES(:key,:value,$expire)";
- try
- {
- $command=$this->getDbConnection()->createCommand($sql);
- $command->bindValue(':key',$key,PDO::PARAM_STR);
- $command->bindValue(':value',Prado::serialize($value),PDO::PARAM_LOB);
- $command->execute();
- return true;
- }
- catch(Exception $e)
- {
- try
- {
- $this->initializeCache(true);
- $command->execute();
- return true;
- }
- catch(Exception $e)
- {
- return false;
- }
- }
- }
-
- /**
- * Deletes a value with the specified key from cache
- * This is the implementation of the method declared in the parent class.
- * @param string the key of the value to be deleted
- * @return boolean if no error happens during deletion
- */
- protected function deleteValue($key)
- {
- if(!$this->_cacheInitialized) $this->initializeCache();
- try
- {
- $command=$this->getDbConnection()->createCommand("DELETE FROM {$this->_cacheTable} WHERE itemkey=:key");
- $command->bindValue(':key',$key,PDO::PARAM_STR);
- $command->execute();
- return true;
- }
- catch(Exception $e)
- {
- $this->initializeCache(true);
- $command->execute();
- return true;
- }
- }
-
- /**
- * Deletes all values from cache.
- * Be careful of performing this operation if the cache is shared by multiple applications.
- */
- public function flush()
- {
- if(!$this->_cacheInitialized) $this->initializeCache();
- try
- {
- $command = $this->getDbConnection()->createCommand("DELETE FROM {$this->_cacheTable}");
- $command->execute();
- }
- catch(Exception $e)
- {
- try
- {
- $this->initializeCache(true);
- $command->execute();
- return true;
- }
- catch(Exception $e)
- {
- return false;
- }
- }
- return true;
- }
-}
+<?php
+/**
+ * TDbCache class file
+ *
+ * @author Qiang Xue <qiang.xue@gmail.com>
+ * @link http://www.pradosoft.com/
+ * @copyright Copyright &copy; 2005-2012 PradoSoft
+ * @license http://www.pradosoft.com/license/
+ * @version $Id$
+ * @package System.Caching
+ */
+
+Prado::using('System.Data.TDbConnection');
+
+/**
+ * TDbCache class
+ *
+ * TDbCache implements a cache application module by storing cached data in a database.
+ *
+ * TDbCache relies on {@link http://www.php.net/manual/en/ref.pdo.php PDO} to retrieve
+ * data from databases. In order to use TDbCache, you need to enable the PDO extension
+ * as well as the corresponding PDO DB driver. For example, to use SQLite database
+ * to store cached data, you need both php_pdo and php_pdo_sqlite extensions.
+ *
+ * By default, TDbCache creates and uses an SQLite database under the application
+ * runtime directory. You may change this default setting by specifying the following
+ * properties:
+ * - {@link setConnectionID ConnectionID} or
+ * - {@link setConnectionString ConnectionString}, {@link setUsername Username} and {@link setPassword Pasword}.
+ *
+ * The cached data is stored in a table in the specified database.
+ * By default, the name of the table is called 'pradocache'. If the table does not
+ * exist in the database, it will be automatically created with the following structure:
+ * <code>
+ * CREATE TABLE pradocache (itemkey CHAR(128), value BLOB, expire INT)
+ * CREATE INDEX IX_itemkey ON pradocache (itemkey)
+ * CREATE INDEX IX_expire ON pradocache (expire)
+ * </code>
+ *
+ * Note, some DBMS might not support BLOB type. In this case, replace 'BLOB' with a suitable
+ * binary data type (e.g. LONGBLOB in MySQL, BYTEA in PostgreSQL.)
+ *
+ * Important: Make sure that the indices are non-unique!
+ *
+ * If you want to change the cache table name, or if you want to create the table by yourself,
+ * you may set {@link setCacheTableName CacheTableName} and {@link setAutoCreateCacheTable AutoCreateCacheTableName} properties.
+ *
+ * {@link setFlushInterval FlushInterval} control how often expired items will be removed from cache.
+ * If you prefer to remove expired items manualy e.g. via cronjob you can disable automatic deletion by setting FlushInterval to '0'.
+ *
+ * The following basic cache operations are implemented:
+ * - {@link get} : retrieve the value with a key (if any) from cache
+ * - {@link set} : store the value with a key into cache
+ * - {@link add} : store the value only if cache does not have this key
+ * - {@link delete} : delete the value with the specified key from cache
+ * - {@link flush} : delete all values from cache
+ *
+ * Each value is associated with an expiration time. The {@link get} operation
+ * ensures that any expired value will not be returned. The expiration time by
+ * the number of seconds. A expiration time 0 represents never expire.
+ *
+ * By definition, cache does not ensure the existence of a value
+ * even if it never expires. Cache is not meant to be an persistent storage.
+ *
+ * Do not use the same database file for multiple applications using TDbCache.
+ * Also note, cache is shared by all user sessions of an application.
+ *
+ * Some usage examples of TDbCache are as follows,
+ * <code>
+ * $cache=new TDbCache; // TDbCache may also be loaded as a Prado application module
+ * $cache->init(null);
+ * $cache->add('object',$object);
+ * $object2=$cache->get('object');
+ * </code>
+ *
+ * If loaded, TDbCache will register itself with {@link TApplication} as the
+ * cache module. It can be accessed via {@link TApplication::getCache()}.
+ *
+ * TDbCache may be configured in application configuration file as follows
+ * <code>
+ * <module id="cache" class="System.Caching.TDbCache" />
+ * </code>
+ *
+ * @author Qiang Xue <qiang.xue@gmail.com>
+ * @version $Id$
+ * @package System.Caching
+ * @since 3.1.0
+ */
+class TDbCache extends TCache
+{
+ /**
+ * @var string the ID of TDataSourceConfig module
+ */
+ private $_connID='';
+ /**
+ * @var TDbConnection the DB connection instance
+ */
+ private $_db;
+ /**
+ * @var string name of the DB cache table
+ */
+ private $_cacheTable='pradocache';
+ /**
+ * @var integer Interval expired items will be removed from cache
+ */
+ private $_flushInterval=60;
+ /**
+ * @var boolean
+ */
+ private $_cacheInitialized = false;
+ /**
+ * @var boolean
+ */
+ private $_createCheck= false;
+ /**
+ * @var boolean whether the cache DB table should be created automatically
+ */
+ private $_autoCreate=true;
+ private $_username='';
+ private $_password='';
+ private $_connectionString='';
+
+ /**
+ * Destructor.
+ * Disconnect the db connection.
+ */
+ public function __destruct()
+ {
+ if($this->_db!==null)
+ $this->_db->setActive(false);
+ }
+
+ /**
+ * Initializes this module.
+ * This method is required by the IModule interface.
+ * attach {@link doInitializeCache} to TApplication.OnLoadStateComplete event
+ * attach {@link doFlushCacheExpired} to TApplication.OnSaveState event
+ *
+ * @param TXmlElement configuration for this module, can be null
+ */
+ public function init($config)
+ {
+ $this -> getApplication() -> attachEventHandler('OnLoadStateComplete', array($this, 'doInitializeCache'));
+ $this -> getApplication() -> attachEventHandler('OnSaveState', array($this, 'doFlushCacheExpired'));
+ parent::init($config);
+ }
+
+ /**
+ * Event listener for TApplication.OnSaveState
+ * @return void
+ * @since 3.1.5
+ * @see flushCacheExpired
+ */
+ public function doFlushCacheExpired()
+ {
+ $this->flushCacheExpired(false);
+ }
+
+ /**
+ * Event listener for TApplication.OnLoadStateComplete
+ *
+ * @return void
+ * @since 3.1.5
+ * @see initializeCache
+ */
+ public function doInitializeCache()
+ {
+ $this->initializeCache();
+ }
+
+ /**
+ * Initialize TDbCache
+ *
+ * If {@link setAutoCreateCacheTable AutoCreateCacheTableName} is 'true' check existence of cache table
+ * and create table if does not exist.
+ *
+ * @param boolean Force override global state check
+ * @return void
+ * @throws TConfigurationException if any error happens during creating database or cache table.
+ * @since 3.1.5
+ */
+ protected function initializeCache($force=false)
+ {
+ if($this->_cacheInitialized && !$force) return;
+ $db=$this->getDbConnection();
+ try
+ {
+ $key = 'TDbCache:' . $this->_cacheTable . ':created';
+ if($force)
+ $this -> _createCheck = false;
+ else
+ $this -> _createCheck = $this -> getApplication() -> getGlobalState($key, 0);
+
+ if($this->_autoCreate && !$this -> _createCheck) {
+
+ Prado::trace(($force ? 'Force initializing: ' : 'Initializing: ') . $this -> id . ', ' . $this->_cacheTable, 'System.Caching.TDbCache');
+
+ $sql='SELECT 1 FROM '.$this->_cacheTable.' WHERE 0=1';
+ $db->createCommand($sql)->queryScalar();
+
+ $this -> _createCheck = true;
+ $this -> getApplication() -> setGlobalState($key, time());
+ }
+ }
+ catch(Exception $e)
+ {
+ // DB table not exists
+ if($this->_autoCreate)
+ {
+ Prado::trace('Autocreate: ' . $this->_cacheTable, 'System.Caching.TDbCache');
+
+ $driver=$db->getDriverName();
+ if($driver==='mysql')
+ $blob='LONGBLOB';
+ else if($driver==='pgsql')
+ $blob='BYTEA';
+ else
+ $blob='BLOB';
+
+ $sql='CREATE TABLE '.$this->_cacheTable." (itemkey CHAR(128) PRIMARY KEY, value $blob, expire INTEGER)";
+ $db->createCommand($sql)->execute();
+
+ $sql='CREATE INDEX IX_expire ON ' . $this->_cacheTable . ' (expire)';
+ $db->createCommand($sql)->execute();
+
+ $this -> _createCheck = true;
+ $this -> getApplication() -> setGlobalState($key, time());
+ }
+ else
+ throw new TConfigurationException('db_cachetable_inexistent',$this->_cacheTable);
+ }
+ $this->_cacheInitialized = true;
+ }
+
+ /**
+ * Flush expired values from cache depending on {@link setFlushInterval FlushInterval}
+ * @param boolean override {@link setFlushInterval FlushInterval} and force deletion of expired items
+ * @return void
+ * @since 3.1.5
+ */
+ public function flushCacheExpired($force=false)
+ {
+ $interval = $this -> getFlushInterval();
+ if(!$force && $interval === 0) return;
+
+ $key = 'TDbCache:' . $this->_cacheTable . ':flushed';
+ $now = time();
+ $next = $interval + (integer)$this -> getApplication() -> getGlobalState($key, 0);
+
+ if($force || $next <= $now)
+ {
+ if(!$this->_cacheInitialized) $this->initializeCache();
+ Prado::trace(($force ? 'Force flush of expired items: ' : 'Flush expired items: ') . $this -> id . ', ' . $this->_cacheTable, 'System.Caching.TDbCache');
+ $sql='DELETE FROM '.$this->_cacheTable.' WHERE expire<>0 AND expire<'.$now;
+ $this->getDbConnection()->createCommand($sql)->execute();
+ $this -> getApplication() -> setGlobalState($key, $now);
+ }
+ }
+
+ /**
+ * @return integer Interval in sec expired items will be removed from cache. Default to 60
+ * @since 3.1.5
+ */
+ public function getFlushInterval()
+ {
+ return $this->_flushInterval;
+ }
+
+ /**
+ * Sets interval expired items will be removed from cache
+ *
+ * To disable automatic deletion of expired items,
+ * e.g. for external flushing via cron you can set value to '0'
+ *
+ * @param integer Interval in sec
+ * @since 3.1.5
+ */
+ public function setFlushInterval($value)
+ {
+ $this->_flushInterval = (integer) $value;
+ }
+
+ /**
+ * Creates the DB connection.
+ * @param string the module ID for TDataSourceConfig
+ * @return TDbConnection the created DB connection
+ * @throws TConfigurationException if module ID is invalid or empty
+ */
+ protected function createDbConnection()
+ {
+ if($this->_connID!=='')
+ {
+ $config=$this->getApplication()->getModule($this->_connID);
+ if($config instanceof TDataSourceConfig)
+ return $config->getDbConnection();
+ else
+ throw new TConfigurationException('dbcache_connectionid_invalid',$this->_connID);
+ }
+ else
+ {
+ $db=new TDbConnection;
+ if($this->_connectionString!=='')
+ {
+ $db->setConnectionString($this->_connectionString);
+ if($this->_username!=='')
+ $db->setUsername($this->_username);
+ if($this->_password!=='')
+ $db->setPassword($this->_password);
+ }
+ else
+ {
+ // default to SQLite3 database
+ $dbFile=$this->getApplication()->getRuntimePath().'/sqlite3.cache';
+ $db->setConnectionString('sqlite:'.$dbFile);
+ }
+ return $db;
+ }
+ }
+
+ /**
+ * @return TDbConnection the DB connection instance
+ */
+ public function getDbConnection()
+ {
+ if($this->_db===null)
+ $this->_db=$this->createDbConnection();
+
+ $this->_db->setActive(true);
+ return $this->_db;
+ }
+
+ /**
+ * @return string the ID of a {@link TDataSourceConfig} module. Defaults to empty string, meaning not set.
+ * @since 3.1.1
+ */
+ public function getConnectionID()
+ {
+ return $this->_connID;
+ }
+
+ /**
+ * Sets the ID of a TDataSourceConfig module.
+ * The datasource module will be used to establish the DB connection for this cache module.
+ * The database connection can also be specified via {@link setConnectionString ConnectionString}.
+ * When both ConnectionID and ConnectionString are specified, the former takes precedence.
+ * @param string ID of the {@link TDataSourceConfig} module
+ * @since 3.1.1
+ */
+ public function setConnectionID($value)
+ {
+ $this->_connID=$value;
+ }
+
+ /**
+ * @return string The Data Source Name, or DSN, contains the information required to connect to the database.
+ */
+ public function getConnectionString()
+ {
+ return $this->_connectionString;
+ }
+
+ /**
+ * @param string The Data Source Name, or DSN, contains the information required to connect to the database.
+ * @see http://www.php.net/manual/en/function.pdo-construct.php
+ */
+ public function setConnectionString($value)
+ {
+ $this->_connectionString=$value;
+ }
+
+ /**
+ * @return string the username for establishing DB connection. Defaults to empty string.
+ */
+ public function getUsername()
+ {
+ return $this->_username;
+ }
+
+ /**
+ * @param string the username for establishing DB connection
+ */
+ public function setUsername($value)
+ {
+ $this->_username=$value;
+ }
+
+ /**
+ * @return string the password for establishing DB connection. Defaults to empty string.
+ */
+ public function getPassword()
+ {
+ return $this->_password;
+ }
+
+ /**
+ * @param string the password for establishing DB connection
+ */
+ public function setPassword($value)
+ {
+ $this->_password=$value;
+ }
+
+ /**
+ * @return string the name of the DB table to store cache content. Defaults to 'pradocache'.
+ * @see setAutoCreateCacheTable
+ */
+ public function getCacheTableName()
+ {
+ return $this->_cacheTable;
+ }
+
+ /**
+ * Sets the name of the DB table to store cache content.
+ * Note, if {@link setAutoCreateCacheTable AutoCreateCacheTable} is false
+ * and you want to create the DB table manually by yourself,
+ * you need to make sure the DB table is of the following structure:
+ * <code>
+ * CREATE TABLE pradocache (itemkey CHAR(128), value BLOB, expire INT)
+ * CREATE INDEX IX_itemkey ON pradocache (itemkey)
+ * CREATE INDEX IX_expire ON pradocache (expire)
+ * </code>
+ *
+ * Note, some DBMS might not support BLOB type. In this case, replace 'BLOB' with a suitable
+ * binary data type (e.g. LONGBLOB in MySQL, BYTEA in PostgreSQL.)
+ *
+ * Important: Make sure that the indices are non-unique!
+ *
+ * @param string the name of the DB table to store cache content
+ * @see setAutoCreateCacheTable
+ */
+ public function setCacheTableName($value)
+ {
+ $this->_cacheTable=$value;
+ }
+
+ /**
+ * @return boolean whether the cache DB table should be automatically created if not exists. Defaults to true.
+ * @see setAutoCreateCacheTable
+ */
+ public function getAutoCreateCacheTable()
+ {
+ return $this->_autoCreate;
+ }
+
+ /**
+ * @param boolean whether the cache DB table should be automatically created if not exists.
+ * @see setCacheTableName
+ */
+ public function setAutoCreateCacheTable($value)
+ {
+ $this->_autoCreate=TPropertyValue::ensureBoolean($value);
+ }
+
+ /**
+ * Retrieves a value from cache with a specified key.
+ * This is the implementation of the method declared in the parent class.
+ * @param string a unique key identifying the cached value
+ * @return string the value stored in cache, false if the value is not in the cache or expired.
+ */
+ protected function getValue($key)
+ {
+ if(!$this->_cacheInitialized) $this->initializeCache();
+ try {
+ $sql='SELECT value FROM '.$this->_cacheTable.' WHERE itemkey=\''.$key.'\' AND (expire=0 OR expire>'.time().') ORDER BY expire DESC';
+ $command=$this->getDbConnection()->createCommand($sql);
+ return Prado::unserialize($command->queryScalar());
+ }
+ catch(Exception $e)
+ {
+ $this->initializeCache(true);
+ return Prado::unserialize($command->queryScalar());
+ }
+ }
+
+ /**
+ * Stores a value identified by a key in cache.
+ * This is the implementation of the method declared in the parent class.
+ *
+ * @param string the key identifying the value to be cached
+ * @param string the value to be cached
+ * @param integer the number of seconds in which the cached value will expire. 0 means never expire.
+ * @return boolean true if the value is successfully stored into cache, false otherwise
+ */
+ protected function setValue($key,$value,$expire)
+ {
+ $this->deleteValue($key);
+ return $this->addValue($key,$value,$expire);
+ }
+
+ /**
+ * Stores a value identified by a key into cache if the cache does not contain this key.
+ * This is the implementation of the method declared in the parent class.
+ *
+ * @param string the key identifying the value to be cached
+ * @param string the value to be cached
+ * @param integer the number of seconds in which the cached value will expire. 0 means never expire.
+ * @return boolean true if the value is successfully stored into cache, false otherwise
+ */
+ protected function addValue($key,$value,$expire)
+ {
+ if(!$this->_cacheInitialized) $this->initializeCache();
+ $expire=($expire<=0)?0:time()+$expire;
+ $sql="INSERT INTO {$this->_cacheTable} (itemkey,value,expire) VALUES(:key,:value,$expire)";
+ try
+ {
+ $command=$this->getDbConnection()->createCommand($sql);
+ $command->bindValue(':key',$key,PDO::PARAM_STR);
+ $command->bindValue(':value',Prado::serialize($value),PDO::PARAM_LOB);
+ $command->execute();
+ return true;
+ }
+ catch(Exception $e)
+ {
+ try
+ {
+ $this->initializeCache(true);
+ $command->execute();
+ return true;
+ }
+ catch(Exception $e)
+ {
+ return false;
+ }
+ }
+ }
+
+ /**
+ * Deletes a value with the specified key from cache
+ * This is the implementation of the method declared in the parent class.
+ * @param string the key of the value to be deleted
+ * @return boolean if no error happens during deletion
+ */
+ protected function deleteValue($key)
+ {
+ if(!$this->_cacheInitialized) $this->initializeCache();
+ try
+ {
+ $command=$this->getDbConnection()->createCommand("DELETE FROM {$this->_cacheTable} WHERE itemkey=:key");
+ $command->bindValue(':key',$key,PDO::PARAM_STR);
+ $command->execute();
+ return true;
+ }
+ catch(Exception $e)
+ {
+ $this->initializeCache(true);
+ $command->execute();
+ return true;
+ }
+ }
+
+ /**
+ * Deletes all values from cache.
+ * Be careful of performing this operation if the cache is shared by multiple applications.
+ */
+ public function flush()
+ {
+ if(!$this->_cacheInitialized) $this->initializeCache();
+ try
+ {
+ $command = $this->getDbConnection()->createCommand("DELETE FROM {$this->_cacheTable}");
+ $command->execute();
+ }
+ catch(Exception $e)
+ {
+ try
+ {
+ $this->initializeCache(true);
+ $command->execute();
+ return true;
+ }
+ catch(Exception $e)
+ {
+ return false;
+ }
+ }
+ return true;
+ }
+}
diff --git a/framework/Caching/TSqliteCache.php b/framework/Caching/TSqliteCache.php
index 2668e3cc..6cba94ae 100644
--- a/framework/Caching/TSqliteCache.php
+++ b/framework/Caching/TSqliteCache.php
@@ -1,224 +1,224 @@
-<?php
-/**
- * TSqliteCache class file
- *
- * @author Qiang Xue <qiang.xue@gmail.com>
- * @link http://www.pradosoft.com/
- * @copyright Copyright &copy; 2005-2012 PradoSoft
- * @license http://www.pradosoft.com/license/
- * @version $Id$
- * @package System.Caching
- */
-
-/**
- * TSqliteCache class
- *
- * TSqliteCache implements a cache application module based on SQLite database.
- *
- * THIS CLASS IS DEPRECATED since it relies on the sqlite PHP extension, that is
- * no longer loaded by default since PHP 5.1. You are discouraged from using it:
- * use {@link TDbCache} instead.
- *
- * Since PRADO v3.1.0, a new DB-based cache module called {@link TDbCache}
- * is provided. If you have PDO extension installed, you may consider using
- * the new cache module instead as it allows you to use different database
- * to store the cached data.
- *
- * The database file is specified by the {@link setDbFile DbFile} property.
- * If not set, the database file will be created under the system state path.
- * If the specified database file does not exist, it will be created automatically.
- * Make sure the directory containing the specified DB file and the file itself is
- * writable by the Web server process.
- *
- * The following basic cache operations are implemented:
- * - {@link get} : retrieve the value with a key (if any) from cache
- * - {@link set} : store the value with a key into cache
- * - {@link add} : store the value only if cache does not have this key
- * - {@link delete} : delete the value with the specified key from cache
- * - {@link flush} : delete all values from cache
- *
- * Each value is associated with an expiration time. The {@link get} operation
- * ensures that any expired value will not be returned. The expiration time by
- * the number of seconds. A expiration time 0 represents never expire.
- *
- * By definition, cache does not ensure the existence of a value
- * even if it never expires. Cache is not meant to be an persistent storage.
- *
- * Do not use the same database file for multiple applications using TSqliteCache.
- * Also note, cache is shared by all user sessions of an application.
- *
- * Some usage examples of TSqliteCache are as follows,
- * <code>
- * $cache=new TSqliteCache; // TSqliteCache may also be loaded as a Prado application module
- * $cache->setDbFile($dbFilePath);
- * $cache->init(null);
- * $cache->add('object',$object);
- * $object2=$cache->get('object');
- * </code>
- *
- * If loaded, TSqliteCache will register itself with {@link TApplication} as the
- * cache module. It can be accessed via {@link TApplication::getCache()}.
- *
- * TSqliteCache may be configured in application configuration file as follows
- * <code>
- * <module id="cache" class="System.Caching.TSqliteCache" DbFile="Application.Data.site" />
- * </code>
- * where {@link getDbFile DbFile} is a property specifying the location of the
- * SQLite DB file (in the namespace format).
- *
- * @author Qiang Xue <qiang.xue@gmail.com>
- * @version $Id$
- * @package System.Caching
- * @since 3.0
- */
-class TSqliteCache extends TCache
-{
- /**
- * name of the table storing cache data
- */
- const CACHE_TABLE='cache';
- /**
- * extension of the db file name
- */
- const DB_FILE_EXT='.db';
-
- /**
- * @var boolean if the module has been initialized
- */
- private $_initialized=false;
- /**
- * @var SQLiteDatabase the sqlite database instance
- */
- private $_db=null;
- /**
- * @var string the database file name
- */
- private $_file=null;
-
- /**
- * Destructor.
- * Disconnect the db connection.
- */
- public function __destruct()
- {
- $this->_db=null;
- }
-
- /**
- * Initializes this module.
- * This method is required by the IModule interface. It checks if the DbFile
- * property is set, and creates a SQLiteDatabase instance for it.
- * The database or the cache table does not exist, they will be created.
- * Expired values are also deleted.
- * @param TXmlElement configuration for this module, can be null
- * @throws TConfigurationException if sqlite extension is not installed,
- * DbFile is set invalid, or any error happens during creating database or cache table.
- */
- public function init($config)
- {
- if(!function_exists('sqlite_open'))
- throw new TConfigurationException('sqlitecache_extension_required');
- if($this->_file===null)
- $this->_file=$this->getApplication()->getRuntimePath().'/sqlite.cache';
- $error='';
- if(($this->_db=new SQLiteDatabase($this->_file,0666,$error))===false)
- throw new TConfigurationException('sqlitecache_connection_failed',$error);
- if(@$this->_db->query('DELETE FROM '.self::CACHE_TABLE.' WHERE expire<>0 AND expire<'.time())===false)
- {
- if($this->_db->query('CREATE TABLE '.self::CACHE_TABLE.' (key CHAR(128) PRIMARY KEY, value BLOB, expire INT)')===false)
- throw new TConfigurationException('sqlitecache_table_creation_failed',sqlite_error_string(sqlite_last_error()));
- }
- $this->_initialized=true;
- parent::init($config);
- }
-
- /**
- * @return string database file path (in namespace form)
- */
- public function getDbFile()
- {
- return $this->_file;
- }
-
- /**
- * @param string database file path (in namespace form)
- * @throws TInvalidOperationException if the module is already initialized
- * @throws TConfigurationException if the file is not in proper namespace format
- */
- public function setDbFile($value)
- {
- if($this->_initialized)
- throw new TInvalidOperationException('sqlitecache_dbfile_unchangeable');
- else if(($this->_file=Prado::getPathOfNamespace($value,self::DB_FILE_EXT))===null)
- throw new TConfigurationException('sqlitecache_dbfile_invalid',$value);
- }
-
- /**
- * Retrieves a value from cache with a specified key.
- * This is the implementation of the method declared in the parent class.
- * @param string a unique key identifying the cached value
- * @return string the value stored in cache, false if the value is not in the cache or expired.
- */
- protected function getValue($key)
- {
- $sql='SELECT value FROM '.self::CACHE_TABLE.' WHERE key=\''.$key.'\' AND (expire=0 OR expire>'.time().') LIMIT 1';
- if(($ret=$this->_db->query($sql))!=false && ($row=$ret->fetch(SQLITE_ASSOC))!==false)
- return Prado::unserialize($row['value']);
- else
- return false;
- }
-
- /**
- * Stores a value identified by a key in cache.
- * This is the implementation of the method declared in the parent class.
- *
- * @param string the key identifying the value to be cached
- * @param string the value to be cached
- * @param integer the number of seconds in which the cached value will expire. 0 means never expire.
- * @return boolean true if the value is successfully stored into cache, false otherwise
- */
- protected function setValue($key,$value,$expire)
- {
- $expire=($expire<=0)?0:time()+$expire;
- $sql='REPLACE INTO '.self::CACHE_TABLE.' VALUES(\''.$key.'\',\''.sqlite_escape_string(Prado::serialize($value)).'\','.$expire.')';
- return $this->_db->query($sql)!==false;
- }
-
- /**
- * Stores a value identified by a key into cache if the cache does not contain this key.
- * This is the implementation of the method declared in the parent class.
- *
- * @param string the key identifying the value to be cached
- * @param string the value to be cached
- * @param integer the number of seconds in which the cached value will expire. 0 means never expire.
- * @return boolean true if the value is successfully stored into cache, false otherwise
- */
- protected function addValue($key,$value,$expire)
- {
- $expire=($expire<=0)?0:time()+$expire;
- $sql='INSERT INTO '.self::CACHE_TABLE.' VALUES(\''.$key.'\',\''.sqlite_escape_string(Prado::serialize($value)).'\','.$expire.')';
- return @$this->_db->query($sql)!==false;
- }
-
- /**
- * Deletes a value with the specified key from cache
- * This is the implementation of the method declared in the parent class.
- * @param string the key of the value to be deleted
- * @return boolean if no error happens during deletion
- */
- protected function deleteValue($key)
- {
- $sql='DELETE FROM '.self::CACHE_TABLE.' WHERE key=\''.$key.'\'';
- return $this->_db->query($sql)!==false;
- }
-
- /**
- * Deletes all values from cache.
- * Be careful of performing this operation if the cache is shared by multiple applications.
- */
- public function flush()
- {
- return $this->_db->query('DELETE FROM '.self::CACHE_TABLE)!==false;
- }
-}
-
+<?php
+/**
+ * TSqliteCache class file
+ *
+ * @author Qiang Xue <qiang.xue@gmail.com>
+ * @link http://www.pradosoft.com/
+ * @copyright Copyright &copy; 2005-2012 PradoSoft
+ * @license http://www.pradosoft.com/license/
+ * @version $Id$
+ * @package System.Caching
+ */
+
+/**
+ * TSqliteCache class
+ *
+ * TSqliteCache implements a cache application module based on SQLite database.
+ *
+ * THIS CLASS IS DEPRECATED since it relies on the sqlite PHP extension, that is
+ * no longer loaded by default since PHP 5.1. You are discouraged from using it:
+ * use {@link TDbCache} instead.
+ *
+ * Since PRADO v3.1.0, a new DB-based cache module called {@link TDbCache}
+ * is provided. If you have PDO extension installed, you may consider using
+ * the new cache module instead as it allows you to use different database
+ * to store the cached data.
+ *
+ * The database file is specified by the {@link setDbFile DbFile} property.
+ * If not set, the database file will be created under the system state path.
+ * If the specified database file does not exist, it will be created automatically.
+ * Make sure the directory containing the specified DB file and the file itself is
+ * writable by the Web server process.
+ *
+ * The following basic cache operations are implemented:
+ * - {@link get} : retrieve the value with a key (if any) from cache
+ * - {@link set} : store the value with a key into cache
+ * - {@link add} : store the value only if cache does not have this key
+ * - {@link delete} : delete the value with the specified key from cache
+ * - {@link flush} : delete all values from cache
+ *
+ * Each value is associated with an expiration time. The {@link get} operation
+ * ensures that any expired value will not be returned. The expiration time by
+ * the number of seconds. A expiration time 0 represents never expire.
+ *
+ * By definition, cache does not ensure the existence of a value
+ * even if it never expires. Cache is not meant to be an persistent storage.
+ *
+ * Do not use the same database file for multiple applications using TSqliteCache.
+ * Also note, cache is shared by all user sessions of an application.
+ *
+ * Some usage examples of TSqliteCache are as follows,
+ * <code>
+ * $cache=new TSqliteCache; // TSqliteCache may also be loaded as a Prado application module
+ * $cache->setDbFile($dbFilePath);
+ * $cache->init(null);
+ * $cache->add('object',$object);
+ * $object2=$cache->get('object');
+ * </code>
+ *
+ * If loaded, TSqliteCache will register itself with {@link TApplication} as the
+ * cache module. It can be accessed via {@link TApplication::getCache()}.
+ *
+ * TSqliteCache may be configured in application configuration file as follows
+ * <code>
+ * <module id="cache" class="System.Caching.TSqliteCache" DbFile="Application.Data.site" />
+ * </code>
+ * where {@link getDbFile DbFile} is a property specifying the location of the
+ * SQLite DB file (in the namespace format).
+ *
+ * @author Qiang Xue <qiang.xue@gmail.com>
+ * @version $Id$
+ * @package System.Caching
+ * @since 3.0
+ */
+class TSqliteCache extends TCache
+{
+ /**
+ * name of the table storing cache data
+ */
+ const CACHE_TABLE='cache';
+ /**
+ * extension of the db file name
+ */
+ const DB_FILE_EXT='.db';
+
+ /**
+ * @var boolean if the module has been initialized
+ */
+ private $_initialized=false;
+ /**
+ * @var SQLiteDatabase the sqlite database instance
+ */
+ private $_db=null;
+ /**
+ * @var string the database file name
+ */
+ private $_file=null;
+
+ /**
+ * Destructor.
+ * Disconnect the db connection.
+ */
+ public function __destruct()
+ {
+ $this->_db=null;
+ }
+
+ /**
+ * Initializes this module.
+ * This method is required by the IModule interface. It checks if the DbFile
+ * property is set, and creates a SQLiteDatabase instance for it.
+ * The database or the cache table does not exist, they will be created.
+ * Expired values are also deleted.
+ * @param TXmlElement configuration for this module, can be null
+ * @throws TConfigurationException if sqlite extension is not installed,
+ * DbFile is set invalid, or any error happens during creating database or cache table.
+ */
+ public function init($config)
+ {
+ if(!function_exists('sqlite_open'))
+ throw new TConfigurationException('sqlitecache_extension_required');
+ if($this->_file===null)
+ $this->_file=$this->getApplication()->getRuntimePath().'/sqlite.cache';
+ $error='';
+ if(($this->_db=new SQLiteDatabase($this->_file,0666,$error))===false)
+ throw new TConfigurationException('sqlitecache_connection_failed',$error);
+ if(@$this->_db->query('DELETE FROM '.self::CACHE_TABLE.' WHERE expire<>0 AND expire<'.time())===false)
+ {
+ if($this->_db->query('CREATE TABLE '.self::CACHE_TABLE.' (key CHAR(128) PRIMARY KEY, value BLOB, expire INT)')===false)
+ throw new TConfigurationException('sqlitecache_table_creation_failed',sqlite_error_string(sqlite_last_error()));
+ }
+ $this->_initialized=true;
+ parent::init($config);
+ }
+
+ /**
+ * @return string database file path (in namespace form)
+ */
+ public function getDbFile()
+ {
+ return $this->_file;
+ }
+
+ /**
+ * @param string database file path (in namespace form)
+ * @throws TInvalidOperationException if the module is already initialized
+ * @throws TConfigurationException if the file is not in proper namespace format
+ */
+ public function setDbFile($value)
+ {
+ if($this->_initialized)
+ throw new TInvalidOperationException('sqlitecache_dbfile_unchangeable');
+ else if(($this->_file=Prado::getPathOfNamespace($value,self::DB_FILE_EXT))===null)
+ throw new TConfigurationException('sqlitecache_dbfile_invalid',$value);
+ }
+
+ /**
+ * Retrieves a value from cache with a specified key.
+ * This is the implementation of the method declared in the parent class.
+ * @param string a unique key identifying the cached value
+ * @return string the value stored in cache, false if the value is not in the cache or expired.
+ */
+ protected function getValue($key)
+ {
+ $sql='SELECT value FROM '.self::CACHE_TABLE.' WHERE key=\''.$key.'\' AND (expire=0 OR expire>'.time().') LIMIT 1';
+ if(($ret=$this->_db->query($sql))!=false && ($row=$ret->fetch(SQLITE_ASSOC))!==false)
+ return Prado::unserialize($row['value']);
+ else
+ return false;
+ }
+
+ /**
+ * Stores a value identified by a key in cache.
+ * This is the implementation of the method declared in the parent class.
+ *
+ * @param string the key identifying the value to be cached
+ * @param string the value to be cached
+ * @param integer the number of seconds in which the cached value will expire. 0 means never expire.
+ * @return boolean true if the value is successfully stored into cache, false otherwise
+ */
+ protected function setValue($key,$value,$expire)
+ {
+ $expire=($expire<=0)?0:time()+$expire;
+ $sql='REPLACE INTO '.self::CACHE_TABLE.' VALUES(\''.$key.'\',\''.sqlite_escape_string(Prado::serialize($value)).'\','.$expire.')';
+ return $this->_db->query($sql)!==false;
+ }
+
+ /**
+ * Stores a value identified by a key into cache if the cache does not contain this key.
+ * This is the implementation of the method declared in the parent class.
+ *
+ * @param string the key identifying the value to be cached
+ * @param string the value to be cached
+ * @param integer the number of seconds in which the cached value will expire. 0 means never expire.
+ * @return boolean true if the value is successfully stored into cache, false otherwise
+ */
+ protected function addValue($key,$value,$expire)
+ {
+ $expire=($expire<=0)?0:time()+$expire;
+ $sql='INSERT INTO '.self::CACHE_TABLE.' VALUES(\''.$key.'\',\''.sqlite_escape_string(Prado::serialize($value)).'\','.$expire.')';
+ return @$this->_db->query($sql)!==false;
+ }
+
+ /**
+ * Deletes a value with the specified key from cache
+ * This is the implementation of the method declared in the parent class.
+ * @param string the key of the value to be deleted
+ * @return boolean if no error happens during deletion
+ */
+ protected function deleteValue($key)
+ {
+ $sql='DELETE FROM '.self::CACHE_TABLE.' WHERE key=\''.$key.'\'';
+ return $this->_db->query($sql)!==false;
+ }
+
+ /**
+ * Deletes all values from cache.
+ * Be careful of performing this operation if the cache is shared by multiple applications.
+ */
+ public function flush()
+ {
+ return $this->_db->query('DELETE FROM '.self::CACHE_TABLE)!==false;
+ }
+}
+
diff --git a/framework/Caching/TXCache.php b/framework/Caching/TXCache.php
index 6750d5b8..31f2a4d2 100644
--- a/framework/Caching/TXCache.php
+++ b/framework/Caching/TXCache.php
@@ -1,131 +1,131 @@
-<?php
-/**
- * TXCache class file
- *
- * @author Wei Zhuo <weizhuo[at]gmail[dot]com>
- * @link http://www.pradosoft.com/
- * @copyright Copyright &copy; 2005-2012 PradoSoft
- * @license http://www.pradosoft.com/license/
- * @version $Id: TXCache.php 1994 2007-06-11 16:02:28Z knut $
- * @package System.Caching
- */
-
-/**
- * TXCache class
- *
- * TXCache implements a cache application module based on {@link http://xcache.lighttpd.net/ xcache}.
- *
- * By definition, cache does not ensure the existence of a value
- * even if it never expires. Cache is not meant to be an persistent storage.
- *
- * To use this module, the xcache PHP extension must be loaded and configured in the php.ini.
- *
- * Some usage examples of TXCache are as follows,
- * <code>
- * $cache=new TXCache; // TXCache may also be loaded as a Prado application module
- * $cache->init(null);
- * $cache->add('object',$object);
- * $object2=$cache->get('object');
- * </code>
- *
- * If loaded, TXCache will register itself with {@link TApplication} as the
- * cache module. It can be accessed via {@link TApplication::getCache()}.
- *
- * TXCache may be configured in application configuration file as follows
- * <code>
- * <module id="cache" class="System.Caching.TXCache" />
- * </code>
- *
- * @author Wei Zhuo <weizhuo[at]gmail[dot]com>
- * @version $Id: TXCache.php 1994 2007-06-11 16:02:28Z knut $
- * @package System.Caching
- * @since 3.1.1
- */
-class TXCache extends TCache
-{
- /**
- * Initializes this module.
- * This method is required by the IModule interface.
- * @param TXmlElement configuration for this module, can be null
- * @throws TConfigurationException if xcache extension is not installed or not started, check your php.ini
- */
- public function init($config)
- {
- if(!function_exists('xcache_isset'))
- throw new TConfigurationException('xcache_extension_required');
-
- $enabled = (int)ini_get('xcache.cacher') !== 0;
- $var_size = (int)ini_get('xcache.var_size');
-
- if(!($enabled && $var_size > 0))
- throw new TConfigurationException('xcache_extension_not_enabled');
-
- parent::init($config);
- }
-
- /**
- * Retrieves a value from cache with a specified key.
- * This is the implementation of the method declared in the parent class.
- * @param string a unique key identifying the cached value
- * @return string the value stored in cache, false if the value is not in the cache or expired.
- */
- protected function getValue($key)
- {
- return xcache_isset($key) ? xcache_get($key) : false;
- }
-
- /**
- * Stores a value identified by a key in cache.
- * This is the implementation of the method declared in the parent class.
- *
- * @param string the key identifying the value to be cached
- * @param string the value to be cached
- * @param integer the number of seconds in which the cached value will expire. 0 means never expire.
- * @return boolean true if the value is successfully stored into cache, false otherwise
- */
- protected function setValue($key,$value,$expire)
- {
- return xcache_set($key,$value,$expire);
- }
-
- /**
- * Stores a value identified by a key into cache if the cache does not contain this key.
- * This is the implementation of the method declared in the parent class.
- *
- * @param string the key identifying the value to be cached
- * @param string the value to be cached
- * @param integer the number of seconds in which the cached value will expire. 0 means never expire.
- * @return boolean true if the value is successfully stored into cache, false otherwise
- */
- protected function addValue($key,$value,$expire)
- {
- return !xcache_isset($key) ? $this->setValue($key,$value,$expire) : false;
- }
-
- /**
- * Deletes a value with the specified key from cache
- * This is the implementation of the method declared in the parent class.
- * @param string the key of the value to be deleted
- * @return boolean if no error happens during deletion
- */
- protected function deleteValue($key)
- {
- return xcache_unset($key);
- }
-
- /**
- * Deletes all values from cache.
- * Be careful of performing this operation if the cache is shared by multiple applications.
- */
- public function flush()
- {
- for($i=0, $max=xcache_count(XC_TYPE_VAR); $i<$max; $i++)
- {
- if(xcache_clear_cache(XC_TYPE_VAR, $i)===false)
- return false;
- }
- return true;
- }
-}
-
-?>
+<?php
+/**
+ * TXCache class file
+ *
+ * @author Wei Zhuo <weizhuo[at]gmail[dot]com>
+ * @link http://www.pradosoft.com/
+ * @copyright Copyright &copy; 2005-2012 PradoSoft
+ * @license http://www.pradosoft.com/license/
+ * @version $Id: TXCache.php 1994 2007-06-11 16:02:28Z knut $
+ * @package System.Caching
+ */
+
+/**
+ * TXCache class
+ *
+ * TXCache implements a cache application module based on {@link http://xcache.lighttpd.net/ xcache}.
+ *
+ * By definition, cache does not ensure the existence of a value
+ * even if it never expires. Cache is not meant to be an persistent storage.
+ *
+ * To use this module, the xcache PHP extension must be loaded and configured in the php.ini.
+ *
+ * Some usage examples of TXCache are as follows,
+ * <code>
+ * $cache=new TXCache; // TXCache may also be loaded as a Prado application module
+ * $cache->init(null);
+ * $cache->add('object',$object);
+ * $object2=$cache->get('object');
+ * </code>
+ *
+ * If loaded, TXCache will register itself with {@link TApplication} as the
+ * cache module. It can be accessed via {@link TApplication::getCache()}.
+ *
+ * TXCache may be configured in application configuration file as follows
+ * <code>
+ * <module id="cache" class="System.Caching.TXCache" />
+ * </code>
+ *
+ * @author Wei Zhuo <weizhuo[at]gmail[dot]com>
+ * @version $Id: TXCache.php 1994 2007-06-11 16:02:28Z knut $
+ * @package System.Caching
+ * @since 3.1.1
+ */
+class TXCache extends TCache
+{
+ /**
+ * Initializes this module.
+ * This method is required by the IModule interface.
+ * @param TXmlElement configuration for this module, can be null
+ * @throws TConfigurationException if xcache extension is not installed or not started, check your php.ini
+ */
+ public function init($config)
+ {
+ if(!function_exists('xcache_isset'))
+ throw new TConfigurationException('xcache_extension_required');
+
+ $enabled = (int)ini_get('xcache.cacher') !== 0;
+ $var_size = (int)ini_get('xcache.var_size');
+
+ if(!($enabled && $var_size > 0))
+ throw new TConfigurationException('xcache_extension_not_enabled');
+
+ parent::init($config);
+ }
+
+ /**
+ * Retrieves a value from cache with a specified key.
+ * This is the implementation of the method declared in the parent class.
+ * @param string a unique key identifying the cached value
+ * @return string the value stored in cache, false if the value is not in the cache or expired.
+ */
+ protected function getValue($key)
+ {
+ return xcache_isset($key) ? xcache_get($key) : false;
+ }
+
+ /**
+ * Stores a value identified by a key in cache.
+ * This is the implementation of the method declared in the parent class.
+ *
+ * @param string the key identifying the value to be cached
+ * @param string the value to be cached
+ * @param integer the number of seconds in which the cached value will expire. 0 means never expire.
+ * @return boolean true if the value is successfully stored into cache, false otherwise
+ */
+ protected function setValue($key,$value,$expire)
+ {
+ return xcache_set($key,$value,$expire);
+ }
+
+ /**
+ * Stores a value identified by a key into cache if the cache does not contain this key.
+ * This is the implementation of the method declared in the parent class.
+ *
+ * @param string the key identifying the value to be cached
+ * @param string the value to be cached
+ * @param integer the number of seconds in which the cached value will expire. 0 means never expire.
+ * @return boolean true if the value is successfully stored into cache, false otherwise
+ */
+ protected function addValue($key,$value,$expire)
+ {
+ return !xcache_isset($key) ? $this->setValue($key,$value,$expire) : false;
+ }
+
+ /**
+ * Deletes a value with the specified key from cache
+ * This is the implementation of the method declared in the parent class.
+ * @param string the key of the value to be deleted
+ * @return boolean if no error happens during deletion
+ */
+ protected function deleteValue($key)
+ {
+ return xcache_unset($key);
+ }
+
+ /**
+ * Deletes all values from cache.
+ * Be careful of performing this operation if the cache is shared by multiple applications.
+ */
+ public function flush()
+ {
+ for($i=0, $max=xcache_count(XC_TYPE_VAR); $i<$max; $i++)
+ {
+ if(xcache_clear_cache(XC_TYPE_VAR, $i)===false)
+ return false;
+ }
+ return true;
+ }
+}
+
+?>
diff --git a/framework/Collections/TAttributeCollection.php b/framework/Collections/TAttributeCollection.php
index dd5fa273..85f9b23d 100644
--- a/framework/Collections/TAttributeCollection.php
+++ b/framework/Collections/TAttributeCollection.php
@@ -1,172 +1,172 @@
-<?php
-/**
- * TAttributeCollection classes
- *
- * @author Qiang Xue <qiang.xue@gmail.com>
- * @link http://www.pradosoft.com/
+<?php
+/**
+ * TAttributeCollection classes
+ *
+ * @author Qiang Xue <qiang.xue@gmail.com>
+ * @link http://www.pradosoft.com/
* @copyright Copyright &copy; 2005-2012 PradoSoft
- * @license http://www.pradosoft.com/license/
- * @version $Id$
- * @package System.Collections
- */
-
-/**
- * Includes TMap class
- */
-Prado::using('System.Collections.TMap');
-
-/**
- * TAttributeCollection class
- *
- * TAttributeCollection implements a collection for storing attribute names and values.
- *
- * Besides all functionalities provided by {@link TMap}, TAttributeCollection
- * allows you to get and set attribute values like getting and setting
- * properties. For example, the following usages are all valid for a
- * TAttributeCollection object:
- * <code>
- * $collection->Text='text';
- * echo $collection->Text;
- * </code>
- * They are equivalent to the following:
- * <code>
- * $collection->add('Text','text');
- * echo $collection->itemAt('Text');
- * </code>
- *
- * Note, attribute names are case-insensitive. They are converted to lower-case
- * in the collection storage.
- *
- * @author Qiang Xue <qiang.xue@gmail.com>
- * @version $Id$
- * @package System.Collections
- * @since 3.0
- */
-class TAttributeCollection extends TMap
-{
- private $_caseSensitive=false;
-
- /**
- * Returns a property value or an event handler list by property or event name.
- * This method overrides the parent implementation by returning
- * a key value if the key exists in the collection.
- * @param string the property name or the event name
- * @return mixed the property value or the event handler list
- * @throws TInvalidOperationException if the property/event is not defined.
- */
- public function __get($name)
- {
- return $this->contains($name)?$this->itemAt($name):parent::__get($name);
- }
-
- /**
- * Sets value of a component property.
- * This method overrides the parent implementation by adding a new key value
- * to the collection.
- * @param string the property name or event name
- * @param mixed the property value or event handler
- * @throws TInvalidOperationException If the property is not defined or read-only.
- */
- public function __set($name,$value)
- {
- $this->add($name,$value);
- }
-
- /**
- * @return boolean whether the keys are case-sensitive. Defaults to false.
- */
- public function getCaseSensitive()
- {
- return $this->_caseSensitive;
- }
-
- /**
- * @param boolean whether the keys are case-sensitive.
- */
- public function setCaseSensitive($value)
- {
- $this->_caseSensitive=TPropertyValue::ensureBoolean($value);
- }
-
- /**
- * Returns the item with the specified key.
- * This overrides the parent implementation by converting the key to lower case first if CaseSensitive is false.
- * @param mixed the key
- * @return mixed the element at the offset, null if no element is found at the offset
- */
- public function itemAt($key)
- {
- return parent::itemAt($this->_caseSensitive?$key:strtolower($key));
- }
-
-
- /**
- * Adds an item into the map.
- * This overrides the parent implementation by converting the key to lower case first if CaseSensitive is false.
- * @param mixed key
- * @param mixed value
- */
- public function add($key,$value)
- {
- parent::add($this->_caseSensitive?$key:strtolower($key),$value);
- }
-
- /**
- * Removes an item from the map by its key.
- * This overrides the parent implementation by converting the key to lower case first if CaseSensitive is false.
- * @param mixed the key of the item to be removed
- * @return mixed the removed value, null if no such key exists.
- */
- public function remove($key)
- {
- return parent::remove($this->_caseSensitive?$key:strtolower($key));
- }
-
- /**
- * Returns whether the specified is in the map.
- * This overrides the parent implementation by converting the key to lower case first if CaseSensitive is false.
- * @param mixed the key
- * @return boolean whether the map contains an item with the specified key
- */
- public function contains($key)
- {
- return parent::contains($this->_caseSensitive?$key:strtolower($key));
- }
-
- /**
- * Determines whether a property is defined.
- * This method overrides parent implementation by returning true
- * if the collection contains the named key.
- * @param string the property name
- * @return boolean whether the property is defined
- */
- public function hasProperty($name)
- {
- return $this->contains($name) || parent::hasProperty($name);
- }
-
- /**
- * Determines whether a property can be read.
- * This method overrides parent implementation by returning true
- * if the collection contains the named key.
- * @param string the property name
- * @return boolean whether the property can be read
- */
- public function canGetProperty($name)
- {
- return $this->contains($name) || parent::canGetProperty($name);
- }
-
- /**
- * Determines whether a property can be set.
- * This method overrides parent implementation by always returning true
- * because you can always add a new value to the collection.
- * @param string the property name
- * @return boolean true
- */
- public function canSetProperty($name)
- {
- return true;
- }
-}
-
+ * @license http://www.pradosoft.com/license/
+ * @version $Id$
+ * @package System.Collections
+ */
+
+/**
+ * Includes TMap class
+ */
+Prado::using('System.Collections.TMap');
+
+/**
+ * TAttributeCollection class
+ *
+ * TAttributeCollection implements a collection for storing attribute names and values.
+ *
+ * Besides all functionalities provided by {@link TMap}, TAttributeCollection
+ * allows you to get and set attribute values like getting and setting
+ * properties. For example, the following usages are all valid for a
+ * TAttributeCollection object:
+ * <code>
+ * $collection->Text='text';
+ * echo $collection->Text;
+ * </code>
+ * They are equivalent to the following:
+ * <code>
+ * $collection->add('Text','text');
+ * echo $collection->itemAt('Text');
+ * </code>
+ *
+ * Note, attribute names are case-insensitive. They are converted to lower-case
+ * in the collection storage.
+ *
+ * @author Qiang Xue <qiang.xue@gmail.com>
+ * @version $Id$
+ * @package System.Collections
+ * @since 3.0
+ */
+class TAttributeCollection extends TMap
+{
+ private $_caseSensitive=false;
+
+ /**
+ * Returns a property value or an event handler list by property or event name.
+ * This method overrides the parent implementation by returning
+ * a key value if the key exists in the collection.
+ * @param string the property name or the event name
+ * @return mixed the property value or the event handler list
+ * @throws TInvalidOperationException if the property/event is not defined.
+ */
+ public function __get($name)
+ {
+ return $this->contains($name)?$this->itemAt($name):parent::__get($name);
+ }
+
+ /**
+ * Sets value of a component property.
+ * This method overrides the parent implementation by adding a new key value
+ * to the collection.
+ * @param string the property name or event name
+ * @param mixed the property value or event handler
+ * @throws TInvalidOperationException If the property is not defined or read-only.
+ */
+ public function __set($name,$value)
+ {
+ $this->add($name,$value);
+ }
+
+ /**
+ * @return boolean whether the keys are case-sensitive. Defaults to false.
+ */
+ public function getCaseSensitive()
+ {
+ return $this->_caseSensitive;
+ }
+
+ /**
+ * @param boolean whether the keys are case-sensitive.
+ */
+ public function setCaseSensitive($value)
+ {
+ $this->_caseSensitive=TPropertyValue::ensureBoolean($value);
+ }
+
+ /**
+ * Returns the item with the specified key.
+ * This overrides the parent implementation by converting the key to lower case first if CaseSensitive is false.
+ * @param mixed the key
+ * @return mixed the element at the offset, null if no element is found at the offset
+ */
+ public function itemAt($key)
+ {
+ return parent::itemAt($this->_caseSensitive?$key:strtolower($key));
+ }
+
+
+ /**
+ * Adds an item into the map.
+ * This overrides the parent implementation by converting the key to lower case first if CaseSensitive is false.
+ * @param mixed key
+ * @param mixed value
+ */
+ public function add($key,$value)
+ {
+ parent::add($this->_caseSensitive?$key:strtolower($key),$value);
+ }
+
+ /**
+ * Removes an item from the map by its key.
+ * This overrides the parent implementation by converting the key to lower case first if CaseSensitive is false.
+ * @param mixed the key of the item to be removed
+ * @return mixed the removed value, null if no such key exists.
+ */
+ public function remove($key)
+ {
+ return parent::remove($this->_caseSensitive?$key:strtolower($key));
+ }
+
+ /**
+ * Returns whether the specified is in the map.
+ * This overrides the parent implementation by converting the key to lower case first if CaseSensitive is false.
+ * @param mixed the key
+ * @return boolean whether the map contains an item with the specified key
+ */
+ public function contains($key)
+ {
+ return parent::contains($this->_caseSensitive?$key:strtolower($key));
+ }
+
+ /**
+ * Determines whether a property is defined.
+ * This method overrides parent implementation by returning true
+ * if the collection contains the named key.
+ * @param string the property name
+ * @return boolean whether the property is defined
+ */
+ public function hasProperty($name)
+ {
+ return $this->contains($name) || parent::hasProperty($name);
+ }
+
+ /**
+ * Determines whether a property can be read.
+ * This method overrides parent implementation by returning true
+ * if the collection contains the named key.
+ * @param string the property name
+ * @return boolean whether the property can be read
+ */
+ public function canGetProperty($name)
+ {
+ return $this->contains($name) || parent::canGetProperty($name);
+ }
+
+ /**
+ * Determines whether a property can be set.
+ * This method overrides parent implementation by always returning true
+ * because you can always add a new value to the collection.
+ * @param string the property name
+ * @return boolean true
+ */
+ public function canSetProperty($name)
+ {
+ return true;
+ }
+}
+
diff --git a/framework/Collections/TDummyDataSource.php b/framework/Collections/TDummyDataSource.php
index c63f5d95..c5804b1e 100644
--- a/framework/Collections/TDummyDataSource.php
+++ b/framework/Collections/TDummyDataSource.php
@@ -1,146 +1,146 @@
-<?php
-/**
- * TDummyDataSource, TDummyDataSourceIterator classes
- *
- * @author Qiang Xue <qiang.xue@gmail.com>
- * @link http://www.pradosoft.com/
+<?php
+/**
+ * TDummyDataSource, TDummyDataSourceIterator classes
+ *
+ * @author Qiang Xue <qiang.xue@gmail.com>
+ * @link http://www.pradosoft.com/
* @copyright Copyright &copy; 2005-2012 PradoSoft
- * @license http://www.pradosoft.com/license/
- * @version $Id$
- * @package System.Collections
- */
-
-/**
- * TDummyDataSource class
- *
- * TDummyDataSource implements a dummy data collection with a specified number
- * of dummy data items. The number of virtual items can be set via
- * {@link setCount Count} property. You can traverse it using <b>foreach</b>
- * PHP statement like the following,
- * <code>
- * foreach($dummyDataSource as $dataItem)
- * </code>
- *
- * @author Qiang Xue <qiang.xue@gmail.com>
- * @version $Id$
- * @package System.Collections
- * @since 3.0
- */
-class TDummyDataSource extends TComponent implements IteratorAggregate, Countable
-{
- private $_count;
-
- /**
- * Constructor.
- * @param integer number of (virtual) items in the data source.
- */
- public function __construct($count)
- {
- $this->_count=$count;
- }
-
- /**
- * @return integer number of (virtual) items in the data source.
- */
- public function getCount()
- {
- return $this->_count;
- }
-
- /**
- * @return Iterator iterator
- */
- public function getIterator()
- {
- return new TDummyDataSourceIterator($this->_count);
- }
-
- /**
- * Returns the number of (virtual) items in the data source.
- * This method is required by Countable interface.
- * @return integer number of (virtual) items in the data source.
- */
- public function count()
- {
- return $this->getCount();
- }
-}
-
-/**
- * TDummyDataSourceIterator class
- *
- * TDummyDataSourceIterator implements Iterator interface.
- *
- * TDummyDataSourceIterator is used by {@link TDummyDataSource}.
- * It allows TDummyDataSource to return a new iterator
- * for traversing its dummy items.
- *
- * @author Qiang Xue <qiang.xue@gmail.com>
- * @version $Id$
- * @package System.Collections
- * @since 3.0
- */
-class TDummyDataSourceIterator implements Iterator
-{
- private $_index;
- private $_count;
-
- /**
- * Constructor.
- * @param integer number of (virtual) items in the data source.
- */
- public function __construct($count)
- {
- $this->_count=$count;
- $this->_index=0;
- }
-
- /**
- * Rewinds internal array pointer.
- * This method is required by the interface Iterator.
- */
- public function rewind()
- {
- $this->_index=0;
- }
-
- /**
- * Returns the key of the current array item.
- * This method is required by the interface Iterator.
- * @return integer the key of the current array item
- */
- public function key()
- {
- return $this->_index;
- }
-
- /**
- * Returns the current array item.
- * This method is required by the interface Iterator.
- * @return mixed the current array item
- */
- public function current()
- {
- return null;
- }
-
- /**
- * Moves the internal pointer to the next array item.
- * This method is required by the interface Iterator.
- */
- public function next()
- {
- $this->_index++;
- }
-
- /**
- * Returns whether there is an item at current position.
- * This method is required by the interface Iterator.
- * @return boolean
- */
- public function valid()
- {
- return $this->_index<$this->_count;
- }
-}
-
+ * @license http://www.pradosoft.com/license/
+ * @version $Id$
+ * @package System.Collections
+ */
+
+/**
+ * TDummyDataSource class
+ *
+ * TDummyDataSource implements a dummy data collection with a specified number
+ * of dummy data items. The number of virtual items can be set via
+ * {@link setCount Count} property. You can traverse it using <b>foreach</b>
+ * PHP statement like the following,
+ * <code>
+ * foreach($dummyDataSource as $dataItem)
+ * </code>
+ *
+ * @author Qiang Xue <qiang.xue@gmail.com>
+ * @version $Id$
+ * @package System.Collections
+ * @since 3.0
+ */
+class TDummyDataSource extends TComponent implements IteratorAggregate, Countable
+{
+ private $_count;
+
+ /**
+ * Constructor.
+ * @param integer number of (virtual) items in the data source.
+ */
+ public function __construct($count)
+ {
+ $this->_count=$count;
+ }
+
+ /**
+ * @return integer number of (virtual) items in the data source.
+ */
+ public function getCount()
+ {
+ return $this->_count;
+ }
+
+ /**
+ * @return Iterator iterator
+ */
+ public function getIterator()
+ {
+ return new TDummyDataSourceIterator($this->_count);
+ }
+
+ /**
+ * Returns the number of (virtual) items in the data source.
+ * This method is required by Countable interface.
+ * @return integer number of (virtual) items in the data source.
+ */
+ public function count()
+ {
+ return $this->getCount();
+ }
+}
+
+/**
+ * TDummyDataSourceIterator class
+ *
+ * TDummyDataSourceIterator implements Iterator interface.
+ *
+ * TDummyDataSourceIterator is used by {@link TDummyDataSource}.
+ * It allows TDummyDataSource to return a new iterator
+ * for traversing its dummy items.
+ *
+ * @author Qiang Xue <qiang.xue@gmail.com>
+ * @version $Id$
+ * @package System.Collections
+ * @since 3.0
+ */
+class TDummyDataSourceIterator implements Iterator
+{
+ private $_index;
+ private $_count;
+
+ /**
+ * Constructor.
+ * @param integer number of (virtual) items in the data source.
+ */
+ public function __construct($count)
+ {
+ $this->_count=$count;
+ $this->_index=0;
+ }
+
+ /**
+ * Rewinds internal array pointer.
+ * This method is required by the interface Iterator.
+ */
+ public function rewind()
+ {
+ $this->_index=0;
+ }
+
+ /**
+ * Returns the key of the current array item.
+ * This method is required by the interface Iterator.
+ * @return integer the key of the current array item
+ */
+ public function key()
+ {
+ return $this->_index;
+ }
+
+ /**
+ * Returns the current array item.
+ * This method is required by the interface Iterator.
+ * @return mixed the current array item
+ */
+ public function current()
+ {
+ return null;
+ }
+
+ /**
+ * Moves the internal pointer to the next array item.
+ * This method is required by the interface Iterator.
+ */
+ public function next()
+ {
+ $this->_index++;
+ }
+
+ /**
+ * Returns whether there is an item at current position.
+ * This method is required by the interface Iterator.
+ * @return boolean
+ */
+ public function valid()
+ {
+ return $this->_index<$this->_count;
+ }
+}
+
diff --git a/framework/Collections/TList.php b/framework/Collections/TList.php
index 1e4c439c..4ba4fb58 100644
--- a/framework/Collections/TList.php
+++ b/framework/Collections/TList.php
@@ -1,486 +1,486 @@
-<?php
-/**
- * TList, TListIterator classes
- *
- * @author Qiang Xue <qiang.xue@gmail.com>
- * @link http://www.pradosoft.com/
- * @copyright Copyright &copy; 2005-2012 PradoSoft
- * @license http://www.pradosoft.com/license/
- * @version $Id$
- * @package System.Collections
- */
-
-/**
- * TList class
- *
- * TList implements an integer-indexed collection class.
- *
- * You can access, append, insert, remove an item by using
- * {@link itemAt}, {@link add}, {@link insertAt}, {@link remove}, and {@link removeAt}.
- * To get the number of the items in the list, use {@link getCount}.
- * TList can also be used like a regular array as follows,
- * <code>
- * $list[]=$item; // append at the end
- * $list[$index]=$item; // $index must be between 0 and $list->Count
- * unset($list[$index]); // remove the item at $index
- * if(isset($list[$index])) // if the list has an item at $index
- * foreach($list as $index=>$item) // traverse each item in the list
- * $n=count($list); // returns the number of items in the list
- * </code>
- *
- * To extend TList by doing additional operations with each addition or removal
- * operation, override {@link insertAt()}, and {@link removeAt()}.
- *
- * @author Qiang Xue <qiang.xue@gmail.com>
- * @version $Id$
- * @package System.Collections
- * @since 3.0
- */
-class TList extends TComponent implements IteratorAggregate,ArrayAccess,Countable
-{
- /**
- * internal data storage
- * @var array
- */
- private $_d=array();
- /**
- * number of items
- * @var integer
- */
- private $_c=0;
- /**
- * @var boolean whether this list is read-only
- */
- private $_r=false;
-
- /**
- * Constructor.
- * Initializes the list with an array or an iterable object.
- * @param array|Iterator the initial data. Default is null, meaning no initialization.
- * @param boolean whether the list is read-only
- * @throws TInvalidDataTypeException If data is not null and neither an array nor an iterator.
- */
- public function __construct($data=null,$readOnly=false)
- {
- if($data!==null)
- $this->copyFrom($data);
- $this->setReadOnly($readOnly);
- }
-
- /**
- * @return boolean whether this list is read-only or not. Defaults to false.
- */
- public function getReadOnly()
- {
- return $this->_r;
- }
-
- /**
- * @param boolean whether this list is read-only or not
- */
- protected function setReadOnly($value)
- {
- $this->_r=TPropertyValue::ensureBoolean($value);
- }
-
- /**
- * Returns an iterator for traversing the items in the list.
- * This method is required by the interface IteratorAggregate.
- * @return Iterator an iterator for traversing the items in the list.
- */
- public function getIterator()
- {
- return new ArrayIterator( $this->_d );
- }
-
- /**
- * Returns the number of items in the list.
- * This method is required by Countable interface.
- * @return integer number of items in the list.
- */
- public function count()
- {
- return $this->getCount();
- }
-
- /**
- * @return integer the number of items in the list
- */
- public function getCount()
- {
- return $this->_c;
- }
-
- /**
- * Returns the item at the specified offset.
- * This method is exactly the same as {@link offsetGet}.
- * @param integer the index of the item
- * @return mixed the item at the index
- * @throws TInvalidDataValueException if the index is out of the range
- */
- public function itemAt($index)
- {
- if($index>=0 && $index<$this->_c)
- return $this->_d[$index];
- else
- throw new TInvalidDataValueException('list_index_invalid',$index);
- }
-
- /**
- * Appends an item at the end of the list.
- * @param mixed new item
- * @return integer the zero-based index at which the item is added
- * @throws TInvalidOperationException if the list is read-only
- */
- public function add($item)
- {
- $this->insertAt($this->_c,$item);
- return $this->_c-1;
- }
-
- /**
- * Inserts an item at the specified position.
- * Original item at the position and the next items
- * will be moved one step towards the end.
- * @param integer the specified position.
- * @param mixed new item
- * @throws TInvalidDataValueException If the index specified exceeds the bound
- * @throws TInvalidOperationException if the list is read-only
- */
- public function insertAt($index,$item)
- {
- if(!$this->_r)
- {
- if($index===$this->_c)
- $this->_d[$this->_c++]=$item;
- else if($index>=0 && $index<$this->_c)
- {
- array_splice($this->_d,$index,0,array($item));
- $this->_c++;
- }
- else
- throw new TInvalidDataValueException('list_index_invalid',$index);
- }
- else
- throw new TInvalidOperationException('list_readonly',get_class($this));
- }
-
- /**
- * Removes an item from the list.
- * The list will first search for the item.
- * The first item found will be removed from the list.
- * @param mixed the item to be removed.
- * @return integer the index at which the item is being removed
- * @throws TInvalidDataValueException If the item does not exist
- * @throws TInvalidOperationException if the list is read-only
- */
- public function remove($item)
- {
- if(!$this->_r)
- {
- if(($index=$this->indexOf($item))>=0)
- {
- $this->removeAt($index);
- return $index;
- }
- else
- throw new TInvalidDataValueException('list_item_inexistent');
- }
- else
- throw new TInvalidOperationException('list_readonly',get_class($this));
- }
-
- /**
- * Removes an item at the specified position.
- * @param integer the index of the item to be removed.
- * @return mixed the removed item.
- * @throws TInvalidDataValueException If the index specified exceeds the bound
- * @throws TInvalidOperationException if the list is read-only
- */
- public function removeAt($index)
- {
- if(!$this->_r)
- {
- if($index>=0 && $index<$this->_c)
- {
- $this->_c--;
- if($index===$this->_c)
- return array_pop($this->_d);
- else
- {
- $item=$this->_d[$index];
- array_splice($this->_d,$index,1);
- return $item;
- }
- }
- else
- throw new TInvalidDataValueException('list_index_invalid',$index);
- }
- else
- throw new TInvalidOperationException('list_readonly',get_class($this));
- }
-
- /**
- * Removes all items in the list.
- * @throws TInvalidOperationException if the list is read-only
- */
- public function clear()
- {
- for($i=$this->_c-1;$i>=0;--$i)
- $this->removeAt($i);
- }
-
- /**
- * @param mixed the item
- * @return boolean whether the list contains the item
- */
- public function contains($item)
- {
- return $this->indexOf($item)>=0;
- }
-
- /**
- * @param mixed the item
- * @return integer the index of the item in the list (0 based), -1 if not found.
- */
- public function indexOf($item)
- {
- if(($index=array_search($item,$this->_d,true))===false)
- return -1;
- else
- return $index;
- }
-
- /**
- * Finds the base item. If found, the item is inserted before it.
- * @param mixed the base item which will be pushed back by the second parameter
- * @param mixed the item
- * @return int the index where the item is inserted
- * @throws TInvalidDataValueException if the base item is not within this list
- * @throws TInvalidOperationException if the list is read-only
- * @since 3.2a
- */
- public function insertBefore($baseitem, $item)
- {
- if(!$this->_r)
- {
- if(($index = $this->indexOf($baseitem)) == -1)
- throw new TInvalidDataValueException('list_item_inexistent');
-
- $this->insertAt($index, $item);
-
- return $index;
- }
- else
- throw new TInvalidOperationException('list_readonly',get_class($this));
- }
-
- /**
- * Finds the base item. If found, the item is inserted after it.
- * @param mixed the base item which comes before the second parameter when added to the list
- * @param mixed the item
- * @return int the index where the item is inserted
- * @throws TInvalidDataValueException if the base item is not within this list
- * @throws TInvalidOperationException if the list is read-only
- * @since 3.2a
- */
- public function insertAfter($baseitem, $item)
- {
- if(!$this->_r)
- {
- if(($index = $this->indexOf($baseitem)) == -1)
- throw new TInvalidDataValueException('list_item_inexistent');
-
- $this->insertAt($index + 1, $item);
-
- return $index + 1;
- }
- else
- throw new TInvalidOperationException('list_readonly',get_class($this));
- }
-
- /**
- * @return array the list of items in array
- */
- public function toArray()
- {
- return $this->_d;
- }
-
- /**
- * Copies iterable data into the list.
- * Note, existing data in the list will be cleared first.
- * @param mixed the data to be copied from, must be an array or object implementing Traversable
- * @throws TInvalidDataTypeException If data is neither an array nor a Traversable.
- */
- public function copyFrom($data)
- {
- if(is_array($data) || ($data instanceof Traversable))
- {
- if($this->_c>0)
- $this->clear();
- foreach($data as $item)
- $this->add($item);
- }
- else if($data!==null)
- throw new TInvalidDataTypeException('list_data_not_iterable');
- }
-
- /**
- * Merges iterable data into the map.
- * New data will be appended to the end of the existing data.
- * @param mixed the data to be merged with, must be an array or object implementing Traversable
- * @throws TInvalidDataTypeException If data is neither an array nor an iterator.
- */
- public function mergeWith($data)
- {
- if(is_array($data) || ($data instanceof Traversable))
- {
- foreach($data as $item)
- $this->add($item);
- }
- else if($data!==null)
- throw new TInvalidDataTypeException('list_data_not_iterable');
- }
-
- /**
- * Returns whether there is an item at the specified offset.
- * This method is required by the interface ArrayAccess.
- * @param integer the offset to check on
- * @return boolean
- */
- public function offsetExists($offset)
- {
- return ($offset>=0 && $offset<$this->_c);
- }
-
- /**
- * Returns the item at the specified offset.
- * This method is required by the interface ArrayAccess.
- * @param integer the offset to retrieve item.
- * @return mixed the item at the offset
- * @throws TInvalidDataValueException if the offset is invalid
- */
- public function offsetGet($offset)
- {
- return $this->itemAt($offset);
- }
-
- /**
- * Sets the item at the specified offset.
- * This method is required by the interface ArrayAccess.
- * @param integer the offset to set item
- * @param mixed the item value
- */
- public function offsetSet($offset,$item)
- {
- if($offset===null || $offset===$this->_c)
- $this->insertAt($this->_c,$item);
- else
- {
- $this->removeAt($offset);
- $this->insertAt($offset,$item);
- }
- }
-
- /**
- * Unsets the item at the specified offset.
- * This method is required by the interface ArrayAccess.
- * @param integer the offset to unset item
- */
- public function offsetUnset($offset)
- {
- $this->removeAt($offset);
- }
-}
-
-
-/**
- * TListIterator class
- *
- * TListIterator implements Iterator interface.
- *
- * TListIterator is used by TList. It allows TList to return a new iterator
- * for traversing the items in the list.
- *
- * @deprecated Issue 264 : ArrayIterator should be used instead
- * @author Qiang Xue <qiang.xue@gmail.com>
- * @version $Id$
- * @package System.Collections
- * @since 3.0
- */
-class TListIterator implements Iterator
-{
- /**
- * @var array the data to be iterated through
- */
- private $_d;
- /**
- * @var integer index of the current item
- */
- private $_i;
- /**
- * @var integer count of the data items
- */
- private $_c;
-
- /**
- * Constructor.
- * @param array the data to be iterated through
- */
- public function __construct(&$data)
- {
- $this->_d=&$data;
- $this->_i=0;
- $this->_c=count($this->_d);
- }
-
- /**
- * Rewinds internal array pointer.
- * This method is required by the interface Iterator.
- */
- public function rewind()
- {
- $this->_i=0;
- }
-
- /**
- * Returns the key of the current array item.
- * This method is required by the interface Iterator.
- * @return integer the key of the current array item
- */
- public function key()
- {
- return $this->_i;
- }
-
- /**
- * Returns the current array item.
- * This method is required by the interface Iterator.
- * @return mixed the current array item
- */
- public function current()
- {
- return $this->_d[$this->_i];
- }
-
- /**
- * Moves the internal pointer to the next array item.
- * This method is required by the interface Iterator.
- */
- public function next()
- {
- $this->_i++;
- }
-
- /**
- * Returns whether there is an item at current position.
- * This method is required by the interface Iterator.
- * @return boolean
- */
- public function valid()
- {
- return $this->_i<$this->_c;
- }
-}
-
+<?php
+/**
+ * TList, TListIterator classes
+ *
+ * @author Qiang Xue <qiang.xue@gmail.com>
+ * @link http://www.pradosoft.com/
+ * @copyright Copyright &copy; 2005-2012 PradoSoft
+ * @license http://www.pradosoft.com/license/
+ * @version $Id$
+ * @package System.Collections
+ */
+
+/**
+ * TList class
+ *
+ * TList implements an integer-indexed collection class.
+ *
+ * You can access, append, insert, remove an item by using
+ * {@link itemAt}, {@link add}, {@link insertAt}, {@link remove}, and {@link removeAt}.
+ * To get the number of the items in the list, use {@link getCount}.
+ * TList can also be used like a regular array as follows,
+ * <code>
+ * $list[]=$item; // append at the end
+ * $list[$index]=$item; // $index must be between 0 and $list->Count
+ * unset($list[$index]); // remove the item at $index
+ * if(isset($list[$index])) // if the list has an item at $index
+ * foreach($list as $index=>$item) // traverse each item in the list
+ * $n=count($list); // returns the number of items in the list
+ * </code>
+ *
+ * To extend TList by doing additional operations with each addition or removal
+ * operation, override {@link insertAt()}, and {@link removeAt()}.
+ *
+ * @author Qiang Xue <qiang.xue@gmail.com>
+ * @version $Id$
+ * @package System.Collections
+ * @since 3.0
+ */
+class TList extends TComponent implements IteratorAggregate,ArrayAccess,Countable
+{
+ /**
+ * internal data storage
+ * @var array
+ */
+ private $_d=array();
+ /**
+ * number of items
+ * @var integer
+ */
+ private $_c=0;
+ /**
+ * @var boolean whether this list is read-only
+ */
+ private $_r=false;
+
+ /**
+ * Constructor.
+ * Initializes the list with an array or an iterable object.
+ * @param array|Iterator the initial data. Default is null, meaning no initialization.
+ * @param boolean whether the list is read-only
+ * @throws TInvalidDataTypeException If data is not null and neither an array nor an iterator.
+ */
+ public function __construct($data=null,$readOnly=false)
+ {
+ if($data!==null)
+ $this->copyFrom($data);
+ $this->setReadOnly($readOnly);
+ }
+
+ /**
+ * @return boolean whether this list is read-only or not. Defaults to false.
+ */
+ public function getReadOnly()
+ {
+ return $this->_r;
+ }
+
+ /**
+ * @param boolean whether this list is read-only or not
+ */
+ protected function setReadOnly($value)
+ {
+ $this->_r=TPropertyValue::ensureBoolean($value);
+ }
+
+ /**
+ * Returns an iterator for traversing the items in the list.
+ * This method is required by the interface IteratorAggregate.
+ * @return Iterator an iterator for traversing the items in the list.
+ */
+ public function getIterator()
+ {
+ return new ArrayIterator( $this->_d );
+ }
+
+ /**
+ * Returns the number of items in the list.
+ * This method is required by Countable interface.
+ * @return integer number of items in the list.
+ */
+ public function count()
+ {
+ return $this->getCount();
+ }
+
+ /**
+ * @return integer the number of items in the list
+ */
+ public function getCount()
+ {
+ return $this->_c;
+ }
+
+ /**
+ * Returns the item at the specified offset.
+ * This method is exactly the same as {@link offsetGet}.
+ * @param integer the index of the item
+ * @return mixed the item at the index
+ * @throws TInvalidDataValueException if the index is out of the range
+ */
+ public function itemAt($index)
+ {
+ if($index>=0 && $index<$this->_c)
+ return $this->_d[$index];
+ else
+ throw new TInvalidDataValueException('list_index_invalid',$index);
+ }
+
+ /**
+ * Appends an item at the end of the list.
+ * @param mixed new item
+ * @return integer the zero-based index at which the item is added
+ * @throws TInvalidOperationException if the list is read-only
+ */
+ public function add($item)
+ {
+ $this->insertAt($this->_c,$item);
+ return $this->_c-1;
+ }
+
+ /**
+ * Inserts an item at the specified position.
+ * Original item at the position and the next items
+ * will be moved one step towards the end.
+ * @param integer the specified position.
+ * @param mixed new item
+ * @throws TInvalidDataValueException If the index specified exceeds the bound
+ * @throws TInvalidOperationException if the list is read-only
+ */
+ public function insertAt($index,$item)
+ {
+ if(!$this->_r)
+ {
+ if($index===$this->_c)
+ $this->_d[$this->_c++]=$item;
+ else if($index>=0 && $index<$this->_c)
+ {
+ array_splice($this->_d,$index,0,array($item));
+ $this->_c++;
+ }
+ else
+ throw new TInvalidDataValueException('list_index_invalid',$index);
+ }
+ else
+ throw new TInvalidOperationException('list_readonly',get_class($this));
+ }
+
+ /**
+ * Removes an item from the list.
+ * The list will first search for the item.
+ * The first item found will be removed from the list.
+ * @param mixed the item to be removed.
+ * @return integer the index at which the item is being removed
+ * @throws TInvalidDataValueException If the item does not exist
+ * @throws TInvalidOperationException if the list is read-only
+ */
+ public function remove($item)
+ {
+ if(!$this->_r)
+ {
+ if(($index=$this->indexOf($item))>=0)
+ {
+ $this->removeAt($index);
+ return $index;
+ }
+ else
+ throw new TInvalidDataValueException('list_item_inexistent');
+ }
+ else
+ throw new TInvalidOperationException('list_readonly',get_class($this));
+ }
+
+ /**
+ * Removes an item at the specified position.
+ * @param integer the index of the item to be removed.
+ * @return mixed the removed item.
+ * @throws TInvalidDataValueException If the index specified exceeds the bound
+ * @throws TInvalidOperationException if the list is read-only
+ */
+ public function removeAt($index)
+ {
+ if(!$this->_r)
+ {
+ if($index>=0 && $index<$this->_c)
+ {
+ $this->_c--;
+ if($index===$this->_c)
+ return array_pop($this->_d);
+ else
+ {
+ $item=$this->_d[$index];
+ array_splice($this->_d,$index,1);
+ return $item;
+ }
+ }
+ else
+ throw new TInvalidDataValueException('list_index_invalid',$index);
+ }
+ else
+ throw new TInvalidOperationException('list_readonly',get_class($this));
+ }
+
+ /**
+ * Removes all items in the list.
+ * @throws TInvalidOperationException if the list is read-only
+ */
+ public function clear()
+ {
+ for($i=$this->_c-1;$i>=0;--$i)
+ $this->removeAt($i);
+ }
+
+ /**
+ * @param mixed the item
+ * @return boolean whether the list contains the item
+ */
+ public function contains($item)
+ {
+ return $this->indexOf($item)>=0;
+ }
+
+ /**
+ * @param mixed the item
+ * @return integer the index of the item in the list (0 based), -1 if not found.
+ */
+ public function indexOf($item)
+ {
+ if(($index=array_search($item,$this->_d,true))===false)
+ return -1;
+ else
+ return $index;
+ }
+
+ /**
+ * Finds the base item. If found, the item is inserted before it.
+ * @param mixed the base item which will be pushed back by the second parameter
+ * @param mixed the item
+ * @return int the index where the item is inserted
+ * @throws TInvalidDataValueException if the base item is not within this list
+ * @throws TInvalidOperationException if the list is read-only
+ * @since 3.2a
+ */
+ public function insertBefore($baseitem, $item)
+ {
+ if(!$this->_r)
+ {
+ if(($index = $this->indexOf($baseitem)) == -1)
+ throw new TInvalidDataValueException('list_item_inexistent');
+
+ $this->insertAt($index, $item);
+
+ return $index;
+ }
+ else
+ throw new TInvalidOperationException('list_readonly',get_class($this));
+ }
+
+ /**
+ * Finds the base item. If found, the item is inserted after it.
+ * @param mixed the base item which comes before the second parameter when added to the list
+ * @param mixed the item
+ * @return int the index where the item is inserted
+ * @throws TInvalidDataValueException if the base item is not within this list
+ * @throws TInvalidOperationException if the list is read-only
+ * @since 3.2a
+ */
+ public function insertAfter($baseitem, $item)
+ {
+ if(!$this->_r)
+ {
+ if(($index = $this->indexOf($baseitem)) == -1)
+ throw new TInvalidDataValueException('list_item_inexistent');
+
+ $this->insertAt($index + 1, $item);
+
+ return $index + 1;
+ }
+ else
+ throw new TInvalidOperationException('list_readonly',get_class($this));
+ }
+
+ /**
+ * @return array the list of items in array
+ */
+ public function toArray()
+ {
+ return $this->_d;
+ }
+
+ /**
+ * Copies iterable data into the list.
+ * Note, existing data in the list will be cleared first.
+ * @param mixed the data to be copied from, must be an array or object implementing Traversable
+ * @throws TInvalidDataTypeException If data is neither an array nor a Traversable.
+ */
+ public function copyFrom($data)
+ {
+ if(is_array($data) || ($data instanceof Traversable))
+ {
+ if($this->_c>0)
+ $this->clear();
+ foreach($data as $item)
+ $this->add($item);
+ }
+ else if($data!==null)
+ throw new TInvalidDataTypeException('list_data_not_iterable');
+ }
+
+ /**
+ * Merges iterable data into the map.
+ * New data will be appended to the end of the existing data.
+ * @param mixed the data to be merged with, must be an array or object implementing Traversable
+ * @throws TInvalidDataTypeException If data is neither an array nor an iterator.
+ */
+ public function mergeWith($data)
+ {
+ if(is_array($data) || ($data instanceof Traversable))
+ {
+ foreach($data as $item)
+ $this->add($item);
+ }
+ else if($data!==null)
+ throw new TInvalidDataTypeException('list_data_not_iterable');
+ }
+
+ /**
+ * Returns whether there is an item at the specified offset.
+ * This method is required by the interface ArrayAccess.
+ * @param integer the offset to check on
+ * @return boolean
+ */
+ public function offsetExists($offset)
+ {
+ return ($offset>=0 && $offset<$this->_c);
+ }
+
+ /**
+ * Returns the item at the specified offset.
+ * This method is required by the interface ArrayAccess.
+ * @param integer the offset to retrieve item.
+ * @return mixed the item at the offset
+ * @throws TInvalidDataValueException if the offset is invalid
+ */
+ public function offsetGet($offset)
+ {
+ return $this->itemAt($offset);
+ }
+
+ /**
+ * Sets the item at the specified offset.
+ * This method is required by the interface ArrayAccess.
+ * @param integer the offset to set item
+ * @param mixed the item value
+ */
+ public function offsetSet($offset,$item)
+ {
+ if($offset===null || $offset===$this->_c)
+ $this->insertAt($this->_c,$item);
+ else
+ {
+ $this->removeAt($offset);
+ $this->insertAt($offset,$item);
+ }
+ }
+
+ /**
+ * Unsets the item at the specified offset.
+ * This method is required by the interface ArrayAccess.
+ * @param integer the offset to unset item
+ */
+ public function offsetUnset($offset)
+ {
+ $this->removeAt($offset);
+ }
+}
+
+
+/**
+ * TListIterator class
+ *
+ * TListIterator implements Iterator interface.
+ *
+ * TListIterator is used by TList. It allows TList to return a new iterator
+ * for traversing the items in the list.
+ *
+ * @deprecated Issue 264 : ArrayIterator should be used instead
+ * @author Qiang Xue <qiang.xue@gmail.com>
+ * @version $Id$
+ * @package System.Collections
+ * @since 3.0
+ */
+class TListIterator implements Iterator
+{
+ /**
+ * @var array the data to be iterated through
+ */
+ private $_d;
+ /**
+ * @var integer index of the current item
+ */
+ private $_i;
+ /**
+ * @var integer count of the data items
+ */
+ private $_c;
+
+ /**
+ * Constructor.
+ * @param array the data to be iterated through
+ */
+ public function __construct(&$data)
+ {
+ $this->_d=&$data;
+ $this->_i=0;
+ $this->_c=count($this->_d);
+ }
+
+ /**
+ * Rewinds internal array pointer.
+ * This method is required by the interface Iterator.
+ */
+ public function rewind()
+ {
+ $this->_i=0;
+ }
+
+ /**
+ * Returns the key of the current array item.
+ * This method is required by the interface Iterator.
+ * @return integer the key of the current array item
+ */
+ public function key()
+ {
+ return $this->_i;
+ }
+
+ /**
+ * Returns the current array item.
+ * This method is required by the interface Iterator.
+ * @return mixed the current array item
+ */
+ public function current()
+ {
+ return $this->_d[$this->_i];
+ }
+
+ /**
+ * Moves the internal pointer to the next array item.
+ * This method is required by the interface Iterator.
+ */
+ public function next()
+ {
+ $this->_i++;
+ }
+
+ /**
+ * Returns whether there is an item at current position.
+ * This method is required by the interface Iterator.
+ * @return boolean
+ */
+ public function valid()
+ {
+ return $this->_i<$this->_c;
+ }
+}
+
diff --git a/framework/Collections/TListItemCollection.php b/framework/Collections/TListItemCollection.php
index 73158553..13a44bcd 100644
--- a/framework/Collections/TListItemCollection.php
+++ b/framework/Collections/TListItemCollection.php
@@ -1,164 +1,164 @@
-<?php
-
-/**
- * TListItemCollection class file
- *
- * @author Robin J. Rogge <rojaro@gmail.com>
- * @author Qiang Xue <qiang.xue@gmail.com>
- * @link http://www.pradosoft.com/
- * @copyright Copyright &copy; 2005-2012 PradoSoft
- * @license http://www.pradosoft.com/license/
- * @version $Id: TListControl.php 2624 2009-03-19 21:20:47Z godzilla80@gmx.net $
- * @package System.Collections
- */
-
-/**
- * Includes the supporting classes
- */
-Prado::using('System.Collections.TList');
-Prado::using('System.Web.UI.WebControls.TListItem');
-
-/**
- * TListItemCollection class.
- *
- * TListItemCollection maintains a list of {@link TListItem} for {@link TListControl}.
- *
- * @author Qiang Xue <qiang.xue@gmail.com>
- * @version $Id: TListControl.php 2624 2009-03-19 21:20:47Z godzilla80@gmx.net $
- * @package System.Collections
- * @since 3.0
- */
-class TListItemCollection extends TList
-{
- /**
- * Creates a list item object.
- * This method may be overriden to provide a customized list item object.
- * @param integer index where the newly created item is to be inserted at.
- * If -1, the item will be appended to the end.
- * @return TListItem list item object
- */
- public function createListItem($index=-1)
- {
- $item=$this->createNewListItem();
- if($index<0)
- $this->add($item);
- else
- $this->insertAt($index,$item);
- return $item;
- }
-
- /**
- * @return TListItem new item.
- */
- protected function createNewListItem($text=null)
- {
- $item = new TListItem;
- if($text!==null)
- $item->setText($text);
- return $item;
- }
-
- /**
- * Inserts an item into the collection.
- * @param integer the location where the item will be inserted.
- * The current item at the place and the following ones will be moved backward.
- * @param TListItem the item to be inserted.
- * @throws TInvalidDataTypeException if the item being inserted is neither a string nor TListItem
- */
- public function insertAt($index,$item)
- {
- if(is_string($item))
- $item = $this->createNewListItem($item);
- if(!($item instanceof TListItem))
- throw new TInvalidDataTypeException('listitemcollection_item_invalid',get_class($this));
- parent::insertAt($index,$item);
- }
-
- /**
- * Finds the lowest cardinal index of the item whose value is the one being looked for.
- * @param string the value to be looked for
- * @param boolean whether to look for disabled items also
- * @return integer the index of the item found, -1 if not found.
- */
- public function findIndexByValue($value,$includeDisabled=true)
- {
- $value=TPropertyValue::ensureString($value);
- $index=0;
- foreach($this as $item)
- {
- if($item->getValue()===$value && ($includeDisabled || $item->getEnabled()))
- return $index;
- $index++;
- }
- return -1;
- }
-
- /**
- * Finds the lowest cardinal index of the item whose text is the one being looked for.
- * @param string the text to be looked for
- * @param boolean whether to look for disabled items also
- * @return integer the index of the item found, -1 if not found.
- */
- public function findIndexByText($text,$includeDisabled=true)
- {
- $text=TPropertyValue::ensureString($text);
- $index=0;
- foreach($this as $item)
- {
- if($item->getText()===$text && ($includeDisabled || $item->getEnabled()))
- return $index;
- $index++;
- }
- return -1;
- }
-
- /**
- * Finds the item whose value is the one being looked for.
- * @param string the value to be looked for
- * @param boolean whether to look for disabled items also
- * @return TListItem the item found, null if not found.
- */
- public function findItemByValue($value,$includeDisabled=true)
- {
- if(($index=$this->findIndexByValue($value,$includeDisabled))>=0)
- return $this->itemAt($index);
- else
- return null;
- }
-
- /**
- * Finds the item whose text is the one being looked for.
- * @param string the text to be looked for
- * @param boolean whether to look for disabled items also
- * @return TListItem the item found, null if not found.
- */
- public function findItemByText($text,$includeDisabled=true)
- {
- if(($index=$this->findIndexByText($text,$includeDisabled))>=0)
- return $this->itemAt($index);
- else
- return null;
- }
-
- /**
- * Loads state into every item in the collection.
- * This method should only be used by framework and control developers.
- * @param array|null state to be loaded.
- */
- public function loadState($state)
- {
- $this->clear();
- if($state!==null)
- $this->copyFrom($state);
- }
-
- /**
- * Saves state of items.
- * This method should only be used by framework and control developers.
- * @return array|null the saved state
- */
- public function saveState()
- {
- return ($this->getCount()>0) ? $this->toArray() : null;
- }
-}
+<?php
+
+/**
+ * TListItemCollection class file
+ *
+ * @author Robin J. Rogge <rojaro@gmail.com>
+ * @author Qiang Xue <qiang.xue@gmail.com>
+ * @link http://www.pradosoft.com/
+ * @copyright Copyright &copy; 2005-2012 PradoSoft
+ * @license http://www.pradosoft.com/license/
+ * @version $Id: TListControl.php 2624 2009-03-19 21:20:47Z godzilla80@gmx.net $
+ * @package System.Collections
+ */
+
+/**
+ * Includes the supporting classes
+ */
+Prado::using('System.Collections.TList');
+Prado::using('System.Web.UI.WebControls.TListItem');
+
+/**
+ * TListItemCollection class.
+ *
+ * TListItemCollection maintains a list of {@link TListItem} for {@link TListControl}.
+ *
+ * @author Qiang Xue <qiang.xue@gmail.com>
+ * @version $Id: TListControl.php 2624 2009-03-19 21:20:47Z godzilla80@gmx.net $
+ * @package System.Collections
+ * @since 3.0
+ */
+class TListItemCollection extends TList
+{
+ /**
+ * Creates a list item object.
+ * This method may be overriden to provide a customized list item object.
+ * @param integer index where the newly created item is to be inserted at.
+ * If -1, the item will be appended to the end.
+ * @return TListItem list item object
+ */
+ public function createListItem($index=-1)
+ {
+ $item=$this->createNewListItem();
+ if($index<0)
+ $this->add($item);
+ else
+ $this->insertAt($index,$item);
+ return $item;
+ }
+
+ /**
+ * @return TListItem new item.
+ */
+ protected function createNewListItem($text=null)
+ {
+ $item = new TListItem;
+ if($text!==null)
+ $item->setText($text);
+ return $item;
+ }
+
+ /**
+ * Inserts an item into the collection.
+ * @param integer the location where the item will be inserted.
+ * The current item at the place and the following ones will be moved backward.
+ * @param TListItem the item to be inserted.
+ * @throws TInvalidDataTypeException if the item being inserted is neither a string nor TListItem
+ */
+ public function insertAt($index,$item)
+ {
+ if(is_string($item))
+ $item = $this->createNewListItem($item);
+ if(!($item instanceof TListItem))
+ throw new TInvalidDataTypeException('listitemcollection_item_invalid',get_class($this));
+ parent::insertAt($index,$item);
+ }
+
+ /**
+ * Finds the lowest cardinal index of the item whose value is the one being looked for.
+ * @param string the value to be looked for
+ * @param boolean whether to look for disabled items also
+ * @return integer the index of the item found, -1 if not found.
+ */
+ public function findIndexByValue($value,$includeDisabled=true)
+ {
+ $value=TPropertyValue::ensureString($value);
+ $index=0;
+ foreach($this as $item)
+ {
+ if($item->getValue()===$value && ($includeDisabled || $item->getEnabled()))
+ return $index;
+ $index++;
+ }
+ return -1;
+ }
+
+ /**
+ * Finds the lowest cardinal index of the item whose text is the one being looked for.
+ * @param string the text to be looked for
+ * @param boolean whether to look for disabled items also
+ * @return integer the index of the item found, -1 if not found.
+ */
+ public function findIndexByText($text,$includeDisabled=true)
+ {
+ $text=TPropertyValue::ensureString($text);
+ $index=0;
+ foreach($this as $item)
+ {
+ if($item->getText()===$text && ($includeDisabled || $item->getEnabled()))
+ return $index;
+ $index++;
+ }
+ return -1;
+ }
+
+ /**
+ * Finds the item whose value is the one being looked for.
+ * @param string the value to be looked for
+ * @param boolean whether to look for disabled items also
+ * @return TListItem the item found, null if not found.
+ */
+ public function findItemByValue($value,$includeDisabled=true)
+ {
+ if(($index=$this->findIndexByValue($value,$includeDisabled))>=0)
+ return $this->itemAt($index);
+ else
+ return null;
+ }
+
+ /**
+ * Finds the item whose text is the one being looked for.
+ * @param string the text to be looked for
+ * @param boolean whether to look for disabled items also
+ * @return TListItem the item found, null if not found.
+ */
+ public function findItemByText($text,$includeDisabled=true)
+ {
+ if(($index=$this->findIndexByText($text,$includeDisabled))>=0)
+ return $this->itemAt($index);
+ else
+ return null;
+ }
+
+ /**
+ * Loads state into every item in the collection.
+ * This method should only be used by framework and control developers.
+ * @param array|null state to be loaded.
+ */
+ public function loadState($state)
+ {
+ $this->clear();
+ if($state!==null)
+ $this->copyFrom($state);
+ }
+
+ /**
+ * Saves state of items.
+ * This method should only be used by framework and control developers.
+ * @return array|null the saved state
+ */
+ public function saveState()
+ {
+ return ($this->getCount()>0) ? $this->toArray() : null;
+ }
+}
diff --git a/framework/Collections/TMap.php b/framework/Collections/TMap.php
index 200f9aea..a9e8db9d 100644
--- a/framework/Collections/TMap.php
+++ b/framework/Collections/TMap.php
@@ -1,353 +1,353 @@
-<?php
-/**
- * TMap, TMapIterator classes
- *
- * @author Qiang Xue <qiang.xue@gmail.com>
- * @link http://www.pradosoft.com/
+<?php
+/**
+ * TMap, TMapIterator classes
+ *
+ * @author Qiang Xue <qiang.xue@gmail.com>
+ * @link http://www.pradosoft.com/
* @copyright Copyright &copy; 2005-2012 PradoSoft
- * @license http://www.pradosoft.com/license/
- * @version $Id$
- * @package System.Collections
- */
-
-/**
- * TMap class
- *
- * TMap implements a collection that takes key-value pairs.
- *
- * You can access, add or remove an item with a key by using
- * {@link itemAt}, {@link add}, and {@link remove}.
- * To get the number of the items in the map, use {@link getCount}.
- * TMap can also be used like a regular array as follows,
- * <code>
- * $map[$key]=$value; // add a key-value pair
- * unset($map[$key]); // remove the value with the specified key
- * if(isset($map[$key])) // if the map contains the key
- * foreach($map as $key=>$value) // traverse the items in the map
- * $n=count($map); // returns the number of items in the map
- * </code>
- *
- * @author Qiang Xue <qiang.xue@gmail.com>
- * @version $Id$
- * @package System.Collections
- * @since 3.0
- */
-class TMap extends TComponent implements IteratorAggregate,ArrayAccess,Countable
-{
- /**
- * @var array internal data storage
- */
- private $_d=array();
- /**
- * @var boolean whether this list is read-only
- */
- private $_r=false;
-
- /**
- * Constructor.
- * Initializes the list with an array or an iterable object.
- * @param array|Iterator the intial data. Default is null, meaning no initialization.
- * @param boolean whether the list is read-only
- * @throws TInvalidDataTypeException If data is not null and neither an array nor an iterator.
- */
- public function __construct($data=null,$readOnly=false)
- {
- if($data!==null)
- $this->copyFrom($data);
- $this->setReadOnly($readOnly);
- }
-
- /**
- * @return boolean whether this map is read-only or not. Defaults to false.
- */
- public function getReadOnly()
- {
- return $this->_r;
- }
-
- /**
- * @param boolean whether this list is read-only or not
- */
- protected function setReadOnly($value)
- {
- $this->_r=TPropertyValue::ensureBoolean($value);
- }
-
- /**
- * Returns an iterator for traversing the items in the list.
- * This method is required by the interface IteratorAggregate.
- * @return Iterator an iterator for traversing the items in the list.
- */
- public function getIterator()
- {
- return new ArrayIterator( $this->_d );
- }
-
- /**
- * Returns the number of items in the map.
- * This method is required by Countable interface.
- * @return integer number of items in the map.
- */
- public function count()
- {
- return $this->getCount();
- }
-
- /**
- * @return integer the number of items in the map
- */
- public function getCount()
- {
- return count($this->_d);
- }
-
- /**
- * @return array the key list
- */
- public function getKeys()
- {
- return array_keys($this->_d);
- }
-
- /**
- * Returns the item with the specified key.
- * This method is exactly the same as {@link offsetGet}.
- * @param mixed the key
- * @return mixed the element at the offset, null if no element is found at the offset
- */
- public function itemAt($key)
- {
- return isset($this->_d[$key]) ? $this->_d[$key] : null;
- }
-
- /**
- * Adds an item into the map.
- * Note, if the specified key already exists, the old value will be overwritten.
- * @param mixed key
- * @param mixed value
- * @throws TInvalidOperationException if the map is read-only
- */
- public function add($key,$value)
- {
- if(!$this->_r)
- $this->_d[$key]=$value;
- else
- throw new TInvalidOperationException('map_readonly',get_class($this));
- }
-
- /**
- * Removes an item from the map by its key.
- * @param mixed the key of the item to be removed
- * @return mixed the removed value, null if no such key exists.
- * @throws TInvalidOperationException if the map is read-only
- */
- public function remove($key)
- {
- if(!$this->_r)
- {
- if(isset($this->_d[$key]) || array_key_exists($key,$this->_d))
- {
- $value=$this->_d[$key];
- unset($this->_d[$key]);
- return $value;
- }
- else
- return null;
- }
- else
- throw new TInvalidOperationException('map_readonly',get_class($this));
- }
-
- /**
- * Removes all items in the map.
- */
- public function clear()
- {
- foreach(array_keys($this->_d) as $key)
- $this->remove($key);
- }
-
- /**
- * @param mixed the key
- * @return boolean whether the map contains an item with the specified key
- */
- public function contains($key)
- {
- return isset($this->_d[$key]) || array_key_exists($key,$this->_d);
- }
-
- /**
- * @return array the list of items in array
- */
- public function toArray()
- {
- return $this->_d;
- }
-
- /**
- * Copies iterable data into the map.
- * Note, existing data in the map will be cleared first.
- * @param mixed the data to be copied from, must be an array or object implementing Traversable
- * @throws TInvalidDataTypeException If data is neither an array nor an iterator.
- */
- public function copyFrom($data)
- {
- if(is_array($data) || $data instanceof Traversable)
- {
- if($this->getCount()>0)
- $this->clear();
- foreach($data as $key=>$value)
- $this->add($key,$value);
- }
- else if($data!==null)
- throw new TInvalidDataTypeException('map_data_not_iterable');
- }
-
- /**
- * Merges iterable data into the map.
- * Existing data in the map will be kept and overwritten if the keys are the same.
- * @param mixed the data to be merged with, must be an array or object implementing Traversable
- * @throws TInvalidDataTypeException If data is neither an array nor an iterator.
- */
- public function mergeWith($data)
- {
- if(is_array($data) || $data instanceof Traversable)
- {
- foreach($data as $key=>$value)
- $this->add($key,$value);
- }
- else if($data!==null)
- throw new TInvalidDataTypeException('map_data_not_iterable');
- }
-
- /**
- * Returns whether there is an element at the specified offset.
- * This method is required by the interface ArrayAccess.
- * @param mixed the offset to check on
- * @return boolean
- */
- public function offsetExists($offset)
- {
- return $this->contains($offset);
- }
-
- /**
- * Returns the element at the specified offset.
- * This method is required by the interface ArrayAccess.
- * @param integer the offset to retrieve element.
- * @return mixed the element at the offset, null if no element is found at the offset
- */
- public function offsetGet($offset)
- {
- return $this->itemAt($offset);
- }
-
- /**
- * Sets the element at the specified offset.
- * This method is required by the interface ArrayAccess.
- * @param integer the offset to set element
- * @param mixed the element value
- */
- public function offsetSet($offset,$item)
- {
- $this->add($offset,$item);
- }
-
- /**
- * Unsets the element at the specified offset.
- * This method is required by the interface ArrayAccess.
- * @param mixed the offset to unset element
- */
- public function offsetUnset($offset)
- {
- $this->remove($offset);
- }
-}
-
-/**
- * TMapIterator class
- *
- * TMapIterator implements Iterator interface.
- *
- * TMapIterator is used by TMap. It allows TMap to return a new iterator
- * for traversing the items in the map.
- *
- * @deprecated Issue 264 : ArrayIterator should be used instead
- * @author Qiang Xue <qiang.xue@gmail.com>
- * @version $Id$
- * @package System.Collections
- * @since 3.0
- */
-class TMapIterator implements Iterator
-{
- /**
- * @var array the data to be iterated through
- */
- private $_d;
- /**
- * @var array list of keys in the map
- */
- private $_keys;
- /**
- * @var mixed current key
- */
- private $_key;
-
- /**
- * Constructor.
- * @param array the data to be iterated through
- */
- public function __construct(&$data)
- {
- $this->_d=&$data;
- $this->_keys=array_keys($data);
- }
-
- /**
- * Rewinds internal array pointer.
- * This method is required by the interface Iterator.
- */
- public function rewind()
- {
- $this->_key=reset($this->_keys);
- }
-
- /**
- * Returns the key of the current array element.
- * This method is required by the interface Iterator.
- * @return mixed the key of the current array element
- */
- public function key()
- {
- return $this->_key;
- }
-
- /**
- * Returns the current array element.
- * This method is required by the interface Iterator.
- * @return mixed the current array element
- */
- public function current()
- {
- return $this->_d[$this->_key];
- }
-
- /**
- * Moves the internal pointer to the next array element.
- * This method is required by the interface Iterator.
- */
- public function next()
- {
- $this->_key=next($this->_keys);
- }
-
- /**
- * Returns whether there is an element at current position.
- * This method is required by the interface Iterator.
- * @return boolean
- */
- public function valid()
- {
- return $this->_key!==false;
- }
-}
+ * @license http://www.pradosoft.com/license/
+ * @version $Id$
+ * @package System.Collections
+ */
+
+/**
+ * TMap class
+ *
+ * TMap implements a collection that takes key-value pairs.
+ *
+ * You can access, add or remove an item with a key by using
+ * {@link itemAt}, {@link add}, and {@link remove}.
+ * To get the number of the items in the map, use {@link getCount}.
+ * TMap can also be used like a regular array as follows,
+ * <code>
+ * $map[$key]=$value; // add a key-value pair
+ * unset($map[$key]); // remove the value with the specified key
+ * if(isset($map[$key])) // if the map contains the key
+ * foreach($map as $key=>$value) // traverse the items in the map
+ * $n=count($map); // returns the number of items in the map
+ * </code>
+ *
+ * @author Qiang Xue <qiang.xue@gmail.com>
+ * @version $Id$
+ * @package System.Collections
+ * @since 3.0
+ */
+class TMap extends TComponent implements IteratorAggregate,ArrayAccess,Countable
+{
+ /**
+ * @var array internal data storage
+ */
+ private $_d=array();
+ /**
+ * @var boolean whether this list is read-only
+ */
+ private $_r=false;
+
+ /**
+ * Constructor.
+ * Initializes the list with an array or an iterable object.
+ * @param array|Iterator the intial data. Default is null, meaning no initialization.
+ * @param boolean whether the list is read-only
+ * @throws TInvalidDataTypeException If data is not null and neither an array nor an iterator.
+ */
+ public function __construct($data=null,$readOnly=false)
+ {
+ if($data!==null)
+ $this->copyFrom($data);
+ $this->setReadOnly($readOnly);
+ }
+
+ /**
+ * @return boolean whether this map is read-only or not. Defaults to false.
+ */
+ public function getReadOnly()
+ {
+ return $this->_r;
+ }
+
+ /**
+ * @param boolean whether this list is read-only or not
+ */
+ protected function setReadOnly($value)
+ {
+ $this->_r=TPropertyValue::ensureBoolean($value);
+ }
+
+ /**
+ * Returns an iterator for traversing the items in the list.
+ * This method is required by the interface IteratorAggregate.
+ * @return Iterator an iterator for traversing the items in the list.
+ */
+ public function getIterator()
+ {
+ return new ArrayIterator( $this->_d );
+ }
+
+ /**
+ * Returns the number of items in the map.
+ * This method is required by Countable interface.
+ * @return integer number of items in the map.
+ */
+ public function count()
+ {
+ return $this->getCount();
+ }
+
+ /**
+ * @return integer the number of items in the map
+ */
+ public function getCount()
+ {
+ return count($this->_d);
+ }
+
+ /**
+ * @return array the key list
+ */
+ public function getKeys()
+ {
+ return array_keys($this->_d);
+ }
+
+ /**
+ * Returns the item with the specified key.
+ * This method is exactly the same as {@link offsetGet}.
+ * @param mixed the key
+ * @return mixed the element at the offset, null if no element is found at the offset
+ */
+ public function itemAt($key)
+ {
+ return isset($this->_d[$key]) ? $this->_d[$key] : null;
+ }
+
+ /**
+ * Adds an item into the map.
+ * Note, if the specified key already exists, the old value will be overwritten.
+ * @param mixed key
+ * @param mixed value
+ * @throws TInvalidOperationException if the map is read-only
+ */
+ public function add($key,$value)
+ {
+ if(!$this->_r)
+ $this->_d[$key]=$value;
+ else
+ throw new TInvalidOperationException('map_readonly',get_class($this));
+ }
+
+ /**
+ * Removes an item from the map by its key.
+ * @param mixed the key of the item to be removed
+ * @return mixed the removed value, null if no such key exists.
+ * @throws TInvalidOperationException if the map is read-only
+ */
+ public function remove($key)
+ {
+ if(!$this->_r)
+ {
+ if(isset($this->_d[$key]) || array_key_exists($key,$this->_d))
+ {
+ $value=$this->_d[$key];
+ unset($this->_d[$key]);
+ return $value;
+ }
+ else
+ return null;
+ }
+ else
+ throw new TInvalidOperationException('map_readonly',get_class($this));
+ }
+
+ /**
+ * Removes all items in the map.
+ */
+ public function clear()
+ {
+ foreach(array_keys($this->_d) as $key)
+ $this->remove($key);
+ }
+
+ /**
+ * @param mixed the key
+ * @return boolean whether the map contains an item with the specified key
+ */
+ public function contains($key)
+ {
+ return isset($this->_d[$key]) || array_key_exists($key,$this->_d);
+ }
+
+ /**
+ * @return array the list of items in array
+ */
+ public function toArray()
+ {
+ return $this->_d;
+ }
+
+ /**
+ * Copies iterable data into the map.
+ * Note, existing data in the map will be cleared first.
+ * @param mixed the data to be copied from, must be an array or object implementing Traversable
+ * @throws TInvalidDataTypeException If data is neither an array nor an iterator.
+ */
+ public function copyFrom($data)
+ {
+ if(is_array($data) || $data instanceof Traversable)
+ {
+ if($this->getCount()>0)
+ $this->clear();
+ foreach($data as $key=>$value)
+ $this->add($key,$value);
+ }
+ else if($data!==null)
+ throw new TInvalidDataTypeException('map_data_not_iterable');
+ }
+
+ /**
+ * Merges iterable data into the map.
+ * Existing data in the map will be kept and overwritten if the keys are the same.
+ * @param mixed the data to be merged with, must be an array or object implementing Traversable
+ * @throws TInvalidDataTypeException If data is neither an array nor an iterator.
+ */
+ public function mergeWith($data)
+ {
+ if(is_array($data) || $data instanceof Traversable)
+ {
+ foreach($data as $key=>$value)
+ $this->add($key,$value);
+ }
+ else if($data!==null)
+ throw new TInvalidDataTypeException('map_data_not_iterable');
+ }
+
+ /**
+ * Returns whether there is an element at the specified offset.
+ * This method is required by the interface ArrayAccess.
+ * @param mixed the offset to check on
+ * @return boolean
+ */
+ public function offsetExists($offset)
+ {
+ return $this->contains($offset);
+ }
+
+ /**
+ * Returns the element at the specified offset.
+ * This method is required by the interface ArrayAccess.
+ * @param integer the offset to retrieve element.
+ * @return mixed the element at the offset, null if no element is found at the offset
+ */
+ public function offsetGet($offset)
+ {
+ return $this->itemAt($offset);
+ }
+
+ /**
+ * Sets the element at the specified offset.
+ * This method is required by the interface ArrayAccess.
+ * @param integer the offset to set element
+ * @param mixed the element value
+ */
+ public function offsetSet($offset,$item)
+ {
+ $this->add($offset,$item);
+ }
+
+ /**
+ * Unsets the element at the specified offset.
+ * This method is required by the interface ArrayAccess.
+ * @param mixed the offset to unset element
+ */
+ public function offsetUnset($offset)
+ {
+ $this->remove($offset);
+ }
+}
+
+/**
+ * TMapIterator class
+ *
+ * TMapIterator implements Iterator interface.
+ *
+ * TMapIterator is used by TMap. It allows TMap to return a new iterator
+ * for traversing the items in the map.
+ *
+ * @deprecated Issue 264 : ArrayIterator should be used instead
+ * @author Qiang Xue <qiang.xue@gmail.com>
+ * @version $Id$
+ * @package System.Collections
+ * @since 3.0
+ */
+class TMapIterator implements Iterator
+{
+ /**
+ * @var array the data to be iterated through
+ */
+ private $_d;
+ /**
+ * @var array list of keys in the map
+ */
+ private $_keys;
+ /**
+ * @var mixed current key
+ */
+ private $_key;
+
+ /**
+ * Constructor.
+ * @param array the data to be iterated through
+ */
+ public function __construct(&$data)
+ {
+ $this->_d=&$data;
+ $this->_keys=array_keys($data);
+ }
+
+ /**
+ * Rewinds internal array pointer.
+ * This method is required by the interface Iterator.
+ */
+ public function rewind()
+ {
+ $this->_key=reset($this->_keys);
+ }
+
+ /**
+ * Returns the key of the current array element.
+ * This method is required by the interface Iterator.
+ * @return mixed the key of the current array element
+ */
+ public function key()
+ {
+ return $this->_key;
+ }
+
+ /**
+ * Returns the current array element.
+ * This method is required by the interface Iterator.
+ * @return mixed the current array element
+ */
+ public function current()
+ {
+ return $this->_d[$this->_key];
+ }
+
+ /**
+ * Moves the internal pointer to the next array element.
+ * This method is required by the interface Iterator.
+ */
+ public function next()
+ {
+ $this->_key=next($this->_keys);
+ }
+
+ /**
+ * Returns whether there is an element at current position.
+ * This method is required by the interface Iterator.
+ * @return boolean
+ */
+ public function valid()
+ {
+ return $this->_key!==false;
+ }
+}
diff --git a/framework/Collections/TPagedDataSource.php b/framework/Collections/TPagedDataSource.php
index c0fbbec1..2b5a2909 100644
--- a/framework/Collections/TPagedDataSource.php
+++ b/framework/Collections/TPagedDataSource.php
@@ -1,446 +1,446 @@
-<?php
-/**
- * TPagedDataSource, TPagedListIterator, TPagedMapIterator classes
- *
- * @author Qiang Xue <qiang.xue@gmail.com>
- * @link http://www.pradosoft.com/
+<?php
+/**
+ * TPagedDataSource, TPagedListIterator, TPagedMapIterator classes
+ *
+ * @author Qiang Xue <qiang.xue@gmail.com>
+ * @link http://www.pradosoft.com/
* @copyright Copyright &copy; 2005-2012 PradoSoft
- * @license http://www.pradosoft.com/license/
- * @version $Id$
- * @package System.Collections
- */
-
-/**
- * TPagedDataSource class
- *
- * TPagedDataSource implements an integer-indexed collection class with paging functionality.
- *
- * Data items in TPagedDataSource can be traversed using <b>foreach</b>
- * PHP statement like the following,
- * <code>
- * foreach($pagedDataSource as $dataItem)
- * </code>
- * The data are fetched from {@link setDataSource DataSource}. Only the items
- * within the specified page will be returned and traversed.
- *
- * @author Qiang Xue <qiang.xue@gmail.com>
- * @version $Id$
- * @package System.Collections
- * @since 3.0
- */
-class TPagedDataSource extends TComponent implements IteratorAggregate,Countable
-{
- /**
- * @var mixed original data source
- */
- private $_dataSource=null;
- /**
- * @var integer number of items in each page
- */
- private $_pageSize=10;
- /**
- * @var integer current page index
- */
- private $_currentPageIndex=0;
- /**
- * @var boolean whether to allow paging
- */
- private $_allowPaging=false;
- /**
- * @var boolean whether to allow custom paging
- */
- private $_allowCustomPaging=false;
- /**
- * @var integer user-assigned number of items in data source
- */
- private $_virtualCount=0;
-
- /**
- * @return mixed original data source. Defaults to null.
- */
- public function getDataSource()
- {
- return $this->_dataSource;
- }
-
- /**
- * @param mixed original data source
- */
- public function setDataSource($value)
- {
- if(!($value instanceof TMap) && !($value instanceof TList))
- {
- if(is_array($value))
- $value=new TMap($value);
- else if($value instanceof Traversable)
- $value=new TList($value);
- else if($value!==null)
- throw new TInvalidDataTypeException('pageddatasource_datasource_invalid');
- }
- $this->_dataSource=$value;
- }
-
- /**
- * @return integer number of items in each page. Defaults to 10.
- */
- public function getPageSize()
- {
- return $this->_pageSize;
- }
-
- /**
- * @param integer number of items in each page
- */
- public function setPageSize($value)
- {
- if(($value=TPropertyValue::ensureInteger($value))>0)
- $this->_pageSize=$value;
- else
- throw new TInvalidDataValueException('pageddatasource_pagesize_invalid');
- }
-
- /**
- * @return integer current page index. Defaults to 0.
- */
- public function getCurrentPageIndex()
- {
- return $this->_currentPageIndex;
- }
-
- /**
- * @param integer current page index
- */
- public function setCurrentPageIndex($value)
- {
- if(($value=TPropertyValue::ensureInteger($value))<0)
- $value=0;
- $this->_currentPageIndex=$value;
- }
-
- /**
- * @return boolean whether to allow paging. Defaults to false.
- */
- public function getAllowPaging()
- {
- return $this->_allowPaging;
- }
-
- /**
- * @param boolean whether to allow paging
- */
- public function setAllowPaging($value)
- {
- $this->_allowPaging=TPropertyValue::ensureBoolean($value);
- }
-
- /**
- * @return boolean whether to allow custom paging. Defaults to false.
- */
- public function getAllowCustomPaging()
- {
- return $this->_allowCustomPaging;
- }
-
- /**
- * @param boolean whether to allow custom paging
- */
- public function setAllowCustomPaging($value)
- {
- $this->_allowCustomPaging=TPropertyValue::ensureBoolean($value);
- }
-
- /**
- * @return integer user-assigned number of items in data source Defaults to 0.
- */
- public function getVirtualItemCount()
- {
- return $this->_virtualCount;
- }
-
- /**
- * @param integer user-assigned number of items in data source
- */
- public function setVirtualItemCount($value)
- {
- if(($value=TPropertyValue::ensureInteger($value))>=0)
- $this->_virtualCount=$value;
- else
- throw new TInvalidDataValueException('pageddatasource_virtualitemcount_invalid');
- }
-
- /**
- * @return integer number of items in current page
- */
- public function getCount()
- {
- if($this->_dataSource===null)
- return 0;
- if(!$this->_allowPaging)
- return $this->getDataSourceCount();
- if(!$this->_allowCustomPaging && $this->getIsLastPage())
- return $this->getDataSourceCount()-$this->getFirstIndexInPage();
- return $this->_pageSize;
- }
-
- /**
- * Returns the number of items in the current page.
- * This method is required by Countable interface.
- * @return integer number of items in the current page.
- */
- public function count()
- {
- return $this->getCount();
- }
-
- /**
- * @return integer number of pages
- */
- public function getPageCount()
- {
- if($this->_dataSource===null)
- return 0;
- $count=$this->getDataSourceCount();
- if(!$this->_allowPaging || $count<=0)
- return 1;
- return (int)(($count+$this->_pageSize-1)/$this->_pageSize);
- }
-
- /**
- * @return boolean whether the current page is the first page Defaults to false.
- */
- public function getIsFirstPage()
- {
- if($this->_allowPaging)
- return $this->_currentPageIndex===0;
- else
- return true;
- }
-
- /**
- * @return boolean whether the current page is the last page
- */
- public function getIsLastPage()
- {
- if($this->_allowPaging)
- return $this->_currentPageIndex===$this->getPageCount()-1;
- else
- return true;
- }
-
- /**
- * @return integer the index of the item in data source, where the item is the first in
- * current page
- */
- public function getFirstIndexInPage()
- {
- if($this->_dataSource!==null && $this->_allowPaging && !$this->_allowCustomPaging)
- return $this->_currentPageIndex*$this->_pageSize;
- else
- return 0;
- }
-
- /**
- * @return integer number of items in data source, if available
- */
- public function getDataSourceCount()
- {
- if($this->_dataSource===null)
- return 0;
- else if($this->_allowCustomPaging)
- return $this->_virtualCount;
- else
- return $this->_dataSource->getCount();
- }
-
- /**
- * @return Iterator iterator
- */
- public function getIterator()
- {
- if($this->_dataSource instanceof TList)
- return new TPagedListIterator($this->_dataSource,$this->getFirstIndexInPage(),$this->getCount());
- else if($this->_dataSource instanceof TMap)
- return new TPagedMapIterator($this->_dataSource,$this->getFirstIndexInPage(),$this->getCount());
- else
- return null;
- }
-}
-
-
-
-/**
- * TPagedListIterator class
- *
- * TPagedListIterator implements Iterator interface.
- *
- * TPagedListIterator is used by {@link TPagedDataSource}. It allows TPagedDataSource
- * to return a new iterator for traversing the items in a {@link TList} object.
- *
- * @author Qiang Xue <qiang.xue@gmail.com>
- * @version $Id$
- * @package System.Collections
- * @since 3.0
- */
-class TPagedListIterator implements Iterator
-{
- private $_list;
- private $_startIndex;
- private $_count;
- private $_index;
-
- /**
- * Constructor.
- * @param TList the data to be iterated through
- * @param integer start index
- * @param integer number of items to be iterated through
- */
- public function __construct(TList $list,$startIndex,$count)
- {
- $this->_list=$list;
- $this->_index=0;
- $this->_startIndex=$startIndex;
- if($startIndex+$count>$list->getCount())
- $this->_count=$list->getCount()-$startIndex;
- else
- $this->_count=$count;
- }
-
- /**
- * Rewinds internal array pointer.
- * This method is required by the interface Iterator.
- */
- public function rewind()
- {
- $this->_index=0;
- }
-
- /**
- * Returns the key of the current array item.
- * This method is required by the interface Iterator.
- * @return integer the key of the current array item
- */
- public function key()
- {
- return $this->_index;
- }
-
- /**
- * Returns the current array item.
- * This method is required by the interface Iterator.
- * @return mixed the current array item
- */
- public function current()
- {
- return $this->_list->itemAt($this->_startIndex+$this->_index);
- }
-
- /**
- * Moves the internal pointer to the next array item.
- * This method is required by the interface Iterator.
- */
- public function next()
- {
- $this->_index++;
- }
-
- /**
- * Returns whether there is an item at current position.
- * This method is required by the interface Iterator.
- * @return boolean
- */
- public function valid()
- {
- return $this->_index<$this->_count;
- }
-}
-
-/**
- * TPagedMapIterator class
- *
- * TPagedMapIterator implements Iterator interface.
- *
- * TPagedMapIterator is used by {@link TPagedDataSource}. It allows TPagedDataSource
- * to return a new iterator for traversing the items in a {@link TMap} object.
- *
- * @author Qiang Xue <qiang.xue@gmail.com>
- * @version $Id$
- * @package System.Collections
- * @since 3.0
- */
-class TPagedMapIterator implements Iterator
-{
- private $_map;
- private $_startIndex;
- private $_count;
- private $_index;
- private $_iterator;
-
- /**
- * Constructor.
- * @param array the data to be iterated through
- */
- public function __construct(TMap $map,$startIndex,$count)
- {
- $this->_map=$map;
- $this->_index=0;
- $this->_startIndex=$startIndex;
- if($startIndex+$count>$map->getCount())
- $this->_count=$map->getCount()-$startIndex;
- else
- $this->_count=$count;
- $this->_iterator=$map->getIterator();
- }
-
- /**
- * Rewinds internal array pointer.
- * This method is required by the interface Iterator.
- */
- public function rewind()
- {
- $this->_iterator->rewind();
- for($i=0;$i<$this->_startIndex;++$i)
- $this->_iterator->next();
- $this->_index=0;
- }
-
- /**
- * Returns the key of the current array item.
- * This method is required by the interface Iterator.
- * @return integer the key of the current array item
- */
- public function key()
- {
- return $this->_iterator->key();
- }
-
- /**
- * Returns the current array item.
- * This method is required by the interface Iterator.
- * @return mixed the current array item
- */
- public function current()
- {
- return $this->_iterator->current();
- }
-
- /**
- * Moves the internal pointer to the next array item.
- * This method is required by the interface Iterator.
- */
- public function next()
- {
- $this->_index++;
- $this->_iterator->next();
- }
-
- /**
- * Returns whether there is an item at current position.
- * This method is required by the interface Iterator.
- * @return boolean
- */
- public function valid()
- {
- return $this->_index<$this->_count;
- }
-}
-
+ * @license http://www.pradosoft.com/license/
+ * @version $Id$
+ * @package System.Collections
+ */
+
+/**
+ * TPagedDataSource class
+ *
+ * TPagedDataSource implements an integer-indexed collection class with paging functionality.
+ *
+ * Data items in TPagedDataSource can be traversed using <b>foreach</b>
+ * PHP statement like the following,
+ * <code>
+ * foreach($pagedDataSource as $dataItem)
+ * </code>
+ * The data are fetched from {@link setDataSource DataSource}. Only the items
+ * within the specified page will be returned and traversed.
+ *
+ * @author Qiang Xue <qiang.xue@gmail.com>
+ * @version $Id$
+ * @package System.Collections
+ * @since 3.0
+ */
+class TPagedDataSource extends TComponent implements IteratorAggregate,Countable
+{
+ /**
+ * @var mixed original data source
+ */
+ private $_dataSource=null;
+ /**
+ * @var integer number of items in each page
+ */
+ private $_pageSize=10;
+ /**
+ * @var integer current page index
+ */
+ private $_currentPageIndex=0;
+ /**
+ * @var boolean whether to allow paging
+ */
+ private $_allowPaging=false;
+ /**
+ * @var boolean whether to allow custom paging
+ */
+ private $_allowCustomPaging=false;
+ /**
+ * @var integer user-assigned number of items in data source
+ */
+ private $_virtualCount=0;
+
+ /**
+ * @return mixed original data source. Defaults to null.
+ */
+ public function getDataSource()
+ {
+ return $this->_dataSource;
+ }
+
+ /**
+ * @param mixed original data source
+ */
+ public function setDataSource($value)
+ {
+ if(!($value instanceof TMap) && !($value instanceof TList))
+ {
+ if(is_array($value))
+ $value=new TMap($value);
+ else if($value instanceof Traversable)
+ $value=new TList($value);
+ else if($value!==null)
+ throw new TInvalidDataTypeException('pageddatasource_datasource_invalid');
+ }
+ $this->_dataSource=$value;
+ }
+
+ /**
+ * @return integer number of items in each page. Defaults to 10.
+ */
+ public function getPageSize()
+ {
+ return $this->_pageSize;
+ }
+
+ /**
+ * @param integer number of items in each page
+ */
+ public function setPageSize($value)
+ {
+ if(($value=TPropertyValue::ensureInteger($value))>0)
+ $this->_pageSize=$value;
+ else
+ throw new TInvalidDataValueException('pageddatasource_pagesize_invalid');
+ }
+
+ /**
+ * @return integer current page index. Defaults to 0.
+ */
+ public function getCurrentPageIndex()
+ {
+ return $this->_currentPageIndex;
+ }
+
+ /**
+ * @param integer current page index
+ */
+ public function setCurrentPageIndex($value)
+ {
+ if(($value=TPropertyValue::ensureInteger($value))<0)
+ $value=0;
+ $this->_currentPageIndex=$value;
+ }
+
+ /**
+ * @return boolean whether to allow paging. Defaults to false.
+ */
+ public function getAllowPaging()
+ {
+ return $this->_allowPaging;
+ }
+
+ /**
+ * @param boolean whether to allow paging
+ */
+ public function setAllowPaging($value)
+ {
+ $this->_allowPaging=TPropertyValue::ensureBoolean($value);
+ }
+
+ /**
+ * @return boolean whether to allow custom paging. Defaults to false.
+ */
+ public function getAllowCustomPaging()
+ {
+ return $this->_allowCustomPaging;
+ }
+
+ /**
+ * @param boolean whether to allow custom paging
+ */
+ public function setAllowCustomPaging($value)
+ {
+ $this->_allowCustomPaging=TPropertyValue::ensureBoolean($value);
+ }
+
+ /**
+ * @return integer user-assigned number of items in data source Defaults to 0.
+ */
+ public function getVirtualItemCount()
+ {
+ return $this->_virtualCount;
+ }
+
+ /**
+ * @param integer user-assigned number of items in data source
+ */
+ public function setVirtualItemCount($value)
+ {
+ if(($value=TPropertyValue::ensureInteger($value))>=0)
+ $this->_virtualCount=$value;
+ else
+ throw new TInvalidDataValueException('pageddatasource_virtualitemcount_invalid');
+ }
+
+ /**
+ * @return integer number of items in current page
+ */
+ public function getCount()
+ {
+ if($this->_dataSource===null)
+ return 0;
+ if(!$this->_allowPaging)
+ return $this->getDataSourceCount();
+ if(!$this->_allowCustomPaging && $this->getIsLastPage())
+ return $this->getDataSourceCount()-$this->getFirstIndexInPage();
+ return $this->_pageSize;
+ }
+
+ /**
+ * Returns the number of items in the current page.
+ * This method is required by Countable interface.
+ * @return integer number of items in the current page.
+ */
+ public function count()
+ {
+ return $this->getCount();
+ }
+
+ /**
+ * @return integer number of pages
+ */
+ public function getPageCount()
+ {
+ if($this->_dataSource===null)
+ return 0;
+ $count=$this->getDataSourceCount();
+ if(!$this->_allowPaging || $count<=0)
+ return 1;
+ return (int)(($count+$this->_pageSize-1)/$this->_pageSize);
+ }
+
+ /**
+ * @return boolean whether the current page is the first page Defaults to false.
+ */
+ public function getIsFirstPage()
+ {
+ if($this->_allowPaging)
+ return $this->_currentPageIndex===0;
+ else
+ return true;
+ }
+
+ /**
+ * @return boolean whether the current page is the last page
+ */
+ public function getIsLastPage()
+ {
+ if($this->_allowPaging)
+ return $this->_currentPageIndex===$this->getPageCount()-1;
+ else
+ return true;
+ }
+
+ /**
+ * @return integer the index of the item in data source, where the item is the first in
+ * current page
+ */
+ public function getFirstIndexInPage()
+ {
+ if($this->_dataSource!==null && $this->_allowPaging && !$this->_allowCustomPaging)
+ return $this->_currentPageIndex*$this->_pageSize;
+ else
+ return 0;
+ }
+
+ /**
+ * @return integer number of items in data source, if available
+ */
+ public function getDataSourceCount()
+ {
+ if($this->_dataSource===null)
+ return 0;
+ else if($this->_allowCustomPaging)
+ return $this->_virtualCount;
+ else
+ return $this->_dataSource->getCount();
+ }
+
+ /**
+ * @return Iterator iterator
+ */
+ public function getIterator()
+ {
+ if($this->_dataSource instanceof TList)
+ return new TPagedListIterator($this->_dataSource,$this->getFirstIndexInPage(),$this->getCount());
+ else if($this->_dataSource instanceof TMap)
+ return new TPagedMapIterator($this->_dataSource,$this->getFirstIndexInPage(),$this->getCount());
+ else
+ return null;
+ }
+}
+
+
+
+/**
+ * TPagedListIterator class
+ *
+ * TPagedListIterator implements Iterator interface.
+ *
+ * TPagedListIterator is used by {@link TPagedDataSource}. It allows TPagedDataSource
+ * to return a new iterator for traversing the items in a {@link TList} object.
+ *
+ * @author Qiang Xue <qiang.xue@gmail.com>
+ * @version $Id$
+ * @package System.Collections
+ * @since 3.0
+ */
+class TPagedListIterator implements Iterator
+{
+ private $_list;
+ private $_startIndex;
+ private $_count;
+ private $_index;
+
+ /**
+ * Constructor.
+ * @param TList the data to be iterated through
+ * @param integer start index
+ * @param integer number of items to be iterated through
+ */
+ public function __construct(TList $list,$startIndex,$count)
+ {
+ $this->_list=$list;
+ $this->_index=0;
+ $this->_startIndex=$startIndex;
+ if($startIndex+$count>$list->getCount())
+ $this->_count=$list->getCount()-$startIndex;
+ else
+ $this->_count=$count;
+ }
+
+ /**
+ * Rewinds internal array pointer.
+ * This method is required by the interface Iterator.
+ */
+ public function rewind()
+ {
+ $this->_index=0;
+ }
+
+ /**
+ * Returns the key of the current array item.
+ * This method is required by the interface Iterator.
+ * @return integer the key of the current array item
+ */
+ public function key()
+ {
+ return $this->_index;
+ }
+
+ /**
+ * Returns the current array item.
+ * This method is required by the interface Iterator.
+ * @return mixed the current array item
+ */
+ public function current()
+ {
+ return $this->_list->itemAt($this->_startIndex+$this->_index);
+ }
+
+ /**
+ * Moves the internal pointer to the next array item.
+ * This method is required by the interface Iterator.
+ */
+ public function next()
+ {
+ $this->_index++;
+ }
+
+ /**
+ * Returns whether there is an item at current position.
+ * This method is required by the interface Iterator.
+ * @return boolean
+ */
+ public function valid()
+ {
+ return $this->_index<$this->_count;
+ }
+}
+
+/**
+ * TPagedMapIterator class
+ *
+ * TPagedMapIterator implements Iterator interface.
+ *
+ * TPagedMapIterator is used by {@link TPagedDataSource}. It allows TPagedDataSource
+ * to return a new iterator for traversing the items in a {@link TMap} object.
+ *
+ * @author Qiang Xue <qiang.xue@gmail.com>
+ * @version $Id$
+ * @package System.Collections
+ * @since 3.0
+ */
+class TPagedMapIterator implements Iterator
+{
+ private $_map;
+ private $_startIndex;
+ private $_count;
+ private $_index;
+ private $_iterator;
+
+ /**
+ * Constructor.
+ * @param array the data to be iterated through
+ */
+ public function __construct(TMap $map,$startIndex,$count)
+ {
+ $this->_map=$map;
+ $this->_index=0;
+ $this->_startIndex=$startIndex;
+ if($startIndex+$count>$map->getCount())
+ $this->_count=$map->getCount()-$startIndex;
+ else
+ $this->_count=$count;
+ $this->_iterator=$map->getIterator();
+ }
+
+ /**
+ * Rewinds internal array pointer.
+ * This method is required by the interface Iterator.
+ */
+ public function rewind()
+ {
+ $this->_iterator->rewind();
+ for($i=0;$i<$this->_startIndex;++$i)
+ $this->_iterator->next();
+ $this->_index=0;
+ }
+
+ /**
+ * Returns the key of the current array item.
+ * This method is required by the interface Iterator.
+ * @return integer the key of the current array item
+ */
+ public function key()
+ {
+ return $this->_iterator->key();
+ }
+
+ /**
+ * Returns the current array item.
+ * This method is required by the interface Iterator.
+ * @return mixed the current array item
+ */
+ public function current()
+ {
+ return $this->_iterator->current();
+ }
+
+ /**
+ * Moves the internal pointer to the next array item.
+ * This method is required by the interface Iterator.
+ */
+ public function next()
+ {
+ $this->_index++;
+ $this->_iterator->next();
+ }
+
+ /**
+ * Returns whether there is an item at current position.
+ * This method is required by the interface Iterator.
+ * @return boolean
+ */
+ public function valid()
+ {
+ return $this->_index<$this->_count;
+ }
+}
+
diff --git a/framework/Collections/TPagedList.php b/framework/Collections/TPagedList.php
index d9590327..15f75c0f 100644
--- a/framework/Collections/TPagedList.php
+++ b/framework/Collections/TPagedList.php
@@ -1,477 +1,477 @@
-<?php
-/**
- * TPagedList, TPagedListFetchDataEventParameter, TPagedListPageChangedEventParameter class file
- *
- * @author Qiang Xue <qiang.xue@gmail.com>
- * @link http://www.pradosoft.com/
+<?php
+/**
+ * TPagedList, TPagedListFetchDataEventParameter, TPagedListPageChangedEventParameter class file
+ *
+ * @author Qiang Xue <qiang.xue@gmail.com>
+ * @link http://www.pradosoft.com/
* @copyright Copyright &copy; 2005-2012 PradoSoft
- * @license http://www.pradosoft.com/license/
- * @version $Id$
- * @package System.Collections
- */
-
-/**
- * TPagedList class
- *
- * TPagedList implements a list with paging functionality.
- *
- * TPagedList works in one of two modes, managed paging or customized paging,
- * specified by {@link setCustomPaging CustomPaging}.
- * - Managed paging ({@link setCustomPaging CustomPaging}=false) :
- * the list is assumed to contain all data and it will manage which page
- * of data are available to user.
- * - Customized paging ({@link setCustomPaging CustomPaging}=true) :
- * the list is assumed to contain only one page of data. An {@link onFetchData OnFetchData}
- * event will be raised if the list changes to a different page.
- * Developers can attach a handler to the event and supply the needed data.
- * The event handler can be written as follows,
- * <code>
- * public function fetchData($sender,$param)
- * {
- * $offset=$param->Offset; // beginning index of the data needed
- * $limit=$param->Limit; // maximum number of data items needed
- * // get data according to the above two parameters
- * $param->Data=$data;
- * }
- * </code>
- *
- * Data in TPagedList can be accessed like an integer-indexed array and can
- * be traversed using foreach. For example,
- * <code>
- * $count=$list->Count;
- * for($index=0;$index<$count;++$index)
- * echo $list[$index];
- * foreach($list as $index=>$item) // traverse each item in the list
- * </code>
- *
- * The {@link setPageSize PageSize} property specifies the number of items in each page.
- * To access different page of data in the list, set {@link setCurrentPageIndex CurrentPageIndex}
- * or call {@link nextPage()}, {@link previousPage()}, or {@link gotoPage()}.
- * The total number of pages can be obtained by {@link getPageCount() PageCount}.
- *
- *
- * @author Qiang Xue <qiang.xue@gmail.com>
- * @version $Id$
- * @package System.Collections
- * @since 3.0
- */
-class TPagedList extends TList
-{
- /**
- * @var boolean whether to allow custom paging
- */
- private $_customPaging=false;
- /**
- * @var integer number of items in each page
- */
- private $_pageSize=10;
- /**
- * @var integer current page index
- */
- private $_currentPageIndex=-1;
- /**
- * @var integer user-assigned number of items in data source
- */
- private $_virtualCount=-1;
-
- /**
- * Constructor.
- * @param array|Iterator the initial data. Default is null, meaning no initialization.
- * @param boolean whether the list is read-only. Always true for paged list.
- */
- public function __construct($data=null,$readOnly=false)
- {
- parent::__construct($data,true);
- }
-
- /**
- * @return boolean whether to use custom paging. Defaults to false.
- */
- public function getCustomPaging()
- {
- return $this->_customPaging;
- }
-
- /**
- * @param boolean whether to allow custom paging
- */
- public function setCustomPaging($value)
- {
- $this->_customPaging=TPropertyValue::ensureBoolean($value);
- }
-
- /**
- * @return integer number of items in each page. Defaults to 10.
- */
- public function getPageSize()
- {
- return $this->_pageSize;
- }
-
- /**
- * @param integer number of items in each page
- */
- public function setPageSize($value)
- {
- if(($value=TPropertyValue::ensureInteger($value))>0)
- $this->_pageSize=$value;
- else
- throw new TInvalidDataValueException('pagedlist_pagesize_invalid');
- }
-
- /**
- * @return integer current page index. Defaults to 0.
- */
- public function getCurrentPageIndex()
- {
- return $this->_currentPageIndex;
- }
-
- /**
- * @param integer current page index
- * @throws TInvalidDataValueException if the page index is out of range
- */
- public function setCurrentPageIndex($value)
- {
- if($this->gotoPage($value=TPropertyValue::ensureInteger($value))===false)
- throw new TInvalidDataValueException('pagedlist_currentpageindex_invalid');
- }
-
- /**
- * Raises <b>OnPageIndexChanged</b> event.
- * This event is raised each time when the list changes to a different page.
- * @param TPagedListPageChangedEventParameter event parameter
- */
- public function onPageIndexChanged($param)
- {
- $this->raiseEvent('OnPageIndexChanged',$this,$param);
- }
-
- /**
- * Raises <b>OnFetchData</b> event.
- * This event is raised each time when the list changes to a different page
- * and needs the new page of data. This event can only be raised when
- * {@link setCustomPaging CustomPaging} is true.
- * @param TPagedListFetchDataEventParameter event parameter
- */
- public function onFetchData($param)
- {
- $this->raiseEvent('OnFetchData',$this,$param);
- }
-
- /**
- * Changes to a page with the specified page index.
- * @param integer page index
- * @return integer|boolean the new page index, false if page index is out of range.
- */
- public function gotoPage($pageIndex)
- {
- if($pageIndex===$this->_currentPageIndex)
- return $pageIndex;
- if($this->_customPaging)
- {
- if($pageIndex>=0 && ($this->_virtualCount<0 || $pageIndex<$this->getPageCount()))
- {
- $param=new TPagedListFetchDataEventParameter($pageIndex,$this->_pageSize*$pageIndex,$this->_pageSize);
- $this->onFetchData($param);
- if(($data=$param->getData())!==null)
- {
- $this->setReadOnly(false);
- $this->copyFrom($data);
- $this->setReadOnly(true);
- $oldPage=$this->_currentPageIndex;
- $this->_currentPageIndex=$pageIndex;
- $this->onPageIndexChanged(new TPagedListPageChangedEventParameter($oldPage));
- return $pageIndex;
- }
- else
- return false;
- }
- else
- return false;
- }
- else
- {
- if($pageIndex>=0 && $pageIndex<$this->getPageCount())
- {
- $this->_currentPageIndex=$pageIndex;
- $this->onPageIndexChanged(null);
- return $pageIndex;
- }
- else
- return false;
- }
- }
-
- /**
- * Switches to the next page.
- * @return integer|boolean the new page index, false if next page is not available.
- */
- public function nextPage()
- {
- return $this->gotoPage($this->_currentPageIndex+1);
- }
-
- /**
- * Switches to the previous page.
- * @return integer|boolean the new page index, false if previous page is not available.
- */
- public function previousPage()
- {
- return $this->gotoPage($this->_currentPageIndex-1);
- }
-
- /**
- * @return integer user-assigned number of items in data source. Defaults to 0.
- */
- public function getVirtualCount()
- {
- return $this->_virtualCount;
- }
-
- /**
- * @param integer user-assigned number of items in data source
- */
- public function setVirtualCount($value)
- {
- if(($value=TPropertyValue::ensureInteger($value))<0)
- $value=-1;
- $this->_virtualCount=$value;
- }
-
- /**
- * @return integer number of pages, -1 if under custom paging mode and {@link setVirtualCount VirtualCount} is not set.
- */
- public function getPageCount()
- {
- if($this->_customPaging)
- {
- if($this->_virtualCount>=0)
- return (int)(($this->_virtualCount+$this->_pageSize-1)/$this->_pageSize);
- else
- return -1;
- }
- else
- return (int)((parent::getCount()+$this->_pageSize-1)/$this->_pageSize);
- }
-
- /**
- * @return boolean whether the current page is the first page
- */
- public function getIsFirstPage()
- {
- return $this->_currentPageIndex===0;
- }
-
- /**
- * @return boolean whether the current page is the last page
- */
- public function getIsLastPage()
- {
- return $this->_currentPageIndex===$this->getPageCount()-1;
- }
-
- /**
- * @return integer the number of items in current page
- */
- public function getCount()
- {
- if($this->_customPaging)
- return parent::getCount();
- else
- {
- if($this->_currentPageIndex===$this->getPageCount()-1)
- return parent::getCount()-$this->_pageSize*$this->_currentPageIndex;
- else
- return $this->_pageSize;
- }
- }
-
- /**
- * @return Iterator iterator
- */
- public function getIterator()
- {
- if($this->_customPaging)
- return parent::getIterator();
- else
- {
- $data=$this->toArray();
- return new TListIterator($data);
- }
- }
-
- /**
- * Returns the item at the specified offset.
- * This method is exactly the same as {@link offsetGet}.
- * @param integer the index of the item
- * @return mixed the item at the index
- * @throws TInvalidDataValueException if the index is out of the range
- */
- public function itemAt($index)
- {
- if($this->_customPaging)
- return parent::itemAt($index);
- else
- return parent::itemAt($this->_pageSize*$this->_currentPageIndex+$index);
- }
-
- /**
- * @param mixed the item
- * @return integer the index of the item in the list (0 based), -1 if not found.
- */
- public function indexOf($item)
- {
- $c=$this->getCount();
- for($i=0;$i<$c;++$i)
- if($this->itemAt($i)===$item)
- return $i;
- return -1;
- }
-
- /**
- * Returns whether there is an item at the specified offset.
- * This method is required by the interface ArrayAccess.
- * @param integer the offset to check on
- * @return boolean
- */
- public function offsetExists($offset)
- {
- return ($offset>=0 && $offset<$this->getCount());
- }
-
- /**
- * Returns the item at the specified offset.
- * This method is required by the interface ArrayAccess.
- * @param integer the offset to retrieve item.
- * @return mixed the item at the offset
- * @throws TInvalidDataValueException if the offset is invalid
- */
- public function offsetGet($offset)
- {
- return $this->itemAt($offset);
- }
-
- /**
- * @return array the list of items in array
- */
- public function toArray()
- {
- $c=$this->getCount();
- $array=array();
- for($i=0;$i<$c;++$i)
- $array[$i]=$this->itemAt($i);
- return $array;
- }
-}
-
-/**
- * TPagedListPageChangedEventParameter class.
- * TPagedListPageChangedEventParameter is used as the parameter for
- * {@link TPagedList::onPageChanged OnPageChanged} event.
- * To obtain the page index before it was changed, use {@link getOldPageIndex OldPageIndex}.
- *
- * @author Qiang Xue <qiang.xue@gmail.com>
- * @version $Id$
- * @package System.Collections
- * @since 3.0
- */
-class TPagedListPageChangedEventParameter extends TEventParameter
-{
- private $_oldPage;
-
- /**
- * Constructor.
- * @param integer old page index
- */
- public function __construct($oldPage)
- {
- $this->_oldPage=$oldPage;
- }
-
- /**
- * @return integer the index of the page before the list changed to the new page
- */
- public function getOldPageIndex()
- {
- return $this->_oldPage;
- }
-}
-
-/**
- * TPagedListFetchDataEventParameter class.
- *
- * TPagedListFetchDataEventParameter is used as the parameter for
- * {@link TPagedList::onFetchData OnFetchData} event.
- * To obtain the new page index, use {@link getNewPageIndex NewPageIndex}.
- * The {@link getOffset Offset} property refers to the index
- * of the first item in the new page, while {@link getLimit Limit}
- * specifies how many items are requested for the page.
- * Newly fetched data should be saved in {@link setData Data} property.
- *
- * @author Qiang Xue <qiang.xue@gmail.com>
- * @version $Id$
- * @package System.Collections
- * @since 3.0
- */
-class TPagedListFetchDataEventParameter extends TEventParameter
-{
- private $_pageIndex;
- private $_offset;
- private $_limit;
- private $_data=null;
-
- /**
- * Constructor.
- * @param integer new page index
- * @param integer offset of the first item in the new page
- * @param integer number of items in the new page desired
- */
- public function __construct($pageIndex,$offset,$limit)
- {
- $this->_pageIndex=$pageIndex;
- $this->_offset=$offset;
- $this->_limit=$limit;
- }
-
- /**
- * @return integer the zero-based index of the new page
- */
- public function getNewPageIndex()
- {
- return $this->_pageIndex;
- }
-
- /**
- * @return integer offset of the first item in the new page
- */
- public function getOffset()
- {
- return $this->_offset;
- }
-
- /**
- * @return integer number of items in the new page
- */
- public function getLimit()
- {
- return $this->_limit;
- }
-
- /**
- * @return mixed new page data
- */
- public function getData()
- {
- return $this->_data;
- }
-
- /**
- * @param mixed new page data
- */
- public function setData($value)
- {
- $this->_data=$value;
- }
-}
-
+ * @license http://www.pradosoft.com/license/
+ * @version $Id$
+ * @package System.Collections
+ */
+
+/**
+ * TPagedList class
+ *
+ * TPagedList implements a list with paging functionality.
+ *
+ * TPagedList works in one of two modes, managed paging or customized paging,
+ * specified by {@link setCustomPaging CustomPaging}.
+ * - Managed paging ({@link setCustomPaging CustomPaging}=false) :
+ * the list is assumed to contain all data and it will manage which page
+ * of data are available to user.
+ * - Customized paging ({@link setCustomPaging CustomPaging}=true) :
+ * the list is assumed to contain only one page of data. An {@link onFetchData OnFetchData}
+ * event will be raised if the list changes to a different page.
+ * Developers can attach a handler to the event and supply the needed data.
+ * The event handler can be written as follows,
+ * <code>
+ * public function fetchData($sender,$param)
+ * {
+ * $offset=$param->Offset; // beginning index of the data needed
+ * $limit=$param->Limit; // maximum number of data items needed
+ * // get data according to the above two parameters
+ * $param->Data=$data;
+ * }
+ * </code>
+ *
+ * Data in TPagedList can be accessed like an integer-indexed array and can
+ * be traversed using foreach. For example,
+ * <code>
+ * $count=$list->Count;
+ * for($index=0;$index<$count;++$index)
+ * echo $list[$index];
+ * foreach($list as $index=>$item) // traverse each item in the list
+ * </code>
+ *
+ * The {@link setPageSize PageSize} property specifies the number of items in each page.
+ * To access different page of data in the list, set {@link setCurrentPageIndex CurrentPageIndex}
+ * or call {@link nextPage()}, {@link previousPage()}, or {@link gotoPage()}.
+ * The total number of pages can be obtained by {@link getPageCount() PageCount}.
+ *
+ *
+ * @author Qiang Xue <qiang.xue@gmail.com>
+ * @version $Id$
+ * @package System.Collections
+ * @since 3.0
+ */
+class TPagedList extends TList
+{
+ /**
+ * @var boolean whether to allow custom paging
+ */
+ private $_customPaging=false;
+ /**
+ * @var integer number of items in each page
+ */
+ private $_pageSize=10;
+ /**
+ * @var integer current page index
+ */
+ private $_currentPageIndex=-1;
+ /**
+ * @var integer user-assigned number of items in data source
+ */
+ private $_virtualCount=-1;
+
+ /**
+ * Constructor.
+ * @param array|Iterator the initial data. Default is null, meaning no initialization.
+ * @param boolean whether the list is read-only. Always true for paged list.
+ */
+ public function __construct($data=null,$readOnly=false)
+ {
+ parent::__construct($data,true);
+ }
+
+ /**
+ * @return boolean whether to use custom paging. Defaults to false.
+ */
+ public function getCustomPaging()
+ {
+ return $this->_customPaging;
+ }
+
+ /**
+ * @param boolean whether to allow custom paging
+ */
+ public function setCustomPaging($value)
+ {
+ $this->_customPaging=TPropertyValue::ensureBoolean($value);
+ }
+
+ /**
+ * @return integer number of items in each page. Defaults to 10.
+ */
+ public function getPageSize()
+ {
+ return $this->_pageSize;
+ }
+
+ /**
+ * @param integer number of items in each page
+ */
+ public function setPageSize($value)
+ {
+ if(($value=TPropertyValue::ensureInteger($value))>0)
+ $this->_pageSize=$value;
+ else
+ throw new TInvalidDataValueException('pagedlist_pagesize_invalid');
+ }
+
+ /**
+ * @return integer current page index. Defaults to 0.
+ */
+ public function getCurrentPageIndex()
+ {
+ return $this->_currentPageIndex;
+ }
+
+ /**
+ * @param integer current page index
+ * @throws TInvalidDataValueException if the page index is out of range
+ */
+ public function setCurrentPageIndex($value)
+ {
+ if($this->gotoPage($value=TPropertyValue::ensureInteger($value))===false)
+ throw new TInvalidDataValueException('pagedlist_currentpageindex_invalid');
+ }
+
+ /**
+ * Raises <b>OnPageIndexChanged</b> event.
+ * This event is raised each time when the list changes to a different page.
+ * @param TPagedListPageChangedEventParameter event parameter
+ */
+ public function onPageIndexChanged($param)
+ {
+ $this->raiseEvent('OnPageIndexChanged',$this,$param);
+ }
+
+ /**
+ * Raises <b>OnFetchData</b> event.
+ * This event is raised each time when the list changes to a different page
+ * and needs the new page of data. This event can only be raised when
+ * {@link setCustomPaging CustomPaging} is true.
+ * @param TPagedListFetchDataEventParameter event parameter
+ */
+ public function onFetchData($param)
+ {
+ $this->raiseEvent('OnFetchData',$this,$param);
+ }
+
+ /**
+ * Changes to a page with the specified page index.
+ * @param integer page index
+ * @return integer|boolean the new page index, false if page index is out of range.
+ */
+ public function gotoPage($pageIndex)
+ {
+ if($pageIndex===$this->_currentPageIndex)
+ return $pageIndex;
+ if($this->_customPaging)
+ {
+ if($pageIndex>=0 && ($this->_virtualCount<0 || $pageIndex<$this->getPageCount()))
+ {
+ $param=new TPagedListFetchDataEventParameter($pageIndex,$this->_pageSize*$pageIndex,$this->_pageSize);
+ $this->onFetchData($param);
+ if(($data=$param->getData())!==null)
+ {
+ $this->setReadOnly(false);
+ $this->copyFrom($data);
+ $this->setReadOnly(true);
+ $oldPage=$this->_currentPageIndex;
+ $this->_currentPageIndex=$pageIndex;
+ $this->onPageIndexChanged(new TPagedListPageChangedEventParameter($oldPage));
+ return $pageIndex;
+ }
+ else
+ return false;
+ }
+ else
+ return false;
+ }
+ else
+ {
+ if($pageIndex>=0 && $pageIndex<$this->getPageCount())
+ {
+ $this->_currentPageIndex=$pageIndex;
+ $this->onPageIndexChanged(null);
+ return $pageIndex;
+ }
+ else
+ return false;
+ }
+ }
+
+ /**
+ * Switches to the next page.
+ * @return integer|boolean the new page index, false if next page is not available.
+ */
+ public function nextPage()
+ {
+ return $this->gotoPage($this->_currentPageIndex+1);
+ }
+
+ /**
+ * Switches to the previous page.
+ * @return integer|boolean the new page index, false if previous page is not available.
+ */
+ public function previousPage()
+ {
+ return $this->gotoPage($this->_currentPageIndex-1);
+ }
+
+ /**
+ * @return integer user-assigned number of items in data source. Defaults to 0.
+ */
+ public function getVirtualCount()
+ {
+ return $this->_virtualCount;
+ }
+
+ /**
+ * @param integer user-assigned number of items in data source
+ */
+ public function setVirtualCount($value)
+ {
+ if(($value=TPropertyValue::ensureInteger($value))<0)
+ $value=-1;
+ $this->_virtualCount=$value;
+ }
+
+ /**
+ * @return integer number of pages, -1 if under custom paging mode and {@link setVirtualCount VirtualCount} is not set.
+ */
+ public function getPageCount()
+ {
+ if($this->_customPaging)
+ {
+ if($this->_virtualCount>=0)
+ return (int)(($this->_virtualCount+$this->_pageSize-1)/$this->_pageSize);
+ else
+ return -1;
+ }
+ else
+ return (int)((parent::getCount()+$this->_pageSize-1)/$this->_pageSize);
+ }
+
+ /**
+ * @return boolean whether the current page is the first page
+ */
+ public function getIsFirstPage()
+ {
+ return $this->_currentPageIndex===0;
+ }
+
+ /**
+ * @return boolean whether the current page is the last page
+ */
+ public function getIsLastPage()
+ {
+ return $this->_currentPageIndex===$this->getPageCount()-1;
+ }
+
+ /**
+ * @return integer the number of items in current page
+ */
+ public function getCount()
+ {
+ if($this->_customPaging)
+ return parent::getCount();
+ else
+ {
+ if($this->_currentPageIndex===$this->getPageCount()-1)
+ return parent::getCount()-$this->_pageSize*$this->_currentPageIndex;
+ else
+ return $this->_pageSize;
+ }
+ }
+
+ /**
+ * @return Iterator iterator
+ */
+ public function getIterator()
+ {
+ if($this->_customPaging)
+ return parent::getIterator();
+ else
+ {
+ $data=$this->toArray();
+ return new TListIterator($data);
+ }
+ }
+
+ /**
+ * Returns the item at the specified offset.
+ * This method is exactly the same as {@link offsetGet}.
+ * @param integer the index of the item
+ * @return mixed the item at the index
+ * @throws TInvalidDataValueException if the index is out of the range
+ */
+ public function itemAt($index)
+ {
+ if($this->_customPaging)
+ return parent::itemAt($index);
+ else
+ return parent::itemAt($this->_pageSize*$this->_currentPageIndex+$index);
+ }
+
+ /**
+ * @param mixed the item
+ * @return integer the index of the item in the list (0 based), -1 if not found.
+ */
+ public function indexOf($item)
+ {
+ $c=$this->getCount();
+ for($i=0;$i<$c;++$i)
+ if($this->itemAt($i)===$item)
+ return $i;
+ return -1;
+ }
+
+ /**
+ * Returns whether there is an item at the specified offset.
+ * This method is required by the interface ArrayAccess.
+ * @param integer the offset to check on
+ * @return boolean
+ */
+ public function offsetExists($offset)
+ {
+ return ($offset>=0 && $offset<$this->getCount());
+ }
+
+ /**
+ * Returns the item at the specified offset.
+ * This method is required by the interface ArrayAccess.
+ * @param integer the offset to retrieve item.
+ * @return mixed the item at the offset
+ * @throws TInvalidDataValueException if the offset is invalid
+ */
+ public function offsetGet($offset)
+ {
+ return $this->itemAt($offset);
+ }
+
+ /**
+ * @return array the list of items in array
+ */
+ public function toArray()
+ {
+ $c=$this->getCount();
+ $array=array();
+ for($i=0;$i<$c;++$i)
+ $array[$i]=$this->itemAt($i);
+ return $array;
+ }
+}
+
+/**
+ * TPagedListPageChangedEventParameter class.
+ * TPagedListPageChangedEventParameter is used as the parameter for
+ * {@link TPagedList::onPageChanged OnPageChanged} event.
+ * To obtain the page index before it was changed, use {@link getOldPageIndex OldPageIndex}.
+ *
+ * @author Qiang Xue <qiang.xue@gmail.com>
+ * @version $Id$
+ * @package System.Collections
+ * @since 3.0
+ */
+class TPagedListPageChangedEventParameter extends TEventParameter
+{
+ private $_oldPage;
+
+ /**
+ * Constructor.
+ * @param integer old page index
+ */
+ public function __construct($oldPage)
+ {
+ $this->_oldPage=$oldPage;
+ }
+
+ /**
+ * @return integer the index of the page before the list changed to the new page
+ */
+ public function getOldPageIndex()
+ {
+ return $this->_oldPage;
+ }
+}
+
+/**
+ * TPagedListFetchDataEventParameter class.
+ *
+ * TPagedListFetchDataEventParameter is used as the parameter for
+ * {@link TPagedList::onFetchData OnFetchData} event.
+ * To obtain the new page index, use {@link getNewPageIndex NewPageIndex}.
+ * The {@link getOffset Offset} property refers to the index
+ * of the first item in the new page, while {@link getLimit Limit}
+ * specifies how many items are requested for the page.
+ * Newly fetched data should be saved in {@link setData Data} property.
+ *
+ * @author Qiang Xue <qiang.xue@gmail.com>
+ * @version $Id$
+ * @package System.Collections
+ * @since 3.0
+ */
+class TPagedListFetchDataEventParameter extends TEventParameter
+{
+ private $_pageIndex;
+ private $_offset;
+ private $_limit;
+ private $_data=null;
+
+ /**
+ * Constructor.
+ * @param integer new page index
+ * @param integer offset of the first item in the new page
+ * @param integer number of items in the new page desired
+ */
+ public function __construct($pageIndex,$offset,$limit)
+ {
+ $this->_pageIndex=$pageIndex;
+ $this->_offset=$offset;
+ $this->_limit=$limit;
+ }
+
+ /**
+ * @return integer the zero-based index of the new page
+ */
+ public function getNewPageIndex()
+ {
+ return $this->_pageIndex;
+ }
+
+ /**
+ * @return integer offset of the first item in the new page
+ */
+ public function getOffset()
+ {
+ return $this->_offset;
+ }
+
+ /**
+ * @return integer number of items in the new page
+ */
+ public function getLimit()
+ {
+ return $this->_limit;
+ }
+
+ /**
+ * @return mixed new page data
+ */
+ public function getData()
+ {
+ return $this->_data;
+ }
+
+ /**
+ * @param mixed new page data
+ */
+ public function setData($value)
+ {
+ $this->_data=$value;
+ }
+}
+
diff --git a/framework/Collections/TPriorityList.php b/framework/Collections/TPriorityList.php
index 5258e802..a174ed13 100644
--- a/framework/Collections/TPriorityList.php
+++ b/framework/Collections/TPriorityList.php
@@ -1,743 +1,743 @@
-<?php
-/**
- * TPriorityList, TPriorityListIterator classes
- *
- * @author Brad Anderson <javalizard@gmail.com>
- * @link http://www.pradosoft.com/
- * @copyright Copyright &copy; 2005-2012 PradoSoft
- * @license http://www.pradosoft.com/license/
- * @version $Id: TPriorityList.php 2541 2008-10-21 15:05:13Z javalizard $
- * @package System.Collections
- */
-
-/**
- * TPriorityList class
- *
- * TPriorityList implements a priority ordered list collection class. It allows you to specify
- * any numeric for priorities down to a specific precision. The lower the numeric, the high the priority of the item in the
- * list. Thus -10 has a higher priority than -5, 0, 10 (the default), 18, 10005, etc. Per {@link round}, precision may be negative and
- * thus rounding can go by 10, 100, 1000, etc, instead of just .1, .01, .001, etc. The default precision allows for 8 decimal
- * places. There is also a default priority of 10, if no different default priority is specified or no item specific priority is indicated.
- * If you replace TList with this class it will work exactly the same with items inserted set to the default priority, until you start
- * using different priorities than the default priority.
- *
- * As you access the PHP array features of this class, it flattens and caches the results. If at all possible, this
- * will keep the cache fresh even when manipulated. If this is not possible the cache is cleared.
- * When an array of items are needed and the cache is outdated, the cache is recreated from the items and their priorities
- *
- * You can access, append, insert, remove an item by using
- * {@link itemAt}, {@link add}, {@link insertAt}, and {@link remove}.
- * To get the number of the items in the list, use {@link getCount}.
- * TPriorityList can also be used like a regular array as follows,
- * <code>
- * $list[]=$item; // append with the default priority. It may not be the last item if other items in the list are prioritized after the default priority
- * $list[$index]=$item; // $index must be between 0 and $list->Count-1. This sets the element regardless of priority. Priority stays the same.
- * $list[$index]=$item; // $index is $list->Count. This appends the item to the end of the list with the same priority as the last item in the list.
- * unset($list[$index]); // remove the item at $index
- * if(isset($list[$index])) // if the list has an item at $index
- * foreach($list as $index=>$item) // traverse each item in the list in proper priority order and add/insert order
- * $n=count($list); // returns the number of items in the list
- * </code>
- *
- * To extend TPriorityList for doing your own operations with each addition or removal,
- * override {@link insertAtIndexInPriority()} and {@link removeAtIndexInPriority()} and then call the parent.
- *
- * @author Brad Anderson <javalizard@gmail.com>
- * @version $Id: TPriorityList.php 2541 2008-10-21 15:05:13Z javalizard $
- * @package System.Collections
- * @since 3.2a
- */
-class TPriorityList extends TList
-{
- /**
- * @var array internal data storage
- */
- private $_d=array();
- /**
- * @var boolean indicates if the _d is currently ordered.
- */
- private $_o=false;
- /**
- * @var array cached flattened internal data storage
- */
- private $_fd=null;
- /**
- * @var integer number of items contain within the list
- */
- private $_c=0;
- /**
- * @var numeric the default priority of items without specified priorities
- */
- private $_dp=10;
- /**
- * @var integer the precision of the numeric priorities within this priority list.
- */
- private $_p=8;
-
- /**
- * Constructor.
- * Initializes the list with an array or an iterable object.
- * @param array|Iterator the intial data. Default is null, meaning no initial data.
- * @param boolean whether the list is read-only
- * @param numeric the default priority of items without specified priorities.
- * @param integer the precision of the numeric priorities
- * @throws TInvalidDataTypeException If data is not null and is neither an array nor an iterator.
- */
- public function __construct($data=null,$readOnly=false,$defaultPriority=10,$precision=8)
- {
- parent::__construct();
- if($data!==null)
- $this->copyFrom($data);
- $this->setReadOnly($readOnly);
- $this->setPrecision($precision);
- $this->setDefaultPriority($defaultPriority);
- }
-
- /**
- * Returns the number of items in the list.
- * This method is required by Countable interface.
- * @return integer number of items in the list.
- */
- public function count()
- {
- return $this->getCount();
- }
-
- /**
- * Returns the total number of items in the list
- * @return integer the number of items in the list
- */
- public function getCount()
- {
- return $this->_c;
- }
-
- /**
- * Gets the number of items at a priority within the list
- * @param numeric optional priority at which to count items. if no parameter, it will be set to the default {@link getDefaultPriority}
- * @return integer the number of items in the list at the specified priority
- */
- public function getPriorityCount($priority=null)
- {
- if($priority===null)
- $priority=$this->getDefaultPriority();
- $priority=(string)round(TPropertyValue::ensureFloat($priority),$this->_p);
-
- if(!isset($this->_d[$priority]) || !is_array($this->_d[$priority]))
- return false;
- return count($this->_d[$priority]);
- }
-
- /**
- * @return numeric gets the default priority of inserted items without a specified priority
- */
- public function getDefaultPriority()
- {
- return $this->_dp;
- }
-
- /**
- * This must be called internally or when instantiated.
- * @param numeric sets the default priority of inserted items without a specified priority
- */
- protected function setDefaultPriority($value)
- {
- $this->_dp=(string)round(TPropertyValue::ensureFloat($value),$this->_p);
- }
-
- /**
- * @return integer The precision of numeric priorities, defaults to 8
- */
- public function getPrecision()
- {
- return $this->_p;
- }
-
- /**
- * This must be called internally or when instantiated.
- * @param integer The precision of numeric priorities.
- */
- protected function setPrecision($value)
- {
- $this->_p=TPropertyValue::ensureInteger($value);
- }
-
- /**
- * Returns an iterator for traversing the items in the list.
- * This method is required by the interface IteratorAggregate.
- * @return Iterator an iterator for traversing the items in the list.
- */
- public function getIterator()
- {
- return new ArrayIterator($this->flattenPriorities());
- }
-
- /**
- * This returns a list of the priorities within this list, ordered lowest to highest.
- * @return array the array of priority numerics in decreasing priority order
- */
- public function getPriorities()
- {
- $this->sortPriorities();
- return array_keys($this->_d);
- }
-
-
- /**
- * This orders the priority list internally.
- */
- protected function sortPriorities() {
- if(!$this->_o) {
- ksort($this->_d,SORT_NUMERIC);
- $this->_o=true;
- }
- }
-
- /**
- * This flattens the priority list into a flat array [0,...,n-1]
- * @return array array of items in the list in priority and index order
- */
- protected function flattenPriorities() {
- if(is_array($this->_fd))
- return $this->_fd;
-
- $this->sortPriorities();
- $this->_fd=array();
- foreach($this->_d as $priority => $itemsatpriority)
- $this->_fd=array_merge($this->_fd,$itemsatpriority);
- return $this->_fd;
- }
-
-
- /**
- * Returns the item at the index of a flattened priority list.
- * {@link offsetGet} calls this method.
- * @param integer the index of the item to get
- * @return mixed the element at the offset
- * @throws TInvalidDataValueException Issued when the index is invalid
- */
- public function itemAt($index)
- {
- if($index>=0&&$index<$this->getCount()) {
- $arr=$this->flattenPriorities();
- return $arr[$index];
- } else
- throw new TInvalidDataValueException('list_index_invalid',$index);
- }
-
- /**
- * Gets all the items at a specific priority.
- * @param numeric priority of the items to get. Defaults to null, filled in with the default priority, if left blank.
- * @return array all items at priority in index order, null if there are no items at that priority
- */
- public function itemsAtPriority($priority=null)
- {
- if($priority===null)
- $priority=$this->getDefaultPriority();
- $priority=(string)round(TPropertyValue::ensureFloat($priority),$this->_p);
-
- return isset($this->_d[$priority])?$this->_d[$priority]:null;
- }
-
- /**
- * Returns the item at an index within a priority
- * @param integer the index into the list of items at priority
- * @param numeric the priority which to index. no parameter or null will result in the default priority
- * @return mixed the element at the offset, false if no element is found at the offset
- */
- public function itemAtIndexInPriority($index,$priority=null)
- {
- if($priority===null)
- $priority=$this->getDefaultPriority();
- $priority=(string)round(TPropertyValue::ensureFloat($priority), $this->_p);
-
- return !isset($this->_d[$priority])?false:(
- isset($this->_d[$priority][$index])?$this->_d[$priority][$index]:false
- );
- }
-
- /**
- * Appends an item into the list at the end of the specified priority. The position of the added item may
- * not be at the end of the list.
- * @param mixed item to add into the list at priority
- * @param numeric priority blank or null for the default priority
- * @return int the index within the flattened array
- * @throws TInvalidOperationException if the map is read-only
- */
- public function add($item,$priority=null)
- {
- if($this->getReadOnly())
- throw new TInvalidOperationException('list_readonly',get_class($this));
-
- return $this->insertAtIndexInPriority($item,false,$priority,true);
- }
-
- /**
- * Inserts an item at an index. It reads the priority of the item at index within the flattened list
- * and then inserts the item at that priority-index.
- * @param integer the specified position in the flattened list.
- * @param mixed new item to add
- * @throws TInvalidDataValueException If the index specified exceeds the bound
- * @throws TInvalidOperationException if the list is read-only
- */
- public function insertAt($index,$item)
- {
- if($this->getReadOnly())
- throw new TInvalidOperationException('list_readonly',get_class($this));
-
- if(($priority=$this->priorityAt($index,true))!==false)
- $this->insertAtIndexInPriority($item,$priority[1],$priority[0]);
- else
- throw new TInvalidDataValueException('list_index_invalid',$index);
- }
-
- /**
- * Inserts an item at the specified index within a priority. Override and call this method to
- * insert your own functionality.
- * @param mixed item to add within the list.
- * @param integer index within the priority to add the item, defaults to false which appends the item at the priority
- * @param numeric priority priority of the item. defaults to null, which sets it to the default priority
- * @param boolean preserveCache specifies if this is a special quick function or not. This defaults to false.
- * @throws TInvalidDataValueException If the index specified exceeds the bound
- * @throws TInvalidOperationException if the list is read-only
- */
- public function insertAtIndexInPriority($item,$index=false,$priority=null,$preserveCache=false)
- {
- if($this->getReadOnly())
- throw new TInvalidOperationException('list_readonly',get_class($this));
-
- if($priority===null)
- $priority=$this->getDefaultPriority();
- $priority=(string)round(TPropertyValue::ensureFloat($priority), $this->_p);
-
- if($preserveCache) {
- $this->sortPriorities();
- $cc=0;
- foreach($this->_d as $prioritykey=>$items)
- if($prioritykey>=$priority)
- break;
- else
- $cc+=count($items);
-
- if($index===false&&isset($this->_d[$priority])) {
- $c=count($this->_d[$priority]);
- $c+=$cc;
- $this->_d[$priority][]=$item;
- } else if(isset($this->_d[$priority])) {
- $c=$index+$cc;
- array_splice($this->_d[$priority],$index,0,array($item));
- } else {
- $c = $cc;
- $this->_o = false;
- $this->_d[$priority]=array($item);
- }
-
- if($this->_fd&&is_array($this->_fd)) // if there is a flattened array cache
- array_splice($this->_fd,$c,0,array($item));
- } else {
- $c=null;
- if($index===false&&isset($this->_d[$priority])) {
- $cc=count($this->_d[$priority]);
- $this->_d[$priority][]=$item;
- } else if(isset($this->_d[$priority])) {
- $cc=$index;
- array_splice($this->_d[$priority],$index,0,array($item));
- } else {
- $cc=0;
- $this->_o=false;
- $this->_d[$priority]=array($item);
- }
- if($this->_fd&&is_array($this->_fd)&&count($this->_d)==1)
- array_splice($this->_fd,$cc,0,array($item));
- else
- $this->_fd=null;
- }
-
- $this->_c++;
-
- return $c;
-
- }
-
-
- /**
- * Removes an item from the priority list.
- * The list will search for the item. The first matching item found will be removed from the list.
- * @param mixed item the item to be removed.
- * @param numeric priority of item to remove. without this parameter it defaults to false.
- * A value of false means any priority. null will be filled in with the default priority.
- * @return integer index within the flattened list at which the item is being removed
- * @throws TInvalidDataValueException If the item does not exist
- */
- public function remove($item,$priority=false)
- {
- if($this->getReadOnly())
- throw new TInvalidOperationException('list_readonly',get_class($this));
-
- if(($p=$this->priorityOf($item,true))!==false)
- {
- if($priority!==false) {
- if($priority===null)
- $priority=$this->getDefaultPriority();
- $priority=(string)round(TPropertyValue::ensureFloat($priority),$this->_p);
-
- if($p[0]!=$priority)
- throw new TInvalidDataValueException('list_item_inexistent');
- }
- $this->removeAtIndexInPriority($p[1],$p[0]);
- return $p[2];
- }
- else
- throw new TInvalidDataValueException('list_item_inexistent');
- }
-
- /**
- * Removes an item at the specified index in the flattened list.
- * @param integer index of the item to be removed.
- * @return mixed the removed item.
- * @throws TInvalidDataValueException If the index specified exceeds the bound
- * @throws TInvalidOperationException if the list is read-only
- */
- public function removeAt($index)
- {
- if($this->getReadOnly())
- throw new TInvalidOperationException('list_readonly',get_class($this));
-
- if(($priority=$this->priorityAt($index, true))!==false)
- return $this->removeAtIndexInPriority($priority[1],$priority[0]);
- throw new TInvalidDataValueException('list_index_invalid',$index);
- }
-
- /**
- * Removes the item at a specific index within a priority. Override
- * and call this method to insert your own functionality.
- * @param integer index of item to remove within the priority.
- * @param numeric priority of the item to remove, defaults to null, or left blank, it is then set to the default priority
- * @return mixed the removed item.
- * @throws TInvalidDataValueException If the item does not exist
- */
- public function removeAtIndexInPriority($index, $priority=null)
- {
- if($this->getReadOnly())
- throw new TInvalidOperationException('list_readonly',get_class($this));
-
- if($priority===null)
- $priority=$this->getDefaultPriority();
- $priority=(string)round(TPropertyValue::ensureFloat($priority),$this->_p);
-
- if(!isset($this->_d[$priority])||$index<0||$index>=count($this->_d[$priority]))
- throw new TInvalidDataValueException('list_item_inexistent');
-
- // $value is an array of elements removed, only one
- $value=array_splice($this->_d[$priority],$index,1);
- $value=$value[0];
-
- if(!count($this->_d[$priority]))
- unset($this->_d[$priority]);
-
- $this->_c--;
- $this->_fd=null;
- return $value;
- }
-
- /**
- * Removes all items in the priority list by calling removeAtIndexInPriority from the last item to the first.
- */
- public function clear()
- {
- if($this->getReadOnly())
- throw new TInvalidOperationException('list_readonly',get_class($this));
-
- $d=array_reverse($this->_d,true);
- foreach($this->_d as $priority=>$items) {
- for($index=count($items)-1;$index>=0;$index--)
- $this->removeAtIndexInPriority($index,$priority);
- unset($this->_d[$priority]);
- }
- }
-
- /**
- * @param mixed item
- * @return boolean whether the list contains the item
- */
- public function contains($item)
- {
- return $this->indexOf($item)>=0;
- }
-
- /**
- * @param mixed item
- * @return integer the index of the item in the flattened list (0 based), -1 if not found.
- */
- public function indexOf($item)
- {
- if(($index=array_search($item,$this->flattenPriorities(),true))===false)
- return -1;
- else
- return $index;
- }
-
- /**
- * Returns the priority of a particular item
- * @param mixed the item to look for within the list
- * @param boolean withindex this specifies if the full positional data of the item within the list is returned.
- * This defaults to false, if no parameter is provided, so only provides the priority number of the item by default.
- * @return numeric|array the priority of the item in the list, false if not found.
- * if withindex is true, an array is returned of [0 => $priority, 1 => $priorityIndex, 2 => flattenedIndex,
- * 'priority' => $priority, 'index' => $priorityIndex, 'absindex' => flattenedIndex]
- */
- public function priorityOf($item,$withindex = false)
- {
- $this->sortPriorities();
-
- $absindex = 0;
- foreach($this->_d as $priority=>$items) {
- if(($index=array_search($item,$items,true))!==false) {
- $absindex+=$index;
- return $withindex?array($priority,$index,$absindex,
- 'priority'=>$priority,'index'=>$index,'absindex'=>$absindex):$priority;
- } else
- $absindex+=count($items);
- }
-
- return false;
- }
-
- /**
- * Retutrns the priority of an item at a particular flattened index.
- * @param integer index of the item within the list
- * @param boolean withindex this specifies if the full positional data of the item within the list is returned.
- * This defaults to false, if no parameter is provided, so only provides the priority number of the item by default.
- * @return numeric|array the priority of the item in the list, false if not found.
- * if withindex is true, an array is returned of [0 => $priority, 1 => $priorityIndex, 2 => flattenedIndex,
- * 'priority' => $priority, 'index' => $priorityIndex, 'absindex' => flattenedIndex]
- */
- public function priorityAt($index,$withindex = false)
- {
- if($index<0||$index>=$this->getCount())
- throw new TInvalidDataValueException('list_index_invalid',$index);
-
- $absindex=$index;
- $this->sortPriorities();
- foreach($this->_d as $priority=>$items) {
- if($index>=($c=count($items)))
- $index-=$c;
- else
- return $withindex?array($priority,$index,$absindex,
- 'priority'=>$priority,'index'=>$index,'absindex'=>$absindex):$priority;
- }
- return false;
- }
-
- /**
- * This inserts an item before another item within the list. It uses the same priority as the
- * found index item and places the new item before it.
- * @param mixed indexitem the item to index
- * @param mixed the item to add before indexitem
- * @return integer where the item has been inserted in the flattened list
- * @throws TInvalidDataValueException If the item does not exist
- */
- public function insertBefore($indexitem, $item)
- {
- if($this->getReadOnly())
- throw new TInvalidOperationException('list_readonly',get_class($this));
-
- if(($priority=$this->priorityOf($indexitem,true))===false)
- throw new TInvalidDataValueException('list_item_inexistent');
-
- $this->insertAtIndexInPriority($item,$priority[1],$priority[0]);
-
- return $priority[2];
- }
-
- /**
- * This inserts an item after another item within the list. It uses the same priority as the
- * found index item and places the new item after it.
- * @param mixed indexitem the item to index
- * @param mixed the item to add after indexitem
- * @return integer where the item has been inserted in the flattened list
- * @throws TInvalidDataValueException If the item does not exist
- */
- public function insertAfter($indexitem, $item)
- {
- if($this->getReadOnly())
- throw new TInvalidOperationException('list_readonly',get_class($this));
-
- if(($priority=$this->priorityOf($indexitem,true))===false)
- throw new TInvalidDataValueException('list_item_inexistent');
-
- $this->insertAtIndexInPriority($item,$priority[1]+1,$priority[0]);
-
- return $priority[2]+1;
- }
-
- /**
- * @return array the priority list of items in array
- */
- public function toArray()
- {
- return $this->flattenPriorities();
- }
-
- /**
- * @return array the array of priorities keys with values of arrays of items. The priorities are sorted so important priorities, lower numerics, are first.
- */
- public function toPriorityArray()
- {
- $this->sortPriorities();
- return $this->_d;
- }
-
- /**
- * Combines the map elements which have a priority below the parameter value
- * @param numeric the cut-off priority. All items of priority less than this are returned.
- * @param boolean whether or not the input cut-off priority is inclusive. Default: false, not inclusive.
- * @return array the array of priorities keys with values of arrays of items that are below a specified priority.
- * The priorities are sorted so important priorities, lower numerics, are first.
- */
- public function toArrayBelowPriority($priority,$inclusive=false)
- {
- $this->sortPriorities();
- $items=array();
- foreach($this->_d as $itemspriority=>$itemsatpriority)
- {
- if((!$inclusive&&$itemspriority>=$priority)||$itemspriority>$priority)
- break;
- $items=array_merge($items,$itemsatpriority);
- }
- return $items;
- }
-
- /**
- * Combines the map elements which have a priority above the parameter value
- * @param numeric the cut-off priority. All items of priority greater than this are returned.
- * @param boolean whether or not the input cut-off priority is inclusive. Default: true, inclusive.
- * @return array the array of priorities keys with values of arrays of items that are above a specified priority.
- * The priorities are sorted so important priorities, lower numerics, are first.
- */
- public function toArrayAbovePriority($priority,$inclusive=true)
- {
- $this->sortPriorities();
- $items=array();
- foreach($this->_d as $itemspriority=>$itemsatpriority)
- {
- if((!$inclusive&&$itemspriority<=$priority)||$itemspriority<$priority)
- continue;
- $items=array_merge($items,$itemsatpriority);
- }
- return $items;
- }
-
-
- /**
- * Copies iterable data into the priority list.
- * Note, existing data in the map will be cleared first.
- * @param mixed the data to be copied from, must be an array or object implementing Traversable
- * @throws TInvalidDataTypeException If data is neither an array nor an iterator.
- */
- public function copyFrom($data)
- {
- if($data instanceof TPriorityList)
- {
- if($this->getCount()>0)
- $this->clear();
- foreach($data->getPriorities() as $priority)
- {
- foreach($data->itemsAtPriority($priority) as $index=>$item)
- $this->insertAtIndexInPriority($item,$index,$priority);
- }
- } else if(is_array($data)||$data instanceof Traversable) {
- if($this->getCount()>0)
- $this->clear();
- foreach($data as $key=>$item)
- $this->add($item);
- } else if($data!==null)
- throw new TInvalidDataTypeException('map_data_not_iterable');
- }
-
- /**
- * Merges iterable data into the priority list.
- * New data will be appended to the end of the existing data. If another TPriorityList is merged,
- * the incoming parameter items will be appended at the priorities they are present. These items will be added
- * to the end of the existing items with equal priorities, if there are any.
- * @param mixed the data to be merged with, must be an array or object implementing Traversable
- * @throws TInvalidDataTypeException If data is neither an array nor an iterator.
- */
- public function mergeWith($data)
- {
- if($data instanceof TPriorityList)
- {
- foreach($data->getPriorities() as $priority)
- {
- foreach($data->itemsAtPriority($priority) as $index=>$item)
- $this->insertAtIndexInPriority($item,false,$priority);
- }
- }
- else if(is_array($data)||$data instanceof Traversable)
- {
- foreach($data as $priority=>$item)
- $this->add($item);
-
- }
- else if($data!==null)
- throw new TInvalidDataTypeException('map_data_not_iterable');
- }
-
- /**
- * Returns whether there is an element at the specified offset.
- * This method is required by the interface ArrayAccess.
- * @param mixed the offset to check on
- * @return boolean
- */
- public function offsetExists($offset)
- {
- return ($offset>=0&&$offset<$this->getCount());
- }
-
- /**
- * Returns the element at the specified offset.
- * This method is required by the interface ArrayAccess.
- * @param integer the offset to retrieve element.
- * @return mixed the element at the offset, null if no element is found at the offset
- */
- public function offsetGet($offset)
- {
- return $this->itemAt($offset);
- }
-
- /**
- * Sets the element at the specified offset. This method is required by the interface ArrayAccess.
- * Setting elements in a priority list is not straight forword when appending and setting at the
- * end boundary. When appending without an offset (a null offset), the item will be added at
- * the default priority. The item may not be the last item in the list. When appending with an
- * offset equal to the count of the list, the item will get be appended with the last items priority.
- *
- * All together, when setting the location of an item, the item stays in that location, but appending
- * an item into a priority list doesn't mean the item is at the end of the list.
- * @param integer the offset to set element
- * @param mixed the element value
- */
- public function offsetSet($offset,$item)
- {
- if($offset===null)
- return $this->add($item);
- if($offset===$this->getCount()) {
- $priority=$this->priorityAt($offset-1,true);
- $priority[1]++;
- } else {
- $priority=$this->priorityAt($offset,true);
- $this->removeAtIndexInPriority($priority[1],$priority[0]);
- }
- $this->insertAtIndexInPriority($item,$priority[1],$priority[0]);
- }
-
- /**
- * Unsets the element at the specified offset.
- * This method is required by the interface ArrayAccess.
- * @param mixed the offset to unset element
- */
- public function offsetUnset($offset)
- {
- $this->removeAt($offset);
- }
-}
+<?php
+/**
+ * TPriorityList, TPriorityListIterator classes
+ *
+ * @author Brad Anderson <javalizard@gmail.com>
+ * @link http://www.pradosoft.com/
+ * @copyright Copyright &copy; 2005-2012 PradoSoft
+ * @license http://www.pradosoft.com/license/
+ * @version $Id: TPriorityList.php 2541 2008-10-21 15:05:13Z javalizard $
+ * @package System.Collections
+ */
+
+/**
+ * TPriorityList class
+ *
+ * TPriorityList implements a priority ordered list collection class. It allows you to specify
+ * any numeric for priorities down to a specific precision. The lower the numeric, the high the priority of the item in the
+ * list. Thus -10 has a higher priority than -5, 0, 10 (the default), 18, 10005, etc. Per {@link round}, precision may be negative and
+ * thus rounding can go by 10, 100, 1000, etc, instead of just .1, .01, .001, etc. The default precision allows for 8 decimal
+ * places. There is also a default priority of 10, if no different default priority is specified or no item specific priority is indicated.
+ * If you replace TList with this class it will work exactly the same with items inserted set to the default priority, until you start
+ * using different priorities than the default priority.
+ *
+ * As you access the PHP array features of this class, it flattens and caches the results. If at all possible, this
+ * will keep the cache fresh even when manipulated. If this is not possible the cache is cleared.
+ * When an array of items are needed and the cache is outdated, the cache is recreated from the items and their priorities
+ *
+ * You can access, append, insert, remove an item by using
+ * {@link itemAt}, {@link add}, {@link insertAt}, and {@link remove}.
+ * To get the number of the items in the list, use {@link getCount}.
+ * TPriorityList can also be used like a regular array as follows,
+ * <code>
+ * $list[]=$item; // append with the default priority. It may not be the last item if other items in the list are prioritized after the default priority
+ * $list[$index]=$item; // $index must be between 0 and $list->Count-1. This sets the element regardless of priority. Priority stays the same.
+ * $list[$index]=$item; // $index is $list->Count. This appends the item to the end of the list with the same priority as the last item in the list.
+ * unset($list[$index]); // remove the item at $index
+ * if(isset($list[$index])) // if the list has an item at $index
+ * foreach($list as $index=>$item) // traverse each item in the list in proper priority order and add/insert order
+ * $n=count($list); // returns the number of items in the list
+ * </code>
+ *
+ * To extend TPriorityList for doing your own operations with each addition or removal,
+ * override {@link insertAtIndexInPriority()} and {@link removeAtIndexInPriority()} and then call the parent.
+ *
+ * @author Brad Anderson <javalizard@gmail.com>
+ * @version $Id: TPriorityList.php 2541 2008-10-21 15:05:13Z javalizard $
+ * @package System.Collections
+ * @since 3.2a
+ */
+class TPriorityList extends TList
+{
+ /**
+ * @var array internal data storage
+ */
+ private $_d=array();
+ /**
+ * @var boolean indicates if the _d is currently ordered.
+ */
+ private $_o=false;
+ /**
+ * @var array cached flattened internal data storage
+ */
+ private $_fd=null;
+ /**
+ * @var integer number of items contain within the list
+ */
+ private $_c=0;
+ /**
+ * @var numeric the default priority of items without specified priorities
+ */
+ private $_dp=10;
+ /**
+ * @var integer the precision of the numeric priorities within this priority list.
+ */
+ private $_p=8;
+
+ /**
+ * Constructor.
+ * Initializes the list with an array or an iterable object.
+ * @param array|Iterator the intial data. Default is null, meaning no initial data.
+ * @param boolean whether the list is read-only
+ * @param numeric the default priority of items without specified priorities.
+ * @param integer the precision of the numeric priorities
+ * @throws TInvalidDataTypeException If data is not null and is neither an array nor an iterator.
+ */
+ public function __construct($data=null,$readOnly=false,$defaultPriority=10,$precision=8)
+ {
+ parent::__construct();
+ if($data!==null)
+ $this->copyFrom($data);
+ $this->setReadOnly($readOnly);
+ $this->setPrecision($precision);
+ $this->setDefaultPriority($defaultPriority);
+ }
+
+ /**
+ * Returns the number of items in the list.
+ * This method is required by Countable interface.
+ * @return integer number of items in the list.
+ */
+ public function count()
+ {
+ return $this->getCount();
+ }
+
+ /**
+ * Returns the total number of items in the list
+ * @return integer the number of items in the list
+ */
+ public function getCount()
+ {
+ return $this->_c;
+ }
+
+ /**
+ * Gets the number of items at a priority within the list
+ * @param numeric optional priority at which to count items. if no parameter, it will be set to the default {@link getDefaultPriority}
+ * @return integer the number of items in the list at the specified priority
+ */
+ public function getPriorityCount($priority=null)
+ {
+ if($priority===null)
+ $priority=$this->getDefaultPriority();
+ $priority=(string)round(TPropertyValue::ensureFloat($priority),$this->_p);
+
+ if(!isset($this->_d[$priority]) || !is_array($this->_d[$priority]))
+ return false;
+ return count($this->_d[$priority]);
+ }
+
+ /**
+ * @return numeric gets the default priority of inserted items without a specified priority
+ */
+ public function getDefaultPriority()
+ {
+ return $this->_dp;
+ }
+
+ /**
+ * This must be called internally or when instantiated.
+ * @param numeric sets the default priority of inserted items without a specified priority
+ */
+ protected function setDefaultPriority($value)
+ {
+ $this->_dp=(string)round(TPropertyValue::ensureFloat($value),$this->_p);
+ }
+
+ /**
+ * @return integer The precision of numeric priorities, defaults to 8
+ */
+ public function getPrecision()
+ {
+ return $this->_p;
+ }
+
+ /**
+ * This must be called internally or when instantiated.
+ * @param integer The precision of numeric priorities.
+ */
+ protected function setPrecision($value)
+ {
+ $this->_p=TPropertyValue::ensureInteger($value);
+ }
+
+ /**
+ * Returns an iterator for traversing the items in the list.
+ * This method is required by the interface IteratorAggregate.
+ * @return Iterator an iterator for traversing the items in the list.
+ */
+ public function getIterator()
+ {
+ return new ArrayIterator($this->flattenPriorities());
+ }
+
+ /**
+ * This returns a list of the priorities within this list, ordered lowest to highest.
+ * @return array the array of priority numerics in decreasing priority order
+ */
+ public function getPriorities()
+ {
+ $this->sortPriorities();
+ return array_keys($this->_d);
+ }
+
+
+ /**
+ * This orders the priority list internally.
+ */
+ protected function sortPriorities() {
+ if(!$this->_o) {
+ ksort($this->_d,SORT_NUMERIC);
+ $this->_o=true;
+ }
+ }
+
+ /**
+ * This flattens the priority list into a flat array [0,...,n-1]
+ * @return array array of items in the list in priority and index order
+ */
+ protected function flattenPriorities() {
+ if(is_array($this->_fd))
+ return $this->_fd;
+
+ $this->sortPriorities();
+ $this->_fd=array();
+ foreach($this->_d as $priority => $itemsatpriority)
+ $this->_fd=array_merge($this->_fd,$itemsatpriority);
+ return $this->_fd;
+ }
+
+
+ /**
+ * Returns the item at the index of a flattened priority list.
+ * {@link offsetGet} calls this method.
+ * @param integer the index of the item to get
+ * @return mixed the element at the offset
+ * @throws TInvalidDataValueException Issued when the index is invalid
+ */
+ public function itemAt($index)
+ {
+ if($index>=0&&$index<$this->getCount()) {
+ $arr=$this->flattenPriorities();
+ return $arr[$index];
+ } else
+ throw new TInvalidDataValueException('list_index_invalid',$index);
+ }
+
+ /**
+ * Gets all the items at a specific priority.
+ * @param numeric priority of the items to get. Defaults to null, filled in with the default priority, if left blank.
+ * @return array all items at priority in index order, null if there are no items at that priority
+ */
+ public function itemsAtPriority($priority=null)
+ {
+ if($priority===null)
+ $priority=$this->getDefaultPriority();
+ $priority=(string)round(TPropertyValue::ensureFloat($priority),$this->_p);
+
+ return isset($this->_d[$priority])?$this->_d[$priority]:null;
+ }
+
+ /**
+ * Returns the item at an index within a priority
+ * @param integer the index into the list of items at priority
+ * @param numeric the priority which to index. no parameter or null will result in the default priority
+ * @return mixed the element at the offset, false if no element is found at the offset
+ */
+ public function itemAtIndexInPriority($index,$priority=null)
+ {
+ if($priority===null)
+ $priority=$this->getDefaultPriority();
+ $priority=(string)round(TPropertyValue::ensureFloat($priority), $this->_p);
+
+ return !isset($this->_d[$priority])?false:(
+ isset($this->_d[$priority][$index])?$this->_d[$priority][$index]:false
+ );
+ }
+
+ /**
+ * Appends an item into the list at the end of the specified priority. The position of the added item may
+ * not be at the end of the list.
+ * @param mixed item to add into the list at priority
+ * @param numeric priority blank or null for the default priority
+ * @return int the index within the flattened array
+ * @throws TInvalidOperationException if the map is read-only
+ */
+ public function add($item,$priority=null)
+ {
+ if($this->getReadOnly())
+ throw new TInvalidOperationException('list_readonly',get_class($this));
+
+ return $this->insertAtIndexInPriority($item,false,$priority,true);
+ }
+
+ /**
+ * Inserts an item at an index. It reads the priority of the item at index within the flattened list
+ * and then inserts the item at that priority-index.
+ * @param integer the specified position in the flattened list.
+ * @param mixed new item to add
+ * @throws TInvalidDataValueException If the index specified exceeds the bound
+ * @throws TInvalidOperationException if the list is read-only
+ */
+ public function insertAt($index,$item)
+ {
+ if($this->getReadOnly())
+ throw new TInvalidOperationException('list_readonly',get_class($this));
+
+ if(($priority=$this->priorityAt($index,true))!==false)
+ $this->insertAtIndexInPriority($item,$priority[1],$priority[0]);
+ else
+ throw new TInvalidDataValueException('list_index_invalid',$index);
+ }
+
+ /**
+ * Inserts an item at the specified index within a priority. Override and call this method to
+ * insert your own functionality.
+ * @param mixed item to add within the list.
+ * @param integer index within the priority to add the item, defaults to false which appends the item at the priority
+ * @param numeric priority priority of the item. defaults to null, which sets it to the default priority
+ * @param boolean preserveCache specifies if this is a special quick function or not. This defaults to false.
+ * @throws TInvalidDataValueException If the index specified exceeds the bound
+ * @throws TInvalidOperationException if the list is read-only
+ */
+ public function insertAtIndexInPriority($item,$index=false,$priority=null,$preserveCache=false)
+ {
+ if($this->getReadOnly())
+ throw new TInvalidOperationException('list_readonly',get_class($this));
+
+ if($priority===null)
+ $priority=$this->getDefaultPriority();
+ $priority=(string)round(TPropertyValue::ensureFloat($priority), $this->_p);
+
+ if($preserveCache) {
+ $this->sortPriorities();
+ $cc=0;
+ foreach($this->_d as $prioritykey=>$items)
+ if($prioritykey>=$priority)
+ break;
+ else
+ $cc+=count($items);
+
+ if($index===false&&isset($this->_d[$priority])) {
+ $c=count($this->_d[$priority]);
+ $c+=$cc;
+ $this->_d[$priority][]=$item;
+ } else if(isset($this->_d[$priority])) {
+ $c=$index+$cc;
+ array_splice($this->_d[$priority],$index,0,array($item));
+ } else {
+ $c = $cc;
+ $this->_o = false;
+ $this->_d[$priority]=array($item);
+ }
+
+ if($this->_fd&&is_array($this->_fd)) // if there is a flattened array cache
+ array_splice($this->_fd,$c,0,array($item));
+ } else {
+ $c=null;
+ if($index===false&&isset($this->_d[$priority])) {
+ $cc=count($this->_d[$priority]);
+ $this->_d[$priority][]=$item;
+ } else if(isset($this->_d[$priority])) {
+ $cc=$index;
+ array_splice($this->_d[$priority],$index,0,array($item));
+ } else {
+ $cc=0;
+ $this->_o=false;
+ $this->_d[$priority]=array($item);
+ }
+ if($this->_fd&&is_array($this->_fd)&&count($this->_d)==1)
+ array_splice($this->_fd,$cc,0,array($item));
+ else
+ $this->_fd=null;
+ }
+
+ $this->_c++;
+
+ return $c;
+
+ }
+
+
+ /**
+ * Removes an item from the priority list.
+ * The list will search for the item. The first matching item found will be removed from the list.
+ * @param mixed item the item to be removed.
+ * @param numeric priority of item to remove. without this parameter it defaults to false.
+ * A value of false means any priority. null will be filled in with the default priority.
+ * @return integer index within the flattened list at which the item is being removed
+ * @throws TInvalidDataValueException If the item does not exist
+ */
+ public function remove($item,$priority=false)
+ {
+ if($this->getReadOnly())
+ throw new TInvalidOperationException('list_readonly',get_class($this));
+
+ if(($p=$this->priorityOf($item,true))!==false)
+ {
+ if($priority!==false) {
+ if($priority===null)
+ $priority=$this->getDefaultPriority();
+ $priority=(string)round(TPropertyValue::ensureFloat($priority),$this->_p);
+
+ if($p[0]!=$priority)
+ throw new TInvalidDataValueException('list_item_inexistent');
+ }
+ $this->removeAtIndexInPriority($p[1],$p[0]);
+ return $p[2];
+ }
+ else
+ throw new TInvalidDataValueException('list_item_inexistent');
+ }
+
+ /**
+ * Removes an item at the specified index in the flattened list.
+ * @param integer index of the item to be removed.
+ * @return mixed the removed item.
+ * @throws TInvalidDataValueException If the index specified exceeds the bound
+ * @throws TInvalidOperationException if the list is read-only
+ */
+ public function removeAt($index)
+ {
+ if($this->getReadOnly())
+ throw new TInvalidOperationException('list_readonly',get_class($this));
+
+ if(($priority=$this->priorityAt($index, true))!==false)
+ return $this->removeAtIndexInPriority($priority[1],$priority[0]);
+ throw new TInvalidDataValueException('list_index_invalid',$index);
+ }
+
+ /**
+ * Removes the item at a specific index within a priority. Override
+ * and call this method to insert your own functionality.
+ * @param integer index of item to remove within the priority.
+ * @param numeric priority of the item to remove, defaults to null, or left blank, it is then set to the default priority
+ * @return mixed the removed item.
+ * @throws TInvalidDataValueException If the item does not exist
+ */
+ public function removeAtIndexInPriority($index, $priority=null)
+ {
+ if($this->getReadOnly())
+ throw new TInvalidOperationException('list_readonly',get_class($this));
+
+ if($priority===null)
+ $priority=$this->getDefaultPriority();
+ $priority=(string)round(TPropertyValue::ensureFloat($priority),$this->_p);
+
+ if(!isset($this->_d[$priority])||$index<0||$index>=count($this->_d[$priority]))
+ throw new TInvalidDataValueException('list_item_inexistent');
+
+ // $value is an array of elements removed, only one
+ $value=array_splice($this->_d[$priority],$index,1);
+ $value=$value[0];
+
+ if(!count($this->_d[$priority]))
+ unset($this->_d[$priority]);
+
+ $this->_c--;
+ $this->_fd=null;
+ return $value;
+ }
+
+ /**
+ * Removes all items in the priority list by calling removeAtIndexInPriority from the last item to the first.
+ */
+ public function clear()
+ {
+ if($this->getReadOnly())
+ throw new TInvalidOperationException('list_readonly',get_class($this));
+
+ $d=array_reverse($this->_d,true);
+ foreach($this->_d as $priority=>$items) {
+ for($index=count($items)-1;$index>=0;$index--)
+ $this->removeAtIndexInPriority($index,$priority);
+ unset($this->_d[$priority]);
+ }
+ }
+
+ /**
+ * @param mixed item
+ * @return boolean whether the list contains the item
+ */
+ public function contains($item)
+ {
+ return $this->indexOf($item)>=0;
+ }
+
+ /**
+ * @param mixed item
+ * @return integer the index of the item in the flattened list (0 based), -1 if not found.
+ */
+ public function indexOf($item)
+ {
+ if(($index=array_search($item,$this->flattenPriorities(),true))===false)
+ return -1;
+ else
+ return $index;
+ }
+
+ /**
+ * Returns the priority of a particular item
+ * @param mixed the item to look for within the list
+ * @param boolean withindex this specifies if the full positional data of the item within the list is returned.
+ * This defaults to false, if no parameter is provided, so only provides the priority number of the item by default.
+ * @return numeric|array the priority of the item in the list, false if not found.
+ * if withindex is true, an array is returned of [0 => $priority, 1 => $priorityIndex, 2 => flattenedIndex,
+ * 'priority' => $priority, 'index' => $priorityIndex, 'absindex' => flattenedIndex]
+ */
+ public function priorityOf($item,$withindex = false)
+ {
+ $this->sortPriorities();
+
+ $absindex = 0;
+ foreach($this->_d as $priority=>$items) {
+ if(($index=array_search($item,$items,true))!==false) {
+ $absindex+=$index;
+ return $withindex?array($priority,$index,$absindex,
+ 'priority'=>$priority,'index'=>$index,'absindex'=>$absindex):$priority;
+ } else
+ $absindex+=count($items);
+ }
+
+ return false;
+ }
+
+ /**
+ * Retutrns the priority of an item at a particular flattened index.
+ * @param integer index of the item within the list
+ * @param boolean withindex this specifies if the full positional data of the item within the list is returned.
+ * This defaults to false, if no parameter is provided, so only provides the priority number of the item by default.
+ * @return numeric|array the priority of the item in the list, false if not found.
+ * if withindex is true, an array is returned of [0 => $priority, 1 => $priorityIndex, 2 => flattenedIndex,
+ * 'priority' => $priority, 'index' => $priorityIndex, 'absindex' => flattenedIndex]
+ */
+ public function priorityAt($index,$withindex = false)
+ {
+ if($index<0||$index>=$this->getCount())
+ throw new TInvalidDataValueException('list_index_invalid',$index);
+
+ $absindex=$index;
+ $this->sortPriorities();
+ foreach($this->_d as $priority=>$items) {
+ if($index>=($c=count($items)))
+ $index-=$c;
+ else
+ return $withindex?array($priority,$index,$absindex,
+ 'priority'=>$priority,'index'=>$index,'absindex'=>$absindex):$priority;
+ }
+ return false;
+ }
+
+ /**
+ * This inserts an item before another item within the list. It uses the same priority as the
+ * found index item and places the new item before it.
+ * @param mixed indexitem the item to index
+ * @param mixed the item to add before indexitem
+ * @return integer where the item has been inserted in the flattened list
+ * @throws TInvalidDataValueException If the item does not exist
+ */
+ public function insertBefore($indexitem, $item)
+ {
+ if($this->getReadOnly())
+ throw new TInvalidOperationException('list_readonly',get_class($this));
+
+ if(($priority=$this->priorityOf($indexitem,true))===false)
+ throw new TInvalidDataValueException('list_item_inexistent');
+
+ $this->insertAtIndexInPriority($item,$priority[1],$priority[0]);
+
+ return $priority[2];
+ }
+
+ /**
+ * This inserts an item after another item within the list. It uses the same priority as the
+ * found index item and places the new item after it.
+ * @param mixed indexitem the item to index
+ * @param mixed the item to add after indexitem
+ * @return integer where the item has been inserted in the flattened list
+ * @throws TInvalidDataValueException If the item does not exist
+ */
+ public function insertAfter($indexitem, $item)
+ {
+ if($this->getReadOnly())
+ throw new TInvalidOperationException('list_readonly',get_class($this));
+
+ if(($priority=$this->priorityOf($indexitem,true))===false)
+ throw new TInvalidDataValueException('list_item_inexistent');
+
+ $this->insertAtIndexInPriority($item,$priority[1]+1,$priority[0]);
+
+ return $priority[2]+1;
+ }
+
+ /**
+ * @return array the priority list of items in array
+ */
+ public function toArray()
+ {
+ return $this->flattenPriorities();
+ }
+
+ /**
+ * @return array the array of priorities keys with values of arrays of items. The priorities are sorted so important priorities, lower numerics, are first.
+ */
+ public function toPriorityArray()
+ {
+ $this->sortPriorities();
+ return $this->_d;
+ }
+
+ /**
+ * Combines the map elements which have a priority below the parameter value
+ * @param numeric the cut-off priority. All items of priority less than this are returned.
+ * @param boolean whether or not the input cut-off priority is inclusive. Default: false, not inclusive.
+ * @return array the array of priorities keys with values of arrays of items that are below a specified priority.
+ * The priorities are sorted so important priorities, lower numerics, are first.
+ */
+ public function toArrayBelowPriority($priority,$inclusive=false)
+ {
+ $this->sortPriorities();
+ $items=array();
+ foreach($this->_d as $itemspriority=>$itemsatpriority)
+ {
+ if((!$inclusive&&$itemspriority>=$priority)||$itemspriority>$priority)
+ break;
+ $items=array_merge($items,$itemsatpriority);
+ }
+ return $items;
+ }
+
+ /**
+ * Combines the map elements which have a priority above the parameter value
+ * @param numeric the cut-off priority. All items of priority greater than this are returned.
+ * @param boolean whether or not the input cut-off priority is inclusive. Default: true, inclusive.
+ * @return array the array of priorities keys with values of arrays of items that are above a specified priority.
+ * The priorities are sorted so important priorities, lower numerics, are first.
+ */
+ public function toArrayAbovePriority($priority,$inclusive=true)
+ {
+ $this->sortPriorities();
+ $items=array();
+ foreach($this->_d as $itemspriority=>$itemsatpriority)
+ {
+ if((!$inclusive&&$itemspriority<=$priority)||$itemspriority<$priority)
+ continue;
+ $items=array_merge($items,$itemsatpriority);
+ }
+ return $items;
+ }
+
+
+ /**
+ * Copies iterable data into the priority list.
+ * Note, existing data in the map will be cleared first.
+ * @param mixed the data to be copied from, must be an array or object implementing Traversable
+ * @throws TInvalidDataTypeException If data is neither an array nor an iterator.
+ */
+ public function copyFrom($data)
+ {
+ if($data instanceof TPriorityList)
+ {
+ if($this->getCount()>0)
+ $this->clear();
+ foreach($data->getPriorities() as $priority)
+ {
+ foreach($data->itemsAtPriority($priority) as $index=>$item)
+ $this->insertAtIndexInPriority($item,$index,$priority);
+ }
+ } else if(is_array($data)||$data instanceof Traversable) {
+ if($this->getCount()>0)
+ $this->clear();
+ foreach($data as $key=>$item)
+ $this->add($item);
+ } else if($data!==null)
+ throw new TInvalidDataTypeException('map_data_not_iterable');
+ }
+
+ /**
+ * Merges iterable data into the priority list.
+ * New data will be appended to the end of the existing data. If another TPriorityList is merged,
+ * the incoming parameter items will be appended at the priorities they are present. These items will be added
+ * to the end of the existing items with equal priorities, if there are any.
+ * @param mixed the data to be merged with, must be an array or object implementing Traversable
+ * @throws TInvalidDataTypeException If data is neither an array nor an iterator.
+ */
+ public function mergeWith($data)
+ {
+ if($data instanceof TPriorityList)
+ {
+ foreach($data->getPriorities() as $priority)
+ {
+ foreach($data->itemsAtPriority($priority) as $index=>$item)
+ $this->insertAtIndexInPriority($item,false,$priority);
+ }
+ }
+ else if(is_array($data)||$data instanceof Traversable)
+ {
+ foreach($data as $priority=>$item)
+ $this->add($item);
+
+ }
+ else if($data!==null)
+ throw new TInvalidDataTypeException('map_data_not_iterable');
+ }
+
+ /**
+ * Returns whether there is an element at the specified offset.
+ * This method is required by the interface ArrayAccess.
+ * @param mixed the offset to check on
+ * @return boolean
+ */
+ public function offsetExists($offset)
+ {
+ return ($offset>=0&&$offset<$this->getCount());
+ }
+
+ /**
+ * Returns the element at the specified offset.
+ * This method is required by the interface ArrayAccess.
+ * @param integer the offset to retrieve element.
+ * @return mixed the element at the offset, null if no element is found at the offset
+ */
+ public function offsetGet($offset)
+ {
+ return $this->itemAt($offset);
+ }
+
+ /**
+ * Sets the element at the specified offset. This method is required by the interface ArrayAccess.
+ * Setting elements in a priority list is not straight forword when appending and setting at the
+ * end boundary. When appending without an offset (a null offset), the item will be added at
+ * the default priority. The item may not be the last item in the list. When appending with an
+ * offset equal to the count of the list, the item will get be appended with the last items priority.
+ *
+ * All together, when setting the location of an item, the item stays in that location, but appending
+ * an item into a priority list doesn't mean the item is at the end of the list.
+ * @param integer the offset to set element
+ * @param mixed the element value
+ */
+ public function offsetSet($offset,$item)
+ {
+ if($offset===null)
+ return $this->add($item);
+ if($offset===$this->getCount()) {
+ $priority=$this->priorityAt($offset-1,true);
+ $priority[1]++;
+ } else {
+ $priority=$this->priorityAt($offset,true);
+ $this->removeAtIndexInPriority($priority[1],$priority[0]);
+ }
+ $this->insertAtIndexInPriority($item,$priority[1],$priority[0]);
+ }
+
+ /**
+ * Unsets the element at the specified offset.
+ * This method is required by the interface ArrayAccess.
+ * @param mixed the offset to unset element
+ */
+ public function offsetUnset($offset)
+ {
+ $this->removeAt($offset);
+ }
+}
diff --git a/framework/Collections/TQueue.php b/framework/Collections/TQueue.php
index 840ec478..d02a7aad 100644
--- a/framework/Collections/TQueue.php
+++ b/framework/Collections/TQueue.php
@@ -1,263 +1,263 @@
-<?php
-/**
- * TQueue, TQueueIterator classes
- *
- * @author Qiang Xue <qiang.xue@gmail.com>
- * @link http://www.pradosoft.com/
- * @copyright Copyright &copy; 2005-2012 PradoSoft
- * @license http://www.pradosoft.com/license/
- * @version $Id$
- * @package System.Collections
- */
-
-/**
- * TQueue class
- *
- * TQueue implements a queue.
- *
- * The typical queue operations are implemented, which include
- * {@link enqueue()}, {@link dequeue()} and {@link peek()}. In addition,
- * {@link contains()} can be used to check if an item is contained
- * in the queue. To obtain the number of the items in the queue,
- * check the {@link getCount Count} property.
- *
- * Items in the queue may be traversed using foreach as follows,
- * <code>
- * foreach($queue as $item) ...
- * </code>
- *
- * @author Qiang Xue <qiang.xue@gmail.com>
- * @author Knut Urdalen <knut.urdalen@gmail.com>
- * @version $Id$
- * @package System.Collections
- * @since 3.1
- */
-class TQueue extends TComponent implements IteratorAggregate,Countable
-{
- /**
- * internal data storage
- * @var array
- */
- private $_d=array();
- /**
- * number of items
- * @var integer
- */
- private $_c=0;
-
- /**
- * Constructor.
- * Initializes the queue with an array or an iterable object.
- * @param array|Iterator the intial data. Default is null, meaning no initialization.
- * @throws TInvalidDataTypeException If data is not null and neither an array nor an iterator.
- */
- public function __construct($data=null)
- {
- if($data!==null)
- $this->copyFrom($data);
- }
-
- /**
- * @return array the list of items in queue
- */
- public function toArray()
- {
- return $this->_d;
- }
-
- /**
- * Copies iterable data into the queue.
- * Note, existing data in the list will be cleared first.
- * @param mixed the data to be copied from, must be an array or object implementing Traversable
- * @throws TInvalidDataTypeException If data is neither an array nor a Traversable.
- */
- public function copyFrom($data)
- {
- if(is_array($data) || ($data instanceof Traversable))
- {
- $this->clear();
- foreach($data as $item)
- {
- $this->_d[]=$item;
- ++$this->_c;
- }
- }
- else if($data!==null)
- throw new TInvalidDataTypeException('queue_data_not_iterable');
- }
-
- /**
- * Removes all items in the queue.
- */
- public function clear()
- {
- $this->_c=0;
- $this->_d=array();
- }
-
- /**
- * @param mixed the item
- * @return boolean whether the queue contains the item
- */
- public function contains($item)
- {
- return array_search($item,$this->_d,true)!==false;
- }
-
- /**
- * Returns the first item at the front of the queue.
- * Unlike {@link dequeue()}, this method does not remove the item from the queue.
- * @return mixed item at the top of the queue
- * @throws TInvalidOperationException if the queue is empty
- */
- public function peek()
- {
- if($this->_c===0)
- throw new TInvalidOperationException('queue_empty');
- else
- return $this->_d[0];
- }
-
- /**
- * Removes and returns the object at the beginning of the queue.
- * @return mixed the item at the beginning of the queue
- * @throws TInvalidOperationException if the queue is empty
- */
- public function dequeue()
- {
- if($this->_c===0)
- throw new TInvalidOperationException('queue_empty');
- else
- {
- --$this->_c;
- return array_shift($this->_d);
- }
- }
-
- /**
- * Adds an object to the end of the queue.
- * @param mixed the item to be appended into the queue
- */
- public function enqueue($item)
- {
- ++$this->_c;
- $this->_d[] = $item;
- }
-
- /**
- * Returns an iterator for traversing the items in the queue.
- * This method is required by the interface IteratorAggregate.
- * @return Iterator an iterator for traversing the items in the queue.
- */
- public function getIterator()
- {
- return new ArrayIterator( $this->_d );
- }
-
- /**
- * @return integer the number of items in the queue
- */
- public function getCount()
- {
- return $this->_c;
- }
-
- /**
- * Returns the number of items in the queue.
- * This method is required by Countable interface.
- * @return integer number of items in the queue.
- */
- public function count()
- {
- return $this->getCount();
- }
-}
-
-/**
- * TQueueIterator class
- *
- * TQueueIterator implements Iterator interface.
- *
- * TQueueIterator is used by TQueue. It allows TQueue to return a new iterator
- * for traversing the items in the queue.
- *
- * @author Qiang Xue <qiang.xue@gmail.com>
- * @version $Id$
- * @package System.Collections
- * @since 3.1
- */
-class TQueueIterator implements Iterator
-{
- /**
- * @var array the data to be iterated through
- */
- private $_d;
- /**
- * @var integer index of the current item
- */
- private $_i;
- /**
- * @var integer count of the data items
- */
- private $_c;
-
- /**
- * Constructor.
- * @param array the data to be iterated through
- */
- public function __construct(&$data)
- {
- $this->_d=&$data;
- $this->_i=0;
- $this->_c=count($this->_d);
- }
-
- /**
- * Rewinds internal array pointer.
- * This method is required by the interface Iterator.
- */
- public function rewind()
- {
- $this->_i=0;
- }
-
- /**
- * Returns the key of the current array item.
- * This method is required by the interface Iterator.
- * @return integer the key of the current array item
- */
- public function key()
- {
- return $this->_i;
- }
-
- /**
- * Returns the current array item.
- * This method is required by the interface Iterator.
- * @return mixed the current array item
- */
- public function current()
- {
- return $this->_d[$this->_i];
- }
-
- /**
- * Moves the internal pointer to the next array item.
- * This method is required by the interface Iterator.
- */
- public function next()
- {
- $this->_i++;
- }
-
- /**
- * Returns whether there is an item at current position.
- * This method is required by the interface Iterator.
- * @return boolean
- */
- public function valid()
- {
- return $this->_i<$this->_c;
- }
-}
-
+<?php
+/**
+ * TQueue, TQueueIterator classes
+ *
+ * @author Qiang Xue <qiang.xue@gmail.com>
+ * @link http://www.pradosoft.com/
+ * @copyright Copyright &copy; 2005-2012 PradoSoft
+ * @license http://www.pradosoft.com/license/
+ * @version $Id$
+ * @package System.Collections
+ */
+
+/**
+ * TQueue class
+ *
+ * TQueue implements a queue.
+ *
+ * The typical queue operations are implemented, which include
+ * {@link enqueue()}, {@link dequeue()} and {@link peek()}. In addition,
+ * {@link contains()} can be used to check if an item is contained
+ * in the queue. To obtain the number of the items in the queue,
+ * check the {@link getCount Count} property.
+ *
+ * Items in the queue may be traversed using foreach as follows,
+ * <code>
+ * foreach($queue as $item) ...
+ * </code>
+ *
+ * @author Qiang Xue <qiang.xue@gmail.com>
+ * @author Knut Urdalen <knut.urdalen@gmail.com>
+ * @version $Id$
+ * @package System.Collections
+ * @since 3.1
+ */
+class TQueue extends TComponent implements IteratorAggregate,Countable
+{
+ /**
+ * internal data storage
+ * @var array
+ */
+ private $_d=array();
+ /**
+ * number of items
+ * @var integer
+ */
+ private $_c=0;
+
+ /**
+ * Constructor.
+ * Initializes the queue with an array or an iterable object.
+ * @param array|Iterator the intial data. Default is null, meaning no initialization.
+ * @throws TInvalidDataTypeException If data is not null and neither an array nor an iterator.
+ */
+ public function __construct($data=null)
+ {
+ if($data!==null)
+ $this->copyFrom($data);
+ }
+
+ /**
+ * @return array the list of items in queue
+ */
+ public function toArray()
+ {
+ return $this->_d;
+ }
+
+ /**
+ * Copies iterable data into the queue.
+ * Note, existing data in the list will be cleared first.
+ * @param mixed the data to be copied from, must be an array or object implementing Traversable
+ * @throws TInvalidDataTypeException If data is neither an array nor a Traversable.
+ */
+ public function copyFrom($data)
+ {
+ if(is_array($data) || ($data instanceof Traversable))
+ {
+ $this->clear();
+ foreach($data as $item)
+ {
+ $this->_d[]=$item;
+ ++$this->_c;
+ }
+ }
+ else if($data!==null)
+ throw new TInvalidDataTypeException('queue_data_not_iterable');
+ }
+
+ /**
+ * Removes all items in the queue.
+ */
+ public function clear()
+ {
+ $this->_c=0;
+ $this->_d=array();
+ }
+
+ /**
+ * @param mixed the item
+ * @return boolean whether the queue contains the item
+ */
+ public function contains($item)
+ {
+ return array_search($item,$this->_d,true)!==false;
+ }
+
+ /**
+ * Returns the first item at the front of the queue.
+ * Unlike {@link dequeue()}, this method does not remove the item from the queue.
+ * @return mixed item at the top of the queue
+ * @throws TInvalidOperationException if the queue is empty
+ */
+ public function peek()
+ {
+ if($this->_c===0)
+ throw new TInvalidOperationException('queue_empty');
+ else
+ return $this->_d[0];
+ }
+
+ /**
+ * Removes and returns the object at the beginning of the queue.
+ * @return mixed the item at the beginning of the queue
+ * @throws TInvalidOperationException if the queue is empty
+ */
+ public function dequeue()
+ {
+ if($this->_c===0)
+ throw new TInvalidOperationException('queue_empty');
+ else
+ {
+ --$this->_c;
+ return array_shift($this->_d);
+ }
+ }
+
+ /**
+ * Adds an object to the end of the queue.
+ * @param mixed the item to be appended into the queue
+ */
+ public function enqueue($item)
+ {
+ ++$this->_c;
+ $this->_d[] = $item;
+ }
+
+ /**
+ * Returns an iterator for traversing the items in the queue.
+ * This method is required by the interface IteratorAggregate.
+ * @return Iterator an iterator for traversing the items in the queue.
+ */
+ public function getIterator()
+ {
+ return new ArrayIterator( $this->_d );
+ }
+
+ /**
+ * @return integer the number of items in the queue
+ */
+ public function getCount()
+ {
+ return $this->_c;
+ }
+
+ /**
+ * Returns the number of items in the queue.
+ * This method is required by Countable interface.
+ * @return integer number of items in the queue.
+ */
+ public function count()
+ {
+ return $this->getCount();
+ }
+}
+
+/**
+ * TQueueIterator class
+ *
+ * TQueueIterator implements Iterator interface.
+ *
+ * TQueueIterator is used by TQueue. It allows TQueue to return a new iterator
+ * for traversing the items in the queue.
+ *
+ * @author Qiang Xue <qiang.xue@gmail.com>
+ * @version $Id$
+ * @package System.Collections
+ * @since 3.1
+ */
+class TQueueIterator implements Iterator
+{
+ /**
+ * @var array the data to be iterated through
+ */
+ private $_d;
+ /**
+ * @var integer index of the current item
+ */
+ private $_i;
+ /**
+ * @var integer count of the data items
+ */
+ private $_c;
+
+ /**
+ * Constructor.
+ * @param array the data to be iterated through
+ */
+ public function __construct(&$data)
+ {
+ $this->_d=&$data;
+ $this->_i=0;
+ $this->_c=count($this->_d);
+ }
+
+ /**
+ * Rewinds internal array pointer.
+ * This method is required by the interface Iterator.
+ */
+ public function rewind()
+ {
+ $this->_i=0;
+ }
+
+ /**
+ * Returns the key of the current array item.
+ * This method is required by the interface Iterator.
+ * @return integer the key of the current array item
+ */
+ public function key()
+ {
+ return $this->_i;
+ }
+
+ /**
+ * Returns the current array item.
+ * This method is required by the interface Iterator.
+ * @return mixed the current array item
+ */
+ public function current()
+ {
+ return $this->_d[$this->_i];
+ }
+
+ /**
+ * Moves the internal pointer to the next array item.
+ * This method is required by the interface Iterator.
+ */
+ public function next()
+ {
+ $this->_i++;
+ }
+
+ /**
+ * Returns whether there is an item at current position.
+ * This method is required by the interface Iterator.
+ * @return boolean
+ */
+ public function valid()
+ {
+ return $this->_i<$this->_c;
+ }
+}
+
diff --git a/framework/Collections/TStack.php b/framework/Collections/TStack.php
index 6f8c21f2..706ca2ed 100644
--- a/framework/Collections/TStack.php
+++ b/framework/Collections/TStack.php
@@ -1,263 +1,263 @@
-<?php
-/**
- * TStack, TStackIterator classes
- *
- * @author Qiang Xue <qiang.xue@gmail.com>
- * @link http://www.pradosoft.com/
+<?php
+/**
+ * TStack, TStackIterator classes
+ *
+ * @author Qiang Xue <qiang.xue@gmail.com>
+ * @link http://www.pradosoft.com/
* @copyright Copyright &copy; 2005-2012 PradoSoft
- * @license http://www.pradosoft.com/license/
- * @version $Id$
- * @package System.Collections
- */
-
-/**
- * TStack class
- *
- * TStack implements a stack.
- *
- * The typical stack operations are implemented, which include
- * {@link push()}, {@link pop()} and {@link peek()}. In addition,
- * {@link contains()} can be used to check if an item is contained
- * in the stack. To obtain the number of the items in the stack,
- * check the {@link getCount Count} property.
- *
- * Items in the stack may be traversed using foreach as follows,
- * <code>
- * foreach($stack as $item) ...
- * </code>
- *
- * @author Qiang Xue <qiang.xue@gmail.com>
- * @version $Id$
- * @package System.Collections
- * @since 3.0
- */
-class TStack extends TComponent implements IteratorAggregate,Countable
-{
- /**
- * internal data storage
- * @var array
- */
- private $_d=array();
- /**
- * number of items
- * @var integer
- */
- private $_c=0;
-
- /**
- * Constructor.
- * Initializes the stack with an array or an iterable object.
- * @param array|Iterator the initial data. Default is null, meaning no initialization.
- * @throws TInvalidDataTypeException If data is not null and neither an array nor an iterator.
- */
- public function __construct($data=null)
- {
- if($data!==null)
- $this->copyFrom($data);
- }
-
- /**
- * @return array the list of items in stack
- */
- public function toArray()
- {
- return $this->_d;
- }
-
- /**
- * Copies iterable data into the stack.
- * Note, existing data in the list will be cleared first.
- * @param mixed the data to be copied from, must be an array or object implementing Traversable
- * @throws TInvalidDataTypeException If data is neither an array nor a Traversable.
- */
- public function copyFrom($data)
- {
- if(is_array($data) || ($data instanceof Traversable))
- {
- $this->clear();
- foreach($data as $item)
- {
- $this->_d[]=$item;
- ++$this->_c;
- }
- }
- else if($data!==null)
- throw new TInvalidDataTypeException('stack_data_not_iterable');
- }
-
- /**
- * Removes all items in the stack.
- */
- public function clear()
- {
- $this->_c=0;
- $this->_d=array();
- }
-
- /**
- * @param mixed the item
- * @return boolean whether the stack contains the item
- */
- public function contains($item)
- {
- return array_search($item,$this->_d,true)!==false;
- }
-
- /**
- * Returns the item at the top of the stack.
- * Unlike {@link pop()}, this method does not remove the item from the stack.
- * @return mixed item at the top of the stack
- * @throws TInvalidOperationException if the stack is empty
- */
- public function peek()
- {
- if($this->_c===0)
- throw new TInvalidOperationException('stack_empty');
- else
- return $this->_d[$this->_c-1];
- }
-
- /**
- * Pops up the item at the top of the stack.
- * @return mixed the item at the top of the stack
- * @throws TInvalidOperationException if the stack is empty
- */
- public function pop()
- {
- if($this->_c===0)
- throw new TInvalidOperationException('stack_empty');
- else
- {
- --$this->_c;
- return array_pop($this->_d);
- }
- }
-
- /**
- * Pushes an item into the stack.
- * @param mixed the item to be pushed into the stack
- */
- public function push($item)
- {
- ++$this->_c;
- $this->_d[] = $item;
- }
-
- /**
- * Returns an iterator for traversing the items in the stack.
- * This method is required by the interface IteratorAggregate.
- * @return Iterator an iterator for traversing the items in the stack.
- */
- public function getIterator()
- {
- return new ArrayIterator( $this->_d );
- }
-
- /**
- * @return integer the number of items in the stack
- */
- public function getCount()
- {
- return $this->_c;
- }
-
- /**
- * Returns the number of items in the stack.
- * This method is required by Countable interface.
- * @return integer number of items in the stack.
- */
- public function count()
- {
- return $this->getCount();
- }
-}
-
-/**
- * TStackIterator class
- *
- * TStackIterator implements Iterator interface.
- *
- * TStackIterator is used by TStack. It allows TStack to return a new iterator
- * for traversing the items in the list.
- *
- * @deprecated Issue 264 : ArrayIterator should be used instead
- * @author Qiang Xue <qiang.xue@gmail.com>
- * @version $Id$
- * @package System.Collections
- * @since 3.0
- */
-class TStackIterator implements Iterator
-{
- /**
- * @var array the data to be iterated through
- */
- private $_d;
- /**
- * @var integer index of the current item
- */
- private $_i;
- /**
- * @var integer count of the data items
- */
- private $_c;
-
- /**
- * Constructor.
- * @param array the data to be iterated through
- */
- public function __construct(&$data)
- {
- $this->_d=&$data;
- $this->_i=0;
- $this->_c=count($this->_d);
- }
-
- /**
- * Rewinds internal array pointer.
- * This method is required by the interface Iterator.
- */
- public function rewind()
- {
- $this->_i=0;
- }
-
- /**
- * Returns the key of the current array item.
- * This method is required by the interface Iterator.
- * @return integer the key of the current array item
- */
- public function key()
- {
- return $this->_i;
- }
-
- /**
- * Returns the current array item.
- * This method is required by the interface Iterator.
- * @return mixed the current array item
- */
- public function current()
- {
- return $this->_d[$this->_i];
- }
-
- /**
- * Moves the internal pointer to the next array item.
- * This method is required by the interface Iterator.
- */
- public function next()
- {
- $this->_i++;
- }
-
- /**
- * Returns whether there is an item at current position.
- * This method is required by the interface Iterator.
- * @return boolean
- */
- public function valid()
- {
- return $this->_i<$this->_c;
- }
-}
-
+ * @license http://www.pradosoft.com/license/
+ * @version $Id$
+ * @package System.Collections
+ */
+
+/**
+ * TStack class
+ *
+ * TStack implements a stack.
+ *
+ * The typical stack operations are implemented, which include
+ * {@link push()}, {@link pop()} and {@link peek()}. In addition,
+ * {@link contains()} can be used to check if an item is contained
+ * in the stack. To obtain the number of the items in the stack,
+ * check the {@link getCount Count} property.
+ *
+ * Items in the stack may be traversed using foreach as follows,
+ * <code>
+ * foreach($stack as $item) ...
+ * </code>
+ *
+ * @author Qiang Xue <qiang.xue@gmail.com>
+ * @version $Id$
+ * @package System.Collections
+ * @since 3.0
+ */
+class TStack extends TComponent implements IteratorAggregate,Countable
+{
+ /**
+ * internal data storage
+ * @var array
+ */
+ private $_d=array();
+ /**
+ * number of items
+ * @var integer
+ */
+ private $_c=0;
+
+ /**
+ * Constructor.
+ * Initializes the stack with an array or an iterable object.
+ * @param array|Iterator the initial data. Default is null, meaning no initialization.
+ * @throws TInvalidDataTypeException If data is not null and neither an array nor an iterator.
+ */
+ public function __construct($data=null)
+ {
+ if($data!==null)
+ $this->copyFrom($data);
+ }
+
+ /**
+ * @return array the list of items in stack
+ */
+ public function toArray()
+ {
+ return $this->_d;
+ }
+
+ /**
+ * Copies iterable data into the stack.
+ * Note, existing data in the list will be cleared first.
+ * @param mixed the data to be copied from, must be an array or object implementing Traversable
+ * @throws TInvalidDataTypeException If data is neither an array nor a Traversable.
+ */
+ public function copyFrom($data)
+ {
+ if(is_array($data) || ($data instanceof Traversable))
+ {
+ $this->clear();
+ foreach($data as $item)
+ {
+ $this->_d[]=$item;
+ ++$this->_c;
+ }
+ }
+ else if($data!==null)
+ throw new TInvalidDataTypeException('stack_data_not_iterable');
+ }
+
+ /**
+ * Removes all items in the stack.
+ */
+ public function clear()
+ {
+ $this->_c=0;
+ $this->_d=array();
+ }
+
+ /**
+ * @param mixed the item
+ * @return boolean whether the stack contains the item
+ */
+ public function contains($item)
+ {
+ return array_search($item,$this->_d,true)!==false;
+ }
+
+ /**
+ * Returns the item at the top of the stack.
+ * Unlike {@link pop()}, this method does not remove the item from the stack.
+ * @return mixed item at the top of the stack
+ * @throws TInvalidOperationException if the stack is empty
+ */
+ public function peek()
+ {
+ if($this->_c===0)
+ throw new TInvalidOperationException('stack_empty');
+ else
+ return $this->_d[$this->_c-1];
+ }
+
+ /**
+ * Pops up the item at the top of the stack.
+ * @return mixed the item at the top of the stack
+ * @throws TInvalidOperationException if the stack is empty
+ */
+ public function pop()
+ {
+ if($this->_c===0)
+ throw new TInvalidOperationException('stack_empty');
+ else
+ {
+ --$this->_c;
+ return array_pop($this->_d);
+ }
+ }
+
+ /**
+ * Pushes an item into the stack.
+ * @param mixed the item to be pushed into the stack
+ */
+ public function push($item)
+ {
+ ++$this->_c;
+ $this->_d[] = $item;
+ }
+
+ /**
+ * Returns an iterator for traversing the items in the stack.
+ * This method is required by the interface IteratorAggregate.
+ * @return Iterator an iterator for traversing the items in the stack.
+ */
+ public function getIterator()
+ {
+ return new ArrayIterator( $this->_d );
+ }
+
+ /**
+ * @return integer the number of items in the stack
+ */
+ public function getCount()
+ {
+ return $this->_c;
+ }
+
+ /**
+ * Returns the number of items in the stack.
+ * This method is required by Countable interface.
+ * @return integer number of items in the stack.
+ */
+ public function count()
+ {
+ return $this->getCount();
+ }
+}
+
+/**
+ * TStackIterator class
+ *
+ * TStackIterator implements Iterator interface.
+ *
+ * TStackIterator is used by TStack. It allows TStack to return a new iterator
+ * for traversing the items in the list.
+ *
+ * @deprecated Issue 264 : ArrayIterator should be used instead
+ * @author Qiang Xue <qiang.xue@gmail.com>
+ * @version $Id$
+ * @package System.Collections
+ * @since 3.0
+ */
+class TStackIterator implements Iterator
+{
+ /**
+ * @var array the data to be iterated through
+ */
+ private $_d;
+ /**
+ * @var integer index of the current item
+ */
+ private $_i;
+ /**
+ * @var integer count of the data items
+ */
+ private $_c;
+
+ /**
+ * Constructor.
+ * @param array the data to be iterated through
+ */
+ public function __construct(&$data)
+ {
+ $this->_d=&$data;
+ $this->_i=0;
+ $this->_c=count($this->_d);
+ }
+
+ /**
+ * Rewinds internal array pointer.
+ * This method is required by the interface Iterator.
+ */
+ public function rewind()
+ {
+ $this->_i=0;
+ }
+
+ /**
+ * Returns the key of the current array item.
+ * This method is required by the interface Iterator.
+ * @return integer the key of the current array item
+ */
+ public function key()
+ {
+ return $this->_i;
+ }
+
+ /**
+ * Returns the current array item.
+ * This method is required by the interface Iterator.
+ * @return mixed the current array item
+ */
+ public function current()
+ {
+ return $this->_d[$this->_i];
+ }
+
+ /**
+ * Moves the internal pointer to the next array item.
+ * This method is required by the interface Iterator.
+ */
+ public function next()
+ {
+ $this->_i++;
+ }
+
+ /**
+ * Returns whether there is an item at current position.
+ * This method is required by the interface Iterator.
+ * @return boolean
+ */
+ public function valid()
+ {
+ return $this->_i<$this->_c;
+ }
+}
+
diff --git a/framework/Data/ActiveRecord/Exceptions/TActiveRecordException.php b/framework/Data/ActiveRecord/Exceptions/TActiveRecordException.php
index a5d6405e..bcfbfbcb 100644
--- a/framework/Data/ActiveRecord/Exceptions/TActiveRecordException.php
+++ b/framework/Data/ActiveRecord/Exceptions/TActiveRecordException.php
@@ -1,49 +1,49 @@
-<?php
-/**
- * TActiveRecordException class file.
- *
- * @author Wei Zhuo <weizhuo[at]gmail[dot]com>
- * @link http://www.pradosoft.com/
- * @copyright Copyright &copy; 2005-2012 PradoSoft
- * @license http://www.pradosoft.com/license/
- * @version $Id$
- * @package System.Data.ActiveRecord
- */
-
-/**
- * Base exception class for Active Records.
- *
- * @author Wei Zhuo <weizho[at]gmail[dot]com>
- * @version $Id$
- * @package System.Data.ActiveRecord
- * @since 3.1
- */
-class TActiveRecordException extends TDbException
-{
- /**
- * @return string path to the error message file
- */
- protected function getErrorMessageFile()
- {
- $lang=Prado::getPreferredLanguage();
- $path = dirname(__FILE__);
- $msgFile=$path.'/messages-'.$lang.'.txt';
- if(!is_file($msgFile))
- $msgFile=$path.'/messages.txt';
- return $msgFile;
- }
-}
-
-/**
- * TActiveRecordConfigurationException class.
- *
- * @author Wei Zhuo <weizho[at]gmail[dot]com>
- * @version $Id$
- * @package System.Data.ActiveRecord
- * @since 3.1
- */
-class TActiveRecordConfigurationException extends TActiveRecordException
-{
-
-}
-
+<?php
+/**
+ * TActiveRecordException class file.
+ *
+ * @author Wei Zhuo <weizhuo[at]gmail[dot]com>
+ * @link http://www.pradosoft.com/
+ * @copyright Copyright &copy; 2005-2012 PradoSoft
+ * @license http://www.pradosoft.com/license/
+ * @version $Id$
+ * @package System.Data.ActiveRecord
+ */
+
+/**
+ * Base exception class for Active Records.
+ *
+ * @author Wei Zhuo <weizho[at]gmail[dot]com>
+ * @version $Id$
+ * @package System.Data.ActiveRecord
+ * @since 3.1
+ */
+class TActiveRecordException extends TDbException
+{
+ /**
+ * @return string path to the error message file
+ */
+ protected function getErrorMessageFile()
+ {
+ $lang=Prado::getPreferredLanguage();
+ $path = dirname(__FILE__);
+ $msgFile=$path.'/messages-'.$lang.'.txt';
+ if(!is_file($msgFile))
+ $msgFile=$path.'/messages.txt';
+ return $msgFile;
+ }
+}
+
+/**
+ * TActiveRecordConfigurationException class.
+ *
+ * @author Wei Zhuo <weizho[at]gmail[dot]com>
+ * @version $Id$
+ * @package System.Data.ActiveRecord
+ * @since 3.1
+ */
+class TActiveRecordConfigurationException extends TActiveRecordException
+{
+
+}
+
diff --git a/framework/Data/ActiveRecord/Relations/TActiveRecordBelongsTo.php b/framework/Data/ActiveRecord/Relations/TActiveRecordBelongsTo.php
index 68510042..f89660a6 100644
--- a/framework/Data/ActiveRecord/Relations/TActiveRecordBelongsTo.php
+++ b/framework/Data/ActiveRecord/Relations/TActiveRecordBelongsTo.php
@@ -1,138 +1,138 @@
-<?php
-/**
- * TActiveRecordBelongsTo class file.
- *
- * @author Wei Zhuo <weizhuo[at]gmail[dot]com>
- * @link http://www.pradosoft.com/
+<?php
+/**
+ * TActiveRecordBelongsTo class file.
+ *
+ * @author Wei Zhuo <weizhuo[at]gmail[dot]com>
+ * @link http://www.pradosoft.com/
* @copyright Copyright &copy; 2005-2012 PradoSoft
- * @license http://www.pradosoft.com/license/
- * @version $Id$
- * @package System.Data.ActiveRecord.Relations
- */
-
-/**
- * Loads base active record relationship class.
- */
-Prado::using('System.Data.ActiveRecord.Relations.TActiveRecordRelation');
-
-/**
- * Implements the foreign key relationship (TActiveRecord::BELONGS_TO) between
- * the source objects and the related foreign object. Consider the
- * <b>entity</b> relationship between a Team and a Player.
- * <code>
- * +------+ +--------+
- * | Team | 1 <----- * | Player |
- * +------+ +--------+
- * </code>
- * Where one team may have 0 or more players and each player belongs to only
- * one team. We may model Team-Player <b>object</b> relationship as active record as follows.
- * <code>
- * class TeamRecord extends TActiveRecord
- * {
- * // see TActiveRecordHasMany for detailed definition.
- * }
- * class PlayerRecord extends TActiveRecord
- * {
- * const TABLE='player';
- * public $player_id; //primary key
- * public $team_name; //foreign key player.team_name <-> team.name
- * public $age;
- * public $team; //foreign object TeamRecord
- *
- * public static $RELATIONS = array
- * (
- * 'team' => array(self::BELONGS_TO, 'TeamRecord')
- * );
- *
- * public static function finder($className=__CLASS__)
- * {
- * return parent::finder($className);
- * }
- * }
- * </code>
- * The static <tt>$RELATIONS</tt> property of PlayerRecord defines that the
- * property <tt>$team</tt> belongs to a <tt>TeamRecord</tt>.
- *
- * The team object may be fetched as follows.
- * <code>
- * $players = PlayerRecord::finder()->with_team()->findAll();
- * </code>
- * The method <tt>with_xxx()</tt> (where <tt>xxx</tt> is the relationship property
- * name, in this case, <tt>team</tt>) fetchs the corresponding TeamRecords using
- * a second query (not by using a join). The <tt>with_xxx()</tt> accepts the same
- * arguments as other finder methods of TActiveRecord, e.g.
- * <tt>with_team('location = ?', 'Madrid')</tt>.
- *
- * @author Wei Zhuo <weizho[at]gmail[dot]com>
- * @version $Id$
- * @package System.Data.ActiveRecord.Relations
- * @since 3.1
- */
-class TActiveRecordBelongsTo extends TActiveRecordRelation
-{
- /**
- * Get the foreign key index values from the results and make calls to the
- * database to find the corresponding foreign objects.
- * @param array original results.
- */
- protected function collectForeignObjects(&$results)
- {
- $fkeys = $this->getRelationForeignKeys();
-
- $properties = array_keys($fkeys);
- $fields = array_values($fkeys);
- $indexValues = $this->getIndexValues($properties, $results);
- $fkObjects = $this->findForeignObjects($fields, $indexValues);
- $this->populateResult($results,$properties,$fkObjects,$fields);
- }
-
- /**
- * @return array foreign key field names as key and object properties as value.
- * @since 3.1.2
- */
- public function getRelationForeignKeys()
- {
- $fkObject = $this->getContext()->getForeignRecordFinder();
- return $this->findForeignKeys($this->getSourceRecord(),$fkObject);
- }
-
- /**
- * Sets the foreign objects to the given property on the source object.
- * @param TActiveRecord source object.
- * @param array foreign objects.
- */
- protected function setObjectProperty($source, $properties, &$collections)
- {
- $hash = $this->getObjectHash($source, $properties);
- $prop = $this->getContext()->getProperty();
- if(isset($collections[$hash]) && count($collections[$hash]) > 0)
- {
- if(count($collections[$hash]) > 1)
- throw new TActiveRecordException('ar_belongs_to_multiple_result');
- $source->$prop=$collections[$hash][0];
- }
- else
- $source->$prop=null;
- }
-
- /**
- * Updates the source object first.
- * @return boolean true if all update are success (including if no update was required), false otherwise .
- */
- public function updateAssociatedRecords()
- {
- $obj = $this->getContext()->getSourceRecord();
- $fkObject = $obj->getColumnValue($this->getContext()->getProperty());
- if($fkObject!==null)
- {
- $fkObject->save();
- $source = $this->getSourceRecord();
- $fkeys = $this->findForeignKeys($source, $fkObject);
- foreach($fkeys as $srcKey => $fKey)
- $source->setColumnValue($srcKey, $fkObject->getColumnValue($fKey));
- return true;
- }
- return false;
- }
-}
-
+ * @license http://www.pradosoft.com/license/
+ * @version $Id$
+ * @package System.Data.ActiveRecord.Relations
+ */
+
+/**
+ * Loads base active record relationship class.
+ */
+Prado::using('System.Data.ActiveRecord.Relations.TActiveRecordRelation');
+
+/**
+ * Implements the foreign key relationship (TActiveRecord::BELONGS_TO) between
+ * the source objects and the related foreign object. Consider the
+ * <b>entity</b> relationship between a Team and a Player.
+ * <code>
+ * +------+ +--------+
+ * | Team | 1 <----- * | Player |
+ * +------+ +--------+
+ * </code>
+ * Where one team may have 0 or more players and each player belongs to only
+ * one team. We may model Team-Player <b>object</b> relationship as active record as follows.
+ * <code>
+ * class TeamRecord extends TActiveRecord
+ * {
+ * // see TActiveRecordHasMany for detailed definition.
+ * }
+ * class PlayerRecord extends TActiveRecord
+ * {
+ * const TABLE='player';
+ * public $player_id; //primary key
+ * public $team_name; //foreign key player.team_name <-> team.name
+ * public $age;
+ * public $team; //foreign object TeamRecord
+ *
+ * public static $RELATIONS = array
+ * (
+ * 'team' => array(self::BELONGS_TO, 'TeamRecord')
+ * );
+ *
+ * public static function finder($className=__CLASS__)
+ * {
+ * return parent::finder($className);
+ * }
+ * }
+ * </code>
+ * The static <tt>$RELATIONS</tt> property of PlayerRecord defines that the
+ * property <tt>$team</tt> belongs to a <tt>TeamRecord</tt>.
+ *
+ * The team object may be fetched as follows.
+ * <code>
+ * $players = PlayerRecord::finder()->with_team()->findAll();
+ * </code>
+ * The method <tt>with_xxx()</tt> (where <tt>xxx</tt> is the relationship property
+ * name, in this case, <tt>team</tt>) fetchs the corresponding TeamRecords using
+ * a second query (not by using a join). The <tt>with_xxx()</tt> accepts the same
+ * arguments as other finder methods of TActiveRecord, e.g.
+ * <tt>with_team('location = ?', 'Madrid')</tt>.
+ *
+ * @author Wei Zhuo <weizho[at]gmail[dot]com>
+ * @version $Id$
+ * @package System.Data.ActiveRecord.Relations
+ * @since 3.1
+ */
+class TActiveRecordBelongsTo extends TActiveRecordRelation
+{
+ /**
+ * Get the foreign key index values from the results and make calls to the
+ * database to find the corresponding foreign objects.
+ * @param array original results.
+ */
+ protected function collectForeignObjects(&$results)
+ {
+ $fkeys = $this->getRelationForeignKeys();
+
+ $properties = array_keys($fkeys);
+ $fields = array_values($fkeys);
+ $indexValues = $this->getIndexValues($properties, $results);
+ $fkObjects = $this->findForeignObjects($fields, $indexValues);
+ $this->populateResult($results,$properties,$fkObjects,$fields);
+ }
+
+ /**
+ * @return array foreign key field names as key and object properties as value.
+ * @since 3.1.2
+ */
+ public function getRelationForeignKeys()
+ {
+ $fkObject = $this->getContext()->getForeignRecordFinder();
+ return $this->findForeignKeys($this->getSourceRecord(),$fkObject);
+ }
+
+ /**
+ * Sets the foreign objects to the given property on the source object.
+ * @param TActiveRecord source object.
+ * @param array foreign objects.
+ */
+ protected function setObjectProperty($source, $properties, &$collections)
+ {
+ $hash = $this->getObjectHash($source, $properties);
+ $prop = $this->getContext()->getProperty();
+ if(isset($collections[$hash]) && count($collections[$hash]) > 0)
+ {
+ if(count($collections[$hash]) > 1)
+ throw new TActiveRecordException('ar_belongs_to_multiple_result');
+ $source->$prop=$collections[$hash][0];
+ }
+ else
+ $source->$prop=null;
+ }
+
+ /**
+ * Updates the source object first.
+ * @return boolean true if all update are success (including if no update was required), false otherwise .
+ */
+ public function updateAssociatedRecords()
+ {
+ $obj = $this->getContext()->getSourceRecord();
+ $fkObject = $obj->getColumnValue($this->getContext()->getProperty());
+ if($fkObject!==null)
+ {
+ $fkObject->save();
+ $source = $this->getSourceRecord();
+ $fkeys = $this->findForeignKeys($source, $fkObject);
+ foreach($fkeys as $srcKey => $fKey)
+ $source->setColumnValue($srcKey, $fkObject->getColumnValue($fKey));
+ return true;
+ }
+ return false;
+ }
+}
+
diff --git a/framework/Data/ActiveRecord/Relations/TActiveRecordHasMany.php b/framework/Data/ActiveRecord/Relations/TActiveRecordHasMany.php
index f5bc4438..6c5628b8 100644
--- a/framework/Data/ActiveRecord/Relations/TActiveRecordHasMany.php
+++ b/framework/Data/ActiveRecord/Relations/TActiveRecordHasMany.php
@@ -1,121 +1,121 @@
-<?php
-/**
- * TActiveRecordHasMany class file.
- *
- * @author Wei Zhuo <weizhuo[at]gmail[dot]com>
- * @link http://www.pradosoft.com/
+<?php
+/**
+ * TActiveRecordHasMany class file.
+ *
+ * @author Wei Zhuo <weizhuo[at]gmail[dot]com>
+ * @link http://www.pradosoft.com/
* @copyright Copyright &copy; 2005-2012 PradoSoft
- * @license http://www.pradosoft.com/license/
- * @version $Id$
- * @package System.Data.ActiveRecord.Relations
- */
-
-/**
- * Loads base active record relations class.
- */
-Prado::using('System.Data.ActiveRecord.Relations.TActiveRecordRelation');
-
-/**
- * Implements TActiveRecord::HAS_MANY relationship between the source object having zero or
- * more foreign objects. Consider the <b>entity</b> relationship between a Team and a Player.
- * <code>
- * +------+ +--------+
- * | Team | 1 <----- * | Player |
- * +------+ +--------+
- * </code>
- * Where one team may have 0 or more players and each player belongs to only
- * one team. We may model Team-Player <b>object</b> relationship as active record as follows.
- * <code>
- * class TeamRecord extends TActiveRecord
- * {
- * const TABLE='team';
- * public $name; //primary key
- * public $location;
- *
- * public $players=array(); //list of players
- *
- * public static $RELATIONS=array
- * (
- * 'players' => array(self::HAS_MANY, 'PlayerRecord')
- * );
- *
- * public static function finder($className=__CLASS__)
- * {
- * return parent::finder($className);
- * }
- * }
- * class PlayerRecord extends TActiveRecord
- * {
- * // see TActiveRecordBelongsTo for detailed definition
- * }
- * </code>
- * The static <tt>$RELATIONS</tt> property of TeamRecord defines that the
- * property <tt>$players</tt> has many <tt>PlayerRecord</tt>s.
- *
- * The players list may be fetched as follows.
- * <code>
- * $team = TeamRecord::finder()->with_players()->findAll();
- * </code>
- * The method <tt>with_xxx()</tt> (where <tt>xxx</tt> is the relationship property
- * name, in this case, <tt>players</tt>) fetchs the corresponding PlayerRecords using
- * a second query (not by using a join). The <tt>with_xxx()</tt> accepts the same
- * arguments as other finder methods of TActiveRecord, e.g. <tt>with_players('age < ?', 35)</tt>.
- *
- * @author Wei Zhuo <weizho[at]gmail[dot]com>
- * @version $Id$
- * @package System.Data.ActiveRecord.Relations
- * @since 3.1
- */
-class TActiveRecordHasMany extends TActiveRecordRelation
-{
- /**
- * Get the foreign key index values from the results and make calls to the
- * database to find the corresponding foreign objects.
- * @param array original results.
- */
- protected function collectForeignObjects(&$results)
- {
- $fkeys = $this->getRelationForeignKeys();
-
- $properties = array_values($fkeys);
- $fields = array_keys($fkeys);
-
- $indexValues = $this->getIndexValues($properties, $results);
- $fkObjects = $this->findForeignObjects($fields,$indexValues);
- $this->populateResult($results,$properties,$fkObjects,$fields);
- }
-
- /**
- * @return array foreign key field names as key and object properties as value.
- * @since 3.1.2
- */
- public function getRelationForeignKeys()
- {
- $fkObject = $this->getContext()->getForeignRecordFinder();
- return $this->findForeignKeys($fkObject, $this->getSourceRecord());
- }
-
- /**
- * Updates the associated foreign objects.
- * @return boolean true if all update are success (including if no update was required), false otherwise .
- */
- public function updateAssociatedRecords()
- {
- $obj = $this->getContext()->getSourceRecord();
- $fkObjects = &$obj->{$this->getContext()->getProperty()};
- $success=true;
- if(($total = count($fkObjects))> 0)
- {
- $source = $this->getSourceRecord();
- $fkeys = $this->findForeignKeys($fkObjects[0], $source);
- for($i=0;$i<$total;$i++)
- {
- foreach($fkeys as $fKey => $srcKey)
- $fkObjects[$i]->setColumnValue($fKey, $source->getColumnValue($srcKey));
- $success = $fkObjects[$i]->save() && $success;
- }
- }
- return $success;
- }
-}
-
+ * @license http://www.pradosoft.com/license/
+ * @version $Id$
+ * @package System.Data.ActiveRecord.Relations
+ */
+
+/**
+ * Loads base active record relations class.
+ */
+Prado::using('System.Data.ActiveRecord.Relations.TActiveRecordRelation');
+
+/**
+ * Implements TActiveRecord::HAS_MANY relationship between the source object having zero or
+ * more foreign objects. Consider the <b>entity</b> relationship between a Team and a Player.
+ * <code>
+ * +------+ +--------+
+ * | Team | 1 <----- * | Player |
+ * +------+ +--------+
+ * </code>
+ * Where one team may have 0 or more players and each player belongs to only
+ * one team. We may model Team-Player <b>object</b> relationship as active record as follows.
+ * <code>
+ * class TeamRecord extends TActiveRecord
+ * {
+ * const TABLE='team';
+ * public $name; //primary key
+ * public $location;
+ *
+ * public $players=array(); //list of players
+ *
+ * public static $RELATIONS=array
+ * (
+ * 'players' => array(self::HAS_MANY, 'PlayerRecord')
+ * );
+ *
+ * public static function finder($className=__CLASS__)
+ * {
+ * return parent::finder($className);
+ * }
+ * }
+ * class PlayerRecord extends TActiveRecord
+ * {
+ * // see TActiveRecordBelongsTo for detailed definition
+ * }
+ * </code>
+ * The static <tt>$RELATIONS</tt> property of TeamRecord defines that the
+ * property <tt>$players</tt> has many <tt>PlayerRecord</tt>s.
+ *
+ * The players list may be fetched as follows.
+ * <code>
+ * $team = TeamRecord::finder()->with_players()->findAll();
+ * </code>
+ * The method <tt>with_xxx()</tt> (where <tt>xxx</tt> is the relationship property
+ * name, in this case, <tt>players</tt>) fetchs the corresponding PlayerRecords using
+ * a second query (not by using a join). The <tt>with_xxx()</tt> accepts the same
+ * arguments as other finder methods of TActiveRecord, e.g. <tt>with_players('age < ?', 35)</tt>.
+ *
+ * @author Wei Zhuo <weizho[at]gmail[dot]com>
+ * @version $Id$
+ * @package System.Data.ActiveRecord.Relations
+ * @since 3.1
+ */
+class TActiveRecordHasMany extends TActiveRecordRelation
+{
+ /**
+ * Get the foreign key index values from the results and make calls to the
+ * database to find the corresponding foreign objects.
+ * @param array original results.
+ */
+ protected function collectForeignObjects(&$results)
+ {
+ $fkeys = $this->getRelationForeignKeys();
+
+ $properties = array_values($fkeys);
+ $fields = array_keys($fkeys);
+
+ $indexValues = $this->getIndexValues($properties, $results);
+ $fkObjects = $this->findForeignObjects($fields,$indexValues);
+ $this->populateResult($results,$properties,$fkObjects,$fields);
+ }
+
+ /**
+ * @return array foreign key field names as key and object properties as value.
+ * @since 3.1.2
+ */
+ public function getRelationForeignKeys()
+ {
+ $fkObject = $this->getContext()->getForeignRecordFinder();
+ return $this->findForeignKeys($fkObject, $this->getSourceRecord());
+ }
+
+ /**
+ * Updates the associated foreign objects.
+ * @return boolean true if all update are success (including if no update was required), false otherwise .
+ */
+ public function updateAssociatedRecords()
+ {
+ $obj = $this->getContext()->getSourceRecord();
+ $fkObjects = &$obj->{$this->getContext()->getProperty()};
+ $success=true;
+ if(($total = count($fkObjects))> 0)
+ {
+ $source = $this->getSourceRecord();
+ $fkeys = $this->findForeignKeys($fkObjects[0], $source);
+ for($i=0;$i<$total;$i++)
+ {
+ foreach($fkeys as $fKey => $srcKey)
+ $fkObjects[$i]->setColumnValue($fKey, $source->getColumnValue($srcKey));
+ $success = $fkObjects[$i]->save() && $success;
+ }
+ }
+ return $success;
+ }
+}
+
diff --git a/framework/Data/ActiveRecord/Relations/TActiveRecordHasManyAssociation.php b/framework/Data/ActiveRecord/Relations/TActiveRecordHasManyAssociation.php
index fe368f9c..28ebb317 100644
--- a/framework/Data/ActiveRecord/Relations/TActiveRecordHasManyAssociation.php
+++ b/framework/Data/ActiveRecord/Relations/TActiveRecordHasManyAssociation.php
@@ -1,376 +1,376 @@
-<?php
-/**
- * TActiveRecordHasManyAssociation class file.
- *
- * @author Wei Zhuo <weizhuo[at]gmail[dot]com>
- * @link http://www.pradosoft.com/
+<?php
+/**
+ * TActiveRecordHasManyAssociation class file.
+ *
+ * @author Wei Zhuo <weizhuo[at]gmail[dot]com>
+ * @link http://www.pradosoft.com/
* @copyright Copyright &copy; 2005-2012 PradoSoft
- * @license http://www.pradosoft.com/license/
- * @version $Id$
- * @package System.Data.ActiveRecord.Relations
- */
-
-/**
- * Loads base active record relations class.
- */
-Prado::using('System.Data.ActiveRecord.Relations.TActiveRecordRelation');
-
-/**
- * Implements the M-N (many to many) relationship via association table.
- * Consider the <b>entity</b> relationship between Articles and Categories
- * via the association table <tt>Article_Category</tt>.
- * <code>
- * +---------+ +------------------+ +----------+
- * | Article | * -----> * | Article_Category | * <----- * | Category |
- * +---------+ +------------------+ +----------+
- * </code>
- * Where one article may have 0 or more categories and each category may have 0
- * or more articles. We may model Article-Category <b>object</b> relationship
- * as active record as follows.
- * <code>
- * class ArticleRecord
- * {
- * const TABLE='Article';
- * public $article_id;
- *
- * public $Categories=array(); //foreign object collection.
- *
- * public static $RELATIONS = array
- * (
- * 'Categories' => array(self::MANY_TO_MANY, 'CategoryRecord', 'Article_Category')
- * );
- *
- * public static function finder($className=__CLASS__)
- * {
- * return parent::finder($className);
- * }
- * }
- * class CategoryRecord
- * {
- * const TABLE='Category';
- * public $category_id;
- *
- * public $Articles=array();
- *
- * public static $RELATIONS = array
- * (
- * 'Articles' => array(self::MANY_TO_MANY, 'ArticleRecord', 'Article_Category')
- * );
- *
- * public static function finder($className=__CLASS__)
- * {
- * return parent::finder($className);
- * }
- * }
- * </code>
- *
- * The static <tt>$RELATIONS</tt> property of ArticleRecord defines that the
- * property <tt>$Categories</tt> has many <tt>CategoryRecord</tt>s. Similar, the
- * static <tt>$RELATIONS</tt> property of CategoryRecord defines many ArticleRecords.
- *
- * The articles with categories list may be fetched as follows.
- * <code>
- * $articles = TeamRecord::finder()->withCategories()->findAll();
- * </code>
- * The method <tt>with_xxx()</tt> (where <tt>xxx</tt> is the relationship property
- * name, in this case, <tt>Categories</tt>) fetchs the corresponding CategoryRecords using
- * a second query (not by using a join). The <tt>with_xxx()</tt> accepts the same
- * arguments as other finder methods of TActiveRecord.
- *
- * @author Wei Zhuo <weizho[at]gmail[dot]com>
- * @version $Id$
- * @package System.Data.ActiveRecord.Relations
- * @since 3.1
- */
-class TActiveRecordHasManyAssociation extends TActiveRecordRelation
-{
- private $_association;
- private $_sourceTable;
- private $_foreignTable;
- private $_association_columns=array();
-
- /**
- * Get the foreign key index values from the results and make calls to the
- * database to find the corresponding foreign objects using association table.
- * @param array original results.
- */
- protected function collectForeignObjects(&$results)
- {
- list($sourceKeys, $foreignKeys) = $this->getRelationForeignKeys();
- $properties = array_values($sourceKeys);
- $indexValues = $this->getIndexValues($properties, $results);
- $this->fetchForeignObjects($results, $foreignKeys,$indexValues,$sourceKeys);
- }
-
- /**
- * @return array 2 arrays of source keys and foreign keys from the association table.
- */
- public function getRelationForeignKeys()
- {
- $association = $this->getAssociationTable();
- $sourceKeys = $this->findForeignKeys($association, $this->getSourceRecord(), true);
- $fkObject = $this->getContext()->getForeignRecordFinder();
- $foreignKeys = $this->findForeignKeys($association, $fkObject);
- return array($sourceKeys, $foreignKeys);
- }
-
- /**
- * @return TDbTableInfo association table information.
- */
- protected function getAssociationTable()
- {
- if($this->_association===null)
- {
- $gateway = $this->getSourceRecord()->getRecordGateway();
- $conn = $this->getSourceRecord()->getDbConnection();
- //table name may include the fk column name separated with a dot.
- $table = explode('.', $this->getContext()->getAssociationTable());
- if(count($table)>1)
- {
- $columns = preg_replace('/^\((.*)\)/', '\1', $table[1]);
- $this->_association_columns = preg_split('/\s*[, ]\*/',$columns);
- }
- $this->_association = $gateway->getTableInfo($conn, $table[0]);
- }
- return $this->_association;
- }
-
- /**
- * @return TDbTableInfo source table information.
- */
- protected function getSourceTable()
- {
- if($this->_sourceTable===null)
- {
- $gateway = $this->getSourceRecord()->getRecordGateway();
- $this->_sourceTable = $gateway->getRecordTableInfo($this->getSourceRecord());
- }
- return $this->_sourceTable;
- }
-
- /**
- * @return TDbTableInfo foreign table information.
- */
- protected function getForeignTable()
- {
- if($this->_foreignTable===null)
- {
- $gateway = $this->getSourceRecord()->getRecordGateway();
- $fkObject = $this->getContext()->getForeignRecordFinder();
- $this->_foreignTable = $gateway->getRecordTableInfo($fkObject);
- }
- return $this->_foreignTable;
- }
-
- /**
- * @return TDataGatewayCommand
- */
- protected function getCommandBuilder()
- {
- return $this->getSourceRecord()->getRecordGateway()->getCommand($this->getSourceRecord());
- }
-
- /**
- * @return TDataGatewayCommand
- */
- protected function getForeignCommandBuilder()
- {
- $obj = $this->getContext()->getForeignRecordFinder();
- return $this->getSourceRecord()->getRecordGateway()->getCommand($obj);
- }
-
-
- /**
- * Fetches the foreign objects using TActiveRecord::findAllByIndex()
- * @param array field names
- * @param array foreign key index values.
- */
- protected function fetchForeignObjects(&$results,$foreignKeys,$indexValues,$sourceKeys)
- {
- $criteria = $this->getCriteria();
- $finder = $this->getContext()->getForeignRecordFinder();
- $type = get_class($finder);
- $command = $this->createCommand($criteria, $foreignKeys,$indexValues,$sourceKeys);
- $srcProps = array_keys($sourceKeys);
- $collections=array();
- foreach($this->getCommandBuilder()->onExecuteCommand($command, $command->query()) as $row)
- {
- $hash = $this->getObjectHash($row, $srcProps);
- foreach($srcProps as $column)
- unset($row[$column]);
- $obj = $this->createFkObject($type,$row,$foreignKeys);
- $collections[$hash][] = $obj;
- }
- $this->setResultCollection($results, $collections, array_values($sourceKeys));
- }
-
- /**
- * @param string active record class name.
- * @param array row data
- * @param array foreign key column names
- * @return TActiveRecord
- */
- protected function createFkObject($type,$row,$foreignKeys)
- {
- $obj = TActiveRecord::createRecord($type, $row);
- if(count($this->_association_columns) > 0)
- {
- $i=0;
- foreach($foreignKeys as $ref=>$fk)
- $obj->setColumnValue($ref, $row[$this->_association_columns[$i++]]);
- }
- return $obj;
- }
-
- /**
- * @param TSqlCriteria
- * @param TTableInfo association table info
- * @param array field names
- * @param array field values
- */
- public function createCommand($criteria, $foreignKeys,$indexValues,$sourceKeys)
- {
- $innerJoin = $this->getAssociationJoin($foreignKeys,$indexValues,$sourceKeys);
- $fkTable = $this->getForeignTable()->getTableFullName();
- $srcColumns = $this->getSourceColumns($sourceKeys);
- if(($where=$criteria->getCondition())===null)
- $where='1=1';
- $sql = "SELECT {$fkTable}.*, {$srcColumns} FROM {$fkTable} {$innerJoin} WHERE {$where}";
-
- $parameters = $criteria->getParameters()->toArray();
- $ordering = $criteria->getOrdersBy();
- $limit = $criteria->getLimit();
- $offset = $criteria->getOffset();
-
- $builder = $this->getForeignCommandBuilder()->getBuilder();
- $command = $builder->applyCriterias($sql,$parameters,$ordering,$limit,$offset);
- $this->getCommandBuilder()->onCreateCommand($command, $criteria);
- return $command;
- }
-
- /**
- * @param array source table column names.
- * @return string comma separated source column names.
- */
- protected function getSourceColumns($sourceKeys)
- {
- $columns=array();
- $table = $this->getAssociationTable();
- $tableName = $table->getTableFullName();
- $columnNames = array_merge(array_keys($sourceKeys),$this->_association_columns);
- foreach($columnNames as $name)
- $columns[] = $tableName.'.'.$table->getColumn($name)->getColumnName();
- return implode(', ', $columns);
- }
-
- /**
- * SQL inner join for M-N relationship via association table.
- * @param array foreign table column key names.
- * @param array source table index values.
- * @param array source table column names.
- * @return string inner join condition for M-N relationship via association table.
- */
- protected function getAssociationJoin($foreignKeys,$indexValues,$sourceKeys)
- {
- $refInfo= $this->getAssociationTable();
- $fkInfo = $this->getForeignTable();
-
- $refTable = $refInfo->getTableFullName();
- $fkTable = $fkInfo->getTableFullName();
-
- $joins = array();
- $hasAssociationColumns = count($this->_association_columns) > 0;
- $i=0;
- foreach($foreignKeys as $ref=>$fk)
- {
- if($hasAssociationColumns)
- $refField = $refInfo->getColumn($this->_association_columns[$i++])->getColumnName();
- else
- $refField = $refInfo->getColumn($ref)->getColumnName();
- $fkField = $fkInfo->getColumn($fk)->getColumnName();
- $joins[] = "{$fkTable}.{$fkField} = {$refTable}.{$refField}";
- }
- $joinCondition = implode(' AND ', $joins);
- $index = $this->getCommandBuilder()->getIndexKeyCondition($refInfo,array_keys($sourceKeys), $indexValues);
- return "INNER JOIN {$refTable} ON ({$joinCondition}) AND {$index}";
- }
-
- /**
- * Updates the associated foreign objects.
- * @return boolean true if all update are success (including if no update was required), false otherwise .
- */
- public function updateAssociatedRecords()
- {
- $obj = $this->getContext()->getSourceRecord();
- $fkObjects = &$obj->{$this->getContext()->getProperty()};
- $success=true;
- if(($total = count($fkObjects))> 0)
- {
- $source = $this->getSourceRecord();
- $builder = $this->getAssociationTableCommandBuilder();
- for($i=0;$i<$total;$i++)
- $success = $fkObjects[$i]->save() && $success;
- return $this->updateAssociationTable($obj, $fkObjects, $builder) && $success;
- }
- return $success;
- }
-
- /**
- * @return TDbCommandBuilder
- */
- protected function getAssociationTableCommandBuilder()
- {
- $conn = $this->getContext()->getSourceRecord()->getDbConnection();
- return $this->getAssociationTable()->createCommandBuilder($conn);
- }
-
- private function hasAssociationData($builder,$data)
- {
- $condition=array();
- $table = $this->getAssociationTable();
- foreach($data as $name=>$value)
- $condition[] = $table->getColumn($name)->getColumnName().' = ?';
- $command = $builder->createCountCommand(implode(' AND ', $condition),array_values($data));
- $result = $this->getCommandBuilder()->onExecuteCommand($command, intval($command->queryScalar()));
- return intval($result) > 0;
- }
-
- private function addAssociationData($builder,$data)
- {
- $command = $builder->createInsertCommand($data);
- return $this->getCommandBuilder()->onExecuteCommand($command, $command->execute()) > 0;
- }
-
- private function updateAssociationTable($obj,$fkObjects, $builder)
- {
- $source = $this->getSourceRecordValues($obj);
- $foreignKeys = $this->findForeignKeys($this->getAssociationTable(), $fkObjects[0]);
- $success=true;
- foreach($fkObjects as $fkObject)
- {
- $data = array_merge($source, $this->getForeignObjectValues($foreignKeys,$fkObject));
- if(!$this->hasAssociationData($builder,$data))
- $success = $this->addAssociationData($builder,$data) && $success;
- }
- return $success;
- }
-
- private function getSourceRecordValues($obj)
- {
- $sourceKeys = $this->findForeignKeys($this->getAssociationTable(), $obj);
- $indexValues = $this->getIndexValues(array_values($sourceKeys), $obj);
- $data = array();
- $i=0;
- foreach($sourceKeys as $name=>$srcKey)
- $data[$name] = $indexValues[0][$i++];
- return $data;
- }
-
- private function getForeignObjectValues($foreignKeys,$fkObject)
- {
- $data=array();
- foreach($foreignKeys as $name=>$fKey)
- $data[$name] = $fkObject->getColumnValue($fKey);
- return $data;
- }
-}
+ * @license http://www.pradosoft.com/license/
+ * @version $Id$
+ * @package System.Data.ActiveRecord.Relations
+ */
+
+/**
+ * Loads base active record relations class.
+ */
+Prado::using('System.Data.ActiveRecord.Relations.TActiveRecordRelation');
+
+/**
+ * Implements the M-N (many to many) relationship via association table.
+ * Consider the <b>entity</b> relationship between Articles and Categories
+ * via the association table <tt>Article_Category</tt>.
+ * <code>
+ * +---------+ +------------------+ +----------+
+ * | Article | * -----> * | Article_Category | * <----- * | Category |
+ * +---------+ +------------------+ +----------+
+ * </code>
+ * Where one article may have 0 or more categories and each category may have 0
+ * or more articles. We may model Article-Category <b>object</b> relationship
+ * as active record as follows.
+ * <code>
+ * class ArticleRecord
+ * {
+ * const TABLE='Article';
+ * public $article_id;
+ *
+ * public $Categories=array(); //foreign object collection.
+ *
+ * public static $RELATIONS = array
+ * (
+ * 'Categories' => array(self::MANY_TO_MANY, 'CategoryRecord', 'Article_Category')
+ * );
+ *
+ * public static function finder($className=__CLASS__)
+ * {
+ * return parent::finder($className);
+ * }
+ * }
+ * class CategoryRecord
+ * {
+ * const TABLE='Category';
+ * public $category_id;
+ *
+ * public $Articles=array();
+ *
+ * public static $RELATIONS = array
+ * (
+ * 'Articles' => array(self::MANY_TO_MANY, 'ArticleRecord', 'Article_Category')
+ * );
+ *
+ * public static function finder($className=__CLASS__)
+ * {
+ * return parent::finder($className);
+ * }
+ * }
+ * </code>
+ *
+ * The static <tt>$RELATIONS</tt> property of ArticleRecord defines that the
+ * property <tt>$Categories</tt> has many <tt>CategoryRecord</tt>s. Similar, the
+ * static <tt>$RELATIONS</tt> property of CategoryRecord defines many ArticleRecords.
+ *
+ * The articles with categories list may be fetched as follows.
+ * <code>
+ * $articles = TeamRecord::finder()->withCategories()->findAll();
+ * </code>
+ * The method <tt>with_xxx()</tt> (where <tt>xxx</tt> is the relationship property
+ * name, in this case, <tt>Categories</tt>) fetchs the corresponding CategoryRecords using
+ * a second query (not by using a join). The <tt>with_xxx()</tt> accepts the same
+ * arguments as other finder methods of TActiveRecord.
+ *
+ * @author Wei Zhuo <weizho[at]gmail[dot]com>
+ * @version $Id$
+ * @package System.Data.ActiveRecord.Relations
+ * @since 3.1
+ */
+class TActiveRecordHasManyAssociation extends TActiveRecordRelation
+{
+ private $_association;
+ private $_sourceTable;
+ private $_foreignTable;
+ private $_association_columns=array();
+
+ /**
+ * Get the foreign key index values from the results and make calls to the
+ * database to find the corresponding foreign objects using association table.
+ * @param array original results.
+ */
+ protected function collectForeignObjects(&$results)
+ {
+ list($sourceKeys, $foreignKeys) = $this->getRelationForeignKeys();
+ $properties = array_values($sourceKeys);
+ $indexValues = $this->getIndexValues($properties, $results);
+ $this->fetchForeignObjects($results, $foreignKeys,$indexValues,$sourceKeys);
+ }
+
+ /**
+ * @return array 2 arrays of source keys and foreign keys from the association table.
+ */
+ public function getRelationForeignKeys()
+ {
+ $association = $this->getAssociationTable();
+ $sourceKeys = $this->findForeignKeys($association, $this->getSourceRecord(), true);
+ $fkObject = $this->getContext()->getForeignRecordFinder();
+ $foreignKeys = $this->findForeignKeys($association, $fkObject);
+ return array($sourceKeys, $foreignKeys);
+ }
+
+ /**
+ * @return TDbTableInfo association table information.
+ */
+ protected function getAssociationTable()
+ {
+ if($this->_association===null)
+ {
+ $gateway = $this->getSourceRecord()->getRecordGateway();
+ $conn = $this->getSourceRecord()->getDbConnection();
+ //table name may include the fk column name separated with a dot.
+ $table = explode('.', $this->getContext()->getAssociationTable());
+ if(count($table)>1)
+ {
+ $columns = preg_replace('/^\((.*)\)/', '\1', $table[1]);
+ $this->_association_columns = preg_split('/\s*[, ]\*/',$columns);
+ }
+ $this->_association = $gateway->getTableInfo($conn, $table[0]);
+ }
+ return $this->_association;
+ }
+
+ /**
+ * @return TDbTableInfo source table information.
+ */
+ protected function getSourceTable()
+ {
+ if($this->_sourceTable===null)
+ {
+ $gateway = $this->getSourceRecord()->getRecordGateway();
+ $this->_sourceTable = $gateway->getRecordTableInfo($this->getSourceRecord());
+ }
+ return $this->_sourceTable;
+ }
+
+ /**
+ * @return TDbTableInfo foreign table information.
+ */
+ protected function getForeignTable()
+ {
+ if($this->_foreignTable===null)
+ {
+ $gateway = $this->getSourceRecord()->getRecordGateway();
+ $fkObject = $this->getContext()->getForeignRecordFinder();
+ $this->_foreignTable = $gateway->getRecordTableInfo($fkObject);
+ }
+ return $this->_foreignTable;
+ }
+
+ /**
+ * @return TDataGatewayCommand
+ */
+ protected function getCommandBuilder()
+ {
+ return $this->getSourceRecord()->getRecordGateway()->getCommand($this->getSourceRecord());
+ }
+
+ /**
+ * @return TDataGatewayCommand
+ */
+ protected function getForeignCommandBuilder()
+ {
+ $obj = $this->getContext()->getForeignRecordFinder();
+ return $this->getSourceRecord()->getRecordGateway()->getCommand($obj);
+ }
+
+
+ /**
+ * Fetches the foreign objects using TActiveRecord::findAllByIndex()
+ * @param array field names
+ * @param array foreign key index values.
+ */
+ protected function fetchForeignObjects(&$results,$foreignKeys,$indexValues,$sourceKeys)
+ {
+ $criteria = $this->getCriteria();
+ $finder = $this->getContext()->getForeignRecordFinder();
+ $type = get_class($finder);
+ $command = $this->createCommand($criteria, $foreignKeys,$indexValues,$sourceKeys);
+ $srcProps = array_keys($sourceKeys);
+ $collections=array();
+ foreach($this->getCommandBuilder()->onExecuteCommand($command, $command->query()) as $row)
+ {
+ $hash = $this->getObjectHash($row, $srcProps);
+ foreach($srcProps as $column)
+ unset($row[$column]);
+ $obj = $this->createFkObject($type,$row,$foreignKeys);
+ $collections[$hash][] = $obj;
+ }
+ $this->setResultCollection($results, $collections, array_values($sourceKeys));
+ }
+
+ /**
+ * @param string active record class name.
+ * @param array row data
+ * @param array foreign key column names
+ * @return TActiveRecord
+ */
+ protected function createFkObject($type,$row,$foreignKeys)
+ {
+ $obj = TActiveRecord::createRecord($type, $row);
+ if(count($this->_association_columns) > 0)
+ {
+ $i=0;
+ foreach($foreignKeys as $ref=>$fk)
+ $obj->setColumnValue($ref, $row[$this->_association_columns[$i++]]);
+ }
+ return $obj;
+ }
+
+ /**
+ * @param TSqlCriteria
+ * @param TTableInfo association table info
+ * @param array field names
+ * @param array field values
+ */
+ public function createCommand($criteria, $foreignKeys,$indexValues,$sourceKeys)
+ {
+ $innerJoin = $this->getAssociationJoin($foreignKeys,$indexValues,$sourceKeys);
+ $fkTable = $this->getForeignTable()->getTableFullName();
+ $srcColumns = $this->getSourceColumns($sourceKeys);
+ if(($where=$criteria->getCondition())===null)
+ $where='1=1';
+ $sql = "SELECT {$fkTable}.*, {$srcColumns} FROM {$fkTable} {$innerJoin} WHERE {$where}";
+
+ $parameters = $criteria->getParameters()->toArray();
+ $ordering = $criteria->getOrdersBy();
+ $limit = $criteria->getLimit();
+ $offset = $criteria->getOffset();
+
+ $builder = $this->getForeignCommandBuilder()->getBuilder();
+ $command = $builder->applyCriterias($sql,$parameters,$ordering,$limit,$offset);
+ $this->getCommandBuilder()->onCreateCommand($command, $criteria);
+ return $command;
+ }
+
+ /**
+ * @param array source table column names.
+ * @return string comma separated source column names.
+ */
+ protected function getSourceColumns($sourceKeys)
+ {
+ $columns=array();
+ $table = $this->getAssociationTable();
+ $tableName = $table->getTableFullName();
+ $columnNames = array_merge(array_keys($sourceKeys),$this->_association_columns);
+ foreach($columnNames as $name)
+ $columns[] = $tableName.'.'.$table->getColumn($name)->getColumnName();
+ return implode(', ', $columns);
+ }
+
+ /**
+ * SQL inner join for M-N relationship via association table.
+ * @param array foreign table column key names.
+ * @param array source table index values.
+ * @param array source table column names.
+ * @return string inner join condition for M-N relationship via association table.
+ */
+ protected function getAssociationJoin($foreignKeys,$indexValues,$sourceKeys)
+ {
+ $refInfo= $this->getAssociationTable();
+ $fkInfo = $this->getForeignTable();
+
+ $refTable = $refInfo->getTableFullName();
+ $fkTable = $fkInfo->getTableFullName();
+
+ $joins = array();
+ $hasAssociationColumns = count($this->_association_columns) > 0;
+ $i=0;
+ foreach($foreignKeys as $ref=>$fk)
+ {
+ if($hasAssociationColumns)
+ $refField = $refInfo->getColumn($this->_association_columns[$i++])->getColumnName();
+ else
+ $refField = $refInfo->getColumn($ref)->getColumnName();
+ $fkField = $fkInfo->getColumn($fk)->getColumnName();
+ $joins[] = "{$fkTable}.{$fkField} = {$refTable}.{$refField}";
+ }
+ $joinCondition = implode(' AND ', $joins);
+ $index = $this->getCommandBuilder()->getIndexKeyCondition($refInfo,array_keys($sourceKeys), $indexValues);
+ return "INNER JOIN {$refTable} ON ({$joinCondition}) AND {$index}";
+ }
+
+ /**
+ * Updates the associated foreign objects.
+ * @return boolean true if all update are success (including if no update was required), false otherwise .
+ */
+ public function updateAssociatedRecords()
+ {
+ $obj = $this->getContext()->getSourceRecord();
+ $fkObjects = &$obj->{$this->getContext()->getProperty()};
+ $success=true;
+ if(($total = count($fkObjects))> 0)
+ {
+ $source = $this->getSourceRecord();
+ $builder = $this->getAssociationTableCommandBuilder();
+ for($i=0;$i<$total;$i++)
+ $success = $fkObjects[$i]->save() && $success;
+ return $this->updateAssociationTable($obj, $fkObjects, $builder) && $success;
+ }
+ return $success;
+ }
+
+ /**
+ * @return TDbCommandBuilder
+ */
+ protected function getAssociationTableCommandBuilder()
+ {
+ $conn = $this->getContext()->getSourceRecord()->getDbConnection();
+ return $this->getAssociationTable()->createCommandBuilder($conn);
+ }
+
+ private function hasAssociationData($builder,$data)
+ {
+ $condition=array();
+ $table = $this->getAssociationTable();
+ foreach($data as $name=>$value)
+ $condition[] = $table->getColumn($name)->getColumnName().' = ?';
+ $command = $builder->createCountCommand(implode(' AND ', $condition),array_values($data));
+ $result = $this->getCommandBuilder()->onExecuteCommand($command, intval($command->queryScalar()));
+ return intval($result) > 0;
+ }
+
+ private function addAssociationData($builder,$data)
+ {
+ $command = $builder->createInsertCommand($data);
+ return $this->getCommandBuilder()->onExecuteCommand($command, $command->execute()) > 0;
+ }
+
+ private function updateAssociationTable($obj,$fkObjects, $builder)
+ {
+ $source = $this->getSourceRecordValues($obj);
+ $foreignKeys = $this->findForeignKeys($this->getAssociationTable(), $fkObjects[0]);
+ $success=true;
+ foreach($fkObjects as $fkObject)
+ {
+ $data = array_merge($source, $this->getForeignObjectValues($foreignKeys,$fkObject));
+ if(!$this->hasAssociationData($builder,$data))
+ $success = $this->addAssociationData($builder,$data) && $success;
+ }
+ return $success;
+ }
+
+ private function getSourceRecordValues($obj)
+ {
+ $sourceKeys = $this->findForeignKeys($this->getAssociationTable(), $obj);
+ $indexValues = $this->getIndexValues(array_values($sourceKeys), $obj);
+ $data = array();
+ $i=0;
+ foreach($sourceKeys as $name=>$srcKey)
+ $data[$name] = $indexValues[0][$i++];
+ return $data;
+ }
+
+ private function getForeignObjectValues($foreignKeys,$fkObject)
+ {
+ $data=array();
+ foreach($foreignKeys as $name=>$fKey)
+ $data[$name] = $fkObject->getColumnValue($fKey);
+ return $data;
+ }
+}
diff --git a/framework/Data/ActiveRecord/Relations/TActiveRecordHasOne.php b/framework/Data/ActiveRecord/Relations/TActiveRecordHasOne.php
index bc895901..a762e196 100644
--- a/framework/Data/ActiveRecord/Relations/TActiveRecordHasOne.php
+++ b/framework/Data/ActiveRecord/Relations/TActiveRecordHasOne.php
@@ -1,145 +1,145 @@
-<?php
-/**
- * TActiveRecordHasOne class file.
- *
- * @author Wei Zhuo <weizhuo[at]gmail[dot]com>
- * @link http://www.pradosoft.com/
+<?php
+/**
+ * TActiveRecordHasOne class file.
+ *
+ * @author Wei Zhuo <weizhuo[at]gmail[dot]com>
+ * @link http://www.pradosoft.com/
* @copyright Copyright &copy; 2005-2012 PradoSoft
- * @license http://www.pradosoft.com/license/
- * @version $Id$
- * @package System.Data.ActiveRecord.Relations
- */
-
-/**
- * Loads base active record relationship class.
- */
-Prado::using('System.Data.ActiveRecord.Relations.TActiveRecordRelation');
-
-/**
- * TActiveRecordHasOne models the object relationship that a record (the source object)
- * property is an instance of foreign record object having a foreign key
- * related to the source object. The HAS_ONE relation is very similar to the
- * HAS_MANY relationship (in fact, it is equivalent in the entities relationship point of view).
- *
- * The difference of HAS_ONE from HAS_MANY is that the foreign object is singular.
- * That is, HAS_MANY will return a collection of records while HAS_ONE returns the
- * corresponding record.
- *
- * Consider the <b>entity</b> relationship between a Car and a Engine.
- * <code>
- * +-----+ +--------+
- * | Car | 1 <----- 1 | Engine |
- * +-----+ +--------+
- * </code>
- * Where each engine belongs to only one car, that is, the Engine entity has
- * a foreign key to the Car's primary key. We may model
- * Engine-Car <b>object</b> relationship as active record as follows.
- * <code>
- * class CarRecord extends TActiveRecord
- * {
- * const TABLE='car';
- * public $car_id; //primary key
- * public $colour;
- *
- * public $engine; //engine foreign object
- *
- * public static $RELATIONS=array
- * (
- * 'engine' => array(self::HAS_ONE, 'EngineRecord')
- * );
- *
- * public static function finder($className=__CLASS__)
- * {
- * return parent::finder($className);
- * }
- * }
- * class EngineRecord extends TActiveRecord
- * {
- * const TABLE='engine';
- * public $engine_id;
- * public $capacity;
- * public $car_id; //foreign key to cars
- *
- * public static function finder($className=__CLASS__)
- * {
- * return parent::finder($className);
- * }
- * }
- * </code>
- * The static <tt>$RELATIONS</tt> property of CarRecord defines that the
- * property <tt>$engine</tt> that will reference an <tt>EngineRecord</tt> instance.
- *
- * The car record with engine property list may be fetched as follows.
- * <code>
- * $cars = CarRecord::finder()->with_engine()->findAll();
- * </code>
- * The method <tt>with_xxx()</tt> (where <tt>xxx</tt> is the relationship property
- * name, in this case, <tt>engine</tt>) fetchs the corresponding EngineRecords using
- * a second query (not by using a join). The <tt>with_xxx()</tt> accepts the same
- * arguments as other finder methods of TActiveRecord, e.g. <tt>with_engine('capacity < ?', 3.8)</tt>.
- *
- * @author Wei Zhuo <weizho[at]gmail[dot]com>
- * @version $Id$
- * @package System.Data.ActiveRecord.Relations
- * @since 3.1
- */
-class TActiveRecordHasOne extends TActiveRecordRelation
-{
- /**
- * Get the foreign key index values from the results and make calls to the
- * database to find the corresponding foreign objects.
- * @param array original results.
- */
- protected function collectForeignObjects(&$results)
- {
- $fkeys = $this->getRelationForeignKeys();
- $properties = array_values($fkeys);
- $fields = array_keys($fkeys);
-
- $indexValues = $this->getIndexValues($properties, $results);
- $fkObjects = $this->findForeignObjects($fields,$indexValues);
- $this->populateResult($results,$properties,$fkObjects,$fields);
- }
-
- /**
- * @return array foreign key field names as key and object properties as value.
- * @since 3.1.2
- */
- public function getRelationForeignKeys()
- {
- $fkObject = $this->getContext()->getForeignRecordFinder();
- return $this->findForeignKeys($fkObject, $this->getSourceRecord());
- }
-
- /**
- * Sets the foreign objects to the given property on the source object.
- * @param TActiveRecord source object.
- * @param array foreign objects.
- */
- protected function setObjectProperty($source, $properties, &$collections)
- {
- $hash = $this->getObjectHash($source, $properties);
- $prop = $this->getContext()->getProperty();
- if(isset($collections[$hash]) && count($collections[$hash]) > 0)
- {
- if(count($collections[$hash]) > 1)
- throw new TActiveRecordException('ar_belongs_to_multiple_result');
- $source->setColumnValue($prop, $collections[$hash][0]);
- }
- }
-
- /**
- * Updates the associated foreign objects.
- * @return boolean true if all update are success (including if no update was required), false otherwise .
- */
- public function updateAssociatedRecords()
- {
- $fkObject = $this->getContext()->getPropertyValue();
- $source = $this->getSourceRecord();
- $fkeys = $this->findForeignKeys($fkObject, $source);
- foreach($fkeys as $fKey => $srcKey)
- $fkObject->setColumnValue($fKey, $source->getColumnValue($srcKey));
- return $fkObject->save();
- }
-}
-
+ * @license http://www.pradosoft.com/license/
+ * @version $Id$
+ * @package System.Data.ActiveRecord.Relations
+ */
+
+/**
+ * Loads base active record relationship class.
+ */
+Prado::using('System.Data.ActiveRecord.Relations.TActiveRecordRelation');
+
+/**
+ * TActiveRecordHasOne models the object relationship that a record (the source object)
+ * property is an instance of foreign record object having a foreign key
+ * related to the source object. The HAS_ONE relation is very similar to the
+ * HAS_MANY relationship (in fact, it is equivalent in the entities relationship point of view).
+ *
+ * The difference of HAS_ONE from HAS_MANY is that the foreign object is singular.
+ * That is, HAS_MANY will return a collection of records while HAS_ONE returns the
+ * corresponding record.
+ *
+ * Consider the <b>entity</b> relationship between a Car and a Engine.
+ * <code>
+ * +-----+ +--------+
+ * | Car | 1 <----- 1 | Engine |
+ * +-----+ +--------+
+ * </code>
+ * Where each engine belongs to only one car, that is, the Engine entity has
+ * a foreign key to the Car's primary key. We may model
+ * Engine-Car <b>object</b> relationship as active record as follows.
+ * <code>
+ * class CarRecord extends TActiveRecord
+ * {
+ * const TABLE='car';
+ * public $car_id; //primary key
+ * public $colour;
+ *
+ * public $engine; //engine foreign object
+ *
+ * public static $RELATIONS=array
+ * (
+ * 'engine' => array(self::HAS_ONE, 'EngineRecord')
+ * );
+ *
+ * public static function finder($className=__CLASS__)
+ * {
+ * return parent::finder($className);
+ * }
+ * }
+ * class EngineRecord extends TActiveRecord
+ * {
+ * const TABLE='engine';
+ * public $engine_id;
+ * public $capacity;
+ * public $car_id; //foreign key to cars
+ *
+ * public static function finder($className=__CLASS__)
+ * {
+ * return parent::finder($className);
+ * }
+ * }
+ * </code>
+ * The static <tt>$RELATIONS</tt> property of CarRecord defines that the
+ * property <tt>$engine</tt> that will reference an <tt>EngineRecord</tt> instance.
+ *
+ * The car record with engine property list may be fetched as follows.
+ * <code>
+ * $cars = CarRecord::finder()->with_engine()->findAll();
+ * </code>
+ * The method <tt>with_xxx()</tt> (where <tt>xxx</tt> is the relationship property
+ * name, in this case, <tt>engine</tt>) fetchs the corresponding EngineRecords using
+ * a second query (not by using a join). The <tt>with_xxx()</tt> accepts the same
+ * arguments as other finder methods of TActiveRecord, e.g. <tt>with_engine('capacity < ?', 3.8)</tt>.
+ *
+ * @author Wei Zhuo <weizho[at]gmail[dot]com>
+ * @version $Id$
+ * @package System.Data.ActiveRecord.Relations
+ * @since 3.1
+ */
+class TActiveRecordHasOne extends TActiveRecordRelation
+{
+ /**
+ * Get the foreign key index values from the results and make calls to the
+ * database to find the corresponding foreign objects.
+ * @param array original results.
+ */
+ protected function collectForeignObjects(&$results)
+ {
+ $fkeys = $this->getRelationForeignKeys();
+ $properties = array_values($fkeys);
+ $fields = array_keys($fkeys);
+
+ $indexValues = $this->getIndexValues($properties, $results);
+ $fkObjects = $this->findForeignObjects($fields,$indexValues);
+ $this->populateResult($results,$properties,$fkObjects,$fields);
+ }
+
+ /**
+ * @return array foreign key field names as key and object properties as value.
+ * @since 3.1.2
+ */
+ public function getRelationForeignKeys()
+ {
+ $fkObject = $this->getContext()->getForeignRecordFinder();
+ return $this->findForeignKeys($fkObject, $this->getSourceRecord());
+ }
+
+ /**
+ * Sets the foreign objects to the given property on the source object.
+ * @param TActiveRecord source object.
+ * @param array foreign objects.
+ */
+ protected function setObjectProperty($source, $properties, &$collections)
+ {
+ $hash = $this->getObjectHash($source, $properties);
+ $prop = $this->getContext()->getProperty();
+ if(isset($collections[$hash]) && count($collections[$hash]) > 0)
+ {
+ if(count($collections[$hash]) > 1)
+ throw new TActiveRecordException('ar_belongs_to_multiple_result');
+ $source->setColumnValue($prop, $collections[$hash][0]);
+ }
+ }
+
+ /**
+ * Updates the associated foreign objects.
+ * @return boolean true if all update are success (including if no update was required), false otherwise .
+ */
+ public function updateAssociatedRecords()
+ {
+ $fkObject = $this->getContext()->getPropertyValue();
+ $source = $this->getSourceRecord();
+ $fkeys = $this->findForeignKeys($fkObject, $source);
+ foreach($fkeys as $fKey => $srcKey)
+ $fkObject->setColumnValue($fKey, $source->getColumnValue($srcKey));
+ return $fkObject->save();
+ }
+}
+
diff --git a/framework/Data/ActiveRecord/Relations/TActiveRecordRelation.php b/framework/Data/ActiveRecord/Relations/TActiveRecordRelation.php
index 39482635..c59532d9 100644
--- a/framework/Data/ActiveRecord/Relations/TActiveRecordRelation.php
+++ b/framework/Data/ActiveRecord/Relations/TActiveRecordRelation.php
@@ -1,254 +1,254 @@
-<?php
-/**
- * TActiveRecordRelation class file.
- *
- * @author Wei Zhuo <weizhuo[at]gmail[dot]com>
- * @link http://www.pradosoft.com/
- * @copyright Copyright &copy; 2005-2012 PradoSoft
- * @license http://www.pradosoft.com/license/
- * @version $Id$
- * @package System.Data.ActiveRecord.Relations
- */
-
-/**
- * Load active record relationship context.
- */
-Prado::using('System.Data.ActiveRecord.Relations.TActiveRecordRelationContext');
-
-/**
- * Base class for active record relationships.
- *
- * @author Wei Zhuo <weizho[at]gmail[dot]com>
- * @version $Id$
- * @package System.Data.ActiveRecord.Relations
- * @since 3.1
- */
-abstract class TActiveRecordRelation
-{
- private $_context;
- private $_criteria;
-
- public function __construct(TActiveRecordRelationContext $context, $criteria)
- {
- $this->_context = $context;
- $this->_criteria = $criteria;
- }
-
- /**
- * @return TActiveRecordRelationContext
- */
- protected function getContext()
- {
- return $this->_context;
- }
-
- /**
- * @return TActiveRecordCriteria
- */
- protected function getCriteria()
- {
- return $this->_criteria;
- }
-
- /**
- * @return TActiveRecord
- */
- protected function getSourceRecord()
- {
- return $this->getContext()->getSourceRecord();
- }
-
- abstract protected function collectForeignObjects(&$results);
-
- /**
- * Dispatch the method calls to the source record finder object. When
- * an instance of TActiveRecord or an array of TActiveRecord is returned
- * the corresponding foreign objects are also fetched and assigned.
- *
- * Multiple relationship calls can be chain together.
- *
- * @param string method name called
- * @param array method arguments
- * @return mixed TActiveRecord or array of TActiveRecord results depending on the method called.
- */
- public function __call($method,$args)
- {
- static $stack=array();
-
- $results = call_user_func_array(array($this->getSourceRecord(),$method),$args);
- $validArray = is_array($results) && count($results) > 0;
- if($validArray || $results instanceof ArrayAccess || $results instanceof TActiveRecord)
- {
- $this->collectForeignObjects($results);
- while($obj = array_pop($stack))
- $obj->collectForeignObjects($results);
- }
- else if($results instanceof TActiveRecordRelation)
- $stack[] = $this; //call it later
- else if($results === null || !$validArray)
- $stack = array();
- return $results;
- }
-
- /**
- * Fetch results for current relationship.
- * @return boolean always true.
- */
- public function fetchResultsInto($obj)
- {
- $this->collectForeignObjects($obj);
- return true;
- }
-
- /**
- * Returns foreign keys in $fromRecord with source column names as key
- * and foreign column names in the corresponding $matchesRecord as value.
- * The method returns the first matching foreign key between these 2 records.
- * @param TActiveRecord $fromRecord
- * @param TActiveRecord $matchesRecord
- * @return array foreign keys with source column names as key and foreign column names as value.
- */
- protected function findForeignKeys($from, $matchesRecord, $loose=false)
- {
- $gateway = $matchesRecord->getRecordGateway();
- $recordTableInfo = $gateway->getRecordTableInfo($matchesRecord);
- $matchingTableName = strtolower($recordTableInfo->getTableName());
- $matchingFullTableName = strtolower($recordTableInfo->getTableFullName());
- $tableInfo=$from;
- if($from instanceof TActiveRecord)
- $tableInfo = $gateway->getRecordTableInfo($from);
- //find first non-empty FK
- foreach($tableInfo->getForeignKeys() as $fkeys)
- {
- $fkTable = strtolower($fkeys['table']);
- if($fkTable===$matchingTableName || $fkTable===$matchingFullTableName)
- {
- $hasFkField = !$loose && $this->getContext()->hasFkField();
- $key = $hasFkField ? $this->getFkFields($fkeys['keys']) : $fkeys['keys'];
- if(!empty($key))
- return $key;
- }
- }
-
- //none found
- $matching = $gateway->getRecordTableInfo($matchesRecord)->getTableFullName();
- throw new TActiveRecordException('ar_relations_missing_fk',
- $tableInfo->getTableFullName(), $matching);
- }
-
- /**
- * @return array foreign key field names as key and object properties as value.
- * @since 3.1.2
- */
- abstract public function getRelationForeignKeys();
-
- /**
- * Find matching foreign key fields from the 3rd element of an entry in TActiveRecord::$RELATION.
- * Assume field names consist of [\w-] character sets. Prefix to the field names ending with a dot
- * are ignored.
- */
- private function getFkFields($fkeys)
- {
- $matching = array();
- preg_match_all('/\s*(\S+\.)?([\w-]+)\s*/', $this->getContext()->getFkField(), $matching);
- $fields = array();
- foreach($fkeys as $fkName => $field)
- {
- if(in_array($fkName, $matching[2]))
- $fields[$fkName] = $field;
- }
- return $fields;
- }
-
- /**
- * @param mixed object or array to be hashed
- * @param array name of property for hashing the properties.
- * @return string object hash using crc32 and serialize.
- */
- protected function getObjectHash($obj, $properties)
- {
- $ids=array();
- foreach($properties as $property)
- $ids[] = is_object($obj) ? (string)$obj->getColumnValue($property) : (string)$obj[$property];
- return serialize($ids);
- }
-
- /**
- * Fetches the foreign objects using TActiveRecord::findAllByIndex()
- * @param array field names
- * @param array foreign key index values.
- * @return TActiveRecord[] foreign objects.
- */
- protected function findForeignObjects($fields, $indexValues)
- {
- $finder = $this->getContext()->getForeignRecordFinder();
- return $finder->findAllByIndex($this->_criteria, $fields, $indexValues);
- }
-
- /**
- * Obtain the foreign key index values from the results.
- * @param array property names
- * @param array TActiveRecord results
- * @return array foreign key index values.
- */
- protected function getIndexValues($keys, $results)
- {
- if(!is_array($results) && !$results instanceof ArrayAccess)
- $results = array($results);
- $values=array();
- foreach($results as $result)
- {
- $value = array();
- foreach($keys as $name)
- $value[] = $result->getColumnValue($name);
- $values[] = $value;
- }
- return $values;
- }
-
- /**
- * Populate the results with the foreign objects found.
- * @param array source results
- * @param array source property names
- * @param array foreign objects
- * @param array foreign object field names.
- */
- protected function populateResult(&$results,$properties,&$fkObjects,$fields)
- {
- $collections=array();
- foreach($fkObjects as $fkObject)
- $collections[$this->getObjectHash($fkObject, $fields)][]=$fkObject;
- $this->setResultCollection($results, $collections, $properties);
- }
-
- /**
- * Populates the result array with foreign objects (matched using foreign key hashed property values).
- * @param array $results
- * @param array $collections
- * @param array property names
- */
- protected function setResultCollection(&$results, &$collections, $properties)
- {
- if(is_array($results) || $results instanceof ArrayAccess)
- {
- for($i=0,$k=count($results);$i<$k;$i++)
- $this->setObjectProperty($results[$i], $properties, $collections);
- }
- else
- $this->setObjectProperty($results, $properties, $collections);
- }
-
- /**
- * Sets the foreign objects to the given property on the source object.
- * @param TActiveRecord source object.
- * @param array source properties
- * @param array foreign objects.
- */
- protected function setObjectProperty($source, $properties, &$collections)
- {
- $hash = $this->getObjectHash($source, $properties);
- $prop = $this->getContext()->getProperty();
- $source->$prop=isset($collections[$hash]) ? $collections[$hash] : array();
- }
-}
-
+<?php
+/**
+ * TActiveRecordRelation class file.
+ *
+ * @author Wei Zhuo <weizhuo[at]gmail[dot]com>
+ * @link http://www.pradosoft.com/
+ * @copyright Copyright &copy; 2005-2012 PradoSoft
+ * @license http://www.pradosoft.com/license/
+ * @version $Id$
+ * @package System.Data.ActiveRecord.Relations
+ */
+
+/**
+ * Load active record relationship context.
+ */
+Prado::using('System.Data.ActiveRecord.Relations.TActiveRecordRelationContext');
+
+/**
+ * Base class for active record relationships.
+ *
+ * @author Wei Zhuo <weizho[at]gmail[dot]com>
+ * @version $Id$
+ * @package System.Data.ActiveRecord.Relations
+ * @since 3.1
+ */
+abstract class TActiveRecordRelation
+{
+ private $_context;
+ private $_criteria;
+
+ public function __construct(TActiveRecordRelationContext $context, $criteria)
+ {
+ $this->_context = $context;
+ $this->_criteria = $criteria;
+ }
+
+ /**
+ * @return TActiveRecordRelationContext
+ */
+ protected function getContext()
+ {
+ return $this->_context;
+ }
+
+ /**
+ * @return TActiveRecordCriteria
+ */
+ protected function getCriteria()
+ {
+ return $this->_criteria;
+ }
+
+ /**
+ * @return TActiveRecord
+ */
+ protected function getSourceRecord()
+ {
+ return $this->getContext()->getSourceRecord();
+ }
+
+ abstract protected function collectForeignObjects(&$results);
+
+ /**
+ * Dispatch the method calls to the source record finder object. When
+ * an instance of TActiveRecord or an array of TActiveRecord is returned
+ * the corresponding foreign objects are also fetched and assigned.
+ *
+ * Multiple relationship calls can be chain together.
+ *
+ * @param string method name called
+ * @param array method arguments
+ * @return mixed TActiveRecord or array of TActiveRecord results depending on the method called.
+ */
+ public function __call($method,$args)
+ {
+ static $stack=array();
+
+ $results = call_user_func_array(array($this->getSourceRecord(),$method),$args);
+ $validArray = is_array($results) && count($results) > 0;
+ if($validArray || $results instanceof ArrayAccess || $results instanceof TActiveRecord)
+ {
+ $this->collectForeignObjects($results);
+ while($obj = array_pop($stack))
+ $obj->collectForeignObjects($results);
+ }
+ else if($results instanceof TActiveRecordRelation)
+ $stack[] = $this; //call it later
+ else if($results === null || !$validArray)
+ $stack = array();
+ return $results;
+ }
+
+ /**
+ * Fetch results for current relationship.
+ * @return boolean always true.
+ */
+ public function fetchResultsInto($obj)
+ {
+ $this->collectForeignObjects($obj);
+ return true;
+ }
+
+ /**
+ * Returns foreign keys in $fromRecord with source column names as key
+ * and foreign column names in the corresponding $matchesRecord as value.
+ * The method returns the first matching foreign key between these 2 records.
+ * @param TActiveRecord $fromRecord
+ * @param TActiveRecord $matchesRecord
+ * @return array foreign keys with source column names as key and foreign column names as value.
+ */
+ protected function findForeignKeys($from, $matchesRecord, $loose=false)
+ {
+ $gateway = $matchesRecord->getRecordGateway();
+ $recordTableInfo = $gateway->getRecordTableInfo($matchesRecord);
+ $matchingTableName = strtolower($recordTableInfo->getTableName());
+ $matchingFullTableName = strtolower($recordTableInfo->getTableFullName());
+ $tableInfo=$from;
+ if($from instanceof TActiveRecord)
+ $tableInfo = $gateway->getRecordTableInfo($from);
+ //find first non-empty FK
+ foreach($tableInfo->getForeignKeys() as $fkeys)
+ {
+ $fkTable = strtolower($fkeys['table']);
+ if($fkTable===$matchingTableName || $fkTable===$matchingFullTableName)
+ {
+ $hasFkField = !$loose && $this->getContext()->hasFkField();
+ $key = $hasFkField ? $this->getFkFields($fkeys['keys']) : $fkeys['keys'];
+ if(!empty($key))
+ return $key;
+ }
+ }
+
+ //none found
+ $matching = $gateway->getRecordTableInfo($matchesRecord)->getTableFullName();
+ throw new TActiveRecordException('ar_relations_missing_fk',
+ $tableInfo->getTableFullName(), $matching);
+ }
+
+ /**
+ * @return array foreign key field names as key and object properties as value.
+ * @since 3.1.2
+ */
+ abstract public function getRelationForeignKeys();
+
+ /**
+ * Find matching foreign key fields from the 3rd element of an entry in TActiveRecord::$RELATION.
+ * Assume field names consist of [\w-] character sets. Prefix to the field names ending with a dot
+ * are ignored.
+ */
+ private function getFkFields($fkeys)
+ {
+ $matching = array();
+ preg_match_all('/\s*(\S+\.)?([\w-]+)\s*/', $this->getContext()->getFkField(), $matching);
+ $fields = array();
+ foreach($fkeys as $fkName => $field)
+ {
+ if(in_array($fkName, $matching[2]))
+ $fields[$fkName] = $field;
+ }
+ return $fields;
+ }
+
+ /**
+ * @param mixed object or array to be hashed
+ * @param array name of property for hashing the properties.
+ * @return string object hash using crc32 and serialize.
+ */
+ protected function getObjectHash($obj, $properties)
+ {
+ $ids=array();
+ foreach($properties as $property)
+ $ids[] = is_object($obj) ? (string)$obj->getColumnValue($property) : (string)$obj[$property];
+ return serialize($ids);
+ }
+
+ /**
+ * Fetches the foreign objects using TActiveRecord::findAllByIndex()
+ * @param array field names
+ * @param array foreign key index values.
+ * @return TActiveRecord[] foreign objects.
+ */
+ protected function findForeignObjects($fields, $indexValues)
+ {
+ $finder = $this->getContext()->getForeignRecordFinder();
+ return $finder->findAllByIndex($this->_criteria, $fields, $indexValues);
+ }
+
+ /**
+ * Obtain the foreign key index values from the results.
+ * @param array property names
+ * @param array TActiveRecord results
+ * @return array foreign key index values.
+ */
+ protected function getIndexValues($keys, $results)
+ {
+ if(!is_array($results) && !$results instanceof ArrayAccess)
+ $results = array($results);
+ $values=array();
+ foreach($results as $result)
+ {
+ $value = array();
+ foreach($keys as $name)
+ $value[] = $result->getColumnValue($name);
+ $values[] = $value;
+ }
+ return $values;
+ }
+
+ /**
+ * Populate the results with the foreign objects found.
+ * @param array source results
+ * @param array source property names
+ * @param array foreign objects
+ * @param array foreign object field names.
+ */
+ protected function populateResult(&$results,$properties,&$fkObjects,$fields)
+ {
+ $collections=array();
+ foreach($fkObjects as $fkObject)
+ $collections[$this->getObjectHash($fkObject, $fields)][]=$fkObject;
+ $this->setResultCollection($results, $collections, $properties);
+ }
+
+ /**
+ * Populates the result array with foreign objects (matched using foreign key hashed property values).
+ * @param array $results
+ * @param array $collections
+ * @param array property names
+ */
+ protected function setResultCollection(&$results, &$collections, $properties)
+ {
+ if(is_array($results) || $results instanceof ArrayAccess)
+ {
+ for($i=0,$k=count($results);$i<$k;$i++)
+ $this->setObjectProperty($results[$i], $properties, $collections);
+ }
+ else
+ $this->setObjectProperty($results, $properties, $collections);
+ }
+
+ /**
+ * Sets the foreign objects to the given property on the source object.
+ * @param TActiveRecord source object.
+ * @param array source properties
+ * @param array foreign objects.
+ */
+ protected function setObjectProperty($source, $properties, &$collections)
+ {
+ $hash = $this->getObjectHash($source, $properties);
+ $prop = $this->getContext()->getProperty();
+ $source->$prop=isset($collections[$hash]) ? $collections[$hash] : array();
+ }
+}
+
diff --git a/framework/Data/ActiveRecord/Relations/TActiveRecordRelationContext.php b/framework/Data/ActiveRecord/Relations/TActiveRecordRelationContext.php
index 8826bb69..dbcc097b 100644
--- a/framework/Data/ActiveRecord/Relations/TActiveRecordRelationContext.php
+++ b/framework/Data/ActiveRecord/Relations/TActiveRecordRelationContext.php
@@ -1,230 +1,230 @@
-<?php
-/**
- * TActiveRecordRelationContext class.
- *
- * @author Wei Zhuo <weizhuo[at]gmail[dot]com>
- * @link http://www.pradosoft.com/
+<?php
+/**
+ * TActiveRecordRelationContext class.
+ *
+ * @author Wei Zhuo <weizhuo[at]gmail[dot]com>
+ * @link http://www.pradosoft.com/
* @copyright Copyright &copy; 2005-2012 PradoSoft
- * @license http://www.pradosoft.com/license/
- * @version $Id$
- * @package System.Data.ActiveRecord.Relations
- */
-
-/**
- * TActiveRecordRelationContext holds information regarding record relationships
- * such as record relation property name, query criteria and foreign object record
- * class names.
- *
- * This class is use internally by passing a context to the TActiveRecordRelation
- * constructor.
- *
- * @author Wei Zhuo <weizho[at]gmail[dot]com>
- * @version $Id$
- * @package System.Data.ActiveRecord.Relations
- * @since 3.1
- */
-class TActiveRecordRelationContext
-{
- private $_property;
- private $_record;
- private $_relation; //data from an entry of TActiveRecord::$RELATION
- private $_fkeys;
-
- public function __construct($record, $property=null, $relation=null)
- {
- $this->_record=$record;
- $this->_property=$property;
- $this->_relation=$relation;
- }
-
- /**
- * @return boolean true if the relation is defined in TActiveRecord::$RELATIONS
- * @since 3.1.2
- */
- public function hasRecordRelation()
- {
- return $this->_relation!==null;
- }
-
- public function getPropertyValue()
- {
- $obj = $this->getSourceRecord();
- return $obj->getColumnValue($this->getProperty());
- }
-
- /**
- * @return string name of the record property that the relationship results will be assigned to.
- */
- public function getProperty()
- {
- return $this->_property;
- }
-
- /**
- * @return TActiveRecord the active record instance that queried for its related records.
- */
- public function getSourceRecord()
- {
- return $this->_record;
- }
-
- /**
- * @return array foreign key of this relations, the keys is dependent on the
- * relationship type.
- * @since 3.1.2
- */
- public function getRelationForeignKeys()
- {
- if($this->_fkeys===null)
- $this->_fkeys=$this->getRelationHandler()->getRelationForeignKeys();
- return $this->_fkeys;
- }
-
- /**
- * @return string HAS_MANY, HAS_ONE, or BELONGS_TO
- */
- public function getRelationType()
- {
- return $this->_relation[0];
- }
-
- /**
- * @return string foreign record class name.
- */
- public function getForeignRecordClass()
- {
- return $this->_relation[1];
- }
-
- /**
- * @return string foreign key field names, comma delimited.
- * @since 3.1.2
- */
- public function getFkField()
- {
- return $this->_relation[2];
- }
-
- /**
- * @return string the query condition for the relation as specified in RELATIONS
- * @since 3.1.2
- */
- public function getCondition()
- {
- return isset($this->_relation[3])?$this->_relation[3]:null;
- }
-
- /**
- * @return array the query parameters for the relation as specified in RELATIONS
- * @since 3.1.2
- */
- public function getParameters()
- {
- return isset($this->_relation[4])?$this->_relation[4]:array();
- }
-
- /**
- * @return boolean true if the 3rd element of an TActiveRecord::$RELATION entry is set.
- * @since 3.1.2
- */
- public function hasFkField()
- {
- $notManyToMany = $this->getRelationType() !== TActiveRecord::MANY_TO_MANY;
- return $notManyToMany && isset($this->_relation[2]) && !empty($this->_relation[2]);
- }
-
- /**
- * @return string the M-N relationship association table name.
- */
- public function getAssociationTable()
- {
- return $this->_relation[2];
- }
-
- /**
- * @return boolean true if the relationship is HAS_MANY and requires an association table.
- */
- public function hasAssociationTable()
- {
- $isManyToMany = $this->getRelationType() === TActiveRecord::MANY_TO_MANY;
- return $isManyToMany && isset($this->_relation[2]) && !empty($this->_relation[2]);
- }
-
- /**
- * @return TActiveRecord corresponding relationship foreign object finder instance.
- */
- public function getForeignRecordFinder()
- {
- return TActiveRecord::finder($this->getForeignRecordClass());
- }
-
- /**
- * Creates and return the TActiveRecordRelation handler for specific relationships.
- * An instance of TActiveRecordHasOne, TActiveRecordBelongsTo, TActiveRecordHasMany,
- * or TActiveRecordHasManyAssocation will be returned.
- * @param TActiveRecordCriteria search criteria
- * @return TActiveRecordRelation record relationship handler instnace.
- * @throws TActiveRecordException if property is not defined or missing.
- */
- public function getRelationHandler($criteria=null)
- {
- if(!$this->hasRecordRelation())
- {
- throw new TActiveRecordException('ar_undefined_relation_prop',
- $this->_property, get_class($this->_record), 'RELATIONS');
- }
- if($criteria===null)
- $criteria = new TActiveRecordCriteria($this->getCondition(), $this->getParameters());
- switch($this->getRelationType())
- {
- case TActiveRecord::HAS_MANY:
- Prado::using('System.Data.ActiveRecord.Relations.TActiveRecordHasMany');
- return new TActiveRecordHasMany($this, $criteria);
- case TActiveRecord::MANY_TO_MANY:
- Prado::using('System.Data.ActiveRecord.Relations.TActiveRecordHasManyAssociation');
- return new TActiveRecordHasManyAssociation($this, $criteria);
- case TActiveRecord::HAS_ONE:
- Prado::using('System.Data.ActiveRecord.Relations.TActiveRecordHasOne');
- return new TActiveRecordHasOne($this, $criteria);
- case TActiveRecord::BELONGS_TO:
- Prado::using('System.Data.ActiveRecord.Relations.TActiveRecordBelongsTo');
- return new TActiveRecordBelongsTo($this, $criteria);
- default:
- throw new TActiveRecordException('ar_invalid_relationship');
- }
- }
-
- /**
- * @return TActiveRecordRelationCommand
- */
- public function updateAssociatedRecords($updateBelongsTo=false)
- {
- $success=true;
- foreach($this->_record->getRecordRelations() as $data)
- {
- list($property, $relation) = $data;
- $belongsTo = $relation[0]==TActiveRecord::BELONGS_TO;
- if(($updateBelongsTo && $belongsTo) || (!$updateBelongsTo && !$belongsTo))
- {
- $obj = $this->getSourceRecord();
- if(!$this->isEmptyFkObject($obj->getColumnValue($property)))
- {
- $context = new TActiveRecordRelationContext($this->getSourceRecord(),$property,$relation);
- $success = $context->getRelationHandler()->updateAssociatedRecords() && $success;
- }
- }
- }
- return $success;
- }
-
- protected function isEmptyFkObject($obj)
- {
- if(is_object($obj))
- return $obj instanceof TList ? $obj->count() === 0 : false;
- else if(is_array($obj))
- return count($obj)===0;
- else
- return empty($obj);
- }
-}
-
+ * @license http://www.pradosoft.com/license/
+ * @version $Id$
+ * @package System.Data.ActiveRecord.Relations
+ */
+
+/**
+ * TActiveRecordRelationContext holds information regarding record relationships
+ * such as record relation property name, query criteria and foreign object record
+ * class names.
+ *
+ * This class is use internally by passing a context to the TActiveRecordRelation
+ * constructor.
+ *
+ * @author Wei Zhuo <weizho[at]gmail[dot]com>
+ * @version $Id$
+ * @package System.Data.ActiveRecord.Relations
+ * @since 3.1
+ */
+class TActiveRecordRelationContext
+{
+ private $_property;
+ private $_record;
+ private $_relation; //data from an entry of TActiveRecord::$RELATION
+ private $_fkeys;
+
+ public function __construct($record, $property=null, $relation=null)
+ {
+ $this->_record=$record;
+ $this->_property=$property;
+ $this->_relation=$relation;
+ }
+
+ /**
+ * @return boolean true if the relation is defined in TActiveRecord::$RELATIONS
+ * @since 3.1.2
+ */
+ public function hasRecordRelation()
+ {
+ return $this->_relation!==null;
+ }
+
+ public function getPropertyValue()
+ {
+ $obj = $this->getSourceRecord();
+ return $obj->getColumnValue($this->getProperty());
+ }
+
+ /**
+ * @return string name of the record property that the relationship results will be assigned to.
+ */
+ public function getProperty()
+ {
+ return $this->_property;
+ }
+
+ /**
+ * @return TActiveRecord the active record instance that queried for its related records.
+ */
+ public function getSourceRecord()
+ {
+ return $this->_record;
+ }
+
+ /**
+ * @return array foreign key of this relations, the keys is dependent on the
+ * relationship type.
+ * @since 3.1.2
+ */
+ public function getRelationForeignKeys()
+ {
+ if($this->_fkeys===null)
+ $this->_fkeys=$this->getRelationHandler()->getRelationForeignKeys();
+ return $this->_fkeys;
+ }
+
+ /**
+ * @return string HAS_MANY, HAS_ONE, or BELONGS_TO
+ */
+ public function getRelationType()
+ {
+ return $this->_relation[0];
+ }
+
+ /**
+ * @return string foreign record class name.
+ */
+ public function getForeignRecordClass()
+ {
+ return $this->_relation[1];
+ }
+
+ /**
+ * @return string foreign key field names, comma delimited.
+ * @since 3.1.2
+ */
+ public function getFkField()
+ {
+ return $this->_relation[2];
+ }
+
+ /**
+ * @return string the query condition for the relation as specified in RELATIONS
+ * @since 3.1.2
+ */
+ public function getCondition()
+ {
+ return isset($this->_relation[3])?$this->_relation[3]:null;
+ }
+
+ /**
+ * @return array the query parameters for the relation as specified in RELATIONS
+ * @since 3.1.2
+ */
+ public function getParameters()
+ {
+ return isset($this->_relation[4])?$this->_relation[4]:array();
+ }
+
+ /**
+ * @return boolean true if the 3rd element of an TActiveRecord::$RELATION entry is set.
+ * @since 3.1.2
+ */
+ public function hasFkField()
+ {
+ $notManyToMany = $this->getRelationType() !== TActiveRecord::MANY_TO_MANY;
+ return $notManyToMany && isset($this->_relation[2]) && !empty($this->_relation[2]);
+ }
+
+ /**
+ * @return string the M-N relationship association table name.
+ */
+ public function getAssociationTable()
+ {
+ return $this->_relation[2];
+ }
+
+ /**
+ * @return boolean true if the relationship is HAS_MANY and requires an association table.
+ */
+ public function hasAssociationTable()
+ {
+ $isManyToMany = $this->getRelationType() === TActiveRecord::MANY_TO_MANY;
+ return $isManyToMany && isset($this->_relation[2]) && !empty($this->_relation[2]);
+ }
+
+ /**
+ * @return TActiveRecord corresponding relationship foreign object finder instance.
+ */
+ public function getForeignRecordFinder()
+ {
+ return TActiveRecord::finder($this->getForeignRecordClass());
+ }
+
+ /**
+ * Creates and return the TActiveRecordRelation handler for specific relationships.
+ * An instance of TActiveRecordHasOne, TActiveRecordBelongsTo, TActiveRecordHasMany,
+ * or TActiveRecordHasManyAssocation will be returned.
+ * @param TActiveRecordCriteria search criteria
+ * @return TActiveRecordRelation record relationship handler instnace.
+ * @throws TActiveRecordException if property is not defined or missing.
+ */
+ public function getRelationHandler($criteria=null)
+ {
+ if(!$this->hasRecordRelation())
+ {
+ throw new TActiveRecordException('ar_undefined_relation_prop',
+ $this->_property, get_class($this->_record), 'RELATIONS');
+ }
+ if($criteria===null)
+ $criteria = new TActiveRecordCriteria($this->getCondition(), $this->getParameters());
+ switch($this->getRelationType())
+ {
+ case TActiveRecord::HAS_MANY:
+ Prado::using('System.Data.ActiveRecord.Relations.TActiveRecordHasMany');
+ return new TActiveRecordHasMany($this, $criteria);
+ case TActiveRecord::MANY_TO_MANY:
+ Prado::using('System.Data.ActiveRecord.Relations.TActiveRecordHasManyAssociation');
+ return new TActiveRecordHasManyAssociation($this, $criteria);
+ case TActiveRecord::HAS_ONE:
+ Prado::using('System.Data.ActiveRecord.Relations.TActiveRecordHasOne');
+ return new TActiveRecordHasOne($this, $criteria);
+ case TActiveRecord::BELONGS_TO:
+ Prado::using('System.Data.ActiveRecord.Relations.TActiveRecordBelongsTo');
+ return new TActiveRecordBelongsTo($this, $criteria);
+ default:
+ throw new TActiveRecordException('ar_invalid_relationship');
+ }
+ }
+
+ /**
+ * @return TActiveRecordRelationCommand
+ */
+ public function updateAssociatedRecords($updateBelongsTo=false)
+ {
+ $success=true;
+ foreach($this->_record->getRecordRelations() as $data)
+ {
+ list($property, $relation) = $data;
+ $belongsTo = $relation[0]==TActiveRecord::BELONGS_TO;
+ if(($updateBelongsTo && $belongsTo) || (!$updateBelongsTo && !$belongsTo))
+ {
+ $obj = $this->getSourceRecord();
+ if(!$this->isEmptyFkObject($obj->getColumnValue($property)))
+ {
+ $context = new TActiveRecordRelationContext($this->getSourceRecord(),$property,$relation);
+ $success = $context->getRelationHandler()->updateAssociatedRecords() && $success;
+ }
+ }
+ }
+ return $success;
+ }
+
+ protected function isEmptyFkObject($obj)
+ {
+ if(is_object($obj))
+ return $obj instanceof TList ? $obj->count() === 0 : false;
+ else if(is_array($obj))
+ return count($obj)===0;
+ else
+ return empty($obj);
+ }
+}
+
diff --git a/framework/Data/ActiveRecord/Scaffold/TScaffoldBase.php b/framework/Data/ActiveRecord/Scaffold/TScaffoldBase.php
index d2e58bc3..68f5806a 100644
--- a/framework/Data/ActiveRecord/Scaffold/TScaffoldBase.php
+++ b/framework/Data/ActiveRecord/Scaffold/TScaffoldBase.php
@@ -1,207 +1,207 @@
-<?php
-/**
- * TScaffoldBase class file.
- *
- * @author Wei Zhuo <weizhuo[at]gmail[dot]com>
- * @link http://www.pradosoft.com/
- * @copyright Copyright &copy; 2005-2012 PradoSoft
- * @license http://www.pradosoft.com/license/
- * @version $Id$
- * @package System.Data.ActiveRecord.Scaffold
- */
-
-/**
- * Include the base Active Record class.
- */
-Prado::using('System.Data.ActiveRecord.TActiveRecord');
-
-/**
- * Base class for Active Record scaffold views.
- *
- * Provides common properties for all scaffold views (such as, TScaffoldListView,
- * TScaffoldEditView, TScaffoldListView and TScaffoldView).
- *
- * During the OnPrRender stage the default css style file (filename style.css)
- * is published and registered. To override the default style, provide your own stylesheet
- * file explicitly.
- *
- * @author Wei Zhuo <weizho[at]gmail[dot]com>
- * @version $Id$
- * @package System.Data.ActiveRecord.Scaffold
- * @since 3.1
- */
-abstract class TScaffoldBase extends TTemplateControl
-{
- /**
- * @var TActiveRecord record instance (may be new or retrieved from db)
- */
- private $_record;
-
- /**
- * @return TDbMetaData table/view information
- */
- protected function getTableInfo()
- {
- $finder = $this->getRecordFinder();
- $gateway = $finder->getRecordManager()->getRecordGateWay();
- return $gateway->getRecordTableInfo($finder);
- }
-
- /**
- * @param TActiveRecord record instance
- * @return array record property values
- */
- protected function getRecordPropertyValues($record)
- {
- $data = array();
- foreach($this->getTableInfo()->getColumns() as $name=>$column)
- $data[] = $record->getColumnValue($name);
- return $data;
- }
-
- /**
- * @param TActiveRecord record instance
- * @return array record primary key values.
- */
- protected function getRecordPkValues($record)
- {
- $data=array();
- foreach($this->getTableInfo()->getColumns() as $name=>$column)
- {
- if($column->getIsPrimaryKey())
- $data[] = $record->getColumnValue($name);
- }
- return $data;
- }
-
- /**
- * Name of the Active Record class to be viewed or scaffolded.
- * @return string Active Record class name.
- */
- public function getRecordClass()
- {
- return $this->getViewState('RecordClass');
- }
-
- /**
- * Name of the Active Record class to be viewed or scaffolded.
- * @param string Active Record class name.
- */
- public function setRecordClass($value)
- {
- $this->setViewState('RecordClass', $value);
- }
-
- /**
- * Copy the view details from another scaffold view instance.
- * @param TScaffoldBase scaffold view.
- */
- protected function copyFrom(TScaffoldBase $obj)
- {
- $this->_record = $obj->_record;
- $this->setRecordClass($obj->getRecordClass());
- $this->setEnableDefaultStyle($obj->getEnableDefaultStyle());
- }
-
- /**
- * Unset the current record instance and table information.
- */
- protected function clearRecordObject()
- {
- $this->_record=null;
- }
-
- /**
- * Gets the current Active Record instance. Creates new instance if the
- * primary key value is null otherwise the record is fetched from the db.
- * @param array primary key value
- * @return TActiveRecord record instance
- */
- protected function getRecordObject($pk=null)
- {
- if($this->_record===null)
- {
- if($pk!==null)
- {
- $this->_record=$this->getRecordFinder()->findByPk($pk);
- if($this->_record===null)
- throw new TConfigurationException('scaffold_invalid_record_pk',
- $this->getRecordClass(), $pk);
- }
- else
- {
- $class = $this->getRecordClass();
- if($class!==null)
- $this->_record=Prado::createComponent($class);
- else
- {
- throw new TConfigurationException('scaffold_invalid_record_class',
- $this->getRecordClass(),$this->getID());
- }
- }
- }
- return $this->_record;
- }
-
- /**
- * @param TActiveRecord Active Record instance.
- */
- protected function setRecordObject(TActiveRecord $value)
- {
- $this->_record=$value;
- }
-
- /**
- * @return TActiveRecord Active Record finder instance
- */
- protected function getRecordFinder()
- {
- return TActiveRecord::finder($this->getRecordClass());
- }
-
- /**
- * @return string default scaffold stylesheet name
- */
- public function getDefaultStyle()
- {
- return $this->getViewState('DefaultStyle', 'style');
- }
-
- /**
- * @param string default scaffold stylesheet name
- */
- public function setDefaultStyle($value)
- {
- $this->setViewState('DefaultStyle', TPropertyValue::ensureString($value), 'style');
- }
-
- /**
- * @return boolean enable default stylesheet, default is true.
- */
- public function getEnableDefaultStyle()
- {
- return $this->getViewState('EnableDefaultStyle', true);
- }
-
- /**
- * @param boolean enable default stylesheet, default is true.
- */
- public function setEnableDefaultStyle($value)
- {
- return $this->setViewState('EnableDefaultStyle', TPropertyValue::ensureBoolean($value), true);
- }
-
- /**
- * Publish the default stylesheet file.
- */
- public function onPreRender($param)
- {
- parent::onPreRender($param);
- if($this->getEnableDefaultStyle())
- {
- $url = $this->publishAsset($this->getDefaultStyle().'.css');
- $this->getPage()->getClientScript()->registerStyleSheetFile($url,$url);
- }
- }
-}
-
+<?php
+/**
+ * TScaffoldBase class file.
+ *
+ * @author Wei Zhuo <weizhuo[at]gmail[dot]com>
+ * @link http://www.pradosoft.com/
+ * @copyright Copyright &copy; 2005-2012 PradoSoft
+ * @license http://www.pradosoft.com/license/
+ * @version $Id$
+ * @package System.Data.ActiveRecord.Scaffold
+ */
+
+/**
+ * Include the base Active Record class.
+ */
+Prado::using('System.Data.ActiveRecord.TActiveRecord');
+
+/**
+ * Base class for Active Record scaffold views.
+ *
+ * Provides common properties for all scaffold views (such as, TScaffoldListView,
+ * TScaffoldEditView, TScaffoldListView and TScaffoldView).
+ *
+ * During the OnPrRender stage the default css style file (filename style.css)
+ * is published and registered. To override the default style, provide your own stylesheet
+ * file explicitly.
+ *
+ * @author Wei Zhuo <weizho[at]gmail[dot]com>
+ * @version $Id$
+ * @package System.Data.ActiveRecord.Scaffold
+ * @since 3.1
+ */
+abstract class TScaffoldBase extends TTemplateControl
+{
+ /**
+ * @var TActiveRecord record instance (may be new or retrieved from db)
+ */
+ private $_record;
+
+ /**
+ * @return TDbMetaData table/view information
+ */
+ protected function getTableInfo()
+ {
+ $finder = $this->getRecordFinder();
+ $gateway = $finder->getRecordManager()->getRecordGateWay();
+ return $gateway->getRecordTableInfo($finder);
+ }
+
+ /**
+ * @param TActiveRecord record instance
+ * @return array record property values
+ */
+ protected function getRecordPropertyValues($record)
+ {
+ $data = array();
+ foreach($this->getTableInfo()->getColumns() as $name=>$column)
+ $data[] = $record->getColumnValue($name);
+ return $data;
+ }
+
+ /**
+ * @param TActiveRecord record instance
+ * @return array record primary key values.
+ */
+ protected function getRecordPkValues($record)
+ {
+ $data=array();
+ foreach($this->getTableInfo()->getColumns() as $name=>$column)
+ {
+ if($column->getIsPrimaryKey())
+ $data[] = $record->getColumnValue($name);
+ }
+ return $data;
+ }
+
+ /**
+ * Name of the Active Record class to be viewed or scaffolded.
+ * @return string Active Record class name.
+ */
+ public function getRecordClass()
+ {
+ return $this->getViewState('RecordClass');
+ }
+
+ /**
+ * Name of the Active Record class to be viewed or scaffolded.
+ * @param string Active Record class name.
+ */
+ public function setRecordClass($value)
+ {
+ $this->setViewState('RecordClass', $value);
+ }
+
+ /**
+ * Copy the view details from another scaffold view instance.
+ * @param TScaffoldBase scaffold view.
+ */
+ protected function copyFrom(TScaffoldBase $obj)
+ {
+ $this->_record = $obj->_record;
+ $this->setRecordClass($obj->getRecordClass());
+ $this->setEnableDefaultStyle($obj->getEnableDefaultStyle());
+ }
+
+ /**
+ * Unset the current record instance and table information.
+ */
+ protected function clearRecordObject()
+ {
+ $this->_record=null;
+ }
+
+ /**
+ * Gets the current Active Record instance. Creates new instance if the
+ * primary key value is null otherwise the record is fetched from the db.
+ * @param array primary key value
+ * @return TActiveRecord record instance
+ */
+ protected function getRecordObject($pk=null)
+ {
+ if($this->_record===null)
+ {
+ if($pk!==null)
+ {
+ $this->_record=$this->getRecordFinder()->findByPk($pk);
+ if($this->_record===null)
+ throw new TConfigurationException('scaffold_invalid_record_pk',
+ $this->getRecordClass(), $pk);
+ }
+ else
+ {
+ $class = $this->getRecordClass();
+ if($class!==null)
+ $this->_record=Prado::createComponent($class);
+ else
+ {
+ throw new TConfigurationException('scaffold_invalid_record_class',
+ $this->getRecordClass(),$this->getID());
+ }
+ }
+ }
+ return $this->_record;
+ }
+
+ /**
+ * @param TActiveRecord Active Record instance.
+ */
+ protected function setRecordObject(TActiveRecord $value)
+ {
+ $this->_record=$value;
+ }
+
+ /**
+ * @return TActiveRecord Active Record finder instance
+ */
+ protected function getRecordFinder()
+ {
+ return TActiveRecord::finder($this->getRecordClass());
+ }
+
+ /**
+ * @return string default scaffold stylesheet name
+ */
+ public function getDefaultStyle()
+ {
+ return $this->getViewState('DefaultStyle', 'style');
+ }
+
+ /**
+ * @param string default scaffold stylesheet name
+ */
+ public function setDefaultStyle($value)
+ {
+ $this->setViewState('DefaultStyle', TPropertyValue::ensureString($value), 'style');
+ }
+
+ /**
+ * @return boolean enable default stylesheet, default is true.
+ */
+ public function getEnableDefaultStyle()
+ {
+ return $this->getViewState('EnableDefaultStyle', true);
+ }
+
+ /**
+ * @param boolean enable default stylesheet, default is true.
+ */
+ public function setEnableDefaultStyle($value)
+ {
+ return $this->setViewState('EnableDefaultStyle', TPropertyValue::ensureBoolean($value), true);
+ }
+
+ /**
+ * Publish the default stylesheet file.
+ */
+ public function onPreRender($param)
+ {
+ parent::onPreRender($param);
+ if($this->getEnableDefaultStyle())
+ {
+ $url = $this->publishAsset($this->getDefaultStyle().'.css');
+ $this->getPage()->getClientScript()->registerStyleSheetFile($url,$url);
+ }
+ }
+}
+
diff --git a/framework/Data/ActiveRecord/Scaffold/TScaffoldEditView.php b/framework/Data/ActiveRecord/Scaffold/TScaffoldEditView.php
index c0547627..166e3360 100644
--- a/framework/Data/ActiveRecord/Scaffold/TScaffoldEditView.php
+++ b/framework/Data/ActiveRecord/Scaffold/TScaffoldEditView.php
@@ -1,309 +1,309 @@
-<?php
-/**
- * TScaffoldEditView class and IScaffoldEditRenderer interface file.
- *
- * @author Wei Zhuo <weizhuo[at]gmail[dot]com>
- * @link http://www.pradosoft.com/
+<?php
+/**
+ * TScaffoldEditView class and IScaffoldEditRenderer interface file.
+ *
+ * @author Wei Zhuo <weizhuo[at]gmail[dot]com>
+ * @link http://www.pradosoft.com/
* @copyright Copyright &copy; 2005-2012 PradoSoft
- * @license http://www.pradosoft.com/license/
- * @version $Id$
- * @package System.Data.ActiveRecord.Scaffold
- */
-
-/**
- * Load scaffold base.
- */
-Prado::using('System.Data.ActiveRecord.Scaffold.TScaffoldBase');
-
-/**
- * Template control for editing an Active Record instance.
- * The <b>RecordClass</b> determines the Active Record class to be edited.
- * A particular record can be edited by specifying the {@link setRecordPk RecordPk}
- * value (may be an array for composite keys).
- *
- * The default editor input controls are created based on the column types.
- * The editor layout can be specified by a renderer by set the value
- * of the {@link setEditRenderer EditRenderer} property to the class name of a
- * class that implements TScaffoldEditRenderer. A renderer is an external
- * template control that implements IScaffoldEditRenderer.
- *
- * The <b>Data</b> of the IScaffoldEditRenderer will be set as the current Active
- * Record to be edited. The <b>UpdateRecord()</b> method of IScaffoldEditRenderer
- * is called when request to save the record is requested.
- *
- * Validators in the custom external editor template should have the
- * {@link TBaseValidator::setValidationGroup ValidationGroup} property set to the
- * value of the {@link getValidationGroup} of the TScaffoldEditView instance
- * (the edit view instance is the <b>Parent</b> of the IScaffoldEditRenderer in most
- * cases.
- *
- * Cosmetic changes to the default editor should be done using Cascading Stylesheets.
- * For example, a particular field/property can be hidden by specifying "display:none" for
- * the corresponding style (each field/property has unique Css class name as "property_xxx", where
- * xxx is the property name).
- *
- * @author Wei Zhuo <weizho[at]gmail[dot]com>
- * @version $Id$
- * @package System.Data.ActiveRecord.Scaffold
- * @since 3.1
- */
-class TScaffoldEditView extends TScaffoldBase
-{
- /**
- * @var IScaffoldEditRenderer custom scaffold edit renderer
- */
- private $_editRenderer;
-
- /**
- * Initialize the editor form if it is Visible.
- */
- public function onLoad($param)
- {
- if($this->getVisible())
- $this->initializeEditForm();
- }
-
- /**
- * @return string the class name for scaffold editor. Defaults to empty, meaning not set.
- */
- public function getEditRenderer()
- {
- return $this->getViewState('EditRenderer', '');
- }
-
- /**
- * @param string the class name for scaffold editor. Defaults to empty, meaning not set.
- */
- public function setEditRenderer($value)
- {
- $this->setViewState('EditRenderer', $value, '');
- }
-
- /**
- * @param array Active Record primary key value to be edited.
- */
- public function setRecordPk($value)
- {
- $this->clearRecordObject();
- $val = TPropertyValue::ensureArray($value);
- $this->setViewState('PK', count($val) > 0 ? $val : null);
- }
-
- /**
- * @return array Active Record primary key value.
- */
- public function getRecordPk()
- {
- return $this->getViewState('PK');
- }
-
- /**
- * @return TActiveRecord current Active Record instance
- */
- protected function getCurrentRecord()
- {
- return $this->getRecordObject($this->getRecordPk());
- }
-
- /**
- * Initialize the editor form
- */
- public function initializeEditForm()
- {
- $record = $this->getCurrentRecord();
- $classPath = $this->getEditRenderer();
- if($classPath === '')
- {
- $columns = $this->getTableInfo()->getColumns();
- $this->getInputRepeater()->setDataSource($columns);
- $this->getInputRepeater()->dataBind();
- }
- else
- {
- if($this->_editRenderer===null)
- $this->createEditRenderer($record, $classPath);
- else
- $this->_editRenderer->setData($record);
- }
- }
-
- /**
- * Instantiate the external edit renderer.
- * @param TActiveRecord record to be edited
- * @param string external edit renderer class name.
- * @throws TConfigurationException raised when renderer is not an
- * instance of IScaffoldEditRenderer.
- */
- protected function createEditRenderer($record, $classPath)
- {
- $this->_editRenderer = Prado::createComponent($classPath);
- if($this->_editRenderer instanceof IScaffoldEditRenderer)
- {
- $index = $this->getControls()->remove($this->getInputRepeater());
- $this->getControls()->insertAt($index,$this->_editRenderer);
- $this->_editRenderer->setData($record);
- }
- else
- {
- throw new TConfigurationException(
- 'scaffold_invalid_edit_renderer', $this->getID(), get_class($record));
- }
- }
-
- /**
- * Initialize the default editor using the scaffold input builder.
- */
- protected function createRepeaterEditItem($sender, $param)
- {
- $type = $param->getItem()->getItemType();
- if($type==TListItemType::Item || $type==TListItemType::AlternatingItem)
- {
- $item = $param->getItem();
- $column = $item->getDataItem();
- if($column===null)
- return;
-
- $record = $this->getCurrentRecord();
- $builder = $this->getScaffoldInputBuilder($record);
- $builder->createScaffoldInput($this, $item, $column, $record);
- }
- }
-
- /**
- * Bubble the command name event. Stops bubbling when the page validator false.
- * Otherwise, the bubble event is continued.
- */
- public function bubbleEvent($sender, $param)
- {
- switch(strtolower($param->getCommandName()))
- {
- case 'save':
- return $this->doSave() ? false : true;
- case 'clear':
- $this->setRecordPk(null);
- $this->initializeEditForm();
- return false;
- default:
- return false;
- }
- }
-
- /**
- * Check the validators, then tries to save the record.
- * @return boolean true if the validators are true, false otherwise.
- */
- protected function doSave()
- {
- if($this->getPage()->getIsValid())
- {
- $record = $this->getCurrentRecord();
- if($this->_editRenderer===null)
- {
- $table = $this->getTableInfo();
- $builder = $this->getScaffoldInputBuilder($record);
- foreach($this->getInputRepeater()->getItems() as $item)
- {
- $column = $table->getColumn($item->getCustomData());
- $builder->loadScaffoldInput($this, $item, $column, $record);
- }
- }
- else
- {
- $this->_editRenderer->updateRecord($record);
- }
- $record->save();
- return true;
- }
- else if($this->_editRenderer!==null)
- {
- //preserve the form data.
- $this->_editRenderer->updateRecord($this->getCurrentRecord());
- }
-
- return false;
- }
-
- /**
- * @return TRepeater default editor input controls repeater
- */
- protected function getInputRepeater()
- {
- $this->ensureChildControls();
- return $this->getRegisteredObject('_repeater');
- }
-
- /**
- * @return TButton Button triggered to save the Active Record.
- */
- public function getSaveButton()
- {
- $this->ensureChildControls();
- return $this->getRegisteredObject('_save');
- }
-
- /**
- * @return TButton Button to clear the editor inputs.
- */
- public function getClearButton()
- {
- $this->ensureChildControls();
- return $this->getRegisteredObject('_clear');
- }
-
- /**
- * @return TButton Button to cancel the edit action (e.g. hide the edit view).
- */
- public function getCancelButton()
- {
- $this->ensureChildControls();
- return $this->getRegisteredObject('_cancel');
- }
-
- /**
- * Create the default scaffold editor control factory.
- * @param TActiveRecord record instance.
- * @return TScaffoldInputBase scaffold editor control factory.
- */
- protected function getScaffoldInputBuilder($record)
- {
- static $_builders=array();
- $class = get_class($record);
- if(!isset($_builders[$class]))
- {
- Prado::using('System.Data.ActiveRecord.Scaffold.InputBuilder.TScaffoldInputBase');
- $_builders[$class] = TScaffoldInputBase::createInputBuilder($record);
- }
- return $_builders[$class];
- }
-
- /**
- * @return string editor validation group name.
- */
- public function getValidationGroup()
- {
- return 'group_'.$this->getUniqueID();
- }
-}
-
-/**
- * IScaffoldEditRenderer interface.
- *
- * IScaffoldEditRenderer defines the interface that an edit renderer
- * needs to implement. Besides the {@link getData Data} property, an edit
- * renderer also needs to provide {@link updateRecord updateRecord} method
- * that is called before the save() method is called on the TActiveRecord.
- *
- * @author Wei Zhuo <weizho[at]gmail[dot]com>
- * @version $Id$
- * @package System.Data.ActiveRecord.Scaffold
- * @since 3.1
- */
-interface IScaffoldEditRenderer extends IDataRenderer
-{
- /**
- * This method should update the record with the user input data.
- * @param TActiveRecord record to be saved.
- */
- public function updateRecord($record);
-}
-
+ * @license http://www.pradosoft.com/license/
+ * @version $Id$
+ * @package System.Data.ActiveRecord.Scaffold
+ */
+
+/**
+ * Load scaffold base.
+ */
+Prado::using('System.Data.ActiveRecord.Scaffold.TScaffoldBase');
+
+/**
+ * Template control for editing an Active Record instance.
+ * The <b>RecordClass</b> determines the Active Record class to be edited.
+ * A particular record can be edited by specifying the {@link setRecordPk RecordPk}
+ * value (may be an array for composite keys).
+ *
+ * The default editor input controls are created based on the column types.
+ * The editor layout can be specified by a renderer by set the value
+ * of the {@link setEditRenderer EditRenderer} property to the class name of a
+ * class that implements TScaffoldEditRenderer. A renderer is an external
+ * template control that implements IScaffoldEditRenderer.
+ *
+ * The <b>Data</b> of the IScaffoldEditRenderer will be set as the current Active
+ * Record to be edited. The <b>UpdateRecord()</b> method of IScaffoldEditRenderer
+ * is called when request to save the record is requested.
+ *
+ * Validators in the custom external editor template should have the
+ * {@link TBaseValidator::setValidationGroup ValidationGroup} property set to the
+ * value of the {@link getValidationGroup} of the TScaffoldEditView instance
+ * (the edit view instance is the <b>Parent</b> of the IScaffoldEditRenderer in most
+ * cases.
+ *
+ * Cosmetic changes to the default editor should be done using Cascading Stylesheets.
+ * For example, a particular field/property can be hidden by specifying "display:none" for
+ * the corresponding style (each field/property has unique Css class name as "property_xxx", where
+ * xxx is the property name).
+ *
+ * @author Wei Zhuo <weizho[at]gmail[dot]com>
+ * @version $Id$
+ * @package System.Data.ActiveRecord.Scaffold
+ * @since 3.1
+ */
+class TScaffoldEditView extends TScaffoldBase
+{
+ /**
+ * @var IScaffoldEditRenderer custom scaffold edit renderer
+ */
+ private $_editRenderer;
+
+ /**
+ * Initialize the editor form if it is Visible.
+ */
+ public function onLoad($param)
+ {
+ if($this->getVisible())
+ $this->initializeEditForm();
+ }
+
+ /**
+ * @return string the class name for scaffold editor. Defaults to empty, meaning not set.
+ */
+ public function getEditRenderer()
+ {
+ return $this->getViewState('EditRenderer', '');
+ }
+
+ /**
+ * @param string the class name for scaffold editor. Defaults to empty, meaning not set.
+ */
+ public function setEditRenderer($value)
+ {
+ $this->setViewState('EditRenderer', $value, '');
+ }
+
+ /**
+ * @param array Active Record primary key value to be edited.
+ */
+ public function setRecordPk($value)
+ {
+ $this->clearRecordObject();
+ $val = TPropertyValue::ensureArray($value);
+ $this->setViewState('PK', count($val) > 0 ? $val : null);
+ }
+
+ /**
+ * @return array Active Record primary key value.
+ */
+ public function getRecordPk()
+ {
+ return $this->getViewState('PK');
+ }
+
+ /**
+ * @return TActiveRecord current Active Record instance
+ */
+ protected function getCurrentRecord()
+ {
+ return $this->getRecordObject($this->getRecordPk());
+ }
+
+ /**
+ * Initialize the editor form
+ */
+ public function initializeEditForm()
+ {
+ $record = $this->getCurrentRecord();
+ $classPath = $this->getEditRenderer();
+ if($classPath === '')
+ {
+ $columns = $this->getTableInfo()->getColumns();
+ $this->getInputRepeater()->setDataSource($columns);
+ $this->getInputRepeater()->dataBind();
+ }
+ else
+ {
+ if($this->_editRenderer===null)
+ $this->createEditRenderer($record, $classPath);
+ else
+ $this->_editRenderer->setData($record);
+ }
+ }
+
+ /**
+ * Instantiate the external edit renderer.
+ * @param TActiveRecord record to be edited
+ * @param string external edit renderer class name.
+ * @throws TConfigurationException raised when renderer is not an
+ * instance of IScaffoldEditRenderer.
+ */
+ protected function createEditRenderer($record, $classPath)
+ {
+ $this->_editRenderer = Prado::createComponent($classPath);
+ if($this->_editRenderer instanceof IScaffoldEditRenderer)
+ {
+ $index = $this->getControls()->remove($this->getInputRepeater());
+ $this->getControls()->insertAt($index,$this->_editRenderer);
+ $this->_editRenderer->setData($record);
+ }
+ else
+ {
+ throw new TConfigurationException(
+ 'scaffold_invalid_edit_renderer', $this->getID(), get_class($record));
+ }
+ }
+
+ /**
+ * Initialize the default editor using the scaffold input builder.
+ */
+ protected function createRepeaterEditItem($sender, $param)
+ {
+ $type = $param->getItem()->getItemType();
+ if($type==TListItemType::Item || $type==TListItemType::AlternatingItem)
+ {
+ $item = $param->getItem();
+ $column = $item->getDataItem();
+ if($column===null)
+ return;
+
+ $record = $this->getCurrentRecord();
+ $builder = $this->getScaffoldInputBuilder($record);
+ $builder->createScaffoldInput($this, $item, $column, $record);
+ }
+ }
+
+ /**
+ * Bubble the command name event. Stops bubbling when the page validator false.
+ * Otherwise, the bubble event is continued.
+ */
+ public function bubbleEvent($sender, $param)
+ {
+ switch(strtolower($param->getCommandName()))
+ {
+ case 'save':
+ return $this->doSave() ? false : true;
+ case 'clear':
+ $this->setRecordPk(null);
+ $this->initializeEditForm();
+ return false;
+ default:
+ return false;
+ }
+ }
+
+ /**
+ * Check the validators, then tries to save the record.
+ * @return boolean true if the validators are true, false otherwise.
+ */
+ protected function doSave()
+ {
+ if($this->getPage()->getIsValid())
+ {
+ $record = $this->getCurrentRecord();
+ if($this->_editRenderer===null)
+ {
+ $table = $this->getTableInfo();
+ $builder = $this->getScaffoldInputBuilder($record);
+ foreach($this->getInputRepeater()->getItems() as $item)
+ {
+ $column = $table->getColumn($item->getCustomData());
+ $builder->loadScaffoldInput($this, $item, $column, $record);
+ }
+ }
+ else
+ {
+ $this->_editRenderer->updateRecord($record);
+ }
+ $record->save();
+ return true;
+ }
+ else if($this->_editRenderer!==null)
+ {
+ //preserve the form data.
+ $this->_editRenderer->updateRecord($this->getCurrentRecord());
+ }
+
+ return false;
+ }
+
+ /**
+ * @return TRepeater default editor input controls repeater
+ */
+ protected function getInputRepeater()
+ {
+ $this->ensureChildControls();
+ return $this->getRegisteredObject('_repeater');
+ }
+
+ /**
+ * @return TButton Button triggered to save the Active Record.
+ */
+ public function getSaveButton()
+ {
+ $this->ensureChildControls();
+ return $this->getRegisteredObject('_save');
+ }
+
+ /**
+ * @return TButton Button to clear the editor inputs.
+ */
+ public function getClearButton()
+ {
+ $this->ensureChildControls();
+ return $this->getRegisteredObject('_clear');
+ }
+
+ /**
+ * @return TButton Button to cancel the edit action (e.g. hide the edit view).
+ */
+ public function getCancelButton()
+ {
+ $this->ensureChildControls();
+ return $this->getRegisteredObject('_cancel');
+ }
+
+ /**
+ * Create the default scaffold editor control factory.
+ * @param TActiveRecord record instance.
+ * @return TScaffoldInputBase scaffold editor control factory.
+ */
+ protected function getScaffoldInputBuilder($record)
+ {
+ static $_builders=array();
+ $class = get_class($record);
+ if(!isset($_builders[$class]))
+ {
+ Prado::using('System.Data.ActiveRecord.Scaffold.InputBuilder.TScaffoldInputBase');
+ $_builders[$class] = TScaffoldInputBase::createInputBuilder($record);
+ }
+ return $_builders[$class];
+ }
+
+ /**
+ * @return string editor validation group name.
+ */
+ public function getValidationGroup()
+ {
+ return 'group_'.$this->getUniqueID();
+ }
+}
+
+/**
+ * IScaffoldEditRenderer interface.
+ *
+ * IScaffoldEditRenderer defines the interface that an edit renderer
+ * needs to implement. Besides the {@link getData Data} property, an edit
+ * renderer also needs to provide {@link updateRecord updateRecord} method
+ * that is called before the save() method is called on the TActiveRecord.
+ *
+ * @author Wei Zhuo <weizho[at]gmail[dot]com>
+ * @version $Id$
+ * @package System.Data.ActiveRecord.Scaffold
+ * @since 3.1
+ */
+interface IScaffoldEditRenderer extends IDataRenderer
+{
+ /**
+ * This method should update the record with the user input data.
+ * @param TActiveRecord record to be saved.
+ */
+ public function updateRecord($record);
+}
+
diff --git a/framework/Data/ActiveRecord/Scaffold/TScaffoldListView.php b/framework/Data/ActiveRecord/Scaffold/TScaffoldListView.php
index 953420e3..bed5bf88 100644
--- a/framework/Data/ActiveRecord/Scaffold/TScaffoldListView.php
+++ b/framework/Data/ActiveRecord/Scaffold/TScaffoldListView.php
@@ -1,306 +1,306 @@
-<?php
-/**
- * TScaffoldListView class file.
- *
- * @author Wei Zhuo <weizhuo[at]gmail[dot]com>
- * @link http://www.pradosoft.com/
+<?php
+/**
+ * TScaffoldListView class file.
+ *
+ * @author Wei Zhuo <weizhuo[at]gmail[dot]com>
+ * @link http://www.pradosoft.com/
* @copyright Copyright &copy; 2005-2012 PradoSoft
- * @license http://www.pradosoft.com/license/
- * @version $Id$
- * @package System.Data.ActiveRecord.Scaffold
- */
-
-/**
- * Load the scaffold base class.
- */
-Prado::using('System.Data.ActiveRecord.Scaffold.TScaffoldBase');
-
-/**
- * TScaffoldListView displays a list of Active Records.
- *
- * The {@link getHeader Header} property is a TRepeater displaying the
- * Active Record property/field names. The {@link getSort Sort} property
- * is a drop down list displaying the combination of properties and its possible
- * ordering. The {@link getPager Pager} property is a TPager control displaying
- * the links and/or buttons that navigate to different pages in the Active Record data.
- * The {@link getList List} property is a TRepeater that renders a row of
- * Active Record data.
- *
- * Custom rendering of the each Active Record can be achieved by specifying
- * the ItemTemplate or AlternatingItemTemplate property of the main {@linnk getList List}
- * repeater.
- *
- * The TScaffoldListView will listen for two command events named "delete" and
- * "edit". A "delete" command will delete a the record for the row where the
- * "delete" command is originates. An "edit" command will push
- * the record data to be edited by a TScaffoldEditView with ID specified by the
- * {@link setEditViewID EditViewID}.
- *
- * Additional {@link setSearchCondition SearchCondition} and
- * {@link setSearchParameters SearchParameters} (takes array values) can be
- * specified to customize the records to be shown. The {@link setSearchCondition SearchCondition}
- * will be used as the Condition property of TActiveRecordCriteria, and similarly
- * the {@link setSearchParameters SearchParameters} will be the corresponding
- * Parameters property of TActiveRecordCriteria.
- *
- * @author Wei Zhuo <weizho[at]gmail[dot]com>
- * @version $Id$
- * @package System.Data.ActiveRecord.Scaffold
- * @since 3.1
- */
-class TScaffoldListView extends TScaffoldBase
-{
- /**
- * Initialize the sort drop down list and the column names repeater.
- */
- protected function initializeSort()
- {
- $table = $this->getTableInfo();
- $sorts = array('Sort By', str_repeat('-',15));
- $headers = array();
- foreach($table->getColumns() as $name=>$colum)
- {
- $fname = ucwords(str_replace('_', ' ', $name));
- $sorts[$name.' ASC'] = $fname .' Ascending';
- $sorts[$name.' DESC'] = $fname .' Descending';
- $headers[] = $fname ;
- }
- $this->_sort->setDataSource($sorts);
- $this->_sort->dataBind();
- $this->_header->setDataSource($headers);
- $this->_header->dataBind();
- }
-
- /**
- * Loads and display the data.
- */
- public function onPreRender($param)
- {
- parent::onPreRender($param);
- if(!$this->getPage()->getIsPostBack() || $this->getViewState('CurrentClass')!=$this->getRecordClass())
- {
- $this->initializeSort();
- $this->setViewState('CurrentClass', $this->getRecordClass());
- }
- $this->loadRecordData();
- }
-
- /**
- * Fetch the records and data bind it to the list.
- */
- protected function loadRecordData()
- {
- $search = new TActiveRecordCriteria($this->getSearchCondition(), $this->getSearchParameters());
- $this->_list->setVirtualItemCount($this->getRecordFinder()->count($search));
- $finder = $this->getRecordFinder();
- $criteria = $this->getRecordCriteria();
- $this->_list->setDataSource($finder->findAll($criteria));
- $this->_list->dataBind();
- }
-
- /**
- * @return TActiveRecordCriteria sort/search/paging criteria
- */
- protected function getRecordCriteria()
- {
- $total = $this->_list->getVirtualItemCount();
- $limit = $this->_list->getPageSize();
- $offset = $this->_list->getCurrentPageIndex()*$limit;
- if($offset + $limit > $total)
- $limit = $total - $offset;
- $criteria = new TActiveRecordCriteria($this->getSearchCondition(), $this->getSearchParameters());
- if($limit > 0)
- {
- $criteria->setLimit($limit);
- if($offset <= $total)
- $criteria->setOffset($offset);
- }
- $order = explode(' ',$this->_sort->getSelectedValue(), 2);
- if(is_array($order) && count($order) === 2)
- $criteria->OrdersBy[$order[0]] = $order[1];
- return $criteria;
- }
-
- /**
- * @param string search condition, the SQL string after the WHERE clause.
- */
- public function setSearchCondition($value)
- {
- $this->setViewState('SearchCondition', $value);
- }
-
- /**
- * @param string SQL search condition for list display.
- */
- public function getSearchCondition()
- {
- return $this->getViewState('SearchCondition');
- }
-
- /**
- * @param array search parameters
- */
- public function setSearchParameters($value)
- {
- $this->setViewState('SearchParameters', TPropertyValue::ensureArray($value),array());
- }
-
- /**
- * @return array search parameters
- */
- public function getSearchParameters()
- {
- return $this->getViewState('SearchParameters', array());
- }
-
- /**
- * Continue bubbling the "edit" command, "delete" command is handled in this class.
- */
- public function bubbleEvent($sender, $param)
- {
- switch(strtolower($param->getCommandName()))
- {
- case 'delete':
- return $this->deleteRecord($sender, $param);
- case 'edit':
- $this->initializeEdit($sender, $param);
- }
- $this->raiseBubbleEvent($this, $param);
- return true;
- }
-
- /**
- * Initialize the edit view control form when EditViewID is set.
- */
- protected function initializeEdit($sender, $param)
- {
- if(($ctrl=$this->getEditViewControl())!==null)
- {
- if($param instanceof TRepeaterCommandEventParameter)
- {
- $pk = $param->getItem()->getCustomData();
- $ctrl->setRecordPk($pk);
- $ctrl->initializeEditForm();
- }
- }
- }
-
- /**
- * Deletes an Active Record.
- */
- protected function deleteRecord($sender, $param)
- {
- if($param instanceof TRepeaterCommandEventParameter)
- {
- $pk = $param->getItem()->getCustomData();
- $this->getRecordFinder()->deleteByPk($pk);
- }
- }
-
- /**
- * Initialize the default display for each Active Record item.
- */
- protected function listItemCreated($sender, $param)
- {
- $item = $param->getItem();
- if($item instanceof IItemDataRenderer)
- {
- $type = $item->getItemType();
- if($type==TListItemType::Item || $type==TListItemType::AlternatingItem)
- $this->populateField($sender, $param);
- }
- }
-
- /**
- * Sets the Record primary key to the current repeater item's CustomData.
- * Binds the inner repeater with properties of the current Active Record.
- */
- protected function populateField($sender, $param)
- {
- $item = $param->getItem();
- if(($data = $item->getData()) !== null)
- {
- $item->setCustomData($this->getRecordPkValues($data));
- if(($prop = $item->findControl('_properties'))!==null)
- {
- $item->_properties->setDataSource($this->getRecordPropertyValues($data));
- $item->_properties->dataBind();
- }
- }
- }
-
- /**
- * Updates repeater page index with the pager new index value.
- */
- protected function pageChanged($sender, $param)
- {
- $this->_list->setCurrentPageIndex($param->getNewPageIndex());
- }
-
- /**
- * @return TRepeater Repeater control for Active Record instances.
- */
- public function getList()
- {
- $this->ensureChildControls();
- return $this->getRegisteredObject('_list');
- }
-
- /**
- * @return TPager List pager control.
- */
- public function getPager()
- {
- $this->ensureChildControls();
- return $this->getRegisteredObject('_pager');
- }
-
- /**
- * @return TDropDownList Control that displays and controls the record ordering.
- */
- public function getSort()
- {
- $this->ensureChildControls();
- return $this->getRegisteredObject('_sort');
- }
-
- /**
- * @return TRepeater Repeater control for record property names.
- */
- public function getHeader()
- {
- $this->ensureChildControls();
- return $this->getRegisteredObject('_header');
- }
-
- /**
- * @return string TScaffoldEditView control ID for editing selected Active Record.
- */
- public function getEditViewID()
- {
- return $this->getViewState('EditViewID');
- }
-
- /**
- * @param string TScaffoldEditView control ID for editing selected Active Record.
- */
- public function setEditViewID($value)
- {
- $this->setViewState('EditViewID', $value);
- }
-
- /**
- * @return TScaffoldEditView control for editing selected Active Record, null if EditViewID is not set.
- */
- protected function getEditViewControl()
- {
- if(($id=$this->getEditViewID())!==null)
- {
- $ctrl = $this->getParent()->findControl($id);
- if($ctrl===null)
- throw new TConfigurationException('scaffold_unable_to_find_edit_view', $id);
- return $ctrl;
- }
- }
-}
+ * @license http://www.pradosoft.com/license/
+ * @version $Id$
+ * @package System.Data.ActiveRecord.Scaffold
+ */
+
+/**
+ * Load the scaffold base class.
+ */
+Prado::using('System.Data.ActiveRecord.Scaffold.TScaffoldBase');
+
+/**
+ * TScaffoldListView displays a list of Active Records.
+ *
+ * The {@link getHeader Header} property is a TRepeater displaying the
+ * Active Record property/field names. The {@link getSort Sort} property
+ * is a drop down list displaying the combination of properties and its possible
+ * ordering. The {@link getPager Pager} property is a TPager control displaying
+ * the links and/or buttons that navigate to different pages in the Active Record data.
+ * The {@link getList List} property is a TRepeater that renders a row of
+ * Active Record data.
+ *
+ * Custom rendering of the each Active Record can be achieved by specifying
+ * the ItemTemplate or AlternatingItemTemplate property of the main {@linnk getList List}
+ * repeater.
+ *
+ * The TScaffoldListView will listen for two command events named "delete" and
+ * "edit". A "delete" command will delete a the record for the row where the
+ * "delete" command is originates. An "edit" command will push
+ * the record data to be edited by a TScaffoldEditView with ID specified by the
+ * {@link setEditViewID EditViewID}.
+ *
+ * Additional {@link setSearchCondition SearchCondition} and
+ * {@link setSearchParameters SearchParameters} (takes array values) can be
+ * specified to customize the records to be shown. The {@link setSearchCondition SearchCondition}
+ * will be used as the Condition property of TActiveRecordCriteria, and similarly
+ * the {@link setSearchParameters SearchParameters} will be the corresponding
+ * Parameters property of TActiveRecordCriteria.
+ *
+ * @author Wei Zhuo <weizho[at]gmail[dot]com>
+ * @version $Id$
+ * @package System.Data.ActiveRecord.Scaffold
+ * @since 3.1
+ */
+class TScaffoldListView extends TScaffoldBase
+{
+ /**
+ * Initialize the sort drop down list and the column names repeater.
+ */
+ protected function initializeSort()
+ {
+ $table = $this->getTableInfo();
+ $sorts = array('Sort By', str_repeat('-',15));
+ $headers = array();
+ foreach($table->getColumns() as $name=>$colum)
+ {
+ $fname = ucwords(str_replace('_', ' ', $name));
+ $sorts[$name.' ASC'] = $fname .' Ascending';
+ $sorts[$name.' DESC'] = $fname .' Descending';
+ $headers[] = $fname ;
+ }
+ $this->_sort->setDataSource($sorts);
+ $this->_sort->dataBind();
+ $this->_header->setDataSource($headers);
+ $this->_header->dataBind();
+ }
+
+ /**
+ * Loads and display the data.
+ */
+ public function onPreRender($param)
+ {
+ parent::onPreRender($param);
+ if(!$this->getPage()->getIsPostBack() || $this->getViewState('CurrentClass')!=$this->getRecordClass())
+ {
+ $this->initializeSort();
+ $this->setViewState('CurrentClass', $this->getRecordClass());
+ }
+ $this->loadRecordData();
+ }
+
+ /**
+ * Fetch the records and data bind it to the list.
+ */
+ protected function loadRecordData()
+ {
+ $search = new TActiveRecordCriteria($this->getSearchCondition(), $this->getSearchParameters());
+ $this->_list->setVirtualItemCount($this->getRecordFinder()->count($search));
+ $finder = $this->getRecordFinder();
+ $criteria = $this->getRecordCriteria();
+ $this->_list->setDataSource($finder->findAll($criteria));
+ $this->_list->dataBind();
+ }
+
+ /**
+ * @return TActiveRecordCriteria sort/search/paging criteria
+ */
+ protected function getRecordCriteria()
+ {
+ $total = $this->_list->getVirtualItemCount();
+ $limit = $this->_list->getPageSize();
+ $offset = $this->_list->getCurrentPageIndex()*$limit;
+ if($offset + $limit > $total)
+ $limit = $total - $offset;
+ $criteria = new TActiveRecordCriteria($this->getSearchCondition(), $this->getSearchParameters());
+ if($limit > 0)
+ {
+ $criteria->setLimit($limit);
+ if($offset <= $total)
+ $criteria->setOffset($offset);
+ }
+ $order = explode(' ',$this->_sort->getSelectedValue(), 2);
+ if(is_array($order) && count($order) === 2)
+ $criteria->OrdersBy[$order[0]] = $order[1];
+ return $criteria;
+ }
+
+ /**
+ * @param string search condition, the SQL string after the WHERE clause.
+ */
+ public function setSearchCondition($value)
+ {
+ $this->setViewState('SearchCondition', $value);
+ }
+
+ /**
+ * @param string SQL search condition for list display.
+ */
+ public function getSearchCondition()
+ {
+ return $this->getViewState('SearchCondition');
+ }
+
+ /**
+ * @param array search parameters
+ */
+ public function setSearchParameters($value)
+ {
+ $this->setViewState('SearchParameters', TPropertyValue::ensureArray($value),array());
+ }
+
+ /**
+ * @return array search parameters
+ */
+ public function getSearchParameters()
+ {
+ return $this->getViewState('SearchParameters', array());
+ }
+
+ /**
+ * Continue bubbling the "edit" command, "delete" command is handled in this class.
+ */
+ public function bubbleEvent($sender, $param)
+ {
+ switch(strtolower($param->getCommandName()))
+ {
+ case 'delete':
+ return $this->deleteRecord($sender, $param);
+ case 'edit':
+ $this->initializeEdit($sender, $param);
+ }
+ $this->raiseBubbleEvent($this, $param);
+ return true;
+ }
+
+ /**
+ * Initialize the edit view control form when EditViewID is set.
+ */
+ protected function initializeEdit($sender, $param)
+ {
+ if(($ctrl=$this->getEditViewControl())!==null)
+ {
+ if($param instanceof TRepeaterCommandEventParameter)
+ {
+ $pk = $param->getItem()->getCustomData();
+ $ctrl->setRecordPk($pk);
+ $ctrl->initializeEditForm();
+ }
+ }
+ }
+
+ /**
+ * Deletes an Active Record.
+ */
+ protected function deleteRecord($sender, $param)
+ {
+ if($param instanceof TRepeaterCommandEventParameter)
+ {
+ $pk = $param->getItem()->getCustomData();
+ $this->getRecordFinder()->deleteByPk($pk);
+ }
+ }
+
+ /**
+ * Initialize the default display for each Active Record item.
+ */
+ protected function listItemCreated($sender, $param)
+ {
+ $item = $param->getItem();
+ if($item instanceof IItemDataRenderer)
+ {
+ $type = $item->getItemType();
+ if($type==TListItemType::Item || $type==TListItemType::AlternatingItem)
+ $this->populateField($sender, $param);
+ }
+ }
+
+ /**
+ * Sets the Record primary key to the current repeater item's CustomData.
+ * Binds the inner repeater with properties of the current Active Record.
+ */
+ protected function populateField($sender, $param)
+ {
+ $item = $param->getItem();
+ if(($data = $item->getData()) !== null)
+ {
+ $item->setCustomData($this->getRecordPkValues($data));
+ if(($prop = $item->findControl('_properties'))!==null)
+ {
+ $item->_properties->setDataSource($this->getRecordPropertyValues($data));
+ $item->_properties->dataBind();
+ }
+ }
+ }
+
+ /**
+ * Updates repeater page index with the pager new index value.
+ */
+ protected function pageChanged($sender, $param)
+ {
+ $this->_list->setCurrentPageIndex($param->getNewPageIndex());
+ }
+
+ /**
+ * @return TRepeater Repeater control for Active Record instances.
+ */
+ public function getList()
+ {
+ $this->ensureChildControls();
+ return $this->getRegisteredObject('_list');
+ }
+
+ /**
+ * @return TPager List pager control.
+ */
+ public function getPager()
+ {
+ $this->ensureChildControls();
+ return $this->getRegisteredObject('_pager');
+ }
+
+ /**
+ * @return TDropDownList Control that displays and controls the record ordering.
+ */
+ public function getSort()
+ {
+ $this->ensureChildControls();
+ return $this->getRegisteredObject('_sort');
+ }
+
+ /**
+ * @return TRepeater Repeater control for record property names.
+ */
+ public function getHeader()
+ {
+ $this->ensureChildControls();
+ return $this->getRegisteredObject('_header');
+ }
+
+ /**
+ * @return string TScaffoldEditView control ID for editing selected Active Record.
+ */
+ public function getEditViewID()
+ {
+ return $this->getViewState('EditViewID');
+ }
+
+ /**
+ * @param string TScaffoldEditView control ID for editing selected Active Record.
+ */
+ public function setEditViewID($value)
+ {
+ $this->setViewState('EditViewID', $value);
+ }
+
+ /**
+ * @return TScaffoldEditView control for editing selected Active Record, null if EditViewID is not set.
+ */
+ protected function getEditViewControl()
+ {
+ if(($id=$this->getEditViewID())!==null)
+ {
+ $ctrl = $this->getParent()->findControl($id);
+ if($ctrl===null)
+ throw new TConfigurationException('scaffold_unable_to_find_edit_view', $id);
+ return $ctrl;
+ }
+ }
+}
diff --git a/framework/Data/ActiveRecord/Scaffold/TScaffoldSearch.php b/framework/Data/ActiveRecord/Scaffold/TScaffoldSearch.php
index bd679c94..40335085 100644
--- a/framework/Data/ActiveRecord/Scaffold/TScaffoldSearch.php
+++ b/framework/Data/ActiveRecord/Scaffold/TScaffoldSearch.php
@@ -1,150 +1,150 @@
-<?php
-/**
- * TScaffoldSearch class file.
- *
- * @author Wei Zhuo <weizhuo[at]gmail[dot]com>
- * @link http://www.pradosoft.com/
+<?php
+/**
+ * TScaffoldSearch class file.
+ *
+ * @author Wei Zhuo <weizhuo[at]gmail[dot]com>
+ * @link http://www.pradosoft.com/
* @copyright Copyright &copy; 2005-2012 PradoSoft
- * @license http://www.pradosoft.com/license/
- * @version $Id$
- * @package System.Data.ActiveRecord.Scaffold
- */
-
-/**
- * Import the scaffold base.
- */
-Prado::using('System.Data.ActiveRecord.Scaffold.TScaffoldBase');
-
-/**
- * TScaffoldSearch provide a simple textbox and a button that is used
- * to perform search on a TScaffoldListView with ID given by {@link setListViewID ListViewID}.
- *
- * The {@link getSearchText SearchText} property is a TTextBox and the
- * {@link getSearchButton SearchButton} property is a TButton with label value "Search".
- *
- * Searchable fields of the Active Record can be restricted by specifying
- * a comma delimited string of allowable fields in the
- * {@link setSearchableFields SearchableFields} property. The default is null,
- * meaning that most text type fields are searched (the default searchable fields
- * are database dependent).
- *
- * @author Wei Zhuo <weizhuo[at]gmail[dot]com>
- * @version $Id$
- * @package System.Data.ActiveRecord.Scaffold
- * @since 3.1
- */
-class TScaffoldSearch extends TScaffoldBase
-{
- /**
- * @var TScaffoldListView the scaffold list view.
- */
- private $_list;
-
- /**
- * @return TScaffoldListView the scaffold list view this search box belongs to.
- */
- protected function getListView()
- {
- if($this->_list===null && ($id = $this->getListViewID()) !== null)
- {
- $this->_list = $this->getParent()->findControl($id);
- if($this->_list ===null)
- throw new TConfigurationException('scaffold_unable_to_find_list_view', $id);
- }
- return $this->_list;
- }
-
- /**
- * @param string ID of the TScaffoldListView this search control belongs to.
- */
- public function setListViewID($value)
- {
- $this->setViewState('ListViewID', $value);
- }
-
- /**
- * @return string ID of the TScaffoldListView this search control belongs to.
- */
- public function getListViewID()
- {
- return $this->getViewState('ListViewID');
- }
-
- /**
- * Sets the SearchCondition of the TScaffoldListView as the search terms
- * given by the text of the search text box.
- */
- public function bubbleEvent($sender, $param)
- {
- if(strtolower($param->getCommandName())==='search')
- {
- if(($list = $this->getListView()) !== null)
- {
- $list->setSearchCondition($this->createSearchCondition());
- return false;
- }
- }
- $this->raiseBubbleEvent($this, $param);
- return true;
- }
-
- /**
- * @return string the search criteria for the search terms in the search text box.
- */
- protected function createSearchCondition()
- {
- $table = $this->getTableInfo();
- if(strlen($str=$this->getSearchText()->getText()) > 0)
- {
- $builder = $table->createCommandBuilder($this->getRecordFinder()->getDbConnection());
- return $builder->getSearchExpression($this->getFields(), $str);
- }
- }
-
- /**
- * @return array list of fields to be searched.
- */
- protected function getFields()
- {
- if(strlen(trim($str=$this->getSearchableFields()))>0)
- $fields = preg_split('/\s*,\s*/', $str);
- else
- $fields = $this->getTableInfo()->getColumns()->getKeys();
- return $fields;
- }
-
- /**
- * @return string comma delimited list of fields that may be searched.
- */
- public function getSearchableFields()
- {
- return $this->getViewState('SearchableFields','');
- }
-
- /**
- * @param string comma delimited list of fields that may be searched.
- */
- public function setSearchableFields($value)
- {
- $this->setViewState('SearchableFields', $value, '');
- }
-
- /**
- * @return TButton button with default label "Search".
- */
- public function getSearchButton()
- {
- $this->ensureChildControls();
- return $this->getRegisteredObject('_search');
- }
-
- /**
- * @return TTextBox search text box.
- */
- public function getSearchText()
- {
- $this->ensureChildControls();
- return $this->getRegisteredObject('_textbox');
- }
-}
+ * @license http://www.pradosoft.com/license/
+ * @version $Id$
+ * @package System.Data.ActiveRecord.Scaffold
+ */
+
+/**
+ * Import the scaffold base.
+ */
+Prado::using('System.Data.ActiveRecord.Scaffold.TScaffoldBase');
+
+/**
+ * TScaffoldSearch provide a simple textbox and a button that is used
+ * to perform search on a TScaffoldListView with ID given by {@link setListViewID ListViewID}.
+ *
+ * The {@link getSearchText SearchText} property is a TTextBox and the
+ * {@link getSearchButton SearchButton} property is a TButton with label value "Search".
+ *
+ * Searchable fields of the Active Record can be restricted by specifying
+ * a comma delimited string of allowable fields in the
+ * {@link setSearchableFields SearchableFields} property. The default is null,
+ * meaning that most text type fields are searched (the default searchable fields
+ * are database dependent).
+ *
+ * @author Wei Zhuo <weizhuo[at]gmail[dot]com>
+ * @version $Id$
+ * @package System.Data.ActiveRecord.Scaffold
+ * @since 3.1
+ */
+class TScaffoldSearch extends TScaffoldBase
+{
+ /**
+ * @var TScaffoldListView the scaffold list view.
+ */
+ private $_list;
+
+ /**
+ * @return TScaffoldListView the scaffold list view this search box belongs to.
+ */
+ protected function getListView()
+ {
+ if($this->_list===null && ($id = $this->getListViewID()) !== null)
+ {
+ $this->_list = $this->getParent()->findControl($id);
+ if($this->_list ===null)
+ throw new TConfigurationException('scaffold_unable_to_find_list_view', $id);
+ }
+ return $this->_list;
+ }
+
+ /**
+ * @param string ID of the TScaffoldListView this search control belongs to.
+ */
+ public function setListViewID($value)
+ {
+ $this->setViewState('ListViewID', $value);
+ }
+
+ /**
+ * @return string ID of the TScaffoldListView this search control belongs to.
+ */
+ public function getListViewID()
+ {
+ return $this->getViewState('ListViewID');
+ }
+
+ /**
+ * Sets the SearchCondition of the TScaffoldListView as the search terms
+ * given by the text of the search text box.
+ */
+ public function bubbleEvent($sender, $param)
+ {
+ if(strtolower($param->getCommandName())==='search')
+ {
+ if(($list = $this->getListView()) !== null)
+ {
+ $list->setSearchCondition($this->createSearchCondition());
+ return false;
+ }
+ }
+ $this->raiseBubbleEvent($this, $param);
+ return true;
+ }
+
+ /**
+ * @return string the search criteria for the search terms in the search text box.
+ */
+ protected function createSearchCondition()
+ {
+ $table = $this->getTableInfo();
+ if(strlen($str=$this->getSearchText()->getText()) > 0)
+ {
+ $builder = $table->createCommandBuilder($this->getRecordFinder()->getDbConnection());
+ return $builder->getSearchExpression($this->getFields(), $str);
+ }
+ }
+
+ /**
+ * @return array list of fields to be searched.
+ */
+ protected function getFields()
+ {
+ if(strlen(trim($str=$this->getSearchableFields()))>0)
+ $fields = preg_split('/\s*,\s*/', $str);
+ else
+ $fields = $this->getTableInfo()->getColumns()->getKeys();
+ return $fields;
+ }
+
+ /**
+ * @return string comma delimited list of fields that may be searched.
+ */
+ public function getSearchableFields()
+ {
+ return $this->getViewState('SearchableFields','');
+ }
+
+ /**
+ * @param string comma delimited list of fields that may be searched.
+ */
+ public function setSearchableFields($value)
+ {
+ $this->setViewState('SearchableFields', $value, '');
+ }
+
+ /**
+ * @return TButton button with default label "Search".
+ */
+ public function getSearchButton()
+ {
+ $this->ensureChildControls();
+ return $this->getRegisteredObject('_search');
+ }
+
+ /**
+ * @return TTextBox search text box.
+ */
+ public function getSearchText()
+ {
+ $this->ensureChildControls();
+ return $this->getRegisteredObject('_textbox');
+ }
+}
diff --git a/framework/Data/ActiveRecord/Scaffold/TScaffoldView.php b/framework/Data/ActiveRecord/Scaffold/TScaffoldView.php
index 69bc1f81..40eee21d 100644
--- a/framework/Data/ActiveRecord/Scaffold/TScaffoldView.php
+++ b/framework/Data/ActiveRecord/Scaffold/TScaffoldView.php
@@ -1,143 +1,143 @@
-<?php
-/**
- * TScaffoldView class.
- *
- * @author Wei Zhuo <weizhuo[at]gmail[dot]com>
- * @link http://www.pradosoft.com/
- * @copyright Copyright &copy; 2005-2012 PradoSoft
- * @license http://www.pradosoft.com/license/
- * @version $Id$
- * @package System.Data.ActiveRecord.Scaffold
- */
-
-/**
- * Import scaffold base, list, edit and search controls.
- */
-Prado::using('System.Data.ActiveRecord.Scaffold.TScaffoldBase');
-Prado::using('System.Data.ActiveRecord.Scaffold.TScaffoldListView');
-Prado::using('System.Data.ActiveRecord.Scaffold.TScaffoldEditView');
-Prado::using('System.Data.ActiveRecord.Scaffold.TScaffoldSearch');
-
-/**
- * TScaffoldView is a composite control consisting of TScaffoldListView
- * with a TScaffoldSearch. In addition, it will display a TScaffoldEditView
- * when an "edit" command is raised from the TScaffoldListView (when the
- * edit button is clicked). Futher more, the "add" button can be clicked
- * that shows an empty data TScaffoldListView for creating new records.
- *
- * The {@link getListView ListView} property gives a TScaffoldListView for
- * display the record data. The {@link getEditView EditView} is the
- * TScaffoldEditView that renders the
- * inputs for editing and adding records. The {@link getSearchControl SearchControl}
- * is a TScaffoldSearch responsible to the search user interface.
- *
- * Set the {@link setRecordClass RecordClass} property to the name of
- * the Active Record class to be displayed/edited/added.
- *
- * @author Wei Zhuo <weizhuo[at]gmail[dot]com>
- * @version $Id$
- * @package System.Data.ActiveRecord.Scaffold
- * @since 3.0
- */
-class TScaffoldView extends TScaffoldBase
-{
- /**
- * Copy basic record details to the list/edit/search controls.
- */
- public function onPreRender($param)
- {
- parent::onPreRender($param);
- $this->getListView()->copyFrom($this);
- $this->getEditView()->copyFrom($this);
- $this->getSearchControl()->copyFrom($this);
- }
-
- /**
- * @return TScaffoldListView scaffold list view.
- */
- public function getListView()
- {
- $this->ensureChildControls();
- return $this->getRegisteredObject('_listView');
- }
-
- /**
- * @return TScaffoldEditView scaffold edit view.
- */
- public function getEditView()
- {
- $this->ensureChildControls();
- return $this->getRegisteredObject('_editView');
- }
-
- /**
- * @return TScaffoldSearch scaffold search textbox and button.
- */
- public function getSearchControl()
- {
- $this->ensureChildControls();
- return $this->getRegisteredObject('_search');
- }
-
- /**
- * @return TButton "Add new record" button.
- */
- public function getAddButton()
- {
- $this->ensureChildControls();
- return $this->getRegisteredObject('_newButton');
- }
-
- /**
- * Handle the "edit" and "new" commands by displaying the edit view.
- * Default command shows the list view.
- */
- public function bubbleEvent($sender,$param)
- {
- switch(strtolower($param->getCommandName()))
- {
- case 'edit':
- return $this->showEditView($sender, $param);
- case 'new':
- return $this->showAddView($sender, $param);
- default:
- return $this->showListView($sender, $param);
- }
- return false;
- }
-
- /**
- * Shows the edit record view.
- */
- protected function showEditView($sender, $param)
- {
- $this->getListView()->setVisible(false);
- $this->getEditView()->setVisible(true);
- $this->_panForNewButton->setVisible(false);
- $this->_panForSearch->setVisible(false);
- $this->getEditView()->getCancelButton()->setVisible(true);
- $this->getEditView()->getClearButton()->setVisible(false);
- }
-
- /**
- * Shows the view for listing the records.
- */
- protected function showListView($sender, $param)
- {
- $this->getListView()->setVisible(true);
- $this->getEditView()->setVisible(false);
- $this->_panForNewButton->setVisible(true);
- $this->_panForSearch->setVisible(true);
- }
-
- /**
- * Shows the add record view.
- */
- protected function showAddView($sender, $param)
- {
- $this->getEditView()->setRecordPk(null);
- $this->getEditView()->initializeEditForm();
- $this->showEditView($sender, $param);
- }
-}
-
+<?php
+/**
+ * TScaffoldView class.
+ *
+ * @author Wei Zhuo <weizhuo[at]gmail[dot]com>
+ * @link http://www.pradosoft.com/
+ * @copyright Copyright &copy; 2005-2012 PradoSoft
+ * @license http://www.pradosoft.com/license/
+ * @version $Id$
+ * @package System.Data.ActiveRecord.Scaffold
+ */
+
+/**
+ * Import scaffold base, list, edit and search controls.
+ */
+Prado::using('System.Data.ActiveRecord.Scaffold.TScaffoldBase');
+Prado::using('System.Data.ActiveRecord.Scaffold.TScaffoldListView');
+Prado::using('System.Data.ActiveRecord.Scaffold.TScaffoldEditView');
+Prado::using('System.Data.ActiveRecord.Scaffold.TScaffoldSearch');
+
+/**
+ * TScaffoldView is a composite control consisting of TScaffoldListView
+ * with a TScaffoldSearch. In addition, it will display a TScaffoldEditView
+ * when an "edit" command is raised from the TScaffoldListView (when the
+ * edit button is clicked). Futher more, the "add" button can be clicked
+ * that shows an empty data TScaffoldListView for creating new records.
+ *
+ * The {@link getListView ListView} property gives a TScaffoldListView for
+ * display the record data. The {@link getEditView EditView} is the
+ * TScaffoldEditView that renders the
+ * inputs for editing and adding records. The {@link getSearchControl SearchControl}
+ * is a TScaffoldSearch responsible to the search user interface.
+ *
+ * Set the {@link setRecordClass RecordClass} property to the name of
+ * the Active Record class to be displayed/edited/added.
+ *
+ * @author Wei Zhuo <weizhuo[at]gmail[dot]com>
+ * @version $Id$
+ * @package System.Data.ActiveRecord.Scaffold
+ * @since 3.0
+ */
+class TScaffoldView extends TScaffoldBase
+{
+ /**
+ * Copy basic record details to the list/edit/search controls.
+ */
+ public function onPreRender($param)
+ {
+ parent::onPreRender($param);
+ $this->getListView()->copyFrom($this);
+ $this->getEditView()->copyFrom($this);
+ $this->getSearchControl()->copyFrom($this);
+ }
+
+ /**
+ * @return TScaffoldListView scaffold list view.
+ */
+ public function getListView()
+ {
+ $this->ensureChildControls();
+ return $this->getRegisteredObject('_listView');
+ }
+
+ /**
+ * @return TScaffoldEditView scaffold edit view.
+ */
+ public function getEditView()
+ {
+ $this->ensureChildControls();
+ return $this->getRegisteredObject('_editView');
+ }
+
+ /**
+ * @return TScaffoldSearch scaffold search textbox and button.
+ */
+ public function getSearchControl()
+ {
+ $this->ensureChildControls();
+ return $this->getRegisteredObject('_search');
+ }
+
+ /**
+ * @return TButton "Add new record" button.
+ */
+ public function getAddButton()
+ {
+ $this->ensureChildControls();
+ return $this->getRegisteredObject('_newButton');
+ }
+
+ /**
+ * Handle the "edit" and "new" commands by displaying the edit view.
+ * Default command shows the list view.
+ */
+ public function bubbleEvent($sender,$param)
+ {
+ switch(strtolower($param->getCommandName()))
+ {
+ case 'edit':
+ return $this->showEditView($sender, $param);
+ case 'new':
+ return $this->showAddView($sender, $param);
+ default:
+ return $this->showListView($sender, $param);
+ }
+ return false;
+ }
+
+ /**
+ * Shows the edit record view.
+ */
+ protected function showEditView($sender, $param)
+ {
+ $this->getListView()->setVisible(false);
+ $this->getEditView()->setVisible(true);
+ $this->_panForNewButton->setVisible(false);
+ $this->_panForSearch->setVisible(false);
+ $this->getEditView()->getCancelButton()->setVisible(true);
+ $this->getEditView()->getClearButton()->setVisible(false);
+ }
+
+ /**
+ * Shows the view for listing the records.
+ */
+ protected function showListView($sender, $param)
+ {
+ $this->getListView()->setVisible(true);
+ $this->getEditView()->setVisible(false);
+ $this->_panForNewButton->setVisible(true);
+ $this->_panForSearch->setVisible(true);
+ }
+
+ /**
+ * Shows the add record view.
+ */
+ protected function showAddView($sender, $param)
+ {
+ $this->getEditView()->setRecordPk(null);
+ $this->getEditView()->initializeEditForm();
+ $this->showEditView($sender, $param);
+ }
+}
+
diff --git a/framework/Data/ActiveRecord/TActiveRecordConfig.php b/framework/Data/ActiveRecord/TActiveRecordConfig.php
index 478786d3..821c4223 100644
--- a/framework/Data/ActiveRecord/TActiveRecordConfig.php
+++ b/framework/Data/ActiveRecord/TActiveRecordConfig.php
@@ -1,201 +1,201 @@
-<?php
-/**
- * TActiveRecordConfig class file.
- *
- * @author Wei Zhuo <weizhuo[at]gmail[dot]com>
- * @link http://www.pradosoft.com/
+<?php
+/**
+ * TActiveRecordConfig class file.
+ *
+ * @author Wei Zhuo <weizhuo[at]gmail[dot]com>
+ * @link http://www.pradosoft.com/
* @copyright Copyright &copy; 2005-2012 PradoSoft
- * @license http://www.pradosoft.com/license/
- * @version $Id$
- * @package System.Data.ActiveRecord
- */
-
-Prado::using('System.Data.TDataSourceConfig');
-Prado::using('System.Data.ActiveRecord.TActiveRecordManager');
-
-/**
- * TActiveRecordConfig module configuration class.
- *
- * Database configuration for the default ActiveRecord manager instance.
- *
- * Example: application.xml configuration
- * <code>
- * <modules>
- * <module class="System.Data.ActiveRecord.TActiveRecordConfig" EnableCache="true">
- * <database ConnectionString="mysql:host=localhost;dbname=test"
- * Username="dbuser" Password="dbpass" />
- * </module>
- * </modules>
- * </code>
- *
- * MySQL database definition:
- * <code>
- * CREATE TABLE `blogs` (
- * `blog_id` int(10) unsigned NOT NULL auto_increment,
- * `blog_name` varchar(255) NOT NULL,
- * `blog_author` varchar(255) NOT NULL,
- * PRIMARY KEY (`blog_id`)
- * ) ENGINE=InnoDB DEFAULT CHARSET=utf8;
- * </code>
- *
- * Record php class:
- * <code>
- * class Blogs extends TActiveRecord
- * {
- * public $blog_id;
- * public $blog_name;
- * public $blog_author;
- *
- * public static function finder($className=__CLASS__)
- * {
- * return parent::finder($className);
- * }
- * }
- * </code>
- *
- * Usage example:
- * <code>
- * class Home extends TPage
- * {
- * function onLoad($param)
- * {
- * $blogs = Blogs::finder()->findAll();
- * print_r($blogs);
- * }
- * }
- * </code>
- *
- * @author Wei Zhuo <weizho[at]gmail[dot]com>
- * @version $Id$
- * @package System.Data.ActiveRecord
- * @since 3.1
- */
-class TActiveRecordConfig extends TDataSourceConfig
-{
- const DEFAULT_MANAGER_CLASS = 'System.Data.ActiveRecord.TActiveRecordManager';
- const DEFAULT_GATEWAY_CLASS = 'System.Data.ActiveRecord.TActiveRecordGateway';
-
- /**
- * Defaults to {@link TActiveRecordConfig::DEFAULT_GATEWAY_CLASS DEFAULT_MANAGER_CLASS}
- * @var string
- */
- private $_managerClass = self::DEFAULT_MANAGER_CLASS;
-
- /**
- * Defaults to {@link TActiveRecordConfig::DEFAULT_GATEWAY_CLASS DEFAULT_GATEWAY_CLASS}
- * @var string
- */
- private $_gatewayClass = self::DEFAULT_GATEWAY_CLASS;
-
- /**
- * @var TActiveRecordManager
- */
- private $_manager = null;
-
- private $_enableCache=false;
-
- /**
- * Defaults to '{@link TActiveRecordInvalidFinderResult::Null Null}'
- *
- * @var TActiveRecordInvalidFinderResult
- * @since 3.1.5
- */
- private $_invalidFinderResult = TActiveRecordInvalidFinderResult::Null;
-
- /**
- * Initialize the active record manager.
- * @param TXmlDocument xml configuration.
- */
- public function init($xml)
- {
- parent::init($xml);
- $manager = $this -> getManager();
- if($this->getEnableCache())
- $manager->setCache($this->getApplication()->getCache());
- $manager->setDbConnection($this->getDbConnection());
- $manager->setInvalidFinderResult($this->getInvalidFinderResult());
- $manager->setGatewayClass($this->getGatewayClass());
- }
-
- /**
- * @return TActiveRecordManager
- */
- public function getManager() {
- if($this->_manager === null)
- $this->_manager = Prado::createComponent($this -> getManagerClass());
- return TActiveRecordManager::getInstance($this->_manager);
- }
-
- /**
- * Set implementation class of ActiveRecordManager
- * @param string $value
- */
- public function setManagerClass($value)
- {
- $this->_managerClass = TPropertyValue::ensureString($value);
- }
-
- /**
- * @return string the implementation class of ActiveRecordManager. Defaults to {@link TActiveRecordConfig::DEFAULT_GATEWAY_CLASS DEFAULT_MANAGER_CLASS}
- */
- public function getManagerClass()
- {
- return $this->_managerClass;
- }
-
- /**
- * Set implementation class of ActiveRecordGateway
- * @param string $value
- */
- public function setGatewayClass($value)
- {
- $this->_gatewayClass = TPropertyValue::ensureString($value);
- }
-
- /**
- * @return string the implementation class of ActiveRecordGateway. Defaults to {@link TActiveRecordConfig::DEFAULT_GATEWAY_CLASS DEFAULT_GATEWAY_CLASS}
- */
- public function getGatewayClass()
- {
- return $this->_gatewayClass;
- }
-
- /**
- * Set true to cache the table meta data.
- * @param boolean true to cache sqlmap instance.
- */
- public function setEnableCache($value)
- {
- $this->_enableCache = TPropertyValue::ensureBoolean($value);
- }
-
- /**
- * @return boolean true if table meta data should be cached, false otherwise.
- */
- public function getEnableCache()
- {
- return $this->_enableCache;
- }
-
- /**
- * @return TActiveRecordInvalidFinderResult Defaults to '{@link TActiveRecordInvalidFinderResult::Null Null}'.
- * @see setInvalidFinderResult
- * @since 3.1.5
- */
- public function getInvalidFinderResult()
- {
- return $this->_invalidFinderResult;
- }
-
- /**
- * Define the way an active record finder react if an invalid magic-finder invoked
- *
- * @param TActiveRecordInvalidFinderResult
- * @see getInvalidFinderResult
- * @since 3.1.5
- */
- public function setInvalidFinderResult($value)
- {
- $this->_invalidFinderResult = TPropertyValue::ensureEnum($value, 'TActiveRecordInvalidFinderResult');
- }
-}
+ * @license http://www.pradosoft.com/license/
+ * @version $Id$
+ * @package System.Data.ActiveRecord
+ */
+
+Prado::using('System.Data.TDataSourceConfig');
+Prado::using('System.Data.ActiveRecord.TActiveRecordManager');
+
+/**
+ * TActiveRecordConfig module configuration class.
+ *
+ * Database configuration for the default ActiveRecord manager instance.
+ *
+ * Example: application.xml configuration
+ * <code>
+ * <modules>
+ * <module class="System.Data.ActiveRecord.TActiveRecordConfig" EnableCache="true">
+ * <database ConnectionString="mysql:host=localhost;dbname=test"
+ * Username="dbuser" Password="dbpass" />
+ * </module>
+ * </modules>
+ * </code>
+ *
+ * MySQL database definition:
+ * <code>
+ * CREATE TABLE `blogs` (
+ * `blog_id` int(10) unsigned NOT NULL auto_increment,
+ * `blog_name` varchar(255) NOT NULL,
+ * `blog_author` varchar(255) NOT NULL,
+ * PRIMARY KEY (`blog_id`)
+ * ) ENGINE=InnoDB DEFAULT CHARSET=utf8;
+ * </code>
+ *
+ * Record php class:
+ * <code>
+ * class Blogs extends TActiveRecord
+ * {
+ * public $blog_id;
+ * public $blog_name;
+ * public $blog_author;
+ *
+ * public static function finder($className=__CLASS__)
+ * {
+ * return parent::finder($className);
+ * }
+ * }
+ * </code>
+ *
+ * Usage example:
+ * <code>
+ * class Home extends TPage
+ * {
+ * function onLoad($param)
+ * {
+ * $blogs = Blogs::finder()->findAll();
+ * print_r($blogs);
+ * }
+ * }
+ * </code>
+ *
+ * @author Wei Zhuo <weizho[at]gmail[dot]com>
+ * @version $Id$
+ * @package System.Data.ActiveRecord
+ * @since 3.1
+ */
+class TActiveRecordConfig extends TDataSourceConfig
+{
+ const DEFAULT_MANAGER_CLASS = 'System.Data.ActiveRecord.TActiveRecordManager';
+ const DEFAULT_GATEWAY_CLASS = 'System.Data.ActiveRecord.TActiveRecordGateway';
+
+ /**
+ * Defaults to {@link TActiveRecordConfig::DEFAULT_GATEWAY_CLASS DEFAULT_MANAGER_CLASS}
+ * @var string
+ */
+ private $_managerClass = self::DEFAULT_MANAGER_CLASS;
+
+ /**
+ * Defaults to {@link TActiveRecordConfig::DEFAULT_GATEWAY_CLASS DEFAULT_GATEWAY_CLASS}
+ * @var string
+ */
+ private $_gatewayClass = self::DEFAULT_GATEWAY_CLASS;
+
+ /**
+ * @var TActiveRecordManager
+ */
+ private $_manager = null;
+
+ private $_enableCache=false;
+
+ /**
+ * Defaults to '{@link TActiveRecordInvalidFinderResult::Null Null}'
+ *
+ * @var TActiveRecordInvalidFinderResult
+ * @since 3.1.5
+ */
+ private $_invalidFinderResult = TActiveRecordInvalidFinderResult::Null;
+
+ /**
+ * Initialize the active record manager.
+ * @param TXmlDocument xml configuration.
+ */
+ public function init($xml)
+ {
+ parent::init($xml);
+ $manager = $this -> getManager();
+ if($this->getEnableCache())
+ $manager->setCache($this->getApplication()->getCache());
+ $manager->setDbConnection($this->getDbConnection());
+ $manager->setInvalidFinderResult($this->getInvalidFinderResult());
+ $manager->setGatewayClass($this->getGatewayClass());
+ }
+
+ /**
+ * @return TActiveRecordManager
+ */
+ public function getManager() {
+ if($this->_manager === null)
+ $this->_manager = Prado::createComponent($this -> getManagerClass());
+ return TActiveRecordManager::getInstance($this->_manager);
+ }
+
+ /**
+ * Set implementation class of ActiveRecordManager
+ * @param string $value
+ */
+ public function setManagerClass($value)
+ {
+ $this->_managerClass = TPropertyValue::ensureString($value);
+ }
+
+ /**
+ * @return string the implementation class of ActiveRecordManager. Defaults to {@link TActiveRecordConfig::DEFAULT_GATEWAY_CLASS DEFAULT_MANAGER_CLASS}
+ */
+ public function getManagerClass()
+ {
+ return $this->_managerClass;
+ }
+
+ /**
+ * Set implementation class of ActiveRecordGateway
+ * @param string $value
+ */
+ public function setGatewayClass($value)
+ {
+ $this->_gatewayClass = TPropertyValue::ensureString($value);
+ }
+
+ /**
+ * @return string the implementation class of ActiveRecordGateway. Defaults to {@link TActiveRecordConfig::DEFAULT_GATEWAY_CLASS DEFAULT_GATEWAY_CLASS}
+ */
+ public function getGatewayClass()
+ {
+ return $this->_gatewayClass;
+ }
+
+ /**
+ * Set true to cache the table meta data.
+ * @param boolean true to cache sqlmap instance.
+ */
+ public function setEnableCache($value)
+ {
+ $this->_enableCache = TPropertyValue::ensureBoolean($value);
+ }
+
+ /**
+ * @return boolean true if table meta data should be cached, false otherwise.
+ */
+ public function getEnableCache()
+ {
+ return $this->_enableCache;
+ }
+
+ /**
+ * @return TActiveRecordInvalidFinderResult Defaults to '{@link TActiveRecordInvalidFinderResult::Null Null}'.
+ * @see setInvalidFinderResult
+ * @since 3.1.5
+ */
+ public function getInvalidFinderResult()
+ {
+ return $this->_invalidFinderResult;
+ }
+
+ /**
+ * Define the way an active record finder react if an invalid magic-finder invoked
+ *
+ * @param TActiveRecordInvalidFinderResult
+ * @see getInvalidFinderResult
+ * @since 3.1.5
+ */
+ public function setInvalidFinderResult($value)
+ {
+ $this->_invalidFinderResult = TPropertyValue::ensureEnum($value, 'TActiveRecordInvalidFinderResult');
+ }
+}
diff --git a/framework/Data/ActiveRecord/TActiveRecordCriteria.php b/framework/Data/ActiveRecord/TActiveRecordCriteria.php
index d15f83ee..cdd7f964 100644
--- a/framework/Data/ActiveRecord/TActiveRecordCriteria.php
+++ b/framework/Data/ActiveRecord/TActiveRecordCriteria.php
@@ -1,39 +1,39 @@
<?php
-/**
- * TActiveRecordCriteria class file.
- *
- * @author Wei Zhuo <weizhuo[at]gmail[dot]com>
- * @link http://www.pradosoft.com/
+/**
+ * TActiveRecordCriteria class file.
+ *
+ * @author Wei Zhuo <weizhuo[at]gmail[dot]com>
+ * @link http://www.pradosoft.com/
* @copyright Copyright &copy; 2005-2012 PradoSoft
- * @license http://www.pradosoft.com/license/
- * @version $Id$
- * @package System.Data.ActiveRecord
- */
-
-Prado::using('System.Data.DataGateway.TSqlCriteria');
-
-/**
- * Search criteria for Active Record.
- *
- * Criteria object for active record finder methods. Usage:
- * <code>
- * $criteria = new TActiveRecordCriteria;
- * $criteria->Condition = 'username = :name AND password = :pass';
- * $criteria->Parameters[':name'] = 'admin';
- * $criteria->Parameters[':pass'] = 'prado';
- * $criteria->OrdersBy['level'] = 'desc';
- * $criteria->OrdersBy['name'] = 'asc';
- * $criteria->Limit = 10;
- * $criteria->Offset = 20;
- * </code>
- *
- * @author Wei Zhuo <weizho[at]gmail[dot]com>
- * @version $Id$
- * @package System.Data.ActiveRecord
- * @since 3.1
- */
-class TActiveRecordCriteria extends TSqlCriteria
-{
-
-}
+ * @license http://www.pradosoft.com/license/
+ * @version $Id$
+ * @package System.Data.ActiveRecord
+ */
+
+Prado::using('System.Data.DataGateway.TSqlCriteria');
+
+/**
+ * Search criteria for Active Record.
+ *
+ * Criteria object for active record finder methods. Usage:
+ * <code>
+ * $criteria = new TActiveRecordCriteria;
+ * $criteria->Condition = 'username = :name AND password = :pass';
+ * $criteria->Parameters[':name'] = 'admin';
+ * $criteria->Parameters[':pass'] = 'prado';
+ * $criteria->OrdersBy['level'] = 'desc';
+ * $criteria->OrdersBy['name'] = 'asc';
+ * $criteria->Limit = 10;
+ * $criteria->Offset = 20;
+ * </code>
+ *
+ * @author Wei Zhuo <weizho[at]gmail[dot]com>
+ * @version $Id$
+ * @package System.Data.ActiveRecord
+ * @since 3.1
+ */
+class TActiveRecordCriteria extends TSqlCriteria
+{
+
+}
diff --git a/framework/Data/ActiveRecord/TActiveRecordManager.php b/framework/Data/ActiveRecord/TActiveRecordManager.php
index 00979d1c..6cca76e7 100644
--- a/framework/Data/ActiveRecord/TActiveRecordManager.php
+++ b/framework/Data/ActiveRecord/TActiveRecordManager.php
@@ -1,163 +1,163 @@
-<?php
-/**
- * TActiveRecordManager class file.
- *
- * @author Wei Zhuo <weizhuo[at]gmail[dot]com>
- * @link http://www.pradosoft.com/
+<?php
+/**
+ * TActiveRecordManager class file.
+ *
+ * @author Wei Zhuo <weizhuo[at]gmail[dot]com>
+ * @link http://www.pradosoft.com/
* @copyright Copyright &copy; 2005-2012 PradoSoft
- * @license http://www.pradosoft.com/license/
- * @version $Id$
- * @package System.Data.ActiveRecord
- */
-
-Prado::using('System.Data.TDbConnection');
-Prado::using('System.Data.ActiveRecord.TActiveRecord');
-Prado::using('System.Data.ActiveRecord.Exceptions.TActiveRecordException');
-Prado::using('System.Data.ActiveRecord.TActiveRecordGateway');
-
-/**
- * TActiveRecordManager provides the default DB connection,
- * default active record gateway, and table meta data inspector.
- *
- * The default connection can be set as follows:
- * <code>
- * TActiveRecordManager::getInstance()->setDbConnection($conn);
- * </code>
- * All new active record created after setting the
- * {@link DbConnection setDbConnection()} will use that connection unless
- * the custom ActiveRecord class overrides the ActiveRecord::getDbConnection().
- *
- * Set the {@link setCache Cache} property to an ICache object to allow
- * the active record gateway to cache the table meta data information.
- *
- * @author Wei Zhuo <weizho[at]gmail[dot]com>
- * @version $Id$
- * @package System.Data.ActiveRecord
- * @since 3.1
- */
-class TActiveRecordManager extends TComponent
-{
- const DEFAULT_GATEWAY_CLASS = 'System.Data.ActiveRecord.TActiveRecordGateway';
-
- /**
- * Defaults to {@link TActiveRecordManager::DEFAULT_GATEWAY_CLASS DEFAULT_GATEWAY_CLASS}
- * @var string
- */
- private $_gatewayClass = self::DEFAULT_GATEWAY_CLASS;
-
- private $_gateway;
- private $_meta=array();
- private $_connection;
-
- private $_cache;
-
- /**
- * Defaults to '{@link TActiveRecordInvalidFinderResult::Null Null}'
- *
- * @var TActiveRecordInvalidFinderResult
- * @since 3.1.5
- */
- private $_invalidFinderResult = TActiveRecordInvalidFinderResult::Null;
-
- /**
- * @return ICache application cache.
- */
- public function getCache()
- {
- return $this->_cache;
- }
-
- /**
- * @param ICache application cache
- */
- public function setCache($value)
- {
- $this->_cache=$value;
- }
-
- /**
- * @param TDbConnection default database connection
- */
- public function setDbConnection($conn)
- {
- $this->_connection=$conn;
- }
-
- /**
- * @return TDbConnection default database connection
- */
- public function getDbConnection()
- {
- return $this->_connection;
- }
-
- /**
- * @return TActiveRecordManager static instance of record manager.
- */
- public static function getInstance($self=null)
- {
- static $instance;
- if($self!==null)
- $instance=$self;
- else if($instance===null)
- $instance = new self;
- return $instance;
- }
-
- /**
- * @return TActiveRecordGateway record gateway.
- */
- public function getRecordGateway()
- {
- if($this->_gateway === null) {
- $this->_gateway = $this->createRecordGateway();
- }
- return $this->_gateway;
- }
-
- /**
- * @return TActiveRecordGateway default record gateway.
- */
- protected function createRecordGateway()
- {
- return Prado::createComponent($this->getGatewayClass(), $this);
- }
-
- /**
- * Set implementation class of ActiveRecordGateway
- * @param string $value
- */
- public function setGatewayClass($value)
- {
- $this->_gatewayClass = (string)$value;
- }
-
- /**
- * @return string the implementation class of ActiveRecordGateway. Defaults to {@link TActiveRecordManager::DEFAULT_GATEWAY_CLASS DEFAULT_GATEWAY_CLASS}
- */
- public function getGatewayClass()
- {
- return $this->_gatewayClass;
- }
-
- /**
- * @return TActiveRecordInvalidFinderResult Defaults to '{@link TActiveRecordInvalidFinderResult::Null Null}'.
- * @since 3.1.5
- * @see setInvalidFinderResult
- */
- public function getInvalidFinderResult()
- {
- return $this->_invalidFinderResult;
- }
-
- /**
- * Define the way an active record finder react if an invalid magic-finder invoked
- * @param TActiveRecordInvalidFinderResult
- * @since 3.1.5
- * @see getInvalidFinderResult
- */
- public function setInvalidFinderResult($value)
- {
- $this->_invalidFinderResult = TPropertyValue::ensureEnum($value, 'TActiveRecordInvalidFinderResult');
- }
-}
+ * @license http://www.pradosoft.com/license/
+ * @version $Id$
+ * @package System.Data.ActiveRecord
+ */
+
+Prado::using('System.Data.TDbConnection');
+Prado::using('System.Data.ActiveRecord.TActiveRecord');
+Prado::using('System.Data.ActiveRecord.Exceptions.TActiveRecordException');
+Prado::using('System.Data.ActiveRecord.TActiveRecordGateway');
+
+/**
+ * TActiveRecordManager provides the default DB connection,
+ * default active record gateway, and table meta data inspector.
+ *
+ * The default connection can be set as follows:
+ * <code>
+ * TActiveRecordManager::getInstance()->setDbConnection($conn);
+ * </code>
+ * All new active record created after setting the
+ * {@link DbConnection setDbConnection()} will use that connection unless
+ * the custom ActiveRecord class overrides the ActiveRecord::getDbConnection().
+ *
+ * Set the {@link setCache Cache} property to an ICache object to allow
+ * the active record gateway to cache the table meta data information.
+ *
+ * @author Wei Zhuo <weizho[at]gmail[dot]com>
+ * @version $Id$
+ * @package System.Data.ActiveRecord
+ * @since 3.1
+ */
+class TActiveRecordManager extends TComponent
+{
+ const DEFAULT_GATEWAY_CLASS = 'System.Data.ActiveRecord.TActiveRecordGateway';
+
+ /**
+ * Defaults to {@link TActiveRecordManager::DEFAULT_GATEWAY_CLASS DEFAULT_GATEWAY_CLASS}
+ * @var string
+ */
+ private $_gatewayClass = self::DEFAULT_GATEWAY_CLASS;
+
+ private $_gateway;
+ private $_meta=array();
+ private $_connection;
+
+ private $_cache;
+
+ /**
+ * Defaults to '{@link TActiveRecordInvalidFinderResult::Null Null}'
+ *
+ * @var TActiveRecordInvalidFinderResult
+ * @since 3.1.5
+ */
+ private $_invalidFinderResult = TActiveRecordInvalidFinderResult::Null;
+
+ /**
+ * @return ICache application cache.
+ */
+ public function getCache()
+ {
+ return $this->_cache;
+ }
+
+ /**
+ * @param ICache application cache
+ */
+ public function setCache($value)
+ {
+ $this->_cache=$value;
+ }
+
+ /**
+ * @param TDbConnection default database connection
+ */
+ public function setDbConnection($conn)
+ {
+ $this->_connection=$conn;
+ }
+
+ /**
+ * @return TDbConnection default database connection
+ */
+ public function getDbConnection()
+ {
+ return $this->_connection;
+ }
+
+ /**
+ * @return TActiveRecordManager static instance of record manager.
+ */
+ public static function getInstance($self=null)
+ {
+ static $instance;
+ if($self!==null)
+ $instance=$self;
+ else if($instance===null)
+ $instance = new self;
+ return $instance;
+ }
+
+ /**
+ * @return TActiveRecordGateway record gateway.
+ */
+ public function getRecordGateway()
+ {
+ if($this->_gateway === null) {
+ $this->_gateway = $this->createRecordGateway();
+ }
+ return $this->_gateway;
+ }
+
+ /**
+ * @return TActiveRecordGateway default record gateway.
+ */
+ protected function createRecordGateway()
+ {
+ return Prado::createComponent($this->getGatewayClass(), $this);
+ }
+
+ /**
+ * Set implementation class of ActiveRecordGateway
+ * @param string $value
+ */
+ public function setGatewayClass($value)
+ {
+ $this->_gatewayClass = (string)$value;
+ }
+
+ /**
+ * @return string the implementation class of ActiveRecordGateway. Defaults to {@link TActiveRecordManager::DEFAULT_GATEWAY_CLASS DEFAULT_GATEWAY_CLASS}
+ */
+ public function getGatewayClass()
+ {
+ return $this->_gatewayClass;
+ }
+
+ /**
+ * @return TActiveRecordInvalidFinderResult Defaults to '{@link TActiveRecordInvalidFinderResult::Null Null}'.
+ * @since 3.1.5
+ * @see setInvalidFinderResult
+ */
+ public function getInvalidFinderResult()
+ {
+ return $this->_invalidFinderResult;
+ }
+
+ /**
+ * Define the way an active record finder react if an invalid magic-finder invoked
+ * @param TActiveRecordInvalidFinderResult
+ * @since 3.1.5
+ * @see getInvalidFinderResult
+ */
+ public function setInvalidFinderResult($value)
+ {
+ $this->_invalidFinderResult = TPropertyValue::ensureEnum($value, 'TActiveRecordInvalidFinderResult');
+ }
+}
diff --git a/framework/Data/Common/Mssql/TMssqlCommandBuilder.php b/framework/Data/Common/Mssql/TMssqlCommandBuilder.php
index 8a1e4dd6..3485adaa 100644
--- a/framework/Data/Common/Mssql/TMssqlCommandBuilder.php
+++ b/framework/Data/Common/Mssql/TMssqlCommandBuilder.php
@@ -1,173 +1,173 @@
-<?php
-/**
- * TMsssqlCommandBuilder class file.
- *
- * @author Wei Zhuo <weizhuo[at]gmail[dot]com>
- * @link http://www.pradosoft.com/
- * @copyright Copyright &copy; 2005-2012 PradoSoft
- * @license http://www.pradosoft.com/license/
- * @version $Id: TDbCommandBuilder.php 1863 2007-04-12 12:43:49Z wei $
- * @package System.Data.Common
- */
-
-Prado::using('System.Data.Common.TDbCommandBuilder');
-
-/**
- * TMssqlCommandBuilder provides specifics methods to create limit/offset query commands
- * for MSSQL servers.
- *
- * @author Wei Zhuo <weizho[at]gmail[dot]com>
- * @version $Id: TDbCommandBuilder.php 1863 2007-04-12 12:43:49Z wei $
- * @package System.Data.Common
- * @since 3.1
- */
-class TMssqlCommandBuilder extends TDbCommandBuilder
-{
- /**
- * Overrides parent implementation. Uses "SELECT @@Identity".
- * @return integer last insert id, null if none is found.
- */
- public function getLastInsertID()
- {
- foreach($this->getTableInfo()->getColumns() as $column)
- {
- if($column->hasSequence())
- {
- $command = $this->getDbConnection()->createCommand('SELECT @@Identity');
- return intval($command->queryScalar());
- }
- }
- }
-
- /**
- * Overrides parent implementation. Alters the sql to apply $limit and $offset.
- * The idea for limit with offset is done by modifying the sql on the fly
- * with numerous assumptions on the structure of the sql string.
- * The modification is done with reference to the notes from
- * http://troels.arvin.dk/db/rdbms/#select-limit-offset
- *
- * <code>
- * SELECT * FROM (
- * SELECT TOP n * FROM (
- * SELECT TOP z columns -- (z=n+skip)
- * FROM tablename
- * ORDER BY key ASC
- * ) AS FOO ORDER BY key DESC -- ('FOO' may be anything)
- * ) AS BAR ORDER BY key ASC -- ('BAR' may be anything)
- * </code>
- *
- * <b>Regular expressions are used to alter the SQL query. The resulting SQL query
- * may be malformed for complex queries.</b> The following restrictions apply
- *
- * <ul>
- * <li>
- * In particular, <b>commas</b> should <b>NOT</b>
- * be used as part of the ordering expression or identifier. Commas must only be
- * used for separating the ordering clauses.
- * </li>
- * <li>
- * In the ORDER BY clause, the column name should NOT be be qualified
- * with a table name or view name. Alias the column names or use column index.
- * </li>
- * <li>
- * No clauses should follow the ORDER BY clause, e.g. no COMPUTE or FOR clauses.
- * </li>
- * </ul>
- *
- * @param string SQL query string.
- * @param integer maximum number of rows, -1 to ignore limit.
- * @param integer row offset, -1 to ignore offset.
- * @return string SQL with limit and offset.
- */
- public function applyLimitOffset($sql, $limit=-1, $offset=-1)
- {
- $limit = $limit!==null ? intval($limit) : -1;
- $offset = $offset!==null ? intval($offset) : -1;
- if ($limit > 0 && $offset <= 0) //just limit
- $sql = preg_replace('/^([\s(])*SELECT( DISTINCT)?(?!\s*TOP\s*\()/i',"\\1SELECT\\2 TOP $limit", $sql);
- else if($limit > 0 && $offset > 0)
- $sql = $this->rewriteLimitOffsetSql($sql, $limit,$offset);
- return $sql;
- }
-
- /**
- * Rewrite sql to apply $limit > and $offset > 0 for MSSQL database.
- * See http://troels.arvin.dk/db/rdbms/#select-limit-offset
- * @param string sql query
- * @param integer $limit > 0
- * @param integer $offset > 0
- * @return sql modified sql query applied with limit and offset.
- */
- protected function rewriteLimitOffsetSql($sql, $limit, $offset)
- {
- $fetch = $limit+$offset;
- $sql = preg_replace('/^([\s(])*SELECT( DISTINCT)?(?!\s*TOP\s*\()/i',"\\1SELECT\\2 TOP $fetch", $sql);
- $ordering = $this->findOrdering($sql);
-
- $orginalOrdering = $this->joinOrdering($ordering);
- $reverseOrdering = $this->joinOrdering($this->reverseDirection($ordering));
- $sql = "SELECT * FROM (SELECT TOP {$limit} * FROM ($sql) as [__inner top table__] {$reverseOrdering}) as [__outer top table__] {$orginalOrdering}";
- return $sql;
- }
-
- /**
- * Base on simplified syntax http://msdn2.microsoft.com/en-us/library/aa259187(SQL.80).aspx
- *
- * @param string $sql
- * @return array ordering expression as key and ordering direction as value
- */
- protected function findOrdering($sql)
- {
- if(!preg_match('/ORDER BY/i', $sql))
- return array();
- $matches=array();
- $ordering=array();
- preg_match_all('/(ORDER BY)[\s"\[](.*)(ASC|DESC)?(?:[\s"\[]|$|COMPUTE|FOR)/i', $sql, $matches);
- if(count($matches)>1 && count($matches[2]) > 0)
- {
- $parts = explode(',', $matches[2][0]);
- foreach($parts as $part)
- {
- $subs=array();
- if(preg_match_all('/(.*)[\s"\]](ASC|DESC)$/i', trim($part), $subs))
- {
- if(count($subs) > 1 && count($subs[2]) > 0)
- {
- $ordering[$subs[1][0]] = $subs[2][0];
- }
- //else what?
- }
- else
- $ordering[trim($part)] = 'ASC';
- }
- }
- return $ordering;
- }
-
- /**
- * @param array ordering obtained from findOrdering()
- * @return string concat the orderings
- */
- protected function joinOrdering($orders)
- {
- if(count($orders)>0)
- {
- $str=array();
- foreach($orders as $column => $direction)
- $str[] = $column.' '.$direction;
- return 'ORDER BY '.implode(', ', $str);
- }
- }
-
- /**
- * @param array original ordering
- * @return array ordering with reversed direction.
- */
- protected function reverseDirection($orders)
- {
- foreach($orders as $column => $direction)
- $orders[$column] = strtolower(trim($direction))==='desc' ? 'ASC' : 'DESC';
- return $orders;
- }
-}
-
+<?php
+/**
+ * TMsssqlCommandBuilder class file.
+ *
+ * @author Wei Zhuo <weizhuo[at]gmail[dot]com>
+ * @link http://www.pradosoft.com/
+ * @copyright Copyright &copy; 2005-2012 PradoSoft
+ * @license http://www.pradosoft.com/license/
+ * @version $Id: TDbCommandBuilder.php 1863 2007-04-12 12:43:49Z wei $
+ * @package System.Data.Common
+ */
+
+Prado::using('System.Data.Common.TDbCommandBuilder');
+
+/**
+ * TMssqlCommandBuilder provides specifics methods to create limit/offset query commands
+ * for MSSQL servers.
+ *
+ * @author Wei Zhuo <weizho[at]gmail[dot]com>
+ * @version $Id: TDbCommandBuilder.php 1863 2007-04-12 12:43:49Z wei $
+ * @package System.Data.Common
+ * @since 3.1
+ */
+class TMssqlCommandBuilder extends TDbCommandBuilder
+{
+ /**
+ * Overrides parent implementation. Uses "SELECT @@Identity".
+ * @return integer last insert id, null if none is found.
+ */
+ public function getLastInsertID()
+ {
+ foreach($this->getTableInfo()->getColumns() as $column)
+ {
+ if($column->hasSequence())
+ {
+ $command = $this->getDbConnection()->createCommand('SELECT @@Identity');
+ return intval($command->queryScalar());
+ }
+ }
+ }
+
+ /**
+ * Overrides parent implementation. Alters the sql to apply $limit and $offset.
+ * The idea for limit with offset is done by modifying the sql on the fly
+ * with numerous assumptions on the structure of the sql string.
+ * The modification is done with reference to the notes from
+ * http://troels.arvin.dk/db/rdbms/#select-limit-offset
+ *
+ * <code>
+ * SELECT * FROM (
+ * SELECT TOP n * FROM (
+ * SELECT TOP z columns -- (z=n+skip)
+ * FROM tablename
+ * ORDER BY key ASC
+ * ) AS FOO ORDER BY key DESC -- ('FOO' may be anything)
+ * ) AS BAR ORDER BY key ASC -- ('BAR' may be anything)
+ * </code>
+ *
+ * <b>Regular expressions are used to alter the SQL query. The resulting SQL query
+ * may be malformed for complex queries.</b> The following restrictions apply
+ *
+ * <ul>
+ * <li>
+ * In particular, <b>commas</b> should <b>NOT</b>
+ * be used as part of the ordering expression or identifier. Commas must only be
+ * used for separating the ordering clauses.
+ * </li>
+ * <li>
+ * In the ORDER BY clause, the column name should NOT be be qualified
+ * with a table name or view name. Alias the column names or use column index.
+ * </li>
+ * <li>
+ * No clauses should follow the ORDER BY clause, e.g. no COMPUTE or FOR clauses.
+ * </li>
+ * </ul>
+ *
+ * @param string SQL query string.
+ * @param integer maximum number of rows, -1 to ignore limit.
+ * @param integer row offset, -1 to ignore offset.
+ * @return string SQL with limit and offset.
+ */
+ public function applyLimitOffset($sql, $limit=-1, $offset=-1)
+ {
+ $limit = $limit!==null ? intval($limit) : -1;
+ $offset = $offset!==null ? intval($offset) : -1;
+ if ($limit > 0 && $offset <= 0) //just limit
+ $sql = preg_replace('/^([\s(])*SELECT( DISTINCT)?(?!\s*TOP\s*\()/i',"\\1SELECT\\2 TOP $limit", $sql);
+ else if($limit > 0 && $offset > 0)
+ $sql = $this->rewriteLimitOffsetSql($sql, $limit,$offset);
+ return $sql;
+ }
+
+ /**
+ * Rewrite sql to apply $limit > and $offset > 0 for MSSQL database.
+ * See http://troels.arvin.dk/db/rdbms/#select-limit-offset
+ * @param string sql query
+ * @param integer $limit > 0
+ * @param integer $offset > 0
+ * @return sql modified sql query applied with limit and offset.
+ */
+ protected function rewriteLimitOffsetSql($sql, $limit, $offset)
+ {
+ $fetch = $limit+$offset;
+ $sql = preg_replace('/^([\s(])*SELECT( DISTINCT)?(?!\s*TOP\s*\()/i',"\\1SELECT\\2 TOP $fetch", $sql);
+ $ordering = $this->findOrdering($sql);
+
+ $orginalOrdering = $this->joinOrdering($ordering);
+ $reverseOrdering = $this->joinOrdering($this->reverseDirection($ordering));
+ $sql = "SELECT * FROM (SELECT TOP {$limit} * FROM ($sql) as [__inner top table__] {$reverseOrdering}) as [__outer top table__] {$orginalOrdering}";
+ return $sql;
+ }
+
+ /**
+ * Base on simplified syntax http://msdn2.microsoft.com/en-us/library/aa259187(SQL.80).aspx
+ *
+ * @param string $sql
+ * @return array ordering expression as key and ordering direction as value
+ */
+ protected function findOrdering($sql)
+ {
+ if(!preg_match('/ORDER BY/i', $sql))
+ return array();
+ $matches=array();
+ $ordering=array();
+ preg_match_all('/(ORDER BY)[\s"\[](.*)(ASC|DESC)?(?:[\s"\[]|$|COMPUTE|FOR)/i', $sql, $matches);
+ if(count($matches)>1 && count($matches[2]) > 0)
+ {
+ $parts = explode(',', $matches[2][0]);
+ foreach($parts as $part)
+ {
+ $subs=array();
+ if(preg_match_all('/(.*)[\s"\]](ASC|DESC)$/i', trim($part), $subs))
+ {
+ if(count($subs) > 1 && count($subs[2]) > 0)
+ {
+ $ordering[$subs[1][0]] = $subs[2][0];
+ }
+ //else what?
+ }
+ else
+ $ordering[trim($part)] = 'ASC';
+ }
+ }
+ return $ordering;
+ }
+
+ /**
+ * @param array ordering obtained from findOrdering()
+ * @return string concat the orderings
+ */
+ protected function joinOrdering($orders)
+ {
+ if(count($orders)>0)
+ {
+ $str=array();
+ foreach($orders as $column => $direction)
+ $str[] = $column.' '.$direction;
+ return 'ORDER BY '.implode(', ', $str);
+ }
+ }
+
+ /**
+ * @param array original ordering
+ * @return array ordering with reversed direction.
+ */
+ protected function reverseDirection($orders)
+ {
+ foreach($orders as $column => $direction)
+ $orders[$column] = strtolower(trim($direction))==='desc' ? 'ASC' : 'DESC';
+ return $orders;
+ }
+}
+
diff --git a/framework/Data/Common/Mssql/TMssqlTableColumn.php b/framework/Data/Common/Mssql/TMssqlTableColumn.php
index 5621bb6b..811d0f6e 100644
--- a/framework/Data/Common/Mssql/TMssqlTableColumn.php
+++ b/framework/Data/Common/Mssql/TMssqlTableColumn.php
@@ -1,64 +1,64 @@
-<?php
-/**
- * TMssqlTableColumn class file.
- *
- * @author Wei Zhuo <weizhuo[at]gmail[dot]com>
- * @link http://www.pradosoft.com/
+<?php
+/**
+ * TMssqlTableColumn class file.
+ *
+ * @author Wei Zhuo <weizhuo[at]gmail[dot]com>
+ * @link http://www.pradosoft.com/
* @copyright Copyright &copy; 2005-2012 PradoSoft
- * @license http://www.pradosoft.com/license/
- * @version $Id: TMssqlTableColumn.php 1863 2007-04-12 12:43:49Z wei $
- * @package System.Data.Common.Mssql
- */
-
-/**
- * Load common TDbTableCommon class.
- */
-Prado::using('System.Data.Common.TDbTableColumn');
-
-/**
- * Describes the column metadata of the schema for a Mssql database table.
- *
- * @author Wei Zhuo <weizho[at]gmail[dot]com>
- * @version $Id: TMssqlTableColumn.php 1863 2007-04-12 12:43:49Z wei $
- * @package System.Data.Common.Mssql
- * @since 3.1
- */
-class TMssqlTableColumn extends TDbTableColumn
-{
- private static $types = array();
-
- /**
- * Overrides parent implementation, returns PHP type from the db type.
- * @return boolean derived PHP primitive type from the column db type.
- */
- public function getPHPType()
- {
-
- return 'string';
- }
-
- /**
- * @return boolean true if the column has identity (auto-increment)
- */
- public function getAutoIncrement()
- {
- return $this->getInfo('AutoIncrement',false);
- }
-
- /**
- * @return boolean true if auto increments.
- */
- public function hasSequence()
- {
- return $this->getAutoIncrement();
- }
-
- /**
- * @return boolean true if db type is 'timestamp'.
- */
- public function getIsExcluded()
- {
- return strtolower($this->getDbType())==='timestamp';
- }
-}
-
+ * @license http://www.pradosoft.com/license/
+ * @version $Id: TMssqlTableColumn.php 1863 2007-04-12 12:43:49Z wei $
+ * @package System.Data.Common.Mssql
+ */
+
+/**
+ * Load common TDbTableCommon class.
+ */
+Prado::using('System.Data.Common.TDbTableColumn');
+
+/**
+ * Describes the column metadata of the schema for a Mssql database table.
+ *
+ * @author Wei Zhuo <weizho[at]gmail[dot]com>
+ * @version $Id: TMssqlTableColumn.php 1863 2007-04-12 12:43:49Z wei $
+ * @package System.Data.Common.Mssql
+ * @since 3.1
+ */
+class TMssqlTableColumn extends TDbTableColumn
+{
+ private static $types = array();
+
+ /**
+ * Overrides parent implementation, returns PHP type from the db type.
+ * @return boolean derived PHP primitive type from the column db type.
+ */
+ public function getPHPType()
+ {
+
+ return 'string';
+ }
+
+ /**
+ * @return boolean true if the column has identity (auto-increment)
+ */
+ public function getAutoIncrement()
+ {
+ return $this->getInfo('AutoIncrement',false);
+ }
+
+ /**
+ * @return boolean true if auto increments.
+ */
+ public function hasSequence()
+ {
+ return $this->getAutoIncrement();
+ }
+
+ /**
+ * @return boolean true if db type is 'timestamp'.
+ */
+ public function getIsExcluded()
+ {
+ return strtolower($this->getDbType())==='timestamp';
+ }
+}
+
diff --git a/framework/Data/Common/Mssql/TMssqlTableInfo.php b/framework/Data/Common/Mssql/TMssqlTableInfo.php
index c65e3eaa..3b48e42d 100644
--- a/framework/Data/Common/Mssql/TMssqlTableInfo.php
+++ b/framework/Data/Common/Mssql/TMssqlTableInfo.php
@@ -1,64 +1,64 @@
-<?php
-/**
- * TMssqlTableInfo class file.
- *
- * @author Wei Zhuo <weizhuo[at]gmail[dot]com>
- * @link http://www.pradosoft.com/
+<?php
+/**
+ * TMssqlTableInfo class file.
+ *
+ * @author Wei Zhuo <weizhuo[at]gmail[dot]com>
+ * @link http://www.pradosoft.com/
* @copyright Copyright &copy; 2005-2012 PradoSoft
- * @license http://www.pradosoft.com/license/
- * @version $Id: TMssqlTableInfo.php 1861 2007-04-12 08:05:03Z wei $
- * @package System.Data.Common.Mssql
- */
-
-/**
- * Loads the base TDbTableInfo class and TMssqlTableColumn class.
- */
-Prado::using('System.Data.Common.TDbTableInfo');
-Prado::using('System.Data.Common.Mssql.TMssqlTableColumn');
-
-/**
- * TMssqlTableInfo class provides additional table information for Mssql database.
- *
- * @author Wei Zhuo <weizho[at]gmail[dot]com>
- * @version $Id: TMssqlTableInfo.php 1861 2007-04-12 08:05:03Z wei $
- * @package System.Data.Common.Mssql
- * @since 3.1
- */
-class TMssqlTableInfo extends TDbTableInfo
-{
- /**
- * @return string name of the schema this column belongs to.
- */
- public function getSchemaName()
- {
- return $this->getInfo('SchemaName');
- }
-
- /**
- * @return string catalog name (database name)
- */
- public function getCatalogName()
- {
- return $this->getInfo('CatalogName');
- }
-
- /**
- * @return string full name of the table, database dependent.
- */
- public function getTableFullName()
- {
- //MSSQL alway returns the catalog, schem and table names.
- return '['.$this->getCatalogName().'].['.$this->getSchemaName().'].['.$this->getTableName().']';
- }
-
- /**
- * @param TDbConnection database connection.
- * @return TDbCommandBuilder new command builder
- */
- public function createCommandBuilder($connection)
- {
- Prado::using('System.Data.Common.Mssql.TMssqlCommandBuilder');
- return new TMssqlCommandBuilder($connection,$this);
- }
-}
-
+ * @license http://www.pradosoft.com/license/
+ * @version $Id: TMssqlTableInfo.php 1861 2007-04-12 08:05:03Z wei $
+ * @package System.Data.Common.Mssql
+ */
+
+/**
+ * Loads the base TDbTableInfo class and TMssqlTableColumn class.
+ */
+Prado::using('System.Data.Common.TDbTableInfo');
+Prado::using('System.Data.Common.Mssql.TMssqlTableColumn');
+
+/**
+ * TMssqlTableInfo class provides additional table information for Mssql database.
+ *
+ * @author Wei Zhuo <weizho[at]gmail[dot]com>
+ * @version $Id: TMssqlTableInfo.php 1861 2007-04-12 08:05:03Z wei $
+ * @package System.Data.Common.Mssql
+ * @since 3.1
+ */
+class TMssqlTableInfo extends TDbTableInfo
+{
+ /**
+ * @return string name of the schema this column belongs to.
+ */
+ public function getSchemaName()
+ {
+ return $this->getInfo('SchemaName');
+ }
+
+ /**
+ * @return string catalog name (database name)
+ */
+ public function getCatalogName()
+ {
+ return $this->getInfo('CatalogName');
+ }
+
+ /**
+ * @return string full name of the table, database dependent.
+ */
+ public function getTableFullName()
+ {
+ //MSSQL alway returns the catalog, schem and table names.
+ return '['.$this->getCatalogName().'].['.$this->getSchemaName().'].['.$this->getTableName().']';
+ }
+
+ /**
+ * @param TDbConnection database connection.
+ * @return TDbCommandBuilder new command builder
+ */
+ public function createCommandBuilder($connection)
+ {
+ Prado::using('System.Data.Common.Mssql.TMssqlCommandBuilder');
+ return new TMssqlCommandBuilder($connection,$this);
+ }
+}
+
diff --git a/framework/Data/Common/Mysql/TMysqlCommandBuilder.php b/framework/Data/Common/Mysql/TMysqlCommandBuilder.php
index fa2b2c51..58854bbc 100644
--- a/framework/Data/Common/Mysql/TMysqlCommandBuilder.php
+++ b/framework/Data/Common/Mysql/TMysqlCommandBuilder.php
@@ -1,26 +1,26 @@
-<?php
-/**
- * TMysqlCommandBuilder class file.
- *
- * @author Wei Zhuo <weizhuo[at]gmail[dot]com>
- * @link http://www.pradosoft.com/
+<?php
+/**
+ * TMysqlCommandBuilder class file.
+ *
+ * @author Wei Zhuo <weizhuo[at]gmail[dot]com>
+ * @link http://www.pradosoft.com/
* @copyright Copyright &copy; 2005-2012 PradoSoft
- * @license http://www.pradosoft.com/license/
- * @version $Id: TDbCommandBuilder.php 1863 2007-04-12 12:43:49Z wei $
- * @package System.Data.Common
- */
-
-Prado::using('System.Data.Common.TDbCommandBuilder');
-
-/**
- * TMysqlCommandBuilder implements default TDbCommandBuilder
- *
- * @author Wei Zhuo <weizho[at]gmail[dot]com>
- * @version $Id: TDbCommandBuilder.php 1863 2007-04-12 12:43:49Z wei $
- * @package System.Data.Common
- * @since 3.1
- */
-class TMysqlCommandBuilder extends TDbCommandBuilder
-{
-}
-
+ * @license http://www.pradosoft.com/license/
+ * @version $Id: TDbCommandBuilder.php 1863 2007-04-12 12:43:49Z wei $
+ * @package System.Data.Common
+ */
+
+Prado::using('System.Data.Common.TDbCommandBuilder');
+
+/**
+ * TMysqlCommandBuilder implements default TDbCommandBuilder
+ *
+ * @author Wei Zhuo <weizho[at]gmail[dot]com>
+ * @version $Id: TDbCommandBuilder.php 1863 2007-04-12 12:43:49Z wei $
+ * @package System.Data.Common
+ * @since 3.1
+ */
+class TMysqlCommandBuilder extends TDbCommandBuilder
+{
+}
+
diff --git a/framework/Data/Common/Mysql/TMysqlMetaData.php b/framework/Data/Common/Mysql/TMysqlMetaData.php
index f9824015..151111af 100644
--- a/framework/Data/Common/Mysql/TMysqlMetaData.php
+++ b/framework/Data/Common/Mysql/TMysqlMetaData.php
@@ -1,386 +1,386 @@
-<?php
-/**
- * TMysqlMetaData class file.
- *
- * @author Wei Zhuo <weizhuo[at]gmail[dot]com>
- * @link http://www.pradosoft.com/
- * @copyright Copyright &copy; 2005-2012 PradoSoft
- * @license http://www.pradosoft.com/license/
- * @version $Id$
- * @package System.Data.Common.Mysql
- */
-
-/**
- * Load the base TDbMetaData class.
- */
-Prado::using('System.Data.Common.TDbMetaData');
-Prado::using('System.Data.Common.Mysql.TMysqlTableInfo');
-
-/**
- * TMysqlMetaData loads Mysql version 4.1.x and 5.x database table and column information.
- *
- * For Mysql version 4.1.x, PHP 5.1.3 or later is required.
- * See http://netevil.org/node.php?nid=795&SC=1
- *
- * @author Wei Zhuo <weizho[at]gmail[dot]com>
- * @version $Id$
- * @package System.Data.Common.Mysql
- * @since 3.1
- */
-class TMysqlMetaData extends TDbMetaData
-{
- private $_serverVersion=0;
-
- /**
- * @return string TDbTableInfo class name.
- */
- protected function getTableInfoClass()
- {
- return 'TMysqlTableInfo';
- }
-
- /**
- * Quotes a table name for use in a query.
- * @param string $name table name
- * @return string the properly quoted table name
- */
- public function quoteTableName($name)
- {
- return parent::quoteTableName($name, '`', '`');
- }
-
- /**
- * Quotes a column name for use in a query.
- * @param string $name column name
- * @return string the properly quoted column name
- */
- public function quoteColumnName($name)
- {
- return parent::quoteColumnName($name, '`', '`');
- }
-
- /**
- * Quotes a column alias for use in a query.
- * @param string $name column alias
- * @return string the properly quoted column alias
- */
- public function quoteColumnAlias($name)
- {
- return parent::quoteColumnAlias($name, '`', '`');
- }
-
- /**
- * Get the column definitions for given table.
- * @param string table name.
- * @return TMysqlTableInfo table information.
- */
- protected function createTableInfo($table)
- {
- list($schemaName,$tableName) = $this->getSchemaTableName($table);
- $find = $schemaName===null ? "`{$tableName}`" : "`{$schemaName}`.`{$tableName}`";
- $this->getDbConnection()->setActive(true);
- $sql = "SHOW FULL FIELDS FROM {$find}";
- $command = $this->getDbConnection()->createCommand($sql);
- $tableInfo = $this->createNewTableInfo($table);
- $index=0;
- foreach($command->query() as $col)
- {
- $col['index'] = $index++;
- $this->processColumn($tableInfo,$col);
- }
- if($index===0)
- throw new TDbException('dbmetadata_invalid_table_view', $table);
- return $tableInfo;
- }
-
- /**
- * @return float server version.
- */
- protected function getServerVersion()
- {
- if(!$this->_serverVersion)
- {
- $version = $this->getDbConnection()->getAttribute(PDO::ATTR_SERVER_VERSION);
- $digits=array();
- preg_match('/(\d+)\.(\d+)\.(\d+)/', $version, $digits);
- $this->_serverVersion=floatval($digits[1].'.'.$digits[2].$digits[3]);
- }
- return $this->_serverVersion;
- }
-
- /**
- * @param TMysqlTableInfo table information.
- * @param array column information.
- */
- protected function processColumn($tableInfo, $col)
- {
- $columnId = $col['Field'];
-
- $info['ColumnName'] = "`$columnId`"; //quote the column names!
- $info['ColumnId'] = $columnId;
- $info['ColumnIndex'] = $col['index'];
- if($col['Null']==='YES')
- $info['AllowNull'] = true;
- if(is_int(strpos(strtolower($col['Extra']), 'auto_increment')))
- $info['AutoIncrement']=true;
- if($col['Default']!=="")
- $info['DefaultValue'] = $col['Default'];
-
- if($col['Key']==='PRI' || in_array($columnId, $tableInfo->getPrimaryKeys()))
- $info['IsPrimaryKey'] = true;
- if($this->isForeignKeyColumn($columnId, $tableInfo))
- $info['IsForeignKey'] = true;
-
- $info['DbType'] = $col['Type'];
- $match=array();
- //find SET/ENUM values, column size, precision, and scale
- if(preg_match('/\((.*)\)/', $col['Type'], $match))
- {
- $info['DbType']= preg_replace('/\(.*\)/', '', $col['Type']);
-
- //find SET/ENUM values
- if($this->isEnumSetType($info['DbType']))
- $info['DbTypeValues'] = preg_split("/[',]/S", $match[1], -1, PREG_SPLIT_NO_EMPTY);
-
- //find column size, precision and scale
- $pscale = array();
- if(preg_match('/(\d+)(?:,(\d+))?+/', $match[1], $pscale))
- {
- if($this->isPrecisionType($info['DbType']))
- {
- $info['NumericPrecision'] = intval($pscale[1]);
- if(count($pscale) > 2)
- $info['NumericScale'] = intval($pscale[2]);
- }
- else
- $info['ColumnSize'] = intval($pscale[1]);
- }
- }
-
- $tableInfo->Columns[$columnId] = new TMysqlTableColumn($info);
- }
-
- /**
- * @return boolean true if column type if "numeric", "interval" or begins with "time".
- */
- protected function isPrecisionType($type)
- {
- $type = strtolower(trim($type));
- return $type==='decimal' || $type==='dec'
- || $type==='float' || $type==='double'
- || $type==='double precision' || $type==='real';
- }
-
- /**
- * @return boolean true if column type if "enum" or "set".
- */
- protected function isEnumSetType($type)
- {
- $type = strtolower(trim($type));
- return $type==='set' || $type==='enum';
- }
-
- /**
- * @param string table name, may be quoted with back-ticks and may contain database name.
- * @return array tuple ($schema,$table), $schema may be null.
- * @throws TDbException when table name contains invalid identifier bytes.
- */
- protected function getSchemaTableName($table)
- {
- //remove the back ticks and separate out the "database.table"
- $result = explode('.', str_replace('`', '', $table));
- foreach($result as $name)
- {
- if(!$this->isValidIdentifier($name))
- {
- $ref = 'http://dev.mysql.com/doc/refman/5.0/en/identifiers.html';
- throw new TDbException('dbcommon_invalid_identifier_name', $table, $ref);
- }
- }
- return count($result) > 1 ? $result : array(null, $result[0]);
- }
-
- /**
- * http://dev.mysql.com/doc/refman/5.0/en/identifiers.html
- * @param string identifier name
- * @param boolean true if valid identifier.
- */
- protected function isValidIdentifier($name)
- {
- return !preg_match('#/|\\|.|\x00|\xFF#', $name);
- }
-
- /**
- * @param string table schema name
- * @param string table name.
- * @return TMysqlTableInfo
- */
- protected function createNewTableInfo($table)
- {
- list($schemaName,$tableName) = $this->getSchemaTableName($table);
- $info['SchemaName'] = $schemaName;
- $info['TableName'] = $tableName;
- if($this->getIsView($schemaName,$tableName))
- $info['IsView'] = true;
- list($primary, $foreign) = $this->getConstraintKeys($schemaName, $tableName);
- $class = $this->getTableInfoClass();
- return new $class($info,$primary,$foreign);
- }
-
- /**
- * For MySQL version 5.0.1 or later we can use SHOW FULL TABLES
- * http://dev.mysql.com/doc/refman/5.0/en/show-tables.html
- *
- * For MySQL version 5.0.1 or ealier, this always return false.
- * @param string database name, null to use default connection database.
- * @param string table or view name.
- * @return boolean true if is view, false otherwise.
- * @throws TDbException if table or view does not exist.
- */
- protected function getIsView($schemaName,$tableName)
- {
- if($this->getServerVersion()<5.01)
- return false;
- if($schemaName!==null)
- $sql = "SHOW FULL TABLES FROM `{$schemaName}` LIKE :table";
- else
- $sql = "SHOW FULL TABLES LIKE :table";
-
- $command = $this->getDbConnection()->createCommand($sql);
- $command->bindValue(':table', $tableName);
- try
- {
- return count($result = $command->queryRow()) > 0 && $result['Table_type']==='VIEW';
- }
- catch(TDbException $e)
- {
- $table = $schemaName===null?$tableName:$schemaName.'.'.$tableName;
- throw new TDbException('dbcommon_invalid_table_name',$table,$e->getMessage());
- }
- }
-
- /**
- * Gets the primary and foreign key column details for the given table.
- * @param string schema name
- * @param string table name.
- * @return array tuple ($primary, $foreign)
- */
- protected function getConstraintKeys($schemaName, $tableName)
- {
- $table = $schemaName===null ? "`{$tableName}`" : "`{$schemaName}`.`{$tableName}`";
- $sql = "SHOW INDEX FROM {$table}";
- $command = $this->getDbConnection()->createCommand($sql);
- $primary = array();
- foreach($command->query() as $row)
- {
- if($row['Key_name']==='PRIMARY')
- $primary[] = $row['Column_name'];
- }
- // MySQL version was increased to >=5.1.21 instead of 5.x
- // due to a MySQL bug (http://bugs.mysql.com/bug.php?id=19588)
- if($this->getServerVersion() >= 5.121)
- $foreign = $this->getForeignConstraints($schemaName,$tableName);
- else
- $foreign = $this->findForeignConstraints($schemaName,$tableName);
- return array($primary,$foreign);
- }
-
- /**
- * Gets foreign relationship constraint keys and table name
- * @param string database name
- * @param string table name
- * @return array foreign relationship table name and keys.
- */
- protected function getForeignConstraints($schemaName, $tableName)
- {
- $andSchema = $schemaName !== null ? 'AND TABLE_SCHEMA LIKE :schema' : 'AND TABLE_SCHEMA LIKE DATABASE()';
- $sql = <<<EOD
- SELECT
- CONSTRAINT_NAME as con,
- COLUMN_NAME as col,
- REFERENCED_TABLE_SCHEMA as fkschema,
- REFERENCED_TABLE_NAME as fktable,
- REFERENCED_COLUMN_NAME as fkcol
- FROM
- `INFORMATION_SCHEMA`.`KEY_COLUMN_USAGE`
- WHERE
- REFERENCED_TABLE_NAME IS NOT NULL
- AND TABLE_NAME LIKE :table
- $andSchema
-EOD;
- $command = $this->getDbConnection()->createCommand($sql);
- $command->bindValue(':table', $tableName);
- if($schemaName!==null)
- $command->bindValue(':schema', $schemaName);
- $fkeys=array();
- foreach($command->query() as $col)
- {
- $fkeys[$col['con']]['keys'][$col['col']] = $col['fkcol'];
- $fkeys[$col['con']]['table'] = $col['fktable'];
- }
- return count($fkeys) > 0 ? array_values($fkeys) : $fkeys;
- }
-
- /**
- * @param string database name
- * @param string table name
- * @return string SQL command to create the table.
- * @throws TDbException if PHP version is less than 5.1.3
- */
- protected function getShowCreateTable($schemaName, $tableName)
- {
- if(version_compare(PHP_VERSION,'5.1.3','<'))
- throw new TDbException('dbmetadata_requires_php_version', 'Mysql 4.1.x', '5.1.3');
-
- //See http://netevil.org/node.php?nid=795&SC=1
- $this->getDbConnection()->setAttribute(PDO::ATTR_EMULATE_PREPARES, true);
- if($schemaName!==null)
- $sql = "SHOW CREATE TABLE `{$schemaName}`.`{$tableName}`";
- else
- $sql = "SHOW CREATE TABLE `{$tableName}`";
- $command = $this->getDbConnection()->createCommand($sql);
- $result = $command->queryRow();
- return isset($result['Create Table']) ? $result['Create Table'] : (isset($result['Create View']) ? $result['Create View'] : '');
- }
-
- /**
- * Extract foreign key constraints by extracting the contraints from SHOW CREATE TABLE result.
- * @param string database name
- * @param string table name
- * @return array foreign relationship table name and keys.
- */
- protected function findForeignConstraints($schemaName, $tableName)
- {
- $sql = $this->getShowCreateTable($schemaName, $tableName);
- $matches =array();
- $regexp = '/FOREIGN KEY\s+\(([^\)]+)\)\s+REFERENCES\s+`?([^`]+)`?\s\(([^\)]+)\)/mi';
- preg_match_all($regexp,$sql,$matches,PREG_SET_ORDER);
- $foreign = array();
- foreach($matches as $match)
- {
- $fields = array_map('trim',explode(',',str_replace('`','',$match[1])));
- $fk_fields = array_map('trim',explode(',',str_replace('`','',$match[3])));
- $keys=array();
- foreach($fields as $k=>$v)
- $keys[$v] = $fk_fields[$k];
- $foreign[] = array('keys' => $keys, 'table' => trim($match[2]));
- }
- return $foreign;
- }
-
- /**
- * @param string column name.
- * @param TPgsqlTableInfo table information.
- * @return boolean true if column is a foreign key.
- */
- protected function isForeignKeyColumn($columnId, $tableInfo)
- {
- foreach($tableInfo->getForeignKeys() as $fk)
- {
- if(in_array($columnId, array_keys($fk['keys'])))
- return true;
- }
- return false;
- }
-}
-
+<?php
+/**
+ * TMysqlMetaData class file.
+ *
+ * @author Wei Zhuo <weizhuo[at]gmail[dot]com>
+ * @link http://www.pradosoft.com/
+ * @copyright Copyright &copy; 2005-2012 PradoSoft
+ * @license http://www.pradosoft.com/license/
+ * @version $Id$
+ * @package System.Data.Common.Mysql
+ */
+
+/**
+ * Load the base TDbMetaData class.
+ */
+Prado::using('System.Data.Common.TDbMetaData');
+Prado::using('System.Data.Common.Mysql.TMysqlTableInfo');
+
+/**
+ * TMysqlMetaData loads Mysql version 4.1.x and 5.x database table and column information.
+ *
+ * For Mysql version 4.1.x, PHP 5.1.3 or later is required.
+ * See http://netevil.org/node.php?nid=795&SC=1
+ *
+ * @author Wei Zhuo <weizho[at]gmail[dot]com>
+ * @version $Id$
+ * @package System.Data.Common.Mysql
+ * @since 3.1
+ */
+class TMysqlMetaData extends TDbMetaData
+{
+ private $_serverVersion=0;
+
+ /**
+ * @return string TDbTableInfo class name.
+ */
+ protected function getTableInfoClass()
+ {
+ return 'TMysqlTableInfo';
+ }
+
+ /**
+ * Quotes a table name for use in a query.
+ * @param string $name table name
+ * @return string the properly quoted table name
+ */
+ public function quoteTableName($name)
+ {
+ return parent::quoteTableName($name, '`', '`');
+ }
+
+ /**
+ * Quotes a column name for use in a query.
+ * @param string $name column name
+ * @return string the properly quoted column name
+ */
+ public function quoteColumnName($name)
+ {
+ return parent::quoteColumnName($name, '`', '`');
+ }
+
+ /**
+ * Quotes a column alias for use in a query.
+ * @param string $name column alias
+ * @return string the properly quoted column alias
+ */
+ public function quoteColumnAlias($name)
+ {
+ return parent::quoteColumnAlias($name, '`', '`');
+ }
+
+ /**
+ * Get the column definitions for given table.
+ * @param string table name.
+ * @return TMysqlTableInfo table information.
+ */
+ protected function createTableInfo($table)
+ {
+ list($schemaName,$tableName) = $this->getSchemaTableName($table);
+ $find = $schemaName===null ? "`{$tableName}`" : "`{$schemaName}`.`{$tableName}`";
+ $this->getDbConnection()->setActive(true);
+ $sql = "SHOW FULL FIELDS FROM {$find}";
+ $command = $this->getDbConnection()->createCommand($sql);
+ $tableInfo = $this->createNewTableInfo($table);
+ $index=0;
+ foreach($command->query() as $col)
+ {
+ $col['index'] = $index++;
+ $this->processColumn($tableInfo,$col);
+ }
+ if($index===0)
+ throw new TDbException('dbmetadata_invalid_table_view', $table);
+ return $tableInfo;
+ }
+
+ /**
+ * @return float server version.
+ */
+ protected function getServerVersion()
+ {
+ if(!$this->_serverVersion)
+ {
+ $version = $this->getDbConnection()->getAttribute(PDO::ATTR_SERVER_VERSION);
+ $digits=array();
+ preg_match('/(\d+)\.(\d+)\.(\d+)/', $version, $digits);
+ $this->_serverVersion=floatval($digits[1].'.'.$digits[2].$digits[3]);
+ }
+ return $this->_serverVersion;
+ }
+
+ /**
+ * @param TMysqlTableInfo table information.
+ * @param array column information.
+ */
+ protected function processColumn($tableInfo, $col)
+ {
+ $columnId = $col['Field'];
+
+ $info['ColumnName'] = "`$columnId`"; //quote the column names!
+ $info['ColumnId'] = $columnId;
+ $info['ColumnIndex'] = $col['index'];
+ if($col['Null']==='YES')
+ $info['AllowNull'] = true;
+ if(is_int(strpos(strtolower($col['Extra']), 'auto_increment')))
+ $info['AutoIncrement']=true;
+ if($col['Default']!=="")
+ $info['DefaultValue'] = $col['Default'];
+
+ if($col['Key']==='PRI' || in_array($columnId, $tableInfo->getPrimaryKeys()))
+ $info['IsPrimaryKey'] = true;
+ if($this->isForeignKeyColumn($columnId, $tableInfo))
+ $info['IsForeignKey'] = true;
+
+ $info['DbType'] = $col['Type'];
+ $match=array();
+ //find SET/ENUM values, column size, precision, and scale
+ if(preg_match('/\((.*)\)/', $col['Type'], $match))
+ {
+ $info['DbType']= preg_replace('/\(.*\)/', '', $col['Type']);
+
+ //find SET/ENUM values
+ if($this->isEnumSetType($info['DbType']))
+ $info['DbTypeValues'] = preg_split("/[',]/S", $match[1], -1, PREG_SPLIT_NO_EMPTY);
+
+ //find column size, precision and scale
+ $pscale = array();
+ if(preg_match('/(\d+)(?:,(\d+))?+/', $match[1], $pscale))
+ {
+ if($this->isPrecisionType($info['DbType']))
+ {
+ $info['NumericPrecision'] = intval($pscale[1]);
+ if(count($pscale) > 2)
+ $info['NumericScale'] = intval($pscale[2]);
+ }
+ else
+ $info['ColumnSize'] = intval($pscale[1]);
+ }
+ }
+
+ $tableInfo->Columns[$columnId] = new TMysqlTableColumn($info);
+ }
+
+ /**
+ * @return boolean true if column type if "numeric", "interval" or begins with "time".
+ */
+ protected function isPrecisionType($type)
+ {
+ $type = strtolower(trim($type));
+ return $type==='decimal' || $type==='dec'
+ || $type==='float' || $type==='double'
+ || $type==='double precision' || $type==='real';
+ }
+
+ /**
+ * @return boolean true if column type if "enum" or "set".
+ */
+ protected function isEnumSetType($type)
+ {
+ $type = strtolower(trim($type));
+ return $type==='set' || $type==='enum';
+ }
+
+ /**
+ * @param string table name, may be quoted with back-ticks and may contain database name.
+ * @return array tuple ($schema,$table), $schema may be null.
+ * @throws TDbException when table name contains invalid identifier bytes.
+ */
+ protected function getSchemaTableName($table)
+ {
+ //remove the back ticks and separate out the "database.table"
+ $result = explode('.', str_replace('`', '', $table));
+ foreach($result as $name)
+ {
+ if(!$this->isValidIdentifier($name))
+ {
+ $ref = 'http://dev.mysql.com/doc/refman/5.0/en/identifiers.html';
+ throw new TDbException('dbcommon_invalid_identifier_name', $table, $ref);
+ }
+ }
+ return count($result) > 1 ? $result : array(null, $result[0]);
+ }
+
+ /**
+ * http://dev.mysql.com/doc/refman/5.0/en/identifiers.html
+ * @param string identifier name
+ * @param boolean true if valid identifier.
+ */
+ protected function isValidIdentifier($name)
+ {
+ return !preg_match('#/|\\|.|\x00|\xFF#', $name);
+ }
+
+ /**
+ * @param string table schema name
+ * @param string table name.
+ * @return TMysqlTableInfo
+ */
+ protected function createNewTableInfo($table)
+ {
+ list($schemaName,$tableName) = $this->getSchemaTableName($table);
+ $info['SchemaName'] = $schemaName;
+ $info['TableName'] = $tableName;
+ if($this->getIsView($schemaName,$tableName))
+ $info['IsView'] = true;
+ list($primary, $foreign) = $this->getConstraintKeys($schemaName, $tableName);
+ $class = $this->getTableInfoClass();
+ return new $class($info,$primary,$foreign);
+ }
+
+ /**
+ * For MySQL version 5.0.1 or later we can use SHOW FULL TABLES
+ * http://dev.mysql.com/doc/refman/5.0/en/show-tables.html
+ *
+ * For MySQL version 5.0.1 or ealier, this always return false.
+ * @param string database name, null to use default connection database.
+ * @param string table or view name.
+ * @return boolean true if is view, false otherwise.
+ * @throws TDbException if table or view does not exist.
+ */
+ protected function getIsView($schemaName,$tableName)
+ {
+ if($this->getServerVersion()<5.01)
+ return false;
+ if($schemaName!==null)
+ $sql = "SHOW FULL TABLES FROM `{$schemaName}` LIKE :table";
+ else
+ $sql = "SHOW FULL TABLES LIKE :table";
+
+ $command = $this->getDbConnection()->createCommand($sql);
+ $command->bindValue(':table', $tableName);
+ try
+ {
+ return count($result = $command->queryRow()) > 0 && $result['Table_type']==='VIEW';
+ }
+ catch(TDbException $e)
+ {
+ $table = $schemaName===null?$tableName:$schemaName.'.'.$tableName;
+ throw new TDbException('dbcommon_invalid_table_name',$table,$e->getMessage());
+ }
+ }
+
+ /**
+ * Gets the primary and foreign key column details for the given table.
+ * @param string schema name
+ * @param string table name.
+ * @return array tuple ($primary, $foreign)
+ */
+ protected function getConstraintKeys($schemaName, $tableName)
+ {
+ $table = $schemaName===null ? "`{$tableName}`" : "`{$schemaName}`.`{$tableName}`";
+ $sql = "SHOW INDEX FROM {$table}";
+ $command = $this->getDbConnection()->createCommand($sql);
+ $primary = array();
+ foreach($command->query() as $row)
+ {
+ if($row['Key_name']==='PRIMARY')
+ $primary[] = $row['Column_name'];
+ }
+ // MySQL version was increased to >=5.1.21 instead of 5.x
+ // due to a MySQL bug (http://bugs.mysql.com/bug.php?id=19588)
+ if($this->getServerVersion() >= 5.121)
+ $foreign = $this->getForeignConstraints($schemaName,$tableName);
+ else
+ $foreign = $this->findForeignConstraints($schemaName,$tableName);
+ return array($primary,$foreign);
+ }
+
+ /**
+ * Gets foreign relationship constraint keys and table name
+ * @param string database name
+ * @param string table name
+ * @return array foreign relationship table name and keys.
+ */
+ protected function getForeignConstraints($schemaName, $tableName)
+ {
+ $andSchema = $schemaName !== null ? 'AND TABLE_SCHEMA LIKE :schema' : 'AND TABLE_SCHEMA LIKE DATABASE()';
+ $sql = <<<EOD
+ SELECT
+ CONSTRAINT_NAME as con,
+ COLUMN_NAME as col,
+ REFERENCED_TABLE_SCHEMA as fkschema,
+ REFERENCED_TABLE_NAME as fktable,
+ REFERENCED_COLUMN_NAME as fkcol
+ FROM
+ `INFORMATION_SCHEMA`.`KEY_COLUMN_USAGE`
+ WHERE
+ REFERENCED_TABLE_NAME IS NOT NULL
+ AND TABLE_NAME LIKE :table
+ $andSchema
+EOD;
+ $command = $this->getDbConnection()->createCommand($sql);
+ $command->bindValue(':table', $tableName);
+ if($schemaName!==null)
+ $command->bindValue(':schema', $schemaName);
+ $fkeys=array();
+ foreach($command->query() as $col)
+ {
+ $fkeys[$col['con']]['keys'][$col['col']] = $col['fkcol'];
+ $fkeys[$col['con']]['table'] = $col['fktable'];
+ }
+ return count($fkeys) > 0 ? array_values($fkeys) : $fkeys;
+ }
+
+ /**
+ * @param string database name
+ * @param string table name
+ * @return string SQL command to create the table.
+ * @throws TDbException if PHP version is less than 5.1.3
+ */
+ protected function getShowCreateTable($schemaName, $tableName)
+ {
+ if(version_compare(PHP_VERSION,'5.1.3','<'))
+ throw new TDbException('dbmetadata_requires_php_version', 'Mysql 4.1.x', '5.1.3');
+
+ //See http://netevil.org/node.php?nid=795&SC=1
+ $this->getDbConnection()->setAttribute(PDO::ATTR_EMULATE_PREPARES, true);
+ if($schemaName!==null)
+ $sql = "SHOW CREATE TABLE `{$schemaName}`.`{$tableName}`";
+ else
+ $sql = "SHOW CREATE TABLE `{$tableName}`";
+ $command = $this->getDbConnection()->createCommand($sql);
+ $result = $command->queryRow();
+ return isset($result['Create Table']) ? $result['Create Table'] : (isset($result['Create View']) ? $result['Create View'] : '');
+ }
+
+ /**
+ * Extract foreign key constraints by extracting the contraints from SHOW CREATE TABLE result.
+ * @param string database name
+ * @param string table name
+ * @return array foreign relationship table name and keys.
+ */
+ protected function findForeignConstraints($schemaName, $tableName)
+ {
+ $sql = $this->getShowCreateTable($schemaName, $tableName);
+ $matches =array();
+ $regexp = '/FOREIGN KEY\s+\(([^\)]+)\)\s+REFERENCES\s+`?([^`]+)`?\s\(([^\)]+)\)/mi';
+ preg_match_all($regexp,$sql,$matches,PREG_SET_ORDER);
+ $foreign = array();
+ foreach($matches as $match)
+ {
+ $fields = array_map('trim',explode(',',str_replace('`','',$match[1])));
+ $fk_fields = array_map('trim',explode(',',str_replace('`','',$match[3])));
+ $keys=array();
+ foreach($fields as $k=>$v)
+ $keys[$v] = $fk_fields[$k];
+ $foreign[] = array('keys' => $keys, 'table' => trim($match[2]));
+ }
+ return $foreign;
+ }
+
+ /**
+ * @param string column name.
+ * @param TPgsqlTableInfo table information.
+ * @return boolean true if column is a foreign key.
+ */
+ protected function isForeignKeyColumn($columnId, $tableInfo)
+ {
+ foreach($tableInfo->getForeignKeys() as $fk)
+ {
+ if(in_array($columnId, array_keys($fk['keys'])))
+ return true;
+ }
+ return false;
+ }
+}
+
diff --git a/framework/Data/Common/Mysql/TMysqlTableColumn.php b/framework/Data/Common/Mysql/TMysqlTableColumn.php
index 34dceaad..901f4f54 100644
--- a/framework/Data/Common/Mysql/TMysqlTableColumn.php
+++ b/framework/Data/Common/Mysql/TMysqlTableColumn.php
@@ -1,72 +1,72 @@
-<?php
-/**
- * TMysqlTableColumn class file.
- *
- * @author Wei Zhuo <weizhuo[at]gmail[dot]com>
- * @link http://www.pradosoft.com/
+<?php
+/**
+ * TMysqlTableColumn class file.
+ *
+ * @author Wei Zhuo <weizhuo[at]gmail[dot]com>
+ * @link http://www.pradosoft.com/
* @copyright Copyright &copy; 2005-2012 PradoSoft
- * @license http://www.pradosoft.com/license/
- * @version $Id$
- * @package System.Data.Common.Mysql
- */
-
-/**
- * Load common TDbTableCommon class.
- */
-Prado::using('System.Data.Common.TDbTableColumn');
-
-/**
- * Describes the column metadata of the schema for a Mysql database table.
- *
- * @author Wei Zhuo <weizho[at]gmail[dot]com>
- * @version $Id$
- * @package System.Data.Common.Mysql
- * @since 3.1
- */
-class TMysqlTableColumn extends TDbTableColumn
-{
- private static $types = array(
- 'integer' => array('bit', 'tinyint', 'smallint', 'mediumint', 'int', 'integer', 'bigint'),
- 'boolean' => array('boolean', 'bool'),
- 'float' => array('float', 'double', 'double precision', 'decimal', 'dec', 'numeric', 'fixed')
- );
-
- /**
- * Overrides parent implementation, returns PHP type from the db type.
- * @return boolean derived PHP primitive type from the column db type.
- */
- public function getPHPType()
- {
- $dbtype = trim(str_replace(array('unsigned', 'zerofill'),array('','',),strtolower($this->getDbType())));
- if($dbtype==='tinyint' && $this->getColumnSize()===1)
- return 'boolean';
- foreach(self::$types as $type => $dbtypes)
- {
- if(in_array($dbtype, $dbtypes))
- return $type;
- }
- return 'string';
- }
-
- /**
- * @return boolean true if column will auto-increment when the column value is inserted as null.
- */
- public function getAutoIncrement()
- {
- return $this->getInfo('AutoIncrement', false);
- }
-
- /**
- * @return boolean true if auto increment is true.
- */
- public function hasSequence()
- {
- return $this->getAutoIncrement();
- }
-
- public function getDbTypeValues()
- {
- return $this->getInfo('DbTypeValues');
- }
-}
-
+ * @license http://www.pradosoft.com/license/
+ * @version $Id$
+ * @package System.Data.Common.Mysql
+ */
+
+/**
+ * Load common TDbTableCommon class.
+ */
+Prado::using('System.Data.Common.TDbTableColumn');
+
+/**
+ * Describes the column metadata of the schema for a Mysql database table.
+ *
+ * @author Wei Zhuo <weizho[at]gmail[dot]com>
+ * @version $Id$
+ * @package System.Data.Common.Mysql
+ * @since 3.1
+ */
+class TMysqlTableColumn extends TDbTableColumn
+{
+ private static $types = array(
+ 'integer' => array('bit', 'tinyint', 'smallint', 'mediumint', 'int', 'integer', 'bigint'),
+ 'boolean' => array('boolean', 'bool'),
+ 'float' => array('float', 'double', 'double precision', 'decimal', 'dec', 'numeric', 'fixed')
+ );
+
+ /**
+ * Overrides parent implementation, returns PHP type from the db type.
+ * @return boolean derived PHP primitive type from the column db type.
+ */
+ public function getPHPType()
+ {
+ $dbtype = trim(str_replace(array('unsigned', 'zerofill'),array('','',),strtolower($this->getDbType())));
+ if($dbtype==='tinyint' && $this->getColumnSize()===1)
+ return 'boolean';
+ foreach(self::$types as $type => $dbtypes)
+ {
+ if(in_array($dbtype, $dbtypes))
+ return $type;
+ }
+ return 'string';
+ }
+
+ /**
+ * @return boolean true if column will auto-increment when the column value is inserted as null.
+ */
+ public function getAutoIncrement()
+ {
+ return $this->getInfo('AutoIncrement', false);
+ }
+
+ /**
+ * @return boolean true if auto increment is true.
+ */
+ public function hasSequence()
+ {
+ return $this->getAutoIncrement();
+ }
+
+ public function getDbTypeValues()
+ {
+ return $this->getInfo('DbTypeValues');
+ }
+}
+
diff --git a/framework/Data/Common/Mysql/TMysqlTableInfo.php b/framework/Data/Common/Mysql/TMysqlTableInfo.php
index 30a3d0a1..40b421db 100644
--- a/framework/Data/Common/Mysql/TMysqlTableInfo.php
+++ b/framework/Data/Common/Mysql/TMysqlTableInfo.php
@@ -1,59 +1,59 @@
-<?php
-/**
- * TMysqlTableInfo class file.
- *
- * @author Wei Zhuo <weizhuo[at]gmail[dot]com>
- * @link http://www.pradosoft.com/
+<?php
+/**
+ * TMysqlTableInfo class file.
+ *
+ * @author Wei Zhuo <weizhuo[at]gmail[dot]com>
+ * @link http://www.pradosoft.com/
* @copyright Copyright &copy; 2005-2012 PradoSoft
- * @license http://www.pradosoft.com/license/
- * @version $Id$
- * @package System.Data.Common.Mysql
- */
-
-/**
- * Loads the base TDbTableInfo class and TMysqlTableColumn class.
- */
-Prado::using('System.Data.Common.TDbTableInfo');
-Prado::using('System.Data.Common.Mysql.TMysqlTableColumn');
-
-/**
- * TMysqlTableInfo class provides additional table information for MySQL database.
- *
- * @author Wei Zhuo <weizho[at]gmail[dot]com>
- * @version $Id$
- * @package System.Data.Common.Mysql
- * @since 3.1
- */
-class TMysqlTableInfo extends TDbTableInfo
-{
- /**
- * @return string name of the schema this column belongs to.
- */
- public function getSchemaName()
- {
- return $this->getInfo('SchemaName');
- }
-
- /**
- * @return string full name of the table, database dependent.
- */
- public function getTableFullName()
- {
- if(($schema=$this->getSchemaName())!==null)
- return '`'.$schema.'`.`'.$this->getTableName().'`';
- else
- return '`'.$this->getTableName().'`';
- }
-
- /**
- * @param TDbConnection database connection.
- * @return TDbCommandBuilder new command builder
- */
- public function createCommandBuilder($connection)
- {
- Prado::using('System.Data.Common.Mysql.TMysqlCommandBuilder');
- return new TMysqlCommandBuilder($connection,$this);
- }
-}
-
-?>
+ * @license http://www.pradosoft.com/license/
+ * @version $Id$
+ * @package System.Data.Common.Mysql
+ */
+
+/**
+ * Loads the base TDbTableInfo class and TMysqlTableColumn class.
+ */
+Prado::using('System.Data.Common.TDbTableInfo');
+Prado::using('System.Data.Common.Mysql.TMysqlTableColumn');
+
+/**
+ * TMysqlTableInfo class provides additional table information for MySQL database.
+ *
+ * @author Wei Zhuo <weizho[at]gmail[dot]com>
+ * @version $Id$
+ * @package System.Data.Common.Mysql
+ * @since 3.1
+ */
+class TMysqlTableInfo extends TDbTableInfo
+{
+ /**
+ * @return string name of the schema this column belongs to.
+ */
+ public function getSchemaName()
+ {
+ return $this->getInfo('SchemaName');
+ }
+
+ /**
+ * @return string full name of the table, database dependent.
+ */
+ public function getTableFullName()
+ {
+ if(($schema=$this->getSchemaName())!==null)
+ return '`'.$schema.'`.`'.$this->getTableName().'`';
+ else
+ return '`'.$this->getTableName().'`';
+ }
+
+ /**
+ * @param TDbConnection database connection.
+ * @return TDbCommandBuilder new command builder
+ */
+ public function createCommandBuilder($connection)
+ {
+ Prado::using('System.Data.Common.Mysql.TMysqlCommandBuilder');
+ return new TMysqlCommandBuilder($connection,$this);
+ }
+}
+
+?>
diff --git a/framework/Data/Common/Pgsql/TPgsqlCommandBuilder.php b/framework/Data/Common/Pgsql/TPgsqlCommandBuilder.php
index 8f4147e5..f9938d61 100644
--- a/framework/Data/Common/Pgsql/TPgsqlCommandBuilder.php
+++ b/framework/Data/Common/Pgsql/TPgsqlCommandBuilder.php
@@ -1,69 +1,69 @@
-<?php
-/**
- * TPgsqlCommandBuilder class file.
- *
- * @author Wei Zhuo <weizhuo[at]gmail[dot]com>
- * @link http://www.pradosoft.com/
+<?php
+/**
+ * TPgsqlCommandBuilder class file.
+ *
+ * @author Wei Zhuo <weizhuo[at]gmail[dot]com>
+ * @link http://www.pradosoft.com/
* @copyright Copyright &copy; 2005-2012 PradoSoft
- * @license http://www.pradosoft.com/license/
- * @version $Id: TDbCommandBuilder.php 1863 2007-04-12 12:43:49Z wei $
- * @package System.Data.Common
- */
-
-Prado::using('System.Data.Common.TDbCommandBuilder');
-
-/**
- * TPgsqlCommandBuilder provides specifics methods to create limit/offset query commands
- * for Pgsql database.
- *
- * @author Wei Zhuo <weizho[at]gmail[dot]com>
- * @version $Id: TDbCommandBuilder.php 1863 2007-04-12 12:43:49Z wei $
- * @package System.Data.Common
- * @since 3.1
- */
-class TPgsqlCommandBuilder extends TDbCommandBuilder
-{
- /**
- * Overrides parent implementation. Only column of type text or character (and its variants)
- * accepts the LIKE criteria.
- * @param array list of column id for potential search condition.
- * @param string string of keywords
- * @return string SQL search condition matching on a set of columns.
- */
- public function getSearchExpression($fields, $keywords)
- {
- $columns = array();
- foreach($fields as $field)
- {
- if($this->isSearchableColumn($this->getTableInfo()->getColumn($field)))
- $columns[] = $field;
- }
- return parent::getSearchExpression($columns, $keywords);
- }
- /**
- *
- * @return boolean true if column can be used for LIKE searching.
- */
- protected function isSearchableColumn($column)
- {
- $type = strtolower($column->getDbType());
- return $type === 'character varying' || $type === 'varchar' ||
- $type === 'character' || $type === 'char' || $type === 'text';
- }
-
- /**
- * Overrides parent implementation to use PostgreSQL's ILIKE instead of LIKE (case-sensitive).
- * @param string column name.
- * @param array keywords
- * @return string search condition for all words in one column.
- */
- protected function getSearchCondition($column, $words)
- {
- $conditions=array();
- foreach($words as $word)
- $conditions[] = $column.' ILIKE '.$this->getDbConnection()->quoteString('%'.$word.'%');
- return '('.implode(' AND ', $conditions).')';
- }
-
-}
-
+ * @license http://www.pradosoft.com/license/
+ * @version $Id: TDbCommandBuilder.php 1863 2007-04-12 12:43:49Z wei $
+ * @package System.Data.Common
+ */
+
+Prado::using('System.Data.Common.TDbCommandBuilder');
+
+/**
+ * TPgsqlCommandBuilder provides specifics methods to create limit/offset query commands
+ * for Pgsql database.
+ *
+ * @author Wei Zhuo <weizho[at]gmail[dot]com>
+ * @version $Id: TDbCommandBuilder.php 1863 2007-04-12 12:43:49Z wei $
+ * @package System.Data.Common
+ * @since 3.1
+ */
+class TPgsqlCommandBuilder extends TDbCommandBuilder
+{
+ /**
+ * Overrides parent implementation. Only column of type text or character (and its variants)
+ * accepts the LIKE criteria.
+ * @param array list of column id for potential search condition.
+ * @param string string of keywords
+ * @return string SQL search condition matching on a set of columns.
+ */
+ public function getSearchExpression($fields, $keywords)
+ {
+ $columns = array();
+ foreach($fields as $field)
+ {
+ if($this->isSearchableColumn($this->getTableInfo()->getColumn($field)))
+ $columns[] = $field;
+ }
+ return parent::getSearchExpression($columns, $keywords);
+ }
+ /**
+ *
+ * @return boolean true if column can be used for LIKE searching.
+ */
+ protected function isSearchableColumn($column)
+ {
+ $type = strtolower($column->getDbType());
+ return $type === 'character varying' || $type === 'varchar' ||
+ $type === 'character' || $type === 'char' || $type === 'text';
+ }
+
+ /**
+ * Overrides parent implementation to use PostgreSQL's ILIKE instead of LIKE (case-sensitive).
+ * @param string column name.
+ * @param array keywords
+ * @return string search condition for all words in one column.
+ */
+ protected function getSearchCondition($column, $words)
+ {
+ $conditions=array();
+ foreach($words as $word)
+ $conditions[] = $column.' ILIKE '.$this->getDbConnection()->quoteString('%'.$word.'%');
+ return '('.implode(' AND ', $conditions).')';
+ }
+
+}
+
diff --git a/framework/Data/Common/Pgsql/TPgsqlMetaData.php b/framework/Data/Common/Pgsql/TPgsqlMetaData.php
index 85785606..86a9892e 100644
--- a/framework/Data/Common/Pgsql/TPgsqlMetaData.php
+++ b/framework/Data/Common/Pgsql/TPgsqlMetaData.php
@@ -1,422 +1,422 @@
-<?php
-/**
- * TPgsqlMetaData class file.
- *
- * @author Wei Zhuo <weizhuo[at]gmail[dot]com>
- * @link http://www.pradosoft.com/
- * @copyright Copyright &copy; 2005-2012 PradoSoft
- * @license http://www.pradosoft.com/license/
- * @version $Id$
- * @package System.Data.Common.Pgsql
- */
-
-/**
- * Load the base TDbMetaData class.
- */
-Prado::using('System.Data.Common.TDbMetaData');
-Prado::using('System.Data.Common.Pgsql.TPgsqlTableInfo');
-
-/**
- * TPgsqlMetaData loads PostgreSQL database table and column information.
- *
- * @author Wei Zhuo <weizho[at]gmail[dot]com>
- * @version $Id$
- * @package System.Data.Common.Pgsql
- * @since 3.1
- */
-class TPgsqlMetaData extends TDbMetaData
-{
- private $_defaultSchema = 'public';
-
- /**
- * @return string TDbTableInfo class name.
- */
- protected function getTableInfoClass()
- {
- return 'TPgsqlTableInfo';
- }
-
- /**
- * Quotes a table name for use in a query.
- * @param string $name table name
- * @return string the properly quoted table name
- */
- public function quoteTableName($name)
- {
- return parent::quoteTableName($name, '"', '"');
- }
-
- /**
- * Quotes a column name for use in a query.
- * @param string $name column name
- * @return string the properly quoted column name
- */
- public function quoteColumnName($name)
- {
- return parent::quoteColumnName($name, '"', '"');
- }
-
- /**
- * Quotes a column alias for use in a query.
- * @param string $name column alias
- * @return string the properly quoted column alias
- */
- public function quoteColumnAlias($name)
- {
- return parent::quoteColumnAlias($name, '"', '"');
- }
-
- /**
- * @param string default schema.
- */
- public function setDefaultSchema($schema)
- {
- $this->_defaultSchema=$schema;
- }
-
- /**
- * @return string default schema.
- */
- public function getDefaultSchema()
- {
- return $this->_defaultSchema;
- }
-
- /**
- * @param string table name with optional schema name prefix, uses default schema name prefix is not provided.
- * @return array tuple as ($schemaName,$tableName)
- */
- protected function getSchemaTableName($table)
- {
- if(count($parts= explode('.', str_replace('"','',$table))) > 1)
- return array($parts[0], $parts[1]);
- else
- return array($this->getDefaultSchema(),$parts[0]);
- }
-
- /**
- * Get the column definitions for given table.
- * @param string table name.
- * @return TPgsqlTableInfo table information.
- */
- protected function createTableInfo($table)
- {
- list($schemaName,$tableName) = $this->getSchemaTableName($table);
-
- // This query is made much more complex by the addition of the 'attisserial' field.
- // The subquery to get that field checks to see if there is an internally dependent
- // sequence on the field.
- $sql =
-<<<EOD
- SELECT
- a.attname,
- pg_catalog.format_type(a.atttypid, a.atttypmod) as type,
- a.atttypmod,
- a.attnotnull, a.atthasdef, adef.adsrc,
- (
- SELECT 1 FROM pg_catalog.pg_depend pd, pg_catalog.pg_class pc
- WHERE pd.objid=pc.oid
- AND pd.classid=pc.tableoid
- AND pd.refclassid=pc.tableoid
- AND pd.refobjid=a.attrelid
- AND pd.refobjsubid=a.attnum
- AND pd.deptype='i'
- AND pc.relkind='S'
- ) IS NOT NULL AS attisserial
-
- FROM
- pg_catalog.pg_attribute a LEFT JOIN pg_catalog.pg_attrdef adef
- ON a.attrelid=adef.adrelid
- AND a.attnum=adef.adnum
- LEFT JOIN pg_catalog.pg_type t ON a.atttypid=t.oid
- WHERE
- a.attrelid = (SELECT oid FROM pg_catalog.pg_class WHERE relname=:table
- AND relnamespace = (SELECT oid FROM pg_catalog.pg_namespace WHERE
- nspname = :schema))
- AND a.attnum > 0 AND NOT a.attisdropped
- ORDER BY a.attnum
-EOD;
- $this->getDbConnection()->setActive(true);
- $command = $this->getDbConnection()->createCommand($sql);
- $command->bindValue(':table', $tableName);
- $command->bindValue(':schema', $schemaName);
- $tableInfo = $this->createNewTableInfo($schemaName, $tableName);
- $index=0;
- foreach($command->query() as $col)
- {
- $col['index'] = $index++;
- $this->processColumn($tableInfo, $col);
- }
- if($index===0)
- throw new TDbException('dbmetadata_invalid_table_view', $table);
- return $tableInfo;
- }
-
- /**
- * @param string table schema name
- * @param string table name.
- * @return TPgsqlTableInfo
- */
- protected function createNewTableInfo($schemaName,$tableName)
- {
- $info['SchemaName'] = $this->assertIdentifier($schemaName);
- $info['TableName'] = $this->assertIdentifier($tableName);
- if($this->getIsView($schemaName,$tableName))
- $info['IsView'] = true;
- list($primary, $foreign) = $this->getConstraintKeys($schemaName, $tableName);
- $class = $this->getTableInfoClass();
- return new $class($info,$primary,$foreign);
- }
-
- /**
- * @param string table name, schema name or column name.
- * @return string a valid identifier.
- * @throws TDbException when table name contains a double quote (").
- */
- protected function assertIdentifier($name)
- {
- if(strpos($name, '"')!==false)
- {
- $ref = 'http://www.postgresql.org/docs/7.4/static/sql-syntax.html#SQL-SYNTAX-IDENTIFIERS';
- throw new TDbException('dbcommon_invalid_identifier_name', $name, $ref);
- }
- return $name;
- }
-
- /**
- * @param string table schema name
- * @param string table name.
- * @return boolean true if the table is a view.
- */
- protected function getIsView($schemaName,$tableName)
- {
- $sql =
-<<<EOD
- SELECT count(c.relname) FROM pg_catalog.pg_class c
- LEFT JOIN pg_catalog.pg_namespace n ON (n.oid = c.relnamespace)
- WHERE (n.nspname=:schema) AND (c.relkind = 'v'::"char") AND c.relname = :table
-EOD;
- $this->getDbConnection()->setActive(true);
- $command = $this->getDbConnection()->createCommand($sql);
- $command->bindValue(':schema',$schemaName);
- $command->bindValue(':table', $tableName);
- return intval($command->queryScalar()) === 1;
- }
-
- /**
- * @param TPgsqlTableInfo table information.
- * @param array column information.
- */
- protected function processColumn($tableInfo, $col)
- {
- $columnId = $col['attname']; //use column name as column Id
-
- $info['ColumnName'] = '"'.$columnId.'"'; //quote the column names!
- $info['ColumnId'] = $columnId;
- $info['ColumnIndex'] = $col['index'];
- if(!$col['attnotnull'])
- $info['AllowNull'] = true;
- if(in_array($columnId, $tableInfo->getPrimaryKeys()))
- $info['IsPrimaryKey'] = true;
- if($this->isForeignKeyColumn($columnId, $tableInfo))
- $info['IsForeignKey'] = true;
-
- if($col['atttypmod'] > 0)
- $info['ColumnSize'] = $col['atttypmod'] - 4;
- if($col['atthasdef'])
- $info['DefaultValue'] = $col['adsrc'];
- if($col['attisserial'] || substr($col['adsrc'],0,8) === 'nextval(')
- {
- if(($sequence = $this->getSequenceName($tableInfo, $col['adsrc']))!==null)
- {
- $info['SequenceName'] = $sequence;
- unset($info['DefaultValue']);
- }
- }
- $matches = array();
- if(preg_match('/\((\d+)(?:,(\d+))?+\)/', $col['type'], $matches))
- {
- $info['DbType'] = preg_replace('/\(\d+(?:,\d+)?\)/','',$col['type']);
- if($this->isPrecisionType($info['DbType']))
- {
- $info['NumericPrecision'] = intval($matches[1]);
- if(count($matches) > 2)
- $info['NumericScale'] = intval($matches[2]);
- }
- else
- $info['ColumnSize'] = intval($matches[1]);
- }
- else
- $info['DbType'] = $col['type'];
-
- $tableInfo->Columns[$columnId] = new TPgsqlTableColumn($info);
- }
-
- /**
- * @return string serial name if found, null otherwise.
- */
- protected function getSequenceName($tableInfo,$src)
- {
- $matches = array();
- if(preg_match('/nextval\([^\']*\'([^\']+)\'[^\)]*\)/i',$src,$matches))
- {
- if(is_int(strpos($matches[1], '.')))
- return $matches[1];
- else
- return $tableInfo->getSchemaName().'.'.$matches[1];
- }
- }
-
- /**
- * @return boolean true if column type if "numeric", "interval" or begins with "time".
- */
- protected function isPrecisionType($type)
- {
- $type = strtolower(trim($type));
- return $type==='numeric' || $type==='interval' || strpos($type, 'time')===0;
- }
-
- /**
- * Gets the primary and foreign key column details for the given table.
- * @param string schema name
- * @param string table name.
- * @return array tuple ($primary, $foreign)
- */
- protected function getConstraintKeys($schemaName, $tableName)
- {
- $sql =
-<<<EOD
- SELECT conname, consrc, contype, indkey, indisclustered FROM (
- SELECT
- conname,
- CASE WHEN contype='f' THEN
- pg_catalog.pg_get_constraintdef(oid)
- ELSE
- 'CHECK (' || consrc || ')'
- END AS consrc,
- contype,
- conrelid AS relid,
- NULL AS indkey,
- FALSE AS indisclustered
- FROM
- pg_catalog.pg_constraint
- WHERE
- contype IN ('f', 'c')
- UNION ALL
- SELECT
- pc.relname,
- NULL,
- CASE WHEN indisprimary THEN
- 'p'
- ELSE
- 'u'
- END,
- pi.indrelid,
- indkey,
- pi.indisclustered
- FROM
- pg_catalog.pg_class pc,
- pg_catalog.pg_index pi
- WHERE
- pc.oid=pi.indexrelid
- AND EXISTS (
- SELECT 1 FROM pg_catalog.pg_depend d JOIN pg_catalog.pg_constraint c
- ON (d.refclassid = c.tableoid AND d.refobjid = c.oid)
- WHERE d.classid = pc.tableoid AND d.objid = pc.oid AND d.deptype = 'i' AND c.contype IN ('u', 'p')
- )
- ) AS sub
- WHERE relid = (SELECT oid FROM pg_catalog.pg_class WHERE relname=:table
- AND relnamespace = (SELECT oid FROM pg_catalog.pg_namespace
- WHERE nspname=:schema))
- ORDER BY
- 1
-EOD;
- $this->getDbConnection()->setActive(true);
- $command = $this->getDbConnection()->createCommand($sql);
- $command->bindValue(':table', $tableName);
- $command->bindValue(':schema', $schemaName);
- $primary = array();
- $foreign = array();
- foreach($command->query() as $row)
- {
- switch($row['contype'])
- {
- case 'p':
- $primary = $this->getPrimaryKeys($tableName, $schemaName, $row['indkey']);
- break;
- case 'f':
- if(($fkey = $this->getForeignKeys($row['consrc']))!==null)
- $foreign[] = $fkey;
- break;
- }
- }
- return array($primary,$foreign);
- }
-
- /**
- * Gets the primary key field names
- * @param string pgsql primary key definition
- * @return array primary key field names.
- */
- protected function getPrimaryKeys($tableName, $schemaName, $columnIndex)
- {
- $index = join(', ', explode(' ', $columnIndex));
- $sql =
-<<<EOD
- SELECT attnum, attname FROM pg_catalog.pg_attribute WHERE
- attrelid=(
- SELECT oid FROM pg_catalog.pg_class WHERE relname=:table AND relnamespace=(
- SELECT oid FROM pg_catalog.pg_namespace WHERE nspname=:schema
- )
- )
- AND attnum IN ({$index})
-EOD;
- $command = $this->getDbConnection()->createCommand($sql);
- $command->bindValue(':table', $tableName);
- $command->bindValue(':schema', $schemaName);
-// $command->bindValue(':columnIndex', join(', ', explode(' ', $columnIndex)));
- $primary = array();
- foreach($command->query() as $row)
- {
- $primary[] = $row['attname'];
- }
-
- return $primary;
- }
-
- /**
- * Gets foreign relationship constraint keys and table name
- * @param string pgsql foreign key definition
- * @return array foreign relationship table name and keys, null otherwise
- */
- protected function getForeignKeys($src)
- {
- $matches = array();
- $brackets = '\(([^\)]+)\)';
- $find = "/FOREIGN\s+KEY\s+{$brackets}\s+REFERENCES\s+([^\(]+){$brackets}/i";
- if(preg_match($find, $src, $matches))
- {
- $keys = preg_split('/,\s+/', $matches[1]);
- $fkeys = array();
- foreach(preg_split('/,\s+/', $matches[3]) as $i => $fkey)
- $fkeys[$keys[$i]] = $fkey;
- return array('table' => str_replace('"','',$matches[2]), 'keys' => $fkeys);
- }
- }
-
- /**
- * @param string column name.
- * @param TPgsqlTableInfo table information.
- * @return boolean true if column is a foreign key.
- */
- protected function isForeignKeyColumn($columnId, $tableInfo)
- {
- foreach($tableInfo->getForeignKeys() as $fk)
- {
- if(in_array($columnId, array_keys($fk['keys'])))
- return true;
- }
- return false;
- }
-}
-
+<?php
+/**
+ * TPgsqlMetaData class file.
+ *
+ * @author Wei Zhuo <weizhuo[at]gmail[dot]com>
+ * @link http://www.pradosoft.com/
+ * @copyright Copyright &copy; 2005-2012 PradoSoft
+ * @license http://www.pradosoft.com/license/
+ * @version $Id$
+ * @package System.Data.Common.Pgsql
+ */
+
+/**
+ * Load the base TDbMetaData class.
+ */
+Prado::using('System.Data.Common.TDbMetaData');
+Prado::using('System.Data.Common.Pgsql.TPgsqlTableInfo');
+
+/**
+ * TPgsqlMetaData loads PostgreSQL database table and column information.
+ *
+ * @author Wei Zhuo <weizho[at]gmail[dot]com>
+ * @version $Id$
+ * @package System.Data.Common.Pgsql
+ * @since 3.1
+ */
+class TPgsqlMetaData extends TDbMetaData
+{
+ private $_defaultSchema = 'public';
+
+ /**
+ * @return string TDbTableInfo class name.
+ */
+ protected function getTableInfoClass()
+ {
+ return 'TPgsqlTableInfo';
+ }
+
+ /**
+ * Quotes a table name for use in a query.
+ * @param string $name table name
+ * @return string the properly quoted table name
+ */
+ public function quoteTableName($name)
+ {
+ return parent::quoteTableName($name, '"', '"');
+ }
+
+ /**
+ * Quotes a column name for use in a query.
+ * @param string $name column name
+ * @return string the properly quoted column name
+ */
+ public function quoteColumnName($name)
+ {
+ return parent::quoteColumnName($name, '"', '"');
+ }
+
+ /**
+ * Quotes a column alias for use in a query.
+ * @param string $name column alias
+ * @return string the properly quoted column alias
+ */
+ public function quoteColumnAlias($name)
+ {
+ return parent::quoteColumnAlias($name, '"', '"');
+ }
+
+ /**
+ * @param string default schema.
+ */
+ public function setDefaultSchema($schema)
+ {
+ $this->_defaultSchema=$schema;
+ }
+
+ /**
+ * @return string default schema.
+ */
+ public function getDefaultSchema()
+ {
+ return $this->_defaultSchema;
+ }
+
+ /**
+ * @param string table name with optional schema name prefix, uses default schema name prefix is not provided.
+ * @return array tuple as ($schemaName,$tableName)
+ */
+ protected function getSchemaTableName($table)
+ {
+ if(count($parts= explode('.', str_replace('"','',$table))) > 1)
+ return array($parts[0], $parts[1]);
+ else
+ return array($this->getDefaultSchema(),$parts[0]);
+ }
+
+ /**
+ * Get the column definitions for given table.
+ * @param string table name.
+ * @return TPgsqlTableInfo table information.
+ */
+ protected function createTableInfo($table)
+ {
+ list($schemaName,$tableName) = $this->getSchemaTableName($table);
+
+ // This query is made much more complex by the addition of the 'attisserial' field.
+ // The subquery to get that field checks to see if there is an internally dependent
+ // sequence on the field.
+ $sql =
+<<<EOD
+ SELECT
+ a.attname,
+ pg_catalog.format_type(a.atttypid, a.atttypmod) as type,
+ a.atttypmod,
+ a.attnotnull, a.atthasdef, adef.adsrc,
+ (
+ SELECT 1 FROM pg_catalog.pg_depend pd, pg_catalog.pg_class pc
+ WHERE pd.objid=pc.oid
+ AND pd.classid=pc.tableoid
+ AND pd.refclassid=pc.tableoid
+ AND pd.refobjid=a.attrelid
+ AND pd.refobjsubid=a.attnum
+ AND pd.deptype='i'
+ AND pc.relkind='S'
+ ) IS NOT NULL AS attisserial
+
+ FROM
+ pg_catalog.pg_attribute a LEFT JOIN pg_catalog.pg_attrdef adef
+ ON a.attrelid=adef.adrelid
+ AND a.attnum=adef.adnum
+ LEFT JOIN pg_catalog.pg_type t ON a.atttypid=t.oid
+ WHERE
+ a.attrelid = (SELECT oid FROM pg_catalog.pg_class WHERE relname=:table
+ AND relnamespace = (SELECT oid FROM pg_catalog.pg_namespace WHERE
+ nspname = :schema))
+ AND a.attnum > 0 AND NOT a.attisdropped
+ ORDER BY a.attnum
+EOD;
+ $this->getDbConnection()->setActive(true);
+ $command = $this->getDbConnection()->createCommand($sql);
+ $command->bindValue(':table', $tableName);
+ $command->bindValue(':schema', $schemaName);
+ $tableInfo = $this->createNewTableInfo($schemaName, $tableName);
+ $index=0;
+ foreach($command->query() as $col)
+ {
+ $col['index'] = $index++;
+ $this->processColumn($tableInfo, $col);
+ }
+ if($index===0)
+ throw new TDbException('dbmetadata_invalid_table_view', $table);
+ return $tableInfo;
+ }
+
+ /**
+ * @param string table schema name
+ * @param string table name.
+ * @return TPgsqlTableInfo
+ */
+ protected function createNewTableInfo($schemaName,$tableName)
+ {
+ $info['SchemaName'] = $this->assertIdentifier($schemaName);
+ $info['TableName'] = $this->assertIdentifier($tableName);
+ if($this->getIsView($schemaName,$tableName))
+ $info['IsView'] = true;
+ list($primary, $foreign) = $this->getConstraintKeys($schemaName, $tableName);
+ $class = $this->getTableInfoClass();
+ return new $class($info,$primary,$foreign);
+ }
+
+ /**
+ * @param string table name, schema name or column name.
+ * @return string a valid identifier.
+ * @throws TDbException when table name contains a double quote (").
+ */
+ protected function assertIdentifier($name)
+ {
+ if(strpos($name, '"')!==false)
+ {
+ $ref = 'http://www.postgresql.org/docs/7.4/static/sql-syntax.html#SQL-SYNTAX-IDENTIFIERS';
+ throw new TDbException('dbcommon_invalid_identifier_name', $name, $ref);
+ }
+ return $name;
+ }
+
+ /**
+ * @param string table schema name
+ * @param string table name.
+ * @return boolean true if the table is a view.
+ */
+ protected function getIsView($schemaName,$tableName)
+ {
+ $sql =
+<<<EOD
+ SELECT count(c.relname) FROM pg_catalog.pg_class c
+ LEFT JOIN pg_catalog.pg_namespace n ON (n.oid = c.relnamespace)
+ WHERE (n.nspname=:schema) AND (c.relkind = 'v'::"char") AND c.relname = :table
+EOD;
+ $this->getDbConnection()->setActive(true);
+ $command = $this->getDbConnection()->createCommand($sql);
+ $command->bindValue(':schema',$schemaName);
+ $command->bindValue(':table', $tableName);
+ return intval($command->queryScalar()) === 1;
+ }
+
+ /**
+ * @param TPgsqlTableInfo table information.
+ * @param array column information.
+ */
+ protected function processColumn($tableInfo, $col)
+ {
+ $columnId = $col['attname']; //use column name as column Id
+
+ $info['ColumnName'] = '"'.$columnId.'"'; //quote the column names!
+ $info['ColumnId'] = $columnId;
+ $info['ColumnIndex'] = $col['index'];
+ if(!$col['attnotnull'])
+ $info['AllowNull'] = true;
+ if(in_array($columnId, $tableInfo->getPrimaryKeys()))
+ $info['IsPrimaryKey'] = true;
+ if($this->isForeignKeyColumn($columnId, $tableInfo))
+ $info['IsForeignKey'] = true;
+
+ if($col['atttypmod'] > 0)
+ $info['ColumnSize'] = $col['atttypmod'] - 4;
+ if($col['atthasdef'])
+ $info['DefaultValue'] = $col['adsrc'];
+ if($col['attisserial'] || substr($col['adsrc'],0,8) === 'nextval(')
+ {
+ if(($sequence = $this->getSequenceName($tableInfo, $col['adsrc']))!==null)
+ {
+ $info['SequenceName'] = $sequence;
+ unset($info['DefaultValue']);
+ }
+ }
+ $matches = array();
+ if(preg_match('/\((\d+)(?:,(\d+))?+\)/', $col['type'], $matches))
+ {
+ $info['DbType'] = preg_replace('/\(\d+(?:,\d+)?\)/','',$col['type']);
+ if($this->isPrecisionType($info['DbType']))
+ {
+ $info['NumericPrecision'] = intval($matches[1]);
+ if(count($matches) > 2)
+ $info['NumericScale'] = intval($matches[2]);
+ }
+ else
+ $info['ColumnSize'] = intval($matches[1]);
+ }
+ else
+ $info['DbType'] = $col['type'];
+
+ $tableInfo->Columns[$columnId] = new TPgsqlTableColumn($info);
+ }
+
+ /**
+ * @return string serial name if found, null otherwise.
+ */
+ protected function getSequenceName($tableInfo,$src)
+ {
+ $matches = array();
+ if(preg_match('/nextval\([^\']*\'([^\']+)\'[^\)]*\)/i',$src,$matches))
+ {
+ if(is_int(strpos($matches[1], '.')))
+ return $matches[1];
+ else
+ return $tableInfo->getSchemaName().'.'.$matches[1];
+ }
+ }
+
+ /**
+ * @return boolean true if column type if "numeric", "interval" or begins with "time".
+ */
+ protected function isPrecisionType($type)
+ {
+ $type = strtolower(trim($type));
+ return $type==='numeric' || $type==='interval' || strpos($type, 'time')===0;
+ }
+
+ /**
+ * Gets the primary and foreign key column details for the given table.
+ * @param string schema name
+ * @param string table name.
+ * @return array tuple ($primary, $foreign)
+ */
+ protected function getConstraintKeys($schemaName, $tableName)
+ {
+ $sql =
+<<<EOD
+ SELECT conname, consrc, contype, indkey, indisclustered FROM (
+ SELECT
+ conname,
+ CASE WHEN contype='f' THEN
+ pg_catalog.pg_get_constraintdef(oid)
+ ELSE
+ 'CHECK (' || consrc || ')'
+ END AS consrc,
+ contype,
+ conrelid AS relid,
+ NULL AS indkey,
+ FALSE AS indisclustered
+ FROM
+ pg_catalog.pg_constraint
+ WHERE
+ contype IN ('f', 'c')
+ UNION ALL
+ SELECT
+ pc.relname,
+ NULL,
+ CASE WHEN indisprimary THEN
+ 'p'
+ ELSE
+ 'u'
+ END,
+ pi.indrelid,
+ indkey,
+ pi.indisclustered
+ FROM
+ pg_catalog.pg_class pc,
+ pg_catalog.pg_index pi
+ WHERE
+ pc.oid=pi.indexrelid
+ AND EXISTS (
+ SELECT 1 FROM pg_catalog.pg_depend d JOIN pg_catalog.pg_constraint c
+ ON (d.refclassid = c.tableoid AND d.refobjid = c.oid)
+ WHERE d.classid = pc.tableoid AND d.objid = pc.oid AND d.deptype = 'i' AND c.contype IN ('u', 'p')
+ )
+ ) AS sub
+ WHERE relid = (SELECT oid FROM pg_catalog.pg_class WHERE relname=:table
+ AND relnamespace = (SELECT oid FROM pg_catalog.pg_namespace
+ WHERE nspname=:schema))
+ ORDER BY
+ 1
+EOD;
+ $this->getDbConnection()->setActive(true);
+ $command = $this->getDbConnection()->createCommand($sql);
+ $command->bindValue(':table', $tableName);
+ $command->bindValue(':schema', $schemaName);
+ $primary = array();
+ $foreign = array();
+ foreach($command->query() as $row)
+ {
+ switch($row['contype'])
+ {
+ case 'p':
+ $primary = $this->getPrimaryKeys($tableName, $schemaName, $row['indkey']);
+ break;
+ case 'f':
+ if(($fkey = $this->getForeignKeys($row['consrc']))!==null)
+ $foreign[] = $fkey;
+ break;
+ }
+ }
+ return array($primary,$foreign);
+ }
+
+ /**
+ * Gets the primary key field names
+ * @param string pgsql primary key definition
+ * @return array primary key field names.
+ */
+ protected function getPrimaryKeys($tableName, $schemaName, $columnIndex)
+ {
+ $index = join(', ', explode(' ', $columnIndex));
+ $sql =
+<<<EOD
+ SELECT attnum, attname FROM pg_catalog.pg_attribute WHERE
+ attrelid=(
+ SELECT oid FROM pg_catalog.pg_class WHERE relname=:table AND relnamespace=(
+ SELECT oid FROM pg_catalog.pg_namespace WHERE nspname=:schema
+ )
+ )
+ AND attnum IN ({$index})
+EOD;
+ $command = $this->getDbConnection()->createCommand($sql);
+ $command->bindValue(':table', $tableName);
+ $command->bindValue(':schema', $schemaName);
+// $command->bindValue(':columnIndex', join(', ', explode(' ', $columnIndex)));
+ $primary = array();
+ foreach($command->query() as $row)
+ {
+ $primary[] = $row['attname'];
+ }
+
+ return $primary;
+ }
+
+ /**
+ * Gets foreign relationship constraint keys and table name
+ * @param string pgsql foreign key definition
+ * @return array foreign relationship table name and keys, null otherwise
+ */
+ protected function getForeignKeys($src)
+ {
+ $matches = array();
+ $brackets = '\(([^\)]+)\)';
+ $find = "/FOREIGN\s+KEY\s+{$brackets}\s+REFERENCES\s+([^\(]+){$brackets}/i";
+ if(preg_match($find, $src, $matches))
+ {
+ $keys = preg_split('/,\s+/', $matches[1]);
+ $fkeys = array();
+ foreach(preg_split('/,\s+/', $matches[3]) as $i => $fkey)
+ $fkeys[$keys[$i]] = $fkey;
+ return array('table' => str_replace('"','',$matches[2]), 'keys' => $fkeys);
+ }
+ }
+
+ /**
+ * @param string column name.
+ * @param TPgsqlTableInfo table information.
+ * @return boolean true if column is a foreign key.
+ */
+ protected function isForeignKeyColumn($columnId, $tableInfo)
+ {
+ foreach($tableInfo->getForeignKeys() as $fk)
+ {
+ if(in_array($columnId, array_keys($fk['keys'])))
+ return true;
+ }
+ return false;
+ }
+}
+
diff --git a/framework/Data/Common/Pgsql/TPgsqlTableColumn.php b/framework/Data/Common/Pgsql/TPgsqlTableColumn.php
index 46eab9c1..fe8ff499 100644
--- a/framework/Data/Common/Pgsql/TPgsqlTableColumn.php
+++ b/framework/Data/Common/Pgsql/TPgsqlTableColumn.php
@@ -1,49 +1,49 @@
<?php
-/**
- * TPgsqlTableColumn class file.
- *
- * @author Wei Zhuo <weizhuo[at]gmail[dot]com>
- * @link http://www.pradosoft.com/
+/**
+ * TPgsqlTableColumn class file.
+ *
+ * @author Wei Zhuo <weizhuo[at]gmail[dot]com>
+ * @link http://www.pradosoft.com/
* @copyright Copyright &copy; 2005-2012 PradoSoft
- * @license http://www.pradosoft.com/license/
- * @version $Id$
- * @package System.Data.Common.Pgsql
- */
-
-/**
- * Load common TDbTableCommon class.
- */
-Prado::using('System.Data.Common.TDbTableColumn');
-
-/**
- * Describes the column metadata of the schema for a PostgreSQL database table.
- *
- * @author Wei Zhuo <weizho[at]gmail[dot]com>
- * @version $Id$
- * @package System.Data.Common.Pgsql
- * @since 3.1
- */
-class TPgsqlTableColumn extends TDbTableColumn
-{
- private static $types=array(
- 'integer' => array('bit', 'bit varying', 'real', 'serial', 'int', 'integer'),
- 'boolean' => array('boolean'),
- 'float' => array('bigint', 'bigserial', 'double precision', 'money', 'numeric')
- );
-
- /**
- * Overrides parent implementation, returns PHP type from the db type.
- * @return boolean derived PHP primitive type from the column db type.
- */
- public function getPHPType()
- {
- $dbtype = strtolower($this->getDbType());
- foreach(self::$types as $type => $dbtypes)
- {
- if(in_array($dbtype, $dbtypes))
- return $type;
- }
- return 'string';
- }
-}
+ * @license http://www.pradosoft.com/license/
+ * @version $Id$
+ * @package System.Data.Common.Pgsql
+ */
+
+/**
+ * Load common TDbTableCommon class.
+ */
+Prado::using('System.Data.Common.TDbTableColumn');
+
+/**
+ * Describes the column metadata of the schema for a PostgreSQL database table.
+ *
+ * @author Wei Zhuo <weizho[at]gmail[dot]com>
+ * @version $Id$
+ * @package System.Data.Common.Pgsql
+ * @since 3.1
+ */
+class TPgsqlTableColumn extends TDbTableColumn
+{
+ private static $types=array(
+ 'integer' => array('bit', 'bit varying', 'real', 'serial', 'int', 'integer'),
+ 'boolean' => array('boolean'),
+ 'float' => array('bigint', 'bigserial', 'double precision', 'money', 'numeric')
+ );
+
+ /**
+ * Overrides parent implementation, returns PHP type from the db type.
+ * @return boolean derived PHP primitive type from the column db type.
+ */
+ public function getPHPType()
+ {
+ $dbtype = strtolower($this->getDbType());
+ foreach(self::$types as $type => $dbtypes)
+ {
+ if(in_array($dbtype, $dbtypes))
+ return $type;
+ }
+ return 'string';
+ }
+}
diff --git a/framework/Data/Common/Pgsql/TPgsqlTableInfo.php b/framework/Data/Common/Pgsql/TPgsqlTableInfo.php
index 11e5a613..6ad941d7 100644
--- a/framework/Data/Common/Pgsql/TPgsqlTableInfo.php
+++ b/framework/Data/Common/Pgsql/TPgsqlTableInfo.php
@@ -1,58 +1,58 @@
<?php
-/**
- * TPgsqlTableInfo class file.
- *
- * @author Wei Zhuo <weizhuo[at]gmail[dot]com>
- * @link http://www.pradosoft.com/
+/**
+ * TPgsqlTableInfo class file.
+ *
+ * @author Wei Zhuo <weizhuo[at]gmail[dot]com>
+ * @link http://www.pradosoft.com/
* @copyright Copyright &copy; 2005-2012 PradoSoft
- * @license http://www.pradosoft.com/license/
- * @version $Id$
- * @package System.Data.Common.Pgsql
- */
-
-/**
- * Loads the base TDbTableInfo class and TPgsqlTableColumn class.
- */
-Prado::using('System.Data.Common.TDbTableInfo');
-Prado::using('System.Data.Common.Pgsql.TPgsqlTableColumn');
-
-/**
- * TPgsqlTableInfo class provides additional table information for PostgreSQL database.
- *
- * @author Wei Zhuo <weizho[at]gmail[dot]com>
- * @version $Id$
- * @package System.Data.Common.Pgsql
- * @since 3.1
- */
-class TPgsqlTableInfo extends TDbTableInfo
-{
- /**
- * @return string name of the schema this column belongs to.
- */
- public function getSchemaName()
- {
- return $this->getInfo('SchemaName');
- }
-
- /**
- * @return string full name of the table, database dependent.
- */
- public function getTableFullName()
- {
- if(($schema=$this->getSchemaName())!==null)
- return $schema.'.'.$this->getTableName();
- else
- return $this->getTableName();
- }
-
- /**
- * @param TDbConnection database connection.
- * @return TDbCommandBuilder new command builder
- */
- public function createCommandBuilder($connection)
- {
- Prado::using('System.Data.Common.Pgsql.TPgsqlCommandBuilder');
- return new TPgsqlCommandBuilder($connection,$this);
- }
-}
+ * @license http://www.pradosoft.com/license/
+ * @version $Id$
+ * @package System.Data.Common.Pgsql
+ */
+
+/**
+ * Loads the base TDbTableInfo class and TPgsqlTableColumn class.
+ */
+Prado::using('System.Data.Common.TDbTableInfo');
+Prado::using('System.Data.Common.Pgsql.TPgsqlTableColumn');
+
+/**
+ * TPgsqlTableInfo class provides additional table information for PostgreSQL database.
+ *
+ * @author Wei Zhuo <weizho[at]gmail[dot]com>
+ * @version $Id$
+ * @package System.Data.Common.Pgsql
+ * @since 3.1
+ */
+class TPgsqlTableInfo extends TDbTableInfo
+{
+ /**
+ * @return string name of the schema this column belongs to.
+ */
+ public function getSchemaName()
+ {
+ return $this->getInfo('SchemaName');
+ }
+
+ /**
+ * @return string full name of the table, database dependent.
+ */
+ public function getTableFullName()
+ {
+ if(($schema=$this->getSchemaName())!==null)
+ return $schema.'.'.$this->getTableName();
+ else
+ return $this->getTableName();
+ }
+
+ /**
+ * @param TDbConnection database connection.
+ * @return TDbCommandBuilder new command builder
+ */
+ public function createCommandBuilder($connection)
+ {
+ Prado::using('System.Data.Common.Pgsql.TPgsqlCommandBuilder');
+ return new TPgsqlCommandBuilder($connection,$this);
+ }
+}
diff --git a/framework/Data/Common/Sqlite/TSqliteCommandBuilder.php b/framework/Data/Common/Sqlite/TSqliteCommandBuilder.php
index d162ed60..d7d82812 100644
--- a/framework/Data/Common/Sqlite/TSqliteCommandBuilder.php
+++ b/framework/Data/Common/Sqlite/TSqliteCommandBuilder.php
@@ -1,47 +1,47 @@
-<?php
-/**
- * TSqliteCommandBuilder class file.
- *
- * @author Wei Zhuo <weizhuo[at]gmail[dot]com>
- * @link http://www.pradosoft.com/
+<?php
+/**
+ * TSqliteCommandBuilder class file.
+ *
+ * @author Wei Zhuo <weizhuo[at]gmail[dot]com>
+ * @link http://www.pradosoft.com/
* @copyright Copyright &copy; 2005-2012 PradoSoft
- * @license http://www.pradosoft.com/license/
- * @version $Id: TDbCommandBuilder.php 1863 2007-04-12 12:43:49Z wei $
- * @package System.Data.Common
- */
-
-Prado::using('System.Data.Common.TDbCommandBuilder');
-
-/**
- * TSqliteCommandBuilder provides specifics methods to create limit/offset query commands
- * for Sqlite database.
- *
- * @author Wei Zhuo <weizho[at]gmail[dot]com>
- * @version $Id: TDbCommandBuilder.php 1863 2007-04-12 12:43:49Z wei $
- * @package System.Data.Common
- * @since 3.1
- */
-class TSqliteCommandBuilder extends TDbCommandBuilder
-{
- /**
- * Alters the sql to apply $limit and $offset.
- * @param string SQL query string.
- * @param integer maximum number of rows, -1 to ignore limit.
- * @param integer row offset, -1 to ignore offset.
- * @return string SQL with limit and offset.
- */
- public function applyLimitOffset($sql, $limit=-1, $offset=-1)
- {
- $limit = $limit!==null ? intval($limit) : -1;
- $offset = $offset!==null ? intval($offset) : -1;
- if($limit > 0 || $offset > 0)
- {
- $limitStr = ' LIMIT '.$limit;
- $offsetStr = $offset >= 0 ? ' OFFSET '.$offset : '';
- return $sql.$limitStr.$offsetStr;
- }
- else
- return $sql;
- }
-}
-
+ * @license http://www.pradosoft.com/license/
+ * @version $Id: TDbCommandBuilder.php 1863 2007-04-12 12:43:49Z wei $
+ * @package System.Data.Common
+ */
+
+Prado::using('System.Data.Common.TDbCommandBuilder');
+
+/**
+ * TSqliteCommandBuilder provides specifics methods to create limit/offset query commands
+ * for Sqlite database.
+ *
+ * @author Wei Zhuo <weizho[at]gmail[dot]com>
+ * @version $Id: TDbCommandBuilder.php 1863 2007-04-12 12:43:49Z wei $
+ * @package System.Data.Common
+ * @since 3.1
+ */
+class TSqliteCommandBuilder extends TDbCommandBuilder
+{
+ /**
+ * Alters the sql to apply $limit and $offset.
+ * @param string SQL query string.
+ * @param integer maximum number of rows, -1 to ignore limit.
+ * @param integer row offset, -1 to ignore offset.
+ * @return string SQL with limit and offset.
+ */
+ public function applyLimitOffset($sql, $limit=-1, $offset=-1)
+ {
+ $limit = $limit!==null ? intval($limit) : -1;
+ $offset = $offset!==null ? intval($offset) : -1;
+ if($limit > 0 || $offset > 0)
+ {
+ $limitStr = ' LIMIT '.$limit;
+ $offsetStr = $offset >= 0 ? ' OFFSET '.$offset : '';
+ return $sql.$limitStr.$offsetStr;
+ }
+ else
+ return $sql;
+ }
+}
+
diff --git a/framework/Data/Common/Sqlite/TSqliteMetaData.php b/framework/Data/Common/Sqlite/TSqliteMetaData.php
index 5acfad9d..d101d179 100644
--- a/framework/Data/Common/Sqlite/TSqliteMetaData.php
+++ b/framework/Data/Common/Sqlite/TSqliteMetaData.php
@@ -1,210 +1,210 @@
-<?php
-/**
- * TSqliteMetaData class file.
- *
- * @author Wei Zhuo <weizhuo[at]gmail[dot]com>
- * @link http://www.pradosoft.com/
- * @copyright Copyright &copy; 2005-2012 PradoSoft
- * @license http://www.pradosoft.com/license/
- * @version $Id: TSqliteMetaData.php 1861 2007-04-12 08:05:03Z wei $
- * @package System.Data.Common.Sqlite
- */
-
-/**
- * Load the base TDbMetaData class.
- */
-Prado::using('System.Data.Common.TDbMetaData');
-Prado::using('System.Data.Common.Sqlite.TSqliteTableInfo');
-
-/**
- * TSqliteMetaData loads SQLite database table and column information.
- *
- * @author Wei Zhuo <weizho[at]gmail[dot]com>
- * @version $Id: TSqliteMetaData.php 1861 2007-04-12 08:05:03Z wei $
- * @package System.Data.Commom.Sqlite
- * @since 3.1
- */
-class TSqliteMetaData extends TDbMetaData
-{
- /**
- * @return string TDbTableInfo class name.
- */
- protected function getTableInfoClass()
- {
- return 'TSqliteTableInfo';
- }
-
- /**
- * Quotes a table name for use in a query.
- * @param string $name table name
- * @return string the properly quoted table name
- */
- public function quoteTableName($name)
- {
- return parent::quoteTableName($name, "'", "'");
- }
-
- /**
- * Quotes a column name for use in a query.
- * @param string $name column name
- * @return string the properly quoted column name
- */
- public function quoteColumnName($name)
- {
- return parent::quoteColumnName($name, '"', '"');
- }
-
- /**
- * Quotes a column alias for use in a query.
- * @param string $name column alias
- * @return string the properly quoted column alias
- */
- public function quoteColumnAlias($name)
- {
- return parent::quoteColumnAlias($name, '"', '"');
- }
-
- /**
- * Get the column definitions for given table.
- * @param string table name.
- * @return TPgsqlTableInfo table information.
- */
- protected function createTableInfo($tableName)
- {
- $tableName = str_replace("'",'',$tableName);
- $this->getDbConnection()->setActive(true);
- $table = $this->getDbConnection()->quoteString($tableName);
- $sql = "PRAGMA table_info({$table})";
- $command = $this->getDbConnection()->createCommand($sql);
- $foreign = $this->getForeignKeys($table);
- $index=0;
- $columns=array();
- $primary=array();
- foreach($command->query() as $col)
- {
- $col['index'] = $index++;
- $column = $this->processColumn($col, $foreign);
- $columns[$col['name']] = $column;
- if($column->getIsPrimaryKey())
- $primary[] = $col['name'];
- }
- $info['TableName'] = $tableName;
- if($this->getIsView($tableName))
- $info['IsView'] = true;
- if(count($columns)===0)
- throw new TDbException('dbmetadata_invalid_table_view', $tableName);
- $class = $this->getTableInfoClass();
- $tableInfo = new $class($info,$primary,$foreign);
- $tableInfo->getColumns()->copyFrom($columns);
- return $tableInfo;
- }
-
- /**
- * @param string table name.
- * @return boolean true if the table is a view.
- */
- protected function getIsView($tableName)
- {
- $sql = 'SELECT count(*) FROM sqlite_master WHERE type="view" AND name= :table';
- $this->getDbConnection()->setActive(true);
- $command = $this->getDbConnection()->createCommand($sql);
- $command->bindValue(':table', $tableName);
- return intval($command->queryScalar()) === 1;
- }
-
- /**
- * @param array column information.
- * @param array foreign key details.
- * @return TSqliteTableColumn column details.
- */
- protected function processColumn($col, $foreign)
- {
- $columnId = $col['name']; //use column name as column Id
-
- $info['ColumnName'] = '"'.$columnId.'"'; //quote the column names!
- $info['ColumnId'] = $columnId;
- $info['ColumnIndex'] = $col['index'];
-
- if($col['notnull']!=='99')
- $info['AllowNull'] = true;
-
- if($col['pk']==='1')
- $info['IsPrimaryKey'] = true;
- if($this->isForeignKeyColumn($columnId, $foreign))
- $info['IsForeignKey'] = true;
-
- if($col['dflt_value']!==null)
- $info['DefaultValue'] = $col['dflt_value'];
-
- $type = strtolower($col['type']);
- $info['AutoIncrement'] = $type==='integer' && $col['pk']==='1';
-
- $info['DbType'] = $type;
- $match=array();
- if(is_int($pos=strpos($type, '(')) && preg_match('/\((.*)\)/', $type, $match))
- {
- $ps = explode(',', $match[1]);
- if(count($ps)===2)
- {
- $info['NumericPrecision'] = intval($ps[0]);
- $info['NumericScale'] = intval($ps[1]);
- }
- else
- $info['ColumnSize']=intval($match[1]);
- $info['DbType'] = substr($type,0,$pos);
- }
-
- return new TSqliteTableColumn($info);
- }
-
- /**
- *
- *
- * @param string quoted table name.
- * @return array foreign key details.
- */
- protected function getForeignKeys($table)
- {
- $sql = "PRAGMA foreign_key_list({$table})";
- $command = $this->getDbConnection()->createCommand($sql);
- $fkeys = array();
- foreach($command->query() as $col)
- {
- $fkeys[$col['table']]['keys'][$col['from']] = $col['to'];
- $fkeys[$col['table']]['table'] = $col['table'];
- }
- return count($fkeys) > 0 ? array_values($fkeys) : $fkeys;
- }
-
- /**
- * @param string column name.
- * @param array foreign key column names.
- * @return boolean true if column is a foreign key.
- */
- protected function isForeignKeyColumn($columnId, $foreign)
- {
- foreach($foreign as $fk)
- {
- if(in_array($columnId, array_keys($fk['keys'])))
- return true;
- }
- return false;
- }
-}
-
-/**
-
-CREATE TABLE foo
-(
- id INTEGER NOT NULL PRIMARY KEY,
- id2 CHAR(2)
-);
-
-CREATE TABLE bar
-(
- id INTEGER NOT NULL PRIMARY KEY,
- foo_id INTEGER
- CONSTRAINT fk_foo_id REFERENCES foo(id) ON DELETE CASCADE
-);
-*/
-
+<?php
+/**
+ * TSqliteMetaData class file.
+ *
+ * @author Wei Zhuo <weizhuo[at]gmail[dot]com>
+ * @link http://www.pradosoft.com/
+ * @copyright Copyright &copy; 2005-2012 PradoSoft
+ * @license http://www.pradosoft.com/license/
+ * @version $Id: TSqliteMetaData.php 1861 2007-04-12 08:05:03Z wei $
+ * @package System.Data.Common.Sqlite
+ */
+
+/**
+ * Load the base TDbMetaData class.
+ */
+Prado::using('System.Data.Common.TDbMetaData');
+Prado::using('System.Data.Common.Sqlite.TSqliteTableInfo');
+
+/**
+ * TSqliteMetaData loads SQLite database table and column information.
+ *
+ * @author Wei Zhuo <weizho[at]gmail[dot]com>
+ * @version $Id: TSqliteMetaData.php 1861 2007-04-12 08:05:03Z wei $
+ * @package System.Data.Commom.Sqlite
+ * @since 3.1
+ */
+class TSqliteMetaData extends TDbMetaData
+{
+ /**
+ * @return string TDbTableInfo class name.
+ */
+ protected function getTableInfoClass()
+ {
+ return 'TSqliteTableInfo';
+ }
+
+ /**
+ * Quotes a table name for use in a query.
+ * @param string $name table name
+ * @return string the properly quoted table name
+ */
+ public function quoteTableName($name)
+ {
+ return parent::quoteTableName($name, "'", "'");
+ }
+
+ /**
+ * Quotes a column name for use in a query.
+ * @param string $name column name
+ * @return string the properly quoted column name
+ */
+ public function quoteColumnName($name)
+ {
+ return parent::quoteColumnName($name, '"', '"');
+ }
+
+ /**
+ * Quotes a column alias for use in a query.
+ * @param string $name column alias
+ * @return string the properly quoted column alias
+ */
+ public function quoteColumnAlias($name)
+ {
+ return parent::quoteColumnAlias($name, '"', '"');
+ }
+
+ /**
+ * Get the column definitions for given table.
+ * @param string table name.
+ * @return TPgsqlTableInfo table information.
+ */
+ protected function createTableInfo($tableName)
+ {
+ $tableName = str_replace("'",'',$tableName);
+ $this->getDbConnection()->setActive(true);
+ $table = $this->getDbConnection()->quoteString($tableName);
+ $sql = "PRAGMA table_info({$table})";
+ $command = $this->getDbConnection()->createCommand($sql);
+ $foreign = $this->getForeignKeys($table);
+ $index=0;
+ $columns=array();
+ $primary=array();
+ foreach($command->query() as $col)
+ {
+ $col['index'] = $index++;
+ $column = $this->processColumn($col, $foreign);
+ $columns[$col['name']] = $column;
+ if($column->getIsPrimaryKey())
+ $primary[] = $col['name'];
+ }
+ $info['TableName'] = $tableName;
+ if($this->getIsView($tableName))
+ $info['IsView'] = true;
+ if(count($columns)===0)
+ throw new TDbException('dbmetadata_invalid_table_view', $tableName);
+ $class = $this->getTableInfoClass();
+ $tableInfo = new $class($info,$primary,$foreign);
+ $tableInfo->getColumns()->copyFrom($columns);
+ return $tableInfo;
+ }
+
+ /**
+ * @param string table name.
+ * @return boolean true if the table is a view.
+ */
+ protected function getIsView($tableName)
+ {
+ $sql = 'SELECT count(*) FROM sqlite_master WHERE type="view" AND name= :table';
+ $this->getDbConnection()->setActive(true);
+ $command = $this->getDbConnection()->createCommand($sql);
+ $command->bindValue(':table', $tableName);
+ return intval($command->queryScalar()) === 1;
+ }
+
+ /**
+ * @param array column information.
+ * @param array foreign key details.
+ * @return TSqliteTableColumn column details.
+ */
+ protected function processColumn($col, $foreign)
+ {
+ $columnId = $col['name']; //use column name as column Id
+
+ $info['ColumnName'] = '"'.$columnId.'"'; //quote the column names!
+ $info['ColumnId'] = $columnId;
+ $info['ColumnIndex'] = $col['index'];
+
+ if($col['notnull']!=='99')
+ $info['AllowNull'] = true;
+
+ if($col['pk']==='1')
+ $info['IsPrimaryKey'] = true;
+ if($this->isForeignKeyColumn($columnId, $foreign))
+ $info['IsForeignKey'] = true;
+
+ if($col['dflt_value']!==null)
+ $info['DefaultValue'] = $col['dflt_value'];
+
+ $type = strtolower($col['type']);
+ $info['AutoIncrement'] = $type==='integer' && $col['pk']==='1';
+
+ $info['DbType'] = $type;
+ $match=array();
+ if(is_int($pos=strpos($type, '(')) && preg_match('/\((.*)\)/', $type, $match))
+ {
+ $ps = explode(',', $match[1]);
+ if(count($ps)===2)
+ {
+ $info['NumericPrecision'] = intval($ps[0]);
+ $info['NumericScale'] = intval($ps[1]);
+ }
+ else
+ $info['ColumnSize']=intval($match[1]);
+ $info['DbType'] = substr($type,0,$pos);
+ }
+
+ return new TSqliteTableColumn($info);
+ }
+
+ /**
+ *
+ *
+ * @param string quoted table name.
+ * @return array foreign key details.
+ */
+ protected function getForeignKeys($table)
+ {
+ $sql = "PRAGMA foreign_key_list({$table})";
+ $command = $this->getDbConnection()->createCommand($sql);
+ $fkeys = array();
+ foreach($command->query() as $col)
+ {
+ $fkeys[$col['table']]['keys'][$col['from']] = $col['to'];
+ $fkeys[$col['table']]['table'] = $col['table'];
+ }
+ return count($fkeys) > 0 ? array_values($fkeys) : $fkeys;
+ }
+
+ /**
+ * @param string column name.
+ * @param array foreign key column names.
+ * @return boolean true if column is a foreign key.
+ */
+ protected function isForeignKeyColumn($columnId, $foreign)
+ {
+ foreach($foreign as $fk)
+ {
+ if(in_array($columnId, array_keys($fk['keys'])))
+ return true;
+ }
+ return false;
+ }
+}
+
+/**
+
+CREATE TABLE foo
+(
+ id INTEGER NOT NULL PRIMARY KEY,
+ id2 CHAR(2)
+);
+
+CREATE TABLE bar
+(
+ id INTEGER NOT NULL PRIMARY KEY,
+ foo_id INTEGER
+ CONSTRAINT fk_foo_id REFERENCES foo(id) ON DELETE CASCADE
+);
+*/
+
diff --git a/framework/Data/Common/Sqlite/TSqliteTableColumn.php b/framework/Data/Common/Sqlite/TSqliteTableColumn.php
index 915debbe..6783e1ad 100644
--- a/framework/Data/Common/Sqlite/TSqliteTableColumn.php
+++ b/framework/Data/Common/Sqlite/TSqliteTableColumn.php
@@ -1,64 +1,64 @@
-<?php
-/**
- * TSqliteTableColumn class file.
- *
- * @author Wei Zhuo <weizhuo[at]gmail[dot]com>
- * @link http://www.pradosoft.com/
+<?php
+/**
+ * TSqliteTableColumn class file.
+ *
+ * @author Wei Zhuo <weizhuo[at]gmail[dot]com>
+ * @link http://www.pradosoft.com/
* @copyright Copyright &copy; 2005-2012 PradoSoft
- * @license http://www.pradosoft.com/license/
- * @version $Id: TSqliteTableColumn.php 1861 2007-04-12 08:05:03Z wei $
- * @package System.Data.Common.Sqlite
- */
-
-/**
- * Load common TDbTableCommon class.
- */
-Prado::using('System.Data.Common.TDbTableColumn');
-
-/**
- * Describes the column metadata of the schema for a PostgreSQL database table.
- *
- * @author Wei Zhuo <weizho[at]gmail[dot]com>
- * @version $Id: TSqliteTableColumn.php 1861 2007-04-12 08:05:03Z wei $
- * @package System.Data.Common.Sqlite
- * @since 3.1
- */
-class TSqliteTableColumn extends TDbTableColumn
-{
- /**
- * @TODO add sqlite types.
- */
- private static $types = array();
-
- /**
- * Overrides parent implementation, returns PHP type from the db type.
- * @return boolean derived PHP primitive type from the column db type.
- */
- public function getPHPType()
- {
- $dbtype = strtolower($this->getDbType());
- foreach(self::$types as $type => $dbtypes)
- {
- if(in_array($dbtype, $dbtypes))
- return $type;
- }
- return 'string';
- }
-
- /**
- * @return boolean true if column will auto-increment when the column value is inserted as null.
- */
- public function getAutoIncrement()
- {
- return $this->getInfo('AutoIncrement', false);
- }
-
- /**
- * @return boolean true if auto increment is true.
- */
- public function hasSequence()
- {
- return $this->getAutoIncrement();
- }
-}
-
+ * @license http://www.pradosoft.com/license/
+ * @version $Id: TSqliteTableColumn.php 1861 2007-04-12 08:05:03Z wei $
+ * @package System.Data.Common.Sqlite
+ */
+
+/**
+ * Load common TDbTableCommon class.
+ */
+Prado::using('System.Data.Common.TDbTableColumn');
+
+/**
+ * Describes the column metadata of the schema for a PostgreSQL database table.
+ *
+ * @author Wei Zhuo <weizho[at]gmail[dot]com>
+ * @version $Id: TSqliteTableColumn.php 1861 2007-04-12 08:05:03Z wei $
+ * @package System.Data.Common.Sqlite
+ * @since 3.1
+ */
+class TSqliteTableColumn extends TDbTableColumn
+{
+ /**
+ * @TODO add sqlite types.
+ */
+ private static $types = array();
+
+ /**
+ * Overrides parent implementation, returns PHP type from the db type.
+ * @return boolean derived PHP primitive type from the column db type.
+ */
+ public function getPHPType()
+ {
+ $dbtype = strtolower($this->getDbType());
+ foreach(self::$types as $type => $dbtypes)
+ {
+ if(in_array($dbtype, $dbtypes))
+ return $type;
+ }
+ return 'string';
+ }
+
+ /**
+ * @return boolean true if column will auto-increment when the column value is inserted as null.
+ */
+ public function getAutoIncrement()
+ {
+ return $this->getInfo('AutoIncrement', false);
+ }
+
+ /**
+ * @return boolean true if auto increment is true.
+ */
+ public function hasSequence()
+ {
+ return $this->getAutoIncrement();
+ }
+}
+
diff --git a/framework/Data/Common/Sqlite/TSqliteTableInfo.php b/framework/Data/Common/Sqlite/TSqliteTableInfo.php
index fe9ab846..420dce85 100644
--- a/framework/Data/Common/Sqlite/TSqliteTableInfo.php
+++ b/framework/Data/Common/Sqlite/TSqliteTableInfo.php
@@ -1,47 +1,47 @@
-<?php
-/**
- * TSqliteTableInfo class file.
- *
- * @author Wei Zhuo <weizhuo[at]gmail[dot]com>
- * @link http://www.pradosoft.com/
+<?php
+/**
+ * TSqliteTableInfo class file.
+ *
+ * @author Wei Zhuo <weizhuo[at]gmail[dot]com>
+ * @link http://www.pradosoft.com/
* @copyright Copyright &copy; 2005-2012 PradoSoft
- * @license http://www.pradosoft.com/license/
- * @version $Id: TSqliteTableInfo.php 1861 2007-04-12 08:05:03Z wei $
- * @package System.Data.Common.Sqlite
- */
-
-/**
- * Loads the base TDbTableInfo class and TSqliteTableColumn class.
- */
-Prado::using('System.Data.Common.TDbTableInfo');
-Prado::using('System.Data.Common.Sqlite.TSqliteTableColumn');
-
-/**
- * TSqliteTableInfo class provides additional table information for PostgreSQL database.
- *
- * @author Wei Zhuo <weizho[at]gmail[dot]com>
- * @version $Id: TSqliteTableInfo.php 1861 2007-04-12 08:05:03Z wei $
- * @package System.Data.Common.Sqlite
- * @since 3.1
- */
-class TSqliteTableInfo extends TDbTableInfo
-{
- /**
- * @param TDbConnection database connection.
- * @return TDbCommandBuilder new command builder
- */
- public function createCommandBuilder($connection)
- {
- Prado::using('System.Data.Common.Sqlite.TSqliteCommandBuilder');
- return new TSqliteCommandBuilder($connection,$this);
- }
-
- /**
- * @return string full name of the table, database dependent.
- */
- public function getTableFullName()
- {
- return "'".$this->getTableName()."'";
- }
-}
-
+ * @license http://www.pradosoft.com/license/
+ * @version $Id: TSqliteTableInfo.php 1861 2007-04-12 08:05:03Z wei $
+ * @package System.Data.Common.Sqlite
+ */
+
+/**
+ * Loads the base TDbTableInfo class and TSqliteTableColumn class.
+ */
+Prado::using('System.Data.Common.TDbTableInfo');
+Prado::using('System.Data.Common.Sqlite.TSqliteTableColumn');
+
+/**
+ * TSqliteTableInfo class provides additional table information for PostgreSQL database.
+ *
+ * @author Wei Zhuo <weizho[at]gmail[dot]com>
+ * @version $Id: TSqliteTableInfo.php 1861 2007-04-12 08:05:03Z wei $
+ * @package System.Data.Common.Sqlite
+ * @since 3.1
+ */
+class TSqliteTableInfo extends TDbTableInfo
+{
+ /**
+ * @param TDbConnection database connection.
+ * @return TDbCommandBuilder new command builder
+ */
+ public function createCommandBuilder($connection)
+ {
+ Prado::using('System.Data.Common.Sqlite.TSqliteCommandBuilder');
+ return new TSqliteCommandBuilder($connection,$this);
+ }
+
+ /**
+ * @return string full name of the table, database dependent.
+ */
+ public function getTableFullName()
+ {
+ return "'".$this->getTableName()."'";
+ }
+}
+
diff --git a/framework/Data/Common/TDbCommandBuilder.php b/framework/Data/Common/TDbCommandBuilder.php
index 212e5f02..ebdede99 100644
--- a/framework/Data/Common/TDbCommandBuilder.php
+++ b/framework/Data/Common/TDbCommandBuilder.php
@@ -1,507 +1,507 @@
-<?php
-/**
- * TDbCommandBuilder class file.
- *
- * @author Wei Zhuo <weizhuo[at]gmail[dot]com>
- * @link http://www.pradosoft.com/
- * @copyright Copyright &copy; 2005-2012 PradoSoft
- * @license http://www.pradosoft.com/license/
- * @version $Id$
- * @package System.Data.Common
- */
-
-/**
- * TDbCommandBuilder provides basic methods to create query commands for tables
- * giving by {@link setTableInfo TableInfo} the property.
- *
- * @author Wei Zhuo <weizho[at]gmail[dot]com>
- * @version $Id$
- * @package System.Data.Common
- * @since 3.1
- */
-class TDbCommandBuilder extends TComponent
-{
- private $_connection;
- private $_tableInfo;
-
- /**
- * @param TDbConnection database connection.
- * @param TDbTableInfo table information.
- */
- public function __construct($connection=null, $tableInfo=null)
- {
- $this->setDbConnection($connection);
- $this->setTableInfo($tableInfo);
- }
-
- /**
- * @return TDbConnection database connection.
- */
- public function getDbConnection()
- {
- return $this->_connection;
- }
-
- /**
- * @param TDbConnection database connection.
- */
- public function setDbConnection($value)
- {
- $this->_connection=$value;
- }
-
- /**
- * @param TDbTableInfo table information.
- */
- public function setTableInfo($value)
- {
- $this->_tableInfo=$value;
- }
-
- /**
- * @param TDbTableInfo table information.
- */
- public function getTableInfo()
- {
- return $this->_tableInfo;
- }
-
- /**
- * Iterate through all the columns and returns the last insert id of the
- * first column that has a sequence or serial.
- * @return mixed last insert id, null if none is found.
- */
- public function getLastInsertID()
- {
- foreach($this->getTableInfo()->getColumns() as $column)
- {
- if($column->hasSequence())
- return $this->getDbConnection()->getLastInsertID($column->getSequenceName());
- }
- }
-
- /**
- * Alters the sql to apply $limit and $offset. Default implementation is applicable
- * for PostgreSQL, MySQL and SQLite.
- * @param string SQL query string.
- * @param integer maximum number of rows, -1 to ignore limit.
- * @param integer row offset, -1 to ignore offset.
- * @return string SQL with limit and offset.
- */
- public function applyLimitOffset($sql, $limit=-1, $offset=-1)
- {
- $limit = $limit!==null ? (int)$limit : -1;
- $offset = $offset!==null ? (int)$offset : -1;
- $limitStr = $limit >= 0 ? ' LIMIT '.$limit : '';
- $offsetStr = $offset >= 0 ? ' OFFSET '.$offset : '';
- return $sql.$limitStr.$offsetStr;
- }
-
- /**
- * @param string SQL string without existing ordering.
- * @param array pairs of column names as key and direction as value.
- * @return string modified SQL applied with ORDER BY.
- */
- public function applyOrdering($sql, $ordering)
- {
- $orders=array();
- foreach($ordering as $name => $direction)
- {
- $direction = strtolower($direction) == 'desc' ? 'DESC' : 'ASC';
- if(false !== strpos($name, '(') && false !== strpos($name, ')')) {
- // key is a function (bad practice, but we need to handle it)
- $key = $name;
- } else {
- // key is a column
- $key = $this->getTableInfo()->getColumn($name)->getColumnName();
- }
- $orders[] = $key.' '.$direction;
- }
- if(count($orders) > 0)
- $sql .= ' ORDER BY '.implode(', ', $orders);
- return $sql;
- }
-
- /**
- * Computes the SQL condition for search a set of column using regular expression
- * (or LIKE, depending on database implementation) to match a string of
- * keywords (default matches all keywords).
- * @param array list of column id for potential search condition.
- * @param string string of keywords
- * @return string SQL search condition matching on a set of columns.
- */
- public function getSearchExpression($fields, $keywords)
- {
- if(strlen(trim($keywords)) == 0) return '';
- $words = preg_split('/\s/u', $keywords);
- $conditions = array();
- foreach($fields as $field)
- {
- $column = $this->getTableInfo()->getColumn($field)->getColumnName();
- $conditions[] = $this->getSearchCondition($column, $words);
- }
- return '('.implode(' OR ', $conditions).')';
- }
-
- /**
- * @param string column name.
- * @param array keywords
- * @return string search condition for all words in one column.
- */
- protected function getSearchCondition($column, $words)
- {
- $conditions=array();
- foreach($words as $word)
- $conditions[] = $column.' LIKE '.$this->getDbConnection()->quoteString('%'.$word.'%');
- return '('.implode(' AND ', $conditions).')';
- }
-
- /**
- *
- * Different behavior depends on type of passed data
- * string
- * usage without modification
- *
- * null
- * will be expanded to full list of quoted table column names (quoting depends on database)
- *
- * array
- * - Column names will be quoted if used as key or value of array
- * <code>
- * array('col1', 'col2', 'col2')
- * // SELECT `col1`, `col2`, `col3` FROM...
- * </code>
- *
- * - Column aliasing
- * <code>
- * array('mycol1' => 'col1', 'mycol2' => 'COUNT(*)')
- * // SELECT `col1` AS mycol1, COUNT(*) AS mycol2 FROM...
- * </code>
- *
- * - NULL and scalar values (strings will be quoted depending on database)
- * <code>
- * array('col1' => 'my custom string', 'col2' => 1.0, 'col3' => 'NULL')
- * // SELECT "my custom string" AS `col1`, 1.0 AS `col2`, NULL AS `col3` FROM...
- * </code>
- *
- * - If the *-wildcard char is used as key or value, add the full list of quoted table column names
- * <code>
- * array('col1' => 'NULL', '*')
- * // SELECT `col1`, `col2`, `col3`, NULL AS `col1` FROM...
- * </code>
- * @param mixed $value
- * @return array of generated fields - use implode(', ', $selectfieldlist) to collapse field list for usage
- * @since 3.1.7
- * @todo add support for table aliasing
- * @todo add support for quoting of column aliasing
- */
- public function getSelectFieldList($data='*') {
- if(is_scalar($data)) {
- $tmp = explode(',', $data);
- $result = array();
- foreach($tmp as $v)
- $result[] = trim($v);
- return $result;
- }
-
- $bHasWildcard = false;
- $result = array();
- if(is_array($data) || $data instanceof Traversable) {
- $columns = $this->getTableInfo()->getColumns();
- foreach($data as $key=>$value) {
- if($key==='*' || $value==='*') {
- $bHasWildcard = true;
- continue;
- }
-
- if(strToUpper($key)==='NULL') {
- $result[] = 'NULL';
- continue;
- }
-
- if(strpos($key, '(')!==false && strpos($key, ')')!==false) {
- $result[] = $key;
- continue;
- }
-
- if(stripos($key, 'AS')!==false) {
- $result[] = $key;
- continue;
- }
-
- if(stripos($value, 'AS')!==false) {
- $result[] = $value;
- continue;
- }
-
- $v = isset($columns[$value]);
- $k = isset($columns[$key]);
- if(is_integer($key) && $v) {
- $key = $value;
- $k = $v;
- }
-
- if(strToUpper($value)==='NULL') {
- if($k)
- $result[] = 'NULL AS ' . $columns[$key]->getColumnName();
- else
- $result[] = 'NULL' . (is_string($key) ? (' AS ' . (string)$key) : '');
- continue;
- }
-
- if(strpos($value, '(')!==false && strpos($value, ')')!==false) {
- if($k)
- $result[] = $value . ' AS ' . $columns[$key]->getColumnName();
- else
- $result[] = $value . (is_string($key) ? (' AS ' . (string)$key) : '');
- continue;
- }
-
- if($v && $key==$value) {
- $result[] = $columns[$value]->getColumnName();
- continue;
- }
-
- if($k && $value==null) {
- $result[] = $columns[$key]->getColumnName();
- continue;
- }
-
- if(is_string($key) && $v) {
- $result[] = $columns[$value]->getColumnName() . ' AS ' . $key;
- continue;
- }
-
- if(is_numeric($value) && $k) {
- $result[] = $value . ' AS ' . $columns[$key]->getColumnName();
- continue;
- }
-
- if(is_string($value) && $k) {
- $result[] = $this->getDbConnection()->quoteString($value) . ' AS ' . $columns[$key]->getColumnName();
- continue;
- }
-
- if(!$v && !$k && is_integer($key)) {
- $result[] = is_numeric($value) ? $value : $this->getDbConnection()->quoteString((string)$value);
- continue;
- }
-
- $result[] = (is_numeric($value) ? $value : $this->getDbConnection()->quoteString((string)$value)) . ' AS ' . $key;
- }
- }
-
- if($data===null || count($result) == 0 || $bHasWildcard)
- $result = $result = array_merge($this->getTableInfo()->getColumnNames(), $result);
-
- return $result;
- }
-
- /**
- * Appends the $where condition to the string "SELECT * FROM tableName WHERE ".
- * The tableName is obtained from the {@link setTableInfo TableInfo} property.
- * @param string query condition
- * @param array condition parameters.
- * @return TDbCommand query command.
- */
- public function createFindCommand($where='1=1', $parameters=array(), $ordering=array(), $limit=-1, $offset=-1, $select='*')
- {
- $table = $this->getTableInfo()->getTableFullName();
- $fields = implode(', ', $this -> getSelectFieldList($select));
- $sql = "SELECT {$fields} FROM {$table}";
- if(!empty($where))
- $sql .= " WHERE {$where}";
- return $this->applyCriterias($sql, $parameters, $ordering, $limit, $offset);
- }
-
- public function applyCriterias($sql, $parameters=array(),$ordering=array(), $limit=-1, $offset=-1)
- {
- if(count($ordering) > 0)
- $sql = $this->applyOrdering($sql, $ordering);
- if($limit>=0 || $offset>=0)
- $sql = $this->applyLimitOffset($sql, $limit, $offset);
- $command = $this->createCommand($sql);
- $this->bindArrayValues($command, $parameters);
- return $command;
- }
-
- /**
- * Creates a count(*) command for the table described in {@link setTableInfo TableInfo}.
- * @param string count condition.
- * @param array binding parameters.
- * @return TDbCommand count command.
- */
- public function createCountCommand($where='1=1', $parameters=array(),$ordering=array(), $limit=-1, $offset=-1)
- {
- return $this->createFindCommand($where, $parameters, $ordering, $limit, $offset, 'COUNT(*)');
- }
-
- /**
- * Creates a delete command for the table described in {@link setTableInfo TableInfo}.
- * The conditions for delete is given by the $where argument and the parameters
- * for the condition is given by $parameters.
- * @param string delete condition.
- * @param array delete parameters.
- * @return TDbCommand delete command.
- */
- public function createDeleteCommand($where,$parameters=array())
- {
- $table = $this->getTableInfo()->getTableFullName();
- if (!empty($where))
- $where = ' WHERE '.$where;
- $command = $this->createCommand("DELETE FROM {$table}".$where);
- $this->bindArrayValues($command, $parameters);
- return $command;
- }
-
- /**
- * Creates an insert command for the table described in {@link setTableInfo TableInfo} for the given data.
- * Each array key in the $data array must correspond to the column name of the table
- * (if a column allows to be null, it may be omitted) to be inserted with
- * the corresponding array value.
- * @param array name-value pairs of new data to be inserted.
- * @return TDbCommand insert command
- */
- public function createInsertCommand($data)
- {
- $table = $this->getTableInfo()->getTableFullName();
- list($fields, $bindings) = $this->getInsertFieldBindings($data);
- $command = $this->createCommand("INSERT INTO {$table}({$fields}) VALUES ($bindings)");
- $this->bindColumnValues($command, $data);
- return $command;
- }
-
- /**
- * Creates an update command for the table described in {@link setTableInfo TableInfo} for the given data.
- * Each array key in the $data array must correspond to the column name to be updated with the corresponding array value.
- * @param array name-value pairs of data to be updated.
- * @param string update condition.
- * @param array update parameters.
- * @return TDbCommand update command.
- */
- public function createUpdateCommand($data, $where, $parameters=array())
- {
- $table = $this->getTableInfo()->getTableFullName();
- if($this->hasIntegerKey($parameters))
- $fields = implode(', ', $this->getColumnBindings($data, true));
- else
- $fields = implode(', ', $this->getColumnBindings($data));
-
- if (!empty($where))
- $where = ' WHERE '.$where;
- $command = $this->createCommand("UPDATE {$table} SET {$fields}".$where);
- $this->bindArrayValues($command, array_merge($data, $parameters));
- return $command;
- }
-
- /**
- * Returns a list of insert field name and a list of binding names.
- * @param object array or object to be inserted.
- * @return array tuple ($fields, $bindings)
- */
- protected function getInsertFieldBindings($values)
- {
- $fields = array(); $bindings=array();
- foreach(array_keys($values) as $name)
- {
- $fields[] = $this->getTableInfo()->getColumn($name)->getColumnName();
- $bindings[] = ':'.$name;
- }
- return array(implode(', ',$fields), implode(', ', $bindings));
- }
-
- /**
- * Create a name-value or position-value if $position=true binding strings.
- * @param array data for binding.
- * @param boolean true to bind as position values.
- * @return string update column names with corresponding binding substrings.
- */
- protected function getColumnBindings($values, $position=false)
- {
- $bindings=array();
- foreach(array_keys($values) as $name)
- {
- $column = $this->getTableInfo()->getColumn($name)->getColumnName();
- $bindings[] = $position ? $column.' = ?' : $column.' = :'.$name;
- }
- return $bindings;
- }
-
- /**
- * @param string SQL query string.
- * @return TDbCommand corresponding database command.
- */
- public function createCommand($sql)
- {
- $this->getDbConnection()->setActive(true);
- return $this->getDbConnection()->createCommand($sql);
- }
-
- /**
- * Bind the name-value pairs of $values where the array keys correspond to column names.
- * @param TDbCommand database command.
- * @param array name-value pairs.
- */
- public function bindColumnValues($command, $values)
- {
- foreach($values as $name=>$value)
- {
- $column = $this->getTableInfo()->getColumn($name);
- if($value === null && $column->getAllowNull())
- $command->bindValue(':'.$name, null, PDO::PARAM_NULL);
- else
- $command->bindValue(':'.$name, $value, $column->getPdoType());
- }
- }
-
- /**
- * @param TDbCommand database command
- * @param array values for binding.
- */
- public function bindArrayValues($command, $values)
- {
- if($this->hasIntegerKey($values))
- {
- $values = array_values($values);
- for($i = 0, $max=count($values); $i<$max; $i++)
- $command->bindValue($i+1, $values[$i], $this->getPdoType($values[$i]));
- }
- else
- {
- foreach($values as $name=>$value)
- {
- $prop = $name[0]===':' ? $name : ':'.$name;
- $command->bindValue($prop, $value, $this->getPdoType($value));
- }
- }
- }
-
- /**
- * @param mixed PHP value
- * @return integer PDO parameter types.
- */
- public static function getPdoType($value)
- {
- switch(gettype($value))
- {
- case 'boolean': return PDO::PARAM_BOOL;
- case 'integer': return PDO::PARAM_INT;
- case 'string' : return PDO::PARAM_STR;
- case 'NULL' : return PDO::PARAM_NULL;
- }
- }
-
- /**
- * @param array
- * @return boolean true if any array key is an integer.
- */
- protected function hasIntegerKey($array)
- {
- foreach($array as $k=>$v)
- {
- if(gettype($k)==='integer')
- return true;
- }
- return false;
- }
-}
+<?php
+/**
+ * TDbCommandBuilder class file.
+ *
+ * @author Wei Zhuo <weizhuo[at]gmail[dot]com>
+ * @link http://www.pradosoft.com/
+ * @copyright Copyright &copy; 2005-2012 PradoSoft
+ * @license http://www.pradosoft.com/license/
+ * @version $Id$
+ * @package System.Data.Common
+ */
+
+/**
+ * TDbCommandBuilder provides basic methods to create query commands for tables
+ * giving by {@link setTableInfo TableInfo} the property.
+ *
+ * @author Wei Zhuo <weizho[at]gmail[dot]com>
+ * @version $Id$
+ * @package System.Data.Common
+ * @since 3.1
+ */
+class TDbCommandBuilder extends TComponent
+{
+ private $_connection;
+ private $_tableInfo;
+
+ /**
+ * @param TDbConnection database connection.
+ * @param TDbTableInfo table information.
+ */
+ public function __construct($connection=null, $tableInfo=null)
+ {
+ $this->setDbConnection($connection);
+ $this->setTableInfo($tableInfo);
+ }
+
+ /**
+ * @return TDbConnection database connection.
+ */
+ public function getDbConnection()
+ {
+ return $this->_connection;
+ }
+
+ /**
+ * @param TDbConnection database connection.
+ */
+ public function setDbConnection($value)
+ {
+ $this->_connection=$value;
+ }
+
+ /**
+ * @param TDbTableInfo table information.
+ */
+ public function setTableInfo($value)
+ {
+ $this->_tableInfo=$value;
+ }
+
+ /**
+ * @param TDbTableInfo table information.
+ */
+ public function getTableInfo()
+ {
+ return $this->_tableInfo;
+ }
+
+ /**
+ * Iterate through all the columns and returns the last insert id of the
+ * first column that has a sequence or serial.
+ * @return mixed last insert id, null if none is found.
+ */
+ public function getLastInsertID()
+ {
+ foreach($this->getTableInfo()->getColumns() as $column)
+ {
+ if($column->hasSequence())
+ return $this->getDbConnection()->getLastInsertID($column->getSequenceName());
+ }
+ }
+
+ /**
+ * Alters the sql to apply $limit and $offset. Default implementation is applicable
+ * for PostgreSQL, MySQL and SQLite.
+ * @param string SQL query string.
+ * @param integer maximum number of rows, -1 to ignore limit.
+ * @param integer row offset, -1 to ignore offset.
+ * @return string SQL with limit and offset.
+ */
+ public function applyLimitOffset($sql, $limit=-1, $offset=-1)
+ {
+ $limit = $limit!==null ? (int)$limit : -1;
+ $offset = $offset!==null ? (int)$offset : -1;
+ $limitStr = $limit >= 0 ? ' LIMIT '.$limit : '';
+ $offsetStr = $offset >= 0 ? ' OFFSET '.$offset : '';
+ return $sql.$limitStr.$offsetStr;
+ }
+
+ /**
+ * @param string SQL string without existing ordering.
+ * @param array pairs of column names as key and direction as value.
+ * @return string modified SQL applied with ORDER BY.
+ */
+ public function applyOrdering($sql, $ordering)
+ {
+ $orders=array();
+ foreach($ordering as $name => $direction)
+ {
+ $direction = strtolower($direction) == 'desc' ? 'DESC' : 'ASC';
+ if(false !== strpos($name, '(') && false !== strpos($name, ')')) {
+ // key is a function (bad practice, but we need to handle it)
+ $key = $name;
+ } else {
+ // key is a column
+ $key = $this->getTableInfo()->getColumn($name)->getColumnName();
+ }
+ $orders[] = $key.' '.$direction;
+ }
+ if(count($orders) > 0)
+ $sql .= ' ORDER BY '.implode(', ', $orders);
+ return $sql;
+ }
+
+ /**
+ * Computes the SQL condition for search a set of column using regular expression
+ * (or LIKE, depending on database implementation) to match a string of
+ * keywords (default matches all keywords).
+ * @param array list of column id for potential search condition.
+ * @param string string of keywords
+ * @return string SQL search condition matching on a set of columns.
+ */
+ public function getSearchExpression($fields, $keywords)
+ {
+ if(strlen(trim($keywords)) == 0) return '';
+ $words = preg_split('/\s/u', $keywords);
+ $conditions = array();
+ foreach($fields as $field)
+ {
+ $column = $this->getTableInfo()->getColumn($field)->getColumnName();
+ $conditions[] = $this->getSearchCondition($column, $words);
+ }
+ return '('.implode(' OR ', $conditions).')';
+ }
+
+ /**
+ * @param string column name.
+ * @param array keywords
+ * @return string search condition for all words in one column.
+ */
+ protected function getSearchCondition($column, $words)
+ {
+ $conditions=array();
+ foreach($words as $word)
+ $conditions[] = $column.' LIKE '.$this->getDbConnection()->quoteString('%'.$word.'%');
+ return '('.implode(' AND ', $conditions).')';
+ }
+
+ /**
+ *
+ * Different behavior depends on type of passed data
+ * string
+ * usage without modification
+ *
+ * null
+ * will be expanded to full list of quoted table column names (quoting depends on database)
+ *
+ * array
+ * - Column names will be quoted if used as key or value of array
+ * <code>
+ * array('col1', 'col2', 'col2')
+ * // SELECT `col1`, `col2`, `col3` FROM...
+ * </code>
+ *
+ * - Column aliasing
+ * <code>
+ * array('mycol1' => 'col1', 'mycol2' => 'COUNT(*)')
+ * // SELECT `col1` AS mycol1, COUNT(*) AS mycol2 FROM...
+ * </code>
+ *
+ * - NULL and scalar values (strings will be quoted depending on database)
+ * <code>
+ * array('col1' => 'my custom string', 'col2' => 1.0, 'col3' => 'NULL')
+ * // SELECT "my custom string" AS `col1`, 1.0 AS `col2`, NULL AS `col3` FROM...
+ * </code>
+ *
+ * - If the *-wildcard char is used as key or value, add the full list of quoted table column names
+ * <code>
+ * array('col1' => 'NULL', '*')
+ * // SELECT `col1`, `col2`, `col3`, NULL AS `col1` FROM...
+ * </code>
+ * @param mixed $value
+ * @return array of generated fields - use implode(', ', $selectfieldlist) to collapse field list for usage
+ * @since 3.1.7
+ * @todo add support for table aliasing
+ * @todo add support for quoting of column aliasing
+ */
+ public function getSelectFieldList($data='*') {
+ if(is_scalar($data)) {
+ $tmp = explode(',', $data);
+ $result = array();
+ foreach($tmp as $v)
+ $result[] = trim($v);
+ return $result;
+ }
+
+ $bHasWildcard = false;
+ $result = array();
+ if(is_array($data) || $data instanceof Traversable) {
+ $columns = $this->getTableInfo()->getColumns();
+ foreach($data as $key=>$value) {
+ if($key==='*' || $value==='*') {
+ $bHasWildcard = true;
+ continue;
+ }
+
+ if(strToUpper($key)==='NULL') {
+ $result[] = 'NULL';
+ continue;
+ }
+
+ if(strpos($key, '(')!==false && strpos($key, ')')!==false) {
+ $result[] = $key;
+ continue;
+ }
+
+ if(stripos($key, 'AS')!==false) {
+ $result[] = $key;
+ continue;
+ }
+
+ if(stripos($value, 'AS')!==false) {
+ $result[] = $value;
+ continue;
+ }
+
+ $v = isset($columns[$value]);
+ $k = isset($columns[$key]);
+ if(is_integer($key) && $v) {
+ $key = $value;
+ $k = $v;
+ }
+
+ if(strToUpper($value)==='NULL') {
+ if($k)
+ $result[] = 'NULL AS ' . $columns[$key]->getColumnName();
+ else
+ $result[] = 'NULL' . (is_string($key) ? (' AS ' . (string)$key) : '');
+ continue;
+ }
+
+ if(strpos($value, '(')!==false && strpos($value, ')')!==false) {
+ if($k)
+ $result[] = $value . ' AS ' . $columns[$key]->getColumnName();
+ else
+ $result[] = $value . (is_string($key) ? (' AS ' . (string)$key) : '');
+ continue;
+ }
+
+ if($v && $key==$value) {
+ $result[] = $columns[$value]->getColumnName();
+ continue;
+ }
+
+ if($k && $value==null) {
+ $result[] = $columns[$key]->getColumnName();
+ continue;
+ }
+
+ if(is_string($key) && $v) {
+ $result[] = $columns[$value]->getColumnName() . ' AS ' . $key;
+ continue;
+ }
+
+ if(is_numeric($value) && $k) {
+ $result[] = $value . ' AS ' . $columns[$key]->getColumnName();
+ continue;
+ }
+
+ if(is_string($value) && $k) {
+ $result[] = $this->getDbConnection()->quoteString($value) . ' AS ' . $columns[$key]->getColumnName();
+ continue;
+ }
+
+ if(!$v && !$k && is_integer($key)) {
+ $result[] = is_numeric($value) ? $value : $this->getDbConnection()->quoteString((string)$value);
+ continue;
+ }
+
+ $result[] = (is_numeric($value) ? $value : $this->getDbConnection()->quoteString((string)$value)) . ' AS ' . $key;
+ }
+ }
+
+ if($data===null || count($result) == 0 || $bHasWildcard)
+ $result = $result = array_merge($this->getTableInfo()->getColumnNames(), $result);
+
+ return $result;
+ }
+
+ /**
+ * Appends the $where condition to the string "SELECT * FROM tableName WHERE ".
+ * The tableName is obtained from the {@link setTableInfo TableInfo} property.
+ * @param string query condition
+ * @param array condition parameters.
+ * @return TDbCommand query command.
+ */
+ public function createFindCommand($where='1=1', $parameters=array(), $ordering=array(), $limit=-1, $offset=-1, $select='*')
+ {
+ $table = $this->getTableInfo()->getTableFullName();
+ $fields = implode(', ', $this -> getSelectFieldList($select));
+ $sql = "SELECT {$fields} FROM {$table}";
+ if(!empty($where))
+ $sql .= " WHERE {$where}";
+ return $this->applyCriterias($sql, $parameters, $ordering, $limit, $offset);
+ }
+
+ public function applyCriterias($sql, $parameters=array(),$ordering=array(), $limit=-1, $offset=-1)
+ {
+ if(count($ordering) > 0)
+ $sql = $this->applyOrdering($sql, $ordering);
+ if($limit>=0 || $offset>=0)
+ $sql = $this->applyLimitOffset($sql, $limit, $offset);
+ $command = $this->createCommand($sql);
+ $this->bindArrayValues($command, $parameters);
+ return $command;
+ }
+
+ /**
+ * Creates a count(*) command for the table described in {@link setTableInfo TableInfo}.
+ * @param string count condition.
+ * @param array binding parameters.
+ * @return TDbCommand count command.
+ */
+ public function createCountCommand($where='1=1', $parameters=array(),$ordering=array(), $limit=-1, $offset=-1)
+ {
+ return $this->createFindCommand($where, $parameters, $ordering, $limit, $offset, 'COUNT(*)');
+ }
+
+ /**
+ * Creates a delete command for the table described in {@link setTableInfo TableInfo}.
+ * The conditions for delete is given by the $where argument and the parameters
+ * for the condition is given by $parameters.
+ * @param string delete condition.
+ * @param array delete parameters.
+ * @return TDbCommand delete command.
+ */
+ public function createDeleteCommand($where,$parameters=array())
+ {
+ $table = $this->getTableInfo()->getTableFullName();
+ if (!empty($where))
+ $where = ' WHERE '.$where;
+ $command = $this->createCommand("DELETE FROM {$table}".$where);
+ $this->bindArrayValues($command, $parameters);
+ return $command;
+ }
+
+ /**
+ * Creates an insert command for the table described in {@link setTableInfo TableInfo} for the given data.
+ * Each array key in the $data array must correspond to the column name of the table
+ * (if a column allows to be null, it may be omitted) to be inserted with
+ * the corresponding array value.
+ * @param array name-value pairs of new data to be inserted.
+ * @return TDbCommand insert command
+ */
+ public function createInsertCommand($data)
+ {
+ $table = $this->getTableInfo()->getTableFullName();
+ list($fields, $bindings) = $this->getInsertFieldBindings($data);
+ $command = $this->createCommand("INSERT INTO {$table}({$fields}) VALUES ($bindings)");
+ $this->bindColumnValues($command, $data);
+ return $command;
+ }
+
+ /**
+ * Creates an update command for the table described in {@link setTableInfo TableInfo} for the given data.
+ * Each array key in the $data array must correspond to the column name to be updated with the corresponding array value.
+ * @param array name-value pairs of data to be updated.
+ * @param string update condition.
+ * @param array update parameters.
+ * @return TDbCommand update command.
+ */
+ public function createUpdateCommand($data, $where, $parameters=array())
+ {
+ $table = $this->getTableInfo()->getTableFullName();
+ if($this->hasIntegerKey($parameters))
+ $fields = implode(', ', $this->getColumnBindings($data, true));
+ else
+ $fields = implode(', ', $this->getColumnBindings($data));
+
+ if (!empty($where))
+ $where = ' WHERE '.$where;
+ $command = $this->createCommand("UPDATE {$table} SET {$fields}".$where);
+ $this->bindArrayValues($command, array_merge($data, $parameters));
+ return $command;
+ }
+
+ /**
+ * Returns a list of insert field name and a list of binding names.
+ * @param object array or object to be inserted.
+ * @return array tuple ($fields, $bindings)
+ */
+ protected function getInsertFieldBindings($values)
+ {
+ $fields = array(); $bindings=array();
+ foreach(array_keys($values) as $name)
+ {
+ $fields[] = $this->getTableInfo()->getColumn($name)->getColumnName();
+ $bindings[] = ':'.$name;
+ }
+ return array(implode(', ',$fields), implode(', ', $bindings));
+ }
+
+ /**
+ * Create a name-value or position-value if $position=true binding strings.
+ * @param array data for binding.
+ * @param boolean true to bind as position values.
+ * @return string update column names with corresponding binding substrings.
+ */
+ protected function getColumnBindings($values, $position=false)
+ {
+ $bindings=array();
+ foreach(array_keys($values) as $name)
+ {
+ $column = $this->getTableInfo()->getColumn($name)->getColumnName();
+ $bindings[] = $position ? $column.' = ?' : $column.' = :'.$name;
+ }
+ return $bindings;
+ }
+
+ /**
+ * @param string SQL query string.
+ * @return TDbCommand corresponding database command.
+ */
+ public function createCommand($sql)
+ {
+ $this->getDbConnection()->setActive(true);
+ return $this->getDbConnection()->createCommand($sql);
+ }
+
+ /**
+ * Bind the name-value pairs of $values where the array keys correspond to column names.
+ * @param TDbCommand database command.
+ * @param array name-value pairs.
+ */
+ public function bindColumnValues($command, $values)
+ {
+ foreach($values as $name=>$value)
+ {
+ $column = $this->getTableInfo()->getColumn($name);
+ if($value === null && $column->getAllowNull())
+ $command->bindValue(':'.$name, null, PDO::PARAM_NULL);
+ else
+ $command->bindValue(':'.$name, $value, $column->getPdoType());
+ }
+ }
+
+ /**
+ * @param TDbCommand database command
+ * @param array values for binding.
+ */
+ public function bindArrayValues($command, $values)
+ {
+ if($this->hasIntegerKey($values))
+ {
+ $values = array_values($values);
+ for($i = 0, $max=count($values); $i<$max; $i++)
+ $command->bindValue($i+1, $values[$i], $this->getPdoType($values[$i]));
+ }
+ else
+ {
+ foreach($values as $name=>$value)
+ {
+ $prop = $name[0]===':' ? $name : ':'.$name;
+ $command->bindValue($prop, $value, $this->getPdoType($value));
+ }
+ }
+ }
+
+ /**
+ * @param mixed PHP value
+ * @return integer PDO parameter types.
+ */
+ public static function getPdoType($value)
+ {
+ switch(gettype($value))
+ {
+ case 'boolean': return PDO::PARAM_BOOL;
+ case 'integer': return PDO::PARAM_INT;
+ case 'string' : return PDO::PARAM_STR;
+ case 'NULL' : return PDO::PARAM_NULL;
+ }
+ }
+
+ /**
+ * @param array
+ * @return boolean true if any array key is an integer.
+ */
+ protected function hasIntegerKey($array)
+ {
+ foreach($array as $k=>$v)
+ {
+ if(gettype($k)==='integer')
+ return true;
+ }
+ return false;
+ }
+}
diff --git a/framework/Data/Common/TDbMetaData.php b/framework/Data/Common/TDbMetaData.php
index fdf367c9..5fc4fec9 100644
--- a/framework/Data/Common/TDbMetaData.php
+++ b/framework/Data/Common/TDbMetaData.php
@@ -1,183 +1,183 @@
-<?php
-/**
- * TDbMetaData class file.
- *
- * @author Wei Zhuo <weizhuo[at]gmail[dot]com>
- * @link http://www.pradosoft.com/
+<?php
+/**
+ * TDbMetaData class file.
+ *
+ * @author Wei Zhuo <weizhuo[at]gmail[dot]com>
+ * @link http://www.pradosoft.com/
* @copyright Copyright &copy; 2005-2012 PradoSoft
- * @license http://www.pradosoft.com/license/
- * @version $Id$
- * @package System.Data.Common
- */
-
-/**
- * TDbMetaData is the base class for retrieving metadata information, such as
- * table and columns information, from a database connection.
- *
- * Use the {@link getTableInfo} method to retrieve a table information.
- *
- * @author Wei Zhuo <weizho[at]gmail[dot]com>
- * @version $Id$
- * @package System.Data.Common
- * @since 3.1
- */
-abstract class TDbMetaData extends TComponent
-{
- private $_tableInfoCache=array();
- private $_connection;
-
- /**
- * @var array
- */
- protected static $delimiterIdentifier = array('[', ']', '"', '`', "'");
-
- /**
- * @param TDbConnection database connection.
- */
- public function __construct($conn)
- {
- $this->_connection=$conn;
- }
-
- /**
- * @return TDbConnection database connection.
- */
- public function getDbConnection()
- {
- return $this->_connection;
- }
-
- /**
- * Obtain database specific TDbMetaData class using the driver name of the database connection.
- * @param TDbConnection database connection.
- * @return TDbMetaData database specific TDbMetaData.
- */
- public static function getInstance($conn)
- {
- $conn->setActive(true); //must be connected before retrieving driver name
- $driver = $conn->getDriverName();
- switch(strtolower($driver))
- {
- case 'pgsql':
- Prado::using('System.Data.Common.Pgsql.TPgsqlMetaData');
- return new TPgsqlMetaData($conn);
- case 'mysqli':
- case 'mysql':
- Prado::using('System.Data.Common.Mysql.TMysqlMetaData');
- return new TMysqlMetaData($conn);
- case 'sqlite': //sqlite 3
- case 'sqlite2': //sqlite 2
- Prado::using('System.Data.Common.Sqlite.TSqliteMetaData');
- return new TSqliteMetaData($conn);
- case 'mssql': // Mssql driver on windows hosts
- case 'dblib': // dblib drivers on linux (and maybe others os) hosts
- Prado::using('System.Data.Common.Mssql.TMssqlMetaData');
- return new TMssqlMetaData($conn);
- case 'oci':
- Prado::using('System.Data.Common.Oracle.TOracleMetaData');
- return new TOracleMetaData($conn);
-// case 'ibm':
-// Prado::using('System.Data.Common.IbmDb2.TIbmDb2MetaData');
-// return new TIbmDb2MetaData($conn);
- default:
- throw new TDbException('ar_invalid_database_driver',$driver);
- }
- }
-
- /**
- * Obtains table meta data information for the current connection and given table name.
- * @param string table or view name
- * @return TDbTableInfo table information.
- */
- public function getTableInfo($tableName=null)
- {
- $key = $tableName===null?$this->getDbConnection()->getConnectionString():$tableName;
- if(!isset($this->_tableInfoCache[$key]))
- {
- $class = $this->getTableInfoClass();
- $tableInfo = $tableName===null ? new $class : $this->createTableInfo($tableName);
- $this->_tableInfoCache[$key] = $tableInfo;
- }
- return $this->_tableInfoCache[$key];
- }
-
- /**
- * Creates a command builder for a given table name.
- * @param string table name.
- * @return TDbCommandBuilder command builder instance for the given table.
- */
- public function createCommandBuilder($tableName=null)
- {
- return $this->getTableInfo($tableName)->createCommandBuilder($this->getDbConnection());
- }
-
- /**
- * This method should be implemented by decendent classes.
- * @return TDbTableInfo driver dependent create builder.
- */
- abstract protected function createTableInfo($tableName);
-
- /**
- * @return string TDbTableInfo class name.
- */
- protected function getTableInfoClass()
- {
- return 'TDbTableInfo';
- }
-
- /**
- * Quotes a table name for use in a query.
- * @param string $name table name
- * @param string $lft left delimiter
- * @param string $rgt right delimiter
- * @return string the properly quoted table name
- */
- public function quoteTableName($name)
- {
- $name = str_replace(self::$delimiterIdentifier, '', $name);
-
- $args = func_get_args();
- $rgt = $lft = isset($args[1]) ? $args[1] : '';
- $rgt = isset($args[2]) ? $args[2] : $rgt;
-
- if(strpos($name, '.')===false)
- return $lft . $name . $rgt;
- $names=explode('.', $name);
- foreach($names as &$n)
- $n = $lft . $n . $rgt;
- return implode('.', $names);
- }
-
- /**
- * Quotes a column name for use in a query.
- * @param string $name column name
- * @param string $lft left delimiter
- * @param string $rgt right delimiter
- * @return string the properly quoted column name
- */
- public function quoteColumnName($name)
- {
- $args = func_get_args();
- $rgt = $lft = isset($args[1]) ? $args[1] : '';
- $rgt = isset($args[2]) ? $args[2] : $rgt;
-
- return $lft . str_replace(self::$delimiterIdentifier, '', $name) . $rgt;
- }
-
- /**
- * Quotes a column alias for use in a query.
- * @param string $name column alias
- * @param string $lft left delimiter
- * @param string $rgt right delimiter
- * @return string the properly quoted column alias
- */
- public function quoteColumnAlias($name)
- {
- $args = func_get_args();
- $rgt = $lft = isset($args[1]) ? $args[1] : '';
- $rgt = isset($args[2]) ? $args[2] : $rgt;
-
- return $lft . str_replace(self::$delimiterIdentifier, '', $name) . $rgt;
- }
-}
-
+ * @license http://www.pradosoft.com/license/
+ * @version $Id$
+ * @package System.Data.Common
+ */
+
+/**
+ * TDbMetaData is the base class for retrieving metadata information, such as
+ * table and columns information, from a database connection.
+ *
+ * Use the {@link getTableInfo} method to retrieve a table information.
+ *
+ * @author Wei Zhuo <weizho[at]gmail[dot]com>
+ * @version $Id$
+ * @package System.Data.Common
+ * @since 3.1
+ */
+abstract class TDbMetaData extends TComponent
+{
+ private $_tableInfoCache=array();
+ private $_connection;
+
+ /**
+ * @var array
+ */
+ protected static $delimiterIdentifier = array('[', ']', '"', '`', "'");
+
+ /**
+ * @param TDbConnection database connection.
+ */
+ public function __construct($conn)
+ {
+ $this->_connection=$conn;
+ }
+
+ /**
+ * @return TDbConnection database connection.
+ */
+ public function getDbConnection()
+ {
+ return $this->_connection;
+ }
+
+ /**
+ * Obtain database specific TDbMetaData class using the driver name of the database connection.
+ * @param TDbConnection database connection.
+ * @return TDbMetaData database specific TDbMetaData.
+ */
+ public static function getInstance($conn)
+ {
+ $conn->setActive(true); //must be connected before retrieving driver name
+ $driver = $conn->getDriverName();
+ switch(strtolower($driver))
+ {
+ case 'pgsql':
+ Prado::using('System.Data.Common.Pgsql.TPgsqlMetaData');
+ return new TPgsqlMetaData($conn);
+ case 'mysqli':
+ case 'mysql':
+ Prado::using('System.Data.Common.Mysql.TMysqlMetaData');
+ return new TMysqlMetaData($conn);
+ case 'sqlite': //sqlite 3
+ case 'sqlite2': //sqlite 2
+ Prado::using('System.Data.Common.Sqlite.TSqliteMetaData');
+ return new TSqliteMetaData($conn);
+ case 'mssql': // Mssql driver on windows hosts
+ case 'dblib': // dblib drivers on linux (and maybe others os) hosts
+ Prado::using('System.Data.Common.Mssql.TMssqlMetaData');
+ return new TMssqlMetaData($conn);
+ case 'oci':
+ Prado::using('System.Data.Common.Oracle.TOracleMetaData');
+ return new TOracleMetaData($conn);
+// case 'ibm':
+// Prado::using('System.Data.Common.IbmDb2.TIbmDb2MetaData');
+// return new TIbmDb2MetaData($conn);
+ default:
+ throw new TDbException('ar_invalid_database_driver',$driver);
+ }
+ }
+
+ /**
+ * Obtains table meta data information for the current connection and given table name.
+ * @param string table or view name
+ * @return TDbTableInfo table information.
+ */
+ public function getTableInfo($tableName=null)
+ {
+ $key = $tableName===null?$this->getDbConnection()->getConnectionString():$tableName;
+ if(!isset($this->_tableInfoCache[$key]))
+ {
+ $class = $this->getTableInfoClass();
+ $tableInfo = $tableName===null ? new $class : $this->createTableInfo($tableName);
+ $this->_tableInfoCache[$key] = $tableInfo;
+ }
+ return $this->_tableInfoCache[$key];
+ }
+
+ /**
+ * Creates a command builder for a given table name.
+ * @param string table name.
+ * @return TDbCommandBuilder command builder instance for the given table.
+ */
+ public function createCommandBuilder($tableName=null)
+ {
+ return $this->getTableInfo($tableName)->createCommandBuilder($this->getDbConnection());
+ }
+
+ /**
+ * This method should be implemented by decendent classes.
+ * @return TDbTableInfo driver dependent create builder.
+ */
+ abstract protected function createTableInfo($tableName);
+
+ /**
+ * @return string TDbTableInfo class name.
+ */
+ protected function getTableInfoClass()
+ {
+ return 'TDbTableInfo';
+ }
+
+ /**
+ * Quotes a table name for use in a query.
+ * @param string $name table name
+ * @param string $lft left delimiter
+ * @param string $rgt right delimiter
+ * @return string the properly quoted table name
+ */
+ public function quoteTableName($name)
+ {
+ $name = str_replace(self::$delimiterIdentifier, '', $name);
+
+ $args = func_get_args();
+ $rgt = $lft = isset($args[1]) ? $args[1] : '';
+ $rgt = isset($args[2]) ? $args[2] : $rgt;
+
+ if(strpos($name, '.')===false)
+ return $lft . $name . $rgt;
+ $names=explode('.', $name);
+ foreach($names as &$n)
+ $n = $lft . $n . $rgt;
+ return implode('.', $names);
+ }
+
+ /**
+ * Quotes a column name for use in a query.
+ * @param string $name column name
+ * @param string $lft left delimiter
+ * @param string $rgt right delimiter
+ * @return string the properly quoted column name
+ */
+ public function quoteColumnName($name)
+ {
+ $args = func_get_args();
+ $rgt = $lft = isset($args[1]) ? $args[1] : '';
+ $rgt = isset($args[2]) ? $args[2] : $rgt;
+
+ return $lft . str_replace(self::$delimiterIdentifier, '', $name) . $rgt;
+ }
+
+ /**
+ * Quotes a column alias for use in a query.
+ * @param string $name column alias
+ * @param string $lft left delimiter
+ * @param string $rgt right delimiter
+ * @return string the properly quoted column alias
+ */
+ public function quoteColumnAlias($name)
+ {
+ $args = func_get_args();
+ $rgt = $lft = isset($args[1]) ? $args[1] : '';
+ $rgt = isset($args[2]) ? $args[2] : $rgt;
+
+ return $lft . str_replace(self::$delimiterIdentifier, '', $name) . $rgt;
+ }
+}
+
diff --git a/framework/Data/Common/TDbTableColumn.php b/framework/Data/Common/TDbTableColumn.php
index 8a0832d8..3967ec0c 100644
--- a/framework/Data/Common/TDbTableColumn.php
+++ b/framework/Data/Common/TDbTableColumn.php
@@ -1,199 +1,199 @@
-<?php
-/**
- * TDbTableColumn class file.
- *
- * @author Wei Zhuo <weizhuo[at]gmail[dot]com>
- * @link http://www.pradosoft.com/
+<?php
+/**
+ * TDbTableColumn class file.
+ *
+ * @author Wei Zhuo <weizhuo[at]gmail[dot]com>
+ * @link http://www.pradosoft.com/
* @copyright Copyright &copy; 2005-2012 PradoSoft
- * @license http://www.pradosoft.com/license/
- * @version $Id$
- * @package System.Data.Common
- */
-
-/**
- * TDbTableColumn class describes the column meta data of the schema for a database table.
- *
- * @author Wei Zhuo <weizho[at]gmail[dot]com>
- * @version $Id$
- * @package System.Data.Common
- * @since 3.1
- */
-class TDbTableColumn extends TComponent
-{
- const UNDEFINED_VALUE= INF; //use infinity for undefined value
-
- private $_info=array();
-
- /**
- * Sets the table column meta data.
- * @param array table column information.
- */
- public function __construct($columnInfo)
- {
- $this->_info=$columnInfo;
- }
-
- /**
- * @param string information array key name
- * @param mixed default value if information array value is null
- * @return mixed information array value.
- */
- protected function getInfo($name,$default=null)
- {
- return isset($this->_info[$name]) ? $this->_info[$name] : $default;
- }
-
- /**
- * @param string information array key name
- * @param mixed new information array value.
- */
- protected function setInfo($name,$value)
- {
- $this->_info[$name]=$value;
- }
-
- /**
- * Returns the derived PHP primitive type from the db type. Default returns 'string'.
- * @return string derived PHP primitive type from the column db type.
- */
- public function getPHPType()
- {
- return 'string';
- }
-
- /**
- * @param integer PDO bind param/value types, default returns string.
- */
- public function getPdoType()
- {
- switch($this->getPHPType())
- {
- case 'boolean': return PDO::PARAM_BOOL;
- case 'integer': return PDO::PARAM_INT;
- case 'string' : return PDO::PARAM_STR;
- }
- return PDO::PARAM_STR;
- }
-
- /**
- * @return string name of the column in the table (identifier quoted).
- */
- public function getColumnName()
- {
- return $this->getInfo('ColumnName');
- }
-
- /**
- * @return string name of the column with quoted identifier.
- */
- public function getColumnId()
- {
- return $this->getInfo('ColumnId');
- }
-
- /**
- * @return string size of the column.
- */
- public function getColumnSize()
- {
- return $this->getInfo('ColumnSize');
- }
-
- /**
- * @return integer zero-based ordinal position of the column in the table.
- */
- public function getColumnIndex()
- {
- return $this->getInfo('ColumnIndex');
- }
-
- /**
- * @return string column type.
- */
- public function getDbType()
- {
- return $this->getInfo('DbType');
- }
-
- /**
- * @return boolean specifies whether value Null is allowed, default is false.
- */
- public function getAllowNull()
- {
- return $this->getInfo('AllowNull',false);
- }
-
- /**
- * @return mixed default column value if column value was null.
- */
- public function getDefaultValue()
- {
- return $this->getInfo('DefaultValue', self::UNDEFINED_VALUE);
- }
-
- /**
- * @return string precision of the column data, if the data is numeric.
- */
- public function getNumericPrecision()
- {
- return $this->getInfo('NumericPrecision');
- }
-
- /**
- * @return string scale of the column data, if the data is numeric.
- */
- public function getNumericScale()
- {
- return $this->getInfo('NumericScale');
- }
-
- public function getMaxiumNumericConstraint()
- {
- if(($precision=$this->getNumericPrecision())!==null)
- {
- $scale=$this->getNumericScale();
- return $scale===null ? pow(10,$precision) : pow(10,$precision-$scale);
- }
- }
-
- /**
- * @return boolean whether this column is a primary key for the table, default is false.
- */
- public function getIsPrimaryKey()
- {
- return $this->getInfo('IsPrimaryKey',false);
- }
-
- /**
- * @return boolean whether this column is a foreign key, default is false.
- */
- public function getIsForeignKey()
- {
- return $this->getInfo('IsForeignKey',false);
- }
-
- /**
- * @param string sequence name, only applicable if column is a sequence
- */
- public function getSequenceName()
- {
- return $this->getInfo('SequenceName');
- }
-
- /**
- * @return boolean whether the column is a sequence.
- */
- public function hasSequence()
- {
- return $this->getSequenceName()!==null;
- }
-
- /**
- * @return boolean whether this column is excluded from insert and update.
- */
- public function getIsExcluded()
- {
- return false;
- }
-}
-
+ * @license http://www.pradosoft.com/license/
+ * @version $Id$
+ * @package System.Data.Common
+ */
+
+/**
+ * TDbTableColumn class describes the column meta data of the schema for a database table.
+ *
+ * @author Wei Zhuo <weizho[at]gmail[dot]com>
+ * @version $Id$
+ * @package System.Data.Common
+ * @since 3.1
+ */
+class TDbTableColumn extends TComponent
+{
+ const UNDEFINED_VALUE= INF; //use infinity for undefined value
+
+ private $_info=array();
+
+ /**
+ * Sets the table column meta data.
+ * @param array table column information.
+ */
+ public function __construct($columnInfo)
+ {
+ $this->_info=$columnInfo;
+ }
+
+ /**
+ * @param string information array key name
+ * @param mixed default value if information array value is null
+ * @return mixed information array value.
+ */
+ protected function getInfo($name,$default=null)
+ {
+ return isset($this->_info[$name]) ? $this->_info[$name] : $default;
+ }
+
+ /**
+ * @param string information array key name
+ * @param mixed new information array value.
+ */
+ protected function setInfo($name,$value)
+ {
+ $this->_info[$name]=$value;
+ }
+
+ /**
+ * Returns the derived PHP primitive type from the db type. Default returns 'string'.
+ * @return string derived PHP primitive type from the column db type.
+ */
+ public function getPHPType()
+ {
+ return 'string';
+ }
+
+ /**
+ * @param integer PDO bind param/value types, default returns string.
+ */
+ public function getPdoType()
+ {
+ switch($this->getPHPType())
+ {
+ case 'boolean': return PDO::PARAM_BOOL;
+ case 'integer': return PDO::PARAM_INT;
+ case 'string' : return PDO::PARAM_STR;
+ }
+ return PDO::PARAM_STR;
+ }
+
+ /**
+ * @return string name of the column in the table (identifier quoted).
+ */
+ public function getColumnName()
+ {
+ return $this->getInfo('ColumnName');
+ }
+
+ /**
+ * @return string name of the column with quoted identifier.
+ */
+ public function getColumnId()
+ {
+ return $this->getInfo('ColumnId');
+ }
+
+ /**
+ * @return string size of the column.
+ */
+ public function getColumnSize()
+ {
+ return $this->getInfo('ColumnSize');
+ }
+
+ /**
+ * @return integer zero-based ordinal position of the column in the table.
+ */
+ public function getColumnIndex()
+ {
+ return $this->getInfo('ColumnIndex');
+ }
+
+ /**
+ * @return string column type.
+ */
+ public function getDbType()
+ {
+ return $this->getInfo('DbType');
+ }
+
+ /**
+ * @return boolean specifies whether value Null is allowed, default is false.
+ */
+ public function getAllowNull()
+ {
+ return $this->getInfo('AllowNull',false);
+ }
+
+ /**
+ * @return mixed default column value if column value was null.
+ */
+ public function getDefaultValue()
+ {
+ return $this->getInfo('DefaultValue', self::UNDEFINED_VALUE);
+ }
+
+ /**
+ * @return string precision of the column data, if the data is numeric.
+ */
+ public function getNumericPrecision()
+ {
+ return $this->getInfo('NumericPrecision');
+ }
+
+ /**
+ * @return string scale of the column data, if the data is numeric.
+ */
+ public function getNumericScale()
+ {
+ return $this->getInfo('NumericScale');
+ }
+
+ public function getMaxiumNumericConstraint()
+ {
+ if(($precision=$this->getNumericPrecision())!==null)
+ {
+ $scale=$this->getNumericScale();
+ return $scale===null ? pow(10,$precision) : pow(10,$precision-$scale);
+ }
+ }
+
+ /**
+ * @return boolean whether this column is a primary key for the table, default is false.
+ */
+ public function getIsPrimaryKey()
+ {
+ return $this->getInfo('IsPrimaryKey',false);
+ }
+
+ /**
+ * @return boolean whether this column is a foreign key, default is false.
+ */
+ public function getIsForeignKey()
+ {
+ return $this->getInfo('IsForeignKey',false);
+ }
+
+ /**
+ * @param string sequence name, only applicable if column is a sequence
+ */
+ public function getSequenceName()
+ {
+ return $this->getInfo('SequenceName');
+ }
+
+ /**
+ * @return boolean whether the column is a sequence.
+ */
+ public function hasSequence()
+ {
+ return $this->getSequenceName()!==null;
+ }
+
+ /**
+ * @return boolean whether this column is excluded from insert and update.
+ */
+ public function getIsExcluded()
+ {
+ return false;
+ }
+}
+
diff --git a/framework/Data/Common/TDbTableInfo.php b/framework/Data/Common/TDbTableInfo.php
index 5342212e..c5c79e5b 100644
--- a/framework/Data/Common/TDbTableInfo.php
+++ b/framework/Data/Common/TDbTableInfo.php
@@ -1,166 +1,166 @@
<?php
-/**
- * TDbTableInfo class file.
- *
- * @author Wei Zhuo <weizhuo[at]gmail[dot]com>
- * @link http://www.pradosoft.com/
+/**
+ * TDbTableInfo class file.
+ *
+ * @author Wei Zhuo <weizhuo[at]gmail[dot]com>
+ * @link http://www.pradosoft.com/
* @copyright Copyright &copy; 2005-2012 PradoSoft
- * @license http://www.pradosoft.com/license/
- * @version $Id$
- * @package System.Data.Common
- */
-
-/**
- * TDbTableInfo class describes the meta data of a database table.
- *
- * @author Wei Zhuo <weizho[at]gmail[dot]com>
- * @version $Id$
- * @package System.Data.Common
- * @since 3.1
- */
-class TDbTableInfo extends TComponent
-{
- private $_info=array();
-
- private $_primaryKeys;
- private $_foreignKeys;
-
- private $_columns;
-
+ * @license http://www.pradosoft.com/license/
+ * @version $Id$
+ * @package System.Data.Common
+ */
+
+/**
+ * TDbTableInfo class describes the meta data of a database table.
+ *
+ * @author Wei Zhuo <weizho[at]gmail[dot]com>
+ * @version $Id$
+ * @package System.Data.Common
+ * @since 3.1
+ */
+class TDbTableInfo extends TComponent
+{
+ private $_info=array();
+
+ private $_primaryKeys;
+ private $_foreignKeys;
+
+ private $_columns;
+
private $_lowercase;
/**
* @var null|array
* @since 3.1.7
- */
- private $_names = null;
-
- /**
- * Sets the database table meta data information.
- * @param array table column information.
- */
- public function __construct($tableInfo=array(),$primary=array(),$foreign=array())
- {
- $this->_info=$tableInfo;
- $this->_primaryKeys=$primary;
- $this->_foreignKeys=$foreign;
- $this->_columns=new TMap;
- }
-
- /**
- * @param TDbConnection database connection.
- * @return TDbCommandBuilder new command builder
- */
- public function createCommandBuilder($connection)
- {
- Prado::using('System.Data.Common.TDbCommandBuilder');
- return new TDbCommandBuilder($connection,$this);
- }
-
- /**
- * @param string information array key name
- * @param mixed default value if information array value is null
- * @return mixed information array value.
- */
- protected function getInfo($name,$default=null)
- {
- return isset($this->_info[$name]) ? $this->_info[$name] : $default;
- }
-
- /**
- * @param string information array key name
- * @param mixed new information array value.
- */
- protected function setInfo($name,$value)
- {
- $this->_info[$name]=$value;
- }
-
- /**
- * @return string name of the table this column belongs to.
- */
- public function getTableName()
- {
- return $this->getInfo('TableName');
- }
-
- /**
- * @return string full name of the table, database dependent.
- */
- public function getTableFullName()
- {
- return $this->getTableName();
- }
-
- /**
- * @return boolean whether the table is a view, default is false.
- */
- public function getIsView()
- {
- return $this->getInfo('IsView',false);
- }
-
- /**
- * @return TMap TDbTableColumn column meta data.
- */
- public function getColumns()
- {
- return $this->_columns;
- }
-
- /**
- * @param string column id
- * @return TDbTableColumn column information.
- */
- public function getColumn($name)
- {
- if(($column = $this->_columns->itemAt($name))!==null)
- return $column;
- throw new TDbException('dbtableinfo_invalid_column_name', $name, $this->getTableFullName());
- }
-
- /**
- * @param array list of column Id, empty to get all columns.
- * @return array table column names (identifier quoted)
- */
- public function getColumnNames()
+ */
+ private $_names = null;
+
+ /**
+ * Sets the database table meta data information.
+ * @param array table column information.
+ */
+ public function __construct($tableInfo=array(),$primary=array(),$foreign=array())
+ {
+ $this->_info=$tableInfo;
+ $this->_primaryKeys=$primary;
+ $this->_foreignKeys=$foreign;
+ $this->_columns=new TMap;
+ }
+
+ /**
+ * @param TDbConnection database connection.
+ * @return TDbCommandBuilder new command builder
+ */
+ public function createCommandBuilder($connection)
+ {
+ Prado::using('System.Data.Common.TDbCommandBuilder');
+ return new TDbCommandBuilder($connection,$this);
+ }
+
+ /**
+ * @param string information array key name
+ * @param mixed default value if information array value is null
+ * @return mixed information array value.
+ */
+ protected function getInfo($name,$default=null)
+ {
+ return isset($this->_info[$name]) ? $this->_info[$name] : $default;
+ }
+
+ /**
+ * @param string information array key name
+ * @param mixed new information array value.
+ */
+ protected function setInfo($name,$value)
+ {
+ $this->_info[$name]=$value;
+ }
+
+ /**
+ * @return string name of the table this column belongs to.
+ */
+ public function getTableName()
+ {
+ return $this->getInfo('TableName');
+ }
+
+ /**
+ * @return string full name of the table, database dependent.
+ */
+ public function getTableFullName()
+ {
+ return $this->getTableName();
+ }
+
+ /**
+ * @return boolean whether the table is a view, default is false.
+ */
+ public function getIsView()
+ {
+ return $this->getInfo('IsView',false);
+ }
+
+ /**
+ * @return TMap TDbTableColumn column meta data.
+ */
+ public function getColumns()
+ {
+ return $this->_columns;
+ }
+
+ /**
+ * @param string column id
+ * @return TDbTableColumn column information.
+ */
+ public function getColumn($name)
+ {
+ if(($column = $this->_columns->itemAt($name))!==null)
+ return $column;
+ throw new TDbException('dbtableinfo_invalid_column_name', $name, $this->getTableFullName());
+ }
+
+ /**
+ * @param array list of column Id, empty to get all columns.
+ * @return array table column names (identifier quoted)
+ */
+ public function getColumnNames()
{
if($this->_names===null)
- {
- $this->_names=array();
- foreach($this->getColumns() as $column)
+ {
+ $this->_names=array();
+ foreach($this->getColumns() as $column)
$this->_names[] = $column->getColumnName();
- }
- return $this->_names;
- }
-
- /**
- * @return string[] names of primary key columns.
- */
- public function getPrimaryKeys()
- {
- return $this->_primaryKeys;
- }
-
- /**
- * @return array tuples of foreign table and column name.
- */
- public function getForeignKeys()
- {
- return $this->_foreignKeys;
- }
-
- /**
- * @return array lowercased column key names mapped to normal column ids.
- */
- public function getLowerCaseColumnNames()
- {
- if($this->_lowercase===null)
- {
- $this->_lowercase=array();
- foreach($this->getColumns()->getKeys() as $key)
- $this->_lowercase[strtolower($key)] = $key;
- }
- return $this->_lowercase;
- }
+ }
+ return $this->_names;
+ }
+
+ /**
+ * @return string[] names of primary key columns.
+ */
+ public function getPrimaryKeys()
+ {
+ return $this->_primaryKeys;
+ }
+
+ /**
+ * @return array tuples of foreign table and column name.
+ */
+ public function getForeignKeys()
+ {
+ return $this->_foreignKeys;
+ }
+
+ /**
+ * @return array lowercased column key names mapped to normal column ids.
+ */
+ public function getLowerCaseColumnNames()
+ {
+ if($this->_lowercase===null)
+ {
+ $this->_lowercase=array();
+ foreach($this->getColumns()->getKeys() as $key)
+ $this->_lowercase[strtolower($key)] = $key;
+ }
+ return $this->_lowercase;
+ }
} \ No newline at end of file
diff --git a/framework/Data/DataGateway/TDataGatewayCommand.php b/framework/Data/DataGateway/TDataGatewayCommand.php
index fa699979..299d39cd 100644
--- a/framework/Data/DataGateway/TDataGatewayCommand.php
+++ b/framework/Data/DataGateway/TDataGatewayCommand.php
@@ -1,541 +1,541 @@
-<?php
-/**
- * TDataGatewayCommand, TDataGatewayEventParameter and TDataGatewayResultEventParameter class file.
- *
- * @author Wei Zhuo <weizhuo[at]gmail[dot]com>
- * @link http://www.pradosoft.com/
- * @copyright Copyright &copy; 2005-2012 PradoSoft
- * @license http://www.pradosoft.com/license/
- * @version $Id$
- * @package System.Data.DataGateway
- */
-
-/**
- * TDataGatewayCommand is command builder and executor class for
- * TTableGateway and TActiveRecordGateway.
- *
- * TDataGatewayCommand builds the TDbCommand for TTableGateway
- * and TActiveRecordGateway commands such as find(), update(), insert(), etc,
- * using the TDbCommandBuilder classes (database specific TDbCommandBuilder
- * classes are used).
- *
- * Once the command is built and the query parameters are binded, the
- * {@link OnCreateCommand} event is raised. Event handlers for the OnCreateCommand
- * event should not alter the Command property nor the Criteria property of the
- * TDataGatewayEventParameter.
- *
- * TDataGatewayCommand excutes the TDbCommands and returns the result obtained from the
- * database (returned value depends on the method executed). The
- * {@link OnExecuteCommand} event is raised after the command is executed and resulting
- * data is set in the TDataGatewayResultEventParameter object's Result property.
- *
- * @author Wei Zhuo <weizho[at]gmail[dot]com>
- * @version $Id$
- * @package System.Data.DataGateway
- * @since 3.1
- */
-class TDataGatewayCommand extends TComponent
-{
- private $_builder;
-
- /**
- * @param TDbCommandBuilder database specific database command builder.
- */
- public function __construct($builder)
- {
- $this->_builder = $builder;
- }
-
- /**
- * @return TDbTableInfo
- */
- public function getTableInfo()
- {
- return $this->_builder->getTableInfo();
- }
-
- /**
- * @return TDbConnection
- */
- public function getDbConnection()
- {
- return $this->_builder->getDbConnection();
- }
-
- /**
- * @return TDbCommandBuilder
- */
- public function getBuilder()
- {
- return $this->_builder;
- }
-
- /**
- * Executes a delete command.
- * @param TSqlCriteria delete conditions and parameters.
- * @return integer number of records affected.
- */
- public function delete($criteria)
- {
- $where = $criteria->getCondition();
- $parameters = $criteria->getParameters()->toArray();
- $command = $this->getBuilder()->createDeleteCommand($where, $parameters);
- $this->onCreateCommand($command,$criteria);
- $command->prepare();
- return $command->execute();
- }
-
- /**
- * Updates the table with new data.
- * @param array date for update.
- * @param TSqlCriteria update conditions and parameters.
- * @return integer number of records affected.
- */
- public function update($data, $criteria)
- {
- $where = $criteria->getCondition();
- $parameters = $criteria->getParameters()->toArray();
- $command = $this->getBuilder()->createUpdateCommand($data,$where, $parameters);
- $this->onCreateCommand($command,$criteria);
- $command->prepare();
- return $this->onExecuteCommand($command, $command->execute());
- }
-
- /**
- * @param array update for update
- * @param array primary key-value name pairs.
- * @return integer number of records affected.
- */
- public function updateByPk($data, $keys)
- {
- list($where, $parameters) = $this->getPrimaryKeyCondition((array)$keys);
- return $this->update($data, new TSqlCriteria($where, $parameters));
- }
-
- /**
- * Find one record matching the critera.
- * @param TSqlCriteria find conditions and parameters.
- * @return array matching record.
- */
- public function find($criteria)
- {
- $command = $this->getFindCommand($criteria);
- return $this->onExecuteCommand($command, $command->queryRow());
- }
-
- /**
- * Find one or more matching records.
- * @param TSqlCriteria $criteria
- * @return TDbDataReader record reader.
- */
- public function findAll($criteria)
- {
- $command = $this->getFindCommand($criteria);
- return $this->onExecuteCommand($command, $command->query());
- }
-
- /**
- * Build the find command from the criteria. Limit, Offset and Ordering are applied if applicable.
- * @param TSqlCriteria $criteria
- * @return TDbCommand.
- */
- protected function getFindCommand($criteria)
- {
- if($criteria===null)
- return $this->getBuilder()->createFindCommand();
- $where = $criteria->getCondition();
- $parameters = $criteria->getParameters()->toArray();
- $ordering = $criteria->getOrdersBy();
- $limit = $criteria->getLimit();
- $offset = $criteria->getOffset();
- $select = $criteria->getSelect();
- $command = $this->getBuilder()->createFindCommand($where,$parameters,$ordering,$limit,$offset,$select);
- $this->onCreateCommand($command, $criteria);
- return $command;
- }
-
- /**
- * @param mixed primary key value, or composite key values as array.
- * @return array matching record.
- */
- public function findByPk($keys)
- {
- list($where, $parameters) = $this->getPrimaryKeyCondition((array)$keys);
- $command = $this->getBuilder()->createFindCommand($where, $parameters);
- $this->onCreateCommand($command, new TSqlCriteria($where,$parameters));
- return $this->onExecuteCommand($command, $command->queryRow());
- }
-
- /**
- * @param array multiple primary key values or composite value arrays
- * @return TDbDataReader record reader.
- */
- public function findAllByPk($keys)
- {
- $where = $this->getCompositeKeyCondition((array)$keys);
- $command = $this->getBuilder()->createFindCommand($where);
- $this->onCreateCommand($command, new TSqlCriteria($where,$keys));
- return $this->onExecuteCommand($command,$command->query());
- }
-
- public function findAllByIndex($criteria,$fields,$values)
- {
- $index = $this->getIndexKeyCondition($this->getTableInfo(),$fields,$values);
- if(strlen($where = $criteria->getCondition())>0)
- $criteria->setCondition("({$index}) AND ({$where})");
- else
- $criteria->setCondition($index);
- $command = $this->getFindCommand($criteria);
- $this->onCreateCommand($command, $criteria);
- return $this->onExecuteCommand($command,$command->query());
- }
-
- /**
- * @param array multiple primary key values or composite value arrays
- * @return integer number of rows affected.
- */
- public function deleteByPk($keys)
- {
- $where = $this->getCompositeKeyCondition((array)$keys);
- $command = $this->getBuilder()->createDeleteCommand($where);
- $this->onCreateCommand($command, new TSqlCriteria($where,$keys));
- $command->prepare();
- return $this->onExecuteCommand($command,$command->execute());
- }
-
- public function getIndexKeyCondition($table,$fields,$values)
- {
- if (!count($values))
- return 'FALSE';
- $columns = array();
- $tableName = $table->getTableFullName();
- foreach($fields as $field)
- $columns[] = $tableName.'.'.$table->getColumn($field)->getColumnName();
- return '('.implode(', ',$columns).') IN '.$this->quoteTuple($values);
- }
-
- /**
- * Construct a "pk IN ('key1', 'key2', ...)" criteria.
- * @param array values for IN predicate
- * @param string SQL string for primary keys IN a list.
- */
- protected function getCompositeKeyCondition($values)
- {
- $primary = $this->getTableInfo()->getPrimaryKeys();
- $count = count($primary);
- if($count===0)
- {
- throw new TDbException('dbtablegateway_no_primary_key_found',
- $this->getTableInfo()->getTableFullName());
- }
- if(!is_array($values) || count($values) === 0)
- {
- throw new TDbException('dbtablegateway_missing_pk_values',
- $this->getTableInfo()->getTableFullName());
- }
- if($count>1 && (!isset($values[0]) || !is_array($values[0])))
- $values = array($values);
- if($count > 1 && count($values[0]) !== $count)
- {
- throw new TDbException('dbtablegateway_pk_value_count_mismatch',
- $this->getTableInfo()->getTableFullName());
- }
- return $this->getIndexKeyCondition($this->getTableInfo(),$primary, $values);
- }
-
- /**
- * @param TDbConnection database connection.
- * @param array values
- * @return string quoted recursive tuple values, e.g. "('val1', 'val2')".
- */
- protected function quoteTuple($array)
- {
- $conn = $this->getDbConnection();
- $data = array();
- foreach($array as $k=>$v)
- $data[] = is_array($v) ? $this->quoteTuple($v) : $conn->quoteString($v);
- return '('.implode(', ', $data).')';
- }
-
- /**
- * Create the condition and parameters for find by primary.
- * @param array primary key values
- * @return array tuple($where, $parameters)
- */
- protected function getPrimaryKeyCondition($values)
- {
- $primary = $this->getTableInfo()->getPrimaryKeys();
- if(count($primary)===0)
- {
- throw new TDbException('dbtablegateway_no_primary_key_found',
- $this->getTableInfo()->getTableFullName());
- }
- $criteria=array();
- $bindings=array();
- $i = 0;
- foreach($primary as $key)
- {
- $column = $this->getTableInfo()->getColumn($key)->getColumnName();
- $criteria[] = $column.' = :'.$key;
- $bindings[$key] = isset($values[$key])?$values[$key]:$values[$i++];
- }
- return array(implode(' AND ', $criteria), $bindings);
- }
-
- /**
- * Find one matching records for arbituary SQL.
- * @param TSqlCriteria $criteria
- * @return TDbDataReader record reader.
- */
- public function findBySql($criteria)
- {
- $command = $this->getSqlCommand($criteria);
- return $this->onExecuteCommand($command, $command->queryRow());
- }
-
- /**
- * Find zero or more matching records for arbituary SQL.
- * @param TSqlCriteria $criteria
- * @return TDbDataReader record reader.
- */
- public function findAllBySql($criteria)
- {
- $command = $this->getSqlCommand($criteria);
- return $this->onExecuteCommand($command, $command->query());
- }
-
- /**
- * Build sql command from the criteria. Limit, Offset and Ordering are applied if applicable.
- * @param TSqlCriteria $criteria
- * @return TDbCommand command corresponding to the criteria.
- */
- protected function getSqlCommand($criteria)
- {
- $sql = $criteria->getCondition();
- $ordering = $criteria->getOrdersBy();
- $limit = $criteria->getLimit();
- $offset = $criteria->getOffset();
- if(count($ordering) > 0)
- $sql = $this->getBuilder()->applyOrdering($sql, $ordering);
- if($limit>=0 || $offset>=0)
- $sql = $this->getBuilder()->applyLimitOffset($sql, $limit, $offset);
- $command = $this->getBuilder()->createCommand($sql);
- $this->getBuilder()->bindArrayValues($command, $criteria->getParameters()->toArray());
- $this->onCreateCommand($command, $criteria);
- return $command;
- }
-
- /**
- * @param TSqlCriteria $criteria
- * @return integer number of records.
- */
- public function count($criteria)
- {
- if($criteria===null)
- return (int)$this->getBuilder()->createCountCommand()->queryScalar();
- $where = $criteria->getCondition();
- $parameters = $criteria->getParameters()->toArray();
- $ordering = $criteria->getOrdersBy();
- $limit = $criteria->getLimit();
- $offset = $criteria->getOffset();
- $command = $this->getBuilder()->createCountCommand($where,$parameters,$ordering,$limit,$offset);
- $this->onCreateCommand($command, $criteria);
- return $this->onExecuteCommand($command, (int)$command->queryScalar());
- }
-
- /**
- * Inserts a new record into the table. Each array key must
- * correspond to a column name in the table unless a null value is permitted.
- * @param array new record data.
- * @return mixed last insert id if one column contains a serial or sequence,
- * otherwise true if command executes successfully and affected 1 or more rows.
- */
- public function insert($data)
- {
- $command=$this->getBuilder()->createInsertCommand($data);
- $this->onCreateCommand($command, new TSqlCriteria(null,$data));
- $command->prepare();
- if($this->onExecuteCommand($command, $command->execute()) > 0)
- {
- $value = $this->getLastInsertId();
- return $value !== null ? $value : true;
- }
- return false;
- }
-
- /**
- * Iterate through all the columns and returns the last insert id of the
- * first column that has a sequence or serial.
- * @return mixed last insert id, null if none is found.
- */
- public function getLastInsertID()
- {
- return $this->getBuilder()->getLastInsertID();
- }
-
- /**
- * @param string __call method name
- * @param string criteria conditions
- * @param array method arguments
- * @return TActiveRecordCriteria criteria created from the method name and its arguments.
- */
- public function createCriteriaFromString($method, $condition, $args)
- {
- $fields = $this->extractMatchingConditions($method, $condition);
- $args=count($args) === 1 && is_array($args[0]) ? $args[0] : $args;
- if(count($fields)>count($args))
- {
- throw new TDbException('dbtablegateway_mismatch_args_exception',
- $method,count($fields),count($args));
- }
- return new TSqlCriteria(implode(' ',$fields), $args);
- }
-
- /**
- * Calculates the AND/OR condition from dynamic method substrings using
- * table meta data, allows for any AND-OR combinations.
- * @param string dynamic method name
- * @param string dynamic method search criteria
- * @return array search condition substrings
- */
- protected function extractMatchingConditions($method, $condition)
- {
- $table = $this->getTableInfo();
- $columns = $table->getLowerCaseColumnNames();
- $regexp = '/('.implode('|', array_keys($columns)).')(and|_and_|or|_or_)?/i';
- $matches = array();
- if(!preg_match_all($regexp, strtolower($condition), $matches,PREG_SET_ORDER))
- {
- throw new TDbException('dbtablegateway_mismatch_column_name',
- $method, implode(', ', $columns), $table->getTableFullName());
- }
-
- $fields = array();
- foreach($matches as $match)
- {
- $key = $columns[$match[1]];
- $column = $table->getColumn($key)->getColumnName();
- $sql = $column . ' = ? ';
- if(count($match) > 2)
- $sql .= strtoupper(str_replace('_', '', $match[2]));
- $fields[] = $sql;
- }
- return $fields;
- }
-
- /**
- * Raised when a command is prepared and parameter binding is completed.
- * The parameter object is TDataGatewayEventParameter of which the
- * {@link TDataGatewayEventParameter::getCommand Command} property can be
- * inspected to obtain the sql query to be executed.
- * @param TDataGatewayCommand originator $sender
- * @param TDataGatewayEventParameter
- */
- public function onCreateCommand($command, $criteria)
- {
- $this->raiseEvent('OnCreateCommand', $this, new TDataGatewayEventParameter($command,$criteria));
- }
-
- /**
- * Raised when a command is executed and the result from the database was returned.
- * The parameter object is TDataGatewayResultEventParameter of which the
- * {@link TDataGatewayEventParameter::getResult Result} property contains
- * the data return from the database. The data returned can be changed
- * by setting the {@link TDataGatewayEventParameter::setResult Result} property.
- * @param TDataGatewayCommand originator $sender
- * @param TDataGatewayResultEventParameter
- */
- public function onExecuteCommand($command, $result)
- {
- $parameter = new TDataGatewayResultEventParameter($command, $result);
- $this->raiseEvent('OnExecuteCommand', $this, $parameter);
- return $parameter->getResult();
- }
-}
-
-/**
- * TDataGatewayEventParameter class contains the TDbCommand to be executed as
- * well as the criteria object.
- *
- * @author Wei Zhuo <weizho[at]gmail[dot]com>
- * @version $Id$
- * @package System.Data.DataGateway
- * @since 3.1
- */
-class TDataGatewayEventParameter extends TEventParameter
-{
- private $_command;
- private $_criteria;
-
- public function __construct($command,$criteria)
- {
- $this->_command=$command;
- $this->_criteria=$criteria;
- }
-
- /**
- * The database command to be executed. Do not rebind the parameters or change
- * the sql query string.
- * @return TDbCommand command to be executed.
- */
- public function getCommand()
- {
- return $this->_command;
- }
-
- /**
- * @return TSqlCriteria criteria used to bind the sql query parameters.
- */
- public function getCriteria()
- {
- return $this->_criteria;
- }
-}
-
-/**
- * TDataGatewayResultEventParameter contains the TDbCommand executed and the resulting
- * data returned from the database. The data can be changed by changing the
- * {@link setResult Result} property.
- *
- * @author Wei Zhuo <weizho[at]gmail[dot]com>
- * @version $Id$
- * @package System.Data.DataGateway
- * @since 3.1
- */
-class TDataGatewayResultEventParameter extends TEventParameter
-{
- private $_command;
- private $_result;
-
- public function __construct($command,$result)
- {
- $this->_command=$command;
- $this->_result=$result;
- }
-
- /**
- * @return TDbCommand database command executed.
- */
- public function getCommand()
- {
- return $this->_command;
- }
-
- /**
- * @return mixed result returned from executing the command.
- */
- public function getResult()
- {
- return $this->_result;
- }
-
- /**
- * @param mixed change the result returned by the gateway.
- */
- public function setResult($value)
- {
- $this->_result=$value;
- }
-}
-
-?>
+<?php
+/**
+ * TDataGatewayCommand, TDataGatewayEventParameter and TDataGatewayResultEventParameter class file.
+ *
+ * @author Wei Zhuo <weizhuo[at]gmail[dot]com>
+ * @link http://www.pradosoft.com/
+ * @copyright Copyright &copy; 2005-2012 PradoSoft
+ * @license http://www.pradosoft.com/license/
+ * @version $Id$
+ * @package System.Data.DataGateway
+ */
+
+/**
+ * TDataGatewayCommand is command builder and executor class for
+ * TTableGateway and TActiveRecordGateway.
+ *
+ * TDataGatewayCommand builds the TDbCommand for TTableGateway
+ * and TActiveRecordGateway commands such as find(), update(), insert(), etc,
+ * using the TDbCommandBuilder classes (database specific TDbCommandBuilder
+ * classes are used).
+ *
+ * Once the command is built and the query parameters are binded, the
+ * {@link OnCreateCommand} event is raised. Event handlers for the OnCreateCommand
+ * event should not alter the Command property nor the Criteria property of the
+ * TDataGatewayEventParameter.
+ *
+ * TDataGatewayCommand excutes the TDbCommands and returns the result obtained from the
+ * database (returned value depends on the method executed). The
+ * {@link OnExecuteCommand} event is raised after the command is executed and resulting
+ * data is set in the TDataGatewayResultEventParameter object's Result property.
+ *
+ * @author Wei Zhuo <weizho[at]gmail[dot]com>
+ * @version $Id$
+ * @package System.Data.DataGateway
+ * @since 3.1
+ */
+class TDataGatewayCommand extends TComponent
+{
+ private $_builder;
+
+ /**
+ * @param TDbCommandBuilder database specific database command builder.
+ */
+ public function __construct($builder)
+ {
+ $this->_builder = $builder;
+ }
+
+ /**
+ * @return TDbTableInfo
+ */
+ public function getTableInfo()
+ {
+ return $this->_builder->getTableInfo();
+ }
+
+ /**
+ * @return TDbConnection
+ */
+ public function getDbConnection()
+ {
+ return $this->_builder->getDbConnection();
+ }
+
+ /**
+ * @return TDbCommandBuilder
+ */
+ public function getBuilder()
+ {
+ return $this->_builder;
+ }
+
+ /**
+ * Executes a delete command.
+ * @param TSqlCriteria delete conditions and parameters.
+ * @return integer number of records affected.
+ */
+ public function delete($criteria)
+ {
+ $where = $criteria->getCondition();
+ $parameters = $criteria->getParameters()->toArray();
+ $command = $this->getBuilder()->createDeleteCommand($where, $parameters);
+ $this->onCreateCommand($command,$criteria);
+ $command->prepare();
+ return $command->execute();
+ }
+
+ /**
+ * Updates the table with new data.
+ * @param array date for update.
+ * @param TSqlCriteria update conditions and parameters.
+ * @return integer number of records affected.
+ */
+ public function update($data, $criteria)
+ {
+ $where = $criteria->getCondition();
+ $parameters = $criteria->getParameters()->toArray();
+ $command = $this->getBuilder()->createUpdateCommand($data,$where, $parameters);
+ $this->onCreateCommand($command,$criteria);
+ $command->prepare();
+ return $this->onExecuteCommand($command, $command->execute());
+ }
+
+ /**
+ * @param array update for update
+ * @param array primary key-value name pairs.
+ * @return integer number of records affected.
+ */
+ public function updateByPk($data, $keys)
+ {
+ list($where, $parameters) = $this->getPrimaryKeyCondition((array)$keys);
+ return $this->update($data, new TSqlCriteria($where, $parameters));
+ }
+
+ /**
+ * Find one record matching the critera.
+ * @param TSqlCriteria find conditions and parameters.
+ * @return array matching record.
+ */
+ public function find($criteria)
+ {
+ $command = $this->getFindCommand($criteria);
+ return $this->onExecuteCommand($command, $command->queryRow());
+ }
+
+ /**
+ * Find one or more matching records.
+ * @param TSqlCriteria $criteria
+ * @return TDbDataReader record reader.
+ */
+ public function findAll($criteria)
+ {
+ $command = $this->getFindCommand($criteria);
+ return $this->onExecuteCommand($command, $command->query());
+ }
+
+ /**
+ * Build the find command from the criteria. Limit, Offset and Ordering are applied if applicable.
+ * @param TSqlCriteria $criteria
+ * @return TDbCommand.
+ */
+ protected function getFindCommand($criteria)
+ {
+ if($criteria===null)
+ return $this->getBuilder()->createFindCommand();
+ $where = $criteria->getCondition();
+ $parameters = $criteria->getParameters()->toArray();
+ $ordering = $criteria->getOrdersBy();
+ $limit = $criteria->getLimit();
+ $offset = $criteria->getOffset();
+ $select = $criteria->getSelect();
+ $command = $this->getBuilder()->createFindCommand($where,$parameters,$ordering,$limit,$offset,$select);
+ $this->onCreateCommand($command, $criteria);
+ return $command;
+ }
+
+ /**
+ * @param mixed primary key value, or composite key values as array.
+ * @return array matching record.
+ */
+ public function findByPk($keys)
+ {
+ list($where, $parameters) = $this->getPrimaryKeyCondition((array)$keys);
+ $command = $this->getBuilder()->createFindCommand($where, $parameters);
+ $this->onCreateCommand($command, new TSqlCriteria($where,$parameters));
+ return $this->onExecuteCommand($command, $command->queryRow());
+ }
+
+ /**
+ * @param array multiple primary key values or composite value arrays
+ * @return TDbDataReader record reader.
+ */
+ public function findAllByPk($keys)
+ {
+ $where = $this->getCompositeKeyCondition((array)$keys);
+ $command = $this->getBuilder()->createFindCommand($where);
+ $this->onCreateCommand($command, new TSqlCriteria($where,$keys));
+ return $this->onExecuteCommand($command,$command->query());
+ }
+
+ public function findAllByIndex($criteria,$fields,$values)
+ {
+ $index = $this->getIndexKeyCondition($this->getTableInfo(),$fields,$values);
+ if(strlen($where = $criteria->getCondition())>0)
+ $criteria->setCondition("({$index}) AND ({$where})");
+ else
+ $criteria->setCondition($index);
+ $command = $this->getFindCommand($criteria);
+ $this->onCreateCommand($command, $criteria);
+ return $this->onExecuteCommand($command,$command->query());
+ }
+
+ /**
+ * @param array multiple primary key values or composite value arrays
+ * @return integer number of rows affected.
+ */
+ public function deleteByPk($keys)
+ {
+ $where = $this->getCompositeKeyCondition((array)$keys);
+ $command = $this->getBuilder()->createDeleteCommand($where);
+ $this->onCreateCommand($command, new TSqlCriteria($where,$keys));
+ $command->prepare();
+ return $this->onExecuteCommand($command,$command->execute());
+ }
+
+ public function getIndexKeyCondition($table,$fields,$values)
+ {
+ if (!count($values))
+ return 'FALSE';
+ $columns = array();
+ $tableName = $table->getTableFullName();
+ foreach($fields as $field)
+ $columns[] = $tableName.'.'.$table->getColumn($field)->getColumnName();
+ return '('.implode(', ',$columns).') IN '.$this->quoteTuple($values);
+ }
+
+ /**
+ * Construct a "pk IN ('key1', 'key2', ...)" criteria.
+ * @param array values for IN predicate
+ * @param string SQL string for primary keys IN a list.
+ */
+ protected function getCompositeKeyCondition($values)
+ {
+ $primary = $this->getTableInfo()->getPrimaryKeys();
+ $count = count($primary);
+ if($count===0)
+ {
+ throw new TDbException('dbtablegateway_no_primary_key_found',
+ $this->getTableInfo()->getTableFullName());
+ }
+ if(!is_array($values) || count($values) === 0)
+ {
+ throw new TDbException('dbtablegateway_missing_pk_values',
+ $this->getTableInfo()->getTableFullName());
+ }
+ if($count>1 && (!isset($values[0]) || !is_array($values[0])))
+ $values = array($values);
+ if($count > 1 && count($values[0]) !== $count)
+ {
+ throw new TDbException('dbtablegateway_pk_value_count_mismatch',
+ $this->getTableInfo()->getTableFullName());
+ }
+ return $this->getIndexKeyCondition($this->getTableInfo(),$primary, $values);
+ }
+
+ /**
+ * @param TDbConnection database connection.
+ * @param array values
+ * @return string quoted recursive tuple values, e.g. "('val1', 'val2')".
+ */
+ protected function quoteTuple($array)
+ {
+ $conn = $this->getDbConnection();
+ $data = array();
+ foreach($array as $k=>$v)
+ $data[] = is_array($v) ? $this->quoteTuple($v) : $conn->quoteString($v);
+ return '('.implode(', ', $data).')';
+ }
+
+ /**
+ * Create the condition and parameters for find by primary.
+ * @param array primary key values
+ * @return array tuple($where, $parameters)
+ */
+ protected function getPrimaryKeyCondition($values)
+ {
+ $primary = $this->getTableInfo()->getPrimaryKeys();
+ if(count($primary)===0)
+ {
+ throw new TDbException('dbtablegateway_no_primary_key_found',
+ $this->getTableInfo()->getTableFullName());
+ }
+ $criteria=array();
+ $bindings=array();
+ $i = 0;
+ foreach($primary as $key)
+ {
+ $column = $this->getTableInfo()->getColumn($key)->getColumnName();
+ $criteria[] = $column.' = :'.$key;
+ $bindings[$key] = isset($values[$key])?$values[$key]:$values[$i++];
+ }
+ return array(implode(' AND ', $criteria), $bindings);
+ }
+
+ /**
+ * Find one matching records for arbituary SQL.
+ * @param TSqlCriteria $criteria
+ * @return TDbDataReader record reader.
+ */
+ public function findBySql($criteria)
+ {
+ $command = $this->getSqlCommand($criteria);
+ return $this->onExecuteCommand($command, $command->queryRow());
+ }
+
+ /**
+ * Find zero or more matching records for arbituary SQL.
+ * @param TSqlCriteria $criteria
+ * @return TDbDataReader record reader.
+ */
+ public function findAllBySql($criteria)
+ {
+ $command = $this->getSqlCommand($criteria);
+ return $this->onExecuteCommand($command, $command->query());
+ }
+
+ /**
+ * Build sql command from the criteria. Limit, Offset and Ordering are applied if applicable.
+ * @param TSqlCriteria $criteria
+ * @return TDbCommand command corresponding to the criteria.
+ */
+ protected function getSqlCommand($criteria)
+ {
+ $sql = $criteria->getCondition();
+ $ordering = $criteria->getOrdersBy();
+ $limit = $criteria->getLimit();
+ $offset = $criteria->getOffset();
+ if(count($ordering) > 0)
+ $sql = $this->getBuilder()->applyOrdering($sql, $ordering);
+ if($limit>=0 || $offset>=0)
+ $sql = $this->getBuilder()->applyLimitOffset($sql, $limit, $offset);
+ $command = $this->getBuilder()->createCommand($sql);
+ $this->getBuilder()->bindArrayValues($command, $criteria->getParameters()->toArray());
+ $this->onCreateCommand($command, $criteria);
+ return $command;
+ }
+
+ /**
+ * @param TSqlCriteria $criteria
+ * @return integer number of records.
+ */
+ public function count($criteria)
+ {
+ if($criteria===null)
+ return (int)$this->getBuilder()->createCountCommand()->queryScalar();
+ $where = $criteria->getCondition();
+ $parameters = $criteria->getParameters()->toArray();
+ $ordering = $criteria->getOrdersBy();
+ $limit = $criteria->getLimit();
+ $offset = $criteria->getOffset();
+ $command = $this->getBuilder()->createCountCommand($where,$parameters,$ordering,$limit,$offset);
+ $this->onCreateCommand($command, $criteria);
+ return $this->onExecuteCommand($command, (int)$command->queryScalar());
+ }
+
+ /**
+ * Inserts a new record into the table. Each array key must
+ * correspond to a column name in the table unless a null value is permitted.
+ * @param array new record data.
+ * @return mixed last insert id if one column contains a serial or sequence,
+ * otherwise true if command executes successfully and affected 1 or more rows.
+ */
+ public function insert($data)
+ {
+ $command=$this->getBuilder()->createInsertCommand($data);
+ $this->onCreateCommand($command, new TSqlCriteria(null,$data));
+ $command->prepare();
+ if($this->onExecuteCommand($command, $command->execute()) > 0)
+ {
+ $value = $this->getLastInsertId();
+ return $value !== null ? $value : true;
+ }
+ return false;
+ }
+
+ /**
+ * Iterate through all the columns and returns the last insert id of the
+ * first column that has a sequence or serial.
+ * @return mixed last insert id, null if none is found.
+ */
+ public function getLastInsertID()
+ {
+ return $this->getBuilder()->getLastInsertID();
+ }
+
+ /**
+ * @param string __call method name
+ * @param string criteria conditions
+ * @param array method arguments
+ * @return TActiveRecordCriteria criteria created from the method name and its arguments.
+ */
+ public function createCriteriaFromString($method, $condition, $args)
+ {
+ $fields = $this->extractMatchingConditions($method, $condition);
+ $args=count($args) === 1 && is_array($args[0]) ? $args[0] : $args;
+ if(count($fields)>count($args))
+ {
+ throw new TDbException('dbtablegateway_mismatch_args_exception',
+ $method,count($fields),count($args));
+ }
+ return new TSqlCriteria(implode(' ',$fields), $args);
+ }
+
+ /**
+ * Calculates the AND/OR condition from dynamic method substrings using
+ * table meta data, allows for any AND-OR combinations.
+ * @param string dynamic method name
+ * @param string dynamic method search criteria
+ * @return array search condition substrings
+ */
+ protected function extractMatchingConditions($method, $condition)
+ {
+ $table = $this->getTableInfo();
+ $columns = $table->getLowerCaseColumnNames();
+ $regexp = '/('.implode('|', array_keys($columns)).')(and|_and_|or|_or_)?/i';
+ $matches = array();
+ if(!preg_match_all($regexp, strtolower($condition), $matches,PREG_SET_ORDER))
+ {
+ throw new TDbException('dbtablegateway_mismatch_column_name',
+ $method, implode(', ', $columns), $table->getTableFullName());
+ }
+
+ $fields = array();
+ foreach($matches as $match)
+ {
+ $key = $columns[$match[1]];
+ $column = $table->getColumn($key)->getColumnName();
+ $sql = $column . ' = ? ';
+ if(count($match) > 2)
+ $sql .= strtoupper(str_replace('_', '', $match[2]));
+ $fields[] = $sql;
+ }
+ return $fields;
+ }
+
+ /**
+ * Raised when a command is prepared and parameter binding is completed.
+ * The parameter object is TDataGatewayEventParameter of which the
+ * {@link TDataGatewayEventParameter::getCommand Command} property can be
+ * inspected to obtain the sql query to be executed.
+ * @param TDataGatewayCommand originator $sender
+ * @param TDataGatewayEventParameter
+ */
+ public function onCreateCommand($command, $criteria)
+ {
+ $this->raiseEvent('OnCreateCommand', $this, new TDataGatewayEventParameter($command,$criteria));
+ }
+
+ /**
+ * Raised when a command is executed and the result from the database was returned.
+ * The parameter object is TDataGatewayResultEventParameter of which the
+ * {@link TDataGatewayEventParameter::getResult Result} property contains
+ * the data return from the database. The data returned can be changed
+ * by setting the {@link TDataGatewayEventParameter::setResult Result} property.
+ * @param TDataGatewayCommand originator $sender
+ * @param TDataGatewayResultEventParameter
+ */
+ public function onExecuteCommand($command, $result)
+ {
+ $parameter = new TDataGatewayResultEventParameter($command, $result);
+ $this->raiseEvent('OnExecuteCommand', $this, $parameter);
+ return $parameter->getResult();
+ }
+}
+
+/**
+ * TDataGatewayEventParameter class contains the TDbCommand to be executed as
+ * well as the criteria object.
+ *
+ * @author Wei Zhuo <weizho[at]gmail[dot]com>
+ * @version $Id$
+ * @package System.Data.DataGateway
+ * @since 3.1
+ */
+class TDataGatewayEventParameter extends TEventParameter
+{
+ private $_command;
+ private $_criteria;
+
+ public function __construct($command,$criteria)
+ {
+ $this->_command=$command;
+ $this->_criteria=$criteria;
+ }
+
+ /**
+ * The database command to be executed. Do not rebind the parameters or change
+ * the sql query string.
+ * @return TDbCommand command to be executed.
+ */
+ public function getCommand()
+ {
+ return $this->_command;
+ }
+
+ /**
+ * @return TSqlCriteria criteria used to bind the sql query parameters.
+ */
+ public function getCriteria()
+ {
+ return $this->_criteria;
+ }
+}
+
+/**
+ * TDataGatewayResultEventParameter contains the TDbCommand executed and the resulting
+ * data returned from the database. The data can be changed by changing the
+ * {@link setResult Result} property.
+ *
+ * @author Wei Zhuo <weizho[at]gmail[dot]com>
+ * @version $Id$
+ * @package System.Data.DataGateway
+ * @since 3.1
+ */
+class TDataGatewayResultEventParameter extends TEventParameter
+{
+ private $_command;
+ private $_result;
+
+ public function __construct($command,$result)
+ {
+ $this->_command=$command;
+ $this->_result=$result;
+ }
+
+ /**
+ * @return TDbCommand database command executed.
+ */
+ public function getCommand()
+ {
+ return $this->_command;
+ }
+
+ /**
+ * @return mixed result returned from executing the command.
+ */
+ public function getResult()
+ {
+ return $this->_result;
+ }
+
+ /**
+ * @param mixed change the result returned by the gateway.
+ */
+ public function setResult($value)
+ {
+ $this->_result=$value;
+ }
+}
+
+?>
diff --git a/framework/Data/DataGateway/TSqlCriteria.php b/framework/Data/DataGateway/TSqlCriteria.php
index a7da3adf..3a54f4c4 100644
--- a/framework/Data/DataGateway/TSqlCriteria.php
+++ b/framework/Data/DataGateway/TSqlCriteria.php
@@ -1,284 +1,284 @@
-<?php
-/**
- * TDbSqlCriteria class file.
- *
- * @author Wei Zhuo <weizhuo[at]gmail[dot]com>
- * @link http://www.pradosoft.com/
- * @copyright Copyright &copy; 2005-2012 PradoSoft
- * @license http://www.pradosoft.com/license/
- * @version $Id: TDbSqlCriteria.php 1835 2007-04-03 01:38:15Z wei $
- * @package System.Data.DataGateway
- */
-
-/**
- * Search criteria for TDbDataGateway.
- *
- * Criteria object for data gateway finder methods. Usage:
- * <code>
- * $criteria = new TSqlCriteria();
- * $criteria->Parameters[':name'] = 'admin';
- * $criteria->Parameters[':pass'] = 'prado';
- * $criteria->OrdersBy['level'] = 'desc';
- * $criteria->OrdersBy['name'] = 'asc';
- * $criteria->Limit = 10;
- * $criteria->Offset = 20;
- * </code>
- *
- * @author Wei Zhuo <weizho[at]gmail[dot]com>
- * @version $Id: TDbSqlCriteria.php 1835 2007-04-03 01:38:15Z wei $
- * @package System.Data.DataGateway
- * @since 3.1
- */
-class TSqlCriteria extends TComponent
-{
- /**
- * @var mixed
- * @since 3.1.7
- */
- private $_select='*';
- private $_condition;
- private $_parameters;
- private $_ordersBy;
- private $_limit;
- private $_offset;
-
- /**
- * Creates a new criteria with given condition;
- * @param string sql string after the WHERE stanza
- * @param mixed named or indexed parameters, accepts as multiple arguments.
- */
- public function __construct($condition=null, $parameters=array())
- {
- if(!is_array($parameters) && func_num_args() > 1)
- $parameters = array_slice(func_get_args(),1);
- $this->_parameters=new TAttributeCollection;
- $this->_parameters->setCaseSensitive(true);
- $this->_parameters->copyFrom((array)$parameters);
- $this->_ordersBy=new TAttributeCollection;
- $this->_ordersBy->setCaseSensitive(true);
-
- $this->setCondition($condition);
- }
-
- /**
- * Gets the field list to be placed after the SELECT in the SQL. Default to '*'
- * @return mixed
- * @since 3.1.7
- */
- public function getSelect()
- {
- return $this->_select;
- }
-
- /**
- * Sets the field list to be placed after the SELECT in the SQL.
- *
- * Different behavior depends on type of assigned value
- * string
- * usage without modification
- *
- * null
- * will be expanded to full list of quoted table column names (quoting depends on database)
- *
- * array
- * - Column names will be quoted if used as key or value of array
- * <code>
- * array('col1', 'col2', 'col2')
- * // SELECT `col1`, `col2`, `col3` FROM...
- * </code>
- *
- * - Column aliasing
- * <code>
- * array('mycol1' => 'col1', 'mycol2' => 'COUNT(*)')
- * // SELECT `col1` AS mycol1, COUNT(*) AS mycol2 FROM...
- * </code>
- *
- * - NULL and scalar values (strings will be quoted depending on database)
- * <code>
- * array('col1' => 'my custom string', 'col2' => 1.0, 'col3' => 'NULL')
- * // SELECT "my custom string" AS `col1`, 1.0 AS `col2`, NULL AS `col3` FROM...
- * </code>
- *
- * - If the *-wildcard char is used as key or value, add the full list of quoted table column names
- * <code>
- * array('col1' => 'NULL', '*')
- * // SELECT `col1`, `col2`, `col3`, NULL AS `col1` FROM...
- * </code>
- *
- * @param mixed
- * @since 3.1.7
- * @see TDbCommandBuilder::getSelectFieldList()
- */
- public function setSelect($value)
- {
- $this->_select = $value;
- }
-
- /**
- * @return string search conditions.
- */
- public function getCondition()
- {
- return $this->_condition;
- }
-
- /**
- * Sets the search conditions to be placed after the WHERE clause in the SQL.
- * @param string search conditions.
- */
- public function setCondition($value)
- {
- if(empty($value)) {
- return;
- }
-
- // supporting the following SELECT-syntax:
- // [ORDER BY {col_name | expr | position}
- // [ASC | DESC], ...]
- // [LIMIT {[offset,] row_count | row_count OFFSET offset}]
- // See: http://dev.mysql.com/doc/refman/5.0/en/select.html
-
- if(preg_match('/ORDER\s+BY\s+(.*?)(?=LIMIT)|ORDER\s+BY\s+(.*?)$/i', $value, $matches) > 0) {
- // condition contains ORDER BY
- $value = str_replace($matches[0], '', $value);
- if(strlen($matches[1]) > 0) {
- $this->setOrdersBy($matches[1]);
- } else if(strlen($matches[2]) > 0) {
- $this->setOrdersBy($matches[2]);
- }
- }
-
- if(preg_match('/LIMIT\s+([\d\s,]+)/i', $value, $matches) > 0) {
- // condition contains limit
- $value = str_replace($matches[0], '', $value); // remove limit from query
- if(strpos($matches[1], ',')) { // both offset and limit given
- list($offset, $limit) = explode(',', $matches[1]);
- $this->_limit = (int)$limit;
- $this->_offset = (int)$offset;
- } else { // only limit given
- $this->_limit = (int)$matches[1];
- }
- }
-
- if(preg_match('/OFFSET\s+(\d+)/i', $value, $matches) > 0) {
- // condition contains offset
- $value = str_replace($matches[0], '', $value); // remove offset from query
- $this->_offset = (int)$matches[1]; // set offset in criteria
- }
-
- $this->_condition = trim($value);
- }
-
- /**
- * @return TAttributeCollection list of named parameters and values.
- */
- public function getParameters()
- {
- return $this->_parameters;
- }
-
- /**
- * @param ArrayAccess named parameters.
- */
- public function setParameters($value)
- {
- if(!(is_array($value) || $value instanceof ArrayAccess))
- throw new TException('value must be array or ArrayAccess');
- $this->_parameters->copyFrom($value);
- }
-
- /**
- * @return boolean true if the parameter index are string base, false otherwise.
- */
- public function getIsNamedParameters()
- {
- foreach($this->getParameters() as $k=>$v)
- return is_string($k);
- }
-
- /**
- * @return TAttributeCollection ordering clause.
- */
- public function getOrdersBy()
- {
- return $this->_ordersBy;
- }
-
- /**
- * @param mixed ordering clause.
- */
- public function setOrdersBy($value)
- {
- if(is_array($value) || $value instanceof Traversable)
- $this->_ordersBy->copyFrom($value);
- else
- {
- $value=trim(preg_replace('/\s+/',' ',(string)$value));
- $orderBys=array();
- foreach(explode(',',$value) as $orderBy)
- {
- $vs=explode(' ',trim($orderBy));
- $orderBys[$vs[0]]=isset($vs[1])?$vs[1]:'asc';
- }
- $this->_ordersBy->copyFrom($orderBys);
- }
- }
-
- /**
- * @return int maximum number of records to return.
- */
- public function getLimit()
- {
- return $this->_limit;
- }
-
- /**
- * @param int maximum number of records to return.
- */
- public function setLimit($value)
- {
- $this->_limit=$value;
- }
-
- /**
- * @return int record offset.
- */
- public function getOffset()
- {
- return $this->_offset;
- }
-
- /**
- * @param int record offset.
- */
- public function setOffset($value)
- {
- $this->_offset=$value;
- }
-
- /**
- * @return string string representation of the parameters. Useful for debugging.
- */
- public function __toString()
- {
- $str = '';
- if(strlen((string)$this->getCondition()) > 0)
- $str .= '"'.(string)$this->getCondition().'"';
- $params = array();
- foreach($this->getParameters() as $k=>$v)
- $params[] = "{$k} => ${v}";
- if(count($params) > 0)
- $str .= ', "'.implode(', ',$params).'"';
- $orders = array();
- foreach($this->getOrdersBy() as $k=>$v)
- $orders[] = "{$k} => ${v}";
- if(count($orders) > 0)
- $str .= ', "'.implode(', ',$orders).'"';
- if($this->_limit !==null)
- $str .= ', '.$this->_limit;
- if($this->_offset !== null)
- $str .= ', '.$this->_offset;
- return $str;
- }
-}
+<?php
+/**
+ * TDbSqlCriteria class file.
+ *
+ * @author Wei Zhuo <weizhuo[at]gmail[dot]com>
+ * @link http://www.pradosoft.com/
+ * @copyright Copyright &copy; 2005-2012 PradoSoft
+ * @license http://www.pradosoft.com/license/
+ * @version $Id: TDbSqlCriteria.php 1835 2007-04-03 01:38:15Z wei $
+ * @package System.Data.DataGateway
+ */
+
+/**
+ * Search criteria for TDbDataGateway.
+ *
+ * Criteria object for data gateway finder methods. Usage:
+ * <code>
+ * $criteria = new TSqlCriteria();
+ * $criteria->Parameters[':name'] = 'admin';
+ * $criteria->Parameters[':pass'] = 'prado';
+ * $criteria->OrdersBy['level'] = 'desc';
+ * $criteria->OrdersBy['name'] = 'asc';
+ * $criteria->Limit = 10;
+ * $criteria->Offset = 20;
+ * </code>
+ *
+ * @author Wei Zhuo <weizho[at]gmail[dot]com>
+ * @version $Id: TDbSqlCriteria.php 1835 2007-04-03 01:38:15Z wei $
+ * @package System.Data.DataGateway
+ * @since 3.1
+ */
+class TSqlCriteria extends TComponent
+{
+ /**
+ * @var mixed
+ * @since 3.1.7
+ */
+ private $_select='*';
+ private $_condition;
+ private $_parameters;
+ private $_ordersBy;
+ private $_limit;
+ private $_offset;
+
+ /**
+ * Creates a new criteria with given condition;
+ * @param string sql string after the WHERE stanza
+ * @param mixed named or indexed parameters, accepts as multiple arguments.
+ */
+ public function __construct($condition=null, $parameters=array())
+ {
+ if(!is_array($parameters) && func_num_args() > 1)
+ $parameters = array_slice(func_get_args(),1);
+ $this->_parameters=new TAttributeCollection;
+ $this->_parameters->setCaseSensitive(true);
+ $this->_parameters->copyFrom((array)$parameters);
+ $this->_ordersBy=new TAttributeCollection;
+ $this->_ordersBy->setCaseSensitive(true);
+
+ $this->setCondition($condition);
+ }
+
+ /**
+ * Gets the field list to be placed after the SELECT in the SQL. Default to '*'
+ * @return mixed
+ * @since 3.1.7
+ */
+ public function getSelect()
+ {
+ return $this->_select;
+ }
+
+ /**
+ * Sets the field list to be placed after the SELECT in the SQL.
+ *
+ * Different behavior depends on type of assigned value
+ * string
+ * usage without modification
+ *
+ * null
+ * will be expanded to full list of quoted table column names (quoting depends on database)
+ *
+ * array
+ * - Column names will be quoted if used as key or value of array
+ * <code>
+ * array('col1', 'col2', 'col2')
+ * // SELECT `col1`, `col2`, `col3` FROM...
+ * </code>
+ *
+ * - Column aliasing
+ * <code>
+ * array('mycol1' => 'col1', 'mycol2' => 'COUNT(*)')
+ * // SELECT `col1` AS mycol1, COUNT(*) AS mycol2 FROM...
+ * </code>
+ *
+ * - NULL and scalar values (strings will be quoted depending on database)
+ * <code>
+ * array('col1' => 'my custom string', 'col2' => 1.0, 'col3' => 'NULL')
+ * // SELECT "my custom string" AS `col1`, 1.0 AS `col2`, NULL AS `col3` FROM...
+ * </code>
+ *
+ * - If the *-wildcard char is used as key or value, add the full list of quoted table column names
+ * <code>
+ * array('col1' => 'NULL', '*')
+ * // SELECT `col1`, `col2`, `col3`, NULL AS `col1` FROM...
+ * </code>
+ *
+ * @param mixed
+ * @since 3.1.7
+ * @see TDbCommandBuilder::getSelectFieldList()
+ */
+ public function setSelect($value)
+ {
+ $this->_select = $value;
+ }
+
+ /**
+ * @return string search conditions.
+ */
+ public function getCondition()
+ {
+ return $this->_condition;
+ }
+
+ /**
+ * Sets the search conditions to be placed after the WHERE clause in the SQL.
+ * @param string search conditions.
+ */
+ public function setCondition($value)
+ {
+ if(empty($value)) {
+ return;
+ }
+
+ // supporting the following SELECT-syntax:
+ // [ORDER BY {col_name | expr | position}
+ // [ASC | DESC], ...]
+ // [LIMIT {[offset,] row_count | row_count OFFSET offset}]
+ // See: http://dev.mysql.com/doc/refman/5.0/en/select.html
+
+ if(preg_match('/ORDER\s+BY\s+(.*?)(?=LIMIT)|ORDER\s+BY\s+(.*?)$/i', $value, $matches) > 0) {
+ // condition contains ORDER BY
+ $value = str_replace($matches[0], '', $value);
+ if(strlen($matches[1]) > 0) {
+ $this->setOrdersBy($matches[1]);
+ } else if(strlen($matches[2]) > 0) {
+ $this->setOrdersBy($matches[2]);
+ }
+ }
+
+ if(preg_match('/LIMIT\s+([\d\s,]+)/i', $value, $matches) > 0) {
+ // condition contains limit
+ $value = str_replace($matches[0], '', $value); // remove limit from query
+ if(strpos($matches[1], ',')) { // both offset and limit given
+ list($offset, $limit) = explode(',', $matches[1]);
+ $this->_limit = (int)$limit;
+ $this->_offset = (int)$offset;
+ } else { // only limit given
+ $this->_limit = (int)$matches[1];
+ }
+ }
+
+ if(preg_match('/OFFSET\s+(\d+)/i', $value, $matches) > 0) {
+ // condition contains offset
+ $value = str_replace($matches[0], '', $value); // remove offset from query
+ $this->_offset = (int)$matches[1]; // set offset in criteria
+ }
+
+ $this->_condition = trim($value);
+ }
+
+ /**
+ * @return TAttributeCollection list of named parameters and values.
+ */
+ public function getParameters()
+ {
+ return $this->_parameters;
+ }
+
+ /**
+ * @param ArrayAccess named parameters.
+ */
+ public function setParameters($value)
+ {
+ if(!(is_array($value) || $value instanceof ArrayAccess))
+ throw new TException('value must be array or ArrayAccess');
+ $this->_parameters->copyFrom($value);
+ }
+
+ /**
+ * @return boolean true if the parameter index are string base, false otherwise.
+ */
+ public function getIsNamedParameters()
+ {
+ foreach($this->getParameters() as $k=>$v)
+ return is_string($k);
+ }
+
+ /**
+ * @return TAttributeCollection ordering clause.
+ */
+ public function getOrdersBy()
+ {
+ return $this->_ordersBy;
+ }
+
+ /**
+ * @param mixed ordering clause.
+ */
+ public function setOrdersBy($value)
+ {
+ if(is_array($value) || $value instanceof Traversable)
+ $this->_ordersBy->copyFrom($value);
+ else
+ {
+ $value=trim(preg_replace('/\s+/',' ',(string)$value));
+ $orderBys=array();
+ foreach(explode(',',$value) as $orderBy)
+ {
+ $vs=explode(' ',trim($orderBy));
+ $orderBys[$vs[0]]=isset($vs[1])?$vs[1]:'asc';
+ }
+ $this->_ordersBy->copyFrom($orderBys);
+ }
+ }
+
+ /**
+ * @return int maximum number of records to return.
+ */
+ public function getLimit()
+ {
+ return $this->_limit;
+ }
+
+ /**
+ * @param int maximum number of records to return.
+ */
+ public function setLimit($value)
+ {
+ $this->_limit=$value;
+ }
+
+ /**
+ * @return int record offset.
+ */
+ public function getOffset()
+ {
+ return $this->_offset;
+ }
+
+ /**
+ * @param int record offset.
+ */
+ public function setOffset($value)
+ {
+ $this->_offset=$value;
+ }
+
+ /**
+ * @return string string representation of the parameters. Useful for debugging.
+ */
+ public function __toString()
+ {
+ $str = '';
+ if(strlen((string)$this->getCondition()) > 0)
+ $str .= '"'.(string)$this->getCondition().'"';
+ $params = array();
+ foreach($this->getParameters() as $k=>$v)
+ $params[] = "{$k} => ${v}";
+ if(count($params) > 0)
+ $str .= ', "'.implode(', ',$params).'"';
+ $orders = array();
+ foreach($this->getOrdersBy() as $k=>$v)
+ $orders[] = "{$k} => ${v}";
+ if(count($orders) > 0)
+ $str .= ', "'.implode(', ',$orders).'"';
+ if($this->_limit !==null)
+ $str .= ', '.$this->_limit;
+ if($this->_offset !== null)
+ $str .= ', '.$this->_offset;
+ return $str;
+ }
+}
?> \ No newline at end of file
diff --git a/framework/Data/DataGateway/TTableGateway.php b/framework/Data/DataGateway/TTableGateway.php
index bdcb391e..c436e0b0 100644
--- a/framework/Data/DataGateway/TTableGateway.php
+++ b/framework/Data/DataGateway/TTableGateway.php
@@ -1,476 +1,476 @@
-<?php
-/**
- * TTableGateway class file.
- *
- * @author Wei Zhuo <weizhuo[at]gmail[dot]com>
- * @link http://www.pradosoft.com/
+<?php
+/**
+ * TTableGateway class file.
+ *
+ * @author Wei Zhuo <weizhuo[at]gmail[dot]com>
+ * @link http://www.pradosoft.com/
* @copyright Copyright &copy; 2005-2012 PradoSoft
- * @license http://www.pradosoft.com/license/
- * @version $Id$
- * @package System.Data.DataGateway
- */
-
-/**
- * Loads the data gateway command builder and sql criteria.
- */
-Prado::using('System.Data.DataGateway.TSqlCriteria');
-Prado::using('System.Data.DataGateway.TDataGatewayCommand');
-
-/**
- * TTableGateway class provides several find methods to get data from the database
- * and update, insert, and delete methods.
- *
- * Each method maps the input parameters into a SQL call and executes the SQL
- * against a database connection. The TTableGateway is stateless
- * (with respect to the data and data objects), as its role is to push data back and forth.
- *
- * Example usage:
- * <code>
- * //create a connection
- * $dsn = 'pgsql:host=localhost;dbname=test';
- * $conn = new TDbConnection($dsn, 'dbuser','dbpass');
- *
- * //create a table gateway for table/view named 'address'
- * $table = new TTableGateway('address', $conn);
- *
- * //insert a new row, returns last insert id (if applicable)
- * $id = $table->insert(array('name'=>'wei', 'phone'=>'111111'));
- *
- * $record1 = $table->findByPk($id); //find inserted record
- *
- * //finds all records, returns an iterator
- * $records = $table->findAll();
- * print_r($records->readAll());
- *
- * //update the row
- * $table->updateByPk($record1, $id);
- * </code>
- *
- * All methods that may return more than one row of data will return an
- * TDbDataReader iterator.
- *
- * The OnCreateCommand event is raised when a command is prepared and parameter
- * binding is completed. The parameter object is a TDataGatewayEventParameter of which the
- * {@link TDataGatewayEventParameter::getCommand Command} property can be
- * inspected to obtain the sql query to be executed.
- *
- * The OnExecuteCommand event is raised when a command is executed and the result
- * from the database was returned. The parameter object is a
- * TDataGatewayResultEventParameter of which the
- * {@link TDataGatewayEventParameter::getResult Result} property contains
- * the data return from the database. The data returned can be changed
- * by setting the {@link TDataGatewayEventParameter::setResult Result} property.
- *
- * <code>
- * $table->OnCreateCommand[] = 'log_it'; //any valid PHP callback statement
- * $table->OnExecuteCommand[] = array($obj, 'method_name'); // calls 'method_name' on $obj
- *
- * function log_it($sender, $param)
- * {
- * var_dump($param); //TDataGatewayEventParameter object.
- * }
- * </code>
- *
- * @author Wei Zhuo <weizho[at]gmail[dot]com>
- * @version $Id$
- * @package System.Data.DataGateway
- * @since 3.1
- */
-class TTableGateway extends TComponent
-{
- private $_command;
- private $_connection;
-
- /**
- * Creates a new generic table gateway for a given table or view name
- * and a database connection.
- * @param string|TDbTableInfo table or view name or table information.
- * @param TDbConnection database connection.
- */
- public function __construct($table,$connection)
- {
- $this->_connection=$connection;
- if(is_string($table))
- $this->setTableName($table);
- else if($table instanceof TDbTableInfo)
- $this->setTableInfo($table);
- else
- throw new TDbException('dbtablegateway_invalid_table_info');
- }
-
- /**
- * @param TDbTableInfo table or view information.
- */
- protected function setTableInfo($tableInfo)
- {
- $builder = $tableInfo->createCommandBuilder($this->getDbConnection());
- $this->initCommandBuilder($builder);
- }
-
- /**
- * Sets up the command builder for the given table.
- * @param string table or view name.
- */
- protected function setTableName($tableName)
- {
- Prado::using('System.Data.Common.TDbMetaData');
- $meta = TDbMetaData::getInstance($this->getDbConnection());
- $this->initCommandBuilder($meta->createCommandBuilder($tableName));
- }
-
- public function getTableInfo()
- {
- return $this->getCommand()->getTableInfo();
- }
-
- public function getTableName()
- {
- return $this->getTableInfo()->getTableName();
- }
-
- /**
- * @param TDbCommandBuilder database specific command builder.
- */
- protected function initCommandBuilder($builder)
- {
- $this->_command = new TDataGatewayCommand($builder);
- $this->_command->OnCreateCommand[] = array($this, 'onCreateCommand');
- $this->_command->OnExecuteCommand[] = array($this, 'onExecuteCommand');
- }
-
- /**
- * Raised when a command is prepared and parameter binding is completed.
- * The parameter object is TDataGatewayEventParameter of which the
- * {@link TDataGatewayEventParameter::getCommand Command} property can be
- * inspected to obtain the sql query to be executed.
- * @param TDataGatewayCommand originator $sender
- * @param TDataGatewayEventParameter
- */
- public function onCreateCommand($sender, $param)
- {
- $this->raiseEvent('OnCreateCommand', $this, $param);
- }
-
- /**
- * Raised when a command is executed and the result from the database was returned.
- * The parameter object is TDataGatewayResultEventParameter of which the
- * {@link TDataGatewayEventParameter::getResult Result} property contains
- * the data return from the database. The data returned can be changed
- * by setting the {@link TDataGatewayEventParameter::setResult Result} property.
- * @param TDataGatewayCommand originator $sender
- * @param TDataGatewayResultEventParameter
- */
- public function onExecuteCommand($sender, $param)
- {
- $this->raiseEvent('OnExecuteCommand', $this, $param);
- }
-
- /**
- * @return TDataGatewayCommand command builder and executor.
- */
- protected function getCommand()
- {
- return $this->_command;
- }
-
- /**
- * @return TDbConnection database connection.
- */
- public function getDbConnection()
- {
- return $this->_connection;
- }
-
- /**
- * Execute arbituary sql command with binding parameters.
- * @param string SQL query string.
- * @param array binding parameters, positional or named.
- * @return array query results.
- */
- public function findBySql($sql, $parameters=array())
- {
- $args = func_num_args() > 1 ? array_slice(func_get_args(),1) : null;
- $criteria = $this->getCriteria($sql,$parameters, $args);
- return $this->getCommand()->findBySql($criteria);
- }
-
- /**
- * Execute arbituary sql command with binding parameters.
- * @param string SQL query string.
- * @param array binding parameters, positional or named.
- * @return TDbDataReader query results.
- */
- public function findAllBySql($sql, $parameters=array())
- {
- $args = func_num_args() > 1 ? array_slice(func_get_args(),1) : null;
- $criteria = $this->getCriteria($sql,$parameters, $args);
- return $this->getCommand()->findAllBySql($criteria);
- }
-
- /**
- * Find one single record that matches the criteria.
- *
- * Usage:
- * <code>
- * $table->find('username = :name AND password = :pass',
- * array(':name'=>$name, ':pass'=>$pass));
- * $table->find('username = ? AND password = ?', array($name, $pass));
- * $table->find('username = ? AND password = ?', $name, $pass);
- * //$criteria is of TSqlCriteria
- * $table->find($criteria); //the 2nd parameter for find() is ignored.
- * </code>
- *
- * @param string|TSqlCriteria SQL condition or criteria object.
- * @param mixed parameter values.
- * @return array matching record object.
- */
- public function find($criteria, $parameters=array())
- {
- $args = func_num_args() > 1 ? array_slice(func_get_args(),1) : null;
- $criteria = $this->getCriteria($criteria,$parameters, $args);
- return $this->getCommand()->find($criteria);
- }
-
- /**
- * Accepts same parameters as find(), but returns TDbDataReader instead.
- * @param string|TSqlCriteria SQL condition or criteria object.
- * @param mixed parameter values.
- * @return TDbDataReader matching records.
- */
- public function findAll($criteria=null, $parameters=array())
- {
- $args = func_num_args() > 1 ? array_slice(func_get_args(),1) : null;
- if($criteria!==null)
- $criteria = $this->getCriteria($criteria,$parameters, $args);
- return $this->getCommand()->findAll($criteria);
- }
-
- /**
- * Find one record using only the primary key or composite primary keys. Usage:
- *
- * <code>
- * $table->findByPk($primaryKey);
- * $table->findByPk($key1, $key2, ...);
- * $table->findByPk(array($key1,$key2,...));
- * </code>
- *
- * @param mixed primary keys
- * @return array matching record.
- */
- public function findByPk($keys)
- {
- if(func_num_args() > 1)
- $keys = func_get_args();
- return $this->getCommand()->findByPk($keys);
- }
-
- /**
- * Similar to findByPk(), but returns TDbDataReader instead.
- *
- * For scalar primary keys:
- * <code>
- * $table->findAllByPk($key1, $key2, ...);
- * $table->findAllByPk(array($key1, $key2, ...));
- * </code>
- *
- * For composite keys:
- * <code>
- * $table->findAllByPk(array($key1, $key2), array($key3, $key4), ...);
- * $table->findAllByPk(array(array($key1, $key2), array($key3, $key4), ...));
- * </code>
- * @param mixed primary keys
- * @return TDbDataReader data reader.
- */
- public function findAllByPks($keys)
- {
- if(func_num_args() > 1)
- $keys = func_get_args();
- return $this->getCommand()->findAllByPk($keys);
- }
-
- /**
- * Delete records from the table with condition given by $where and
- * binding values specified by $parameter argument.
- * This method uses additional arguments as $parameters. E.g.
- * <code>
- * $table->delete('age > ? AND location = ?', $age, $location);
- * </code>
- * @param string delete condition.
- * @param array condition parameters.
- * @return integer number of records deleted.
- */
- public function deleteAll($criteria, $parameters=array())
- {
- $args = func_num_args() > 1 ? array_slice(func_get_args(),1) : null;
- $criteria = $this->getCriteria($criteria,$parameters, $args);
- return $this->getCommand()->delete($criteria);
- }
-
- /**
- * Delete records by primary key. Usage:
- *
- * <code>
- * $table->deleteByPk($primaryKey); //delete 1 record
- * $table->deleteByPk($key1,$key2,...); //delete multiple records
- * $table->deleteByPk(array($key1,$key2,...)); //delete multiple records
- * </code>
- *
- * For composite primary keys (determined from the table definitions):
- * <code>
- * $table->deleteByPk(array($key1,$key2)); //delete 1 record
- *
- * //delete multiple records
- * $table->deleteByPk(array($key1,$key2), array($key3,$key4),...);
- *
- * //delete multiple records
- * $table->deleteByPk(array( array($key1,$key2), array($key3,$key4), .. ));
- * </code>
- *
- * @param mixed primary key values.
- * @return int number of records deleted.
- */
- public function deleteByPk($keys)
- {
- if(func_num_args() > 1)
- $keys = func_get_args();
- return $this->getCommand()->deleteByPk($keys);
- }
-
- /**
- * Alias for deleteByPk()
- */
- public function deleteAllByPks($keys)
- {
- if(func_num_args() > 1)
- $keys = func_get_args();
- return $this->deleteByPk($keys);
- }
-
- /**
- * Find the number of records.
- * @param string|TSqlCriteria SQL condition or criteria object.
- * @param mixed parameter values.
- * @return int number of records.
- */
- public function count($criteria=null,$parameters=array())
- {
- $args = func_num_args() > 1 ? array_slice(func_get_args(),1) : null;
- if($criteria!==null)
- $criteria = $this->getCriteria($criteria,$parameters, $args);
- return $this->getCommand()->count($criteria);
- }
-
- /**
- * Updates the table with new name-value pair $data. Each array key must
- * correspond to a column name in the table. The update condition is
- * specified by the $where argument and additional binding values can be
- * specified using the $parameter argument.
- * This method uses additional arguments as $parameters. E.g.
- * <code>
- * $gateway->update($data, 'age > ? AND location = ?', $age, $location);
- * </code>
- * @param array new record data.
- * @param string update condition
- * @param array additional binding name-value pairs.
- * @return integer number of records updated.
- */
- public function update($data, $criteria, $parameters=array())
- {
- $args = func_num_args() > 2 ? array_slice(func_get_args(),2) : null;
- $criteria = $this->getCriteria($criteria,$parameters, $args);
- return $this->getCommand()->update($data, $criteria);
- }
-
- /**
- * Inserts a new record into the table. Each array key must
- * correspond to a column name in the table unless a null value is permitted.
- * @param array new record data.
- * @return mixed last insert id if one column contains a serial or sequence,
- * otherwise true if command executes successfully and affected 1 or more rows.
- */
- public function insert($data)
- {
- return $this->getCommand()->insert($data);
- }
-
- /**
- * @return mixed last insert id, null if none is found.
- */
- public function getLastInsertId()
- {
- return $this->getCommand()->getLastInsertId();
- }
-
- /**
- * Create a new TSqlCriteria object from a string $criteria. The $args
- * are additional parameters and are used in place of the $parameters
- * if $parameters is not an array and $args is an arrary.
- * @param string|TSqlCriteria sql criteria
- * @param mixed parameters passed by the user.
- * @param array additional parameters obtained from function_get_args().
- * @return TSqlCriteria criteria object.
- */
- protected function getCriteria($criteria, $parameters, $args)
- {
- if(is_string($criteria))
- {
- $useArgs = !is_array($parameters) && is_array($args);
- return new TSqlCriteria($criteria,$useArgs ? $args : $parameters);
- }
- else if($criteria instanceof TSqlCriteria)
- return $criteria;
- else
- throw new TDbException('dbtablegateway_invalid_criteria');
- }
-
- /**
- * Dynamic find method using parts of method name as search criteria.
- * Method name starting with "findBy" only returns 1 record.
- * Method name starting with "findAllBy" returns 0 or more records.
- * Method name starting with "deleteBy" deletes records by the trail criteria.
- * The condition is taken as part of the method name after "findBy", "findAllBy"
- * or "deleteBy".
- *
- * The following are equivalent:
- * <code>
- * $table->findByName($name)
- * $table->find('Name = ?', $name);
- * </code>
- * <code>
- * $table->findByUsernameAndPassword($name,$pass); // OR may be used
- * $table->findBy_Username_And_Password($name,$pass); // _OR_ may be used
- * $table->find('Username = ? AND Password = ?', $name, $pass);
- * </code>
- * <code>
- * $table->findAllByAge($age);
- * $table->findAll('Age = ?', $age);
- * </code>
- * <code>
- * $table->deleteAll('Name = ?', $name);
- * $table->deleteByName($name);
- * </code>
- * @return mixed single record if method name starts with "findBy", 0 or more records
- * if method name starts with "findAllBy"
- */
- public function __call($method,$args)
- {
- $delete =false;
- if($findOne = substr(strtolower($method),0,6)==='findby')
- $condition = $method[6]==='_' ? substr($method,7) : substr($method,6);
- else if(substr(strtolower($method),0,9)==='findallby')
- $condition = $method[9]==='_' ? substr($method,10) : substr($method,9);
- else if($delete = substr(strtolower($method),0,8)==='deleteby')
- $condition = $method[8]==='_' ? substr($method,9) : substr($method,8);
- else if($delete = substr(strtolower($method),0,11)==='deleteallby')
- $condition = $method[11]==='_' ? substr($method,12) : substr($method,11);
- else
- return null;
-
- $criteria = $this->getCommand()->createCriteriaFromString($method, $condition, $args);
- if($delete)
- return $this->deleteAll($criteria);
- else
- return $findOne ? $this->find($criteria) : $this->findAll($criteria);
- }
-}
+ * @license http://www.pradosoft.com/license/
+ * @version $Id$
+ * @package System.Data.DataGateway
+ */
+
+/**
+ * Loads the data gateway command builder and sql criteria.
+ */
+Prado::using('System.Data.DataGateway.TSqlCriteria');
+Prado::using('System.Data.DataGateway.TDataGatewayCommand');
+
+/**
+ * TTableGateway class provides several find methods to get data from the database
+ * and update, insert, and delete methods.
+ *
+ * Each method maps the input parameters into a SQL call and executes the SQL
+ * against a database connection. The TTableGateway is stateless
+ * (with respect to the data and data objects), as its role is to push data back and forth.
+ *
+ * Example usage:
+ * <code>
+ * //create a connection
+ * $dsn = 'pgsql:host=localhost;dbname=test';
+ * $conn = new TDbConnection($dsn, 'dbuser','dbpass');
+ *
+ * //create a table gateway for table/view named 'address'
+ * $table = new TTableGateway('address', $conn);
+ *
+ * //insert a new row, returns last insert id (if applicable)
+ * $id = $table->insert(array('name'=>'wei', 'phone'=>'111111'));
+ *
+ * $record1 = $table->findByPk($id); //find inserted record
+ *
+ * //finds all records, returns an iterator
+ * $records = $table->findAll();
+ * print_r($records->readAll());
+ *
+ * //update the row
+ * $table->updateByPk($record1, $id);
+ * </code>
+ *
+ * All methods that may return more than one row of data will return an
+ * TDbDataReader iterator.
+ *
+ * The OnCreateCommand event is raised when a command is prepared and parameter
+ * binding is completed. The parameter object is a TDataGatewayEventParameter of which the
+ * {@link TDataGatewayEventParameter::getCommand Command} property can be
+ * inspected to obtain the sql query to be executed.
+ *
+ * The OnExecuteCommand event is raised when a command is executed and the result
+ * from the database was returned. The parameter object is a
+ * TDataGatewayResultEventParameter of which the
+ * {@link TDataGatewayEventParameter::getResult Result} property contains
+ * the data return from the database. The data returned can be changed
+ * by setting the {@link TDataGatewayEventParameter::setResult Result} property.
+ *
+ * <code>
+ * $table->OnCreateCommand[] = 'log_it'; //any valid PHP callback statement
+ * $table->OnExecuteCommand[] = array($obj, 'method_name'); // calls 'method_name' on $obj
+ *
+ * function log_it($sender, $param)
+ * {
+ * var_dump($param); //TDataGatewayEventParameter object.
+ * }
+ * </code>
+ *
+ * @author Wei Zhuo <weizho[at]gmail[dot]com>
+ * @version $Id$
+ * @package System.Data.DataGateway
+ * @since 3.1
+ */
+class TTableGateway extends TComponent
+{
+ private $_command;
+ private $_connection;
+
+ /**
+ * Creates a new generic table gateway for a given table or view name
+ * and a database connection.
+ * @param string|TDbTableInfo table or view name or table information.
+ * @param TDbConnection database connection.
+ */
+ public function __construct($table,$connection)
+ {
+ $this->_connection=$connection;
+ if(is_string($table))
+ $this->setTableName($table);
+ else if($table instanceof TDbTableInfo)
+ $this->setTableInfo($table);
+ else
+ throw new TDbException('dbtablegateway_invalid_table_info');
+ }
+
+ /**
+ * @param TDbTableInfo table or view information.
+ */
+ protected function setTableInfo($tableInfo)
+ {
+ $builder = $tableInfo->createCommandBuilder($this->getDbConnection());
+ $this->initCommandBuilder($builder);
+ }
+
+ /**
+ * Sets up the command builder for the given table.
+ * @param string table or view name.
+ */
+ protected function setTableName($tableName)
+ {
+ Prado::using('System.Data.Common.TDbMetaData');
+ $meta = TDbMetaData::getInstance($this->getDbConnection());
+ $this->initCommandBuilder($meta->createCommandBuilder($tableName));
+ }
+
+ public function getTableInfo()
+ {
+ return $this->getCommand()->getTableInfo();
+ }
+
+ public function getTableName()
+ {
+ return $this->getTableInfo()->getTableName();
+ }
+
+ /**
+ * @param TDbCommandBuilder database specific command builder.
+ */
+ protected function initCommandBuilder($builder)
+ {
+ $this->_command = new TDataGatewayCommand($builder);
+ $this->_command->OnCreateCommand[] = array($this, 'onCreateCommand');
+ $this->_command->OnExecuteCommand[] = array($this, 'onExecuteCommand');
+ }
+
+ /**
+ * Raised when a command is prepared and parameter binding is completed.
+ * The parameter object is TDataGatewayEventParameter of which the
+ * {@link TDataGatewayEventParameter::getCommand Command} property can be
+ * inspected to obtain the sql query to be executed.
+ * @param TDataGatewayCommand originator $sender
+ * @param TDataGatewayEventParameter
+ */
+ public function onCreateCommand($sender, $param)
+ {
+ $this->raiseEvent('OnCreateCommand', $this, $param);
+ }
+
+ /**
+ * Raised when a command is executed and the result from the database was returned.
+ * The parameter object is TDataGatewayResultEventParameter of which the
+ * {@link TDataGatewayEventParameter::getResult Result} property contains
+ * the data return from the database. The data returned can be changed
+ * by setting the {@link TDataGatewayEventParameter::setResult Result} property.
+ * @param TDataGatewayCommand originator $sender
+ * @param TDataGatewayResultEventParameter
+ */
+ public function onExecuteCommand($sender, $param)
+ {
+ $this->raiseEvent('OnExecuteCommand', $this, $param);
+ }
+
+ /**
+ * @return TDataGatewayCommand command builder and executor.
+ */
+ protected function getCommand()
+ {
+ return $this->_command;
+ }
+
+ /**
+ * @return TDbConnection database connection.
+ */
+ public function getDbConnection()
+ {
+ return $this->_connection;
+ }
+
+ /**
+ * Execute arbituary sql command with binding parameters.
+ * @param string SQL query string.
+ * @param array binding parameters, positional or named.
+ * @return array query results.
+ */
+ public function findBySql($sql, $parameters=array())
+ {
+ $args = func_num_args() > 1 ? array_slice(func_get_args(),1) : null;
+ $criteria = $this->getCriteria($sql,$parameters, $args);
+ return $this->getCommand()->findBySql($criteria);
+ }
+
+ /**
+ * Execute arbituary sql command with binding parameters.
+ * @param string SQL query string.
+ * @param array binding parameters, positional or named.
+ * @return TDbDataReader query results.
+ */
+ public function findAllBySql($sql, $parameters=array())
+ {
+ $args = func_num_args() > 1 ? array_slice(func_get_args(),1) : null;
+ $criteria = $this->getCriteria($sql,$parameters, $args);
+ return $this->getCommand()->findAllBySql($criteria);
+ }
+
+ /**
+ * Find one single record that matches the criteria.
+ *
+ * Usage:
+ * <code>
+ * $table->find('username = :name AND password = :pass',
+ * array(':name'=>$name, ':pass'=>$pass));
+ * $table->find('username = ? AND password = ?', array($name, $pass));
+ * $table->find('username = ? AND password = ?', $name, $pass);
+ * //$criteria is of TSqlCriteria
+ * $table->find($criteria); //the 2nd parameter for find() is ignored.
+ * </code>
+ *
+ * @param string|TSqlCriteria SQL condition or criteria object.
+ * @param mixed parameter values.
+ * @return array matching record object.
+ */
+ public function find($criteria, $parameters=array())
+ {
+ $args = func_num_args() > 1 ? array_slice(func_get_args(),1) : null;
+ $criteria = $this->getCriteria($criteria,$parameters, $args);
+ return $this->getCommand()->find($criteria);
+ }
+
+ /**
+ * Accepts same parameters as find(), but returns TDbDataReader instead.
+ * @param string|TSqlCriteria SQL condition or criteria object.
+ * @param mixed parameter values.
+ * @return TDbDataReader matching records.
+ */
+ public function findAll($criteria=null, $parameters=array())
+ {
+ $args = func_num_args() > 1 ? array_slice(func_get_args(),1) : null;
+ if($criteria!==null)
+ $criteria = $this->getCriteria($criteria,$parameters, $args);
+ return $this->getCommand()->findAll($criteria);
+ }
+
+ /**
+ * Find one record using only the primary key or composite primary keys. Usage:
+ *
+ * <code>
+ * $table->findByPk($primaryKey);
+ * $table->findByPk($key1, $key2, ...);
+ * $table->findByPk(array($key1,$key2,...));
+ * </code>
+ *
+ * @param mixed primary keys
+ * @return array matching record.
+ */
+ public function findByPk($keys)
+ {
+ if(func_num_args() > 1)
+ $keys = func_get_args();
+ return $this->getCommand()->findByPk($keys);
+ }
+
+ /**
+ * Similar to findByPk(), but returns TDbDataReader instead.
+ *
+ * For scalar primary keys:
+ * <code>
+ * $table->findAllByPk($key1, $key2, ...);
+ * $table->findAllByPk(array($key1, $key2, ...));
+ * </code>
+ *
+ * For composite keys:
+ * <code>
+ * $table->findAllByPk(array($key1, $key2), array($key3, $key4), ...);
+ * $table->findAllByPk(array(array($key1, $key2), array($key3, $key4), ...));
+ * </code>
+ * @param mixed primary keys
+ * @return TDbDataReader data reader.
+ */
+ public function findAllByPks($keys)
+ {
+ if(func_num_args() > 1)
+ $keys = func_get_args();
+ return $this->getCommand()->findAllByPk($keys);
+ }
+
+ /**
+ * Delete records from the table with condition given by $where and
+ * binding values specified by $parameter argument.
+ * This method uses additional arguments as $parameters. E.g.
+ * <code>
+ * $table->delete('age > ? AND location = ?', $age, $location);
+ * </code>
+ * @param string delete condition.
+ * @param array condition parameters.
+ * @return integer number of records deleted.
+ */
+ public function deleteAll($criteria, $parameters=array())
+ {
+ $args = func_num_args() > 1 ? array_slice(func_get_args(),1) : null;
+ $criteria = $this->getCriteria($criteria,$parameters, $args);
+ return $this->getCommand()->delete($criteria);
+ }
+
+ /**
+ * Delete records by primary key. Usage:
+ *
+ * <code>
+ * $table->deleteByPk($primaryKey); //delete 1 record
+ * $table->deleteByPk($key1,$key2,...); //delete multiple records
+ * $table->deleteByPk(array($key1,$key2,...)); //delete multiple records
+ * </code>
+ *
+ * For composite primary keys (determined from the table definitions):
+ * <code>
+ * $table->deleteByPk(array($key1,$key2)); //delete 1 record
+ *
+ * //delete multiple records
+ * $table->deleteByPk(array($key1,$key2), array($key3,$key4),...);
+ *
+ * //delete multiple records
+ * $table->deleteByPk(array( array($key1,$key2), array($key3,$key4), .. ));
+ * </code>
+ *
+ * @param mixed primary key values.
+ * @return int number of records deleted.
+ */
+ public function deleteByPk($keys)
+ {
+ if(func_num_args() > 1)
+ $keys = func_get_args();
+ return $this->getCommand()->deleteByPk($keys);
+ }
+
+ /**
+ * Alias for deleteByPk()
+ */
+ public function deleteAllByPks($keys)
+ {
+ if(func_num_args() > 1)
+ $keys = func_get_args();
+ return $this->deleteByPk($keys);
+ }
+
+ /**
+ * Find the number of records.
+ * @param string|TSqlCriteria SQL condition or criteria object.
+ * @param mixed parameter values.
+ * @return int number of records.
+ */
+ public function count($criteria=null,$parameters=array())
+ {
+ $args = func_num_args() > 1 ? array_slice(func_get_args(),1) : null;
+ if($criteria!==null)
+ $criteria = $this->getCriteria($criteria,$parameters, $args);
+ return $this->getCommand()->count($criteria);
+ }
+
+ /**
+ * Updates the table with new name-value pair $data. Each array key must
+ * correspond to a column name in the table. The update condition is
+ * specified by the $where argument and additional binding values can be
+ * specified using the $parameter argument.
+ * This method uses additional arguments as $parameters. E.g.
+ * <code>
+ * $gateway->update($data, 'age > ? AND location = ?', $age, $location);
+ * </code>
+ * @param array new record data.
+ * @param string update condition
+ * @param array additional binding name-value pairs.
+ * @return integer number of records updated.
+ */
+ public function update($data, $criteria, $parameters=array())
+ {
+ $args = func_num_args() > 2 ? array_slice(func_get_args(),2) : null;
+ $criteria = $this->getCriteria($criteria,$parameters, $args);
+ return $this->getCommand()->update($data, $criteria);
+ }
+
+ /**
+ * Inserts a new record into the table. Each array key must
+ * correspond to a column name in the table unless a null value is permitted.
+ * @param array new record data.
+ * @return mixed last insert id if one column contains a serial or sequence,
+ * otherwise true if command executes successfully and affected 1 or more rows.
+ */
+ public function insert($data)
+ {
+ return $this->getCommand()->insert($data);
+ }
+
+ /**
+ * @return mixed last insert id, null if none is found.
+ */
+ public function getLastInsertId()
+ {
+ return $this->getCommand()->getLastInsertId();
+ }
+
+ /**
+ * Create a new TSqlCriteria object from a string $criteria. The $args
+ * are additional parameters and are used in place of the $parameters
+ * if $parameters is not an array and $args is an arrary.
+ * @param string|TSqlCriteria sql criteria
+ * @param mixed parameters passed by the user.
+ * @param array additional parameters obtained from function_get_args().
+ * @return TSqlCriteria criteria object.
+ */
+ protected function getCriteria($criteria, $parameters, $args)
+ {
+ if(is_string($criteria))
+ {
+ $useArgs = !is_array($parameters) && is_array($args);
+ return new TSqlCriteria($criteria,$useArgs ? $args : $parameters);
+ }
+ else if($criteria instanceof TSqlCriteria)
+ return $criteria;
+ else
+ throw new TDbException('dbtablegateway_invalid_criteria');
+ }
+
+ /**
+ * Dynamic find method using parts of method name as search criteria.
+ * Method name starting with "findBy" only returns 1 record.
+ * Method name starting with "findAllBy" returns 0 or more records.
+ * Method name starting with "deleteBy" deletes records by the trail criteria.
+ * The condition is taken as part of the method name after "findBy", "findAllBy"
+ * or "deleteBy".
+ *
+ * The following are equivalent:
+ * <code>
+ * $table->findByName($name)
+ * $table->find('Name = ?', $name);
+ * </code>
+ * <code>
+ * $table->findByUsernameAndPassword($name,$pass); // OR may be used
+ * $table->findBy_Username_And_Password($name,$pass); // _OR_ may be used
+ * $table->find('Username = ? AND Password = ?', $name, $pass);
+ * </code>
+ * <code>
+ * $table->findAllByAge($age);
+ * $table->findAll('Age = ?', $age);
+ * </code>
+ * <code>
+ * $table->deleteAll('Name = ?', $name);
+ * $table->deleteByName($name);
+ * </code>
+ * @return mixed single record if method name starts with "findBy", 0 or more records
+ * if method name starts with "findAllBy"
+ */
+ public function __call($method,$args)
+ {
+ $delete =false;
+ if($findOne = substr(strtolower($method),0,6)==='findby')
+ $condition = $method[6]==='_' ? substr($method,7) : substr($method,6);
+ else if(substr(strtolower($method),0,9)==='findallby')
+ $condition = $method[9]==='_' ? substr($method,10) : substr($method,9);
+ else if($delete = substr(strtolower($method),0,8)==='deleteby')
+ $condition = $method[8]==='_' ? substr($method,9) : substr($method,8);
+ else if($delete = substr(strtolower($method),0,11)==='deleteallby')
+ $condition = $method[11]==='_' ? substr($method,12) : substr($method,11);
+ else
+ return null;
+
+ $criteria = $this->getCommand()->createCriteriaFromString($method, $condition, $args);
+ if($delete)
+ return $this->deleteAll($criteria);
+ else
+ return $findOne ? $this->find($criteria) : $this->findAll($criteria);
+ }
+}
diff --git a/framework/Data/SqlMap/Configuration/TDiscriminator.php b/framework/Data/SqlMap/Configuration/TDiscriminator.php
index cbc05612..f0c9187b 100644
--- a/framework/Data/SqlMap/Configuration/TDiscriminator.php
+++ b/framework/Data/SqlMap/Configuration/TDiscriminator.php
@@ -1,232 +1,232 @@
-<?php
-/**
- * TDiscriminator and TSubMap classes file.
- *
- * @author Wei Zhuo <weizhuo[at]gmail[dot]com>
- * @link http://www.pradosoft.com/
+<?php
+/**
+ * TDiscriminator and TSubMap classes file.
+ *
+ * @author Wei Zhuo <weizhuo[at]gmail[dot]com>
+ * @link http://www.pradosoft.com/
* @copyright Copyright &copy; 2005-2012 PradoSoft
- * @license http://www.pradosoft.com/license/
- * @version $Id$
- * @package System.Data.SqlMap.Configuration
- */
-
-/**
- * The TDiscriminator corresponds to the <discriminator> tag within a <resultMap>.
- *
- * TDiscriminator allows inheritance logic in SqlMap result mappings.
- * SqlMap compares the data found in the discriminator column to the different
- * <submap> values using the column value's string equivalence. When the string values
- * matches a particular <submap>, SqlMap will use the <resultMap> defined by
- * {@link resultMapping TSubMap::setResultMapping()} property for loading
- * the object data.
- *
- * @author Wei Zhuo <weizho[at]gmail[dot]com>
- * @version $Id$
- * @package System.Data.SqlMap.Configuration
- * @since 3.1
- */
-class TDiscriminator extends TComponent
-{
- private $_column;
- private $_type;
- private $_typeHandler=null;
- private $_columnIndex;
- private $_nullValue;
- private $_mapping;
- private $_resultMaps=array();
- private $_subMaps=array();
-
- /**
- * @return string the name of the column in the result set from which the
- * value will be used to populate the property.
- */
- public function getColumn()
- {
- return $this->_column;
- }
-
- /**
- * @param string the name of the column in the result set from which the
- * value will be used to populate the property.
- */
- public function setColumn($value)
- {
- $this->_column = $value;
- }
-
- /**
- * @param string property type of the parameter to be set.
- */
- public function getType()
- {
- return $this->_type;
- }
-
- /**
- * The type attribute is used to explicitly specify the property type of the
- * parameter to be set. If the attribute type is not set and the framework
- * cannot otherwise determine the type, the type is assumed from the default
- * value of the property.
- * @return string property type of the parameter to be set.
- */
- public function setType($value)
- {
- $this->_type = $value;
- }
-
- /**
- * @return string custom type handler class name (may use namespace).
- */
- public function getTypeHandler()
- {
- return $this->_typeHandler;
- }
-
- /**
- * @param string custom type handler class name (may use namespace).
- */
- public function setTypeHandler($value)
- {
- $this->_typeHandler = $value;
- }
-
- /**
- * @return int index of the column in the ResultSet
- */
- public function getColumnIndex()
- {
- return $this->_columnIndex;
- }
-
- /**
- * The columnIndex attribute value is the index of the column in the
- * ResultSet from which the value will be used to populate the object property.
- * @param int index of the column in the ResultSet
- */
- public function setColumnIndex($value)
- {
- $this->_columnIndex = TPropertyValue::ensureInteger($value);
- }
-
- /**
- * @return mixed outgoing null value replacement.
- */
- public function getNullValue()
- {
- return $this->_nullValue;
- }
-
- /**
- * @param mixed outgoing null value replacement.
- */
- public function setNullValue($value)
- {
- $this->_nullValue = $value;
- }
-
- /**
- * @return TResultProperty result property for the discriminator column.
- */
- public function getMapping()
- {
- return $this->_mapping;
- }
-
- /**
- * @param TSubMap add new sub mapping.
- */
- public function addSubMap($subMap)
- {
- $this->_subMaps[] = $subMap;
- }
-
- /**
- * @param string database value
- * @return TResultMap result mapping.
- */
- public function getSubMap($value)
- {
- if(isset($this->_resultMaps[$value]))
- return $this->_resultMaps[$value];
- }
-
- /**
- * Copies the discriminator properties to a new TResultProperty.
- * @param TResultMap result map holding the discriminator.
- */
- public function initMapping($resultMap)
- {
- $this->_mapping = new TResultProperty($resultMap);
- $this->_mapping->setColumn($this->getColumn());
- $this->_mapping->setColumnIndex($this->getColumnIndex());
- $this->_mapping->setType($this->getType());
- $this->_mapping->setTypeHandler($this->getTypeHandler());
- $this->_mapping->setNullValue($this->getNullValue());
- }
-
- /**
- * Set the result maps for particular sub-mapping values.
- * @param TSqlMapManager sql map manager instance.
- */
- public function initialize($manager)
- {
- foreach($this->_subMaps as $subMap)
- {
- $this->_resultMaps[$subMap->getValue()] =
- $manager->getResultMap($subMap->getResultMapping());
- }
- }
-}
-
-/**
- * TSubMap class defines a submapping value and the corresponding <resultMap>
- *
- * The {@link Value setValue()} property is used for comparison with the
- * discriminator column value. When the {@link Value setValue()} matches
- * that of the discriminator column value, the corresponding {@link ResultMapping setResultMapping}
- * is used inplace of the current result map.
- *
- * @author Wei Zhuo <weizho[at]gmail[dot]com>
- * @version $Id$
- * @package System.Data.SqlMap.Configuration
- * @since 3.1
- */
-class TSubMap extends TComponent
-{
- private $_value;
- private $_resultMapping;
-
- /**
- * @return string value for comparison with discriminator column value.
- */
- public function getValue()
- {
- return $this->_value;
- }
-
- /**
- * @param string value for comparison with discriminator column value.
- */
- public function setValue($value)
- {
- $this->_value = $value;
- }
-
- /**
- * The result map to use when the Value matches the discriminator column value.
- * @return string ID of a result map
- */
- public function getResultMapping()
- {
- return $this->_resultMapping;
- }
-
- /**
- * @param string ID of a result map
- */
- public function setResultMapping($value)
- {
- $this->_resultMapping = $value;
- }
-}
-
+ * @license http://www.pradosoft.com/license/
+ * @version $Id$
+ * @package System.Data.SqlMap.Configuration
+ */
+
+/**
+ * The TDiscriminator corresponds to the <discriminator> tag within a <resultMap>.
+ *
+ * TDiscriminator allows inheritance logic in SqlMap result mappings.
+ * SqlMap compares the data found in the discriminator column to the different
+ * <submap> values using the column value's string equivalence. When the string values
+ * matches a particular <submap>, SqlMap will use the <resultMap> defined by
+ * {@link resultMapping TSubMap::setResultMapping()} property for loading
+ * the object data.
+ *
+ * @author Wei Zhuo <weizho[at]gmail[dot]com>
+ * @version $Id$
+ * @package System.Data.SqlMap.Configuration
+ * @since 3.1
+ */
+class TDiscriminator extends TComponent
+{
+ private $_column;
+ private $_type;
+ private $_typeHandler=null;
+ private $_columnIndex;
+ private $_nullValue;
+ private $_mapping;
+ private $_resultMaps=array();
+ private $_subMaps=array();
+
+ /**
+ * @return string the name of the column in the result set from which the
+ * value will be used to populate the property.
+ */
+ public function getColumn()
+ {
+ return $this->_column;
+ }
+
+ /**
+ * @param string the name of the column in the result set from which the
+ * value will be used to populate the property.
+ */
+ public function setColumn($value)
+ {
+ $this->_column = $value;
+ }
+
+ /**
+ * @param string property type of the parameter to be set.
+ */
+ public function getType()
+ {
+ return $this->_type;
+ }
+
+ /**
+ * The type attribute is used to explicitly specify the property type of the
+ * parameter to be set. If the attribute type is not set and the framework
+ * cannot otherwise determine the type, the type is assumed from the default
+ * value of the property.
+ * @return string property type of the parameter to be set.
+ */
+ public function setType($value)
+ {
+ $this->_type = $value;
+ }
+
+ /**
+ * @return string custom type handler class name (may use namespace).
+ */
+ public function getTypeHandler()
+ {
+ return $this->_typeHandler;
+ }
+
+ /**
+ * @param string custom type handler class name (may use namespace).
+ */
+ public function setTypeHandler($value)
+ {
+ $this->_typeHandler = $value;
+ }
+
+ /**
+ * @return int index of the column in the ResultSet
+ */
+ public function getColumnIndex()
+ {
+ return $this->_columnIndex;
+ }
+
+ /**
+ * The columnIndex attribute value is the index of the column in the
+ * ResultSet from which the value will be used to populate the object property.
+ * @param int index of the column in the ResultSet
+ */
+ public function setColumnIndex($value)
+ {
+ $this->_columnIndex = TPropertyValue::ensureInteger($value);
+ }
+
+ /**
+ * @return mixed outgoing null value replacement.
+ */
+ public function getNullValue()
+ {
+ return $this->_nullValue;
+ }
+
+ /**
+ * @param mixed outgoing null value replacement.
+ */
+ public function setNullValue($value)
+ {
+ $this->_nullValue = $value;
+ }
+
+ /**
+ * @return TResultProperty result property for the discriminator column.
+ */
+ public function getMapping()
+ {
+ return $this->_mapping;
+ }
+
+ /**
+ * @param TSubMap add new sub mapping.
+ */
+ public function addSubMap($subMap)
+ {
+ $this->_subMaps[] = $subMap;
+ }
+
+ /**
+ * @param string database value
+ * @return TResultMap result mapping.
+ */
+ public function getSubMap($value)
+ {
+ if(isset($this->_resultMaps[$value]))
+ return $this->_resultMaps[$value];
+ }
+
+ /**
+ * Copies the discriminator properties to a new TResultProperty.
+ * @param TResultMap result map holding the discriminator.
+ */
+ public function initMapping($resultMap)
+ {
+ $this->_mapping = new TResultProperty($resultMap);
+ $this->_mapping->setColumn($this->getColumn());
+ $this->_mapping->setColumnIndex($this->getColumnIndex());
+ $this->_mapping->setType($this->getType());
+ $this->_mapping->setTypeHandler($this->getTypeHandler());
+ $this->_mapping->setNullValue($this->getNullValue());
+ }
+
+ /**
+ * Set the result maps for particular sub-mapping values.
+ * @param TSqlMapManager sql map manager instance.
+ */
+ public function initialize($manager)
+ {
+ foreach($this->_subMaps as $subMap)
+ {
+ $this->_resultMaps[$subMap->getValue()] =
+ $manager->getResultMap($subMap->getResultMapping());
+ }
+ }
+}
+
+/**
+ * TSubMap class defines a submapping value and the corresponding <resultMap>
+ *
+ * The {@link Value setValue()} property is used for comparison with the
+ * discriminator column value. When the {@link Value setValue()} matches
+ * that of the discriminator column value, the corresponding {@link ResultMapping setResultMapping}
+ * is used inplace of the current result map.
+ *
+ * @author Wei Zhuo <weizho[at]gmail[dot]com>
+ * @version $Id$
+ * @package System.Data.SqlMap.Configuration
+ * @since 3.1
+ */
+class TSubMap extends TComponent
+{
+ private $_value;
+ private $_resultMapping;
+
+ /**
+ * @return string value for comparison with discriminator column value.
+ */
+ public function getValue()
+ {
+ return $this->_value;
+ }
+
+ /**
+ * @param string value for comparison with discriminator column value.
+ */
+ public function setValue($value)
+ {
+ $this->_value = $value;
+ }
+
+ /**
+ * The result map to use when the Value matches the discriminator column value.
+ * @return string ID of a result map
+ */
+ public function getResultMapping()
+ {
+ return $this->_resultMapping;
+ }
+
+ /**
+ * @param string ID of a result map
+ */
+ public function setResultMapping($value)
+ {
+ $this->_resultMapping = $value;
+ }
+}
+
diff --git a/framework/Data/SqlMap/Configuration/TInlineParameterMapParser.php b/framework/Data/SqlMap/Configuration/TInlineParameterMapParser.php
index b78a235c..914d7eb7 100644
--- a/framework/Data/SqlMap/Configuration/TInlineParameterMapParser.php
+++ b/framework/Data/SqlMap/Configuration/TInlineParameterMapParser.php
@@ -1,79 +1,79 @@
-<?php
-/**
- * TInlineParameterMapParser class file.
- *
- * @author Wei Zhuo <weizhuo[at]gmail[dot]com>
- * @link http://www.pradosoft.com/
+<?php
+/**
+ * TInlineParameterMapParser class file.
+ *
+ * @author Wei Zhuo <weizhuo[at]gmail[dot]com>
+ * @link http://www.pradosoft.com/
* @copyright Copyright &copy; 2005-2012 PradoSoft
- * @license http://www.pradosoft.com/license/
- * @version $Id$
- * @package System.Data.SqlMap.Configuration
- */
-
-/**
- * TInlineParameterMapParser class.
- *
- * The inline parameter map syntax lets you embed the property name,
- * the property type, the column type, and a null value replacement into a
- * parametrized SQL statement.
- *
- * @author Wei Zhuo <weizho[at]gmail[dot]com>
- * @version $Id$
- * @package System.Data.SqlMap.Configuration
- * @since 3.1
- */
-class TInlineParameterMapParser
-{
- /**
- * Regular expression for parsing inline parameter maps.
- */
- const PARAMETER_TOKEN_REGEXP = '/#([^#]+)#/';
-
- /**
- * Parse the sql text for inline parameters.
- * @param string sql text
- * @param array file and node details for exception message.
- * @return array 'sql' and 'parameters' name value pairs.
- */
- public function parse($sqlText, $scope)
- {
- $matches = array();
- $mappings = array();
- preg_match_all(self::PARAMETER_TOKEN_REGEXP, $sqlText, $matches);
-
- for($i = 0, $k=count($matches[1]); $i<$k; $i++)
- {
- $mappings[] = $this->parseMapping($matches[1][$i], $scope);
- $sqlText = str_replace($matches[0][$i], '?', $sqlText);
- }
- return array('sql'=>$sqlText, 'parameters'=>$mappings);
- }
-
- /**
- * Parse inline parameter with syntax as
- * #propertyName,type=string,dbype=Varchar,nullValue=N/A,handler=string#
- * @param string parameter token
- * @param array file and node details for exception message.
- */
- protected function parseMapping($token, $scope)
- {
- $mapping = new TParameterProperty;
- $properties = explode(',', $token);
- $mapping->setProperty(trim(array_shift($properties)));
- foreach($properties as $property)
- {
- $prop = explode('=',$property);
- $name = trim($prop[0]); $value=trim($prop[1]);
- if($mapping->canSetProperty($name))
- $mapping->{'set'.$name}($value);
- else
- {
- throw new TSqlMapUndefinedException(
- 'sqlmap_undefined_property_inline_map',
- $name, $scope['file'], $scope['node'], $token);
- }
- }
- return $mapping;
- }
-}
-
+ * @license http://www.pradosoft.com/license/
+ * @version $Id$
+ * @package System.Data.SqlMap.Configuration
+ */
+
+/**
+ * TInlineParameterMapParser class.
+ *
+ * The inline parameter map syntax lets you embed the property name,
+ * the property type, the column type, and a null value replacement into a
+ * parametrized SQL statement.
+ *
+ * @author Wei Zhuo <weizho[at]gmail[dot]com>
+ * @version $Id$
+ * @package System.Data.SqlMap.Configuration
+ * @since 3.1
+ */
+class TInlineParameterMapParser
+{
+ /**
+ * Regular expression for parsing inline parameter maps.
+ */
+ const PARAMETER_TOKEN_REGEXP = '/#([^#]+)#/';
+
+ /**
+ * Parse the sql text for inline parameters.
+ * @param string sql text
+ * @param array file and node details for exception message.
+ * @return array 'sql' and 'parameters' name value pairs.
+ */
+ public function parse($sqlText, $scope)
+ {
+ $matches = array();
+ $mappings = array();
+ preg_match_all(self::PARAMETER_TOKEN_REGEXP, $sqlText, $matches);
+
+ for($i = 0, $k=count($matches[1]); $i<$k; $i++)
+ {
+ $mappings[] = $this->parseMapping($matches[1][$i], $scope);
+ $sqlText = str_replace($matches[0][$i], '?', $sqlText);
+ }
+ return array('sql'=>$sqlText, 'parameters'=>$mappings);
+ }
+
+ /**
+ * Parse inline parameter with syntax as
+ * #propertyName,type=string,dbype=Varchar,nullValue=N/A,handler=string#
+ * @param string parameter token
+ * @param array file and node details for exception message.
+ */
+ protected function parseMapping($token, $scope)
+ {
+ $mapping = new TParameterProperty;
+ $properties = explode(',', $token);
+ $mapping->setProperty(trim(array_shift($properties)));
+ foreach($properties as $property)
+ {
+ $prop = explode('=',$property);
+ $name = trim($prop[0]); $value=trim($prop[1]);
+ if($mapping->canSetProperty($name))
+ $mapping->{'set'.$name}($value);
+ else
+ {
+ throw new TSqlMapUndefinedException(
+ 'sqlmap_undefined_property_inline_map',
+ $name, $scope['file'], $scope['node'], $token);
+ }
+ }
+ return $mapping;
+ }
+}
+
diff --git a/framework/Data/SqlMap/Configuration/TParameterMap.php b/framework/Data/SqlMap/Configuration/TParameterMap.php
index d7cc5eb6..ee740fdb 100644
--- a/framework/Data/SqlMap/Configuration/TParameterMap.php
+++ b/framework/Data/SqlMap/Configuration/TParameterMap.php
@@ -1,210 +1,210 @@
-<?php
-/**
- * TParameterMap class file.
- *
- * @author Wei Zhuo <weizhuo[at]gmail[dot]com>
- * @link http://www.pradosoft.com/
- * @copyright Copyright &copy; 2005-2012 PradoSoft
- * @license http://www.pradosoft.com/license/
- * @version $Id$
- * @package System.Data.SqlMap.Configuration
- */
-
-/**
- * TParameterMap corresponds to the <parameterMap> element.
- *
- * TParameterMap holds one or more parameter child elements that map object
- * properties to placeholders in a SQL statement.
- *
- * A TParameterMap defines an ordered list of values that match up with the
- * placeholders of a parameterized query statement. While the attributes
- * specified by the map still need to be in the correct order, each parameter
- * is named. You can populate the underlying class in any order, and the
- * TParameterMap ensures each value is passed in the correct order.
- *
- * Parameter Maps can be provided as an external element and inline.
- * The <parameterMap> element accepts two attributes: id (required) and extends (optional).
- *
- * @author Wei Zhuo <weizho[at]gmail[dot]com>
- * @version $Id$
- * @package System.Data.SqlMap.Configuration
- * @since 3.1
- */
-class TParameterMap extends TComponent
-{
- private $_extend;
- private $_properties;
- private $_propertyMap;
- private $_extendMap;
- private $_ID;
-
- /**
- * Initialize the properties and property map collections.
- */
- public function __construct()
- {
- $this->_properties = new TList;
- $this->_propertyMap = new TMap;
- }
-
- /**
- * @return string a unique identifier for the <parameterMap>.
- */
- public function getID()
- {
- return $this->_ID;
- }
-
- /**
- * @param string a unique identifier for the <parameterMap>.
- */
- public function setID($value)
- {
- $this->_ID=$value;
- }
-
- /**
- * @return TParameterProperty[] list of properties for the parameter map.
- */
- public function getProperties()
- {
- return $this->_properties;
- }
-
- /**
- * @return string name of another <parameterMap> upon which to base this TParameterMap.
- */
- public function getExtends()
- {
- return $this->_extend;
- }
-
- /**
- * @param string name of another <parameterMap> upon which to base this TParameterMap.
- */
- public function setExtends($value)
- {
- $this->_extend = $value;
- }
-
- /**
- * @param string name of a parameter property.
- * @return TParameterProperty parameter property.
- * @throws TSqlMapException if index is not string nor integer.
- */
- public function getProperty($index)
- {
- if(is_string($index))
- return $this->_propertyMap->itemAt($index);
- else if(is_int($index))
- return $this->_properties->itemAt($index);
- else
- throw new TSqlMapException('sqlmap_index_must_be_string_or_int', $index);
- }
-
- /**
- * @param TParameterProperty new parameter property
- */
- public function addProperty(TParameterProperty $property)
- {
- $this->_propertyMap->add($property->getProperty(), $property);
- $this->_properties->add($property);
- }
-
- /**
- * @param int parameter property index
- * @param TParameterProperty new parameter property.
- */
- public function insertProperty($index, TParameterProperty $property)
- {
- $this->_propertyMap->add($property->getProperty(), $property);
- $this->_properties->insertAt($index, $property);
- }
-
- /**
- * @return array list of property names.
- */
- public function getPropertyNames()
- {
- return $this->_propertyMap->getKeys();
- }
-
- /**
- * Get the value of a property from the the parameter object.
- * @param TSqlMapTypeHandlerRegistry type handler registry.
- * @param TParameterProperty parameter proproperty.
- * @param mixed parameter object to get the value from.
- * @return unknown
- */
- public function getPropertyValue($registry, $property, $parameterValue)
- {
- $value = $this->getObjectValue($parameterValue,$property);
-
- if(($handler=$this->createTypeHandler($property, $registry))!==null)
- $value = $handler->getParameter($value);
-
- $value = $this->nullifyDefaultValue($property,$value);
-
- if(($type = $property->getType())!==null)
- $value = $registry->convertToType($type, $value);
-
- return $value;
- }
-
-
- /**
- * Create type handler from {@link Type setType()} or {@link TypeHandler setTypeHandler}.
- * @param TParameterProperty parameter property
- * @param TSqlMapTypeHandlerRegistry type handler registry
- * @return TSqlMapTypeHandler type handler.
- */
- protected function createTypeHandler($property, $registry)
- {
- $type=$property->getTypeHandler() ? $property->getTypeHandler() : $property->getType();
- $handler=$registry->getTypeHandler($type);
- if($handler===null && $property->getTypeHandler())
- $handler = Prado::createComponent($type);
- return $handler;
- }
-
-
- /**
- * @param mixed object to obtain the property from.
- * @param TParameterProperty parameter property.
- * @return mixed property value.
- * @throws TSqlMapException if property access is invalid.
- */
- protected function getObjectValue($object,$property)
- {
- try
- {
- return TPropertyAccess::get($object, $property->getProperty());
- }
- catch (TInvalidPropertyException $e)
- {
- throw new TSqlMapException(
- 'sqlmap_unable_to_get_property_for_parameter',
- $this->getID(),
- $property->getProperty(),
- (is_object($object) ? get_class($object) : gettype($object))
- );
- }
- }
-
- /**
- * When the actual value matches the {@link NullValue TParameterProperty::setNullValue()},
- * set the current value to null.
- * @param TParameterProperty parameter property.
- * @param mixed current property value
- * @return mixed null if NullValue matches currrent value.
- */
- protected function nullifyDefaultValue($property,$value)
- {
- if(($nullValue = $property->getNullValue())!==null)
- {
- if($nullValue === $value)
- $value = null;
- }
- return $value;
- }
-}
+<?php
+/**
+ * TParameterMap class file.
+ *
+ * @author Wei Zhuo <weizhuo[at]gmail[dot]com>
+ * @link http://www.pradosoft.com/
+ * @copyright Copyright &copy; 2005-2012 PradoSoft
+ * @license http://www.pradosoft.com/license/
+ * @version $Id$
+ * @package System.Data.SqlMap.Configuration
+ */
+
+/**
+ * TParameterMap corresponds to the <parameterMap> element.
+ *
+ * TParameterMap holds one or more parameter child elements that map object
+ * properties to placeholders in a SQL statement.
+ *
+ * A TParameterMap defines an ordered list of values that match up with the
+ * placeholders of a parameterized query statement. While the attributes
+ * specified by the map still need to be in the correct order, each parameter
+ * is named. You can populate the underlying class in any order, and the
+ * TParameterMap ensures each value is passed in the correct order.
+ *
+ * Parameter Maps can be provided as an external element and inline.
+ * The <parameterMap> element accepts two attributes: id (required) and extends (optional).
+ *
+ * @author Wei Zhuo <weizho[at]gmail[dot]com>
+ * @version $Id$
+ * @package System.Data.SqlMap.Configuration
+ * @since 3.1
+ */
+class TParameterMap extends TComponent
+{
+ private $_extend;
+ private $_properties;
+ private $_propertyMap;
+ private $_extendMap;
+ private $_ID;
+
+ /**
+ * Initialize the properties and property map collections.
+ */
+ public function __construct()
+ {
+ $this->_properties = new TList;
+ $this->_propertyMap = new TMap;
+ }
+
+ /**
+ * @return string a unique identifier for the <parameterMap>.
+ */
+ public function getID()
+ {
+ return $this->_ID;
+ }
+
+ /**
+ * @param string a unique identifier for the <parameterMap>.
+ */
+ public function setID($value)
+ {
+ $this->_ID=$value;
+ }
+
+ /**
+ * @return TParameterProperty[] list of properties for the parameter map.
+ */
+ public function getProperties()
+ {
+ return $this->_properties;
+ }
+
+ /**
+ * @return string name of another <parameterMap> upon which to base this TParameterMap.
+ */
+ public function getExtends()
+ {
+ return $this->_extend;
+ }
+
+ /**
+ * @param string name of another <parameterMap> upon which to base this TParameterMap.
+ */
+ public function setExtends($value)
+ {
+ $this->_extend = $value;
+ }
+
+ /**
+ * @param string name of a parameter property.
+ * @return TParameterProperty parameter property.
+ * @throws TSqlMapException if index is not string nor integer.
+ */
+ public function getProperty($index)
+ {
+ if(is_string($index))
+ return $this->_propertyMap->itemAt($index);
+ else if(is_int($index))
+ return $this->_properties->itemAt($index);
+ else
+ throw new TSqlMapException('sqlmap_index_must_be_string_or_int', $index);
+ }
+
+ /**
+ * @param TParameterProperty new parameter property
+ */
+ public function addProperty(TParameterProperty $property)
+ {
+ $this->_propertyMap->add($property->getProperty(), $property);
+ $this->_properties->add($property);
+ }
+
+ /**
+ * @param int parameter property index
+ * @param TParameterProperty new parameter property.
+ */
+ public function insertProperty($index, TParameterProperty $property)
+ {
+ $this->_propertyMap->add($property->getProperty(), $property);
+ $this->_properties->insertAt($index, $property);
+ }
+
+ /**
+ * @return array list of property names.
+ */
+ public function getPropertyNames()
+ {
+ return $this->_propertyMap->getKeys();
+ }
+
+ /**
+ * Get the value of a property from the the parameter object.
+ * @param TSqlMapTypeHandlerRegistry type handler registry.
+ * @param TParameterProperty parameter proproperty.
+ * @param mixed parameter object to get the value from.
+ * @return unknown
+ */
+ public function getPropertyValue($registry, $property, $parameterValue)
+ {
+ $value = $this->getObjectValue($parameterValue,$property);
+
+ if(($handler=$this->createTypeHandler($property, $registry))!==null)
+ $value = $handler->getParameter($value);
+
+ $value = $this->nullifyDefaultValue($property,$value);
+
+ if(($type = $property->getType())!==null)
+ $value = $registry->convertToType($type, $value);
+
+ return $value;
+ }
+
+
+ /**
+ * Create type handler from {@link Type setType()} or {@link TypeHandler setTypeHandler}.
+ * @param TParameterProperty parameter property
+ * @param TSqlMapTypeHandlerRegistry type handler registry
+ * @return TSqlMapTypeHandler type handler.
+ */
+ protected function createTypeHandler($property, $registry)
+ {
+ $type=$property->getTypeHandler() ? $property->getTypeHandler() : $property->getType();
+ $handler=$registry->getTypeHandler($type);
+ if($handler===null && $property->getTypeHandler())
+ $handler = Prado::createComponent($type);
+ return $handler;
+ }
+
+
+ /**
+ * @param mixed object to obtain the property from.
+ * @param TParameterProperty parameter property.
+ * @return mixed property value.
+ * @throws TSqlMapException if property access is invalid.
+ */
+ protected function getObjectValue($object,$property)
+ {
+ try
+ {
+ return TPropertyAccess::get($object, $property->getProperty());
+ }
+ catch (TInvalidPropertyException $e)
+ {
+ throw new TSqlMapException(
+ 'sqlmap_unable_to_get_property_for_parameter',
+ $this->getID(),
+ $property->getProperty(),
+ (is_object($object) ? get_class($object) : gettype($object))
+ );
+ }
+ }
+
+ /**
+ * When the actual value matches the {@link NullValue TParameterProperty::setNullValue()},
+ * set the current value to null.
+ * @param TParameterProperty parameter property.
+ * @param mixed current property value
+ * @return mixed null if NullValue matches currrent value.
+ */
+ protected function nullifyDefaultValue($property,$value)
+ {
+ if(($nullValue = $property->getNullValue())!==null)
+ {
+ if($nullValue === $value)
+ $value = null;
+ }
+ return $value;
+ }
+}
diff --git a/framework/Data/SqlMap/Configuration/TParameterProperty.php b/framework/Data/SqlMap/Configuration/TParameterProperty.php
index d941ca18..a79af7f2 100644
--- a/framework/Data/SqlMap/Configuration/TParameterProperty.php
+++ b/framework/Data/SqlMap/Configuration/TParameterProperty.php
@@ -1,150 +1,150 @@
-<?php
-/**
- * TParameterPropert class file.
- *
- * @author Wei Zhuo <weizhuo[at]gmail[dot]com>
- * @link http://www.pradosoft.com/
+<?php
+/**
+ * TParameterPropert class file.
+ *
+ * @author Wei Zhuo <weizhuo[at]gmail[dot]com>
+ * @link http://www.pradosoft.com/
* @copyright Copyright &copy; 2005-2012 PradoSoft
- * @license http://www.pradosoft.com/license/
- * @version $Id$
- * @package System.Data.SqlMap.Configuration
- */
-
-/**
- * TParameterProperty corresponds to the <property> tag and defines
- * one object property for the <parameterMap>
- *
- * The {@link NullValue setNullValue()} attribute can be set to any valid
- * value (based on property type). The {@link NullValue setNullValue()} attribute
- * is used to specify an inbound null value replacement. What this means is
- * that when the value is detected in the object property, a NULL will be written
- * to the database (the opposite behavior of an inbound null value replacement).
- * This allows you to use a magic null number in your application for types that
- * do not support null values (such as int, double, float). When these types of
- * properties contain a matching null value (for example, say, -9999), a NULL
- * will be written to the database instead of the value.
- *
- * @author Wei Zhuo <weizho[at]gmail[dot]com>
- * @version $Id$
- * @package System.Data.SqlMap.Configuration
- * @since 3.1
- */
-class TParameterProperty extends TComponent
-{
- private $_typeHandler;
- private $_type;
- private $_column;
- private $_dbType;
- private $_property;
- private $_nullValue;
-
- /**
- * @return string class name of a custom type handler.
- */
- public function getTypeHandler()
- {
- return $this->_typeHandler;
- }
-
- /**
- * @param string class name of a custom type handler.
- */
- public function setTypeHandler($value)
- {
- $this->_typeHandler = $value;
- }
-
- /**
- * @return string type of the parameter's property
- */
- public function getType()
- {
- return $this->_type;
- }
-
- /**
- * @param string type of the parameter's property
- */
- public function setType($value)
- {
- $this->_type = $value;
- }
-
- /**
- * @return string name of a parameter to be used in the SQL statement.
- */
- public function getColumn()
- {
- return $this->_column;
- }
-
- /**
- * @param string name of a parameter to be used in the SQL statement.
- */
- public function setColumn($value)
- {
- $this->_column = $value;
- }
-
- /**
- * @return string the database column type of the parameter to be set by this property.
- */
- public function getDbType()
- {
- return $this->_dbType;
- }
-
- /**
- * @param string the database column type of the parameter to be set by this property.
- */
- public function setDbType($value)
- {
- $this->_dbType = $value;
- }
-
- /**
- * @return string name of a property of the parameter object.
- */
- public function getProperty()
- {
- return $this->_property;
- }
-
- /**
- * @param string name of a property of the parameter object.
- */
- public function setProperty($value)
- {
- $this->_property = $value;
- }
-
- /**
- * @return mixed null value replacement
- */
- public function getNullValue()
- {
- return $this->_nullValue;
- }
-
- /**
- * The nullValue attribute is used to specify an outgoing null value replacement.
- * @param mixed null value replacement.
- */
- public function setNullValue($value)
- {
- $this->_nullValue = $value;
- }
-
- public function __sleep()
- {
- $exprops = array(); $cn = 'TParameterProperty';
- if ($this->_typeHandler===null) $exprops[] = "\0$cn\0_typeHandler";
- if ($this->_type===null) $exprops[] = "\0$cn\0_type";
- if ($this->_column===null) $exprops[] = "\0$cn\0_column";
- if ($this->_dbType===null) $exprops[] = "\0$cn\0_dbType";
- if ($this->_property===null) $exprops[] = "\0$cn\0_property";
- if ($this->_nullValue===null) $exprops[] = "\0$cn\0_nullValue";
- return array_diff(parent::__sleep(),$exprops);
- }
-}
-
+ * @license http://www.pradosoft.com/license/
+ * @version $Id$
+ * @package System.Data.SqlMap.Configuration
+ */
+
+/**
+ * TParameterProperty corresponds to the <property> tag and defines
+ * one object property for the <parameterMap>
+ *
+ * The {@link NullValue setNullValue()} attribute can be set to any valid
+ * value (based on property type). The {@link NullValue setNullValue()} attribute
+ * is used to specify an inbound null value replacement. What this means is
+ * that when the value is detected in the object property, a NULL will be written
+ * to the database (the opposite behavior of an inbound null value replacement).
+ * This allows you to use a magic null number in your application for types that
+ * do not support null values (such as int, double, float). When these types of
+ * properties contain a matching null value (for example, say, -9999), a NULL
+ * will be written to the database instead of the value.
+ *
+ * @author Wei Zhuo <weizho[at]gmail[dot]com>
+ * @version $Id$
+ * @package System.Data.SqlMap.Configuration
+ * @since 3.1
+ */
+class TParameterProperty extends TComponent
+{
+ private $_typeHandler;
+ private $_type;
+ private $_column;
+ private $_dbType;
+ private $_property;
+ private $_nullValue;
+
+ /**
+ * @return string class name of a custom type handler.
+ */
+ public function getTypeHandler()
+ {
+ return $this->_typeHandler;
+ }
+
+ /**
+ * @param string class name of a custom type handler.
+ */
+ public function setTypeHandler($value)
+ {
+ $this->_typeHandler = $value;
+ }
+
+ /**
+ * @return string type of the parameter's property
+ */
+ public function getType()
+ {
+ return $this->_type;
+ }
+
+ /**
+ * @param string type of the parameter's property
+ */
+ public function setType($value)
+ {
+ $this->_type = $value;
+ }
+
+ /**
+ * @return string name of a parameter to be used in the SQL statement.
+ */
+ public function getColumn()
+ {
+ return $this->_column;
+ }
+
+ /**
+ * @param string name of a parameter to be used in the SQL statement.
+ */
+ public function setColumn($value)
+ {
+ $this->_column = $value;
+ }
+
+ /**
+ * @return string the database column type of the parameter to be set by this property.
+ */
+ public function getDbType()
+ {
+ return $this->_dbType;
+ }
+
+ /**
+ * @param string the database column type of the parameter to be set by this property.
+ */
+ public function setDbType($value)
+ {
+ $this->_dbType = $value;
+ }
+
+ /**
+ * @return string name of a property of the parameter object.
+ */
+ public function getProperty()
+ {
+ return $this->_property;
+ }
+
+ /**
+ * @param string name of a property of the parameter object.
+ */
+ public function setProperty($value)
+ {
+ $this->_property = $value;
+ }
+
+ /**
+ * @return mixed null value replacement
+ */
+ public function getNullValue()
+ {
+ return $this->_nullValue;
+ }
+
+ /**
+ * The nullValue attribute is used to specify an outgoing null value replacement.
+ * @param mixed null value replacement.
+ */
+ public function setNullValue($value)
+ {
+ $this->_nullValue = $value;
+ }
+
+ public function __sleep()
+ {
+ $exprops = array(); $cn = 'TParameterProperty';
+ if ($this->_typeHandler===null) $exprops[] = "\0$cn\0_typeHandler";
+ if ($this->_type===null) $exprops[] = "\0$cn\0_type";
+ if ($this->_column===null) $exprops[] = "\0$cn\0_column";
+ if ($this->_dbType===null) $exprops[] = "\0$cn\0_dbType";
+ if ($this->_property===null) $exprops[] = "\0$cn\0_property";
+ if ($this->_nullValue===null) $exprops[] = "\0$cn\0_nullValue";
+ return array_diff(parent::__sleep(),$exprops);
+ }
+}
+
diff --git a/framework/Data/SqlMap/Configuration/TResultMap.php b/framework/Data/SqlMap/Configuration/TResultMap.php
index e05c4c47..77b5f0b2 100644
--- a/framework/Data/SqlMap/Configuration/TResultMap.php
+++ b/framework/Data/SqlMap/Configuration/TResultMap.php
@@ -1,200 +1,200 @@
-<?php
-/**
- * TResultMap class file.
- *
- * @author Wei Zhuo <weizhuo[at]gmail[dot]com>
- * @link http://www.pradosoft.com/
- * @copyright Copyright &copy; 2005-2012 PradoSoft
- * @license http://www.pradosoft.com/license/
- * @version $Id$
- * @package System.Data.SqlMap.Configuration
- */
-
-/**
- * TResultMap corresponds to <resultMap> mapping tag.
- *
- * A TResultMap lets you control how data is extracted from the result of a
- * query, and how the columns are mapped to object properties. A TResultMap
- * can describe the column type, a null value replacement, and complex property
- * mappings including Collections.
- *
- * The <resultMap> can contain any number of property mappings that map object
- * properties to the columns of a result element. The property mappings are
- * applied, and the columns are read, in the order that they are defined.
- * Maintaining the element order ensures consistent results between different
- * drivers and providers.
- *
- * The {@link Class setClass()} property must be a PHP class object or array instance.
- *
- * The optional {@link Extends setExtends()} attribute can be set to the ID of
- * another <resultMap> upon which to base this <resultMap>. All properties of the
- * "parent" <resultMap> will be included as part of this <resultMap>, and values
- * from the "parent" <resultMap> are set before any values specified by this <resultMap>.
- *
- * @author Wei Zhuo <weizho[at]gmail[dot]com>
- * @version $Id$
- * @package System.Data.SqlMap.Configuration
- * @since 3.1
- */
-class TResultMap extends TComponent
-{
- private $_columns;
- private $_class;
- private $_extends;
- private $_groupBy;
- private $_discriminator;
- private $_typeHandlers;
- private $_ID;
-
- /**
- * Initialize the columns collection.
- */
- public function __construct()
- {
- $this->_columns=new TMap;
- }
-
- /**
- * @return string a unique identifier for the <resultMap>.
- */
- public function getID()
- {
- return $this->_ID;
- }
-
- /**
- * @param string a unique identifier for the <resultMap>.
- */
- public function setID($value)
- {
- $this->_ID=$value;
- }
-
- /**
- * @return string result class name.
- */
- public function getClass()
- {
- return $this->_class;
- }
-
- /**
- * @param string result class name.
- */
- public function setClass($value)
- {
- $this->_class = $value;
- }
-
- /**
- * @return TMap result columns.
- */
- public function getColumns()
- {
- return $this->_columns;
- }
-
- /**
- * @return string result map extends another result map.
- */
- public function getExtends()
- {
- return $this->_extends;
- }
-
- /**
- * @param string result map extends another result map.
- */
- public function setExtends($value)
- {
- $this->_extends = $value;
- }
-
- /**
- * @return string result map groups by.
- */
- public function getGroupBy()
- {
- return $this->_groupBy;
- }
-
- /**
- * @param string result map group by
- */
- public function setGroupBy($value)
- {
- $this->_groupBy = $value;
- }
-
- /**
- * @return TDiscriminator result class discriminator.
- */
- public function getDiscriminator()
- {
- return $this->_discriminator;
- }
-
- /**
- * @param TDiscriminator result class discriminator.
- */
- public function setDiscriminator(TDiscriminator $value)
- {
- $this->_discriminator = $value;
- }
-
- /**
- * Add a TResultProperty to result mapping.
- * @param TResultProperty result property.
- */
- public function addResultProperty(TResultProperty $property)
- {
- $this->_columns[$property->getProperty()] = $property;
- }
-
- /**
- * Create a new instance of the class of this result map.
- * @param TSqlMapTypeHandlerRegistry type handler registry.
- * @return mixed new result object.
- * @throws TSqlMapException
- */
- public function createInstanceOfResult($registry)
- {
- $handler = $registry->getTypeHandler($this->getClass());
- try
- {
- if($handler!==null)
- return $handler->createNewInstance();
- else
- return $registry->createInstanceOf($this->getClass());
- }
- catch (TSqlMapException $e)
- {
- throw new TSqlMapException(
- 'sqlmap_unable_to_create_new_instance',
- $this->getClass(), get_class($handler), $this->getID());
- }
- }
-
- /**
- * Result sub-mappings using the discriminiator column.
- * @param TSqlMapTypeHandlerRegistry type handler registry
- * @param array row data.
- * @return TResultMap result sub-map.
- */
- public function resolveSubMap($registry,$row)
- {
- $subMap = $this;
- if(($disc = $this->getDiscriminator())!==null)
- {
- $value = $disc->getMapping()->getPropertyValue($registry,$row);
- $subMap = $disc->getSubMap((string)$value);
-
- if($subMap===null)
- $subMap = $this;
- else if($subMap !== $this)
- $subMap = $subMap->resolveSubMap($registry,$row);
- }
- return $subMap;
- }
-}
-
+<?php
+/**
+ * TResultMap class file.
+ *
+ * @author Wei Zhuo <weizhuo[at]gmail[dot]com>
+ * @link http://www.pradosoft.com/
+ * @copyright Copyright &copy; 2005-2012 PradoSoft
+ * @license http://www.pradosoft.com/license/
+ * @version $Id$
+ * @package System.Data.SqlMap.Configuration
+ */
+
+/**
+ * TResultMap corresponds to <resultMap> mapping tag.
+ *
+ * A TResultMap lets you control how data is extracted from the result of a
+ * query, and how the columns are mapped to object properties. A TResultMap
+ * can describe the column type, a null value replacement, and complex property
+ * mappings including Collections.
+ *
+ * The <resultMap> can contain any number of property mappings that map object
+ * properties to the columns of a result element. The property mappings are
+ * applied, and the columns are read, in the order that they are defined.
+ * Maintaining the element order ensures consistent results between different
+ * drivers and providers.
+ *
+ * The {@link Class setClass()} property must be a PHP class object or array instance.
+ *
+ * The optional {@link Extends setExtends()} attribute can be set to the ID of
+ * another <resultMap> upon which to base this <resultMap>. All properties of the
+ * "parent" <resultMap> will be included as part of this <resultMap>, and values
+ * from the "parent" <resultMap> are set before any values specified by this <resultMap>.
+ *
+ * @author Wei Zhuo <weizho[at]gmail[dot]com>
+ * @version $Id$
+ * @package System.Data.SqlMap.Configuration
+ * @since 3.1
+ */
+class TResultMap extends TComponent
+{
+ private $_columns;
+ private $_class;
+ private $_extends;
+ private $_groupBy;
+ private $_discriminator;
+ private $_typeHandlers;
+ private $_ID;
+
+ /**
+ * Initialize the columns collection.
+ */
+ public function __construct()
+ {
+ $this->_columns=new TMap;
+ }
+
+ /**
+ * @return string a unique identifier for the <resultMap>.
+ */
+ public function getID()
+ {
+ return $this->_ID;
+ }
+
+ /**
+ * @param string a unique identifier for the <resultMap>.
+ */
+ public function setID($value)
+ {
+ $this->_ID=$value;
+ }
+
+ /**
+ * @return string result class name.
+ */
+ public function getClass()
+ {
+ return $this->_class;
+ }
+
+ /**
+ * @param string result class name.
+ */
+ public function setClass($value)
+ {
+ $this->_class = $value;
+ }
+
+ /**
+ * @return TMap result columns.
+ */
+ public function getColumns()
+ {
+ return $this->_columns;
+ }
+
+ /**
+ * @return string result map extends another result map.
+ */
+ public function getExtends()
+ {
+ return $this->_extends;
+ }
+
+ /**
+ * @param string result map extends another result map.
+ */
+ public function setExtends($value)
+ {
+ $this->_extends = $value;
+ }
+
+ /**
+ * @return string result map groups by.
+ */
+ public function getGroupBy()
+ {
+ return $this->_groupBy;
+ }
+
+ /**
+ * @param string result map group by
+ */
+ public function setGroupBy($value)
+ {
+ $this->_groupBy = $value;
+ }
+
+ /**
+ * @return TDiscriminator result class discriminator.
+ */
+ public function getDiscriminator()
+ {
+ return $this->_discriminator;
+ }
+
+ /**
+ * @param TDiscriminator result class discriminator.
+ */
+ public function setDiscriminator(TDiscriminator $value)
+ {
+ $this->_discriminator = $value;
+ }
+
+ /**
+ * Add a TResultProperty to result mapping.
+ * @param TResultProperty result property.
+ */
+ public function addResultProperty(TResultProperty $property)
+ {
+ $this->_columns[$property->getProperty()] = $property;
+ }
+
+ /**
+ * Create a new instance of the class of this result map.
+ * @param TSqlMapTypeHandlerRegistry type handler registry.
+ * @return mixed new result object.
+ * @throws TSqlMapException
+ */
+ public function createInstanceOfResult($registry)
+ {
+ $handler = $registry->getTypeHandler($this->getClass());
+ try
+ {
+ if($handler!==null)
+ return $handler->createNewInstance();
+ else
+ return $registry->createInstanceOf($this->getClass());
+ }
+ catch (TSqlMapException $e)
+ {
+ throw new TSqlMapException(
+ 'sqlmap_unable_to_create_new_instance',
+ $this->getClass(), get_class($handler), $this->getID());
+ }
+ }
+
+ /**
+ * Result sub-mappings using the discriminiator column.
+ * @param TSqlMapTypeHandlerRegistry type handler registry
+ * @param array row data.
+ * @return TResultMap result sub-map.
+ */
+ public function resolveSubMap($registry,$row)
+ {
+ $subMap = $this;
+ if(($disc = $this->getDiscriminator())!==null)
+ {
+ $value = $disc->getMapping()->getPropertyValue($registry,$row);
+ $subMap = $disc->getSubMap((string)$value);
+
+ if($subMap===null)
+ $subMap = $this;
+ else if($subMap !== $this)
+ $subMap = $subMap->resolveSubMap($registry,$row);
+ }
+ return $subMap;
+ }
+}
+
diff --git a/framework/Data/SqlMap/Configuration/TResultProperty.php b/framework/Data/SqlMap/Configuration/TResultProperty.php
index 0a016350..8447d400 100644
--- a/framework/Data/SqlMap/Configuration/TResultProperty.php
+++ b/framework/Data/SqlMap/Configuration/TResultProperty.php
@@ -1,344 +1,344 @@
-<?php
-/**
- * TResultProperty class file.
- *
- * @author Wei Zhuo <weizhuo[at]gmail[dot]com>
- * @link http://www.pradosoft.com/
- * @copyright Copyright &copy; 2005-2012 PradoSoft
- * @license http://www.pradosoft.com/license/
- * @version $Id$
- * @package System.Data.SqlMap.Configuration
- */
-
-/**
- * TResultProperty corresponds a <property> tags inside a <resultMap> tag.
- *
- * The {@link NullValue setNullValue()} attribute can be set to any valid
- * value (based on property type). The {@link NullValue setNullValue()} attribute
- * is used to specify an outgoing null value replacement. What this means is
- * that when a null value is detected in the result, the corresponding value of
- * the {@link NullValue getNullValue()} will be used instead.
- *
- * The {@link Select setSelect()} property is used to describe a relationship
- * between objects and to automatically load complex (i.e. user defined)
- * property types. The value of the {@link Select setSelect()} property must be
- * the name of another mapped statement. The value of the database
- * {@link Column setColumn()} that is defined in the same property element as
- * this statement attribute will be passed to the related mapped statement as
- * the parameter. The {@link LazyLoad setLayLoad()} attribute can be specified
- * with the {@link Select setSelect()} .
- *
- * @author Wei Zhuo <weizho[at]gmail[dot]com>
- * @version $Id$
- * @package System.Data.SqlMap.Configuration
- * @since 3.1
- */
-class TResultProperty extends TComponent
-{
- private $_nullValue;
- private $_propertyName;
- private $_columnName;
- private $_columnIndex=-1;
- private $_nestedResultMapName;
- private $_nestedResultMap;
- private $_valueType;
- private $_typeHandler;
- private $_isLazyLoad=false;
- private $_select;
-
- private $_hostResultMapID='inplicit internal mapping';
-
- const LIST_TYPE = 0;
- const ARRAY_TYPE = 1;
-
- /**
- * Gets the containing result map ID.
- * @param TResultMap containing result map.
- */
- public function __construct($resultMap=null)
- {
- if($resultMap instanceof TResultMap)
- $this->_hostResultMapID = $resultMap->getID();
- }
-
- /**
- * @return mixed null value replacement.
- */
- public function getNullValue()
- {
- return $this->_nullValue;
- }
-
- /**
- * @param mixed null value replacement.
- */
- public function setNullValue($value)
- {
- $this->_nullValue = $value;
- }
-
- /**
- * @return string name of a property of the result object that will be set to.
- */
- public function getProperty()
- {
- return $this->_propertyName;
- }
-
- /**
- * @param string name of a property of the result object that will be set to.
- */
- public function setProperty($value)
- {
- $this->_propertyName = $value;
- }
-
- /**
- * @return string name of the column in the result set from which the value
- * will be used to populate the property.
- */
- public function getColumn()
- {
- return $this->_columnName;
- }
-
- /**
- * @param string name of the column in the result set from which the value
- * will be used to populate the property.
- */
- public function setColumn($value)
- {
- $this->_columnName = $value;
- }
-
- /**
- * @return int index of the column in the ResultSet from which the value will
- * be used to populate the object property
- */
- public function getColumnIndex()
- {
- return $this->_columnIndex;
- }
-
- /**
- * @param int index of the column in the ResultSet from which the value will
- * be used to populate the object property
- */
- public function setColumnIndex($value)
- {
- $this->_columnIndex = TPropertyValue::ensureInteger($value);
- }
-
- /**
- * @return string ID of another <resultMap> used to fill the property.
- */
- public function getResultMapping()
- {
- return $this->_nestedResultMapName;
- }
-
- /**
- * @param string ID of another <resultMap> used to fill the property.
- */
- public function setResultMapping($value)
- {
- $this->_nestedResultMapName = $value;
- }
-
- /**
- * @return TResultMap nested result map.
- */
- public function getNestedResultMap()
- {
- return $this->_nestedResultMap;
- }
-
- /**
- * @param TResult nested result map.
- */
- public function setNestedResultMap($value)
- {
- $this->_nestedResultMap = $value;
- }
-
- /**
- * @return string property type of the object property to be set.
- */
- public function getType()
- {
- return $this->_valueType;
- }
-
- /**
- * @param string property type of the object property to be set.
- */
- public function setType($value)
- {
- $this->_valueType = $value;
- }
-
- /**
- * @return string custom type handler class name (may use namespace).
- */
- public function getTypeHandler()
- {
- return $this->_typeHandler;
- }
-
- /**
- * @param string custom type handler class name (may use namespace).
- */
- public function setTypeHandler($value)
- {
- $this->_typeHandler = $value;
- }
-
- /**
- * @return string name of another mapped statement
- */
- public function getSelect()
- {
- return $this->_select;
- }
-
- /**
- * The select property is used to describe a relationship between objects
- * and to automatically load complex (i.e. user defined) property types.
- * @param string name of another mapped statement.
- */
- public function setSelect($value)
- {
- $this->_select = $value;
- }
-
- /**
- * @return boolean indicate whether or not the select statement's results should be lazy loaded
- */
- public function getLazyLoad()
- {
- return $this->_isLazyLoad;
- }
-
- /**
- * @param boolean indicate whether or not the select statement's results should be lazy loaded
- */
- public function setLazyLoad($value)
- {
- $this->_isLazyLoad = TPropertyValue::ensureBoolean($value,false);
- }
-
- /**
- * Gets the value for the current property, converts to applicable type if necessary.
- * @param TSqlMapTypeHandlerRegistry type handler registry
- * @param array result row
- * @return mixed property value.
- */
- public function getPropertyValue($registry,$row)
- {
- $value = null;
- $index = $this->getColumnIndex();
- $name = $this->getColumn();
- if($index > 0 && isset($row[$index]))
- $value = $this->getTypedValue($registry,$row[$index]);
- else if(isset($row[$name]))
- $value = $this->getTypedValue($registry,$row[$name]);
- if(($value===null) && ($this->getNullValue()!==null))
- $value = $this->getTypedValue($registry,$this->getNullValue());
- return $value;
- }
-
- /**
- * @param TSqlMapTypeHandlerRegistry type handler registry
- * @param mixed raw property value
- * @return mixed property value casted to specific type.
- */
- protected function getTypedValue($registry,$value)
- {
- if(($handler = $this->createTypeHandler($registry))!==null)
- return $handler->getResult($value);
- else
- return $registry->convertToType($this->getType(), $value);
- }
-
- /**
- * Create type handler from {@link Type setType()} or {@link TypeHandler setTypeHandler}.
- * @param TSqlMapTypeHandlerRegistry type handler registry
- * @return TSqlMapTypeHandler type handler.
- */
- protected function createTypeHandler($registry)
- {
- $type=$this->getTypeHandler() ? $this->getTypeHandler() : $this->getType();
- $handler=$registry->getTypeHandler($type);
- if($handler===null && $this->getTypeHandler())
- $handler = Prado::createComponent($type);
- return $handler;
- }
-
- /**
- * Determines if the type is an instance of ArrayAccess, TList or an array.
- * @return int TResultProperty::LIST_TYPE or TResultProperty::ARRAY_TYPE
- */
- protected function getPropertyValueType()
- {
- if(class_exists($type = $this->getType(), false)) //NO force autoloading
- {
- if($type==='TList')
- return self::LIST_TYPE;
- $class = new ReflectionClass($type);
- if($class->isSubclassOf('TList'))
- return self::LIST_TYPE;
- if($class->implementsInterface('ArrayAccess'))
- return self::ARRAY_TYPE;
- }
- if(strtolower($type) == 'array')
- return self::ARRAY_TYPE;
- }
-
- /**
- * Returns true if the result property {@link Type getType()} is of TList type
- * or that the actual result object is an instance of TList.
- * @param object result object
- * @return boolean true if the result object is an instance of TList
- */
- public function instanceOfListType($target)
- {
- if($this->getType()===null)
- return TPropertyAccess::get($target,$this->getProperty()) instanceof TList;
- return $this->getPropertyValueType() == self::LIST_TYPE;
- }
-
- /**
- * Returns true if the result property {@link Type getType()} is of ArrayAccess
- * or that the actual result object is an array or implements ArrayAccess
- * @param object result object
- * @return boolean true if the result object is an instance of ArrayAccess or is an array.
- */
- public function instanceOfArrayType($target)
- {
- if($this->getType()===null)
- {
- $prop = TPropertyAccess::get($target,$this->getProperty());
- if(is_object($prop))
- return $prop instanceof ArrayAccess;
- return is_array($prop);
- }
- return $this->getPropertyValueType() == self::ARRAY_TYPE;
- }
-
- public function __sleep()
- {
- $exprops = array(); $cn = 'TResultProperty';
- if ($this->_nullValue===null) $exprops[] = "\0$cn\0_nullValue";
- if ($this->_propertyName===null) $exprops[] = "\0$cn\0_propertyNama";
- if ($this->_columnName===null) $exprops[] = "\0$cn\0_columnName";
- if ($this->_columnIndex==-1) $exprops[] = "\0$cn\0_columnIndex";
- if ($this->_nestedResultMapName===null) $exprops[] = "\0$cn\0_nestedResultMapName";
- if ($this->_nestedResultMap===null) $exprops[] = "\0$cn\0_nestedResultMap";
- if ($this->_valueType===null) $exprops[] = "\0$cn\0_valueType";
- if ($this->_typeHandler===null) $exprops[] = "\0$cn\0_typeHandler";
- if ($this->_isLazyLoad===false) $exprops[] = "\0$cn\0_isLazyLoad";
- if ($this->_select===null) $exprops[] = "\0$cn\0_select";
- return array_diff(parent::__sleep(),$exprops);
- }
-}
-
+<?php
+/**
+ * TResultProperty class file.
+ *
+ * @author Wei Zhuo <weizhuo[at]gmail[dot]com>
+ * @link http://www.pradosoft.com/
+ * @copyright Copyright &copy; 2005-2012 PradoSoft
+ * @license http://www.pradosoft.com/license/
+ * @version $Id$
+ * @package System.Data.SqlMap.Configuration
+ */
+
+/**
+ * TResultProperty corresponds a <property> tags inside a <resultMap> tag.
+ *
+ * The {@link NullValue setNullValue()} attribute can be set to any valid
+ * value (based on property type). The {@link NullValue setNullValue()} attribute
+ * is used to specify an outgoing null value replacement. What this means is
+ * that when a null value is detected in the result, the corresponding value of
+ * the {@link NullValue getNullValue()} will be used instead.
+ *
+ * The {@link Select setSelect()} property is used to describe a relationship
+ * between objects and to automatically load complex (i.e. user defined)
+ * property types. The value of the {@link Select setSelect()} property must be
+ * the name of another mapped statement. The value of the database
+ * {@link Column setColumn()} that is defined in the same property element as
+ * this statement attribute will be passed to the related mapped statement as
+ * the parameter. The {@link LazyLoad setLayLoad()} attribute can be specified
+ * with the {@link Select setSelect()} .
+ *
+ * @author Wei Zhuo <weizho[at]gmail[dot]com>
+ * @version $Id$
+ * @package System.Data.SqlMap.Configuration
+ * @since 3.1
+ */
+class TResultProperty extends TComponent
+{
+ private $_nullValue;
+ private $_propertyName;
+ private $_columnName;
+ private $_columnIndex=-1;
+ private $_nestedResultMapName;
+ private $_nestedResultMap;
+ private $_valueType;
+ private $_typeHandler;
+ private $_isLazyLoad=false;
+ private $_select;
+
+ private $_hostResultMapID='inplicit internal mapping';
+
+ const LIST_TYPE = 0;
+ const ARRAY_TYPE = 1;
+
+ /**
+ * Gets the containing result map ID.
+ * @param TResultMap containing result map.
+ */
+ public function __construct($resultMap=null)
+ {
+ if($resultMap instanceof TResultMap)
+ $this->_hostResultMapID = $resultMap->getID();
+ }
+
+ /**
+ * @return mixed null value replacement.
+ */
+ public function getNullValue()
+ {
+ return $this->_nullValue;
+ }
+
+ /**
+ * @param mixed null value replacement.
+ */
+ public function setNullValue($value)
+ {
+ $this->_nullValue = $value;
+ }
+
+ /**
+ * @return string name of a property of the result object that will be set to.
+ */
+ public function getProperty()
+ {
+ return $this->_propertyName;
+ }
+
+ /**
+ * @param string name of a property of the result object that will be set to.
+ */
+ public function setProperty($value)
+ {
+ $this->_propertyName = $value;
+ }
+
+ /**
+ * @return string name of the column in the result set from which the value
+ * will be used to populate the property.
+ */
+ public function getColumn()
+ {
+ return $this->_columnName;
+ }
+
+ /**
+ * @param string name of the column in the result set from which the value
+ * will be used to populate the property.
+ */
+ public function setColumn($value)
+ {
+ $this->_columnName = $value;
+ }
+
+ /**
+ * @return int index of the column in the ResultSet from which the value will
+ * be used to populate the object property
+ */
+ public function getColumnIndex()
+ {
+ return $this->_columnIndex;
+ }
+
+ /**
+ * @param int index of the column in the ResultSet from which the value will
+ * be used to populate the object property
+ */
+ public function setColumnIndex($value)
+ {
+ $this->_columnIndex = TPropertyValue::ensureInteger($value);
+ }
+
+ /**
+ * @return string ID of another <resultMap> used to fill the property.
+ */
+ public function getResultMapping()
+ {
+ return $this->_nestedResultMapName;
+ }
+
+ /**
+ * @param string ID of another <resultMap> used to fill the property.
+ */
+ public function setResultMapping($value)
+ {
+ $this->_nestedResultMapName = $value;
+ }
+
+ /**
+ * @return TResultMap nested result map.
+ */
+ public function getNestedResultMap()
+ {
+ return $this->_nestedResultMap;
+ }
+
+ /**
+ * @param TResult nested result map.
+ */
+ public function setNestedResultMap($value)
+ {
+ $this->_nestedResultMap = $value;
+ }
+
+ /**
+ * @return string property type of the object property to be set.
+ */
+ public function getType()
+ {
+ return $this->_valueType;
+ }
+
+ /**
+ * @param string property type of the object property to be set.
+ */
+ public function setType($value)
+ {
+ $this->_valueType = $value;
+ }
+
+ /**
+ * @return string custom type handler class name (may use namespace).
+ */
+ public function getTypeHandler()
+ {
+ return $this->_typeHandler;
+ }
+
+ /**
+ * @param string custom type handler class name (may use namespace).
+ */
+ public function setTypeHandler($value)
+ {
+ $this->_typeHandler = $value;
+ }
+
+ /**
+ * @return string name of another mapped statement
+ */
+ public function getSelect()
+ {
+ return $this->_select;
+ }
+
+ /**
+ * The select property is used to describe a relationship between objects
+ * and to automatically load complex (i.e. user defined) property types.
+ * @param string name of another mapped statement.
+ */
+ public function setSelect($value)
+ {
+ $this->_select = $value;
+ }
+
+ /**
+ * @return boolean indicate whether or not the select statement's results should be lazy loaded
+ */
+ public function getLazyLoad()
+ {
+ return $this->_isLazyLoad;
+ }
+
+ /**
+ * @param boolean indicate whether or not the select statement's results should be lazy loaded
+ */
+ public function setLazyLoad($value)
+ {
+ $this->_isLazyLoad = TPropertyValue::ensureBoolean($value,false);
+ }
+
+ /**
+ * Gets the value for the current property, converts to applicable type if necessary.
+ * @param TSqlMapTypeHandlerRegistry type handler registry
+ * @param array result row
+ * @return mixed property value.
+ */
+ public function getPropertyValue($registry,$row)
+ {
+ $value = null;
+ $index = $this->getColumnIndex();
+ $name = $this->getColumn();
+ if($index > 0 && isset($row[$index]))
+ $value = $this->getTypedValue($registry,$row[$index]);
+ else if(isset($row[$name]))
+ $value = $this->getTypedValue($registry,$row[$name]);
+ if(($value===null) && ($this->getNullValue()!==null))
+ $value = $this->getTypedValue($registry,$this->getNullValue());
+ return $value;
+ }
+
+ /**
+ * @param TSqlMapTypeHandlerRegistry type handler registry
+ * @param mixed raw property value
+ * @return mixed property value casted to specific type.
+ */
+ protected function getTypedValue($registry,$value)
+ {
+ if(($handler = $this->createTypeHandler($registry))!==null)
+ return $handler->getResult($value);
+ else
+ return $registry->convertToType($this->getType(), $value);
+ }
+
+ /**
+ * Create type handler from {@link Type setType()} or {@link TypeHandler setTypeHandler}.
+ * @param TSqlMapTypeHandlerRegistry type handler registry
+ * @return TSqlMapTypeHandler type handler.
+ */
+ protected function createTypeHandler($registry)
+ {
+ $type=$this->getTypeHandler() ? $this->getTypeHandler() : $this->getType();
+ $handler=$registry->getTypeHandler($type);
+ if($handler===null && $this->getTypeHandler())
+ $handler = Prado::createComponent($type);
+ return $handler;
+ }
+
+ /**
+ * Determines if the type is an instance of ArrayAccess, TList or an array.
+ * @return int TResultProperty::LIST_TYPE or TResultProperty::ARRAY_TYPE
+ */
+ protected function getPropertyValueType()
+ {
+ if(class_exists($type = $this->getType(), false)) //NO force autoloading
+ {
+ if($type==='TList')
+ return self::LIST_TYPE;
+ $class = new ReflectionClass($type);
+ if($class->isSubclassOf('TList'))
+ return self::LIST_TYPE;
+ if($class->implementsInterface('ArrayAccess'))
+ return self::ARRAY_TYPE;
+ }
+ if(strtolower($type) == 'array')
+ return self::ARRAY_TYPE;
+ }
+
+ /**
+ * Returns true if the result property {@link Type getType()} is of TList type
+ * or that the actual result object is an instance of TList.
+ * @param object result object
+ * @return boolean true if the result object is an instance of TList
+ */
+ public function instanceOfListType($target)
+ {
+ if($this->getType()===null)
+ return TPropertyAccess::get($target,$this->getProperty()) instanceof TList;
+ return $this->getPropertyValueType() == self::LIST_TYPE;
+ }
+
+ /**
+ * Returns true if the result property {@link Type getType()} is of ArrayAccess
+ * or that the actual result object is an array or implements ArrayAccess
+ * @param object result object
+ * @return boolean true if the result object is an instance of ArrayAccess or is an array.
+ */
+ public function instanceOfArrayType($target)
+ {
+ if($this->getType()===null)
+ {
+ $prop = TPropertyAccess::get($target,$this->getProperty());
+ if(is_object($prop))
+ return $prop instanceof ArrayAccess;
+ return is_array($prop);
+ }
+ return $this->getPropertyValueType() == self::ARRAY_TYPE;
+ }
+
+ public function __sleep()
+ {
+ $exprops = array(); $cn = 'TResultProperty';
+ if ($this->_nullValue===null) $exprops[] = "\0$cn\0_nullValue";
+ if ($this->_propertyName===null) $exprops[] = "\0$cn\0_propertyNama";
+ if ($this->_columnName===null) $exprops[] = "\0$cn\0_columnName";
+ if ($this->_columnIndex==-1) $exprops[] = "\0$cn\0_columnIndex";
+ if ($this->_nestedResultMapName===null) $exprops[] = "\0$cn\0_nestedResultMapName";
+ if ($this->_nestedResultMap===null) $exprops[] = "\0$cn\0_nestedResultMap";
+ if ($this->_valueType===null) $exprops[] = "\0$cn\0_valueType";
+ if ($this->_typeHandler===null) $exprops[] = "\0$cn\0_typeHandler";
+ if ($this->_isLazyLoad===false) $exprops[] = "\0$cn\0_isLazyLoad";
+ if ($this->_select===null) $exprops[] = "\0$cn\0_select";
+ return array_diff(parent::__sleep(),$exprops);
+ }
+}
+
diff --git a/framework/Data/SqlMap/Configuration/TSimpleDynamicParser.php b/framework/Data/SqlMap/Configuration/TSimpleDynamicParser.php
index 1ceba9eb..a70e6b3f 100644
--- a/framework/Data/SqlMap/Configuration/TSimpleDynamicParser.php
+++ b/framework/Data/SqlMap/Configuration/TSimpleDynamicParser.php
@@ -1,45 +1,45 @@
-<?php
-/**
- * TSimpleDynamicParser class file.
- *
- * @author Wei Zhuo <weizhuo[at]gmail[dot]com>
- * @link http://www.pradosoft.com/
+<?php
+/**
+ * TSimpleDynamicParser class file.
+ *
+ * @author Wei Zhuo <weizhuo[at]gmail[dot]com>
+ * @link http://www.pradosoft.com/
* @copyright Copyright &copy; 2005-2012 PradoSoft
- * @license http://www.pradosoft.com/license/
- * @version $Id$
- * @package System.Data.SqlMap.Configuration
- */
-
-/**
- * TSimpleDynamicParser finds place holders $name$ in the sql text and replaces
- * it with a TSimpleDynamicParser::DYNAMIC_TOKEN.
- *
- * @author Wei Zhuo <weizho[at]gmail[dot]com>
- * @version $Id$
- * @package System.Data.SqlMap.Configuration
- * @since 3.1
- */
-class TSimpleDynamicParser
-{
- const PARAMETER_TOKEN_REGEXP = '/\$([^\$]+)\$/';
- const DYNAMIC_TOKEN = '`!`';
-
- /**
- * Parse the sql text for dynamic place holders of the form $name$.
- * @param string Sql text.
- * @return array name value pairs 'sql' and 'parameters'.
- */
- public function parse($sqlText)
- {
- $matches = array();
- $mappings = array();
- preg_match_all(self::PARAMETER_TOKEN_REGEXP, $sqlText, $matches);
- for($i = 0, $k=count($matches[1]); $i<$k; $i++)
- {
- $mappings[] = $matches[1][$i];
- $sqlText = str_replace($matches[0][$i], self::DYNAMIC_TOKEN, $sqlText);
- }
- return array('sql'=>$sqlText, 'parameters'=>$mappings);
- }
-}
-
+ * @license http://www.pradosoft.com/license/
+ * @version $Id$
+ * @package System.Data.SqlMap.Configuration
+ */
+
+/**
+ * TSimpleDynamicParser finds place holders $name$ in the sql text and replaces
+ * it with a TSimpleDynamicParser::DYNAMIC_TOKEN.
+ *
+ * @author Wei Zhuo <weizho[at]gmail[dot]com>
+ * @version $Id$
+ * @package System.Data.SqlMap.Configuration
+ * @since 3.1
+ */
+class TSimpleDynamicParser
+{
+ const PARAMETER_TOKEN_REGEXP = '/\$([^\$]+)\$/';
+ const DYNAMIC_TOKEN = '`!`';
+
+ /**
+ * Parse the sql text for dynamic place holders of the form $name$.
+ * @param string Sql text.
+ * @return array name value pairs 'sql' and 'parameters'.
+ */
+ public function parse($sqlText)
+ {
+ $matches = array();
+ $mappings = array();
+ preg_match_all(self::PARAMETER_TOKEN_REGEXP, $sqlText, $matches);
+ for($i = 0, $k=count($matches[1]); $i<$k; $i++)
+ {
+ $mappings[] = $matches[1][$i];
+ $sqlText = str_replace($matches[0][$i], self::DYNAMIC_TOKEN, $sqlText);
+ }
+ return array('sql'=>$sqlText, 'parameters'=>$mappings);
+ }
+}
+
diff --git a/framework/Data/SqlMap/Configuration/TSqlMapCacheModel.php b/framework/Data/SqlMap/Configuration/TSqlMapCacheModel.php
index 4b985e51..0dc5d821 100644
--- a/framework/Data/SqlMap/Configuration/TSqlMapCacheModel.php
+++ b/framework/Data/SqlMap/Configuration/TSqlMapCacheModel.php
@@ -1,246 +1,246 @@
-<?php
-/**
- * TSqlMapCacheModel, TSqlMapCacheTypes and TSqlMapCacheKey classes file.
- *
- * @author Wei Zhuo <weizhuo[at]gmail[dot]com>
- * @link http://www.pradosoft.com/
- * @copyright Copyright &copy; 2005-2012 PradoSoft
- * @license http://www.pradosoft.com/license/
- * @version $Id$
- * @package System.Data.SqlMap.Configuration
- */
-
-/**
- * TSqlMapCacheModel corresponds to the <cacheModel> sql mapping configuration tag.
- *
- * The results from a query Mapped Statement can be cached simply by specifying
- * the {@link CacheModel TSqlMapStatement::setCacheModel()} property in <statement> tag.
- * A cache model is a configured cache that is defined within the sql map
- * configuration file. Cache models are configured using the <cacheModel> element.
- *
- * The cache model uses a pluggable framework for supporting different types of
- * caches. The choice of cache is specified by the {@link Implementation setImplementation()}
- * property. The class name specified must be one of {@link TSqlMapCacheTypes}.
- *
- * The cache implementations, LRU and FIFO cache below do not persist across
- * requests. That is, once the request is complete, all cache data is lost.
- * These caches are useful queries that results in the same repeated data during
- * the current request.
- *
- * @author Wei Zhuo <weizho[at]gmail[dot]com>
- * @version $Id$
- * @package System.Data.SqlMap.Configuration
- * @since 3.1
- */
-class TSqlMapCacheModel extends TComponent
-{
- private $_cache;
- private $_hits = 0;
- private $_requests = 0;
- private $_id;
- private $_implementation=TSqlMapCacheTypes::Basic;
- private $_properties = array();
- private $_flushInterval = 0;
-
- private static $_cacheTypes = array();
-
- public static function registerCacheType($type, $className)
- {
- self::$_cacheTypes[$type] = $className;
- }
-
- /**
- * @return string unique cache model identifier.
- */
- public function getID()
- {
- return $this->_id;
- }
-
- /**
- * @param string unique cache model identifier.
- */
- public function setID($value)
- {
- $this->_id = $value;
- }
-
- /**
- * @return string cache implements of TSqlMapCacheTypes, either 'Basic', 'LRU' or 'FIFO'.
- */
- public function getImplementation()
- {
- return $this->_implementation;
- }
-
- /**
- * @param string cache implements of TSqlMapCacheTypes, either 'Basic', 'LRU' or 'FIFO'.
- */
- public function setImplementation($value)
- {
- if (isset(self::$_cacheTypes[$value]))
- $this->_implementation = $value;
- else
- $this->_implementation = TPropertyValue::ensureEnum($value,'TSqlMapCacheTypes');
- }
-
- /**
- * @param integer the number of seconds in which the cached value will expire. 0 means never expire.
- */
- public function setFlushInterval($value)
- {
- $this->_flushInterval=TPropertyValue::ensureInteger($value);
- }
-
- /**
- * @return integer cache duration.
- */
- public function getFlushInterval()
- {
- return $this->_flushInterval;
- }
-
- /**
- * Initialize the cache implementation, sets the actual cache contain if supplied.
- * @param ISqLMapCache cache implementation instance.
- */
- public function initialize($cache=null)
- {
- if($cache===null)
- $this->_cache= Prado::createComponent($this->getImplementationClass(), $this);
- else
- $this->_cache=$cache;
- }
-
- /**
- * @return string cache implementation class name.
- */
- public function getImplementationClass()
- {
- $implementation = $this->_implementation;
- if (isset(self::$_cacheTypes[$implementation])) return self::$_cacheTypes[$implementation];
-
- switch(TPropertyValue::ensureEnum($implementation,'TSqlMapCacheTypes'))
- {
- case TSqlMapCacheTypes::FIFO: return 'TSqlMapFifoCache';
- case TSqlMapCacheTypes::LRU : return 'TSqlMapLruCache';
- case TSqlMapCacheTypes::Basic : return 'TSqlMapApplicationCache';
- }
- }
-
- /**
- * Register a mapped statement that will trigger a cache flush.
- * @param TMappedStatement mapped statement that may flush the cache.
- */
- public function registerTriggerStatement($mappedStatement)
- {
- $mappedStatement->attachEventHandler('OnExecuteQuery',array($this, 'flush'));
- }
-
- /**
- * Clears the cache.
- */
- public function flush()
- {
- $this->_cache->flush();
- }
-
- /**
- * @param TSqlMapCacheKey|string cache key
- * @return mixed cached value.
- */
- public function get($key)
- {
- if($key instanceof TSqlMapCacheKey)
- $key = $key->getHash();
-
- //if flush ?
- $value = $this->_cache->get($key);
- $this->_requests++;
- if($value!==null)
- $this->_hits++;
- return $value;
- }
-
- /**
- * @param TSqlMapCacheKey|string cache key
- * @param mixed value to be cached.
- */
- public function set($key, $value)
- {
- if($key instanceof TSqlMapCacheKey)
- $key = $key->getHash();
-
- if($value!==null)
- $this->_cache->set($key, $value, $this->_flushInterval);
- }
-
- /**
- * @return float cache hit ratio.
- */
- public function getHitRatio()
- {
- if($this->_requests != 0)
- return $this->_hits / $this->_requests;
- else
- return 0;
- }
-}
-
-/**
- * TSqlMapCacheTypes enumerable class.
- *
- * Implemented cache are 'Basic', 'FIFO' and 'LRU'.
- *
- * @author Wei Zhuo <weizho[at]gmail[dot]com>
- * @version $Id$
- * @package System.Data.SqlMap.Configuration
- * @since 3.1
- */
-class TSqlMapCacheTypes extends TEnumerable
-{
- const Basic='Basic';
- const FIFO='FIFO';
- const LRU='LRU';
-}
-
-/**
- * TSqlMapCacheKey class.
- *
- * Provides a hash of the object to be cached.
- *
- * @author Wei Zhuo <weizho[at]gmail[dot]com>
- * @version $Id$
- * @package System.Data.SqlMap.Configuration
- * @since 3.1
- */
-class TSqlMapCacheKey
-{
- private $_key;
-
- /**
- * @param mixed object to be cached.
- */
- public function __construct($object)
- {
- $this->_key = $this->generateKey(serialize($object));
- }
-
- /**
- * @param string serialized object
- * @return string crc32 hash of the serialized object.
- */
- protected function generateKey($string)
- {
- return sprintf('%x',crc32($string));
- }
-
- /**
- * @return string object hash.
- */
- public function getHash()
- {
- return $this->_key;
- }
-}
-
+<?php
+/**
+ * TSqlMapCacheModel, TSqlMapCacheTypes and TSqlMapCacheKey classes file.
+ *
+ * @author Wei Zhuo <weizhuo[at]gmail[dot]com>
+ * @link http://www.pradosoft.com/
+ * @copyright Copyright &copy; 2005-2012 PradoSoft
+ * @license http://www.pradosoft.com/license/
+ * @version $Id$
+ * @package System.Data.SqlMap.Configuration
+ */
+
+/**
+ * TSqlMapCacheModel corresponds to the <cacheModel> sql mapping configuration tag.
+ *
+ * The results from a query Mapped Statement can be cached simply by specifying
+ * the {@link CacheModel TSqlMapStatement::setCacheModel()} property in <statement> tag.
+ * A cache model is a configured cache that is defined within the sql map
+ * configuration file. Cache models are configured using the <cacheModel> element.
+ *
+ * The cache model uses a pluggable framework for supporting different types of
+ * caches. The choice of cache is specified by the {@link Implementation setImplementation()}
+ * property. The class name specified must be one of {@link TSqlMapCacheTypes}.
+ *
+ * The cache implementations, LRU and FIFO cache below do not persist across
+ * requests. That is, once the request is complete, all cache data is lost.
+ * These caches are useful queries that results in the same repeated data during
+ * the current request.
+ *
+ * @author Wei Zhuo <weizho[at]gmail[dot]com>
+ * @version $Id$
+ * @package System.Data.SqlMap.Configuration
+ * @since 3.1
+ */
+class TSqlMapCacheModel extends TComponent
+{
+ private $_cache;
+ private $_hits = 0;
+ private $_requests = 0;
+ private $_id;
+ private $_implementation=TSqlMapCacheTypes::Basic;
+ private $_properties = array();
+ private $_flushInterval = 0;
+
+ private static $_cacheTypes = array();
+
+ public static function registerCacheType($type, $className)
+ {
+ self::$_cacheTypes[$type] = $className;
+ }
+
+ /**
+ * @return string unique cache model identifier.
+ */
+ public function getID()
+ {
+ return $this->_id;
+ }
+
+ /**
+ * @param string unique cache model identifier.
+ */
+ public function setID($value)
+ {
+ $this->_id = $value;
+ }
+
+ /**
+ * @return string cache implements of TSqlMapCacheTypes, either 'Basic', 'LRU' or 'FIFO'.
+ */
+ public function getImplementation()
+ {
+ return $this->_implementation;
+ }
+
+ /**
+ * @param string cache implements of TSqlMapCacheTypes, either 'Basic', 'LRU' or 'FIFO'.
+ */
+ public function setImplementation($value)
+ {
+ if (isset(self::$_cacheTypes[$value]))
+ $this->_implementation = $value;
+ else
+ $this->_implementation = TPropertyValue::ensureEnum($value,'TSqlMapCacheTypes');
+ }
+
+ /**
+ * @param integer the number of seconds in which the cached value will expire. 0 means never expire.
+ */
+ public function setFlushInterval($value)
+ {
+ $this->_flushInterval=TPropertyValue::ensureInteger($value);
+ }
+
+ /**
+ * @return integer cache duration.
+ */
+ public function getFlushInterval()
+ {
+ return $this->_flushInterval;
+ }
+
+ /**
+ * Initialize the cache implementation, sets the actual cache contain if supplied.
+ * @param ISqLMapCache cache implementation instance.
+ */
+ public function initialize($cache=null)
+ {
+ if($cache===null)
+ $this->_cache= Prado::createComponent($this->getImplementationClass(), $this);
+ else
+ $this->_cache=$cache;
+ }
+
+ /**
+ * @return string cache implementation class name.
+ */
+ public function getImplementationClass()
+ {
+ $implementation = $this->_implementation;
+ if (isset(self::$_cacheTypes[$implementation])) return self::$_cacheTypes[$implementation];
+
+ switch(TPropertyValue::ensureEnum($implementation,'TSqlMapCacheTypes'))
+ {
+ case TSqlMapCacheTypes::FIFO: return 'TSqlMapFifoCache';
+ case TSqlMapCacheTypes::LRU : return 'TSqlMapLruCache';
+ case TSqlMapCacheTypes::Basic : return 'TSqlMapApplicationCache';
+ }
+ }
+
+ /**
+ * Register a mapped statement that will trigger a cache flush.
+ * @param TMappedStatement mapped statement that may flush the cache.
+ */
+ public function registerTriggerStatement($mappedStatement)
+ {
+ $mappedStatement->attachEventHandler('OnExecuteQuery',array($this, 'flush'));
+ }
+
+ /**
+ * Clears the cache.
+ */
+ public function flush()
+ {
+ $this->_cache->flush();
+ }
+
+ /**
+ * @param TSqlMapCacheKey|string cache key
+ * @return mixed cached value.
+ */
+ public function get($key)
+ {
+ if($key instanceof TSqlMapCacheKey)
+ $key = $key->getHash();
+
+ //if flush ?
+ $value = $this->_cache->get($key);
+ $this->_requests++;
+ if($value!==null)
+ $this->_hits++;
+ return $value;
+ }
+
+ /**
+ * @param TSqlMapCacheKey|string cache key
+ * @param mixed value to be cached.
+ */
+ public function set($key, $value)
+ {
+ if($key instanceof TSqlMapCacheKey)
+ $key = $key->getHash();
+
+ if($value!==null)
+ $this->_cache->set($key, $value, $this->_flushInterval);
+ }
+
+ /**
+ * @return float cache hit ratio.
+ */
+ public function getHitRatio()
+ {
+ if($this->_requests != 0)
+ return $this->_hits / $this->_requests;
+ else
+ return 0;
+ }
+}
+
+/**
+ * TSqlMapCacheTypes enumerable class.
+ *
+ * Implemented cache are 'Basic', 'FIFO' and 'LRU'.
+ *
+ * @author Wei Zhuo <weizho[at]gmail[dot]com>
+ * @version $Id$
+ * @package System.Data.SqlMap.Configuration
+ * @since 3.1
+ */
+class TSqlMapCacheTypes extends TEnumerable
+{
+ const Basic='Basic';
+ const FIFO='FIFO';
+ const LRU='LRU';
+}
+
+/**
+ * TSqlMapCacheKey class.
+ *
+ * Provides a hash of the object to be cached.
+ *
+ * @author Wei Zhuo <weizho[at]gmail[dot]com>
+ * @version $Id$
+ * @package System.Data.SqlMap.Configuration
+ * @since 3.1
+ */
+class TSqlMapCacheKey
+{
+ private $_key;
+
+ /**
+ * @param mixed object to be cached.
+ */
+ public function __construct($object)
+ {
+ $this->_key = $this->generateKey(serialize($object));
+ }
+
+ /**
+ * @param string serialized object
+ * @return string crc32 hash of the serialized object.
+ */
+ protected function generateKey($string)
+ {
+ return sprintf('%x',crc32($string));
+ }
+
+ /**
+ * @return string object hash.
+ */
+ public function getHash()
+ {
+ return $this->_key;
+ }
+}
+
diff --git a/framework/Data/SqlMap/Configuration/TSqlMapStatement.php b/framework/Data/SqlMap/Configuration/TSqlMapStatement.php
index 1d90d4b1..8f2ca5cc 100644
--- a/framework/Data/SqlMap/Configuration/TSqlMapStatement.php
+++ b/framework/Data/SqlMap/Configuration/TSqlMapStatement.php
@@ -1,451 +1,451 @@
-<?php
-/**
- * TSqlMapStatement, TSqlMapInsert, TSqlMapUpdate, TSqlMapDelete,
- * TSqlMapSelect and TSqlMapSelectKey classes file.
- *
- * @author Wei Zhuo <weizhuo[at]gmail[dot]com>
- * @link http://www.pradosoft.com/
- * @copyright Copyright &copy; 2005-2012 PradoSoft
- * @license http://www.pradosoft.com/license/
- * @version $Id$
- * @package System.Data.SqlMap.Configuration
- */
-
-/**
- * TSqlMapStatement class corresponds to <statement> element.
- *
- * Mapped Statements can hold any SQL statement and can use Parameter Maps
- * and Result Maps for input and output.
- *
- * The <statement> element is a general "catch all" element that can be used
- * for any type of SQL statement. Generally it is a good idea to use one of the
- * more specific statement-type elements. The more specific elements provided
- * better error-checking and even more functionality. (For example, the insert
- * statement can return a database-generated key.)
- *
- * @author Wei Zhuo <weizho[at]gmail[dot]com>
- * @version $Id$
- * @package System.Data.SqlMap.Configuration
- * @since 3.1
- */
-class TSqlMapStatement extends TComponent
-{
- private $_parameterMapName;
- private $_parameterMap;
- private $_parameterClassName;
- private $_resultMapName;
- private $_resultMap;
- private $_resultClassName;
- private $_cacheModelName;
- private $_SQL;
- private $_listClass;
- private $_typeHandler;
- private $_extendStatement;
- private $_cache;
- private $_ID;
-
- /**
- * @return string name for this statement, unique to each sql map manager.
- */
- public function getID()
- {
- return $this->_ID;
- }
-
- /**
- * @param string name for this statement, which must be unique for each sql map manager.
- */
- public function setID($value)
- {
- $this->_ID=$value;
- }
-
- /**
- * @return string name of a parameter map.
- */
- public function getParameterMap()
- {
- return $this->_parameterMapName;
- }
-
- /**
- * A Parameter Map defines an ordered list of values that match up with
- * the "?" placeholders of a standard, parameterized query statement.
- * @param string parameter map name.
- */
- public function setParameterMap($value)
- {
- $this->_parameterMapName = $value;
- }
-
- /**
- * @return string parameter class name.
- */
- public function getParameterClass()
- {
- return $this->_parameterClassName;
- }
-
- /**
- * If a {@link ParameterMap setParameterMap()} property is not specified,
- * you may specify a ParameterClass instead and use inline parameters.
- * The value of the parameterClass attribute can be any existing PHP class name.
- * @param string parameter class name.
- */
- public function setParameterClass($value)
- {
- $this->_parameterClassName = $value;
- }
-
- /**
- * @return string result map name.
- */
- public function getResultMap()
- {
- return $this->_resultMapName;
- }
-
- /**
- * A Result Map lets you control how data is extracted from the result of a
- * query, and how the columns are mapped to object properties.
- * @param string result map name.
- */
- public function setResultMap($value)
- {
- $this->_resultMapName = $value;
- }
-
- /**
- * @return string result class name.
- */
- public function getResultClass()
- {
- return $this->_resultClassName;
- }
-
- /**
- * If a {@link ResultMap setResultMap()} is not specified, you may specify a
- * ResultClass instead. The value of the ResultClass property can be the
- * name of a PHP class or primitives like integer, string, or array. The
- * class specified will be automatically mapped to the columns in the
- * result, based on the result metadata.
- * @param string result class name.
- */
- public function setResultClass($value)
- {
- $this->_resultClassName = $value;
- }
-
- /**
- * @return string cache mode name.
- */
- public function getCacheModel()
- {
- return $this->_cacheModelName;
- }
-
- /**
- * @param string cache mode name.
- */
- public function setCacheModel($value)
- {
- $this->_cacheModelName = $value;
- }
-
- /**
- * @return TSqlMapCacheModel cache implementation instance for this statement.
- */
- public function getCache()
- {
- return $this->_cache;
- }
-
- /**
- * @param TSqlMapCacheModel cache implementation instance for this statement.
- */
- public function setCache($value)
- {
- $this->_cache = $value;
- }
-
- /**
- * @return TStaticSql sql text container.
- */
- public function getSqlText()
- {
- return $this->_SQL;
- }
-
- /**
- * @param TStaticSql sql text container.
- */
- public function setSqlText($value)
- {
- $this->_SQL = $value;
- }
-
- /**
- * @return string name of a PHP class that implements ArrayAccess.
- */
- public function getListClass()
- {
- return $this->_listClass;
- }
-
- /**
- * An ArrayAccess class can be specified to handle the type of objects in the collection.
- * @param string name of a PHP class that implements ArrayAccess.
- */
- public function setListClass($value)
- {
- $this->_listClass = $value;
- }
-
- /**
- * @return string another statement element name.
- */
- public function getExtends()
- {
- return $this->_extendStatement;
- }
-
- /**
- * @param string name of another statement element to extend.
- */
- public function setExtends($value)
- {
- $this->_extendStatement = $value;
- }
-
- /**
- * @return TResultMap the result map corresponding to the
- * {@link ResultMap getResultMap()} property.
- */
- public function resultMap()
- {
- return $this->_resultMap;
- }
-
- /**
- * @return TParameterMap the parameter map corresponding to the
- * {@link ParameterMap getParameterMap()} property.
- */
- public function parameterMap()
- {
- return $this->_parameterMap;
- }
-
- /**
- * @param TInlineParameterMap parameter extracted from the sql text.
- */
- public function setInlineParameterMap($map)
- {
- $this->_parameterMap = $map;
- }
-
- /**
- * @param TSqlMapManager initialize the statement, sets the result and parameter maps.
- */
- public function initialize($manager)
- {
- if(strlen($this->_resultMapName) > 0)
- $this->_resultMap = $manager->getResultMap($this->_resultMapName);
- if(strlen($this->_parameterMapName) > 0)
- $this->_parameterMap = $manager->getParameterMap($this->_parameterMapName);
- }
-
- /**
- * @param TSqlMapTypeHandlerRegistry type handler registry
- * @return ArrayAccess new instance of list class.
- */
- public function createInstanceOfListClass($registry)
- {
- if(strlen($type = $this->getListClass()) > 0)
- return $this->createInstanceOf($registry,$type);
- return array();
- }
-
- /**
- * Create a new instance of a given type.
- * @param TSqlMapTypeHandlerRegistry type handler registry
- * @param string result class name.
- * @param array result data.
- * @return mixed result object.
- */
- protected function createInstanceOf($registry,$type,$row=null)
- {
- $handler = $registry->getTypeHandler($type);
- if($handler!==null)
- return $handler->createNewInstance($row);
- else
- return $registry->createInstanceOf($type);
- }
-
- /**
- * Create a new instance of result class.
- * @param TSqlMapTypeHandlerRegistry type handler registry
- * @param array result data.
- * @return mixed result object.
- */
- public function createInstanceOfResultClass($registry,$row)
- {
- if(strlen($type= $this->getResultClass()) > 0)
- return $this->createInstanceOf($registry,$type,$row);
- }
-
- public function __sleep()
- {
- $cn = __CLASS__;
- $exprops = array("\0$cn\0_resultMap");
- if (!$this->_parameterMapName) $exprops[] = "\0$cn\0_parameterMapName";
- if (!$this->_parameterMap) $exprops[] = "\0$cn\0_parameterMap";
- if (!$this->_parameterClassName) $exprops[] = "\0$cn\0_parameterClassName";
- if (!$this->_resultMapName) $exprops[] = "\0$cn\0_resultMapName";
- if (!$this->_resultMap) $exprops[] = "\0$cn\0_resultMap";
- if (!$this->_resultClassName) $exprops[] = "\0$cn\0_resultClassName";
- if (!$this->_cacheModelName) $exprops[] = "\0$cn\0_cacheModelName";
- if (!$this->_SQL) $exprops[] = "\0$cn\0_SQL";
- if (!$this->_listClass) $exprops[] = "\0$cn\0_listClass";
- if (!$this->_typeHandler) $exprops[] = "\0$cn\0_typeHandler";
- if (!$this->_extendStatement) $exprops[] = "\0$cn\0_extendStatement";
- if (!$this->_cache) $exprops[] = "\0$cn\0_cache";
-
- return array_diff(parent::__sleep(),$exprops);
- }
-
-}
-
-/**
- * TSqlMapSelect class file.
- *
- * @author Wei Zhuo <weizho[at]gmail[dot]com>
- * @version $Id$
- * @package System.Data.SqlMap.Statements
- * @since 3.1
- */
-class TSqlMapSelect extends TSqlMapStatement
-{
- private $_generate;
-
- public function getGenerate(){ return $this->_generate; }
- public function setGenerate($value){ $this->_generate = $value; }
-}
-
-/**
- * TSqlMapInsert class corresponds to the <insert> element.
- *
- * The <insert> element allows <selectKey> child elements that can be used
- * to generate a key to be used for the insert command.
- *
- * @author Wei Zhuo <weizho[at]gmail[dot]com>
- * @version $Id$
- * @package System.Data.SqlMap.Configuration
- * @since 3.1
- */
-class TSqlMapInsert extends TSqlMapStatement
-{
- private $_selectKey=null;
-
- /**
- * @return TSqlMapSelectKey select key element.
- */
- public function getSelectKey()
- {
- return $this->_selectKey;
- }
-
- /**
- * @param TSqlMapSelectKey select key.
- */
- public function setSelectKey($value)
- {
- $this->_selectKey = $value;
- }
-}
-
-/**
- * TSqlMapUpdate class corresponds to <update> element.
- *
- * @author Wei Zhuo <weizho[at]gmail[dot]com>
- * @version $Id$
- * @package System.Data.SqlMap.Configuration
- * @since 3.1
- */
-class TSqlMapUpdate extends TSqlMapStatement
-{
-}
-
-/**
- * TSqlMapDelete class corresponds to the <delete> element.
- *
- * @author Wei Zhuo <weizho[at]gmail[dot]com>
- * @version $Id$
- * @package System.Data.SqlMap.Configuration
- * @since 3.1
- */
-class TSqlMapDelete extends TSqlMapUpdate
-{
-}
-
-/**
- * TSqlMapSelect corresponds to the <selectKey> element.
- *
- * @author Wei Zhuo <weizho[at]gmail[dot]com>
- * @version $Id$
- * @package System.Data.SqlMap.Configuration
- * @since 3.1
- */
-class TSqlMapSelectKey extends TSqlMapStatement
-{
- private $_type = 'post';
- private $_property;
-
- /**
- * @return string select generated key type, 'post' or 'pre'.
- */
- public function getType()
- {
- return $this->_type;
- }
-
- /**
- * @param string select generated key type, 'post' or 'pre'.
- */
- public function setType($value)
- {
- $this->_type = strtolower($value) == 'post' ? 'post' : 'pre';
- }
-
- /**
- * @return string property name for the generated key.
- */
- public function getProperty()
- {
- return $this->_property;
- }
-
- /**
- * @param string property name for the generated key.
- */
- public function setProperty($value)
- {
- $this->_property = $value;
- }
-
- /**
- * @throws TSqlMapConfigurationException extends is unsupported.
- */
- public function setExtends($value)
- {
- throw new TSqlMapConfigurationException('sqlmap_can_not_extend_select_key');
- }
-
- /**
- * @return boolean true if key is generated after insert command, false otherwise.
- */
- public function getIsAfter()
- {
- return $this->_type == 'post';
- }
-}
-
+<?php
+/**
+ * TSqlMapStatement, TSqlMapInsert, TSqlMapUpdate, TSqlMapDelete,
+ * TSqlMapSelect and TSqlMapSelectKey classes file.
+ *
+ * @author Wei Zhuo <weizhuo[at]gmail[dot]com>
+ * @link http://www.pradosoft.com/
+ * @copyright Copyright &copy; 2005-2012 PradoSoft
+ * @license http://www.pradosoft.com/license/
+ * @version $Id$
+ * @package System.Data.SqlMap.Configuration
+ */
+
+/**
+ * TSqlMapStatement class corresponds to <statement> element.
+ *
+ * Mapped Statements can hold any SQL statement and can use Parameter Maps
+ * and Result Maps for input and output.
+ *
+ * The <statement> element is a general "catch all" element that can be used
+ * for any type of SQL statement. Generally it is a good idea to use one of the
+ * more specific statement-type elements. The more specific elements provided
+ * better error-checking and even more functionality. (For example, the insert
+ * statement can return a database-generated key.)
+ *
+ * @author Wei Zhuo <weizho[at]gmail[dot]com>
+ * @version $Id$
+ * @package System.Data.SqlMap.Configuration
+ * @since 3.1
+ */
+class TSqlMapStatement extends TComponent
+{
+ private $_parameterMapName;
+ private $_parameterMap;
+ private $_parameterClassName;
+ private $_resultMapName;
+ private $_resultMap;
+ private $_resultClassName;
+ private $_cacheModelName;
+ private $_SQL;
+ private $_listClass;
+ private $_typeHandler;
+ private $_extendStatement;
+ private $_cache;
+ private $_ID;
+
+ /**
+ * @return string name for this statement, unique to each sql map manager.
+ */
+ public function getID()
+ {
+ return $this->_ID;
+ }
+
+ /**
+ * @param string name for this statement, which must be unique for each sql map manager.
+ */
+ public function setID($value)
+ {
+ $this->_ID=$value;
+ }
+
+ /**
+ * @return string name of a parameter map.
+ */
+ public function getParameterMap()
+ {
+ return $this->_parameterMapName;
+ }
+
+ /**
+ * A Parameter Map defines an ordered list of values that match up with
+ * the "?" placeholders of a standard, parameterized query statement.
+ * @param string parameter map name.
+ */
+ public function setParameterMap($value)
+ {
+ $this->_parameterMapName = $value;
+ }
+
+ /**
+ * @return string parameter class name.
+ */
+ public function getParameterClass()
+ {
+ return $this->_parameterClassName;
+ }
+
+ /**
+ * If a {@link ParameterMap setParameterMap()} property is not specified,
+ * you may specify a ParameterClass instead and use inline parameters.
+ * The value of the parameterClass attribute can be any existing PHP class name.
+ * @param string parameter class name.
+ */
+ public function setParameterClass($value)
+ {
+ $this->_parameterClassName = $value;
+ }
+
+ /**
+ * @return string result map name.
+ */
+ public function getResultMap()
+ {
+ return $this->_resultMapName;
+ }
+
+ /**
+ * A Result Map lets you control how data is extracted from the result of a
+ * query, and how the columns are mapped to object properties.
+ * @param string result map name.
+ */
+ public function setResultMap($value)
+ {
+ $this->_resultMapName = $value;
+ }
+
+ /**
+ * @return string result class name.
+ */
+ public function getResultClass()
+ {
+ return $this->_resultClassName;
+ }
+
+ /**
+ * If a {@link ResultMap setResultMap()} is not specified, you may specify a
+ * ResultClass instead. The value of the ResultClass property can be the
+ * name of a PHP class or primitives like integer, string, or array. The
+ * class specified will be automatically mapped to the columns in the
+ * result, based on the result metadata.
+ * @param string result class name.
+ */
+ public function setResultClass($value)
+ {
+ $this->_resultClassName = $value;
+ }
+
+ /**
+ * @return string cache mode name.
+ */
+ public function getCacheModel()
+ {
+ return $this->_cacheModelName;
+ }
+
+ /**
+ * @param string cache mode name.
+ */
+ public function setCacheModel($value)
+ {
+ $this->_cacheModelName = $value;
+ }
+
+ /**
+ * @return TSqlMapCacheModel cache implementation instance for this statement.
+ */
+ public function getCache()
+ {
+ return $this->_cache;
+ }
+
+ /**
+ * @param TSqlMapCacheModel cache implementation instance for this statement.
+ */
+ public function setCache($value)
+ {
+ $this->_cache = $value;
+ }
+
+ /**
+ * @return TStaticSql sql text container.
+ */
+ public function getSqlText()
+ {
+ return $this->_SQL;
+ }
+
+ /**
+ * @param TStaticSql sql text container.
+ */
+ public function setSqlText($value)
+ {
+ $this->_SQL = $value;
+ }
+
+ /**
+ * @return string name of a PHP class that implements ArrayAccess.
+ */
+ public function getListClass()
+ {
+ return $this->_listClass;
+ }
+
+ /**
+ * An ArrayAccess class can be specified to handle the type of objects in the collection.
+ * @param string name of a PHP class that implements ArrayAccess.
+ */
+ public function setListClass($value)
+ {
+ $this->_listClass = $value;
+ }
+
+ /**
+ * @return string another statement element name.
+ */
+ public function getExtends()
+ {
+ return $this->_extendStatement;
+ }
+
+ /**
+ * @param string name of another statement element to extend.
+ */
+ public function setExtends($value)
+ {
+ $this->_extendStatement = $value;
+ }
+
+ /**
+ * @return TResultMap the result map corresponding to the
+ * {@link ResultMap getResultMap()} property.
+ */
+ public function resultMap()
+ {
+ return $this->_resultMap;
+ }
+
+ /**
+ * @return TParameterMap the parameter map corresponding to the
+ * {@link ParameterMap getParameterMap()} property.
+ */
+ public function parameterMap()
+ {
+ return $this->_parameterMap;
+ }
+
+ /**
+ * @param TInlineParameterMap parameter extracted from the sql text.
+ */
+ public function setInlineParameterMap($map)
+ {
+ $this->_parameterMap = $map;
+ }
+
+ /**
+ * @param TSqlMapManager initialize the statement, sets the result and parameter maps.
+ */
+ public function initialize($manager)
+ {
+ if(strlen($this->_resultMapName) > 0)
+ $this->_resultMap = $manager->getResultMap($this->_resultMapName);
+ if(strlen($this->_parameterMapName) > 0)
+ $this->_parameterMap = $manager->getParameterMap($this->_parameterMapName);
+ }
+
+ /**
+ * @param TSqlMapTypeHandlerRegistry type handler registry
+ * @return ArrayAccess new instance of list class.
+ */
+ public function createInstanceOfListClass($registry)
+ {
+ if(strlen($type = $this->getListClass()) > 0)
+ return $this->createInstanceOf($registry,$type);
+ return array();
+ }
+
+ /**
+ * Create a new instance of a given type.
+ * @param TSqlMapTypeHandlerRegistry type handler registry
+ * @param string result class name.
+ * @param array result data.
+ * @return mixed result object.
+ */
+ protected function createInstanceOf($registry,$type,$row=null)
+ {
+ $handler = $registry->getTypeHandler($type);
+ if($handler!==null)
+ return $handler->createNewInstance($row);
+ else
+ return $registry->createInstanceOf($type);
+ }
+
+ /**
+ * Create a new instance of result class.
+ * @param TSqlMapTypeHandlerRegistry type handler registry
+ * @param array result data.
+ * @return mixed result object.
+ */
+ public function createInstanceOfResultClass($registry,$row)
+ {
+ if(strlen($type= $this->getResultClass()) > 0)
+ return $this->createInstanceOf($registry,$type,$row);
+ }
+
+ public function __sleep()
+ {
+ $cn = __CLASS__;
+ $exprops = array("\0$cn\0_resultMap");
+ if (!$this->_parameterMapName) $exprops[] = "\0$cn\0_parameterMapName";
+ if (!$this->_parameterMap) $exprops[] = "\0$cn\0_parameterMap";
+ if (!$this->_parameterClassName) $exprops[] = "\0$cn\0_parameterClassName";
+ if (!$this->_resultMapName) $exprops[] = "\0$cn\0_resultMapName";
+ if (!$this->_resultMap) $exprops[] = "\0$cn\0_resultMap";
+ if (!$this->_resultClassName) $exprops[] = "\0$cn\0_resultClassName";
+ if (!$this->_cacheModelName) $exprops[] = "\0$cn\0_cacheModelName";
+ if (!$this->_SQL) $exprops[] = "\0$cn\0_SQL";
+ if (!$this->_listClass) $exprops[] = "\0$cn\0_listClass";
+ if (!$this->_typeHandler) $exprops[] = "\0$cn\0_typeHandler";
+ if (!$this->_extendStatement) $exprops[] = "\0$cn\0_extendStatement";
+ if (!$this->_cache) $exprops[] = "\0$cn\0_cache";
+
+ return array_diff(parent::__sleep(),$exprops);
+ }
+
+}
+
+/**
+ * TSqlMapSelect class file.
+ *
+ * @author Wei Zhuo <weizho[at]gmail[dot]com>
+ * @version $Id$
+ * @package System.Data.SqlMap.Statements
+ * @since 3.1
+ */
+class TSqlMapSelect extends TSqlMapStatement
+{
+ private $_generate;
+
+ public function getGenerate(){ return $this->_generate; }
+ public function setGenerate($value){ $this->_generate = $value; }
+}
+
+/**
+ * TSqlMapInsert class corresponds to the <insert> element.
+ *
+ * The <insert> element allows <selectKey> child elements that can be used
+ * to generate a key to be used for the insert command.
+ *
+ * @author Wei Zhuo <weizho[at]gmail[dot]com>
+ * @version $Id$
+ * @package System.Data.SqlMap.Configuration
+ * @since 3.1
+ */
+class TSqlMapInsert extends TSqlMapStatement
+{
+ private $_selectKey=null;
+
+ /**
+ * @return TSqlMapSelectKey select key element.
+ */
+ public function getSelectKey()
+ {
+ return $this->_selectKey;
+ }
+
+ /**
+ * @param TSqlMapSelectKey select key.
+ */
+ public function setSelectKey($value)
+ {
+ $this->_selectKey = $value;
+ }
+}
+
+/**
+ * TSqlMapUpdate class corresponds to <update> element.
+ *
+ * @author Wei Zhuo <weizho[at]gmail[dot]com>
+ * @version $Id$
+ * @package System.Data.SqlMap.Configuration
+ * @since 3.1
+ */
+class TSqlMapUpdate extends TSqlMapStatement
+{
+}
+
+/**
+ * TSqlMapDelete class corresponds to the <delete> element.
+ *
+ * @author Wei Zhuo <weizho[at]gmail[dot]com>
+ * @version $Id$
+ * @package System.Data.SqlMap.Configuration
+ * @since 3.1
+ */
+class TSqlMapDelete extends TSqlMapUpdate
+{
+}
+
+/**
+ * TSqlMapSelect corresponds to the <selectKey> element.
+ *
+ * @author Wei Zhuo <weizho[at]gmail[dot]com>
+ * @version $Id$
+ * @package System.Data.SqlMap.Configuration
+ * @since 3.1
+ */
+class TSqlMapSelectKey extends TSqlMapStatement
+{
+ private $_type = 'post';
+ private $_property;
+
+ /**
+ * @return string select generated key type, 'post' or 'pre'.
+ */
+ public function getType()
+ {
+ return $this->_type;
+ }
+
+ /**
+ * @param string select generated key type, 'post' or 'pre'.
+ */
+ public function setType($value)
+ {
+ $this->_type = strtolower($value) == 'post' ? 'post' : 'pre';
+ }
+
+ /**
+ * @return string property name for the generated key.
+ */
+ public function getProperty()
+ {
+ return $this->_property;
+ }
+
+ /**
+ * @param string property name for the generated key.
+ */
+ public function setProperty($value)
+ {
+ $this->_property = $value;
+ }
+
+ /**
+ * @throws TSqlMapConfigurationException extends is unsupported.
+ */
+ public function setExtends($value)
+ {
+ throw new TSqlMapConfigurationException('sqlmap_can_not_extend_select_key');
+ }
+
+ /**
+ * @return boolean true if key is generated after insert command, false otherwise.
+ */
+ public function getIsAfter()
+ {
+ return $this->_type == 'post';
+ }
+}
+
diff --git a/framework/Data/SqlMap/Configuration/TSqlMapXmlConfiguration.php b/framework/Data/SqlMap/Configuration/TSqlMapXmlConfiguration.php
index a60827fe..988d00db 100644
--- a/framework/Data/SqlMap/Configuration/TSqlMapXmlConfiguration.php
+++ b/framework/Data/SqlMap/Configuration/TSqlMapXmlConfiguration.php
@@ -1,805 +1,805 @@
-<?php
-/**
- * TSqlMapXmlConfigBuilder, TSqlMapXmlConfiguration, TSqlMapXmlMappingConfiguration classes file.
- *
- * @author Wei Zhuo <weizhuo[at]gmail[dot]com>
- * @link http://www.pradosoft.com/
- * @copyright Copyright &copy; 2005-2012 PradoSoft
- * @license http://www.pradosoft.com/license/
- * @version $Id$
- * @package System.Data.SqlMap.Configuration
- */
-
-Prado::using('System.Data.SqlMap.Configuration.TSqlMapStatement');
-
-/**
- * TSqlMapXmlConfig class file.
- *
- * @author Wei Zhuo <weizhuo[at]gmail[dot]com>
- * @version $Id$
- * @package System.Data.SqlMap.Configuration
- */
-abstract class TSqlMapXmlConfigBuilder
-{
- /**
- * Create an instance of an object give by the attribute named 'class' in the
- * node and set the properties on the object given by attribute names and values.
- * @param SimpleXmlNode property node
- * @return Object new instance of class with class name given by 'class' attribute value.
- */
- protected function createObjectFromNode($node)
- {
- if(isset($node['class']))
- {
- $obj = Prado::createComponent((string)$node['class']);
- $this->setObjectPropFromNode($obj,$node,array('class'));
- return $obj;
- }
- throw new TSqlMapConfigurationException(
- 'sqlmap_node_class_undef', $node, $this->getConfigFile());
- }
-
- /**
- * For each attributes (excluding attribute named in $except) set the
- * property of the $obj given by the name of the attribute with the value
- * of the attribute.
- * @param Object object instance
- * @param SimpleXmlNode property node
- * @param array exception property name
- */
- protected function setObjectPropFromNode($obj,$node,$except=array())
- {
- foreach($node->attributes() as $name=>$value)
- {
- if(!in_array($name,$except))
- {
- if($obj->canSetProperty($name))
- $obj->{$name} = (string)$value;
- else
- throw new TSqlMapConfigurationException(
- 'sqlmap_invalid_property', $name, get_class($obj),
- $node, $this->getConfigFile());
- }
- }
- }
-
- /**
- * Gets the filename relative to the basefile.
- * @param string base filename
- * @param string relative filename
- * @return string absolute filename.
- */
- protected function getAbsoluteFilePath($basefile,$resource)
- {
- $basedir = dirname($basefile);
- $file = realpath($basedir.DIRECTORY_SEPARATOR.$resource);
- if(!is_string($file) || !is_file($file))
- $file = realpath($resource);
- if(is_string($file) && is_file($file))
- return $file;
- else
- throw new TSqlMapConfigurationException(
- 'sqlmap_unable_to_find_resource', $resource);
- }
-
- /**
- * Load document using simple xml.
- * @param string filename.
- * @return SimpleXmlElement xml document.
- */
- protected function loadXmlDocument($filename,TSqlMapXmlConfiguration $config)
- {
- if( strpos($filename, '${') !== false)
- $filename = $config->replaceProperties($filename);
-
- if(!is_file($filename))
- throw new TSqlMapConfigurationException(
- 'sqlmap_unable_to_find_config', $filename);
- return simplexml_load_string($config->replaceProperties(file_get_contents($filename)));
- }
-
- /**
- * Get element node by ID value (try for attribute name ID as case insensitive).
- * @param SimpleXmlDocument $document
- * @param string tag name.
- * @param string id value.
- * @return SimpleXmlElement node if found, null otherwise.
- */
- protected function getElementByIdValue($document, $tag, $value)
- {
- //hack to allow upper case and lower case attribute names.
- foreach(array('id','ID','Id', 'iD') as $id)
- {
- $xpath = "//{$tag}[@{$id}='{$value}']";
- foreach($document->xpath($xpath) as $node)
- return $node;
- }
- }
-
- /**
- * @return string configuration file.
- */
- protected abstract function getConfigFile();
-}
-
-/**
- * TSqlMapXmlConfig class.
- *
- * Configures the TSqlMapManager using xml configuration file.
- *
- * @author Wei Zhuo <weizho[at]gmail[dot]com>
- * @version $Id$
- * @package System.Data.SqlMap.Configuration
- * @since 3.1
- */
-class TSqlMapXmlConfiguration extends TSqlMapXmlConfigBuilder
-{
- /**
- * @var TSqlMapManager manager
- */
- private $_manager;
- /**
- * @var string configuration file.
- */
- private $_configFile;
- /**
- * @var array global properties.
- */
- private $_properties=array();
-
- /**
- * @param TSqlMapManager manager instance.
- */
- public function __construct($manager)
- {
- $this->_manager=$manager;
- }
-
- public function getManager()
- {
- return $this->_manager;
- }
-
- protected function getConfigFile()
- {
- return $this->_configFile;
- }
-
- /**
- * Configure the TSqlMapManager using the given xml file.
- * @param string SqlMap configuration xml file.
- */
- public function configure($filename=null)
- {
- $this->_configFile=$filename;
- $document = $this->loadXmlDocument($filename,$this);
-
- foreach($document->xpath('//property') as $property)
- $this->loadGlobalProperty($property);
-
- foreach($document->xpath('//typeHandler') as $handler)
- $this->loadTypeHandler($handler);
-
- foreach($document->xpath('//connection[last()]') as $conn)
- $this->loadDatabaseConnection($conn);
-
- //try to load configuration in the current config file.
- $mapping = new TSqlMapXmlMappingConfiguration($this);
- $mapping->configure($filename);
-
- foreach($document->xpath('//sqlMap') as $sqlmap)
- $this->loadSqlMappingFiles($sqlmap);
-
- $this->resolveResultMapping();
- $this->attachCacheModels();
- }
-
- /**
- * Load global replacement property.
- * @param SimpleXmlElement property node.
- */
- protected function loadGlobalProperty($node)
- {
- $this->_properties[(string)$node['name']] = (string)$node['value'];
- }
-
- /**
- * Load the type handler configurations.
- * @param SimpleXmlElement type handler node
- */
- protected function loadTypeHandler($node)
- {
- $handler = $this->createObjectFromNode($node);
- $this->_manager->getTypeHandlers()->registerTypeHandler($handler);
- }
-
- /**
- * Load the database connection tag.
- * @param SimpleXmlElement connection node.
- */
- protected function loadDatabaseConnection($node)
- {
- $conn = $this->createObjectFromNode($node);
- $this->_manager->setDbConnection($conn);
- }
-
- /**
- * Load SqlMap mapping configuration.
- * @param unknown_type $node
- */
- protected function loadSqlMappingFiles($node)
- {
- if(strlen($resource = (string)$node['resource']) > 0)
- {
- if( strpos($resource, '${') !== false)
- $resource = $this->replaceProperties($resource);
-
- $mapping = new TSqlMapXmlMappingConfiguration($this);
- $filename = $this->getAbsoluteFilePath($this->_configFile, $resource);
- $mapping->configure($filename);
- }
- }
-
- /**
- * Resolve nest result mappings.
- */
- protected function resolveResultMapping()
- {
- $maps = $this->_manager->getResultMaps();
- foreach($maps as $entry)
- {
- foreach($entry->getColumns() as $item)
- {
- $resultMap = $item->getResultMapping();
- if(strlen($resultMap) > 0)
- {
- if($maps->contains($resultMap))
- $item->setNestedResultMap($maps[$resultMap]);
- else
- throw new TSqlMapConfigurationException(
- 'sqlmap_unable_to_find_result_mapping',
- $resultMap, $this->_configFile, $entry->getID());
- }
- }
- if($entry->getDiscriminator()!==null)
- $entry->getDiscriminator()->initialize($this->_manager);
- }
- }
-
- /**
- * Set the cache for each statement having a cache model property.
- */
- protected function attachCacheModels()
- {
- foreach($this->_manager->getMappedStatements() as $mappedStatement)
- {
- if(strlen($model = $mappedStatement->getStatement()->getCacheModel()) > 0)
- {
- $cache = $this->_manager->getCacheModel($model);
- $mappedStatement->getStatement()->setCache($cache);
- }
- }
- }
-
- /**
- * Replace the place holders ${name} in text with properties the
- * corresponding global property value.
- * @param string original string.
- * @return string string with global property replacement.
- */
- public function replaceProperties($string)
- {
- foreach($this->_properties as $find => $replace)
- $string = str_replace('${'.$find.'}', $replace, $string);
- return $string;
- }
-}
-
-/**
- * Loads the statements, result maps, parameters maps from xml configuration.
- *
- * description
- *
- * @author Wei Zhuo <weizho[at]gmail[dot]com>
- * @version $Id$
- * @package System.Data.SqlMap.Configuration
- * @since 3.1
- */
-class TSqlMapXmlMappingConfiguration extends TSqlMapXmlConfigBuilder
-{
- private $_xmlConfig;
- private $_configFile;
- private $_manager;
-
- private $_document;
-
- private $_FlushOnExecuteStatements=array();
-
- /**
- * Regular expressions for escaping simple/inline parameter symbols
- */
- const SIMPLE_MARK='$';
- const INLINE_SYMBOL='#';
- const ESCAPED_SIMPLE_MARK_REGEXP='/\$\$/';
- const ESCAPED_INLINE_SYMBOL_REGEXP='/\#\#/';
- const SIMPLE_PLACEHOLDER='`!!`';
- const INLINE_PLACEHOLDER='`!!!`';
-
- /**
- * @param TSqlMapXmlConfiguration parent xml configuration.
- */
- public function __construct(TSqlMapXmlConfiguration $xmlConfig)
- {
- $this->_xmlConfig=$xmlConfig;
- $this->_manager=$xmlConfig->getManager();
- }
-
- protected function getConfigFile()
- {
- return $this->_configFile;
- }
-
- /**
- * Configure an XML mapping.
- * @param string xml mapping filename.
- */
- public function configure($filename)
- {
- $this->_configFile=$filename;
- $document = $this->loadXmlDocument($filename,$this->_xmlConfig);
- $this->_document=$document;
-
- static $bCacheDependencies;
- if($bCacheDependencies === null)
- $bCacheDependencies = Prado::getApplication()->getMode() !== TApplicationMode::Performance;
-
- if($bCacheDependencies)
- $this->_manager->getCacheDependencies()
- ->getDependencies()
- ->add(new TFileCacheDependency($filename));
-
- foreach($document->xpath('//resultMap') as $node)
- $this->loadResultMap($node);
-
- foreach($document->xpath('//parameterMap') as $node)
- $this->loadParameterMap($node);
-
- foreach($document->xpath('//statement') as $node)
- $this->loadStatementTag($node);
-
- foreach($document->xpath('//select') as $node)
- $this->loadSelectTag($node);
-
- foreach($document->xpath('//insert') as $node)
- $this->loadInsertTag($node);
-
- foreach($document->xpath('//update') as $node)
- $this->loadUpdateTag($node);
-
- foreach($document->xpath('//delete') as $node)
- $this->loadDeleteTag($node);
-
- foreach($document->xpath('//procedure') as $node)
- $this->loadProcedureTag($node);
-
- foreach($document->xpath('//cacheModel') as $node)
- $this->loadCacheModel($node);
-
- $this->registerCacheTriggers();
- }
-
- /**
- * Load the result maps.
- * @param SimpleXmlElement result map node.
- */
- protected function loadResultMap($node)
- {
- $resultMap = $this->createResultMap($node);
-
- //find extended result map.
- if(strlen($extendMap = $resultMap->getExtends()) > 0)
- {
- if(!$this->_manager->getResultMaps()->contains($extendMap))
- {
- $extendNode=$this->getElementByIdValue($this->_document,'resultMap',$extendMap);
- if($extendNode!==null)
- $this->loadResultMap($extendNode);
- }
-
- if(!$this->_manager->getResultMaps()->contains($extendMap))
- throw new TSqlMapConfigurationException(
- 'sqlmap_unable_to_find_parent_result_map', $node, $this->_configFile, $extendMap);
-
- $superMap = $this->_manager->getResultMap($extendMap);
- $resultMap->getColumns()->mergeWith($superMap->getColumns());
- }
-
- //add the result map
- if(!$this->_manager->getResultMaps()->contains($resultMap->getID()))
- $this->_manager->addResultMap($resultMap);
- }
-
- /**
- * Create a new result map and its associated result properties,
- * disciminiator and sub maps.
- * @param SimpleXmlElement result map node
- * @return TResultMap SqlMap result mapping.
- */
- protected function createResultMap($node)
- {
- $resultMap = new TResultMap();
- $this->setObjectPropFromNode($resultMap,$node);
-
- //result nodes
- foreach($node->result as $result)
- {
- $property = new TResultProperty($resultMap);
- $this->setObjectPropFromNode($property,$result);
- $resultMap->addResultProperty($property);
- }
-
- //create the discriminator
- $discriminator = null;
- if(isset($node->discriminator))
- {
- $discriminator = new TDiscriminator();
- $this->setObjectPropFromNode($discriminator, $node->discriminator);
- $discriminator->initMapping($resultMap);
- }
-
- foreach($node->xpath('subMap') as $subMapNode)
- {
- if($discriminator===null)
- throw new TSqlMapConfigurationException(
- 'sqlmap_undefined_discriminator', $node, $this->_configFile,$subMapNode);
- $subMap = new TSubMap;
- $this->setObjectPropFromNode($subMap,$subMapNode);
- $discriminator->addSubMap($subMap);
- }
-
- if($discriminator!==null)
- $resultMap->setDiscriminator($discriminator);
-
- return $resultMap;
- }
-
- /**
- * Load parameter map from xml.
- *
- * @param SimpleXmlElement parameter map node.
- */
- protected function loadParameterMap($node)
- {
- $parameterMap = $this->createParameterMap($node);
-
- if(strlen($extendMap = $parameterMap->getExtends()) > 0)
- {
- if(!$this->_manager->getParameterMaps()->contains($extendMap))
- {
- $extendNode=$this->getElementByIdValue($this->_document,'parameterMap',$extendMap);
- if($extendNode!==null)
- $this->loadParameterMap($extendNode);
- }
-
- if(!$this->_manager->getParameterMaps()->contains($extendMap))
- throw new TSqlMapConfigurationException(
- 'sqlmap_unable_to_find_parent_parameter_map', $node, $this->_configFile,$extendMap);
- $superMap = $this->_manager->getParameterMap($extendMap);
- $index = 0;
- foreach($superMap->getPropertyNames() as $propertyName)
- $parameterMap->insertProperty($index++,$superMap->getProperty($propertyName));
- }
- $this->_manager->addParameterMap($parameterMap);
- }
-
- /**
- * Create a new parameter map from xml node.
- * @param SimpleXmlElement parameter map node.
- * @return TParameterMap new parameter mapping.
- */
- protected function createParameterMap($node)
- {
- $parameterMap = new TParameterMap();
- $this->setObjectPropFromNode($parameterMap,$node);
- foreach($node->parameter as $parameter)
- {
- $property = new TParameterProperty();
- $this->setObjectPropFromNode($property,$parameter);
- $parameterMap->addProperty($property);
- }
- return $parameterMap;
- }
-
- /**
- * Load statement mapping from xml configuration file.
- * @param SimpleXmlElement statement node.
- */
- protected function loadStatementTag($node)
- {
- $statement = new TSqlMapStatement();
- $this->setObjectPropFromNode($statement,$node);
- $this->processSqlStatement($statement, $node);
- $mappedStatement = new TMappedStatement($this->_manager, $statement);
- $this->_manager->addMappedStatement($mappedStatement);
- }
-
- /**
- * Load extended SQL statements if application. Replaces global properties
- * in the sql text. Extracts inline parameter maps.
- * @param TSqlMapStatement mapped statement.
- * @param SimpleXmlElement statement node.
- */
- protected function processSqlStatement($statement, $node)
- {
- $commandText = (string)$node;
- if(strlen($extend = $statement->getExtends()) > 0)
- {
- $superNode = $this->getElementByIdValue($this->_document,'*',$extend);
- if($superNode!==null)
- $commandText = (string)$superNode . $commandText;
- else
- throw new TSqlMapConfigurationException(
- 'sqlmap_unable_to_find_parent_sql', $extend, $this->_configFile,$node);
- }
- //$commandText = $this->_xmlConfig->replaceProperties($commandText);
- $statement->initialize($this->_manager);
- $this->applyInlineParameterMap($statement, $commandText, $node);
- }
-
- /**
- * Extract inline parameter maps.
- * @param TSqlMapStatement statement object.
- * @param string sql text
- * @param SimpleXmlElement statement node.
- */
- protected function applyInlineParameterMap($statement, $sqlStatement, $node)
- {
- $scope['file'] = $this->_configFile;
- $scope['node'] = $node;
-
- $sqlStatement=preg_replace(self::ESCAPED_INLINE_SYMBOL_REGEXP,self::INLINE_PLACEHOLDER,$sqlStatement);
- if($statement->parameterMap() === null)
- {
- // Build a Parametermap with the inline parameters.
- // if they exist. Then delete inline infos from sqltext.
- $parameterParser = new TInlineParameterMapParser;
- $sqlText = $parameterParser->parse($sqlStatement, $scope);
- if(count($sqlText['parameters']) > 0)
- {
- $map = new TParameterMap();
- $map->setID($statement->getID().'-InLineParameterMap');
- $statement->setInlineParameterMap($map);
- foreach($sqlText['parameters'] as $property)
- $map->addProperty($property);
- }
- $sqlStatement = $sqlText['sql'];
- }
- $sqlStatement=preg_replace('/'.self::INLINE_PLACEHOLDER.'/',self::INLINE_SYMBOL,$sqlStatement);
-
- $this->prepareSql($statement, $sqlStatement, $node);
- }
-
- /**
- * Prepare the sql text (may extend to dynamic sql).
- * @param TSqlMapStatement mapped statement.
- * @param string sql text.
- * @param SimpleXmlElement statement node.
- * @todo Extend to dynamic sql.
- */
- protected function prepareSql($statement,$sqlStatement, $node)
- {
- $simpleDynamic = new TSimpleDynamicParser;
- $sqlStatement=preg_replace(self::ESCAPED_SIMPLE_MARK_REGEXP,self::SIMPLE_PLACEHOLDER,$sqlStatement);
- $dynamics = $simpleDynamic->parse($sqlStatement);
- if(count($dynamics['parameters']) > 0)
- {
- $sql = new TSimpleDynamicSql($dynamics['parameters']);
- $sqlStatement = $dynamics['sql'];
- }
- else
- $sql = new TStaticSql();
- $sqlStatement=preg_replace('/'.self::SIMPLE_PLACEHOLDER.'/',self::SIMPLE_MARK,$sqlStatement);
- $sql->buildPreparedStatement($statement, $sqlStatement);
- $statement->setSqlText($sql);
- }
-
- /**
- * Load select statement from xml mapping.
- * @param SimpleXmlElement select node.
- */
- protected function loadSelectTag($node)
- {
- $select = new TSqlMapSelect;
- $this->setObjectPropFromNode($select,$node);
- $this->processSqlStatement($select,$node);
- $mappedStatement = new TMappedStatement($this->_manager, $select);
- if(strlen($select->getCacheModel()) > 0)
- $mappedStatement = new TCachingStatement($mappedStatement);
-
- $this->_manager->addMappedStatement($mappedStatement);
- }
-
- /**
- * Load insert statement from xml mapping.
- * @param SimpleXmlElement insert node.
- */
- protected function loadInsertTag($node)
- {
- $insert = $this->createInsertStatement($node);
- $this->processSqlStatement($insert, $node);
- $mappedStatement = new TInsertMappedStatement($this->_manager, $insert);
- $this->_manager->addMappedStatement($mappedStatement);
- }
-
- /**
- * Create new insert statement from xml node.
- * @param SimpleXmlElement insert node.
- * @return TSqlMapInsert insert statement.
- */
- protected function createInsertStatement($node)
- {
- $insert = new TSqlMapInsert;
- $this->setObjectPropFromNode($insert,$node);
- if(isset($node->selectKey))
- $this->loadSelectKeyTag($insert,$node->selectKey);
- return $insert;
- }
-
- /**
- * Load the selectKey statement from xml mapping.
- * @param SimpleXmlElement selectkey node
- */
- protected function loadSelectKeyTag($insert, $node)
- {
- $selectKey = new TSqlMapSelectKey;
- $this->setObjectPropFromNode($selectKey,$node);
- $selectKey->setID($insert->getID());
- $selectKey->setID($insert->getID().'.SelectKey');
- $this->processSqlStatement($selectKey,$node);
- $insert->setSelectKey($selectKey);
- $mappedStatement = new TMappedStatement($this->_manager, $selectKey);
- $this->_manager->addMappedStatement($mappedStatement);
- }
-
- /**
- * Load update statement from xml mapping.
- * @param SimpleXmlElement update node.
- */
- protected function loadUpdateTag($node)
- {
- $update = new TSqlMapUpdate;
- $this->setObjectPropFromNode($update,$node);
- $this->processSqlStatement($update, $node);
- $mappedStatement = new TUpdateMappedStatement($this->_manager, $update);
- $this->_manager->addMappedStatement($mappedStatement);
- }
-
- /**
- * Load delete statement from xml mapping.
- * @param SimpleXmlElement delete node.
- */
- protected function loadDeleteTag($node)
- {
- $delete = new TSqlMapDelete;
- $this->setObjectPropFromNode($delete,$node);
- $this->processSqlStatement($delete, $node);
- $mappedStatement = new TDeleteMappedStatement($this->_manager, $delete);
- $this->_manager->addMappedStatement($mappedStatement);
- }
-
- /**
- * Load procedure statement from xml mapping.
- * @todo Implement loading procedure
- * @param SimpleXmlElement procedure node
- */
- protected function loadProcedureTag($node)
- {
- //var_dump('todo: add load procedure');
- }
-
- /**
- * Load cache models from xml mapping.
- * @param SimpleXmlElement cache node.
- */
- protected function loadCacheModel($node)
- {
- $cacheModel = new TSqlMapCacheModel;
- $properties = array('id','implementation');
- foreach($node->attributes() as $name=>$value)
- {
- if(in_array(strtolower($name), $properties))
- $cacheModel->{'set'.$name}((string)$value);
- }
- $cache = Prado::createComponent($cacheModel->getImplementationClass(), $cacheModel);
- $this->setObjectPropFromNode($cache,$node,$properties);
-
- foreach($node->xpath('property') as $propertyNode)
- {
- $name = $propertyNode->attributes()->name;
- if($name===null || $name==='') continue;
-
- $value = $propertyNode->attributes()->value;
- if($value===null || $value==='') continue;
-
- if( !TPropertyAccess::has($cache, $name) ) continue;
-
- TPropertyAccess::set($cache, $name, $value);
- }
-
- $this->loadFlushInterval($cacheModel,$node);
-
- $cacheModel->initialize($cache);
- $this->_manager->addCacheModel($cacheModel);
- foreach($node->xpath('flushOnExecute') as $flush)
- $this->loadFlushOnCache($cacheModel,$node,$flush);
- }
-
- /**
- * Load the flush interval
- * @param TSqlMapCacheModel cache model
- * @param SimpleXmlElement cache node
- */
- protected function loadFlushInterval($cacheModel, $node)
- {
- $flushInterval = $node->xpath('flushInterval');
- if($flushInterval === null || count($flushInterval) === 0) return;
- $duration = 0;
- foreach($flushInterval[0]->attributes() as $name=>$value)
- {
- switch(strToLower($name))
- {
- case 'seconds':
- $duration += (integer)$value;
- break;
- case 'minutes':
- $duration += 60 * (integer)$value;
- break;
- case 'hours':
- $duration += 3600 * (integer)$value;
- break;
- case 'days':
- $duration += 86400 * (integer)$value;
- break;
- case 'duration':
- $duration = (integer)$value;
- break 2; // switch, foreach
- }
- }
- $cacheModel->setFlushInterval($duration);
- }
-
- /**
- * Load the flush on cache properties.
- * @param TSqlMapCacheModel cache model
- * @param SimpleXmlElement parent node.
- * @param SimpleXmlElement flush node.
- */
- protected function loadFlushOnCache($cacheModel,$parent,$node)
- {
- $id = $cacheModel->getID();
- if(!isset($this->_FlushOnExecuteStatements[$id]))
- $this->_FlushOnExecuteStatements[$id] = array();
- foreach($node->attributes() as $name=>$value)
- {
- if(strtolower($name)==='statement')
- $this->_FlushOnExecuteStatements[$id][] = (string)$value;
- }
- }
-
- /**
- * Attach CacheModel to statement and register trigger statements for cache models
- */
- protected function registerCacheTriggers()
- {
- foreach($this->_FlushOnExecuteStatements as $cacheID => $statementIDs)
- {
- $cacheModel = $this->_manager->getCacheModel($cacheID);
- foreach($statementIDs as $statementID)
- {
- $statement = $this->_manager->getMappedStatement($statementID);
- $cacheModel->registerTriggerStatement($statement);
- }
- }
- }
-}
-
+<?php
+/**
+ * TSqlMapXmlConfigBuilder, TSqlMapXmlConfiguration, TSqlMapXmlMappingConfiguration classes file.
+ *
+ * @author Wei Zhuo <weizhuo[at]gmail[dot]com>
+ * @link http://www.pradosoft.com/
+ * @copyright Copyright &copy; 2005-2012 PradoSoft
+ * @license http://www.pradosoft.com/license/
+ * @version $Id$
+ * @package System.Data.SqlMap.Configuration
+ */
+
+Prado::using('System.Data.SqlMap.Configuration.TSqlMapStatement');
+
+/**
+ * TSqlMapXmlConfig class file.
+ *
+ * @author Wei Zhuo <weizhuo[at]gmail[dot]com>
+ * @version $Id$
+ * @package System.Data.SqlMap.Configuration
+ */
+abstract class TSqlMapXmlConfigBuilder
+{
+ /**
+ * Create an instance of an object give by the attribute named 'class' in the
+ * node and set the properties on the object given by attribute names and values.
+ * @param SimpleXmlNode property node
+ * @return Object new instance of class with class name given by 'class' attribute value.
+ */
+ protected function createObjectFromNode($node)
+ {
+ if(isset($node['class']))
+ {
+ $obj = Prado::createComponent((string)$node['class']);
+ $this->setObjectPropFromNode($obj,$node,array('class'));
+ return $obj;
+ }
+ throw new TSqlMapConfigurationException(
+ 'sqlmap_node_class_undef', $node, $this->getConfigFile());
+ }
+
+ /**
+ * For each attributes (excluding attribute named in $except) set the
+ * property of the $obj given by the name of the attribute with the value
+ * of the attribute.
+ * @param Object object instance
+ * @param SimpleXmlNode property node
+ * @param array exception property name
+ */
+ protected function setObjectPropFromNode($obj,$node,$except=array())
+ {
+ foreach($node->attributes() as $name=>$value)
+ {
+ if(!in_array($name,$except))
+ {
+ if($obj->canSetProperty($name))
+ $obj->{$name} = (string)$value;
+ else
+ throw new TSqlMapConfigurationException(
+ 'sqlmap_invalid_property', $name, get_class($obj),
+ $node, $this->getConfigFile());
+ }
+ }
+ }
+
+ /**
+ * Gets the filename relative to the basefile.
+ * @param string base filename
+ * @param string relative filename
+ * @return string absolute filename.
+ */
+ protected function getAbsoluteFilePath($basefile,$resource)
+ {
+ $basedir = dirname($basefile);
+ $file = realpath($basedir.DIRECTORY_SEPARATOR.$resource);
+ if(!is_string($file) || !is_file($file))
+ $file = realpath($resource);
+ if(is_string($file) && is_file($file))
+ return $file;
+ else
+ throw new TSqlMapConfigurationException(
+ 'sqlmap_unable_to_find_resource', $resource);
+ }
+
+ /**
+ * Load document using simple xml.
+ * @param string filename.
+ * @return SimpleXmlElement xml document.
+ */
+ protected function loadXmlDocument($filename,TSqlMapXmlConfiguration $config)
+ {
+ if( strpos($filename, '${') !== false)
+ $filename = $config->replaceProperties($filename);
+
+ if(!is_file($filename))
+ throw new TSqlMapConfigurationException(
+ 'sqlmap_unable_to_find_config', $filename);
+ return simplexml_load_string($config->replaceProperties(file_get_contents($filename)));
+ }
+
+ /**
+ * Get element node by ID value (try for attribute name ID as case insensitive).
+ * @param SimpleXmlDocument $document
+ * @param string tag name.
+ * @param string id value.
+ * @return SimpleXmlElement node if found, null otherwise.
+ */
+ protected function getElementByIdValue($document, $tag, $value)
+ {
+ //hack to allow upper case and lower case attribute names.
+ foreach(array('id','ID','Id', 'iD') as $id)
+ {
+ $xpath = "//{$tag}[@{$id}='{$value}']";
+ foreach($document->xpath($xpath) as $node)
+ return $node;
+ }
+ }
+
+ /**
+ * @return string configuration file.
+ */
+ protected abstract function getConfigFile();
+}
+
+/**
+ * TSqlMapXmlConfig class.
+ *
+ * Configures the TSqlMapManager using xml configuration file.
+ *
+ * @author Wei Zhuo <weizho[at]gmail[dot]com>
+ * @version $Id$
+ * @package System.Data.SqlMap.Configuration
+ * @since 3.1
+ */
+class TSqlMapXmlConfiguration extends TSqlMapXmlConfigBuilder
+{
+ /**
+ * @var TSqlMapManager manager
+ */
+ private $_manager;
+ /**
+ * @var string configuration file.
+ */
+ private $_configFile;
+ /**
+ * @var array global properties.
+ */
+ private $_properties=array();
+
+ /**
+ * @param TSqlMapManager manager instance.
+ */
+ public function __construct($manager)
+ {
+ $this->_manager=$manager;
+ }
+
+ public function getManager()
+ {
+ return $this->_manager;
+ }
+
+ protected function getConfigFile()
+ {
+ return $this->_configFile;
+ }
+
+ /**
+ * Configure the TSqlMapManager using the given xml file.
+ * @param string SqlMap configuration xml file.
+ */
+ public function configure($filename=null)
+ {
+ $this->_configFile=$filename;
+ $document = $this->loadXmlDocument($filename,$this);
+
+ foreach($document->xpath('//property') as $property)
+ $this->loadGlobalProperty($property);
+
+ foreach($document->xpath('//typeHandler') as $handler)
+ $this->loadTypeHandler($handler);
+
+ foreach($document->xpath('//connection[last()]') as $conn)
+ $this->loadDatabaseConnection($conn);
+
+ //try to load configuration in the current config file.
+ $mapping = new TSqlMapXmlMappingConfiguration($this);
+ $mapping->configure($filename);
+
+ foreach($document->xpath('//sqlMap') as $sqlmap)
+ $this->loadSqlMappingFiles($sqlmap);
+
+ $this->resolveResultMapping();
+ $this->attachCacheModels();
+ }
+
+ /**
+ * Load global replacement property.
+ * @param SimpleXmlElement property node.
+ */
+ protected function loadGlobalProperty($node)
+ {
+ $this->_properties[(string)$node['name']] = (string)$node['value'];
+ }
+
+ /**
+ * Load the type handler configurations.
+ * @param SimpleXmlElement type handler node
+ */
+ protected function loadTypeHandler($node)
+ {
+ $handler = $this->createObjectFromNode($node);
+ $this->_manager->getTypeHandlers()->registerTypeHandler($handler);
+ }
+
+ /**
+ * Load the database connection tag.
+ * @param SimpleXmlElement connection node.
+ */
+ protected function loadDatabaseConnection($node)
+ {
+ $conn = $this->createObjectFromNode($node);
+ $this->_manager->setDbConnection($conn);
+ }
+
+ /**
+ * Load SqlMap mapping configuration.
+ * @param unknown_type $node
+ */
+ protected function loadSqlMappingFiles($node)
+ {
+ if(strlen($resource = (string)$node['resource']) > 0)
+ {
+ if( strpos($resource, '${') !== false)
+ $resource = $this->replaceProperties($resource);
+
+ $mapping = new TSqlMapXmlMappingConfiguration($this);
+ $filename = $this->getAbsoluteFilePath($this->_configFile, $resource);
+ $mapping->configure($filename);
+ }
+ }
+
+ /**
+ * Resolve nest result mappings.
+ */
+ protected function resolveResultMapping()
+ {
+ $maps = $this->_manager->getResultMaps();
+ foreach($maps as $entry)
+ {
+ foreach($entry->getColumns() as $item)
+ {
+ $resultMap = $item->getResultMapping();
+ if(strlen($resultMap) > 0)
+ {
+ if($maps->contains($resultMap))
+ $item->setNestedResultMap($maps[$resultMap]);
+ else
+ throw new TSqlMapConfigurationException(
+ 'sqlmap_unable_to_find_result_mapping',
+ $resultMap, $this->_configFile, $entry->getID());
+ }
+ }
+ if($entry->getDiscriminator()!==null)
+ $entry->getDiscriminator()->initialize($this->_manager);
+ }
+ }
+
+ /**
+ * Set the cache for each statement having a cache model property.
+ */
+ protected function attachCacheModels()
+ {
+ foreach($this->_manager->getMappedStatements() as $mappedStatement)
+ {
+ if(strlen($model = $mappedStatement->getStatement()->getCacheModel()) > 0)
+ {
+ $cache = $this->_manager->getCacheModel($model);
+ $mappedStatement->getStatement()->setCache($cache);
+ }
+ }
+ }
+
+ /**
+ * Replace the place holders ${name} in text with properties the
+ * corresponding global property value.
+ * @param string original string.
+ * @return string string with global property replacement.
+ */
+ public function replaceProperties($string)
+ {
+ foreach($this->_properties as $find => $replace)
+ $string = str_replace('${'.$find.'}', $replace, $string);
+ return $string;
+ }
+}
+
+/**
+ * Loads the statements, result maps, parameters maps from xml configuration.
+ *
+ * description
+ *
+ * @author Wei Zhuo <weizho[at]gmail[dot]com>
+ * @version $Id$
+ * @package System.Data.SqlMap.Configuration
+ * @since 3.1
+ */
+class TSqlMapXmlMappingConfiguration extends TSqlMapXmlConfigBuilder
+{
+ private $_xmlConfig;
+ private $_configFile;
+ private $_manager;
+
+ private $_document;
+
+ private $_FlushOnExecuteStatements=array();
+
+ /**
+ * Regular expressions for escaping simple/inline parameter symbols
+ */
+ const SIMPLE_MARK='$';
+ const INLINE_SYMBOL='#';
+ const ESCAPED_SIMPLE_MARK_REGEXP='/\$\$/';
+ const ESCAPED_INLINE_SYMBOL_REGEXP='/\#\#/';
+ const SIMPLE_PLACEHOLDER='`!!`';
+ const INLINE_PLACEHOLDER='`!!!`';
+
+ /**
+ * @param TSqlMapXmlConfiguration parent xml configuration.
+ */
+ public function __construct(TSqlMapXmlConfiguration $xmlConfig)
+ {
+ $this->_xmlConfig=$xmlConfig;
+ $this->_manager=$xmlConfig->getManager();
+ }
+
+ protected function getConfigFile()
+ {
+ return $this->_configFile;
+ }
+
+ /**
+ * Configure an XML mapping.
+ * @param string xml mapping filename.
+ */
+ public function configure($filename)
+ {
+ $this->_configFile=$filename;
+ $document = $this->loadXmlDocument($filename,$this->_xmlConfig);
+ $this->_document=$document;
+
+ static $bCacheDependencies;
+ if($bCacheDependencies === null)
+ $bCacheDependencies = Prado::getApplication()->getMode() !== TApplicationMode::Performance;
+
+ if($bCacheDependencies)
+ $this->_manager->getCacheDependencies()
+ ->getDependencies()
+ ->add(new TFileCacheDependency($filename));
+
+ foreach($document->xpath('//resultMap') as $node)
+ $this->loadResultMap($node);
+
+ foreach($document->xpath('//parameterMap') as $node)
+ $this->loadParameterMap($node);
+
+ foreach($document->xpath('//statement') as $node)
+ $this->loadStatementTag($node);
+
+ foreach($document->xpath('//select') as $node)
+ $this->loadSelectTag($node);
+
+ foreach($document->xpath('//insert') as $node)
+ $this->loadInsertTag($node);
+
+ foreach($document->xpath('//update') as $node)
+ $this->loadUpdateTag($node);
+
+ foreach($document->xpath('//delete') as $node)
+ $this->loadDeleteTag($node);
+
+ foreach($document->xpath('//procedure') as $node)
+ $this->loadProcedureTag($node);
+
+ foreach($document->xpath('//cacheModel') as $node)
+ $this->loadCacheModel($node);
+
+ $this->registerCacheTriggers();
+ }
+
+ /**
+ * Load the result maps.
+ * @param SimpleXmlElement result map node.
+ */
+ protected function loadResultMap($node)
+ {
+ $resultMap = $this->createResultMap($node);
+
+ //find extended result map.
+ if(strlen($extendMap = $resultMap->getExtends()) > 0)
+ {
+ if(!$this->_manager->getResultMaps()->contains($extendMap))
+ {
+ $extendNode=$this->getElementByIdValue($this->_document,'resultMap',$extendMap);
+ if($extendNode!==null)
+ $this->loadResultMap($extendNode);
+ }
+
+ if(!$this->_manager->getResultMaps()->contains($extendMap))
+ throw new TSqlMapConfigurationException(
+ 'sqlmap_unable_to_find_parent_result_map', $node, $this->_configFile, $extendMap);
+
+ $superMap = $this->_manager->getResultMap($extendMap);
+ $resultMap->getColumns()->mergeWith($superMap->getColumns());
+ }
+
+ //add the result map
+ if(!$this->_manager->getResultMaps()->contains($resultMap->getID()))
+ $this->_manager->addResultMap($resultMap);
+ }
+
+ /**
+ * Create a new result map and its associated result properties,
+ * disciminiator and sub maps.
+ * @param SimpleXmlElement result map node
+ * @return TResultMap SqlMap result mapping.
+ */
+ protected function createResultMap($node)
+ {
+ $resultMap = new TResultMap();
+ $this->setObjectPropFromNode($resultMap,$node);
+
+ //result nodes
+ foreach($node->result as $result)
+ {
+ $property = new TResultProperty($resultMap);
+ $this->setObjectPropFromNode($property,$result);
+ $resultMap->addResultProperty($property);
+ }
+
+ //create the discriminator
+ $discriminator = null;
+ if(isset($node->discriminator))
+ {
+ $discriminator = new TDiscriminator();
+ $this->setObjectPropFromNode($discriminator, $node->discriminator);
+ $discriminator->initMapping($resultMap);
+ }
+
+ foreach($node->xpath('subMap') as $subMapNode)
+ {
+ if($discriminator===null)
+ throw new TSqlMapConfigurationException(
+ 'sqlmap_undefined_discriminator', $node, $this->_configFile,$subMapNode);
+ $subMap = new TSubMap;
+ $this->setObjectPropFromNode($subMap,$subMapNode);
+ $discriminator->addSubMap($subMap);
+ }
+
+ if($discriminator!==null)
+ $resultMap->setDiscriminator($discriminator);
+
+ return $resultMap;
+ }
+
+ /**
+ * Load parameter map from xml.
+ *
+ * @param SimpleXmlElement parameter map node.
+ */
+ protected function loadParameterMap($node)
+ {
+ $parameterMap = $this->createParameterMap($node);
+
+ if(strlen($extendMap = $parameterMap->getExtends()) > 0)
+ {
+ if(!$this->_manager->getParameterMaps()->contains($extendMap))
+ {
+ $extendNode=$this->getElementByIdValue($this->_document,'parameterMap',$extendMap);
+ if($extendNode!==null)
+ $this->loadParameterMap($extendNode);
+ }
+
+ if(!$this->_manager->getParameterMaps()->contains($extendMap))
+ throw new TSqlMapConfigurationException(
+ 'sqlmap_unable_to_find_parent_parameter_map', $node, $this->_configFile,$extendMap);
+ $superMap = $this->_manager->getParameterMap($extendMap);
+ $index = 0;
+ foreach($superMap->getPropertyNames() as $propertyName)
+ $parameterMap->insertProperty($index++,$superMap->getProperty($propertyName));
+ }
+ $this->_manager->addParameterMap($parameterMap);
+ }
+
+ /**
+ * Create a new parameter map from xml node.
+ * @param SimpleXmlElement parameter map node.
+ * @return TParameterMap new parameter mapping.
+ */
+ protected function createParameterMap($node)
+ {
+ $parameterMap = new TParameterMap();
+ $this->setObjectPropFromNode($parameterMap,$node);
+ foreach($node->parameter as $parameter)
+ {
+ $property = new TParameterProperty();
+ $this->setObjectPropFromNode($property,$parameter);
+ $parameterMap->addProperty($property);
+ }
+ return $parameterMap;
+ }
+
+ /**
+ * Load statement mapping from xml configuration file.
+ * @param SimpleXmlElement statement node.
+ */
+ protected function loadStatementTag($node)
+ {
+ $statement = new TSqlMapStatement();
+ $this->setObjectPropFromNode($statement,$node);
+ $this->processSqlStatement($statement, $node);
+ $mappedStatement = new TMappedStatement($this->_manager, $statement);
+ $this->_manager->addMappedStatement($mappedStatement);
+ }
+
+ /**
+ * Load extended SQL statements if application. Replaces global properties
+ * in the sql text. Extracts inline parameter maps.
+ * @param TSqlMapStatement mapped statement.
+ * @param SimpleXmlElement statement node.
+ */
+ protected function processSqlStatement($statement, $node)
+ {
+ $commandText = (string)$node;
+ if(strlen($extend = $statement->getExtends()) > 0)
+ {
+ $superNode = $this->getElementByIdValue($this->_document,'*',$extend);
+ if($superNode!==null)
+ $commandText = (string)$superNode . $commandText;
+ else
+ throw new TSqlMapConfigurationException(
+ 'sqlmap_unable_to_find_parent_sql', $extend, $this->_configFile,$node);
+ }
+ //$commandText = $this->_xmlConfig->replaceProperties($commandText);
+ $statement->initialize($this->_manager);
+ $this->applyInlineParameterMap($statement, $commandText, $node);
+ }
+
+ /**
+ * Extract inline parameter maps.
+ * @param TSqlMapStatement statement object.
+ * @param string sql text
+ * @param SimpleXmlElement statement node.
+ */
+ protected function applyInlineParameterMap($statement, $sqlStatement, $node)
+ {
+ $scope['file'] = $this->_configFile;
+ $scope['node'] = $node;
+
+ $sqlStatement=preg_replace(self::ESCAPED_INLINE_SYMBOL_REGEXP,self::INLINE_PLACEHOLDER,$sqlStatement);
+ if($statement->parameterMap() === null)
+ {
+ // Build a Parametermap with the inline parameters.
+ // if they exist. Then delete inline infos from sqltext.
+ $parameterParser = new TInlineParameterMapParser;
+ $sqlText = $parameterParser->parse($sqlStatement, $scope);
+ if(count($sqlText['parameters']) > 0)
+ {
+ $map = new TParameterMap();
+ $map->setID($statement->getID().'-InLineParameterMap');
+ $statement->setInlineParameterMap($map);
+ foreach($sqlText['parameters'] as $property)
+ $map->addProperty($property);
+ }
+ $sqlStatement = $sqlText['sql'];
+ }
+ $sqlStatement=preg_replace('/'.self::INLINE_PLACEHOLDER.'/',self::INLINE_SYMBOL,$sqlStatement);
+
+ $this->prepareSql($statement, $sqlStatement, $node);
+ }
+
+ /**
+ * Prepare the sql text (may extend to dynamic sql).
+ * @param TSqlMapStatement mapped statement.
+ * @param string sql text.
+ * @param SimpleXmlElement statement node.
+ * @todo Extend to dynamic sql.
+ */
+ protected function prepareSql($statement,$sqlStatement, $node)
+ {
+ $simpleDynamic = new TSimpleDynamicParser;
+ $sqlStatement=preg_replace(self::ESCAPED_SIMPLE_MARK_REGEXP,self::SIMPLE_PLACEHOLDER,$sqlStatement);
+ $dynamics = $simpleDynamic->parse($sqlStatement);
+ if(count($dynamics['parameters']) > 0)
+ {
+ $sql = new TSimpleDynamicSql($dynamics['parameters']);
+ $sqlStatement = $dynamics['sql'];
+ }
+ else
+ $sql = new TStaticSql();
+ $sqlStatement=preg_replace('/'.self::SIMPLE_PLACEHOLDER.'/',self::SIMPLE_MARK,$sqlStatement);
+ $sql->buildPreparedStatement($statement, $sqlStatement);
+ $statement->setSqlText($sql);
+ }
+
+ /**
+ * Load select statement from xml mapping.
+ * @param SimpleXmlElement select node.
+ */
+ protected function loadSelectTag($node)
+ {
+ $select = new TSqlMapSelect;
+ $this->setObjectPropFromNode($select,$node);
+ $this->processSqlStatement($select,$node);
+ $mappedStatement = new TMappedStatement($this->_manager, $select);
+ if(strlen($select->getCacheModel()) > 0)
+ $mappedStatement = new TCachingStatement($mappedStatement);
+
+ $this->_manager->addMappedStatement($mappedStatement);
+ }
+
+ /**
+ * Load insert statement from xml mapping.
+ * @param SimpleXmlElement insert node.
+ */
+ protected function loadInsertTag($node)
+ {
+ $insert = $this->createInsertStatement($node);
+ $this->processSqlStatement($insert, $node);
+ $mappedStatement = new TInsertMappedStatement($this->_manager, $insert);
+ $this->_manager->addMappedStatement($mappedStatement);
+ }
+
+ /**
+ * Create new insert statement from xml node.
+ * @param SimpleXmlElement insert node.
+ * @return TSqlMapInsert insert statement.
+ */
+ protected function createInsertStatement($node)
+ {
+ $insert = new TSqlMapInsert;
+ $this->setObjectPropFromNode($insert,$node);
+ if(isset($node->selectKey))
+ $this->loadSelectKeyTag($insert,$node->selectKey);
+ return $insert;
+ }
+
+ /**
+ * Load the selectKey statement from xml mapping.
+ * @param SimpleXmlElement selectkey node
+ */
+ protected function loadSelectKeyTag($insert, $node)
+ {
+ $selectKey = new TSqlMapSelectKey;
+ $this->setObjectPropFromNode($selectKey,$node);
+ $selectKey->setID($insert->getID());
+ $selectKey->setID($insert->getID().'.SelectKey');
+ $this->processSqlStatement($selectKey,$node);
+ $insert->setSelectKey($selectKey);
+ $mappedStatement = new TMappedStatement($this->_manager, $selectKey);
+ $this->_manager->addMappedStatement($mappedStatement);
+ }
+
+ /**
+ * Load update statement from xml mapping.
+ * @param SimpleXmlElement update node.
+ */
+ protected function loadUpdateTag($node)
+ {
+ $update = new TSqlMapUpdate;
+ $this->setObjectPropFromNode($update,$node);
+ $this->processSqlStatement($update, $node);
+ $mappedStatement = new TUpdateMappedStatement($this->_manager, $update);
+ $this->_manager->addMappedStatement($mappedStatement);
+ }
+
+ /**
+ * Load delete statement from xml mapping.
+ * @param SimpleXmlElement delete node.
+ */
+ protected function loadDeleteTag($node)
+ {
+ $delete = new TSqlMapDelete;
+ $this->setObjectPropFromNode($delete,$node);
+ $this->processSqlStatement($delete, $node);
+ $mappedStatement = new TDeleteMappedStatement($this->_manager, $delete);
+ $this->_manager->addMappedStatement($mappedStatement);
+ }
+
+ /**
+ * Load procedure statement from xml mapping.
+ * @todo Implement loading procedure
+ * @param SimpleXmlElement procedure node
+ */
+ protected function loadProcedureTag($node)
+ {
+ //var_dump('todo: add load procedure');
+ }
+
+ /**
+ * Load cache models from xml mapping.
+ * @param SimpleXmlElement cache node.
+ */
+ protected function loadCacheModel($node)
+ {
+ $cacheModel = new TSqlMapCacheModel;
+ $properties = array('id','implementation');
+ foreach($node->attributes() as $name=>$value)
+ {
+ if(in_array(strtolower($name), $properties))
+ $cacheModel->{'set'.$name}((string)$value);
+ }
+ $cache = Prado::createComponent($cacheModel->getImplementationClass(), $cacheModel);
+ $this->setObjectPropFromNode($cache,$node,$properties);
+
+ foreach($node->xpath('property') as $propertyNode)
+ {
+ $name = $propertyNode->attributes()->name;
+ if($name===null || $name==='') continue;
+
+ $value = $propertyNode->attributes()->value;
+ if($value===null || $value==='') continue;
+
+ if( !TPropertyAccess::has($cache, $name) ) continue;
+
+ TPropertyAccess::set($cache, $name, $value);
+ }
+
+ $this->loadFlushInterval($cacheModel,$node);
+
+ $cacheModel->initialize($cache);
+ $this->_manager->addCacheModel($cacheModel);
+ foreach($node->xpath('flushOnExecute') as $flush)
+ $this->loadFlushOnCache($cacheModel,$node,$flush);
+ }
+
+ /**
+ * Load the flush interval
+ * @param TSqlMapCacheModel cache model
+ * @param SimpleXmlElement cache node
+ */
+ protected function loadFlushInterval($cacheModel, $node)
+ {
+ $flushInterval = $node->xpath('flushInterval');
+ if($flushInterval === null || count($flushInterval) === 0) return;
+ $duration = 0;
+ foreach($flushInterval[0]->attributes() as $name=>$value)
+ {
+ switch(strToLower($name))
+ {
+ case 'seconds':
+ $duration += (integer)$value;
+ break;
+ case 'minutes':
+ $duration += 60 * (integer)$value;
+ break;
+ case 'hours':
+ $duration += 3600 * (integer)$value;
+ break;
+ case 'days':
+ $duration += 86400 * (integer)$value;
+ break;
+ case 'duration':
+ $duration = (integer)$value;
+ break 2; // switch, foreach
+ }
+ }
+ $cacheModel->setFlushInterval($duration);
+ }
+
+ /**
+ * Load the flush on cache properties.
+ * @param TSqlMapCacheModel cache model
+ * @param SimpleXmlElement parent node.
+ * @param SimpleXmlElement flush node.
+ */
+ protected function loadFlushOnCache($cacheModel,$parent,$node)
+ {
+ $id = $cacheModel->getID();
+ if(!isset($this->_FlushOnExecuteStatements[$id]))
+ $this->_FlushOnExecuteStatements[$id] = array();
+ foreach($node->attributes() as $name=>$value)
+ {
+ if(strtolower($name)==='statement')
+ $this->_FlushOnExecuteStatements[$id][] = (string)$value;
+ }
+ }
+
+ /**
+ * Attach CacheModel to statement and register trigger statements for cache models
+ */
+ protected function registerCacheTriggers()
+ {
+ foreach($this->_FlushOnExecuteStatements as $cacheID => $statementIDs)
+ {
+ $cacheModel = $this->_manager->getCacheModel($cacheID);
+ foreach($statementIDs as $statementID)
+ {
+ $statement = $this->_manager->getMappedStatement($statementID);
+ $cacheModel->registerTriggerStatement($statement);
+ }
+ }
+ }
+}
+
diff --git a/framework/Data/SqlMap/DataMapper/TFastSqlMapApplicationCache.php b/framework/Data/SqlMap/DataMapper/TFastSqlMapApplicationCache.php
index d780b413..e85c54cf 100644
--- a/framework/Data/SqlMap/DataMapper/TFastSqlMapApplicationCache.php
+++ b/framework/Data/SqlMap/DataMapper/TFastSqlMapApplicationCache.php
@@ -1,89 +1,89 @@
-<?php
-/**
- * TFastSqlMapApplicationCache class file contains Fast SqlMap cache implementation.
- *
- * @author Berczi Gabor <gabor.berczi@devworx.hu>
- * @link http://www.pradosoft.com/
- * @copyright Copyright &copy; 2005-2012 PradoSoft
- * @license http://www.pradosoft.com/license/
- * @version $Id: TFastSqlMapApplicationCache.php 2996 2011-06-20 15:24:57Z ctrlaltca@gmail.com $
- * @package System.Data.SqlMap
- */
-
-/**
- * TFastSqlMapApplicationCache class file
- *
- * Fast SqlMap result cache class with minimal-concurrency get/set and atomic flush operations
- *
- * @author Berczi Gabor <gabor.berczi@devworx.hu>
- * @version $Id: TFastSqlMapApplicationCache.php 2996 2011-06-20 15:24:57Z ctrlaltca@gmail.com $
- * @package System.Data.SqlMap
- * @since 3.2
- */
-
-class TFastSqlMapApplicationCache implements ICache
-{
- protected $_cacheModel=null;
- protected $_cache=null;
-
- public function __construct($cacheModel=null)
- {
- $this->_cacheModel = $cacheModel;
- }
-
- protected function getBaseKeyKeyName()
- {
- return 'SqlMapCacheBaseKey::'.$this->_cacheModel->getId();
- }
-
- protected function getBaseKey()
- {
- $cache = $this->getCache();
- $keyname = $this->getBaseKeyKeyName();
- $basekey = $cache->get($keyname);
- if (!$basekey)
- {
- $basekey = DxUtil::generateRandomHash(8);
- $cache->set($keyname,$basekey);
- }
- return $basekey;
- }
-
- protected function getCacheKey($key)
- {
- return $this->getBaseKey().'###'.$key;
- }
-
- public function delete($key)
- {
- $this->getCache()->delete($this->getCacheKey($key));
- }
-
- public function flush()
- {
- $this->getCache()->delete($this->getBaseKeyKeyName());
- }
-
- public function get($key)
- {
- $result = $this->getCache()->get($this->getCacheKey($key));
- return $result === false ? null : $result;
- }
-
- public function set($key, $value,$expire=0,$dependency=null)
- {
- $this->getCache()->set($this->getCacheKey($key), $value, $expire,$dependency);
- }
-
- protected function getCache()
- {
- if (!$this->_cache)
- $this->_cache = Prado::getApplication()->getCache();
- return $this->_cache;
- }
-
- public function add($id,$value,$expire=0,$dependency=null)
- {
- throw new TSqlMapException('sqlmap_use_set_to_store_cache');
- }
-}
+<?php
+/**
+ * TFastSqlMapApplicationCache class file contains Fast SqlMap cache implementation.
+ *
+ * @author Berczi Gabor <gabor.berczi@devworx.hu>
+ * @link http://www.pradosoft.com/
+ * @copyright Copyright &copy; 2005-2012 PradoSoft
+ * @license http://www.pradosoft.com/license/
+ * @version $Id: TFastSqlMapApplicationCache.php 2996 2011-06-20 15:24:57Z ctrlaltca@gmail.com $
+ * @package System.Data.SqlMap
+ */
+
+/**
+ * TFastSqlMapApplicationCache class file
+ *
+ * Fast SqlMap result cache class with minimal-concurrency get/set and atomic flush operations
+ *
+ * @author Berczi Gabor <gabor.berczi@devworx.hu>
+ * @version $Id: TFastSqlMapApplicationCache.php 2996 2011-06-20 15:24:57Z ctrlaltca@gmail.com $
+ * @package System.Data.SqlMap
+ * @since 3.2
+ */
+
+class TFastSqlMapApplicationCache implements ICache
+{
+ protected $_cacheModel=null;
+ protected $_cache=null;
+
+ public function __construct($cacheModel=null)
+ {
+ $this->_cacheModel = $cacheModel;
+ }
+
+ protected function getBaseKeyKeyName()
+ {
+ return 'SqlMapCacheBaseKey::'.$this->_cacheModel->getId();
+ }
+
+ protected function getBaseKey()
+ {
+ $cache = $this->getCache();
+ $keyname = $this->getBaseKeyKeyName();
+ $basekey = $cache->get($keyname);
+ if (!$basekey)
+ {
+ $basekey = DxUtil::generateRandomHash(8);
+ $cache->set($keyname,$basekey);
+ }
+ return $basekey;
+ }
+
+ protected function getCacheKey($key)
+ {
+ return $this->getBaseKey().'###'.$key;
+ }
+
+ public function delete($key)
+ {
+ $this->getCache()->delete($this->getCacheKey($key));
+ }
+
+ public function flush()
+ {
+ $this->getCache()->delete($this->getBaseKeyKeyName());
+ }
+
+ public function get($key)
+ {
+ $result = $this->getCache()->get($this->getCacheKey($key));
+ return $result === false ? null : $result;
+ }
+
+ public function set($key, $value,$expire=0,$dependency=null)
+ {
+ $this->getCache()->set($this->getCacheKey($key), $value, $expire,$dependency);
+ }
+
+ protected function getCache()
+ {
+ if (!$this->_cache)
+ $this->_cache = Prado::getApplication()->getCache();
+ return $this->_cache;
+ }
+
+ public function add($id,$value,$expire=0,$dependency=null)
+ {
+ throw new TSqlMapException('sqlmap_use_set_to_store_cache');
+ }
+}
diff --git a/framework/Data/SqlMap/DataMapper/TLazyLoadList.php b/framework/Data/SqlMap/DataMapper/TLazyLoadList.php
index 9b163960..8e5d8d85 100644
--- a/framework/Data/SqlMap/DataMapper/TLazyLoadList.php
+++ b/framework/Data/SqlMap/DataMapper/TLazyLoadList.php
@@ -1,144 +1,144 @@
-<?php
-/**
- * TLazyLoadList, TObjectProxy classes file.
- *
- * @author Wei Zhuo <weizhuo[at]gmail[dot]com>
- * @link http://www.pradosoft.com/
+<?php
+/**
+ * TLazyLoadList, TObjectProxy classes file.
+ *
+ * @author Wei Zhuo <weizhuo[at]gmail[dot]com>
+ * @link http://www.pradosoft.com/
* @copyright Copyright &copy; 2005-2012 PradoSoft
- * @license http://www.pradosoft.com/license/
- * @version $Id$
- * @package System.Data.SqlMap
- */
-
-/**
- * TLazyLoadList executes mapped statements when the proxy collection is first accessed.
- *
- * @author Wei Zhuo <weizho[at]gmail[dot]com>
- * @version $Id$
- * @package System.Data.SqlMap
- * @since 3.1
- */
-class TLazyLoadList
-{
- private $_param;
- private $_target;
- private $_propertyName='';
- private $_statement='';
- private $_loaded=false;
- private $_innerList;
- private $_connection;
-
- /**
- * Create a new proxy list that will execute the mapped statement when any
- * of the list's method are accessed for the first time.
- * @param TMappedStatement statement to be executed to load the data.
- * @param mixed parameter value for the statement.
- * @param object result object that contains the lazy collection.
- * @param string property of the result object to set the loaded collection.
- */
- protected function __construct($mappedStatement, $param, $target, $propertyName)
- {
- $this->_param = $param;
- $this->_target = $target;
- $this->_statement = $mappedStatement;
- $this->_connection=$mappedStatement->getManager()->getDbConnection();
- $this->_propertyName = $propertyName;
- }
-
- /**
- * Create a new instance of a lazy collection.
- * @param TMappedStatement statement to be executed to load the data.
- * @param mixed parameter value for the statement.
- * @param object result object that contains the lazy collection.
- * @param string property of the result object to set the loaded collection.
- * @return TObjectProxy proxied collection object.
- */
- public static function newInstance($mappedStatement, $param, $target, $propertyName)
- {
- $handler = new self($mappedStatement, $param, $target, $propertyName);
- $statement = $mappedStatement->getStatement();
- $registry=$mappedStatement->getManager()->getTypeHandlers();
- $list = $statement->createInstanceOfListClass($registry);
- if(!is_object($list))
- throw new TSqlMapExecutionException('sqlmap_invalid_lazyload_list',$statement->getID());
- return new TObjectProxy($handler, $list);
- }
-
- /**
- * Relay the method call to the underlying collection.
- * @param string method name.
- * @param array method parameters.
- */
- public function intercept($method, $arguments)
- {
- return call_user_func_array(array($this->_innerList, $method), $arguments);
- }
-
- /**
- * Load the data by executing the mapped statement.
- */
- protected function fetchListData()
- {
- if($this->_loaded == false)
- {
- $this->_innerList = $this->_statement->executeQueryForList($this->_connection,$this->_param);
- $this->_loaded = true;
- //replace the target property with real list
- TPropertyAccess::set($this->_target, $this->_propertyName, $this->_innerList);
- }
- }
-
- /**
- * Try to fetch the data when any of the proxy collection method is called.
- * @param string method name.
- * @return boolean true if the underlying collection has the corresponding method name.
- */
- public function hasMethod($method)
- {
- $this->fetchListData();
- if(is_object($this->_innerList))
- return in_array($method, get_class_methods($this->_innerList));
- return false;
- }
-}
-
-/**
- * TObjectProxy sets up a simple object that intercepts method calls to a
- * particular object and relays the call to handler object.
- *
- * @author Wei Zhuo <weizho[at]gmail[dot]com>
- * @version $Id$
- * @package System.Data.SqlMap
- * @since 3.1
- */
-class TObjectProxy
-{
- private $_object;
- private $_handler;
-
- /**
- * @param object handler to method calls.
- * @param object the object to by proxied.
- */
- public function __construct($handler, $object)
- {
- $this->_handler = $handler;
- $this->_object = $object;
- }
-
- /**
- * Relay the method call to the handler object (if able to be handled), otherwise
- * it calls the proxied object's method.
- * @param string method name called
- * @param array method arguments
- * @return mixed method return value.
- */
- public function __call($method,$params)
- {
- if($this->_handler->hasMethod($method))
- return $this->_handler->intercept($method, $params);
- else
- return call_user_func_array(array($this->_object, $method), $params);
- }
-}
-
+ * @license http://www.pradosoft.com/license/
+ * @version $Id$
+ * @package System.Data.SqlMap
+ */
+
+/**
+ * TLazyLoadList executes mapped statements when the proxy collection is first accessed.
+ *
+ * @author Wei Zhuo <weizho[at]gmail[dot]com>
+ * @version $Id$
+ * @package System.Data.SqlMap
+ * @since 3.1
+ */
+class TLazyLoadList
+{
+ private $_param;
+ private $_target;
+ private $_propertyName='';
+ private $_statement='';
+ private $_loaded=false;
+ private $_innerList;
+ private $_connection;
+
+ /**
+ * Create a new proxy list that will execute the mapped statement when any
+ * of the list's method are accessed for the first time.
+ * @param TMappedStatement statement to be executed to load the data.
+ * @param mixed parameter value for the statement.
+ * @param object result object that contains the lazy collection.
+ * @param string property of the result object to set the loaded collection.
+ */
+ protected function __construct($mappedStatement, $param, $target, $propertyName)
+ {
+ $this->_param = $param;
+ $this->_target = $target;
+ $this->_statement = $mappedStatement;
+ $this->_connection=$mappedStatement->getManager()->getDbConnection();
+ $this->_propertyName = $propertyName;
+ }
+
+ /**
+ * Create a new instance of a lazy collection.
+ * @param TMappedStatement statement to be executed to load the data.
+ * @param mixed parameter value for the statement.
+ * @param object result object that contains the lazy collection.
+ * @param string property of the result object to set the loaded collection.
+ * @return TObjectProxy proxied collection object.
+ */
+ public static function newInstance($mappedStatement, $param, $target, $propertyName)
+ {
+ $handler = new self($mappedStatement, $param, $target, $propertyName);
+ $statement = $mappedStatement->getStatement();
+ $registry=$mappedStatement->getManager()->getTypeHandlers();
+ $list = $statement->createInstanceOfListClass($registry);
+ if(!is_object($list))
+ throw new TSqlMapExecutionException('sqlmap_invalid_lazyload_list',$statement->getID());
+ return new TObjectProxy($handler, $list);
+ }
+
+ /**
+ * Relay the method call to the underlying collection.
+ * @param string method name.
+ * @param array method parameters.
+ */
+ public function intercept($method, $arguments)
+ {
+ return call_user_func_array(array($this->_innerList, $method), $arguments);
+ }
+
+ /**
+ * Load the data by executing the mapped statement.
+ */
+ protected function fetchListData()
+ {
+ if($this->_loaded == false)
+ {
+ $this->_innerList = $this->_statement->executeQueryForList($this->_connection,$this->_param);
+ $this->_loaded = true;
+ //replace the target property with real list
+ TPropertyAccess::set($this->_target, $this->_propertyName, $this->_innerList);
+ }
+ }
+
+ /**
+ * Try to fetch the data when any of the proxy collection method is called.
+ * @param string method name.
+ * @return boolean true if the underlying collection has the corresponding method name.
+ */
+ public function hasMethod($method)
+ {
+ $this->fetchListData();
+ if(is_object($this->_innerList))
+ return in_array($method, get_class_methods($this->_innerList));
+ return false;
+ }
+}
+
+/**
+ * TObjectProxy sets up a simple object that intercepts method calls to a
+ * particular object and relays the call to handler object.
+ *
+ * @author Wei Zhuo <weizho[at]gmail[dot]com>
+ * @version $Id$
+ * @package System.Data.SqlMap
+ * @since 3.1
+ */
+class TObjectProxy
+{
+ private $_object;
+ private $_handler;
+
+ /**
+ * @param object handler to method calls.
+ * @param object the object to by proxied.
+ */
+ public function __construct($handler, $object)
+ {
+ $this->_handler = $handler;
+ $this->_object = $object;
+ }
+
+ /**
+ * Relay the method call to the handler object (if able to be handled), otherwise
+ * it calls the proxied object's method.
+ * @param string method name called
+ * @param array method arguments
+ * @return mixed method return value.
+ */
+ public function __call($method,$params)
+ {
+ if($this->_handler->hasMethod($method))
+ return $this->_handler->intercept($method, $params);
+ else
+ return call_user_func_array(array($this->_object, $method), $params);
+ }
+}
+
diff --git a/framework/Data/SqlMap/DataMapper/TPropertyAccess.php b/framework/Data/SqlMap/DataMapper/TPropertyAccess.php
index 7445e9d8..a6a2c451 100644
--- a/framework/Data/SqlMap/DataMapper/TPropertyAccess.php
+++ b/framework/Data/SqlMap/DataMapper/TPropertyAccess.php
@@ -1,156 +1,156 @@
-<?php
-/**
- * TPropertyAccess class file.
- *
- * @author Wei Zhuo <weizhuo[at]gmail[dot]com>
- * @link http://www.pradosoft.com/
- * @copyright Copyright &copy; 2005-2012 PradoSoft
- * @license http://www.pradosoft.com/license/
- * @version $Id$
- * @package System.Data.SqlMap
- */
-
-/**
- * TPropertyAccess class provides dot notation stype property access and setting.
- *
- * Access object's properties (and subproperties) using dot path notation.
- * The following are equivalent.
- * <code>
- * echo $obj->property1;
- * echo $obj->getProperty1();
- * echo $obj['property1']; //$obj may be an array or object
- * echo TPropertyAccess($obj, 'property1');
- * </code>
- *
- * Setting a property value.
- * <code>
- * $obj1->propert1 = 'hello';
- * $obj->setProperty('hello');
- * $obj['property1'] = 'hello'; //$obj may be an array or object
- * TPropertyAccess($obj, 'property1', 'hello');
- * </code>
- *
- * Subproperties are supported using the dot notation. E.g.
- * <code>
- * echo $obj->property1->property2->property3
- * echo TPropertyAccess::get($obj, 'property1.property2.property3');
- * </code>
- *
- * @author Wei Zhuo <weizho[at]gmail[dot]com>
- * @version $Id$
- * @package System.Data.SqlMap
- * @since 3.1
- */
-class TPropertyAccess
-{
- /**
- * Gets the property value.
- * @param mixed object or path.
- * @param string property path.
- * @return mixed property value.
- * @throws TInvalidDataValueException if property path is invalid.
- */
- public static function get($object,$path)
- {
- if(!is_array($object) && !is_object($object))
- return $object;
- $properties = explode('.', $path);
- foreach($properties as $prop)
- {
- if(is_array($object) || $object instanceof ArrayAccess)
- {
- if(array_key_exists($prop, $object))
- $object = $object[$prop];
- else
- throw new TInvalidPropertyException('sqlmap_invalid_property',$path);
- }
- else if(is_object($object))
- {
- $getter = 'get'.$prop;
- if(method_exists($object, $getter) && is_callable(array($object, $getter)))
- $object = $object->{$getter}();
- else if(in_array($prop, array_keys(get_object_vars($object))))
- $object = $object->{$prop};
- elseif(method_exists($object, '__get') && is_callable(array($object, '__get')))
- $object = $object->{$prop};
- else
- throw new TInvalidPropertyException('sqlmap_invalid_property',$path);
- }
- else
- throw new TInvalidPropertyException('sqlmap_invalid_property',$path);
- }
- return $object;
- }
-
- /**
- * @param mixed object or array
- * @param string property path.
- * @return boolean true if property path is valid
- */
- public static function has($object, $path)
- {
- if(!is_array($object) && !is_object($object))
- return false;
- $properties = explode('.', $path);
- foreach($properties as $prop)
- {
- if(is_array($object) || $object instanceof ArrayAccess)
- {
- if(array_key_exists($prop, $object))
- $object = $object[$prop];
- else
- return false;
- }
- else if(is_object($object))
- {
- $getter = 'get'.$prop;
- if(method_exists($object, $getter) && is_callable(array($object, $getter)))
- $object = $object->{$getter}();
- else if(in_array($prop, array_keys(get_object_vars($object))))
- $object = $object->{$prop};
- elseif(method_exists($object, '__get') && is_callable(array($object, '__get')))
- $object = $object->{$prop};
- else
- return false;
- }
- else
- return false;
- }
- return true;
- }
-
- /**
- * Sets the property value.
- * @param mixed object or array
- * @param string property path.
- * @param mixed new property value.
- * @throws TInvalidDataValueException if property path is invalid.
- */
- public static function set(&$originalObject, $path, $value)
- {
- $properties = explode('.', $path);
- $prop = array_pop($properties);
- if(count($properties) > 0)
- $object = self::get($originalObject, implode('.',$properties));
- else
- $object = &$originalObject;
-
- if(is_array($object) || $object instanceof ArrayAccess)
- {
- $object[$prop] = $value;
- }
- else if(is_object($object))
- {
- $setter = 'set'.$prop;
- if (method_exists($object, $setter) && is_callable(array($object, $setter)))
- $object->{$setter}($value);
- else
- $object->{$prop} = $value;
- }
- else
- throw new TInvalidPropertyException('sqlmap_invalid_property_type',$path);
- }
-
-}
-
-?>
+<?php
+/**
+ * TPropertyAccess class file.
+ *
+ * @author Wei Zhuo <weizhuo[at]gmail[dot]com>
+ * @link http://www.pradosoft.com/
+ * @copyright Copyright &copy; 2005-2012 PradoSoft
+ * @license http://www.pradosoft.com/license/
+ * @version $Id$
+ * @package System.Data.SqlMap
+ */
+
+/**
+ * TPropertyAccess class provides dot notation stype property access and setting.
+ *
+ * Access object's properties (and subproperties) using dot path notation.
+ * The following are equivalent.
+ * <code>
+ * echo $obj->property1;
+ * echo $obj->getProperty1();
+ * echo $obj['property1']; //$obj may be an array or object
+ * echo TPropertyAccess($obj, 'property1');
+ * </code>
+ *
+ * Setting a property value.
+ * <code>
+ * $obj1->propert1 = 'hello';
+ * $obj->setProperty('hello');
+ * $obj['property1'] = 'hello'; //$obj may be an array or object
+ * TPropertyAccess($obj, 'property1', 'hello');
+ * </code>
+ *
+ * Subproperties are supported using the dot notation. E.g.
+ * <code>
+ * echo $obj->property1->property2->property3
+ * echo TPropertyAccess::get($obj, 'property1.property2.property3');
+ * </code>
+ *
+ * @author Wei Zhuo <weizho[at]gmail[dot]com>
+ * @version $Id$
+ * @package System.Data.SqlMap
+ * @since 3.1
+ */
+class TPropertyAccess
+{
+ /**
+ * Gets the property value.
+ * @param mixed object or path.
+ * @param string property path.
+ * @return mixed property value.
+ * @throws TInvalidDataValueException if property path is invalid.
+ */
+ public static function get($object,$path)
+ {
+ if(!is_array($object) && !is_object($object))
+ return $object;
+ $properties = explode('.', $path);
+ foreach($properties as $prop)
+ {
+ if(is_array($object) || $object instanceof ArrayAccess)
+ {
+ if(array_key_exists($prop, $object))
+ $object = $object[$prop];
+ else
+ throw new TInvalidPropertyException('sqlmap_invalid_property',$path);
+ }
+ else if(is_object($object))
+ {
+ $getter = 'get'.$prop;
+ if(method_exists($object, $getter) && is_callable(array($object, $getter)))
+ $object = $object->{$getter}();
+ else if(in_array($prop, array_keys(get_object_vars($object))))
+ $object = $object->{$prop};
+ elseif(method_exists($object, '__get') && is_callable(array($object, '__get')))
+ $object = $object->{$prop};
+ else
+ throw new TInvalidPropertyException('sqlmap_invalid_property',$path);
+ }
+ else
+ throw new TInvalidPropertyException('sqlmap_invalid_property',$path);
+ }
+ return $object;
+ }
+
+ /**
+ * @param mixed object or array
+ * @param string property path.
+ * @return boolean true if property path is valid
+ */
+ public static function has($object, $path)
+ {
+ if(!is_array($object) && !is_object($object))
+ return false;
+ $properties = explode('.', $path);
+ foreach($properties as $prop)
+ {
+ if(is_array($object) || $object instanceof ArrayAccess)
+ {
+ if(array_key_exists($prop, $object))
+ $object = $object[$prop];
+ else
+ return false;
+ }
+ else if(is_object($object))
+ {
+ $getter = 'get'.$prop;
+ if(method_exists($object, $getter) && is_callable(array($object, $getter)))
+ $object = $object->{$getter}();
+ else if(in_array($prop, array_keys(get_object_vars($object))))
+ $object = $object->{$prop};
+ elseif(method_exists($object, '__get') && is_callable(array($object, '__get')))
+ $object = $object->{$prop};
+ else
+ return false;
+ }
+ else
+ return false;
+ }
+ return true;
+ }
+
+ /**
+ * Sets the property value.
+ * @param mixed object or array
+ * @param string property path.
+ * @param mixed new property value.
+ * @throws TInvalidDataValueException if property path is invalid.
+ */
+ public static function set(&$originalObject, $path, $value)
+ {
+ $properties = explode('.', $path);
+ $prop = array_pop($properties);
+ if(count($properties) > 0)
+ $object = self::get($originalObject, implode('.',$properties));
+ else
+ $object = &$originalObject;
+
+ if(is_array($object) || $object instanceof ArrayAccess)
+ {
+ $object[$prop] = $value;
+ }
+ else if(is_object($object))
+ {
+ $setter = 'set'.$prop;
+ if (method_exists($object, $setter) && is_callable(array($object, $setter)))
+ $object->{$setter}($value);
+ else
+ $object->{$prop} = $value;
+ }
+ else
+ throw new TInvalidPropertyException('sqlmap_invalid_property_type',$path);
+ }
+
+}
+
+?>
diff --git a/framework/Data/SqlMap/DataMapper/TSqlMapCache.php b/framework/Data/SqlMap/DataMapper/TSqlMapCache.php
index db027013..4e713fea 100644
--- a/framework/Data/SqlMap/DataMapper/TSqlMapCache.php
+++ b/framework/Data/SqlMap/DataMapper/TSqlMapCache.php
@@ -1,295 +1,295 @@
-<?php
-/**
- * TSqlMapCache class file contains FIFO, LRU, and GLOBAL cache implementations.
- *
- * @author Wei Zhuo <weizhuo[at]gmail[dot]com>
- * @link http://www.pradosoft.com/
- * @copyright Copyright &copy; 2005-2012 PradoSoft
- * @license http://www.pradosoft.com/license/
- * @version $Id$
- * @package System.Data.SqlMap
- */
-
-/**
- * Allow different implementation of caching strategy. See <tt>TSqlMapFifoCache</tt>
- * for a first-in-first-out implementation. See <tt>TSqlMapLruCache</tt> for
- * a least-recently-used cache implementation.
- *
- * @author Wei Zhuo <weizhuo[at]gmail[dot]com>
- * @version $Id$
- * @package System.Data.SqlMap
- * @since 3.1
- */
-abstract class TSqlMapCache implements ICache
-{
- protected $_keyList;
- protected $_cache;
- protected $_cacheSize = 100;
- protected $_cacheModel = null;
-
- /**
- * Create a new cache with limited cache size.
- * @param TSqlMapCacheModel $cacheModel.
- */
- public function __construct($cacheModel=null)
- {
- $this->_cache = new TMap;
- $this->_keyList = new TList;
- $this->_cacheModel=$cacheModel;
- }
-
- /**
- * Maximum number of items to cache. Default size is 100.
- * @param int cache size.
- */
- public function setCacheSize($value)
- {
- $this->_cacheSize=TPropertyValue::ensureInteger($value,100);
- }
-
- /**
- * @return int cache size.
- */
- public function getCacheSize()
- {
- return $this->_cacheSize;
- }
-
- /**
- * @return object the object removed if exists, null otherwise.
- */
- public function delete($key)
- {
- $object = $this->get($key);
- $this->_cache->remove($key);
- $this->_keyList->remove($key);
- return $object;
- }
-
- /**
- * Clears the cache.
- */
- public function flush()
- {
- $this->_keyList->clear();
- $this->_cache->clear();
- }
-
- /**
- * @throws TSqlMapException not implemented.
- */
- public function add($id,$value,$expire=0,$dependency=null)
- {
- throw new TSqlMapException('sqlmap_use_set_to_store_cache');
- }
-}
-
-/**
- * First-in-First-out cache implementation, removes
- * object that was first added when the cache is full.
- *
- * @author Wei Zhuo <weizhuo[at]gmail[dot]com>
- * @version $Id$
- * @package System.Data.SqlMap
- * @since 3.1
- */
-class TSqlMapFifoCache extends TSqlMapCache
-{
- /**
- * @return mixed Gets a cached object with the specified key.
- */
- public function get($key)
- {
- return $this->_cache->itemAt($key);
- }
-
- /**
- * Stores a value identified by a key into cache.
- * The expire and dependency parameters are ignored.
- * @param string cache key
- * @param mixed value to cache.
- */
- public function set($key, $value,$expire=0,$dependency=null)
- {
- $this->_cache->add($key, $value);
- $this->_keyList->add($key);
- if($this->_keyList->getCount() > $this->_cacheSize)
- {
- $oldestKey = $this->_keyList->removeAt(0);
- $this->_cache->remove($oldestKey);
- }
- }
-}
-
-/**
- * Least recently used cache implementation, removes
- * object that was accessed last when the cache is full.
- *
- * @author Wei Zhuo <weizhuo[at]gmail[dot]com>
- * @version $Id$
- * @package System.Data.SqlMap
- * @since 3.1
- */
-class TSqlMapLruCache extends TSqlMapCache
-{
- /**
- * @return mixed Gets a cached object with the specified key.
- */
- public function get($key)
- {
- if($this->_keyList->contains($key))
- {
- $this->_keyList->remove($key);
- $this->_keyList->add($key);
- return $this->_cache->itemAt($key);
- }
- }
-
- /**
- * Stores a value identified by a key into cache.
- * The expire and dependency parameters are ignored.
- * @param string the key identifying the value to be cached
- * @param mixed the value to be cached
- */
- public function set($key, $value,$expire=0,$dependency=null)
- {
- $this->_cache->add($key, $value);
- $this->_keyList->add($key);
- if($this->_keyList->getCount() > $this->_cacheSize)
- {
- $oldestKey = $this->_keyList->removeAt(0);
- $this->_cache->remove($oldestKey);
- }
- }
-}
-
-/**
- * TSqlMapApplicationCache uses the default Prado application cache for
- * caching SqlMap results.
- *
- * @author Wei Zhuo <weizho[at]gmail[dot]com>
- * @version $Id$
- * @package System.Data.SqlMap
- * @since 3.1
- */
-class TSqlMapApplicationCache implements ICache
-{
- protected $_cacheModel=null;
-
- /**
- * Create a new cache with limited cache size.
- * @param TSqlMapCacheModel $cacheModel.
- */
- public function __construct($cacheModel=null)
- {
- $this->_cacheModel=$cacheModel;
- }
-
- /**
- *
- * @return string a KeyListID for the cache model.
- */
- protected function getKeyListId()
- {
- $id='keyList';
- if ($this->_cacheModel instanceof TSqlMapCacheModel)
- $id.='_'.$this->_cacheModel->getId();
- return $id;
- }
- /**
- * Retreive keylist from cache or create it if it doesn't exists
- * @return TList
- */
- protected function getKeyList()
- {
- if (($keyList=$this->getCache()->get($this->getKeyListId()))===false)
- {
- $keyList=new TList();
- $this->getCache()->set($this->getKeyListId(), $keyList);
- }
- return $keyList;
- }
-
- protected function setKeyList($keyList)
- {
- $this->getCache()->set($this->getKeyListId(), $keyList);
- }
-
- /**
- * @param string item to be deleted.
- */
- public function delete($key)
- {
- $keyList=$this->getKeyList();
- $keyList->remove($key);
- $this->getCache()->delete($key);
- $this->setKeyList($keyList);
- }
-
- /**
- * Deletes all items in the cache, only for data cached by sqlmap cachemodel
- */
- public function flush()
- {
- $keyList=$this->getKeyList();
- $cache=$this->getCache();
- foreach ($keyList as $key)
- {
- $cache->delete($key);
- }
- // Remove the old keylist
- $cache->delete($this->getKeyListId());
- }
-
- /**
- * @return mixed Gets a cached object with the specified key.
- */
- public function get($key)
- {
- $result = $this->getCache()->get($key);
- if ($result === false)
- {
- // if the key has not been found in cache (e.g expired), remove from keylist
- $keyList=$this->getKeyList();
- if ($keyList->contains($key))
- {
- $keyList->remove($key);
- $this->setKeyList($keyList);
- }
- }
- return $result === false ? null : $result;
- }
-
- /**
- * Stores a value identified by a key into cache.
- * @param string the key identifying the value to be cached
- * @param mixed the value to be cached
- */
- public function set($key, $value,$expire=0,$dependency=null)
- {
- $this->getCache()->set($key, $value, $expire,$dependency);
- $keyList=$this->getKeyList();
- if (!$keyList->contains($key))
- {
- $keyList->add($key);
- $this->setKeyList($keyList);
- }
- }
-
- /**
- * @return ICache Application cache instance.
- */
- protected function getCache()
- {
- return Prado::getApplication()->getCache();
- }
-
- /**
- * @throws TSqlMapException not implemented.
- */
- public function add($id,$value,$expire=0,$dependency=null)
- {
- throw new TSqlMapException('sqlmap_use_set_to_store_cache');
- }
-}
-
+<?php
+/**
+ * TSqlMapCache class file contains FIFO, LRU, and GLOBAL cache implementations.
+ *
+ * @author Wei Zhuo <weizhuo[at]gmail[dot]com>
+ * @link http://www.pradosoft.com/
+ * @copyright Copyright &copy; 2005-2012 PradoSoft
+ * @license http://www.pradosoft.com/license/
+ * @version $Id$
+ * @package System.Data.SqlMap
+ */
+
+/**
+ * Allow different implementation of caching strategy. See <tt>TSqlMapFifoCache</tt>
+ * for a first-in-first-out implementation. See <tt>TSqlMapLruCache</tt> for
+ * a least-recently-used cache implementation.
+ *
+ * @author Wei Zhuo <weizhuo[at]gmail[dot]com>
+ * @version $Id$
+ * @package System.Data.SqlMap
+ * @since 3.1
+ */
+abstract class TSqlMapCache implements ICache
+{
+ protected $_keyList;
+ protected $_cache;
+ protected $_cacheSize = 100;
+ protected $_cacheModel = null;
+
+ /**
+ * Create a new cache with limited cache size.
+ * @param TSqlMapCacheModel $cacheModel.
+ */
+ public function __construct($cacheModel=null)
+ {
+ $this->_cache = new TMap;
+ $this->_keyList = new TList;
+ $this->_cacheModel=$cacheModel;
+ }
+
+ /**
+ * Maximum number of items to cache. Default size is 100.
+ * @param int cache size.
+ */
+ public function setCacheSize($value)
+ {
+ $this->_cacheSize=TPropertyValue::ensureInteger($value,100);
+ }
+
+ /**
+ * @return int cache size.
+ */
+ public function getCacheSize()
+ {
+ return $this->_cacheSize;
+ }
+
+ /**
+ * @return object the object removed if exists, null otherwise.
+ */
+ public function delete($key)
+ {
+ $object = $this->get($key);
+ $this->_cache->remove($key);
+ $this->_keyList->remove($key);
+ return $object;
+ }
+
+ /**
+ * Clears the cache.
+ */
+ public function flush()
+ {
+ $this->_keyList->clear();
+ $this->_cache->clear();
+ }
+
+ /**
+ * @throws TSqlMapException not implemented.
+ */
+ public function add($id,$value,$expire=0,$dependency=null)
+ {
+ throw new TSqlMapException('sqlmap_use_set_to_store_cache');
+ }
+}
+
+/**
+ * First-in-First-out cache implementation, removes
+ * object that was first added when the cache is full.
+ *
+ * @author Wei Zhuo <weizhuo[at]gmail[dot]com>
+ * @version $Id$
+ * @package System.Data.SqlMap
+ * @since 3.1
+ */
+class TSqlMapFifoCache extends TSqlMapCache
+{
+ /**
+ * @return mixed Gets a cached object with the specified key.
+ */
+ public function get($key)
+ {
+ return $this->_cache->itemAt($key);
+ }
+
+ /**
+ * Stores a value identified by a key into cache.
+ * The expire and dependency parameters are ignored.
+ * @param string cache key
+ * @param mixed value to cache.
+ */
+ public function set($key, $value,$expire=0,$dependency=null)
+ {
+ $this->_cache->add($key, $value);
+ $this->_keyList->add($key);
+ if($this->_keyList->getCount() > $this->_cacheSize)
+ {
+ $oldestKey = $this->_keyList->removeAt(0);
+ $this->_cache->remove($oldestKey);
+ }
+ }
+}
+
+/**
+ * Least recently used cache implementation, removes
+ * object that was accessed last when the cache is full.
+ *
+ * @author Wei Zhuo <weizhuo[at]gmail[dot]com>
+ * @version $Id$
+ * @package System.Data.SqlMap
+ * @since 3.1
+ */
+class TSqlMapLruCache extends TSqlMapCache
+{
+ /**
+ * @return mixed Gets a cached object with the specified key.
+ */
+ public function get($key)
+ {
+ if($this->_keyList->contains($key))
+ {
+ $this->_keyList->remove($key);
+ $this->_keyList->add($key);
+ return $this->_cache->itemAt($key);
+ }
+ }
+
+ /**
+ * Stores a value identified by a key into cache.
+ * The expire and dependency parameters are ignored.
+ * @param string the key identifying the value to be cached
+ * @param mixed the value to be cached
+ */
+ public function set($key, $value,$expire=0,$dependency=null)
+ {
+ $this->_cache->add($key, $value);
+ $this->_keyList->add($key);
+ if($this->_keyList->getCount() > $this->_cacheSize)
+ {
+ $oldestKey = $this->_keyList->removeAt(0);
+ $this->_cache->remove($oldestKey);
+ }
+ }
+}
+
+/**
+ * TSqlMapApplicationCache uses the default Prado application cache for
+ * caching SqlMap results.
+ *
+ * @author Wei Zhuo <weizho[at]gmail[dot]com>
+ * @version $Id$
+ * @package System.Data.SqlMap
+ * @since 3.1
+ */
+class TSqlMapApplicationCache implements ICache
+{
+ protected $_cacheModel=null;
+
+ /**
+ * Create a new cache with limited cache size.
+ * @param TSqlMapCacheModel $cacheModel.
+ */
+ public function __construct($cacheModel=null)
+ {
+ $this->_cacheModel=$cacheModel;
+ }
+
+ /**
+ *
+ * @return string a KeyListID for the cache model.
+ */
+ protected function getKeyListId()
+ {
+ $id='keyList';
+ if ($this->_cacheModel instanceof TSqlMapCacheModel)
+ $id.='_'.$this->_cacheModel->getId();
+ return $id;
+ }
+ /**
+ * Retreive keylist from cache or create it if it doesn't exists
+ * @return TList
+ */
+ protected function getKeyList()
+ {
+ if (($keyList=$this->getCache()->get($this->getKeyListId()))===false)
+ {
+ $keyList=new TList();
+ $this->getCache()->set($this->getKeyListId(), $keyList);
+ }
+ return $keyList;
+ }
+
+ protected function setKeyList($keyList)
+ {
+ $this->getCache()->set($this->getKeyListId(), $keyList);
+ }
+
+ /**
+ * @param string item to be deleted.
+ */
+ public function delete($key)
+ {
+ $keyList=$this->getKeyList();
+ $keyList->remove($key);
+ $this->getCache()->delete($key);
+ $this->setKeyList($keyList);
+ }
+
+ /**
+ * Deletes all items in the cache, only for data cached by sqlmap cachemodel
+ */
+ public function flush()
+ {
+ $keyList=$this->getKeyList();
+ $cache=$this->getCache();
+ foreach ($keyList as $key)
+ {
+ $cache->delete($key);
+ }
+ // Remove the old keylist
+ $cache->delete($this->getKeyListId());
+ }
+
+ /**
+ * @return mixed Gets a cached object with the specified key.
+ */
+ public function get($key)
+ {
+ $result = $this->getCache()->get($key);
+ if ($result === false)
+ {
+ // if the key has not been found in cache (e.g expired), remove from keylist
+ $keyList=$this->getKeyList();
+ if ($keyList->contains($key))
+ {
+ $keyList->remove($key);
+ $this->setKeyList($keyList);
+ }
+ }
+ return $result === false ? null : $result;
+ }
+
+ /**
+ * Stores a value identified by a key into cache.
+ * @param string the key identifying the value to be cached
+ * @param mixed the value to be cached
+ */
+ public function set($key, $value,$expire=0,$dependency=null)
+ {
+ $this->getCache()->set($key, $value, $expire,$dependency);
+ $keyList=$this->getKeyList();
+ if (!$keyList->contains($key))
+ {
+ $keyList->add($key);
+ $this->setKeyList($keyList);
+ }
+ }
+
+ /**
+ * @return ICache Application cache instance.
+ */
+ protected function getCache()
+ {
+ return Prado::getApplication()->getCache();
+ }
+
+ /**
+ * @throws TSqlMapException not implemented.
+ */
+ public function add($id,$value,$expire=0,$dependency=null)
+ {
+ throw new TSqlMapException('sqlmap_use_set_to_store_cache');
+ }
+}
+
diff --git a/framework/Data/SqlMap/DataMapper/TSqlMapException.php b/framework/Data/SqlMap/DataMapper/TSqlMapException.php
index 0bf0ac32..694774d8 100644
--- a/framework/Data/SqlMap/DataMapper/TSqlMapException.php
+++ b/framework/Data/SqlMap/DataMapper/TSqlMapException.php
@@ -1,115 +1,115 @@
-<?php
-
-/**
- * TSqlMapException is the base exception class for all SqlMap exceptions.
- *
- * @author Wei Zhuo <weizho[at]gmail[dot]com>
- * @version $Id$
- * @package System.Data.SqlMap
- * @since 3.1
- */
-class TSqlMapException extends TException
-{
- /**
- * Constructor, similar to the parent constructor. For parameters that
- * are of SimpleXmlElement, the tag name and its attribute names and values
- * are expanded into a string.
- */
- public function __construct($errorMessage)
- {
- $this->setErrorCode($errorMessage);
- $errorMessage=$this->translateErrorMessage($errorMessage);
- $args=func_get_args();
- array_shift($args);
- $n=count($args);
- $tokens=array();
- for($i=0;$i<$n;++$i)
- {
- if($args[$i] instanceof SimpleXmlElement)
- $tokens['{'.$i.'}']=$this->implodeNode($args[$i]);
- else
- $tokens['{'.$i.'}']=TPropertyValue::ensureString($args[$i]);
- }
- parent::__construct(strtr($errorMessage,$tokens));
- }
-
- /**
- * @param SimpleXmlElement node
- * @return string tag name and attribute names and values.
- */
- protected function implodeNode($node)
- {
- $attributes=array();
- foreach($node->attributes() as $k=>$v)
- $attributes[]=$k.'="'.(string)$v.'"';
- return '<'.$node->getName().' '.implode(' ',$attributes).'>';
- }
-
- /**
- * @return string path to the error message file
- */
- protected function getErrorMessageFile()
- {
- $lang=Prado::getPreferredLanguage();
- $dir=dirname(__FILE__);
- $msgFile=$dir.'/messages-'.$lang.'.txt';
- if(!is_file($msgFile))
- $msgFile=$dir.'/messages.txt';
- return $msgFile;
- }
-}
-
-/**
- * TSqlMapConfigurationException, raised during configuration file parsing.
- *
- * @author Wei Zhuo <weizho[at]gmail[dot]com>
- * @version $Id$
- * @package System.Data.SqlMap
- * @since 3.1
- */
-class TSqlMapConfigurationException extends TSqlMapException
-{
-
-}
-
-/**
- * TSqlMapUndefinedException, raised when mapped statemented are undefined.
- *
- * @author Wei Zhuo <weizho[at]gmail[dot]com>
- * @version $Id$
- * @package System.Data.SqlMap
- * @since 3.1
- */
-class TSqlMapUndefinedException extends TSqlMapException
-{
-
-}
-
-/**
- * TSqlMapDuplicateException, raised when a duplicate mapped statement is found.
- *
- * @author Wei Zhuo <weizho[at]gmail[dot]com>
- * @version $Id$
- * @package System.Data.SqlMap
- * @since 3.1
- */
-class TSqlMapDuplicateException extends TSqlMapException
-{
-}
-
-/**
- * TInvalidPropertyException, raised when setting or getting an invalid property.
- *
- * @author Wei Zhuo <weizho[at]gmail[dot]com>
- * @version $Id$
- * @package System.Data.SqlMap
- * @since 3.1
- */
-class TInvalidPropertyException extends TSqlMapException
-{
-}
-
-class TSqlMapExecutionException extends TSqlMapException
-{
-}
-
+<?php
+
+/**
+ * TSqlMapException is the base exception class for all SqlMap exceptions.
+ *
+ * @author Wei Zhuo <weizho[at]gmail[dot]com>
+ * @version $Id$
+ * @package System.Data.SqlMap
+ * @since 3.1
+ */
+class TSqlMapException extends TException
+{
+ /**
+ * Constructor, similar to the parent constructor. For parameters that
+ * are of SimpleXmlElement, the tag name and its attribute names and values
+ * are expanded into a string.
+ */
+ public function __construct($errorMessage)
+ {
+ $this->setErrorCode($errorMessage);
+ $errorMessage=$this->translateErrorMessage($errorMessage);
+ $args=func_get_args();
+ array_shift($args);
+ $n=count($args);
+ $tokens=array();
+ for($i=0;$i<$n;++$i)
+ {
+ if($args[$i] instanceof SimpleXmlElement)
+ $tokens['{'.$i.'}']=$this->implodeNode($args[$i]);
+ else
+ $tokens['{'.$i.'}']=TPropertyValue::ensureString($args[$i]);
+ }
+ parent::__construct(strtr($errorMessage,$tokens));
+ }
+
+ /**
+ * @param SimpleXmlElement node
+ * @return string tag name and attribute names and values.
+ */
+ protected function implodeNode($node)
+ {
+ $attributes=array();
+ foreach($node->attributes() as $k=>$v)
+ $attributes[]=$k.'="'.(string)$v.'"';
+ return '<'.$node->getName().' '.implode(' ',$attributes).'>';
+ }
+
+ /**
+ * @return string path to the error message file
+ */
+ protected function getErrorMessageFile()
+ {
+ $lang=Prado::getPreferredLanguage();
+ $dir=dirname(__FILE__);
+ $msgFile=$dir.'/messages-'.$lang.'.txt';
+ if(!is_file($msgFile))
+ $msgFile=$dir.'/messages.txt';
+ return $msgFile;
+ }
+}
+
+/**
+ * TSqlMapConfigurationException, raised during configuration file parsing.
+ *
+ * @author Wei Zhuo <weizho[at]gmail[dot]com>
+ * @version $Id$
+ * @package System.Data.SqlMap
+ * @since 3.1
+ */
+class TSqlMapConfigurationException extends TSqlMapException
+{
+
+}
+
+/**
+ * TSqlMapUndefinedException, raised when mapped statemented are undefined.
+ *
+ * @author Wei Zhuo <weizho[at]gmail[dot]com>
+ * @version $Id$
+ * @package System.Data.SqlMap
+ * @since 3.1
+ */
+class TSqlMapUndefinedException extends TSqlMapException
+{
+
+}
+
+/**
+ * TSqlMapDuplicateException, raised when a duplicate mapped statement is found.
+ *
+ * @author Wei Zhuo <weizho[at]gmail[dot]com>
+ * @version $Id$
+ * @package System.Data.SqlMap
+ * @since 3.1
+ */
+class TSqlMapDuplicateException extends TSqlMapException
+{
+}
+
+/**
+ * TInvalidPropertyException, raised when setting or getting an invalid property.
+ *
+ * @author Wei Zhuo <weizho[at]gmail[dot]com>
+ * @version $Id$
+ * @package System.Data.SqlMap
+ * @since 3.1
+ */
+class TInvalidPropertyException extends TSqlMapException
+{
+}
+
+class TSqlMapExecutionException extends TSqlMapException
+{
+}
+
diff --git a/framework/Data/SqlMap/DataMapper/TSqlMapPagedList.php b/framework/Data/SqlMap/DataMapper/TSqlMapPagedList.php
index 7c6a8e87..57949561 100644
--- a/framework/Data/SqlMap/DataMapper/TSqlMapPagedList.php
+++ b/framework/Data/SqlMap/DataMapper/TSqlMapPagedList.php
@@ -1,208 +1,208 @@
-<?php
-/**
- * TSqlMapPagedList class file.
- *
- * @author Wei Zhuo <weizhuo[at]gmail[dot]com>
- * @link http://www.pradosoft.com/
- * @copyright Copyright &copy; 2005-2012 PradoSoft
- * @license http://www.pradosoft.com/license/
- * @version $Id$
- * @package System.Data.SqlMap
- */
-
-Prado::using('System.Collections.TPagedList');
-
-/**
- * TSqlMapPagedList implements a list with paging functionality that retrieves
- * data from a SqlMap statement.
- *
- * The maximum number of records fetched is 3 times the page size. It fetches
- * the current, the previous and the next page at a time. This allows the paged
- * list to determine if the page is a the begin, the middle or the end of the list.
- *
- * The paged list does not need to know about the total number of records.
- *
- * @author Wei Zhuo <weizhuo[at]gmail[dot]com>
- * @version $Id$
- * @package System.Data.SqlMap
- * @since 3.1
- */
-class TSqlMapPagedList extends TPagedList
-{
- private $_statement;
- private $_parameter;
- private $_prevPageList;
- private $_nextPageList;
- private $_delegate=null;
-
- /**
- * Create a new SqlMap paged list.
- * @param IMappedStatement SqlMap statement.
- * @param mixed query parameters
- * @param int page size
- * @param mixed delegate for each data row retrieved.
- * @param int number of page to fetch on initialization
- */
- public function __construct(IMappedStatement $statement,$parameter, $pageSize, $delegate=null, $page=0)
- {
- parent::__construct();
- parent::setCustomPaging(true);
- $this->initialize($statement,$parameter, $pageSize, $page);
- $this->_delegate=$delegate;
- }
-
- /**
- * Initialize the paged list.
- * @param IMappedStatement SqlMap statement.
- * @param mixed query parameters
- * @param int page size.
- * @param int number of page.
- */
- protected function initialize($statement, $parameter, $pageSize, $page)
- {
- $this->_statement = $statement;
- $this->_parameter = $parameter;
- $this->setPageSize($pageSize);
- $this->attachEventHandler('OnFetchData', array($this, 'fetchDataFromStatement'));
- $this->gotoPage($page);
- }
-
- /**
- * @throws TSqlMapException custom paging must be enabled.
- */
- public function setCustomPaging($value)
- {
- throw new TSqlMapException('sqlmap_must_enable_custom_paging');
- }
-
- /**
- * Fetch data by executing the SqlMap statement.
- * @param TPageList current object.
- * @param TPagedListFetchDataEventParameter fetch parameters
- */
- protected function fetchDataFromStatement($sender, $param)
- {
- $limit = $this->getOffsetAndLimit($param);
- $connection = $this->_statement->getManager()->getDbConnection();
- $data = $this->_statement->executeQueryForList($connection,
- $this->_parameter, null, $limit[0], $limit[1], $this->_delegate);
- $this->populateData($param, $data);
- }
-
- /**
- * Switches to the next page.
- * @return integer|boolean the new page index, false if next page is not availabe.
- */
- public function nextPage()
- {
- return $this->getIsNextPageAvailable() ? parent::nextPage() : false;
- }
-
- /**
- * Switches to the previous page.
- * @return integer|boolean the new page index, false if previous page is not availabe.
- */
- public function previousPage()
- {
- return $this->getIsPreviousPageAvailable() ? parent::previousPage() : false;
- }
-
- /**
- * Populate the list with the fetched data.
- * @param TPagedListFetchDataEventParameter fetch parameters
- * @param array fetched data.
- */
- protected function populateData($param, $data)
- {
- $total = $data instanceof TList ? $data->getCount() : count($data);
- $pageSize = $this->getPageSize();
- if($total < 1)
- {
- $param->setData($data);
- $this->_prevPageList = null;
- $this->_nextPageList = null;
- return;
- }
-
- if($param->getNewPageIndex() < 1)
- {
- $this->_prevPageList = null;
- if($total <= $pageSize)
- {
- $param->setData($data);
- $this->_nextPageList = null;
- }
- else
- {
- $param->setData(array_slice($data, 0, $pageSize));
- $this->_nextPageList = array_slice($data, $pageSize-1,$total);
- }
- }
- else
- {
- if($total <= $pageSize)
- {
- $this->_prevPageList = array_slice($data, 0, $total);
- $param->setData(array());
- $this->_nextPageList = null;
- }
- else if($total <= $pageSize*2)
- {
- $this->_prevPageList = array_slice($data, 0, $pageSize);
- $param->setData(array_slice($data, $pageSize, $total));
- $this->_nextPageList = null;
- }
- else
- {
- $this->_prevPageList = array_slice($data, 0, $pageSize);
- $param->setData(array_slice($data, $pageSize, $pageSize));
- $this->_nextPageList = array_slice($data, $pageSize*2, $total-$pageSize*2);
- }
- }
- }
-
- /**
- * Calculate the data fetch offsets and limits.
- * @param TPagedListFetchDataEventParameter fetch parameters
- * @return array 1st element is the offset, 2nd element is the limit.
- */
- protected function getOffsetAndLimit($param)
- {
- $index = $param->getNewPageIndex();
- $pageSize = $this->getPageSize();
- return $index < 1 ? array($index, $pageSize*2) : array(($index-1)*$pageSize, $pageSize*3);
- }
-
- /**
- * @return boolean true if the next page is available, false otherwise.
- */
- public function getIsNextPageAvailable()
- {
- return $this->_nextPageList!==null;
- }
-
- /**
- * @return boolean true if the previous page is available, false otherwise.
- */
- public function getIsPreviousPageAvailable()
- {
- return $this->_prevPageList!==null;
- }
-
- /**
- * @return boolean true if is the very last page, false otherwise.
- */
- public function getIsLastPage()
- {
- return ($this->_nextPageList===null) || $this->_nextPageList->getCount() < 1;
- }
-
- /**
- * @return boolean true if is not first nor last page, false otherwise.
- */
- public function getIsMiddlePage()
- {
- return !($this->getIsFirstPage() || $this->getIsLastPage());
- }
-}
-
+<?php
+/**
+ * TSqlMapPagedList class file.
+ *
+ * @author Wei Zhuo <weizhuo[at]gmail[dot]com>
+ * @link http://www.pradosoft.com/
+ * @copyright Copyright &copy; 2005-2012 PradoSoft
+ * @license http://www.pradosoft.com/license/
+ * @version $Id$
+ * @package System.Data.SqlMap
+ */
+
+Prado::using('System.Collections.TPagedList');
+
+/**
+ * TSqlMapPagedList implements a list with paging functionality that retrieves
+ * data from a SqlMap statement.
+ *
+ * The maximum number of records fetched is 3 times the page size. It fetches
+ * the current, the previous and the next page at a time. This allows the paged
+ * list to determine if the page is a the begin, the middle or the end of the list.
+ *
+ * The paged list does not need to know about the total number of records.
+ *
+ * @author Wei Zhuo <weizhuo[at]gmail[dot]com>
+ * @version $Id$
+ * @package System.Data.SqlMap
+ * @since 3.1
+ */
+class TSqlMapPagedList extends TPagedList
+{
+ private $_statement;
+ private $_parameter;
+ private $_prevPageList;
+ private $_nextPageList;
+ private $_delegate=null;
+
+ /**
+ * Create a new SqlMap paged list.
+ * @param IMappedStatement SqlMap statement.
+ * @param mixed query parameters
+ * @param int page size
+ * @param mixed delegate for each data row retrieved.
+ * @param int number of page to fetch on initialization
+ */
+ public function __construct(IMappedStatement $statement,$parameter, $pageSize, $delegate=null, $page=0)
+ {
+ parent::__construct();
+ parent::setCustomPaging(true);
+ $this->initialize($statement,$parameter, $pageSize, $page);
+ $this->_delegate=$delegate;
+ }
+
+ /**
+ * Initialize the paged list.
+ * @param IMappedStatement SqlMap statement.
+ * @param mixed query parameters
+ * @param int page size.
+ * @param int number of page.
+ */
+ protected function initialize($statement, $parameter, $pageSize, $page)
+ {
+ $this->_statement = $statement;
+ $this->_parameter = $parameter;
+ $this->setPageSize($pageSize);
+ $this->attachEventHandler('OnFetchData', array($this, 'fetchDataFromStatement'));
+ $this->gotoPage($page);
+ }
+
+ /**
+ * @throws TSqlMapException custom paging must be enabled.
+ */
+ public function setCustomPaging($value)
+ {
+ throw new TSqlMapException('sqlmap_must_enable_custom_paging');
+ }
+
+ /**
+ * Fetch data by executing the SqlMap statement.
+ * @param TPageList current object.
+ * @param TPagedListFetchDataEventParameter fetch parameters
+ */
+ protected function fetchDataFromStatement($sender, $param)
+ {
+ $limit = $this->getOffsetAndLimit($param);
+ $connection = $this->_statement->getManager()->getDbConnection();
+ $data = $this->_statement->executeQueryForList($connection,
+ $this->_parameter, null, $limit[0], $limit[1], $this->_delegate);
+ $this->populateData($param, $data);
+ }
+
+ /**
+ * Switches to the next page.
+ * @return integer|boolean the new page index, false if next page is not availabe.
+ */
+ public function nextPage()
+ {
+ return $this->getIsNextPageAvailable() ? parent::nextPage() : false;
+ }
+
+ /**
+ * Switches to the previous page.
+ * @return integer|boolean the new page index, false if previous page is not availabe.
+ */
+ public function previousPage()
+ {
+ return $this->getIsPreviousPageAvailable() ? parent::previousPage() : false;
+ }
+
+ /**
+ * Populate the list with the fetched data.
+ * @param TPagedListFetchDataEventParameter fetch parameters
+ * @param array fetched data.
+ */
+ protected function populateData($param, $data)
+ {
+ $total = $data instanceof TList ? $data->getCount() : count($data);
+ $pageSize = $this->getPageSize();
+ if($total < 1)
+ {
+ $param->setData($data);
+ $this->_prevPageList = null;
+ $this->_nextPageList = null;
+ return;
+ }
+
+ if($param->getNewPageIndex() < 1)
+ {
+ $this->_prevPageList = null;
+ if($total <= $pageSize)
+ {
+ $param->setData($data);
+ $this->_nextPageList = null;
+ }
+ else
+ {
+ $param->setData(array_slice($data, 0, $pageSize));
+ $this->_nextPageList = array_slice($data, $pageSize-1,$total);
+ }
+ }
+ else
+ {
+ if($total <= $pageSize)
+ {
+ $this->_prevPageList = array_slice($data, 0, $total);
+ $param->setData(array());
+ $this->_nextPageList = null;
+ }
+ else if($total <= $pageSize*2)
+ {
+ $this->_prevPageList = array_slice($data, 0, $pageSize);
+ $param->setData(array_slice($data, $pageSize, $total));
+ $this->_nextPageList = null;
+ }
+ else
+ {
+ $this->_prevPageList = array_slice($data, 0, $pageSize);
+ $param->setData(array_slice($data, $pageSize, $pageSize));
+ $this->_nextPageList = array_slice($data, $pageSize*2, $total-$pageSize*2);
+ }
+ }
+ }
+
+ /**
+ * Calculate the data fetch offsets and limits.
+ * @param TPagedListFetchDataEventParameter fetch parameters
+ * @return array 1st element is the offset, 2nd element is the limit.
+ */
+ protected function getOffsetAndLimit($param)
+ {
+ $index = $param->getNewPageIndex();
+ $pageSize = $this->getPageSize();
+ return $index < 1 ? array($index, $pageSize*2) : array(($index-1)*$pageSize, $pageSize*3);
+ }
+
+ /**
+ * @return boolean true if the next page is available, false otherwise.
+ */
+ public function getIsNextPageAvailable()
+ {
+ return $this->_nextPageList!==null;
+ }
+
+ /**
+ * @return boolean true if the previous page is available, false otherwise.
+ */
+ public function getIsPreviousPageAvailable()
+ {
+ return $this->_prevPageList!==null;
+ }
+
+ /**
+ * @return boolean true if is the very last page, false otherwise.
+ */
+ public function getIsLastPage()
+ {
+ return ($this->_nextPageList===null) || $this->_nextPageList->getCount() < 1;
+ }
+
+ /**
+ * @return boolean true if is not first nor last page, false otherwise.
+ */
+ public function getIsMiddlePage()
+ {
+ return !($this->getIsFirstPage() || $this->getIsLastPage());
+ }
+}
+
diff --git a/framework/Data/SqlMap/DataMapper/TSqlMapTypeHandlerRegistry.php b/framework/Data/SqlMap/DataMapper/TSqlMapTypeHandlerRegistry.php
index 7a54e347..61c97245 100644
--- a/framework/Data/SqlMap/DataMapper/TSqlMapTypeHandlerRegistry.php
+++ b/framework/Data/SqlMap/DataMapper/TSqlMapTypeHandlerRegistry.php
@@ -1,192 +1,192 @@
-<?php
-/**
- * TSqlMapTypeHandlerRegistry, and abstract TSqlMapTypeHandler classes file.
- *
- * @author Wei Zhuo <weizhuo[at]gmail[dot]com>
- * @link http://www.pradosoft.com/
+<?php
+/**
+ * TSqlMapTypeHandlerRegistry, and abstract TSqlMapTypeHandler classes file.
+ *
+ * @author Wei Zhuo <weizhuo[at]gmail[dot]com>
+ * @link http://www.pradosoft.com/
* @copyright Copyright &copy; 2005-2012 PradoSoft
- * @license http://www.pradosoft.com/license/
- * @version $Id$
- * @package System.Data.SqlMap
- */
-
-/**
- * TTypeHandlerFactory provides type handler classes to convert database field type
- * to PHP types and vice versa.
- *
- * @author Wei Zhuo <weizho[at]gmail[dot]com>
- * @version $Id$
- * @package System.Data.SqlMap
- * @since 3.1
- */
-class TSqlMapTypeHandlerRegistry
-{
- private $_typeHandlers=array();
-
- /**
- * @param string database field type
- * @return TSqlMapTypeHandler type handler for give database field type.
- */
- public function getDbTypeHandler($dbType='NULL')
- {
- foreach($this->_typeHandlers as $handler)
- if($handler->getDbType()===$dbType)
- return $handler;
- }
-
- /**
- * @param string type handler class name
- * @return TSqlMapTypeHandler type handler
- */
- public function getTypeHandler($class)
- {
- if(isset($this->_typeHandlers[$class]))
- return $this->_typeHandlers[$class];
- }
-
- /**
- * @param TSqlMapTypeHandler registers a new type handler
- */
- public function registerTypeHandler(TSqlMapTypeHandler $handler)
- {
- $this->_typeHandlers[$handler->getType()] = $handler;
- }
-
- /**
- * Creates a new instance of a particular class (for PHP primative types,
- * their corresponding default value for given type is used).
- * @param string PHP type name
- * @return mixed default type value, if no type is specified null is returned.
- * @throws TSqlMapException if class name is not found.
- */
- public function createInstanceOf($type='')
- {
- if(strlen($type) > 0)
- {
- switch(strtolower($type))
- {
- case 'string': return '';
- case 'array': return array();
- case 'float': case 'double': case 'decimal': return 0.0;
- case 'integer': case 'int': return 0;
- case 'bool': case 'boolean': return false;
- }
-
- if(class_exists('Prado', false))
- return Prado::createComponent($type);
- else if(class_exists($type, false)) //NO auto loading
- return new $type;
- else
- throw new TSqlMapException('sqlmap_unable_to_find_class', $type);
- }
- }
-
- /**
- * Converts the value to given type using PHP's settype() function.
- * @param string PHP primative type.
- * @param mixed value to be casted
- * @return mixed type casted value.
- */
- public function convertToType($type, $value)
- {
- switch(strtolower($type))
- {
- case 'integer': case 'int':
- $type = 'integer'; break;
- case 'float': case 'double': case 'decimal':
- $type = 'float'; break;
- case 'boolean': case 'bool':
- $type = 'boolean'; break;
- case 'string' :
- $type = 'string'; break;
- default:
- return $value;
- }
- settype($value, $type);
- return $value;
- }
-}
-
-/**
- * A simple interface for implementing custom type handlers.
- *
- * Using this interface, you can implement a type handler that
- * will perform customized processing before parameters are set
- * on and after values are retrieved from the database.
- * Using a custom type handler you can extend
- * the framework to handle types that are not supported, or
- * handle supported types in a different way. For example,
- * you might use a custom type handler to implement proprietary
- * BLOB support (e.g. Oracle), or you might use it to handle
- * booleans using "Y" and "N" instead of the more typical 0/1.
- *
- * @author Wei Zhuo <weizho[at]gmail[dot]com>
- * @version $Id$
- * @package System.Data.SqlMap
- * @since 3.1
- */
-abstract class TSqlMapTypeHandler extends TComponent
-{
- private $_dbType='NULL';
- private $_type;
- /**
- * @param string database field type.
- */
- public function setDbType($value)
- {
- $this->_dbType=$value;
- }
-
- /**
- * @return string database field type.
- */
- public function getDbType()
- {
- return $this->_dbType;
- }
-
- public function getType()
- {
- if($this->_type===null)
- return get_class($this);
- else
- return $this->_type;
- }
-
- public function setType($value)
- {
- $this->_type=$value;
- }
-
- /**
- * Performs processing on a value before it is used to set
- * the parameter of a IDbCommand.
- * @param object The interface for setting the value.
- * @param object The value to be set.
- */
- public abstract function getParameter($object);
-
-
- /**
- * Performs processing on a value before after it has been retrieved
- * from a database
- * @param object The interface for getting the value.
- * @return mixed The processed value.
- */
- public abstract function getResult($string);
-
-
- /**
- * Casts the string representation of a value into a type recognized by
- * this type handler. This method is used to translate nullValue values
- * into types that can be appropriately compared. If your custom type handler
- * cannot support nullValues, or if there is no reasonable string representation
- * for this type (e.g. File type), you can simply return the String representation
- * as it was passed in. It is not recommended to return null, unless null was passed
- * in.
- * @param array result row.
- * @return mixed
- */
- public abstract function createNewInstance($row=null);
-}
-
+ * @license http://www.pradosoft.com/license/
+ * @version $Id$
+ * @package System.Data.SqlMap
+ */
+
+/**
+ * TTypeHandlerFactory provides type handler classes to convert database field type
+ * to PHP types and vice versa.
+ *
+ * @author Wei Zhuo <weizho[at]gmail[dot]com>
+ * @version $Id$
+ * @package System.Data.SqlMap
+ * @since 3.1
+ */
+class TSqlMapTypeHandlerRegistry
+{
+ private $_typeHandlers=array();
+
+ /**
+ * @param string database field type
+ * @return TSqlMapTypeHandler type handler for give database field type.
+ */
+ public function getDbTypeHandler($dbType='NULL')
+ {
+ foreach($this->_typeHandlers as $handler)
+ if($handler->getDbType()===$dbType)
+ return $handler;
+ }
+
+ /**
+ * @param string type handler class name
+ * @return TSqlMapTypeHandler type handler
+ */
+ public function getTypeHandler($class)
+ {
+ if(isset($this->_typeHandlers[$class]))
+ return $this->_typeHandlers[$class];
+ }
+
+ /**
+ * @param TSqlMapTypeHandler registers a new type handler
+ */
+ public function registerTypeHandler(TSqlMapTypeHandler $handler)
+ {
+ $this->_typeHandlers[$handler->getType()] = $handler;
+ }
+
+ /**
+ * Creates a new instance of a particular class (for PHP primative types,
+ * their corresponding default value for given type is used).
+ * @param string PHP type name
+ * @return mixed default type value, if no type is specified null is returned.
+ * @throws TSqlMapException if class name is not found.
+ */
+ public function createInstanceOf($type='')
+ {
+ if(strlen($type) > 0)
+ {
+ switch(strtolower($type))
+ {
+ case 'string': return '';
+ case 'array': return array();
+ case 'float': case 'double': case 'decimal': return 0.0;
+ case 'integer': case 'int': return 0;
+ case 'bool': case 'boolean': return false;
+ }
+
+ if(class_exists('Prado', false))
+ return Prado::createComponent($type);
+ else if(class_exists($type, false)) //NO auto loading
+ return new $type;
+ else
+ throw new TSqlMapException('sqlmap_unable_to_find_class', $type);
+ }
+ }
+
+ /**
+ * Converts the value to given type using PHP's settype() function.
+ * @param string PHP primative type.
+ * @param mixed value to be casted
+ * @return mixed type casted value.
+ */
+ public function convertToType($type, $value)
+ {
+ switch(strtolower($type))
+ {
+ case 'integer': case 'int':
+ $type = 'integer'; break;
+ case 'float': case 'double': case 'decimal':
+ $type = 'float'; break;
+ case 'boolean': case 'bool':
+ $type = 'boolean'; break;
+ case 'string' :
+ $type = 'string'; break;
+ default:
+ return $value;
+ }
+ settype($value, $type);
+ return $value;
+ }
+}
+
+/**
+ * A simple interface for implementing custom type handlers.
+ *
+ * Using this interface, you can implement a type handler that
+ * will perform customized processing before parameters are set
+ * on and after values are retrieved from the database.
+ * Using a custom type handler you can extend
+ * the framework to handle types that are not supported, or
+ * handle supported types in a different way. For example,
+ * you might use a custom type handler to implement proprietary
+ * BLOB support (e.g. Oracle), or you might use it to handle
+ * booleans using "Y" and "N" instead of the more typical 0/1.
+ *
+ * @author Wei Zhuo <weizho[at]gmail[dot]com>
+ * @version $Id$
+ * @package System.Data.SqlMap
+ * @since 3.1
+ */
+abstract class TSqlMapTypeHandler extends TComponent
+{
+ private $_dbType='NULL';
+ private $_type;
+ /**
+ * @param string database field type.
+ */
+ public function setDbType($value)
+ {
+ $this->_dbType=$value;
+ }
+
+ /**
+ * @return string database field type.
+ */
+ public function getDbType()
+ {
+ return $this->_dbType;
+ }
+
+ public function getType()
+ {
+ if($this->_type===null)
+ return get_class($this);
+ else
+ return $this->_type;
+ }
+
+ public function setType($value)
+ {
+ $this->_type=$value;
+ }
+
+ /**
+ * Performs processing on a value before it is used to set
+ * the parameter of a IDbCommand.
+ * @param object The interface for setting the value.
+ * @param object The value to be set.
+ */
+ public abstract function getParameter($object);
+
+
+ /**
+ * Performs processing on a value before after it has been retrieved
+ * from a database
+ * @param object The interface for getting the value.
+ * @return mixed The processed value.
+ */
+ public abstract function getResult($string);
+
+
+ /**
+ * Casts the string representation of a value into a type recognized by
+ * this type handler. This method is used to translate nullValue values
+ * into types that can be appropriately compared. If your custom type handler
+ * cannot support nullValues, or if there is no reasonable string representation
+ * for this type (e.g. File type), you can simply return the String representation
+ * as it was passed in. It is not recommended to return null, unless null was passed
+ * in.
+ * @param array result row.
+ * @return mixed
+ */
+ public abstract function createNewInstance($row=null);
+}
+
diff --git a/framework/Data/SqlMap/Statements/IMappedStatement.php b/framework/Data/SqlMap/Statements/IMappedStatement.php
index dc628c9e..15f61fad 100644
--- a/framework/Data/SqlMap/Statements/IMappedStatement.php
+++ b/framework/Data/SqlMap/Statements/IMappedStatement.php
@@ -1,82 +1,82 @@
-<?php
-/**
- * IMappedStatement interface file.
- *
- * @author Wei Zhuo <weizhuo[at]gmail[dot]com>
- * @version $Id$
- * @package System.Data.SqlMap.Statements
- */
-
-/**
- * Interface for all mapping statements.
- *
- * @author Wei Zhuo <weizho[at]gmail[dot]com>
- * @version $Id$
- * @package System.Data.SqlMap.Statements
- * @since 3.1
- */
-interface IMappedStatement
-{
- /**
- * @return string Name used to identify the MappedStatement amongst the others.
- */
- public function getID();
-
- /**
- * @return TSqlMapStatement The SQL statment used by this TMappedStatement.
- */
- public function getStatement();
-
- /**
- * @return TSqlMap The TSqlMap used by this TMappedStatement
- */
- public function getManager();
-
- /**
- * Executes the SQL and retuns all rows selected in a map that is keyed on
- * the property named in the <tt>$keyProperty</tt> parameter. The value at
- * each key will be the value of the property specified in the
- * <tt>$valueProperty</tt> parameter. If <tt>$valueProperty</tt> is
- * <tt>null</tt>, the entire result object will be entered.
- * @param IDbConnection database connection to execute the query
- * @param mixed The object used to set the parameters in the SQL.
- * @param string The property of the result object to be used as the key.
- * @param string The property of the result object to be used as the value (or null)
- * @return TMap A map of object containing the rows keyed by <tt>$keyProperty</tt>.
- */
- public function executeQueryForMap($connection, $parameter, $keyProperty, $valueProperty=null);
-
-
- /**
- * Execute an update statement. Also used for delete statement. Return the
- * number of row effected.
- * @param IDbConnection database connection to execute the query
- * @param mixed The object used to set the parameters in the SQL.
- * @return integer The number of row effected.
- */
- public function executeUpdate($connection, $parameter);
-
-
- /**
- * Executes the SQL and retuns a subset of the rows selected.
- * @param IDbConnection database connection to execute the query
- * @param mixed The object used to set the parameters in the SQL.
- * @param TList A list to populate the result with.
- * @param integer The number of rows to skip over.
- * @param integer The maximum number of rows to return.
- * @return TList A TList of result objects.
- */
- public function executeQueryForList($connection, $parameter, $result=null, $skip=-1, $max=-1);
-
-
- /**
- * Executes an SQL statement that returns a single row as an object
- * of the type of the <tt>$result</tt> passed in as a parameter.
- * @param IDbConnection database connection to execute the query
- * @param mixed The object used to set the parameters in the SQL.
- * @param object The result object.
- * @return object result.
- */
- public function executeQueryForObject($connection,$parameter, $result=null);
-}
-
+<?php
+/**
+ * IMappedStatement interface file.
+ *
+ * @author Wei Zhuo <weizhuo[at]gmail[dot]com>
+ * @version $Id$
+ * @package System.Data.SqlMap.Statements
+ */
+
+/**
+ * Interface for all mapping statements.
+ *
+ * @author Wei Zhuo <weizho[at]gmail[dot]com>
+ * @version $Id$
+ * @package System.Data.SqlMap.Statements
+ * @since 3.1
+ */
+interface IMappedStatement
+{
+ /**
+ * @return string Name used to identify the MappedStatement amongst the others.
+ */
+ public function getID();
+
+ /**
+ * @return TSqlMapStatement The SQL statment used by this TMappedStatement.
+ */
+ public function getStatement();
+
+ /**
+ * @return TSqlMap The TSqlMap used by this TMappedStatement
+ */
+ public function getManager();
+
+ /**
+ * Executes the SQL and retuns all rows selected in a map that is keyed on
+ * the property named in the <tt>$keyProperty</tt> parameter. The value at
+ * each key will be the value of the property specified in the
+ * <tt>$valueProperty</tt> parameter. If <tt>$valueProperty</tt> is
+ * <tt>null</tt>, the entire result object will be entered.
+ * @param IDbConnection database connection to execute the query
+ * @param mixed The object used to set the parameters in the SQL.
+ * @param string The property of the result object to be used as the key.
+ * @param string The property of the result object to be used as the value (or null)
+ * @return TMap A map of object containing the rows keyed by <tt>$keyProperty</tt>.
+ */
+ public function executeQueryForMap($connection, $parameter, $keyProperty, $valueProperty=null);
+
+
+ /**
+ * Execute an update statement. Also used for delete statement. Return the
+ * number of row effected.
+ * @param IDbConnection database connection to execute the query
+ * @param mixed The object used to set the parameters in the SQL.
+ * @return integer The number of row effected.
+ */
+ public function executeUpdate($connection, $parameter);
+
+
+ /**
+ * Executes the SQL and retuns a subset of the rows selected.
+ * @param IDbConnection database connection to execute the query
+ * @param mixed The object used to set the parameters in the SQL.
+ * @param TList A list to populate the result with.
+ * @param integer The number of rows to skip over.
+ * @param integer The maximum number of rows to return.
+ * @return TList A TList of result objects.
+ */
+ public function executeQueryForList($connection, $parameter, $result=null, $skip=-1, $max=-1);
+
+
+ /**
+ * Executes an SQL statement that returns a single row as an object
+ * of the type of the <tt>$result</tt> passed in as a parameter.
+ * @param IDbConnection database connection to execute the query
+ * @param mixed The object used to set the parameters in the SQL.
+ * @param object The result object.
+ * @return object result.
+ */
+ public function executeQueryForObject($connection,$parameter, $result=null);
+}
+
diff --git a/framework/Data/SqlMap/Statements/TCachingStatement.php b/framework/Data/SqlMap/Statements/TCachingStatement.php
index 54664e37..cac84458 100644
--- a/framework/Data/SqlMap/Statements/TCachingStatement.php
+++ b/framework/Data/SqlMap/Statements/TCachingStatement.php
@@ -1,108 +1,108 @@
-<?php
-/**
- * TCachingStatement class file.
- *
- * @author Wei Zhuo <weizhuo[at]gmail[dot]com>
- * @link http://www.pradosoft.com/
- * @copyright Copyright &copy; 2005-2012 PradoSoft
- * @license http://www.pradosoft.com/license/
- * @version $Id$
- * @package System.Data.SqlMap.Statements
- */
-
-/**
- * TCacheingStatement class.
- *
- * @author Wei Zhuo <weizhuo[at]gmail[dot]com>
- * @version $Id$
- * @package System.Data.SqlMap.Statements
- * @since 3.1
- */
-class TCachingStatement extends TComponent implements IMappedStatement
-{
- private $_mappedStatement;
-
- public function __construct(TMappedStatement $statement)
- {
- $this->_mappedStatement = $statement;
- }
-
- public function getID()
- {
- return $this->_mappedStatement->getID();
- }
-
- public function getStatement()
- {
- return $this->_mappedStatement->getStatement();
- }
-
- public function getManager()
- {
- return $this->_mappedStatement->getManager();
- }
-
- public function executeQueryForMap($connection, $parameter,$keyProperty, $valueProperty=null, $skip=-1, $max=-1,$delegate=null)
- {
- $sql = $this->createCommand($connection, $parameter, $skip, $max);
- $key = $this->getCacheKey(array(clone($sql), $keyProperty, $valueProperty,$skip, $max));
- $map = $this->getStatement()->getCache()->get($key);
- if($map===null)
- {
- $map = $this->_mappedStatement->runQueryForMap(
- $connection, $parameter, $sql, $keyProperty, $valueProperty, $delegate);
- $this->getStatement()->getCache()->set($key, $map);
- }
- return $map;
- }
-
- public function executeUpdate($connection, $parameter)
- {
- return $this->_mappedStatement->executeUpdate($connection, $parameter);
- }
-
- public function executeInsert($connection, $parameter)
- {
- return $this->executeInsert($connection, $parameter);
- }
-
- public function executeQueryForList($connection, $parameter, $result=null, $skip=-1, $max=-1, $delegate=null)
- {
- $sql = $this->createCommand($connection, $parameter, $skip, $max);
- $key = $this->getCacheKey(array(clone($sql), $parameter, $skip, $max));
- $list = $this->getStatement()->getCache()->get($key);
- if($list===null)
- {
- $list = $this->_mappedStatement->runQueryForList(
- $connection, $parameter, $sql, $result, $delegate);
- $this->getStatement()->getCache()->set($key, $list);
- }
- return $list;
- }
-
- public function executeQueryForObject($connection, $parameter, $result=null)
- {
- $sql = $this->createCommand($connection, $parameter);
- $key = $this->getCacheKey(array(clone($sql), $parameter));
- $object = $this->getStatement()->getCache()->get($key);
- if($object===null)
- {
- $object = $this->_mappedStatement->runQueryForObject($connection, $sql, $result);
- $this->getStatement()->getCache()->set($key, $object);
- }
- return $object;
- }
-
- protected function getCacheKey($object)
- {
- $cacheKey = new TSqlMapCacheKey($object);
- return $cacheKey->getHash();
- }
-
- protected function createCommand($connection, $parameter, $skip=null, $max=null)
- {
- return $this->_mappedStatement->getCommand()->create($this->getManager(),
- $connection, $this->getStatement(), $parameter, $skip, $max);
- }
-}
-
+<?php
+/**
+ * TCachingStatement class file.
+ *
+ * @author Wei Zhuo <weizhuo[at]gmail[dot]com>
+ * @link http://www.pradosoft.com/
+ * @copyright Copyright &copy; 2005-2012 PradoSoft
+ * @license http://www.pradosoft.com/license/
+ * @version $Id$
+ * @package System.Data.SqlMap.Statements
+ */
+
+/**
+ * TCacheingStatement class.
+ *
+ * @author Wei Zhuo <weizhuo[at]gmail[dot]com>
+ * @version $Id$
+ * @package System.Data.SqlMap.Statements
+ * @since 3.1
+ */
+class TCachingStatement extends TComponent implements IMappedStatement
+{
+ private $_mappedStatement;
+
+ public function __construct(TMappedStatement $statement)
+ {
+ $this->_mappedStatement = $statement;
+ }
+
+ public function getID()
+ {
+ return $this->_mappedStatement->getID();
+ }
+
+ public function getStatement()
+ {
+ return $this->_mappedStatement->getStatement();
+ }
+
+ public function getManager()
+ {
+ return $this->_mappedStatement->getManager();
+ }
+
+ public function executeQueryForMap($connection, $parameter,$keyProperty, $valueProperty=null, $skip=-1, $max=-1,$delegate=null)
+ {
+ $sql = $this->createCommand($connection, $parameter, $skip, $max);
+ $key = $this->getCacheKey(array(clone($sql), $keyProperty, $valueProperty,$skip, $max));
+ $map = $this->getStatement()->getCache()->get($key);
+ if($map===null)
+ {
+ $map = $this->_mappedStatement->runQueryForMap(
+ $connection, $parameter, $sql, $keyProperty, $valueProperty, $delegate);
+ $this->getStatement()->getCache()->set($key, $map);
+ }
+ return $map;
+ }
+
+ public function executeUpdate($connection, $parameter)
+ {
+ return $this->_mappedStatement->executeUpdate($connection, $parameter);
+ }
+
+ public function executeInsert($connection, $parameter)
+ {
+ return $this->executeInsert($connection, $parameter);
+ }
+
+ public function executeQueryForList($connection, $parameter, $result=null, $skip=-1, $max=-1, $delegate=null)
+ {
+ $sql = $this->createCommand($connection, $parameter, $skip, $max);
+ $key = $this->getCacheKey(array(clone($sql), $parameter, $skip, $max));
+ $list = $this->getStatement()->getCache()->get($key);
+ if($list===null)
+ {
+ $list = $this->_mappedStatement->runQueryForList(
+ $connection, $parameter, $sql, $result, $delegate);
+ $this->getStatement()->getCache()->set($key, $list);
+ }
+ return $list;
+ }
+
+ public function executeQueryForObject($connection, $parameter, $result=null)
+ {
+ $sql = $this->createCommand($connection, $parameter);
+ $key = $this->getCacheKey(array(clone($sql), $parameter));
+ $object = $this->getStatement()->getCache()->get($key);
+ if($object===null)
+ {
+ $object = $this->_mappedStatement->runQueryForObject($connection, $sql, $result);
+ $this->getStatement()->getCache()->set($key, $object);
+ }
+ return $object;
+ }
+
+ protected function getCacheKey($object)
+ {
+ $cacheKey = new TSqlMapCacheKey($object);
+ return $cacheKey->getHash();
+ }
+
+ protected function createCommand($connection, $parameter, $skip=null, $max=null)
+ {
+ return $this->_mappedStatement->getCommand()->create($this->getManager(),
+ $connection, $this->getStatement(), $parameter, $skip, $max);
+ }
+}
+
diff --git a/framework/Data/SqlMap/Statements/TDeleteMappedStatement.php b/framework/Data/SqlMap/Statements/TDeleteMappedStatement.php
index a3cbaadb..562720ed 100644
--- a/framework/Data/SqlMap/Statements/TDeleteMappedStatement.php
+++ b/framework/Data/SqlMap/Statements/TDeleteMappedStatement.php
@@ -1,24 +1,24 @@
-<?php
-/**
- * TDeleteMappedStatement class file.
- *
- * @author Wei Zhuo <weizhuo[at]gmail[dot]com>
- * @link http://www.pradosoft.com/
+<?php
+/**
+ * TDeleteMappedStatement class file.
+ *
+ * @author Wei Zhuo <weizhuo[at]gmail[dot]com>
+ * @link http://www.pradosoft.com/
* @copyright Copyright &copy; 2005-2012 PradoSoft
- * @license http://www.pradosoft.com/license/
- * @version $Id$
- * @package System.Data.SqlMap.Statements
- */
-
-/**
- * TDeleteMappedStatement class.
- *
- * @author Wei Zhuo <weizho[at]gmail[dot]com>
- * @version $Id$
- * @package System.Data.SqlMap.Statements
- * @since 3.1
- */
-class TDeleteMappedStatement extends TUpdateMappedStatement
-{
-}
-
+ * @license http://www.pradosoft.com/license/
+ * @version $Id$
+ * @package System.Data.SqlMap.Statements
+ */
+
+/**
+ * TDeleteMappedStatement class.
+ *
+ * @author Wei Zhuo <weizho[at]gmail[dot]com>
+ * @version $Id$
+ * @package System.Data.SqlMap.Statements
+ * @since 3.1
+ */
+class TDeleteMappedStatement extends TUpdateMappedStatement
+{
+}
+
diff --git a/framework/Data/SqlMap/Statements/TInsertMappedStatement.php b/framework/Data/SqlMap/Statements/TInsertMappedStatement.php
index c7cd6ff6..e91ca3aa 100644
--- a/framework/Data/SqlMap/Statements/TInsertMappedStatement.php
+++ b/framework/Data/SqlMap/Statements/TInsertMappedStatement.php
@@ -1,49 +1,49 @@
-<?php
-/**
- * TInsertMappedStatement class file.
- *
- * @author Wei Zhuo <weizhuo[at]gmail[dot]com>
- * @link http://www.pradosoft.com/
+<?php
+/**
+ * TInsertMappedStatement class file.
+ *
+ * @author Wei Zhuo <weizhuo[at]gmail[dot]com>
+ * @link http://www.pradosoft.com/
* @copyright Copyright &copy; 2005-2012 PradoSoft
- * @license http://www.pradosoft.com/license/
- * @version $Id$
- * @package System.Data.SqlMap.Statements
- */
-
-/**
- * TInsertMappedStatement class.
- *
- * @author Wei Zhuo <weizho[at]gmail[dot]com>
- * @version $Id$
- * @package System.Data.SqlMap.Statements
- * @since 3.1
- */
-class TInsertMappedStatement extends TMappedStatement
-{
- public function executeQueryForMap($connection, $parameter,
- $keyProperty, $valueProperty=null)
- {
- throw new TSqlMapExecutionException(
- 'sqlmap_cannot_execute_query_for_map', get_class($this), $this->getID());
- }
-
- public function executeUpdate($connection, $parameter)
- {
- throw new TSqlMapExecutionException(
- 'sqlmap_cannot_execute_update', get_class($this), $this->getID());
- }
-
- public function executeQueryForList($connection, $parameter, $result=null,
- $skip=-1, $max=-1)
- {
- throw new TSqlMapExecutionException(
- 'sqlmap_cannot_execute_query_for_list', get_class($this), $this->getID());
- }
-
- public function executeQueryForObject($connection, $parameter, $result=null)
- {
- throw new TSqlMapExecutionException(
- 'sqlmap_cannot_execute_query_for_object', get_class($this), $this->getID());
- }
-}
-
+ * @license http://www.pradosoft.com/license/
+ * @version $Id$
+ * @package System.Data.SqlMap.Statements
+ */
+
+/**
+ * TInsertMappedStatement class.
+ *
+ * @author Wei Zhuo <weizho[at]gmail[dot]com>
+ * @version $Id$
+ * @package System.Data.SqlMap.Statements
+ * @since 3.1
+ */
+class TInsertMappedStatement extends TMappedStatement
+{
+ public function executeQueryForMap($connection, $parameter,
+ $keyProperty, $valueProperty=null)
+ {
+ throw new TSqlMapExecutionException(
+ 'sqlmap_cannot_execute_query_for_map', get_class($this), $this->getID());
+ }
+
+ public function executeUpdate($connection, $parameter)
+ {
+ throw new TSqlMapExecutionException(
+ 'sqlmap_cannot_execute_update', get_class($this), $this->getID());
+ }
+
+ public function executeQueryForList($connection, $parameter, $result=null,
+ $skip=-1, $max=-1)
+ {
+ throw new TSqlMapExecutionException(
+ 'sqlmap_cannot_execute_query_for_list', get_class($this), $this->getID());
+ }
+
+ public function executeQueryForObject($connection, $parameter, $result=null)
+ {
+ throw new TSqlMapExecutionException(
+ 'sqlmap_cannot_execute_query_for_object', get_class($this), $this->getID());
+ }
+}
+
diff --git a/framework/Data/SqlMap/Statements/TMappedStatement.php b/framework/Data/SqlMap/Statements/TMappedStatement.php
index 0dbc8def..ee54df95 100644
--- a/framework/Data/SqlMap/Statements/TMappedStatement.php
+++ b/framework/Data/SqlMap/Statements/TMappedStatement.php
@@ -1,1242 +1,1242 @@
-<?php
-/**
- * TMappedStatement and related classes.
- *
- * @author Wei Zhuo <weizhuo[at]gmail[dot]com>
- * @link http://www.pradosoft.com/
- * @copyright Copyright &copy; 2005-2012 PradoSoft
- * @license http://www.pradosoft.com/license/
- * @version $Id$
- * @package System.Data.SqlMap.Statements
- */
-
-/**
- * TMappedStatement class executes SQL mapped statements. Mapped Statements can
- * hold any SQL statement and use Parameter Maps and Result Maps for input and output.
- *
- * This class is usualy instantiated during SQLMap configuration by TSqlDomBuilder.
- *
- * @author Wei Zhuo <weizhuo[at]gmail[dot]com>
- * @version $Id$
- * @package System.Data.SqlMap.Statements
- * @since 3.0
- */
-class TMappedStatement extends TComponent implements IMappedStatement
-{
- /**
- * @var TSqlMapStatement current SQL statement.
- */
- private $_statement;
-
- /**
- * @var TPreparedCommand SQL command prepareer
- */
- private $_command;
-
- /**
- * @var TSqlMapper sqlmap used by this mapper.
- */
- private $_manager;
-
- /**
- * @var TPostSelectBinding[] post select statement queue.
- */
- private $_selectQueue=array();
-
- /**
- * @var boolean true when data is mapped to a particular row.
- */
- private $_IsRowDataFound = false;
-
- /**
- * @var TSQLMapObjectCollectionTree group by object collection tree
- */
- private $_groupBy;
-
- /**
- * @var Post select is to query for list.
- */
- const QUERY_FOR_LIST = 0;
-
- /**
- * @var Post select is to query for list.
- */
- const QUERY_FOR_ARRAY = 1;
-
- /**
- * @var Post select is to query for object.
- */
- const QUERY_FOR_OBJECT = 2;
-
- /**
- * @return string Name used to identify the TMappedStatement amongst the others.
- * This the name of the SQL statement by default.
- */
- public function getID()
- {
- return $this->_statement->ID;
- }
-
- /**
- * @return TSqlMapStatement The SQL statment used by this MappedStatement
- */
- public function getStatement()
- {
- return $this->_statement;
- }
-
- /**
- * @return TSqlMapper The SqlMap used by this MappedStatement
- */
- public function getManager()
- {
- return $this->_manager;
- }
-
- /**
- * @return TPreparedCommand command to prepare SQL statements.
- */
- public function getCommand()
- {
- return $this->_command;
- }
-
- /**
- * Empty the group by results cache.
- */
- protected function initialGroupByResults()
- {
- $this->_groupBy = new TSqlMapObjectCollectionTree();
- }
-
- /**
- * Creates a new mapped statement.
- * @param TSqlMapper an sqlmap.
- * @param TSqlMapStatement An SQL statement.
- */
- public function __construct(TSqlMapManager $sqlMap, TSqlMapStatement $statement)
- {
- $this->_manager = $sqlMap;
- $this->_statement = $statement;
- $this->_command = new TPreparedCommand();
- $this->initialGroupByResults();
- }
-
- public function getSqlString()
- {
- return $this->getStatement()->getSqlText()->getPreparedStatement()->getPreparedSql();
- }
-
- /**
- * Execute SQL Query.
- * @param IDbConnection database connection
- * @param array SQL statement and parameters.
- * @return mixed record set if applicable.
- * @throws TSqlMapExecutionException if execution error or false record set.
- * @throws TSqlMapQueryExecutionException if any execution error
- */
-/* protected function executeSQLQuery($connection, $sql)
- {
- try
- {
- if(!($recordSet = $connection->execute($sql['sql'],$sql['parameters'])))
- {
- throw new TSqlMapExecutionException(
- 'sqlmap_execution_error_no_record', $this->getID(),
- $connection->ErrorMsg());
- }
- return $recordSet;
- }
- catch (Exception $e)
- {
- throw new TSqlMapQueryExecutionException($this->getStatement(), $e);
- }
- }*/
-
- /**
- * Execute SQL Query with limits.
- * @param IDbConnection database connection
- * @param array SQL statement and parameters.
- * @return mixed record set if applicable.
- * @throws TSqlMapExecutionException if execution error or false record set.
- * @throws TSqlMapQueryExecutionException if any execution error
- */
- protected function executeSQLQueryLimit($connection, $command, $max, $skip)
- {
- if($max>-1 || $skip > -1)
- {
- $maxStr=$max>0?' LIMIT '.$max:'';
- $skipStr=$skip>0?' OFFSET '.$skip:'';
- $command->setText($command->getText().$maxStr.$skipStr);
- }
- $connection->setActive(true);
- return $command->query();
-
- /*//var_dump($command);
- try
- {
- $recordSet = $connection->selectLimit($sql['sql'],$max,$skip,$sql['parameters']);
- if(!$recordSet)
- {
- throw new TSqlMapExecutionException(
- 'sqlmap_execution_error_query_for_list',
- $connection->ErrorMsg());
- }
- return $recordSet;
- }
- catch (Exception $e)
- {
- throw new TSqlMapQueryExecutionException($this->getStatement(), $e);
- }*/
- }
-
- /**
- * Executes the SQL and retuns a List of result objects.
- * @param IDbConnection database connection
- * @param mixed The object used to set the parameters in the SQL.
- * @param object result collection object.
- * @param integer The number of rows to skip over.
- * @param integer The maximum number of rows to return.
- * @return array a list of result objects
- * @param callback row delegate handler
- * @see executeQueryForList()
- */
- public function executeQueryForList($connection, $parameter, $result=null, $skip=-1, $max=-1, $delegate=null)
- {
- $sql = $this->_command->create($this->_manager, $connection, $this->_statement, $parameter,$skip,$max);
- return $this->runQueryForList($connection, $parameter, $sql, $result, $delegate);
- }
-
- /**
- * Executes the SQL and retuns a List of result objects.
- *
- * This method should only be called by internal developers, consider using
- * <tt>executeQueryForList()</tt> first.
- *
- * @param IDbConnection database connection
- * @param mixed The object used to set the parameters in the SQL.
- * @param array SQL string and subsititution parameters.
- * @param object result collection object.
- * @param integer The number of rows to skip over.
- * @param integer The maximum number of rows to return.
- * @param callback row delegate handler
- * @return array a list of result objects
- * @see executeQueryForList()
- */
- public function runQueryForList($connection, $parameter, $sql, $result, $delegate=null)
- {
- $registry=$this->getManager()->getTypeHandlers();
- $list = $result instanceof ArrayAccess ? $result :
- $this->_statement->createInstanceOfListClass($registry);
- $connection->setActive(true);
- $reader = $sql->query();
- //$reader = $this->executeSQLQueryLimit($connection, $sql, $max, $skip);
- if($delegate!==null)
- {
- foreach($reader as $row)
- {
- $obj = $this->applyResultMap($row);
- $param = new TResultSetListItemParameter($obj, $parameter, $list);
- $this->raiseRowDelegate($delegate, $param);
- }
- }
- else
- {
- //var_dump($sql,$parameter);
- foreach($reader as $row)
- {
-// var_dump($row);
- $list[] = $this->applyResultMap($row);
- }
- }
-
- if(!$this->_groupBy->isEmpty())
- {
- $list = $this->_groupBy->collect();
- $this->initialGroupByResults();
- }
-
- $this->executePostSelect($connection);
- $this->onExecuteQuery($sql);
-
- return $list;
- }
-
- /**
- * Executes the SQL and retuns all rows selected in a map that is keyed on
- * the property named in the keyProperty parameter. The value at each key
- * will be the value of the property specified in the valueProperty parameter.
- * If valueProperty is null, the entire result object will be entered.
- * @param IDbConnection database connection
- * @param mixed The object used to set the parameters in the SQL.
- * @param string The property of the result object to be used as the key.
- * @param string The property of the result object to be used as the value (or null).
- * @param callback row delegate handler
- * @return array An array of object containing the rows keyed by keyProperty.
- */
- public function executeQueryForMap($connection, $parameter, $keyProperty, $valueProperty=null, $skip=-1, $max=-1, $delegate=null)
- {
- $sql = $this->_command->create($this->_manager, $connection, $this->_statement, $parameter, $skip, $max);
- return $this->runQueryForMap($connection, $parameter, $sql, $keyProperty, $valueProperty, $delegate);
- }
-
- /**
- * Executes the SQL and retuns all rows selected in a map that is keyed on
- * the property named in the keyProperty parameter. The value at each key
- * will be the value of the property specified in the valueProperty parameter.
- * If valueProperty is null, the entire result object will be entered.
- *
- * This method should only be called by internal developers, consider using
- * <tt>executeQueryForMap()</tt> first.
- *
- * @param IDbConnection database connection
- * @param mixed The object used to set the parameters in the SQL.
- * @param array SQL string and subsititution parameters.
- * @param string The property of the result object to be used as the key.
- * @param string The property of the result object to be used as the value (or null).
- * @param callback row delegate, a callback function
- * @return array An array of object containing the rows keyed by keyProperty.
- * @see executeQueryForMap()
- */
- public function runQueryForMap($connection, $parameter, $command, $keyProperty, $valueProperty=null, $delegate=null)
- {
- $map = array();
- //$recordSet = $this->executeSQLQuery($connection, $sql);
- $connection->setActive(true);
- $reader = $command->query();
- if($delegate!==null)
- {
- //while($row = $recordSet->fetchRow())
- foreach($reader as $row)
- {
- $obj = $this->applyResultMap($row);
- $key = TPropertyAccess::get($obj, $keyProperty);
- $value = ($valueProperty===null) ? $obj :
- TPropertyAccess::get($obj, $valueProperty);
- $param = new TResultSetMapItemParameter($key, $value, $parameter, $map);
- $this->raiseRowDelegate($delegate, $param);
- }
- }
- else
- {
- //while($row = $recordSet->fetchRow())
- foreach($reader as $row)
- {
- $obj = $this->applyResultMap($row);
- $key = TPropertyAccess::get($obj, $keyProperty);
- $map[$key] = ($valueProperty===null) ? $obj :
- TPropertyAccess::get($obj, $valueProperty);
- }
- }
- $this->onExecuteQuery($command);
- return $map;
- }
-
- /**
- * Raises delegate handler.
- * This method is invoked for each new list item. It is the responsibility
- * of the handler to add the item to the list.
- * @param object event parameter
- */
- protected function raiseRowDelegate($handler, $param)
- {
- if(is_string($handler))
- {
- call_user_func($handler,$this,$param);
- }
- else if(is_callable($handler,true))
- {
- // an array: 0 - object, 1 - method name/path
- list($object,$method)=$handler;
- if(is_string($object)) // static method call
- call_user_func($handler,$this,$param);
- else
- {
- if(($pos=strrpos($method,'.'))!==false)
- {
- $object=$this->getSubProperty(substr($method,0,$pos));
- $method=substr($method,$pos+1);
- }
- $object->$method($this,$param);
- }
- }
- else
- throw new TInvalidDataValueException('sqlmap_invalid_delegate', $this->getID(), $handler);
- }
-
- /**
- * Executes an SQL statement that returns a single row as an object of the
- * type of the <tt>$result</tt> passed in as a parameter.
- * @param IDbConnection database connection
- * @param mixed The parameter data (object, arrary, primitive) used to set the parameters in the SQL
- * @param mixed The result object.
- * @return ${return}
- */
- public function executeQueryForObject($connection, $parameter, $result=null)
- {
- $sql = $this->_command->create($this->_manager, $connection, $this->_statement, $parameter);
- return $this->runQueryForObject($connection, $sql, $result);
- }
-
- /**
- * Executes an SQL statement that returns a single row as an object of the
- * type of the <tt>$result</tt> passed in as a parameter.
- *
- * This method should only be called by internal developers, consider using
- * <tt>executeQueryForObject()</tt> first.
- *
- * @param IDbConnection database connection
- * @param array SQL string and subsititution parameters.
- * @param object The result object.
- * @return object the object.
- * @see executeQueryForObject()
- */
- public function runQueryForObject($connection, $command, &$result)
- {
- $object = null;
- $connection->setActive(true);
- foreach($command->query() as $row)
- $object = $this->applyResultMap($row, $result);
-
- if(!$this->_groupBy->isEmpty())
- {
- $list = $this->_groupBy->collect();
- $this->initialGroupByResults();
- $object = $list[0];
- }
-
- $this->executePostSelect($connection);
- $this->onExecuteQuery($command);
-
- return $object;
- }
-
- /**
- * Execute an insert statement. Fill the parameter object with the ouput
- * parameters if any, also could return the insert generated key.
- * @param IDbConnection database connection
- * @param mixed The parameter object used to fill the statement.
- * @return string the insert generated key.
- */
- public function executeInsert($connection, $parameter)
- {
- $generatedKey = $this->getPreGeneratedSelectKey($connection, $parameter);
-
- $command = $this->_command->create($this->_manager, $connection, $this->_statement, $parameter);
-// var_dump($command,$parameter);
- $result = $command->execute();
-
- if($generatedKey===null)
- $generatedKey = $this->getPostGeneratedSelectKey($connection, $parameter);
-
- $this->executePostSelect($connection);
- $this->onExecuteQuery($command);
- return $generatedKey;
- }
-
- /**
- * Gets the insert generated ID before executing an insert statement.
- * @param IDbConnection database connection
- * @param mixed insert statement parameter.
- * @return string new insert ID if pre-select key statement was executed, null otherwise.
- */
- protected function getPreGeneratedSelectKey($connection, $parameter)
- {
- if($this->_statement instanceof TSqlMapInsert)
- {
- $selectKey = $this->_statement->getSelectKey();
- if(($selectKey!==null) && !$selectKey->getIsAfter())
- return $this->executeSelectKey($connection, $parameter, $selectKey);
- }
- }
-
- /**
- * Gets the inserted row ID after executing an insert statement.
- * @param IDbConnection database connection
- * @param mixed insert statement parameter.
- * @return string last insert ID, null otherwise.
- */
- protected function getPostGeneratedSelectKey($connection, $parameter)
- {
- if($this->_statement instanceof TSqlMapInsert)
- {
- $selectKey = $this->_statement->getSelectKey();
- if(($selectKey!==null) && $selectKey->getIsAfter())
- return $this->executeSelectKey($connection, $parameter, $selectKey);
- }
- }
-
- /**
- * Execute the select key statement, used to obtain last insert ID.
- * @param IDbConnection database connection
- * @param mixed insert statement parameter
- * @param TSqlMapSelectKey select key statement
- * @return string last insert ID.
- */
- protected function executeSelectKey($connection, $parameter, $selectKey)
- {
- $mappedStatement = $this->getManager()->getMappedStatement($selectKey->getID());
- $generatedKey = $mappedStatement->executeQueryForObject(
- $connection, $parameter, null);
- if(strlen($prop = $selectKey->getProperty()) > 0)
- TPropertyAccess::set($parameter, $prop, $generatedKey);
- return $generatedKey;
- }
-
- /**
- * Execute an update statement. Also used for delete statement.
- * Return the number of rows effected.
- * @param IDbConnection database connection
- * @param mixed The object used to set the parameters in the SQL.
- * @return integer The number of rows effected.
- */
- public function executeUpdate($connection, $parameter)
- {
- $sql = $this->_command->create($this->getManager(),$connection, $this->_statement, $parameter);
- $affectedRows = $sql->execute();
- //$this->executeSQLQuery($connection, $sql);
- $this->executePostSelect($connection);
- $this->onExecuteQuery($sql);
- return $affectedRows;
- }
-
- /**
- * Process 'select' result properties
- * @param IDbConnection database connection
- */
- protected function executePostSelect($connection)
- {
- while(count($this->_selectQueue))
- {
- $postSelect = array_shift($this->_selectQueue);
- $method = $postSelect->getMethod();
- $statement = $postSelect->getStatement();
- $property = $postSelect->getResultProperty()->getProperty();
- $keys = $postSelect->getKeys();
- $resultObject = $postSelect->getResultObject();
-
- if($method == self::QUERY_FOR_LIST || $method == self::QUERY_FOR_ARRAY)
- {
- $values = $statement->executeQueryForList($connection, $keys, null);
-
- if($method == self::QUERY_FOR_ARRAY)
- $values = $values->toArray();
- TPropertyAccess::set($resultObject, $property, $values);
- }
- else if($method == self::QUERY_FOR_OBJECT)
- {
- $value = $statement->executeQueryForObject($connection, $keys, null);
- TPropertyAccess::set($resultObject, $property, $value);
- }
- }
- }
-
- /**
- * Raise the execute query event.
- * @param array prepared SQL statement and subsititution parameters
- */
- public function onExecuteQuery($sql)
- {
- $this->raiseEvent('OnExecuteQuery', $this, $sql);
- }
-
- /**
- * Apply result mapping.
- * @param array a result set row retrieved from the database
- * @param object the result object, will create if necessary.
- * @return object the result filled with data, null if not filled.
- */
- protected function applyResultMap($row, &$resultObject=null)
- {
- if($row === false) return null;
-
- $resultMapName = $this->_statement->getResultMap();
- $resultClass = $this->_statement->getResultClass();
-
- $obj=null;
- if($this->getManager()->getResultMaps()->contains($resultMapName))
- $obj = $this->fillResultMap($resultMapName, $row, null, $resultObject);
- else if(strlen($resultClass) > 0)
- $obj = $this->fillResultClass($resultClass, $row, $resultObject);
- else
- $obj = $this->fillDefaultResultMap(null, $row, $resultObject);
- if(class_exists('TActiveRecord',false) && $obj instanceof TActiveRecord)
- //Create a new clean active record.
- $obj=TActiveRecord::createRecord(get_class($obj),$obj);
- return $obj;
- }
-
- /**
- * Fill the result using ResultClass, will creates new result object if required.
- * @param string result object class name
- * @param array a result set row retrieved from the database
- * @param object the result object, will create if necessary.
- * @return object result object filled with data
- */
- protected function fillResultClass($resultClass, $row, $resultObject)
- {
- if($resultObject===null)
- {
- $registry = $this->getManager()->getTypeHandlers();
- $resultObject = $this->_statement->createInstanceOfResultClass($registry,$row);
- }
-
- if($resultObject instanceOf ArrayAccess)
- return $this->fillResultArrayList($row, $resultObject);
- else if(is_object($resultObject))
- return $this->fillResultObjectProperty($row, $resultObject);
- else
- return $this->fillDefaultResultMap(null, $row, $resultObject);
- }
-
- /**
- * Apply the result to a TList or an array.
- * @param array a result set row retrieved from the database
- * @param object result object, array or list
- * @return object result filled with data.
- */
- protected function fillResultArrayList($row, $resultObject)
- {
- if($resultObject instanceof TList)
- foreach($row as $v)
- $resultObject[] = $v;
- else
- foreach($row as $k => $v)
- $resultObject[$k] = $v;
- return $resultObject;
- }
-
- /**
- * Apply the result to an object.
- * @param array a result set row retrieved from the database
- * @param object result object, array or list
- * @return object result filled with data.
- */
- protected function fillResultObjectProperty($row, $resultObject)
- {
- $index = 0;
- $registry=$this->getManager()->getTypeHandlers();
- foreach($row as $k=>$v)
- {
- $property = new TResultProperty;
- if(is_string($k) && strlen($k) > 0)
- $property->setColumn($k);
- $property->setColumnIndex(++$index);
- $type = gettype(TPropertyAccess::get($resultObject,$k));
- $property->setType($type);
- $value = $property->getPropertyValue($registry,$row);
- TPropertyAccess::set($resultObject, $k,$value);
- }
- return $resultObject;
- }
-
- /**
- * Fills the result object according to result mappings.
- * @param string result map name.
- * @param array a result set row retrieved from the database
- * @param object result object to fill, will create new instances if required.
- * @return object result object filled with data.
- */
- protected function fillResultMap($resultMapName, $row, $parentGroup=null, &$resultObject=null)
- {
- $resultMap = $this->getManager()->getResultMap($resultMapName);
- $registry = $this->getManager()->getTypeHandlers();
- $resultMap = $resultMap->resolveSubMap($registry,$row);
-
- if($resultObject===null)
- $resultObject = $resultMap->createInstanceOfResult($registry);
-
- if(is_object($resultObject))
- {
- if(strlen($resultMap->getGroupBy()) > 0)
- return $this->addResultMapGroupBy($resultMap, $row, $parentGroup, $resultObject);
- else
- foreach($resultMap->getColumns() as $property)
- $this->setObjectProperty($resultMap, $property, $row, $resultObject);
- }
- else
- {
- $resultObject = $this->fillDefaultResultMap($resultMap, $row, $resultObject);
- }
- return $resultObject;
- }
-
- /**
- * ResultMap with GroupBy property. Save object collection graph in a tree
- * and collect the result later.
- * @param TResultMap result mapping details.
- * @param array a result set row retrieved from the database
- * @param object the result object
- * @return object result object.
- */
- protected function addResultMapGroupBy($resultMap, $row, $parent, &$resultObject)
- {
- $group = $this->getResultMapGroupKey($resultMap, $row);
-
- if(empty($parent))
- {
- $rootObject = array('object'=>$resultObject, 'property' => null);
- $this->_groupBy->add(null, $group, $rootObject);
- }
-
- foreach($resultMap->getColumns() as $property)
- {
- //set properties.
- $this->setObjectProperty($resultMap, $property, $row, $resultObject);
- $nested = $property->getResultMapping();
-
- //nested property
- if($this->getManager()->getResultMaps()->contains($nested))
- {
- $nestedMap = $this->getManager()->getResultMap($nested);
- $groupKey = $this->getResultMapGroupKey($nestedMap, $row);
-
- //add the node reference first
- if(empty($parent))
- $this->_groupBy->add($group, $groupKey, '');
-
- //get the nested result mapping value
- $value = $this->fillResultMap($nested, $row, $groupKey);
-
- //add it to the object tree graph
- $groupObject = array('object'=>$value, 'property' => $property->getProperty());
- if(empty($parent))
- $this->_groupBy->add($group, $groupKey, $groupObject);
- else
- $this->_groupBy->add($parent, $groupKey, $groupObject);
- }
- }
- return $resultObject;
- }
-
- /**
- * Gets the result 'group by' groupping key for each row.
- * @param TResultMap result mapping details.
- * @param array a result set row retrieved from the database
- * @return string groupping key.
- */
- protected function getResultMapGroupKey($resultMap, $row)
- {
- $groupBy = $resultMap->getGroupBy();
- if(isset($row[$groupBy]))
- return $resultMap->getID().$row[$groupBy];
- else
- return $resultMap->getID().crc32(serialize($row));
- }
-
- /**
- * Fill the result map using default settings. If <tt>$resultMap</tt> is null
- * the result object returned will be guessed from <tt>$resultObject</tt>.
- * @param TResultMap result mapping details.
- * @param array a result set row retrieved from the database
- * @param object the result object
- * @return mixed the result object filled with data.
- */
- protected function fillDefaultResultMap($resultMap, $row, $resultObject)
- {
- if($resultObject===null)
- $resultObject='';
-
- if($resultMap!==null)
- $result = $this->fillArrayResultMap($resultMap, $row, $resultObject);
- else
- $result = $row;
-
- //if scalar result types
- if(count($result) == 1 && ($type = gettype($resultObject))!= 'array')
- return $this->getScalarResult($result, $type);
- else
- return $result;
- }
-
- /**
- * Retrieve the result map as an array.
- * @param TResultMap result mapping details.
- * @param array a result set row retrieved from the database
- * @param object the result object
- * @return array array list of result objects.
- */
- protected function fillArrayResultMap($resultMap, $row, $resultObject)
- {
- $result = array();
- $registry=$this->getManager()->getTypeHandlers();
- foreach($resultMap->getColumns() as $column)
- {
- if(($column->getType()===null)
- && ($resultObject!==null) && !is_object($resultObject))
- $column->setType(gettype($resultObject));
- $result[$column->getProperty()] = $column->getPropertyValue($registry,$row);
- }
- return $result;
- }
-
- /**
- * Converts the first array value to scalar value of given type.
- * @param array list of results
- * @param string scalar type.
- * @return mixed scalar value.
- */
- protected function getScalarResult($result, $type)
- {
- $scalar = array_shift($result);
- settype($scalar, $type);
- return $scalar;
- }
-
- /**
- * Set a property of the result object with appropriate value.
- * @param TResultMap result mapping details.
- * @param TResultProperty the result property to fill.
- * @param array a result set row retrieved from the database
- * @param object the result object
- */
- protected function setObjectProperty($resultMap, $property, $row, &$resultObject)
- {
- $select = $property->getSelect();
- $key = $property->getProperty();
- $nested = $property->getNestedResultMap();
- $registry=$this->getManager()->getTypeHandlers();
- if($key === '')
- {
- $resultObject = $property->getPropertyValue($registry,$row);
- }
- else if(strlen($select) == 0 && ($nested===null))
- {
- $value = $property->getPropertyValue($registry,$row);
-
- $this->_IsRowDataFound = $this->_IsRowDataFound || ($value != null);
- if(is_array($resultObject) || is_object($resultObject))
- TPropertyAccess::set($resultObject, $key, $value);
- else
- $resultObject = $value;
- }
- else if($nested!==null)
- {
- if($property->instanceOfListType($resultObject) || $property->instanceOfArrayType($resultObject))
- {
- if(strlen($resultMap->getGroupBy()) <= 0)
- throw new TSqlMapExecutionException(
- 'sqlmap_non_groupby_array_list_type', $resultMap->getID(),
- get_class($resultObject), $key);
- }
- else
- {
- $obj = $nested->createInstanceOfResult($this->getManager()->getTypeHandlers());
- if($this->fillPropertyWithResultMap($nested, $row, $obj) == false)
- $obj = null;
- TPropertyAccess::set($resultObject, $key, $obj);
- }
- }
- else //'select' ResultProperty
- {
- $this->enquequePostSelect($select, $resultMap, $property, $row, $resultObject);
- }
- }
-
- /**
- * Add nested result property to post select queue.
- * @param string post select statement ID
- * @param TResultMap current result mapping details.
- * @param TResultProperty current result property.
- * @param array a result set row retrieved from the database
- * @param object the result object
- */
- protected function enquequePostSelect($select, $resultMap, $property, $row, $resultObject)
- {
- $statement = $this->getManager()->getMappedStatement($select);
- $key = $this->getPostSelectKeys($resultMap, $property, $row);
- $postSelect = new TPostSelectBinding;
- $postSelect->setStatement($statement);
- $postSelect->setResultObject($resultObject);
- $postSelect->setResultProperty($property);
- $postSelect->setKeys($key);
-
- if($property->instanceOfListType($resultObject))
- {
- $values = null;
- if($property->getLazyLoad())
- {
- $values = TLazyLoadList::newInstance($statement, $key,
- $resultObject, $property->getProperty());
- TPropertyAccess::set($resultObject, $property->getProperty(), $values);
- }
- else
- $postSelect->setMethod(self::QUERY_FOR_LIST);
- }
- else if($property->instanceOfArrayType($resultObject))
- $postSelect->setMethod(self::QUERY_FOR_ARRAY);
- else
- $postSelect->setMethod(self::QUERY_FOR_OBJECT);
-
- if(!$property->getLazyLoad())
- $this->_selectQueue[] = $postSelect;
- }
-
- /**
- * Finds in the post select property the SQL statement primary selection keys.
- * @param TResultMap result mapping details
- * @param TResultProperty result property
- * @param array current row data.
- * @return array list of primary key values.
- */
- protected function getPostSelectKeys($resultMap, $property,$row)
- {
- $value = $property->getColumn();
- if(is_int(strpos($value.',',0)) || is_int(strpos($value, '=',0)))
- {
- $keys = array();
- foreach(explode(',', $value) as $entry)
- {
- $pair =explode('=',$entry);
- $keys[trim($pair[0])] = $row[trim($pair[1])];
- }
- return $keys;
- }
- else
- {
- $registry=$this->getManager()->getTypeHandlers();
- return $property->getPropertyValue($registry,$row);
- }
- }
-
- /**
- * Fills the property with result mapping results.
- * @param TResultMap nested result mapping details.
- * @param array a result set row retrieved from the database
- * @param object the result object
- * @return boolean true if the data was found, false otherwise.
- */
- protected function fillPropertyWithResultMap($resultMap, $row, &$resultObject)
- {
- $dataFound = false;
- foreach($resultMap->getColumns() as $property)
- {
- $this->_IsRowDataFound = false;
- $this->setObjectProperty($resultMap, $property, $row, $resultObject);
- $dataFound = $dataFound || $this->_IsRowDataFound;
- }
- $this->_IsRowDataFound = $dataFound;
- return $dataFound;
- }
-
- public function __wakeup()
- {
- parent::__wakeup();
- if (is_null($this->_selectQueue)) $this->_selectQueue = array();
- }
-
- public function __sleep()
- {
- $exprops = array(); $cn = __CLASS__;
- if (!count($this->_selectQueue)) $exprops[] = "\0$cn\0_selectQueue";
- if (is_null($this->_groupBy)) $exprops[] = "\0$cn\0_groupBy";
- if (!$this->_IsRowDataFound) $exprops[] = "\0$cn\0_IsRowDataFound";
- return array_diff(parent::__sleep(),$exprops);
- }
-}
-
-/**
- * TPostSelectBinding class.
- *
- * @author Wei Zhuo <weizho[at]gmail[dot]com>
- * @version $Id$
- * @package System.Data.SqlMap.Statements
- * @since 3.1
- */
-class TPostSelectBinding
-{
- private $_statement=null;
- private $_property=null;
- private $_resultObject=null;
- private $_keys=null;
- private $_method=TMappedStatement::QUERY_FOR_LIST;
-
- public function getStatement(){ return $this->_statement; }
- public function setStatement($value){ $this->_statement = $value; }
-
- public function getResultProperty(){ return $this->_property; }
- public function setResultProperty($value){ $this->_property = $value; }
-
- public function getResultObject(){ return $this->_resultObject; }
- public function setResultObject($value){ $this->_resultObject = $value; }
-
- public function getKeys(){ return $this->_keys; }
- public function setKeys($value){ $this->_keys = $value; }
-
- public function getMethod(){ return $this->_method; }
- public function setMethod($value){ $this->_method = $value; }
-}
-
-/**
- * TSQLMapObjectCollectionTree class.
- *
- * Maps object collection graphs as trees. Nodes in the collection can
- * be {@link add} using parent relationships. The object collections can be
- * build using the {@link collect} method.
- *
- * @author Wei Zhuo <weizhuo[at]gmail[dot]com>
- * @version $Id$
- * @package System.Data.SqlMap.Statements
- * @since 3.1
- */
-class TSqlMapObjectCollectionTree extends TComponent
-{
- /**
- * @var array object graph as tree
- */
- private $_tree = array();
- /**
- * @var array tree node values
- */
- private $_entries = array();
- /**
- * @var array resulting object collection
- */
- private $_list = array();
-
- /**
- * @return boolean true if the graph is empty
- */
- public function isEmpty()
- {
- return count($this->_entries) == 0;
- }
-
- /**
- * Add a new node to the object tree graph.
- * @param string parent node id
- * @param string new node id
- * @param mixed node value
- */
- public function add($parent, $node, $object='')
- {
- if(isset($this->_entries[$parent]) && ($this->_entries[$parent]!==null)
- && isset($this->_entries[$node]) && ($this->_entries[$node]!==null))
- {
- $this->_entries[$node] = $object;
- return;
- }
- $this->_entries[$node] = $object;
- if(empty($parent))
- {
- if(isset($this->_entries[$node]))
- return;
- $this->_tree[$node] = array();
- }
- $found = $this->addNode($this->_tree, $parent, $node);
- if(!$found && !empty($parent))
- {
- $this->_tree[$parent] = array();
- if(!isset($this->_entries[$parent]) || $object !== '')
- $this->_entries[$parent] = $object;
- $this->addNode($this->_tree, $parent, $node);
- }
- }
-
- /**
- * Find the parent node and add the new node as its child.
- * @param array list of nodes to check
- * @param string parent node id
- * @param string new node id
- * @return boolean true if parent node is found.
- */
- protected function addNode(&$childs, $parent, $node)
- {
- $found = false;
- reset($childs);
- for($i = 0, $k = count($childs); $i < $k; $i++)
- {
- $key = key($childs);
- next($childs);
- if($key == $parent)
- {
- $found = true;
- $childs[$key][$node] = array();
- }
- else
- {
- $found = $found || $this->addNode($childs[$key], $parent, $node);
- }
- }
- return $found;
- }
-
- /**
- * @return array object collection
- */
- public function collect()
- {
- while(count($this->_tree) > 0)
- $this->collectChildren(null, $this->_tree);
- return $this->getCollection();
- }
-
- /**
- * @param array list of nodes to check
- * @return boolean true if all nodes are leaf nodes, false otherwise
- */
- protected function hasChildren(&$nodes)
- {
- $hasChildren = false;
- foreach($nodes as $node)
- if(count($node) != 0)
- return true;
- return $hasChildren;
- }
-
- /**
- * Visit all the child nodes and collect them by removing.
- * @param string parent node id
- * @param array list of child nodes.
- */
- protected function collectChildren($parent, &$nodes)
- {
- $noChildren = !$this->hasChildren($nodes);
- $childs = array();
- for(reset($nodes); $key = key($nodes);)
- {
- next($nodes);
- if($noChildren)
- {
- $childs[] = $key;
- unset($nodes[$key]);
- }
- else
- $this->collectChildren($key, $nodes[$key]);
- }
- if(count($childs) > 0)
- $this->onChildNodesVisited($parent, $childs);
- }
-
- /**
- * Set the object properties for all the child nodes visited.
- * @param string parent node id
- * @param array list of child nodes visited.
- */
- protected function onChildNodesVisited($parent, $nodes)
- {
- if(empty($parent) || empty($this->_entries[$parent]))
- return;
-
- $parentObject = $this->_entries[$parent]['object'];
- $property = $this->_entries[$nodes[0]]['property'];
-
- $list = TPropertyAccess::get($parentObject, $property);
-
- foreach($nodes as $node)
- {
- if($list instanceof TList)
- $parentObject->{$property}[] = $this->_entries[$node]['object'];
- else if(is_array($list))
- $list[] = $this->_entries[$node]['object'];
- else
- throw new TSqlMapExecutionException(
- 'sqlmap_property_must_be_list');
- }
-
- if(is_array($list))
- TPropertyAccess::set($parentObject, $property, $list);
-
- if($this->_entries[$parent]['property'] === null)
- $this->_list[] = $parentObject;
- }
-
- /**
- * @return array object collection.
- */
- protected function getCollection()
- {
- return $this->_list;
- }
-
- public function __sleep()
- {
- $exprops = array(); $cn = __CLASS__;
- if (!count($this->_tree)) $exprops[] = "\0$cn\0_tree";
- if (!count($this->_entries)) $exprops[] = "\0$cn\0_entries";
- if (!count($this->_list)) $exprops[] = "\0$cn\0_list";
- return array_diff(parent::__sleep(),$exprops);
- }
-}
-
-/**
- * TResultSetListItemParameter class
- *
- * @author Wei Zhuo <weizho[at]gmail[dot]com>
- * @version $Id$
- * @package System.Data.SqlMap.Statements
- * @since 3.1
- */
-class TResultSetListItemParameter extends TComponent
-{
- private $_resultObject;
- private $_parameterObject;
- private $_list;
-
- public function __construct($result, $parameter, &$list)
- {
- $this->_resultObject = $result;
- $this->_parameterObject = $parameter;
- $this->_list = &$list;
- }
-
- public function getResult()
- {
- return $this->_resultObject;
- }
-
- public function getParameter()
- {
- return $this->_parameterObject;
- }
-
- public function &getList()
- {
- return $this->_list;
- }
-}
-
-/**
- * TResultSetMapItemParameter class.
- *
- * @author Wei Zhuo <weizho[at]gmail[dot]com>
- * @version $Id$
- * @package System.Data.SqlMap.Statements
- * @since 3.1
- */
-class TResultSetMapItemParameter extends TComponent
-{
- private $_key;
- private $_value;
- private $_parameterObject;
- private $_map;
-
- public function __construct($key, $value, $parameter, &$map)
- {
- $this->_key = $key;
- $this->_value = $value;
- $this->_parameterObject = $parameter;
- $this->_map = &$map;
- }
-
- public function getKey()
- {
- return $this->_key;
- }
-
- public function getValue()
- {
- return $this->_value;
- }
-
- public function getParameter()
- {
- return $this->_parameterObject;
- }
-
- public function &getMap()
- {
- return $this->_map;
- }
-}
-
+<?php
+/**
+ * TMappedStatement and related classes.
+ *
+ * @author Wei Zhuo <weizhuo[at]gmail[dot]com>
+ * @link http://www.pradosoft.com/
+ * @copyright Copyright &copy; 2005-2012 PradoSoft
+ * @license http://www.pradosoft.com/license/
+ * @version $Id$
+ * @package System.Data.SqlMap.Statements
+ */
+
+/**
+ * TMappedStatement class executes SQL mapped statements. Mapped Statements can
+ * hold any SQL statement and use Parameter Maps and Result Maps for input and output.
+ *
+ * This class is usualy instantiated during SQLMap configuration by TSqlDomBuilder.
+ *
+ * @author Wei Zhuo <weizhuo[at]gmail[dot]com>
+ * @version $Id$
+ * @package System.Data.SqlMap.Statements
+ * @since 3.0
+ */
+class TMappedStatement extends TComponent implements IMappedStatement
+{
+ /**
+ * @var TSqlMapStatement current SQL statement.
+ */
+ private $_statement;
+
+ /**
+ * @var TPreparedCommand SQL command prepareer
+ */
+ private $_command;
+
+ /**
+ * @var TSqlMapper sqlmap used by this mapper.
+ */
+ private $_manager;
+
+ /**
+ * @var TPostSelectBinding[] post select statement queue.
+ */
+ private $_selectQueue=array();
+
+ /**
+ * @var boolean true when data is mapped to a particular row.
+ */
+ private $_IsRowDataFound = false;
+
+ /**
+ * @var TSQLMapObjectCollectionTree group by object collection tree
+ */
+ private $_groupBy;
+
+ /**
+ * @var Post select is to query for list.
+ */
+ const QUERY_FOR_LIST = 0;
+
+ /**
+ * @var Post select is to query for list.
+ */
+ const QUERY_FOR_ARRAY = 1;
+
+ /**
+ * @var Post select is to query for object.
+ */
+ const QUERY_FOR_OBJECT = 2;
+
+ /**
+ * @return string Name used to identify the TMappedStatement amongst the others.
+ * This the name of the SQL statement by default.
+ */
+ public function getID()
+ {
+ return $this->_statement->ID;
+ }
+
+ /**
+ * @return TSqlMapStatement The SQL statment used by this MappedStatement
+ */
+ public function getStatement()
+ {
+ return $this->_statement;
+ }
+
+ /**
+ * @return TSqlMapper The SqlMap used by this MappedStatement
+ */
+ public function getManager()
+ {
+ return $this->_manager;
+ }
+
+ /**
+ * @return TPreparedCommand command to prepare SQL statements.
+ */
+ public function getCommand()
+ {
+ return $this->_command;
+ }
+
+ /**
+ * Empty the group by results cache.
+ */
+ protected function initialGroupByResults()
+ {
+ $this->_groupBy = new TSqlMapObjectCollectionTree();
+ }
+
+ /**
+ * Creates a new mapped statement.
+ * @param TSqlMapper an sqlmap.
+ * @param TSqlMapStatement An SQL statement.
+ */
+ public function __construct(TSqlMapManager $sqlMap, TSqlMapStatement $statement)
+ {
+ $this->_manager = $sqlMap;
+ $this->_statement = $statement;
+ $this->_command = new TPreparedCommand();
+ $this->initialGroupByResults();
+ }
+
+ public function getSqlString()
+ {
+ return $this->getStatement()->getSqlText()->getPreparedStatement()->getPreparedSql();
+ }
+
+ /**
+ * Execute SQL Query.
+ * @param IDbConnection database connection
+ * @param array SQL statement and parameters.
+ * @return mixed record set if applicable.
+ * @throws TSqlMapExecutionException if execution error or false record set.
+ * @throws TSqlMapQueryExecutionException if any execution error
+ */
+/* protected function executeSQLQuery($connection, $sql)
+ {
+ try
+ {
+ if(!($recordSet = $connection->execute($sql['sql'],$sql['parameters'])))
+ {
+ throw new TSqlMapExecutionException(
+ 'sqlmap_execution_error_no_record', $this->getID(),
+ $connection->ErrorMsg());
+ }
+ return $recordSet;
+ }
+ catch (Exception $e)
+ {
+ throw new TSqlMapQueryExecutionException($this->getStatement(), $e);
+ }
+ }*/
+
+ /**
+ * Execute SQL Query with limits.
+ * @param IDbConnection database connection
+ * @param array SQL statement and parameters.
+ * @return mixed record set if applicable.
+ * @throws TSqlMapExecutionException if execution error or false record set.
+ * @throws TSqlMapQueryExecutionException if any execution error
+ */
+ protected function executeSQLQueryLimit($connection, $command, $max, $skip)
+ {
+ if($max>-1 || $skip > -1)
+ {
+ $maxStr=$max>0?' LIMIT '.$max:'';
+ $skipStr=$skip>0?' OFFSET '.$skip:'';
+ $command->setText($command->getText().$maxStr.$skipStr);
+ }
+ $connection->setActive(true);
+ return $command->query();
+
+ /*//var_dump($command);
+ try
+ {
+ $recordSet = $connection->selectLimit($sql['sql'],$max,$skip,$sql['parameters']);
+ if(!$recordSet)
+ {
+ throw new TSqlMapExecutionException(
+ 'sqlmap_execution_error_query_for_list',
+ $connection->ErrorMsg());
+ }
+ return $recordSet;
+ }
+ catch (Exception $e)
+ {
+ throw new TSqlMapQueryExecutionException($this->getStatement(), $e);
+ }*/
+ }
+
+ /**
+ * Executes the SQL and retuns a List of result objects.
+ * @param IDbConnection database connection
+ * @param mixed The object used to set the parameters in the SQL.
+ * @param object result collection object.
+ * @param integer The number of rows to skip over.
+ * @param integer The maximum number of rows to return.
+ * @return array a list of result objects
+ * @param callback row delegate handler
+ * @see executeQueryForList()
+ */
+ public function executeQueryForList($connection, $parameter, $result=null, $skip=-1, $max=-1, $delegate=null)
+ {
+ $sql = $this->_command->create($this->_manager, $connection, $this->_statement, $parameter,$skip,$max);
+ return $this->runQueryForList($connection, $parameter, $sql, $result, $delegate);
+ }
+
+ /**
+ * Executes the SQL and retuns a List of result objects.
+ *
+ * This method should only be called by internal developers, consider using
+ * <tt>executeQueryForList()</tt> first.
+ *
+ * @param IDbConnection database connection
+ * @param mixed The object used to set the parameters in the SQL.
+ * @param array SQL string and subsititution parameters.
+ * @param object result collection object.
+ * @param integer The number of rows to skip over.
+ * @param integer The maximum number of rows to return.
+ * @param callback row delegate handler
+ * @return array a list of result objects
+ * @see executeQueryForList()
+ */
+ public function runQueryForList($connection, $parameter, $sql, $result, $delegate=null)
+ {
+ $registry=$this->getManager()->getTypeHandlers();
+ $list = $result instanceof ArrayAccess ? $result :
+ $this->_statement->createInstanceOfListClass($registry);
+ $connection->setActive(true);
+ $reader = $sql->query();
+ //$reader = $this->executeSQLQueryLimit($connection, $sql, $max, $skip);
+ if($delegate!==null)
+ {
+ foreach($reader as $row)
+ {
+ $obj = $this->applyResultMap($row);
+ $param = new TResultSetListItemParameter($obj, $parameter, $list);
+ $this->raiseRowDelegate($delegate, $param);
+ }
+ }
+ else
+ {
+ //var_dump($sql,$parameter);
+ foreach($reader as $row)
+ {
+// var_dump($row);
+ $list[] = $this->applyResultMap($row);
+ }
+ }
+
+ if(!$this->_groupBy->isEmpty())
+ {
+ $list = $this->_groupBy->collect();
+ $this->initialGroupByResults();
+ }
+
+ $this->executePostSelect($connection);
+ $this->onExecuteQuery($sql);
+
+ return $list;
+ }
+
+ /**
+ * Executes the SQL and retuns all rows selected in a map that is keyed on
+ * the property named in the keyProperty parameter. The value at each key
+ * will be the value of the property specified in the valueProperty parameter.
+ * If valueProperty is null, the entire result object will be entered.
+ * @param IDbConnection database connection
+ * @param mixed The object used to set the parameters in the SQL.
+ * @param string The property of the result object to be used as the key.
+ * @param string The property of the result object to be used as the value (or null).
+ * @param callback row delegate handler
+ * @return array An array of object containing the rows keyed by keyProperty.
+ */
+ public function executeQueryForMap($connection, $parameter, $keyProperty, $valueProperty=null, $skip=-1, $max=-1, $delegate=null)
+ {
+ $sql = $this->_command->create($this->_manager, $connection, $this->_statement, $parameter, $skip, $max);
+ return $this->runQueryForMap($connection, $parameter, $sql, $keyProperty, $valueProperty, $delegate);
+ }
+
+ /**
+ * Executes the SQL and retuns all rows selected in a map that is keyed on
+ * the property named in the keyProperty parameter. The value at each key
+ * will be the value of the property specified in the valueProperty parameter.
+ * If valueProperty is null, the entire result object will be entered.
+ *
+ * This method should only be called by internal developers, consider using
+ * <tt>executeQueryForMap()</tt> first.
+ *
+ * @param IDbConnection database connection
+ * @param mixed The object used to set the parameters in the SQL.
+ * @param array SQL string and subsititution parameters.
+ * @param string The property of the result object to be used as the key.
+ * @param string The property of the result object to be used as the value (or null).
+ * @param callback row delegate, a callback function
+ * @return array An array of object containing the rows keyed by keyProperty.
+ * @see executeQueryForMap()
+ */
+ public function runQueryForMap($connection, $parameter, $command, $keyProperty, $valueProperty=null, $delegate=null)
+ {
+ $map = array();
+ //$recordSet = $this->executeSQLQuery($connection, $sql);
+ $connection->setActive(true);
+ $reader = $command->query();
+ if($delegate!==null)
+ {
+ //while($row = $recordSet->fetchRow())
+ foreach($reader as $row)
+ {
+ $obj = $this->applyResultMap($row);
+ $key = TPropertyAccess::get($obj, $keyProperty);
+ $value = ($valueProperty===null) ? $obj :
+ TPropertyAccess::get($obj, $valueProperty);
+ $param = new TResultSetMapItemParameter($key, $value, $parameter, $map);
+ $this->raiseRowDelegate($delegate, $param);
+ }
+ }
+ else
+ {
+ //while($row = $recordSet->fetchRow())
+ foreach($reader as $row)
+ {
+ $obj = $this->applyResultMap($row);
+ $key = TPropertyAccess::get($obj, $keyProperty);
+ $map[$key] = ($valueProperty===null) ? $obj :
+ TPropertyAccess::get($obj, $valueProperty);
+ }
+ }
+ $this->onExecuteQuery($command);
+ return $map;
+ }
+
+ /**
+ * Raises delegate handler.
+ * This method is invoked for each new list item. It is the responsibility
+ * of the handler to add the item to the list.
+ * @param object event parameter
+ */
+ protected function raiseRowDelegate($handler, $param)
+ {
+ if(is_string($handler))
+ {
+ call_user_func($handler,$this,$param);
+ }
+ else if(is_callable($handler,true))
+ {
+ // an array: 0 - object, 1 - method name/path
+ list($object,$method)=$handler;
+ if(is_string($object)) // static method call
+ call_user_func($handler,$this,$param);
+ else
+ {
+ if(($pos=strrpos($method,'.'))!==false)
+ {
+ $object=$this->getSubProperty(substr($method,0,$pos));
+ $method=substr($method,$pos+1);
+ }
+ $object->$method($this,$param);
+ }
+ }
+ else
+ throw new TInvalidDataValueException('sqlmap_invalid_delegate', $this->getID(), $handler);
+ }
+
+ /**
+ * Executes an SQL statement that returns a single row as an object of the
+ * type of the <tt>$result</tt> passed in as a parameter.
+ * @param IDbConnection database connection
+ * @param mixed The parameter data (object, arrary, primitive) used to set the parameters in the SQL
+ * @param mixed The result object.
+ * @return ${return}
+ */
+ public function executeQueryForObject($connection, $parameter, $result=null)
+ {
+ $sql = $this->_command->create($this->_manager, $connection, $this->_statement, $parameter);
+ return $this->runQueryForObject($connection, $sql, $result);
+ }
+
+ /**
+ * Executes an SQL statement that returns a single row as an object of the
+ * type of the <tt>$result</tt> passed in as a parameter.
+ *
+ * This method should only be called by internal developers, consider using
+ * <tt>executeQueryForObject()</tt> first.
+ *
+ * @param IDbConnection database connection
+ * @param array SQL string and subsititution parameters.
+ * @param object The result object.
+ * @return object the object.
+ * @see executeQueryForObject()
+ */
+ public function runQueryForObject($connection, $command, &$result)
+ {
+ $object = null;
+ $connection->setActive(true);
+ foreach($command->query() as $row)
+ $object = $this->applyResultMap($row, $result);
+
+ if(!$this->_groupBy->isEmpty())
+ {
+ $list = $this->_groupBy->collect();
+ $this->initialGroupByResults();
+ $object = $list[0];
+ }
+
+ $this->executePostSelect($connection);
+ $this->onExecuteQuery($command);
+
+ return $object;
+ }
+
+ /**
+ * Execute an insert statement. Fill the parameter object with the ouput
+ * parameters if any, also could return the insert generated key.
+ * @param IDbConnection database connection
+ * @param mixed The parameter object used to fill the statement.
+ * @return string the insert generated key.
+ */
+ public function executeInsert($connection, $parameter)
+ {
+ $generatedKey = $this->getPreGeneratedSelectKey($connection, $parameter);
+
+ $command = $this->_command->create($this->_manager, $connection, $this->_statement, $parameter);
+// var_dump($command,$parameter);
+ $result = $command->execute();
+
+ if($generatedKey===null)
+ $generatedKey = $this->getPostGeneratedSelectKey($connection, $parameter);
+
+ $this->executePostSelect($connection);
+ $this->onExecuteQuery($command);
+ return $generatedKey;
+ }
+
+ /**
+ * Gets the insert generated ID before executing an insert statement.
+ * @param IDbConnection database connection
+ * @param mixed insert statement parameter.
+ * @return string new insert ID if pre-select key statement was executed, null otherwise.
+ */
+ protected function getPreGeneratedSelectKey($connection, $parameter)
+ {
+ if($this->_statement instanceof TSqlMapInsert)
+ {
+ $selectKey = $this->_statement->getSelectKey();
+ if(($selectKey!==null) && !$selectKey->getIsAfter())
+ return $this->executeSelectKey($connection, $parameter, $selectKey);
+ }
+ }
+
+ /**
+ * Gets the inserted row ID after executing an insert statement.
+ * @param IDbConnection database connection
+ * @param mixed insert statement parameter.
+ * @return string last insert ID, null otherwise.
+ */
+ protected function getPostGeneratedSelectKey($connection, $parameter)
+ {
+ if($this->_statement instanceof TSqlMapInsert)
+ {
+ $selectKey = $this->_statement->getSelectKey();
+ if(($selectKey!==null) && $selectKey->getIsAfter())
+ return $this->executeSelectKey($connection, $parameter, $selectKey);
+ }
+ }
+
+ /**
+ * Execute the select key statement, used to obtain last insert ID.
+ * @param IDbConnection database connection
+ * @param mixed insert statement parameter
+ * @param TSqlMapSelectKey select key statement
+ * @return string last insert ID.
+ */
+ protected function executeSelectKey($connection, $parameter, $selectKey)
+ {
+ $mappedStatement = $this->getManager()->getMappedStatement($selectKey->getID());
+ $generatedKey = $mappedStatement->executeQueryForObject(
+ $connection, $parameter, null);
+ if(strlen($prop = $selectKey->getProperty()) > 0)
+ TPropertyAccess::set($parameter, $prop, $generatedKey);
+ return $generatedKey;
+ }
+
+ /**
+ * Execute an update statement. Also used for delete statement.
+ * Return the number of rows effected.
+ * @param IDbConnection database connection
+ * @param mixed The object used to set the parameters in the SQL.
+ * @return integer The number of rows effected.
+ */
+ public function executeUpdate($connection, $parameter)
+ {
+ $sql = $this->_command->create($this->getManager(),$connection, $this->_statement, $parameter);
+ $affectedRows = $sql->execute();
+ //$this->executeSQLQuery($connection, $sql);
+ $this->executePostSelect($connection);
+ $this->onExecuteQuery($sql);
+ return $affectedRows;
+ }
+
+ /**
+ * Process 'select' result properties
+ * @param IDbConnection database connection
+ */
+ protected function executePostSelect($connection)
+ {
+ while(count($this->_selectQueue))
+ {
+ $postSelect = array_shift($this->_selectQueue);
+ $method = $postSelect->getMethod();
+ $statement = $postSelect->getStatement();
+ $property = $postSelect->getResultProperty()->getProperty();
+ $keys = $postSelect->getKeys();
+ $resultObject = $postSelect->getResultObject();
+
+ if($method == self::QUERY_FOR_LIST || $method == self::QUERY_FOR_ARRAY)
+ {
+ $values = $statement->executeQueryForList($connection, $keys, null);
+
+ if($method == self::QUERY_FOR_ARRAY)
+ $values = $values->toArray();
+ TPropertyAccess::set($resultObject, $property, $values);
+ }
+ else if($method == self::QUERY_FOR_OBJECT)
+ {
+ $value = $statement->executeQueryForObject($connection, $keys, null);
+ TPropertyAccess::set($resultObject, $property, $value);
+ }
+ }
+ }
+
+ /**
+ * Raise the execute query event.
+ * @param array prepared SQL statement and subsititution parameters
+ */
+ public function onExecuteQuery($sql)
+ {
+ $this->raiseEvent('OnExecuteQuery', $this, $sql);
+ }
+
+ /**
+ * Apply result mapping.
+ * @param array a result set row retrieved from the database
+ * @param object the result object, will create if necessary.
+ * @return object the result filled with data, null if not filled.
+ */
+ protected function applyResultMap($row, &$resultObject=null)
+ {
+ if($row === false) return null;
+
+ $resultMapName = $this->_statement->getResultMap();
+ $resultClass = $this->_statement->getResultClass();
+
+ $obj=null;
+ if($this->getManager()->getResultMaps()->contains($resultMapName))
+ $obj = $this->fillResultMap($resultMapName, $row, null, $resultObject);
+ else if(strlen($resultClass) > 0)
+ $obj = $this->fillResultClass($resultClass, $row, $resultObject);
+ else
+ $obj = $this->fillDefaultResultMap(null, $row, $resultObject);
+ if(class_exists('TActiveRecord',false) && $obj instanceof TActiveRecord)
+ //Create a new clean active record.
+ $obj=TActiveRecord::createRecord(get_class($obj),$obj);
+ return $obj;
+ }
+
+ /**
+ * Fill the result using ResultClass, will creates new result object if required.
+ * @param string result object class name
+ * @param array a result set row retrieved from the database
+ * @param object the result object, will create if necessary.
+ * @return object result object filled with data
+ */
+ protected function fillResultClass($resultClass, $row, $resultObject)
+ {
+ if($resultObject===null)
+ {
+ $registry = $this->getManager()->getTypeHandlers();
+ $resultObject = $this->_statement->createInstanceOfResultClass($registry,$row);
+ }
+
+ if($resultObject instanceOf ArrayAccess)
+ return $this->fillResultArrayList($row, $resultObject);
+ else if(is_object($resultObject))
+ return $this->fillResultObjectProperty($row, $resultObject);
+ else
+ return $this->fillDefaultResultMap(null, $row, $resultObject);
+ }
+
+ /**
+ * Apply the result to a TList or an array.
+ * @param array a result set row retrieved from the database
+ * @param object result object, array or list
+ * @return object result filled with data.
+ */
+ protected function fillResultArrayList($row, $resultObject)
+ {
+ if($resultObject instanceof TList)
+ foreach($row as $v)
+ $resultObject[] = $v;
+ else
+ foreach($row as $k => $v)
+ $resultObject[$k] = $v;
+ return $resultObject;
+ }
+
+ /**
+ * Apply the result to an object.
+ * @param array a result set row retrieved from the database
+ * @param object result object, array or list
+ * @return object result filled with data.
+ */
+ protected function fillResultObjectProperty($row, $resultObject)
+ {
+ $index = 0;
+ $registry=$this->getManager()->getTypeHandlers();
+ foreach($row as $k=>$v)
+ {
+ $property = new TResultProperty;
+ if(is_string($k) && strlen($k) > 0)
+ $property->setColumn($k);
+ $property->setColumnIndex(++$index);
+ $type = gettype(TPropertyAccess::get($resultObject,$k));
+ $property->setType($type);
+ $value = $property->getPropertyValue($registry,$row);
+ TPropertyAccess::set($resultObject, $k,$value);
+ }
+ return $resultObject;
+ }
+
+ /**
+ * Fills the result object according to result mappings.
+ * @param string result map name.
+ * @param array a result set row retrieved from the database
+ * @param object result object to fill, will create new instances if required.
+ * @return object result object filled with data.
+ */
+ protected function fillResultMap($resultMapName, $row, $parentGroup=null, &$resultObject=null)
+ {
+ $resultMap = $this->getManager()->getResultMap($resultMapName);
+ $registry = $this->getManager()->getTypeHandlers();
+ $resultMap = $resultMap->resolveSubMap($registry,$row);
+
+ if($resultObject===null)
+ $resultObject = $resultMap->createInstanceOfResult($registry);
+
+ if(is_object($resultObject))
+ {
+ if(strlen($resultMap->getGroupBy()) > 0)
+ return $this->addResultMapGroupBy($resultMap, $row, $parentGroup, $resultObject);
+ else
+ foreach($resultMap->getColumns() as $property)
+ $this->setObjectProperty($resultMap, $property, $row, $resultObject);
+ }
+ else
+ {
+ $resultObject = $this->fillDefaultResultMap($resultMap, $row, $resultObject);
+ }
+ return $resultObject;
+ }
+
+ /**
+ * ResultMap with GroupBy property. Save object collection graph in a tree
+ * and collect the result later.
+ * @param TResultMap result mapping details.
+ * @param array a result set row retrieved from the database
+ * @param object the result object
+ * @return object result object.
+ */
+ protected function addResultMapGroupBy($resultMap, $row, $parent, &$resultObject)
+ {
+ $group = $this->getResultMapGroupKey($resultMap, $row);
+
+ if(empty($parent))
+ {
+ $rootObject = array('object'=>$resultObject, 'property' => null);
+ $this->_groupBy->add(null, $group, $rootObject);
+ }
+
+ foreach($resultMap->getColumns() as $property)
+ {
+ //set properties.
+ $this->setObjectProperty($resultMap, $property, $row, $resultObject);
+ $nested = $property->getResultMapping();
+
+ //nested property
+ if($this->getManager()->getResultMaps()->contains($nested))
+ {
+ $nestedMap = $this->getManager()->getResultMap($nested);
+ $groupKey = $this->getResultMapGroupKey($nestedMap, $row);
+
+ //add the node reference first
+ if(empty($parent))
+ $this->_groupBy->add($group, $groupKey, '');
+
+ //get the nested result mapping value
+ $value = $this->fillResultMap($nested, $row, $groupKey);
+
+ //add it to the object tree graph
+ $groupObject = array('object'=>$value, 'property' => $property->getProperty());
+ if(empty($parent))
+ $this->_groupBy->add($group, $groupKey, $groupObject);
+ else
+ $this->_groupBy->add($parent, $groupKey, $groupObject);
+ }
+ }
+ return $resultObject;
+ }
+
+ /**
+ * Gets the result 'group by' groupping key for each row.
+ * @param TResultMap result mapping details.
+ * @param array a result set row retrieved from the database
+ * @return string groupping key.
+ */
+ protected function getResultMapGroupKey($resultMap, $row)
+ {
+ $groupBy = $resultMap->getGroupBy();
+ if(isset($row[$groupBy]))
+ return $resultMap->getID().$row[$groupBy];
+ else
+ return $resultMap->getID().crc32(serialize($row));
+ }
+
+ /**
+ * Fill the result map using default settings. If <tt>$resultMap</tt> is null
+ * the result object returned will be guessed from <tt>$resultObject</tt>.
+ * @param TResultMap result mapping details.
+ * @param array a result set row retrieved from the database
+ * @param object the result object
+ * @return mixed the result object filled with data.
+ */
+ protected function fillDefaultResultMap($resultMap, $row, $resultObject)
+ {
+ if($resultObject===null)
+ $resultObject='';
+
+ if($resultMap!==null)
+ $result = $this->fillArrayResultMap($resultMap, $row, $resultObject);
+ else
+ $result = $row;
+
+ //if scalar result types
+ if(count($result) == 1 && ($type = gettype($resultObject))!= 'array')
+ return $this->getScalarResult($result, $type);
+ else
+ return $result;
+ }
+
+ /**
+ * Retrieve the result map as an array.
+ * @param TResultMap result mapping details.
+ * @param array a result set row retrieved from the database
+ * @param object the result object
+ * @return array array list of result objects.
+ */
+ protected function fillArrayResultMap($resultMap, $row, $resultObject)
+ {
+ $result = array();
+ $registry=$this->getManager()->getTypeHandlers();
+ foreach($resultMap->getColumns() as $column)
+ {
+ if(($column->getType()===null)
+ && ($resultObject!==null) && !is_object($resultObject))
+ $column->setType(gettype($resultObject));
+ $result[$column->getProperty()] = $column->getPropertyValue($registry,$row);
+ }
+ return $result;
+ }
+
+ /**
+ * Converts the first array value to scalar value of given type.
+ * @param array list of results
+ * @param string scalar type.
+ * @return mixed scalar value.
+ */
+ protected function getScalarResult($result, $type)
+ {
+ $scalar = array_shift($result);
+ settype($scalar, $type);
+ return $scalar;
+ }
+
+ /**
+ * Set a property of the result object with appropriate value.
+ * @param TResultMap result mapping details.
+ * @param TResultProperty the result property to fill.
+ * @param array a result set row retrieved from the database
+ * @param object the result object
+ */
+ protected function setObjectProperty($resultMap, $property, $row, &$resultObject)
+ {
+ $select = $property->getSelect();
+ $key = $property->getProperty();
+ $nested = $property->getNestedResultMap();
+ $registry=$this->getManager()->getTypeHandlers();
+ if($key === '')
+ {
+ $resultObject = $property->getPropertyValue($registry,$row);
+ }
+ else if(strlen($select) == 0 && ($nested===null))
+ {
+ $value = $property->getPropertyValue($registry,$row);
+
+ $this->_IsRowDataFound = $this->_IsRowDataFound || ($value != null);
+ if(is_array($resultObject) || is_object($resultObject))
+ TPropertyAccess::set($resultObject, $key, $value);
+ else
+ $resultObject = $value;
+ }
+ else if($nested!==null)
+ {
+ if($property->instanceOfListType($resultObject) || $property->instanceOfArrayType($resultObject))
+ {
+ if(strlen($resultMap->getGroupBy()) <= 0)
+ throw new TSqlMapExecutionException(
+ 'sqlmap_non_groupby_array_list_type', $resultMap->getID(),
+ get_class($resultObject), $key);
+ }
+ else
+ {
+ $obj = $nested->createInstanceOfResult($this->getManager()->getTypeHandlers());
+ if($this->fillPropertyWithResultMap($nested, $row, $obj) == false)
+ $obj = null;
+ TPropertyAccess::set($resultObject, $key, $obj);
+ }
+ }
+ else //'select' ResultProperty
+ {
+ $this->enquequePostSelect($select, $resultMap, $property, $row, $resultObject);
+ }
+ }
+
+ /**
+ * Add nested result property to post select queue.
+ * @param string post select statement ID
+ * @param TResultMap current result mapping details.
+ * @param TResultProperty current result property.
+ * @param array a result set row retrieved from the database
+ * @param object the result object
+ */
+ protected function enquequePostSelect($select, $resultMap, $property, $row, $resultObject)
+ {
+ $statement = $this->getManager()->getMappedStatement($select);
+ $key = $this->getPostSelectKeys($resultMap, $property, $row);
+ $postSelect = new TPostSelectBinding;
+ $postSelect->setStatement($statement);
+ $postSelect->setResultObject($resultObject);
+ $postSelect->setResultProperty($property);
+ $postSelect->setKeys($key);
+
+ if($property->instanceOfListType($resultObject))
+ {
+ $values = null;
+ if($property->getLazyLoad())
+ {
+ $values = TLazyLoadList::newInstance($statement, $key,
+ $resultObject, $property->getProperty());
+ TPropertyAccess::set($resultObject, $property->getProperty(), $values);
+ }
+ else
+ $postSelect->setMethod(self::QUERY_FOR_LIST);
+ }
+ else if($property->instanceOfArrayType($resultObject))
+ $postSelect->setMethod(self::QUERY_FOR_ARRAY);
+ else
+ $postSelect->setMethod(self::QUERY_FOR_OBJECT);
+
+ if(!$property->getLazyLoad())
+ $this->_selectQueue[] = $postSelect;
+ }
+
+ /**
+ * Finds in the post select property the SQL statement primary selection keys.
+ * @param TResultMap result mapping details
+ * @param TResultProperty result property
+ * @param array current row data.
+ * @return array list of primary key values.
+ */
+ protected function getPostSelectKeys($resultMap, $property,$row)
+ {
+ $value = $property->getColumn();
+ if(is_int(strpos($value.',',0)) || is_int(strpos($value, '=',0)))
+ {
+ $keys = array();
+ foreach(explode(',', $value) as $entry)
+ {
+ $pair =explode('=',$entry);
+ $keys[trim($pair[0])] = $row[trim($pair[1])];
+ }
+ return $keys;
+ }
+ else
+ {
+ $registry=$this->getManager()->getTypeHandlers();
+ return $property->getPropertyValue($registry,$row);
+ }
+ }
+
+ /**
+ * Fills the property with result mapping results.
+ * @param TResultMap nested result mapping details.
+ * @param array a result set row retrieved from the database
+ * @param object the result object
+ * @return boolean true if the data was found, false otherwise.
+ */
+ protected function fillPropertyWithResultMap($resultMap, $row, &$resultObject)
+ {
+ $dataFound = false;
+ foreach($resultMap->getColumns() as $property)
+ {
+ $this->_IsRowDataFound = false;
+ $this->setObjectProperty($resultMap, $property, $row, $resultObject);
+ $dataFound = $dataFound || $this->_IsRowDataFound;
+ }
+ $this->_IsRowDataFound = $dataFound;
+ return $dataFound;
+ }
+
+ public function __wakeup()
+ {
+ parent::__wakeup();
+ if (is_null($this->_selectQueue)) $this->_selectQueue = array();
+ }
+
+ public function __sleep()
+ {
+ $exprops = array(); $cn = __CLASS__;
+ if (!count($this->_selectQueue)) $exprops[] = "\0$cn\0_selectQueue";
+ if (is_null($this->_groupBy)) $exprops[] = "\0$cn\0_groupBy";
+ if (!$this->_IsRowDataFound) $exprops[] = "\0$cn\0_IsRowDataFound";
+ return array_diff(parent::__sleep(),$exprops);
+ }
+}
+
+/**
+ * TPostSelectBinding class.
+ *
+ * @author Wei Zhuo <weizho[at]gmail[dot]com>
+ * @version $Id$
+ * @package System.Data.SqlMap.Statements
+ * @since 3.1
+ */
+class TPostSelectBinding
+{
+ private $_statement=null;
+ private $_property=null;
+ private $_resultObject=null;
+ private $_keys=null;
+ private $_method=TMappedStatement::QUERY_FOR_LIST;
+
+ public function getStatement(){ return $this->_statement; }
+ public function setStatement($value){ $this->_statement = $value; }
+
+ public function getResultProperty(){ return $this->_property; }
+ public function setResultProperty($value){ $this->_property = $value; }
+
+ public function getResultObject(){ return $this->_resultObject; }
+ public function setResultObject($value){ $this->_resultObject = $value; }
+
+ public function getKeys(){ return $this->_keys; }
+ public function setKeys($value){ $this->_keys = $value; }
+
+ public function getMethod(){ return $this->_method; }
+ public function setMethod($value){ $this->_method = $value; }
+}
+
+/**
+ * TSQLMapObjectCollectionTree class.
+ *
+ * Maps object collection graphs as trees. Nodes in the collection can
+ * be {@link add} using parent relationships. The object collections can be
+ * build using the {@link collect} method.
+ *
+ * @author Wei Zhuo <weizhuo[at]gmail[dot]com>
+ * @version $Id$
+ * @package System.Data.SqlMap.Statements
+ * @since 3.1
+ */
+class TSqlMapObjectCollectionTree extends TComponent
+{
+ /**
+ * @var array object graph as tree
+ */
+ private $_tree = array();
+ /**
+ * @var array tree node values
+ */
+ private $_entries = array();
+ /**
+ * @var array resulting object collection
+ */
+ private $_list = array();
+
+ /**
+ * @return boolean true if the graph is empty
+ */
+ public function isEmpty()
+ {
+ return count($this->_entries) == 0;
+ }
+
+ /**
+ * Add a new node to the object tree graph.
+ * @param string parent node id
+ * @param string new node id
+ * @param mixed node value
+ */
+ public function add($parent, $node, $object='')
+ {
+ if(isset($this->_entries[$parent]) && ($this->_entries[$parent]!==null)
+ && isset($this->_entries[$node]) && ($this->_entries[$node]!==null))
+ {
+ $this->_entries[$node] = $object;
+ return;
+ }
+ $this->_entries[$node] = $object;
+ if(empty($parent))
+ {
+ if(isset($this->_entries[$node]))
+ return;
+ $this->_tree[$node] = array();
+ }
+ $found = $this->addNode($this->_tree, $parent, $node);
+ if(!$found && !empty($parent))
+ {
+ $this->_tree[$parent] = array();
+ if(!isset($this->_entries[$parent]) || $object !== '')
+ $this->_entries[$parent] = $object;
+ $this->addNode($this->_tree, $parent, $node);
+ }
+ }
+
+ /**
+ * Find the parent node and add the new node as its child.
+ * @param array list of nodes to check
+ * @param string parent node id
+ * @param string new node id
+ * @return boolean true if parent node is found.
+ */
+ protected function addNode(&$childs, $parent, $node)
+ {
+ $found = false;
+ reset($childs);
+ for($i = 0, $k = count($childs); $i < $k; $i++)
+ {
+ $key = key($childs);
+ next($childs);
+ if($key == $parent)
+ {
+ $found = true;
+ $childs[$key][$node] = array();
+ }
+ else
+ {
+ $found = $found || $this->addNode($childs[$key], $parent, $node);
+ }
+ }
+ return $found;
+ }
+
+ /**
+ * @return array object collection
+ */
+ public function collect()
+ {
+ while(count($this->_tree) > 0)
+ $this->collectChildren(null, $this->_tree);
+ return $this->getCollection();
+ }
+
+ /**
+ * @param array list of nodes to check
+ * @return boolean true if all nodes are leaf nodes, false otherwise
+ */
+ protected function hasChildren(&$nodes)
+ {
+ $hasChildren = false;
+ foreach($nodes as $node)
+ if(count($node) != 0)
+ return true;
+ return $hasChildren;
+ }
+
+ /**
+ * Visit all the child nodes and collect them by removing.
+ * @param string parent node id
+ * @param array list of child nodes.
+ */
+ protected function collectChildren($parent, &$nodes)
+ {
+ $noChildren = !$this->hasChildren($nodes);
+ $childs = array();
+ for(reset($nodes); $key = key($nodes);)
+ {
+ next($nodes);
+ if($noChildren)
+ {
+ $childs[] = $key;
+ unset($nodes[$key]);
+ }
+ else
+ $this->collectChildren($key, $nodes[$key]);
+ }
+ if(count($childs) > 0)
+ $this->onChildNodesVisited($parent, $childs);
+ }
+
+ /**
+ * Set the object properties for all the child nodes visited.
+ * @param string parent node id
+ * @param array list of child nodes visited.
+ */
+ protected function onChildNodesVisited($parent, $nodes)
+ {
+ if(empty($parent) || empty($this->_entries[$parent]))
+ return;
+
+ $parentObject = $this->_entries[$parent]['object'];
+ $property = $this->_entries[$nodes[0]]['property'];
+
+ $list = TPropertyAccess::get($parentObject, $property);
+
+ foreach($nodes as $node)
+ {
+ if($list instanceof TList)
+ $parentObject->{$property}[] = $this->_entries[$node]['object'];
+ else if(is_array($list))
+ $list[] = $this->_entries[$node]['object'];
+ else
+ throw new TSqlMapExecutionException(
+ 'sqlmap_property_must_be_list');
+ }
+
+ if(is_array($list))
+ TPropertyAccess::set($parentObject, $property, $list);
+
+ if($this->_entries[$parent]['property'] === null)
+ $this->_list[] = $parentObject;
+ }
+
+ /**
+ * @return array object collection.
+ */
+ protected function getCollection()
+ {
+ return $this->_list;
+ }
+
+ public function __sleep()
+ {
+ $exprops = array(); $cn = __CLASS__;
+ if (!count($this->_tree)) $exprops[] = "\0$cn\0_tree";
+ if (!count($this->_entries)) $exprops[] = "\0$cn\0_entries";
+ if (!count($this->_list)) $exprops[] = "\0$cn\0_list";
+ return array_diff(parent::__sleep(),$exprops);
+ }
+}
+
+/**
+ * TResultSetListItemParameter class
+ *
+ * @author Wei Zhuo <weizho[at]gmail[dot]com>
+ * @version $Id$
+ * @package System.Data.SqlMap.Statements
+ * @since 3.1
+ */
+class TResultSetListItemParameter extends TComponent
+{
+ private $_resultObject;
+ private $_parameterObject;
+ private $_list;
+
+ public function __construct($result, $parameter, &$list)
+ {
+ $this->_resultObject = $result;
+ $this->_parameterObject = $parameter;
+ $this->_list = &$list;
+ }
+
+ public function getResult()
+ {
+ return $this->_resultObject;
+ }
+
+ public function getParameter()
+ {
+ return $this->_parameterObject;
+ }
+
+ public function &getList()
+ {
+ return $this->_list;
+ }
+}
+
+/**
+ * TResultSetMapItemParameter class.
+ *
+ * @author Wei Zhuo <weizho[at]gmail[dot]com>
+ * @version $Id$
+ * @package System.Data.SqlMap.Statements
+ * @since 3.1
+ */
+class TResultSetMapItemParameter extends TComponent
+{
+ private $_key;
+ private $_value;
+ private $_parameterObject;
+ private $_map;
+
+ public function __construct($key, $value, $parameter, &$map)
+ {
+ $this->_key = $key;
+ $this->_value = $value;
+ $this->_parameterObject = $parameter;
+ $this->_map = &$map;
+ }
+
+ public function getKey()
+ {
+ return $this->_key;
+ }
+
+ public function getValue()
+ {
+ return $this->_value;
+ }
+
+ public function getParameter()
+ {
+ return $this->_parameterObject;
+ }
+
+ public function &getMap()
+ {
+ return $this->_map;
+ }
+}
+
diff --git a/framework/Data/SqlMap/Statements/TPreparedCommand.php b/framework/Data/SqlMap/Statements/TPreparedCommand.php
index 1d4a7088..7aa249ee 100644
--- a/framework/Data/SqlMap/Statements/TPreparedCommand.php
+++ b/framework/Data/SqlMap/Statements/TPreparedCommand.php
@@ -1,67 +1,67 @@
-<?php
-/**
- * TPreparedCommand class file.
- *
- * @author Wei Zhuo <weizhuo[at]gmail[dot]com>
- * @link http://www.pradosoft.com/
+<?php
+/**
+ * TPreparedCommand class file.
+ *
+ * @author Wei Zhuo <weizhuo[at]gmail[dot]com>
+ * @link http://www.pradosoft.com/
* @copyright Copyright &copy; 2005-2012 PradoSoft
- * @license http://www.pradosoft.com/license/
- * @version $Id$
- * @package System.Data.SqlMap.Statements
- */
-
-Prado::using('System.Data.Common.TDbMetaData');
-Prado::using('System.Data.Common.TDbCommandBuilder');
-
-/**
- * TPreparedCommand class.
- *
- * @author Wei Zhuo <weizho[at]gmail[dot]com>
- * @version $Id$
- * @package System.Data.SqlMap.Statements
- * @since 3.1
- */
-class TPreparedCommand
-{
- public function create(TSqlMapManager $manager, $connection, $statement, $parameterObject,$skip=null,$max=null)
- {
- $sqlText = $statement->getSQLText();
-
- $prepared = $sqlText->getPreparedStatement($parameterObject);
- $connection->setActive(true);
- $sql = $prepared->getPreparedSql();
-
- if($sqlText instanceof TSimpleDynamicSql)
- $sql = $sqlText->replaceDynamicParameter($sql, $parameterObject);
-
- if($max!==null || $skip!==null)
- {
- $builder = TDbMetaData::getInstance($connection)->createCommandBuilder();
- $sql = $builder->applyLimitOffset($sql,$max,$skip);
- }
- $command = $connection->createCommand($sql);
- $this->applyParameterMap($manager, $command, $prepared, $statement, $parameterObject);
-
- return $command;
- }
-
- protected function applyParameterMap($manager,$command,$prepared, $statement, $parameterObject)
- {
- $properties = $prepared->getParameterNames();
- $parameters = $prepared->getParameterValues();
- $registry=$manager->getTypeHandlers();
- for($i = 0, $k=$properties->getCount(); $i<$k; $i++)
- {
- $property = $statement->parameterMap()->getProperty($i);
- $value = $statement->parameterMap()->getPropertyValue($registry,$property, $parameterObject);
- $dbType = $property->getDbType();
- if($dbType=='') //relies on PHP lax comparison
- $command->bindValue($i+1,$value, TDbCommandBuilder::getPdoType($value));
- else if(strpos($dbType, 'PDO::')===0)
- $command->bindValue($i+1,$value, constant($property->getDbType())); //assumes PDO types, e.g. PDO::PARAM_INT
- else
- $command->bindValue($i+1,$value);
- }
- }
-}
-
+ * @license http://www.pradosoft.com/license/
+ * @version $Id$
+ * @package System.Data.SqlMap.Statements
+ */
+
+Prado::using('System.Data.Common.TDbMetaData');
+Prado::using('System.Data.Common.TDbCommandBuilder');
+
+/**
+ * TPreparedCommand class.
+ *
+ * @author Wei Zhuo <weizho[at]gmail[dot]com>
+ * @version $Id$
+ * @package System.Data.SqlMap.Statements
+ * @since 3.1
+ */
+class TPreparedCommand
+{
+ public function create(TSqlMapManager $manager, $connection, $statement, $parameterObject,$skip=null,$max=null)
+ {
+ $sqlText = $statement->getSQLText();
+
+ $prepared = $sqlText->getPreparedStatement($parameterObject);
+ $connection->setActive(true);
+ $sql = $prepared->getPreparedSql();
+
+ if($sqlText instanceof TSimpleDynamicSql)
+ $sql = $sqlText->replaceDynamicParameter($sql, $parameterObject);
+
+ if($max!==null || $skip!==null)
+ {
+ $builder = TDbMetaData::getInstance($connection)->createCommandBuilder();
+ $sql = $builder->applyLimitOffset($sql,$max,$skip);
+ }
+ $command = $connection->createCommand($sql);
+ $this->applyParameterMap($manager, $command, $prepared, $statement, $parameterObject);
+
+ return $command;
+ }
+
+ protected function applyParameterMap($manager,$command,$prepared, $statement, $parameterObject)
+ {
+ $properties = $prepared->getParameterNames();
+ $parameters = $prepared->getParameterValues();
+ $registry=$manager->getTypeHandlers();
+ for($i = 0, $k=$properties->getCount(); $i<$k; $i++)
+ {
+ $property = $statement->parameterMap()->getProperty($i);
+ $value = $statement->parameterMap()->getPropertyValue($registry,$property, $parameterObject);
+ $dbType = $property->getDbType();
+ if($dbType=='') //relies on PHP lax comparison
+ $command->bindValue($i+1,$value, TDbCommandBuilder::getPdoType($value));
+ else if(strpos($dbType, 'PDO::')===0)
+ $command->bindValue($i+1,$value, constant($property->getDbType())); //assumes PDO types, e.g. PDO::PARAM_INT
+ else
+ $command->bindValue($i+1,$value);
+ }
+ }
+}
+
diff --git a/framework/Data/SqlMap/Statements/TPreparedStatement.php b/framework/Data/SqlMap/Statements/TPreparedStatement.php
index d091861f..3abd7442 100644
--- a/framework/Data/SqlMap/Statements/TPreparedStatement.php
+++ b/framework/Data/SqlMap/Statements/TPreparedStatement.php
@@ -1,57 +1,57 @@
-<?php
-/**
- * TPreparedStatement class file.
- *
- * @author Wei Zhuo <weizhuo[at]gmail[dot]com>
- * @link http://www.pradosoft.com/
+<?php
+/**
+ * TPreparedStatement class file.
+ *
+ * @author Wei Zhuo <weizhuo[at]gmail[dot]com>
+ * @link http://www.pradosoft.com/
* @copyright Copyright &copy; 2005-2012 PradoSoft
- * @license http://www.pradosoft.com/license/
- * @version $Id$
- * @package System.Data.SqlMap.Statements
- */
-
-/**
- * TpreparedStatement class.
- *
- * @author Wei Zhuo <weizho[at]gmail[dot]com>
- * @version $Id$
- * @package System.Data.SqlMap.Statements
- * @since 3.1
- */
-class TPreparedStatement extends TComponent
-{
- private $_sqlString='';
- private $_parameterNames;
- private $_parameterValues;
-
- public function __construct()
- {
- $this->_parameterNames=new TList;
- $this->_parameterValues=new TMap;
- }
-
- public function getPreparedSql(){ return $this->_sqlString; }
- public function setPreparedSql($value){ $this->_sqlString = $value; }
-
- public function getParameterNames(){ return $this->_parameterNames; }
- public function setParameterNames($value){ $this->_parameterNames = $value; }
-
- public function getParameterValues(){ return $this->_parameterValues; }
- public function setParameterValues($value){ $this->_parameterValues = $value; }
-
- public function __wakeup()
- {
- parent::__wakeup();
- if (!$this->_parameterNames) $this->_parameterNames = new TList;
- if (!$this->_parameterValues) $this->_parameterValues = new TMap;
- }
-
- public function __sleep()
- {
- $exprops = array(); $cn = __CLASS__;
- if (!$this->_parameterNames->getCount()) $exprops[] = "\0$cn\0_parameterNames";
- if (!$this->_parameterValues->getCount()) $exprops[] = "\0$cn\0_parameterValues";
- return array_diff(parent::__sleep(),$exprops);
- }
-}
-
+ * @license http://www.pradosoft.com/license/
+ * @version $Id$
+ * @package System.Data.SqlMap.Statements
+ */
+
+/**
+ * TpreparedStatement class.
+ *
+ * @author Wei Zhuo <weizho[at]gmail[dot]com>
+ * @version $Id$
+ * @package System.Data.SqlMap.Statements
+ * @since 3.1
+ */
+class TPreparedStatement extends TComponent
+{
+ private $_sqlString='';
+ private $_parameterNames;
+ private $_parameterValues;
+
+ public function __construct()
+ {
+ $this->_parameterNames=new TList;
+ $this->_parameterValues=new TMap;
+ }
+
+ public function getPreparedSql(){ return $this->_sqlString; }
+ public function setPreparedSql($value){ $this->_sqlString = $value; }
+
+ public function getParameterNames(){ return $this->_parameterNames; }
+ public function setParameterNames($value){ $this->_parameterNames = $value; }
+
+ public function getParameterValues(){ return $this->_parameterValues; }
+ public function setParameterValues($value){ $this->_parameterValues = $value; }
+
+ public function __wakeup()
+ {
+ parent::__wakeup();
+ if (!$this->_parameterNames) $this->_parameterNames = new TList;
+ if (!$this->_parameterValues) $this->_parameterValues = new TMap;
+ }
+
+ public function __sleep()
+ {
+ $exprops = array(); $cn = __CLASS__;
+ if (!$this->_parameterNames->getCount()) $exprops[] = "\0$cn\0_parameterNames";
+ if (!$this->_parameterValues->getCount()) $exprops[] = "\0$cn\0_parameterValues";
+ return array_diff(parent::__sleep(),$exprops);
+ }
+}
+
diff --git a/framework/Data/SqlMap/Statements/TPreparedStatementFactory.php b/framework/Data/SqlMap/Statements/TPreparedStatementFactory.php
index 0d8286fa..9e70ba00 100644
--- a/framework/Data/SqlMap/Statements/TPreparedStatementFactory.php
+++ b/framework/Data/SqlMap/Statements/TPreparedStatementFactory.php
@@ -1,49 +1,49 @@
-<?php
-/**
- * TPreparedStatementFactory class file.
- *
- * @author Wei Zhuo <weizhuo[at]gmail[dot]com>
- * @link http://www.pradosoft.com/
- * @copyright Copyright &copy; 2005-2012 PradoSoft
- * @license http://www.pradosoft.com/license/
- * @version $Id$
- * @package System.Data.SqlMap.Statements
- */
-
-/**
- * TPreparedStatementFactory class.
- *
- * @author Wei Zhuo <weizho[at]gmail[dot]com>
- * @version $Id$
- * @package System.Data.SqlMap.Statements
- * @since 3.1
- */
-class TPreparedStatementFactory
-{
- private $_statement;
- private $_preparedStatement;
- private $_parameterPrefix = 'param';
- private $_commandText;
-
- public function __construct($statement, $sqlString)
- {
- $this->_statement = $statement;
- $this->_commandText = $sqlString;
- }
-
- public function prepare()
- {
- $this->_preparedStatement = new TPreparedStatement();
- $this->_preparedStatement->setPreparedSql($this->_commandText);
- if($this->_statement->parameterMap()!==null)
- $this->createParametersForTextCommand();
- return $this->_preparedStatement;
- }
-
- protected function createParametersForTextCommand()
- {
- foreach($this->_statement->ParameterMap()->getProperties() as $prop)
- $this->_preparedStatement->getParameterNames()->add($prop->getProperty());
- }
-}
-
+<?php
+/**
+ * TPreparedStatementFactory class file.
+ *
+ * @author Wei Zhuo <weizhuo[at]gmail[dot]com>
+ * @link http://www.pradosoft.com/
+ * @copyright Copyright &copy; 2005-2012 PradoSoft
+ * @license http://www.pradosoft.com/license/
+ * @version $Id$
+ * @package System.Data.SqlMap.Statements
+ */
+
+/**
+ * TPreparedStatementFactory class.
+ *
+ * @author Wei Zhuo <weizho[at]gmail[dot]com>
+ * @version $Id$
+ * @package System.Data.SqlMap.Statements
+ * @since 3.1
+ */
+class TPreparedStatementFactory
+{
+ private $_statement;
+ private $_preparedStatement;
+ private $_parameterPrefix = 'param';
+ private $_commandText;
+
+ public function __construct($statement, $sqlString)
+ {
+ $this->_statement = $statement;
+ $this->_commandText = $sqlString;
+ }
+
+ public function prepare()
+ {
+ $this->_preparedStatement = new TPreparedStatement();
+ $this->_preparedStatement->setPreparedSql($this->_commandText);
+ if($this->_statement->parameterMap()!==null)
+ $this->createParametersForTextCommand();
+ return $this->_preparedStatement;
+ }
+
+ protected function createParametersForTextCommand()
+ {
+ foreach($this->_statement->ParameterMap()->getProperties() as $prop)
+ $this->_preparedStatement->getParameterNames()->add($prop->getProperty());
+ }
+}
+
diff --git a/framework/Data/SqlMap/Statements/TSelectMappedStatement.php b/framework/Data/SqlMap/Statements/TSelectMappedStatement.php
index 4b1e5c65..5a2b25f0 100644
--- a/framework/Data/SqlMap/Statements/TSelectMappedStatement.php
+++ b/framework/Data/SqlMap/Statements/TSelectMappedStatement.php
@@ -1,36 +1,36 @@
-<?php
-/**
- * TSelectMappedStatement class.
- *
- * @author Wei Zhuo <weizhuo[at]gmail[dot]com>
- * @link http://www.pradosoft.com/
+<?php
+/**
+ * TSelectMappedStatement class.
+ *
+ * @author Wei Zhuo <weizhuo[at]gmail[dot]com>
+ * @link http://www.pradosoft.com/
* @copyright Copyright &copy; 2005-2012 PradoSoft
- * @license http://www.pradosoft.com/license/
- * @version $Id$
- * @package System.Data.SqlMap.Statements
- */
-
-/**
- * TSelectMappedStatment class.
- *
- * @author Wei Zhuo <weizho[at]gmail[dot]com>
- * @version $Id$
- * @package System.Data.SqlMap.Statements
- * @since 3.1
- */
-class TSelectMappedStatement extends TMappedStatement
-{
- public function executeInsert($connection, $parameter)
- {
- throw new TSqlMapExecutionException(
- 'sqlmap_cannot_execute_insert', get_class($this), $this->getID());
- }
-
- public function executeUpdate($connection, $parameter)
- {
- throw new TSqlMapExecutionException(
- 'sqlmap_cannot_execute_update', get_class($this), $this->getID());
- }
-
-}
-
+ * @license http://www.pradosoft.com/license/
+ * @version $Id$
+ * @package System.Data.SqlMap.Statements
+ */
+
+/**
+ * TSelectMappedStatment class.
+ *
+ * @author Wei Zhuo <weizho[at]gmail[dot]com>
+ * @version $Id$
+ * @package System.Data.SqlMap.Statements
+ * @since 3.1
+ */
+class TSelectMappedStatement extends TMappedStatement
+{
+ public function executeInsert($connection, $parameter)
+ {
+ throw new TSqlMapExecutionException(
+ 'sqlmap_cannot_execute_insert', get_class($this), $this->getID());
+ }
+
+ public function executeUpdate($connection, $parameter)
+ {
+ throw new TSqlMapExecutionException(
+ 'sqlmap_cannot_execute_update', get_class($this), $this->getID());
+ }
+
+}
+
diff --git a/framework/Data/SqlMap/Statements/TSimpleDynamicSql.php b/framework/Data/SqlMap/Statements/TSimpleDynamicSql.php
index 81ae4d76..377563ed 100644
--- a/framework/Data/SqlMap/Statements/TSimpleDynamicSql.php
+++ b/framework/Data/SqlMap/Statements/TSimpleDynamicSql.php
@@ -1,40 +1,40 @@
-<?php
-/**
- * TSimpleDynamicSql class file.
- *
- * @author Wei Zhuo <weizhuo[at]gmail[dot]com>
- * @link http://www.pradosoft.com/
+<?php
+/**
+ * TSimpleDynamicSql class file.
+ *
+ * @author Wei Zhuo <weizhuo[at]gmail[dot]com>
+ * @link http://www.pradosoft.com/
* @copyright Copyright &copy; 2005-2012 PradoSoft
- * @license http://www.pradosoft.com/license/
- * @version $Id$
- * @package System.Data.SqlMap.Statements
- */
-
-/**
- * TSimpleDynamicSql class.
- *
- * @author Wei Zhuo <weizho[at]gmail[dot]com>
- * @version $Id$
- * @package System.Data.SqlMap.Statements
- * @since 3.1
- */
-class TSimpleDynamicSql extends TStaticSql
-{
- private $_mappings=array();
-
- public function __construct($mappings)
- {
- $this->_mappings = $mappings;
- }
-
- public function replaceDynamicParameter($sql, $parameter)
- {
- foreach($this->_mappings as $property)
- {
- $value = TPropertyAccess::get($parameter, $property);
- $sql = preg_replace('/'.TSimpleDynamicParser::DYNAMIC_TOKEN.'/', str_replace('$', '\$', $value), $sql, 1);
- }
- return $sql;
- }
-}
-
+ * @license http://www.pradosoft.com/license/
+ * @version $Id$
+ * @package System.Data.SqlMap.Statements
+ */
+
+/**
+ * TSimpleDynamicSql class.
+ *
+ * @author Wei Zhuo <weizho[at]gmail[dot]com>
+ * @version $Id$
+ * @package System.Data.SqlMap.Statements
+ * @since 3.1
+ */
+class TSimpleDynamicSql extends TStaticSql
+{
+ private $_mappings=array();
+
+ public function __construct($mappings)
+ {
+ $this->_mappings = $mappings;
+ }
+
+ public function replaceDynamicParameter($sql, $parameter)
+ {
+ foreach($this->_mappings as $property)
+ {
+ $value = TPropertyAccess::get($parameter, $property);
+ $sql = preg_replace('/'.TSimpleDynamicParser::DYNAMIC_TOKEN.'/', str_replace('$', '\$', $value), $sql, 1);
+ }
+ return $sql;
+ }
+}
+
diff --git a/framework/Data/SqlMap/Statements/TStaticSql.php b/framework/Data/SqlMap/Statements/TStaticSql.php
index e6949c35..6374745d 100644
--- a/framework/Data/SqlMap/Statements/TStaticSql.php
+++ b/framework/Data/SqlMap/Statements/TStaticSql.php
@@ -1,36 +1,36 @@
-<?php
-/**
- * TStaticSql class file.
- *
- * @author Wei Zhuo <weizhuo[at]gmail[dot]com>
- * @link http://www.pradosoft.com/
+<?php
+/**
+ * TStaticSql class file.
+ *
+ * @author Wei Zhuo <weizhuo[at]gmail[dot]com>
+ * @link http://www.pradosoft.com/
* @copyright Copyright &copy; 2005-2012 PradoSoft
- * @license http://www.pradosoft.com/license/
- * @version $Id$
- * @package System.Data.SqlMap.Statements
- */
-
-/**
- * TStaticSql class.
- *
- * @author Wei Zhuo <weizho[at]gmail[dot]com>
- * @version $Id$
- * @package System.Data.SqlMap.Statements
- * @since 3.1
- */
-class TStaticSql extends TComponent
-{
- private $_preparedStatement;
-
- public function buildPreparedStatement($statement, $sqlString)
- {
- $factory = new TPreparedStatementFactory($statement, $sqlString);
- $this->_preparedStatement = $factory->prepare();
- }
-
- public function getPreparedStatement($parameter=null)
- {
- return $this->_preparedStatement;
- }
-}
-
+ * @license http://www.pradosoft.com/license/
+ * @version $Id$
+ * @package System.Data.SqlMap.Statements
+ */
+
+/**
+ * TStaticSql class.
+ *
+ * @author Wei Zhuo <weizho[at]gmail[dot]com>
+ * @version $Id$
+ * @package System.Data.SqlMap.Statements
+ * @since 3.1
+ */
+class TStaticSql extends TComponent
+{
+ private $_preparedStatement;
+
+ public function buildPreparedStatement($statement, $sqlString)
+ {
+ $factory = new TPreparedStatementFactory($statement, $sqlString);
+ $this->_preparedStatement = $factory->prepare();
+ }
+
+ public function getPreparedStatement($parameter=null)
+ {
+ return $this->_preparedStatement;
+ }
+}
+
diff --git a/framework/Data/SqlMap/Statements/TUpdateMappedStatement.php b/framework/Data/SqlMap/Statements/TUpdateMappedStatement.php
index 76bc8ae5..af300a0e 100644
--- a/framework/Data/SqlMap/Statements/TUpdateMappedStatement.php
+++ b/framework/Data/SqlMap/Statements/TUpdateMappedStatement.php
@@ -1,49 +1,49 @@
-<?php
-/**
- * TUpdateMappedStatement class file.
- *
- * @author Wei Zhuo <weizhuo[at]gmail[dot]com>
- * @link http://www.pradosoft.com/
+<?php
+/**
+ * TUpdateMappedStatement class file.
+ *
+ * @author Wei Zhuo <weizhuo[at]gmail[dot]com>
+ * @link http://www.pradosoft.com/
* @copyright Copyright &copy; 2005-2012 PradoSoft
- * @license http://www.pradosoft.com/license/
- * @version $Id$
- * @package System.Data.SqlMap.Statements
- */
-
-/**
- * TUpdateMappedStatement class.
- *
- * @author Wei Zhuo <weizho[at]gmail[dot]com>
- * @version $Id$
- * @package System.Data.SqlMap.Statements
- * @since 3.1
- */
-class TUpdateMappedStatement extends TMappedStatement
-{
- public function executeInsert($connection, $parameter)
- {
- throw new TSqlMapExecutionException(
- 'sqlmap_cannot_execute_insert', get_class($this), $this->getID());
- }
-
- public function executeQueryForMap($connection, $parameter, $keyProperty,
- $valueProperty=null)
- {
- throw new TSqlMapExecutionException(
- 'sqlmap_cannot_execute_query_for_map', get_class($this), $this->getID());
- }
-
- public function executeQueryForList($connection, $parameter, $result=null,
- $skip=-1, $max=-1)
- {
- throw new TSqlMapExecutionException(
- 'sqlmap_cannot_execute_query_for_list', get_class($this), $this->getID());
- }
-
- public function executeQueryForObject($connection, $parameter, $result=null)
- {
- throw new TSqlMapExecutionException(
- 'sqlmap_cannot_execute_query_for_object', get_class($this), $this->getID());
- }
-}
-
+ * @license http://www.pradosoft.com/license/
+ * @version $Id$
+ * @package System.Data.SqlMap.Statements
+ */
+
+/**
+ * TUpdateMappedStatement class.
+ *
+ * @author Wei Zhuo <weizho[at]gmail[dot]com>
+ * @version $Id$
+ * @package System.Data.SqlMap.Statements
+ * @since 3.1
+ */
+class TUpdateMappedStatement extends TMappedStatement
+{
+ public function executeInsert($connection, $parameter)
+ {
+ throw new TSqlMapExecutionException(
+ 'sqlmap_cannot_execute_insert', get_class($this), $this->getID());
+ }
+
+ public function executeQueryForMap($connection, $parameter, $keyProperty,
+ $valueProperty=null)
+ {
+ throw new TSqlMapExecutionException(
+ 'sqlmap_cannot_execute_query_for_map', get_class($this), $this->getID());
+ }
+
+ public function executeQueryForList($connection, $parameter, $result=null,
+ $skip=-1, $max=-1)
+ {
+ throw new TSqlMapExecutionException(
+ 'sqlmap_cannot_execute_query_for_list', get_class($this), $this->getID());
+ }
+
+ public function executeQueryForObject($connection, $parameter, $result=null)
+ {
+ throw new TSqlMapExecutionException(
+ 'sqlmap_cannot_execute_query_for_object', get_class($this), $this->getID());
+ }
+}
+
diff --git a/framework/Data/SqlMap/TSqlMapConfig.php b/framework/Data/SqlMap/TSqlMapConfig.php
index 1e9dcdd3..ee3685fe 100644
--- a/framework/Data/SqlMap/TSqlMapConfig.php
+++ b/framework/Data/SqlMap/TSqlMapConfig.php
@@ -1,181 +1,181 @@
-<?php
-/**
- * TSqlMapConfig class file.
- *
- * @author Wei Zhuo <weizhuo[at]gmail[dot]com>
- * @link http://www.pradosoft.com/
+<?php
+/**
+ * TSqlMapConfig class file.
+ *
+ * @author Wei Zhuo <weizhuo[at]gmail[dot]com>
+ * @link http://www.pradosoft.com/
* @copyright Copyright &copy; 2005-2012 PradoSoft
- * @license http://www.pradosoft.com/license/
- * @version $Id$
- * @package System.Data.SqlMap
- */
-
-Prado::using('System.Data.TDataSourceConfig');
-
-/**
- * TSqlMapConfig module configuration class.
- *
- * Database connection and TSqlMapManager configuration.
- *
- * @author Wei Zhuo <weizho[at]gmail[dot]com>
- * @version $Id$
- * @package System.Data.SqlMap
- * @since 3.1
- */
-class TSqlMapConfig extends TDataSourceConfig
-{
- private $_configFile;
- private $_sqlmap;
- private $_enableCache=false;
-
- /**
- * File extension of external configuration file
- */
- const CONFIG_FILE_EXT='.xml';
-
- /**
- * @return string module ID + configuration file path.
- */
- private function getCacheKey()
- {
- return $this->getID().$this->getConfigFile();
- }
-
- /**
- * Deletes the configuration cache.
- */
- public function clearCache()
- {
- $cache = $this->getApplication()->getCache();
- if($cache !== null) {
- $cache->delete($this->getCacheKey());
- }
- }
-
- /**
- * Create and configure the data mapper using sqlmap configuration file.
- * Or if cache is enabled and manager already cached load from cache.
- * If cache is enabled, the data mapper instance is cached.
- *
- * @return TSqlMapManager SqlMap manager instance
- * @since 3.1.7
- */
- public function getSqlMapManager() {
- Prado::using('System.Data.SqlMap.TSqlMapManager');
- if(($manager = $this->loadCachedSqlMapManager())===null)
- {
- $manager = new TSqlMapManager($this->getDbConnection());
- if(strlen($file=$this->getConfigFile()) > 0)
- {
- $manager->configureXml($file);
- $this->cacheSqlMapManager($manager);
- }
- }
- elseif($this->getConnectionID() !== '') {
- $manager->setDbConnection($this->getDbConnection());
- }
- return $manager;
- }
-
- /**
- * Saves the current SqlMap manager to cache.
- * @return boolean true if SqlMap manager was cached, false otherwise.
- */
- protected function cacheSqlMapManager($manager)
- {
- if($this->getEnableCache())
- {
- $cache = $this->getApplication()->getCache();
- if($cache !== null) {
- $dependencies = null;
- if($this->getApplication()->getMode() !== TApplicationMode::Performance)
- $dependencies = $manager->getCacheDependencies();
- return $cache->set($this->getCacheKey(), $manager, 0, $dependencies);
- }
- }
- return false;
- }
-
- /**
- * Loads SqlMap manager from cache.
- * @return TSqlMapManager SqlMap manager intance if load was successful, null otherwise.
- */
- protected function loadCachedSqlMapManager()
- {
- if($this->getEnableCache())
- {
- $cache = $this->getApplication()->getCache();
- if($cache !== null)
- {
- $manager = $cache->get($this->getCacheKey());
- if($manager instanceof TSqlMapManager)
- return $manager;
- }
- }
- return null;
- }
-
- /**
- * @return string SqlMap configuration file.
- */
- public function getConfigFile()
- {
- return $this->_configFile;
- }
-
- /**
- * @param string external configuration file in namespace format. The file
- * extension must be '.xml'.
- * @throws TConfigurationException if the file is invalid.
- */
- public function setConfigFile($value)
- {
- if(is_file($value))
- $this->_configFile=$value;
- else
- {
- $file = Prado::getPathOfNamespace($value,self::CONFIG_FILE_EXT);
- if($file === null || !is_file($file))
- throw new TConfigurationException('sqlmap_configfile_invalid',$value);
- else
- $this->_configFile = $file;
- }
- }
-
- /**
- * Set true to cache sqlmap instances.
- * @param boolean true to cache sqlmap instance.
- */
- public function setEnableCache($value)
- {
- $this->_enableCache = TPropertyValue::ensureBoolean($value);
- }
-
- /**
- * @return boolean true if configuration should be cached, false otherwise.
- */
- public function getEnableCache()
- {
- return $this->_enableCache;
- }
-
- /**
- * @return TSqlMapGateway SqlMap gateway instance.
- */
- protected function createSqlMapGateway()
- {
- return $this->getSqlMapManager()->getSqlmapGateway();
- }
-
- /**
- * Initialize the sqlmap if necessary, returns the TSqlMapGateway instance.
- * @return TSqlMapGateway SqlMap gateway instance.
- */
- public function getClient()
- {
- if($this->_sqlmap===null )
- $this->_sqlmap=$this->createSqlMapGateway();
- return $this->_sqlmap;
- }
-}
-
+ * @license http://www.pradosoft.com/license/
+ * @version $Id$
+ * @package System.Data.SqlMap
+ */
+
+Prado::using('System.Data.TDataSourceConfig');
+
+/**
+ * TSqlMapConfig module configuration class.
+ *
+ * Database connection and TSqlMapManager configuration.
+ *
+ * @author Wei Zhuo <weizho[at]gmail[dot]com>
+ * @version $Id$
+ * @package System.Data.SqlMap
+ * @since 3.1
+ */
+class TSqlMapConfig extends TDataSourceConfig
+{
+ private $_configFile;
+ private $_sqlmap;
+ private $_enableCache=false;
+
+ /**
+ * File extension of external configuration file
+ */
+ const CONFIG_FILE_EXT='.xml';
+
+ /**
+ * @return string module ID + configuration file path.
+ */
+ private function getCacheKey()
+ {
+ return $this->getID().$this->getConfigFile();
+ }
+
+ /**
+ * Deletes the configuration cache.
+ */
+ public function clearCache()
+ {
+ $cache = $this->getApplication()->getCache();
+ if($cache !== null) {
+ $cache->delete($this->getCacheKey());
+ }
+ }
+
+ /**
+ * Create and configure the data mapper using sqlmap configuration file.
+ * Or if cache is enabled and manager already cached load from cache.
+ * If cache is enabled, the data mapper instance is cached.
+ *
+ * @return TSqlMapManager SqlMap manager instance
+ * @since 3.1.7
+ */
+ public function getSqlMapManager() {
+ Prado::using('System.Data.SqlMap.TSqlMapManager');
+ if(($manager = $this->loadCachedSqlMapManager())===null)
+ {
+ $manager = new TSqlMapManager($this->getDbConnection());
+ if(strlen($file=$this->getConfigFile()) > 0)
+ {
+ $manager->configureXml($file);
+ $this->cacheSqlMapManager($manager);
+ }
+ }
+ elseif($this->getConnectionID() !== '') {
+ $manager->setDbConnection($this->getDbConnection());
+ }
+ return $manager;
+ }
+
+ /**
+ * Saves the current SqlMap manager to cache.
+ * @return boolean true if SqlMap manager was cached, false otherwise.
+ */
+ protected function cacheSqlMapManager($manager)
+ {
+ if($this->getEnableCache())
+ {
+ $cache = $this->getApplication()->getCache();
+ if($cache !== null) {
+ $dependencies = null;
+ if($this->getApplication()->getMode() !== TApplicationMode::Performance)
+ $dependencies = $manager->getCacheDependencies();
+ return $cache->set($this->getCacheKey(), $manager, 0, $dependencies);
+ }
+ }
+ return false;
+ }
+
+ /**
+ * Loads SqlMap manager from cache.
+ * @return TSqlMapManager SqlMap manager intance if load was successful, null otherwise.
+ */
+ protected function loadCachedSqlMapManager()
+ {
+ if($this->getEnableCache())
+ {
+ $cache = $this->getApplication()->getCache();
+ if($cache !== null)
+ {
+ $manager = $cache->get($this->getCacheKey());
+ if($manager instanceof TSqlMapManager)
+ return $manager;
+ }
+ }
+ return null;
+ }
+
+ /**
+ * @return string SqlMap configuration file.
+ */
+ public function getConfigFile()
+ {
+ return $this->_configFile;
+ }
+
+ /**
+ * @param string external configuration file in namespace format. The file
+ * extension must be '.xml'.
+ * @throws TConfigurationException if the file is invalid.
+ */
+ public function setConfigFile($value)
+ {
+ if(is_file($value))
+ $this->_configFile=$value;
+ else
+ {
+ $file = Prado::getPathOfNamespace($value,self::CONFIG_FILE_EXT);
+ if($file === null || !is_file($file))
+ throw new TConfigurationException('sqlmap_configfile_invalid',$value);
+ else
+ $this->_configFile = $file;
+ }
+ }
+
+ /**
+ * Set true to cache sqlmap instances.
+ * @param boolean true to cache sqlmap instance.
+ */
+ public function setEnableCache($value)
+ {
+ $this->_enableCache = TPropertyValue::ensureBoolean($value);
+ }
+
+ /**
+ * @return boolean true if configuration should be cached, false otherwise.
+ */
+ public function getEnableCache()
+ {
+ return $this->_enableCache;
+ }
+
+ /**
+ * @return TSqlMapGateway SqlMap gateway instance.
+ */
+ protected function createSqlMapGateway()
+ {
+ return $this->getSqlMapManager()->getSqlmapGateway();
+ }
+
+ /**
+ * Initialize the sqlmap if necessary, returns the TSqlMapGateway instance.
+ * @return TSqlMapGateway SqlMap gateway instance.
+ */
+ public function getClient()
+ {
+ if($this->_sqlmap===null )
+ $this->_sqlmap=$this->createSqlMapGateway();
+ return $this->_sqlmap;
+ }
+}
+
diff --git a/framework/Data/SqlMap/TSqlMapGateway.php b/framework/Data/SqlMap/TSqlMapGateway.php
index f1915e86..3be4e12f 100644
--- a/framework/Data/SqlMap/TSqlMapGateway.php
+++ b/framework/Data/SqlMap/TSqlMapGateway.php
@@ -1,261 +1,261 @@
-<?php
-/**
- * TSqlMapGateway class file.
- *
- * @author Wei Zhuo <weizhuo[at]gmail[dot]com>
- * @link http://www.pradosoft.com/
+<?php
+/**
+ * TSqlMapGateway class file.
+ *
+ * @author Wei Zhuo <weizhuo[at]gmail[dot]com>
+ * @link http://www.pradosoft.com/
* @copyright Copyright &copy; 2005-2012 PradoSoft
- * @license http://www.pradosoft.com/license/
- * @version $Id$
- * @package System.Data.SqlMap
- */
-
-Prado::using('System.Data.SqlMap.TSqlMapManager');
-
-/**
- * DataMapper client, a fascade to provide access the rest of the DataMapper
- * framework. It provides three core functions:
- *
- * # execute an update query (including insert and delete).
- * # execute a select query for a single object
- * # execute a select query for a list of objects
- *
- * This class should be instantiated from a TSqlMapManager instance.
- *
- * @author Wei Zhuo <weizhuo[at]gmail[dot]com>
- * @version $Id$
- * @package System.Data.SqlMap
- * @since 3.1
- */
-class TSqlMapGateway extends TComponent
-{
- /**
- * @var TSqlMapManager manager
- */
- private $_manager;
-
- public function __construct($manager)
- {
- $this->_manager=$manager;
- }
-
- /**
- * @return TSqlMapManager sqlmap manager.
- */
- public function getSqlMapManager()
- {
- return $this->_manager;
- }
-
- /**
- * @return TDbConnection database connection.
- */
- public function getDbConnection()
- {
- return $this->getSqlMapManager()->getDbConnection();
- }
-
- /**
- * Executes a Sql SELECT statement that returns that returns data
- * to populate a single object instance.
- *
- * The parameter object is generally used to supply the input
- * data for the WHERE clause parameter(s) of the SELECT statement.
- *
- * @param string The name of the sql statement to execute.
- * @param mixed The object used to set the parameters in the SQL.
- * @param mixed An object of the type to be returned.
- * @return object A single result object populated with the result set data.
- */
- public function queryForObject($statementName, $parameter=null, $result=null)
- {
- $statement = $this->getSqlMapManager()->getMappedStatement($statementName);
- return $statement->executeQueryForObject($this->getDbConnection(), $parameter, $result);
- }
-
- /**
- * Executes a Sql SELECT statement that returns data to populate a number
- * of result objects.
- *
- * The parameter object is generally used to supply the input
- * data for the WHERE clause parameter(s) of the SELECT statement.
- *
- * @param string The name of the sql statement to execute.
- * @param mixed The object used to set the parameters in the SQL.
- * @param TList An Ilist object used to hold the objects,
- * pass in null if want to return a list instead.
- * @param int The number of rows to skip over.
- * @param int The maximum number of rows to return.
- * @return TList A List of result objects.
- */
- public function queryForList($statementName, $parameter=null, $result=null, $skip=-1, $max=-1)
- {
- $statement = $this->getSqlMapManager()->getMappedStatement($statementName);
- return $statement->executeQueryForList($this->getDbConnection(),$parameter, $result, $skip, $max);
- }
-
- /**
- * Runs a query for list with a custom object that gets a chance to deal
- * with each row as it is processed.
- *
- * Example: $sqlmap->queryWithRowDelegate('getAccounts', array($this, 'rowHandler'));
- *
- * @param string The name of the sql statement to execute.
- * @param callback Row delegate handler, a valid callback required.
- * @param mixed The object used to set the parameters in the SQL.
- * @param TList An Ilist object used to hold the objects,
- * pass in null if want to return a list instead.
- * @param int The number of rows to skip over.
- * @param int The maximum number of rows to return.
- * @return TList A List of result objects.
- */
- public function queryWithRowDelegate($statementName, $delegate, $parameter=null, $result=null, $skip=-1, $max=-1)
- {
- $statement = $this->getSqlMapManager()->getMappedStatement($statementName);
- return $statement->executeQueryForList($this->getDbConnection(), $parameter, $result, $skip, $max, $delegate);
- }
-
- /**
- * Executes the SQL and retuns a subset of the results in a dynamic
- * TPagedList that can be used to automatically scroll through results
- * from a database table.
- * @param string The name of the sql statement to execute.
- * @param mixed The object used to set the parameters in the SQL.
- * @param integer The maximum number of objects to store in each page.
+ * @license http://www.pradosoft.com/license/
+ * @version $Id$
+ * @package System.Data.SqlMap
+ */
+
+Prado::using('System.Data.SqlMap.TSqlMapManager');
+
+/**
+ * DataMapper client, a fascade to provide access the rest of the DataMapper
+ * framework. It provides three core functions:
+ *
+ * # execute an update query (including insert and delete).
+ * # execute a select query for a single object
+ * # execute a select query for a list of objects
+ *
+ * This class should be instantiated from a TSqlMapManager instance.
+ *
+ * @author Wei Zhuo <weizhuo[at]gmail[dot]com>
+ * @version $Id$
+ * @package System.Data.SqlMap
+ * @since 3.1
+ */
+class TSqlMapGateway extends TComponent
+{
+ /**
+ * @var TSqlMapManager manager
+ */
+ private $_manager;
+
+ public function __construct($manager)
+ {
+ $this->_manager=$manager;
+ }
+
+ /**
+ * @return TSqlMapManager sqlmap manager.
+ */
+ public function getSqlMapManager()
+ {
+ return $this->_manager;
+ }
+
+ /**
+ * @return TDbConnection database connection.
+ */
+ public function getDbConnection()
+ {
+ return $this->getSqlMapManager()->getDbConnection();
+ }
+
+ /**
+ * Executes a Sql SELECT statement that returns that returns data
+ * to populate a single object instance.
+ *
+ * The parameter object is generally used to supply the input
+ * data for the WHERE clause parameter(s) of the SELECT statement.
+ *
+ * @param string The name of the sql statement to execute.
+ * @param mixed The object used to set the parameters in the SQL.
+ * @param mixed An object of the type to be returned.
+ * @return object A single result object populated with the result set data.
+ */
+ public function queryForObject($statementName, $parameter=null, $result=null)
+ {
+ $statement = $this->getSqlMapManager()->getMappedStatement($statementName);
+ return $statement->executeQueryForObject($this->getDbConnection(), $parameter, $result);
+ }
+
+ /**
+ * Executes a Sql SELECT statement that returns data to populate a number
+ * of result objects.
+ *
+ * The parameter object is generally used to supply the input
+ * data for the WHERE clause parameter(s) of the SELECT statement.
+ *
+ * @param string The name of the sql statement to execute.
+ * @param mixed The object used to set the parameters in the SQL.
+ * @param TList An Ilist object used to hold the objects,
+ * pass in null if want to return a list instead.
+ * @param int The number of rows to skip over.
+ * @param int The maximum number of rows to return.
+ * @return TList A List of result objects.
+ */
+ public function queryForList($statementName, $parameter=null, $result=null, $skip=-1, $max=-1)
+ {
+ $statement = $this->getSqlMapManager()->getMappedStatement($statementName);
+ return $statement->executeQueryForList($this->getDbConnection(),$parameter, $result, $skip, $max);
+ }
+
+ /**
+ * Runs a query for list with a custom object that gets a chance to deal
+ * with each row as it is processed.
+ *
+ * Example: $sqlmap->queryWithRowDelegate('getAccounts', array($this, 'rowHandler'));
+ *
+ * @param string The name of the sql statement to execute.
+ * @param callback Row delegate handler, a valid callback required.
+ * @param mixed The object used to set the parameters in the SQL.
+ * @param TList An Ilist object used to hold the objects,
+ * pass in null if want to return a list instead.
+ * @param int The number of rows to skip over.
+ * @param int The maximum number of rows to return.
+ * @return TList A List of result objects.
+ */
+ public function queryWithRowDelegate($statementName, $delegate, $parameter=null, $result=null, $skip=-1, $max=-1)
+ {
+ $statement = $this->getSqlMapManager()->getMappedStatement($statementName);
+ return $statement->executeQueryForList($this->getDbConnection(), $parameter, $result, $skip, $max, $delegate);
+ }
+
+ /**
+ * Executes the SQL and retuns a subset of the results in a dynamic
+ * TPagedList that can be used to automatically scroll through results
+ * from a database table.
+ * @param string The name of the sql statement to execute.
+ * @param mixed The object used to set the parameters in the SQL.
+ * @param integer The maximum number of objects to store in each page.
* @param integer The number of the page to initially load into the list.
- * @return TPagedList A PaginatedList of beans containing the rows.
- */
- public function queryForPagedList($statementName, $parameter=null, $pageSize=10, $page=0)
- {
- $statement = $this->getSqlMapManager()->getMappedStatement($statementName);
- return new TSqlMapPagedList($statement, $parameter, $pageSize, null, $page);
- }
-
- /**
- * Executes the SQL and retuns a subset of the results in a dynamic
- * TPagedList that can be used to automatically scroll through results
- * from a database table.
- *
- * Runs paged list query with row delegate
- * Example: $sqlmap->queryForPagedListWithRowDelegate('getAccounts', array($this, 'rowHandler'));
- *
- * @param string The name of the sql statement to execute.
- * @param callback Row delegate handler, a valid callback required.
- * @param mixed The object used to set the parameters in the SQL.
- * @param integer The maximum number of objects to store in each page.
+ * @return TPagedList A PaginatedList of beans containing the rows.
+ */
+ public function queryForPagedList($statementName, $parameter=null, $pageSize=10, $page=0)
+ {
+ $statement = $this->getSqlMapManager()->getMappedStatement($statementName);
+ return new TSqlMapPagedList($statement, $parameter, $pageSize, null, $page);
+ }
+
+ /**
+ * Executes the SQL and retuns a subset of the results in a dynamic
+ * TPagedList that can be used to automatically scroll through results
+ * from a database table.
+ *
+ * Runs paged list query with row delegate
+ * Example: $sqlmap->queryForPagedListWithRowDelegate('getAccounts', array($this, 'rowHandler'));
+ *
+ * @param string The name of the sql statement to execute.
+ * @param callback Row delegate handler, a valid callback required.
+ * @param mixed The object used to set the parameters in the SQL.
+ * @param integer The maximum number of objects to store in each page.
* @param integer The number of the page to initially load into the list.
- * @return TPagedList A PaginatedList of beans containing the rows.
- */
- public function queryForPagedListWithRowDelegate($statementName,$delegate, $parameter=null, $pageSize=10, $page=0)
- {
- $statement = $this->getSqlMapManager()->getMappedStatement($statementName);
- return new TSqlMapPagedList($statement, $parameter, $pageSize, $delegate,$page);
- }
-
-
- /**
- * Executes the SQL and retuns all rows selected in a map that is keyed on
- * the property named in the keyProperty parameter. The value at each key
- * will be the value of the property specified in the valueProperty
- * parameter. If valueProperty is null, the entire result object will be
- * entered.
- * @param string The name of the sql statement to execute.
- * @param mixed The object used to set the parameters in the SQL.
- * @param string The property of the result object to be used as the key.
- * @param string The property of the result object to be used as the value.
- * @return TMap Array object containing the rows keyed by keyProperty.
- */
- public function queryForMap($statementName, $parameter=null, $keyProperty=null, $valueProperty=null, $skip=-1, $max=-1)
- {
- $statement = $this->getSqlMapManager()->getMappedStatement($statementName);
- return $statement->executeQueryForMap($this->getDbConnection(), $parameter, $keyProperty, $valueProperty, $skip, $max);
- }
-
- /**
- * Runs a query with a custom object that gets a chance to deal
- * with each row as it is processed.
- *
- * Example: $sqlmap->queryForMapWithRowDelegate('getAccounts', array($this, 'rowHandler'));
- *
- * @param string The name of the sql statement to execute.
- * @param callback Row delegate handler, a valid callback required.
- * @param mixed The object used to set the parameters in the SQL.
- * @param string The property of the result object to be used as the key.
- * @param string The property of the result object to be used as the value.
- * @return TMap Array object containing the rows keyed by keyProperty.
- */
- public function queryForMapWithRowDelegate($statementName, $delegate, $parameter=null, $keyProperty=null, $valueProperty=null, $skip=-1, $max=-1)
- {
- $statement = $this->getSqlMapManager()->getMappedStatement($statementName);
- return $statement->executeQueryForMap($this->getDbConnection(), $parameter, $keyProperty, $valueProperty, $skip, $max, $delegate);
- }
-
- /**
- * Executes a Sql INSERT statement.
- *
- * Insert is a bit different from other update methods, as it provides
- * facilities for returning the primary key of the newly inserted row
- * (rather than the effected rows),
- *
- * The parameter object is generally used to supply the input data for the
- * INSERT values.
- *
- * @param string The name of the statement to execute.
- * @param string The parameter object.
- * @return mixed The primary key of the newly inserted row.
- * This might be automatically generated by the RDBMS,
- * or selected from a sequence table or other source.
- */
- public function insert($statementName, $parameter=null)
- {
- $statement = $this->getSqlMapManager()->getMappedStatement($statementName);
- return $statement->executeInsert($this->getDbConnection(), $parameter);
- }
-
- /**
- * Executes a Sql UPDATE statement.
- *
- * Update can also be used for any other update statement type, such as
- * inserts and deletes. Update returns the number of rows effected.
- *
- * The parameter object is generally used to supply the input data for the
- * UPDATE values as well as the WHERE clause parameter(s).
- *
- * @param string The name of the statement to execute.
- * @param mixed The parameter object.
- * @return integer The number of rows effected.
- */
- public function update($statementName, $parameter=null)
- {
- $statement = $this->getSqlMapManager()->getMappedStatement($statementName);
- return $statement->executeUpdate($this->getDbConnection(), $parameter);
- }
-
- /**
- * Executes a Sql DELETE statement. Delete returns the number of rows effected.
- * @param string The name of the statement to execute.
- * @param mixed The parameter object.
- * @return integer The number of rows effected.
- */
- public function delete($statementName, $parameter=null)
- {
- return $this->update($statementName, $parameter);
- }
-
- /**
- * Flushes all cached objects that belong to this SqlMap
- */
- public function flushCaches()
- {
- $this->getSqlMapManager()->flushCacheModels();
- }
-
- /**
- * @param TSqlMapTypeHandler new type handler.
- */
- public function registerTypeHandler($typeHandler)
- {
- $this->getSqlMapManager()->getTypeHandlers()->registerTypeHandler($typeHandler);
- }
-}
-
+ * @return TPagedList A PaginatedList of beans containing the rows.
+ */
+ public function queryForPagedListWithRowDelegate($statementName,$delegate, $parameter=null, $pageSize=10, $page=0)
+ {
+ $statement = $this->getSqlMapManager()->getMappedStatement($statementName);
+ return new TSqlMapPagedList($statement, $parameter, $pageSize, $delegate,$page);
+ }
+
+
+ /**
+ * Executes the SQL and retuns all rows selected in a map that is keyed on
+ * the property named in the keyProperty parameter. The value at each key
+ * will be the value of the property specified in the valueProperty
+ * parameter. If valueProperty is null, the entire result object will be
+ * entered.
+ * @param string The name of the sql statement to execute.
+ * @param mixed The object used to set the parameters in the SQL.
+ * @param string The property of the result object to be used as the key.
+ * @param string The property of the result object to be used as the value.
+ * @return TMap Array object containing the rows keyed by keyProperty.
+ */
+ public function queryForMap($statementName, $parameter=null, $keyProperty=null, $valueProperty=null, $skip=-1, $max=-1)
+ {
+ $statement = $this->getSqlMapManager()->getMappedStatement($statementName);
+ return $statement->executeQueryForMap($this->getDbConnection(), $parameter, $keyProperty, $valueProperty, $skip, $max);
+ }
+
+ /**
+ * Runs a query with a custom object that gets a chance to deal
+ * with each row as it is processed.
+ *
+ * Example: $sqlmap->queryForMapWithRowDelegate('getAccounts', array($this, 'rowHandler'));
+ *
+ * @param string The name of the sql statement to execute.
+ * @param callback Row delegate handler, a valid callback required.
+ * @param mixed The object used to set the parameters in the SQL.
+ * @param string The property of the result object to be used as the key.
+ * @param string The property of the result object to be used as the value.
+ * @return TMap Array object containing the rows keyed by keyProperty.
+ */
+ public function queryForMapWithRowDelegate($statementName, $delegate, $parameter=null, $keyProperty=null, $valueProperty=null, $skip=-1, $max=-1)
+ {
+ $statement = $this->getSqlMapManager()->getMappedStatement($statementName);
+ return $statement->executeQueryForMap($this->getDbConnection(), $parameter, $keyProperty, $valueProperty, $skip, $max, $delegate);
+ }
+
+ /**
+ * Executes a Sql INSERT statement.
+ *
+ * Insert is a bit different from other update methods, as it provides
+ * facilities for returning the primary key of the newly inserted row
+ * (rather than the effected rows),
+ *
+ * The parameter object is generally used to supply the input data for the
+ * INSERT values.
+ *
+ * @param string The name of the statement to execute.
+ * @param string The parameter object.
+ * @return mixed The primary key of the newly inserted row.
+ * This might be automatically generated by the RDBMS,
+ * or selected from a sequence table or other source.
+ */
+ public function insert($statementName, $parameter=null)
+ {
+ $statement = $this->getSqlMapManager()->getMappedStatement($statementName);
+ return $statement->executeInsert($this->getDbConnection(), $parameter);
+ }
+
+ /**
+ * Executes a Sql UPDATE statement.
+ *
+ * Update can also be used for any other update statement type, such as
+ * inserts and deletes. Update returns the number of rows effected.
+ *
+ * The parameter object is generally used to supply the input data for the
+ * UPDATE values as well as the WHERE clause parameter(s).
+ *
+ * @param string The name of the statement to execute.
+ * @param mixed The parameter object.
+ * @return integer The number of rows effected.
+ */
+ public function update($statementName, $parameter=null)
+ {
+ $statement = $this->getSqlMapManager()->getMappedStatement($statementName);
+ return $statement->executeUpdate($this->getDbConnection(), $parameter);
+ }
+
+ /**
+ * Executes a Sql DELETE statement. Delete returns the number of rows effected.
+ * @param string The name of the statement to execute.
+ * @param mixed The parameter object.
+ * @return integer The number of rows effected.
+ */
+ public function delete($statementName, $parameter=null)
+ {
+ return $this->update($statementName, $parameter);
+ }
+
+ /**
+ * Flushes all cached objects that belong to this SqlMap
+ */
+ public function flushCaches()
+ {
+ $this->getSqlMapManager()->flushCacheModels();
+ }
+
+ /**
+ * @param TSqlMapTypeHandler new type handler.
+ */
+ public function registerTypeHandler($typeHandler)
+ {
+ $this->getSqlMapManager()->getTypeHandlers()->registerTypeHandler($typeHandler);
+ }
+}
+
diff --git a/framework/Data/SqlMap/TSqlMapManager.php b/framework/Data/SqlMap/TSqlMapManager.php
index e27ad079..d8a16407 100644
--- a/framework/Data/SqlMap/TSqlMapManager.php
+++ b/framework/Data/SqlMap/TSqlMapManager.php
@@ -1,274 +1,274 @@
-<?php
-/**
- * TSqlMapManager class file.
- *
- * @author Wei Zhuo <weizhuo[at]gmail[dot]com>
- * @link http://www.pradosoft.com/
+<?php
+/**
+ * TSqlMapManager class file.
+ *
+ * @author Wei Zhuo <weizhuo[at]gmail[dot]com>
+ * @link http://www.pradosoft.com/
* @copyright Copyright &copy; 2005-2012 PradoSoft
- * @license http://www.pradosoft.com/license/
- * @version $Id$
- * @package System.Data.SqlMap
- */
-
-Prado::using('System.Data.SqlMap.TSqlMapGateway');
-Prado::using('System.Data.SqlMap.DataMapper.TSqlMapException');
-Prado::using('System.Data.SqlMap.DataMapper.TSqlMapTypeHandlerRegistry');
-Prado::using('System.Data.SqlMap.DataMapper.TSqlMapCache');
-Prado::using('System.Data.SqlMap.Configuration.TSqlMapStatement');
-Prado::using('System.Data.SqlMap.Configuration.*');
-Prado::using('System.Data.SqlMap.DataMapper.*');
-Prado::using('System.Data.SqlMap.Statements.*');
-Prado::using('System.Caching.TCache');
-
-
-/**
- * TSqlMapManager class holds the sqlmap configuation result maps, statements
- * parameter maps and a type handler factory.
- *
- * Use {@link SqlMapGateway getSqlMapGateway()} property to obtain the gateway
- * instance used for querying statements defined in the SqlMap configuration files.
- *
- * <code>
- * $conn = new TDbConnection($dsn,$dbuser,$dbpass);
- * $manager = new TSqlMapManager($conn);
- * $manager->configureXml('mydb-sqlmap.xml');
- * $sqlmap = $manager->getSqlMapGateway();
- * $result = $sqlmap->queryForObject('Products');
- * </code>
- *
- * @author Wei Zhuo <weizhuo[at]gmail[dot]com>
- * @version $Id$
- * @package System.Data.SqlMap
- * @since 3.1
- */
-class TSqlMapManager extends TComponent
-{
- private $_mappedStatements;
- private $_resultMaps;
- private $_parameterMaps;
- private $_typeHandlers;
- private $_cacheModels;
-
- private $_connection;
- private $_gateway;
- private $_cacheDependencies;
-
- /**
- * Constructor, create a new SqlMap manager.
- * @param TDbConnection database connection
- * @param string configuration file.
- */
- public function __construct($connection=null)
- {
- $this->_connection=$connection;
-
- $this->_mappedStatements=new TMap;
- $this->_resultMaps=new TMap;
- $this->_parameterMaps=new TMap;
- $this->_cacheModels=new TMap;
- }
-
- /**
- * @param TDbConnection default database connection
- */
- public function setDbConnection($conn)
- {
- $this->_connection=$conn;
- }
-
- /**
- * @return TDbConnection default database connection
- */
- public function getDbConnection()
- {
- return $this->_connection;
- }
-
- /**
- * @return TTypeHandlerFactory The TypeHandlerFactory
- */
- public function getTypeHandlers()
- {
- if($this->_typeHandlers===null)
- $this->_typeHandlers= new TSqlMapTypeHandlerRegistry();
- return $this->_typeHandlers;
- }
-
- /**
- * @return TSqlMapGateway SqlMap gateway.
- */
- public function getSqlmapGateway()
- {
- if($this->_gateway===null)
- $this->_gateway=$this->createSqlMapGateway();
- return $this->_gateway;
- }
-
- /**
- * Loads and parses the SqlMap configuration file.
- * @param string xml configuration file.
- */
- public function configureXml($file)
- {
- $config = new TSqlMapXmlConfiguration($this);
- $config->configure($file);
- }
-
- /**
- * @return TChainedCacheDependency
- * @since 3.1.5
- */
- public function getCacheDependencies()
- {
- if($this->_cacheDependencies === null)
- $this->_cacheDependencies=new TChainedCacheDependency();
-
- return $this->_cacheDependencies;
- }
-
- /**
- * Configures the current TSqlMapManager using the given xml configuration file
- * defined in {@link ConfigFile setConfigFile()}.
- * @return TSqlMapGateway create and configure a new TSqlMapGateway.
- */
- protected function createSqlMapGateway()
- {
- return new TSqlMapGateway($this);
- }
-
- /**
- * @return TMap mapped statements collection.
- */
- public function getMappedStatements()
- {
- return $this->_mappedStatements;
- }
-
- /**
- * Gets a MappedStatement by name.
- * @param string The name of the statement.
- * @return IMappedStatement The MappedStatement
- * @throws TSqlMapUndefinedException
- */
- public function getMappedStatement($name)
- {
- if($this->_mappedStatements->contains($name) == false)
- throw new TSqlMapUndefinedException('sqlmap_contains_no_statement', $name);
- return $this->_mappedStatements[$name];
- }
-
- /**
- * Adds a (named) MappedStatement.
- * @param string The key name
- * @param IMappedStatement The statement to add
- * @throws TSqlMapDuplicateException
- */
- public function addMappedStatement(IMappedStatement $statement)
- {
- $key = $statement->getID();
- if($this->_mappedStatements->contains($key) == true)
- throw new TSqlMapDuplicateException('sqlmap_already_contains_statement', $key);
- $this->_mappedStatements->add($key, $statement);
- }
-
- /**
- * @return TMap result maps collection.
- */
- public function getResultMaps()
- {
- return $this->_resultMaps;
- }
-
- /**
- * Gets a named result map
- * @param string result name.
- * @return TResultMap the result map.
- * @throws TSqlMapUndefinedException
- */
- public function getResultMap($name)
- {
- if($this->_resultMaps->contains($name) == false)
- throw new TSqlMapUndefinedException('sqlmap_contains_no_result_map', $name);
- return $this->_resultMaps[$name];
- }
-
- /**
- * @param TResultMap add a new result map to this SQLMap
- * @throws TSqlMapDuplicateException
- */
- public function addResultMap(TResultMap $result)
- {
- $key = $result->getID();
- if($this->_resultMaps->contains($key) == true)
- throw new TSqlMapDuplicateException('sqlmap_already_contains_result_map', $key);
- $this->_resultMaps->add($key, $result);
- }
-
- /**
- * @return TMap parameter maps collection.
- */
- public function getParameterMaps()
- {
- return $this->_parameterMaps;
- }
-
- /**
- * @param string parameter map ID name.
- * @return TParameterMap the parameter with given ID.
- * @throws TSqlMapUndefinedException
- */
- public function getParameterMap($name)
- {
- if($this->_parameterMaps->contains($name) == false)
- throw new TSqlMapUndefinedException('sqlmap_contains_no_parameter_map', $name);
- return $this->_parameterMaps[$name];
- }
-
- /**
- * @param TParameterMap add a new parameter map to this SQLMap.
- * @throws TSqlMapDuplicateException
- */
- public function addParameterMap(TParameterMap $parameter)
- {
- $key = $parameter->getID();
- if($this->_parameterMaps->contains($key) == true)
- throw new TSqlMapDuplicateException('sqlmap_already_contains_parameter_map', $key);
- $this->_parameterMaps->add($key, $parameter);
- }
-
- /**
- * Adds a named cache.
- * @param TSqlMapCacheModel the cache to add.
- * @throws TSqlMapConfigurationException
- */
- public function addCacheModel(TSqlMapCacheModel $cacheModel)
- {
- if($this->_cacheModels->contains($cacheModel->getID()))
- throw new TSqlMapConfigurationException('sqlmap_cache_model_already_exists', $cacheModel->getID());
- else
- $this->_cacheModels->add($cacheModel->getID(), $cacheModel);
- }
-
- /**
- * Gets a cache by name
- * @param string the name of the cache to get.
- * @return TSqlMapCacheModel the cache object.
- * @throws TSqlMapConfigurationException
- */
- public function getCacheModel($name)
- {
- if(!$this->_cacheModels->contains($name))
- throw new TSqlMapConfigurationException('sqlmap_unable_to_find_cache_model', $name);
- return $this->_cacheModels[$name];
- }
-
- /**
- * Flushes all cached objects that belong to this SqlMap
- */
- public function flushCacheModels()
- {
- foreach($this->_cacheModels as $cache)
- $cache->flush();
- }
-}
-
+ * @license http://www.pradosoft.com/license/
+ * @version $Id$
+ * @package System.Data.SqlMap
+ */
+
+Prado::using('System.Data.SqlMap.TSqlMapGateway');
+Prado::using('System.Data.SqlMap.DataMapper.TSqlMapException');
+Prado::using('System.Data.SqlMap.DataMapper.TSqlMapTypeHandlerRegistry');
+Prado::using('System.Data.SqlMap.DataMapper.TSqlMapCache');
+Prado::using('System.Data.SqlMap.Configuration.TSqlMapStatement');
+Prado::using('System.Data.SqlMap.Configuration.*');
+Prado::using('System.Data.SqlMap.DataMapper.*');
+Prado::using('System.Data.SqlMap.Statements.*');
+Prado::using('System.Caching.TCache');
+
+
+/**
+ * TSqlMapManager class holds the sqlmap configuation result maps, statements
+ * parameter maps and a type handler factory.
+ *
+ * Use {@link SqlMapGateway getSqlMapGateway()} property to obtain the gateway
+ * instance used for querying statements defined in the SqlMap configuration files.
+ *
+ * <code>
+ * $conn = new TDbConnection($dsn,$dbuser,$dbpass);
+ * $manager = new TSqlMapManager($conn);
+ * $manager->configureXml('mydb-sqlmap.xml');
+ * $sqlmap = $manager->getSqlMapGateway();
+ * $result = $sqlmap->queryForObject('Products');
+ * </code>
+ *
+ * @author Wei Zhuo <weizhuo[at]gmail[dot]com>
+ * @version $Id$
+ * @package System.Data.SqlMap
+ * @since 3.1
+ */
+class TSqlMapManager extends TComponent
+{
+ private $_mappedStatements;
+ private $_resultMaps;
+ private $_parameterMaps;
+ private $_typeHandlers;
+ private $_cacheModels;
+
+ private $_connection;
+ private $_gateway;
+ private $_cacheDependencies;
+
+ /**
+ * Constructor, create a new SqlMap manager.
+ * @param TDbConnection database connection
+ * @param string configuration file.
+ */
+ public function __construct($connection=null)
+ {
+ $this->_connection=$connection;
+
+ $this->_mappedStatements=new TMap;
+ $this->_resultMaps=new TMap;
+ $this->_parameterMaps=new TMap;
+ $this->_cacheModels=new TMap;
+ }
+
+ /**
+ * @param TDbConnection default database connection
+ */
+ public function setDbConnection($conn)
+ {
+ $this->_connection=$conn;
+ }
+
+ /**
+ * @return TDbConnection default database connection
+ */
+ public function getDbConnection()
+ {
+ return $this->_connection;
+ }
+
+ /**
+ * @return TTypeHandlerFactory The TypeHandlerFactory
+ */
+ public function getTypeHandlers()
+ {
+ if($this->_typeHandlers===null)
+ $this->_typeHandlers= new TSqlMapTypeHandlerRegistry();
+ return $this->_typeHandlers;
+ }
+
+ /**
+ * @return TSqlMapGateway SqlMap gateway.
+ */
+ public function getSqlmapGateway()
+ {
+ if($this->_gateway===null)
+ $this->_gateway=$this->createSqlMapGateway();
+ return $this->_gateway;
+ }
+
+ /**
+ * Loads and parses the SqlMap configuration file.
+ * @param string xml configuration file.
+ */
+ public function configureXml($file)
+ {
+ $config = new TSqlMapXmlConfiguration($this);
+ $config->configure($file);
+ }
+
+ /**
+ * @return TChainedCacheDependency
+ * @since 3.1.5
+ */
+ public function getCacheDependencies()
+ {
+ if($this->_cacheDependencies === null)
+ $this->_cacheDependencies=new TChainedCacheDependency();
+
+ return $this->_cacheDependencies;
+ }
+
+ /**
+ * Configures the current TSqlMapManager using the given xml configuration file
+ * defined in {@link ConfigFile setConfigFile()}.
+ * @return TSqlMapGateway create and configure a new TSqlMapGateway.
+ */
+ protected function createSqlMapGateway()
+ {
+ return new TSqlMapGateway($this);
+ }
+
+ /**
+ * @return TMap mapped statements collection.
+ */
+ public function getMappedStatements()
+ {
+ return $this->_mappedStatements;
+ }
+
+ /**
+ * Gets a MappedStatement by name.
+ * @param string The name of the statement.
+ * @return IMappedStatement The MappedStatement
+ * @throws TSqlMapUndefinedException
+ */
+ public function getMappedStatement($name)
+ {
+ if($this->_mappedStatements->contains($name) == false)
+ throw new TSqlMapUndefinedException('sqlmap_contains_no_statement', $name);
+ return $this->_mappedStatements[$name];
+ }
+
+ /**
+ * Adds a (named) MappedStatement.
+ * @param string The key name
+ * @param IMappedStatement The statement to add
+ * @throws TSqlMapDuplicateException
+ */
+ public function addMappedStatement(IMappedStatement $statement)
+ {
+ $key = $statement->getID();
+ if($this->_mappedStatements->contains($key) == true)
+ throw new TSqlMapDuplicateException('sqlmap_already_contains_statement', $key);
+ $this->_mappedStatements->add($key, $statement);
+ }
+
+ /**
+ * @return TMap result maps collection.
+ */
+ public function getResultMaps()
+ {
+ return $this->_resultMaps;
+ }
+
+ /**
+ * Gets a named result map
+ * @param string result name.
+ * @return TResultMap the result map.
+ * @throws TSqlMapUndefinedException
+ */
+ public function getResultMap($name)
+ {
+ if($this->_resultMaps->contains($name) == false)
+ throw new TSqlMapUndefinedException('sqlmap_contains_no_result_map', $name);
+ return $this->_resultMaps[$name];
+ }
+
+ /**
+ * @param TResultMap add a new result map to this SQLMap
+ * @throws TSqlMapDuplicateException
+ */
+ public function addResultMap(TResultMap $result)
+ {
+ $key = $result->getID();
+ if($this->_resultMaps->contains($key) == true)
+ throw new TSqlMapDuplicateException('sqlmap_already_contains_result_map', $key);
+ $this->_resultMaps->add($key, $result);
+ }
+
+ /**
+ * @return TMap parameter maps collection.
+ */
+ public function getParameterMaps()
+ {
+ return $this->_parameterMaps;
+ }
+
+ /**
+ * @param string parameter map ID name.
+ * @return TParameterMap the parameter with given ID.
+ * @throws TSqlMapUndefinedException
+ */
+ public function getParameterMap($name)
+ {
+ if($this->_parameterMaps->contains($name) == false)
+ throw new TSqlMapUndefinedException('sqlmap_contains_no_parameter_map', $name);
+ return $this->_parameterMaps[$name];
+ }
+
+ /**
+ * @param TParameterMap add a new parameter map to this SQLMap.
+ * @throws TSqlMapDuplicateException
+ */
+ public function addParameterMap(TParameterMap $parameter)
+ {
+ $key = $parameter->getID();
+ if($this->_parameterMaps->contains($key) == true)
+ throw new TSqlMapDuplicateException('sqlmap_already_contains_parameter_map', $key);
+ $this->_parameterMaps->add($key, $parameter);
+ }
+
+ /**
+ * Adds a named cache.
+ * @param TSqlMapCacheModel the cache to add.
+ * @throws TSqlMapConfigurationException
+ */
+ public function addCacheModel(TSqlMapCacheModel $cacheModel)
+ {
+ if($this->_cacheModels->contains($cacheModel->getID()))
+ throw new TSqlMapConfigurationException('sqlmap_cache_model_already_exists', $cacheModel->getID());
+ else
+ $this->_cacheModels->add($cacheModel->getID(), $cacheModel);
+ }
+
+ /**
+ * Gets a cache by name
+ * @param string the name of the cache to get.
+ * @return TSqlMapCacheModel the cache object.
+ * @throws TSqlMapConfigurationException
+ */
+ public function getCacheModel($name)
+ {
+ if(!$this->_cacheModels->contains($name))
+ throw new TSqlMapConfigurationException('sqlmap_unable_to_find_cache_model', $name);
+ return $this->_cacheModels[$name];
+ }
+
+ /**
+ * Flushes all cached objects that belong to this SqlMap
+ */
+ public function flushCacheModels()
+ {
+ foreach($this->_cacheModels as $cache)
+ $cache->flush();
+ }
+}
+
diff --git a/framework/Data/TDataSourceConfig.php b/framework/Data/TDataSourceConfig.php
index a880c522..84d23dc6 100644
--- a/framework/Data/TDataSourceConfig.php
+++ b/framework/Data/TDataSourceConfig.php
@@ -1,167 +1,167 @@
-<?php
-/**
- * TDataSourceConfig class file.
- *
- * @author Wei Zhuo <weizhuo[at]gmail[dot]com>
- * @link http://www.pradosoft.com/
- * @copyright Copyright &copy; 2005-2012 PradoSoft
- * @license http://www.pradosoft.com/license/
- * @version $Id$
- * @package System.Data
- */
-
-Prado::using('System.Data.TDbConnection');
-
-/**
- * TDataSourceConfig module class provides <module> configuration for database connections.
- *
- * Example usage: mysql connection
- * <code>
- * <modules>
- * <module id="db1">
- * <database ConnectionString="mysqli:host=localhost;dbname=test"
- * username="dbuser" password="dbpass" />
- * </module>
- * </modules>
- * </code>
- *
- * Usage in php:
- * <code>
- * class Home extends TPage
- * {
- * function onLoad($param)
- * {
- * $db = $this->Application->Modules['db1']->DbConnection;
- * $db->createCommand('...'); //...
- * }
- * }
- * </code>
- *
- * The properties of <connection> are those of the class TDbConnection.
- * Set {@link setConnectionClass} attribute for a custom database connection class
- * that extends the TDbConnection class.
- *
- * @author Wei Zhuo <weizho[at]gmail[dot]com>
- * @version $Id$
- * @package System.Data
- * @since 3.1
- */
-class TDataSourceConfig extends TModule
-{
- private $_connID='';
- private $_conn;
- private $_connClass='System.Data.TDbConnection';
-
- /**
- * Initalize the database connection properties from attributes in <database> tag.
- * @param TXmlDocument xml configuration.
- */
- public function init($xml)
- {
- if($this->getApplication()->getConfigurationType()==TApplication::CONFIG_TYPE_PHP)
- {
- if(isset($xml['database']) && is_array($xml['database']))
- {
- $db=$this->getDbConnection();
- foreach($xml['database'] as $name=>$value)
- $db->setSubProperty($name,$value);
- }
- }
- else
- {
- if($prop=$xml->getElementByTagName('database'))
- {
- $db=$this->getDbConnection();
- foreach($prop->getAttributes() as $name=>$value)
- $db->setSubproperty($name,$value);
- }
- }
- }
-
- /**
- * The module ID of another TDataSourceConfig. The {@link getDbConnection DbConnection}
- * property of this configuration will equal to {@link getDbConnection DbConnection}
- * of the given TDataSourceConfig module.
- * @param string module ID.
- */
- public function setConnectionID($value)
- {
- $this->_connID=$value;
- }
-
- /**
- * @return string connection module ID.
- */
- public function getConnectionID()
- {
- return $this->_connID;
- }
-
- /**
- * Gets the TDbConnection from another module if {@link setConnectionID ConnectionID}
- * is supplied and valid. Otherwise, a connection of type given by
- * {@link setConnectionClass ConnectionClass} is created.
- * @return TDbConnection database connection.
- */
- public function getDbConnection()
- {
- if($this->_conn===null)
- {
- if($this->_connID!=='')
- $this->_conn = $this->findConnectionByID($this->getConnectionID());
- else
- $this->_conn = Prado::createComponent($this->getConnectionClass());
- }
- return $this->_conn;
- }
-
- /**
- * Alias for getDbConnection().
- * @return TDbConnection database connection.
- */
- public function getDatabase()
- {
- return $this->getDbConnection();
- }
-
- /**
- * @param string Database connection class name to be created.
- */
- public function getConnectionClass()
- {
- return $this->_connClass;
- }
-
- /**
- * The database connection class name to be created when {@link getDbConnection}
- * method is called <b>and</b> {@link setConnectionID ConnectionID} is null. The
- * {@link setConnectionClass ConnectionClass} property must be set before
- * calling {@link getDbConnection} if you wish to create the connection using the
- * given class name.
- * @param string Database connection class name.
- * @throws TConfigurationException when database connection is already established.
- */
- public function setConnectionClass($value)
- {
- if($this->_conn!==null)
- throw new TConfigurationException('datasource_dbconnection_exists', $value);
- $this->_connClass=$value;
- }
-
- /**
- * Finds the database connection instance from the Application modules.
- * @param string Database connection module ID.
- * @return TDbConnection database connection.
- * @throws TConfigurationException when module is not of TDbConnection or TDataSourceConfig.
- */
- protected function findConnectionByID($id)
- {
- $conn = $this->getApplication()->getModule($id);
- if($conn instanceof TDbConnection)
- return $conn;
- else if($conn instanceof TDataSourceConfig)
- return $conn->getDbConnection();
- else
- throw new TConfigurationException('datasource_dbconnection_invalid',$id);
- }
-}
+<?php
+/**
+ * TDataSourceConfig class file.
+ *
+ * @author Wei Zhuo <weizhuo[at]gmail[dot]com>
+ * @link http://www.pradosoft.com/
+ * @copyright Copyright &copy; 2005-2012 PradoSoft
+ * @license http://www.pradosoft.com/license/
+ * @version $Id$
+ * @package System.Data
+ */
+
+Prado::using('System.Data.TDbConnection');
+
+/**
+ * TDataSourceConfig module class provides <module> configuration for database connections.
+ *
+ * Example usage: mysql connection
+ * <code>
+ * <modules>
+ * <module id="db1">
+ * <database ConnectionString="mysqli:host=localhost;dbname=test"
+ * username="dbuser" password="dbpass" />
+ * </module>
+ * </modules>
+ * </code>
+ *
+ * Usage in php:
+ * <code>
+ * class Home extends TPage
+ * {
+ * function onLoad($param)
+ * {
+ * $db = $this->Application->Modules['db1']->DbConnection;
+ * $db->createCommand('...'); //...
+ * }
+ * }
+ * </code>
+ *
+ * The properties of <connection> are those of the class TDbConnection.
+ * Set {@link setConnectionClass} attribute for a custom database connection class
+ * that extends the TDbConnection class.
+ *
+ * @author Wei Zhuo <weizho[at]gmail[dot]com>
+ * @version $Id$
+ * @package System.Data
+ * @since 3.1
+ */
+class TDataSourceConfig extends TModule
+{
+ private $_connID='';
+ private $_conn;
+ private $_connClass='System.Data.TDbConnection';
+
+ /**
+ * Initalize the database connection properties from attributes in <database> tag.
+ * @param TXmlDocument xml configuration.
+ */
+ public function init($xml)
+ {
+ if($this->getApplication()->getConfigurationType()==TApplication::CONFIG_TYPE_PHP)
+ {
+ if(isset($xml['database']) && is_array($xml['database']))
+ {
+ $db=$this->getDbConnection();
+ foreach($xml['database'] as $name=>$value)
+ $db->setSubProperty($name,$value);
+ }
+ }
+ else
+ {
+ if($prop=$xml->getElementByTagName('database'))
+ {
+ $db=$this->getDbConnection();
+ foreach($prop->getAttributes() as $name=>$value)
+ $db->setSubproperty($name,$value);
+ }
+ }
+ }
+
+ /**
+ * The module ID of another TDataSourceConfig. The {@link getDbConnection DbConnection}
+ * property of this configuration will equal to {@link getDbConnection DbConnection}
+ * of the given TDataSourceConfig module.
+ * @param string module ID.
+ */
+ public function setConnectionID($value)
+ {
+ $this->_connID=$value;
+ }
+
+ /**
+ * @return string connection module ID.
+ */
+ public function getConnectionID()
+ {
+ return $this->_connID;
+ }
+
+ /**
+ * Gets the TDbConnection from another module if {@link setConnectionID ConnectionID}
+ * is supplied and valid. Otherwise, a connection of type given by
+ * {@link setConnectionClass ConnectionClass} is created.
+ * @return TDbConnection database connection.
+ */
+ public function getDbConnection()
+ {
+ if($this->_conn===null)
+ {
+ if($this->_connID!=='')
+ $this->_conn = $this->findConnectionByID($this->getConnectionID());
+ else
+ $this->_conn = Prado::createComponent($this->getConnectionClass());
+ }
+ return $this->_conn;
+ }
+
+ /**
+ * Alias for getDbConnection().
+ * @return TDbConnection database connection.
+ */
+ public function getDatabase()
+ {
+ return $this->getDbConnection();
+ }
+
+ /**
+ * @param string Database connection class name to be created.
+ */
+ public function getConnectionClass()
+ {
+ return $this->_connClass;
+ }
+
+ /**
+ * The database connection class name to be created when {@link getDbConnection}
+ * method is called <b>and</b> {@link setConnectionID ConnectionID} is null. The
+ * {@link setConnectionClass ConnectionClass} property must be set before
+ * calling {@link getDbConnection} if you wish to create the connection using the
+ * given class name.
+ * @param string Database connection class name.
+ * @throws TConfigurationException when database connection is already established.
+ */
+ public function setConnectionClass($value)
+ {
+ if($this->_conn!==null)
+ throw new TConfigurationException('datasource_dbconnection_exists', $value);
+ $this->_connClass=$value;
+ }
+
+ /**
+ * Finds the database connection instance from the Application modules.
+ * @param string Database connection module ID.
+ * @return TDbConnection database connection.
+ * @throws TConfigurationException when module is not of TDbConnection or TDataSourceConfig.
+ */
+ protected function findConnectionByID($id)
+ {
+ $conn = $this->getApplication()->getModule($id);
+ if($conn instanceof TDbConnection)
+ return $conn;
+ else if($conn instanceof TDataSourceConfig)
+ return $conn->getDbConnection();
+ else
+ throw new TConfigurationException('datasource_dbconnection_invalid',$id);
+ }
+}
diff --git a/framework/Data/TDbCommand.php b/framework/Data/TDbCommand.php
index 44630fdd..054191a2 100644
--- a/framework/Data/TDbCommand.php
+++ b/framework/Data/TDbCommand.php
@@ -1,308 +1,308 @@
-<?php
-/**
- * TDbCommand class file
- *
- * @author Qiang Xue <qiang.xue@gmail.com>
- * @link http://www.pradosoft.com/
- * @copyright Copyright &copy; 2005-2012 PradoSoft
- * @license http://www.pradosoft.com/license/
- * @version $Id$
- * @package System.Data
- */
-
-/**
- * TDbCommand class.
- *
- * TDbCommand represents an SQL statement to execute against a database.
- * It is usually created by calling {@link TDbConnection::createCommand}.
- * The SQL statement to be executed may be set via {@link setText Text}.
- *
- * To execute a non-query SQL (such as insert, delete, update), call
- * {@link execute}. To execute an SQL statement that returns result data set
- * (such as select), use {@link query} or its convenient versions {@link queryRow}
- * and {@link queryScalar}.
- *
- * If an SQL statement returns results (such as a SELECT SQL), the results
- * can be accessed via the returned {@link TDbDataReader}.
- *
- * TDbCommand supports SQL statment preparation and parameter binding.
- * Call {@link bindParameter} to bind a PHP variable to a parameter in SQL.
- * Call {@link bindValue} to bind a value to an SQL parameter.
- * When binding a parameter, the SQL statement is automatically prepared.
- * You may also call {@link prepare} to explicitly prepare an SQL statement.
- *
- * @author Qiang Xue <qiang.xue@gmail.com>
- * @version $Id$
- * @package System.Data
- * @since 3.0
- */
-class TDbCommand extends TComponent
-{
- private $_connection;
- private $_text='';
- private $_statement=null;
-
- /**
- * Constructor.
- * @param TDbConnection the database connection
- * @param string the SQL statement to be executed
- */
- public function __construct(TDbConnection $connection,$text)
- {
- $this->_connection=$connection;
- $this->setText($text);
- }
-
- /**
- * Set the statement to null when serializing.
- */
- public function __sleep()
- {
- return array_diff(parent::__sleep(),array("\0TDbCommand\0_statement"));
- }
-
- /**
- * @return string the SQL statement to be executed
- */
- public function getText()
- {
- return $this->_text;
- }
-
- /**
- * Specifies the SQL statement to be executed.
- * Any previous execution will be terminated or cancel.
- * @param string the SQL statement to be executed
- */
- public function setText($value)
- {
- $this->_text=$value;
- $this->cancel();
- }
-
- /**
- * @return TDbConnection the connection associated with this command
- */
- public function getConnection()
- {
- return $this->_connection;
- }
-
- /**
- * @return PDOStatement the underlying PDOStatement for this command
- * It could be null if the statement is not prepared yet.
- */
- public function getPdoStatement()
- {
- return $this->_statement;
- }
-
- /**
- * Prepares the SQL statement to be executed.
- * For complex SQL statement that is to be executed multiple times,
- * this may improve performance.
- * For SQL statement with binding parameters, this method is invoked
- * automatically.
- */
- public function prepare()
- {
- if($this->_statement==null)
- {
- try
- {
- $this->_statement=$this->getConnection()->getPdoInstance()->prepare($this->getText());
- }
- catch(Exception $e)
- {
- throw new TDbException('dbcommand_prepare_failed',$e->getMessage(),$this->getText());
- }
- }
- }
-
- /**
- * Cancels the execution of the SQL statement.
- */
- public function cancel()
- {
- $this->_statement=null;
- }
-
- /**
- * Binds a parameter to the SQL statement to be executed.
- * @param mixed Parameter identifier. For a prepared statement
- * using named placeholders, this will be a parameter name of
- * the form :name. For a prepared statement using question mark
- * placeholders, this will be the 1-indexed position of the parameter.
- * Unlike {@link bindValue}, the variable is bound as a reference and will
- * only be evaluated at the time that {@link execute} or {@link query} is called.
- * @param mixed Name of the PHP variable to bind to the SQL statement parameter
- * @param int SQL data type of the parameter
- * @param int length of the data type
- * @see http://www.php.net/manual/en/function.PDOStatement-bindParam.php
- */
- public function bindParameter($name, &$value, $dataType=null, $length=null)
- {
- $this->prepare();
- if($dataType===null)
- $this->_statement->bindParam($name,$value);
- else if($length===null)
- $this->_statement->bindParam($name,$value,$dataType);
- else
- $this->_statement->bindParam($name,$value,$dataType,$length);
- }
-
- /**
- * Binds a value to a parameter.
- * @param mixed Parameter identifier. For a prepared statement
- * using named placeholders, this will be a parameter name of
- * the form :name. For a prepared statement using question mark
- * placeholders, this will be the 1-indexed position of the parameter.
- * @param mixed The value to bind to the parameter
- * @param int SQL data type of the parameter
- * @see http://www.php.net/manual/en/function.PDOStatement-bindValue.php
- */
- public function bindValue($name, $value, $dataType=null)
- {
- $this->prepare();
- if($dataType===null)
- $this->_statement->bindValue($name,$value);
- else
- $this->_statement->bindValue($name,$value,$dataType);
- }
-
- /**
- * Executes the SQL statement.
- * This method is meant only for executing non-query SQL statement.
- * No result set will be returned.
- * @return integer number of rows affected by the execution.
- * @throws TDbException execution failed
- */
- public function execute()
- {
- try
- {
- // Do not trace because it will remain even in
- // Performance mode or when pradolite.php is used
- // Prado::trace('Execute Command: '.$this->getDebugStatementText(), 'System.Data');
- if($this->_statement instanceof PDOStatement)
- {
- $this->_statement->execute();
- return $this->_statement->rowCount();
- }
- else
- return $this->getConnection()->getPdoInstance()->exec($this->getText());
- }
- catch(Exception $e)
- {
- throw new TDbException('dbcommand_execute_failed',$e->getMessage(),$this->getDebugStatementText());
- }
- }
-
- /**
- * @return String prepared SQL text for debugging purposes.
- */
- public function getDebugStatementText()
- {
- if(Prado::getApplication()->getMode() === TApplicationMode::Debug)
- return $this->_statement instanceof PDOStatement ?
- $this->_statement->queryString
- : $this->getText();
- }
-
- /**
- * Executes the SQL statement and returns query result.
- * This method is for executing an SQL query that returns result set.
- * @return TDbDataReader the reader object for fetching the query result
- * @throws TDbException execution failed
- */
- public function query()
- {
- try
- {
- // Prado::trace('Query: '.$this->getDebugStatementText(), 'System.Data');
- if($this->_statement instanceof PDOStatement)
- $this->_statement->execute();
- else
- $this->_statement=$this->getConnection()->getPdoInstance()->query($this->getText());
- return new TDbDataReader($this);
- }
- catch(Exception $e)
- {
- throw new TDbException('dbcommand_query_failed',$e->getMessage(),$this->getDebugStatementText());
- }
- }
-
- /**
- * Executes the SQL statement and returns the first row of the result.
- * This is a convenient method of {@link query} when only the first row of data is needed.
- * @param boolean whether the row should be returned as an associated array with
- * column names as the keys or the array keys are column indexes (0-based).
- * @return array the first row of the query result, false if no result.
- * @throws TDbException execution failed
- */
- public function queryRow($fetchAssociative=true)
- {
- try
- {
- // Prado::trace('Query Row: '.$this->getDebugStatementText(), 'System.Data');
- if($this->_statement instanceof PDOStatement)
- $this->_statement->execute();
- else
- $this->_statement=$this->getConnection()->getPdoInstance()->query($this->getText());
- $result=$this->_statement->fetch($fetchAssociative ? PDO::FETCH_ASSOC : PDO::FETCH_NUM);
- $this->_statement->closeCursor();
- return $result;
- }
- catch(Exception $e)
- {
- throw new TDbException('dbcommand_query_failed',$e->getMessage(),$this->getDebugStatementText());
- }
- }
-
- /**
- * Executes the SQL statement and returns the value of the first column in the first row of data.
- * This is a convenient method of {@link query} when only a single scalar
- * value is needed (e.g. obtaining the count of the records).
- * @return mixed the value of the first column in the first row of the query result. False is returned if there is no value.
- * @throws TDbException execution failed
- */
- public function queryScalar()
- {
- try
- {
- // Prado::trace('Query Scalar: '.$this->getDebugStatementText(), 'System.Data');
- if($this->_statement instanceof PDOStatement)
- $this->_statement->execute();
- else
- $this->_statement=$this->getConnection()->getPdoInstance()->query($this->getText());
- $result=$this->_statement->fetchColumn();
- $this->_statement->closeCursor();
- if(is_resource($result) && get_resource_type($result)==='stream')
- return stream_get_contents($result);
- else
- return $result;
- }
- catch(Exception $e)
- {
- throw new TDbException('dbcommand_query_failed',$e->getMessage(),$this->getDebugStatementText());
- }
- }
-
- /**
- * Executes the SQL statement and returns the first column of the result.
- * This is a convenient method of {@link query} when only the first column of data is needed.
- * Note, the column returned will contain the first element in each row of result.
- * @return array the first column of the query result. Empty array if no result.
- * @throws TDbException execution failed
- * @since 3.1.2
- */
- public function queryColumn()
- {
- $rows=$this->query()->readAll();
- $column=array();
- foreach($rows as $row)
- $column[]=current($row);
- return $column;
- }
-}
-
+<?php
+/**
+ * TDbCommand class file
+ *
+ * @author Qiang Xue <qiang.xue@gmail.com>
+ * @link http://www.pradosoft.com/
+ * @copyright Copyright &copy; 2005-2012 PradoSoft
+ * @license http://www.pradosoft.com/license/
+ * @version $Id$
+ * @package System.Data
+ */
+
+/**
+ * TDbCommand class.
+ *
+ * TDbCommand represents an SQL statement to execute against a database.
+ * It is usually created by calling {@link TDbConnection::createCommand}.
+ * The SQL statement to be executed may be set via {@link setText Text}.
+ *
+ * To execute a non-query SQL (such as insert, delete, update), call
+ * {@link execute}. To execute an SQL statement that returns result data set
+ * (such as select), use {@link query} or its convenient versions {@link queryRow}
+ * and {@link queryScalar}.
+ *
+ * If an SQL statement returns results (such as a SELECT SQL), the results
+ * can be accessed via the returned {@link TDbDataReader}.
+ *
+ * TDbCommand supports SQL statment preparation and parameter binding.
+ * Call {@link bindParameter} to bind a PHP variable to a parameter in SQL.
+ * Call {@link bindValue} to bind a value to an SQL parameter.
+ * When binding a parameter, the SQL statement is automatically prepared.
+ * You may also call {@link prepare} to explicitly prepare an SQL statement.
+ *
+ * @author Qiang Xue <qiang.xue@gmail.com>
+ * @version $Id$
+ * @package System.Data
+ * @since 3.0
+ */
+class TDbCommand extends TComponent
+{
+ private $_connection;
+ private $_text='';
+ private $_statement=null;
+
+ /**
+ * Constructor.
+ * @param TDbConnection the database connection
+ * @param string the SQL statement to be executed
+ */
+ public function __construct(TDbConnection $connection,$text)
+ {
+ $this->_connection=$connection;
+ $this->setText($text);
+ }
+
+ /**
+ * Set the statement to null when serializing.
+ */
+ public function __sleep()
+ {
+ return array_diff(parent::__sleep(),array("\0TDbCommand\0_statement"));
+ }
+
+ /**
+ * @return string the SQL statement to be executed
+ */
+ public function getText()
+ {
+ return $this->_text;
+ }
+
+ /**
+ * Specifies the SQL statement to be executed.
+ * Any previous execution will be terminated or cancel.
+ * @param string the SQL statement to be executed
+ */
+ public function setText($value)
+ {
+ $this->_text=$value;
+ $this->cancel();
+ }
+
+ /**
+ * @return TDbConnection the connection associated with this command
+ */
+ public function getConnection()
+ {
+ return $this->_connection;
+ }
+
+ /**
+ * @return PDOStatement the underlying PDOStatement for this command
+ * It could be null if the statement is not prepared yet.
+ */
+ public function getPdoStatement()
+ {
+ return $this->_statement;
+ }
+
+ /**
+ * Prepares the SQL statement to be executed.
+ * For complex SQL statement that is to be executed multiple times,
+ * this may improve performance.
+ * For SQL statement with binding parameters, this method is invoked
+ * automatically.
+ */
+ public function prepare()
+ {
+ if($this->_statement==null)
+ {
+ try
+ {
+ $this->_statement=$this->getConnection()->getPdoInstance()->prepare($this->getText());
+ }
+ catch(Exception $e)
+ {
+ throw new TDbException('dbcommand_prepare_failed',$e->getMessage(),$this->getText());
+ }
+ }
+ }
+
+ /**
+ * Cancels the execution of the SQL statement.
+ */
+ public function cancel()
+ {
+ $this->_statement=null;
+ }
+
+ /**
+ * Binds a parameter to the SQL statement to be executed.
+ * @param mixed Parameter identifier. For a prepared statement
+ * using named placeholders, this will be a parameter name of
+ * the form :name. For a prepared statement using question mark
+ * placeholders, this will be the 1-indexed position of the parameter.
+ * Unlike {@link bindValue}, the variable is bound as a reference and will
+ * only be evaluated at the time that {@link execute} or {@link query} is called.
+ * @param mixed Name of the PHP variable to bind to the SQL statement parameter
+ * @param int SQL data type of the parameter
+ * @param int length of the data type
+ * @see http://www.php.net/manual/en/function.PDOStatement-bindParam.php
+ */
+ public function bindParameter($name, &$value, $dataType=null, $length=null)
+ {
+ $this->prepare();
+ if($dataType===null)
+ $this->_statement->bindParam($name,$value);
+ else if($length===null)
+ $this->_statement->bindParam($name,$value,$dataType);
+ else
+ $this->_statement->bindParam($name,$value,$dataType,$length);
+ }
+
+ /**
+ * Binds a value to a parameter.
+ * @param mixed Parameter identifier. For a prepared statement
+ * using named placeholders, this will be a parameter name of
+ * the form :name. For a prepared statement using question mark
+ * placeholders, this will be the 1-indexed position of the parameter.
+ * @param mixed The value to bind to the parameter
+ * @param int SQL data type of the parameter
+ * @see http://www.php.net/manual/en/function.PDOStatement-bindValue.php
+ */
+ public function bindValue($name, $value, $dataType=null)
+ {
+ $this->prepare();
+ if($dataType===null)
+ $this->_statement->bindValue($name,$value);
+ else
+ $this->_statement->bindValue($name,$value,$dataType);
+ }
+
+ /**
+ * Executes the SQL statement.
+ * This method is meant only for executing non-query SQL statement.
+ * No result set will be returned.
+ * @return integer number of rows affected by the execution.
+ * @throws TDbException execution failed
+ */
+ public function execute()
+ {
+ try
+ {
+ // Do not trace because it will remain even in
+ // Performance mode or when pradolite.php is used
+ // Prado::trace('Execute Command: '.$this->getDebugStatementText(), 'System.Data');
+ if($this->_statement instanceof PDOStatement)
+ {
+ $this->_statement->execute();
+ return $this->_statement->rowCount();
+ }
+ else
+ return $this->getConnection()->getPdoInstance()->exec($this->getText());
+ }
+ catch(Exception $e)
+ {
+ throw new TDbException('dbcommand_execute_failed',$e->getMessage(),$this->getDebugStatementText());
+ }
+ }
+
+ /**
+ * @return String prepared SQL text for debugging purposes.
+ */
+ public function getDebugStatementText()
+ {
+ if(Prado::getApplication()->getMode() === TApplicationMode::Debug)
+ return $this->_statement instanceof PDOStatement ?
+ $this->_statement->queryString
+ : $this->getText();
+ }
+
+ /**
+ * Executes the SQL statement and returns query result.
+ * This method is for executing an SQL query that returns result set.
+ * @return TDbDataReader the reader object for fetching the query result
+ * @throws TDbException execution failed
+ */
+ public function query()
+ {
+ try
+ {
+ // Prado::trace('Query: '.$this->getDebugStatementText(), 'System.Data');
+ if($this->_statement instanceof PDOStatement)
+ $this->_statement->execute();
+ else
+ $this->_statement=$this->getConnection()->getPdoInstance()->query($this->getText());
+ return new TDbDataReader($this);
+ }
+ catch(Exception $e)
+ {
+ throw new TDbException('dbcommand_query_failed',$e->getMessage(),$this->getDebugStatementText());
+ }
+ }
+
+ /**
+ * Executes the SQL statement and returns the first row of the result.
+ * This is a convenient method of {@link query} when only the first row of data is needed.
+ * @param boolean whether the row should be returned as an associated array with
+ * column names as the keys or the array keys are column indexes (0-based).
+ * @return array the first row of the query result, false if no result.
+ * @throws TDbException execution failed
+ */
+ public function queryRow($fetchAssociative=true)
+ {
+ try
+ {
+ // Prado::trace('Query Row: '.$this->getDebugStatementText(), 'System.Data');
+ if($this->_statement instanceof PDOStatement)
+ $this->_statement->execute();
+ else
+ $this->_statement=$this->getConnection()->getPdoInstance()->query($this->getText());
+ $result=$this->_statement->fetch($fetchAssociative ? PDO::FETCH_ASSOC : PDO::FETCH_NUM);
+ $this->_statement->closeCursor();
+ return $result;
+ }
+ catch(Exception $e)
+ {
+ throw new TDbException('dbcommand_query_failed',$e->getMessage(),$this->getDebugStatementText());
+ }
+ }
+
+ /**
+ * Executes the SQL statement and returns the value of the first column in the first row of data.
+ * This is a convenient method of {@link query} when only a single scalar
+ * value is needed (e.g. obtaining the count of the records).
+ * @return mixed the value of the first column in the first row of the query result. False is returned if there is no value.
+ * @throws TDbException execution failed
+ */
+ public function queryScalar()
+ {
+ try
+ {
+ // Prado::trace('Query Scalar: '.$this->getDebugStatementText(), 'System.Data');
+ if($this->_statement instanceof PDOStatement)
+ $this->_statement->execute();
+ else
+ $this->_statement=$this->getConnection()->getPdoInstance()->query($this->getText());
+ $result=$this->_statement->fetchColumn();
+ $this->_statement->closeCursor();
+ if(is_resource($result) && get_resource_type($result)==='stream')
+ return stream_get_contents($result);
+ else
+ return $result;
+ }
+ catch(Exception $e)
+ {
+ throw new TDbException('dbcommand_query_failed',$e->getMessage(),$this->getDebugStatementText());
+ }
+ }
+
+ /**
+ * Executes the SQL statement and returns the first column of the result.
+ * This is a convenient method of {@link query} when only the first column of data is needed.
+ * Note, the column returned will contain the first element in each row of result.
+ * @return array the first column of the query result. Empty array if no result.
+ * @throws TDbException execution failed
+ * @since 3.1.2
+ */
+ public function queryColumn()
+ {
+ $rows=$this->query()->readAll();
+ $column=array();
+ foreach($rows as $row)
+ $column[]=current($row);
+ return $column;
+ }
+}
+
diff --git a/framework/Data/TDbConnection.php b/framework/Data/TDbConnection.php
index 0fd17ae1..fb93f076 100644
--- a/framework/Data/TDbConnection.php
+++ b/framework/Data/TDbConnection.php
@@ -1,685 +1,685 @@
-<?php
-/**
- * TDbConnection class file
- *
- * @author Qiang Xue <qiang.xue@gmail.com>
- * @link http://www.pradosoft.com/
- * @copyright Copyright &copy; 2005-2012 PradoSoft
- * @license http://www.pradosoft.com/license/
- * @version $Id$
- * @package System.Data
- */
-
-Prado::using('System.Data.TDbTransaction');
-Prado::using('System.Data.TDbCommand');
-
-/**
- * TDbConnection class
- *
- * TDbConnection represents a connection to a database.
- *
- * TDbConnection works together with {@link TDbCommand}, {@link TDbDataReader}
- * and {@link TDbTransaction} to provide data access to various DBMS
- * in a common set of APIs. They are a thin wrapper of the {@link http://www.php.net/manual/en/ref.pdo.php PDO}
- * PHP extension.
- *
- * To establish a connection, set {@link setActive Active} to true after
- * specifying {@link setConnectionString ConnectionString}, {@link setUsername Username}
- * and {@link setPassword Password}.
- *
- * Since 3.1.2, the connection charset can be set (for MySQL and PostgreSQL databases only)
- * using the {@link setCharset Charset} property. The value of this property is database dependant.
- * e.g. for mysql, you can use 'latin1' for cp1252 West European, 'utf8' for unicode, ...
- *
- * The following example shows how to create a TDbConnection instance and establish
- * the actual connection:
- * <code>
- * $connection=new TDbConnection($dsn,$username,$password);
- * $connection->Active=true;
- * </code>
- *
- * After the DB connection is established, one can execute an SQL statement like the following:
- * <code>
- * $command=$connection->createCommand($sqlStatement);
- * $command->execute(); // a non-query SQL statement execution
- * // or execute an SQL query and fetch the result set
- * $reader=$command->query();
- *
- * // each $row is an array representing a row of data
- * foreach($reader as $row) ...
- * </code>
- *
- * One can do prepared SQL execution and bind parameters to the prepared SQL:
- * <code>
- * $command=$connection->createCommand($sqlStatement);
- * $command->bindParameter($name1,$value1);
- * $command->bindParameter($name2,$value2);
- * $command->execute();
- * </code>
- *
- * To use transaction, do like the following:
- * <code>
- * $transaction=$connection->beginTransaction();
- * try
- * {
- * $connection->createCommand($sql1)->execute();
- * $connection->createCommand($sql2)->execute();
- * //.... other SQL executions
- * $transaction->commit();
- * }
- * catch(Exception $e)
- * {
- * $transaction->rollBack();
- * }
- * </code>
- *
- * TDbConnection provides a set of methods to support setting and querying
- * of certain DBMS attributes, such as {@link getNullConversion NullConversion}.
- *
- * @author Qiang Xue <qiang.xue@gmail.com>
- * @version $Id$
- * @package System.Data
- * @since 3.0
- */
-class TDbConnection extends TComponent
-{
- /**
- *
- * @since 3.1.7
- */
- const DEFAULT_TRANSACTION_CLASS = 'System.Data.TDbTransaction';
-
- private $_dsn='';
- private $_username='';
- private $_password='';
- private $_charset='';
- private $_attributes=array();
- private $_active=false;
- private $_pdo=null;
- private $_transaction;
-
- /**
- * @var TDbMetaData
- */
- private $_dbMeta = null;
-
- /**
- * @var string
- * @since 3.1.7
- */
- private $_transactionClass=self::DEFAULT_TRANSACTION_CLASS;
-
- /**
- * Constructor.
- * Note, the DB connection is not established when this connection
- * instance is created. Set {@link setActive Active} property to true
- * to establish the connection.
- * Since 3.1.2, you can set the charset for MySql connection
- *
- * @param string The Data Source Name, or DSN, contains the information required to connect to the database.
- * @param string The user name for the DSN string.
- * @param string The password for the DSN string.
- * @param string Charset used for DB Connection (MySql & pgsql only). If not set, will use the default charset of your database server
- * @see http://www.php.net/manual/en/function.PDO-construct.php
- */
- public function __construct($dsn='',$username='',$password='', $charset='')
- {
- $this->_dsn=$dsn;
- $this->_username=$username;
- $this->_password=$password;
- $this->_charset=$charset;
- }
-
- /**
- * Close the connection when serializing.
- */
- public function __sleep()
- {
-// $this->close(); - DO NOT CLOSE the current connection as serializing doesn't neccessarily mean we don't this connection anymore in the current session
- return array_diff(parent::__sleep(),array("\0TDbConnection\0_pdo","\0TDbConnection\0_active"));
- }
-
- /**
- * @return array list of available PDO drivers
- * @see http://www.php.net/manual/en/function.PDO-getAvailableDrivers.php
- */
- public static function getAvailableDrivers()
- {
- return PDO::getAvailableDrivers();
- }
-
- /**
- * @return boolean whether the DB connection is established
- */
- public function getActive()
- {
- return $this->_active;
- }
-
- /**
- * Open or close the DB connection.
- * @param boolean whether to open or close DB connection
- * @throws TDbException if connection fails
- */
- public function setActive($value)
- {
- $value=TPropertyValue::ensureBoolean($value);
- if($value!==$this->_active)
- {
- if($value)
- $this->open();
- else
- $this->close();
- }
- }
-
- /**
- * Opens DB connection if it is currently not
- * @throws TDbException if connection fails
- */
- protected function open()
- {
- if($this->_pdo===null)
- {
- try
- {
- $this->_pdo=new PDO($this->getConnectionString(),$this->getUsername(),
+<?php
+/**
+ * TDbConnection class file
+ *
+ * @author Qiang Xue <qiang.xue@gmail.com>
+ * @link http://www.pradosoft.com/
+ * @copyright Copyright &copy; 2005-2012 PradoSoft
+ * @license http://www.pradosoft.com/license/
+ * @version $Id$
+ * @package System.Data
+ */
+
+Prado::using('System.Data.TDbTransaction');
+Prado::using('System.Data.TDbCommand');
+
+/**
+ * TDbConnection class
+ *
+ * TDbConnection represents a connection to a database.
+ *
+ * TDbConnection works together with {@link TDbCommand}, {@link TDbDataReader}
+ * and {@link TDbTransaction} to provide data access to various DBMS
+ * in a common set of APIs. They are a thin wrapper of the {@link http://www.php.net/manual/en/ref.pdo.php PDO}
+ * PHP extension.
+ *
+ * To establish a connection, set {@link setActive Active} to true after
+ * specifying {@link setConnectionString ConnectionString}, {@link setUsername Username}
+ * and {@link setPassword Password}.
+ *
+ * Since 3.1.2, the connection charset can be set (for MySQL and PostgreSQL databases only)
+ * using the {@link setCharset Charset} property. The value of this property is database dependant.
+ * e.g. for mysql, you can use 'latin1' for cp1252 West European, 'utf8' for unicode, ...
+ *
+ * The following example shows how to create a TDbConnection instance and establish
+ * the actual connection:
+ * <code>
+ * $connection=new TDbConnection($dsn,$username,$password);
+ * $connection->Active=true;
+ * </code>
+ *
+ * After the DB connection is established, one can execute an SQL statement like the following:
+ * <code>
+ * $command=$connection->createCommand($sqlStatement);
+ * $command->execute(); // a non-query SQL statement execution
+ * // or execute an SQL query and fetch the result set
+ * $reader=$command->query();
+ *
+ * // each $row is an array representing a row of data
+ * foreach($reader as $row) ...
+ * </code>
+ *
+ * One can do prepared SQL execution and bind parameters to the prepared SQL:
+ * <code>
+ * $command=$connection->createCommand($sqlStatement);
+ * $command->bindParameter($name1,$value1);
+ * $command->bindParameter($name2,$value2);
+ * $command->execute();
+ * </code>
+ *
+ * To use transaction, do like the following:
+ * <code>
+ * $transaction=$connection->beginTransaction();
+ * try
+ * {
+ * $connection->createCommand($sql1)->execute();
+ * $connection->createCommand($sql2)->execute();
+ * //.... other SQL executions
+ * $transaction->commit();
+ * }
+ * catch(Exception $e)
+ * {
+ * $transaction->rollBack();
+ * }
+ * </code>
+ *
+ * TDbConnection provides a set of methods to support setting and querying
+ * of certain DBMS attributes, such as {@link getNullConversion NullConversion}.
+ *
+ * @author Qiang Xue <qiang.xue@gmail.com>
+ * @version $Id$
+ * @package System.Data
+ * @since 3.0
+ */
+class TDbConnection extends TComponent
+{
+ /**
+ *
+ * @since 3.1.7
+ */
+ const DEFAULT_TRANSACTION_CLASS = 'System.Data.TDbTransaction';
+
+ private $_dsn='';
+ private $_username='';
+ private $_password='';
+ private $_charset='';
+ private $_attributes=array();
+ private $_active=false;
+ private $_pdo=null;
+ private $_transaction;
+
+ /**
+ * @var TDbMetaData
+ */
+ private $_dbMeta = null;
+
+ /**
+ * @var string
+ * @since 3.1.7
+ */
+ private $_transactionClass=self::DEFAULT_TRANSACTION_CLASS;
+
+ /**
+ * Constructor.
+ * Note, the DB connection is not established when this connection
+ * instance is created. Set {@link setActive Active} property to true
+ * to establish the connection.
+ * Since 3.1.2, you can set the charset for MySql connection
+ *
+ * @param string The Data Source Name, or DSN, contains the information required to connect to the database.
+ * @param string The user name for the DSN string.
+ * @param string The password for the DSN string.
+ * @param string Charset used for DB Connection (MySql & pgsql only). If not set, will use the default charset of your database server
+ * @see http://www.php.net/manual/en/function.PDO-construct.php
+ */
+ public function __construct($dsn='',$username='',$password='', $charset='')
+ {
+ $this->_dsn=$dsn;
+ $this->_username=$username;
+ $this->_password=$password;
+ $this->_charset=$charset;
+ }
+
+ /**
+ * Close the connection when serializing.
+ */
+ public function __sleep()
+ {
+// $this->close(); - DO NOT CLOSE the current connection as serializing doesn't neccessarily mean we don't this connection anymore in the current session
+ return array_diff(parent::__sleep(),array("\0TDbConnection\0_pdo","\0TDbConnection\0_active"));
+ }
+
+ /**
+ * @return array list of available PDO drivers
+ * @see http://www.php.net/manual/en/function.PDO-getAvailableDrivers.php
+ */
+ public static function getAvailableDrivers()
+ {
+ return PDO::getAvailableDrivers();
+ }
+
+ /**
+ * @return boolean whether the DB connection is established
+ */
+ public function getActive()
+ {
+ return $this->_active;
+ }
+
+ /**
+ * Open or close the DB connection.
+ * @param boolean whether to open or close DB connection
+ * @throws TDbException if connection fails
+ */
+ public function setActive($value)
+ {
+ $value=TPropertyValue::ensureBoolean($value);
+ if($value!==$this->_active)
+ {
+ if($value)
+ $this->open();
+ else
+ $this->close();
+ }
+ }
+
+ /**
+ * Opens DB connection if it is currently not
+ * @throws TDbException if connection fails
+ */
+ protected function open()
+ {
+ if($this->_pdo===null)
+ {
+ try
+ {
+ $this->_pdo=new PDO($this->getConnectionString(),$this->getUsername(),
$this->getPassword(),$this->_attributes);
- // This attribute is only useful for PDO::MySql driver.
+ // This attribute is only useful for PDO::MySql driver.
// Ignore the warning if a driver doesn't understand this.
- @$this->_pdo->setAttribute(PDO::ATTR_EMULATE_PREPARES, true);
- $this->_pdo->setAttribute(PDO::ATTR_ERRMODE, PDO::ERRMODE_EXCEPTION);
- $this->_active=true;
- $this->setConnectionCharset();
- }
- catch(PDOException $e)
- {
- throw new TDbException('dbconnection_open_failed',$e->getMessage());
- }
- }
- }
-
- /**
- * Closes the currently active DB connection.
- * It does nothing if the connection is already closed.
- */
- protected function close()
- {
- $this->_pdo=null;
- $this->_active=false;
- }
-
- /*
- * Set the database connection charset.
- * Only MySql databases are supported for now.
- * @since 3.1.2
- */
- protected function setConnectionCharset()
- {
- if ($this->_charset === '' || $this->_active === false)
- return;
- switch ($this->_pdo->getAttribute(PDO::ATTR_DRIVER_NAME))
- {
- case 'mysql':
- case 'sqlite':
- $stmt = $this->_pdo->prepare('SET NAMES ?');
- break;
- case 'pgsql':
- $stmt = $this->_pdo->prepare('SET client_encoding TO ?');
- break;
- default:
- throw new TDbException('dbconnection_unsupported_driver_charset', $driver);
- }
- $stmt->execute(array($this->_charset));
- }
-
- /**
- * @return string The Data Source Name, or DSN, contains the information required to connect to the database.
- */
- public function getConnectionString()
- {
- return $this->_dsn;
- }
-
- /**
- * @param string The Data Source Name, or DSN, contains the information required to connect to the database.
- * @see http://www.php.net/manual/en/function.PDO-construct.php
- */
- public function setConnectionString($value)
- {
- $this->_dsn=$value;
- }
-
- /**
- * @return string the username for establishing DB connection. Defaults to empty string.
- */
- public function getUsername()
- {
- return $this->_username;
- }
-
- /**
- * @param string the username for establishing DB connection
- */
- public function setUsername($value)
- {
- $this->_username=$value;
- }
-
- /**
- * @return string the password for establishing DB connection. Defaults to empty string.
- */
- public function getPassword()
- {
- return $this->_password;
- }
-
- /**
- * @param string the password for establishing DB connection
- */
- public function setPassword($value)
- {
- $this->_password=$value;
- }
-
- /**
- * @return string the charset used for database connection. Defaults to emtpy string.
- */
- public function getCharset ()
- {
- return $this->_charset;
- }
-
- /**
- * @param string the charset used for database connection
- */
- public function setCharset ($value)
- {
- $this->_charset=$value;
- $this->setConnectionCharset();
- }
-
- /**
- * @return PDO the PDO instance, null if the connection is not established yet
- */
- public function getPdoInstance()
- {
- return $this->_pdo;
- }
-
- /**
- * Creates a command for execution.
- * @param string SQL statement associated with the new command.
- * @return TDbCommand the DB command
- * @throws TDbException if the connection is not active
- */
- public function createCommand($sql)
- {
- if($this->getActive())
- return new TDbCommand($this,$sql);
- else
- throw new TDbException('dbconnection_connection_inactive');
- }
-
- /**
- * @return TDbTransaction the currently active transaction. Null if no active transaction.
- */
- public function getCurrentTransaction()
- {
- if($this->_transaction!==null)
- {
- if($this->_transaction->getActive())
- return $this->_transaction;
- }
- return null;
- }
-
- /**
- * Starts a transaction.
- * @return TDbTransaction the transaction initiated
- * @throws TDbException if the connection is not active
- */
- public function beginTransaction()
- {
- if($this->getActive())
- {
- $this->_pdo->beginTransaction();
- return $this->_transaction=Prado::createComponent($this->getTransactionClass(), $this);
- }
- else
- throw new TDbException('dbconnection_connection_inactive');
- }
-
- /**
- * @return string Transaction class name to be created by calling {@link TDbConnection::beginTransaction}. Defaults to 'System.Data.TDbTransaction'.
- * @since 3.1.7
- */
- public function getTransactionClass()
- {
- return $this->_transactionClass;
- }
-
-
- /**
- * @param string Transaction class name to be created by calling {@link TDbConnection::beginTransaction}.
- * @since 3.1.7
- */
- public function setTransactionClass($value)
- {
- $this->_transactionClass = (string)$value;
- }
-
- /**
- * Returns the ID of the last inserted row or sequence value.
- * @param string name of the sequence object (required by some DBMS)
- * @return string the row ID of the last row inserted, or the last value retrieved from the sequence object
- * @see http://www.php.net/manual/en/function.PDO-lastInsertId.php
- */
- public function getLastInsertID($sequenceName='')
- {
- if($this->getActive())
- return $this->_pdo->lastInsertId($sequenceName);
- else
- throw new TDbException('dbconnection_connection_inactive');
- }
-
- /**
- * Quotes a string for use in a query.
- * @param string string to be quoted
- * @return string the properly quoted string
- * @see http://www.php.net/manual/en/function.PDO-quote.php
- */
- public function quoteString($str)
- {
- if($this->getActive())
- return $this->_pdo->quote($str);
- else
- throw new TDbException('dbconnection_connection_inactive');
- }
-
- /**
- * Quotes a table name for use in a query.
- * @param string $name table name
- * @return string the properly quoted table name
- */
- public function quoteTableName($name)
- {
- return $this->getDbMetaData()->quoteTableName($name);
- }
-
- /**
- * Quotes a column name for use in a query.
- * @param string $name column name
- * @return string the properly quoted column name
- */
- public function quoteColumnName($name)
- {
- return $this->getDbMetaData()->quoteColumnName($name);
- }
-
- /**
- * Quotes a column alias for use in a query.
- * @param string $name column name
- * @return string the properly quoted column alias
- */
- public function quoteColumnAlias($name)
- {
- return $this->getDbMetaData()->quoteColumnAlias($name);
- }
-
- /**
- * @return TDbMetaData
- */
- public function getDbMetaData()
- {
- if($this->_dbMeta===null)
- {
- Prado::using('System.Data.Common.TDbMetaData');
- $this->_dbMeta = TDbMetaData::getInstance($this);
- }
- return $this->_dbMeta;
- }
-
- /**
- * @return TDbColumnCaseMode the case of the column names
- */
- public function getColumnCase()
- {
- switch($this->getAttribute(PDO::ATTR_CASE))
- {
- case PDO::CASE_NATURAL:
- return TDbColumnCaseMode::Preserved;
- case PDO::CASE_LOWER:
- return TDbColumnCaseMode::LowerCase;
- case PDO::CASE_UPPER:
- return TDbColumnCaseMode::UpperCase;
- }
- }
-
- /**
- * @param TDbColumnCaseMode the case of the column names
- */
- public function setColumnCase($value)
- {
- switch(TPropertyValue::ensureEnum($value,'TDbColumnCaseMode'))
- {
- case TDbColumnCaseMode::Preserved:
- $value=PDO::CASE_NATURAL;
- break;
- case TDbColumnCaseMode::LowerCase:
- $value=PDO::CASE_LOWER;
- break;
- case TDbColumnCaseMode::UpperCase:
- $value=PDO::CASE_UPPER;
- break;
- }
- $this->setAttribute(PDO::ATTR_CASE,$value);
- }
-
- /**
- * @return TDbNullConversionMode how the null and empty strings are converted
- */
- public function getNullConversion()
- {
- switch($this->getAttribute(PDO::ATTR_ORACLE_NULLS))
- {
- case PDO::NULL_NATURAL:
- return TDbNullConversionMode::Preserved;
- case PDO::NULL_EMPTY_STRING:
- return TDbNullConversionMode::EmptyStringToNull;
- case PDO::NULL_TO_STRING:
- return TDbNullConversionMode::NullToEmptyString;
- }
- }
-
- /**
- * @param TDbNullConversionMode how the null and empty strings are converted
- */
- public function setNullConversion($value)
- {
- switch(TPropertyValue::ensureEnum($value,'TDbNullConversionMode'))
- {
- case TDbNullConversionMode::Preserved:
- $value=PDO::NULL_NATURAL;
- break;
- case TDbNullConversionMode::EmptyStringToNull:
- $value=PDO::NULL_EMPTY_STRING;
- break;
- case TDbNullConversionMode::NullToEmptyString:
- $value=PDO::NULL_TO_STRING;
- break;
- }
- $this->setAttribute(PDO::ATTR_ORACLE_NULLS,$value);
- }
-
- /**
- * @return boolean whether creating or updating a DB record will be automatically committed.
- * Some DBMS (such as sqlite) may not support this feature.
- */
- public function getAutoCommit()
- {
- return $this->getAttribute(PDO::ATTR_AUTOCOMMIT);
- }
-
- /**
- * @param boolean whether creating or updating a DB record will be automatically committed.
- * Some DBMS (such as sqlite) may not support this feature.
- */
- public function setAutoCommit($value)
- {
- $this->setAttribute(PDO::ATTR_AUTOCOMMIT,TPropertyValue::ensureBoolean($value));
- }
-
- /**
- * @return boolean whether the connection is persistent or not
- * Some DBMS (such as sqlite) may not support this feature.
- */
- public function getPersistent()
- {
- return $this->getAttribute(PDO::ATTR_PERSISTENT);
- }
-
- /**
- * @param boolean whether the connection is persistent or not
- * Some DBMS (such as sqlite) may not support this feature.
- */
- public function setPersistent($value)
- {
- return $this->setAttribute(PDO::ATTR_PERSISTENT,TPropertyValue::ensureBoolean($value));
- }
-
- /**
- * @return string name of the DB driver
- */
- public function getDriverName()
- {
- return $this->getAttribute(PDO::ATTR_DRIVER_NAME);
- }
-
- /**
- * @return string the version information of the DB driver
- */
- public function getClientVersion()
- {
- return $this->getAttribute(PDO::ATTR_CLIENT_VERSION);
- }
-
- /**
- * @return string the status of the connection
- * Some DBMS (such as sqlite) may not support this feature.
- */
- public function getConnectionStatus()
- {
- return $this->getAttribute(PDO::ATTR_CONNECTION_STATUS);
- }
-
- /**
- * @return boolean whether the connection performs data prefetching
- */
- public function getPrefetch()
- {
- return $this->getAttribute(PDO::ATTR_PREFETCH);
- }
-
- /**
- * @return string the information of DBMS server
- */
- public function getServerInfo()
- {
- return $this->getAttribute(PDO::ATTR_SERVER_INFO);
- }
-
- /**
- * @return string the version information of DBMS server
- */
- public function getServerVersion()
- {
- return $this->getAttribute(PDO::ATTR_SERVER_VERSION);
- }
-
- /**
- * @return int timeout settings for the connection
- */
- public function getTimeout()
- {
- return $this->getAttribute(PDO::ATTR_TIMEOUT);
- }
-
- /**
- * Obtains a specific DB connection attribute information.
- * @param int the attribute to be queried
- * @return mixed the corresponding attribute information
- * @see http://www.php.net/manual/en/function.PDO-getAttribute.php
- */
- public function getAttribute($name)
- {
- if($this->getActive())
- return $this->_pdo->getAttribute($name);
- else
- throw new TDbException('dbconnection_connection_inactive');
- }
-
- /**
- * Sets an attribute on the database connection.
- * @param int the attribute to be set
- * @param mixed the attribute value
- * @see http://www.php.net/manual/en/function.PDO-setAttribute.php
- */
- public function setAttribute($name,$value)
- {
- if($this->_pdo instanceof PDO)
- $this->_pdo->setAttribute($name,$value);
- else
- $this->_attributes[$name]=$value;
- }
-}
-
-/**
- * TDbColumnCaseMode
- *
- * @author Qiang Xue <qiang.xue@gmail.com>
- * @version $Id$
- * @package System.Data
- * @since 3.0
- */
-class TDbColumnCaseMode extends TEnumerable
-{
- /**
- * Column name cases are kept as is from the database
- */
- const Preserved='Preserved';
- /**
- * Column names are converted to lower case
- */
- const LowerCase='LowerCase';
- /**
- * Column names are converted to upper case
- */
- const UpperCase='UpperCase';
-}
-
-/**
- * TDbNullConversionMode
- *
- * @author Qiang Xue <qiang.xue@gmail.com>
- * @version $Id$
- * @package System.Data
- * @since 3.0
- */
-class TDbNullConversionMode extends TEnumerable
-{
- /**
- * No conversion is performed for null and empty values.
- */
- const Preserved='Preserved';
- /**
- * NULL is converted to empty string
- */
- const NullToEmptyString='NullToEmptyString';
- /**
- * Empty string is converted to NULL
- */
- const EmptyStringToNull='EmptyStringToNull';
-}
-
-?>
+ @$this->_pdo->setAttribute(PDO::ATTR_EMULATE_PREPARES, true);
+ $this->_pdo->setAttribute(PDO::ATTR_ERRMODE, PDO::ERRMODE_EXCEPTION);
+ $this->_active=true;
+ $this->setConnectionCharset();
+ }
+ catch(PDOException $e)
+ {
+ throw new TDbException('dbconnection_open_failed',$e->getMessage());
+ }
+ }
+ }
+
+ /**
+ * Closes the currently active DB connection.
+ * It does nothing if the connection is already closed.
+ */
+ protected function close()
+ {
+ $this->_pdo=null;
+ $this->_active=false;
+ }
+
+ /*
+ * Set the database connection charset.
+ * Only MySql databases are supported for now.
+ * @since 3.1.2
+ */
+ protected function setConnectionCharset()
+ {
+ if ($this->_charset === '' || $this->_active === false)
+ return;
+ switch ($this->_pdo->getAttribute(PDO::ATTR_DRIVER_NAME))
+ {
+ case 'mysql':
+ case 'sqlite':
+ $stmt = $this->_pdo->prepare('SET NAMES ?');
+ break;
+ case 'pgsql':
+ $stmt = $this->_pdo->prepare('SET client_encoding TO ?');
+ break;
+ default:
+ throw new TDbException('dbconnection_unsupported_driver_charset', $driver);
+ }
+ $stmt->execute(array($this->_charset));
+ }
+
+ /**
+ * @return string The Data Source Name, or DSN, contains the information required to connect to the database.
+ */
+ public function getConnectionString()
+ {
+ return $this->_dsn;
+ }
+
+ /**
+ * @param string The Data Source Name, or DSN, contains the information required to connect to the database.
+ * @see http://www.php.net/manual/en/function.PDO-construct.php
+ */
+ public function setConnectionString($value)
+ {
+ $this->_dsn=$value;
+ }
+
+ /**
+ * @return string the username for establishing DB connection. Defaults to empty string.
+ */
+ public function getUsername()
+ {
+ return $this->_username;
+ }
+
+ /**
+ * @param string the username for establishing DB connection
+ */
+ public function setUsername($value)
+ {
+ $this->_username=$value;
+ }
+
+ /**
+ * @return string the password for establishing DB connection. Defaults to empty string.
+ */
+ public function getPassword()
+ {
+ return $this->_password;
+ }
+
+ /**
+ * @param string the password for establishing DB connection
+ */
+ public function setPassword($value)
+ {
+ $this->_password=$value;
+ }
+
+ /**
+ * @return string the charset used for database connection. Defaults to emtpy string.
+ */
+ public function getCharset ()
+ {
+ return $this->_charset;
+ }
+
+ /**
+ * @param string the charset used for database connection
+ */
+ public function setCharset ($value)
+ {
+ $this->_charset=$value;
+ $this->setConnectionCharset();
+ }
+
+ /**
+ * @return PDO the PDO instance, null if the connection is not established yet
+ */
+ public function getPdoInstance()
+ {
+ return $this->_pdo;
+ }
+
+ /**
+ * Creates a command for execution.
+ * @param string SQL statement associated with the new command.
+ * @return TDbCommand the DB command
+ * @throws TDbException if the connection is not active
+ */
+ public function createCommand($sql)
+ {
+ if($this->getActive())
+ return new TDbCommand($this,$sql);
+ else
+ throw new TDbException('dbconnection_connection_inactive');
+ }
+
+ /**
+ * @return TDbTransaction the currently active transaction. Null if no active transaction.
+ */
+ public function getCurrentTransaction()
+ {
+ if($this->_transaction!==null)
+ {
+ if($this->_transaction->getActive())
+ return $this->_transaction;
+ }
+ return null;
+ }
+
+ /**
+ * Starts a transaction.
+ * @return TDbTransaction the transaction initiated
+ * @throws TDbException if the connection is not active
+ */
+ public function beginTransaction()
+ {
+ if($this->getActive())
+ {
+ $this->_pdo->beginTransaction();
+ return $this->_transaction=Prado::createComponent($this->getTransactionClass(), $this);
+ }
+ else
+ throw new TDbException('dbconnection_connection_inactive');
+ }
+
+ /**
+ * @return string Transaction class name to be created by calling {@link TDbConnection::beginTransaction}. Defaults to 'System.Data.TDbTransaction'.
+ * @since 3.1.7
+ */
+ public function getTransactionClass()
+ {
+ return $this->_transactionClass;
+ }
+
+
+ /**
+ * @param string Transaction class name to be created by calling {@link TDbConnection::beginTransaction}.
+ * @since 3.1.7
+ */
+ public function setTransactionClass($value)
+ {
+ $this->_transactionClass = (string)$value;
+ }
+
+ /**
+ * Returns the ID of the last inserted row or sequence value.
+ * @param string name of the sequence object (required by some DBMS)
+ * @return string the row ID of the last row inserted, or the last value retrieved from the sequence object
+ * @see http://www.php.net/manual/en/function.PDO-lastInsertId.php
+ */
+ public function getLastInsertID($sequenceName='')
+ {
+ if($this->getActive())
+ return $this->_pdo->lastInsertId($sequenceName);
+ else
+ throw new TDbException('dbconnection_connection_inactive');
+ }
+
+ /**
+ * Quotes a string for use in a query.
+ * @param string string to be quoted
+ * @return string the properly quoted string
+ * @see http://www.php.net/manual/en/function.PDO-quote.php
+ */
+ public function quoteString($str)
+ {
+ if($this->getActive())
+ return $this->_pdo->quote($str);
+ else
+ throw new TDbException('dbconnection_connection_inactive');
+ }
+
+ /**
+ * Quotes a table name for use in a query.
+ * @param string $name table name
+ * @return string the properly quoted table name
+ */
+ public function quoteTableName($name)
+ {
+ return $this->getDbMetaData()->quoteTableName($name);
+ }
+
+ /**
+ * Quotes a column name for use in a query.
+ * @param string $name column name
+ * @return string the properly quoted column name
+ */
+ public function quoteColumnName($name)
+ {
+ return $this->getDbMetaData()->quoteColumnName($name);
+ }
+
+ /**
+ * Quotes a column alias for use in a query.
+ * @param string $name column name
+ * @return string the properly quoted column alias
+ */
+ public function quoteColumnAlias($name)
+ {
+ return $this->getDbMetaData()->quoteColumnAlias($name);
+ }
+
+ /**
+ * @return TDbMetaData
+ */
+ public function getDbMetaData()
+ {
+ if($this->_dbMeta===null)
+ {
+ Prado::using('System.Data.Common.TDbMetaData');
+ $this->_dbMeta = TDbMetaData::getInstance($this);
+ }
+ return $this->_dbMeta;
+ }
+
+ /**
+ * @return TDbColumnCaseMode the case of the column names
+ */
+ public function getColumnCase()
+ {
+ switch($this->getAttribute(PDO::ATTR_CASE))
+ {
+ case PDO::CASE_NATURAL:
+ return TDbColumnCaseMode::Preserved;
+ case PDO::CASE_LOWER:
+ return TDbColumnCaseMode::LowerCase;
+ case PDO::CASE_UPPER:
+ return TDbColumnCaseMode::UpperCase;
+ }
+ }
+
+ /**
+ * @param TDbColumnCaseMode the case of the column names
+ */
+ public function setColumnCase($value)
+ {
+ switch(TPropertyValue::ensureEnum($value,'TDbColumnCaseMode'))
+ {
+ case TDbColumnCaseMode::Preserved:
+ $value=PDO::CASE_NATURAL;
+ break;
+ case TDbColumnCaseMode::LowerCase:
+ $value=PDO::CASE_LOWER;
+ break;
+ case TDbColumnCaseMode::UpperCase:
+ $value=PDO::CASE_UPPER;
+ break;
+ }
+ $this->setAttribute(PDO::ATTR_CASE,$value);
+ }
+
+ /**
+ * @return TDbNullConversionMode how the null and empty strings are converted
+ */
+ public function getNullConversion()
+ {
+ switch($this->getAttribute(PDO::ATTR_ORACLE_NULLS))
+ {
+ case PDO::NULL_NATURAL:
+ return TDbNullConversionMode::Preserved;
+ case PDO::NULL_EMPTY_STRING:
+ return TDbNullConversionMode::EmptyStringToNull;
+ case PDO::NULL_TO_STRING:
+ return TDbNullConversionMode::NullToEmptyString;
+ }
+ }
+
+ /**
+ * @param TDbNullConversionMode how the null and empty strings are converted
+ */
+ public function setNullConversion($value)
+ {
+ switch(TPropertyValue::ensureEnum($value,'TDbNullConversionMode'))
+ {
+ case TDbNullConversionMode::Preserved:
+ $value=PDO::NULL_NATURAL;
+ break;
+ case TDbNullConversionMode::EmptyStringToNull:
+ $value=PDO::NULL_EMPTY_STRING;
+ break;
+ case TDbNullConversionMode::NullToEmptyString:
+ $value=PDO::NULL_TO_STRING;
+ break;
+ }
+ $this->setAttribute(PDO::ATTR_ORACLE_NULLS,$value);
+ }
+
+ /**
+ * @return boolean whether creating or updating a DB record will be automatically committed.
+ * Some DBMS (such as sqlite) may not support this feature.
+ */
+ public function getAutoCommit()
+ {
+ return $this->getAttribute(PDO::ATTR_AUTOCOMMIT);
+ }
+
+ /**
+ * @param boolean whether creating or updating a DB record will be automatically committed.
+ * Some DBMS (such as sqlite) may not support this feature.
+ */
+ public function setAutoCommit($value)
+ {
+ $this->setAttribute(PDO::ATTR_AUTOCOMMIT,TPropertyValue::ensureBoolean($value));
+ }
+
+ /**
+ * @return boolean whether the connection is persistent or not
+ * Some DBMS (such as sqlite) may not support this feature.
+ */
+ public function getPersistent()
+ {
+ return $this->getAttribute(PDO::ATTR_PERSISTENT);
+ }
+
+ /**
+ * @param boolean whether the connection is persistent or not
+ * Some DBMS (such as sqlite) may not support this feature.
+ */
+ public function setPersistent($value)
+ {
+ return $this->setAttribute(PDO::ATTR_PERSISTENT,TPropertyValue::ensureBoolean($value));
+ }
+
+ /**
+ * @return string name of the DB driver
+ */
+ public function getDriverName()
+ {
+ return $this->getAttribute(PDO::ATTR_DRIVER_NAME);
+ }
+
+ /**
+ * @return string the version information of the DB driver
+ */
+ public function getClientVersion()
+ {
+ return $this->getAttribute(PDO::ATTR_CLIENT_VERSION);
+ }
+
+ /**
+ * @return string the status of the connection
+ * Some DBMS (such as sqlite) may not support this feature.
+ */
+ public function getConnectionStatus()
+ {
+ return $this->getAttribute(PDO::ATTR_CONNECTION_STATUS);
+ }
+
+ /**
+ * @return boolean whether the connection performs data prefetching
+ */
+ public function getPrefetch()
+ {
+ return $this->getAttribute(PDO::ATTR_PREFETCH);
+ }
+
+ /**
+ * @return string the information of DBMS server
+ */
+ public function getServerInfo()
+ {
+ return $this->getAttribute(PDO::ATTR_SERVER_INFO);
+ }
+
+ /**
+ * @return string the version information of DBMS server
+ */
+ public function getServerVersion()
+ {
+ return $this->getAttribute(PDO::ATTR_SERVER_VERSION);
+ }
+
+ /**
+ * @return int timeout settings for the connection
+ */
+ public function getTimeout()
+ {
+ return $this->getAttribute(PDO::ATTR_TIMEOUT);
+ }
+
+ /**
+ * Obtains a specific DB connection attribute information.
+ * @param int the attribute to be queried
+ * @return mixed the corresponding attribute information
+ * @see http://www.php.net/manual/en/function.PDO-getAttribute.php
+ */
+ public function getAttribute($name)
+ {
+ if($this->getActive())
+ return $this->_pdo->getAttribute($name);
+ else
+ throw new TDbException('dbconnection_connection_inactive');
+ }
+
+ /**
+ * Sets an attribute on the database connection.
+ * @param int the attribute to be set
+ * @param mixed the attribute value
+ * @see http://www.php.net/manual/en/function.PDO-setAttribute.php
+ */
+ public function setAttribute($name,$value)
+ {
+ if($this->_pdo instanceof PDO)
+ $this->_pdo->setAttribute($name,$value);
+ else
+ $this->_attributes[$name]=$value;
+ }
+}
+
+/**
+ * TDbColumnCaseMode
+ *
+ * @author Qiang Xue <qiang.xue@gmail.com>
+ * @version $Id$
+ * @package System.Data
+ * @since 3.0
+ */
+class TDbColumnCaseMode extends TEnumerable
+{
+ /**
+ * Column name cases are kept as is from the database
+ */
+ const Preserved='Preserved';
+ /**
+ * Column names are converted to lower case
+ */
+ const LowerCase='LowerCase';
+ /**
+ * Column names are converted to upper case
+ */
+ const UpperCase='UpperCase';
+}
+
+/**
+ * TDbNullConversionMode
+ *
+ * @author Qiang Xue <qiang.xue@gmail.com>
+ * @version $Id$
+ * @package System.Data
+ * @since 3.0
+ */
+class TDbNullConversionMode extends TEnumerable
+{
+ /**
+ * No conversion is performed for null and empty values.
+ */
+ const Preserved='Preserved';
+ /**
+ * NULL is converted to empty string
+ */
+ const NullToEmptyString='NullToEmptyString';
+ /**
+ * Empty string is converted to NULL
+ */
+ const EmptyStringToNull='EmptyStringToNull';
+}
+
+?>
diff --git a/framework/Data/TDbDataReader.php b/framework/Data/TDbDataReader.php
index 879fd49f..d191e336 100644
--- a/framework/Data/TDbDataReader.php
+++ b/framework/Data/TDbDataReader.php
@@ -1,225 +1,225 @@
-<?php
-/**
- * TDbDataReader class file
- *
- * @author Qiang Xue <qiang.xue@gmail.com>
- * @link http://www.pradosoft.com/
+<?php
+/**
+ * TDbDataReader class file
+ *
+ * @author Qiang Xue <qiang.xue@gmail.com>
+ * @link http://www.pradosoft.com/
* @copyright Copyright &copy; 2005-2012 PradoSoft
- * @license http://www.pradosoft.com/license/
- * @version $Id$
- * @package System.Data
- */
-
-/**
- * TDbDataReader class.
- *
- * TDbDataReader represents a forward-only stream of rows from a query result set.
- *
- * To read the current row of data, call {@link read}. The method {@link readAll}
- * returns all the rows in a single array.
- *
- * One can also retrieve the rows of data in TDbDataReader by using foreach:
- * <code>
- * foreach($reader as $row)
- * // $row represents a row of data
- * </code>
- * Since TDbDataReader is a forward-only stream, you can only traverse it once.
- *
- * It is possible to use a specific mode of data fetching by setting
- * {@link setFetchMode FetchMode}. See {@link http://www.php.net/manual/en/function.PDOStatement-setFetchMode.php}
- * for more details.
- *
- * @author Qiang Xue <qiang.xue@gmail.com>
- * @version $Id$
- * @package System.Data
- * @since 3.0
- */
-class TDbDataReader extends TComponent implements Iterator
-{
- private $_statement;
- private $_closed=false;
- private $_row;
- private $_index=-1;
-
- /**
- * Constructor.
- * @param TDbCommand the command generating the query result
- */
- public function __construct(TDbCommand $command)
- {
- $this->_statement=$command->getPdoStatement();
- $this->_statement->setFetchMode(PDO::FETCH_ASSOC);
- }
-
- /**
- * Binds a column to a PHP variable.
- * When rows of data are being fetched, the corresponding column value
- * will be set in the variable. Note, the fetch mode must include PDO::FETCH_BOUND.
- * @param mixed Number of the column (1-indexed) or name of the column
- * in the result set. If using the column name, be aware that the name
- * should match the case of the column, as returned by the driver.
- * @param mixed Name of the PHP variable to which the column will be bound.
- * @param int Data type of the parameter
- * @see http://www.php.net/manual/en/function.PDOStatement-bindColumn.php
- */
- public function bindColumn($column, &$value, $dataType=null)
- {
- if($dataType===null)
- $this->_statement->bindColumn($column,$value);
- else
- $this->_statement->bindColumn($column,$value,$dataType);
- }
-
- /**
- * @see http://www.php.net/manual/en/function.PDOStatement-setFetchMode.php
- */
- public function setFetchMode($mode)
- {
- $params=func_get_args();
- call_user_func_array(array($this->_statement,'setFetchMode'),$params);
- }
-
- /**
- * Advances the reader to the next row in a result set.
- * @return array|false the current row, false if no more row available
- */
- public function read()
- {
- return $this->_statement->fetch();
- }
-
- /**
- * Returns a single column from the next row of a result set.
- * @param int zero-based column index
- * @return mixed|false the column of the current row, false if no more row available
- */
- public function readColumn($columnIndex)
- {
- return $this->_statement->fetchColumn($columnIndex);
- }
-
- /**
- * Returns a single column from the next row of a result set.
- * @param string class name of the object to be created and populated
- * @param array list of column names whose values are to be passed as parameters in the constructor of the class being created
- * @return mixed|false the populated object, false if no more row of data available
- */
- public function readObject($className,$fields)
- {
- return $this->_statement->fetchObject($className,$fields);
- }
-
- /**
- * Reads the whole result set into an array.
- * @return array the result set (each array element represents a row of data).
- * An empty array will be returned if the result contains no row.
- */
- public function readAll()
- {
- return $this->_statement->fetchAll();
- }
-
- /**
- * Advances the reader to the next result when reading the results of a batch of statements.
- * This method is only useful when there are multiple result sets
- * returned by the query. Not all DBMS support this feature.
- */
- public function nextResult()
- {
- return $this->_statement->nextRowset();
- }
-
- /**
- * Closes the reader.
- * Any further data reading will result in an exception.
- */
- public function close()
- {
- $this->_statement->closeCursor();
- $this->_closed=true;
- }
-
- /**
- * @return boolean whether the reader is closed or not.
- */
- public function getIsClosed()
- {
- return $this->_closed;
- }
-
- /**
- * @return int number of rows contained in the result.
- * Note, most DBMS may not give a meaningful count.
- * In this case, use "SELECT COUNT(*) FROM tableName" to obtain the number of rows.
- */
- public function getRowCount()
- {
- return $this->_statement->rowCount();
- }
-
- /**
- * @return int the number of columns in the result set.
- * Note, even there's no row in the reader, this still gives correct column number.
- */
- public function getColumnCount()
- {
- return $this->_statement->columnCount();
- }
-
- /**
- * Resets the iterator to the initial state.
- * This method is required by the interface Iterator.
- * @throws TDbException if this method is invoked twice
- */
- public function rewind()
- {
- if($this->_index<0)
- {
- $this->_row=$this->_statement->fetch();
- $this->_index=0;
- }
- else
- throw new TDbException('dbdatareader_rewind_invalid');
- }
-
- /**
- * Returns the index of the current row.
- * This method is required by the interface Iterator.
- * @return integer the index of the current row.
- */
- public function key()
- {
- return $this->_index;
- }
-
- /**
- * Returns the current row.
- * This method is required by the interface Iterator.
- * @return mixed the current row.
- */
- public function current()
- {
- return $this->_row;
- }
-
- /**
- * Moves the internal pointer to the next row.
- * This method is required by the interface Iterator.
- */
- public function next()
- {
- $this->_row=$this->_statement->fetch();
- $this->_index++;
- }
-
- /**
- * Returns whether there is a row of data at current position.
- * This method is required by the interface Iterator.
- * @return boolean whether there is a row of data at current position.
- */
- public function valid()
- {
- return $this->_row!==false;
- }
-}
-
+ * @license http://www.pradosoft.com/license/
+ * @version $Id$
+ * @package System.Data
+ */
+
+/**
+ * TDbDataReader class.
+ *
+ * TDbDataReader represents a forward-only stream of rows from a query result set.
+ *
+ * To read the current row of data, call {@link read}. The method {@link readAll}
+ * returns all the rows in a single array.
+ *
+ * One can also retrieve the rows of data in TDbDataReader by using foreach:
+ * <code>
+ * foreach($reader as $row)
+ * // $row represents a row of data
+ * </code>
+ * Since TDbDataReader is a forward-only stream, you can only traverse it once.
+ *
+ * It is possible to use a specific mode of data fetching by setting
+ * {@link setFetchMode FetchMode}. See {@link http://www.php.net/manual/en/function.PDOStatement-setFetchMode.php}
+ * for more details.
+ *
+ * @author Qiang Xue <qiang.xue@gmail.com>
+ * @version $Id$
+ * @package System.Data
+ * @since 3.0
+ */
+class TDbDataReader extends TComponent implements Iterator
+{
+ private $_statement;
+ private $_closed=false;
+ private $_row;
+ private $_index=-1;
+
+ /**
+ * Constructor.
+ * @param TDbCommand the command generating the query result
+ */
+ public function __construct(TDbCommand $command)
+ {
+ $this->_statement=$command->getPdoStatement();
+ $this->_statement->setFetchMode(PDO::FETCH_ASSOC);
+ }
+
+ /**
+ * Binds a column to a PHP variable.
+ * When rows of data are being fetched, the corresponding column value
+ * will be set in the variable. Note, the fetch mode must include PDO::FETCH_BOUND.
+ * @param mixed Number of the column (1-indexed) or name of the column
+ * in the result set. If using the column name, be aware that the name
+ * should match the case of the column, as returned by the driver.
+ * @param mixed Name of the PHP variable to which the column will be bound.
+ * @param int Data type of the parameter
+ * @see http://www.php.net/manual/en/function.PDOStatement-bindColumn.php
+ */
+ public function bindColumn($column, &$value, $dataType=null)
+ {
+ if($dataType===null)
+ $this->_statement->bindColumn($column,$value);
+ else
+ $this->_statement->bindColumn($column,$value,$dataType);
+ }
+
+ /**
+ * @see http://www.php.net/manual/en/function.PDOStatement-setFetchMode.php
+ */
+ public function setFetchMode($mode)
+ {
+ $params=func_get_args();
+ call_user_func_array(array($this->_statement,'setFetchMode'),$params);
+ }
+
+ /**
+ * Advances the reader to the next row in a result set.
+ * @return array|false the current row, false if no more row available
+ */
+ public function read()
+ {
+ return $this->_statement->fetch();
+ }
+
+ /**
+ * Returns a single column from the next row of a result set.
+ * @param int zero-based column index
+ * @return mixed|false the column of the current row, false if no more row available
+ */
+ public function readColumn($columnIndex)
+ {
+ return $this->_statement->fetchColumn($columnIndex);
+ }
+
+ /**
+ * Returns a single column from the next row of a result set.
+ * @param string class name of the object to be created and populated
+ * @param array list of column names whose values are to be passed as parameters in the constructor of the class being created
+ * @return mixed|false the populated object, false if no more row of data available
+ */
+ public function readObject($className,$fields)
+ {
+ return $this->_statement->fetchObject($className,$fields);
+ }
+
+ /**
+ * Reads the whole result set into an array.
+ * @return array the result set (each array element represents a row of data).
+ * An empty array will be returned if the result contains no row.
+ */
+ public function readAll()
+ {
+ return $this->_statement->fetchAll();
+ }
+
+ /**
+ * Advances the reader to the next result when reading the results of a batch of statements.
+ * This method is only useful when there are multiple result sets
+ * returned by the query. Not all DBMS support this feature.
+ */
+ public function nextResult()
+ {
+ return $this->_statement->nextRowset();
+ }
+
+ /**
+ * Closes the reader.
+ * Any further data reading will result in an exception.
+ */
+ public function close()
+ {
+ $this->_statement->closeCursor();
+ $this->_closed=true;
+ }
+
+ /**
+ * @return boolean whether the reader is closed or not.
+ */
+ public function getIsClosed()
+ {
+ return $this->_closed;
+ }
+
+ /**
+ * @return int number of rows contained in the result.
+ * Note, most DBMS may not give a meaningful count.
+ * In this case, use "SELECT COUNT(*) FROM tableName" to obtain the number of rows.
+ */
+ public function getRowCount()
+ {
+ return $this->_statement->rowCount();
+ }
+
+ /**
+ * @return int the number of columns in the result set.
+ * Note, even there's no row in the reader, this still gives correct column number.
+ */
+ public function getColumnCount()
+ {
+ return $this->_statement->columnCount();
+ }
+
+ /**
+ * Resets the iterator to the initial state.
+ * This method is required by the interface Iterator.
+ * @throws TDbException if this method is invoked twice
+ */
+ public function rewind()
+ {
+ if($this->_index<0)
+ {
+ $this->_row=$this->_statement->fetch();
+ $this->_index=0;
+ }
+ else
+ throw new TDbException('dbdatareader_rewind_invalid');
+ }
+
+ /**
+ * Returns the index of the current row.
+ * This method is required by the interface Iterator.
+ * @return integer the index of the current row.
+ */
+ public function key()
+ {
+ return $this->_index;
+ }
+
+ /**
+ * Returns the current row.
+ * This method is required by the interface Iterator.
+ * @return mixed the current row.
+ */
+ public function current()
+ {
+ return $this->_row;
+ }
+
+ /**
+ * Moves the internal pointer to the next row.
+ * This method is required by the interface Iterator.
+ */
+ public function next()
+ {
+ $this->_row=$this->_statement->fetch();
+ $this->_index++;
+ }
+
+ /**
+ * Returns whether there is a row of data at current position.
+ * This method is required by the interface Iterator.
+ * @return boolean whether there is a row of data at current position.
+ */
+ public function valid()
+ {
+ return $this->_row!==false;
+ }
+}
+
diff --git a/framework/Data/TDbTransaction.php b/framework/Data/TDbTransaction.php
index c60deec5..618ec79e 100644
--- a/framework/Data/TDbTransaction.php
+++ b/framework/Data/TDbTransaction.php
@@ -1,112 +1,112 @@
-<?php
-/**
- * TDbTransaction class file
- *
- * @author Qiang Xue <qiang.xue@gmail.com>
- * @link http://www.pradosoft.com/
+<?php
+/**
+ * TDbTransaction class file
+ *
+ * @author Qiang Xue <qiang.xue@gmail.com>
+ * @link http://www.pradosoft.com/
* @copyright Copyright &copy; 2005-2012 PradoSoft
- * @license http://www.pradosoft.com/license/
- * @version $Id$
- * @package System.Data
- */
-
-Prado::using('System.Data.TDbDataReader');
-
-/**
- * TDbTransaction class.
- *
- * TDbTransaction represents a DB transaction.
- * It is usually created by calling {@link TDbConnection::beginTransaction}.
- *
- * The following code is a common scenario of using transactions:
- * <code>
- * try
- * {
- * $transaction=$connection->beginTransaction();
- * $connection->createCommand($sql1)->execute();
- * $connection->createCommand($sql2)->execute();
- * //.... other SQL executions
- * $transaction->commit();
- * }
- * catch(Exception $e)
- * {
- * $transaction->rollBack();
- * }
- * </code>
- *
- * @author Qiang Xue <qiang.xue@gmail.com>
- * @version $Id$
- * @package System.Data
- * @since 3.0
- */
-class TDbTransaction extends TComponent
-{
- private $_connection=null;
- private $_active;
-
- /**
- * Constructor.
- * @param TDbConnection the connection associated with this transaction
- * @see TDbConnection::beginTransaction
- */
- public function __construct(TDbConnection $connection)
- {
- $this->_connection=$connection;
- $this->setActive(true);
- }
-
- /**
- * Commits a transaction.
- * @throws TDbException if the transaction or the DB connection is not active.
- */
- public function commit()
- {
- if($this->_active && $this->_connection->getActive())
- {
- $this->_connection->getPdoInstance()->commit();
- $this->_active=false;
- }
- else
- throw new TDbException('dbtransaction_transaction_inactive');
- }
-
- /**
- * Rolls back a transaction.
- * @throws TDbException if the transaction or the DB connection is not active.
- */
- public function rollback()
- {
- if($this->_active && $this->_connection->getActive())
- {
- $this->_connection->getPdoInstance()->rollBack();
- $this->_active=false;
- }
- else
- throw new TDbException('dbtransaction_transaction_inactive');
- }
-
- /**
- * @return TDbConnection the DB connection for this transaction
- */
- public function getConnection()
- {
- return $this->_connection;
- }
-
- /**
- * @return boolean whether this transaction is active
- */
- public function getActive()
- {
- return $this->_active;
- }
-
- /**
- * @param boolean whether this transaction is active
- */
- protected function setActive($value)
- {
- $this->_active=TPropertyValue::ensureBoolean($value);
- }
-}
-
+ * @license http://www.pradosoft.com/license/
+ * @version $Id$
+ * @package System.Data
+ */
+
+Prado::using('System.Data.TDbDataReader');
+
+/**
+ * TDbTransaction class.
+ *
+ * TDbTransaction represents a DB transaction.
+ * It is usually created by calling {@link TDbConnection::beginTransaction}.
+ *
+ * The following code is a common scenario of using transactions:
+ * <code>
+ * try
+ * {
+ * $transaction=$connection->beginTransaction();
+ * $connection->createCommand($sql1)->execute();
+ * $connection->createCommand($sql2)->execute();
+ * //.... other SQL executions
+ * $transaction->commit();
+ * }
+ * catch(Exception $e)
+ * {
+ * $transaction->rollBack();
+ * }
+ * </code>
+ *
+ * @author Qiang Xue <qiang.xue@gmail.com>
+ * @version $Id$
+ * @package System.Data
+ * @since 3.0
+ */
+class TDbTransaction extends TComponent
+{
+ private $_connection=null;
+ private $_active;
+
+ /**
+ * Constructor.
+ * @param TDbConnection the connection associated with this transaction
+ * @see TDbConnection::beginTransaction
+ */
+ public function __construct(TDbConnection $connection)
+ {
+ $this->_connection=$connection;
+ $this->setActive(true);
+ }
+
+ /**
+ * Commits a transaction.
+ * @throws TDbException if the transaction or the DB connection is not active.
+ */
+ public function commit()
+ {
+ if($this->_active && $this->_connection->getActive())
+ {
+ $this->_connection->getPdoInstance()->commit();
+ $this->_active=false;
+ }
+ else
+ throw new TDbException('dbtransaction_transaction_inactive');
+ }
+
+ /**
+ * Rolls back a transaction.
+ * @throws TDbException if the transaction or the DB connection is not active.
+ */
+ public function rollback()
+ {
+ if($this->_active && $this->_connection->getActive())
+ {
+ $this->_connection->getPdoInstance()->rollBack();
+ $this->_active=false;
+ }
+ else
+ throw new TDbException('dbtransaction_transaction_inactive');
+ }
+
+ /**
+ * @return TDbConnection the DB connection for this transaction
+ */
+ public function getConnection()
+ {
+ return $this->_connection;
+ }
+
+ /**
+ * @return boolean whether this transaction is active
+ */
+ public function getActive()
+ {
+ return $this->_active;
+ }
+
+ /**
+ * @param boolean whether this transaction is active
+ */
+ protected function setActive($value)
+ {
+ $this->_active=TPropertyValue::ensureBoolean($value);
+ }
+}
+
diff --git a/framework/Exceptions/TErrorHandler.php b/framework/Exceptions/TErrorHandler.php
index 7940fcae..f105cd1a 100644
--- a/framework/Exceptions/TErrorHandler.php
+++ b/framework/Exceptions/TErrorHandler.php
@@ -1,413 +1,413 @@
-<?php
-/**
- * TErrorHandler class file
- *
- * @author Qiang Xue <qiang.xue@gmail.com>
- * @link http://www.pradosoft.com/
- * @copyright Copyright &copy; 2005-2012 PradoSoft
- * @license http://www.pradosoft.com/license/
- * @version $Id$
- * @package System.Exceptions
- */
-
-/**
- * TErrorHandler class
- *
- * TErrorHandler handles all PHP user errors and exceptions generated during
- * servicing user requests. It displays these errors using different templates
- * and if possible, using languages preferred by the client user.
- * Note, PHP parsing errors cannot be caught and handled by TErrorHandler.
- *
- * The templates used to format the error output are stored under System.Exceptions.
- * You may choose to use your own templates, should you not like the templates
- * provided by Prado. Simply set {@link setErrorTemplatePath ErrorTemplatePath}
- * to the path (in namespace format) storing your own templates.
- *
- * There are two sets of templates, one for errors to be displayed to client users
- * (called external errors), one for errors to be displayed to system developers
- * (called internal errors). The template file name for the former is
- * <b>error[StatusCode][-LanguageCode].html</b>, and for the latter it is
- * <b>exception[-LanguageCode].html</b>, where StatusCode refers to response status
- * code (e.g. 404, 500) specified when {@link THttpException} is thrown,
- * and LanguageCode is the client user preferred language code (e.g. en, zh, de).
- * The templates <b>error.html</b> and <b>exception.html</b> are default ones
- * that are used if no other appropriate templates are available.
- * Note, these templates are not Prado control templates. They are simply
- * html files with keywords (e.g. %%ErrorMessage%%, %%Version%%)
- * to be replaced with the corresponding information.
- *
- * By default, TErrorHandler is registered with {@link TApplication} as the
- * error handler module. It can be accessed via {@link TApplication::getErrorHandler()}.
- * You seldom need to deal with the error handler directly. It is mainly used
- * by the application object to handle errors.
- *
- * TErrorHandler may be configured in application configuration file as follows
- * <module id="error" class="TErrorHandler" ErrorTemplatePath="System.Exceptions" />
- *
- * @author Qiang Xue <qiang.xue@gmail.com>
- * @version $Id$
- * @package System.Exceptions
- * @since 3.0
- */
-class TErrorHandler extends TModule
-{
- /**
- * error template file basename
- */
- const ERROR_FILE_NAME='error';
- /**
- * exception template file basename
- */
- const EXCEPTION_FILE_NAME='exception';
- /**
- * number of lines before and after the error line to be displayed in case of an exception
- */
- const SOURCE_LINES=12;
-
- /**
- * @var string error template directory
- */
- private $_templatePath=null;
-
- /**
- * Initializes the module.
- * This method is required by IModule and is invoked by application.
- * @param TXmlElement module configuration
- */
- public function init($config)
- {
- $this->getApplication()->setErrorHandler($this);
- }
-
- /**
- * @return string the directory containing error template files.
- */
- public function getErrorTemplatePath()
- {
- if($this->_templatePath===null)
- $this->_templatePath=Prado::getFrameworkPath().'/Exceptions/templates';
- return $this->_templatePath;
- }
-
- /**
- * Sets the path storing all error and exception template files.
- * The path must be in namespace format, such as System.Exceptions (which is the default).
- * @param string template path in namespace format
- * @throws TConfigurationException if the template path is invalid
- */
- public function setErrorTemplatePath($value)
- {
- if(($templatePath=Prado::getPathOfNamespace($value))!==null && is_dir($templatePath))
- $this->_templatePath=$templatePath;
- else
- throw new TConfigurationException('errorhandler_errortemplatepath_invalid',$value);
- }
-
- /**
- * Handles PHP user errors and exceptions.
- * This is the event handler responding to the <b>Error</b> event
- * raised in {@link TApplication}.
- * The method mainly uses appropriate template to display the error/exception.
- * It terminates the application immediately after the error is displayed.
- * @param mixed sender of the event
- * @param mixed event parameter (if the event is raised by TApplication, it refers to the exception instance)
- */
- public function handleError($sender,$param)
- {
- static $handling=false;
- // We need to restore error and exception handlers,
- // because within error and exception handlers, new errors and exceptions
- // cannot be handled properly by PHP
- restore_error_handler();
- restore_exception_handler();
- // ensure that we do not enter infinite loop of error handling
- if($handling)
- $this->handleRecursiveError($param);
- else
- {
- $handling=true;
- if(($response=$this->getResponse())!==null)
- $response->clear();
- if(!headers_sent())
- header('Content-Type: text/html; charset=UTF-8');
- if($param instanceof THttpException)
- $this->handleExternalError($param->getStatusCode(),$param);
- else if($this->getApplication()->getMode()===TApplicationMode::Debug)
- $this->displayException($param);
- else
- $this->handleExternalError(500,$param);
- }
- }
-
-
- /**
- * @param string $value
- * @param Exception|null$exception
- * @return string
- * @since 3.1.6
- */
- protected static function hideSecurityRelated($value, $exception=null)
- {
- $aRpl = array();
- if($exception !== null && $exception instanceof Exception)
- {
- $aTrace = $exception->getTrace();
- foreach($aTrace as $item)
- {
- if(isset($item['file']))
- $aRpl[dirname($item['file']) . DIRECTORY_SEPARATOR] = '<hidden>' . DIRECTORY_SEPARATOR;
- }
- }
- $aRpl[$_SERVER['DOCUMENT_ROOT']] = '${DocumentRoot}';
- $aRpl[str_replace('/', DIRECTORY_SEPARATOR, $_SERVER['DOCUMENT_ROOT'])] = '${DocumentRoot}';
- $aRpl[PRADO_DIR . DIRECTORY_SEPARATOR] = '${PradoFramework}' . DIRECTORY_SEPARATOR;
- if(isset($aRpl[DIRECTORY_SEPARATOR])) unset($aRpl[DIRECTORY_SEPARATOR]);
- $aRpl = array_reverse($aRpl, true);
-
- return str_replace(array_keys($aRpl), $aRpl, $value);
- }
-
- /**
- * Displays error to the client user.
- * THttpException and errors happened when the application is in <b>Debug</b>
- * mode will be displayed to the client user.
- * @param integer response status code
- * @param Exception exception instance
- */
- protected function handleExternalError($statusCode,$exception)
- {
- if(!($exception instanceof THttpException))
- error_log($exception->__toString());
-
- $content=$this->getErrorTemplate($statusCode,$exception);
-
- $serverAdmin=isset($_SERVER['SERVER_ADMIN'])?$_SERVER['SERVER_ADMIN']:'';
-
- $isDebug = $this->getApplication()->getMode()===TApplicationMode::Debug;
-
- $errorMessage = $exception->getMessage();
- if($isDebug)
- $version=$_SERVER['SERVER_SOFTWARE'].' <a href="http://www.pradosoft.com/">PRADO</a>/'.Prado::getVersion();
- else
- {
- $version='';
- $errorMessage = self::hideSecurityRelated($errorMessage, $exception);
- }
- $tokens=array(
- '%%StatusCode%%' => "$statusCode",
- '%%ErrorMessage%%' => htmlspecialchars($errorMessage),
- '%%ServerAdmin%%' => $serverAdmin,
- '%%Version%%' => $version,
- '%%Time%%' => @strftime('%Y-%m-%d %H:%M',time())
- );
-
- $CGI=substr(php_sapi_name(), 0, 3) == 'cgi'; // FastCGI / IIS
- if($isDebug)
- {
- if ($CGI)
- header("Status: $statusCode ".$exception->getMessage(), true, TPropertyValue::ensureInteger($statusCode));
- else
- header("HTTP/1.0 $statusCode ".$exception->getMessage(), true, TPropertyValue::ensureInteger($statusCode));
- } else {
- if ($CGI)
- header("Status: $statusCode", true, TPropertyValue::ensureInteger($statusCode));
- else
- header("HTTP/1.0 $statusCode", true, TPropertyValue::ensureInteger($statusCode));
- }
-
- echo strtr($content,$tokens);
- }
-
- /**
- * Handles error occurs during error handling (called recursive error).
- * THttpException and errors happened when the application is in <b>Debug</b>
- * mode will be displayed to the client user.
- * Error is displayed without using existing template to prevent further errors.
- * @param Exception exception instance
- */
- protected function handleRecursiveError($exception)
- {
- if($this->getApplication()->getMode()===TApplicationMode::Debug)
- {
- echo "<html><head><title>Recursive Error</title></head>\n";
- echo "<body><h1>Recursive Error</h1>\n";
- echo "<pre>".$exception->__toString()."</pre>\n";
- echo "</body></html>";
- }
- else
- {
- error_log("Error happened while processing an existing error:\n".$exception->__toString());
- header('HTTP/1.0 500 Internal Error');
- }
- }
-
- /**
- * Displays exception information.
- * Exceptions are displayed with rich context information, including
- * the call stack and the context source code.
- * This method is only invoked when application is in <b>Debug</b> mode.
- * @param Exception exception instance
- */
- protected function displayException($exception)
- {
- if(php_sapi_name()==='cli')
- {
- echo $exception->getMessage()."\n";
- echo $exception->getTraceAsString();
- return;
- }
-
- if($exception instanceof TTemplateException)
- {
- $fileName=$exception->getTemplateFile();
- $lines=empty($fileName)?explode("\n",$exception->getTemplateSource()):@file($fileName);
- $source=$this->getSourceCode($lines,$exception->getLineNumber());
- if($fileName==='')
- $fileName='---embedded template---';
- $errorLine=$exception->getLineNumber();
- }
- else
- {
- if(($trace=$this->getExactTrace($exception))!==null)
- {
- $fileName=$trace['file'];
- $errorLine=$trace['line'];
- }
- else
- {
- $fileName=$exception->getFile();
- $errorLine=$exception->getLine();
- }
- $source=$this->getSourceCode(@file($fileName),$errorLine);
- }
-
- if($this->getApplication()->getMode()===TApplicationMode::Debug)
- $version=$_SERVER['SERVER_SOFTWARE'].' <a href="http://www.pradosoft.com/">PRADO</a>/'.Prado::getVersion();
- else
- $version='';
-
- $tokens=array(
- '%%ErrorType%%' => get_class($exception),
- '%%ErrorMessage%%' => $this->addLink(htmlspecialchars($exception->getMessage())),
- '%%SourceFile%%' => htmlspecialchars($fileName).' ('.$errorLine.')',
- '%%SourceCode%%' => $source,
- '%%StackTrace%%' => htmlspecialchars($exception->getTraceAsString()),
- '%%Version%%' => $version,
- '%%Time%%' => @strftime('%Y-%m-%d %H:%M',time())
- );
-
- $content=$this->getExceptionTemplate($exception);
-
- echo strtr($content,$tokens);
- }
-
- /**
- * Retrieves the template used for displaying internal exceptions.
- * Internal exceptions will be displayed with source code causing the exception.
- * This occurs when the application is in debug mode.
- * @param Exception the exception to be displayed
- * @return string the template content
- */
- protected function getExceptionTemplate($exception)
- {
- $lang=Prado::getPreferredLanguage();
- $exceptionFile=Prado::getFrameworkPath().'/Exceptions/templates/'.self::EXCEPTION_FILE_NAME.'-'.$lang.'.html';
- if(!is_file($exceptionFile))
- $exceptionFile=Prado::getFrameworkPath().'/Exceptions/templates/'.self::EXCEPTION_FILE_NAME.'.html';
- if(($content=@file_get_contents($exceptionFile))===false)
- die("Unable to open exception template file '$exceptionFile'.");
- return $content;
- }
-
- /**
- * Retrieves the template used for displaying external exceptions.
- * External exceptions are those displayed to end-users. They do not contain
- * error source code. Therefore, you might want to override this method
- * to provide your own error template for displaying certain external exceptions.
- * The following tokens in the template will be replaced with corresponding content:
- * %%StatusCode%% : the status code of the exception
- * %%ErrorMessage%% : the error message (HTML encoded).
- * %%ServerAdmin%% : the server admin information (retrieved from Web server configuration)
- * %%Version%% : the version information of the Web server.
- * %%Time%% : the time the exception occurs at
- *
- * @param integer status code (such as 404, 500, etc.)
- * @param Exception the exception to be displayed
- * @return string the template content
- */
- protected function getErrorTemplate($statusCode,$exception)
- {
- $base=$this->getErrorTemplatePath().DIRECTORY_SEPARATOR.self::ERROR_FILE_NAME;
- $lang=Prado::getPreferredLanguage();
- if(is_file("$base$statusCode-$lang.html"))
- $errorFile="$base$statusCode-$lang.html";
- else if(is_file("$base$statusCode.html"))
- $errorFile="$base$statusCode.html";
- else if(is_file("$base-$lang.html"))
- $errorFile="$base-$lang.html";
- else
- $errorFile="$base.html";
- if(($content=@file_get_contents($errorFile))===false)
- die("Unable to open error template file '$errorFile'.");
- return $content;
- }
-
- private function getExactTrace($exception)
- {
- $trace=$exception->getTrace();
- $result=null;
- // if PHP exception, we want to show the 2nd stack level context
- // because the 1st stack level is of little use (it's in error handler)
- if($exception instanceof TPhpErrorException)
- $result=isset($trace[0]['file'])?$trace[0]:$trace[1];
- else if($exception instanceof TInvalidOperationException)
- {
- // in case of getter or setter error, find out the exact file and row
- if(($result=$this->getPropertyAccessTrace($trace,'__get'))===null)
- $result=$this->getPropertyAccessTrace($trace,'__set');
- }
- if($result!==null && strpos($result['file'],': eval()\'d code')!==false)
- return null;
-
- return $result;
- }
-
- private function getPropertyAccessTrace($trace,$pattern)
- {
- $result=null;
- foreach($trace as $t)
- {
- if(isset($t['function']) && $t['function']===$pattern)
- $result=$t;
- else
- break;
- }
- return $result;
- }
-
- private function getSourceCode($lines,$errorLine)
- {
- $beginLine=$errorLine-self::SOURCE_LINES>=0?$errorLine-self::SOURCE_LINES:0;
- $endLine=$errorLine+self::SOURCE_LINES<=count($lines)?$errorLine+self::SOURCE_LINES:count($lines);
-
- $source='';
- for($i=$beginLine;$i<$endLine;++$i)
- {
- if($i===$errorLine-1)
- {
- $line=htmlspecialchars(sprintf("%04d: %s",$i+1,str_replace("\t",' ',$lines[$i])));
- $source.="<div class=\"error\">".$line."</div>";
- }
- else
- $source.=htmlspecialchars(sprintf("%04d: %s",$i+1,str_replace("\t",' ',$lines[$i])));
- }
- return $source;
- }
-
- private function addLink($message)
- {
- $baseUrl='http://www.pradosoft.com/docs/classdoc';
- return preg_replace('/\b(T[A-Z]\w+)\b/',"<a href=\"$baseUrl/\${1}\" target=\"_blank\">\${1}</a>",$message);
- }
-}
-
+<?php
+/**
+ * TErrorHandler class file
+ *
+ * @author Qiang Xue <qiang.xue@gmail.com>
+ * @link http://www.pradosoft.com/
+ * @copyright Copyright &copy; 2005-2012 PradoSoft
+ * @license http://www.pradosoft.com/license/
+ * @version $Id$
+ * @package System.Exceptions
+ */
+
+/**
+ * TErrorHandler class
+ *
+ * TErrorHandler handles all PHP user errors and exceptions generated during
+ * servicing user requests. It displays these errors using different templates
+ * and if possible, using languages preferred by the client user.
+ * Note, PHP parsing errors cannot be caught and handled by TErrorHandler.
+ *
+ * The templates used to format the error output are stored under System.Exceptions.
+ * You may choose to use your own templates, should you not like the templates
+ * provided by Prado. Simply set {@link setErrorTemplatePath ErrorTemplatePath}
+ * to the path (in namespace format) storing your own templates.
+ *
+ * There are two sets of templates, one for errors to be displayed to client users
+ * (called external errors), one for errors to be displayed to system developers
+ * (called internal errors). The template file name for the former is
+ * <b>error[StatusCode][-LanguageCode].html</b>, and for the latter it is
+ * <b>exception[-LanguageCode].html</b>, where StatusCode refers to response status
+ * code (e.g. 404, 500) specified when {@link THttpException} is thrown,
+ * and LanguageCode is the client user preferred language code (e.g. en, zh, de).
+ * The templates <b>error.html</b> and <b>exception.html</b> are default ones
+ * that are used if no other appropriate templates are available.
+ * Note, these templates are not Prado control templates. They are simply
+ * html files with keywords (e.g. %%ErrorMessage%%, %%Version%%)
+ * to be replaced with the corresponding information.
+ *
+ * By default, TErrorHandler is registered with {@link TApplication} as the
+ * error handler module. It can be accessed via {@link TApplication::getErrorHandler()}.
+ * You seldom need to deal with the error handler directly. It is mainly used
+ * by the application object to handle errors.
+ *
+ * TErrorHandler may be configured in application configuration file as follows
+ * <module id="error" class="TErrorHandler" ErrorTemplatePath="System.Exceptions" />
+ *
+ * @author Qiang Xue <qiang.xue@gmail.com>
+ * @version $Id$
+ * @package System.Exceptions
+ * @since 3.0
+ */
+class TErrorHandler extends TModule
+{
+ /**
+ * error template file basename
+ */
+ const ERROR_FILE_NAME='error';
+ /**
+ * exception template file basename
+ */
+ const EXCEPTION_FILE_NAME='exception';
+ /**
+ * number of lines before and after the error line to be displayed in case of an exception
+ */
+ const SOURCE_LINES=12;
+
+ /**
+ * @var string error template directory
+ */
+ private $_templatePath=null;
+
+ /**
+ * Initializes the module.
+ * This method is required by IModule and is invoked by application.
+ * @param TXmlElement module configuration
+ */
+ public function init($config)
+ {
+ $this->getApplication()->setErrorHandler($this);
+ }
+
+ /**
+ * @return string the directory containing error template files.
+ */
+ public function getErrorTemplatePath()
+ {
+ if($this->_templatePath===null)
+ $this->_templatePath=Prado::getFrameworkPath().'/Exceptions/templates';
+ return $this->_templatePath;
+ }
+
+ /**
+ * Sets the path storing all error and exception template files.
+ * The path must be in namespace format, such as System.Exceptions (which is the default).
+ * @param string template path in namespace format
+ * @throws TConfigurationException if the template path is invalid
+ */
+ public function setErrorTemplatePath($value)
+ {
+ if(($templatePath=Prado::getPathOfNamespace($value))!==null && is_dir($templatePath))
+ $this->_templatePath=$templatePath;
+ else
+ throw new TConfigurationException('errorhandler_errortemplatepath_invalid',$value);
+ }
+
+ /**
+ * Handles PHP user errors and exceptions.
+ * This is the event handler responding to the <b>Error</b> event
+ * raised in {@link TApplication}.
+ * The method mainly uses appropriate template to display the error/exception.
+ * It terminates the application immediately after the error is displayed.
+ * @param mixed sender of the event
+ * @param mixed event parameter (if the event is raised by TApplication, it refers to the exception instance)
+ */
+ public function handleError($sender,$param)
+ {
+ static $handling=false;
+ // We need to restore error and exception handlers,
+ // because within error and exception handlers, new errors and exceptions
+ // cannot be handled properly by PHP
+ restore_error_handler();
+ restore_exception_handler();
+ // ensure that we do not enter infinite loop of error handling
+ if($handling)
+ $this->handleRecursiveError($param);
+ else
+ {
+ $handling=true;
+ if(($response=$this->getResponse())!==null)
+ $response->clear();
+ if(!headers_sent())
+ header('Content-Type: text/html; charset=UTF-8');
+ if($param instanceof THttpException)
+ $this->handleExternalError($param->getStatusCode(),$param);
+ else if($this->getApplication()->getMode()===TApplicationMode::Debug)
+ $this->displayException($param);
+ else
+ $this->handleExternalError(500,$param);
+ }
+ }
+
+
+ /**
+ * @param string $value
+ * @param Exception|null$exception
+ * @return string
+ * @since 3.1.6
+ */
+ protected static function hideSecurityRelated($value, $exception=null)
+ {
+ $aRpl = array();
+ if($exception !== null && $exception instanceof Exception)
+ {
+ $aTrace = $exception->getTrace();
+ foreach($aTrace as $item)
+ {
+ if(isset($item['file']))
+ $aRpl[dirname($item['file']) . DIRECTORY_SEPARATOR] = '<hidden>' . DIRECTORY_SEPARATOR;
+ }
+ }
+ $aRpl[$_SERVER['DOCUMENT_ROOT']] = '${DocumentRoot}';
+ $aRpl[str_replace('/', DIRECTORY_SEPARATOR, $_SERVER['DOCUMENT_ROOT'])] = '${DocumentRoot}';
+ $aRpl[PRADO_DIR . DIRECTORY_SEPARATOR] = '${PradoFramework}' . DIRECTORY_SEPARATOR;
+ if(isset($aRpl[DIRECTORY_SEPARATOR])) unset($aRpl[DIRECTORY_SEPARATOR]);
+ $aRpl = array_reverse($aRpl, true);
+
+ return str_replace(array_keys($aRpl), $aRpl, $value);
+ }
+
+ /**
+ * Displays error to the client user.
+ * THttpException and errors happened when the application is in <b>Debug</b>
+ * mode will be displayed to the client user.
+ * @param integer response status code
+ * @param Exception exception instance
+ */
+ protected function handleExternalError($statusCode,$exception)
+ {
+ if(!($exception instanceof THttpException))
+ error_log($exception->__toString());
+
+ $content=$this->getErrorTemplate($statusCode,$exception);
+
+ $serverAdmin=isset($_SERVER['SERVER_ADMIN'])?$_SERVER['SERVER_ADMIN']:'';
+
+ $isDebug = $this->getApplication()->getMode()===TApplicationMode::Debug;
+
+ $errorMessage = $exception->getMessage();
+ if($isDebug)
+ $version=$_SERVER['SERVER_SOFTWARE'].' <a href="http://www.pradosoft.com/">PRADO</a>/'.Prado::getVersion();
+ else
+ {
+ $version='';
+ $errorMessage = self::hideSecurityRelated($errorMessage, $exception);
+ }
+ $tokens=array(
+ '%%StatusCode%%' => "$statusCode",
+ '%%ErrorMessage%%' => htmlspecialchars($errorMessage),
+ '%%ServerAdmin%%' => $serverAdmin,
+ '%%Version%%' => $version,
+ '%%Time%%' => @strftime('%Y-%m-%d %H:%M',time())
+ );
+
+ $CGI=substr(php_sapi_name(), 0, 3) == 'cgi'; // FastCGI / IIS
+ if($isDebug)
+ {
+ if ($CGI)
+ header("Status: $statusCode ".$exception->getMessage(), true, TPropertyValue::ensureInteger($statusCode));
+ else
+ header("HTTP/1.0 $statusCode ".$exception->getMessage(), true, TPropertyValue::ensureInteger($statusCode));
+ } else {
+ if ($CGI)
+ header("Status: $statusCode", true, TPropertyValue::ensureInteger($statusCode));
+ else
+ header("HTTP/1.0 $statusCode", true, TPropertyValue::ensureInteger($statusCode));
+ }
+
+ echo strtr($content,$tokens);
+ }
+
+ /**
+ * Handles error occurs during error handling (called recursive error).
+ * THttpException and errors happened when the application is in <b>Debug</b>
+ * mode will be displayed to the client user.
+ * Error is displayed without using existing template to prevent further errors.
+ * @param Exception exception instance
+ */
+ protected function handleRecursiveError($exception)
+ {
+ if($this->getApplication()->getMode()===TApplicationMode::Debug)
+ {
+ echo "<html><head><title>Recursive Error</title></head>\n";
+ echo "<body><h1>Recursive Error</h1>\n";
+ echo "<pre>".$exception->__toString()."</pre>\n";
+ echo "</body></html>";
+ }
+ else
+ {
+ error_log("Error happened while processing an existing error:\n".$exception->__toString());
+ header('HTTP/1.0 500 Internal Error');
+ }
+ }
+
+ /**
+ * Displays exception information.
+ * Exceptions are displayed with rich context information, including
+ * the call stack and the context source code.
+ * This method is only invoked when application is in <b>Debug</b> mode.
+ * @param Exception exception instance
+ */
+ protected function displayException($exception)
+ {
+ if(php_sapi_name()==='cli')
+ {
+ echo $exception->getMessage()."\n";
+ echo $exception->getTraceAsString();
+ return;
+ }
+
+ if($exception instanceof TTemplateException)
+ {
+ $fileName=$exception->getTemplateFile();
+ $lines=empty($fileName)?explode("\n",$exception->getTemplateSource()):@file($fileName);
+ $source=$this->getSourceCode($lines,$exception->getLineNumber());
+ if($fileName==='')
+ $fileName='---embedded template---';
+ $errorLine=$exception->getLineNumber();
+ }
+ else
+ {
+ if(($trace=$this->getExactTrace($exception))!==null)
+ {
+ $fileName=$trace['file'];
+ $errorLine=$trace['line'];
+ }
+ else
+ {
+ $fileName=$exception->getFile();
+ $errorLine=$exception->getLine();
+ }
+ $source=$this->getSourceCode(@file($fileName),$errorLine);
+ }
+
+ if($this->getApplication()->getMode()===TApplicationMode::Debug)
+ $version=$_SERVER['SERVER_SOFTWARE'].' <a href="http://www.pradosoft.com/">PRADO</a>/'.Prado::getVersion();
+ else
+ $version='';
+
+ $tokens=array(
+ '%%ErrorType%%' => get_class($exception),
+ '%%ErrorMessage%%' => $this->addLink(htmlspecialchars($exception->getMessage())),
+ '%%SourceFile%%' => htmlspecialchars($fileName).' ('.$errorLine.')',
+ '%%SourceCode%%' => $source,
+ '%%StackTrace%%' => htmlspecialchars($exception->getTraceAsString()),
+ '%%Version%%' => $version,
+ '%%Time%%' => @strftime('%Y-%m-%d %H:%M',time())
+ );
+
+ $content=$this->getExceptionTemplate($exception);
+
+ echo strtr($content,$tokens);
+ }
+
+ /**
+ * Retrieves the template used for displaying internal exceptions.
+ * Internal exceptions will be displayed with source code causing the exception.
+ * This occurs when the application is in debug mode.
+ * @param Exception the exception to be displayed
+ * @return string the template content
+ */
+ protected function getExceptionTemplate($exception)
+ {
+ $lang=Prado::getPreferredLanguage();
+ $exceptionFile=Prado::getFrameworkPath().'/Exceptions/templates/'.self::EXCEPTION_FILE_NAME.'-'.$lang.'.html';
+ if(!is_file($exceptionFile))
+ $exceptionFile=Prado::getFrameworkPath().'/Exceptions/templates/'.self::EXCEPTION_FILE_NAME.'.html';
+ if(($content=@file_get_contents($exceptionFile))===false)
+ die("Unable to open exception template file '$exceptionFile'.");
+ return $content;
+ }
+
+ /**
+ * Retrieves the template used for displaying external exceptions.
+ * External exceptions are those displayed to end-users. They do not contain
+ * error source code. Therefore, you might want to override this method
+ * to provide your own error template for displaying certain external exceptions.
+ * The following tokens in the template will be replaced with corresponding content:
+ * %%StatusCode%% : the status code of the exception
+ * %%ErrorMessage%% : the error message (HTML encoded).
+ * %%ServerAdmin%% : the server admin information (retrieved from Web server configuration)
+ * %%Version%% : the version information of the Web server.
+ * %%Time%% : the time the exception occurs at
+ *
+ * @param integer status code (such as 404, 500, etc.)
+ * @param Exception the exception to be displayed
+ * @return string the template content
+ */
+ protected function getErrorTemplate($statusCode,$exception)
+ {
+ $base=$this->getErrorTemplatePath().DIRECTORY_SEPARATOR.self::ERROR_FILE_NAME;
+ $lang=Prado::getPreferredLanguage();
+ if(is_file("$base$statusCode-$lang.html"))
+ $errorFile="$base$statusCode-$lang.html";
+ else if(is_file("$base$statusCode.html"))
+ $errorFile="$base$statusCode.html";
+ else if(is_file("$base-$lang.html"))
+ $errorFile="$base-$lang.html";
+ else
+ $errorFile="$base.html";
+ if(($content=@file_get_contents($errorFile))===false)
+ die("Unable to open error template file '$errorFile'.");
+ return $content;
+ }
+
+ private function getExactTrace($exception)
+ {
+ $trace=$exception->getTrace();
+ $result=null;
+ // if PHP exception, we want to show the 2nd stack level context
+ // because the 1st stack level is of little use (it's in error handler)
+ if($exception instanceof TPhpErrorException)
+ $result=isset($trace[0]['file'])?$trace[0]:$trace[1];
+ else if($exception instanceof TInvalidOperationException)
+ {
+ // in case of getter or setter error, find out the exact file and row
+ if(($result=$this->getPropertyAccessTrace($trace,'__get'))===null)
+ $result=$this->getPropertyAccessTrace($trace,'__set');
+ }
+ if($result!==null && strpos($result['file'],': eval()\'d code')!==false)
+ return null;
+
+ return $result;
+ }
+
+ private function getPropertyAccessTrace($trace,$pattern)
+ {
+ $result=null;
+ foreach($trace as $t)
+ {
+ if(isset($t['function']) && $t['function']===$pattern)
+ $result=$t;
+ else
+ break;
+ }
+ return $result;
+ }
+
+ private function getSourceCode($lines,$errorLine)
+ {
+ $beginLine=$errorLine-self::SOURCE_LINES>=0?$errorLine-self::SOURCE_LINES:0;
+ $endLine=$errorLine+self::SOURCE_LINES<=count($lines)?$errorLine+self::SOURCE_LINES:count($lines);
+
+ $source='';
+ for($i=$beginLine;$i<$endLine;++$i)
+ {
+ if($i===$errorLine-1)
+ {
+ $line=htmlspecialchars(sprintf("%04d: %s",$i+1,str_replace("\t",' ',$lines[$i])));
+ $source.="<div class=\"error\">".$line."</div>";
+ }
+ else
+ $source.=htmlspecialchars(sprintf("%04d: %s",$i+1,str_replace("\t",' ',$lines[$i])));
+ }
+ return $source;
+ }
+
+ private function addLink($message)
+ {
+ $baseUrl='http://www.pradosoft.com/docs/classdoc';
+ return preg_replace('/\b(T[A-Z]\w+)\b/',"<a href=\"$baseUrl/\${1}\" target=\"_blank\">\${1}</a>",$message);
+ }
+}
+
diff --git a/framework/Exceptions/TException.php b/framework/Exceptions/TException.php
index 5e266e17..c9f9d530 100644
--- a/framework/Exceptions/TException.php
+++ b/framework/Exceptions/TException.php
@@ -1,424 +1,424 @@
-<?php
-/**
- * Exception classes file
- *
- * @author Qiang Xue <qiang.xue@gmail.com>
- * @link http://www.pradosoft.com/
+<?php
+/**
+ * Exception classes file
+ *
+ * @author Qiang Xue <qiang.xue@gmail.com>
+ * @link http://www.pradosoft.com/
* @copyright Copyright &copy; 2005-2012 PradoSoft
- * @license http://www.pradosoft.com/license/
- * @version $Id$
- * @package System.Exceptions
- */
-
-/**
- * TException class
- *
- * TException is the base class for all PRADO exceptions.
- *
- * TException provides the functionality of translating an error code
- * into a descriptive error message in a language that is preferred
- * by user browser. Additional parameters may be passed together with
- * the error code so that the translated message contains more detailed
- * information.
- *
- * By default, TException looks for a message file by calling
- * {@link getErrorMessageFile()} method, which uses the "message-xx.txt"
- * file located under "System.Exceptions" folder, where "xx" is the
- * code of the user preferred language. If such a file is not found,
- * "message.txt" will be used instead.
- *
- * @author Qiang Xue <qiang.xue@gmail.com>
- * @version $Id$
- * @package System.Exceptions
- * @since 3.0
- */
-class TException extends Exception
-{
- private $_errorCode='';
+ * @license http://www.pradosoft.com/license/
+ * @version $Id$
+ * @package System.Exceptions
+ */
+
+/**
+ * TException class
+ *
+ * TException is the base class for all PRADO exceptions.
+ *
+ * TException provides the functionality of translating an error code
+ * into a descriptive error message in a language that is preferred
+ * by user browser. Additional parameters may be passed together with
+ * the error code so that the translated message contains more detailed
+ * information.
+ *
+ * By default, TException looks for a message file by calling
+ * {@link getErrorMessageFile()} method, which uses the "message-xx.txt"
+ * file located under "System.Exceptions" folder, where "xx" is the
+ * code of the user preferred language. If such a file is not found,
+ * "message.txt" will be used instead.
+ *
+ * @author Qiang Xue <qiang.xue@gmail.com>
+ * @version $Id$
+ * @package System.Exceptions
+ * @since 3.0
+ */
+class TException extends Exception
+{
+ private $_errorCode='';
static $_messageCache=array();
-
- /**
- * Constructor.
- * @param string error message. This can be a string that is listed
- * in the message file. If so, the message in the preferred language
- * will be used as the error message. Any rest parameters will be used
- * to replace placeholders ({0}, {1}, {2}, etc.) in the message.
- */
- public function __construct($errorMessage)
- {
- $this->_errorCode=$errorMessage;
- $errorMessage=$this->translateErrorMessage($errorMessage);
- $args=func_get_args();
- array_shift($args);
- $n=count($args);
- $tokens=array();
- for($i=0;$i<$n;++$i)
- $tokens['{'.$i.'}']=TPropertyValue::ensureString($args[$i]);
- parent::__construct(strtr($errorMessage,$tokens));
- }
-
- /**
- * Translates an error code into an error message.
- * @param string error code that is passed in the exception constructor.
- * @return string the translated error message
- */
- protected function translateErrorMessage($key)
- {
- $msgFile=$this->getErrorMessageFile();
+
+ /**
+ * Constructor.
+ * @param string error message. This can be a string that is listed
+ * in the message file. If so, the message in the preferred language
+ * will be used as the error message. Any rest parameters will be used
+ * to replace placeholders ({0}, {1}, {2}, etc.) in the message.
+ */
+ public function __construct($errorMessage)
+ {
+ $this->_errorCode=$errorMessage;
+ $errorMessage=$this->translateErrorMessage($errorMessage);
+ $args=func_get_args();
+ array_shift($args);
+ $n=count($args);
+ $tokens=array();
+ for($i=0;$i<$n;++$i)
+ $tokens['{'.$i.'}']=TPropertyValue::ensureString($args[$i]);
+ parent::__construct(strtr($errorMessage,$tokens));
+ }
+
+ /**
+ * Translates an error code into an error message.
+ * @param string error code that is passed in the exception constructor.
+ * @return string the translated error message
+ */
+ protected function translateErrorMessage($key)
+ {
+ $msgFile=$this->getErrorMessageFile();
// Cache messages
if (!isset(self::$_messageCache[$msgFile]))
{
- if(($entries=@file($msgFile))!==false)
- {
- foreach($entries as $entry)
- {
- @list($code,$message)=explode('=',$entry,2);
+ if(($entries=@file($msgFile))!==false)
+ {
+ foreach($entries as $entry)
+ {
+ @list($code,$message)=explode('=',$entry,2);
self::$_messageCache[$msgFile][trim($code)]=trim($message);
- }
- }
+ }
+ }
}
- return isset(self::$_messageCache[$msgFile][$key]) ? self::$_messageCache[$msgFile][$key] : $key;
- }
-
- /**
- * @return string path to the error message file
- */
- protected function getErrorMessageFile()
- {
- $lang=Prado::getPreferredLanguage();
- $msgFile=Prado::getFrameworkPath().'/Exceptions/messages/messages-'.$lang.'.txt';
- if(!is_file($msgFile))
- $msgFile=Prado::getFrameworkPath().'/Exceptions/messages/messages.txt';
- return $msgFile;
- }
-
- /**
- * @return string error code
- */
- public function getErrorCode()
- {
- return $this->_errorCode;
- }
-
- /**
- * @param string error code
- */
- public function setErrorCode($code)
- {
- $this->_errorCode=$code;
- }
-
- /**
- * @return string error message
- */
- public function getErrorMessage()
- {
- return $this->getMessage();
- }
-
- /**
- * @param string error message
- */
- protected function setErrorMessage($message)
- {
- $this->message=$message;
- }
-}
-
-/**
- * TSystemException class
- *
- * TSystemException is the base class for all framework-level exceptions.
- *
- * @author Qiang Xue <qiang.xue@gmail.com>
- * @version $Id$
- * @package System.Exceptions
- * @since 3.0
- */
-class TSystemException extends TException
-{
-}
-
-/**
- * TApplicationException class
- *
- * TApplicationException is the base class for all user application-level exceptions.
- *
- * @author Qiang Xue <qiang.xue@gmail.com>
- * @version $Id$
- * @package System.Exceptions
- * @since 3.0
- */
-class TApplicationException extends TException
-{
-}
-
-/**
- * TInvalidOperationException class
- *
- * TInvalidOperationException represents an exception caused by invalid operations.
- *
- * @author Qiang Xue <qiang.xue@gmail.com>
- * @version $Id$
- * @package System.Exceptions
- * @since 3.0
- */
-class TInvalidOperationException extends TSystemException
-{
-}
-
-/**
- * TInvalidDataTypeException class
- *
- * TInvalidDataTypeException represents an exception caused by invalid data type.
- *
- * @author Qiang Xue <qiang.xue@gmail.com>
- * @version $Id$
- * @package System.Exceptions
- * @since 3.0
- */
-class TInvalidDataTypeException extends TSystemException
-{
-}
-
-/**
- * TInvalidDataValueException class
- *
- * TInvalidDataValueException represents an exception caused by invalid data value.
- *
- * @author Qiang Xue <qiang.xue@gmail.com>
- * @version $Id$
- * @package System.Exceptions
- * @since 3.0
- */
-class TInvalidDataValueException extends TSystemException
-{
-}
-
-/**
- * TConfigurationException class
- *
- * TConfigurationException represents an exception caused by invalid configurations,
- * such as error in an application configuration file or control template file.
- *
- * @author Qiang Xue <qiang.xue@gmail.com>
- * @version $Id$
- * @package System.Exceptions
- * @since 3.0
- */
-class TConfigurationException extends TSystemException
-{
-}
-
-/**
- * TTemplateException class
- *
- * TTemplateException represents an exception caused by invalid template syntax.
- *
- * @author Qiang Xue <qiang.xue@gmail.com>
- * @version $Id$
- * @package System.Exceptions
- * @since 3.1
- */
-class TTemplateException extends TConfigurationException
-{
- private $_template='';
- private $_lineNumber=0;
- private $_fileName='';
-
- /**
- * @return string the template source code that causes the exception. This is empty if {@link getTemplateFile TemplateFile} is not empty.
- */
- public function getTemplateSource()
- {
- return $this->_template;
- }
-
- /**
- * @param string the template source code that causes the exception
- */
- public function setTemplateSource($value)
- {
- $this->_template=$value;
- }
-
- /**
- * @return string the template file that causes the exception. This could be empty if the template is an embedded template. In this case, use {@link getTemplateSource TemplateSource} to obtain the actual template content.
- */
- public function getTemplateFile()
- {
- return $this->_fileName;
- }
-
- /**
- * @param string the template file that causes the exception
- */
- public function setTemplateFile($value)
- {
- $this->_fileName=$value;
- }
-
- /**
- * @return integer the line number at which the template has error
- */
- public function getLineNumber()
- {
- return $this->_lineNumber;
- }
-
- /**
- * @param integer the line number at which the template has error
- */
- public function setLineNumber($value)
- {
- $this->_lineNumber=TPropertyValue::ensureInteger($value);
- }
-}
-
-/**
- * TIOException class
- *
- * TIOException represents an exception related with improper IO operations.
- *
- * @author Qiang Xue <qiang.xue@gmail.com>
- * @version $Id$
- * @package System.Exceptions
- * @since 3.0
- */
-class TIOException extends TSystemException
-{
-}
-
-/**
- * TDbException class
- *
- * TDbException represents an exception related with DB operations.
- *
- * @author Qiang Xue <qiang.xue@gmail.com>
- * @version $Id$
- * @package System.Exceptions
- * @since 3.0
- */
-class TDbException extends TSystemException
-{
-}
-
-/**
- * TDbConnectionException class
- *
- * TDbConnectionException represents an exception caused by DB connection failure.
- *
- * @author Qiang Xue <qiang.xue@gmail.com>
- * @version $Id$
- * @package System.Exceptions
- * @since 3.0
- */
-class TDbConnectionException extends TDbException
-{
-}
-
-/**
- * TNotSupportedException class
- *
- * TNotSupportedException represents an exception caused by using an unsupported PRADO feature.
- *
- * @author Qiang Xue <qiang.xue@gmail.com>
- * @version $Id$
- * @package System.Exceptions
- * @since 3.0
- */
-class TNotSupportedException extends TSystemException
-{
-}
-
-/**
- * TPhpErrorException class
- *
- * TPhpErrorException represents an exception caused by a PHP error.
- * This exception is mainly thrown within a PHP error handler.
- *
- * @author Qiang Xue <qiang.xue@gmail.com>
- * @version $Id$
- * @package System.Exceptions
- * @since 3.0
- */
-class TPhpErrorException extends TSystemException
-{
- /**
- * Constructor.
- * @param integer error number
- * @param string error string
- * @param string error file
- * @param integer error line number
- */
- public function __construct($errno,$errstr,$errfile,$errline)
- {
- static $errorTypes=array(
- E_ERROR => "Error",
- E_WARNING => "Warning",
- E_PARSE => "Parsing Error",
- E_NOTICE => "Notice",
- E_CORE_ERROR => "Core Error",
- E_CORE_WARNING => "Core Warning",
- E_COMPILE_ERROR => "Compile Error",
- E_COMPILE_WARNING => "Compile Warning",
- E_USER_ERROR => "User Error",
- E_USER_WARNING => "User Warning",
- E_USER_NOTICE => "User Notice",
- E_STRICT => "Runtime Notice"
- );
- $errorType=isset($errorTypes[$errno])?$errorTypes[$errno]:'Unknown Error';
- parent::__construct("[$errorType] $errstr (@line $errline in file $errfile).");
- }
-}
-
-
-/**
- * THttpException class
- *
- * THttpException represents an exception that is caused by invalid operations
- * of end-users. The {@link getStatusCode StatusCode} gives the type of HTTP error.
- * It is used by {@link TErrorHandler} to provide different error output to users.
- *
- * @author Qiang Xue <qiang.xue@gmail.com>
- * @version $Id$
- * @package System.Exceptions
- * @since 3.0
- */
-class THttpException extends TSystemException
-{
- private $_statusCode;
-
- /**
- * Constructor.
- * @param integer HTTP status code, such as 404, 500, etc.
- * @param string error message. This can be a string that is listed
- * in the message file. If so, the message in the preferred language
- * will be used as the error message. Any rest parameters will be used
- * to replace placeholders ({0}, {1}, {2}, etc.) in the message.
- */
- public function __construct($statusCode,$errorMessage)
- {
- $this->_statusCode=$statusCode;
- $this->setErrorCode($errorMessage);
- $errorMessage=$this->translateErrorMessage($errorMessage);
- $args=func_get_args();
- array_shift($args);
- array_shift($args);
- $n=count($args);
- $tokens=array();
- for($i=0;$i<$n;++$i)
- $tokens['{'.$i.'}']=TPropertyValue::ensureString($args[$i]);
- parent::__construct(strtr($errorMessage,$tokens));
- }
-
- /**
- * @return integer HTTP status code, such as 404, 500, etc.
- */
- public function getStatusCode()
- {
- return $this->_statusCode;
- }
-}
-
+ return isset(self::$_messageCache[$msgFile][$key]) ? self::$_messageCache[$msgFile][$key] : $key;
+ }
+
+ /**
+ * @return string path to the error message file
+ */
+ protected function getErrorMessageFile()
+ {
+ $lang=Prado::getPreferredLanguage();
+ $msgFile=Prado::getFrameworkPath().'/Exceptions/messages/messages-'.$lang.'.txt';
+ if(!is_file($msgFile))
+ $msgFile=Prado::getFrameworkPath().'/Exceptions/messages/messages.txt';
+ return $msgFile;
+ }
+
+ /**
+ * @return string error code
+ */
+ public function getErrorCode()
+ {
+ return $this->_errorCode;
+ }
+
+ /**
+ * @param string error code
+ */
+ public function setErrorCode($code)
+ {
+ $this->_errorCode=$code;
+ }
+
+ /**
+ * @return string error message
+ */
+ public function getErrorMessage()
+ {
+ return $this->getMessage();
+ }
+
+ /**
+ * @param string error message
+ */
+ protected function setErrorMessage($message)
+ {
+ $this->message=$message;
+ }
+}
+
+/**
+ * TSystemException class
+ *
+ * TSystemException is the base class for all framework-level exceptions.
+ *
+ * @author Qiang Xue <qiang.xue@gmail.com>
+ * @version $Id$
+ * @package System.Exceptions
+ * @since 3.0
+ */
+class TSystemException extends TException
+{
+}
+
+/**
+ * TApplicationException class
+ *
+ * TApplicationException is the base class for all user application-level exceptions.
+ *
+ * @author Qiang Xue <qiang.xue@gmail.com>
+ * @version $Id$
+ * @package System.Exceptions
+ * @since 3.0
+ */
+class TApplicationException extends TException
+{
+}
+
+/**
+ * TInvalidOperationException class
+ *
+ * TInvalidOperationException represents an exception caused by invalid operations.
+ *
+ * @author Qiang Xue <qiang.xue@gmail.com>
+ * @version $Id$
+ * @package System.Exceptions
+ * @since 3.0
+ */
+class TInvalidOperationException extends TSystemException
+{
+}
+
+/**
+ * TInvalidDataTypeException class
+ *
+ * TInvalidDataTypeException represents an exception caused by invalid data type.
+ *
+ * @author Qiang Xue <qiang.xue@gmail.com>
+ * @version $Id$
+ * @package System.Exceptions
+ * @since 3.0
+ */
+class TInvalidDataTypeException extends TSystemException
+{
+}
+
+/**
+ * TInvalidDataValueException class
+ *
+ * TInvalidDataValueException represents an exception caused by invalid data value.
+ *
+ * @author Qiang Xue <qiang.xue@gmail.com>
+ * @version $Id$
+ * @package System.Exceptions
+ * @since 3.0
+ */
+class TInvalidDataValueException extends TSystemException
+{
+}
+
+/**
+ * TConfigurationException class
+ *
+ * TConfigurationException represents an exception caused by invalid configurations,
+ * such as error in an application configuration file or control template file.
+ *
+ * @author Qiang Xue <qiang.xue@gmail.com>
+ * @version $Id$
+ * @package System.Exceptions
+ * @since 3.0
+ */
+class TConfigurationException extends TSystemException
+{
+}
+
+/**
+ * TTemplateException class
+ *
+ * TTemplateException represents an exception caused by invalid template syntax.
+ *
+ * @author Qiang Xue <qiang.xue@gmail.com>
+ * @version $Id$
+ * @package System.Exceptions
+ * @since 3.1
+ */
+class TTemplateException extends TConfigurationException
+{
+ private $_template='';
+ private $_lineNumber=0;
+ private $_fileName='';
+
+ /**
+ * @return string the template source code that causes the exception. This is empty if {@link getTemplateFile TemplateFile} is not empty.
+ */
+ public function getTemplateSource()
+ {
+ return $this->_template;
+ }
+
+ /**
+ * @param string the template source code that causes the exception
+ */
+ public function setTemplateSource($value)
+ {
+ $this->_template=$value;
+ }
+
+ /**
+ * @return string the template file that causes the exception. This could be empty if the template is an embedded template. In this case, use {@link getTemplateSource TemplateSource} to obtain the actual template content.
+ */
+ public function getTemplateFile()
+ {
+ return $this->_fileName;
+ }
+
+ /**
+ * @param string the template file that causes the exception
+ */
+ public function setTemplateFile($value)
+ {
+ $this->_fileName=$value;
+ }
+
+ /**
+ * @return integer the line number at which the template has error
+ */
+ public function getLineNumber()
+ {
+ return $this->_lineNumber;
+ }
+
+ /**
+ * @param integer the line number at which the template has error
+ */
+ public function setLineNumber($value)
+ {
+ $this->_lineNumber=TPropertyValue::ensureInteger($value);
+ }
+}
+
+/**
+ * TIOException class
+ *
+ * TIOException represents an exception related with improper IO operations.
+ *
+ * @author Qiang Xue <qiang.xue@gmail.com>
+ * @version $Id$
+ * @package System.Exceptions
+ * @since 3.0
+ */
+class TIOException extends TSystemException
+{
+}
+
+/**
+ * TDbException class
+ *
+ * TDbException represents an exception related with DB operations.
+ *
+ * @author Qiang Xue <qiang.xue@gmail.com>
+ * @version $Id$
+ * @package System.Exceptions
+ * @since 3.0
+ */
+class TDbException extends TSystemException
+{
+}
+
+/**
+ * TDbConnectionException class
+ *
+ * TDbConnectionException represents an exception caused by DB connection failure.
+ *
+ * @author Qiang Xue <qiang.xue@gmail.com>
+ * @version $Id$
+ * @package System.Exceptions
+ * @since 3.0
+ */
+class TDbConnectionException extends TDbException
+{
+}
+
+/**
+ * TNotSupportedException class
+ *
+ * TNotSupportedException represents an exception caused by using an unsupported PRADO feature.
+ *
+ * @author Qiang Xue <qiang.xue@gmail.com>
+ * @version $Id$
+ * @package System.Exceptions
+ * @since 3.0
+ */
+class TNotSupportedException extends TSystemException
+{
+}
+
+/**
+ * TPhpErrorException class
+ *
+ * TPhpErrorException represents an exception caused by a PHP error.
+ * This exception is mainly thrown within a PHP error handler.
+ *
+ * @author Qiang Xue <qiang.xue@gmail.com>
+ * @version $Id$
+ * @package System.Exceptions
+ * @since 3.0
+ */
+class TPhpErrorException extends TSystemException
+{
+ /**
+ * Constructor.
+ * @param integer error number
+ * @param string error string
+ * @param string error file
+ * @param integer error line number
+ */
+ public function __construct($errno,$errstr,$errfile,$errline)
+ {
+ static $errorTypes=array(
+ E_ERROR => "Error",
+ E_WARNING => "Warning",
+ E_PARSE => "Parsing Error",
+ E_NOTICE => "Notice",
+ E_CORE_ERROR => "Core Error",
+ E_CORE_WARNING => "Core Warning",
+ E_COMPILE_ERROR => "Compile Error",
+ E_COMPILE_WARNING => "Compile Warning",
+ E_USER_ERROR => "User Error",
+ E_USER_WARNING => "User Warning",
+ E_USER_NOTICE => "User Notice",
+ E_STRICT => "Runtime Notice"
+ );
+ $errorType=isset($errorTypes[$errno])?$errorTypes[$errno]:'Unknown Error';
+ parent::__construct("[$errorType] $errstr (@line $errline in file $errfile).");
+ }
+}
+
+
+/**
+ * THttpException class
+ *
+ * THttpException represents an exception that is caused by invalid operations
+ * of end-users. The {@link getStatusCode StatusCode} gives the type of HTTP error.
+ * It is used by {@link TErrorHandler} to provide different error output to users.
+ *
+ * @author Qiang Xue <qiang.xue@gmail.com>
+ * @version $Id$
+ * @package System.Exceptions
+ * @since 3.0
+ */
+class THttpException extends TSystemException
+{
+ private $_statusCode;
+
+ /**
+ * Constructor.
+ * @param integer HTTP status code, such as 404, 500, etc.
+ * @param string error message. This can be a string that is listed
+ * in the message file. If so, the message in the preferred language
+ * will be used as the error message. Any rest parameters will be used
+ * to replace placeholders ({0}, {1}, {2}, etc.) in the message.
+ */
+ public function __construct($statusCode,$errorMessage)
+ {
+ $this->_statusCode=$statusCode;
+ $this->setErrorCode($errorMessage);
+ $errorMessage=$this->translateErrorMessage($errorMessage);
+ $args=func_get_args();
+ array_shift($args);
+ array_shift($args);
+ $n=count($args);
+ $tokens=array();
+ for($i=0;$i<$n;++$i)
+ $tokens['{'.$i.'}']=TPropertyValue::ensureString($args[$i]);
+ parent::__construct(strtr($errorMessage,$tokens));
+ }
+
+ /**
+ * @return integer HTTP status code, such as 404, 500, etc.
+ */
+ public function getStatusCode()
+ {
+ return $this->_statusCode;
+ }
+}
+
diff --git a/framework/I18N/TChoiceFormat.php b/framework/I18N/TChoiceFormat.php
index a1d7ad74..401b25d9 100644
--- a/framework/I18N/TChoiceFormat.php
+++ b/framework/I18N/TChoiceFormat.php
@@ -1,111 +1,111 @@
-<?php
-/**
- * TChoiceFormat, I18N choice format component.
- *
- * @author Wei Zhuo <weizhuo[at]gmail[dot]com>
- * @link http://www.pradosoft.com/
+<?php
+/**
+ * TChoiceFormat, I18N choice format component.
+ *
+ * @author Wei Zhuo <weizhuo[at]gmail[dot]com>
+ * @link http://www.pradosoft.com/
* @copyright Copyright &copy; 2005-2012 PradoSoft
- * @license http://www.pradosoft.com/license/
- * @version $Id$
- * @package System.I18N
- */
-
- /**
- * Get the ChoiceFormat class.
- */
-Prado::using('System.I18N.core.ChoiceFormat');
-Prado::using('System.I18N.TTranslate');
-
-/**
- * TChoiceFormat class.
- *
- * This component performs message/string choice translation. The translation
- * source is set in the TGlobalization module. The following example
- * demonstrates a simple 2 choice message translation.
- * <code>
- * <com:TChoiceFormat Value="1">[1] One Apple. |[2] Two Apples</com:TChoiceFormat>
- * </code>
- *
- * The Choice has <b>Value</b> "1" (one), thus the translated string
- * is "One Apple". If the <b>Value</b> is "2", then it will show
- * "Two Apples".
- *
- * The message/string choices are separated by the pipe "|" followed
- * by a set notation of the form
- * # <tt>[1,2]</tt> -- accepts values between 1 and 2, inclusive.
- * # <tt>(1,2)</tt> -- accepts values between 1 and 2, excluding 1 and 2.
- * # <tt>{1,2,3,4}</tt> -- only values defined in the set are accepted.
- * # <tt>[-Inf,0)</tt> -- accepts value greater or equal to negative infinity
- * and strictly less than 0
- * Any non-empty combinations of the delimiters of square and round brackets
- * are acceptable.
- *
- * The string choosen for display depends on the <b>Value</b> property.
- * The <b>Value</b> is evaluated for each set until the Value is found
- * to belong to a particular set.
- *
- * Properties
- * - <b>Value</b>, float,
- * <br>Gets or sets the Value that determines which string choice to display.
- * Since version 3.1.2 the following set notation is also possible.
- *
- * # <tt>{n: n % 10 > 1 && n % 10 < 5}</tt> -- matches numbers like 2, 3, 4, 22, 23, 24
- *
- * Where set is defined by the expression after <tt>n:</tt>. In particular, the expression
- * accepts the following mathematical/logical operators to form a set of logical conditions
- * on the value given by <tt>n</tt>:
- * # <tt>&lt;</tt> -- less than.
- * # <tt>&lt;=</tt> -- less than equals.
- * # <tt>&gt;</tt> -- greater than.
- * # <tt>&gt=</tt> -- greater than equals.
- * # <tt>==</tt> -- of equal value.
- * # <tt>%</tt> -- modulo, e.g., 1 % 10 equals 1, 11 % 10 equals 1.
- * # <tt>-</tt> -- minus, negative.
- * # <tt>+</tt> -- addition.
- * # <tt>&amp;</tt> -- conditional AND.
- * # <tt>&amp;&amp;</tt> -- condition AND with short circuit.
- * # <tt>|</tt> -- conditional OR.
- * # <tt>||</tt> -- conditional OR with short circuit.
- * # <tt>!</tt> -- negation.
- *
- * Additional round brackets can also be used to perform grouping.
- *
- * @author Xiang Wei Zhuo <weizhuo[at]gmail[dot]com>
- * @version v1.0, last update on Fri Dec 24 21:38:49 EST 2004
- * @package System.I18N
- */
-class TChoiceFormat extends TTranslate
-{
- /**
- * @return float the numerical value.
- */
- public function getValue()
- {
- return $this->getViewState('Value','');
- }
-
- /**
- * Sets the numerical choice value
- * @param float the choice value
- */
- public function setValue($value)
- {
- $this->setViewState('Value',$value,'');
- }
-
- /**
- * Display the choosen translated string.
- * Overrides the parent method, also calls parent's renderBody to
- * translate.
- */
- protected function translateText($text, $subs)
- {
- $text = parent::translateText($text, $subs);
- $choice = new ChoiceFormat();
- $value = $this->getValue();
- $string = $choice->format($text, $value);
- if($string)
- return strtr($string, array('{Value}'=> $value));
- }
-}
-?>
+ * @license http://www.pradosoft.com/license/
+ * @version $Id$
+ * @package System.I18N
+ */
+
+ /**
+ * Get the ChoiceFormat class.
+ */
+Prado::using('System.I18N.core.ChoiceFormat');
+Prado::using('System.I18N.TTranslate');
+
+/**
+ * TChoiceFormat class.
+ *
+ * This component performs message/string choice translation. The translation
+ * source is set in the TGlobalization module. The following example
+ * demonstrates a simple 2 choice message translation.
+ * <code>
+ * <com:TChoiceFormat Value="1">[1] One Apple. |[2] Two Apples</com:TChoiceFormat>
+ * </code>
+ *
+ * The Choice has <b>Value</b> "1" (one), thus the translated string
+ * is "One Apple". If the <b>Value</b> is "2", then it will show
+ * "Two Apples".
+ *
+ * The message/string choices are separated by the pipe "|" followed
+ * by a set notation of the form
+ * # <tt>[1,2]</tt> -- accepts values between 1 and 2, inclusive.
+ * # <tt>(1,2)</tt> -- accepts values between 1 and 2, excluding 1 and 2.
+ * # <tt>{1,2,3,4}</tt> -- only values defined in the set are accepted.
+ * # <tt>[-Inf,0)</tt> -- accepts value greater or equal to negative infinity
+ * and strictly less than 0
+ * Any non-empty combinations of the delimiters of square and round brackets
+ * are acceptable.
+ *
+ * The string choosen for display depends on the <b>Value</b> property.
+ * The <b>Value</b> is evaluated for each set until the Value is found
+ * to belong to a particular set.
+ *
+ * Properties
+ * - <b>Value</b>, float,
+ * <br>Gets or sets the Value that determines which string choice to display.
+ * Since version 3.1.2 the following set notation is also possible.
+ *
+ * # <tt>{n: n % 10 > 1 && n % 10 < 5}</tt> -- matches numbers like 2, 3, 4, 22, 23, 24
+ *
+ * Where set is defined by the expression after <tt>n:</tt>. In particular, the expression
+ * accepts the following mathematical/logical operators to form a set of logical conditions
+ * on the value given by <tt>n</tt>:
+ * # <tt>&lt;</tt> -- less than.
+ * # <tt>&lt;=</tt> -- less than equals.
+ * # <tt>&gt;</tt> -- greater than.
+ * # <tt>&gt=</tt> -- greater than equals.
+ * # <tt>==</tt> -- of equal value.
+ * # <tt>%</tt> -- modulo, e.g., 1 % 10 equals 1, 11 % 10 equals 1.
+ * # <tt>-</tt> -- minus, negative.
+ * # <tt>+</tt> -- addition.
+ * # <tt>&amp;</tt> -- conditional AND.
+ * # <tt>&amp;&amp;</tt> -- condition AND with short circuit.
+ * # <tt>|</tt> -- conditional OR.
+ * # <tt>||</tt> -- conditional OR with short circuit.
+ * # <tt>!</tt> -- negation.
+ *
+ * Additional round brackets can also be used to perform grouping.
+ *
+ * @author Xiang Wei Zhuo <weizhuo[at]gmail[dot]com>
+ * @version v1.0, last update on Fri Dec 24 21:38:49 EST 2004
+ * @package System.I18N
+ */
+class TChoiceFormat extends TTranslate
+{
+ /**
+ * @return float the numerical value.
+ */
+ public function getValue()
+ {
+ return $this->getViewState('Value','');
+ }
+
+ /**
+ * Sets the numerical choice value
+ * @param float the choice value
+ */
+ public function setValue($value)
+ {
+ $this->setViewState('Value',$value,'');
+ }
+
+ /**
+ * Display the choosen translated string.
+ * Overrides the parent method, also calls parent's renderBody to
+ * translate.
+ */
+ protected function translateText($text, $subs)
+ {
+ $text = parent::translateText($text, $subs);
+ $choice = new ChoiceFormat();
+ $value = $this->getValue();
+ $string = $choice->format($text, $value);
+ if($string)
+ return strtr($string, array('{Value}'=> $value));
+ }
+}
+?>
diff --git a/framework/I18N/TDateFormat.php b/framework/I18N/TDateFormat.php
index 831fe71d..7604dd44 100644
--- a/framework/I18N/TDateFormat.php
+++ b/framework/I18N/TDateFormat.php
@@ -1,254 +1,254 @@
-<?php
-/**
- * TDateFromat formatting component.
- *
- * @author Wei Zhuo <weizhuo[at]gmail[dot]com>
- * @link http://www.pradosoft.com/
- * @copyright Copyright &copy; 2005-2012 PradoSoft
- * @license http://www.pradosoft.com/license/
- * @version $Id$
- * @package System.I18N
- */
-
-/**
- * Get the DateFormat class.
- */
-Prado::using('System.I18N.core.DateFormat');
-
-/**
- * Get the parent control class.
- */
-Prado::using('System.I18N.TI18NControl');
-
-/**
- * To format dates and/or time according to the current locale use
- * <code>
- * <com:TDateFormat Pattern="dd:MMM:yyyy" Value="01/01/2001" />
- *</code>
- * The date will be formatted according to the current locale (or culture)
- * using the format specified by 'Pattern' attribute.
- *
- * To format date and/or time for a locale (e.g. de_DE) include a Culture
- * attribute, for example:
- * <code>
- * <com:TDateFormat Culture="de_DE" Value="01/01/2001 12:00" />
- * </code>
- * The date will be formatted according to this format.
- *
- * If no Pattern was specified then the date will be formatted with the
- * default format (both date and time). If no value for the date is specified
- * then the current date will be used. E.g.: <code><com:TDateFormat /></code>
- * will result in the current date, formatted with default localized pattern.
- *
- * Namespace: System.I18N
- *
- * Properties
- * - <b>Value</b>, date,
- * <br>Gets or sets the date to format. The tag content is used as Value
- * if the Value property is not specified.
- * - <b>Pattern</b>, string,
- * <br>Gets or sets the formatting pattern. The predefined patterns are
- * 'fulldate', 'longdate', 'mediumdate', 'shortdate', 'fulltime',
- * 'longtime', 'mediumtime', and 'shorttime'. Custom patterns can specified
- * when the Pattern property does not match the predefined patterns.
- * - <b>DefaultText</b>, string,
- * <br>Gets or sets the default text. If Value is not set, DefaultText will be
- * shown instead of todays date and time.
- *
- * @author Xiang Wei Zhuo <weizhuo[at]gmail[dot]com>
- * @version v1.0, last update on Sat Dec 11 15:25:11 EST 2004
- * @package System.I18N
- */
-class TDateFormat extends TI18NControl implements IDataRenderer
-{
- /**
- * Default DateFormat, set to the application culture.
- * @var DateFormat
- */
- protected static $formatter;
-
- /**
- * A set of pattern presets and their respective formatting shorthand.
- * @var array
- */
- static private $_patternPresets = array(
- 'fulldate'=>'P','full'=>'P',
- 'longdate'=>'D','long'=>'d',
- 'mediumdate'=>'p','medium'=>'p',
- 'shortdate'=>'d','short'=>'d',
- 'fulltime'=>'Q', 'longtime'=>'T',
- 'mediumtime'=>'q', 'shorttime'=>'t');
-
- /**
- * Sets the date time formatting pattern.
- * @param string format pattern.
- */
- public function setPattern($value)
- {
- $this->setViewState('Pattern',$value,'');
- }
-
- /**
- * Gets the date time format pattern.
- * @return string format pattern.
- */
- public function getPattern()
- {
- $string = $this->getViewState('Pattern','');
-
- $pattern = null;
-
- //try the subpattern of "date time" presets
- $subpatterns = explode(' ',$string,2);
- $datetime = array();
- if(count($subpatterns)==2)
- {
- $datetime[] = $this->getPreset($subpatterns[0]);
- $datetime[] = $this->getPreset($subpatterns[1]);
- }
-
- //we have a good subpattern
- if(count($datetime) == 2
- && strlen($datetime[0]) == 1
- && strlen($datetime[1]) == 1)
- {
- $pattern = $datetime;
- }
- else //no subpattern, try the presets
- $pattern = $this->getPreset($string);
-
- //no presets found, use the string as the pattern
- //and let the DateFormat handle it.
- if($pattern===null)
- $pattern = $string;
- if (!is_array($pattern) && strlen($pattern) == 0)
- $pattern = null;
- return $pattern;
- }
-
- /**
- * For a given string, try and find a preset pattern.
- * @param string the preset pattern name
- * @return string a preset pattern if found, null otherwise.
- */
- protected function getPreset($string)
- {
- $string = strtolower($string);
- foreach(self::$_patternPresets as $pattern => $preset)
- {
- if($string == $pattern)
- return $preset;
- }
- }
-
- /**
- * Get the date-time value for this control.
- * @return string date time value.
- */
- public function getValue()
- {
- $value = $this->getViewState('Value','');
- if(empty($value))
- {
- $defaultText = $this->getDefaultText();
- if(empty($defaultText))
- return time();
- }
- return $value;
- }
-
- /**
- * Set the date-time value for this control.
- * @param string the date-time value.
- */
- public function setValue($value)
- {
- $this->setViewState('Value',$value,'');
- }
-
- /**
- * Get the default text value for this control.
- * @return string default text value
- */
- public function getDefaultText()
- {
- return $this->getViewState('DefaultText','');
- }
-
- /**
- * Set the default text value for this control.
- * @param string default text value
- */
- public function setDefaultText($value)
- {
- $this->setViewState('DefaultText',$value,'');
- }
-
- /**
- * Get the date-time value for this control.
- * This method is required by {@link IDataRenderer}.
- * It is the same as {@link getValue()}.
- * @return string date time value.
- * @see getValue
- * @since 3.1.2
- */
- public function getData()
- {
- return $this->getValue();
- }
-
- /**
- * Set the date-time value for this control.
- * This method is required by {@link IDataRenderer}.
- * It is the same as {@link setValue()}.
- * @param string the date-time value.
- * @see setValue
- * @since 3.1.2
- */
- public function setData($value)
- {
- $this->setValue($value);
- }
-
- /**
- * Renders the localized version of the date-time value.
- * If the culture is not specified, the default application
- * culture will be used.
- * This method overrides parent's implementation.
- */
- protected function getFormattedDate()
- {
- $value = $this->getValue();
- $defaultText = $this->getDefaultText();
- if(empty($value) && !empty($defaultText))
- return $this->getDefaultText();
-
- $app = $this->getApplication()->getGlobalization();
-
- //initialized the default class wide formatter
- if(self::$formatter===null)
- self::$formatter = new DateFormat($app->getCulture());
-
- $culture = $this->getCulture();
-
- //return the specific cultural formatted date time
- if(strlen($culture) && $app->getCulture() !== $culture)
- {
- $formatter = new DateFormat($culture);
- return $formatter->format($value,
- $this->getPattern(),
- $this->getCharset());
- }
- //return the application wide culture formatted date time.
- $result = self::$formatter->format($value,
- $this->getPattern(),
- $this->getCharset());
- return $result;
- }
-
- public function render($writer)
- {
- $writer->write($this->getFormattedDate());
- }
-
+<?php
+/**
+ * TDateFromat formatting component.
+ *
+ * @author Wei Zhuo <weizhuo[at]gmail[dot]com>
+ * @link http://www.pradosoft.com/
+ * @copyright Copyright &copy; 2005-2012 PradoSoft
+ * @license http://www.pradosoft.com/license/
+ * @version $Id$
+ * @package System.I18N
+ */
+
+/**
+ * Get the DateFormat class.
+ */
+Prado::using('System.I18N.core.DateFormat');
+
+/**
+ * Get the parent control class.
+ */
+Prado::using('System.I18N.TI18NControl');
+
+/**
+ * To format dates and/or time according to the current locale use
+ * <code>
+ * <com:TDateFormat Pattern="dd:MMM:yyyy" Value="01/01/2001" />
+ *</code>
+ * The date will be formatted according to the current locale (or culture)
+ * using the format specified by 'Pattern' attribute.
+ *
+ * To format date and/or time for a locale (e.g. de_DE) include a Culture
+ * attribute, for example:
+ * <code>
+ * <com:TDateFormat Culture="de_DE" Value="01/01/2001 12:00" />
+ * </code>
+ * The date will be formatted according to this format.
+ *
+ * If no Pattern was specified then the date will be formatted with the
+ * default format (both date and time). If no value for the date is specified
+ * then the current date will be used. E.g.: <code><com:TDateFormat /></code>
+ * will result in the current date, formatted with default localized pattern.
+ *
+ * Namespace: System.I18N
+ *
+ * Properties
+ * - <b>Value</b>, date,
+ * <br>Gets or sets the date to format. The tag content is used as Value
+ * if the Value property is not specified.
+ * - <b>Pattern</b>, string,
+ * <br>Gets or sets the formatting pattern. The predefined patterns are
+ * 'fulldate', 'longdate', 'mediumdate', 'shortdate', 'fulltime',
+ * 'longtime', 'mediumtime', and 'shorttime'. Custom patterns can specified
+ * when the Pattern property does not match the predefined patterns.
+ * - <b>DefaultText</b>, string,
+ * <br>Gets or sets the default text. If Value is not set, DefaultText will be
+ * shown instead of todays date and time.
+ *
+ * @author Xiang Wei Zhuo <weizhuo[at]gmail[dot]com>
+ * @version v1.0, last update on Sat Dec 11 15:25:11 EST 2004
+ * @package System.I18N
+ */
+class TDateFormat extends TI18NControl implements IDataRenderer
+{
+ /**
+ * Default DateFormat, set to the application culture.
+ * @var DateFormat
+ */
+ protected static $formatter;
+
+ /**
+ * A set of pattern presets and their respective formatting shorthand.
+ * @var array
+ */
+ static private $_patternPresets = array(
+ 'fulldate'=>'P','full'=>'P',
+ 'longdate'=>'D','long'=>'d',
+ 'mediumdate'=>'p','medium'=>'p',
+ 'shortdate'=>'d','short'=>'d',
+ 'fulltime'=>'Q', 'longtime'=>'T',
+ 'mediumtime'=>'q', 'shorttime'=>'t');
+
+ /**
+ * Sets the date time formatting pattern.
+ * @param string format pattern.
+ */
+ public function setPattern($value)
+ {
+ $this->setViewState('Pattern',$value,'');
+ }
+
+ /**
+ * Gets the date time format pattern.
+ * @return string format pattern.
+ */
+ public function getPattern()
+ {
+ $string = $this->getViewState('Pattern','');
+
+ $pattern = null;
+
+ //try the subpattern of "date time" presets
+ $subpatterns = explode(' ',$string,2);
+ $datetime = array();
+ if(count($subpatterns)==2)
+ {
+ $datetime[] = $this->getPreset($subpatterns[0]);
+ $datetime[] = $this->getPreset($subpatterns[1]);
+ }
+
+ //we have a good subpattern
+ if(count($datetime) == 2
+ && strlen($datetime[0]) == 1
+ && strlen($datetime[1]) == 1)
+ {
+ $pattern = $datetime;
+ }
+ else //no subpattern, try the presets
+ $pattern = $this->getPreset($string);
+
+ //no presets found, use the string as the pattern
+ //and let the DateFormat handle it.
+ if($pattern===null)
+ $pattern = $string;
+ if (!is_array($pattern) && strlen($pattern) == 0)
+ $pattern = null;
+ return $pattern;
+ }
+
+ /**
+ * For a given string, try and find a preset pattern.
+ * @param string the preset pattern name
+ * @return string a preset pattern if found, null otherwise.
+ */
+ protected function getPreset($string)
+ {
+ $string = strtolower($string);
+ foreach(self::$_patternPresets as $pattern => $preset)
+ {
+ if($string == $pattern)
+ return $preset;
+ }
+ }
+
+ /**
+ * Get the date-time value for this control.
+ * @return string date time value.
+ */
+ public function getValue()
+ {
+ $value = $this->getViewState('Value','');
+ if(empty($value))
+ {
+ $defaultText = $this->getDefaultText();
+ if(empty($defaultText))
+ return time();
+ }
+ return $value;
+ }
+
+ /**
+ * Set the date-time value for this control.
+ * @param string the date-time value.
+ */
+ public function setValue($value)
+ {
+ $this->setViewState('Value',$value,'');
+ }
+
+ /**
+ * Get the default text value for this control.
+ * @return string default text value
+ */
+ public function getDefaultText()
+ {
+ return $this->getViewState('DefaultText','');
+ }
+
+ /**
+ * Set the default text value for this control.
+ * @param string default text value
+ */
+ public function setDefaultText($value)
+ {
+ $this->setViewState('DefaultText',$value,'');
+ }
+
+ /**
+ * Get the date-time value for this control.
+ * This method is required by {@link IDataRenderer}.
+ * It is the same as {@link getValue()}.
+ * @return string date time value.
+ * @see getValue
+ * @since 3.1.2
+ */
+ public function getData()
+ {
+ return $this->getValue();
+ }
+
+ /**
+ * Set the date-time value for this control.
+ * This method is required by {@link IDataRenderer}.
+ * It is the same as {@link setValue()}.
+ * @param string the date-time value.
+ * @see setValue
+ * @since 3.1.2
+ */
+ public function setData($value)
+ {
+ $this->setValue($value);
+ }
+
+ /**
+ * Renders the localized version of the date-time value.
+ * If the culture is not specified, the default application
+ * culture will be used.
+ * This method overrides parent's implementation.
+ */
+ protected function getFormattedDate()
+ {
+ $value = $this->getValue();
+ $defaultText = $this->getDefaultText();
+ if(empty($value) && !empty($defaultText))
+ return $this->getDefaultText();
+
+ $app = $this->getApplication()->getGlobalization();
+
+ //initialized the default class wide formatter
+ if(self::$formatter===null)
+ self::$formatter = new DateFormat($app->getCulture());
+
+ $culture = $this->getCulture();
+
+ //return the specific cultural formatted date time
+ if(strlen($culture) && $app->getCulture() !== $culture)
+ {
+ $formatter = new DateFormat($culture);
+ return $formatter->format($value,
+ $this->getPattern(),
+ $this->getCharset());
+ }
+ //return the application wide culture formatted date time.
+ $result = self::$formatter->format($value,
+ $this->getPattern(),
+ $this->getCharset());
+ return $result;
+ }
+
+ public function render($writer)
+ {
+ $writer->write($this->getFormattedDate());
+ }
+
} \ No newline at end of file
diff --git a/framework/I18N/TGlobalization.php b/framework/I18N/TGlobalization.php
index 54f5d66f..d5496353 100644
--- a/framework/I18N/TGlobalization.php
+++ b/framework/I18N/TGlobalization.php
@@ -1,299 +1,299 @@
-<?php
-/**
- * TGlobalization class file.
- *
- * @author Wei Zhuo<weizhuo[at]gmail[dot]com>
- * @link http://www.pradosoft.com/
- * @copyright Copyright &copy; 2005-2012 PradoSoft
- * @license http://www.pradosoft.com/license/
- * @version $Id$
- * @package System.I18N
- */
-
-
-/**
- * TGlobalization contains settings for Culture, Charset
- * and TranslationConfiguration.
- *
- * TGlobalization can be subclassed to change how the Culture, Charset
- * are determined. See TGlobalizationAutoDetect for example of
- * setting the Culture based on browser settings.
- *
- * @author Wei Zhuo<weizhuo[at]gmail[dot]com>
- * @version $Revision: 1.66 $ $Date: ${DATE} ${TIME} $
- * @package System.I18N
- * @since 3.0
- */
-class TGlobalization extends TModule
-{
- /**
- * Default character set is 'UTF-8'.
- * @var string
- */
- private $_defaultCharset = 'UTF-8';
-
- /**
- * Default culture is 'en'.
- * @var string
- */
- private $_defaultCulture = 'en';
-
- /**
- * The current charset.
- * @var string
- */
- private $_charset=null;
-
- /**
- * The current culture.
- * @var string
- */
- private $_culture=null;
-
- /**
- * Translation source parameters.
- * @var TMap
- */
- private $_translation;
-
- /**
- * @var boolean whether we should translate the default culture
- */
- private $_translateDefaultCulture=true;
-
- /**
- * Initialize the Culture and Charset for this application.
- * You should override this method if you want a different way of
- * setting the Culture and/or Charset for your application.
- * If you override this method, call parent::init($xml) first.
- * @param mixed application configuration
- */
- public function init($config)
- {
- if($this->_charset===null)
- $this->_charset=$this->getDefaultCharset();
- if($this->_culture===null)
- $this->_culture=$this->getDefaultCulture();
-
- if($config!==null)
- {
- if($this->getApplication()->getConfigurationType()==TApplication::CONFIG_TYPE_PHP)
- $translation = isset($config['translate'])?$config['translate']:null;
- else
- {
- $t = $config->getElementByTagName('translation');
- $translation = ($t)?$t->getAttributes():null;
- }
- if($translation)
- $this->setTranslationConfiguration($translation);
- }
- $this->getApplication()->setGlobalization($this);
- }
-
- /**
- * @return string default culture
- */
- public function getTranslateDefaultCulture()
- {
- return $this->_translateDefaultCulture;
- }
-
- /**
- * @param bool default culture, e.g. <tt>en_US</tt> for American English
- */
- public function setTranslateDefaultCulture($value)
- {
- $this->_translateDefaultCulture = TPropertyValue::ensureBoolean($value);
- }
-
- /**
- * @return string default culture
- */
- public function getDefaultCulture()
- {
- return $this->_defaultCulture;
- }
-
- /**
- * @param string default culture, e.g. <tt>en_US</tt> for American English
- */
- public function setDefaultCulture($culture)
- {
- $this->_defaultCulture = str_replace('-','_',$culture);
- }
-
- /**
- * @return string default charset set
- */
- public function getDefaultCharset()
- {
- return $this->_defaultCharset;
- }
-
- /**
- * @param string default localization charset, e.g. <tt>UTF-8</tt>
- */
- public function setDefaultCharset($charset)
- {
- $this->_defaultCharset = $charset;
- }
-
- /**
- * @return string current application culture
- */
- public function getCulture()
- {
- return $this->_culture;
- }
-
- /**
- * @param string culture, e.g. <tt>en_US</tt> for American English
- */
- public function setCulture($culture)
- {
- $this->_culture = str_replace('-','_',$culture);
- }
-
- /**
- * @return string localization charset
- */
- public function getCharset()
- {
- return $this->_charset;
- }
-
- /**
- * @param string localization charset, e.g. <tt>UTF-8</tt>
- */
- public function setCharset($charset)
- {
- $this->_charset = $charset;
- }
-
- /**
- * @return TMap translation source configuration.
- */
- public function getTranslationConfiguration()
- {
- return (!$this->_translateDefaultCulture && ($this->getDefaultCulture() == $this->getCulture()))
- ? null
- : $this->_translation;
- }
-
- /**
- * Sets the translation configuration. Example configuration:
- * <code>
- * $config['type'] = 'XLIFF'; //XLIFF, gettext, Database or MySQL (deprecated)
- * $config['source'] = 'Path.to.directory'; // for types XLIFF and gettext
- * $config['source'] = 'connectionId'; // for type Database
- * $config['source'] = 'mysql://user:pw@host/db'; // for type MySQL (deprecated)
- * $config['catalogue'] = 'messages'; //default catalog
- * $config['autosave'] = 'true'; //save untranslated message
- * $config['cache'] = 'true'; //cache translated message
- * $config['marker'] = '@@'; // surround untranslated text with '@@'
- * </code>
- * Throws exception is source is not found.
- * @param TMap|array configuration options
- */
- protected function setTranslationConfiguration($config)
- {
- if($config['type'] == 'XLIFF' || $config['type'] == 'gettext')
- {
- if($config['source'])
- {
- $config['source'] = Prado::getPathOfNamespace($config['source']);
- if(!is_dir($config['source']))
- {
- if(@mkdir($config['source'])===false)
- throw new TConfigurationException('globalization_source_path_failed',
- $config['source']);
- chmod($config['source'], PRADO_CHMOD); //make it deletable
- }
- }
- else
- {
- throw new TConfigurationException("invalid source dir '{$config['source']}'");
- }
- }
- if($config['cache'])
- {
- $config['cache'] = $this->getApplication()->getRunTimePath().'/i18n';
- if(!is_dir($config['cache']))
- {
- if(@mkdir($config['cache'])===false)
- throw new TConfigurationException('globalization_cache_path_failed',
- $config['cache']);
- chmod($config['cache'], PRADO_CHMOD); //make it deletable
- }
- }
- $this->_translation = $config;
- }
-
- /**
- * @return string current translation catalogue.
- */
- public function getTranslationCatalogue()
- {
- return $this->_translation['catalogue'];
- }
-
- /**
- * @param string update the translation catalogue.
- */
- public function setTranslationCatalogue($value)
- {
- $this->_translation['catalogue'] = $value;
- }
-
- /**
- * Gets all the variants of a specific culture. If the parameter
- * $culture is null, the current culture is used.
- * @param string $culture the Culture string
- * @return array variants of the culture.
- */
- public function getCultureVariants($culture=null)
- {
- if($culture===null) $culture = $this->getCulture();
- $variants = explode('_', $culture);
- $result = array();
- for(; count($variants) > 0; array_pop($variants))
- $result[] = implode('_', $variants);
- return $result;
- }
-
- /**
- * Returns a list of possible localized files. Example
- * <code>
- * $files = $app->getLocalizedResource("path/to/Home.page","en_US");
- * </code>
- * will return
- * <pre>
- * array
- * 0 => 'path/to/en_US/Home.page'
- * 1 => 'path/to/en/Home.page'
- * 2 => 'path/to/Home.en_US.page'
- * 3 => 'path/to/Home.en.page'
- * 4 => 'path/to/Home.page'
- * </pre>
- * Note that you still need to verify the existance of these files.
- * @param string filename
- * @param string culture string, null to use current culture
- * @return array list of possible localized resource files.
- */
- public function getLocalizedResource($file,$culture=null)
- {
- $files = array();
- $variants = $this->getCultureVariants($culture);
- $path = pathinfo($file);
- foreach($variants as $variant)
- $files[] = $path['dirname'].DIRECTORY_SEPARATOR.$variant.DIRECTORY_SEPARATOR.$path['basename'];
- $filename = substr($path['basename'],0,strrpos($path['basename'],'.'));
- foreach($variants as $variant)
- $files[] = $path['dirname'].DIRECTORY_SEPARATOR.$filename.'.'.$variant.'.'.$path['extension'];
- $files[] = $file;
- return $files;
- }
-
-}
-
-?>
+<?php
+/**
+ * TGlobalization class file.
+ *
+ * @author Wei Zhuo<weizhuo[at]gmail[dot]com>
+ * @link http://www.pradosoft.com/
+ * @copyright Copyright &copy; 2005-2012 PradoSoft
+ * @license http://www.pradosoft.com/license/
+ * @version $Id$
+ * @package System.I18N
+ */
+
+
+/**
+ * TGlobalization contains settings for Culture, Charset
+ * and TranslationConfiguration.
+ *
+ * TGlobalization can be subclassed to change how the Culture, Charset
+ * are determined. See TGlobalizationAutoDetect for example of
+ * setting the Culture based on browser settings.
+ *
+ * @author Wei Zhuo<weizhuo[at]gmail[dot]com>
+ * @version $Revision: 1.66 $ $Date: ${DATE} ${TIME} $
+ * @package System.I18N
+ * @since 3.0
+ */
+class TGlobalization extends TModule
+{
+ /**
+ * Default character set is 'UTF-8'.
+ * @var string
+ */
+ private $_defaultCharset = 'UTF-8';
+
+ /**
+ * Default culture is 'en'.
+ * @var string
+ */
+ private $_defaultCulture = 'en';
+
+ /**
+ * The current charset.
+ * @var string
+ */
+ private $_charset=null;
+
+ /**
+ * The current culture.
+ * @var string
+ */
+ private $_culture=null;
+
+ /**
+ * Translation source parameters.
+ * @var TMap
+ */
+ private $_translation;
+
+ /**
+ * @var boolean whether we should translate the default culture
+ */
+ private $_translateDefaultCulture=true;
+
+ /**
+ * Initialize the Culture and Charset for this application.
+ * You should override this method if you want a different way of
+ * setting the Culture and/or Charset for your application.
+ * If you override this method, call parent::init($xml) first.
+ * @param mixed application configuration
+ */
+ public function init($config)
+ {
+ if($this->_charset===null)
+ $this->_charset=$this->getDefaultCharset();
+ if($this->_culture===null)
+ $this->_culture=$this->getDefaultCulture();
+
+ if($config!==null)
+ {
+ if($this->getApplication()->getConfigurationType()==TApplication::CONFIG_TYPE_PHP)
+ $translation = isset($config['translate'])?$config['translate']:null;
+ else
+ {
+ $t = $config->getElementByTagName('translation');
+ $translation = ($t)?$t->getAttributes():null;
+ }
+ if($translation)
+ $this->setTranslationConfiguration($translation);
+ }
+ $this->getApplication()->setGlobalization($this);
+ }
+
+ /**
+ * @return string default culture
+ */
+ public function getTranslateDefaultCulture()
+ {
+ return $this->_translateDefaultCulture;
+ }
+
+ /**
+ * @param bool default culture, e.g. <tt>en_US</tt> for American English
+ */
+ public function setTranslateDefaultCulture($value)
+ {
+ $this->_translateDefaultCulture = TPropertyValue::ensureBoolean($value);
+ }
+
+ /**
+ * @return string default culture
+ */
+ public function getDefaultCulture()
+ {
+ return $this->_defaultCulture;
+ }
+
+ /**
+ * @param string default culture, e.g. <tt>en_US</tt> for American English
+ */
+ public function setDefaultCulture($culture)
+ {
+ $this->_defaultCulture = str_replace('-','_',$culture);
+ }
+
+ /**
+ * @return string default charset set
+ */
+ public function getDefaultCharset()
+ {
+ return $this->_defaultCharset;
+ }
+
+ /**
+ * @param string default localization charset, e.g. <tt>UTF-8</tt>
+ */
+ public function setDefaultCharset($charset)
+ {
+ $this->_defaultCharset = $charset;
+ }
+
+ /**
+ * @return string current application culture
+ */
+ public function getCulture()
+ {
+ return $this->_culture;
+ }
+
+ /**
+ * @param string culture, e.g. <tt>en_US</tt> for American English
+ */
+ public function setCulture($culture)
+ {
+ $this->_culture = str_replace('-','_',$culture);
+ }
+
+ /**
+ * @return string localization charset
+ */
+ public function getCharset()
+ {
+ return $this->_charset;
+ }
+
+ /**
+ * @param string localization charset, e.g. <tt>UTF-8</tt>
+ */
+ public function setCharset($charset)
+ {
+ $this->_charset = $charset;
+ }
+
+ /**
+ * @return TMap translation source configuration.
+ */
+ public function getTranslationConfiguration()
+ {
+ return (!$this->_translateDefaultCulture && ($this->getDefaultCulture() == $this->getCulture()))
+ ? null
+ : $this->_translation;
+ }
+
+ /**
+ * Sets the translation configuration. Example configuration:
+ * <code>
+ * $config['type'] = 'XLIFF'; //XLIFF, gettext, Database or MySQL (deprecated)
+ * $config['source'] = 'Path.to.directory'; // for types XLIFF and gettext
+ * $config['source'] = 'connectionId'; // for type Database
+ * $config['source'] = 'mysql://user:pw@host/db'; // for type MySQL (deprecated)
+ * $config['catalogue'] = 'messages'; //default catalog
+ * $config['autosave'] = 'true'; //save untranslated message
+ * $config['cache'] = 'true'; //cache translated message
+ * $config['marker'] = '@@'; // surround untranslated text with '@@'
+ * </code>
+ * Throws exception is source is not found.
+ * @param TMap|array configuration options
+ */
+ protected function setTranslationConfiguration($config)
+ {
+ if($config['type'] == 'XLIFF' || $config['type'] == 'gettext')
+ {
+ if($config['source'])
+ {
+ $config['source'] = Prado::getPathOfNamespace($config['source']);
+ if(!is_dir($config['source']))
+ {
+ if(@mkdir($config['source'])===false)
+ throw new TConfigurationException('globalization_source_path_failed',
+ $config['source']);
+ chmod($config['source'], PRADO_CHMOD); //make it deletable
+ }
+ }
+ else
+ {
+ throw new TConfigurationException("invalid source dir '{$config['source']}'");
+ }
+ }
+ if($config['cache'])
+ {
+ $config['cache'] = $this->getApplication()->getRunTimePath().'/i18n';
+ if(!is_dir($config['cache']))
+ {
+ if(@mkdir($config['cache'])===false)
+ throw new TConfigurationException('globalization_cache_path_failed',
+ $config['cache']);
+ chmod($config['cache'], PRADO_CHMOD); //make it deletable
+ }
+ }
+ $this->_translation = $config;
+ }
+
+ /**
+ * @return string current translation catalogue.
+ */
+ public function getTranslationCatalogue()
+ {
+ return $this->_translation['catalogue'];
+ }
+
+ /**
+ * @param string update the translation catalogue.
+ */
+ public function setTranslationCatalogue($value)
+ {
+ $this->_translation['catalogue'] = $value;
+ }
+
+ /**
+ * Gets all the variants of a specific culture. If the parameter
+ * $culture is null, the current culture is used.
+ * @param string $culture the Culture string
+ * @return array variants of the culture.
+ */
+ public function getCultureVariants($culture=null)
+ {
+ if($culture===null) $culture = $this->getCulture();
+ $variants = explode('_', $culture);
+ $result = array();
+ for(; count($variants) > 0; array_pop($variants))
+ $result[] = implode('_', $variants);
+ return $result;
+ }
+
+ /**
+ * Returns a list of possible localized files. Example
+ * <code>
+ * $files = $app->getLocalizedResource("path/to/Home.page","en_US");
+ * </code>
+ * will return
+ * <pre>
+ * array
+ * 0 => 'path/to/en_US/Home.page'
+ * 1 => 'path/to/en/Home.page'
+ * 2 => 'path/to/Home.en_US.page'
+ * 3 => 'path/to/Home.en.page'
+ * 4 => 'path/to/Home.page'
+ * </pre>
+ * Note that you still need to verify the existance of these files.
+ * @param string filename
+ * @param string culture string, null to use current culture
+ * @return array list of possible localized resource files.
+ */
+ public function getLocalizedResource($file,$culture=null)
+ {
+ $files = array();
+ $variants = $this->getCultureVariants($culture);
+ $path = pathinfo($file);
+ foreach($variants as $variant)
+ $files[] = $path['dirname'].DIRECTORY_SEPARATOR.$variant.DIRECTORY_SEPARATOR.$path['basename'];
+ $filename = substr($path['basename'],0,strrpos($path['basename'],'.'));
+ foreach($variants as $variant)
+ $files[] = $path['dirname'].DIRECTORY_SEPARATOR.$filename.'.'.$variant.'.'.$path['extension'];
+ $files[] = $file;
+ return $files;
+ }
+
+}
+
+?>
diff --git a/framework/I18N/TGlobalizationAutoDetect.php b/framework/I18N/TGlobalizationAutoDetect.php
index 36273867..5d8a7677 100644
--- a/framework/I18N/TGlobalizationAutoDetect.php
+++ b/framework/I18N/TGlobalizationAutoDetect.php
@@ -1,49 +1,49 @@
-<?php
-/**
- * TMultiView and TView class file.
- *
- * @author Wei Zhuo<weizhuo[at]gmail[dot]com>
- * @link http://www.pradosoft.com/
+<?php
+/**
+ * TMultiView and TView class file.
+ *
+ * @author Wei Zhuo<weizhuo[at]gmail[dot]com>
+ * @link http://www.pradosoft.com/
* @copyright Copyright &copy; 2005-2012 PradoSoft
- * @license http://www.pradosoft.com/license/
- * @version $Revision: 1.66 $ $Date: ${DATE} ${TIME} $
- * @package System.I18N
- */
-
-/**
- * Import the HTTPNeogtiator
- */
-Prado::using('System.I18N.core.HTTPNegotiator');
-
-/**
- * TGlobalizationAutoDetect class will automatically try to resolve the default
- * culture using the user browser language settings.
- *
- * @author Wei Zhuo<weizhuo[at]gmail[dot]com>
- * @version $Revision: 1.66 $ $Date: ${DATE} ${TIME} $
- * @package System.I18N
- */
-class TGlobalizationAutoDetect extends TGlobalization
-{
- private $_detectedLanguage;
-
- public function init($xml)
- {
- parent::init($xml);
-
- //set the culture according to browser language settings
- $http = new HTTPNegotiator();
- $languages = $http->getLanguages();
- if(count($languages) > 0)
- {
- $this->_detectedLanguage=$languages[0];
- $this->setCulture($languages[0]);
- }
- }
-
- public function getDetectedLanguage()
- {
- return $this->_detectedLanguage;
- }
-}
-
+ * @license http://www.pradosoft.com/license/
+ * @version $Revision: 1.66 $ $Date: ${DATE} ${TIME} $
+ * @package System.I18N
+ */
+
+/**
+ * Import the HTTPNeogtiator
+ */
+Prado::using('System.I18N.core.HTTPNegotiator');
+
+/**
+ * TGlobalizationAutoDetect class will automatically try to resolve the default
+ * culture using the user browser language settings.
+ *
+ * @author Wei Zhuo<weizhuo[at]gmail[dot]com>
+ * @version $Revision: 1.66 $ $Date: ${DATE} ${TIME} $
+ * @package System.I18N
+ */
+class TGlobalizationAutoDetect extends TGlobalization
+{
+ private $_detectedLanguage;
+
+ public function init($xml)
+ {
+ parent::init($xml);
+
+ //set the culture according to browser language settings
+ $http = new HTTPNegotiator();
+ $languages = $http->getLanguages();
+ if(count($languages) > 0)
+ {
+ $this->_detectedLanguage=$languages[0];
+ $this->setCulture($languages[0]);
+ }
+ }
+
+ public function getDetectedLanguage()
+ {
+ return $this->_detectedLanguage;
+ }
+}
+
diff --git a/framework/I18N/TI18NControl.php b/framework/I18N/TI18NControl.php
index 7e8efe0a..79c7d5ed 100644
--- a/framework/I18N/TI18NControl.php
+++ b/framework/I18N/TI18NControl.php
@@ -1,90 +1,90 @@
-<?php
-/**
- * Base I18N component.
- *
- * @author Wei Zhuo <weizhuo[at]gmail[dot]com>
- * @link http://www.pradosoft.com/
- * @copyright Copyright &copy; 2005-2012 PradoSoft
- * @license http://www.pradosoft.com/license/
- * @version $Id$
- * @package System.I18N
- */
-
-
-/**
- * TI18NControl class.
- *
- * Base class for I18N components, providing Culture and Charset properties.
- * Namespace: System.I18N
- *
- * Properties
- * - <b>Culture</b>, string,
- * <br>Gets or sets the culture for formatting. If the Culture property
- * is not specified. The culture from the Application/Page is used.
- * - <b>Charset</b>, string,
- * <br>Gets or sets the charset for both input and output.
- * If the Charset property is not specified. The charset from the
- * Application/Page is used. The default is UTF-8.
- *
- * @author Xiang Wei Zhuo <weizhuo[at]gmail[dot]com>
- * @version v1.0, last update on Sat Dec 11 15:25:11 EST 2004
- * @package System.I18N
- */
-class TI18NControl extends TControl
-{
- /**
- * Gets the charset.
- * It is evaluated in the following order:
- * 1) application charset,
- * 2) the default charset in globalization
- * 3) UTF-8
- * @return string charset
- */
- public function getCharset()
- {
- $app = $this->getApplication()->getGlobalization(false);
-
- //instance charset
- $charset = $this->getViewState('Charset','');
-
- //fall back to globalization charset
- if(empty($charset))
- $charset = ($app===null) ? '' : $app->getCharset();
-
- //fall back to default charset
- if(empty($charset))
- $charset = ($app===null) ? 'UTF-8' : $app->getDefaultCharset();
-
- return $charset;
- }
-
- /**
- * Sets the charset for message output
- * @param string the charset, e.g. UTF-8
- */
- public function setCharset($value)
- {
- $this->setViewState('Charset',$value,'');
- }
-
-
- /**
- * Get the specific culture for this control.
- * @param parameter
- * @return string culture identifier.
- */
- public function getCulture()
- {
- return $this->getViewState('Culture','');
- }
-
- /**
- * Get the custom culture identifier.
- * @param string culture identifier.
- */
- public function setCulture($culture)
- {
- $this->setViewState('Culture',$culture,'');
- }
-}
-
+<?php
+/**
+ * Base I18N component.
+ *
+ * @author Wei Zhuo <weizhuo[at]gmail[dot]com>
+ * @link http://www.pradosoft.com/
+ * @copyright Copyright &copy; 2005-2012 PradoSoft
+ * @license http://www.pradosoft.com/license/
+ * @version $Id$
+ * @package System.I18N
+ */
+
+
+/**
+ * TI18NControl class.
+ *
+ * Base class for I18N components, providing Culture and Charset properties.
+ * Namespace: System.I18N
+ *
+ * Properties
+ * - <b>Culture</b>, string,
+ * <br>Gets or sets the culture for formatting. If the Culture property
+ * is not specified. The culture from the Application/Page is used.
+ * - <b>Charset</b>, string,
+ * <br>Gets or sets the charset for both input and output.
+ * If the Charset property is not specified. The charset from the
+ * Application/Page is used. The default is UTF-8.
+ *
+ * @author Xiang Wei Zhuo <weizhuo[at]gmail[dot]com>
+ * @version v1.0, last update on Sat Dec 11 15:25:11 EST 2004
+ * @package System.I18N
+ */
+class TI18NControl extends TControl
+{
+ /**
+ * Gets the charset.
+ * It is evaluated in the following order:
+ * 1) application charset,
+ * 2) the default charset in globalization
+ * 3) UTF-8
+ * @return string charset
+ */
+ public function getCharset()
+ {
+ $app = $this->getApplication()->getGlobalization(false);
+
+ //instance charset
+ $charset = $this->getViewState('Charset','');
+
+ //fall back to globalization charset
+ if(empty($charset))
+ $charset = ($app===null) ? '' : $app->getCharset();
+
+ //fall back to default charset
+ if(empty($charset))
+ $charset = ($app===null) ? 'UTF-8' : $app->getDefaultCharset();
+
+ return $charset;
+ }
+
+ /**
+ * Sets the charset for message output
+ * @param string the charset, e.g. UTF-8
+ */
+ public function setCharset($value)
+ {
+ $this->setViewState('Charset',$value,'');
+ }
+
+
+ /**
+ * Get the specific culture for this control.
+ * @param parameter
+ * @return string culture identifier.
+ */
+ public function getCulture()
+ {
+ return $this->getViewState('Culture','');
+ }
+
+ /**
+ * Get the custom culture identifier.
+ * @param string culture identifier.
+ */
+ public function setCulture($culture)
+ {
+ $this->setViewState('Culture',$culture,'');
+ }
+}
+
diff --git a/framework/I18N/TNumberFormat.php b/framework/I18N/TNumberFormat.php
index 30a1e638..1c2502be 100644
--- a/framework/I18N/TNumberFormat.php
+++ b/framework/I18N/TNumberFormat.php
@@ -1,251 +1,251 @@
-<?php
-/**
- * TNumberFromat component.
- *
- * @author Wei Zhuo <weizhuo[at]gmail[dot]com>
- * @link http://www.pradosoft.com/
- * @copyright Copyright &copy; 2005-2012 PradoSoft
- * @license http://www.pradosoft.com/license/
- * @version $Id$
- * @package System.I18N
- */
-
-/**
- * Get the NumberFormat class.
- */
-Prado::using('System.I18N.core.NumberFormat');
-
-/**
- * Get the parent control class.
- */
-Prado::using('System.I18N.TI18NControl');
-
-/**
- * To format numbers in locale sensitive manner use
- * <code>
- * <com:TNumberFormat Pattern="0.##" value="2.0" />
- * </code>
- *
- * Numbers can be formatted as currency, percentage, decimal or scientific
- * numbers by specifying the Type attribute. The known types are
- * "currency", "percentage", "decimal" and "scientific".
- *
- * If someone from US want to see sales figures from a store in
- * Germany (say using the EURO currency), formatted using the german
- * currency, you would need to use the attribute Culture="de_DE" to get
- * the currency right, e.g. 100,00. The decimal and grouping separator is
- * then also from the de_DE locale. This may lead to some confusion because
- * people from US know the "," as thousand separator. Therefore a "Currency"
- * attribute is available, so that the output from the following example
- * results in 100.00.
- * <code>
- * <com:TNumberFormat Type="currency" Culture="en_US" Currency="EUR" Value="100" />
- * </code>
- *
- * Namespace: System.I18N
- *
- * Properties
- * - <b>Value</b>, number,
- * <br>Gets or sets the number to format. The tag content is used as Value
- * if the Value property is not specified.
- * - <b>Type</b>, string,
- * <br>Gets or sets the formatting type. The valid types are
- * 'decimal', 'currency', 'percentage' and 'scientific'.
- * - <b>Currency</b>, string,
- * <br>Gets or sets the currency symbol for the currency format.
- * The default is 'USD' if the Currency property is not specified.
- * - <b>Pattern</b>, string,
- * <br>Gets or sets the custom number formatting pattern.
- * - <b>DefaultText</b>, string,
- * <br>Gets or sets the default text. If Value is not set, DefaultText will be
- * shown instead of the default currency Value/Pattern.
- *
- * @author Xiang Wei Zhuo <weizhuo[at]gmail[dot]com>
- * @version v1.0, last update on Sat Dec 11 17:49:56 EST 2004
- * @package System.I18N
- */
-class TNumberFormat extends TI18NControl implements IDataRenderer
-{
- /**
- * Default NumberFormat, set to the application culture.
- * @var NumberFormat
- */
- protected static $formatter;
-
- /**
- * Get the number formatting pattern.
- * @return string format pattern.
- */
- public function getPattern()
- {
- return $this->getViewState('Pattern','');
- }
-
- /**
- * Set the number format pattern.
- * @param string format pattern.
- */
- public function setPattern($pattern)
- {
- $this->setViewState('Pattern',$pattern,'');
- }
-
- /**
- * Get the numberic value for this control.
- * @return string number
- */
- public function getValue()
- {
- return $this->getViewState('Value','');
- }
-
- /**
- * Set the numberic value for this control.
- * @param string the number value
- */
- public function setValue($value)
- {
- $this->setViewState('Value',$value,'');
- }
-
- /**
- * Get the default text value for this control.
- * @return string default text value
- */
- public function getDefaultText()
- {
- return $this->getViewState('DefaultText','');
- }
-
- /**
- * Set the default text value for this control.
- * @param string default text value
- */
- public function setDefaultText($value)
- {
- $this->setViewState('DefaultText',$value,'');
- }
-
- /**
- * Get the numberic value for this control.
- * This method is required by {@link IDataRenderer}.
- * It is the same as {@link getValue()}.
- * @return string number
- * @see getValue
- * @since 3.1.2
- */
- public function getData()
- {
- return $this->getValue();
- }
-
- /**
- * Set the numberic value for this control.
- * This method is required by {@link IDataRenderer}.
- * It is the same as {@link setValue()}.
- * @param string the number value
- * @see setValue
- * @since 3.1.2
- */
- public function setData($value)
- {
- $this->setValue($value);
- }
-
- /**
- * Get the formatting type for this control.
- * @return string formatting type.
- */
- public function getType()
- {
- return $this->getViewState('Type','d');
- }
-
- /**
- * Set the formatting type for this control.
- * @param string formatting type, either "decimal", "currency","percentage"
- * or "scientific"
- * @throws TPropertyTypeInvalidException
- */
- public function setType($type)
- {
- $type = strtolower($type);
-
- switch($type)
- {
- case 'decimal':
- $this->setViewState('Type','d',''); break;
- case 'currency':
- $this->setViewState('Type','c',''); break;
- case 'percentage':
- $this->setViewState('Type','p',''); break;
- case 'scientific':
- $this->setViewState('Type','e',''); break;
- default:
- throw new TInvalidDataValueException('numberformat_type_invalid',$type);
- }
-
- }
-
- /**
- * @return string 3 letter currency code. Defaults to 'USD'.
- */
- public function getCurrency()
- {
- return $this->getViewState('Currency','USD');
- }
-
- /**
- * Set the 3-letter ISO 4217 code. For example, the code
- * "USD" represents the US Dollar and "EUR" represents the Euro currency.
- * @param string currency code.
- */
- public function setCurrency($currency)
- {
- $this->setViewState('Currency', $currency,'');
- }
-
- /**
- * Formats the localized number, be it currency or decimal, or percentage.
- * If the culture is not specified, the default application
- * culture will be used.
- * @return string formatted number
- */
- protected function getFormattedValue()
- {
- $value = $this->getValue();
- $defaultText = $this->getDefaultText();
- if(empty($value) && !empty($defaultText))
- return $this->getDefaultText();
-
- $app = $this->getApplication()->getGlobalization();
- //initialized the default class wide formatter
- if(self::$formatter===null)
- self::$formatter = new NumberFormat($app->getCulture());
-
- $pattern = strlen($this->getPattern()) > 0
- ? $this->getPattern() : $this->getType();
-
- $culture = $this->getCulture();
- //return the specific cultural formatted number
- if(!empty($culture) && $app->getCulture() != $culture)
- {
- $formatter = new NumberFormat($culture);
- return $formatter->format($this->getValue(),$pattern,
- $this->getCurrency(),
- $this->getCharset());
- }
-
- //return the application wide culture formatted number.
- return self::$formatter->format($this->getValue(),$pattern,
- $this->getCurrency(),
- $this->getCharset());
- }
-
- public function render($writer)
- {
- $writer->write($this->getFormattedValue());
- }
-}
-
-?>
+<?php
+/**
+ * TNumberFromat component.
+ *
+ * @author Wei Zhuo <weizhuo[at]gmail[dot]com>
+ * @link http://www.pradosoft.com/
+ * @copyright Copyright &copy; 2005-2012 PradoSoft
+ * @license http://www.pradosoft.com/license/
+ * @version $Id$
+ * @package System.I18N
+ */
+
+/**
+ * Get the NumberFormat class.
+ */
+Prado::using('System.I18N.core.NumberFormat');
+
+/**
+ * Get the parent control class.
+ */
+Prado::using('System.I18N.TI18NControl');
+
+/**
+ * To format numbers in locale sensitive manner use
+ * <code>
+ * <com:TNumberFormat Pattern="0.##" value="2.0" />
+ * </code>
+ *
+ * Numbers can be formatted as currency, percentage, decimal or scientific
+ * numbers by specifying the Type attribute. The known types are
+ * "currency", "percentage", "decimal" and "scientific".
+ *
+ * If someone from US want to see sales figures from a store in
+ * Germany (say using the EURO currency), formatted using the german
+ * currency, you would need to use the attribute Culture="de_DE" to get
+ * the currency right, e.g. 100,00. The decimal and grouping separator is
+ * then also from the de_DE locale. This may lead to some confusion because
+ * people from US know the "," as thousand separator. Therefore a "Currency"
+ * attribute is available, so that the output from the following example
+ * results in 100.00.
+ * <code>
+ * <com:TNumberFormat Type="currency" Culture="en_US" Currency="EUR" Value="100" />
+ * </code>
+ *
+ * Namespace: System.I18N
+ *
+ * Properties
+ * - <b>Value</b>, number,
+ * <br>Gets or sets the number to format. The tag content is used as Value
+ * if the Value property is not specified.
+ * - <b>Type</b>, string,
+ * <br>Gets or sets the formatting type. The valid types are
+ * 'decimal', 'currency', 'percentage' and 'scientific'.
+ * - <b>Currency</b>, string,
+ * <br>Gets or sets the currency symbol for the currency format.
+ * The default is 'USD' if the Currency property is not specified.
+ * - <b>Pattern</b>, string,
+ * <br>Gets or sets the custom number formatting pattern.
+ * - <b>DefaultText</b>, string,
+ * <br>Gets or sets the default text. If Value is not set, DefaultText will be
+ * shown instead of the default currency Value/Pattern.
+ *
+ * @author Xiang Wei Zhuo <weizhuo[at]gmail[dot]com>
+ * @version v1.0, last update on Sat Dec 11 17:49:56 EST 2004
+ * @package System.I18N
+ */
+class TNumberFormat extends TI18NControl implements IDataRenderer
+{
+ /**
+ * Default NumberFormat, set to the application culture.
+ * @var NumberFormat
+ */
+ protected static $formatter;
+
+ /**
+ * Get the number formatting pattern.
+ * @return string format pattern.
+ */
+ public function getPattern()
+ {
+ return $this->getViewState('Pattern','');
+ }
+
+ /**
+ * Set the number format pattern.
+ * @param string format pattern.
+ */
+ public function setPattern($pattern)
+ {
+ $this->setViewState('Pattern',$pattern,'');
+ }
+
+ /**
+ * Get the numberic value for this control.
+ * @return string number
+ */
+ public function getValue()
+ {
+ return $this->getViewState('Value','');
+ }
+
+ /**
+ * Set the numberic value for this control.
+ * @param string the number value
+ */
+ public function setValue($value)
+ {
+ $this->setViewState('Value',$value,'');
+ }
+
+ /**
+ * Get the default text value for this control.
+ * @return string default text value
+ */
+ public function getDefaultText()
+ {
+ return $this->getViewState('DefaultText','');
+ }
+
+ /**
+ * Set the default text value for this control.
+ * @param string default text value
+ */
+ public function setDefaultText($value)
+ {
+ $this->setViewState('DefaultText',$value,'');
+ }
+
+ /**
+ * Get the numberic value for this control.
+ * This method is required by {@link IDataRenderer}.
+ * It is the same as {@link getValue()}.
+ * @return string number
+ * @see getValue
+ * @since 3.1.2
+ */
+ public function getData()
+ {
+ return $this->getValue();
+ }
+
+ /**
+ * Set the numberic value for this control.
+ * This method is required by {@link IDataRenderer}.
+ * It is the same as {@link setValue()}.
+ * @param string the number value
+ * @see setValue
+ * @since 3.1.2
+ */
+ public function setData($value)
+ {
+ $this->setValue($value);
+ }
+
+ /**
+ * Get the formatting type for this control.
+ * @return string formatting type.
+ */
+ public function getType()
+ {
+ return $this->getViewState('Type','d');
+ }
+
+ /**
+ * Set the formatting type for this control.
+ * @param string formatting type, either "decimal", "currency","percentage"
+ * or "scientific"
+ * @throws TPropertyTypeInvalidException
+ */
+ public function setType($type)
+ {
+ $type = strtolower($type);
+
+ switch($type)
+ {
+ case 'decimal':
+ $this->setViewState('Type','d',''); break;
+ case 'currency':
+ $this->setViewState('Type','c',''); break;
+ case 'percentage':
+ $this->setViewState('Type','p',''); break;
+ case 'scientific':
+ $this->setViewState('Type','e',''); break;
+ default:
+ throw new TInvalidDataValueException('numberformat_type_invalid',$type);
+ }
+
+ }
+
+ /**
+ * @return string 3 letter currency code. Defaults to 'USD'.
+ */
+ public function getCurrency()
+ {
+ return $this->getViewState('Currency','USD');
+ }
+
+ /**
+ * Set the 3-letter ISO 4217 code. For example, the code
+ * "USD" represents the US Dollar and "EUR" represents the Euro currency.
+ * @param string currency code.
+ */
+ public function setCurrency($currency)
+ {
+ $this->setViewState('Currency', $currency,'');
+ }
+
+ /**
+ * Formats the localized number, be it currency or decimal, or percentage.
+ * If the culture is not specified, the default application
+ * culture will be used.
+ * @return string formatted number
+ */
+ protected function getFormattedValue()
+ {
+ $value = $this->getValue();
+ $defaultText = $this->getDefaultText();
+ if(empty($value) && !empty($defaultText))
+ return $this->getDefaultText();
+
+ $app = $this->getApplication()->getGlobalization();
+ //initialized the default class wide formatter
+ if(self::$formatter===null)
+ self::$formatter = new NumberFormat($app->getCulture());
+
+ $pattern = strlen($this->getPattern()) > 0
+ ? $this->getPattern() : $this->getType();
+
+ $culture = $this->getCulture();
+ //return the specific cultural formatted number
+ if(!empty($culture) && $app->getCulture() != $culture)
+ {
+ $formatter = new NumberFormat($culture);
+ return $formatter->format($this->getValue(),$pattern,
+ $this->getCurrency(),
+ $this->getCharset());
+ }
+
+ //return the application wide culture formatted number.
+ return self::$formatter->format($this->getValue(),$pattern,
+ $this->getCurrency(),
+ $this->getCharset());
+ }
+
+ public function render($writer)
+ {
+ $writer->write($this->getFormattedValue());
+ }
+}
+
+?>
diff --git a/framework/I18N/TTranslate.php b/framework/I18N/TTranslate.php
index 9ecb8a29..2976e8c3 100644
--- a/framework/I18N/TTranslate.php
+++ b/framework/I18N/TTranslate.php
@@ -1,255 +1,255 @@
-<?php
-/**
- * TTranslate, I18N translation component.
- *
- * @author Wei Zhuo <weizhuo[at]gmail[dot]com>
- * @link http://www.pradosoft.com/
- * @copyright Copyright &copy; 2005-2012 PradoSoft
- * @license http://www.pradosoft.com/license/
- * @version $Id$
- * @package System.I18N
- */
-
-/**
- * Get the parent control class.
- */
-Prado::using('System.I18N.TI18NControl');
-
-/**
- * TTranslate class.
- *
- * This component performs message/string translation. The translation
- * source is set in the TGlobalization handler. The following example
- * demonstrated a simple message translation.
- * <code>
- * <com:TTranslate Text="Goodbye" />
- * </code>
- *
- * Depending on the culture set on the page, the phrase "Goodbye" will
- * be translated.
- *
- * The {@link getParameters Parameters} property can be use to add name values pairs for
- * substitution. Substrings enclosed with "{" and "}" in the translation message are consider as the
- * parameter names during substitution lookup. The following example will substitute the substring
- * "{time}" with the value of the parameter attribute "Parameters.time=<%= time() %>. Note that
- * the value of the parameter named "time" is evaluated.
- * <code>
- * <com:TTranslate Parameters.time=<%= time() %> >
- * The unix-time is "{time}".
- * </com:TTranslate>
- * </code>
- *
- * More complex string substitution can be applied using the
- * TTranslateParameter component.
- *
- * Namespace: System.I18N
- *
- * Properties
- * - <b>Text</b>, string,
- * <br>Gets or sets the string to translate.
- * - <b>Catalogue</b>, string,
- * <br>Gets or sets the catalogue for message translation. The
- * default catalogue can be set by the @Page directive.
- * - <b>Key</b>, string,
- * <br>Gets or sets the key used to message look up.
- * - <b>Trim</b>, boolean,
- * <br>Gets or sets an option to trim the contents.
- * Default is to trim the contents.
- *
- * @author Xiang Wei Zhuo <weizhuo[at]gmail[dot]com>
- * @version v1.0, last update on Fri Dec 24 21:38:49 EST 2004
- * @package System.I18N
- */
-class TTranslate extends TI18NControl
-{
- /**
- * @return string the text to be localized/translated.
- */
- public function getText()
- {
- return $this->getViewState('Text','');
- }
-
- /**
- * Sets the text for localization.
- * @param string the text for translation.
- */
- public function setText($value)
- {
- $this->setViewState('Text',$value,'');
- }
-
- /**
- * Set the key for message lookup.
- * @param string key
- */
- public function setKey($value)
- {
- $this->setViewState('Key',$value,'');
- }
-
- /**
- * Get the key for message lookup.
- * @return string key
- */
- public function getKey()
- {
- return $this->getViewState('Key','');
- }
-
- /**
- * Get the message catalogue.
- * @return string catalogue.
- */
- public function getCatalogue()
- {
- return $this->getViewState('Catalogue','');
- }
-
- /**
- * Set the message catalogue.
- * @param string catalogue.
- */
- public function setCatalogue($value)
- {
- $this->setViewState('Catalogue',$value,'');
- }
-
- /**
- * Set the option to trim the contents.
- * @param boolean trim or not.
- */
- public function setTrim($value)
- {
- $this->setViewState('Trim',TPropertyValue::ensureBoolean($value),true);
- }
-
- /**
- * Trim the content or not.
- * @return boolean trim or not.
- */
- public function getTrim()
- {
- return $this->getViewState('Trim',true);
- }
-
- /**
- * Returns the list of custom parameters.
- * Custom parameters are name-value pairs that may subsititute translation
- * place holders during rendering.
- * @return TAttributeCollection the list of custom parameters
- */
- public function getParameters()
- {
- if($parameters=$this->getViewState('Parameters',null))
- return $parameters;
- else
- {
- $parameters=new TAttributeCollection;
- $parameters->setCaseSensitive(true);
- $this->setViewState('Parameters',$parameters,null);
- return $parameters;
- }
- }
-
- /**
- * @return boolean whether the named parameter exists
- */
- public function hasParameter($name)
- {
- if($parameters=$this->getViewState('Parameters',null))
- return $parameters->contains($name);
- else
- return false;
- }
-
- /**
- * @return string parameter value, null if parameter does not exist
- */
- public function getParameter($name)
- {
- if($parameters=$this->getViewState('Parameters',null))
- return $parameters->itemAt($name);
- else
- return null;
- }
-
- /**
- * @param string parameter name
- * @param string value of the parameter
- */
- public function setParameter($name,$value)
- {
- $this->getParameters()->add($name,$value);
- }
-
- /**
- * Removes the named parameter.
- * @param string the name of the parameter to be removed.
- * @return string parameter value removed, null if parameter does not exist.
- */
- public function removeParameter($name)
- {
- if($parameters=$this->getViewState('Parameters',null))
- return $parameters->remove($name);
- else
- return null;
- }
-
- /**
- * renders the translated string.
- */
- public function render($writer)
- {
- $htmlWriter = Prado::createComponent($this->GetResponse()->getHtmlWriterType(), new TTextWriter());
- $subs = array();
- foreach($this->getParameters() as $key => $value)
- $subs['{'.$key.'}'] = $value;
- foreach($this->getControls() as $control)
- {
- if($control instanceof TTranslateParameter)
- $subs['{'.$control->getKey().'}'] = $control->getParameter();
- elseif($control instanceof TControl)
- $control->render($htmlWriter);
- elseif(is_string($control))
- $htmlWriter->write($control);
- }
-
- $text = $this->getText();
- if(strlen($text)==0)
- $text = $htmlWriter->flush();
- if($this->getTrim())
- $text = trim($text);
-
- $writer->write($this->translateText($text, $subs));
- }
-
- /**
- * Translates the text with subsititution.
- * @param string text for translation
- * @param array list of substitutions
- * @return string translated text
- */
- protected function translateText($text, $subs)
- {
- $app = $this->getApplication()->getGlobalization();
-
- //no translation handler provided
- if(($config = $app->getTranslationConfiguration())===null)
- return strtr($text, $subs);
-
- $catalogue = $this->getCatalogue();
- if(empty($catalogue) && isset($config['catalogue']))
- $catalogue = $config['catalogue'];
- if (empty($catalogue)) $catalogue='messages';
- Translation::init($catalogue);
-
- $key = $this->getKey();
- if(!empty($key)) $text = $key;
-
- //translate it
- return Translation::formatter($catalogue)->format($text,
- $subs, $catalogue, $this->getCharset());
- }
-}
-
+<?php
+/**
+ * TTranslate, I18N translation component.
+ *
+ * @author Wei Zhuo <weizhuo[at]gmail[dot]com>
+ * @link http://www.pradosoft.com/
+ * @copyright Copyright &copy; 2005-2012 PradoSoft
+ * @license http://www.pradosoft.com/license/
+ * @version $Id$
+ * @package System.I18N
+ */
+
+/**
+ * Get the parent control class.
+ */
+Prado::using('System.I18N.TI18NControl');
+
+/**
+ * TTranslate class.
+ *
+ * This component performs message/string translation. The translation
+ * source is set in the TGlobalization handler. The following example
+ * demonstrated a simple message translation.
+ * <code>
+ * <com:TTranslate Text="Goodbye" />
+ * </code>
+ *
+ * Depending on the culture set on the page, the phrase "Goodbye" will
+ * be translated.
+ *
+ * The {@link getParameters Parameters} property can be use to add name values pairs for
+ * substitution. Substrings enclosed with "{" and "}" in the translation message are consider as the
+ * parameter names during substitution lookup. The following example will substitute the substring
+ * "{time}" with the value of the parameter attribute "Parameters.time=<%= time() %>. Note that
+ * the value of the parameter named "time" is evaluated.
+ * <code>
+ * <com:TTranslate Parameters.time=<%= time() %> >
+ * The unix-time is "{time}".
+ * </com:TTranslate>
+ * </code>
+ *
+ * More complex string substitution can be applied using the
+ * TTranslateParameter component.
+ *
+ * Namespace: System.I18N
+ *
+ * Properties
+ * - <b>Text</b>, string,
+ * <br>Gets or sets the string to translate.
+ * - <b>Catalogue</b>, string,
+ * <br>Gets or sets the catalogue for message translation. The
+ * default catalogue can be set by the @Page directive.
+ * - <b>Key</b>, string,
+ * <br>Gets or sets the key used to message look up.
+ * - <b>Trim</b>, boolean,
+ * <br>Gets or sets an option to trim the contents.
+ * Default is to trim the contents.
+ *
+ * @author Xiang Wei Zhuo <weizhuo[at]gmail[dot]com>
+ * @version v1.0, last update on Fri Dec 24 21:38:49 EST 2004
+ * @package System.I18N
+ */
+class TTranslate extends TI18NControl
+{
+ /**
+ * @return string the text to be localized/translated.
+ */
+ public function getText()
+ {
+ return $this->getViewState('Text','');
+ }
+
+ /**
+ * Sets the text for localization.
+ * @param string the text for translation.
+ */
+ public function setText($value)
+ {
+ $this->setViewState('Text',$value,'');
+ }
+
+ /**
+ * Set the key for message lookup.
+ * @param string key
+ */
+ public function setKey($value)
+ {
+ $this->setViewState('Key',$value,'');
+ }
+
+ /**
+ * Get the key for message lookup.
+ * @return string key
+ */
+ public function getKey()
+ {
+ return $this->getViewState('Key','');
+ }
+
+ /**
+ * Get the message catalogue.
+ * @return string catalogue.
+ */
+ public function getCatalogue()
+ {
+ return $this->getViewState('Catalogue','');
+ }
+
+ /**
+ * Set the message catalogue.
+ * @param string catalogue.
+ */
+ public function setCatalogue($value)
+ {
+ $this->setViewState('Catalogue',$value,'');
+ }
+
+ /**
+ * Set the option to trim the contents.
+ * @param boolean trim or not.
+ */
+ public function setTrim($value)
+ {
+ $this->setViewState('Trim',TPropertyValue::ensureBoolean($value),true);
+ }
+
+ /**
+ * Trim the content or not.
+ * @return boolean trim or not.
+ */
+ public function getTrim()
+ {
+ return $this->getViewState('Trim',true);
+ }
+
+ /**
+ * Returns the list of custom parameters.
+ * Custom parameters are name-value pairs that may subsititute translation
+ * place holders during rendering.
+ * @return TAttributeCollection the list of custom parameters
+ */
+ public function getParameters()
+ {
+ if($parameters=$this->getViewState('Parameters',null))
+ return $parameters;
+ else
+ {
+ $parameters=new TAttributeCollection;
+ $parameters->setCaseSensitive(true);
+ $this->setViewState('Parameters',$parameters,null);
+ return $parameters;
+ }
+ }
+
+ /**
+ * @return boolean whether the named parameter exists
+ */
+ public function hasParameter($name)
+ {
+ if($parameters=$this->getViewState('Parameters',null))
+ return $parameters->contains($name);
+ else
+ return false;
+ }
+
+ /**
+ * @return string parameter value, null if parameter does not exist
+ */
+ public function getParameter($name)
+ {
+ if($parameters=$this->getViewState('Parameters',null))
+ return $parameters->itemAt($name);
+ else
+ return null;
+ }
+
+ /**
+ * @param string parameter name
+ * @param string value of the parameter
+ */
+ public function setParameter($name,$value)
+ {
+ $this->getParameters()->add($name,$value);
+ }
+
+ /**
+ * Removes the named parameter.
+ * @param string the name of the parameter to be removed.
+ * @return string parameter value removed, null if parameter does not exist.
+ */
+ public function removeParameter($name)
+ {
+ if($parameters=$this->getViewState('Parameters',null))
+ return $parameters->remove($name);
+ else
+ return null;
+ }
+
+ /**
+ * renders the translated string.
+ */
+ public function render($writer)
+ {
+ $htmlWriter = Prado::createComponent($this->GetResponse()->getHtmlWriterType(), new TTextWriter());
+ $subs = array();
+ foreach($this->getParameters() as $key => $value)
+ $subs['{'.$key.'}'] = $value;
+ foreach($this->getControls() as $control)
+ {
+ if($control instanceof TTranslateParameter)
+ $subs['{'.$control->getKey().'}'] = $control->getParameter();
+ elseif($control instanceof TControl)
+ $control->render($htmlWriter);
+ elseif(is_string($control))
+ $htmlWriter->write($control);
+ }
+
+ $text = $this->getText();
+ if(strlen($text)==0)
+ $text = $htmlWriter->flush();
+ if($this->getTrim())
+ $text = trim($text);
+
+ $writer->write($this->translateText($text, $subs));
+ }
+
+ /**
+ * Translates the text with subsititution.
+ * @param string text for translation
+ * @param array list of substitutions
+ * @return string translated text
+ */
+ protected function translateText($text, $subs)
+ {
+ $app = $this->getApplication()->getGlobalization();
+
+ //no translation handler provided
+ if(($config = $app->getTranslationConfiguration())===null)
+ return strtr($text, $subs);
+
+ $catalogue = $this->getCatalogue();
+ if(empty($catalogue) && isset($config['catalogue']))
+ $catalogue = $config['catalogue'];
+ if (empty($catalogue)) $catalogue='messages';
+ Translation::init($catalogue);
+
+ $key = $this->getKey();
+ if(!empty($key)) $text = $key;
+
+ //translate it
+ return Translation::formatter($catalogue)->format($text,
+ $subs, $catalogue, $this->getCharset());
+ }
+}
+
diff --git a/framework/I18N/TTranslateParameter.php b/framework/I18N/TTranslateParameter.php
index c54f6ab1..6ac6617c 100644
--- a/framework/I18N/TTranslateParameter.php
+++ b/framework/I18N/TTranslateParameter.php
@@ -1,119 +1,119 @@
-<?php
-/**
- * TTranslateParameter component.
- *
- * @author Wei Zhuo <weizhuo[at]gmail[dot]com>
- * @link http://www.pradosoft.com/
+<?php
+/**
+ * TTranslateParameter component.
+ *
+ * @author Wei Zhuo <weizhuo[at]gmail[dot]com>
+ * @link http://www.pradosoft.com/
* @copyright Copyright &copy; 2005-2012 PradoSoft
- * @license http://www.pradosoft.com/license/
- * @version $Id$
- * @package System.I18N
- */
-
-/**
- * TTranslateParameter component should be used inside the TTranslate component to
- * allow parameter substitution.
- *
- * For example, the strings "{greeting}" and "{name}" will be replace
- * with the values of "Hello" and "World", respectively.
- * The substitution string must be enclose with "{" and "}".
- * The parameters can be further translated by using TTranslate.
- * <code>
- * <com:TTranslate>
- * {greeting} {name}!
- * <com:TTranslateParameter Key="name">World</com:TTranslateParameter>
- * <com:TTranslateParameter Key="greeting">Hello</com:TTranslateParameter>
- * </com:TTranslate>
- * </code>
- *
- * Namespace: System.I18N
- *
- * Properties
- * - <b>Key</b>, string, <b>required</b>.
- * <br>Gets or sets the string in TTranslate to substitute.
- * - <b>Trim</b>, boolean,
- * <br>Gets or sets an option to trim the contents of the TParam.
- * Default is to trim the contents.
- *
- * @author Xiang Wei Zhuo <weizhuo[at]gmail[dot]com>
- * @version v3.0, last update on Friday, 6 January 2006
- * @package System.I18N
- */
-class TTranslateParameter extends TControl
-{
- /**
- * The substitution key.
- * @var string
- */
- protected $key;
-
- /**
- * To trim or not to trim the contents.
- * @var boolean
- */
- protected $trim = true;
-
-
- /**
- * Get the parameter substitution key.
- * @return string substitution key.
- */
- public function getKey()
- {
- if(empty($this->key))
- throw new TException('The Key property must be specified.');
- return $this->key;
- }
-
- /**
- * Set the parameter substitution key.
- * @param string substitution key.
- */
- public function setKey($value)
- {
- $this->key = $value;
- }
-
- /**
- * Set the option to trim the contents.
- * @param boolean trim or not.
- */
- public function setTrim($value)
- {
- $this->trim = TPropertyValue::ensureBoolean($value);
- }
-
- /**
- * Trim the content or not.
- * @return boolean trim or not.
- */
- public function getTrim()
- {
- return $this->trim;
- }
-
- public function getValue()
- {
- return $this->getViewState('Value', '');
- }
-
- public function setValue($value)
- {
- $this->setViewState('Value', $value, '');
- }
-
- /**
- * @return string parameter contents.
- */
- public function getParameter()
- {
- $value = $this->getValue();
- if(strlen($value) > 0)
- return $value;
- $htmlWriter = Prado::createComponent($this->GetResponse()->getHtmlWriterType(), new TTextWriter());
- $this->renderControl($htmlWriter);
- return $this->getTrim() ?
- trim($htmlWriter->flush()) : $htmlWriter->flush();
- }
-}
-
+ * @license http://www.pradosoft.com/license/
+ * @version $Id$
+ * @package System.I18N
+ */
+
+/**
+ * TTranslateParameter component should be used inside the TTranslate component to
+ * allow parameter substitution.
+ *
+ * For example, the strings "{greeting}" and "{name}" will be replace
+ * with the values of "Hello" and "World", respectively.
+ * The substitution string must be enclose with "{" and "}".
+ * The parameters can be further translated by using TTranslate.
+ * <code>
+ * <com:TTranslate>
+ * {greeting} {name}!
+ * <com:TTranslateParameter Key="name">World</com:TTranslateParameter>
+ * <com:TTranslateParameter Key="greeting">Hello</com:TTranslateParameter>
+ * </com:TTranslate>
+ * </code>
+ *
+ * Namespace: System.I18N
+ *
+ * Properties
+ * - <b>Key</b>, string, <b>required</b>.
+ * <br>Gets or sets the string in TTranslate to substitute.
+ * - <b>Trim</b>, boolean,
+ * <br>Gets or sets an option to trim the contents of the TParam.
+ * Default is to trim the contents.
+ *
+ * @author Xiang Wei Zhuo <weizhuo[at]gmail[dot]com>
+ * @version v3.0, last update on Friday, 6 January 2006
+ * @package System.I18N
+ */
+class TTranslateParameter extends TControl
+{
+ /**
+ * The substitution key.
+ * @var string
+ */
+ protected $key;
+
+ /**
+ * To trim or not to trim the contents.
+ * @var boolean
+ */
+ protected $trim = true;
+
+
+ /**
+ * Get the parameter substitution key.
+ * @return string substitution key.
+ */
+ public function getKey()
+ {
+ if(empty($this->key))
+ throw new TException('The Key property must be specified.');
+ return $this->key;
+ }
+
+ /**
+ * Set the parameter substitution key.
+ * @param string substitution key.
+ */
+ public function setKey($value)
+ {
+ $this->key = $value;
+ }
+
+ /**
+ * Set the option to trim the contents.
+ * @param boolean trim or not.
+ */
+ public function setTrim($value)
+ {
+ $this->trim = TPropertyValue::ensureBoolean($value);
+ }
+
+ /**
+ * Trim the content or not.
+ * @return boolean trim or not.
+ */
+ public function getTrim()
+ {
+ return $this->trim;
+ }
+
+ public function getValue()
+ {
+ return $this->getViewState('Value', '');
+ }
+
+ public function setValue($value)
+ {
+ $this->setViewState('Value', $value, '');
+ }
+
+ /**
+ * @return string parameter contents.
+ */
+ public function getParameter()
+ {
+ $value = $this->getValue();
+ if(strlen($value) > 0)
+ return $value;
+ $htmlWriter = Prado::createComponent($this->GetResponse()->getHtmlWriterType(), new TTextWriter());
+ $this->renderControl($htmlWriter);
+ return $this->getTrim() ?
+ trim($htmlWriter->flush()) : $htmlWriter->flush();
+ }
+}
+
diff --git a/framework/I18N/core/ChoiceFormat.php b/framework/I18N/core/ChoiceFormat.php
index b8eb69f0..dd8e48f8 100644
--- a/framework/I18N/core/ChoiceFormat.php
+++ b/framework/I18N/core/ChoiceFormat.php
@@ -1,226 +1,226 @@
-<?php
-
-/**
- * ChoiceFormat class file.
- *
- * This program is free software; you can redistribute it and/or modify
- * it under the terms of the BSD License.
- *
- * Copyright(c) 2004 by Qiang Xue. All rights reserved.
- *
- * To contact the author write to {@link mailto:qiang.xue@gmail.com Qiang Xue}
- * The latest version of PRADO can be obtained from:
- * {@link http://prado.sourceforge.net/}
- *
- * @author Wei Zhuo <weizhuo[at]gmail[dot]com>
- * @version $Revision: 1.1 $ $Date: 2005/01/11 07:19:39 $
- * @package System.I18N.core
- */
-
-
-/**
- * ChoiceFormat class.
- *
- * ChoiceFormat converts between ranges of numeric values and string
- * names for those ranges.
- *
- * A ChoiceFormat splits the real number line -Inf to +Inf into two or
- * more contiguous ranges. Each range is mapped to a string.
- * ChoiceFormat is generally used in a MessageFormat for displaying
- * grammatically correct plurals such as "There are 2 files."
- *
- * <code>
- * $string = '[0] are no files |[1] is one file |(1,Inf] are {number} files';
- *
- * $formatter = new MessageFormat(...); //init for a source
- * $translated = $formatter->format($string);
- *
- * $choice = new ChoiceFormat();
- * echo $choice->format($translated, 0); //shows "are no files"
- * </code>
- *
- * The message/string choices are separated by the pipe "|" followed
- * by a set notation of the form
- * # <tt>[1,2]</tt> -- accepts values between 1 and 2, inclusive.
- * # <tt>(1,2)</tt> -- accepts values between 1 and 2, excluding 1 and 2.
- * # <tt>{1,2,3,4}</tt> -- only values defined in the set are accepted.
- * # <tt>[-Inf,0)</tt> -- accepts value greater or equal to negative infinity
- * and strictly less than 0
- * Any non-empty combinations of the delimiters of square and round brackets
- * are acceptable.
- *
- * Since version 3.1.2 the following set notation is also possible.
- *
- * # <tt>{n: n % 10 > 1 && n % 10 < 5}</tt> -- matches numbers like 2, 3, 4, 22, 23, 24
- *
- * Where set is defined by the expression after <tt>n:</tt>. In particular, the expression
- * accepts the following mathematical/logical operators to form a set of logical conditions
- * on the value given by <tt>n</tt>:
- * # <tt>&lt;</tt> -- less than.
- * # <tt>&lt;=</tt> -- less than equals.
- * # <tt>&gt;</tt> -- greater than.
- * # <tt>&gt=</tt> -- greater than equals.
- * # <tt>==</tt> -- of equal value.
- * # <tt>%</tt> -- modulo, e.g., 1 % 10 equals 1, 11 % 10 equals 1.
- * # <tt>-</tt> -- minus, negative.
- * # <tt>+</tt> -- addition.
- * # <tt>&amp;</tt> -- conditional AND.
- * # <tt>&amp;&amp;</tt> -- condition AND with short circuit.
- * # <tt>|</tt> -- conditional OR.
- * # <tt>||</tt> -- conditional OR with short circuit.
- * # <tt>!</tt> -- negation.
- *
- * Additional round brackets can also be used to perform grouping.
- *
- * @author Xiang Wei Zhuo <weizhuo[at]gmail[dot]com>
- * @version v1.0, last update on Fri Dec 24 20:46:16 EST 2004
- * @package System.I18N.core
- */
-class ChoiceFormat
-{
- /**
- * The pattern to validate a set notation
- * @var string
- */
- protected $validate = '/[\(\[\{]|[-Inf\d:\s]+|,|[\+Inf\d\s:\?\-=!><%\|&\(\)]+|[\)\]\}]/ms';
-
- /**
- * The pattern to parse the formatting string.
- * @var string
- */
- protected $parse = '/\s*\|?([\(\[\{]([-Inf\d:\s]+,?[\+Inf\d\s:\?\-=!><%\|&\(\)]*)+[\)\]\}])\s*/';
-
- /**
- * The value for positive infinity.
- * @var float
- */
- protected $inf;
-
-
- /**
- * Constructor.
- */
- function __construct()
- {
- $this->inf = -log(0);
- }
-
-
- /**
- * Determine if the given number belongs to a given set
- * @param float the number to test.
- * @param string the set, in set notation.
- * @return boolean true if number is in the set, false otherwise.
- */
- function isValid($number, $set)
- {
- $n = preg_match_all($this->validate,$set,$matches,PREG_SET_ORDER);
-
- if($n < 3) throw new Exception("Invalid set \"{$set}\"");
-
- if(preg_match('/\{\s*n:([^\}]+)\}/', $set, $def))
- {
- return $this->isValidSetNotation($number, $def[1]);
- }
-
- $leftBracket = $matches[0][0];
- $rightBracket = $matches[$n-1][0];
-
- $i = 0;
- $elements = array();
- foreach($matches as $match)
- {
- $string = $match[0];
- if($i != 0 && $i != $n-1 && $string !== ',')
- {
- if($string == '-Inf')
- $elements[] = -1*$this->inf;
- else if ($string == '+Inf' || $string == 'Inf')
- $elements[] = $this->inf;
- else
- $elements[] = floatval($string);
- }
- $i++;
- }
- $total = count($elements);
- $number = floatval($number);
-
- if($leftBracket == '{' && $rightBracket == '}')
- return in_array($number, $elements);
-
- $left = false;
- if($leftBracket == '[')
- $left = $number >= $elements[0];
- else if ($leftBracket == '(')
- $left = $number > $elements[0];
-
- $right = false;
- if($rightBracket==']')
- $right = $number <= $elements[$total-1];
- else if($rightBracket == ')')
- $right = $number < $elements[$total-1];
-
- if($left && $right) return true;
-
- return false;
- }
-
- protected function isValidSetNotation($number, $set)
- {
- $str = '$result = '.str_replace('n', '$number', $set).';';
- try
- {
- eval($str);
- return $result;
- }
- catch(Exception $e)
- {
- return false;
- }
- }
-
- /**
- * Parse a choice string and get a list of sets and a list of strings
- * corresponding to the sets.
- * @param string the string containing the choices
- * @return array array($sets, $strings)
- */
- function parse($string)
- {
- $n = preg_match_all($this->parse,$string,$matches, PREG_OFFSET_CAPTURE);
- $sets = array();
- foreach($matches[1] as $match)
- $sets[] = $match[0];
- $offset = $matches[0];
- $strings = array();
- for($i = 0; $i < $n; $i++)
- {
- $len = strlen($offset[$i][0]);
- $begin = $i == 0? $len : $offset[$i][1] + $len;
- $end = $i == $n-1 ? strlen($string) : $offset[$i+1][1];
- $strings[] = substr($string, $begin, $end - $begin);
- }
- return array($sets, $strings);
- }
-
- /**
- * For the choice string, and a number, find and return the
- * string that satisfied the set within the choices.
- * @param string the choices string.
- * @param float the number to test.
- * @return string the choosen string.
- */
- public function format($string, $number)
- {
- list($sets, $strings) = $this->parse($string);
- $total = count($sets);
- for($i = 0; $i < $total; $i++)
- {
- if($this->isValid($number, $sets[$i]))
- return $strings[$i];
- }
- return false;
- }
-}
-
-?>
+<?php
+
+/**
+ * ChoiceFormat class file.
+ *
+ * This program is free software; you can redistribute it and/or modify
+ * it under the terms of the BSD License.
+ *
+ * Copyright(c) 2004 by Qiang Xue. All rights reserved.
+ *
+ * To contact the author write to {@link mailto:qiang.xue@gmail.com Qiang Xue}
+ * The latest version of PRADO can be obtained from:
+ * {@link http://prado.sourceforge.net/}
+ *
+ * @author Wei Zhuo <weizhuo[at]gmail[dot]com>
+ * @version $Revision: 1.1 $ $Date: 2005/01/11 07:19:39 $
+ * @package System.I18N.core
+ */
+
+
+/**
+ * ChoiceFormat class.
+ *
+ * ChoiceFormat converts between ranges of numeric values and string
+ * names for those ranges.
+ *
+ * A ChoiceFormat splits the real number line -Inf to +Inf into two or
+ * more contiguous ranges. Each range is mapped to a string.
+ * ChoiceFormat is generally used in a MessageFormat for displaying
+ * grammatically correct plurals such as "There are 2 files."
+ *
+ * <code>
+ * $string = '[0] are no files |[1] is one file |(1,Inf] are {number} files';
+ *
+ * $formatter = new MessageFormat(...); //init for a source
+ * $translated = $formatter->format($string);
+ *
+ * $choice = new ChoiceFormat();
+ * echo $choice->format($translated, 0); //shows "are no files"
+ * </code>
+ *
+ * The message/string choices are separated by the pipe "|" followed
+ * by a set notation of the form
+ * # <tt>[1,2]</tt> -- accepts values between 1 and 2, inclusive.
+ * # <tt>(1,2)</tt> -- accepts values between 1 and 2, excluding 1 and 2.
+ * # <tt>{1,2,3,4}</tt> -- only values defined in the set are accepted.
+ * # <tt>[-Inf,0)</tt> -- accepts value greater or equal to negative infinity
+ * and strictly less than 0
+ * Any non-empty combinations of the delimiters of square and round brackets
+ * are acceptable.
+ *
+ * Since version 3.1.2 the following set notation is also possible.
+ *
+ * # <tt>{n: n % 10 > 1 && n % 10 < 5}</tt> -- matches numbers like 2, 3, 4, 22, 23, 24
+ *
+ * Where set is defined by the expression after <tt>n:</tt>. In particular, the expression
+ * accepts the following mathematical/logical operators to form a set of logical conditions
+ * on the value given by <tt>n</tt>:
+ * # <tt>&lt;</tt> -- less than.
+ * # <tt>&lt;=</tt> -- less than equals.
+ * # <tt>&gt;</tt> -- greater than.
+ * # <tt>&gt=</tt> -- greater than equals.
+ * # <tt>==</tt> -- of equal value.
+ * # <tt>%</tt> -- modulo, e.g., 1 % 10 equals 1, 11 % 10 equals 1.
+ * # <tt>-</tt> -- minus, negative.
+ * # <tt>+</tt> -- addition.
+ * # <tt>&amp;</tt> -- conditional AND.
+ * # <tt>&amp;&amp;</tt> -- condition AND with short circuit.
+ * # <tt>|</tt> -- conditional OR.
+ * # <tt>||</tt> -- conditional OR with short circuit.
+ * # <tt>!</tt> -- negation.
+ *
+ * Additional round brackets can also be used to perform grouping.
+ *
+ * @author Xiang Wei Zhuo <weizhuo[at]gmail[dot]com>
+ * @version v1.0, last update on Fri Dec 24 20:46:16 EST 2004
+ * @package System.I18N.core
+ */
+class ChoiceFormat
+{
+ /**
+ * The pattern to validate a set notation
+ * @var string
+ */
+ protected $validate = '/[\(\[\{]|[-Inf\d:\s]+|,|[\+Inf\d\s:\?\-=!><%\|&\(\)]+|[\)\]\}]/ms';
+
+ /**
+ * The pattern to parse the formatting string.
+ * @var string
+ */
+ protected $parse = '/\s*\|?([\(\[\{]([-Inf\d:\s]+,?[\+Inf\d\s:\?\-=!><%\|&\(\)]*)+[\)\]\}])\s*/';
+
+ /**
+ * The value for positive infinity.
+ * @var float
+ */
+ protected $inf;
+
+
+ /**
+ * Constructor.
+ */
+ function __construct()
+ {
+ $this->inf = -log(0);
+ }
+
+
+ /**
+ * Determine if the given number belongs to a given set
+ * @param float the number to test.
+ * @param string the set, in set notation.
+ * @return boolean true if number is in the set, false otherwise.
+ */
+ function isValid($number, $set)
+ {
+ $n = preg_match_all($this->validate,$set,$matches,PREG_SET_ORDER);
+
+ if($n < 3) throw new Exception("Invalid set \"{$set}\"");
+
+ if(preg_match('/\{\s*n:([^\}]+)\}/', $set, $def))
+ {
+ return $this->isValidSetNotation($number, $def[1]);
+ }
+
+ $leftBracket = $matches[0][0];
+ $rightBracket = $matches[$n-1][0];
+
+ $i = 0;
+ $elements = array();
+ foreach($matches as $match)
+ {
+ $string = $match[0];
+ if($i != 0 && $i != $n-1 && $string !== ',')
+ {
+ if($string == '-Inf')
+ $elements[] = -1*$this->inf;
+ else if ($string == '+Inf' || $string == 'Inf')
+ $elements[] = $this->inf;
+ else
+ $elements[] = floatval($string);
+ }
+ $i++;
+ }
+ $total = count($elements);
+ $number = floatval($number);
+
+ if($leftBracket == '{' && $rightBracket == '}')
+ return in_array($number, $elements);
+
+ $left = false;
+ if($leftBracket == '[')
+ $left = $number >= $elements[0];
+ else if ($leftBracket == '(')
+ $left = $number > $elements[0];
+
+ $right = false;
+ if($rightBracket==']')
+ $right = $number <= $elements[$total-1];
+ else if($rightBracket == ')')
+ $right = $number < $elements[$total-1];
+
+ if($left && $right) return true;
+
+ return false;
+ }
+
+ protected function isValidSetNotation($number, $set)
+ {
+ $str = '$result = '.str_replace('n', '$number', $set).';';
+ try
+ {
+ eval($str);
+ return $result;
+ }
+ catch(Exception $e)
+ {
+ return false;
+ }
+ }
+
+ /**
+ * Parse a choice string and get a list of sets and a list of strings
+ * corresponding to the sets.
+ * @param string the string containing the choices
+ * @return array array($sets, $strings)
+ */
+ function parse($string)
+ {
+ $n = preg_match_all($this->parse,$string,$matches, PREG_OFFSET_CAPTURE);
+ $sets = array();
+ foreach($matches[1] as $match)
+ $sets[] = $match[0];
+ $offset = $matches[0];
+ $strings = array();
+ for($i = 0; $i < $n; $i++)
+ {
+ $len = strlen($offset[$i][0]);
+ $begin = $i == 0? $len : $offset[$i][1] + $len;
+ $end = $i == $n-1 ? strlen($string) : $offset[$i+1][1];
+ $strings[] = substr($string, $begin, $end - $begin);
+ }
+ return array($sets, $strings);
+ }
+
+ /**
+ * For the choice string, and a number, find and return the
+ * string that satisfied the set within the choices.
+ * @param string the choices string.
+ * @param float the number to test.
+ * @return string the choosen string.
+ */
+ public function format($string, $number)
+ {
+ list($sets, $strings) = $this->parse($string);
+ $total = count($sets);
+ for($i = 0; $i < $total; $i++)
+ {
+ if($this->isValid($number, $sets[$i]))
+ return $strings[$i];
+ }
+ return false;
+ }
+}
+
+?>
diff --git a/framework/I18N/core/CultureInfo.php b/framework/I18N/core/CultureInfo.php
index 18aae74d..799ccdb4 100644
--- a/framework/I18N/core/CultureInfo.php
+++ b/framework/I18N/core/CultureInfo.php
@@ -1,632 +1,632 @@
-<?php
-
-/**
- * CultureInfo class file.
- *
- * This program is free software; you can redistribute it and/or modify
- * it under the terms of the BSD License.
- *
- * Copyright(c) 2004 by Qiang Xue. All rights reserved.
- *
- * To contact the author write to {@link mailto:qiang.xue@gmail.com Qiang Xue}
- * The latest version of PRADO can be obtained from:
- * {@link http://prado.sourceforge.net/}
- *
- * @author Wei Zhuo <weizhuo[at]gmail[dot]com>
- * @version $Id$
- * @package System.I18N.core
- */
-
-/**
- * CultureInfo class.
- *
- * Represents information about a specific culture including the
- * names of the culture, the calendar used, as well as access to
- * culture-specific objects that provide methods for common operations,
- * such as formatting dates, numbers, and currency.
- *
- * The CultureInfo class holds culture-specific information, such as the
- * associated language, sublanguage, country/region, calendar, and cultural
- * conventions. This class also provides access to culture-specific
- * instances of DateTimeFormatInfo and NumberFormatInfo. These objects
- * contain the information required for culture-specific operations,
- * such as formatting dates, numbers and currency.
- *
- * The culture names follow the format "<languagecode>_<country/regioncode>",
- * where <languagecode> is a lowercase two-letter code derived from ISO 639
- * codes. You can find a full list of the ISO-639 codes at
- * http://www.ics.uci.edu/pub/ietf/http/related/iso639.txt
- *
- * The <country/regioncode2> is an uppercase two-letter code derived from
- * ISO 3166. A copy of ISO-3166 can be found at
- * http://www.chemie.fu-berlin.de/diverse/doc/ISO_3166.html
- *
- * For example, Australian English is "en_AU".
- *
- * @author Xiang Wei Zhuo <weizhuo[at]gmail[dot]com>
- * @version $Id$
- * @package System.I18N.core
- */
-class CultureInfo
-{
- /**
- * ICU data filename extension.
- * @var string
- */
- private $dataFileExt = '.dat';
-
- /**
- * The ICU data array.
- * @var array
- */
- private $data = array();
-
- /**
- * The current culture.
- * @var string
- */
- private $culture;
-
- /**
- * Directory where the ICU data is stored.
- * @var string
- */
- private $dataDir;
-
- /**
- * A list of ICU date files loaded.
- * @var array
- */
- private $dataFiles = array();
-
- /**
- * The current date time format info.
- * @var DateTimeFormatInfo
- */
- private $dateTimeFormat;
-
- /**
- * The current number format info.
- * @var NumberFormatInfo
- */
- private $numberFormat;
-
- /**
- * A list of properties that are accessable/writable.
- * @var array
- */
- protected $properties = array();
-
- /**
- * Culture type, all.
- * @see getCultures()
- * @var int
- */
- const ALL = 0;
-
- /**
- * Culture type, neutral.
- * @see getCultures()
- * @var int
- */
- const NEUTRAL = 1;
-
- /**
- * Culture type, specific.
- * @see getCultures()
- * @var int
- */
- const SPECIFIC = 2;
-
- /**
- * Display the culture name.
- * @return string the culture name.
- * @see getName()
- */
- function __toString()
- {
- return $this->getName();
- }
-
-
- /**
- * Allow functions that begins with 'set' to be called directly
- * as an attribute/property to retrieve the value.
- * @return mixed
- */
- function __get($name)
- {
- $getProperty = 'get'.$name;
- if(in_array($getProperty, $this->properties))
- return $this->$getProperty();
- else
- throw new Exception('Property '.$name.' does not exists.');
- }
-
- /**
- * Allow functions that begins with 'set' to be called directly
- * as an attribute/property to set the value.
- */
- function __set($name, $value)
- {
- $setProperty = 'set'.$name;
- if(in_array($setProperty, $this->properties))
- $this->$setProperty($value);
- else
- throw new Exception('Property '.$name.' can not be set.');
- }
-
-
- /**
- * Initializes a new instance of the CultureInfo class based on the
- * culture specified by name. E.g. <code>new CultureInfo('en_AU');</cdoe>
- * The culture indentifier must be of the form
- * "language_(country/region/variant)".
- * @param string a culture name, e.g. "en_AU".
- * @return return new CultureInfo.
- */
- function __construct($culture='en')
- {
- $this->properties = get_class_methods($this);
-
- if(empty($culture))
- $culture = 'en';
-
- $this->dataDir = $this->dataDir();
- $this->dataFileExt = $this->fileExt();
-
- $this->setCulture($culture);
-
- $this->loadCultureData('root');
- $this->loadCultureData($culture);
- }
-
- /**
- * Get the default directory for the ICU data.
- * The default is the "data" directory for this class.
- * @return string directory containing the ICU data.
- */
- protected static function dataDir()
- {
- return dirname(__FILE__).'/data/';
- }
-
- /**
- * Get the filename extension for ICU data. Default is ".dat".
- * @return string filename extension for ICU data.
- */
- protected static function fileExt()
- {
- return '.dat';
- }
-
- /**
- * Gets the CultureInfo that for this culture string
- * @return CultureInfo invariant culture info is "en".
- */
- public static function getInstance($culture)
- {
- static $instances = array();
- if(!isset($instances[$culture]))
- $instances[$culture] = new CultureInfo($culture);
- return $instances[$culture];
- }
-
- /**
- * Determine if a given culture is valid. Simply checks that the
- * culture data exists.
- * @param string a culture
- * @return boolean true if valid, false otherwise.
- */
- public static function validCulture($culture)
- {
- if(preg_match('/^[_\\w]+$/', $culture))
- return is_file(self::dataDir().$culture.self::fileExt());
-
- return false;
- }
-
- /**
- * Set the culture for the current instance. The culture indentifier
- * must be of the form "<language>_(country/region)".
- * @param string culture identifier, e.g. "fr_FR_EURO".
- */
- protected function setCulture($culture)
- {
- if(!empty($culture))
- {
- if (!preg_match('/^[_\\w]+$/', $culture))
- throw new Exception('Invalid culture supplied: ' . $culture);
- }
-
- $this->culture = $culture;
- }
-
- /**
- * Load the ICU culture data for the specific culture identifier.
- * @param string the culture identifier.
- */
- protected function loadCultureData($culture)
- {
- $file_parts = explode('_',$culture);
- $current_part = $file_parts[0];
-
- $files = array($current_part);
-
- for($i = 1, $k = count($file_parts); $i < $k; ++$i)
- {
- $current_part .= '_'.$file_parts[$i];
- $files[] = $current_part;
- }
-
- foreach($files as $file)
- {
- $filename = $this->dataDir.$file.$this->dataFileExt;
-
- if(is_file($filename) == false)
- throw new Exception('Data file for "'.$file.'" was not found.');
-
- if(in_array($filename, $this->dataFiles) === false)
- {
- array_unshift($this->dataFiles, $file);
-
- $data = &$this->getData($filename);
- $this->data[$file] = &$data;
-
- if(isset($data['__ALIAS']))
- $this->loadCultureData($data['__ALIAS'][0]);
- unset($data);
- }
- }
- }
-
- /**
- * Get the data by unserializing the ICU data from disk.
- * The data files are cached in a static variable inside
- * this function.
- * @param string the ICU data filename
- * @return array ICU data
- */
- protected function &getData($filename)
- {
- static $data = array();
- static $files = array();
-
- if(!in_array($filename, $files))
- {
- $data[$filename] = unserialize(file_get_contents($filename));
- $files[] = $filename;
- }
-
- return $data[$filename];
- }
-
- /**
- * Find the specific ICU data information from the data.
- * The path to the specific ICU data is separated with a slash "/".
- * E.g. To find the default calendar used by the culture, the path
- * "calendar/default" will return the corresponding default calendar.
- * Use merge=true to return the ICU including the parent culture.
- * E.g. The currency data for a variant, say "en_AU" contains one
- * entry, the currency for AUD, the other currency data are stored
- * in the "en" data file. Thus to retrieve all the data regarding
- * currency for "en_AU", you need to use findInfo("Currencies,true);.
- * @param string the data you want to find.
- * @param boolean merge the data from its parents.
- * @return mixed the specific ICU data.
- */
- protected function findInfo($path='/', $merge=false)
- {
- $result = array();
- foreach($this->dataFiles as $section)
- {
- $info = $this->searchArray($this->data[$section], $path);
-
- if($info)
- {
- if($merge)
- $result = array_merge($info,$result);
- else
- return $info;
- }
- }
-
- return $result;
- }
-
- /**
- * Search the array for a specific value using a path separated using
- * slash "/" separated path. e.g to find $info['hello']['world'],
- * the path "hello/world" will return the corresponding value.
- * @param array the array for search
- * @param string slash "/" separated array path.
- * @return mixed the value array using the path
- */
- private function searchArray($info, $path='/')
- {
- $index = explode('/',$path);
-
- $array = $info;
-
- for($i = 0, $k = count($index); $i < $k; ++$i)
- {
- $value = $index[$i];
- if($i < $k-1 && isset($array[$value]))
- $array = $array[$value];
- else if ($i == $k-1 && isset($array[$value]))
- return $array[$value];
- }
- }
-
- /**
- * Gets the culture name in the format
- * "<languagecode2>_(country/regioncode2)".
- * @return string culture name.
- */
- function getName()
- {
- return $this->culture;
- }
-
- /**
- * Gets the DateTimeFormatInfo that defines the culturally appropriate
- * format of displaying dates and times.
- * @return DateTimeFormatInfo date time format information for the culture.
- */
- function getDateTimeFormat()
- {
- if($this->dateTimeFormat === null)
- {
- $calendar = $this->getCalendar();
- $info = $this->findInfo("calendar/{$calendar}", true);
- $this->setDateTimeFormat(new DateTimeFormatInfo($info));
- }
-
- return $this->dateTimeFormat;
- }
-
- /**
- * Set the date time format information.
- * @param DateTimeFormatInfo the new date time format info.
- */
- function setDateTimeFormat($dateTimeFormat)
- {
- $this->dateTimeFormat = $dateTimeFormat;
- }
-
- /**
- * Gets the default calendar used by the culture, e.g. "gregorian".
- * @return string the default calendar.
- */
- function getCalendar()
- {
- $info = $this->findInfo('calendar/default');
- return $info[0];
- }
-
- /**
- * Gets the culture name in the language that the culture is set
- * to display. Returns <code>array('Language','Country');</code>
- * 'Country' is omitted if the culture is neutral.
- * @return array array with language and country as elements, localized.
- */
- function getNativeName()
- {
- $lang = substr($this->culture,0,2);
- $reg = substr($this->culture,3,2);
- $language = $this->findInfo("Languages/{$lang}");
- $region = $this->findInfo("Countries/{$reg}");
- if($region)
- return $language[0].' ('.$region[0].')';
- else
- return $language[0];
- }
-
- /**
- * Gets the culture name in English.
- * Returns <code>array('Language','Country');</code>
- * 'Country' is omitted if the culture is neutral.
- * @return string language (country), it may locale code string if english name does not exist.
- */
- function getEnglishName()
- {
- $lang = substr($this->culture,0,2);
- $reg = substr($this->culture,3,2);
- $culture = $this->getInvariantCulture();
-
- $language = $culture->findInfo("Languages/{$lang}");
- if(count($language) == 0)
- return $this->culture;
-
- $region = $culture->findInfo("Countries/{$reg}");
- if($region)
- return $language[0].' ('.$region[0].')';
- else
- return $language[0];
- }
-
- /**
- * Gets the CultureInfo that is culture-independent (invariant).
- * Any changes to the invariant culture affects all other
- * instances of the invariant culture.
- * The invariant culture is assumed to be "en";
- * @return CultureInfo invariant culture info is "en".
- */
- static function getInvariantCulture()
- {
- static $invariant;
- if($invariant === null)
- $invariant = new CultureInfo();
- return $invariant;
- }
-
- /**
- * Gets a value indicating whether the current CultureInfo
- * represents a neutral culture. Returns true if the culture
- * only contains two characters.
- * @return boolean true if culture is neutral, false otherwise.
- */
- function getIsNeutralCulture()
- {
- return strlen($this->culture) == 2;
- }
-
- /**
- * Gets the NumberFormatInfo that defines the culturally appropriate
- * format of displaying numbers, currency, and percentage.
- * @return NumberFormatInfo the number format info for current culture.
- */
- function getNumberFormat()
- {
- if($this->numberFormat === null)
- {
- $elements = $this->findInfo('NumberElements');
- $patterns = $this->findInfo('NumberPatterns');
- $currencies = $this->getCurrencies();
- $data = array( 'NumberElements'=>$elements,
- 'NumberPatterns'=>$patterns,
- 'Currencies' => $currencies);
-
- $this->setNumberFormat(new NumberFormatInfo($data));
- }
- return $this->numberFormat;
- }
-
- /**
- * Set the number format information.
- * @param NumberFormatInfo the new number format info.
- */
- function setNumberFormat($numberFormat)
- {
- $this->numberFormat = $numberFormat;
- }
-
- /**
- * Gets the CultureInfo that represents the parent culture of the
- * current CultureInfo
- * @return CultureInfo parent culture information.
- */
- function getParent()
- {
- if(strlen($this->culture) == 2)
- return $this->getInvariantCulture();
-
- $lang = substr($this->culture,0,2);
- return new CultureInfo($lang);
- }
-
- /**
- * Gets the list of supported cultures filtered by the specified
- * culture type. This is an EXPENSIVE function, it needs to traverse
- * a list of ICU files in the data directory.
- * This function can be called statically.
- * @param int culture type, CultureInfo::ALL, CultureInfo::NEUTRAL
- * or CultureInfo::SPECIFIC.
- * @return array list of culture information available.
- */
- static function getCultures($type=CultureInfo::ALL)
- {
- $dataDir = CultureInfo::dataDir();
- $dataExt = CultureInfo::fileExt();
- $dir = dir($dataDir);
-
- $neutral = array();
- $specific = array();
-
- while (false !== ($entry = $dir->read()))
- {
- if(is_file($dataDir.$entry)
- && substr($entry,-4) == $dataExt
- && $entry != 'root'.$dataExt)
- {
- $culture = substr($entry,0,-4);
- if(strlen($culture) == 2)
- $neutral[] = $culture;
- else
- $specific[] = $culture;
- }
- }
- $dir->close();
-
- switch($type)
- {
- case CultureInfo::ALL :
- $all = array_merge($neutral, $specific);
- sort($all);
- return $all;
- break;
- case CultureInfo::NEUTRAL :
- return $neutral;
- break;
- case CultureInfo::SPECIFIC :
- return $specific;
- break;
- }
- }
-
- /**
- * Simplify a single element array into its own value.
- * E.g. <code>array(0 => array('hello'), 1 => 'world');</code>
- * becomes <code>array(0 => 'hello', 1 => 'world');</code>
- * @param array with single elements arrays
- * @return array simplified array.
- */
- private function simplify($array)
- {
- for($i = 0, $k = count($array); $i<$k; ++$i)
- {
- $key = key($array);
- if(is_array($array[$key])
- && count($array[$key]) == 1)
- $array[$key] = $array[$key][0];
- next($array);
- }
- return $array;
- }
-
- /**
- * Get a list of countries in the language of the localized version.
- * @return array a list of localized country names.
- */
- function getCountries()
- {
- return $this->simplify($this->findInfo('Countries',true));
- }
-
- /**
- * Get a list of currencies in the language of the localized version.
- * @return array a list of localized currencies.
- */
- function getCurrencies()
- {
- return $this->findInfo('Currencies',true);
- }
-
- /**
- * Get a list of languages in the language of the localized version.
- * @return array list of localized language names.
- */
- function getLanguages()
- {
- return $this->simplify($this->findInfo('Languages',true));
- }
-
- /**
- * Get a list of scripts in the language of the localized version.
- * @return array list of localized script names.
- */
- function getScripts()
- {
- return $this->simplify($this->findInfo('Scripts',true));
- }
-
- /**
- * Get a list of timezones in the language of the localized version.
- * @return array list of localized timezones.
- */
- function getTimeZones()
- {
- return $this->simplify($this->findInfo('zoneStrings',true));
- }
-}
-
+<?php
+
+/**
+ * CultureInfo class file.
+ *
+ * This program is free software; you can redistribute it and/or modify
+ * it under the terms of the BSD License.
+ *
+ * Copyright(c) 2004 by Qiang Xue. All rights reserved.
+ *
+ * To contact the author write to {@link mailto:qiang.xue@gmail.com Qiang Xue}
+ * The latest version of PRADO can be obtained from:
+ * {@link http://prado.sourceforge.net/}
+ *
+ * @author Wei Zhuo <weizhuo[at]gmail[dot]com>
+ * @version $Id$
+ * @package System.I18N.core
+ */
+
+/**
+ * CultureInfo class.
+ *
+ * Represents information about a specific culture including the
+ * names of the culture, the calendar used, as well as access to
+ * culture-specific objects that provide methods for common operations,
+ * such as formatting dates, numbers, and currency.
+ *
+ * The CultureInfo class holds culture-specific information, such as the
+ * associated language, sublanguage, country/region, calendar, and cultural
+ * conventions. This class also provides access to culture-specific
+ * instances of DateTimeFormatInfo and NumberFormatInfo. These objects
+ * contain the information required for culture-specific operations,
+ * such as formatting dates, numbers and currency.
+ *
+ * The culture names follow the format "<languagecode>_<country/regioncode>",
+ * where <languagecode> is a lowercase two-letter code derived from ISO 639
+ * codes. You can find a full list of the ISO-639 codes at
+ * http://www.ics.uci.edu/pub/ietf/http/related/iso639.txt
+ *
+ * The <country/regioncode2> is an uppercase two-letter code derived from
+ * ISO 3166. A copy of ISO-3166 can be found at
+ * http://www.chemie.fu-berlin.de/diverse/doc/ISO_3166.html
+ *
+ * For example, Australian English is "en_AU".
+ *
+ * @author Xiang Wei Zhuo <weizhuo[at]gmail[dot]com>
+ * @version $Id$
+ * @package System.I18N.core
+ */
+class CultureInfo
+{
+ /**
+ * ICU data filename extension.
+ * @var string
+ */
+ private $dataFileExt = '.dat';
+
+ /**
+ * The ICU data array.
+ * @var array
+ */
+ private $data = array();
+
+ /**
+ * The current culture.
+ * @var string
+ */
+ private $culture;
+
+ /**
+ * Directory where the ICU data is stored.
+ * @var string
+ */
+ private $dataDir;
+
+ /**
+ * A list of ICU date files loaded.
+ * @var array
+ */
+ private $dataFiles = array();
+
+ /**
+ * The current date time format info.
+ * @var DateTimeFormatInfo
+ */
+ private $dateTimeFormat;
+
+ /**
+ * The current number format info.
+ * @var NumberFormatInfo
+ */
+ private $numberFormat;
+
+ /**
+ * A list of properties that are accessable/writable.
+ * @var array
+ */
+ protected $properties = array();
+
+ /**
+ * Culture type, all.
+ * @see getCultures()
+ * @var int
+ */
+ const ALL = 0;
+
+ /**
+ * Culture type, neutral.
+ * @see getCultures()
+ * @var int
+ */
+ const NEUTRAL = 1;
+
+ /**
+ * Culture type, specific.
+ * @see getCultures()
+ * @var int
+ */
+ const SPECIFIC = 2;
+
+ /**
+ * Display the culture name.
+ * @return string the culture name.
+ * @see getName()
+ */
+ function __toString()
+ {
+ return $this->getName();
+ }
+
+
+ /**
+ * Allow functions that begins with 'set' to be called directly
+ * as an attribute/property to retrieve the value.
+ * @return mixed
+ */
+ function __get($name)
+ {
+ $getProperty = 'get'.$name;
+ if(in_array($getProperty, $this->properties))
+ return $this->$getProperty();
+ else
+ throw new Exception('Property '.$name.' does not exists.');
+ }
+
+ /**
+ * Allow functions that begins with 'set' to be called directly
+ * as an attribute/property to set the value.
+ */
+ function __set($name, $value)
+ {
+ $setProperty = 'set'.$name;
+ if(in_array($setProperty, $this->properties))
+ $this->$setProperty($value);
+ else
+ throw new Exception('Property '.$name.' can not be set.');
+ }
+
+
+ /**
+ * Initializes a new instance of the CultureInfo class based on the
+ * culture specified by name. E.g. <code>new CultureInfo('en_AU');</cdoe>
+ * The culture indentifier must be of the form
+ * "language_(country/region/variant)".
+ * @param string a culture name, e.g. "en_AU".
+ * @return return new CultureInfo.
+ */
+ function __construct($culture='en')
+ {
+ $this->properties = get_class_methods($this);
+
+ if(empty($culture))
+ $culture = 'en';
+
+ $this->dataDir = $this->dataDir();
+ $this->dataFileExt = $this->fileExt();
+
+ $this->setCulture($culture);
+
+ $this->loadCultureData('root');
+ $this->loadCultureData($culture);
+ }
+
+ /**
+ * Get the default directory for the ICU data.
+ * The default is the "data" directory for this class.
+ * @return string directory containing the ICU data.
+ */
+ protected static function dataDir()
+ {
+ return dirname(__FILE__).'/data/';
+ }
+
+ /**
+ * Get the filename extension for ICU data. Default is ".dat".
+ * @return string filename extension for ICU data.
+ */
+ protected static function fileExt()
+ {
+ return '.dat';
+ }
+
+ /**
+ * Gets the CultureInfo that for this culture string
+ * @return CultureInfo invariant culture info is "en".
+ */
+ public static function getInstance($culture)
+ {
+ static $instances = array();
+ if(!isset($instances[$culture]))
+ $instances[$culture] = new CultureInfo($culture);
+ return $instances[$culture];
+ }
+
+ /**
+ * Determine if a given culture is valid. Simply checks that the
+ * culture data exists.
+ * @param string a culture
+ * @return boolean true if valid, false otherwise.
+ */
+ public static function validCulture($culture)
+ {
+ if(preg_match('/^[_\\w]+$/', $culture))
+ return is_file(self::dataDir().$culture.self::fileExt());
+
+ return false;
+ }
+
+ /**
+ * Set the culture for the current instance. The culture indentifier
+ * must be of the form "<language>_(country/region)".
+ * @param string culture identifier, e.g. "fr_FR_EURO".
+ */
+ protected function setCulture($culture)
+ {
+ if(!empty($culture))
+ {
+ if (!preg_match('/^[_\\w]+$/', $culture))
+ throw new Exception('Invalid culture supplied: ' . $culture);
+ }
+
+ $this->culture = $culture;
+ }
+
+ /**
+ * Load the ICU culture data for the specific culture identifier.
+ * @param string the culture identifier.
+ */
+ protected function loadCultureData($culture)
+ {
+ $file_parts = explode('_',$culture);
+ $current_part = $file_parts[0];
+
+ $files = array($current_part);
+
+ for($i = 1, $k = count($file_parts); $i < $k; ++$i)
+ {
+ $current_part .= '_'.$file_parts[$i];
+ $files[] = $current_part;
+ }
+
+ foreach($files as $file)
+ {
+ $filename = $this->dataDir.$file.$this->dataFileExt;
+
+ if(is_file($filename) == false)
+ throw new Exception('Data file for "'.$file.'" was not found.');
+
+ if(in_array($filename, $this->dataFiles) === false)
+ {
+ array_unshift($this->dataFiles, $file);
+
+ $data = &$this->getData($filename);
+ $this->data[$file] = &$data;
+
+ if(isset($data['__ALIAS']))
+ $this->loadCultureData($data['__ALIAS'][0]);
+ unset($data);
+ }
+ }
+ }
+
+ /**
+ * Get the data by unserializing the ICU data from disk.
+ * The data files are cached in a static variable inside
+ * this function.
+ * @param string the ICU data filename
+ * @return array ICU data
+ */
+ protected function &getData($filename)
+ {
+ static $data = array();
+ static $files = array();
+
+ if(!in_array($filename, $files))
+ {
+ $data[$filename] = unserialize(file_get_contents($filename));
+ $files[] = $filename;
+ }
+
+ return $data[$filename];
+ }
+
+ /**
+ * Find the specific ICU data information from the data.
+ * The path to the specific ICU data is separated with a slash "/".
+ * E.g. To find the default calendar used by the culture, the path
+ * "calendar/default" will return the corresponding default calendar.
+ * Use merge=true to return the ICU including the parent culture.
+ * E.g. The currency data for a variant, say "en_AU" contains one
+ * entry, the currency for AUD, the other currency data are stored
+ * in the "en" data file. Thus to retrieve all the data regarding
+ * currency for "en_AU", you need to use findInfo("Currencies,true);.
+ * @param string the data you want to find.
+ * @param boolean merge the data from its parents.
+ * @return mixed the specific ICU data.
+ */
+ protected function findInfo($path='/', $merge=false)
+ {
+ $result = array();
+ foreach($this->dataFiles as $section)
+ {
+ $info = $this->searchArray($this->data[$section], $path);
+
+ if($info)
+ {
+ if($merge)
+ $result = array_merge($info,$result);
+ else
+ return $info;
+ }
+ }
+
+ return $result;
+ }
+
+ /**
+ * Search the array for a specific value using a path separated using
+ * slash "/" separated path. e.g to find $info['hello']['world'],
+ * the path "hello/world" will return the corresponding value.
+ * @param array the array for search
+ * @param string slash "/" separated array path.
+ * @return mixed the value array using the path
+ */
+ private function searchArray($info, $path='/')
+ {
+ $index = explode('/',$path);
+
+ $array = $info;
+
+ for($i = 0, $k = count($index); $i < $k; ++$i)
+ {
+ $value = $index[$i];
+ if($i < $k-1 && isset($array[$value]))
+ $array = $array[$value];
+ else if ($i == $k-1 && isset($array[$value]))
+ return $array[$value];
+ }
+ }
+
+ /**
+ * Gets the culture name in the format
+ * "<languagecode2>_(country/regioncode2)".
+ * @return string culture name.
+ */
+ function getName()
+ {
+ return $this->culture;
+ }
+
+ /**
+ * Gets the DateTimeFormatInfo that defines the culturally appropriate
+ * format of displaying dates and times.
+ * @return DateTimeFormatInfo date time format information for the culture.
+ */
+ function getDateTimeFormat()
+ {
+ if($this->dateTimeFormat === null)
+ {
+ $calendar = $this->getCalendar();
+ $info = $this->findInfo("calendar/{$calendar}", true);
+ $this->setDateTimeFormat(new DateTimeFormatInfo($info));
+ }
+
+ return $this->dateTimeFormat;
+ }
+
+ /**
+ * Set the date time format information.
+ * @param DateTimeFormatInfo the new date time format info.
+ */
+ function setDateTimeFormat($dateTimeFormat)
+ {
+ $this->dateTimeFormat = $dateTimeFormat;
+ }
+
+ /**
+ * Gets the default calendar used by the culture, e.g. "gregorian".
+ * @return string the default calendar.
+ */
+ function getCalendar()
+ {
+ $info = $this->findInfo('calendar/default');
+ return $info[0];
+ }
+
+ /**
+ * Gets the culture name in the language that the culture is set
+ * to display. Returns <code>array('Language','Country');</code>
+ * 'Country' is omitted if the culture is neutral.
+ * @return array array with language and country as elements, localized.
+ */
+ function getNativeName()
+ {
+ $lang = substr($this->culture,0,2);
+ $reg = substr($this->culture,3,2);
+ $language = $this->findInfo("Languages/{$lang}");
+ $region = $this->findInfo("Countries/{$reg}");
+ if($region)
+ return $language[0].' ('.$region[0].')';
+ else
+ return $language[0];
+ }
+
+ /**
+ * Gets the culture name in English.
+ * Returns <code>array('Language','Country');</code>
+ * 'Country' is omitted if the culture is neutral.
+ * @return string language (country), it may locale code string if english name does not exist.
+ */
+ function getEnglishName()
+ {
+ $lang = substr($this->culture,0,2);
+ $reg = substr($this->culture,3,2);
+ $culture = $this->getInvariantCulture();
+
+ $language = $culture->findInfo("Languages/{$lang}");
+ if(count($language) == 0)
+ return $this->culture;
+
+ $region = $culture->findInfo("Countries/{$reg}");
+ if($region)
+ return $language[0].' ('.$region[0].')';
+ else
+ return $language[0];
+ }
+
+ /**
+ * Gets the CultureInfo that is culture-independent (invariant).
+ * Any changes to the invariant culture affects all other
+ * instances of the invariant culture.
+ * The invariant culture is assumed to be "en";
+ * @return CultureInfo invariant culture info is "en".
+ */
+ static function getInvariantCulture()
+ {
+ static $invariant;
+ if($invariant === null)
+ $invariant = new CultureInfo();
+ return $invariant;
+ }
+
+ /**
+ * Gets a value indicating whether the current CultureInfo
+ * represents a neutral culture. Returns true if the culture
+ * only contains two characters.
+ * @return boolean true if culture is neutral, false otherwise.
+ */
+ function getIsNeutralCulture()
+ {
+ return strlen($this->culture) == 2;
+ }
+
+ /**
+ * Gets the NumberFormatInfo that defines the culturally appropriate
+ * format of displaying numbers, currency, and percentage.
+ * @return NumberFormatInfo the number format info for current culture.
+ */
+ function getNumberFormat()
+ {
+ if($this->numberFormat === null)
+ {
+ $elements = $this->findInfo('NumberElements');
+ $patterns = $this->findInfo('NumberPatterns');
+ $currencies = $this->getCurrencies();
+ $data = array( 'NumberElements'=>$elements,
+ 'NumberPatterns'=>$patterns,
+ 'Currencies' => $currencies);
+
+ $this->setNumberFormat(new NumberFormatInfo($data));
+ }
+ return $this->numberFormat;
+ }
+
+ /**
+ * Set the number format information.
+ * @param NumberFormatInfo the new number format info.
+ */
+ function setNumberFormat($numberFormat)
+ {
+ $this->numberFormat = $numberFormat;
+ }
+
+ /**
+ * Gets the CultureInfo that represents the parent culture of the
+ * current CultureInfo
+ * @return CultureInfo parent culture information.
+ */
+ function getParent()
+ {
+ if(strlen($this->culture) == 2)
+ return $this->getInvariantCulture();
+
+ $lang = substr($this->culture,0,2);
+ return new CultureInfo($lang);
+ }
+
+ /**
+ * Gets the list of supported cultures filtered by the specified
+ * culture type. This is an EXPENSIVE function, it needs to traverse
+ * a list of ICU files in the data directory.
+ * This function can be called statically.
+ * @param int culture type, CultureInfo::ALL, CultureInfo::NEUTRAL
+ * or CultureInfo::SPECIFIC.
+ * @return array list of culture information available.
+ */
+ static function getCultures($type=CultureInfo::ALL)
+ {
+ $dataDir = CultureInfo::dataDir();
+ $dataExt = CultureInfo::fileExt();
+ $dir = dir($dataDir);
+
+ $neutral = array();
+ $specific = array();
+
+ while (false !== ($entry = $dir->read()))
+ {
+ if(is_file($dataDir.$entry)
+ && substr($entry,-4) == $dataExt
+ && $entry != 'root'.$dataExt)
+ {
+ $culture = substr($entry,0,-4);
+ if(strlen($culture) == 2)
+ $neutral[] = $culture;
+ else
+ $specific[] = $culture;
+ }
+ }
+ $dir->close();
+
+ switch($type)
+ {
+ case CultureInfo::ALL :
+ $all = array_merge($neutral, $specific);
+ sort($all);
+ return $all;
+ break;
+ case CultureInfo::NEUTRAL :
+ return $neutral;
+ break;
+ case CultureInfo::SPECIFIC :
+ return $specific;
+ break;
+ }
+ }
+
+ /**
+ * Simplify a single element array into its own value.
+ * E.g. <code>array(0 => array('hello'), 1 => 'world');</code>
+ * becomes <code>array(0 => 'hello', 1 => 'world');</code>
+ * @param array with single elements arrays
+ * @return array simplified array.
+ */
+ private function simplify($array)
+ {
+ for($i = 0, $k = count($array); $i<$k; ++$i)
+ {
+ $key = key($array);
+ if(is_array($array[$key])
+ && count($array[$key]) == 1)
+ $array[$key] = $array[$key][0];
+ next($array);
+ }
+ return $array;
+ }
+
+ /**
+ * Get a list of countries in the language of the localized version.
+ * @return array a list of localized country names.
+ */
+ function getCountries()
+ {
+ return $this->simplify($this->findInfo('Countries',true));
+ }
+
+ /**
+ * Get a list of currencies in the language of the localized version.
+ * @return array a list of localized currencies.
+ */
+ function getCurrencies()
+ {
+ return $this->findInfo('Currencies',true);
+ }
+
+ /**
+ * Get a list of languages in the language of the localized version.
+ * @return array list of localized language names.
+ */
+ function getLanguages()
+ {
+ return $this->simplify($this->findInfo('Languages',true));
+ }
+
+ /**
+ * Get a list of scripts in the language of the localized version.
+ * @return array list of localized script names.
+ */
+ function getScripts()
+ {
+ return $this->simplify($this->findInfo('Scripts',true));
+ }
+
+ /**
+ * Get a list of timezones in the language of the localized version.
+ * @return array list of localized timezones.
+ */
+ function getTimeZones()
+ {
+ return $this->simplify($this->findInfo('zoneStrings',true));
+ }
+}
+
diff --git a/framework/I18N/core/DateFormat.php b/framework/I18N/core/DateFormat.php
index 7724a480..27c9d3c6 100644
--- a/framework/I18N/core/DateFormat.php
+++ b/framework/I18N/core/DateFormat.php
@@ -1,652 +1,652 @@
-<?php
-/**
- * DateFormat class file.
- *
- * This program is free software; you can redistribute it and/or modify
- * it under the terms of the BSD License.
- *
- * Copyright(c) 2004 by Qiang Xue. All rights reserved.
- *
- * To contact the author write to {@link mailto:qiang.xue@gmail.com Qiang Xue}
- * The latest version of PRADO can be obtained from:
- * {@link http://prado.sourceforge.net/}
- *
- * @author Wei Zhuo <weizhuo[at]gmail[dot]com>
- * @version $Revision: 1.8 $ $Date: 2005/12/15 07:14:49 $
- * @package System.I18N.core
- */
-
-/**
- * Get the DateTimeFormatInfo class.
- */
-require_once(dirname(__FILE__).'/DateTimeFormatInfo.php');
-
-/**
- * Get the encoding utilities
- */
-require_once(dirname(__FILE__).'/util.php');
-
-/**
- * DateFormat class.
- *
- * The DateFormat class allows you to format dates and times with
- * predefined styles in a locale-sensitive manner. Formatting times
- * with the DateFormat class is similar to formatting dates.
- *
- * Formatting dates with the DateFormat class is a two-step process.
- * First, you create a formatter with the getDateInstance method.
- * Second, you invoke the format method, which returns a string containing
- * the formatted date.
- *
- * DateTime values are formatted using standard or custom patterns stored
- * in the properties of a DateTimeFormatInfo.
- *
- * @author Xiang Wei Zhuo <weizhuo[at]gmail[dot]com>
- * @version v1.0, last update on Sat Dec 04 14:10:49 EST 2004
- * @package System.I18N.core
- */
-class DateFormat
-{
- /**
- * A list of tokens and their function call.
- * @var array
- */
- protected $tokens = array(
- 'G'=>'Era',
- 'y'=>'Year',
- 'M'=>'Month',
- 'd'=>'Day',
- 'h'=>'Hour12',
- 'H'=>'Hour24',
- 'm'=>'Minutes',
- 's'=>'Seconds',
- 'E'=>'DayInWeek',
- 'D'=>'DayInYear',
- 'F'=>'DayInMonth',
- 'w'=>'WeekInYear',
- 'W'=>'WeekInMonth',
- 'a'=>'AMPM',
- 'k'=>'HourInDay',
- 'K'=>'HourInAMPM',
- 'z'=>'TimeZone'
- );
-
- /**
- * A list of methods, to be used by the token function calls.
- * @var array
- */
- protected $methods = array();
-
- /**
- * The DateTimeFormatInfo, containing culture specific patterns and names.
- * @var DateTimeFormatInfo
- */
- protected $formatInfo;
-
- /**
- * Initialize a new DateFormat.
- * @param mixed either, null, a CultureInfo instance,
- * a DateTimeFormatInfo instance, or a locale.
- * @return DateFormat instance
- */
- function __construct($formatInfo=null)
- {
- if($formatInfo === null)
- $this->formatInfo = DateTimeFormatInfo::getInvariantInfo();
- else if($formatInfo instanceof CultureInfo)
- $this->formatInfo = $formatInfo->DateTimeFormat;
- else if($formatInfo instanceof DateTimeFormatInfo)
- $this->formatInfo = $formatInfo;
- else
- $this->formatInfo = DateTimeFormatInfo::getInstance($formatInfo);
-
- $this->methods = get_class_methods($this);
- }
-
- /**
- * Format a date according to the pattern.
- * @param mixed the time as integer or string in strtotime format.
- * @return string formatted date time.
- */
- public function format($time, $pattern='F', $charset='UTF-8')
- {
- if (is_numeric($time)) //assumes unix epoch
- $time = floatval($time);
- else if(is_string($time))
- $time = @strtotime($time);
-
- if($pattern === null)
- $pattern = 'F';
-
- $s = Prado::createComponent('System.Util.TDateTimeStamp');
-
- $date = $s->getDate($time);
-
- $pattern = $this->getPattern($pattern);
-
- $tokens = $this->getTokens($pattern);
-
- for($i = 0, $k = count($tokens); $i<$k; ++$i)
- {
- $pattern = $tokens[$i];
- if($pattern{0} == "'"
- && $pattern{strlen($pattern)-1} == "'")
- {
- $sub = preg_replace('/(^\')|(\'$)/','',$pattern);
- $tokens[$i] = str_replace('``````','\'',$sub);
- }
- else if($pattern == '``````')
- {
- $tokens[$i] = '\'';
- }
- else
- {
- $function = $this->getFunctionName($pattern);
- if($function != null)
- {
- $fName = 'get'.$function;
- if(in_array($fName, $this->methods))
- {
- $rs = $this->$fName($date, $pattern);
- $tokens[$i] = $rs;
- }
- else
- throw new
- Exception('function '.$function.' not found.');
- }
- }
- }
-
- return I18N_toEncoding(implode('',$tokens), $charset);
- }
-
- /**
- * For a particular token, get the corresponding function to call.
- * @param string token
- * @return mixed the function if good token, null otherwise.
- */
- protected function getFunctionName($token)
- {
- if(isset($this->tokens[$token{0}]))
- return $this->tokens[$token{0}];
- }
-
- /**
- * Get the pattern from DateTimeFormatInfo or some predefined patterns.
- * If the $pattern parameter is an array of 2 element, it will assume
- * that the first element is the date, and second the time
- * and try to find an appropriate pattern and apply
- * DateTimeFormatInfo::formatDateTime
- * See the tutorial documentation for futher details on the patterns.
- * @param mixed a pattern.
- * @return string a pattern.
- * @see DateTimeFormatInfo::formatDateTime()
- */
- protected function getPattern($pattern)
- {
- if(is_array($pattern) && count($pattern) == 2)
- {
- return $this->formatInfo->formatDateTime(
- $this->getPattern($pattern[0]),
- $this->getPattern($pattern[1]));
- }
-
- switch($pattern)
- {
- case 'd':
- return $this->formatInfo->ShortDatePattern;
- break;
- case 'D':
- return $this->formatInfo->LongDatePattern;
- break;
- case 'p':
- return $this->formatInfo->MediumDatePattern;
- break;
- case 'P':
- return $this->formatInfo->FullDatePattern;
- break;
- case 't':
- return $this->formatInfo->ShortTimePattern;
- break;
- case 'T':
- return $this->formatInfo->LongTimePattern;
- break;
- case 'q':
- return $this->formatInfo->MediumTimePattern;
- break;
- case 'Q':
- return $this->formatInfo->FullTimePattern;
- break;
- case 'f':
- return $this->formatInfo->formatDateTime(
- $this->formatInfo->LongDatePattern,
- $this->formatInfo->ShortTimePattern);
- break;
- case 'F':
- return $this->formatInfo->formatDateTime(
- $this->formatInfo->LongDatePattern,
- $this->formatInfo->LongTimePattern);
- break;
- case 'g':
- return $this->formatInfo->formatDateTime(
- $this->formatInfo->ShortDatePattern,
- $this->formatInfo->ShortTimePattern);
- break;
- case 'G':
- return $this->formatInfo->formatDateTime(
- $this->formatInfo->ShortDatePattern,
- $this->formatInfo->LongTimePattern);
- break;
- case 'M':
- case 'm':
- return 'MMMM dd';
- break;
- case 'R':
- case 'r':
- return 'EEE, dd MMM yyyy HH:mm:ss';
- break;
- case 's':
- return 'yyyy-MM-ddTHH:mm:ss';
- break;
- case 'u':
- return 'yyyy-MM-dd HH:mm:ss z';
- break;
- case 'U':
- return 'EEEE dd MMMM yyyy HH:mm:ss';
- break;
- case 'Y':
- case 'y':
- return 'yyyy MMMM';
- break;
- default :
- return $pattern;
- }
- }
-
- /**
- * Tokenize the pattern. The tokens are delimited by group of
- * similar characters, e.g. 'aabb' will form 2 tokens of 'aa' and 'bb'.
- * Any substrings, starting and ending with a single quote (')
- * will be treated as a single token.
- * @param string pattern.
- * @return array string tokens in an array.
- */
- protected function getTokens($pattern)
- {
- $char = null;
- $tokens = array();
- $token = null;
-
- $text = false;
- $pattern = preg_replace("/''/", '``````', $pattern);
-
- for($i = 0; $i < strlen($pattern); $i++)
- {
- if($char==null || $pattern{$i} == $char || $text)
- {
- $token .= $pattern{$i};
- }
- else
- {
- $tokens[] = str_replace("","'",$token);
- $token = $pattern{$i};
- }
-
- if($pattern{$i} == "'" && $text == false)
- $text = true;
- else if($text && $pattern{$i} == "'" && $char == "'")
- $text = true;
- else if($text && $char != "'" && $pattern{$i} == "'")
- $text = false;
-
- $char = $pattern{$i};
-
- }
- $tokens[] = $token;
- return $tokens;
- }
-
- /**
- * Get the year.
- * "yy" will return the last two digits of year.
- * "yyyy" will return the full integer year.
- * @param array getdate format.
- * @param string a pattern.
- * @return string year
- */
- protected function getYear($date, $pattern='yyyy')
- {
- $year = $date['year'];
- switch($pattern)
- {
- case 'yy':
- return substr($year,2);
- case 'yyyy':
- return $year;
- default:
- throw new Exception('The pattern for year is either "yy" or "yyyy".');
- }
- }
-
- /**
- * Get the month.
- * "M" will return integer 1 through 12
- * "MM" will return the narrow month name, e.g. "J"
- * "MMM" will return the abrreviated month name, e.g. "Jan"
- * "MMMM" will return the month name, e.g. "January"
- * @param array getdate format.
- * @param string a pattern.
- * @return string month name
- */
- protected function getMonth($date, $pattern='M')
- {
- $month = $date['mon'];
-
- switch($pattern)
- {
- case 'M':
- return $month;
- case 'MM':
- return str_pad($month, 2,'0',STR_PAD_LEFT);
- case 'MMM':
- return $this->formatInfo->AbbreviatedMonthNames[$month-1];
- break;
- case 'MMMM':
- return $this->formatInfo->MonthNames[$month-1];
- default:
- throw new Exception('The pattern for month '.
- 'is "M", "MM", "MMM", or "MMMM".');
- }
- }
-
- /**
- * Get the day of the week.
- * "E" will return integer 0 (for Sunday) through 6 (for Saturday).
- * "EE" will return the narrow day of the week, e.g. "M"
- * "EEE" will return the abrreviated day of the week, e.g. "Mon"
- * "EEEE" will return the day of the week, e.g. "Monday"
- * @param array getdate format.
- * @param string a pattern.
- * @return string day of the week.
- */
- protected function getDayInWeek($date, $pattern='EEEE')
- {
- $day = $date['wday'];
-
- switch($pattern)
- {
- case 'E':
- return $day;
- break;
- case 'EE':
- return $this->formatInfo->NarrowDayNames[$day];
- case 'EEE':
- return $this->formatInfo->AbbreviatedDayNames[$day];
- break;
- case 'EEEE':
- return $this->formatInfo->DayNames[$day];
- break;
- default:
- throw new Exception('The pattern for day of the week '.
- 'is "E", "EE", "EEE", or "EEEE".');
- }
- }
-
- /**
- * Get the day of the month.
- * "d" for non-padding, "dd" will always return 2 characters.
- * @param array getdate format.
- * @param string a pattern.
- * @return string day of the month
- */
- protected function getDay($date, $pattern='d')
- {
- $day = $date['mday'];
-
- switch($pattern)
- {
- case 'd':
- return $day;
- case 'dd':
- return str_pad($day, 2,'0',STR_PAD_LEFT);
- default:
- throw new Exception('The pattern for day of '.
- 'the month is "d" or "dd".');
- }
- }
-
-
- /**
- * Get the era. i.e. in gregorian, year > 0 is AD, else BC.
- * @todo How to support multiple Eras?, e.g. Japanese.
- * @param array getdate format.
- * @param string a pattern.
- * @return string era
- */
- protected function getEra($date, $pattern='G')
- {
-
- if($pattern != 'G')
- throw new Exception('The pattern for era is "G".');
-
- $year = $date['year'];
- if($year > 0)
- return $this->formatInfo->getEra(1);
- else
- return $this->formatInfo->getEra(0);
- }
-
- /**
- * Get the hours in 24 hour format, i.e. [0-23].
- * "H" for non-padding, "HH" will always return 2 characters.
- * @param array getdate format.
- * @param string a pattern.
- * @return string hours in 24 hour format.
- */
- protected function getHour24($date, $pattern='H')
- {
- $hour = $date['hours'];
-
- switch($pattern)
- {
- case 'H':
- return $hour;
- case 'HH':
- return str_pad($hour, 2,'0',STR_PAD_LEFT);
- default:
- throw new Exception('The pattern for 24 hour '.
- 'format is "H" or "HH".');
- }
- }
-
- /**
- * Get the AM/PM designator, 12 noon is PM, 12 midnight is AM.
- * @param array getdate format.
- * @param string a pattern.
- * @return string AM or PM designator
- */
- protected function getAMPM($date, $pattern='a')
- {
- if($pattern != 'a')
- throw new Exception('The pattern for AM/PM marker is "a".');
-
- $hour = $date['hours'];
- $ampm = (int)($hour/12);
- return $this->formatInfo->AMPMMarkers[$ampm];
- }
-
- /**
- * Get the hours in 12 hour format.
- * "h" for non-padding, "hh" will always return 2 characters.
- * @param array getdate format.
- * @param string a pattern.
- * @return string hours in 12 hour format.
- */
- protected function getHour12($date, $pattern='h')
- {
- $hour = $date['hours'];
- $hour = ($hour==12|$hour==0)?12:($hour)%12;
-
- switch($pattern)
- {
- case 'h':
- return $hour;
- case 'hh':
- return str_pad($hour, 2,'0',STR_PAD_LEFT);
- default:
- throw new Exception('The pattern for 24 hour '.
- 'format is "H" or "HH".');
- }
- }
-
- /**
- * Get the minutes.
- * "m" for non-padding, "mm" will always return 2 characters.
- * @param array getdate format.
- * @param string a pattern.
- * @return string minutes.
- */
- protected function getMinutes($date, $pattern='m')
- {
- $minutes = $date['minutes'];
-
- switch($pattern)
- {
- case 'm':
- return $minutes;
- case 'mm':
- return str_pad($minutes, 2,'0',STR_PAD_LEFT);
- default:
- throw new Exception('The pattern for minutes is "m" or "mm".');
- }
- }
-
- /**
- * Get the seconds.
- * "s" for non-padding, "ss" will always return 2 characters.
- * @param array getdate format.
- * @param string a pattern.
- * @return string seconds
- */
- protected function getSeconds($date, $pattern='s')
- {
- $seconds = $date['seconds'];
-
- switch($pattern)
- {
- case 's':
- return $seconds;
- case 'ss':
- return str_pad($seconds, 2,'0',STR_PAD_LEFT);
- default:
- throw new Exception('The pattern for seconds is "s" or "ss".');
- }
- }
-
- /**
- * Get the timezone from the server machine.
- * @todo How to get the timezone for a different region?
- * @param array getdate format.
- * @param string a pattern.
- * @return string time zone
- */
- protected function getTimeZone($date, $pattern='z')
- {
- if($pattern != 'z')
- throw new Exception('The pattern for time zone is "z".');
-
- return @date('T', @mktime($date['hours'], $date['minutes'], $date['seconds'], $date['mon'], $date['mday'], $date['year']));
- }
-
- /**
- * Get the day in the year, e.g. [1-366]
- * @param array getdate format.
- * @param string a pattern.
- * @return int hours in AM/PM format.
- */
- protected function getDayInYear($date, $pattern='D')
- {
- if($pattern != 'D')
- throw new Exception('The pattern for day in year is "D".');
-
- return $date['yday'];
- }
-
- /**
- * Get day in the month.
- * @param array getdate format.
- * @param string a pattern.
- * @return int day in month
- */
- protected function getDayInMonth($date, $pattern='FF')
- {
- switch ($pattern) {
- case 'F':
- return @date('j', @mktime(0, 0, 0, $date['mon'], $date['mday'], $date['year']));
- break;
- case 'FF':
- return @date('d', @mktime(0, 0, 0, $date['mon'], $date['mday'], $date['year']));
- break;
- default:
- throw new Exception('The pattern for day in month is "F" or "FF".');
- }
- }
-
- /**
- * Get the week in the year.
- * @param array getdate format.
- * @param string a pattern.
- * @return int week in year
- */
- protected function getWeekInYear($date, $pattern='w')
- {
- if($pattern != 'w')
- throw new Exception('The pattern for week in year is "w".');
-
- return @date('W', @mktime(0, 0, 0, $date['mon'], $date['mday'], $date['year']));
- }
-
- /**
- * Get week in the month.
- * @param array getdate format.
- * @return int week in month
- */
- protected function getWeekInMonth($date, $pattern='W')
- {
- if($pattern != 'W')
- throw new Exception('The pattern for week in month is "W".');
-
- return @date('W', @mktime(0, 0, 0, $date['mon'], $date['mday'], $date['year'])) - date('W', mktime(0, 0, 0, $date['mon'], 1, $date['year']));
- }
-
- /**
- * Get the hours [1-24].
- * @param array getdate format.
- * @param string a pattern.
- * @return int hours [1-24]
- */
- protected function getHourInDay($date, $pattern='k')
- {
- if($pattern != 'k')
- throw new Exception('The pattern for hour in day is "k".');
-
- return $date['hours']+1;
- }
-
- /**
- * Get the hours in AM/PM format, e.g [1-12]
- * @param array getdate format.
- * @param string a pattern.
- * @return int hours in AM/PM format.
- */
- protected function getHourInAMPM($date, $pattern='K')
- {
- if($pattern != 'K')
- throw new Exception('The pattern for hour in AM/PM is "K".');
-
- return ($date['hours']+1)%12;
- }
-
-}
-
-?>
+<?php
+/**
+ * DateFormat class file.
+ *
+ * This program is free software; you can redistribute it and/or modify
+ * it under the terms of the BSD License.
+ *
+ * Copyright(c) 2004 by Qiang Xue. All rights reserved.
+ *
+ * To contact the author write to {@link mailto:qiang.xue@gmail.com Qiang Xue}
+ * The latest version of PRADO can be obtained from:
+ * {@link http://prado.sourceforge.net/}
+ *
+ * @author Wei Zhuo <weizhuo[at]gmail[dot]com>
+ * @version $Revision: 1.8 $ $Date: 2005/12/15 07:14:49 $
+ * @package System.I18N.core
+ */
+
+/**
+ * Get the DateTimeFormatInfo class.
+ */
+require_once(dirname(__FILE__).'/DateTimeFormatInfo.php');
+
+/**
+ * Get the encoding utilities
+ */
+require_once(dirname(__FILE__).'/util.php');
+
+/**
+ * DateFormat class.
+ *
+ * The DateFormat class allows you to format dates and times with
+ * predefined styles in a locale-sensitive manner. Formatting times
+ * with the DateFormat class is similar to formatting dates.
+ *
+ * Formatting dates with the DateFormat class is a two-step process.
+ * First, you create a formatter with the getDateInstance method.
+ * Second, you invoke the format method, which returns a string containing
+ * the formatted date.
+ *
+ * DateTime values are formatted using standard or custom patterns stored
+ * in the properties of a DateTimeFormatInfo.
+ *
+ * @author Xiang Wei Zhuo <weizhuo[at]gmail[dot]com>
+ * @version v1.0, last update on Sat Dec 04 14:10:49 EST 2004
+ * @package System.I18N.core
+ */
+class DateFormat
+{
+ /**
+ * A list of tokens and their function call.
+ * @var array
+ */
+ protected $tokens = array(
+ 'G'=>'Era',
+ 'y'=>'Year',
+ 'M'=>'Month',
+ 'd'=>'Day',
+ 'h'=>'Hour12',
+ 'H'=>'Hour24',
+ 'm'=>'Minutes',
+ 's'=>'Seconds',
+ 'E'=>'DayInWeek',
+ 'D'=>'DayInYear',
+ 'F'=>'DayInMonth',
+ 'w'=>'WeekInYear',
+ 'W'=>'WeekInMonth',
+ 'a'=>'AMPM',
+ 'k'=>'HourInDay',
+ 'K'=>'HourInAMPM',
+ 'z'=>'TimeZone'
+ );
+
+ /**
+ * A list of methods, to be used by the token function calls.
+ * @var array
+ */
+ protected $methods = array();
+
+ /**
+ * The DateTimeFormatInfo, containing culture specific patterns and names.
+ * @var DateTimeFormatInfo
+ */
+ protected $formatInfo;
+
+ /**
+ * Initialize a new DateFormat.
+ * @param mixed either, null, a CultureInfo instance,
+ * a DateTimeFormatInfo instance, or a locale.
+ * @return DateFormat instance
+ */
+ function __construct($formatInfo=null)
+ {
+ if($formatInfo === null)
+ $this->formatInfo = DateTimeFormatInfo::getInvariantInfo();
+ else if($formatInfo instanceof CultureInfo)
+ $this->formatInfo = $formatInfo->DateTimeFormat;
+ else if($formatInfo instanceof DateTimeFormatInfo)
+ $this->formatInfo = $formatInfo;
+ else
+ $this->formatInfo = DateTimeFormatInfo::getInstance($formatInfo);
+
+ $this->methods = get_class_methods($this);
+ }
+
+ /**
+ * Format a date according to the pattern.
+ * @param mixed the time as integer or string in strtotime format.
+ * @return string formatted date time.
+ */
+ public function format($time, $pattern='F', $charset='UTF-8')
+ {
+ if (is_numeric($time)) //assumes unix epoch
+ $time = floatval($time);
+ else if(is_string($time))
+ $time = @strtotime($time);
+
+ if($pattern === null)
+ $pattern = 'F';
+
+ $s = Prado::createComponent('System.Util.TDateTimeStamp');
+
+ $date = $s->getDate($time);
+
+ $pattern = $this->getPattern($pattern);
+
+ $tokens = $this->getTokens($pattern);
+
+ for($i = 0, $k = count($tokens); $i<$k; ++$i)
+ {
+ $pattern = $tokens[$i];
+ if($pattern{0} == "'"
+ && $pattern{strlen($pattern)-1} == "'")
+ {
+ $sub = preg_replace('/(^\')|(\'$)/','',$pattern);
+ $tokens[$i] = str_replace('``````','\'',$sub);
+ }
+ else if($pattern == '``````')
+ {
+ $tokens[$i] = '\'';
+ }
+ else
+ {
+ $function = $this->getFunctionName($pattern);
+ if($function != null)
+ {
+ $fName = 'get'.$function;
+ if(in_array($fName, $this->methods))
+ {
+ $rs = $this->$fName($date, $pattern);
+ $tokens[$i] = $rs;
+ }
+ else
+ throw new
+ Exception('function '.$function.' not found.');
+ }
+ }
+ }
+
+ return I18N_toEncoding(implode('',$tokens), $charset);
+ }
+
+ /**
+ * For a particular token, get the corresponding function to call.
+ * @param string token
+ * @return mixed the function if good token, null otherwise.
+ */
+ protected function getFunctionName($token)
+ {
+ if(isset($this->tokens[$token{0}]))
+ return $this->tokens[$token{0}];
+ }
+
+ /**
+ * Get the pattern from DateTimeFormatInfo or some predefined patterns.
+ * If the $pattern parameter is an array of 2 element, it will assume
+ * that the first element is the date, and second the time
+ * and try to find an appropriate pattern and apply
+ * DateTimeFormatInfo::formatDateTime
+ * See the tutorial documentation for futher details on the patterns.
+ * @param mixed a pattern.
+ * @return string a pattern.
+ * @see DateTimeFormatInfo::formatDateTime()
+ */
+ protected function getPattern($pattern)
+ {
+ if(is_array($pattern) && count($pattern) == 2)
+ {
+ return $this->formatInfo->formatDateTime(
+ $this->getPattern($pattern[0]),
+ $this->getPattern($pattern[1]));
+ }
+
+ switch($pattern)
+ {
+ case 'd':
+ return $this->formatInfo->ShortDatePattern;
+ break;
+ case 'D':
+ return $this->formatInfo->LongDatePattern;
+ break;
+ case 'p':
+ return $this->formatInfo->MediumDatePattern;
+ break;
+ case 'P':
+ return $this->formatInfo->FullDatePattern;
+ break;
+ case 't':
+ return $this->formatInfo->ShortTimePattern;
+ break;
+ case 'T':
+ return $this->formatInfo->LongTimePattern;
+ break;
+ case 'q':
+ return $this->formatInfo->MediumTimePattern;
+ break;
+ case 'Q':
+ return $this->formatInfo->FullTimePattern;
+ break;
+ case 'f':
+ return $this->formatInfo->formatDateTime(
+ $this->formatInfo->LongDatePattern,
+ $this->formatInfo->ShortTimePattern);
+ break;
+ case 'F':
+ return $this->formatInfo->formatDateTime(
+ $this->formatInfo->LongDatePattern,
+ $this->formatInfo->LongTimePattern);
+ break;
+ case 'g':
+ return $this->formatInfo->formatDateTime(
+ $this->formatInfo->ShortDatePattern,
+ $this->formatInfo->ShortTimePattern);
+ break;
+ case 'G':
+ return $this->formatInfo->formatDateTime(
+ $this->formatInfo->ShortDatePattern,
+ $this->formatInfo->LongTimePattern);
+ break;
+ case 'M':
+ case 'm':
+ return 'MMMM dd';
+ break;
+ case 'R':
+ case 'r':
+ return 'EEE, dd MMM yyyy HH:mm:ss';
+ break;
+ case 's':
+ return 'yyyy-MM-ddTHH:mm:ss';
+ break;
+ case 'u':
+ return 'yyyy-MM-dd HH:mm:ss z';
+ break;
+ case 'U':
+ return 'EEEE dd MMMM yyyy HH:mm:ss';
+ break;
+ case 'Y':
+ case 'y':
+ return 'yyyy MMMM';
+ break;
+ default :
+ return $pattern;
+ }
+ }
+
+ /**
+ * Tokenize the pattern. The tokens are delimited by group of
+ * similar characters, e.g. 'aabb' will form 2 tokens of 'aa' and 'bb'.
+ * Any substrings, starting and ending with a single quote (')
+ * will be treated as a single token.
+ * @param string pattern.
+ * @return array string tokens in an array.
+ */
+ protected function getTokens($pattern)
+ {
+ $char = null;
+ $tokens = array();
+ $token = null;
+
+ $text = false;
+ $pattern = preg_replace("/''/", '``````', $pattern);
+
+ for($i = 0; $i < strlen($pattern); $i++)
+ {
+ if($char==null || $pattern{$i} == $char || $text)
+ {
+ $token .= $pattern{$i};
+ }
+ else
+ {
+ $tokens[] = str_replace("","'",$token);
+ $token = $pattern{$i};
+ }
+
+ if($pattern{$i} == "'" && $text == false)
+ $text = true;
+ else if($text && $pattern{$i} == "'" && $char == "'")
+ $text = true;
+ else if($text && $char != "'" && $pattern{$i} == "'")
+ $text = false;
+
+ $char = $pattern{$i};
+
+ }
+ $tokens[] = $token;
+ return $tokens;
+ }
+
+ /**
+ * Get the year.
+ * "yy" will return the last two digits of year.
+ * "yyyy" will return the full integer year.
+ * @param array getdate format.
+ * @param string a pattern.
+ * @return string year
+ */
+ protected function getYear($date, $pattern='yyyy')
+ {
+ $year = $date['year'];
+ switch($pattern)
+ {
+ case 'yy':
+ return substr($year,2);
+ case 'yyyy':
+ return $year;
+ default:
+ throw new Exception('The pattern for year is either "yy" or "yyyy".');
+ }
+ }
+
+ /**
+ * Get the month.
+ * "M" will return integer 1 through 12
+ * "MM" will return the narrow month name, e.g. "J"
+ * "MMM" will return the abrreviated month name, e.g. "Jan"
+ * "MMMM" will return the month name, e.g. "January"
+ * @param array getdate format.
+ * @param string a pattern.
+ * @return string month name
+ */
+ protected function getMonth($date, $pattern='M')
+ {
+ $month = $date['mon'];
+
+ switch($pattern)
+ {
+ case 'M':
+ return $month;
+ case 'MM':
+ return str_pad($month, 2,'0',STR_PAD_LEFT);
+ case 'MMM':
+ return $this->formatInfo->AbbreviatedMonthNames[$month-1];
+ break;
+ case 'MMMM':
+ return $this->formatInfo->MonthNames[$month-1];
+ default:
+ throw new Exception('The pattern for month '.
+ 'is "M", "MM", "MMM", or "MMMM".');
+ }
+ }
+
+ /**
+ * Get the day of the week.
+ * "E" will return integer 0 (for Sunday) through 6 (for Saturday).
+ * "EE" will return the narrow day of the week, e.g. "M"
+ * "EEE" will return the abrreviated day of the week, e.g. "Mon"
+ * "EEEE" will return the day of the week, e.g. "Monday"
+ * @param array getdate format.
+ * @param string a pattern.
+ * @return string day of the week.
+ */
+ protected function getDayInWeek($date, $pattern='EEEE')
+ {
+ $day = $date['wday'];
+
+ switch($pattern)
+ {
+ case 'E':
+ return $day;
+ break;
+ case 'EE':
+ return $this->formatInfo->NarrowDayNames[$day];
+ case 'EEE':
+ return $this->formatInfo->AbbreviatedDayNames[$day];
+ break;
+ case 'EEEE':
+ return $this->formatInfo->DayNames[$day];
+ break;
+ default:
+ throw new Exception('The pattern for day of the week '.
+ 'is "E", "EE", "EEE", or "EEEE".');
+ }
+ }
+
+ /**
+ * Get the day of the month.
+ * "d" for non-padding, "dd" will always return 2 characters.
+ * @param array getdate format.
+ * @param string a pattern.
+ * @return string day of the month
+ */
+ protected function getDay($date, $pattern='d')
+ {
+ $day = $date['mday'];
+
+ switch($pattern)
+ {
+ case 'd':
+ return $day;
+ case 'dd':
+ return str_pad($day, 2,'0',STR_PAD_LEFT);
+ default:
+ throw new Exception('The pattern for day of '.
+ 'the month is "d" or "dd".');
+ }
+ }
+
+
+ /**
+ * Get the era. i.e. in gregorian, year > 0 is AD, else BC.
+ * @todo How to support multiple Eras?, e.g. Japanese.
+ * @param array getdate format.
+ * @param string a pattern.
+ * @return string era
+ */
+ protected function getEra($date, $pattern='G')
+ {
+
+ if($pattern != 'G')
+ throw new Exception('The pattern for era is "G".');
+
+ $year = $date['year'];
+ if($year > 0)
+ return $this->formatInfo->getEra(1);
+ else
+ return $this->formatInfo->getEra(0);
+ }
+
+ /**
+ * Get the hours in 24 hour format, i.e. [0-23].
+ * "H" for non-padding, "HH" will always return 2 characters.
+ * @param array getdate format.
+ * @param string a pattern.
+ * @return string hours in 24 hour format.
+ */
+ protected function getHour24($date, $pattern='H')
+ {
+ $hour = $date['hours'];
+
+ switch($pattern)
+ {
+ case 'H':
+ return $hour;
+ case 'HH':
+ return str_pad($hour, 2,'0',STR_PAD_LEFT);
+ default:
+ throw new Exception('The pattern for 24 hour '.
+ 'format is "H" or "HH".');
+ }
+ }
+
+ /**
+ * Get the AM/PM designator, 12 noon is PM, 12 midnight is AM.
+ * @param array getdate format.
+ * @param string a pattern.
+ * @return string AM or PM designator
+ */
+ protected function getAMPM($date, $pattern='a')
+ {
+ if($pattern != 'a')
+ throw new Exception('The pattern for AM/PM marker is "a".');
+
+ $hour = $date['hours'];
+ $ampm = (int)($hour/12);
+ return $this->formatInfo->AMPMMarkers[$ampm];
+ }
+
+ /**
+ * Get the hours in 12 hour format.
+ * "h" for non-padding, "hh" will always return 2 characters.
+ * @param array getdate format.
+ * @param string a pattern.
+ * @return string hours in 12 hour format.
+ */
+ protected function getHour12($date, $pattern='h')
+ {
+ $hour = $date['hours'];
+ $hour = ($hour==12|$hour==0)?12:($hour)%12;
+
+ switch($pattern)
+ {
+ case 'h':
+ return $hour;
+ case 'hh':
+ return str_pad($hour, 2,'0',STR_PAD_LEFT);
+ default:
+ throw new Exception('The pattern for 24 hour '.
+ 'format is "H" or "HH".');
+ }
+ }
+
+ /**
+ * Get the minutes.
+ * "m" for non-padding, "mm" will always return 2 characters.
+ * @param array getdate format.
+ * @param string a pattern.
+ * @return string minutes.
+ */
+ protected function getMinutes($date, $pattern='m')
+ {
+ $minutes = $date['minutes'];
+
+ switch($pattern)
+ {
+ case 'm':
+ return $minutes;
+ case 'mm':
+ return str_pad($minutes, 2,'0',STR_PAD_LEFT);
+ default:
+ throw new Exception('The pattern for minutes is "m" or "mm".');
+ }
+ }
+
+ /**
+ * Get the seconds.
+ * "s" for non-padding, "ss" will always return 2 characters.
+ * @param array getdate format.
+ * @param string a pattern.
+ * @return string seconds
+ */
+ protected function getSeconds($date, $pattern='s')
+ {
+ $seconds = $date['seconds'];
+
+ switch($pattern)
+ {
+ case 's':
+ return $seconds;
+ case 'ss':
+ return str_pad($seconds, 2,'0',STR_PAD_LEFT);
+ default:
+ throw new Exception('The pattern for seconds is "s" or "ss".');
+ }
+ }
+
+ /**
+ * Get the timezone from the server machine.
+ * @todo How to get the timezone for a different region?
+ * @param array getdate format.
+ * @param string a pattern.
+ * @return string time zone
+ */
+ protected function getTimeZone($date, $pattern='z')
+ {
+ if($pattern != 'z')
+ throw new Exception('The pattern for time zone is "z".');
+
+ return @date('T', @mktime($date['hours'], $date['minutes'], $date['seconds'], $date['mon'], $date['mday'], $date['year']));
+ }
+
+ /**
+ * Get the day in the year, e.g. [1-366]
+ * @param array getdate format.
+ * @param string a pattern.
+ * @return int hours in AM/PM format.
+ */
+ protected function getDayInYear($date, $pattern='D')
+ {
+ if($pattern != 'D')
+ throw new Exception('The pattern for day in year is "D".');
+
+ return $date['yday'];
+ }
+
+ /**
+ * Get day in the month.
+ * @param array getdate format.
+ * @param string a pattern.
+ * @return int day in month
+ */
+ protected function getDayInMonth($date, $pattern='FF')
+ {
+ switch ($pattern) {
+ case 'F':
+ return @date('j', @mktime(0, 0, 0, $date['mon'], $date['mday'], $date['year']));
+ break;
+ case 'FF':
+ return @date('d', @mktime(0, 0, 0, $date['mon'], $date['mday'], $date['year']));
+ break;
+ default:
+ throw new Exception('The pattern for day in month is "F" or "FF".');
+ }
+ }
+
+ /**
+ * Get the week in the year.
+ * @param array getdate format.
+ * @param string a pattern.
+ * @return int week in year
+ */
+ protected function getWeekInYear($date, $pattern='w')
+ {
+ if($pattern != 'w')
+ throw new Exception('The pattern for week in year is "w".');
+
+ return @date('W', @mktime(0, 0, 0, $date['mon'], $date['mday'], $date['year']));
+ }
+
+ /**
+ * Get week in the month.
+ * @param array getdate format.
+ * @return int week in month
+ */
+ protected function getWeekInMonth($date, $pattern='W')
+ {
+ if($pattern != 'W')
+ throw new Exception('The pattern for week in month is "W".');
+
+ return @date('W', @mktime(0, 0, 0, $date['mon'], $date['mday'], $date['year'])) - date('W', mktime(0, 0, 0, $date['mon'], 1, $date['year']));
+ }
+
+ /**
+ * Get the hours [1-24].
+ * @param array getdate format.
+ * @param string a pattern.
+ * @return int hours [1-24]
+ */
+ protected function getHourInDay($date, $pattern='k')
+ {
+ if($pattern != 'k')
+ throw new Exception('The pattern for hour in day is "k".');
+
+ return $date['hours']+1;
+ }
+
+ /**
+ * Get the hours in AM/PM format, e.g [1-12]
+ * @param array getdate format.
+ * @param string a pattern.
+ * @return int hours in AM/PM format.
+ */
+ protected function getHourInAMPM($date, $pattern='K')
+ {
+ if($pattern != 'K')
+ throw new Exception('The pattern for hour in AM/PM is "K".');
+
+ return ($date['hours']+1)%12;
+ }
+
+}
+
+?>
diff --git a/framework/I18N/core/DateTimeFormatInfo.php b/framework/I18N/core/DateTimeFormatInfo.php
index aebd094a..d4deee1f 100644
--- a/framework/I18N/core/DateTimeFormatInfo.php
+++ b/framework/I18N/core/DateTimeFormatInfo.php
@@ -1,516 +1,516 @@
-<?php
-
-/**
- * DateTimeFormatInfo class file.
- *
- * This program is free software; you can redistribute it and/or modify
- * it under the terms of the BSD License.
- *
- * Copyright(c) 2004 by Qiang Xue. All rights reserved.
- *
- * To contact the author write to {@link mailto:qiang.xue@gmail.com Qiang Xue}
- * The latest version of PRADO can be obtained from:
- * {@link http://prado.sourceforge.net/}
- *
- * @author Wei Zhuo <weizhuo[at]gmail[dot]com>
- * @version $Revision: 1.2 $ $Date: 2005/01/05 03:15:14 $
- * @package System.I18N.core
- */
-
-/**
- * Get the CultureInfo class.
- */
-require_once(dirname(__FILE__).'/CultureInfo.php');
-
-
-/**
- * Defines how DateTime values are formatted and displayed, depending
- * on the culture.
- *
- * This class contains information, such as date patterns, time patterns,
- * and AM/PM designators.
- *
- * To create a DateTimeFormatInfo for a specific culture, create a
- * CultureInfo for that culture and retrieve the CultureInfo.DateTimeFormat
- * property. For example:
- * <code>
- * $culture = new CultureInfo('en_AU');
- * $dtfi = $culture->DateTimeFormat;
- * </code>
- *
- * To create a DateTimeFormatInfo for the invariant culture, use
- * <code>
- * DateTimeFormatInfo::getInstance($culture=null);
- * </code>
- * you may pass a CultureInfo parameter $culture to get the DateTimeFormatInfo
- * for a specific culture.
- *
- * DateTime values are formatted using standard or custom patterns stored in
- * the properties of a DateTimeFormatInfo.
- *
- * The standard patterns can be replaced with custom patterns by setting the
- * associated properties of DateTimeFormatInfo.
- *
- * The following table lists the standard format characters for each standard
- * pattern and the associated DateTimeFormatInfo property that can be set to
- * modify the standard pattern. The format characters are case-sensitive;
- * for example, 'g' and 'G' represent slightly different patterns.
- *
- * <code>
- * Format Character Associated Property Example Format Pattern (en-US)
- * --------------------------------------------------------------------------
- * d ShortDatePattern MM/dd/yyyy
- * D LongDatePattern dddd, dd MMMM yyyy
- * F FullDateTimePattern dddd, dd MMMM yyyy HH:mm:ss
- * m, M MonthDayPattern MMMM dd
- * r, R RFC1123Pattern ddd, dd MMM yyyy HH':'mm':'ss 'GMT'
- * s SortableDateTimePattern yyyy'-'MM'-'dd'T'HH':'mm':'ss
- * t ShortTimePattern HH:mm
- * T LongTimePattern HH:mm:ss
- * Y YearMonthPattern yyyy MMMM
- * --------------------------------------------------------------------------
- * </code>
- *
- * @author Xiang Wei Zhuo <weizhuo[at]gmail[dot]com>
- * @version v1.0, last update on Fri Dec 03 22:30:31 EST 2004
- * @package System.I18N.core
- */
-class DateTimeFormatInfo
-{
- /**
- * ICU date time formatting data.
- * @var array
- */
- private $data = array();
-
- /**
- * A list of properties that are accessable/writable.
- * @var array
- */
- protected $properties = array();
-
- /**
- * Allow functions that begins with 'set' to be called directly
- * as an attribute/property to retrieve the value.
- * @return mixed
- */
- function __get($name)
- {
- $getProperty = 'get'.$name;
- if(in_array($getProperty, $this->properties))
- return $this->$getProperty();
- else
- throw new Exception('Property '.$name.' does not exists.');
- }
-
- /**
- * Allow functions that begins with 'set' to be called directly
- * as an attribute/property to set the value.
- */
- function __set($name, $value)
- {
- $setProperty = 'set'.$name;
- if(in_array($setProperty, $this->properties))
- $this->$setProperty($value);
- else
- throw new Exception('Property '.$name.' can not be set.');
- }
-
- /**
- * Initializes a new writable instance of the DateTimeFormatInfo class
- * that is dependent on the ICU data for date time formatting
- * information. <b>N.B.</b>You should not initialize this class directly
- * unless you know what you are doing. Please use use
- * DateTimeFormatInfo::getInstance() to create an instance.
- * @param array ICU data for date time formatting.
- * @see getInstance()
- */
- function __construct($data=array())
- {
- $this->properties = get_class_methods($this);
-
- if(empty($data))
- throw new Exception('Please provide the ICU data to initialize.');
-
- $this->data = $data;
- }
-
- /**
- * Get the internal ICU data for date time formatting.
- * @return array ICU date time formatting data.
- */
- protected function getData()
- {
- return $this->data;
- }
-
- /**
- * Gets the default DateTimeFormatInfo that is culture-independent
- * (invariant).
- * @return DateTimeFormatInfo default DateTimeFormatInfo.
- */
- static function getInvariantInfo()
- {
- static $invariant;
- if($invariant === null)
- {
- $culture = CultureInfo::getInvariantCulture();
- $invariant = $culture->getDateTimeFormat();
- }
- return $invariant;
- }
-
- /**
- * Returns the DateTimeFormatInfo associated with the specified culture.
- * @param CultureInfo the culture that gets the DateTimeFormat property.
- * @return DateTimeFormatInfo DateTimeFormatInfo for the specified
- * culture.
- */
- static function getInstance($culture=null)
- {
-
- if ($culture instanceof CultureInfo)
- return $culture->getDateTimeFormat();
- else if(is_string($culture))
- {
- $cultureInfo = CultureInfo::getInstance($culture);
- return $cultureInfo->getDateTimeFormat();
- }
- else
- {
- $cultureInfo = CultureInfo::getInvariantCulture();
- return $cultureInfo->getDateTimeFormat();
- }
- }
-
- /**
- * A one-dimensional array of type String containing
- * the culture-specific abbreviated names of the days
- * of the week. The array for InvariantInfo contains
- * "Sun", "Mon", "Tue", "Wed", "Thu", "Fri", and "Sat".
- * @return array abbreviated day names
- */
- function getAbbreviatedDayNames()
- {
- return $this->data['dayNames']['format']['abbreviated'];
- //return $this->data['dayNames/format/abbreviated'];
- }
-
- /**
- * Set the abbreviated day names. The value should be
- * an array of string starting with Sunday and ends in Saturady.
- * For example,
- * <code>array("Sun", "Mon", "Tue", "Wed", "Thu", "Fri", "Sat");</code>
- * @param array abbreviated day names.
- */
- function setAbbreviatedDayNames($value)
- {
- $this->data['dayNames']['format']['abbreviated'] = $value;
- }
-
- /**
- * A one-dimensional array of type String containing
- * the culture-specific narrow names of the days
- * of the week. The array for InvariantInfo contains
- * "S", "M", "T", "W", "T", "F", and "S".
- * @return array narrow day names
- */
- function getNarrowDayNames()
- {
- return $this->data['dayNames']['format']['narrow'];
- }
-
- /**
- * Set the narrow day names. The value should be
- * an array of string starting with Sunday and ends in Saturady.
- * For example,
- * <code>array("S", "M", "T", "W", "T", "F", "S");</code>
- * @param array narrow day names.
- */
- function setNarrowDayNames($value)
- {
- $this->data['dayNames']['format']['narrow'] = $value;
- }
-
- /**
- * A one-dimensional array of type String containing the
- * culture-specific full names of the days of the week.
- * The array for InvariantInfo contains "Sunday", "Monday",
- * "Tuesday", "Wednesday", "Thursday", "Friday", and "Saturday".
- * @return array day names
- */
- function getDayNames()
- {
- return $this->data['dayNames']['format']['wide'];
- }
-
-
- /**
- * Set the day names. The value should be
- * an array of string starting with Sunday and ends in Saturady.
- * For example,
- * <code>array("Sunday", "Monday", "Tuesday", "Wednesday", "Thursday",
- * "Friday", "Saturday".);</code>
- * @param array day names.
- */
- function setDayNames($value)
- {
- $this->data['dayNames']['format']['wide'] = $value;
- }
-
- /**
- * A one-dimensional array of type String containing the
- * culture-specific narrow names of the months. The array
- * for InvariantInfo contains "J", "F", "M", "A", "M", "J",
- * "J", "A", "S", "O", "N", and "D".
- * @return array narrow month names.
- */
- function getNarrowMonthNames()
- {
- return $this->data['monthNames']['format']['narrow'];
- }
-
- /**
- * Set the narrow month names. The value should be
- * an array of string starting with J and ends in D.
- * For example,
- * <code>array("J","F","M","A","M","J","J","A","S","O","N","D");</code>
- * @param array month names.
- */
- function setNarrowMonthNames($value)
- {
- $this->data['monthNames']['format']['narrow'] = $value;
- }
-
- /**
- * A one-dimensional array of type String containing the
- * culture-specific abbreviated names of the months. The array
- * for InvariantInfo contains "Jan", "Feb", "Mar", "Apr", "May",
- * "Jun", "Jul", "Aug", "Sep", "Oct", "Nov", and "Dec".
- * Returns wide names if abbreviated names doesn't exist.
- * @return array abbreviated month names.
- */
- function getAbbreviatedMonthNames()
- {
- if (isset($this->data['monthNames']['format']['abbreviated']))
- return $this->data['monthNames']['format']['abbreviated'];
- else
- return $this->data['monthNames']['format']['wide'];
- }
-
- /**
- * Set the abbreviated month names. The value should be
- * an array of string starting with Jan and ends in Dec.
- * For example,
- * <code>array("Jan", "Feb", "Mar", "Apr", "May", "Jun",
- * "Jul", "Aug", "Sep","Oct","Nov","Dec");</code>
- * @param array month names.
- */
- function setAbbreviatedMonthNames($value)
- {
- $this->data['monthNames']['format']['abbreviated'] = $value;
- }
-
- /**
- * A one-dimensional array of type String containing the
- * culture-specific full names of the months. The array for
- * InvariantInfo contains "January", "February", "March", "April",
- * "May", "June", "July", "August", "September", "October", "November",
- * and "December"
- * @return array month names.
- */
- function getMonthNames()
- {
- return $this->data['monthNames']['format']['wide'];
- }
-
- /**
- * Set the month names. The value should be
- * an array of string starting with Janurary and ends in December.
- * For example,
- * <code>array("January", "February", "March", "April", "May", "June",
- * "July", "August", "September","October","November","December");</code>
- * @param array month names.
- */
- function setMonthNames($value)
- {
- $this->data['monthNames']['format']['wide'] = $value;
- }
-
- /**
- * A string containing the name of the era.
- * @param int era The integer representing the era.
- * @return string the era name.
- */
- function getEra($era)
- {
- $eraName = $this->data['eras']['abbreviated'];
- return $eraName[$era];
- }
-
- /**
- * The string designator for hours that are "ante meridiem" (before noon).
- * The default for InvariantInfo is "AM".
- * @return string AM designator.
- */
- function getAMDesignator()
- {
- $result = $this->getAMPMMarkers();
- return $result[0];
- }
-
- /**
- * Set the AM Designator. For example, 'AM'.
- * @param string AM designator.
- */
- function setAMDesignator($value)
- {
- $markers = $this->getAMPMMarkers();
- $markers[0] = $value;
- $this->setAMPMMarkers($markers);
- }
-
- /**
- * The string designator for hours that are "post meridiem" (after noon).
- * The default for InvariantInfo is "PM".
- * @return string PM designator.
- */
- function getPMDesignator()
- {
- $result = $this->getAMPMMarkers();
- return $result[1];
- }
-
- /**
- * Set the PM Designator. For example, 'PM'.
- * @param string PM designator.
- */
- function setPMDesignator($value)
- {
- $markers = $this->getAMPMMarkers();
- $markers[1] = $value;
- $this->setAMPMMarkers($markers);
- }
-
- /**
- * Get the AM and PM markers array.
- * Default InvariantInfo for AM and PM is <code>array('AM','PM');</code>
- * @return array AM and PM markers
- */
- function getAMPMMarkers()
- {
- return $this->data['AmPmMarkers'];
- }
-
- /**
- * Set the AM and PM markers array.
- * For example <code>array('AM','PM');</code>
- * @param array AM and PM markers
- */
- function setAMPMMarkers($value)
- {
- $this->data['AmPmMarkers'] = $value;
- }
-
- /**
- * Returns the full time pattern "HH:mm:ss z" (default).
- * This is culture sensitive.
- * @return string pattern "HH:mm:ss z".
- */
- function getFullTimePattern()
- {
- return $this->data['DateTimePatterns'][0];
- }
-
- /**
- * Returns the long time pattern "HH:mm:ss z" (default).
- * This is culture sensitive.
- * @return string pattern "HH:mm:ss z".
- */
- function getLongTimePattern()
- {
- return $this->data['DateTimePatterns'][1];
- }
-
- /**
- * Returns the medium time pattern "HH:mm:ss" (default).
- * This is culture sensitive.
- * @return string pattern "HH:mm:ss".
- */
- function getMediumTimePattern()
- {
- return $this->data['DateTimePatterns'][2];
- }
-
- /**
- * Returns the short time pattern "HH:mm" (default).
- * This is culture sensitive.
- * @return string pattern "HH:mm".
- */
- function getShortTimePattern()
- {
- return $this->data['DateTimePatterns'][3];
- }
-
- /**
- * Returns the full date pattern "EEEE, yyyy MMMM dd" (default).
- * This is culture sensitive.
- * @return string pattern "EEEE, yyyy MMMM dd".
- */
- function getFullDatePattern()
- {
- return $this->data['DateTimePatterns'][4];
- }
-
- /**
- * Returns the long date pattern "yyyy MMMM d" (default).
- * This is culture sensitive.
- * @return string pattern "yyyy MMMM d".
- */
- function getLongDatePattern()
- {
- return $this->data['DateTimePatterns'][5];
- }
-
- /**
- * Returns the medium date pattern "yyyy MMMM d" (default).
- * This is culture sensitive.
- * @return string pattern "yyyy MMM d".
- */
- function getMediumDatePattern()
- {
- return $this->data['DateTimePatterns'][6];
- }
-
- /**
- * Returns the short date pattern "yy/MM/dd" (default).
- * This is culture sensitive.
- * @return string pattern "yy/MM/dd".
- */
- function getShortDatePattern()
- {
- return $this->data['DateTimePatterns'][7];
- }
-
- /**
- * Returns the date time order pattern, "{1} {0}" (default).
- * This is culture sensitive.
- * @return string pattern "{1} {0}".
- */
- function getDateTimeOrderPattern()
- {
- return $this->data['DateTimePatterns'][8];
- }
-
- /**
- * Formats the date and time in a culture sensitive paterrn.
- * The default is "Date Time".
- * @return string date and time formated
- */
- function formatDateTime($date, $time)
- {
- $pattern = $this->getDateTimeOrderPattern();
- return str_replace(array('{0}','{1}'), array($time, $date), $pattern);
- }
-
-}
+<?php
+
+/**
+ * DateTimeFormatInfo class file.
+ *
+ * This program is free software; you can redistribute it and/or modify
+ * it under the terms of the BSD License.
+ *
+ * Copyright(c) 2004 by Qiang Xue. All rights reserved.
+ *
+ * To contact the author write to {@link mailto:qiang.xue@gmail.com Qiang Xue}
+ * The latest version of PRADO can be obtained from:
+ * {@link http://prado.sourceforge.net/}
+ *
+ * @author Wei Zhuo <weizhuo[at]gmail[dot]com>
+ * @version $Revision: 1.2 $ $Date: 2005/01/05 03:15:14 $
+ * @package System.I18N.core
+ */
+
+/**
+ * Get the CultureInfo class.
+ */
+require_once(dirname(__FILE__).'/CultureInfo.php');
+
+
+/**
+ * Defines how DateTime values are formatted and displayed, depending
+ * on the culture.
+ *
+ * This class contains information, such as date patterns, time patterns,
+ * and AM/PM designators.
+ *
+ * To create a DateTimeFormatInfo for a specific culture, create a
+ * CultureInfo for that culture and retrieve the CultureInfo.DateTimeFormat
+ * property. For example:
+ * <code>
+ * $culture = new CultureInfo('en_AU');
+ * $dtfi = $culture->DateTimeFormat;
+ * </code>
+ *
+ * To create a DateTimeFormatInfo for the invariant culture, use
+ * <code>
+ * DateTimeFormatInfo::getInstance($culture=null);
+ * </code>
+ * you may pass a CultureInfo parameter $culture to get the DateTimeFormatInfo
+ * for a specific culture.
+ *
+ * DateTime values are formatted using standard or custom patterns stored in
+ * the properties of a DateTimeFormatInfo.
+ *
+ * The standard patterns can be replaced with custom patterns by setting the
+ * associated properties of DateTimeFormatInfo.
+ *
+ * The following table lists the standard format characters for each standard
+ * pattern and the associated DateTimeFormatInfo property that can be set to
+ * modify the standard pattern. The format characters are case-sensitive;
+ * for example, 'g' and 'G' represent slightly different patterns.
+ *
+ * <code>
+ * Format Character Associated Property Example Format Pattern (en-US)
+ * --------------------------------------------------------------------------
+ * d ShortDatePattern MM/dd/yyyy
+ * D LongDatePattern dddd, dd MMMM yyyy
+ * F FullDateTimePattern dddd, dd MMMM yyyy HH:mm:ss
+ * m, M MonthDayPattern MMMM dd
+ * r, R RFC1123Pattern ddd, dd MMM yyyy HH':'mm':'ss 'GMT'
+ * s SortableDateTimePattern yyyy'-'MM'-'dd'T'HH':'mm':'ss
+ * t ShortTimePattern HH:mm
+ * T LongTimePattern HH:mm:ss
+ * Y YearMonthPattern yyyy MMMM
+ * --------------------------------------------------------------------------
+ * </code>
+ *
+ * @author Xiang Wei Zhuo <weizhuo[at]gmail[dot]com>
+ * @version v1.0, last update on Fri Dec 03 22:30:31 EST 2004
+ * @package System.I18N.core
+ */
+class DateTimeFormatInfo
+{
+ /**
+ * ICU date time formatting data.
+ * @var array
+ */
+ private $data = array();
+
+ /**
+ * A list of properties that are accessable/writable.
+ * @var array
+ */
+ protected $properties = array();
+
+ /**
+ * Allow functions that begins with 'set' to be called directly
+ * as an attribute/property to retrieve the value.
+ * @return mixed
+ */
+ function __get($name)
+ {
+ $getProperty = 'get'.$name;
+ if(in_array($getProperty, $this->properties))
+ return $this->$getProperty();
+ else
+ throw new Exception('Property '.$name.' does not exists.');
+ }
+
+ /**
+ * Allow functions that begins with 'set' to be called directly
+ * as an attribute/property to set the value.
+ */
+ function __set($name, $value)
+ {
+ $setProperty = 'set'.$name;
+ if(in_array($setProperty, $this->properties))
+ $this->$setProperty($value);
+ else
+ throw new Exception('Property '.$name.' can not be set.');
+ }
+
+ /**
+ * Initializes a new writable instance of the DateTimeFormatInfo class
+ * that is dependent on the ICU data for date time formatting
+ * information. <b>N.B.</b>You should not initialize this class directly
+ * unless you know what you are doing. Please use use
+ * DateTimeFormatInfo::getInstance() to create an instance.
+ * @param array ICU data for date time formatting.
+ * @see getInstance()
+ */
+ function __construct($data=array())
+ {
+ $this->properties = get_class_methods($this);
+
+ if(empty($data))
+ throw new Exception('Please provide the ICU data to initialize.');
+
+ $this->data = $data;
+ }
+
+ /**
+ * Get the internal ICU data for date time formatting.
+ * @return array ICU date time formatting data.
+ */
+ protected function getData()
+ {
+ return $this->data;
+ }
+
+ /**
+ * Gets the default DateTimeFormatInfo that is culture-independent
+ * (invariant).
+ * @return DateTimeFormatInfo default DateTimeFormatInfo.
+ */
+ static function getInvariantInfo()
+ {
+ static $invariant;
+ if($invariant === null)
+ {
+ $culture = CultureInfo::getInvariantCulture();
+ $invariant = $culture->getDateTimeFormat();
+ }
+ return $invariant;
+ }
+
+ /**
+ * Returns the DateTimeFormatInfo associated with the specified culture.
+ * @param CultureInfo the culture that gets the DateTimeFormat property.
+ * @return DateTimeFormatInfo DateTimeFormatInfo for the specified
+ * culture.
+ */
+ static function getInstance($culture=null)
+ {
+
+ if ($culture instanceof CultureInfo)
+ return $culture->getDateTimeFormat();
+ else if(is_string($culture))
+ {
+ $cultureInfo = CultureInfo::getInstance($culture);
+ return $cultureInfo->getDateTimeFormat();
+ }
+ else
+ {
+ $cultureInfo = CultureInfo::getInvariantCulture();
+ return $cultureInfo->getDateTimeFormat();
+ }
+ }
+
+ /**
+ * A one-dimensional array of type String containing
+ * the culture-specific abbreviated names of the days
+ * of the week. The array for InvariantInfo contains
+ * "Sun", "Mon", "Tue", "Wed", "Thu", "Fri", and "Sat".
+ * @return array abbreviated day names
+ */
+ function getAbbreviatedDayNames()
+ {
+ return $this->data['dayNames']['format']['abbreviated'];
+ //return $this->data['dayNames/format/abbreviated'];
+ }
+
+ /**
+ * Set the abbreviated day names. The value should be
+ * an array of string starting with Sunday and ends in Saturady.
+ * For example,
+ * <code>array("Sun", "Mon", "Tue", "Wed", "Thu", "Fri", "Sat");</code>
+ * @param array abbreviated day names.
+ */
+ function setAbbreviatedDayNames($value)
+ {
+ $this->data['dayNames']['format']['abbreviated'] = $value;
+ }
+
+ /**
+ * A one-dimensional array of type String containing
+ * the culture-specific narrow names of the days
+ * of the week. The array for InvariantInfo contains
+ * "S", "M", "T", "W", "T", "F", and "S".
+ * @return array narrow day names
+ */
+ function getNarrowDayNames()
+ {
+ return $this->data['dayNames']['format']['narrow'];
+ }
+
+ /**
+ * Set the narrow day names. The value should be
+ * an array of string starting with Sunday and ends in Saturady.
+ * For example,
+ * <code>array("S", "M", "T", "W", "T", "F", "S");</code>
+ * @param array narrow day names.
+ */
+ function setNarrowDayNames($value)
+ {
+ $this->data['dayNames']['format']['narrow'] = $value;
+ }
+
+ /**
+ * A one-dimensional array of type String containing the
+ * culture-specific full names of the days of the week.
+ * The array for InvariantInfo contains "Sunday", "Monday",
+ * "Tuesday", "Wednesday", "Thursday", "Friday", and "Saturday".
+ * @return array day names
+ */
+ function getDayNames()
+ {
+ return $this->data['dayNames']['format']['wide'];
+ }
+
+
+ /**
+ * Set the day names. The value should be
+ * an array of string starting with Sunday and ends in Saturady.
+ * For example,
+ * <code>array("Sunday", "Monday", "Tuesday", "Wednesday", "Thursday",
+ * "Friday", "Saturday".);</code>
+ * @param array day names.
+ */
+ function setDayNames($value)
+ {
+ $this->data['dayNames']['format']['wide'] = $value;
+ }
+
+ /**
+ * A one-dimensional array of type String containing the
+ * culture-specific narrow names of the months. The array
+ * for InvariantInfo contains "J", "F", "M", "A", "M", "J",
+ * "J", "A", "S", "O", "N", and "D".
+ * @return array narrow month names.
+ */
+ function getNarrowMonthNames()
+ {
+ return $this->data['monthNames']['format']['narrow'];
+ }
+
+ /**
+ * Set the narrow month names. The value should be
+ * an array of string starting with J and ends in D.
+ * For example,
+ * <code>array("J","F","M","A","M","J","J","A","S","O","N","D");</code>
+ * @param array month names.
+ */
+ function setNarrowMonthNames($value)
+ {
+ $this->data['monthNames']['format']['narrow'] = $value;
+ }
+
+ /**
+ * A one-dimensional array of type String containing the
+ * culture-specific abbreviated names of the months. The array
+ * for InvariantInfo contains "Jan", "Feb", "Mar", "Apr", "May",
+ * "Jun", "Jul", "Aug", "Sep", "Oct", "Nov", and "Dec".
+ * Returns wide names if abbreviated names doesn't exist.
+ * @return array abbreviated month names.
+ */
+ function getAbbreviatedMonthNames()
+ {
+ if (isset($this->data['monthNames']['format']['abbreviated']))
+ return $this->data['monthNames']['format']['abbreviated'];
+ else
+ return $this->data['monthNames']['format']['wide'];
+ }
+
+ /**
+ * Set the abbreviated month names. The value should be
+ * an array of string starting with Jan and ends in Dec.
+ * For example,
+ * <code>array("Jan", "Feb", "Mar", "Apr", "May", "Jun",
+ * "Jul", "Aug", "Sep","Oct","Nov","Dec");</code>
+ * @param array month names.
+ */
+ function setAbbreviatedMonthNames($value)
+ {
+ $this->data['monthNames']['format']['abbreviated'] = $value;
+ }
+
+ /**
+ * A one-dimensional array of type String containing the
+ * culture-specific full names of the months. The array for
+ * InvariantInfo contains "January", "February", "March", "April",
+ * "May", "June", "July", "August", "September", "October", "November",
+ * and "December"
+ * @return array month names.
+ */
+ function getMonthNames()
+ {
+ return $this->data['monthNames']['format']['wide'];
+ }
+
+ /**
+ * Set the month names. The value should be
+ * an array of string starting with Janurary and ends in December.
+ * For example,
+ * <code>array("January", "February", "March", "April", "May", "June",
+ * "July", "August", "September","October","November","December");</code>
+ * @param array month names.
+ */
+ function setMonthNames($value)
+ {
+ $this->data['monthNames']['format']['wide'] = $value;
+ }
+
+ /**
+ * A string containing the name of the era.
+ * @param int era The integer representing the era.
+ * @return string the era name.
+ */
+ function getEra($era)
+ {
+ $eraName = $this->data['eras']['abbreviated'];
+ return $eraName[$era];
+ }
+
+ /**
+ * The string designator for hours that are "ante meridiem" (before noon).
+ * The default for InvariantInfo is "AM".
+ * @return string AM designator.
+ */
+ function getAMDesignator()
+ {
+ $result = $this->getAMPMMarkers();
+ return $result[0];
+ }
+
+ /**
+ * Set the AM Designator. For example, 'AM'.
+ * @param string AM designator.
+ */
+ function setAMDesignator($value)
+ {
+ $markers = $this->getAMPMMarkers();
+ $markers[0] = $value;
+ $this->setAMPMMarkers($markers);
+ }
+
+ /**
+ * The string designator for hours that are "post meridiem" (after noon).
+ * The default for InvariantInfo is "PM".
+ * @return string PM designator.
+ */
+ function getPMDesignator()
+ {
+ $result = $this->getAMPMMarkers();
+ return $result[1];
+ }
+
+ /**
+ * Set the PM Designator. For example, 'PM'.
+ * @param string PM designator.
+ */
+ function setPMDesignator($value)
+ {
+ $markers = $this->getAMPMMarkers();
+ $markers[1] = $value;
+ $this->setAMPMMarkers($markers);
+ }
+
+ /**
+ * Get the AM and PM markers array.
+ * Default InvariantInfo for AM and PM is <code>array('AM','PM');</code>
+ * @return array AM and PM markers
+ */
+ function getAMPMMarkers()
+ {
+ return $this->data['AmPmMarkers'];
+ }
+
+ /**
+ * Set the AM and PM markers array.
+ * For example <code>array('AM','PM');</code>
+ * @param array AM and PM markers
+ */
+ function setAMPMMarkers($value)
+ {
+ $this->data['AmPmMarkers'] = $value;
+ }
+
+ /**
+ * Returns the full time pattern "HH:mm:ss z" (default).
+ * This is culture sensitive.
+ * @return string pattern "HH:mm:ss z".
+ */
+ function getFullTimePattern()
+ {
+ return $this->data['DateTimePatterns'][0];
+ }
+
+ /**
+ * Returns the long time pattern "HH:mm:ss z" (default).
+ * This is culture sensitive.
+ * @return string pattern "HH:mm:ss z".
+ */
+ function getLongTimePattern()
+ {
+ return $this->data['DateTimePatterns'][1];
+ }
+
+ /**
+ * Returns the medium time pattern "HH:mm:ss" (default).
+ * This is culture sensitive.
+ * @return string pattern "HH:mm:ss".
+ */
+ function getMediumTimePattern()
+ {
+ return $this->data['DateTimePatterns'][2];
+ }
+
+ /**
+ * Returns the short time pattern "HH:mm" (default).
+ * This is culture sensitive.
+ * @return string pattern "HH:mm".
+ */
+ function getShortTimePattern()
+ {
+ return $this->data['DateTimePatterns'][3];
+ }
+
+ /**
+ * Returns the full date pattern "EEEE, yyyy MMMM dd" (default).
+ * This is culture sensitive.
+ * @return string pattern "EEEE, yyyy MMMM dd".
+ */
+ function getFullDatePattern()
+ {
+ return $this->data['DateTimePatterns'][4];
+ }
+
+ /**
+ * Returns the long date pattern "yyyy MMMM d" (default).
+ * This is culture sensitive.
+ * @return string pattern "yyyy MMMM d".
+ */
+ function getLongDatePattern()
+ {
+ return $this->data['DateTimePatterns'][5];
+ }
+
+ /**
+ * Returns the medium date pattern "yyyy MMMM d" (default).
+ * This is culture sensitive.
+ * @return string pattern "yyyy MMM d".
+ */
+ function getMediumDatePattern()
+ {
+ return $this->data['DateTimePatterns'][6];
+ }
+
+ /**
+ * Returns the short date pattern "yy/MM/dd" (default).
+ * This is culture sensitive.
+ * @return string pattern "yy/MM/dd".
+ */
+ function getShortDatePattern()
+ {
+ return $this->data['DateTimePatterns'][7];
+ }
+
+ /**
+ * Returns the date time order pattern, "{1} {0}" (default).
+ * This is culture sensitive.
+ * @return string pattern "{1} {0}".
+ */
+ function getDateTimeOrderPattern()
+ {
+ return $this->data['DateTimePatterns'][8];
+ }
+
+ /**
+ * Formats the date and time in a culture sensitive paterrn.
+ * The default is "Date Time".
+ * @return string date and time formated
+ */
+ function formatDateTime($date, $time)
+ {
+ $pattern = $this->getDateTimeOrderPattern();
+ return str_replace(array('{0}','{1}'), array($time, $date), $pattern);
+ }
+
+}
diff --git a/framework/I18N/core/Gettext/MO.php b/framework/I18N/core/Gettext/MO.php
index 2a97aee7..4b34034e 100644
--- a/framework/I18N/core/Gettext/MO.php
+++ b/framework/I18N/core/Gettext/MO.php
@@ -1,355 +1,355 @@
-<?php
-/**
- * TGettext_MO class file.
- *
- * This program is free software; you can redistribute it and/or modify
- * it under the terms of the BSD License.
- *
- * Copyright(c) 2004 by Qiang Xue. All rights reserved.
- *
- * To contact the author write to {@link mailto:qiang.xue@gmail.com Qiang Xue}
- * The latest version of PRADO can be obtained from:
- * {@link http://prado.sourceforge.net/}
- *
- * @author Wei Zhuo <weizhuo[at]gmail[dot]com>
- * @version $Revision: 1.3 $ $Date: 2005/08/27 03:21:12 $
- * @package System.I18N.core
- */
-
-
-// +----------------------------------------------------------------------+
-// | PEAR :: File :: Gettext :: MO |
-// +----------------------------------------------------------------------+
-// | This source file is subject to version 3.0 of the PHP license, |
-// | that is available at http://www.php.net/license/3_0.txt |
-// | If you did not receive a copy of the PHP license and are unable |
-// | to obtain it through the world-wide-web, please send a note to |
-// | license@php.net so we can mail you a copy immediately. |
-// +----------------------------------------------------------------------+
-// | Copyright (c) 2004 Michael Wallner <mike@iworks.at> |
-// +----------------------------------------------------------------------+
-//
-// $Id$
-
-/**
- * File::Gettext::MO
- *
- * @author Michael Wallner <mike@php.net>
- * @license PHP License
- */
-
-require_once dirname(__FILE__).'/TGettext.php';
-
-/**
- * File_Gettext_MO
- *
- * GNU MO file reader and writer.
- *
- * @author Michael Wallner <mike@php.net>
- * @version $Revision: 1.3 $
- * @access public
- * @package System.I18N.core
- */
-class TGettext_MO extends TGettext
-{
- /**
- * file handle
- *
- * @access private
- * @var resource
- */
- protected $_handle = null;
-
- /**
- * big endianess
- *
- * Whether to write with big endian byte order.
- *
- * @access public
- * @var bool
- */
- protected $writeBigEndian = false;
-
- /**
- * Constructor
- *
- * @access public
- * @return object File_Gettext_MO
- * @param string $file path to GNU MO file
- */
- function TGettext_MO($file = '')
- {
- $this->file = $file;
- }
-
- /**
- * _read
- *
- * @access private
- * @return mixed
- * @param int $bytes
- */
- function _read($bytes = 1)
- {
- if (0 < $bytes = abs($bytes)) {
- return fread($this->_handle, $bytes);
- }
- return null;
- }
-
- /**
- * _readInt
- *
- * @access private
- * @return int
- * @param bool $bigendian
- */
- function _readInt($bigendian = false)
- {
- //unpack returns a reference????
- $unpacked = unpack($bigendian ? 'N' : 'V', $this->_read(4));
- return array_shift($unpacked);
- }
-
- /**
- * _writeInt
- *
- * @access private
- * @return int
- * @param int $int
- */
- function _writeInt($int)
- {
- return $this->_write(pack($this->writeBigEndian ? 'N' : 'V', (int) $int));
- }
-
- /**
- * _write
- *
- * @access private
- * @return int
- * @param string $data
- */
- function _write($data)
- {
- return fwrite($this->_handle, $data);
- }
-
- /**
- * _writeStr
- *
- * @access private
- * @return int
- * @param string $string
- */
- function _writeStr($string)
- {
- return $this->_write($string . "\0");
- }
-
- /**
- * _readStr
- *
- * @access private
- * @return string
- * @param array $params associative array with offset and length
- * of the string
- */
- function _readStr($params)
- {
- fseek($this->_handle, $params['offset']);
- return $this->_read($params['length']);
- }
-
- /**
- * Load MO file
- *
- * @access public
- * @return mixed Returns true on success or PEAR_Error on failure.
- * @param string $file
- */
- function load($file = null)
- {
- if (!isset($file)) {
- $file = $this->file;
- }
-
- // open MO file
- if (!is_resource($this->_handle = @fopen($file, 'rb'))) {
- return false;
- }
- // lock MO file shared
- if (!@flock($this->_handle, LOCK_SH)) {
- @fclose($this->_handle);
- return false;
- }
-
- // read (part of) magic number from MO file header and define endianess
-
- //unpack returns a reference????
- $unpacked = unpack('c', $this->_read(4));
- switch ($magic = array_shift($unpacked))
- {
- case -34:
- $be = false;
- break;
-
- case -107:
- $be = true;
- break;
-
- default:
- return false;
- }
-
- // check file format revision - we currently only support 0
- if (0 !== ($_rev = $this->_readInt($be))) {
- return false;
- }
-
- // count of strings in this file
- $count = $this->_readInt($be);
-
- // offset of hashing table of the msgids
- $offset_original = $this->_readInt($be);
- // offset of hashing table of the msgstrs
- $offset_translat = $this->_readInt($be);
-
- // move to msgid hash table
- fseek($this->_handle, $offset_original);
- // read lengths and offsets of msgids
- $original = array();
- for ($i = 0; $i < $count; $i++) {
- $original[$i] = array(
- 'length' => $this->_readInt($be),
- 'offset' => $this->_readInt($be)
- );
- }
-
- // move to msgstr hash table
- fseek($this->_handle, $offset_translat);
- // read lengths and offsets of msgstrs
- $translat = array();
- for ($i = 0; $i < $count; $i++) {
- $translat[$i] = array(
- 'length' => $this->_readInt($be),
- 'offset' => $this->_readInt($be)
- );
- }
-
- // read all
- for ($i = 0; $i < $count; $i++) {
- $this->strings[$this->_readStr($original[$i])] =
- $this->_readStr($translat[$i]);
- }
-
- // done
- @flock($this->_handle, LOCK_UN);
- @fclose($this->_handle);
- $this->_handle = null;
-
- // check for meta info
- if (isset($this->strings[''])) {
- $this->meta = parent::meta2array($this->strings['']);
- unset($this->strings['']);
- }
-
- return true;
- }
-
- /**
- * Save MO file
- *
- * @access public
- * @return mixed Returns true on success or PEAR_Error on failure.
- * @param string $file
- */
- function save($file = null)
- {
- if (!isset($file)) {
- $file = $this->file;
- }
-
- // open MO file
- if (!is_resource($this->_handle = @fopen($file, 'wb'))) {
- return false;
- }
- // lock MO file exclusively
- if (!@flock($this->_handle, LOCK_EX)) {
- @fclose($this->_handle);
- return false;
- }
-
- // write magic number
- if ($this->writeBigEndian) {
- $this->_write(pack('c*', 0x95, 0x04, 0x12, 0xde));
- } else {
- $this->_write(pack('c*', 0xde, 0x12, 0x04, 0x95));
- }
-
- // write file format revision
- $this->_writeInt(0);
-
- $count = count($this->strings) + ($meta = (count($this->meta) ? 1 : 0));
- // write count of strings
- $this->_writeInt($count);
-
- $offset = 28;
- // write offset of orig. strings hash table
- $this->_writeInt($offset);
-
- $offset += ($count * 8);
- // write offset transl. strings hash table
- $this->_writeInt($offset);
-
- // write size of hash table (we currently ommit the hash table)
- $this->_writeInt(0);
-
- $offset += ($count * 8);
- // write offset of hash table
- $this->_writeInt($offset);
-
- // unshift meta info
- if ($this->meta) {
- $meta = '';
- foreach ($this->meta as $key => $val) {
- $meta .= $key . ': ' . $val . "\n";
- }
- $strings = array('' => $meta) + $this->strings;
- } else {
- $strings = $this->strings;
- }
-
- // write offsets for original strings
- foreach (array_keys($strings) as $o) {
- $len = strlen($o);
- $this->_writeInt($len);
- $this->_writeInt($offset);
- $offset += $len + 1;
- }
-
- // write offsets for translated strings
- foreach ($strings as $t) {
- $len = strlen($t);
- $this->_writeInt($len);
- $this->_writeInt($offset);
- $offset += $len + 1;
- }
-
- // write original strings
- foreach (array_keys($strings) as $o) {
- $this->_writeStr($o);
- }
-
- // write translated strings
- foreach ($strings as $t) {
- $this->_writeStr($t);
- }
-
- // done
- @flock($this->_handle, LOCK_UN);
- @fclose($this->_handle);
- chmod($file,PRADO_CHMOD);
- return true;
- }
-}
+<?php
+/**
+ * TGettext_MO class file.
+ *
+ * This program is free software; you can redistribute it and/or modify
+ * it under the terms of the BSD License.
+ *
+ * Copyright(c) 2004 by Qiang Xue. All rights reserved.
+ *
+ * To contact the author write to {@link mailto:qiang.xue@gmail.com Qiang Xue}
+ * The latest version of PRADO can be obtained from:
+ * {@link http://prado.sourceforge.net/}
+ *
+ * @author Wei Zhuo <weizhuo[at]gmail[dot]com>
+ * @version $Revision: 1.3 $ $Date: 2005/08/27 03:21:12 $
+ * @package System.I18N.core
+ */
+
+
+// +----------------------------------------------------------------------+
+// | PEAR :: File :: Gettext :: MO |
+// +----------------------------------------------------------------------+
+// | This source file is subject to version 3.0 of the PHP license, |
+// | that is available at http://www.php.net/license/3_0.txt |
+// | If you did not receive a copy of the PHP license and are unable |
+// | to obtain it through the world-wide-web, please send a note to |
+// | license@php.net so we can mail you a copy immediately. |
+// +----------------------------------------------------------------------+
+// | Copyright (c) 2004 Michael Wallner <mike@iworks.at> |
+// +----------------------------------------------------------------------+
+//
+// $Id$
+
+/**
+ * File::Gettext::MO
+ *
+ * @author Michael Wallner <mike@php.net>
+ * @license PHP License
+ */
+
+require_once dirname(__FILE__).'/TGettext.php';
+
+/**
+ * File_Gettext_MO
+ *
+ * GNU MO file reader and writer.
+ *
+ * @author Michael Wallner <mike@php.net>
+ * @version $Revision: 1.3 $
+ * @access public
+ * @package System.I18N.core
+ */
+class TGettext_MO extends TGettext
+{
+ /**
+ * file handle
+ *
+ * @access private
+ * @var resource
+ */
+ protected $_handle = null;
+
+ /**
+ * big endianess
+ *
+ * Whether to write with big endian byte order.
+ *
+ * @access public
+ * @var bool
+ */
+ protected $writeBigEndian = false;
+
+ /**
+ * Constructor
+ *
+ * @access public
+ * @return object File_Gettext_MO
+ * @param string $file path to GNU MO file
+ */
+ function TGettext_MO($file = '')
+ {
+ $this->file = $file;
+ }
+
+ /**
+ * _read
+ *
+ * @access private
+ * @return mixed
+ * @param int $bytes
+ */
+ function _read($bytes = 1)
+ {
+ if (0 < $bytes = abs($bytes)) {
+ return fread($this->_handle, $bytes);
+ }
+ return null;
+ }
+
+ /**
+ * _readInt
+ *
+ * @access private
+ * @return int
+ * @param bool $bigendian
+ */
+ function _readInt($bigendian = false)
+ {
+ //unpack returns a reference????
+ $unpacked = unpack($bigendian ? 'N' : 'V', $this->_read(4));
+ return array_shift($unpacked);
+ }
+
+ /**
+ * _writeInt
+ *
+ * @access private
+ * @return int
+ * @param int $int
+ */
+ function _writeInt($int)
+ {
+ return $this->_write(pack($this->writeBigEndian ? 'N' : 'V', (int) $int));
+ }
+
+ /**
+ * _write
+ *
+ * @access private
+ * @return int
+ * @param string $data
+ */
+ function _write($data)
+ {
+ return fwrite($this->_handle, $data);
+ }
+
+ /**
+ * _writeStr
+ *
+ * @access private
+ * @return int
+ * @param string $string
+ */
+ function _writeStr($string)
+ {
+ return $this->_write($string . "\0");
+ }
+
+ /**
+ * _readStr
+ *
+ * @access private
+ * @return string
+ * @param array $params associative array with offset and length
+ * of the string
+ */
+ function _readStr($params)
+ {
+ fseek($this->_handle, $params['offset']);
+ return $this->_read($params['length']);
+ }
+
+ /**
+ * Load MO file
+ *
+ * @access public
+ * @return mixed Returns true on success or PEAR_Error on failure.
+ * @param string $file
+ */
+ function load($file = null)
+ {
+ if (!isset($file)) {
+ $file = $this->file;
+ }
+
+ // open MO file
+ if (!is_resource($this->_handle = @fopen($file, 'rb'))) {
+ return false;
+ }
+ // lock MO file shared
+ if (!@flock($this->_handle, LOCK_SH)) {
+ @fclose($this->_handle);
+ return false;
+ }
+
+ // read (part of) magic number from MO file header and define endianess
+
+ //unpack returns a reference????
+ $unpacked = unpack('c', $this->_read(4));
+ switch ($magic = array_shift($unpacked))
+ {
+ case -34:
+ $be = false;
+ break;
+
+ case -107:
+ $be = true;
+ break;
+
+ default:
+ return false;
+ }
+
+ // check file format revision - we currently only support 0
+ if (0 !== ($_rev = $this->_readInt($be))) {
+ return false;
+ }
+
+ // count of strings in this file
+ $count = $this->_readInt($be);
+
+ // offset of hashing table of the msgids
+ $offset_original = $this->_readInt($be);
+ // offset of hashing table of the msgstrs
+ $offset_translat = $this->_readInt($be);
+
+ // move to msgid hash table
+ fseek($this->_handle, $offset_original);
+ // read lengths and offsets of msgids
+ $original = array();
+ for ($i = 0; $i < $count; $i++) {
+ $original[$i] = array(
+ 'length' => $this->_readInt($be),
+ 'offset' => $this->_readInt($be)
+ );
+ }
+
+ // move to msgstr hash table
+ fseek($this->_handle, $offset_translat);
+ // read lengths and offsets of msgstrs
+ $translat = array();
+ for ($i = 0; $i < $count; $i++) {
+ $translat[$i] = array(
+ 'length' => $this->_readInt($be),
+ 'offset' => $this->_readInt($be)
+ );
+ }
+
+ // read all
+ for ($i = 0; $i < $count; $i++) {
+ $this->strings[$this->_readStr($original[$i])] =
+ $this->_readStr($translat[$i]);
+ }
+
+ // done
+ @flock($this->_handle, LOCK_UN);
+ @fclose($this->_handle);
+ $this->_handle = null;
+
+ // check for meta info
+ if (isset($this->strings[''])) {
+ $this->meta = parent::meta2array($this->strings['']);
+ unset($this->strings['']);
+ }
+
+ return true;
+ }
+
+ /**
+ * Save MO file
+ *
+ * @access public
+ * @return mixed Returns true on success or PEAR_Error on failure.
+ * @param string $file
+ */
+ function save($file = null)
+ {
+ if (!isset($file)) {
+ $file = $this->file;
+ }
+
+ // open MO file
+ if (!is_resource($this->_handle = @fopen($file, 'wb'))) {
+ return false;
+ }
+ // lock MO file exclusively
+ if (!@flock($this->_handle, LOCK_EX)) {
+ @fclose($this->_handle);
+ return false;
+ }
+
+ // write magic number
+ if ($this->writeBigEndian) {
+ $this->_write(pack('c*', 0x95, 0x04, 0x12, 0xde));
+ } else {
+ $this->_write(pack('c*', 0xde, 0x12, 0x04, 0x95));
+ }
+
+ // write file format revision
+ $this->_writeInt(0);
+
+ $count = count($this->strings) + ($meta = (count($this->meta) ? 1 : 0));
+ // write count of strings
+ $this->_writeInt($count);
+
+ $offset = 28;
+ // write offset of orig. strings hash table
+ $this->_writeInt($offset);
+
+ $offset += ($count * 8);
+ // write offset transl. strings hash table
+ $this->_writeInt($offset);
+
+ // write size of hash table (we currently ommit the hash table)
+ $this->_writeInt(0);
+
+ $offset += ($count * 8);
+ // write offset of hash table
+ $this->_writeInt($offset);
+
+ // unshift meta info
+ if ($this->meta) {
+ $meta = '';
+ foreach ($this->meta as $key => $val) {
+ $meta .= $key . ': ' . $val . "\n";
+ }
+ $strings = array('' => $meta) + $this->strings;
+ } else {
+ $strings = $this->strings;
+ }
+
+ // write offsets for original strings
+ foreach (array_keys($strings) as $o) {
+ $len = strlen($o);
+ $this->_writeInt($len);
+ $this->_writeInt($offset);
+ $offset += $len + 1;
+ }
+
+ // write offsets for translated strings
+ foreach ($strings as $t) {
+ $len = strlen($t);
+ $this->_writeInt($len);
+ $this->_writeInt($offset);
+ $offset += $len + 1;
+ }
+
+ // write original strings
+ foreach (array_keys($strings) as $o) {
+ $this->_writeStr($o);
+ }
+
+ // write translated strings
+ foreach ($strings as $t) {
+ $this->_writeStr($t);
+ }
+
+ // done
+ @flock($this->_handle, LOCK_UN);
+ @fclose($this->_handle);
+ chmod($file,PRADO_CHMOD);
+ return true;
+ }
+}
diff --git a/framework/I18N/core/Gettext/PO.php b/framework/I18N/core/Gettext/PO.php
index 54fe10e3..57028f6d 100644
--- a/framework/I18N/core/Gettext/PO.php
+++ b/framework/I18N/core/Gettext/PO.php
@@ -1,160 +1,160 @@
-<?php
-/**
- * TGettext_PO class file.
- *
- * This program is free software; you can redistribute it and/or modify
- * it under the terms of the BSD License.
- *
- * Copyright(c) 2004 by Qiang Xue. All rights reserved.
- *
- * To contact the author write to {@link mailto:qiang.xue@gmail.com Qiang Xue}
- * The latest version of PRADO can be obtained from:
- * {@link http://prado.sourceforge.net/}
- *
- * @author Wei Zhuo <weizhuo[at]gmail[dot]com>
- * @version $Revision: 1.2 $ $Date: 2005/01/05 03:15:14 $
- * @package System.I18N.core
- */
-
-// +----------------------------------------------------------------------+
-// | PEAR :: File :: Gettext :: PO |
-// +----------------------------------------------------------------------+
-// | This source file is subject to version 3.0 of the PHP license, |
-// | that is available at http://www.php.net/license/3_0.txt |
-// | If you did not receive a copy of the PHP license and are unable |
-// | to obtain it through the world-wide-web, please send a note to |
-// | license@php.net so we can mail you a copy immediately. |
-// +----------------------------------------------------------------------+
-// | Copyright (c) 2004 Michael Wallner <mike@iworks.at> |
-// +----------------------------------------------------------------------+
-//
-// $Id$
-
-/**
- * File::Gettext::PO
- *
- * @author Michael Wallner <mike@php.net>
- * @license PHP License
- */
-
-require_once dirname(__FILE__).'/TGettext.php';
-
-/**
- * File_Gettext_PO
- *
- * GNU PO file reader and writer.
- *
- * @author Michael Wallner <mike@php.net>
- * @version $Revision: 1.2 $
- * @access public
- * @package System.I18N.core
- */
-class TGettext_PO extends TGettext
-{
- /**
- * Constructor
- *
- * @access public
- * @return object File_Gettext_PO
- * @param string path to GNU PO file
- */
- function TGettext_PO($file = '')
- {
- $this->file = $file;
- }
-
- /**
- * Load PO file
- *
- * @access public
- * @return mixed Returns true on success or PEAR_Error on failure.
- * @param string $file
- */
- function load($file = null)
- {
- if (!isset($file)) {
- $file = $this->file;
- }
-
- // load file
- if (!$contents = @file($file)) {
- return false;
- }
- $contents = implode('', $contents);
-
- // match all msgid/msgstr entries
- $matched = preg_match_all(
- '/(msgid\s+("([^"]|\\\\")*?"\s*)+)\s+' .
- '(msgstr\s+("([^"]|\\\\")*?"\s*)+)/',
- $contents, $matches
- );
- unset($contents);
-
- if (!$matched) {
- return false;
- }
-
- // get all msgids and msgtrs
- for ($i = 0; $i < $matched; $i++) {
- $msgid = preg_replace(
- '/\s*msgid\s*"(.*)"\s*/s', '\\1', $matches[1][$i]);
- $msgstr= preg_replace(
- '/\s*msgstr\s*"(.*)"\s*/s', '\\1', $matches[4][$i]);
- $this->strings[parent::prepare($msgid)] = parent::prepare($msgstr);
- }
-
- // check for meta info
- if (isset($this->strings[''])) {
- $this->meta = parent::meta2array($this->strings['']);
- unset($this->strings['']);
- }
-
- return true;
- }
-
- /**
- * Save PO file
- *
- * @access public
- * @return mixed Returns true on success or PEAR_Error on failure.
- * @param string $file
- */
- function save($file = null)
- {
- if (!isset($file)) {
- $file = $this->file;
- }
-
- // open PO file
- if (!is_resource($fh = @fopen($file, 'w'))) {
- return false;
- }
-
- // lock PO file exclusively
- if (!flock($fh, LOCK_EX)) {
- fclose($fh);
- return false;
- }
- // write meta info
- if (count($this->meta)) {
- $meta = 'msgid ""' . "\nmsgstr " . '""' . "\n";
- foreach ($this->meta as $k => $v) {
- $meta .= '"' . $k . ': ' . $v . '\n"' . "\n";
- }
- fwrite($fh, $meta . "\n");
- }
- // write strings
- foreach ($this->strings as $o => $t) {
- fwrite($fh,
- 'msgid "' . parent::prepare($o, true) . '"' . "\n" .
- 'msgstr "' . parent::prepare($t, true) . '"' . "\n\n"
- );
- }
-
- //done
- @flock($fh, LOCK_UN);
- @fclose($fh);
- chmod($file,PRADO_CHMOD);
- return true;
- }
-}
+<?php
+/**
+ * TGettext_PO class file.
+ *
+ * This program is free software; you can redistribute it and/or modify
+ * it under the terms of the BSD License.
+ *
+ * Copyright(c) 2004 by Qiang Xue. All rights reserved.
+ *
+ * To contact the author write to {@link mailto:qiang.xue@gmail.com Qiang Xue}
+ * The latest version of PRADO can be obtained from:
+ * {@link http://prado.sourceforge.net/}
+ *
+ * @author Wei Zhuo <weizhuo[at]gmail[dot]com>
+ * @version $Revision: 1.2 $ $Date: 2005/01/05 03:15:14 $
+ * @package System.I18N.core
+ */
+
+// +----------------------------------------------------------------------+
+// | PEAR :: File :: Gettext :: PO |
+// +----------------------------------------------------------------------+
+// | This source file is subject to version 3.0 of the PHP license, |
+// | that is available at http://www.php.net/license/3_0.txt |
+// | If you did not receive a copy of the PHP license and are unable |
+// | to obtain it through the world-wide-web, please send a note to |
+// | license@php.net so we can mail you a copy immediately. |
+// +----------------------------------------------------------------------+
+// | Copyright (c) 2004 Michael Wallner <mike@iworks.at> |
+// +----------------------------------------------------------------------+
+//
+// $Id$
+
+/**
+ * File::Gettext::PO
+ *
+ * @author Michael Wallner <mike@php.net>
+ * @license PHP License
+ */
+
+require_once dirname(__FILE__).'/TGettext.php';
+
+/**
+ * File_Gettext_PO
+ *
+ * GNU PO file reader and writer.
+ *
+ * @author Michael Wallner <mike@php.net>
+ * @version $Revision: 1.2 $
+ * @access public
+ * @package System.I18N.core
+ */
+class TGettext_PO extends TGettext
+{
+ /**
+ * Constructor
+ *
+ * @access public
+ * @return object File_Gettext_PO
+ * @param string path to GNU PO file
+ */
+ function TGettext_PO($file = '')
+ {
+ $this->file = $file;
+ }
+
+ /**
+ * Load PO file
+ *
+ * @access public
+ * @return mixed Returns true on success or PEAR_Error on failure.
+ * @param string $file
+ */
+ function load($file = null)
+ {
+ if (!isset($file)) {
+ $file = $this->file;
+ }
+
+ // load file
+ if (!$contents = @file($file)) {
+ return false;
+ }
+ $contents = implode('', $contents);
+
+ // match all msgid/msgstr entries
+ $matched = preg_match_all(
+ '/(msgid\s+("([^"]|\\\\")*?"\s*)+)\s+' .
+ '(msgstr\s+("([^"]|\\\\")*?"\s*)+)/',
+ $contents, $matches
+ );
+ unset($contents);
+
+ if (!$matched) {
+ return false;
+ }
+
+ // get all msgids and msgtrs
+ for ($i = 0; $i < $matched; $i++) {
+ $msgid = preg_replace(
+ '/\s*msgid\s*"(.*)"\s*/s', '\\1', $matches[1][$i]);
+ $msgstr= preg_replace(
+ '/\s*msgstr\s*"(.*)"\s*/s', '\\1', $matches[4][$i]);
+ $this->strings[parent::prepare($msgid)] = parent::prepare($msgstr);
+ }
+
+ // check for meta info
+ if (isset($this->strings[''])) {
+ $this->meta = parent::meta2array($this->strings['']);
+ unset($this->strings['']);
+ }
+
+ return true;
+ }
+
+ /**
+ * Save PO file
+ *
+ * @access public
+ * @return mixed Returns true on success or PEAR_Error on failure.
+ * @param string $file
+ */
+ function save($file = null)
+ {
+ if (!isset($file)) {
+ $file = $this->file;
+ }
+
+ // open PO file
+ if (!is_resource($fh = @fopen($file, 'w'))) {
+ return false;
+ }
+
+ // lock PO file exclusively
+ if (!flock($fh, LOCK_EX)) {
+ fclose($fh);
+ return false;
+ }
+ // write meta info
+ if (count($this->meta)) {
+ $meta = 'msgid ""' . "\nmsgstr " . '""' . "\n";
+ foreach ($this->meta as $k => $v) {
+ $meta .= '"' . $k . ': ' . $v . '\n"' . "\n";
+ }
+ fwrite($fh, $meta . "\n");
+ }
+ // write strings
+ foreach ($this->strings as $o => $t) {
+ fwrite($fh,
+ 'msgid "' . parent::prepare($o, true) . '"' . "\n" .
+ 'msgstr "' . parent::prepare($t, true) . '"' . "\n\n"
+ );
+ }
+
+ //done
+ @flock($fh, LOCK_UN);
+ @fclose($fh);
+ chmod($file,PRADO_CHMOD);
+ return true;
+ }
+}
diff --git a/framework/I18N/core/Gettext/TGettext.php b/framework/I18N/core/Gettext/TGettext.php
index 39e5d07e..4ca7fadb 100644
--- a/framework/I18N/core/Gettext/TGettext.php
+++ b/framework/I18N/core/Gettext/TGettext.php
@@ -1,286 +1,286 @@
-<?php
-/**
- * TGettext class file.
- *
- * This program is free software; you can redistribute it and/or modify
- * it under the terms of the BSD License.
- *
- * Copyright(c) 2004 by Qiang Xue. All rights reserved.
- *
- * To contact the author write to {@link mailto:qiang.xue@gmail.com Qiang Xue}
- * The latest version of PRADO can be obtained from:
- * {@link http://prado.sourceforge.net/}
- *
- * @author Wei Zhuo <weizhuo[at]gmail[dot]com>
- * @version $Revision: 1.4 $ $Date: 2005/01/09 23:36:23 $
- * @package System.I18N.core
- */
-
-// +----------------------------------------------------------------------+
-// | PEAR :: File :: Gettext |
-// +----------------------------------------------------------------------+
-// | This source file is subject to version 3.0 of the PHP license, |
-// | that is available at http://www.php.net/license/3_0.txt |
-// | If you did not receive a copy of the PHP license and are unable |
-// | to obtain it through the world-wide-web, please send a note to |
-// | license@php.net so we can mail you a copy immediately. |
-// +----------------------------------------------------------------------+
-// | Copyright (c) 2004 Michael Wallner <mike@iworks.at> |
-// +----------------------------------------------------------------------+
-//
-// $Id$
-
-/**
- * File::Gettext
- *
- * @author Michael Wallner <mike@php.net>
- * @license PHP License
- */
-
-/**
- * Use PHPs builtin error messages
- */
-//ini_set('track_errors', true);
-
-/**
- * File_Gettext
- *
- * GNU gettext file reader and writer.
- *
- * #################################################################
- * # All protected members of this class are public in its childs. #
- * #################################################################
- *
- * @author Michael Wallner <mike@php.net>
- * @version $Revision: 1.4 $
- * @access public
- * @package System.I18N.core
- */
-class TGettext
-{
- /**
- * strings
- *
- * associative array with all [msgid => msgstr] entries
- *
- * @access protected
- * @var array
- */
- protected $strings = array();
-
- /**
- * meta
- *
- * associative array containing meta
- * information like project name or content type
- *
- * @access protected
- * @var array
- */
- protected $meta = array();
-
- /**
- * file path
- *
- * @access protected
- * @var string
- */
- protected $file = '';
-
- /**
- * Factory
- *
- * @static
- * @access public
- * @return object Returns File_Gettext_PO or File_Gettext_MO on success
- * or PEAR_Error on failure.
- * @param string $format MO or PO
- * @param string $file path to GNU gettext file
- */
- function factory($format, $file = '')
- {
- $format = strToUpper($format);
- $filename = dirname(__FILE__).'/'.$format.'.php';
- if(is_file($filename) == false)
- throw new Exception ("Class file $file not found");
-
- include_once $filename;
- $class = 'TGettext_' . $format;
-
- return new $class($file);
- }
-
- /**
- * poFile2moFile
- *
- * That's a simple fake of the 'msgfmt' console command. It reads the
- * contents of a GNU PO file and saves them to a GNU MO file.
- *
- * @static
- * @access public
- * @return mixed Returns true on success or PEAR_Error on failure.
- * @param string $pofile path to GNU PO file
- * @param string $mofile path to GNU MO file
- */
- function poFile2moFile($pofile, $mofile)
- {
- if (!is_file($pofile)) {
- throw new Exception("File $pofile doesn't exist.");
- }
-
- include_once dirname(__FILE__).'/PO.php';
-
- $PO = new TGettext_PO($pofile);
- if (true !== ($e = $PO->load())) {
- return $e;
- }
-
- $MO = $PO->toMO();
- if (true !== ($e = $MO->save($mofile))) {
- return $e;
- }
- unset($PO, $MO);
-
- return true;
- }
-
- /**
- * prepare
- *
- * @static
- * @access protected
- * @return string
- * @param string $string
- * @param bool $reverse
- */
- function prepare($string, $reverse = false)
- {
- if ($reverse) {
- $smap = array('"', "\n", "\t", "\r");
- $rmap = array('\"', '\\n"' . "\n" . '"', '\\t', '\\r');
- return (string) str_replace($smap, $rmap, $string);
- } else {
- $string = preg_replace('/"\s+"/', '', $string);
- $smap = array('\\n', '\\r', '\\t', '\"');
- $rmap = array("\n", "\r", "\t", '"');
- return (string) str_replace($smap, $rmap, $string);
- }
- }
-
- /**
- * meta2array
- *
- * @static
- * @access public
- * @return array
- * @param string $meta
- */
- function meta2array($meta)
- {
- $array = array();
- foreach (explode("\n", $meta) as $info) {
- if ($info = trim($info)) {
- list($key, $value) = explode(':', $info, 2);
- $array[trim($key)] = trim($value);
- }
- }
- return $array;
- }
-
- /**
- * toArray
- *
- * Returns meta info and strings as an array of a structure like that:
- * <code>
- * array(
- * 'meta' => array(
- * 'Content-Type' => 'text/plain; charset=iso-8859-1',
- * 'Last-Translator' => 'Michael Wallner <mike@iworks.at>',
- * 'PO-Revision-Date' => '2004-07-21 17:03+0200',
- * 'Language-Team' => 'German <mail@example.com>',
- * ),
- * 'strings' => array(
- * 'All rights reserved' => 'Alle Rechte vorbehalten',
- * 'Welcome' => 'Willkommen',
- * // ...
- * )
- * )
- * </code>
- *
- * @see fromArray()
- * @access protected
- * @return array
- */
- function toArray()
- {
- return array('meta' => $this->meta, 'strings' => $this->strings);
- }
-
- /**
- * fromArray
- *
- * Assigns meta info and strings from an array of a structure like that:
- * <code>
- * array(
- * 'meta' => array(
- * 'Content-Type' => 'text/plain; charset=iso-8859-1',
- * 'Last-Translator' => 'Michael Wallner <mike@iworks.at>',
- * 'PO-Revision-Date' => date('Y-m-d H:iO'),
- * 'Language-Team' => 'German <mail@example.com>',
- * ),
- * 'strings' => array(
- * 'All rights reserved' => 'Alle Rechte vorbehalten',
- * 'Welcome' => 'Willkommen',
- * // ...
- * )
- * )
- * </code>
- *
- * @see toArray()
- * @access protected
- * @return bool
- * @param array $array
- */
- function fromArray($array)
- {
- if (!array_key_exists('strings', $array)) {
- if (count($array) != 2) {
- return false;
- } else {
- list($this->meta, $this->strings) = $array;
- }
- } else {
- $this->meta = @$array['meta'];
- $this->strings = @$array['strings'];
- }
- return true;
- }
-
- /**
- * toMO
- *
- * @access protected
- * @return object File_Gettext_MO
- */
- function toMO()
- {
- include_once dirname(__FILE__).'/MO.php';
- $MO = new TGettext_MO;
- $MO->fromArray($this->toArray());
- return $MO;
- }
-
- /**
- * toPO
- *
- * @access protected
- * @return object File_Gettext_PO
- */
- function toPO()
- {
- include_once dirname(__FILE__).'/PO.php';
- $PO = new TGettext_PO;
- $PO->fromArray($this->toArray());
- return $PO;
- }
-}
+<?php
+/**
+ * TGettext class file.
+ *
+ * This program is free software; you can redistribute it and/or modify
+ * it under the terms of the BSD License.
+ *
+ * Copyright(c) 2004 by Qiang Xue. All rights reserved.
+ *
+ * To contact the author write to {@link mailto:qiang.xue@gmail.com Qiang Xue}
+ * The latest version of PRADO can be obtained from:
+ * {@link http://prado.sourceforge.net/}
+ *
+ * @author Wei Zhuo <weizhuo[at]gmail[dot]com>
+ * @version $Revision: 1.4 $ $Date: 2005/01/09 23:36:23 $
+ * @package System.I18N.core
+ */
+
+// +----------------------------------------------------------------------+
+// | PEAR :: File :: Gettext |
+// +----------------------------------------------------------------------+
+// | This source file is subject to version 3.0 of the PHP license, |
+// | that is available at http://www.php.net/license/3_0.txt |
+// | If you did not receive a copy of the PHP license and are unable |
+// | to obtain it through the world-wide-web, please send a note to |
+// | license@php.net so we can mail you a copy immediately. |
+// +----------------------------------------------------------------------+
+// | Copyright (c) 2004 Michael Wallner <mike@iworks.at> |
+// +----------------------------------------------------------------------+
+//
+// $Id$
+
+/**
+ * File::Gettext
+ *
+ * @author Michael Wallner <mike@php.net>
+ * @license PHP License
+ */
+
+/**
+ * Use PHPs builtin error messages
+ */
+//ini_set('track_errors', true);
+
+/**
+ * File_Gettext
+ *
+ * GNU gettext file reader and writer.
+ *
+ * #################################################################
+ * # All protected members of this class are public in its childs. #
+ * #################################################################
+ *
+ * @author Michael Wallner <mike@php.net>
+ * @version $Revision: 1.4 $
+ * @access public
+ * @package System.I18N.core
+ */
+class TGettext
+{
+ /**
+ * strings
+ *
+ * associative array with all [msgid => msgstr] entries
+ *
+ * @access protected
+ * @var array
+ */
+ protected $strings = array();
+
+ /**
+ * meta
+ *
+ * associative array containing meta
+ * information like project name or content type
+ *
+ * @access protected
+ * @var array
+ */
+ protected $meta = array();
+
+ /**
+ * file path
+ *
+ * @access protected
+ * @var string
+ */
+ protected $file = '';
+
+ /**
+ * Factory
+ *
+ * @static
+ * @access public
+ * @return object Returns File_Gettext_PO or File_Gettext_MO on success
+ * or PEAR_Error on failure.
+ * @param string $format MO or PO
+ * @param string $file path to GNU gettext file
+ */
+ function factory($format, $file = '')
+ {
+ $format = strToUpper($format);
+ $filename = dirname(__FILE__).'/'.$format.'.php';
+ if(is_file($filename) == false)
+ throw new Exception ("Class file $file not found");
+
+ include_once $filename;
+ $class = 'TGettext_' . $format;
+
+ return new $class($file);
+ }
+
+ /**
+ * poFile2moFile
+ *
+ * That's a simple fake of the 'msgfmt' console command. It reads the
+ * contents of a GNU PO file and saves them to a GNU MO file.
+ *
+ * @static
+ * @access public
+ * @return mixed Returns true on success or PEAR_Error on failure.
+ * @param string $pofile path to GNU PO file
+ * @param string $mofile path to GNU MO file
+ */
+ function poFile2moFile($pofile, $mofile)
+ {
+ if (!is_file($pofile)) {
+ throw new Exception("File $pofile doesn't exist.");
+ }
+
+ include_once dirname(__FILE__).'/PO.php';
+
+ $PO = new TGettext_PO($pofile);
+ if (true !== ($e = $PO->load())) {
+ return $e;
+ }
+
+ $MO = $PO->toMO();
+ if (true !== ($e = $MO->save($mofile))) {
+ return $e;
+ }
+ unset($PO, $MO);
+
+ return true;
+ }
+
+ /**
+ * prepare
+ *
+ * @static
+ * @access protected
+ * @return string
+ * @param string $string
+ * @param bool $reverse
+ */
+ function prepare($string, $reverse = false)
+ {
+ if ($reverse) {
+ $smap = array('"', "\n", "\t", "\r");
+ $rmap = array('\"', '\\n"' . "\n" . '"', '\\t', '\\r');
+ return (string) str_replace($smap, $rmap, $string);
+ } else {
+ $string = preg_replace('/"\s+"/', '', $string);
+ $smap = array('\\n', '\\r', '\\t', '\"');
+ $rmap = array("\n", "\r", "\t", '"');
+ return (string) str_replace($smap, $rmap, $string);
+ }
+ }
+
+ /**
+ * meta2array
+ *
+ * @static
+ * @access public
+ * @return array
+ * @param string $meta
+ */
+ function meta2array($meta)
+ {
+ $array = array();
+ foreach (explode("\n", $meta) as $info) {
+ if ($info = trim($info)) {
+ list($key, $value) = explode(':', $info, 2);
+ $array[trim($key)] = trim($value);
+ }
+ }
+ return $array;
+ }
+
+ /**
+ * toArray
+ *
+ * Returns meta info and strings as an array of a structure like that:
+ * <code>
+ * array(
+ * 'meta' => array(
+ * 'Content-Type' => 'text/plain; charset=iso-8859-1',
+ * 'Last-Translator' => 'Michael Wallner <mike@iworks.at>',
+ * 'PO-Revision-Date' => '2004-07-21 17:03+0200',
+ * 'Language-Team' => 'German <mail@example.com>',
+ * ),
+ * 'strings' => array(
+ * 'All rights reserved' => 'Alle Rechte vorbehalten',
+ * 'Welcome' => 'Willkommen',
+ * // ...
+ * )
+ * )
+ * </code>
+ *
+ * @see fromArray()
+ * @access protected
+ * @return array
+ */
+ function toArray()
+ {
+ return array('meta' => $this->meta, 'strings' => $this->strings);
+ }
+
+ /**
+ * fromArray
+ *
+ * Assigns meta info and strings from an array of a structure like that:
+ * <code>
+ * array(
+ * 'meta' => array(
+ * 'Content-Type' => 'text/plain; charset=iso-8859-1',
+ * 'Last-Translator' => 'Michael Wallner <mike@iworks.at>',
+ * 'PO-Revision-Date' => date('Y-m-d H:iO'),
+ * 'Language-Team' => 'German <mail@example.com>',
+ * ),
+ * 'strings' => array(
+ * 'All rights reserved' => 'Alle Rechte vorbehalten',
+ * 'Welcome' => 'Willkommen',
+ * // ...
+ * )
+ * )
+ * </code>
+ *
+ * @see toArray()
+ * @access protected
+ * @return bool
+ * @param array $array
+ */
+ function fromArray($array)
+ {
+ if (!array_key_exists('strings', $array)) {
+ if (count($array) != 2) {
+ return false;
+ } else {
+ list($this->meta, $this->strings) = $array;
+ }
+ } else {
+ $this->meta = @$array['meta'];
+ $this->strings = @$array['strings'];
+ }
+ return true;
+ }
+
+ /**
+ * toMO
+ *
+ * @access protected
+ * @return object File_Gettext_MO
+ */
+ function toMO()
+ {
+ include_once dirname(__FILE__).'/MO.php';
+ $MO = new TGettext_MO;
+ $MO->fromArray($this->toArray());
+ return $MO;
+ }
+
+ /**
+ * toPO
+ *
+ * @access protected
+ * @return object File_Gettext_PO
+ */
+ function toPO()
+ {
+ include_once dirname(__FILE__).'/PO.php';
+ $PO = new TGettext_PO;
+ $PO->fromArray($this->toArray());
+ return $PO;
+ }
+}
diff --git a/framework/I18N/core/HTTPNegotiator.php b/framework/I18N/core/HTTPNegotiator.php
index 9199ba15..26b532b8 100644
--- a/framework/I18N/core/HTTPNegotiator.php
+++ b/framework/I18N/core/HTTPNegotiator.php
@@ -1,129 +1,129 @@
-<?php
-
-/**
- * HTTPNegotiator class file.
- *
- * This program is free software; you can redistribute it and/or modify
- * it under the terms of the BSD License.
- *
- * Copyright(c) 2004 by Qiang Xue. All rights reserved.
- *
- * To contact the author write to {@link mailto:qiang.xue@gmail.com Qiang Xue}
- * The latest version of PRADO can be obtained from:
- * {@link http://prado.sourceforge.net/}
- *
- * @author Wei Zhuo <weizhuo[at]gmail[dot]com>
- * @version $Revision: 1.2 $ $Date: 2005/01/05 03:15:14 $
- * @package System.I18N.core
- */
-
-/**
- * Include the CultureInfo class.
- */
-require_once(dirname(__FILE__).'/CultureInfo.php');
-
-/**
- * HTTPNegotiator class.
- *
- * Get the language and charset information from the client browser.
- *
- * @author Xiang Wei Zhuo <weizhuo[at]gmail[dot]com>
- * @version v1.0, last update on Fri Dec 24 16:01:35 EST 2004
- * @package System.I18N.core
- */
-class HTTPNegotiator
-{
- /**
- * A list of languages accepted by the browser.
- * @var array
- */
- protected $languages;
-
- /**
- * A list of charsets accepted by the browser
- * @var array
- */
- protected $charsets;
-
- /**
- * Get a list of languages acceptable by the client browser
- * @return array languages ordered in the user browser preferences.
- */
- function getLanguages()
- {
- if($this->languages !== null) {
- return $this->languages;
- }
-
- $this->languages = array();
-
- if (!isset($_SERVER['HTTP_ACCEPT_LANGUAGE']))
- return $this->languages;
-
- //$basedir = CultureInfo::dataDir();
- //$ext = CultureInfo::fileExt();
- $info = new CultureInfo();
-
- foreach(explode(',', $_SERVER['HTTP_ACCEPT_LANGUAGE']) as $lang)
- {
- // Cut off any q-value that might come after a semi-colon
- if ($pos = strpos($lang, ';'))
- $lang = trim(substr($lang, 0, $pos));
-
- if (strstr($lang, '-'))
- {
- $codes = explode('-',$lang);
- if($codes[0] == 'i')
- {
- // Language not listed in ISO 639 that are not variants
- // of any listed language, which can be registerd with the
- // i-prefix, such as i-cherokee
- if(count($codes)>1)
- $lang = $codes[1];
- }
- else
- {
- for($i = 0, $k = count($codes); $i<$k; ++$i)
- {
- if($i == 0)
- $lang = strtolower($codes[0]);
- else
- $lang .= '_'.strtoupper($codes[$i]);
- }
- }
- }
-
-
-
- if($info->validCulture($lang))
- $this->languages[] = $lang;
- }
-
- return $this->languages;
- }
-
- /**
- * Get a list of charsets acceptable by the client browser.
- * @return array list of charsets in preferable order.
- */
- function getCharsets()
- {
- if($this->charsets !== null) {
- return $this->charsets;
- }
-
- $this->charsets = array();
-
- if (!isset($_SERVER['HTTP_ACCEPT_CHARSET']))
- return $this->charsets;
-
- foreach (explode(',', $_SERVER['HTTP_ACCEPT_CHARSET']) as $charset)
- {
- if (!empty($charset))
- $this->charsets[] = preg_replace('/;.*/', '', $charset);
- }
-
- return $this->charsets;
- }
-}
-
+<?php
+
+/**
+ * HTTPNegotiator class file.
+ *
+ * This program is free software; you can redistribute it and/or modify
+ * it under the terms of the BSD License.
+ *
+ * Copyright(c) 2004 by Qiang Xue. All rights reserved.
+ *
+ * To contact the author write to {@link mailto:qiang.xue@gmail.com Qiang Xue}
+ * The latest version of PRADO can be obtained from:
+ * {@link http://prado.sourceforge.net/}
+ *
+ * @author Wei Zhuo <weizhuo[at]gmail[dot]com>
+ * @version $Revision: 1.2 $ $Date: 2005/01/05 03:15:14 $
+ * @package System.I18N.core
+ */
+
+/**
+ * Include the CultureInfo class.
+ */
+require_once(dirname(__FILE__).'/CultureInfo.php');
+
+/**
+ * HTTPNegotiator class.
+ *
+ * Get the language and charset information from the client browser.
+ *
+ * @author Xiang Wei Zhuo <weizhuo[at]gmail[dot]com>
+ * @version v1.0, last update on Fri Dec 24 16:01:35 EST 2004
+ * @package System.I18N.core
+ */
+class HTTPNegotiator
+{
+ /**
+ * A list of languages accepted by the browser.
+ * @var array
+ */
+ protected $languages;
+
+ /**
+ * A list of charsets accepted by the browser
+ * @var array
+ */
+ protected $charsets;
+
+ /**
+ * Get a list of languages acceptable by the client browser
+ * @return array languages ordered in the user browser preferences.
+ */
+ function getLanguages()
+ {
+ if($this->languages !== null) {
+ return $this->languages;
+ }
+
+ $this->languages = array();
+
+ if (!isset($_SERVER['HTTP_ACCEPT_LANGUAGE']))
+ return $this->languages;
+
+ //$basedir = CultureInfo::dataDir();
+ //$ext = CultureInfo::fileExt();
+ $info = new CultureInfo();
+
+ foreach(explode(',', $_SERVER['HTTP_ACCEPT_LANGUAGE']) as $lang)
+ {
+ // Cut off any q-value that might come after a semi-colon
+ if ($pos = strpos($lang, ';'))
+ $lang = trim(substr($lang, 0, $pos));
+
+ if (strstr($lang, '-'))
+ {
+ $codes = explode('-',$lang);
+ if($codes[0] == 'i')
+ {
+ // Language not listed in ISO 639 that are not variants
+ // of any listed language, which can be registerd with the
+ // i-prefix, such as i-cherokee
+ if(count($codes)>1)
+ $lang = $codes[1];
+ }
+ else
+ {
+ for($i = 0, $k = count($codes); $i<$k; ++$i)
+ {
+ if($i == 0)
+ $lang = strtolower($codes[0]);
+ else
+ $lang .= '_'.strtoupper($codes[$i]);
+ }
+ }
+ }
+
+
+
+ if($info->validCulture($lang))
+ $this->languages[] = $lang;
+ }
+
+ return $this->languages;
+ }
+
+ /**
+ * Get a list of charsets acceptable by the client browser.
+ * @return array list of charsets in preferable order.
+ */
+ function getCharsets()
+ {
+ if($this->charsets !== null) {
+ return $this->charsets;
+ }
+
+ $this->charsets = array();
+
+ if (!isset($_SERVER['HTTP_ACCEPT_CHARSET']))
+ return $this->charsets;
+
+ foreach (explode(',', $_SERVER['HTTP_ACCEPT_CHARSET']) as $charset)
+ {
+ if (!empty($charset))
+ $this->charsets[] = preg_replace('/;.*/', '', $charset);
+ }
+
+ return $this->charsets;
+ }
+}
+
diff --git a/framework/I18N/core/IMessageSource.php b/framework/I18N/core/IMessageSource.php
index 1d40bd73..f8263b97 100644
--- a/framework/I18N/core/IMessageSource.php
+++ b/framework/I18N/core/IMessageSource.php
@@ -1,122 +1,122 @@
-<?php
-
-/**
- * IMessageSource interface file.
- *
- * This program is free software; you can redistribute it and/or modify
- * it under the terms of the BSD License.
- *
- * Copyright(c) 2004 by Qiang Xue. All rights reserved.
- *
- * To contact the author write to {@link mailto:qiang.xue@gmail.com Qiang Xue}
- * The latest version of PRADO can be obtained from:
- * {@link http://prado.sourceforge.net/}
- *
- * @author Wei Zhuo <weizhuo[at]gmail[dot]com>
- * @version $Revision: 1.3 $ $Date: 2005/01/09 22:15:32 $
- * @package System.I18N.core
- */
-
-/**
- * IMessageSource interface.
- *
- * All messages source used by MessageFormat must be of IMessageSource.
- * It defines a set of operations to add and retrive messages from the
- * message source. In addition, message source can load a particular
- * catalogue.
- *
- * @author Xiang Wei Zhuo <weizhuo[at]gmail[dot]com>
- * @version v1.0, last update on Fri Dec 24 17:40:19 EST 2004
- * @package System.I18N.core
- */
-interface IMessageSource
-{
- /**
- * Load the translation table for this particular catalogue.
- * The translation should be loaded in the following order.
- * # [1] call getCatalogeList($catalogue) to get a list of
- * variants for for the specified $catalogue.
- * # [2] for each of the variants, call getSource($variant)
- * to get the resource, could be a file or catalogue ID.
- * # [3] verify that this resource is valid by calling isValidSource($source)
- * # [4] try to get the messages from the cache
- * # [5] if a cache miss, call load($source) to load the message array
- * # [6] store the messages to cache.
- * # [7] continue with the foreach loop, e.g. goto [2].
- *
- * @param string a catalogue to load
- * @return boolean true if loaded, false otherwise.
- */
- function load($catalogue = 'messages');
-
- /**
- * Get the translation table. This includes all the loaded sections.
- * It must return a 2 level array of translation strings.
- * # "catalogue+variant" the catalogue and its variants.
- * # "source string" translation keys, and its translations.
- * <code>
- * array('catalogue+variant' =>
- * array('source string' => 'target string', ...)
- * ...),
- * ...);
- * </code>
- *
- * @return array 2 level array translation table.
- */
- function read();
-
- /**
- * Save the list of untranslated blocks to the translation source.
- * If the translation was not found, you should add those
- * strings to the translation source via the <b>append()</b> method.
- * @param string the catalogue to add to
- * @return boolean true if saved successfuly, false otherwise.
- */
- function save($catalogue='messages');
-
- /**
- * Add a untranslated message to the source. Need to call save()
- * to save the messages to source.
- * @param string message to add
- * @return void
- */
- function append($message);
-
- /**
- * Delete a particular message from the specified catalogue.
- * @param string the source message to delete.
- * @param string the catalogue to delete from.
- * @return boolean true if deleted, false otherwise.
- */
- function delete($message, $catalogue='messages');
-
- /**
- * Update the translation.
- * @param string the source string.
- * @param string the new translation string.
- * @param string comments
- * @param string the catalogue of the translation.
- * @return boolean true if translation was updated, false otherwise.
- */
- function update($text, $target, $comments, $catalogue='messages');
-
- /**
- * Returns a list of catalogue as key and all it variants as value.
- * @return array list of catalogues
- */
- function catalogues();
-
- /**
- * Set the culture for this particular message source.
- * @param string the Culture name.
- */
- function setCulture($culture);
-
- /**
- * Get the culture identifier for the source.
- * @return string culture identifier.
- */
- function getCulture();
-
-}
-
+<?php
+
+/**
+ * IMessageSource interface file.
+ *
+ * This program is free software; you can redistribute it and/or modify
+ * it under the terms of the BSD License.
+ *
+ * Copyright(c) 2004 by Qiang Xue. All rights reserved.
+ *
+ * To contact the author write to {@link mailto:qiang.xue@gmail.com Qiang Xue}
+ * The latest version of PRADO can be obtained from:
+ * {@link http://prado.sourceforge.net/}
+ *
+ * @author Wei Zhuo <weizhuo[at]gmail[dot]com>
+ * @version $Revision: 1.3 $ $Date: 2005/01/09 22:15:32 $
+ * @package System.I18N.core
+ */
+
+/**
+ * IMessageSource interface.
+ *
+ * All messages source used by MessageFormat must be of IMessageSource.
+ * It defines a set of operations to add and retrive messages from the
+ * message source. In addition, message source can load a particular
+ * catalogue.
+ *
+ * @author Xiang Wei Zhuo <weizhuo[at]gmail[dot]com>
+ * @version v1.0, last update on Fri Dec 24 17:40:19 EST 2004
+ * @package System.I18N.core
+ */
+interface IMessageSource
+{
+ /**
+ * Load the translation table for this particular catalogue.
+ * The translation should be loaded in the following order.
+ * # [1] call getCatalogeList($catalogue) to get a list of
+ * variants for for the specified $catalogue.
+ * # [2] for each of the variants, call getSource($variant)
+ * to get the resource, could be a file or catalogue ID.
+ * # [3] verify that this resource is valid by calling isValidSource($source)
+ * # [4] try to get the messages from the cache
+ * # [5] if a cache miss, call load($source) to load the message array
+ * # [6] store the messages to cache.
+ * # [7] continue with the foreach loop, e.g. goto [2].
+ *
+ * @param string a catalogue to load
+ * @return boolean true if loaded, false otherwise.
+ */
+ function load($catalogue = 'messages');
+
+ /**
+ * Get the translation table. This includes all the loaded sections.
+ * It must return a 2 level array of translation strings.
+ * # "catalogue+variant" the catalogue and its variants.
+ * # "source string" translation keys, and its translations.
+ * <code>
+ * array('catalogue+variant' =>
+ * array('source string' => 'target string', ...)
+ * ...),
+ * ...);
+ * </code>
+ *
+ * @return array 2 level array translation table.
+ */
+ function read();
+
+ /**
+ * Save the list of untranslated blocks to the translation source.
+ * If the translation was not found, you should add those
+ * strings to the translation source via the <b>append()</b> method.
+ * @param string the catalogue to add to
+ * @return boolean true if saved successfuly, false otherwise.
+ */
+ function save($catalogue='messages');
+
+ /**
+ * Add a untranslated message to the source. Need to call save()
+ * to save the messages to source.
+ * @param string message to add
+ * @return void
+ */
+ function append($message);
+
+ /**
+ * Delete a particular message from the specified catalogue.
+ * @param string the source message to delete.
+ * @param string the catalogue to delete from.
+ * @return boolean true if deleted, false otherwise.
+ */
+ function delete($message, $catalogue='messages');
+
+ /**
+ * Update the translation.
+ * @param string the source string.
+ * @param string the new translation string.
+ * @param string comments
+ * @param string the catalogue of the translation.
+ * @return boolean true if translation was updated, false otherwise.
+ */
+ function update($text, $target, $comments, $catalogue='messages');
+
+ /**
+ * Returns a list of catalogue as key and all it variants as value.
+ * @return array list of catalogues
+ */
+ function catalogues();
+
+ /**
+ * Set the culture for this particular message source.
+ * @param string the Culture name.
+ */
+ function setCulture($culture);
+
+ /**
+ * Get the culture identifier for the source.
+ * @return string culture identifier.
+ */
+ function getCulture();
+
+}
+
diff --git a/framework/I18N/core/MessageCache.php b/framework/I18N/core/MessageCache.php
index d4f58f1d..44392b79 100644
--- a/framework/I18N/core/MessageCache.php
+++ b/framework/I18N/core/MessageCache.php
@@ -1,171 +1,171 @@
-<?php
-/**
- * Translation table cache.
- * @author $Author: weizhuo $
- * @version $Id$
- * @package System.I18N.core
- */
-
-/**
- * Load the cache lite library.
- */
-require_once(dirname(__FILE__).'/TCache_Lite.php');
-
-/**
- * Cache the translation table into the file system.
- * It can cache each cataloug+variant or just the whole section.
- * @package System.I18N.core
- * @author $Author: weizhuo $
- * @version $Id$
- */
-class MessageCache
-{
-
- /**
- * Cache Lite instance.
- * @var TCache_Lite
- */
- protected $cache;
-
- /**
- * Caceh life time, default is 1 year.
- */
- protected $lifetime = 3153600;
-
-
- /**
- * Create a new Translation cache.
- * @param string $cacheDir Directory to store the cache files.
- */
- public function __construct($cacheDir)
- {
- $cacheDir = $cacheDir.'/';
-
- if(!is_dir($cacheDir))
- throw new Exception(
- 'The cache directory '.$cacheDir.' does not exists.'.
- 'The cache directory must be writable by the server.');
- if(!is_writable($cacheDir))
- throw new Exception(
- 'The cache directory '.$cacheDir.' must be writable '.
- 'by the server.');
-
- $options = array(
- 'cacheDir' => $cacheDir,
- 'lifeTime' => $this->getLifeTime(),
- 'automaticSerialization' => true
- );
-
- $this->cache = new TCache_Lite($options);
- }
-
- /**
- * Get the cache life time.
- * @return int Cache life time.
- */
- public function getLifeTime()
- {
- return $this->lifetime;
- }
-
- /**
- * Set the cache life time.
- * @param int $time Cache life time.
- */
- public function setLifeTime($time)
- {
- $this->lifetime = (int)$time;
- }
-
- /**
- * Get the cache file ID based section and locale.
- * @param string $catalogue The translation section.
- * @param string $culture The translation locale, e.g. "en_AU".
- */
- protected function getID($catalogue, $culture)
- {
- return $catalogue.':'.$culture;
- }
-
- /**
- * Get the cache file GROUP based section and locale.
- * @param string $catalogue The translation section.
- * @param string $culture The translation locale, e.g. "en_AU".
- */
- protected function getGroup($catalogue, $culture)
- {
- return $catalogue.':'.get_class($this);
- }
-
- /**
- * Get the data from the cache.
- * @param string $catalogue The translation section.
- * @param string $culture The translation locale, e.g. "en_AU".
- * @param string $filename If the source is a file, this file's modified
- * time is newer than the cache's modified time, no cache hit.
- * @return mixed Boolean FALSE if no cache hit. Otherwise, translation
- * table data for the specified section and locale.
- */
- public function get($catalogue, $culture, $lastmodified=0)
- {
- $ID = $this->getID($catalogue, $culture);
- $group = $this->getGroup($catalogue, $culture);
-
- $this->cache->_setFileName($ID, $group);
-
- $cache = $this->cache->getCacheFile();
-
- if(is_file($cache) == false)
- return false;
-
-
- $lastmodified = (int)$lastmodified;
-
- if($lastmodified <= 0 || $lastmodified > filemtime($cache))
- return false;
-
- //echo '@@ Cache hit: "'.$ID.'" : "'.$group.'"';
- //echo "<br>\n";
-
- return $this->cache->get($ID, $group);
- }
-
- /**
- * Save the data to cache for the specified section and locale.
- * @param array $data The data to save.
- * @param string $catalogue The translation section.
- * @param string $culture The translation locale, e.g. "en_AU".
- */
- public function save($data, $catalogue, $culture)
- {
- $ID = $this->getID($catalogue, $culture);
- $group = $this->getGroup($catalogue, $culture);
-
- //echo '## Cache save: "'.$ID.'" : "'.$group.'"';
- //echo "<br>\n";
-
- return $this->cache->save($data, $ID, $group);
- }
-
- /**
- * Clean up the cache for the specified section and locale.
- * @param string $catalogue The translation section.
- * @param string $culture The translation locale, e.g. "en_AU".
- */
- public function clean($catalogue, $culture)
- {
- $group = $this->getGroup($catalogue, $culture);
- $this->cache->clean($group);
- }
-
- /**
- * Flush the cache. Deletes all the cache files.
- */
- public function clear()
- {
- $this->cache->clean();
- }
-
-}
-
-?>
+<?php
+/**
+ * Translation table cache.
+ * @author $Author: weizhuo $
+ * @version $Id$
+ * @package System.I18N.core
+ */
+
+/**
+ * Load the cache lite library.
+ */
+require_once(dirname(__FILE__).'/TCache_Lite.php');
+
+/**
+ * Cache the translation table into the file system.
+ * It can cache each cataloug+variant or just the whole section.
+ * @package System.I18N.core
+ * @author $Author: weizhuo $
+ * @version $Id$
+ */
+class MessageCache
+{
+
+ /**
+ * Cache Lite instance.
+ * @var TCache_Lite
+ */
+ protected $cache;
+
+ /**
+ * Caceh life time, default is 1 year.
+ */
+ protected $lifetime = 3153600;
+
+
+ /**
+ * Create a new Translation cache.
+ * @param string $cacheDir Directory to store the cache files.
+ */
+ public function __construct($cacheDir)
+ {
+ $cacheDir = $cacheDir.'/';
+
+ if(!is_dir($cacheDir))
+ throw new Exception(
+ 'The cache directory '.$cacheDir.' does not exists.'.
+ 'The cache directory must be writable by the server.');
+ if(!is_writable($cacheDir))
+ throw new Exception(
+ 'The cache directory '.$cacheDir.' must be writable '.
+ 'by the server.');
+
+ $options = array(
+ 'cacheDir' => $cacheDir,
+ 'lifeTime' => $this->getLifeTime(),
+ 'automaticSerialization' => true
+ );
+
+ $this->cache = new TCache_Lite($options);
+ }
+
+ /**
+ * Get the cache life time.
+ * @return int Cache life time.
+ */
+ public function getLifeTime()
+ {
+ return $this->lifetime;
+ }
+
+ /**
+ * Set the cache life time.
+ * @param int $time Cache life time.
+ */
+ public function setLifeTime($time)
+ {
+ $this->lifetime = (int)$time;
+ }
+
+ /**
+ * Get the cache file ID based section and locale.
+ * @param string $catalogue The translation section.
+ * @param string $culture The translation locale, e.g. "en_AU".
+ */
+ protected function getID($catalogue, $culture)
+ {
+ return $catalogue.':'.$culture;
+ }
+
+ /**
+ * Get the cache file GROUP based section and locale.
+ * @param string $catalogue The translation section.
+ * @param string $culture The translation locale, e.g. "en_AU".
+ */
+ protected function getGroup($catalogue, $culture)
+ {
+ return $catalogue.':'.get_class($this);
+ }
+
+ /**
+ * Get the data from the cache.
+ * @param string $catalogue The translation section.
+ * @param string $culture The translation locale, e.g. "en_AU".
+ * @param string $filename If the source is a file, this file's modified
+ * time is newer than the cache's modified time, no cache hit.
+ * @return mixed Boolean FALSE if no cache hit. Otherwise, translation
+ * table data for the specified section and locale.
+ */
+ public function get($catalogue, $culture, $lastmodified=0)
+ {
+ $ID = $this->getID($catalogue, $culture);
+ $group = $this->getGroup($catalogue, $culture);
+
+ $this->cache->_setFileName($ID, $group);
+
+ $cache = $this->cache->getCacheFile();
+
+ if(is_file($cache) == false)
+ return false;
+
+
+ $lastmodified = (int)$lastmodified;
+
+ if($lastmodified <= 0 || $lastmodified > filemtime($cache))
+ return false;
+
+ //echo '@@ Cache hit: "'.$ID.'" : "'.$group.'"';
+ //echo "<br>\n";
+
+ return $this->cache->get($ID, $group);
+ }
+
+ /**
+ * Save the data to cache for the specified section and locale.
+ * @param array $data The data to save.
+ * @param string $catalogue The translation section.
+ * @param string $culture The translation locale, e.g. "en_AU".
+ */
+ public function save($data, $catalogue, $culture)
+ {
+ $ID = $this->getID($catalogue, $culture);
+ $group = $this->getGroup($catalogue, $culture);
+
+ //echo '## Cache save: "'.$ID.'" : "'.$group.'"';
+ //echo "<br>\n";
+
+ return $this->cache->save($data, $ID, $group);
+ }
+
+ /**
+ * Clean up the cache for the specified section and locale.
+ * @param string $catalogue The translation section.
+ * @param string $culture The translation locale, e.g. "en_AU".
+ */
+ public function clean($catalogue, $culture)
+ {
+ $group = $this->getGroup($catalogue, $culture);
+ $this->cache->clean($group);
+ }
+
+ /**
+ * Flush the cache. Deletes all the cache files.
+ */
+ public function clear()
+ {
+ $this->cache->clean();
+ }
+
+}
+
+?>
diff --git a/framework/I18N/core/MessageFormat.php b/framework/I18N/core/MessageFormat.php
index 7af6deb1..fd0d445d 100644
--- a/framework/I18N/core/MessageFormat.php
+++ b/framework/I18N/core/MessageFormat.php
@@ -1,255 +1,255 @@
-<?php
-
-/**
- * MessageFormat class file.
- *
- * This program is free software; you can redistribute it and/or modify
- * it under the terms of the BSD License.
- *
- * Copyright(c) 2004 by Qiang Xue. All rights reserved.
- *
- * To contact the author write to {@link mailto:qiang.xue@gmail.com Qiang Xue}
- * The latest version of PRADO can be obtained from:
- * {@link http://prado.sourceforge.net/}
- *
- * @author Wei Zhuo <weizhuo[at]gmail[dot]com>
- * @version $Revision: 1.5 $ $Date: 2005/08/27 03:21:12 $
- * @package System.I18N.core
- */
-
-/**
- * Get the MessageSource classes.
- */
-require_once(dirname(__FILE__).'/MessageSource.php');
-
-/**
- * Get the encoding utilities
- */
-require_once(dirname(__FILE__).'/util.php');
-
-/**
- * MessageFormat class.
- *
- * Format a message, that is, for a particular message find the
- * translated message. The following is an example using
- * a SQLite database to store the translation message.
- * Create a new message format instance and echo "Hello"
- * in simplified Chinese. This assumes that the world "Hello"
- * is translated in the database.
- *
- * <code>
- * $source = MessageSource::factory('SQLite', 'sqlite://messages.db');
- * $source->setCulture('zh_CN');
- * $source->setCache(new MessageCache('./tmp'));
- *
- * $formatter = new MessageFormat($source);
- *
- * echo $formatter->format('Hello');
- * </code>
- *
- * @author Xiang Wei Zhuo <weizhuo[at]gmail[dot]com>
- * @version v1.0, last update on Fri Dec 24 20:46:16 EST 2004
- * @package System.I18N.core
- */
-class MessageFormat
-{
- /**
- * The message source.
- * @var MessageSource
- */
- protected $source;
-
- /**
- * A list of loaded message catalogues.
- * @var array
- */
- protected $catagloues = array();
-
- /**
- * The translation messages.
- * @var array
- */
- protected $messages = array();
-
- /**
- * A list of untranslated messages.
- * @var array
- */
- protected $untranslated = array();
-
- /**
- * The prefix and suffix to append to untranslated messages.
- * @var array
- */
- protected $postscript = array('','');
-
- /**
- * Set the default catalogue.
- * @var string
- */
- public $Catalogue;
-
- /**
- * Output encoding charset
- * @var string
- */
- protected $charset = 'UTF-8';
-
- /**
- * Constructor.
- * Create a new instance of MessageFormat using the messages
- * from the supplied message source.
- * @param MessageSource the source of translation messages.
- * @param string charset for the message output.
- */
- function __construct(IMessageSource $source, $charset='UTF-8')
- {
- $this->source = $source;
- $this->setCharset($charset);
- }
-
- /**
- * Sets the charset for message output.
- * @param string charset, default is UTF-8
- */
- public function setCharset($charset)
- {
- $this->charset = $charset;
- }
-
- /**
- * Gets the charset for message output. Default is UTF-8.
- * @return string charset, default UTF-8
- */
- public function getCharset()
- {
- return $this->charset;
- }
-
- /**
- * Load the message from a particular catalogue. A listed
- * loaded catalogues is kept to prevent reload of the same
- * catalogue. The load catalogue messages are stored
- * in the $this->message array.
- * @param string message catalogue to load.
- */
- protected function loadCatalogue($catalogue)
- {
- if(in_array($catalogue,$this->catagloues))
- return;
-
- if($this->source->load($catalogue))
- {
- $this->messages[$catalogue] = $this->source->read();
- $this->catagloues[] = $catalogue;
- }
- }
-
- /**
- * Format the string. That is, for a particular string find
- * the corresponding translation. Variable subsitution is performed
- * for the $args parameter. A different catalogue can be specified
- * using the $catalogue parameter.
- * The output charset is determined by $this->getCharset();
- * @param string the string to translate.
- * @param array a list of string to substitute.
- * @param string get the translation from a particular message
- * @param string charset, the input AND output charset
- * catalogue.
- * @return string translated string.
- */
- public function format($string,$args=array(), $catalogue=null, $charset=null)
- {
- if(empty($charset)) $charset = $this->getCharset();
-
- //force args as UTF-8
- foreach($args as $k => $v)
- $args[$k] = I18N_toUTF8($v, $charset);
- $s = $this->formatString(I18N_toUTF8($string, $charset),$args,$catalogue);
- return I18N_toEncoding($s, $charset);
- }
-
- /**
- * Do string translation.
- * @param string the string to translate.
- * @param array a list of string to substitute.
- * @param string get the translation from a particular message
- * catalogue.
- * @return string translated string.
- */
- protected function formatString($string, $args=array(), $catalogue=null)
- {
- if(empty($catalogue))
- {
- if(empty($this->Catalogue))
- $catalogue = 'messages';
- else
- $catalogue = $this->Catalogue;
- }
-
- $this->loadCatalogue($catalogue);
-
- if(empty($args))
- $args = array();
-
- foreach($this->messages[$catalogue] as $variant)
- {
- // foreach of the translation units
- foreach($variant as $source => $result)
- {
- // we found it, so return the target translation
- if($source == $string)
- {
- //check if it contains only strings.
- if(is_string($result))
- $target = $result;
- else
- {
- $target = $result[0];
- }
- //found, but untranslated
- if(empty($target))
- {
- return $this->postscript[0].
- strtr($string, $args).
- $this->postscript[1];
- }
- else
- return strtr($target, $args);
- }
- }
- }
-
- // well we did not find the translation string.
- $this->source->append($string);
-
- return $this->postscript[0].
- strtr($string, $args).
- $this->postscript[1];
- }
-
- /**
- * Get the message source.
- * @return MessageSource
- */
- function getSource()
- {
- return $this->source;
- }
-
- /**
- * Set the prefix and suffix to append to untranslated messages.
- * e.g. $postscript=array('[T]','[/T]'); will output
- * "[T]Hello[/T]" if the translation for "Hello" can not be determined.
- * @param array first element is the prefix, second element the suffix.
- */
- function setUntranslatedPS($postscript)
- {
- if(is_array($postscript) && count($postscript)>=2)
- {
- $this->postscript[0] = $postscript[0];
- $this->postscript[1] = $postscript[1];
- }
- }
-}
-
+<?php
+
+/**
+ * MessageFormat class file.
+ *
+ * This program is free software; you can redistribute it and/or modify
+ * it under the terms of the BSD License.
+ *
+ * Copyright(c) 2004 by Qiang Xue. All rights reserved.
+ *
+ * To contact the author write to {@link mailto:qiang.xue@gmail.com Qiang Xue}
+ * The latest version of PRADO can be obtained from:
+ * {@link http://prado.sourceforge.net/}
+ *
+ * @author Wei Zhuo <weizhuo[at]gmail[dot]com>
+ * @version $Revision: 1.5 $ $Date: 2005/08/27 03:21:12 $
+ * @package System.I18N.core
+ */
+
+/**
+ * Get the MessageSource classes.
+ */
+require_once(dirname(__FILE__).'/MessageSource.php');
+
+/**
+ * Get the encoding utilities
+ */
+require_once(dirname(__FILE__).'/util.php');
+
+/**
+ * MessageFormat class.
+ *
+ * Format a message, that is, for a particular message find the
+ * translated message. The following is an example using
+ * a SQLite database to store the translation message.
+ * Create a new message format instance and echo "Hello"
+ * in simplified Chinese. This assumes that the world "Hello"
+ * is translated in the database.
+ *
+ * <code>
+ * $source = MessageSource::factory('SQLite', 'sqlite://messages.db');
+ * $source->setCulture('zh_CN');
+ * $source->setCache(new MessageCache('./tmp'));
+ *
+ * $formatter = new MessageFormat($source);
+ *
+ * echo $formatter->format('Hello');
+ * </code>
+ *
+ * @author Xiang Wei Zhuo <weizhuo[at]gmail[dot]com>
+ * @version v1.0, last update on Fri Dec 24 20:46:16 EST 2004
+ * @package System.I18N.core
+ */
+class MessageFormat
+{
+ /**
+ * The message source.
+ * @var MessageSource
+ */
+ protected $source;
+
+ /**
+ * A list of loaded message catalogues.
+ * @var array
+ */
+ protected $catagloues = array();
+
+ /**
+ * The translation messages.
+ * @var array
+ */
+ protected $messages = array();
+
+ /**
+ * A list of untranslated messages.
+ * @var array
+ */
+ protected $untranslated = array();
+
+ /**
+ * The prefix and suffix to append to untranslated messages.
+ * @var array
+ */
+ protected $postscript = array('','');
+
+ /**
+ * Set the default catalogue.
+ * @var string
+ */
+ public $Catalogue;
+
+ /**
+ * Output encoding charset
+ * @var string
+ */
+ protected $charset = 'UTF-8';
+
+ /**
+ * Constructor.
+ * Create a new instance of MessageFormat using the messages
+ * from the supplied message source.
+ * @param MessageSource the source of translation messages.
+ * @param string charset for the message output.
+ */
+ function __construct(IMessageSource $source, $charset='UTF-8')
+ {
+ $this->source = $source;
+ $this->setCharset($charset);
+ }
+
+ /**
+ * Sets the charset for message output.
+ * @param string charset, default is UTF-8
+ */
+ public function setCharset($charset)
+ {
+ $this->charset = $charset;
+ }
+
+ /**
+ * Gets the charset for message output. Default is UTF-8.
+ * @return string charset, default UTF-8
+ */
+ public function getCharset()
+ {
+ return $this->charset;
+ }
+
+ /**
+ * Load the message from a particular catalogue. A listed
+ * loaded catalogues is kept to prevent reload of the same
+ * catalogue. The load catalogue messages are stored
+ * in the $this->message array.
+ * @param string message catalogue to load.
+ */
+ protected function loadCatalogue($catalogue)
+ {
+ if(in_array($catalogue,$this->catagloues))
+ return;
+
+ if($this->source->load($catalogue))
+ {
+ $this->messages[$catalogue] = $this->source->read();
+ $this->catagloues[] = $catalogue;
+ }
+ }
+
+ /**
+ * Format the string. That is, for a particular string find
+ * the corresponding translation. Variable subsitution is performed
+ * for the $args parameter. A different catalogue can be specified
+ * using the $catalogue parameter.
+ * The output charset is determined by $this->getCharset();
+ * @param string the string to translate.
+ * @param array a list of string to substitute.
+ * @param string get the translation from a particular message
+ * @param string charset, the input AND output charset
+ * catalogue.
+ * @return string translated string.
+ */
+ public function format($string,$args=array(), $catalogue=null, $charset=null)
+ {
+ if(empty($charset)) $charset = $this->getCharset();
+
+ //force args as UTF-8
+ foreach($args as $k => $v)
+ $args[$k] = I18N_toUTF8($v, $charset);
+ $s = $this->formatString(I18N_toUTF8($string, $charset),$args,$catalogue);
+ return I18N_toEncoding($s, $charset);
+ }
+
+ /**
+ * Do string translation.
+ * @param string the string to translate.
+ * @param array a list of string to substitute.
+ * @param string get the translation from a particular message
+ * catalogue.
+ * @return string translated string.
+ */
+ protected function formatString($string, $args=array(), $catalogue=null)
+ {
+ if(empty($catalogue))
+ {
+ if(empty($this->Catalogue))
+ $catalogue = 'messages';
+ else
+ $catalogue = $this->Catalogue;
+ }
+
+ $this->loadCatalogue($catalogue);
+
+ if(empty($args))
+ $args = array();
+
+ foreach($this->messages[$catalogue] as $variant)
+ {
+ // foreach of the translation units
+ foreach($variant as $source => $result)
+ {
+ // we found it, so return the target translation
+ if($source == $string)
+ {
+ //check if it contains only strings.
+ if(is_string($result))
+ $target = $result;
+ else
+ {
+ $target = $result[0];
+ }
+ //found, but untranslated
+ if(empty($target))
+ {
+ return $this->postscript[0].
+ strtr($string, $args).
+ $this->postscript[1];
+ }
+ else
+ return strtr($target, $args);
+ }
+ }
+ }
+
+ // well we did not find the translation string.
+ $this->source->append($string);
+
+ return $this->postscript[0].
+ strtr($string, $args).
+ $this->postscript[1];
+ }
+
+ /**
+ * Get the message source.
+ * @return MessageSource
+ */
+ function getSource()
+ {
+ return $this->source;
+ }
+
+ /**
+ * Set the prefix and suffix to append to untranslated messages.
+ * e.g. $postscript=array('[T]','[/T]'); will output
+ * "[T]Hello[/T]" if the translation for "Hello" can not be determined.
+ * @param array first element is the prefix, second element the suffix.
+ */
+ function setUntranslatedPS($postscript)
+ {
+ if(is_array($postscript) && count($postscript)>=2)
+ {
+ $this->postscript[0] = $postscript[0];
+ $this->postscript[1] = $postscript[1];
+ }
+ }
+}
+
diff --git a/framework/I18N/core/MessageSource.php b/framework/I18N/core/MessageSource.php
index 76d06e9d..f0f94015 100644
--- a/framework/I18N/core/MessageSource.php
+++ b/framework/I18N/core/MessageSource.php
@@ -1,336 +1,336 @@
-<?php
-
-/**
- * MessageSource class file.
- *
- * This program is free software; you can redistribute it and/or modify
- * it under the terms of the BSD License.
- *
- * Copyright(c) 2004 by Qiang Xue. All rights reserved.
- *
- * To contact the author write to {@link mailto:qiang.xue@gmail.com Qiang Xue}
- * The latest version of PRADO can be obtained from:
- * {@link http://prado.sourceforge.net/}
- *
- * @author Wei Zhuo <weizhuo[at]gmail[dot]com>
- * @version $Revision: 1.4 $ $Date: 2005/12/17 06:11:28 $
- * @package System.I18N.core
- */
-
- /**
- * Get the IMessageSource interface.
- */
-require_once(dirname(__FILE__).'/IMessageSource.php');
-
-/**
- * Get the MessageCache class file.
- */
-require_once(dirname(__FILE__).'/MessageCache.php');
-
-/**
- * Abstract MessageSource class.
- *
- * The base class for all MessageSources. Message sources must be instantiated
- * using the factory method. The default valid sources are
- *
- * # XLIFF -- using XML XLIFF format to store the translation messages.
- * # gettext -- Translated messages are stored in the gettext format.
- * # Database -- Use an existing TDbConnection to store the messages.
- * # SQLite -- (Deprecated) Store the translation messages in a SQLite database.
- * # MySQL -- (Deprecated) Using a MySQL database to store the messages.
- *
- * A custom message source can be instantiated by specifying the filename
- * parameter to point to the custom class file. E.g.
- * <code>
- * $resource = '...'; //custom message source resource
- * $classfile = '../MessageSource_MySource.php'; //custom message source
- * $source = MessageSource::factory('MySource', $resource, $classfile);
- * </code>
- *
- * If you are writting your own message sources, pay attention to the
- * loadCatalogue method. It details how the resources are loaded and cached.
- * See also the existing message source types as examples.
- *
- * The following example instantiates a Database message source, set the culture,
- * set the cache handler, and use the source in a message formatter.
- * The messages are stored using an existing connection. The source parameter
- * for the factory method must contain a valid ConnectionID.
- * <code>
- * // db1 must be already configured
- * $source = MessageSource::factory('Database', 'db1');
- *
- * //set the culture and cache, store the cache in the /tmp directory.
- * $source->setCulture('en_AU')l
- * $source->setCache(new MessageCache('/tmp'));
- *
- * $formatter = new MessageFormat($source);
- * </code>
- *
- * @author Xiang Wei Zhuo <weizhuo[at]gmail[dot]com>
- * @version v1.0, last update on Fri Dec 24 19:55:49 EST 2004
- * @package System.I18N.core
- */
-abstract class MessageSource implements IMessageSource
-{
- /**
- * The culture name for this message source.
- * @var string
- */
- protected $culture;
-
- /**
- * Array of translation messages.
- * @var array
- */
- protected $messages = array();
-
- /**
- * The source of message translations.
- * @var string
- */
- protected $source;
-
- /**
- * The translation cache.
- * @var MessageCache
- */
- protected $cache;
-
- protected $untranslated = array();
-
- /**
- * Private constructor. MessageSource must be initialized using
- * the factory method.
- */
- private function __construct()
- {
- //throw new Exception('Please use the factory method to instantiate.');
- }
-
- /**
- * Factory method to instantiate a new MessageSource depending on the
- * source type. The allowed source types are 'XLIFF', 'gettext' and
- * 'Database'. The source parameter depends on the source type.
- * For 'gettext' and 'XLIFF', 'source' should point to the directory
- * where the messages are stored.
- * For 'Database', 'source' must be a valid connection id.
- * If one of the deprecated types 'MySQL' or 'SQLite' is used,
- * 'source' must contain a valid DSN.
- *
- * Custom message source are possible by supplying the a filename parameter
- * in the factory method.
- *
- * @param string the message source type.
- * @param string the location of the resource or the ConnectionID.
- * @param string the filename of the custom message source.
- * @return MessageSource a new message source of the specified type.
- * @throws InvalidMessageSourceTypeException
- */
- static function &factory($type, $source='.', $filename='')
- {
- $types = array('XLIFF','gettext','Database','MySQL','SQLite');
-
- if(empty($filename) && !in_array($type, $types))
- throw new Exception('Invalid type "'.$type.'", valid types are '.
- implode(', ', $types));
-
- $class = 'MessageSource_'.$type;
-
- if(empty($filename))
- $filename = dirname(__FILE__).'/'.$class.'.php';
-
- if(is_file($filename) == false)
- throw new Exception("File $filename not found");
-
- include_once $filename;
-
- $obj = new $class($source);
-
- return $obj;
- }
-
- /**
- * Load a particular message catalogue. Use read() to
- * to get the array of messages. The catalogue loading sequence
- * is as follows
- *
- * # [1] call getCatalogeList($catalogue) to get a list of
- * variants for for the specified $catalogue.
- * # [2] for each of the variants, call getSource($variant)
- * to get the resource, could be a file or catalogue ID.
- * # [3] verify that this resource is valid by calling isValidSource($source)
- * # [4] try to get the messages from the cache
- * # [5] if a cache miss, call load($source) to load the message array
- * # [6] store the messages to cache.
- * # [7] continue with the foreach loop, e.g. goto [2].
- *
- * @param string a catalogue to load
- * @return boolean true if loaded, false otherwise.
- * @see read()
- */
- function load($catalogue='messages')
- {
- $variants = $this->getCatalogueList($catalogue);
-
- $this->messages = array();
-
- foreach($variants as $variant)
- {
- $source = $this->getSource($variant);
-
- if($this->isValidSource($source) == false) continue;
-
- $loadData = true;
-
- if($this->cache)
- {
- $data = $this->cache->get($variant,
- $this->culture, $this->getLastModified($source));
-
- if(is_array($data))
- {
- $this->messages[$variant] = $data;
- $loadData = false;
- }
- unset($data);
- }
- if($loadData)
- {
- $data = &$this->loadData($source);
- if(is_array($data))
- {
- $this->messages[$variant] = $data;
- if($this->cache)
- $this->cache->save($data, $variant, $this->culture);
- }
- unset($data);
- }
- }
-
- return true;
- }
-
- /**
- * Get the array of messages.
- * @param parameter
- * @return array translation messages.
- */
- public function read()
- {
- return $this->messages;
- }
-
- /**
- * Get the cache handler for this source.
- * @return MessageCache cache handler
- */
- public function getCache()
- {
- return $this->cache;
- }
-
- /**
- * Set the cache handler for caching the messages.
- * @param MessageCache the cache handler.
- */
- public function setCache(MessageCache $cache)
- {
- $this->cache = $cache;
- }
-
- /**
- * Add a untranslated message to the source. Need to call save()
- * to save the messages to source.
- * @param string message to add
- */
- public function append($message)
- {
- if(!in_array($message, $this->untranslated))
- $this->untranslated[] = $message;
- }
-
- /**
- * Set the culture for this message source.
- * @param string culture name
- */
- public function setCulture($culture)
- {
- $this->culture = $culture;
- }
-
- /**
- * Get the culture identifier for the source.
- * @return string culture identifier.
- */
- public function getCulture()
- {
- return $this->culture;
- }
-
- /**
- * Get the last modified unix-time for this particular catalogue+variant.
- * @param string catalogue+variant
- * @return int last modified in unix-time format.
- */
- protected function getLastModified($source)
- {
- return 0;
- }
-
- /**
- * Load the message for a particular catalogue+variant.
- * This methods needs to implemented by subclasses.
- * @param string catalogue+variant.
- * @return array of translation messages.
- */
- protected function &loadData($variant)
- {
- return array();
- }
-
- /**
- * Get the source, this could be a filename or database ID.
- * @param string catalogue+variant
- * @return string the resource key
- */
- protected function getSource($variant)
- {
- return $variant;
- }
-
- /**
- * Determine if the source is valid.
- * @param string catalogue+variant
- * @return boolean true if valid, false otherwise.
- */
- protected function isValidSource($source)
- {
- return false;
- }
-
- /**
- * Get all the variants of a particular catalogue.
- * This method must be implemented by subclasses.
- * @param string catalogue name
- * @return array list of all variants for this catalogue.
- */
- protected function getCatalogueList($catalogue)
- {
- return array();
- }
-}
-
-
-/**
- * TMessageSourceIOException thrown when unable to modify message source
- * data.
- *
- * @author Wei Zhuo<weizhuo[at]gmail[dot]com>
- * @version $Revision: 1.4 $ $Date: 2005/12/17 06:11:28 ${DATE} ${TIME} $
- * @package System.I18N.core
- */
-class TMessageSourceIOException extends TException
-{
-
-}
-?>
+<?php
+
+/**
+ * MessageSource class file.
+ *
+ * This program is free software; you can redistribute it and/or modify
+ * it under the terms of the BSD License.
+ *
+ * Copyright(c) 2004 by Qiang Xue. All rights reserved.
+ *
+ * To contact the author write to {@link mailto:qiang.xue@gmail.com Qiang Xue}
+ * The latest version of PRADO can be obtained from:
+ * {@link http://prado.sourceforge.net/}
+ *
+ * @author Wei Zhuo <weizhuo[at]gmail[dot]com>
+ * @version $Revision: 1.4 $ $Date: 2005/12/17 06:11:28 $
+ * @package System.I18N.core
+ */
+
+ /**
+ * Get the IMessageSource interface.
+ */
+require_once(dirname(__FILE__).'/IMessageSource.php');
+
+/**
+ * Get the MessageCache class file.
+ */
+require_once(dirname(__FILE__).'/MessageCache.php');
+
+/**
+ * Abstract MessageSource class.
+ *
+ * The base class for all MessageSources. Message sources must be instantiated
+ * using the factory method. The default valid sources are
+ *
+ * # XLIFF -- using XML XLIFF format to store the translation messages.
+ * # gettext -- Translated messages are stored in the gettext format.
+ * # Database -- Use an existing TDbConnection to store the messages.
+ * # SQLite -- (Deprecated) Store the translation messages in a SQLite database.
+ * # MySQL -- (Deprecated) Using a MySQL database to store the messages.
+ *
+ * A custom message source can be instantiated by specifying the filename
+ * parameter to point to the custom class file. E.g.
+ * <code>
+ * $resource = '...'; //custom message source resource
+ * $classfile = '../MessageSource_MySource.php'; //custom message source
+ * $source = MessageSource::factory('MySource', $resource, $classfile);
+ * </code>
+ *
+ * If you are writting your own message sources, pay attention to the
+ * loadCatalogue method. It details how the resources are loaded and cached.
+ * See also the existing message source types as examples.
+ *
+ * The following example instantiates a Database message source, set the culture,
+ * set the cache handler, and use the source in a message formatter.
+ * The messages are stored using an existing connection. The source parameter
+ * for the factory method must contain a valid ConnectionID.
+ * <code>
+ * // db1 must be already configured
+ * $source = MessageSource::factory('Database', 'db1');
+ *
+ * //set the culture and cache, store the cache in the /tmp directory.
+ * $source->setCulture('en_AU')l
+ * $source->setCache(new MessageCache('/tmp'));
+ *
+ * $formatter = new MessageFormat($source);
+ * </code>
+ *
+ * @author Xiang Wei Zhuo <weizhuo[at]gmail[dot]com>
+ * @version v1.0, last update on Fri Dec 24 19:55:49 EST 2004
+ * @package System.I18N.core
+ */
+abstract class MessageSource implements IMessageSource
+{
+ /**
+ * The culture name for this message source.
+ * @var string
+ */
+ protected $culture;
+
+ /**
+ * Array of translation messages.
+ * @var array
+ */
+ protected $messages = array();
+
+ /**
+ * The source of message translations.
+ * @var string
+ */
+ protected $source;
+
+ /**
+ * The translation cache.
+ * @var MessageCache
+ */
+ protected $cache;
+
+ protected $untranslated = array();
+
+ /**
+ * Private constructor. MessageSource must be initialized using
+ * the factory method.
+ */
+ private function __construct()
+ {
+ //throw new Exception('Please use the factory method to instantiate.');
+ }
+
+ /**
+ * Factory method to instantiate a new MessageSource depending on the
+ * source type. The allowed source types are 'XLIFF', 'gettext' and
+ * 'Database'. The source parameter depends on the source type.
+ * For 'gettext' and 'XLIFF', 'source' should point to the directory
+ * where the messages are stored.
+ * For 'Database', 'source' must be a valid connection id.
+ * If one of the deprecated types 'MySQL' or 'SQLite' is used,
+ * 'source' must contain a valid DSN.
+ *
+ * Custom message source are possible by supplying the a filename parameter
+ * in the factory method.
+ *
+ * @param string the message source type.
+ * @param string the location of the resource or the ConnectionID.
+ * @param string the filename of the custom message source.
+ * @return MessageSource a new message source of the specified type.
+ * @throws InvalidMessageSourceTypeException
+ */
+ static function &factory($type, $source='.', $filename='')
+ {
+ $types = array('XLIFF','gettext','Database','MySQL','SQLite');
+
+ if(empty($filename) && !in_array($type, $types))
+ throw new Exception('Invalid type "'.$type.'", valid types are '.
+ implode(', ', $types));
+
+ $class = 'MessageSource_'.$type;
+
+ if(empty($filename))
+ $filename = dirname(__FILE__).'/'.$class.'.php';
+
+ if(is_file($filename) == false)
+ throw new Exception("File $filename not found");
+
+ include_once $filename;
+
+ $obj = new $class($source);
+
+ return $obj;
+ }
+
+ /**
+ * Load a particular message catalogue. Use read() to
+ * to get the array of messages. The catalogue loading sequence
+ * is as follows
+ *
+ * # [1] call getCatalogeList($catalogue) to get a list of
+ * variants for for the specified $catalogue.
+ * # [2] for each of the variants, call getSource($variant)
+ * to get the resource, could be a file or catalogue ID.
+ * # [3] verify that this resource is valid by calling isValidSource($source)
+ * # [4] try to get the messages from the cache
+ * # [5] if a cache miss, call load($source) to load the message array
+ * # [6] store the messages to cache.
+ * # [7] continue with the foreach loop, e.g. goto [2].
+ *
+ * @param string a catalogue to load
+ * @return boolean true if loaded, false otherwise.
+ * @see read()
+ */
+ function load($catalogue='messages')
+ {
+ $variants = $this->getCatalogueList($catalogue);
+
+ $this->messages = array();
+
+ foreach($variants as $variant)
+ {
+ $source = $this->getSource($variant);
+
+ if($this->isValidSource($source) == false) continue;
+
+ $loadData = true;
+
+ if($this->cache)
+ {
+ $data = $this->cache->get($variant,
+ $this->culture, $this->getLastModified($source));
+
+ if(is_array($data))
+ {
+ $this->messages[$variant] = $data;
+ $loadData = false;
+ }
+ unset($data);
+ }
+ if($loadData)
+ {
+ $data = &$this->loadData($source);
+ if(is_array($data))
+ {
+ $this->messages[$variant] = $data;
+ if($this->cache)
+ $this->cache->save($data, $variant, $this->culture);
+ }
+ unset($data);
+ }
+ }
+
+ return true;
+ }
+
+ /**
+ * Get the array of messages.
+ * @param parameter
+ * @return array translation messages.
+ */
+ public function read()
+ {
+ return $this->messages;
+ }
+
+ /**
+ * Get the cache handler for this source.
+ * @return MessageCache cache handler
+ */
+ public function getCache()
+ {
+ return $this->cache;
+ }
+
+ /**
+ * Set the cache handler for caching the messages.
+ * @param MessageCache the cache handler.
+ */
+ public function setCache(MessageCache $cache)
+ {
+ $this->cache = $cache;
+ }
+
+ /**
+ * Add a untranslated message to the source. Need to call save()
+ * to save the messages to source.
+ * @param string message to add
+ */
+ public function append($message)
+ {
+ if(!in_array($message, $this->untranslated))
+ $this->untranslated[] = $message;
+ }
+
+ /**
+ * Set the culture for this message source.
+ * @param string culture name
+ */
+ public function setCulture($culture)
+ {
+ $this->culture = $culture;
+ }
+
+ /**
+ * Get the culture identifier for the source.
+ * @return string culture identifier.
+ */
+ public function getCulture()
+ {
+ return $this->culture;
+ }
+
+ /**
+ * Get the last modified unix-time for this particular catalogue+variant.
+ * @param string catalogue+variant
+ * @return int last modified in unix-time format.
+ */
+ protected function getLastModified($source)
+ {
+ return 0;
+ }
+
+ /**
+ * Load the message for a particular catalogue+variant.
+ * This methods needs to implemented by subclasses.
+ * @param string catalogue+variant.
+ * @return array of translation messages.
+ */
+ protected function &loadData($variant)
+ {
+ return array();
+ }
+
+ /**
+ * Get the source, this could be a filename or database ID.
+ * @param string catalogue+variant
+ * @return string the resource key
+ */
+ protected function getSource($variant)
+ {
+ return $variant;
+ }
+
+ /**
+ * Determine if the source is valid.
+ * @param string catalogue+variant
+ * @return boolean true if valid, false otherwise.
+ */
+ protected function isValidSource($source)
+ {
+ return false;
+ }
+
+ /**
+ * Get all the variants of a particular catalogue.
+ * This method must be implemented by subclasses.
+ * @param string catalogue name
+ * @return array list of all variants for this catalogue.
+ */
+ protected function getCatalogueList($catalogue)
+ {
+ return array();
+ }
+}
+
+
+/**
+ * TMessageSourceIOException thrown when unable to modify message source
+ * data.
+ *
+ * @author Wei Zhuo<weizhuo[at]gmail[dot]com>
+ * @version $Revision: 1.4 $ $Date: 2005/12/17 06:11:28 ${DATE} ${TIME} $
+ * @package System.I18N.core
+ */
+class TMessageSourceIOException extends TException
+{
+
+}
+?>
diff --git a/framework/I18N/core/MessageSource_Database.php b/framework/I18N/core/MessageSource_Database.php
index 3ccea61b..549d1c40 100644
--- a/framework/I18N/core/MessageSource_Database.php
+++ b/framework/I18N/core/MessageSource_Database.php
@@ -1,323 +1,323 @@
-<?php
-/**
- * MessageSource_Database class file.
- *
- * This program is free software; you can redistribute it and/or modify
- * it under the terms of the BSD License.
- *
- * Copyright(c) 2004 by Qiang Xue. All rights reserved.
- *
- * To contact the author write to {@link mailto:qiang.xue@gmail.com Qiang Xue}
- * The latest version of PRADO can be obtained from:
- * {@link http://prado.sourceforge.net/}
- *
- * @package System.I18N.core
- */
-
-/**
- * Get the MessageSource class file.
- */
-require_once(dirname(__FILE__).'/MessageSource.php');
-
-/**
- * MessageSource_Database class.
- *
- * Retrive the message translation from a database.
- *
- * See the MessageSource::factory() method to instantiate this class.
- *
- * @package System.I18N.core
- */
-class MessageSource_Database extends MessageSource
-{
- private $_connID='';
- private $_conn;
-
- /**
- * Constructor.
- * Create a new message source using a Database
- * @param string MySQL datasource, in PEAR's DB DSN format.
- * @see MessageSource::factory();
- */
- function __construct($source)
- {
- $this->_connID= (string)$source;
- }
-
- /**
- * @return TDbConnection the database connection that may be used to retrieve messages.
- */
- public function getDbConnection()
- {
- if($this->_conn===null)
- {
- $this->_conn=$this->createDbConnection($this->_connID);
- $this->_conn->setActive(true);
- }
- return $this->_conn;
- }
-
- /**
- * Creates the DB connection.
- * @param string the module ID for TDataSourceConfig
- * @return TDbConnection the created DB connection
- * @throws TConfigurationException if module ID is invalid or empty
- */
- protected function createDbConnection($connectionID)
- {
- if($connectionID!=='')
- {
- $conn=Prado::getApplication()->getModule($connectionID);
- if($conn instanceof TDataSourceConfig)
- return $conn->getDbConnection();
- else
- throw new TConfigurationException('messagesource_connectionid_invalid',$connectionID);
- }
- else
- throw new TConfigurationException('messagesource_connectionid_required');
- }
-
- /**
- * Get an array of messages for a particular catalogue and cultural
- * variant.
- * @param string the catalogue name + variant
- * @return array translation messages.
- */
- protected function &loadData($variant)
- {
- $command=$this->getDBConnection()->createCommand(
- 'SELECT t.id, t.source, t.target, t.comments
- FROM trans_unit t, catalogue c
- WHERE c.cat_id = t.cat_id
- AND c.name = :variant
- ORDER BY id ASC');
- $command->bindParameter(':variant',$variant,PDO::PARAM_STR);
- $dataReader=$command->query();
-
- $result = array();
-
- foreach ($dataReader as $row)
- $result[$row['source']] = array($row['target'],$row['id'],$row['comments']);
-
- return $result;
- }
-
- /**
- * Get the last modified unix-time for this particular catalogue+variant.
- * We need to query the database to get the date_modified.
- * @param string catalogue+variant
- * @return int last modified in unix-time format.
- */
- protected function getLastModified($source)
- {
- $command=$this->getDBConnection()->createCommand(
- 'SELECT date_modified FROM catalogue WHERE name = :source');
- $command->bindParameter(':source',$source,PDO::PARAM_STR);
- $result=$command->queryScalar();
- return $result ? $result : 0;
- }
-
-
- /**
- * Check if a particular catalogue+variant exists in the database.
- * @param string catalogue+variant
- * @return boolean true if the catalogue+variant is in the database,
- * false otherwise.
- */
- protected function isValidSource($variant)
- {
- $command=$this->getDBConnection()->createCommand(
- 'SELECT COUNT(*) FROM catalogue WHERE name = :variant');
- $command->bindParameter(':variant',$variant,PDO::PARAM_STR);
- return $command->queryScalar()==1;
- }
-
- /**
- * Get all the variants of a particular catalogue.
- * @param string catalogue name
- * @return array list of all variants for this catalogue.
- */
- protected function getCatalogueList($catalogue)
- {
- $variants = explode('_',$this->culture);
-
- $catalogues = array($catalogue);
-
- $variant = null;
-
- for($i = 0, $k = count($variants); $i < $k; ++$i)
- {
- if(isset($variants[$i]{0}))
- {
- $variant .= ($variant)?'_'.$variants[$i]:$variants[$i];
- $catalogues[] = $catalogue.'.'.$variant;
- }
- }
- return array_reverse($catalogues);
- }
-
- /**
- * Retrive catalogue details, array($cat_id, $variant, $count).
- * @param string catalogue
- * @return array catalogue details, array($cat_id, $variant, $count).
- */
- private function getCatalogueDetails($catalogue='messages')
- {
- if(empty($catalogue))
- $catalogue = 'messages';
-
- $variant = $catalogue.'.'.$this->culture;
-
- $command=$this->getDBConnection()->createCommand(
- 'SELECT cat_id FROM catalogue WHERE name = :variant');
- $command->bindParameter(':variant',$variant,PDO::PARAM_STR);
- $cat_id=$command->queryScalar();
-
- if ($cat_id===null) return false;
-
- $command=$this->getDBConnection()->createCommand(
- 'SELECT COUNT(msg_id) FROM trans_unit WHERE cat_id = :catid ');
- $command->bindParameter(':catid',$cat_id,PDO::PARAM_INT);
- $count=$command->queryScalar();
-
- return array($cat_id, $variant, $count);
- }
-
- /**
- * Update the catalogue last modified time.
- * @return boolean true if updated, false otherwise.
- */
- private function updateCatalogueTime($cat_id, $variant)
- {
- $time = time();
- $command=$this->getDBConnection()->createCommand(
- 'UPDATE catalogue SET date_modified = :moddate WHERE cat_id = :catid');
- $command->bindParameter(':moddate',$time,PDO::PARAM_INT);
- $command->bindParameter(':catid',$cat_id,PDO::PARAM_INT);
- $result=$command->execute();
-
- if(!empty($this->cache))
- $this->cache->clean($variant, $this->culture);
-
- return $result;
- }
-
- /**
- * Save the list of untranslated blocks to the translation source.
- * If the translation was not found, you should add those
- * strings to the translation source via the <b>append()</b> method.
- * @param string the catalogue to add to
- * @return boolean true if saved successfuly, false otherwise.
- */
- function save($catalogue='messages')
- {
- $messages = $this->untranslated;
-
- if(count($messages) <= 0) return false;
-
- $details = $this->getCatalogueDetails($catalogue);
-
- if($details)
- list($cat_id, $variant, $count) = $details;
- else
- return false;
-
- if($cat_id <= 0) return false;
- $inserted = 0;
-
- $time = time();
-
- $command=$this->getDBConnection()->createCommand(
- 'INSERT INTO trans_unit (cat_id,id,source,date_added) VALUES (:catid,:id,:source,:dateadded)');
- $command->bindParameter(':catid',$cat_id,PDO::PARAM_INT);
- $command->bindParameter(':id',$count,PDO::PARAM_INT);
- $command->bindParameter(':source',$message,PDO::PARAM_STR);
- $command->bindParameter(':dateadded',$time,PDO::PARAM_INT);
- foreach($messages as $message)
- {
- if (empty($message)) continue;
- $count++; $inserted++;
- $command->execute();
- }
- if($inserted > 0)
- $this->updateCatalogueTime($cat_id, $variant);
-
- return $inserted > 0;
- }
-
- /**
- * Delete a particular message from the specified catalogue.
- * @param string the source message to delete.
- * @param string the catalogue to delete from.
- * @return boolean true if deleted, false otherwise.
- */
- function delete($message, $catalogue='messages')
- {
- $details = $this->getCatalogueDetails($catalogue);
- if($details)
- list($cat_id, $variant, $count) = $details;
- else
- return false;
-
- $command=$this->getDBConnection()->createCommand(
- 'DELETE FROM trans_unit WHERE cat_id = :catid AND source = :message');
- $command->bindParameter(':catid',$cat_id,PDO::PARAM_INT);
- $command->bindParameter(':message',$message,PDO::PARAM_STR);
-
- return ($command->execute()==1) ? $this->updateCatalogueTime($cat_id, $variant) : false;
-
- }
-
- /**
- * Update the translation.
- * @param string the source string.
- * @param string the new translation string.
- * @param string comments
- * @param string the catalogue of the translation.
- * @return boolean true if translation was updated, false otherwise.
- */
- function update($text, $target, $comments, $catalogue='messages')
- {
- $details = $this->getCatalogueDetails($catalogue);
- if($details)
- list($cat_id, $variant, $count) = $details;
- else
- return false;
-
- $time = time();
- $command=$this->getDBConnection()->createCommand(
- 'UPDATE trans_unit SET target = :target, comments = :comments, date_modified = :datemod
- WHERE cat_id = :catid AND source = :source');
- $command->bindParameter(':target',$target,PDO::PARAM_STR);
- $command->bindParameter(':comments',$comments,PDO::PARAM_STR);
- $command->bindParameter(':datemod',$time,PDO::PARAM_INT);
- $command->bindParameter(':catid',$cat_id,PDO::PARAM_INT);
- $command->bindParameter(':source',$text,PDO::PARAM_STR);
-
- return ($command->execute()==1) ? $this->updateCatalogueTime($cat_id, $variant) : false;
- }
-
- /**
- * Returns a list of catalogue as key and all it variants as value.
- * @return array list of catalogues
- */
- function catalogues()
- {
- $command=$this->getDBConnection()->createCommand( 'SELECT name FROM catalogue ORDER BY name');
- $dataReader=$command->query();
-
- $result = array();
-
- foreach ($dataReader as $row)
- {
- $details = explode('.',$row[0]);
- if(!isset($details[1])) $details[1] = null;
-
- $result[] = $details;
- }
-
- return $result;
- }
-
-}
-?>
+<?php
+/**
+ * MessageSource_Database class file.
+ *
+ * This program is free software; you can redistribute it and/or modify
+ * it under the terms of the BSD License.
+ *
+ * Copyright(c) 2004 by Qiang Xue. All rights reserved.
+ *
+ * To contact the author write to {@link mailto:qiang.xue@gmail.com Qiang Xue}
+ * The latest version of PRADO can be obtained from:
+ * {@link http://prado.sourceforge.net/}
+ *
+ * @package System.I18N.core
+ */
+
+/**
+ * Get the MessageSource class file.
+ */
+require_once(dirname(__FILE__).'/MessageSource.php');
+
+/**
+ * MessageSource_Database class.
+ *
+ * Retrive the message translation from a database.
+ *
+ * See the MessageSource::factory() method to instantiate this class.
+ *
+ * @package System.I18N.core
+ */
+class MessageSource_Database extends MessageSource
+{
+ private $_connID='';
+ private $_conn;
+
+ /**
+ * Constructor.
+ * Create a new message source using a Database
+ * @param string MySQL datasource, in PEAR's DB DSN format.
+ * @see MessageSource::factory();
+ */
+ function __construct($source)
+ {
+ $this->_connID= (string)$source;
+ }
+
+ /**
+ * @return TDbConnection the database connection that may be used to retrieve messages.
+ */
+ public function getDbConnection()
+ {
+ if($this->_conn===null)
+ {
+ $this->_conn=$this->createDbConnection($this->_connID);
+ $this->_conn->setActive(true);
+ }
+ return $this->_conn;
+ }
+
+ /**
+ * Creates the DB connection.
+ * @param string the module ID for TDataSourceConfig
+ * @return TDbConnection the created DB connection
+ * @throws TConfigurationException if module ID is invalid or empty
+ */
+ protected function createDbConnection($connectionID)
+ {
+ if($connectionID!=='')
+ {
+ $conn=Prado::getApplication()->getModule($connectionID);
+ if($conn instanceof TDataSourceConfig)
+ return $conn->getDbConnection();
+ else
+ throw new TConfigurationException('messagesource_connectionid_invalid',$connectionID);
+ }
+ else
+ throw new TConfigurationException('messagesource_connectionid_required');
+ }
+
+ /**
+ * Get an array of messages for a particular catalogue and cultural
+ * variant.
+ * @param string the catalogue name + variant
+ * @return array translation messages.
+ */
+ protected function &loadData($variant)
+ {
+ $command=$this->getDBConnection()->createCommand(
+ 'SELECT t.id, t.source, t.target, t.comments
+ FROM trans_unit t, catalogue c
+ WHERE c.cat_id = t.cat_id
+ AND c.name = :variant
+ ORDER BY id ASC');
+ $command->bindParameter(':variant',$variant,PDO::PARAM_STR);
+ $dataReader=$command->query();
+
+ $result = array();
+
+ foreach ($dataReader as $row)
+ $result[$row['source']] = array($row['target'],$row['id'],$row['comments']);
+
+ return $result;
+ }
+
+ /**
+ * Get the last modified unix-time for this particular catalogue+variant.
+ * We need to query the database to get the date_modified.
+ * @param string catalogue+variant
+ * @return int last modified in unix-time format.
+ */
+ protected function getLastModified($source)
+ {
+ $command=$this->getDBConnection()->createCommand(
+ 'SELECT date_modified FROM catalogue WHERE name = :source');
+ $command->bindParameter(':source',$source,PDO::PARAM_STR);
+ $result=$command->queryScalar();
+ return $result ? $result : 0;
+ }
+
+
+ /**
+ * Check if a particular catalogue+variant exists in the database.
+ * @param string catalogue+variant
+ * @return boolean true if the catalogue+variant is in the database,
+ * false otherwise.
+ */
+ protected function isValidSource($variant)
+ {
+ $command=$this->getDBConnection()->createCommand(
+ 'SELECT COUNT(*) FROM catalogue WHERE name = :variant');
+ $command->bindParameter(':variant',$variant,PDO::PARAM_STR);
+ return $command->queryScalar()==1;
+ }
+
+ /**
+ * Get all the variants of a particular catalogue.
+ * @param string catalogue name
+ * @return array list of all variants for this catalogue.
+ */
+ protected function getCatalogueList($catalogue)
+ {
+ $variants = explode('_',$this->culture);
+
+ $catalogues = array($catalogue);
+
+ $variant = null;
+
+ for($i = 0, $k = count($variants); $i < $k; ++$i)
+ {
+ if(isset($variants[$i]{0}))
+ {
+ $variant .= ($variant)?'_'.$variants[$i]:$variants[$i];
+ $catalogues[] = $catalogue.'.'.$variant;
+ }
+ }
+ return array_reverse($catalogues);
+ }
+
+ /**
+ * Retrive catalogue details, array($cat_id, $variant, $count).
+ * @param string catalogue
+ * @return array catalogue details, array($cat_id, $variant, $count).
+ */
+ private function getCatalogueDetails($catalogue='messages')
+ {
+ if(empty($catalogue))
+ $catalogue = 'messages';
+
+ $variant = $catalogue.'.'.$this->culture;
+
+ $command=$this->getDBConnection()->createCommand(
+ 'SELECT cat_id FROM catalogue WHERE name = :variant');
+ $command->bindParameter(':variant',$variant,PDO::PARAM_STR);
+ $cat_id=$command->queryScalar();
+
+ if ($cat_id===null) return false;
+
+ $command=$this->getDBConnection()->createCommand(
+ 'SELECT COUNT(msg_id) FROM trans_unit WHERE cat_id = :catid ');
+ $command->bindParameter(':catid',$cat_id,PDO::PARAM_INT);
+ $count=$command->queryScalar();
+
+ return array($cat_id, $variant, $count);
+ }
+
+ /**
+ * Update the catalogue last modified time.
+ * @return boolean true if updated, false otherwise.
+ */
+ private function updateCatalogueTime($cat_id, $variant)
+ {
+ $time = time();
+ $command=$this->getDBConnection()->createCommand(
+ 'UPDATE catalogue SET date_modified = :moddate WHERE cat_id = :catid');
+ $command->bindParameter(':moddate',$time,PDO::PARAM_INT);
+ $command->bindParameter(':catid',$cat_id,PDO::PARAM_INT);
+ $result=$command->execute();
+
+ if(!empty($this->cache))
+ $this->cache->clean($variant, $this->culture);
+
+ return $result;
+ }
+
+ /**
+ * Save the list of untranslated blocks to the translation source.
+ * If the translation was not found, you should add those
+ * strings to the translation source via the <b>append()</b> method.
+ * @param string the catalogue to add to
+ * @return boolean true if saved successfuly, false otherwise.
+ */
+ function save($catalogue='messages')
+ {
+ $messages = $this->untranslated;
+
+ if(count($messages) <= 0) return false;
+
+ $details = $this->getCatalogueDetails($catalogue);
+
+ if($details)
+ list($cat_id, $variant, $count) = $details;
+ else
+ return false;
+
+ if($cat_id <= 0) return false;
+ $inserted = 0;
+
+ $time = time();
+
+ $command=$this->getDBConnection()->createCommand(
+ 'INSERT INTO trans_unit (cat_id,id,source,date_added) VALUES (:catid,:id,:source,:dateadded)');
+ $command->bindParameter(':catid',$cat_id,PDO::PARAM_INT);
+ $command->bindParameter(':id',$count,PDO::PARAM_INT);
+ $command->bindParameter(':source',$message,PDO::PARAM_STR);
+ $command->bindParameter(':dateadded',$time,PDO::PARAM_INT);
+ foreach($messages as $message)
+ {
+ if (empty($message)) continue;
+ $count++; $inserted++;
+ $command->execute();
+ }
+ if($inserted > 0)
+ $this->updateCatalogueTime($cat_id, $variant);
+
+ return $inserted > 0;
+ }
+
+ /**
+ * Delete a particular message from the specified catalogue.
+ * @param string the source message to delete.
+ * @param string the catalogue to delete from.
+ * @return boolean true if deleted, false otherwise.
+ */
+ function delete($message, $catalogue='messages')
+ {
+ $details = $this->getCatalogueDetails($catalogue);
+ if($details)
+ list($cat_id, $variant, $count) = $details;
+ else
+ return false;
+
+ $command=$this->getDBConnection()->createCommand(
+ 'DELETE FROM trans_unit WHERE cat_id = :catid AND source = :message');
+ $command->bindParameter(':catid',$cat_id,PDO::PARAM_INT);
+ $command->bindParameter(':message',$message,PDO::PARAM_STR);
+
+ return ($command->execute()==1) ? $this->updateCatalogueTime($cat_id, $variant) : false;
+
+ }
+
+ /**
+ * Update the translation.
+ * @param string the source string.
+ * @param string the new translation string.
+ * @param string comments
+ * @param string the catalogue of the translation.
+ * @return boolean true if translation was updated, false otherwise.
+ */
+ function update($text, $target, $comments, $catalogue='messages')
+ {
+ $details = $this->getCatalogueDetails($catalogue);
+ if($details)
+ list($cat_id, $variant, $count) = $details;
+ else
+ return false;
+
+ $time = time();
+ $command=$this->getDBConnection()->createCommand(
+ 'UPDATE trans_unit SET target = :target, comments = :comments, date_modified = :datemod
+ WHERE cat_id = :catid AND source = :source');
+ $command->bindParameter(':target',$target,PDO::PARAM_STR);
+ $command->bindParameter(':comments',$comments,PDO::PARAM_STR);
+ $command->bindParameter(':datemod',$time,PDO::PARAM_INT);
+ $command->bindParameter(':catid',$cat_id,PDO::PARAM_INT);
+ $command->bindParameter(':source',$text,PDO::PARAM_STR);
+
+ return ($command->execute()==1) ? $this->updateCatalogueTime($cat_id, $variant) : false;
+ }
+
+ /**
+ * Returns a list of catalogue as key and all it variants as value.
+ * @return array list of catalogues
+ */
+ function catalogues()
+ {
+ $command=$this->getDBConnection()->createCommand( 'SELECT name FROM catalogue ORDER BY name');
+ $dataReader=$command->query();
+
+ $result = array();
+
+ foreach ($dataReader as $row)
+ {
+ $details = explode('.',$row[0]);
+ if(!isset($details[1])) $details[1] = null;
+
+ $result[] = $details;
+ }
+
+ return $result;
+ }
+
+}
+?>
diff --git a/framework/I18N/core/MessageSource_MySQL.php b/framework/I18N/core/MessageSource_MySQL.php
index 080b89bc..0cd893d4 100644
--- a/framework/I18N/core/MessageSource_MySQL.php
+++ b/framework/I18N/core/MessageSource_MySQL.php
@@ -1,418 +1,418 @@
-<?php
-
-/**
- * MessageSource_MySQL class file.
- *
- * This program is free software; you can redistribute it and/or modify
- * it under the terms of the BSD License.
- *
- * Copyright(c) 2004 by Qiang Xue. All rights reserved.
- *
- * To contact the author write to {@link mailto:qiang.xue@gmail.com Qiang Xue}
- * The latest version of PRADO can be obtained from:
- * {@link http://prado.sourceforge.net/}
- *
- * @author Wei Zhuo <weizhuo[at]gmail[dot]com>
- * @version $Revision: 1.4 $ $Date: 2005/02/25 09:59:40 $
- * @package System.I18N.core
- */
-
-/**
- * Get the MessageSource class file.
- */
-require_once(dirname(__FILE__).'/MessageSource.php');
-
-/**
- * Get the I18N utility file, contains the DSN parser.
- */
-require_once(dirname(__FILE__).'/util.php');
-
-/**
- * MessageSource_MySQL class.
- *
- * Retrive the message translation from a MySQL database.
- *
- * See the MessageSource::factory() method to instantiate this class.
- *
- * @author Xiang Wei Zhuo <weizhuo[at]gmail[dot]com>
- * @version v1.0, last update on Fri Dec 24 16:58:58 EST 2004
- * @package System.I18N.core
- */
-class MessageSource_MySQL extends MessageSource
-{
- /**
- * The datasource string, full DSN to the database.
- * @var string
- */
- protected $source;
-
- /**
- * The DSN array property, parsed by PEAR's DB DSN parser.
- * @var array
- */
- protected $dns;
-
- /**
- * A resource link to the database
- * @var db
- */
- protected $db;
- /**
- * Constructor.
- * Create a new message source using MySQL.
- * @param string MySQL datasource, in PEAR's DB DSN format.
- * @see MessageSource::factory();
- */
- function __construct($source)
- {
- $this->source = (string)$source;
- $this->dns = parseDSN($this->source);
- $this->db = $this->connect();
- }
-
- /**
- * Destructor, close the database connection.
- */
- function __destruct()
- {
- @mysql_close($this->db);
- }
-
- /**
- * Connect to the MySQL datasource
- * @return resource MySQL connection.
- * @throws Exception, connection and database errors.
- */
- protected function connect()
- {
- /*static $conn;
-
- if($conn!==null)
- return $conn;
- */
- $dsninfo = $this->dns;
-
- if (isset($dsninfo['protocol']) && $dsninfo['protocol'] == 'unix')
- $dbhost = ':' . $dsninfo['socket'];
- else
- {
- $dbhost = $dsninfo['hostspec'] ? $dsninfo['hostspec'] : 'localhost';
- if (!empty($dsninfo['port']))
- $dbhost .= ':' . $dsninfo['port'];
- }
- $user = $dsninfo['username'];
- $pw = $dsninfo['password'];
-
- $connect_function = 'mysql_connect';
-
- if ($dbhost && $user && $pw)
- $conn = @$connect_function($dbhost, $user, $pw);
- elseif ($dbhost && $user)
- $conn = @$connect_function($dbhost, $user);
- elseif ($dbhost)
- $conn = @$connect_function($dbhost);
- else
- $conn = false;
-
- if (empty($conn))
- {
- throw new Exception('Error in connecting to '.$dsninfo);
- }
-
- if ($dsninfo['database'])
- {
- if (!@mysql_select_db($dsninfo['database'], $conn))
- throw new Exception('Error in connecting database, dns:'.
- $dsninfo);
- }
- else
- throw new Exception('Please provide a database for message'.
- ' translation.');
- return $conn;
- }
-
- /**
- * Get the database connection.
- * @return db database connection.
- */
- public function connection()
- {
- return $this->db;
- }
-
- /**
- * Get an array of messages for a particular catalogue and cultural
- * variant.
- * @param string the catalogue name + variant
- * @return array translation messages.
- */
- protected function &loadData($variant)
- {
- $variant = mysql_real_escape_string($variant);
-
- $statement =
- "SELECT t.id, t.source, t.target, t.comments
- FROM trans_unit t, catalogue c
- WHERE c.cat_id = t.cat_id
- AND c.name = '{$variant}'
- ORDER BY id ASC";
-
- $rs = mysql_query($statement,$this->db);
-
- $result = array();
-
- while($row = mysql_fetch_array($rs,MYSQL_NUM))
- {
- $source = $row[1];
- $result[$source][] = $row[2]; //target
- $result[$source][] = $row[0]; //id
- $result[$source][] = $row[3]; //comments
- }
-
- return $result;
- }
-
- /**
- * Get the last modified unix-time for this particular catalogue+variant.
- * We need to query the database to get the date_modified.
- * @param string catalogue+variant
- * @return int last modified in unix-time format.
- */
- protected function getLastModified($source)
- {
- $source = mysql_real_escape_string($source);
-
- $rs = mysql_query(
- "SELECT date_modified FROM catalogue WHERE name = '{$source}'",
- $this->db);
-
- $result = $rs ? (int)mysql_result($rs,0) : 0;
-
- return $result;
- }
-
- /**
- * Check if a particular catalogue+variant exists in the database.
- * @param string catalogue+variant
- * @return boolean true if the catalogue+variant is in the database,
- * false otherwise.
- */
- protected function isValidSource($variant)
- {
- $variant = mysql_real_escape_string ($variant);
-
- $rs = mysql_query(
- "SELECT COUNT(*) FROM catalogue WHERE name = '{$variant}'",
- $this->db);
-
- $row = mysql_fetch_array($rs,MYSQL_NUM);
-
- $result = $row && $row[0] == '1';
-
- return $result;
- }
-
- /**
- * Get all the variants of a particular catalogue.
- * @param string catalogue name
- * @return array list of all variants for this catalogue.
- */
- protected function getCatalogueList($catalogue)
- {
- $variants = explode('_',$this->culture);
-
- $catalogues = array($catalogue);
-
- $variant = null;
-
- for($i = 0, $k = count($variants); $i < $k; ++$i)
- {
- if(isset($variants[$i]{0}))
- {
- $variant .= ($variant)?'_'.$variants[$i]:$variants[$i];
- $catalogues[] = $catalogue.'.'.$variant;
- }
- }
- return array_reverse($catalogues);
- }
-
- /**
- * Retrive catalogue details, array($cat_id, $variant, $count).
- * @param string catalogue
- * @return array catalogue details, array($cat_id, $variant, $count).
- */
- private function getCatalogueDetails($catalogue='messages')
- {
- if(empty($catalogue))
- $catalogue = 'messages';
-
- $variant = $catalogue.'.'.$this->culture;
-
- $name = mysql_real_escape_string($this->getSource($variant));
-
- $rs = mysql_query("SELECT cat_id
- FROM catalogue WHERE name = '{$name}'", $this->db);
-
- if(mysql_num_rows($rs) != 1)
- return false;
-
- $cat_id = (int)mysql_result($rs,0);
-
- //first get the catalogue ID
- $rs = mysql_query(
- "SELECT count(msg_id)
- FROM trans_unit
- WHERE cat_id = {$cat_id}", $this->db);
-
- $count = (int)mysql_result($rs,0);
-
- return array($cat_id, $variant, $count);
- }
-
- /**
- * Update the catalogue last modified time.
- * @return boolean true if updated, false otherwise.
- */
- private function updateCatalogueTime($cat_id, $variant)
- {
- $time = time();
-
- $result = mysql_query("UPDATE catalogue
- SET date_modified = {$time}
- WHERE cat_id = {$cat_id}", $this->db);
-
- if(!empty($this->cache))
- $this->cache->clean($variant, $this->culture);
-
- return $result;
- }
-
- /**
- * Save the list of untranslated blocks to the translation source.
- * If the translation was not found, you should add those
- * strings to the translation source via the <b>append()</b> method.
- * @param string the catalogue to add to
- * @return boolean true if saved successfuly, false otherwise.
- */
- function save($catalogue='messages')
- {
- $messages = $this->untranslated;
-
- if(count($messages) <= 0) return false;
-
- $details = $this->getCatalogueDetails($catalogue);
-
- if($details)
- list($cat_id, $variant, $count) = $details;
- else
- return false;
-
- if($cat_id <= 0) return false;
- $inserted = 0;
-
- $time = time();
-
- foreach($messages as $message)
- {
- $count++; $inserted++;
- $message = mysql_real_escape_string($message);
- $statement = "INSERT INTO trans_unit
- (cat_id,id,source,date_added) VALUES
- ({$cat_id}, {$count},'{$message}',$time)";
- mysql_query($statement, $this->db);
- }
- if($inserted > 0)
- $this->updateCatalogueTime($cat_id, $variant);
-
- return $inserted > 0;
- }
-
- /**
- * Delete a particular message from the specified catalogue.
- * @param string the source message to delete.
- * @param string the catalogue to delete from.
- * @return boolean true if deleted, false otherwise.
- */
- function delete($message, $catalogue='messages')
- {
- $details = $this->getCatalogueDetails($catalogue);
- if($details)
- list($cat_id, $variant, $count) = $details;
- else
- return false;
-
- $text = mysql_real_escape_string($message);
-
- $statement = "DELETE FROM trans_unit WHERE
- cat_id = {$cat_id} AND source = '{$message}'";
- $deleted = false;
-
- mysql_query($statement, $this->db);
-
- if(mysql_affected_rows($this->db) == 1)
- $deleted = $this->updateCatalogueTime($cat_id, $variant);
-
- return $deleted;
-
- }
-
- /**
- * Update the translation.
- * @param string the source string.
- * @param string the new translation string.
- * @param string comments
- * @param string the catalogue of the translation.
- * @return boolean true if translation was updated, false otherwise.
- */
- function update($text, $target, $comments, $catalogue='messages')
- {
- $details = $this->getCatalogueDetails($catalogue);
- if($details)
- list($cat_id, $variant, $count) = $details;
- else
- return false;
-
- $comments = mysql_real_escape_string($comments);
- $target = mysql_real_escape_string($target);
- $text = mysql_real_escape_string($text);
-
- $time = time();
-
- $statement = "UPDATE trans_unit SET
- target = '{$target}',
- comments = '{$comments}',
- date_modified = '{$time}'
- WHERE cat_id = {$cat_id}
- AND source = '{$text}'";
-
- $updated = false;
-
- mysql_query($statement, $this->db);
- if(mysql_affected_rows($this->db) == 1)
- $updated = $this->updateCatalogueTime($cat_id, $variant);
-
- return $updated;
- }
-
- /**
- * Returns a list of catalogue as key and all it variants as value.
- * @return array list of catalogues
- */
- function catalogues()
- {
- $statement = 'SELECT name FROM catalogue ORDER BY name';
- $rs = mysql_query($statement, $this->db);
- $result = array();
- while($row = mysql_fetch_array($rs,MYSQL_NUM))
- {
- $details = explode('.',$row[0]);
- if(!isset($details[1])) $details[1] = null;
-
- $result[] = $details;
- }
- return $result;
- }
-
-}
-
-?>
+<?php
+
+/**
+ * MessageSource_MySQL class file.
+ *
+ * This program is free software; you can redistribute it and/or modify
+ * it under the terms of the BSD License.
+ *
+ * Copyright(c) 2004 by Qiang Xue. All rights reserved.
+ *
+ * To contact the author write to {@link mailto:qiang.xue@gmail.com Qiang Xue}
+ * The latest version of PRADO can be obtained from:
+ * {@link http://prado.sourceforge.net/}
+ *
+ * @author Wei Zhuo <weizhuo[at]gmail[dot]com>
+ * @version $Revision: 1.4 $ $Date: 2005/02/25 09:59:40 $
+ * @package System.I18N.core
+ */
+
+/**
+ * Get the MessageSource class file.
+ */
+require_once(dirname(__FILE__).'/MessageSource.php');
+
+/**
+ * Get the I18N utility file, contains the DSN parser.
+ */
+require_once(dirname(__FILE__).'/util.php');
+
+/**
+ * MessageSource_MySQL class.
+ *
+ * Retrive the message translation from a MySQL database.
+ *
+ * See the MessageSource::factory() method to instantiate this class.
+ *
+ * @author Xiang Wei Zhuo <weizhuo[at]gmail[dot]com>
+ * @version v1.0, last update on Fri Dec 24 16:58:58 EST 2004
+ * @package System.I18N.core
+ */
+class MessageSource_MySQL extends MessageSource
+{
+ /**
+ * The datasource string, full DSN to the database.
+ * @var string
+ */
+ protected $source;
+
+ /**
+ * The DSN array property, parsed by PEAR's DB DSN parser.
+ * @var array
+ */
+ protected $dns;
+
+ /**
+ * A resource link to the database
+ * @var db
+ */
+ protected $db;
+ /**
+ * Constructor.
+ * Create a new message source using MySQL.
+ * @param string MySQL datasource, in PEAR's DB DSN format.
+ * @see MessageSource::factory();
+ */
+ function __construct($source)
+ {
+ $this->source = (string)$source;
+ $this->dns = parseDSN($this->source);
+ $this->db = $this->connect();
+ }
+
+ /**
+ * Destructor, close the database connection.
+ */
+ function __destruct()
+ {
+ @mysql_close($this->db);
+ }
+
+ /**
+ * Connect to the MySQL datasource
+ * @return resource MySQL connection.
+ * @throws Exception, connection and database errors.
+ */
+ protected function connect()
+ {
+ /*static $conn;
+
+ if($conn!==null)
+ return $conn;
+ */
+ $dsninfo = $this->dns;
+
+ if (isset($dsninfo['protocol']) && $dsninfo['protocol'] == 'unix')
+ $dbhost = ':' . $dsninfo['socket'];
+ else
+ {
+ $dbhost = $dsninfo['hostspec'] ? $dsninfo['hostspec'] : 'localhost';
+ if (!empty($dsninfo['port']))
+ $dbhost .= ':' . $dsninfo['port'];
+ }
+ $user = $dsninfo['username'];
+ $pw = $dsninfo['password'];
+
+ $connect_function = 'mysql_connect';
+
+ if ($dbhost && $user && $pw)
+ $conn = @$connect_function($dbhost, $user, $pw);
+ elseif ($dbhost && $user)
+ $conn = @$connect_function($dbhost, $user);
+ elseif ($dbhost)
+ $conn = @$connect_function($dbhost);
+ else
+ $conn = false;
+
+ if (empty($conn))
+ {
+ throw new Exception('Error in connecting to '.$dsninfo);
+ }
+
+ if ($dsninfo['database'])
+ {
+ if (!@mysql_select_db($dsninfo['database'], $conn))
+ throw new Exception('Error in connecting database, dns:'.
+ $dsninfo);
+ }
+ else
+ throw new Exception('Please provide a database for message'.
+ ' translation.');
+ return $conn;
+ }
+
+ /**
+ * Get the database connection.
+ * @return db database connection.
+ */
+ public function connection()
+ {
+ return $this->db;
+ }
+
+ /**
+ * Get an array of messages for a particular catalogue and cultural
+ * variant.
+ * @param string the catalogue name + variant
+ * @return array translation messages.
+ */
+ protected function &loadData($variant)
+ {
+ $variant = mysql_real_escape_string($variant);
+
+ $statement =
+ "SELECT t.id, t.source, t.target, t.comments
+ FROM trans_unit t, catalogue c
+ WHERE c.cat_id = t.cat_id
+ AND c.name = '{$variant}'
+ ORDER BY id ASC";
+
+ $rs = mysql_query($statement,$this->db);
+
+ $result = array();
+
+ while($row = mysql_fetch_array($rs,MYSQL_NUM))
+ {
+ $source = $row[1];
+ $result[$source][] = $row[2]; //target
+ $result[$source][] = $row[0]; //id
+ $result[$source][] = $row[3]; //comments
+ }
+
+ return $result;
+ }
+
+ /**
+ * Get the last modified unix-time for this particular catalogue+variant.
+ * We need to query the database to get the date_modified.
+ * @param string catalogue+variant
+ * @return int last modified in unix-time format.
+ */
+ protected function getLastModified($source)
+ {
+ $source = mysql_real_escape_string($source);
+
+ $rs = mysql_query(
+ "SELECT date_modified FROM catalogue WHERE name = '{$source}'",
+ $this->db);
+
+ $result = $rs ? (int)mysql_result($rs,0) : 0;
+
+ return $result;
+ }
+
+ /**
+ * Check if a particular catalogue+variant exists in the database.
+ * @param string catalogue+variant
+ * @return boolean true if the catalogue+variant is in the database,
+ * false otherwise.
+ */
+ protected function isValidSource($variant)
+ {
+ $variant = mysql_real_escape_string ($variant);
+
+ $rs = mysql_query(
+ "SELECT COUNT(*) FROM catalogue WHERE name = '{$variant}'",
+ $this->db);
+
+ $row = mysql_fetch_array($rs,MYSQL_NUM);
+
+ $result = $row && $row[0] == '1';
+
+ return $result;
+ }
+
+ /**
+ * Get all the variants of a particular catalogue.
+ * @param string catalogue name
+ * @return array list of all variants for this catalogue.
+ */
+ protected function getCatalogueList($catalogue)
+ {
+ $variants = explode('_',$this->culture);
+
+ $catalogues = array($catalogue);
+
+ $variant = null;
+
+ for($i = 0, $k = count($variants); $i < $k; ++$i)
+ {
+ if(isset($variants[$i]{0}))
+ {
+ $variant .= ($variant)?'_'.$variants[$i]:$variants[$i];
+ $catalogues[] = $catalogue.'.'.$variant;
+ }
+ }
+ return array_reverse($catalogues);
+ }
+
+ /**
+ * Retrive catalogue details, array($cat_id, $variant, $count).
+ * @param string catalogue
+ * @return array catalogue details, array($cat_id, $variant, $count).
+ */
+ private function getCatalogueDetails($catalogue='messages')
+ {
+ if(empty($catalogue))
+ $catalogue = 'messages';
+
+ $variant = $catalogue.'.'.$this->culture;
+
+ $name = mysql_real_escape_string($this->getSource($variant));
+
+ $rs = mysql_query("SELECT cat_id
+ FROM catalogue WHERE name = '{$name}'", $this->db);
+
+ if(mysql_num_rows($rs) != 1)
+ return false;
+
+ $cat_id = (int)mysql_result($rs,0);
+
+ //first get the catalogue ID
+ $rs = mysql_query(
+ "SELECT count(msg_id)
+ FROM trans_unit
+ WHERE cat_id = {$cat_id}", $this->db);
+
+ $count = (int)mysql_result($rs,0);
+
+ return array($cat_id, $variant, $count);
+ }
+
+ /**
+ * Update the catalogue last modified time.
+ * @return boolean true if updated, false otherwise.
+ */
+ private function updateCatalogueTime($cat_id, $variant)
+ {
+ $time = time();
+
+ $result = mysql_query("UPDATE catalogue
+ SET date_modified = {$time}
+ WHERE cat_id = {$cat_id}", $this->db);
+
+ if(!empty($this->cache))
+ $this->cache->clean($variant, $this->culture);
+
+ return $result;
+ }
+
+ /**
+ * Save the list of untranslated blocks to the translation source.
+ * If the translation was not found, you should add those
+ * strings to the translation source via the <b>append()</b> method.
+ * @param string the catalogue to add to
+ * @return boolean true if saved successfuly, false otherwise.
+ */
+ function save($catalogue='messages')
+ {
+ $messages = $this->untranslated;
+
+ if(count($messages) <= 0) return false;
+
+ $details = $this->getCatalogueDetails($catalogue);
+
+ if($details)
+ list($cat_id, $variant, $count) = $details;
+ else
+ return false;
+
+ if($cat_id <= 0) return false;
+ $inserted = 0;
+
+ $time = time();
+
+ foreach($messages as $message)
+ {
+ $count++; $inserted++;
+ $message = mysql_real_escape_string($message);
+ $statement = "INSERT INTO trans_unit
+ (cat_id,id,source,date_added) VALUES
+ ({$cat_id}, {$count},'{$message}',$time)";
+ mysql_query($statement, $this->db);
+ }
+ if($inserted > 0)
+ $this->updateCatalogueTime($cat_id, $variant);
+
+ return $inserted > 0;
+ }
+
+ /**
+ * Delete a particular message from the specified catalogue.
+ * @param string the source message to delete.
+ * @param string the catalogue to delete from.
+ * @return boolean true if deleted, false otherwise.
+ */
+ function delete($message, $catalogue='messages')
+ {
+ $details = $this->getCatalogueDetails($catalogue);
+ if($details)
+ list($cat_id, $variant, $count) = $details;
+ else
+ return false;
+
+ $text = mysql_real_escape_string($message);
+
+ $statement = "DELETE FROM trans_unit WHERE
+ cat_id = {$cat_id} AND source = '{$message}'";
+ $deleted = false;
+
+ mysql_query($statement, $this->db);
+
+ if(mysql_affected_rows($this->db) == 1)
+ $deleted = $this->updateCatalogueTime($cat_id, $variant);
+
+ return $deleted;
+
+ }
+
+ /**
+ * Update the translation.
+ * @param string the source string.
+ * @param string the new translation string.
+ * @param string comments
+ * @param string the catalogue of the translation.
+ * @return boolean true if translation was updated, false otherwise.
+ */
+ function update($text, $target, $comments, $catalogue='messages')
+ {
+ $details = $this->getCatalogueDetails($catalogue);
+ if($details)
+ list($cat_id, $variant, $count) = $details;
+ else
+ return false;
+
+ $comments = mysql_real_escape_string($comments);
+ $target = mysql_real_escape_string($target);
+ $text = mysql_real_escape_string($text);
+
+ $time = time();
+
+ $statement = "UPDATE trans_unit SET
+ target = '{$target}',
+ comments = '{$comments}',
+ date_modified = '{$time}'
+ WHERE cat_id = {$cat_id}
+ AND source = '{$text}'";
+
+ $updated = false;
+
+ mysql_query($statement, $this->db);
+ if(mysql_affected_rows($this->db) == 1)
+ $updated = $this->updateCatalogueTime($cat_id, $variant);
+
+ return $updated;
+ }
+
+ /**
+ * Returns a list of catalogue as key and all it variants as value.
+ * @return array list of catalogues
+ */
+ function catalogues()
+ {
+ $statement = 'SELECT name FROM catalogue ORDER BY name';
+ $rs = mysql_query($statement, $this->db);
+ $result = array();
+ while($row = mysql_fetch_array($rs,MYSQL_NUM))
+ {
+ $details = explode('.',$row[0]);
+ if(!isset($details[1])) $details[1] = null;
+
+ $result[] = $details;
+ }
+ return $result;
+ }
+
+}
+
+?>
diff --git a/framework/I18N/core/MessageSource_SQLite.php b/framework/I18N/core/MessageSource_SQLite.php
index 22518bba..4694e018 100644
--- a/framework/I18N/core/MessageSource_SQLite.php
+++ b/framework/I18N/core/MessageSource_SQLite.php
@@ -1,354 +1,354 @@
-<?php
-
-/**
- * MessageSource_SQLite class file.
- *
- * This program is free software; you can redistribute it and/or modify
- * it under the terms of the BSD License.
- *
- * Copyright(c) 2004 by Qiang Xue. All rights reserved.
- *
- * To contact the author write to {@link mailto:qiang.xue@gmail.com Qiang Xue}
- * The latest version of PRADO can be obtained from:
- * {@link http://prado.sourceforge.net/}
- *
- * @author Wei Zhuo <weizhuo[at]gmail[dot]com>
- * @version $Revision: 1.4 $ $Date: 2005/02/25 09:59:40 $
- * @package System.I18N.core
- */
-
-/**
- * Get the MessageSource class file.
- */
-require_once(dirname(__FILE__).'/MessageSource.php');
-
-/**
- * Get the I18N utility file, contains the DSN parser.
- */
-require_once(dirname(__FILE__).'/util.php');
-
-/**
- * MessageSource_SQLite class.
- *
- * Retrive the message translation from a SQLite database.
- *
- * See the MessageSource::factory() method to instantiate this class.
- *
- * @author Xiang Wei Zhuo <weizhuo[at]gmail[dot]com>
- * @version v1.0, last update on Fri Dec 24 16:58:58 EST 2004
- * @package System.I18N.core
- */
-class MessageSource_SQLite extends MessageSource
-{
- /**
- * The SQLite datasource, the filename of the database.
- * @var string
- */
- protected $source;
-
- /**
- * Constructor.
- * Create a new message source using SQLite.
- * @see MessageSource::factory();
- * @param string SQLite datasource, in PEAR's DB DSN format.
- */
- function __construct($source)
- {
- $dsn = parseDSN((string)$source);
- $this->source = $dsn['database'];
- }
-
- /**
- * Get an array of messages for a particular catalogue and cultural
- * variant.
- * @param string the catalogue name + variant
- * @return array translation messages.
- */
- protected function &loadData($variant)
- {
- $variant = sqlite_escape_string($variant);
-
- $statement =
- "SELECT t.id, t.source, t.target, t.comments
- FROM trans_unit t, catalogue c
- WHERE c.cat_id = t.cat_id
- AND c.name = '{$variant}'
- ORDER BY id ASC";
-
- $db = sqlite_open($this->source);
- $rs = sqlite_query($statement, $db);
-
- $result = array();
-
- while($row = sqlite_fetch_array($rs,SQLITE_NUM))
- {
- $source = $row[1];
- $result[$source][] = $row[2]; //target
- $result[$source][] = $row[0]; //id
- $result[$source][] = $row[3]; //comments
- }
-
- sqlite_close($db);
-
- return $result;
- }
-
- /**
- * Get the last modified unix-time for this particular catalogue+variant.
- * We need to query the database to get the date_modified.
- * @param string catalogue+variant
- * @return int last modified in unix-time format.
- */
- protected function getLastModified($source)
- {
- $source = sqlite_escape_string($source);
-
- $db = sqlite_open($this->source);
-
- $rs = sqlite_query(
- "SELECT date_modified FROM catalogue WHERE name = '{$source}'",
- $db);
-
- $result = $rs ? (int)sqlite_fetch_single($rs) : 0;
-
- sqlite_close($db);
-
- return $result;
- }
-
- /**
- * Check if a particular catalogue+variant exists in the database.
- * @param string catalogue+variant
- * @return boolean true if the catalogue+variant is in the database,
- * false otherwise.
- */
- protected function isValidSource($variant)
- {
- $variant = sqlite_escape_string($variant);
- $db = sqlite_open($this->source);
- $rs = sqlite_query(
- "SELECT COUNT(*) FROM catalogue WHERE name = '{$variant}'",
- $db);
- $result = $rs && (int)sqlite_fetch_single($rs);
- sqlite_close($db);
-
- return $result;
- }
-
- /**
- * Get all the variants of a particular catalogue.
- * @param string catalogue name
- * @return array list of all variants for this catalogue.
- */
- protected function getCatalogueList($catalogue)
- {
- $variants = explode('_',$this->culture);
-
- $catalogues = array($catalogue);
-
- $variant = null;
-
- for($i = 0, $k = count($variants); $i < $k; ++$i)
- {
- if(isset($variants[$i]{0}))
- {
- $variant .= ($variant)?'_'.$variants[$i]:$variants[$i];
- $catalogues[] = $catalogue.'.'.$variant;
- }
- }
- return array_reverse($catalogues);
- }
-
- /**
- * Retrive catalogue details, array($cat_id, $variant, $count).
- * @param string catalogue
- * @return array catalogue details, array($cat_id, $variant, $count).
- */
- private function getCatalogueDetails($catalogue='messages')
- {
- if(empty($catalogue))
- $catalogue = 'messages';
-
- $variant = $catalogue.'.'.$this->culture;
-
- $name = sqlite_escape_string($this->getSource($variant));
-
- $db = sqlite_open($this->source);
-
- $rs = sqlite_query("SELECT cat_id
- FROM catalogue WHERE name = '{$name}'", $db);
-
- if(sqlite_num_rows($rs) != 1)
- return false;
-
- $cat_id = (int)sqlite_fetch_single($rs);
-
- //first get the catalogue ID
- $rs = sqlite_query(
- "SELECT count(msg_id)
- FROM trans_unit
- WHERE cat_id = {$cat_id}", $db);
-
- $count = (int)sqlite_fetch_single($rs);
-
- sqlite_close($db);
-
- return array($cat_id, $variant, $count);
- }
-
- /**
- * Update the catalogue last modified time.
- * @return boolean true if updated, false otherwise.
- */
- private function updateCatalogueTime($cat_id, $variant, $db)
- {
- $time = time();
-
- $result = sqlite_query("UPDATE catalogue
- SET date_modified = {$time}
- WHERE cat_id = {$cat_id}", $db);
-
- if(!empty($this->cache))
- $this->cache->clean($variant, $this->culture);
-
- return $result;
- }
-
- /**
- * Save the list of untranslated blocks to the translation source.
- * If the translation was not found, you should add those
- * strings to the translation source via the <b>append()</b> method.
- * @param string the catalogue to add to
- * @return boolean true if saved successfuly, false otherwise.
- */
- function save($catalogue='messages')
- {
- $messages = $this->untranslated;
-
- if(count($messages) <= 0) return false;
-
- $details = $this->getCatalogueDetails($catalogue);
-
- if($details)
- list($cat_id, $variant, $count) = $details;
- else
- return false;
-
- if($cat_id <= 0) return false;
- $inserted = 0;
-
- $db = sqlite_open($this->source);
- $time = time();
-
- foreach($messages as $message)
- {
- $message = sqlite_escape_string($message);
- $statement = "INSERT INTO trans_unit
- (cat_id,id,source,date_added) VALUES
- ({$cat_id}, {$count},'{$message}',$time)";
- if(sqlite_query($statement, $db))
- {
- $count++; $inserted++;
- }
- }
- if($inserted > 0)
- $this->updateCatalogueTime($cat_id, $variant, $db);
-
- sqlite_close($db);
-
- return $inserted > 0;
- }
-
- /**
- * Update the translation.
- * @param string the source string.
- * @param string the new translation string.
- * @param string comments
- * @param string the catalogue of the translation.
- * @return boolean true if translation was updated, false otherwise.
- */
- function update($text, $target, $comments, $catalogue='messages')
- {
- $details = $this->getCatalogueDetails($catalogue);
- if($details)
- list($cat_id, $variant, $count) = $details;
- else
- return false;
-
- $comments = sqlite_escape_string($comments);
- $target = sqlite_escape_string($target);
- $text = sqlite_escape_string($text);
-
- $time = time();
-
- $db = sqlite_open($this->source);
-
- $statement = "UPDATE trans_unit SET
- target = '{$target}',
- comments = '{$comments}',
- date_modified = '{$time}'
- WHERE cat_id = {$cat_id}
- AND source = '{$text}'";
-
- $updated = false;
-
- if(sqlite_query($statement, $db))
- $updated = $this->updateCatalogueTime($cat_id, $variant, $db);
-
- sqlite_close($db);
-
- return $updated;
- }
-
- /**
- * Delete a particular message from the specified catalogue.
- * @param string the source message to delete.
- * @param string the catalogue to delete from.
- * @return boolean true if deleted, false otherwise.
- */
- function delete($message, $catalogue='messages')
- {
- $details = $this->getCatalogueDetails($catalogue);
- if($details)
- list($cat_id, $variant, $count) = $details;
- else
- return false;
-
- $db = sqlite_open($this->source);
- $text = sqlite_escape_string($message);
-
- $statement = "DELETE FROM trans_unit WHERE
- cat_id = {$cat_id} AND source = '{$message}'";
- $deleted = false;
-
- if(sqlite_query($statement, $db))
- $deleted = $this->updateCatalogueTime($cat_id, $variant, $db);
-
- sqlite_close($db);
-
- return $deleted;
- }
-
- /**
- * Returns a list of catalogue as key and all it variants as value.
- * @return array list of catalogues
- */
- function catalogues()
- {
- $db = sqlite_open($this->source);
- $statement = 'SELECT name FROM catalogue ORDER BY name';
- $rs = sqlite_query($statement, $db);
- $result = array();
- while($row = sqlite_fetch_array($rs,SQLITE_NUM))
- {
- $details = explode('.',$row[0]);
- if(!isset($details[1])) $details[1] = null;
-
- $result[] = $details;
- }
- sqlite_close($db);
- return $result;
- }
-}
-
-?>
+<?php
+
+/**
+ * MessageSource_SQLite class file.
+ *
+ * This program is free software; you can redistribute it and/or modify
+ * it under the terms of the BSD License.
+ *
+ * Copyright(c) 2004 by Qiang Xue. All rights reserved.
+ *
+ * To contact the author write to {@link mailto:qiang.xue@gmail.com Qiang Xue}
+ * The latest version of PRADO can be obtained from:
+ * {@link http://prado.sourceforge.net/}
+ *
+ * @author Wei Zhuo <weizhuo[at]gmail[dot]com>
+ * @version $Revision: 1.4 $ $Date: 2005/02/25 09:59:40 $
+ * @package System.I18N.core
+ */
+
+/**
+ * Get the MessageSource class file.
+ */
+require_once(dirname(__FILE__).'/MessageSource.php');
+
+/**
+ * Get the I18N utility file, contains the DSN parser.
+ */
+require_once(dirname(__FILE__).'/util.php');
+
+/**
+ * MessageSource_SQLite class.
+ *
+ * Retrive the message translation from a SQLite database.
+ *
+ * See the MessageSource::factory() method to instantiate this class.
+ *
+ * @author Xiang Wei Zhuo <weizhuo[at]gmail[dot]com>
+ * @version v1.0, last update on Fri Dec 24 16:58:58 EST 2004
+ * @package System.I18N.core
+ */
+class MessageSource_SQLite extends MessageSource
+{
+ /**
+ * The SQLite datasource, the filename of the database.
+ * @var string
+ */
+ protected $source;
+
+ /**
+ * Constructor.
+ * Create a new message source using SQLite.
+ * @see MessageSource::factory();
+ * @param string SQLite datasource, in PEAR's DB DSN format.
+ */
+ function __construct($source)
+ {
+ $dsn = parseDSN((string)$source);
+ $this->source = $dsn['database'];
+ }
+
+ /**
+ * Get an array of messages for a particular catalogue and cultural
+ * variant.
+ * @param string the catalogue name + variant
+ * @return array translation messages.
+ */
+ protected function &loadData($variant)
+ {
+ $variant = sqlite_escape_string($variant);
+
+ $statement =
+ "SELECT t.id, t.source, t.target, t.comments
+ FROM trans_unit t, catalogue c
+ WHERE c.cat_id = t.cat_id
+ AND c.name = '{$variant}'
+ ORDER BY id ASC";
+
+ $db = sqlite_open($this->source);
+ $rs = sqlite_query($statement, $db);
+
+ $result = array();
+
+ while($row = sqlite_fetch_array($rs,SQLITE_NUM))
+ {
+ $source = $row[1];
+ $result[$source][] = $row[2]; //target
+ $result[$source][] = $row[0]; //id
+ $result[$source][] = $row[3]; //comments
+ }
+
+ sqlite_close($db);
+
+ return $result;
+ }
+
+ /**
+ * Get the last modified unix-time for this particular catalogue+variant.
+ * We need to query the database to get the date_modified.
+ * @param string catalogue+variant
+ * @return int last modified in unix-time format.
+ */
+ protected function getLastModified($source)
+ {
+ $source = sqlite_escape_string($source);
+
+ $db = sqlite_open($this->source);
+
+ $rs = sqlite_query(
+ "SELECT date_modified FROM catalogue WHERE name = '{$source}'",
+ $db);
+
+ $result = $rs ? (int)sqlite_fetch_single($rs) : 0;
+
+ sqlite_close($db);
+
+ return $result;
+ }
+
+ /**
+ * Check if a particular catalogue+variant exists in the database.
+ * @param string catalogue+variant
+ * @return boolean true if the catalogue+variant is in the database,
+ * false otherwise.
+ */
+ protected function isValidSource($variant)
+ {
+ $variant = sqlite_escape_string($variant);
+ $db = sqlite_open($this->source);
+ $rs = sqlite_query(
+ "SELECT COUNT(*) FROM catalogue WHERE name = '{$variant}'",
+ $db);
+ $result = $rs && (int)sqlite_fetch_single($rs);
+ sqlite_close($db);
+
+ return $result;
+ }
+
+ /**
+ * Get all the variants of a particular catalogue.
+ * @param string catalogue name
+ * @return array list of all variants for this catalogue.
+ */
+ protected function getCatalogueList($catalogue)
+ {
+ $variants = explode('_',$this->culture);
+
+ $catalogues = array($catalogue);
+
+ $variant = null;
+
+ for($i = 0, $k = count($variants); $i < $k; ++$i)
+ {
+ if(isset($variants[$i]{0}))
+ {
+ $variant .= ($variant)?'_'.$variants[$i]:$variants[$i];
+ $catalogues[] = $catalogue.'.'.$variant;
+ }
+ }
+ return array_reverse($catalogues);
+ }
+
+ /**
+ * Retrive catalogue details, array($cat_id, $variant, $count).
+ * @param string catalogue
+ * @return array catalogue details, array($cat_id, $variant, $count).
+ */
+ private function getCatalogueDetails($catalogue='messages')
+ {
+ if(empty($catalogue))
+ $catalogue = 'messages';
+
+ $variant = $catalogue.'.'.$this->culture;
+
+ $name = sqlite_escape_string($this->getSource($variant));
+
+ $db = sqlite_open($this->source);
+
+ $rs = sqlite_query("SELECT cat_id
+ FROM catalogue WHERE name = '{$name}'", $db);
+
+ if(sqlite_num_rows($rs) != 1)
+ return false;
+
+ $cat_id = (int)sqlite_fetch_single($rs);
+
+ //first get the catalogue ID
+ $rs = sqlite_query(
+ "SELECT count(msg_id)
+ FROM trans_unit
+ WHERE cat_id = {$cat_id}", $db);
+
+ $count = (int)sqlite_fetch_single($rs);
+
+ sqlite_close($db);
+
+ return array($cat_id, $variant, $count);
+ }
+
+ /**
+ * Update the catalogue last modified time.
+ * @return boolean true if updated, false otherwise.
+ */
+ private function updateCatalogueTime($cat_id, $variant, $db)
+ {
+ $time = time();
+
+ $result = sqlite_query("UPDATE catalogue
+ SET date_modified = {$time}
+ WHERE cat_id = {$cat_id}", $db);
+
+ if(!empty($this->cache))
+ $this->cache->clean($variant, $this->culture);
+
+ return $result;
+ }
+
+ /**
+ * Save the list of untranslated blocks to the translation source.
+ * If the translation was not found, you should add those
+ * strings to the translation source via the <b>append()</b> method.
+ * @param string the catalogue to add to
+ * @return boolean true if saved successfuly, false otherwise.
+ */
+ function save($catalogue='messages')
+ {
+ $messages = $this->untranslated;
+
+ if(count($messages) <= 0) return false;
+
+ $details = $this->getCatalogueDetails($catalogue);
+
+ if($details)
+ list($cat_id, $variant, $count) = $details;
+ else
+ return false;
+
+ if($cat_id <= 0) return false;
+ $inserted = 0;
+
+ $db = sqlite_open($this->source);
+ $time = time();
+
+ foreach($messages as $message)
+ {
+ $message = sqlite_escape_string($message);
+ $statement = "INSERT INTO trans_unit
+ (cat_id,id,source,date_added) VALUES
+ ({$cat_id}, {$count},'{$message}',$time)";
+ if(sqlite_query($statement, $db))
+ {
+ $count++; $inserted++;
+ }
+ }
+ if($inserted > 0)
+ $this->updateCatalogueTime($cat_id, $variant, $db);
+
+ sqlite_close($db);
+
+ return $inserted > 0;
+ }
+
+ /**
+ * Update the translation.
+ * @param string the source string.
+ * @param string the new translation string.
+ * @param string comments
+ * @param string the catalogue of the translation.
+ * @return boolean true if translation was updated, false otherwise.
+ */
+ function update($text, $target, $comments, $catalogue='messages')
+ {
+ $details = $this->getCatalogueDetails($catalogue);
+ if($details)
+ list($cat_id, $variant, $count) = $details;
+ else
+ return false;
+
+ $comments = sqlite_escape_string($comments);
+ $target = sqlite_escape_string($target);
+ $text = sqlite_escape_string($text);
+
+ $time = time();
+
+ $db = sqlite_open($this->source);
+
+ $statement = "UPDATE trans_unit SET
+ target = '{$target}',
+ comments = '{$comments}',
+ date_modified = '{$time}'
+ WHERE cat_id = {$cat_id}
+ AND source = '{$text}'";
+
+ $updated = false;
+
+ if(sqlite_query($statement, $db))
+ $updated = $this->updateCatalogueTime($cat_id, $variant, $db);
+
+ sqlite_close($db);
+
+ return $updated;
+ }
+
+ /**
+ * Delete a particular message from the specified catalogue.
+ * @param string the source message to delete.
+ * @param string the catalogue to delete from.
+ * @return boolean true if deleted, false otherwise.
+ */
+ function delete($message, $catalogue='messages')
+ {
+ $details = $this->getCatalogueDetails($catalogue);
+ if($details)
+ list($cat_id, $variant, $count) = $details;
+ else
+ return false;
+
+ $db = sqlite_open($this->source);
+ $text = sqlite_escape_string($message);
+
+ $statement = "DELETE FROM trans_unit WHERE
+ cat_id = {$cat_id} AND source = '{$message}'";
+ $deleted = false;
+
+ if(sqlite_query($statement, $db))
+ $deleted = $this->updateCatalogueTime($cat_id, $variant, $db);
+
+ sqlite_close($db);
+
+ return $deleted;
+ }
+
+ /**
+ * Returns a list of catalogue as key and all it variants as value.
+ * @return array list of catalogues
+ */
+ function catalogues()
+ {
+ $db = sqlite_open($this->source);
+ $statement = 'SELECT name FROM catalogue ORDER BY name';
+ $rs = sqlite_query($statement, $db);
+ $result = array();
+ while($row = sqlite_fetch_array($rs,SQLITE_NUM))
+ {
+ $details = explode('.',$row[0]);
+ if(!isset($details[1])) $details[1] = null;
+
+ $result[] = $details;
+ }
+ sqlite_close($db);
+ return $result;
+ }
+}
+
+?>
diff --git a/framework/I18N/core/MessageSource_XLIFF.php b/framework/I18N/core/MessageSource_XLIFF.php
index 207fc920..198a1290 100644
--- a/framework/I18N/core/MessageSource_XLIFF.php
+++ b/framework/I18N/core/MessageSource_XLIFF.php
@@ -1,529 +1,529 @@
-<?php
-
-/**
- * MessageSource_XLIFF class file.
- *
- * This program is free software; you can redistribute it and/or modify
- * it under the terms of the BSD License.
- *
- * Copyright(c) 2004 by Qiang Xue. All rights reserved.
- *
- * To contact the author write to {@link mailto:qiang.xue@gmail.com Qiang Xue}
- * The latest version of PRADO can be obtained from:
- * {@link http://prado.sourceforge.net/}
- *
- * @author Wei Zhuo <weizhuo[at]gmail[dot]com>
- * @version $Revision: 1.8 $ $Date: 2005/12/17 06:11:28 $
- * @package System.I18N.core
- */
-
-/**
- * Get the MessageSource class file.
- */
-require_once(dirname(__FILE__).'/MessageSource.php');
-
-/**
- * MessageSource_XLIFF class.
- *
- * Using XML XLIFF format as the message source for translation.
- * Details and example of XLIFF can be found in the following URLs.
- *
- * # http://www.opentag.com/xliff.htm
- * # http://www-106.ibm.com/developerworks/xml/library/x-localis2/
- *
- * See the MessageSource::factory() method to instantiate this class.
- *
- * @author Xiang Wei Zhuo <weizhuo[at]gmail[dot]com>
- * @version v1.0, last update on Fri Dec 24 16:18:44 EST 2004
- * @package System.I18N.core
- */
-class MessageSource_XLIFF extends MessageSource
-{
- /**
- * Message data filename extension.
- * @var string
- */
- protected $dataExt = '.xml';
-
- /**
- * Separator between culture name and source.
- * @var string
- */
- protected $dataSeparator = '.';
-
- /**
- * Constructor.
- * @param string the directory where the messages are stored.
- * @see MessageSource::factory();
- */
- function __construct($source)
- {
- $this->source = (string)$source;
- }
-
- /**
- * Load the messages from a XLIFF file.
- * @param string XLIFF file.
- * @return array of messages.
- */
- protected function &loadData($filename)
- {
- //load it.
- if(false === ($XML = simplexml_load_file($filename))) {
- return false;
- }
-
- $translationUnit = $XML->xpath('//trans-unit');
-
- $translations = array();
-
- foreach($translationUnit as $unit)
- {
- $source = (string)$unit->source;
- $translations[$source][] = (string)$unit->target;
- $translations[$source][] = (string)$unit['id'];
- $translations[$source][] = (string)$unit->note;
- }
-
- return $translations;
- }
-
- /**
- * Get the last modified unix-time for this particular catalogue+variant.
- * Just use the file modified time.
- * @param string catalogue+variant
- * @return int last modified in unix-time format.
- */
- protected function getLastModified($source)
- {
- return is_file($source) ? filemtime($source) : 0;
- }
-
- /**
- * Get the XLIFF file for a specific message catalogue and cultural
- * vairant.
- * @param string message catalogue
- * @return string full path to the XLIFF file.
- */
- protected function getSource($variant)
- {
- return $this->source.'/'.$variant;
- }
-
- /**
- * Determin if the XLIFF file source is valid.
- * @param string XLIFF file
- * @return boolean true if valid, false otherwise.
- */
- protected function isValidSource($source)
- {
- return is_file($source);
- }
-
- /**
- * Get all the variants of a particular catalogue.
- * @param string catalogue name
- * @return array list of all variants for this catalogue.
- */
- protected function getCatalogueList($catalogue)
- {
- $variants = explode('_',$this->culture);
- $source = $catalogue.$this->dataExt;
- $catalogues = array($source);
- $variant = null;
-
- for($i = 0, $k = count($variants); $i < $k; ++$i)
- {
- if(isset($variants[$i]{0}))
- {
- $variant .= ($variant)?'_'.$variants[$i]:$variants[$i];
- $catalogues[] = $catalogue.$this->dataSeparator.$variant.$this->dataExt;
- }
- }
-
- $byDir = $this->getCatalogueByDir($catalogue);
- $catalogues = array_merge($byDir,array_reverse($catalogues));
- $files = array();
-
- foreach($catalogues as $file)
- {
- $files[] = $file;
- $files[] = preg_replace('/\.xml$/', '.xlf', $file);
- }
-
- return $files;
- }
-
- /**
- * Traverse through the directory structure to find the catalogues.
- * This should only be called by getCatalogueList()
- * @param string a particular catalogue.
- * @return array a list of catalogues.
- * @see getCatalogueList()
- */
- private function getCatalogueByDir($catalogue)
- {
- $variants = explode('_',$this->culture);
- $catalogues = array();
- $variant = null;
-
- for($i = 0, $k = count($variants); $i < $k; ++$i)
- {
- if(isset($variants[$i]{0}))
- {
- $variant .= ($variant)?'_'.$variants[$i]:$variants[$i];
- $catalogues[] = $variant.'/'.$catalogue.$this->dataExt;
- }
- }
-
- return array_reverse($catalogues);
- }
-
- /**
- * Returns a list of catalogue and its culture ID.
- * E.g. array('messages','en_AU')
- * @return array list of catalogues
- * @see getCatalogues()
- */
- public function catalogues()
- {
- return $this->getCatalogues();
- }
-
- /**
- * Returns a list of catalogue and its culture ID. This takes care
- * of directory structures.
- * E.g. array('messages','en_AU')
- * @return array list of catalogues
- */
- protected function getCatalogues($dir=null,$variant=null)
- {
- $dir = $dir?$dir:$this->source;
- $files = scandir($dir);
- $catalogue = array();
-
- foreach($files as $file)
- {
- if(is_dir($dir.'/'.$file) && preg_match('/^[a-z]{2}(_[A-Z]{2,3})?$/',$file)) {
- $catalogue = array_merge(
- $catalogue,
- $this->getCatalogues($dir.'/'.$file, $file)
- );
- }
-
- $pos = strpos($file,$this->dataExt);
- if($pos >0 && substr($file, -1*strlen($this->dataExt)) == $this->dataExt)
- {
- $name = substr($file,0,$pos);
- $dot = strrpos($name,$this->dataSeparator);
- $culture = $variant;
- $cat = $name;
-
- if(is_int($dot))
- {
- $culture = substr($name, $dot+1, strlen($name));
- $cat = substr($name, 0, $dot);
- }
-
- $details[0] = $cat;
- $details[1] = $culture;
- $catalogue[] = $details;
- }
- }
- sort($catalogue);
- return $catalogue;
- }
-
- /**
- * Get the variant for a catalogue depending on the current culture.
- * @param string catalogue
- * @return string the variant.
- * @see save()
- * @see update()
- * @see delete()
- */
- private function getVariants($catalogue='messages')
- {
- if($catalogue === null) {
- $catalogue = 'messages';
- }
-
- foreach($this->getCatalogueList($catalogue) as $variant)
- {
- $file = $this->getSource($variant);
- if(is_file($file)) {
- return array($variant, $file);
- }
- }
- return false;
- }
-
- /**
- * Save the list of untranslated blocks to the translation source.
- * If the translation was not found, you should add those
- * strings to the translation source via the <b>append()</b> method.
- * @param string the catalogue to add to
- * @return boolean true if saved successfuly, false otherwise.
- */
- public function save($catalogue='messages')
- {
- $messages = $this->untranslated;
- if(count($messages) <= 0) {
- return false;
- }
-
- $variants = $this->getVariants($catalogue);
-
- if($variants) {
- list($variant, $filename) = $variants;
- } else {
- list($variant, $filename) = $this->createMessageTemplate($catalogue);
- }
-
- if(is_writable($filename) == false) {
- throw new TIOException("Unable to save to file {$filename}, file must be writable.");
- }
-
- //create a new dom, import the existing xml
- $dom = new DOMDocument();
- $dom->load($filename);
-
- //find the body element
- $xpath = new DomXPath($dom);
- $body = $xpath->query('//body')->item(0);
-
- $lastNodes = $xpath->query('//trans-unit[last()]');
- if(($last=$lastNodes->item(0))!==null) {
- $count = (int)$last->getAttribute('id');
- } else {
- $count = 0;
- }
-
- //for each message add it to the XML file using DOM
- foreach($messages as $message)
- {
- $unit = $dom->createElement('trans-unit');
- $unit->setAttribute('id',++$count);
-
- $source = $dom->createElement('source');
- $source->appendChild($dom->createCDATASection($message));
-
- $target = $dom->createElement('target');
- $target->appendChild($dom->createCDATASection(''));
-
- $unit->appendChild($dom->createTextNode("\n"));
- $unit->appendChild($source);
- $unit->appendChild($dom->createTextNode("\n"));
- $unit->appendChild($target);
- $unit->appendChild($dom->createTextNode("\n"));
-
- $body->appendChild($dom->createTextNode("\n"));
- $body->appendChild($unit);
- $body->appendChild($dom->createTextNode("\n"));
- }
-
-
- $fileNode = $xpath->query('//file')->item(0);
- $fileNode->setAttribute('date', @date('Y-m-d\TH:i:s\Z'));
-
- //save it and clear the cache for this variant
- $dom->save($filename);
- if(!empty($this->cache)) {
- $this->cache->clean($variant, $this->culture);
- }
-
- return true;
- }
-
- /**
- * Update the translation.
- * @param string the source string.
- * @param string the new translation string.
- * @param string comments
- * @param string the catalogue to save to.
- * @return boolean true if translation was updated, false otherwise.
- */
- public function update($text, $target, $comments, $catalogue='messages')
- {
- $variants = $this->getVariants($catalogue);
-
- if($variants) {
- list($variant, $filename) = $variants;
- } else {
- return false;
- }
-
- if(is_writable($filename) == false) {
- throw new TIOException("Unable to update file {$filename}, file must be writable.");
- }
-
- //create a new dom, import the existing xml
- $dom = DOMDocument::load($filename);
-
- //find the body element
- $xpath = new DomXPath($dom);
- $units = $xpath->query('//trans-unit');
-
- //for each of the existin units
- foreach($units as $unit)
- {
- $found = false;
- $targetted = false;
- $commented = false;
-
- //in each unit, need to find the source, target and comment nodes
- //it will assume that the source is before the target.
- foreach($unit->childNodes as $node)
- {
- //source node
- if($node->nodeName == 'source' && $node->firstChild->wholeText == $text) {
- $found = true;
- }
-
- //found source, get the target and notes
- if($found)
- {
- //set the new translated string
- if($node->nodeName == 'target')
- {
- $node->nodeValue = $target;
- $targetted = true;
- }
-
- //set the notes
- if(!empty($comments) && $node->nodeName == 'note')
- {
- $node->nodeValue = $comments;
- $commented = true;
- }
- }
- }
-
- //append a target
- if($found && !$targetted) {
- $unit->appendChild($dom->createElement('target',$target));
- }
-
- //append a note
- if($found && !$commented && !empty($comments)) {
- $unit->appendChild($dom->createElement('note',$comments));
- }
-
- //finished searching
- if($found) {
- break;
- }
- }
-
- $fileNode = $xpath->query('//file')->item(0);
- $fileNode->setAttribute('date', @date('Y-m-d\TH:i:s\Z'));
-
- if($dom->save($filename) >0)
- {
- if(!empty($this->cache)) {
- $this->cache->clean($variant, $this->culture);
- }
-
- return true;
- }
-
- return false;
- }
-
- /**
- * Delete a particular message from the specified catalogue.
- * @param string the source message to delete.
- * @param string the catalogue to delete from.
- * @return boolean true if deleted, false otherwise.
- */
- public function delete($message, $catalogue='messages')
- {
- $variants = $this->getVariants($catalogue);
- if($variants) {
- list($variant, $filename) = $variants;
- } else {
- return false;
- }
-
- if(is_writable($filename) == false) {
- throw new TIOException("Unable to modify file {$filename}, file must be writable.");
- }
-
- //create a new dom, import the existing xml
- $dom = DOMDocument::load($filename);
-
- //find the body element
- $xpath = new DomXPath($dom);
- $units = $xpath->query('//trans-unit');
-
- //for each of the existin units
- foreach($units as $unit)
- {
- //in each unit, need to find the source, target and comment nodes
- //it will assume that the source is before the target.
- foreach($unit->childNodes as $node)
- {
- //source node
- if($node->nodeName == 'source' && $node->firstChild->wholeText == $message)
- {
- //we found it, remove and save the xml file.
- $unit->parentNode->removeChild($unit);
- $fileNode = $xpath->query('//file')->item(0);
- $fileNode->setAttribute('date', @date('Y-m-d\TH:i:s\Z'));
-
- if(false !== $dom->save($filename)) {
- if(!empty($this->cache)) {
- $this->cache->clean($variant, $this->culture);
- }
- return true;
- }
-
- return false;
- }
- }
- }
-
- return false;
- }
-
- protected function createMessageTemplate($catalogue)
- {
- if($catalogue === null) {
- $catalogue = 'messages';
- }
-
- $variants = $this->getCatalogueList($catalogue);
- $variant = array_shift($variants);
- $file = $this->getSource($variant);
- $dir = dirname($file);
-
- if(!is_dir($dir)) {
- @mkdir($dir);
- @chmod($dir,PRADO_CHMOD);
- }
-
- if(!is_dir($dir)) {
- throw new TException("Unable to create directory $dir");
- }
-
- file_put_contents($file, $this->getTemplate($catalogue));
- chmod($file, PRADO_CHMOD);
-
- return array($variant, $file);
- }
-
- protected function getTemplate($catalogue)
- {
- $date = @date('c');
- $xml = <<<EOD
-<?xml version="1.0" encoding="UTF-8"?>
-<xliff version="1.0">
- <file source-language="EN" target-language="{$this->culture}" datatype="plaintext" original="$catalogue" date="$date" product-name="$catalogue">
- <body>
- </body>
- </file>
-</xliff>
-EOD;
- return $xml;
- }
-}
+<?php
+
+/**
+ * MessageSource_XLIFF class file.
+ *
+ * This program is free software; you can redistribute it and/or modify
+ * it under the terms of the BSD License.
+ *
+ * Copyright(c) 2004 by Qiang Xue. All rights reserved.
+ *
+ * To contact the author write to {@link mailto:qiang.xue@gmail.com Qiang Xue}
+ * The latest version of PRADO can be obtained from:
+ * {@link http://prado.sourceforge.net/}
+ *
+ * @author Wei Zhuo <weizhuo[at]gmail[dot]com>
+ * @version $Revision: 1.8 $ $Date: 2005/12/17 06:11:28 $
+ * @package System.I18N.core
+ */
+
+/**
+ * Get the MessageSource class file.
+ */
+require_once(dirname(__FILE__).'/MessageSource.php');
+
+/**
+ * MessageSource_XLIFF class.
+ *
+ * Using XML XLIFF format as the message source for translation.
+ * Details and example of XLIFF can be found in the following URLs.
+ *
+ * # http://www.opentag.com/xliff.htm
+ * # http://www-106.ibm.com/developerworks/xml/library/x-localis2/
+ *
+ * See the MessageSource::factory() method to instantiate this class.
+ *
+ * @author Xiang Wei Zhuo <weizhuo[at]gmail[dot]com>
+ * @version v1.0, last update on Fri Dec 24 16:18:44 EST 2004
+ * @package System.I18N.core
+ */
+class MessageSource_XLIFF extends MessageSource
+{
+ /**
+ * Message data filename extension.
+ * @var string
+ */
+ protected $dataExt = '.xml';
+
+ /**
+ * Separator between culture name and source.
+ * @var string
+ */
+ protected $dataSeparator = '.';
+
+ /**
+ * Constructor.
+ * @param string the directory where the messages are stored.
+ * @see MessageSource::factory();
+ */
+ function __construct($source)
+ {
+ $this->source = (string)$source;
+ }
+
+ /**
+ * Load the messages from a XLIFF file.
+ * @param string XLIFF file.
+ * @return array of messages.
+ */
+ protected function &loadData($filename)
+ {
+ //load it.
+ if(false === ($XML = simplexml_load_file($filename))) {
+ return false;
+ }
+
+ $translationUnit = $XML->xpath('//trans-unit');
+
+ $translations = array();
+
+ foreach($translationUnit as $unit)
+ {
+ $source = (string)$unit->source;
+ $translations[$source][] = (string)$unit->target;
+ $translations[$source][] = (string)$unit['id'];
+ $translations[$source][] = (string)$unit->note;
+ }
+
+ return $translations;
+ }
+
+ /**
+ * Get the last modified unix-time for this particular catalogue+variant.
+ * Just use the file modified time.
+ * @param string catalogue+variant
+ * @return int last modified in unix-time format.
+ */
+ protected function getLastModified($source)
+ {
+ return is_file($source) ? filemtime($source) : 0;
+ }
+
+ /**
+ * Get the XLIFF file for a specific message catalogue and cultural
+ * vairant.
+ * @param string message catalogue
+ * @return string full path to the XLIFF file.
+ */
+ protected function getSource($variant)
+ {
+ return $this->source.'/'.$variant;
+ }
+
+ /**
+ * Determin if the XLIFF file source is valid.
+ * @param string XLIFF file
+ * @return boolean true if valid, false otherwise.
+ */
+ protected function isValidSource($source)
+ {
+ return is_file($source);
+ }
+
+ /**
+ * Get all the variants of a particular catalogue.
+ * @param string catalogue name
+ * @return array list of all variants for this catalogue.
+ */
+ protected function getCatalogueList($catalogue)
+ {
+ $variants = explode('_',$this->culture);
+ $source = $catalogue.$this->dataExt;
+ $catalogues = array($source);
+ $variant = null;
+
+ for($i = 0, $k = count($variants); $i < $k; ++$i)
+ {
+ if(isset($variants[$i]{0}))
+ {
+ $variant .= ($variant)?'_'.$variants[$i]:$variants[$i];
+ $catalogues[] = $catalogue.$this->dataSeparator.$variant.$this->dataExt;
+ }
+ }
+
+ $byDir = $this->getCatalogueByDir($catalogue);
+ $catalogues = array_merge($byDir,array_reverse($catalogues));
+ $files = array();
+
+ foreach($catalogues as $file)
+ {
+ $files[] = $file;
+ $files[] = preg_replace('/\.xml$/', '.xlf', $file);
+ }
+
+ return $files;
+ }
+
+ /**
+ * Traverse through the directory structure to find the catalogues.
+ * This should only be called by getCatalogueList()
+ * @param string a particular catalogue.
+ * @return array a list of catalogues.
+ * @see getCatalogueList()
+ */
+ private function getCatalogueByDir($catalogue)
+ {
+ $variants = explode('_',$this->culture);
+ $catalogues = array();
+ $variant = null;
+
+ for($i = 0, $k = count($variants); $i < $k; ++$i)
+ {
+ if(isset($variants[$i]{0}))
+ {
+ $variant .= ($variant)?'_'.$variants[$i]:$variants[$i];
+ $catalogues[] = $variant.'/'.$catalogue.$this->dataExt;
+ }
+ }
+
+ return array_reverse($catalogues);
+ }
+
+ /**
+ * Returns a list of catalogue and its culture ID.
+ * E.g. array('messages','en_AU')
+ * @return array list of catalogues
+ * @see getCatalogues()
+ */
+ public function catalogues()
+ {
+ return $this->getCatalogues();
+ }
+
+ /**
+ * Returns a list of catalogue and its culture ID. This takes care
+ * of directory structures.
+ * E.g. array('messages','en_AU')
+ * @return array list of catalogues
+ */
+ protected function getCatalogues($dir=null,$variant=null)
+ {
+ $dir = $dir?$dir:$this->source;
+ $files = scandir($dir);
+ $catalogue = array();
+
+ foreach($files as $file)
+ {
+ if(is_dir($dir.'/'.$file) && preg_match('/^[a-z]{2}(_[A-Z]{2,3})?$/',$file)) {
+ $catalogue = array_merge(
+ $catalogue,
+ $this->getCatalogues($dir.'/'.$file, $file)
+ );
+ }
+
+ $pos = strpos($file,$this->dataExt);
+ if($pos >0 && substr($file, -1*strlen($this->dataExt)) == $this->dataExt)
+ {
+ $name = substr($file,0,$pos);
+ $dot = strrpos($name,$this->dataSeparator);
+ $culture = $variant;
+ $cat = $name;
+
+ if(is_int($dot))
+ {
+ $culture = substr($name, $dot+1, strlen($name));
+ $cat = substr($name, 0, $dot);
+ }
+
+ $details[0] = $cat;
+ $details[1] = $culture;
+ $catalogue[] = $details;
+ }
+ }
+ sort($catalogue);
+ return $catalogue;
+ }
+
+ /**
+ * Get the variant for a catalogue depending on the current culture.
+ * @param string catalogue
+ * @return string the variant.
+ * @see save()
+ * @see update()
+ * @see delete()
+ */
+ private function getVariants($catalogue='messages')
+ {
+ if($catalogue === null) {
+ $catalogue = 'messages';
+ }
+
+ foreach($this->getCatalogueList($catalogue) as $variant)
+ {
+ $file = $this->getSource($variant);
+ if(is_file($file)) {
+ return array($variant, $file);
+ }
+ }
+ return false;
+ }
+
+ /**
+ * Save the list of untranslated blocks to the translation source.
+ * If the translation was not found, you should add those
+ * strings to the translation source via the <b>append()</b> method.
+ * @param string the catalogue to add to
+ * @return boolean true if saved successfuly, false otherwise.
+ */
+ public function save($catalogue='messages')
+ {
+ $messages = $this->untranslated;
+ if(count($messages) <= 0) {
+ return false;
+ }
+
+ $variants = $this->getVariants($catalogue);
+
+ if($variants) {
+ list($variant, $filename) = $variants;
+ } else {
+ list($variant, $filename) = $this->createMessageTemplate($catalogue);
+ }
+
+ if(is_writable($filename) == false) {
+ throw new TIOException("Unable to save to file {$filename}, file must be writable.");
+ }
+
+ //create a new dom, import the existing xml
+ $dom = new DOMDocument();
+ $dom->load($filename);
+
+ //find the body element
+ $xpath = new DomXPath($dom);
+ $body = $xpath->query('//body')->item(0);
+
+ $lastNodes = $xpath->query('//trans-unit[last()]');
+ if(($last=$lastNodes->item(0))!==null) {
+ $count = (int)$last->getAttribute('id');
+ } else {
+ $count = 0;
+ }
+
+ //for each message add it to the XML file using DOM
+ foreach($messages as $message)
+ {
+ $unit = $dom->createElement('trans-unit');
+ $unit->setAttribute('id',++$count);
+
+ $source = $dom->createElement('source');
+ $source->appendChild($dom->createCDATASection($message));
+
+ $target = $dom->createElement('target');
+ $target->appendChild($dom->createCDATASection(''));
+
+ $unit->appendChild($dom->createTextNode("\n"));
+ $unit->appendChild($source);
+ $unit->appendChild($dom->createTextNode("\n"));
+ $unit->appendChild($target);
+ $unit->appendChild($dom->createTextNode("\n"));
+
+ $body->appendChild($dom->createTextNode("\n"));
+ $body->appendChild($unit);
+ $body->appendChild($dom->createTextNode("\n"));
+ }
+
+
+ $fileNode = $xpath->query('//file')->item(0);
+ $fileNode->setAttribute('date', @date('Y-m-d\TH:i:s\Z'));
+
+ //save it and clear the cache for this variant
+ $dom->save($filename);
+ if(!empty($this->cache)) {
+ $this->cache->clean($variant, $this->culture);
+ }
+
+ return true;
+ }
+
+ /**
+ * Update the translation.
+ * @param string the source string.
+ * @param string the new translation string.
+ * @param string comments
+ * @param string the catalogue to save to.
+ * @return boolean true if translation was updated, false otherwise.
+ */
+ public function update($text, $target, $comments, $catalogue='messages')
+ {
+ $variants = $this->getVariants($catalogue);
+
+ if($variants) {
+ list($variant, $filename) = $variants;
+ } else {
+ return false;
+ }
+
+ if(is_writable($filename) == false) {
+ throw new TIOException("Unable to update file {$filename}, file must be writable.");
+ }
+
+ //create a new dom, import the existing xml
+ $dom = DOMDocument::load($filename);
+
+ //find the body element
+ $xpath = new DomXPath($dom);
+ $units = $xpath->query('//trans-unit');
+
+ //for each of the existin units
+ foreach($units as $unit)
+ {
+ $found = false;
+ $targetted = false;
+ $commented = false;
+
+ //in each unit, need to find the source, target and comment nodes
+ //it will assume that the source is before the target.
+ foreach($unit->childNodes as $node)
+ {
+ //source node
+ if($node->nodeName == 'source' && $node->firstChild->wholeText == $text) {
+ $found = true;
+ }
+
+ //found source, get the target and notes
+ if($found)
+ {
+ //set the new translated string
+ if($node->nodeName == 'target')
+ {
+ $node->nodeValue = $target;
+ $targetted = true;
+ }
+
+ //set the notes
+ if(!empty($comments) && $node->nodeName == 'note')
+ {
+ $node->nodeValue = $comments;
+ $commented = true;
+ }
+ }
+ }
+
+ //append a target
+ if($found && !$targetted) {
+ $unit->appendChild($dom->createElement('target',$target));
+ }
+
+ //append a note
+ if($found && !$commented && !empty($comments)) {
+ $unit->appendChild($dom->createElement('note',$comments));
+ }
+
+ //finished searching
+ if($found) {
+ break;
+ }
+ }
+
+ $fileNode = $xpath->query('//file')->item(0);
+ $fileNode->setAttribute('date', @date('Y-m-d\TH:i:s\Z'));
+
+ if($dom->save($filename) >0)
+ {
+ if(!empty($this->cache)) {
+ $this->cache->clean($variant, $this->culture);
+ }
+
+ return true;
+ }
+
+ return false;
+ }
+
+ /**
+ * Delete a particular message from the specified catalogue.
+ * @param string the source message to delete.
+ * @param string the catalogue to delete from.
+ * @return boolean true if deleted, false otherwise.
+ */
+ public function delete($message, $catalogue='messages')
+ {
+ $variants = $this->getVariants($catalogue);
+ if($variants) {
+ list($variant, $filename) = $variants;
+ } else {
+ return false;
+ }
+
+ if(is_writable($filename) == false) {
+ throw new TIOException("Unable to modify file {$filename}, file must be writable.");
+ }
+
+ //create a new dom, import the existing xml
+ $dom = DOMDocument::load($filename);
+
+ //find the body element
+ $xpath = new DomXPath($dom);
+ $units = $xpath->query('//trans-unit');
+
+ //for each of the existin units
+ foreach($units as $unit)
+ {
+ //in each unit, need to find the source, target and comment nodes
+ //it will assume that the source is before the target.
+ foreach($unit->childNodes as $node)
+ {
+ //source node
+ if($node->nodeName == 'source' && $node->firstChild->wholeText == $message)
+ {
+ //we found it, remove and save the xml file.
+ $unit->parentNode->removeChild($unit);
+ $fileNode = $xpath->query('//file')->item(0);
+ $fileNode->setAttribute('date', @date('Y-m-d\TH:i:s\Z'));
+
+ if(false !== $dom->save($filename)) {
+ if(!empty($this->cache)) {
+ $this->cache->clean($variant, $this->culture);
+ }
+ return true;
+ }
+
+ return false;
+ }
+ }
+ }
+
+ return false;
+ }
+
+ protected function createMessageTemplate($catalogue)
+ {
+ if($catalogue === null) {
+ $catalogue = 'messages';
+ }
+
+ $variants = $this->getCatalogueList($catalogue);
+ $variant = array_shift($variants);
+ $file = $this->getSource($variant);
+ $dir = dirname($file);
+
+ if(!is_dir($dir)) {
+ @mkdir($dir);
+ @chmod($dir,PRADO_CHMOD);
+ }
+
+ if(!is_dir($dir)) {
+ throw new TException("Unable to create directory $dir");
+ }
+
+ file_put_contents($file, $this->getTemplate($catalogue));
+ chmod($file, PRADO_CHMOD);
+
+ return array($variant, $file);
+ }
+
+ protected function getTemplate($catalogue)
+ {
+ $date = @date('c');
+ $xml = <<<EOD
+<?xml version="1.0" encoding="UTF-8"?>
+<xliff version="1.0">
+ <file source-language="EN" target-language="{$this->culture}" datatype="plaintext" original="$catalogue" date="$date" product-name="$catalogue">
+ <body>
+ </body>
+ </file>
+</xliff>
+EOD;
+ return $xml;
+ }
+}
diff --git a/framework/I18N/core/MessageSource_gettext.php b/framework/I18N/core/MessageSource_gettext.php
index 5428e32b..0e12ddba 100644
--- a/framework/I18N/core/MessageSource_gettext.php
+++ b/framework/I18N/core/MessageSource_gettext.php
@@ -1,457 +1,457 @@
-<?php
-
-/**
- * MessageSource_gettext class file.
- *
- * This program is free software; you can redistribute it and/or modify
- * it under the terms of the BSD License.
- *
- * Copyright(c) 2004 by Qiang Xue. All rights reserved.
- *
- * To contact the author write to {@link mailto:qiang.xue@gmail.com Qiang Xue}
- * The latest version of PRADO can be obtained from:
- * {@link http://prado.sourceforge.net/}
- *
- * @author Wei Zhuo <weizhuo[at]gmail[dot]com>
- * @version $Revision: 1.7 $ $Date: 2005/12/17 06:11:28 $
- * @package System.I18N.core
- */
-
-/**
- * Get the MessageSource class file.
- */
-require_once(dirname(__FILE__).'/MessageSource.php');
-
-/**
- * Get the Gettext class.
- */
-require_once(dirname(__FILE__).'/Gettext/TGettext.php');
-
-/**
- * MessageSource_gettext class.
- *
- * Using Gettext MO format as the message source for translation.
- * The gettext classes are based on PEAR's gettext MO and PO classes.
- *
- * See the MessageSource::factory() method to instantiate this class.
- *
- * @author Xiang Wei Zhuo <weizhuo[at]gmail[dot]com>
- * @version v1.0, last update on Fri Dec 24 16:18:44 EST 2004
- * @package System.I18N.core
- */
-class MessageSource_gettext extends MessageSource
-{
- /**
- * Message data filename extension.
- * @var string
- */
- protected $dataExt = '.mo';
-
- /**
- * PO data filename extension
- * @var string
- */
- protected $poExt = '.po';
-
- /**
- * Separator between culture name and source.
- * @var string
- */
- protected $dataSeparator = '.';
-
- function __construct($source)
- {
- $this->source = (string)$source;
- }
-
-
- /**
- * Load the messages from a MO file.
- * @param string MO file.
- * @return array of messages.
- */
- protected function &loadData($filename)
- {
- $mo = TGettext::factory('MO',$filename);
- $mo->load();
- $result = $mo->toArray();
-
- $results = array();
- $count=0;
- foreach($result['strings'] as $source => $target)
- {
- $results[$source][] = $target; //target
- $results[$source][] = $count++; //id
- $results[$source][] = ''; //comments
- }
- return $results;
- }
-
- /**
- * Determin if the MO file source is valid.
- * @param string MO file
- * @return boolean true if valid, false otherwise.
- */
- protected function isValidSource($filename)
- {
- return is_file($filename);
- }
-
- /**
- * Get the MO file for a specific message catalogue and cultural
- * vairant.
- * @param string message catalogue
- * @return string full path to the MO file.
- */
- protected function getSource($variant)
- {
- return $this->source.'/'.$variant;
- }
-
- /**
- * Get the last modified unix-time for this particular catalogue+variant.
- * Just use the file modified time.
- * @param string catalogue+variant
- * @return int last modified in unix-time format.
- */
- protected function getLastModified($source)
- {
- if(is_file($source))
- return filemtime($source);
- else
- return 0;
- }
-
- /**
- * Get all the variants of a particular catalogue.
- * @param string catalogue name
- * @return array list of all variants for this catalogue.
- */
- protected function getCatalogueList($catalogue)
- {
- $variants = explode('_',$this->culture);
- $source = $catalogue.$this->dataExt;
-
- $catalogues = array($source);
-
- $variant = null;
-
- for($i = 0, $k = count($variants); $i < $k; ++$i)
- {
- if(isset($variants[$i]{0}))
- {
- $variant .= ($variant)?'_'.$variants[$i]:$variants[$i];
- $catalogues[] = $catalogue.$this->dataSeparator.
- $variant.$this->dataExt;
- }
- }
- $byDir = $this->getCatalogueByDir($catalogue);
- $catalogues = array_merge($byDir,array_reverse($catalogues));
- return $catalogues;
- }
-
-
- /**
- * Traverse through the directory structure to find the catalogues.
- * This should only be called by getCatalogueList()
- * @param string a particular catalogue.
- * @return array a list of catalogues.
- * @see getCatalogueList()
- */
- private function getCatalogueByDir($catalogue)
- {
- $variants = explode('_',$this->culture);
- $catalogues = array();
-
- $variant = null;
-
- for($i = 0, $k = count($variants); $i < $k; ++$i)
- {
- if(isset($variants[$i]{0}))
- {
- $variant .= ($variant)?'_'.$variants[$i]:$variants[$i];
- $catalogues[] = $variant.'/'.$catalogue.$this->dataExt;
- }
- }
- return array_reverse($catalogues);
- }
-
- /**
- * Get the variant for a catalogue depending on the current culture.
- * @param string catalogue
- * @return string the variant.
- * @see save()
- * @see update()
- * @see delete()
- */
- private function getVariants($catalogue='messages')
- {
- if($catalogue === null) {
- $catalogue = 'messages';
- }
-
- foreach($this->getCatalogueList($catalogue) as $variant)
- {
- $file = $this->getSource($variant);
- $po = $this->getPOFile($file);
- if(is_file($file) || is_file($po))
- return array($variant, $file, $po);
- }
- return false;
- }
-
- private function getPOFile($MOFile)
- {
- $filebase = substr($MOFile, 0, strlen($MOFile)-strlen($this->dataExt));
- return $filebase.$this->poExt;
- }
-
- /**
- * Save the list of untranslated blocks to the translation source.
- * If the translation was not found, you should add those
- * strings to the translation source via the <b>append()</b> method.
- * @param string the catalogue to add to
- * @return boolean true if saved successfuly, false otherwise.
- */
- function save($catalogue='messages')
- {
- $messages = $this->untranslated;
-
- if(count($messages) <= 0) return false;
-
- $variants = $this->getVariants($catalogue);
-
- if($variants)
- list($variant, $MOFile, $POFile) = $variants;
- else
- list($variant, $MOFile, $POFile) = $this->createMessageTemplate($catalogue);
-
- if(is_writable($MOFile) == false)
- throw new TIOException("Unable to save to file {$MOFile}, file must be writable.");
- if(is_writable($POFile) == false)
- throw new TIOException("Unable to save to file {$POFile}, file must be writable.");
-
- //set the strings as untranslated.
- $strings = array();
- foreach($messages as $message)
- $strings[$message] = '';
-
- //load the PO
- $po = TGettext::factory('PO',$POFile);
- $po->load();
- $result = $po->toArray();
-
- $existing = count($result['strings']);
-
- //add to strings to the existing message list
- $result['strings'] = array_merge($result['strings'],$strings);
-
- $new = count($result['strings']);
-
- if($new > $existing)
- {
- //change the date 2004-12-25 12:26
- $result['meta']['PO-Revision-Date'] = @date('Y-m-d H:i:s');
-
- $po->fromArray($result);
- $mo = $po->toMO();
- if($po->save() && $mo->save($MOFile))
- {
- if(!empty($this->cache))
- $this->cache->clean($variant, $this->culture);
- return true;
- }
- else
- return false;
- }
- return false;
- }
-
- /**
- * Delete a particular message from the specified catalogue.
- * @param string the source message to delete.
- * @param string the catalogue to delete from.
- * @return boolean true if deleted, false otherwise.
- */
- function delete($message, $catalogue='messages')
- {
- $variants = $this->getVariants($catalogue);
- if($variants)
- list($variant, $MOFile, $POFile) = $variants;
- else
- return false;
-
- if(is_writable($MOFile) == false)
- throw new TIOException("Unable to modify file {$MOFile}, file must be writable.");
- if(is_writable($POFile) == false)
- throw new TIOException("Unable to modify file {$POFile}, file must be writable.");
-
- $po = TGettext::factory('PO',$POFile);
- $po->load();
- $result = $po->toArray();
-
- foreach($result['strings'] as $string => $value)
- {
- if($string == $message)
- {
- $result['meta']['PO-Revision-Date'] = @date('Y-m-d H:i:s');
- unset($result['strings'][$string]);
-
- $po->fromArray($result);
- $mo = $po->toMO();
- if($po->save() && $mo->save($MOFile))
- {
- if(!empty($this->cache))
- $this->cache->clean($variant, $this->culture);
- return true;
- }
- else
- return false;
- }
- }
-
- return false;
- }
-
- /**
- * Update the translation.
- * @param string the source string.
- * @param string the new translation string.
- * @param string comments
- * @param string the catalogue of the translation.
- * @return boolean true if translation was updated, false otherwise.
- */
- function update($text, $target, $comments, $catalogue='messages')
- {
- $variants = $this->getVariants($catalogue);
- if($variants)
- list($variant, $MOFile, $POFile) = $variants;
- else
- return false;
-
- if(is_writable($MOFile) == false)
- throw new TIOException("Unable to update file {$MOFile}, file must be writable.");
- if(is_writable($POFile) == false)
- throw new TIOException("Unable to update file {$POFile}, file must be writable.");
-
-
- $po = TGettext::factory('PO',$POFile);
- $po->load();
- $result = $po->toArray();
-
- foreach($result['strings'] as $string => $value)
- {
- if($string == $text)
- {
- $result['strings'][$string] = $target;
- $result['meta']['PO-Revision-Date'] = @date('Y-m-d H:i:s');
-
- $po->fromArray($result);
- $mo = $po->toMO();
-
- if($po->save() && $mo->save($MOFile))
- {
- if(!empty($this->cache))
- $this->cache->clean($variant, $this->culture);
- return true;
- }
- else
- return false;
- }
- }
-
- return false;
- }
-
-
- /**
- * Returns a list of catalogue as key and all it variants as value.
- * @return array list of catalogues
- */
- function catalogues()
- {
- return $this->getCatalogues();
- }
-
- /**
- * Returns a list of catalogue and its culture ID. This takes care
- * of directory structures.
- * E.g. array('messages','en_AU')
- * @return array list of catalogues
- */
- protected function getCatalogues($dir=null,$variant=null)
- {
- $dir = $dir?$dir:$this->source;
- $files = scandir($dir);
-
- $catalogue = array();
-
- foreach($files as $file)
- {
- if(is_dir($dir.'/'.$file)
- && preg_match('/^[a-z]{2}(_[A-Z]{2,3})?$/',$file))
- {
-
- $catalogue = array_merge($catalogue,
- $this->getCatalogues($dir.'/'.$file, $file));
- }
-
- $pos = strpos($file,$this->dataExt);
-
- if($pos >0
- && substr($file,-1*strlen($this->dataExt)) == $this->dataExt)
- {
- $name = substr($file,0,$pos);
- $dot = strrpos($name,$this->dataSeparator);
- $culture = $variant;
- $cat = $name;
- if(is_int($dot))
- {
- $culture = substr($name, $dot+1,strlen($name));
- $cat = substr($name,0,$dot);
- }
- $details[0] = $cat;
- $details[1] = $culture;
-
-
- $catalogue[] = $details;
- }
- }
- sort($catalogue);
-
- return $catalogue;
- }
-
- protected function createMessageTemplate($catalogue)
- {
- if($catalogue === null) {
- $catalogue = 'messages';
- }
- $variants = $this->getCatalogueList($catalogue);
- $variant = array_shift($variants);
- $mo_file = $this->getSource($variant);
- $po_file = $this->getPOFile($mo_file);
-
- $dir = dirname($mo_file);
- if(!is_dir($dir))
- {
- @mkdir($dir);
- @chmod($dir,PRADO_CHMOD);
- }
- if(!is_dir($dir))
- throw new TException("Unable to create directory $dir");
-
- $po = TGettext::factory('PO',$po_file);
- $result['meta']['PO-Revision-Date'] = @date('Y-m-d H:i:s');
- $result['strings'] = array();
-
- $po->fromArray($result);
- $mo = $po->toMO();
- if($po->save() && $mo->save($mo_file))
- return array($variant, $mo_file, $po_file);
- else
- throw new TException("Unable to create file $po_file and $mo_file");
- }
-}
-
-?>
+<?php
+
+/**
+ * MessageSource_gettext class file.
+ *
+ * This program is free software; you can redistribute it and/or modify
+ * it under the terms of the BSD License.
+ *
+ * Copyright(c) 2004 by Qiang Xue. All rights reserved.
+ *
+ * To contact the author write to {@link mailto:qiang.xue@gmail.com Qiang Xue}
+ * The latest version of PRADO can be obtained from:
+ * {@link http://prado.sourceforge.net/}
+ *
+ * @author Wei Zhuo <weizhuo[at]gmail[dot]com>
+ * @version $Revision: 1.7 $ $Date: 2005/12/17 06:11:28 $
+ * @package System.I18N.core
+ */
+
+/**
+ * Get the MessageSource class file.
+ */
+require_once(dirname(__FILE__).'/MessageSource.php');
+
+/**
+ * Get the Gettext class.
+ */
+require_once(dirname(__FILE__).'/Gettext/TGettext.php');
+
+/**
+ * MessageSource_gettext class.
+ *
+ * Using Gettext MO format as the message source for translation.
+ * The gettext classes are based on PEAR's gettext MO and PO classes.
+ *
+ * See the MessageSource::factory() method to instantiate this class.
+ *
+ * @author Xiang Wei Zhuo <weizhuo[at]gmail[dot]com>
+ * @version v1.0, last update on Fri Dec 24 16:18:44 EST 2004
+ * @package System.I18N.core
+ */
+class MessageSource_gettext extends MessageSource
+{
+ /**
+ * Message data filename extension.
+ * @var string
+ */
+ protected $dataExt = '.mo';
+
+ /**
+ * PO data filename extension
+ * @var string
+ */
+ protected $poExt = '.po';
+
+ /**
+ * Separator between culture name and source.
+ * @var string
+ */
+ protected $dataSeparator = '.';
+
+ function __construct($source)
+ {
+ $this->source = (string)$source;
+ }
+
+
+ /**
+ * Load the messages from a MO file.
+ * @param string MO file.
+ * @return array of messages.
+ */
+ protected function &loadData($filename)
+ {
+ $mo = TGettext::factory('MO',$filename);
+ $mo->load();
+ $result = $mo->toArray();
+
+ $results = array();
+ $count=0;
+ foreach($result['strings'] as $source => $target)
+ {
+ $results[$source][] = $target; //target
+ $results[$source][] = $count++; //id
+ $results[$source][] = ''; //comments
+ }
+ return $results;
+ }
+
+ /**
+ * Determin if the MO file source is valid.
+ * @param string MO file
+ * @return boolean true if valid, false otherwise.
+ */
+ protected function isValidSource($filename)
+ {
+ return is_file($filename);
+ }
+
+ /**
+ * Get the MO file for a specific message catalogue and cultural
+ * vairant.
+ * @param string message catalogue
+ * @return string full path to the MO file.
+ */
+ protected function getSource($variant)
+ {
+ return $this->source.'/'.$variant;
+ }
+
+ /**
+ * Get the last modified unix-time for this particular catalogue+variant.
+ * Just use the file modified time.
+ * @param string catalogue+variant
+ * @return int last modified in unix-time format.
+ */
+ protected function getLastModified($source)
+ {
+ if(is_file($source))
+ return filemtime($source);
+ else
+ return 0;
+ }
+
+ /**
+ * Get all the variants of a particular catalogue.
+ * @param string catalogue name
+ * @return array list of all variants for this catalogue.
+ */
+ protected function getCatalogueList($catalogue)
+ {
+ $variants = explode('_',$this->culture);
+ $source = $catalogue.$this->dataExt;
+
+ $catalogues = array($source);
+
+ $variant = null;
+
+ for($i = 0, $k = count($variants); $i < $k; ++$i)
+ {
+ if(isset($variants[$i]{0}))
+ {
+ $variant .= ($variant)?'_'.$variants[$i]:$variants[$i];
+ $catalogues[] = $catalogue.$this->dataSeparator.
+ $variant.$this->dataExt;
+ }
+ }
+ $byDir = $this->getCatalogueByDir($catalogue);
+ $catalogues = array_merge($byDir,array_reverse($catalogues));
+ return $catalogues;
+ }
+
+
+ /**
+ * Traverse through the directory structure to find the catalogues.
+ * This should only be called by getCatalogueList()
+ * @param string a particular catalogue.
+ * @return array a list of catalogues.
+ * @see getCatalogueList()
+ */
+ private function getCatalogueByDir($catalogue)
+ {
+ $variants = explode('_',$this->culture);
+ $catalogues = array();
+
+ $variant = null;
+
+ for($i = 0, $k = count($variants); $i < $k; ++$i)
+ {
+ if(isset($variants[$i]{0}))
+ {
+ $variant .= ($variant)?'_'.$variants[$i]:$variants[$i];
+ $catalogues[] = $variant.'/'.$catalogue.$this->dataExt;
+ }
+ }
+ return array_reverse($catalogues);
+ }
+
+ /**
+ * Get the variant for a catalogue depending on the current culture.
+ * @param string catalogue
+ * @return string the variant.
+ * @see save()
+ * @see update()
+ * @see delete()
+ */
+ private function getVariants($catalogue='messages')
+ {
+ if($catalogue === null) {
+ $catalogue = 'messages';
+ }
+
+ foreach($this->getCatalogueList($catalogue) as $variant)
+ {
+ $file = $this->getSource($variant);
+ $po = $this->getPOFile($file);
+ if(is_file($file) || is_file($po))
+ return array($variant, $file, $po);
+ }
+ return false;
+ }
+
+ private function getPOFile($MOFile)
+ {
+ $filebase = substr($MOFile, 0, strlen($MOFile)-strlen($this->dataExt));
+ return $filebase.$this->poExt;
+ }
+
+ /**
+ * Save the list of untranslated blocks to the translation source.
+ * If the translation was not found, you should add those
+ * strings to the translation source via the <b>append()</b> method.
+ * @param string the catalogue to add to
+ * @return boolean true if saved successfuly, false otherwise.
+ */
+ function save($catalogue='messages')
+ {
+ $messages = $this->untranslated;
+
+ if(count($messages) <= 0) return false;
+
+ $variants = $this->getVariants($catalogue);
+
+ if($variants)
+ list($variant, $MOFile, $POFile) = $variants;
+ else
+ list($variant, $MOFile, $POFile) = $this->createMessageTemplate($catalogue);
+
+ if(is_writable($MOFile) == false)
+ throw new TIOException("Unable to save to file {$MOFile}, file must be writable.");
+ if(is_writable($POFile) == false)
+ throw new TIOException("Unable to save to file {$POFile}, file must be writable.");
+
+ //set the strings as untranslated.
+ $strings = array();
+ foreach($messages as $message)
+ $strings[$message] = '';
+
+ //load the PO
+ $po = TGettext::factory('PO',$POFile);
+ $po->load();
+ $result = $po->toArray();
+
+ $existing = count($result['strings']);
+
+ //add to strings to the existing message list
+ $result['strings'] = array_merge($result['strings'],$strings);
+
+ $new = count($result['strings']);
+
+ if($new > $existing)
+ {
+ //change the date 2004-12-25 12:26
+ $result['meta']['PO-Revision-Date'] = @date('Y-m-d H:i:s');
+
+ $po->fromArray($result);
+ $mo = $po->toMO();
+ if($po->save() && $mo->save($MOFile))
+ {
+ if(!empty($this->cache))
+ $this->cache->clean($variant, $this->culture);
+ return true;
+ }
+ else
+ return false;
+ }
+ return false;
+ }
+
+ /**
+ * Delete a particular message from the specified catalogue.
+ * @param string the source message to delete.
+ * @param string the catalogue to delete from.
+ * @return boolean true if deleted, false otherwise.
+ */
+ function delete($message, $catalogue='messages')
+ {
+ $variants = $this->getVariants($catalogue);
+ if($variants)
+ list($variant, $MOFile, $POFile) = $variants;
+ else
+ return false;
+
+ if(is_writable($MOFile) == false)
+ throw new TIOException("Unable to modify file {$MOFile}, file must be writable.");
+ if(is_writable($POFile) == false)
+ throw new TIOException("Unable to modify file {$POFile}, file must be writable.");
+
+ $po = TGettext::factory('PO',$POFile);
+ $po->load();
+ $result = $po->toArray();
+
+ foreach($result['strings'] as $string => $value)
+ {
+ if($string == $message)
+ {
+ $result['meta']['PO-Revision-Date'] = @date('Y-m-d H:i:s');
+ unset($result['strings'][$string]);
+
+ $po->fromArray($result);
+ $mo = $po->toMO();
+ if($po->save() && $mo->save($MOFile))
+ {
+ if(!empty($this->cache))
+ $this->cache->clean($variant, $this->culture);
+ return true;
+ }
+ else
+ return false;
+ }
+ }
+
+ return false;
+ }
+
+ /**
+ * Update the translation.
+ * @param string the source string.
+ * @param string the new translation string.
+ * @param string comments
+ * @param string the catalogue of the translation.
+ * @return boolean true if translation was updated, false otherwise.
+ */
+ function update($text, $target, $comments, $catalogue='messages')
+ {
+ $variants = $this->getVariants($catalogue);
+ if($variants)
+ list($variant, $MOFile, $POFile) = $variants;
+ else
+ return false;
+
+ if(is_writable($MOFile) == false)
+ throw new TIOException("Unable to update file {$MOFile}, file must be writable.");
+ if(is_writable($POFile) == false)
+ throw new TIOException("Unable to update file {$POFile}, file must be writable.");
+
+
+ $po = TGettext::factory('PO',$POFile);
+ $po->load();
+ $result = $po->toArray();
+
+ foreach($result['strings'] as $string => $value)
+ {
+ if($string == $text)
+ {
+ $result['strings'][$string] = $target;
+ $result['meta']['PO-Revision-Date'] = @date('Y-m-d H:i:s');
+
+ $po->fromArray($result);
+ $mo = $po->toMO();
+
+ if($po->save() && $mo->save($MOFile))
+ {
+ if(!empty($this->cache))
+ $this->cache->clean($variant, $this->culture);
+ return true;
+ }
+ else
+ return false;
+ }
+ }
+
+ return false;
+ }
+
+
+ /**
+ * Returns a list of catalogue as key and all it variants as value.
+ * @return array list of catalogues
+ */
+ function catalogues()
+ {
+ return $this->getCatalogues();
+ }
+
+ /**
+ * Returns a list of catalogue and its culture ID. This takes care
+ * of directory structures.
+ * E.g. array('messages','en_AU')
+ * @return array list of catalogues
+ */
+ protected function getCatalogues($dir=null,$variant=null)
+ {
+ $dir = $dir?$dir:$this->source;
+ $files = scandir($dir);
+
+ $catalogue = array();
+
+ foreach($files as $file)
+ {
+ if(is_dir($dir.'/'.$file)
+ && preg_match('/^[a-z]{2}(_[A-Z]{2,3})?$/',$file))
+ {
+
+ $catalogue = array_merge($catalogue,
+ $this->getCatalogues($dir.'/'.$file, $file));
+ }
+
+ $pos = strpos($file,$this->dataExt);
+
+ if($pos >0
+ && substr($file,-1*strlen($this->dataExt)) == $this->dataExt)
+ {
+ $name = substr($file,0,$pos);
+ $dot = strrpos($name,$this->dataSeparator);
+ $culture = $variant;
+ $cat = $name;
+ if(is_int($dot))
+ {
+ $culture = substr($name, $dot+1,strlen($name));
+ $cat = substr($name,0,$dot);
+ }
+ $details[0] = $cat;
+ $details[1] = $culture;
+
+
+ $catalogue[] = $details;
+ }
+ }
+ sort($catalogue);
+
+ return $catalogue;
+ }
+
+ protected function createMessageTemplate($catalogue)
+ {
+ if($catalogue === null) {
+ $catalogue = 'messages';
+ }
+ $variants = $this->getCatalogueList($catalogue);
+ $variant = array_shift($variants);
+ $mo_file = $this->getSource($variant);
+ $po_file = $this->getPOFile($mo_file);
+
+ $dir = dirname($mo_file);
+ if(!is_dir($dir))
+ {
+ @mkdir($dir);
+ @chmod($dir,PRADO_CHMOD);
+ }
+ if(!is_dir($dir))
+ throw new TException("Unable to create directory $dir");
+
+ $po = TGettext::factory('PO',$po_file);
+ $result['meta']['PO-Revision-Date'] = @date('Y-m-d H:i:s');
+ $result['strings'] = array();
+
+ $po->fromArray($result);
+ $mo = $po->toMO();
+ if($po->save() && $mo->save($mo_file))
+ return array($variant, $mo_file, $po_file);
+ else
+ throw new TException("Unable to create file $po_file and $mo_file");
+ }
+}
+
+?>
diff --git a/framework/I18N/core/NumberFormat.php b/framework/I18N/core/NumberFormat.php
index 3b683c6c..3c733713 100644
--- a/framework/I18N/core/NumberFormat.php
+++ b/framework/I18N/core/NumberFormat.php
@@ -1,306 +1,306 @@
-<?php
-
-/**
- * NumberFormat class file.
- *
- * This program is free software; you can redistribute it and/or modify
- * it under the terms of the BSD License.
- *
- * Copyright(c) 2004 by Qiang Xue. All rights reserved.
- *
- * To contact the author write to {@link mailto:qiang.xue@gmail.com Qiang Xue}
- * The latest version of PRADO can be obtained from:
- * {@link http://prado.sourceforge.net/}
- *
- * @author Wei Zhuo <weizhuo[at]gmail[dot]com>
- * @version $Revision: 1.6 $ $Date: 2005/12/20 09:32:42 $
- * @package System.I18N.core
- */
-
-/**
- * Get the NumberFormatInfo class file.
- */
-require_once(dirname(__FILE__).'/NumberFormatInfo.php');
-
-
-/**
- * Get the encoding utilities
- */
-require_once(dirname(__FILE__).'/util.php');
-
-
-/**
- * NumberFormat class.
- *
- * NumberFormat formats decimal numbers in any locale. The decimal
- * number is formatted according to a particular pattern. These
- * patterns can arise from the NumberFormatInfo object which is
- * culturally sensitive. The NumberFormat class can be instantiated in
- * many ways. E.g.
- *
- * <code>
- * //create a invariant number formatter.
- * $formatter = new NumberFormat();
- *
- * //create a number format for the french language locale.
- * $fr = new NumberFormat('fr');
- *
- * //create a number format base on a NumberFormatInfo instance $numberInfo.
- * $format = new NumberFormat($numberInfo);
- * </code>
- *
- * A normal decimal number can also be displayed as a currency
- * or as a percentage. For example
- * <code>
- * $format->format(1234.5); //Decimal number "1234.5"
- * $format->format(1234.5,'c'); //Default currency "$1234.50"
- * $format->format(0.25, 'p') //Percent "25%"
- * </code>
- *
- * Currency is formated using the localized currency pattern. For example
- * to format the number as Japanese Yen:
- * <code>
- * $ja = new NumberFormat('ja_JP');
- *
- * //Japanese currency pattern, and using Japanese Yen symbol
- * $ja->format(123.14,'c','JPY'); //�?123 (Yen 123)
- * </code>
- * For each culture, the symbol for each currency may be different.
- *
- * @author Xiang Wei Zhuo <weizhuo[at]gmail[dot]com>
- * @version v1.0, last update on Fri Dec 10 18:10:20 EST 2004
- * @package System.I18N.core
- */
-class NumberFormat
-{
-
- /**
- * The DateTimeFormatInfo, containing culture specific patterns and names.
- * @var DateTimeFormatInfo
- */
- protected $formatInfo;
-
- /**
- * Create a new number format instance. The constructor can be instantiated
- * with a string that represent a culture/locale. Similarly, passing
- * a CultureInfo or NumberFormatInfo instance will instantiated a instance
- * for that particular culture.
- * @param mixed either null, a CultureInfo, a NumberFormatInfo, or string
- * @return NumberFormat
- */
- function __construct($formatInfo=null)
- {
- if($formatInfo === null)
- $this->formatInfo = NumberFormatInfo::getInvariantInfo();
- else if($formatInfo instanceof CultureInfo)
- $this->formatInfo = $formatInfo->NumberFormat;
- else if($formatInfo instanceof NumberFormatInfo)
- $this->formatInfo = $formatInfo;
- else
- $this->formatInfo =
- NumberFormatInfo::getInstance($formatInfo);
- }
-
- /**
- * For the number for a certain pattern. The valid patterns are
- * 'c', 'd', 'e', 'p' or a custom pattern, such as "#.000" for
- * 3 decimal places.
- * @param mixed the number to format.
- * @param string the format pattern, either, 'c', 'd', 'e', 'p'
- * or a custom pattern. E.g. "#.000" will format the number to
- * 3 decimal places.
- * @param string 3-letter ISO 4217 code. For example, the code
- * "USD" represents the US Dollar and "EUR" represents the Euro currency.
- * @return string formatted number string
- */
- function format($number, $pattern='d', $currency='USD', $charset='UTF-8')
- {
- $this->setPattern($pattern);
-
- if(strtolower($pattern) == 'p')
- $number = $number * 100;
-
- $string = (string)$number;
-
- $decimal = $this->formatDecimal($string);
- $integer = $this->formatInteger(abs($number));
-
- if(strlen($decimal)>0)
- $result = $integer.$decimal;
- else
- $result = $integer;
-
- //get the suffix
- if($number >= 0)
- $suffix = $this->formatInfo->PositivePattern;
- else if($number < 0)
- $suffix = $this->formatInfo->NegativePattern;
- else
- $suffix = array("","");
-
- //append and prepend suffix
- $result = $suffix[0].$result.$suffix[1];
-
- //replace currency sign
- $symbol = @$this->formatInfo->getCurrencySymbol($currency);
- if($symbol === null) {
- $symbol = $currency;
- }
-
- $result = str_replace('¤',$symbol, $result);
-
- return I18N_toEncoding($result, $charset);
- }
-
- /**
- * For the integer, perform groupings and string padding.
- * @param string the decimal number in string form.
- * @return string formatted integer string with grouping
- */
- protected function formatInteger($string)
- {
- $string = (string)$string;
-
- $decimalDigits = $this->formatInfo->DecimalDigits;
- //if not decimal digits, assume 0 decimal points.
- if(is_int($decimalDigits) && $decimalDigits > 0)
- $string = (string)round(floatval($string),$decimalDigits);
- $dp = strpos($string, '.');
- if(is_int($dp))
- $string = substr($string, 0, $dp);
- $integer = '';
-
- $digitSize = $this->formatInfo->getDigitSize();
-
- $string = str_pad($string, $digitSize, '0',STR_PAD_LEFT);
-
- $len = strlen($string);
-
- $groupSeparator = $this->formatInfo->GroupSeparator;
- $groupSize = $this->formatInfo->GroupSizes;
-
-
- $firstGroup = true;
- $multiGroup = is_int($groupSize[1]);
- $count = 0;
-
- if(is_int($groupSize[0]))
- {
- //now for the integer groupings
- for($i=0; $i<$len; $i++)
- {
- $char = $string{$len-$i-1};
-
- if($multiGroup && $count == 0)
- {
- if($i != 0 && $i%$groupSize[0] == 0)
- {
- $integer = $groupSeparator . $integer;
- $count++;
- }
- }
- else if($multiGroup && $count >= 1)
- {
- if($i != 0 && ($i-$groupSize[0])%$groupSize[1] == 0)
- {
- $integer = $groupSeparator . $integer;
- $count++;
- }
- }
- else
- {
- if($i != 0 && $i%$groupSize[0] == 0)
- {
- $integer = $groupSeparator . $integer;
- $count++;
- }
- }
-
- $integer = $char . $integer;
- }
- }
- else
- $integer = $string;
-
- return $integer;
- }
-
- /**
- * Format the decimal places.
- * @param string the decimal number in string form.
- * @return string formatted decimal places.
- */
- protected function formatDecimal($string)
- {
- $dp = strpos($string, '.');
- $decimal = '';
-
- $decimalDigits = $this->formatInfo->DecimalDigits;
- $decimalSeparator = $this->formatInfo->DecimalSeparator;
-
- //do the correct rounding here
- //$string = round(floatval($string), $decimalDigits);
- if(is_int($dp))
- {
- if($decimalDigits == -1)
- {
- $decimal = substr($string, $dp+1);
- }
- else if(is_int($decimalDigits))
- {
- $float = round((float)$string, $decimalDigits);
- if(strpos((string)$float, '.') === false)
- {
- $decimal = str_pad($decimal,$decimalDigits,'0');
- }
- else
- {
- $decimal = substr($float, strpos($float,'.')+1);
- if(strlen($decimal)<$decimalDigits)
- $decimal = str_pad($decimal,$decimalDigits,'0');
- }
- }
- else
- return $decimal;
-
- return $decimalSeparator.$decimal;
- }
- else if ($decimalDigits > 0)
- return $decimalSeparator.str_pad($decimal,$decimalDigits,'0');
-
- return $decimal;
- }
-
- /**
- * Set the pattern to format against. The default patterns
- * are retrieved from the NumberFormatInfo instance.
- * @param string the requested patterns.
- * @return string a number format pattern.
- */
- protected function setPattern($pattern)
- {
- switch($pattern)
- {
- case 'c':
- case 'C':
- $this->formatInfo->setPattern(NumberFormatInfo::CURRENCY);
- break;
- case 'd':
- case 'D':
- $this->formatInfo->setPattern(NumberFormatInfo::DECIMAL);
- break;
- case 'e':
- case 'E':
- $this->formatInfo->setPattern(NumberFormatInfo::SCIENTIFIC);
- break;
- case 'p':
- case 'P':
- $this->formatInfo->setPattern(NumberFormatInfo::PERCENTAGE);
- break;
- default:
- $this->formatInfo->setPattern($pattern);
- break;
- }
- }
-}
-
+<?php
+
+/**
+ * NumberFormat class file.
+ *
+ * This program is free software; you can redistribute it and/or modify
+ * it under the terms of the BSD License.
+ *
+ * Copyright(c) 2004 by Qiang Xue. All rights reserved.
+ *
+ * To contact the author write to {@link mailto:qiang.xue@gmail.com Qiang Xue}
+ * The latest version of PRADO can be obtained from:
+ * {@link http://prado.sourceforge.net/}
+ *
+ * @author Wei Zhuo <weizhuo[at]gmail[dot]com>
+ * @version $Revision: 1.6 $ $Date: 2005/12/20 09:32:42 $
+ * @package System.I18N.core
+ */
+
+/**
+ * Get the NumberFormatInfo class file.
+ */
+require_once(dirname(__FILE__).'/NumberFormatInfo.php');
+
+
+/**
+ * Get the encoding utilities
+ */
+require_once(dirname(__FILE__).'/util.php');
+
+
+/**
+ * NumberFormat class.
+ *
+ * NumberFormat formats decimal numbers in any locale. The decimal
+ * number is formatted according to a particular pattern. These
+ * patterns can arise from the NumberFormatInfo object which is
+ * culturally sensitive. The NumberFormat class can be instantiated in
+ * many ways. E.g.
+ *
+ * <code>
+ * //create a invariant number formatter.
+ * $formatter = new NumberFormat();
+ *
+ * //create a number format for the french language locale.
+ * $fr = new NumberFormat('fr');
+ *
+ * //create a number format base on a NumberFormatInfo instance $numberInfo.
+ * $format = new NumberFormat($numberInfo);
+ * </code>
+ *
+ * A normal decimal number can also be displayed as a currency
+ * or as a percentage. For example
+ * <code>
+ * $format->format(1234.5); //Decimal number "1234.5"
+ * $format->format(1234.5,'c'); //Default currency "$1234.50"
+ * $format->format(0.25, 'p') //Percent "25%"
+ * </code>
+ *
+ * Currency is formated using the localized currency pattern. For example
+ * to format the number as Japanese Yen:
+ * <code>
+ * $ja = new NumberFormat('ja_JP');
+ *
+ * //Japanese currency pattern, and using Japanese Yen symbol
+ * $ja->format(123.14,'c','JPY'); //�?123 (Yen 123)
+ * </code>
+ * For each culture, the symbol for each currency may be different.
+ *
+ * @author Xiang Wei Zhuo <weizhuo[at]gmail[dot]com>
+ * @version v1.0, last update on Fri Dec 10 18:10:20 EST 2004
+ * @package System.I18N.core
+ */
+class NumberFormat
+{
+
+ /**
+ * The DateTimeFormatInfo, containing culture specific patterns and names.
+ * @var DateTimeFormatInfo
+ */
+ protected $formatInfo;
+
+ /**
+ * Create a new number format instance. The constructor can be instantiated
+ * with a string that represent a culture/locale. Similarly, passing
+ * a CultureInfo or NumberFormatInfo instance will instantiated a instance
+ * for that particular culture.
+ * @param mixed either null, a CultureInfo, a NumberFormatInfo, or string
+ * @return NumberFormat
+ */
+ function __construct($formatInfo=null)
+ {
+ if($formatInfo === null)
+ $this->formatInfo = NumberFormatInfo::getInvariantInfo();
+ else if($formatInfo instanceof CultureInfo)
+ $this->formatInfo = $formatInfo->NumberFormat;
+ else if($formatInfo instanceof NumberFormatInfo)
+ $this->formatInfo = $formatInfo;
+ else
+ $this->formatInfo =
+ NumberFormatInfo::getInstance($formatInfo);
+ }
+
+ /**
+ * For the number for a certain pattern. The valid patterns are
+ * 'c', 'd', 'e', 'p' or a custom pattern, such as "#.000" for
+ * 3 decimal places.
+ * @param mixed the number to format.
+ * @param string the format pattern, either, 'c', 'd', 'e', 'p'
+ * or a custom pattern. E.g. "#.000" will format the number to
+ * 3 decimal places.
+ * @param string 3-letter ISO 4217 code. For example, the code
+ * "USD" represents the US Dollar and "EUR" represents the Euro currency.
+ * @return string formatted number string
+ */
+ function format($number, $pattern='d', $currency='USD', $charset='UTF-8')
+ {
+ $this->setPattern($pattern);
+
+ if(strtolower($pattern) == 'p')
+ $number = $number * 100;
+
+ $string = (string)$number;
+
+ $decimal = $this->formatDecimal($string);
+ $integer = $this->formatInteger(abs($number));
+
+ if(strlen($decimal)>0)
+ $result = $integer.$decimal;
+ else
+ $result = $integer;
+
+ //get the suffix
+ if($number >= 0)
+ $suffix = $this->formatInfo->PositivePattern;
+ else if($number < 0)
+ $suffix = $this->formatInfo->NegativePattern;
+ else
+ $suffix = array("","");
+
+ //append and prepend suffix
+ $result = $suffix[0].$result.$suffix[1];
+
+ //replace currency sign
+ $symbol = @$this->formatInfo->getCurrencySymbol($currency);
+ if($symbol === null) {
+ $symbol = $currency;
+ }
+
+ $result = str_replace('¤',$symbol, $result);
+
+ return I18N_toEncoding($result, $charset);
+ }
+
+ /**
+ * For the integer, perform groupings and string padding.
+ * @param string the decimal number in string form.
+ * @return string formatted integer string with grouping
+ */
+ protected function formatInteger($string)
+ {
+ $string = (string)$string;
+
+ $decimalDigits = $this->formatInfo->DecimalDigits;
+ //if not decimal digits, assume 0 decimal points.
+ if(is_int($decimalDigits) && $decimalDigits > 0)
+ $string = (string)round(floatval($string),$decimalDigits);
+ $dp = strpos($string, '.');
+ if(is_int($dp))
+ $string = substr($string, 0, $dp);
+ $integer = '';
+
+ $digitSize = $this->formatInfo->getDigitSize();
+
+ $string = str_pad($string, $digitSize, '0',STR_PAD_LEFT);
+
+ $len = strlen($string);
+
+ $groupSeparator = $this->formatInfo->GroupSeparator;
+ $groupSize = $this->formatInfo->GroupSizes;
+
+
+ $firstGroup = true;
+ $multiGroup = is_int($groupSize[1]);
+ $count = 0;
+
+ if(is_int($groupSize[0]))
+ {
+ //now for the integer groupings
+ for($i=0; $i<$len; $i++)
+ {
+ $char = $string{$len-$i-1};
+
+ if($multiGroup && $count == 0)
+ {
+ if($i != 0 && $i%$groupSize[0] == 0)
+ {
+ $integer = $groupSeparator . $integer;
+ $count++;
+ }
+ }
+ else if($multiGroup && $count >= 1)
+ {
+ if($i != 0 && ($i-$groupSize[0])%$groupSize[1] == 0)
+ {
+ $integer = $groupSeparator . $integer;
+ $count++;
+ }
+ }
+ else
+ {
+ if($i != 0 && $i%$groupSize[0] == 0)
+ {
+ $integer = $groupSeparator . $integer;
+ $count++;
+ }
+ }
+
+ $integer = $char . $integer;
+ }
+ }
+ else
+ $integer = $string;
+
+ return $integer;
+ }
+
+ /**
+ * Format the decimal places.
+ * @param string the decimal number in string form.
+ * @return string formatted decimal places.
+ */
+ protected function formatDecimal($string)
+ {
+ $dp = strpos($string, '.');
+ $decimal = '';
+
+ $decimalDigits = $this->formatInfo->DecimalDigits;
+ $decimalSeparator = $this->formatInfo->DecimalSeparator;
+
+ //do the correct rounding here
+ //$string = round(floatval($string), $decimalDigits);
+ if(is_int($dp))
+ {
+ if($decimalDigits == -1)
+ {
+ $decimal = substr($string, $dp+1);
+ }
+ else if(is_int($decimalDigits))
+ {
+ $float = round((float)$string, $decimalDigits);
+ if(strpos((string)$float, '.') === false)
+ {
+ $decimal = str_pad($decimal,$decimalDigits,'0');
+ }
+ else
+ {
+ $decimal = substr($float, strpos($float,'.')+1);
+ if(strlen($decimal)<$decimalDigits)
+ $decimal = str_pad($decimal,$decimalDigits,'0');
+ }
+ }
+ else
+ return $decimal;
+
+ return $decimalSeparator.$decimal;
+ }
+ else if ($decimalDigits > 0)
+ return $decimalSeparator.str_pad($decimal,$decimalDigits,'0');
+
+ return $decimal;
+ }
+
+ /**
+ * Set the pattern to format against. The default patterns
+ * are retrieved from the NumberFormatInfo instance.
+ * @param string the requested patterns.
+ * @return string a number format pattern.
+ */
+ protected function setPattern($pattern)
+ {
+ switch($pattern)
+ {
+ case 'c':
+ case 'C':
+ $this->formatInfo->setPattern(NumberFormatInfo::CURRENCY);
+ break;
+ case 'd':
+ case 'D':
+ $this->formatInfo->setPattern(NumberFormatInfo::DECIMAL);
+ break;
+ case 'e':
+ case 'E':
+ $this->formatInfo->setPattern(NumberFormatInfo::SCIENTIFIC);
+ break;
+ case 'p':
+ case 'P':
+ $this->formatInfo->setPattern(NumberFormatInfo::PERCENTAGE);
+ break;
+ default:
+ $this->formatInfo->setPattern($pattern);
+ break;
+ }
+ }
+}
+
diff --git a/framework/I18N/core/NumberFormatInfo.php b/framework/I18N/core/NumberFormatInfo.php
index 17149317..2a666726 100644
--- a/framework/I18N/core/NumberFormatInfo.php
+++ b/framework/I18N/core/NumberFormatInfo.php
@@ -1,650 +1,650 @@
-<?php
-
-/**
- * NumberFormatInfo class file.
- *
- * This program is free software; you can redistribute it and/or modify
- * it under the terms of the BSD License.
- *
- * Copyright(c) 2004 by Qiang Xue. All rights reserved.
- *
- * To contact the author write to {@link mailto:qiang.xue@gmail.com Qiang Xue}
- * The latest version of PRADO can be obtained from:
- * {@link http://prado.sourceforge.net/}
- *
- * @author Wei Zhuo <weizhuo[at]gmail[dot]com>
- * @version $Revision: 1.3 $ $Date: 2005/08/04 05:27:19 $
- * @package System.I18N.core
- */
-
-/**
- * Get the CultureInfo class file.
- */
-require_once(dirname(__FILE__).'/CultureInfo.php');
-
-/**
- * NumberFormatInfo class
- *
- * Defines how numeric values are formatted and displayed,
- * depending on the culture. Numeric values are formatted using
- * standard or custom patterns stored in the properties of a
- * NumberFormatInfo.
- *
- * This class contains information, such as currency, decimal
- * separators, and other numeric symbols.
- *
- * To create a NumberFormatInfo for a specific culture,
- * create a CultureInfo for that culture and retrieve the
- * CultureInfo->NumberFormat property. Or use
- * NumberFormatInfo::getInstance($culture).
- * To create a NumberFormatInfo for the invariant culture, use the
- * InvariantInfo::getInvariantInfo().
- *
- *
- * @author Xiang Wei Zhuo <weizhuo[at]gmail[dot]com>
- * @version v1.0, last update on Sun Dec 05 14:48:26 EST 2004
- * @package System.I18N.core
- */
-class NumberFormatInfo
-{
-
- /**
- * ICU number formatting data.
- * @var array
- */
- private $data = array();
-
- /**
- * A list of properties that are accessable/writable.
- * @var array
- */
- protected $properties = array();
-
- /**
- * The number pattern.
- * @var array
- */
- protected $pattern = array();
-
- const DECIMAL = 0;
- const CURRENCY = 1;
- const PERCENTAGE = 2;
- const SCIENTIFIC = 3;
-
- /**
- * Allow functions that begins with 'set' to be called directly
- * as an attribute/property to retrieve the value.
- * @return mixed
- */
- public function __get($name)
- {
- $getProperty = 'get'.$name;
- if(in_array($getProperty, $this->properties))
- return $this->$getProperty();
- else
- throw new Exception('Property '.$name.' does not exists.');
- }
-
- /**
- * Allow functions that begins with 'set' to be called directly
- * as an attribute/property to set the value.
- */
- public function __set($name, $value)
- {
- $setProperty = 'set'.$name;
- if(in_array($setProperty, $this->properties))
- $this->$setProperty($value);
- else
- throw new Exception('Property '.$name.' can not be set.');
- }
-
- /**
- * Initializes a new writable instance of the NumberFormatInfo class
- * that is dependent on the ICU data for number, decimal, and currency
- * formatting information. <b>N.B.</b>You should not initialize this
- * class directly unless you know what you are doing. Please use use
- * NumberFormatInfo::getInstance() to create an instance.
- * @param array ICU data for date time formatting.
- * @see getInstance()
- */
- public function __construct($data=array(), $type=NumberFormatInfo::DECIMAL)
- {
- $this->properties = get_class_methods($this);
-
- if(empty($data))
- throw new Exception('Please provide the ICU data to initialize.');
-
- $this->data = $data;
-
- $this->setPattern($type);
- }
-
- /**
- * Set the pattern for a specific number pattern. The validate patterns
- * NumberFormatInfo::DECIMAL, NumberFormatInfo::CURRENCY,
- * NumberFormatInfo::PERCENTAGE, or NumberFormatInfo::SCIENTIFIC
- * @param int pattern type.
- */
- public function setPattern($type=NumberFormatInfo::DECIMAL)
- {
- if(is_int($type))
- $this->pattern =
- $this->parsePattern($this->data['NumberPatterns'][$type]);
- else
- $this->pattern = $this->parsePattern($type);
-
- $this->pattern['negInfty'] =
- $this->data['NumberElements'][6].
- $this->data['NumberElements'][9];
-
- $this->pattern['posInfty'] =
- $this->data['NumberElements'][11].
- $this->data['NumberElements'][9];
- }
-
- public function getPattern()
- {
- return $this->pattern;
- }
-
- /**
- * Gets the default NumberFormatInfo that is culture-independent
- * (invariant).
- * @return NumberFormatInfo default NumberFormatInfo.
- */
- public static function getInvariantInfo($type=NumberFormatInfo::DECIMAL)
- {
- static $invariant;
- if($invariant === null)
- {
- $culture = CultureInfo::getInvariantCulture();
- $invariant = $culture->NumberFormat;
- $invariant->setPattern($type);
- }
- return $invariant;
- }
-
- /**
- * Returns the NumberFormatInfo associated with the specified culture.
- * @param CultureInfo the culture that gets the NumberFormat property.
- * @param int the number formatting type, it should be
- * NumberFormatInfo::DECIMAL, NumberFormatInfo::CURRENCY,
- * NumberFormatInfo::PERCENTAGE, or NumberFormatInfo::SCIENTIFIC
- * @return NumberFormatInfo NumberFormatInfo for the specified
- * culture.
- * @see getCurrencyInstance();
- * @see getPercentageInstance();
- * @see getScientificInstance();
- */
- public static function getInstance($culture=null,
- $type=NumberFormatInfo::DECIMAL)
- {
- if ($culture instanceof CultureInfo)
- {
- $formatInfo = $culture->NumberFormat;
- $formatInfo->setPattern($type);
- return $formatInfo;
- }
- else if(is_string($culture))
- {
- $cultureInfo = new CultureInfo($culture);
- $formatInfo = $cultureInfo->NumberFormat;
- $formatInfo->setPattern($type);
- return $formatInfo;
- }
- else
- {
- $cultureInfo = new CultureInfo();
- $formatInfo = $cultureInfo->NumberFormat;
- $formatInfo->setPattern($type);
- return $formatInfo;
- }
- }
-
- /**
- * Returns the currency format info associated with the specified culture.
- * @param CultureInfo the culture that gets the NumberFormat property.
- * @return NumberFormatInfo NumberFormatInfo for the specified
- * culture.
- */
- public static function getCurrencyInstance($culture=null)
- {
- return self::getInstance($culture, self::CURRENCY);
- }
-
- /**
- * Returns the percentage format info associated with the specified culture.
- * @param CultureInfo the culture that gets the NumberFormat property.
- * @return NumberFormatInfo NumberFormatInfo for the specified
- * culture.
- */
- public static function getPercentageInstance($culture=null)
- {
- return self::getInstance($culture, self::PERCENTAGE);
- }
-
- /**
- * Returns the scientific format info associated with the specified culture.
- * @param CultureInfo the culture that gets the NumberFormat property.
- * @return NumberFormatInfo NumberFormatInfo for the specified
- * culture.
- */
- public static function getScientificInstance($culture=null)
- {
- return self::getInstance($culture, self::SCIENTIFIC);
- }
-
- /**
- * Parse the given pattern and return a list of known properties.
- * @param string a number pattern.
- * @return array list of pattern properties.
- */
- protected function parsePattern($pattern)
- {
- $pattern = explode(';',$pattern);
-
- $negative = null;
- if(count($pattern) > 1)
- $negative = $pattern[1];
- $pattern = $pattern[0];
-
- $comma = ',';
- $dot = '.';
- $digit = '0';
- $hash = '#';
-
- //find the first group point, and decimal point
- $groupPos1 = strrpos($pattern,$comma);
- $decimalPos = strrpos($pattern,$dot);
-
- $groupPos2 = false;
- $groupSize1 = false;
- $groupSize2 = false;
- $decimalPoints = is_int($decimalPos)?-1:false;
-
- $info['negPref'] = $this->data['NumberElements'][6];
- $info['negPost'] = '';
-
- $info['negative'] = $negative;
- $info['positive'] = $pattern;
-
- //find the negative prefix and postfix
- if($negative)
- {
- $prefixPostfix = $this->getPrePostfix($negative);
- $info['negPref'] = $prefixPostfix[0];
- $info['negPost'] = $prefixPostfix[1];
- }
-
- $posfix = $this->getPrePostfix($pattern);
- $info['posPref'] = $posfix[0];
- $info['posPost'] = $posfix[1];
-
- //var_dump($pattern);
- //var_dump($decimalPos);
- if(is_int($groupPos1))
- {
- //get the second group
- $groupPos2 = strrpos(substr($pattern,0,$groupPos1),$comma);
-
- //get the number of decimal digits
- if(is_int($decimalPos))
- {
- $groupSize1 = $decimalPos - $groupPos1-1;
-
- }
- else
- {
- //no decimal point, so traverse from the back
- //to find the groupsize 1.
- for($i=strlen($pattern)-1; $i>=0; $i--)
- {
- if($pattern{$i} == $digit || $pattern{$i}==$hash)
- {
- $groupSize1 = $i - $groupPos1;
- break;
- }
- }
- }
-
- //get the second group size
- if(is_int($groupPos2))
- $groupSize2 = $groupPos1 - $groupPos2-1;
- }
-
- if(is_int($decimalPos))
- {
- for($i=strlen($pattern)-1; $i>=0; $i--)
- {
- if($pattern{$i} == $dot) break;
- if($pattern{$i} == $digit)
- {
- $decimalPoints = $i - $decimalPos;
- break;
- }
- }
- }
-
- if(is_int($decimalPos))
- $digitPattern = substr($pattern,0,$decimalPos);
- else
- $digitPattern = $pattern;
-
- $digitPattern = preg_replace('/[^0]/','',$digitPattern);
-
- $info['groupPos1'] = $groupPos1;
- $info['groupSize1'] = $groupSize1;
- $info['groupPos2'] = $groupPos2;
- $info['groupSize2'] = $groupSize2;
- $info['decimalPos'] = $decimalPos;
- $info['decimalPoints'] = $decimalPoints;
- $info['digitSize'] = strlen($digitPattern);
- return $info;
- }
-
- /**
- * Get the prefix and postfix of a pattern.
- * @param string pattern
- * @return array of prefix and postfix, array(prefix,postfix).
- */
- protected function getPrePostfix($pattern)
- {
- $regexp = '/[#,\.0]+/';
- $result = preg_split($regexp, $pattern);
- return array($result[0],$result[1]);
- }
-
-
- /**
- * Indicates the number of decimal places.
- * @return int number of decimal places.
- */
- function getDecimalDigits()
- {
- return $this->pattern['decimalPoints'];
- }
-
- /**
- * Set the number of decimal places.
- * @param int number of decimal places.
- */
- function setDecimalDigits($value)
- {
- return $this->pattern['decimalPoints'] = $value;
- }
-
- function getDigitSize()
- {
- return $this->pattern['digitSize'];
- }
-
- function setDigitSize($value)
- {
- $this->pattern['digitSize'] = $value;
- }
-
- /**
- * Gets the string to use as the decimal separator.
- * @return string decimal separator.
- */
- function getDecimalSeparator()
- {
- return $this->data['NumberElements'][0];
- }
-
- /**
- * Set the string to use as the decimal separator.
- * @param string the decimal point
- */
- function setDecimalSeparator($value)
- {
- return $this->data['NumberElements'][0] = $value;
- }
-
- /**
- * Gets the string that separates groups of digits to the left
- * of the decimal in currency values.
- * @param parameter
- * @return string currency group separator.
- */
- function getGroupSeparator()
- {
- return $this->data['NumberElements'][1];
- }
-
- /**
- * Set the string to use as the group separator.
- * @param string the group separator.
- */
- function setGroupSeparator($value)
- {
- return $this->data['NumberElements'][1] = $value;
- }
-
- /**
- * Gets the number of digits in each group to the left of the decimal
- * There can be two grouping sizes, this fucntion
- * returns <b>array(group1, group2)</b>, if there is only 1 grouping size,
- * group2 will be false.
- * @return array grouping size(s).
- */
- function getGroupSizes()
- {
- $group1 = $this->pattern['groupSize1'];
- $group2 = $this->pattern['groupSize2'];
-
- return array($group1, $group2);
- }
-
- /**
- * Set the number of digits in each group to the left of the decimal.
- * There can be two grouping sizes, the value should
- * be an <b>array(group1, group2)</b>, if there is only 1 grouping size,
- * group2 should be false.
- * @param array grouping size(s).
- */
- function setGroupSizes($groupSize)
- {
- $this->pattern['groupSize1'] = $groupSize[0];
- $this->pattern['groupSize2'] = $groupSize[1];
- }
-
- /**
- * Gets the format pattern for negative values.
- * The negative pattern is composed of a prefix, and postfix.
- * This function returns <b>array(prefix, postfix)</b>.
- * @return arary negative pattern.
- */
- function getNegativePattern()
- {
- $prefix = $this->pattern['negPref'];
- $postfix = $this->pattern['negPost'];
- return array($prefix, $postfix);
- }
-
- /**
- * Set the format pattern for negative values.
- * The negative pattern is composed of a prefix, and postfix in the form
- * <b>array(prefix, postfix)</b>.
- * @param arary negative pattern.
- */
- function setNegativePattern($pattern)
- {
- $this->pattern['negPref'] = $pattern[0];
- $this->pattern['negPost'] = $pattern[1];
- }
-
- /**
- * Gets the format pattern for positive values.
- * The positive pattern is composed of a prefix, and postfix.
- * This function returns <b>array(prefix, postfix)</b>.
- * @return arary positive pattern.
- */
- function getPositivePattern()
- {
- $prefix = $this->pattern['posPref'];
- $postfix = $this->pattern['posPost'];
- return array($prefix, $postfix);
- }
-
- /**
- * Set the format pattern for positive values.
- * The positive pattern is composed of a prefix, and postfix in the form
- * <b>array(prefix, postfix)</b>.
- * @param arary positive pattern.
- */
- function setPositivePattern($pattern)
- {
- $this->pattern['posPref'] = $pattern[0];
- $this->pattern['posPost'] = $pattern[1];
- }
-
- /**
- * Gets the string to use as the currency symbol.
- * @return string currency symbol.
- */
- function getCurrencySymbol($currency='USD')
- {
- if(isset($this->pattern['symbol']))
- return $this->pattern['symbol'];
- else
- return $this->data['Currencies'][$currency][0];
- }
-
-
- /**
- * Set the string to use as the currency symbol.
- * @param string currency symbol.
- */
- function setCurrencySymbol($symbol)
- {
- $this->pattern['symbol'] = $symbol;
- }
-
- /**
- * Gets the string that represents negative infinity.
- * @return string negative infinity.
- */
- function getNegativeInfinitySymbol()
- {
- return $this->pattern['negInfty'];
- }
-
- /**
- * Set the string that represents negative infinity.
- * @param string negative infinity.
- */
- function setNegativeInfinitySymbol($value)
- {
- $this->pattern['negInfty'] = $value;
- }
-
- /**
- * Gets the string that represents positive infinity.
- * @return string positive infinity.
- */
- function getPositiveInfinitySymbol()
- {
- return $this->pattern['posInfty'];
- }
-
- /**
- * Set the string that represents positive infinity.
- * @param string positive infinity.
- */
- function setPositiveInfinitySymbol($value)
- {
- $this->pattern['posInfty'] = $value;
- }
-
- /**
- * Gets the string that denotes that the associated number is negative.
- * @return string negative sign.
- */
- function getNegativeSign()
- {
- return $this->data['NumberElements'][6];
- }
-
- /**
- * Set the string that denotes that the associated number is negative.
- * @param string negative sign.
- */
- function setNegativeSign($value)
- {
- $this->data['NumberElements'][6] = $value;
- }
-
- /**
- * Gets the string that denotes that the associated number is positive.
- * @return string positive sign.
- */
- function getPositiveSign()
- {
- return $this->data['NumberElements'][11];
- }
-
- /**
- * Set the string that denotes that the associated number is positive.
- * @param string positive sign.
- */
- function setPositiveSign($value)
- {
- $this->data['NumberElements'][11] = $value;
- }
-
- /**
- * Gets the string that represents the IEEE NaN (not a number) value.
- * @return string NaN symbol.
- */
- function getNaNSymbol()
- {
- return $this->data['NumberElements'][10];
- }
-
- /**
- * Set the string that represents the IEEE NaN (not a number) value.
- * @param string NaN symbol.
- */
- function setNaNSymbol($value)
- {
- $this->data['NumberElements'][10] = $value;
- }
-
- /**
- * Gets the string to use as the percent symbol.
- * @return string percent symbol.
- */
- function getPercentSymbol()
- {
- return $this->data['NumberElements'][3];
- }
-
- /**
- * Set the string to use as the percent symbol.
- * @param string percent symbol.
- */
- function setPercentSymbol($value)
- {
- $this->data['NumberElements'][3] = $value;
- }
-
- /**
- * Gets the string to use as the per mille symbol.
- * @return string percent symbol.
- */
- function getPerMilleSymbol()
- {
- return $this->data['NumberElements'][8];
- }
-
- /**
- * Set the string to use as the per mille symbol.
- * @param string percent symbol.
- */
- function setPerMilleSymbol($value)
- {
- $this->data['NumberElements'][8] = $value;
- }
-}
-
+<?php
+
+/**
+ * NumberFormatInfo class file.
+ *
+ * This program is free software; you can redistribute it and/or modify
+ * it under the terms of the BSD License.
+ *
+ * Copyright(c) 2004 by Qiang Xue. All rights reserved.
+ *
+ * To contact the author write to {@link mailto:qiang.xue@gmail.com Qiang Xue}
+ * The latest version of PRADO can be obtained from:
+ * {@link http://prado.sourceforge.net/}
+ *
+ * @author Wei Zhuo <weizhuo[at]gmail[dot]com>
+ * @version $Revision: 1.3 $ $Date: 2005/08/04 05:27:19 $
+ * @package System.I18N.core
+ */
+
+/**
+ * Get the CultureInfo class file.
+ */
+require_once(dirname(__FILE__).'/CultureInfo.php');
+
+/**
+ * NumberFormatInfo class
+ *
+ * Defines how numeric values are formatted and displayed,
+ * depending on the culture. Numeric values are formatted using
+ * standard or custom patterns stored in the properties of a
+ * NumberFormatInfo.
+ *
+ * This class contains information, such as currency, decimal
+ * separators, and other numeric symbols.
+ *
+ * To create a NumberFormatInfo for a specific culture,
+ * create a CultureInfo for that culture and retrieve the
+ * CultureInfo->NumberFormat property. Or use
+ * NumberFormatInfo::getInstance($culture).
+ * To create a NumberFormatInfo for the invariant culture, use the
+ * InvariantInfo::getInvariantInfo().
+ *
+ *
+ * @author Xiang Wei Zhuo <weizhuo[at]gmail[dot]com>
+ * @version v1.0, last update on Sun Dec 05 14:48:26 EST 2004
+ * @package System.I18N.core
+ */
+class NumberFormatInfo
+{
+
+ /**
+ * ICU number formatting data.
+ * @var array
+ */
+ private $data = array();
+
+ /**
+ * A list of properties that are accessable/writable.
+ * @var array
+ */
+ protected $properties = array();
+
+ /**
+ * The number pattern.
+ * @var array
+ */
+ protected $pattern = array();
+
+ const DECIMAL = 0;
+ const CURRENCY = 1;
+ const PERCENTAGE = 2;
+ const SCIENTIFIC = 3;
+
+ /**
+ * Allow functions that begins with 'set' to be called directly
+ * as an attribute/property to retrieve the value.
+ * @return mixed
+ */
+ public function __get($name)
+ {
+ $getProperty = 'get'.$name;
+ if(in_array($getProperty, $this->properties))
+ return $this->$getProperty();
+ else
+ throw new Exception('Property '.$name.' does not exists.');
+ }
+
+ /**
+ * Allow functions that begins with 'set' to be called directly
+ * as an attribute/property to set the value.
+ */
+ public function __set($name, $value)
+ {
+ $setProperty = 'set'.$name;
+ if(in_array($setProperty, $this->properties))
+ $this->$setProperty($value);
+ else
+ throw new Exception('Property '.$name.' can not be set.');
+ }
+
+ /**
+ * Initializes a new writable instance of the NumberFormatInfo class
+ * that is dependent on the ICU data for number, decimal, and currency
+ * formatting information. <b>N.B.</b>You should not initialize this
+ * class directly unless you know what you are doing. Please use use
+ * NumberFormatInfo::getInstance() to create an instance.
+ * @param array ICU data for date time formatting.
+ * @see getInstance()
+ */
+ public function __construct($data=array(), $type=NumberFormatInfo::DECIMAL)
+ {
+ $this->properties = get_class_methods($this);
+
+ if(empty($data))
+ throw new Exception('Please provide the ICU data to initialize.');
+
+ $this->data = $data;
+
+ $this->setPattern($type);
+ }
+
+ /**
+ * Set the pattern for a specific number pattern. The validate patterns
+ * NumberFormatInfo::DECIMAL, NumberFormatInfo::CURRENCY,
+ * NumberFormatInfo::PERCENTAGE, or NumberFormatInfo::SCIENTIFIC
+ * @param int pattern type.
+ */
+ public function setPattern($type=NumberFormatInfo::DECIMAL)
+ {
+ if(is_int($type))
+ $this->pattern =
+ $this->parsePattern($this->data['NumberPatterns'][$type]);
+ else
+ $this->pattern = $this->parsePattern($type);
+
+ $this->pattern['negInfty'] =
+ $this->data['NumberElements'][6].
+ $this->data['NumberElements'][9];
+
+ $this->pattern['posInfty'] =
+ $this->data['NumberElements'][11].
+ $this->data['NumberElements'][9];
+ }
+
+ public function getPattern()
+ {
+ return $this->pattern;
+ }
+
+ /**
+ * Gets the default NumberFormatInfo that is culture-independent
+ * (invariant).
+ * @return NumberFormatInfo default NumberFormatInfo.
+ */
+ public static function getInvariantInfo($type=NumberFormatInfo::DECIMAL)
+ {
+ static $invariant;
+ if($invariant === null)
+ {
+ $culture = CultureInfo::getInvariantCulture();
+ $invariant = $culture->NumberFormat;
+ $invariant->setPattern($type);
+ }
+ return $invariant;
+ }
+
+ /**
+ * Returns the NumberFormatInfo associated with the specified culture.
+ * @param CultureInfo the culture that gets the NumberFormat property.
+ * @param int the number formatting type, it should be
+ * NumberFormatInfo::DECIMAL, NumberFormatInfo::CURRENCY,
+ * NumberFormatInfo::PERCENTAGE, or NumberFormatInfo::SCIENTIFIC
+ * @return NumberFormatInfo NumberFormatInfo for the specified
+ * culture.
+ * @see getCurrencyInstance();
+ * @see getPercentageInstance();
+ * @see getScientificInstance();
+ */
+ public static function getInstance($culture=null,
+ $type=NumberFormatInfo::DECIMAL)
+ {
+ if ($culture instanceof CultureInfo)
+ {
+ $formatInfo = $culture->NumberFormat;
+ $formatInfo->setPattern($type);
+ return $formatInfo;
+ }
+ else if(is_string($culture))
+ {
+ $cultureInfo = new CultureInfo($culture);
+ $formatInfo = $cultureInfo->NumberFormat;
+ $formatInfo->setPattern($type);
+ return $formatInfo;
+ }
+ else
+ {
+ $cultureInfo = new CultureInfo();
+ $formatInfo = $cultureInfo->NumberFormat;
+ $formatInfo->setPattern($type);
+ return $formatInfo;
+ }
+ }
+
+ /**
+ * Returns the currency format info associated with the specified culture.
+ * @param CultureInfo the culture that gets the NumberFormat property.
+ * @return NumberFormatInfo NumberFormatInfo for the specified
+ * culture.
+ */
+ public static function getCurrencyInstance($culture=null)
+ {
+ return self::getInstance($culture, self::CURRENCY);
+ }
+
+ /**
+ * Returns the percentage format info associated with the specified culture.
+ * @param CultureInfo the culture that gets the NumberFormat property.
+ * @return NumberFormatInfo NumberFormatInfo for the specified
+ * culture.
+ */
+ public static function getPercentageInstance($culture=null)
+ {
+ return self::getInstance($culture, self::PERCENTAGE);
+ }
+
+ /**
+ * Returns the scientific format info associated with the specified culture.
+ * @param CultureInfo the culture that gets the NumberFormat property.
+ * @return NumberFormatInfo NumberFormatInfo for the specified
+ * culture.
+ */
+ public static function getScientificInstance($culture=null)
+ {
+ return self::getInstance($culture, self::SCIENTIFIC);
+ }
+
+ /**
+ * Parse the given pattern and return a list of known properties.
+ * @param string a number pattern.
+ * @return array list of pattern properties.
+ */
+ protected function parsePattern($pattern)
+ {
+ $pattern = explode(';',$pattern);
+
+ $negative = null;
+ if(count($pattern) > 1)
+ $negative = $pattern[1];
+ $pattern = $pattern[0];
+
+ $comma = ',';
+ $dot = '.';
+ $digit = '0';
+ $hash = '#';
+
+ //find the first group point, and decimal point
+ $groupPos1 = strrpos($pattern,$comma);
+ $decimalPos = strrpos($pattern,$dot);
+
+ $groupPos2 = false;
+ $groupSize1 = false;
+ $groupSize2 = false;
+ $decimalPoints = is_int($decimalPos)?-1:false;
+
+ $info['negPref'] = $this->data['NumberElements'][6];
+ $info['negPost'] = '';
+
+ $info['negative'] = $negative;
+ $info['positive'] = $pattern;
+
+ //find the negative prefix and postfix
+ if($negative)
+ {
+ $prefixPostfix = $this->getPrePostfix($negative);
+ $info['negPref'] = $prefixPostfix[0];
+ $info['negPost'] = $prefixPostfix[1];
+ }
+
+ $posfix = $this->getPrePostfix($pattern);
+ $info['posPref'] = $posfix[0];
+ $info['posPost'] = $posfix[1];
+
+ //var_dump($pattern);
+ //var_dump($decimalPos);
+ if(is_int($groupPos1))
+ {
+ //get the second group
+ $groupPos2 = strrpos(substr($pattern,0,$groupPos1),$comma);
+
+ //get the number of decimal digits
+ if(is_int($decimalPos))
+ {
+ $groupSize1 = $decimalPos - $groupPos1-1;
+
+ }
+ else
+ {
+ //no decimal point, so traverse from the back
+ //to find the groupsize 1.
+ for($i=strlen($pattern)-1; $i>=0; $i--)
+ {
+ if($pattern{$i} == $digit || $pattern{$i}==$hash)
+ {
+ $groupSize1 = $i - $groupPos1;
+ break;
+ }
+ }
+ }
+
+ //get the second group size
+ if(is_int($groupPos2))
+ $groupSize2 = $groupPos1 - $groupPos2-1;
+ }
+
+ if(is_int($decimalPos))
+ {
+ for($i=strlen($pattern)-1; $i>=0; $i--)
+ {
+ if($pattern{$i} == $dot) break;
+ if($pattern{$i} == $digit)
+ {
+ $decimalPoints = $i - $decimalPos;
+ break;
+ }
+ }
+ }
+
+ if(is_int($decimalPos))
+ $digitPattern = substr($pattern,0,$decimalPos);
+ else
+ $digitPattern = $pattern;
+
+ $digitPattern = preg_replace('/[^0]/','',$digitPattern);
+
+ $info['groupPos1'] = $groupPos1;
+ $info['groupSize1'] = $groupSize1;
+ $info['groupPos2'] = $groupPos2;
+ $info['groupSize2'] = $groupSize2;
+ $info['decimalPos'] = $decimalPos;
+ $info['decimalPoints'] = $decimalPoints;
+ $info['digitSize'] = strlen($digitPattern);
+ return $info;
+ }
+
+ /**
+ * Get the prefix and postfix of a pattern.
+ * @param string pattern
+ * @return array of prefix and postfix, array(prefix,postfix).
+ */
+ protected function getPrePostfix($pattern)
+ {
+ $regexp = '/[#,\.0]+/';
+ $result = preg_split($regexp, $pattern);
+ return array($result[0],$result[1]);
+ }
+
+
+ /**
+ * Indicates the number of decimal places.
+ * @return int number of decimal places.
+ */
+ function getDecimalDigits()
+ {
+ return $this->pattern['decimalPoints'];
+ }
+
+ /**
+ * Set the number of decimal places.
+ * @param int number of decimal places.
+ */
+ function setDecimalDigits($value)
+ {
+ return $this->pattern['decimalPoints'] = $value;
+ }
+
+ function getDigitSize()
+ {
+ return $this->pattern['digitSize'];
+ }
+
+ function setDigitSize($value)
+ {
+ $this->pattern['digitSize'] = $value;
+ }
+
+ /**
+ * Gets the string to use as the decimal separator.
+ * @return string decimal separator.
+ */
+ function getDecimalSeparator()
+ {
+ return $this->data['NumberElements'][0];
+ }
+
+ /**
+ * Set the string to use as the decimal separator.
+ * @param string the decimal point
+ */
+ function setDecimalSeparator($value)
+ {
+ return $this->data['NumberElements'][0] = $value;
+ }
+
+ /**
+ * Gets the string that separates groups of digits to the left
+ * of the decimal in currency values.
+ * @param parameter
+ * @return string currency group separator.
+ */
+ function getGroupSeparator()
+ {
+ return $this->data['NumberElements'][1];
+ }
+
+ /**
+ * Set the string to use as the group separator.
+ * @param string the group separator.
+ */
+ function setGroupSeparator($value)
+ {
+ return $this->data['NumberElements'][1] = $value;
+ }
+
+ /**
+ * Gets the number of digits in each group to the left of the decimal
+ * There can be two grouping sizes, this fucntion
+ * returns <b>array(group1, group2)</b>, if there is only 1 grouping size,
+ * group2 will be false.
+ * @return array grouping size(s).
+ */
+ function getGroupSizes()
+ {
+ $group1 = $this->pattern['groupSize1'];
+ $group2 = $this->pattern['groupSize2'];
+
+ return array($group1, $group2);
+ }
+
+ /**
+ * Set the number of digits in each group to the left of the decimal.
+ * There can be two grouping sizes, the value should
+ * be an <b>array(group1, group2)</b>, if there is only 1 grouping size,
+ * group2 should be false.
+ * @param array grouping size(s).
+ */
+ function setGroupSizes($groupSize)
+ {
+ $this->pattern['groupSize1'] = $groupSize[0];
+ $this->pattern['groupSize2'] = $groupSize[1];
+ }
+
+ /**
+ * Gets the format pattern for negative values.
+ * The negative pattern is composed of a prefix, and postfix.
+ * This function returns <b>array(prefix, postfix)</b>.
+ * @return arary negative pattern.
+ */
+ function getNegativePattern()
+ {
+ $prefix = $this->pattern['negPref'];
+ $postfix = $this->pattern['negPost'];
+ return array($prefix, $postfix);
+ }
+
+ /**
+ * Set the format pattern for negative values.
+ * The negative pattern is composed of a prefix, and postfix in the form
+ * <b>array(prefix, postfix)</b>.
+ * @param arary negative pattern.
+ */
+ function setNegativePattern($pattern)
+ {
+ $this->pattern['negPref'] = $pattern[0];
+ $this->pattern['negPost'] = $pattern[1];
+ }
+
+ /**
+ * Gets the format pattern for positive values.
+ * The positive pattern is composed of a prefix, and postfix.
+ * This function returns <b>array(prefix, postfix)</b>.
+ * @return arary positive pattern.
+ */
+ function getPositivePattern()
+ {
+ $prefix = $this->pattern['posPref'];
+ $postfix = $this->pattern['posPost'];
+ return array($prefix, $postfix);
+ }
+
+ /**
+ * Set the format pattern for positive values.
+ * The positive pattern is composed of a prefix, and postfix in the form
+ * <b>array(prefix, postfix)</b>.
+ * @param arary positive pattern.
+ */
+ function setPositivePattern($pattern)
+ {
+ $this->pattern['posPref'] = $pattern[0];
+ $this->pattern['posPost'] = $pattern[1];
+ }
+
+ /**
+ * Gets the string to use as the currency symbol.
+ * @return string currency symbol.
+ */
+ function getCurrencySymbol($currency='USD')
+ {
+ if(isset($this->pattern['symbol']))
+ return $this->pattern['symbol'];
+ else
+ return $this->data['Currencies'][$currency][0];
+ }
+
+
+ /**
+ * Set the string to use as the currency symbol.
+ * @param string currency symbol.
+ */
+ function setCurrencySymbol($symbol)
+ {
+ $this->pattern['symbol'] = $symbol;
+ }
+
+ /**
+ * Gets the string that represents negative infinity.
+ * @return string negative infinity.
+ */
+ function getNegativeInfinitySymbol()
+ {
+ return $this->pattern['negInfty'];
+ }
+
+ /**
+ * Set the string that represents negative infinity.
+ * @param string negative infinity.
+ */
+ function setNegativeInfinitySymbol($value)
+ {
+ $this->pattern['negInfty'] = $value;
+ }
+
+ /**
+ * Gets the string that represents positive infinity.
+ * @return string positive infinity.
+ */
+ function getPositiveInfinitySymbol()
+ {
+ return $this->pattern['posInfty'];
+ }
+
+ /**
+ * Set the string that represents positive infinity.
+ * @param string positive infinity.
+ */
+ function setPositiveInfinitySymbol($value)
+ {
+ $this->pattern['posInfty'] = $value;
+ }
+
+ /**
+ * Gets the string that denotes that the associated number is negative.
+ * @return string negative sign.
+ */
+ function getNegativeSign()
+ {
+ return $this->data['NumberElements'][6];
+ }
+
+ /**
+ * Set the string that denotes that the associated number is negative.
+ * @param string negative sign.
+ */
+ function setNegativeSign($value)
+ {
+ $this->data['NumberElements'][6] = $value;
+ }
+
+ /**
+ * Gets the string that denotes that the associated number is positive.
+ * @return string positive sign.
+ */
+ function getPositiveSign()
+ {
+ return $this->data['NumberElements'][11];
+ }
+
+ /**
+ * Set the string that denotes that the associated number is positive.
+ * @param string positive sign.
+ */
+ function setPositiveSign($value)
+ {
+ $this->data['NumberElements'][11] = $value;
+ }
+
+ /**
+ * Gets the string that represents the IEEE NaN (not a number) value.
+ * @return string NaN symbol.
+ */
+ function getNaNSymbol()
+ {
+ return $this->data['NumberElements'][10];
+ }
+
+ /**
+ * Set the string that represents the IEEE NaN (not a number) value.
+ * @param string NaN symbol.
+ */
+ function setNaNSymbol($value)
+ {
+ $this->data['NumberElements'][10] = $value;
+ }
+
+ /**
+ * Gets the string to use as the percent symbol.
+ * @return string percent symbol.
+ */
+ function getPercentSymbol()
+ {
+ return $this->data['NumberElements'][3];
+ }
+
+ /**
+ * Set the string to use as the percent symbol.
+ * @param string percent symbol.
+ */
+ function setPercentSymbol($value)
+ {
+ $this->data['NumberElements'][3] = $value;
+ }
+
+ /**
+ * Gets the string to use as the per mille symbol.
+ * @return string percent symbol.
+ */
+ function getPerMilleSymbol()
+ {
+ return $this->data['NumberElements'][8];
+ }
+
+ /**
+ * Set the string to use as the per mille symbol.
+ * @param string percent symbol.
+ */
+ function setPerMilleSymbol($value)
+ {
+ $this->data['NumberElements'][8] = $value;
+ }
+}
+
diff --git a/framework/I18N/core/TCache_Lite.php b/framework/I18N/core/TCache_Lite.php
index 6ef78852..665ca469 100644
--- a/framework/I18N/core/TCache_Lite.php
+++ b/framework/I18N/core/TCache_Lite.php
@@ -1,629 +1,629 @@
-<?php
-
-/**
- * TCache_Lite class file.
- *
- * This program is free software; you can redistribute it and/or modify
- * it under the terms of the BSD License.
- *
- * Copyright(c) 2004 by Qiang Xue. All rights reserved.
- *
- * To contact the author write to {@link mailto:qiang.xue@gmail.com Qiang Xue}
- * The latest version of PRADO can be obtained from:
- * {@link http://prado.sourceforge.net/}
- *
- * @author Wei Zhuo <weizhuo[at]gmail[dot]com>
- * @version $Revision: 1.3 $ $Date: 2005/10/09 10:24:12 $
- * @package System.I18N.core
- */
-
-/**
-* Fast, light and safe Cache Class
-*
-* TCache_Lite is a fast, light and safe cache system. It's optimized
-* for file containers. It is fast and safe (because it uses file
-* locking and/or anti-corruption tests).
-*
-* There are some examples in the 'docs/examples' file
-* Technical choices are described in the 'docs/technical' file
-*
-* A tutorial is available in english at this url :
-* http://www.pearfr.org/index.php/en/article/cache_lite
-* (big thanks to Pierre-Alain Joye for the translation)
-*
-* The same tutorial is also available in french at this url :
-* http://www.pearfr.org/index.php/fr/article/cache_lite
-*
-* Memory Caching is from an original idea of
-* Mike BENOIT <ipso@snappymail.ca>
-*
-* @package System.I18N.core
-* @version $Id$
-* @author Fabien MARTY <fab@php.net>
-* @copyright 1997-2005 The PHP Group
-* @license http://www.gnu.org/copyleft/lesser.html GNU LGPL
-* @link http://pear.php.net/package/Cache_Lite
-*/
-class TCache_Lite
-{
-
- // --- Private properties ---
-
- /**
- * Directory where to put the cache files
- * (make sure to add a trailing slash)
- *
- * @var string $_cacheDir
- */
- protected $_cacheDir = '/tmp/';
-
- /**
- * Enable / disable caching
- *
- * (can be very usefull for the debug of cached scripts)
- *
- * @var boolean $_caching
- */
- protected $_caching = true;
-
- /**
- * Cache lifetime (in seconds)
- *
- * @var int $_lifeTime
- */
- protected $_lifeTime = 3600;
-
- /**
- * Enable / disable fileLocking
- *
- * (can avoid cache corruption under bad circumstances)
- *
- * @var boolean $_fileLocking
- */
- protected $_fileLocking = true;
-
- /**
- * Timestamp of the last valid cache
- *
- * @var int $_refreshTime
- */
- protected $_refreshTime;
-
- /**
- * File name (with path)
- *
- * @var string $_file
- */
- protected $_file;
-
- /**
- * Enable / disable write control (the cache is read just after writing
- * to detect corrupt entries)
- *
- * Enable write control will lightly slow the cache writing but not the
- * cache reading. Write control can detect some corrupt cache files but
- * maybe it's not a perfect control
- *
- * @var boolean $_writeControl
- */
- protected $_writeControl = true;
-
- /**
- * Enable / disable read control
- *
- * If enabled, a control key is embeded in cache file and this key is
- * compared with the one calculated after the reading.
- *
- * @var boolean $_writeControl
- */
- protected $_readControl = true;
-
- /**
- * Type of read control (only if read control is enabled)
- *
- * Available values are :
- * 'md5' for a md5 hash control (best but slowest)
- * 'crc32' for a crc32 hash control (lightly less safe but faster,
- * better choice)
- * 'strlen' for a length only test (fastest)
- *
- * @var boolean $_readControlType
- */
- protected $_readControlType = 'crc32';
-
- /**
- * Current cache id
- *
- * @var string $_id
- */
- protected $_id;
-
- /**
- * Current cache group
- *
- * @var string $_group
- */
- protected $_group;
-
- /**
- * Enable / Disable "Memory Caching"
- *
- * NB : There is no lifetime for memory caching !
- *
- * @var boolean $_memoryCaching
- */
- protected $_memoryCaching = false;
-
- /**
- * Enable / Disable "Only Memory Caching"
- * (be carefull, memory caching is "beta quality")
- *
- * @var boolean $_onlyMemoryCaching
- */
- protected $_onlyMemoryCaching = false;
-
- /**
- * Memory caching array
- *
- * @var array $_memoryCachingArray
- */
- protected $_memoryCachingArray = array();
-
- /**
- * Memory caching counter
- *
- * @var int $memoryCachingCounter
- */
- protected $_memoryCachingCounter = 0;
-
- /**
- * Memory caching limit
- *
- * @var int $memoryCachingLimit
- */
- protected $_memoryCachingLimit = 1000;
-
- /**
- * File Name protection
- *
- * if set to true, you can use any cache id or group name
- * if set to false, it can be faster but cache ids and group names
- * will be used directly in cache file names so be carefull with
- * special characters...
- *
- * @var boolean $fileNameProtection
- */
- protected $_fileNameProtection = true;
-
- /**
- * Enable / disable automatic serialization
- *
- * it can be used to save directly datas which aren't strings
- * (but it's slower)
- *
- * @var boolean $_serialize
- */
- protected $_automaticSerialization = false;
-
- // --- Public methods ---
-
- /**
- * Constructor
- *
- * $options is an assoc. Available options are :
- * $options = array(
- * 'cacheDir' => directory where to put the cache files (string),
- * 'caching' => enable / disable caching (boolean),
- * 'lifeTime' => cache lifetime in seconds (int),
- * 'fileLocking' => enable / disable fileLocking (boolean),
- * 'writeControl' => enable / disable write control (boolean),
- * 'readControl' => enable / disable read control (boolean),
- * 'readControlType' => type of read control 'crc32', 'md5', 'strlen',
- * 'memoryCaching' => enable / disable memory caching (boolean),
- * 'onlyMemoryCaching' => enable / disable only memory caching (boolean),
- * 'memoryCachingLimit' => max nbr of records in memory caching (int),
- * 'fileNameProtection' => enable / disable file name protection (boolean),
- * 'automaticSerialization' => enable / disable serialization (boolean)
- * );
- *
- * @param array $options options
- * @access public
- */
- function TCache_Lite($options = array(null))
- {
- $availableOptions = array( 'automaticSerialization',
- 'fileNameProtection',
- 'memoryCaching',
- 'onlyMemoryCaching',
- 'memoryCachingLimit',
- 'cacheDir',
- 'caching',
- 'lifeTime',
- 'fileLocking',
- 'writeControl',
- 'readControl',
- 'readControlType');
- foreach($options as $key => $value) {
- if(in_array($key, $availableOptions)) {
- $property = '_'.$key;
- $this->$property = $value;
- }
- }
- $this->_refreshTime = time() - $this->_lifeTime;
- }
-
- /**
- * Test if a cache is available and (if yes) return it
- *
- * @param string $id cache id
- * @param string $group name of the cache group
- * @param boolean $doNotTestCacheValidity if set to true, the cache
- * validity won't be tested
- * @return string data of the cache (or false if no cache available)
- * @access public
- */
- function get($id, $group = 'default', $doNotTestCacheValidity = false)
- {
- $this->_id = $id;
- $this->_group = $group;
- $data = false;
- if ($this->_caching) {
- $this->_setFileName($id, $group);
- if ($this->_memoryCaching) {
- if (isset($this->_memoryCachingArray[$this->_file])) {
- if ($this->_automaticSerialization) {
- return unserialize(
- $this->_memoryCachingArray[$this->_file]);
- } else {
- return $this->_memoryCachingArray[$this->_file];
- }
- } else {
- if ($this->_onlyMemoryCaching) {
- return false;
- }
- }
- }
- if ($doNotTestCacheValidity) {
- if (file_exists($this->_file)) {
- $data = $this->_read();
- }
- } else {
- if (@filemtime($this->_file) > $this->_refreshTime) {
- $data = $this->_read();
- }
- }
- if (($data) and ($this->_memoryCaching)) {
- $this->_memoryCacheAdd($this->_file, $data);
- }
- if ($this->_automaticSerialization && is_string($data)) {
- $data = unserialize($data);
- }
- return $data;
- }
- return false;
- }
-
- /**
- * Save some data in a cache file
- *
- * @param string $data data to put in cache (can be another type than strings
- * if automaticSerialization is on)
- * @param string $id cache id
- * @param string $group name of the cache group
- * @return boolean true if no problem
- * @access public
- */
- function save($data, $id = null, $group = 'default')
- {
- if ($this->_caching) {
- if ($this->_automaticSerialization) {
- $data = serialize($data);
- }
- if (isset($id)) {
- $this->_setFileName($id, $group);
- }
- if ($this->_memoryCaching) {
- $this->_memoryCacheAdd($this->_file, $data);
- if ($this->_onlyMemoryCaching) {
- return true;
- }
- }
- if ($this->_writeControl) {
- if (!$this->_writeAndControl($data)) {
- @touch($this->_file, time() - 2*abs($this->_lifeTime));
- return false;
- } else {
- return true;
- }
- } else {
- return $this->_write($data);
- }
- }
- return false;
- }
-
- /**
- * Remove a cache file
- *
- * @param string $id cache id
- * @param string $group name of the cache group
- * @return boolean true if no problem
- * @access public
- */
- function remove($id, $group = 'default')
- {
- $this->_setFileName($id, $group);
- if (!@unlink($this->_file)) {
- $this->raiseError('TCache_Lite : Unable to remove cache !', -3);
- return false;
- }
- return true;
- }
-
- /**
- * Clean the cache
- *
- * if no group is specified all cache files will be destroyed
- * else only cache files of the specified group will be destroyed
- *
- * @param string $group name of the cache group
- * @return boolean true if no problem
- * @access public
- */
- function clean($group = false)
- {
- if ($this->_fileNameProtection) {
- $motif = ($group) ? 'cache_'.md5($group).'_' : 'cache_';
- } else {
- $motif = ($group) ? 'cache_'.$group.'_' : 'cache_';
- }
- if ($this->_memoryCaching) {
- while (list($key, $value) = each($this->_memoryCaching)) {
- if (strpos($key, $motif, 0)) {
- unset($this->_memoryCaching[$key]);
- $this->_memoryCachingCounter =
- $this->_memoryCachingCounter - 1;
- }
- }
- if ($this->_onlyMemoryCaching) {
- return true;
- }
- }
- if (!($dh = opendir($this->_cacheDir))) {
- $this->raiseError('TCache_Lite : Unable to open cache directory !');
- return false;
- }
- while ($file = readdir($dh)) {
- if (($file != '.') && ($file != '..')) {
- $file = $this->_cacheDir . $file;
- if (is_file($file)) {
- if (strpos($file, $motif, 0)) {
- if (!@unlink($file)) {
- $this->raiseError('Cache_Lite : Unable to remove cache !', -3);
- return false;
- }
- }
- }
- }
- }
- return true;
- }
-
- /**
- * Set a new life time
- *
- * @param int $newLifeTime new life time (in seconds)
- * @access public
- */
- function setLifeTime($newLifeTime)
- {
- $this->_lifeTime = $newLifeTime;
- $this->_refreshTime = time() - $newLifeTime;
- }
-
- /**
- *
- * @access public
- */
- function saveMemoryCachingState($id, $group = 'default')
- {
- if ($this->_caching) {
- $array = array(
- 'counter' => $this->_memoryCachingCounter,
- 'array' => $this->_memoryCachingState
- );
- $data = serialize($array);
- $this->save($data, $id, $group);
- }
- }
-
- /**
- *
- * @access public
- */
- function getMemoryCachingState($id, $group = 'default',
- $doNotTestCacheValidity = false)
- {
- if ($this->_caching) {
- if ($data = $this->get($id, $group, $doNotTestCacheValidity))
- {
- $array = unserialize($data);
- $this->_memoryCachingCounter = $array['counter'];
- $this->_memoryCachingArray = $array['array'];
- }
- }
- }
-
- /**
- * Return the cache last modification time
- *
- * BE CAREFUL : THIS METHOD IS FOR HACKING ONLY !
- *
- * @return int last modification time
- */
- function lastModified() {
- return filemtime($this->cache->_file);
- }
-
- /**
- * Trigger a PEAR error
- *
- * To improve performances, the PEAR.php file is included dynamically.
- * The file is so included only when an error is triggered. So, in most
- * cases, the file isn't included and perfs are much better.
- *
- * @param string $msg error message
- * @param int $code error code
- * @access public
- */
- function raiseError($msg, $code)
- {
- throw new Exception($msg);
- }
-
- // --- Private methods ---
-
- /**
- *
- * @access private
- */
- function _memoryCacheAdd($id, $data)
- {
- $this->_memoryCachingArray[$this->_file] = $data;
- if ($this->_memoryCachingCounter >= $this->_memoryCachingLimit) {
- list($key, $value) = each($this->_memoryCachingArray);
- unset($this->_memoryCachingArray[$key]);
- } else {
- $this->_memoryCachingCounter = $this->_memoryCachingCounter + 1;
- }
- }
-
- /**
- * Make a file name (with path)
- *
- * @param string $id cache id
- * @param string $group name of the group
- * @access private
- */
- function _setFileName($id, $group)
- {
- if ($this->_fileNameProtection) {
- $this->_file = ($this->_cacheDir.'cache_'.md5($group).'_'
- .md5($id));
- } else {
- $this->_file = $this->_cacheDir.'cache_'.$group.'_'.$id;
- }
- }
-
- function getCacheFile()
- {
- return $this->_file;
- }
-
- /**
- * Read the cache file and return the content
- *
- * @return string content of the cache file
- * @access private
- */
- function _read()
- {
- $fp = @fopen($this->_file, "rb");
- if ($this->_fileLocking) @flock($fp, LOCK_SH);
- if ($fp) {
- // because the filesize can be cached by PHP itself...
- clearstatcache();
- $length = @filesize($this->_file);
- if(version_compare(PHP_VERSION, '5.3.0', 'lt'))
- {
- $mqr = get_magic_quotes_runtime();
- set_magic_quotes_runtime(0);
- }
- if ($this->_readControl) {
- $hashControl = @fread($fp, 32);
- $length = $length - 32;
- }
- $data = @fread($fp, $length);
- if(isset($mqr))
- set_magic_quotes_runtime($mqr);
- if ($this->_fileLocking) @flock($fp, LOCK_UN);
- @fclose($fp);
- if ($this->_readControl) {
- $hashData = $this->_hash($data, $this->_readControlType);
- if ($hashData != $hashControl) {
- @touch($this->_file, time() - 2*abs($this->_lifeTime));
- return false;
- }
- }
- return $data;
- }
- $this->raiseError('Cache_Lite : Unable to read cache !', -2);
- return false;
- }
-
- /**
- * Write the given data in the cache file
- *
- * @param string $data data to put in cache
- * @return boolean true if ok
- * @access private
- */
- function _write($data)
- {
- $fp = @fopen($this->_file, "wb");
- if ($fp) {
- if ($this->_fileLocking) @flock($fp, LOCK_EX);
- if ($this->_readControl) {
- @fwrite($fp, $this->_hash($data, $this->_readControlType), 32);
- }
- $len = strlen($data);
- @fwrite($fp, $data, $len);
- if ($this->_fileLocking) @flock($fp, LOCK_UN);
- @fclose($fp);
- return true;
- }
- $this->raiseError('Cache_Lite : Unable to write cache !', -1);
- return false;
- }
-
- /**
- * Write the given data in the cache file and control it just after to avoid
- * corrupted cache entries
- *
- * @param string $data data to put in cache
- * @return boolean true if the test is ok
- * @access private
- */
- function _writeAndControl($data)
- {
- $this->_write($data);
- $dataRead = $this->_read($data);
- return ($dataRead==$data);
- }
-
- /**
- * Make a control key with the string containing datas
- *
- * @param string $data data
- * @param string $controlType type of control 'md5', 'crc32' or 'strlen'
- * @return string control key
- * @access private
- */
- function _hash($data, $controlType)
- {
- switch ($controlType) {
- case 'md5':
- return md5($data);
- case 'crc32':
- return sprintf('% 32d', crc32($data));
- case 'strlen':
- return sprintf('% 32d', strlen($data));
- default:
- $this->raiseError('Unknown controlType ! '.
- '(available values are only \'md5\', \'crc32\', \'strlen\')', -5);
- }
- }
-
-}
-
-?>
+<?php
+
+/**
+ * TCache_Lite class file.
+ *
+ * This program is free software; you can redistribute it and/or modify
+ * it under the terms of the BSD License.
+ *
+ * Copyright(c) 2004 by Qiang Xue. All rights reserved.
+ *
+ * To contact the author write to {@link mailto:qiang.xue@gmail.com Qiang Xue}
+ * The latest version of PRADO can be obtained from:
+ * {@link http://prado.sourceforge.net/}
+ *
+ * @author Wei Zhuo <weizhuo[at]gmail[dot]com>
+ * @version $Revision: 1.3 $ $Date: 2005/10/09 10:24:12 $
+ * @package System.I18N.core
+ */
+
+/**
+* Fast, light and safe Cache Class
+*
+* TCache_Lite is a fast, light and safe cache system. It's optimized
+* for file containers. It is fast and safe (because it uses file
+* locking and/or anti-corruption tests).
+*
+* There are some examples in the 'docs/examples' file
+* Technical choices are described in the 'docs/technical' file
+*
+* A tutorial is available in english at this url :
+* http://www.pearfr.org/index.php/en/article/cache_lite
+* (big thanks to Pierre-Alain Joye for the translation)
+*
+* The same tutorial is also available in french at this url :
+* http://www.pearfr.org/index.php/fr/article/cache_lite
+*
+* Memory Caching is from an original idea of
+* Mike BENOIT <ipso@snappymail.ca>
+*
+* @package System.I18N.core
+* @version $Id$
+* @author Fabien MARTY <fab@php.net>
+* @copyright 1997-2005 The PHP Group
+* @license http://www.gnu.org/copyleft/lesser.html GNU LGPL
+* @link http://pear.php.net/package/Cache_Lite
+*/
+class TCache_Lite
+{
+
+ // --- Private properties ---
+
+ /**
+ * Directory where to put the cache files
+ * (make sure to add a trailing slash)
+ *
+ * @var string $_cacheDir
+ */
+ protected $_cacheDir = '/tmp/';
+
+ /**
+ * Enable / disable caching
+ *
+ * (can be very usefull for the debug of cached scripts)
+ *
+ * @var boolean $_caching
+ */
+ protected $_caching = true;
+
+ /**
+ * Cache lifetime (in seconds)
+ *
+ * @var int $_lifeTime
+ */
+ protected $_lifeTime = 3600;
+
+ /**
+ * Enable / disable fileLocking
+ *
+ * (can avoid cache corruption under bad circumstances)
+ *
+ * @var boolean $_fileLocking
+ */
+ protected $_fileLocking = true;
+
+ /**
+ * Timestamp of the last valid cache
+ *
+ * @var int $_refreshTime
+ */
+ protected $_refreshTime;
+
+ /**
+ * File name (with path)
+ *
+ * @var string $_file
+ */
+ protected $_file;
+
+ /**
+ * Enable / disable write control (the cache is read just after writing
+ * to detect corrupt entries)
+ *
+ * Enable write control will lightly slow the cache writing but not the
+ * cache reading. Write control can detect some corrupt cache files but
+ * maybe it's not a perfect control
+ *
+ * @var boolean $_writeControl
+ */
+ protected $_writeControl = true;
+
+ /**
+ * Enable / disable read control
+ *
+ * If enabled, a control key is embeded in cache file and this key is
+ * compared with the one calculated after the reading.
+ *
+ * @var boolean $_writeControl
+ */
+ protected $_readControl = true;
+
+ /**
+ * Type of read control (only if read control is enabled)
+ *
+ * Available values are :
+ * 'md5' for a md5 hash control (best but slowest)
+ * 'crc32' for a crc32 hash control (lightly less safe but faster,
+ * better choice)
+ * 'strlen' for a length only test (fastest)
+ *
+ * @var boolean $_readControlType
+ */
+ protected $_readControlType = 'crc32';
+
+ /**
+ * Current cache id
+ *
+ * @var string $_id
+ */
+ protected $_id;
+
+ /**
+ * Current cache group
+ *
+ * @var string $_group
+ */
+ protected $_group;
+
+ /**
+ * Enable / Disable "Memory Caching"
+ *
+ * NB : There is no lifetime for memory caching !
+ *
+ * @var boolean $_memoryCaching
+ */
+ protected $_memoryCaching = false;
+
+ /**
+ * Enable / Disable "Only Memory Caching"
+ * (be carefull, memory caching is "beta quality")
+ *
+ * @var boolean $_onlyMemoryCaching
+ */
+ protected $_onlyMemoryCaching = false;
+
+ /**
+ * Memory caching array
+ *
+ * @var array $_memoryCachingArray
+ */
+ protected $_memoryCachingArray = array();
+
+ /**
+ * Memory caching counter
+ *
+ * @var int $memoryCachingCounter
+ */
+ protected $_memoryCachingCounter = 0;
+
+ /**
+ * Memory caching limit
+ *
+ * @var int $memoryCachingLimit
+ */
+ protected $_memoryCachingLimit = 1000;
+
+ /**
+ * File Name protection
+ *
+ * if set to true, you can use any cache id or group name
+ * if set to false, it can be faster but cache ids and group names
+ * will be used directly in cache file names so be carefull with
+ * special characters...
+ *
+ * @var boolean $fileNameProtection
+ */
+ protected $_fileNameProtection = true;
+
+ /**
+ * Enable / disable automatic serialization
+ *
+ * it can be used to save directly datas which aren't strings
+ * (but it's slower)
+ *
+ * @var boolean $_serialize
+ */
+ protected $_automaticSerialization = false;
+
+ // --- Public methods ---
+
+ /**
+ * Constructor
+ *
+ * $options is an assoc. Available options are :
+ * $options = array(
+ * 'cacheDir' => directory where to put the cache files (string),
+ * 'caching' => enable / disable caching (boolean),
+ * 'lifeTime' => cache lifetime in seconds (int),
+ * 'fileLocking' => enable / disable fileLocking (boolean),
+ * 'writeControl' => enable / disable write control (boolean),
+ * 'readControl' => enable / disable read control (boolean),
+ * 'readControlType' => type of read control 'crc32', 'md5', 'strlen',
+ * 'memoryCaching' => enable / disable memory caching (boolean),
+ * 'onlyMemoryCaching' => enable / disable only memory caching (boolean),
+ * 'memoryCachingLimit' => max nbr of records in memory caching (int),
+ * 'fileNameProtection' => enable / disable file name protection (boolean),
+ * 'automaticSerialization' => enable / disable serialization (boolean)
+ * );
+ *
+ * @param array $options options
+ * @access public
+ */
+ function TCache_Lite($options = array(null))
+ {
+ $availableOptions = array( 'automaticSerialization',
+ 'fileNameProtection',
+ 'memoryCaching',
+ 'onlyMemoryCaching',
+ 'memoryCachingLimit',
+ 'cacheDir',
+ 'caching',
+ 'lifeTime',
+ 'fileLocking',
+ 'writeControl',
+ 'readControl',
+ 'readControlType');
+ foreach($options as $key => $value) {
+ if(in_array($key, $availableOptions)) {
+ $property = '_'.$key;
+ $this->$property = $value;
+ }
+ }
+ $this->_refreshTime = time() - $this->_lifeTime;
+ }
+
+ /**
+ * Test if a cache is available and (if yes) return it
+ *
+ * @param string $id cache id
+ * @param string $group name of the cache group
+ * @param boolean $doNotTestCacheValidity if set to true, the cache
+ * validity won't be tested
+ * @return string data of the cache (or false if no cache available)
+ * @access public
+ */
+ function get($id, $group = 'default', $doNotTestCacheValidity = false)
+ {
+ $this->_id = $id;
+ $this->_group = $group;
+ $data = false;
+ if ($this->_caching) {
+ $this->_setFileName($id, $group);
+ if ($this->_memoryCaching) {
+ if (isset($this->_memoryCachingArray[$this->_file])) {
+ if ($this->_automaticSerialization) {
+ return unserialize(
+ $this->_memoryCachingArray[$this->_file]);
+ } else {
+ return $this->_memoryCachingArray[$this->_file];
+ }
+ } else {
+ if ($this->_onlyMemoryCaching) {
+ return false;
+ }
+ }
+ }
+ if ($doNotTestCacheValidity) {
+ if (file_exists($this->_file)) {
+ $data = $this->_read();
+ }
+ } else {
+ if (@filemtime($this->_file) > $this->_refreshTime) {
+ $data = $this->_read();
+ }
+ }
+ if (($data) and ($this->_memoryCaching)) {
+ $this->_memoryCacheAdd($this->_file, $data);
+ }
+ if ($this->_automaticSerialization && is_string($data)) {
+ $data = unserialize($data);
+ }
+ return $data;
+ }
+ return false;
+ }
+
+ /**
+ * Save some data in a cache file
+ *
+ * @param string $data data to put in cache (can be another type than strings
+ * if automaticSerialization is on)
+ * @param string $id cache id
+ * @param string $group name of the cache group
+ * @return boolean true if no problem
+ * @access public
+ */
+ function save($data, $id = null, $group = 'default')
+ {
+ if ($this->_caching) {
+ if ($this->_automaticSerialization) {
+ $data = serialize($data);
+ }
+ if (isset($id)) {
+ $this->_setFileName($id, $group);
+ }
+ if ($this->_memoryCaching) {
+ $this->_memoryCacheAdd($this->_file, $data);
+ if ($this->_onlyMemoryCaching) {
+ return true;
+ }
+ }
+ if ($this->_writeControl) {
+ if (!$this->_writeAndControl($data)) {
+ @touch($this->_file, time() - 2*abs($this->_lifeTime));
+ return false;
+ } else {
+ return true;
+ }
+ } else {
+ return $this->_write($data);
+ }
+ }
+ return false;
+ }
+
+ /**
+ * Remove a cache file
+ *
+ * @param string $id cache id
+ * @param string $group name of the cache group
+ * @return boolean true if no problem
+ * @access public
+ */
+ function remove($id, $group = 'default')
+ {
+ $this->_setFileName($id, $group);
+ if (!@unlink($this->_file)) {
+ $this->raiseError('TCache_Lite : Unable to remove cache !', -3);
+ return false;
+ }
+ return true;
+ }
+
+ /**
+ * Clean the cache
+ *
+ * if no group is specified all cache files will be destroyed
+ * else only cache files of the specified group will be destroyed
+ *
+ * @param string $group name of the cache group
+ * @return boolean true if no problem
+ * @access public
+ */
+ function clean($group = false)
+ {
+ if ($this->_fileNameProtection) {
+ $motif = ($group) ? 'cache_'.md5($group).'_' : 'cache_';
+ } else {
+ $motif = ($group) ? 'cache_'.$group.'_' : 'cache_';
+ }
+ if ($this->_memoryCaching) {
+ while (list($key, $value) = each($this->_memoryCaching)) {
+ if (strpos($key, $motif, 0)) {
+ unset($this->_memoryCaching[$key]);
+ $this->_memoryCachingCounter =
+ $this->_memoryCachingCounter - 1;
+ }
+ }
+ if ($this->_onlyMemoryCaching) {
+ return true;
+ }
+ }
+ if (!($dh = opendir($this->_cacheDir))) {
+ $this->raiseError('TCache_Lite : Unable to open cache directory !');
+ return false;
+ }
+ while ($file = readdir($dh)) {
+ if (($file != '.') && ($file != '..')) {
+ $file = $this->_cacheDir . $file;
+ if (is_file($file)) {
+ if (strpos($file, $motif, 0)) {
+ if (!@unlink($file)) {
+ $this->raiseError('Cache_Lite : Unable to remove cache !', -3);
+ return false;
+ }
+ }
+ }
+ }
+ }
+ return true;
+ }
+
+ /**
+ * Set a new life time
+ *
+ * @param int $newLifeTime new life time (in seconds)
+ * @access public
+ */
+ function setLifeTime($newLifeTime)
+ {
+ $this->_lifeTime = $newLifeTime;
+ $this->_refreshTime = time() - $newLifeTime;
+ }
+
+ /**
+ *
+ * @access public
+ */
+ function saveMemoryCachingState($id, $group = 'default')
+ {
+ if ($this->_caching) {
+ $array = array(
+ 'counter' => $this->_memoryCachingCounter,
+ 'array' => $this->_memoryCachingState
+ );
+ $data = serialize($array);
+ $this->save($data, $id, $group);
+ }
+ }
+
+ /**
+ *
+ * @access public
+ */
+ function getMemoryCachingState($id, $group = 'default',
+ $doNotTestCacheValidity = false)
+ {
+ if ($this->_caching) {
+ if ($data = $this->get($id, $group, $doNotTestCacheValidity))
+ {
+ $array = unserialize($data);
+ $this->_memoryCachingCounter = $array['counter'];
+ $this->_memoryCachingArray = $array['array'];
+ }
+ }
+ }
+
+ /**
+ * Return the cache last modification time
+ *
+ * BE CAREFUL : THIS METHOD IS FOR HACKING ONLY !
+ *
+ * @return int last modification time
+ */
+ function lastModified() {
+ return filemtime($this->cache->_file);
+ }
+
+ /**
+ * Trigger a PEAR error
+ *
+ * To improve performances, the PEAR.php file is included dynamically.
+ * The file is so included only when an error is triggered. So, in most
+ * cases, the file isn't included and perfs are much better.
+ *
+ * @param string $msg error message
+ * @param int $code error code
+ * @access public
+ */
+ function raiseError($msg, $code)
+ {
+ throw new Exception($msg);
+ }
+
+ // --- Private methods ---
+
+ /**
+ *
+ * @access private
+ */
+ function _memoryCacheAdd($id, $data)
+ {
+ $this->_memoryCachingArray[$this->_file] = $data;
+ if ($this->_memoryCachingCounter >= $this->_memoryCachingLimit) {
+ list($key, $value) = each($this->_memoryCachingArray);
+ unset($this->_memoryCachingArray[$key]);
+ } else {
+ $this->_memoryCachingCounter = $this->_memoryCachingCounter + 1;
+ }
+ }
+
+ /**
+ * Make a file name (with path)
+ *
+ * @param string $id cache id
+ * @param string $group name of the group
+ * @access private
+ */
+ function _setFileName($id, $group)
+ {
+ if ($this->_fileNameProtection) {
+ $this->_file = ($this->_cacheDir.'cache_'.md5($group).'_'
+ .md5($id));
+ } else {
+ $this->_file = $this->_cacheDir.'cache_'.$group.'_'.$id;
+ }
+ }
+
+ function getCacheFile()
+ {
+ return $this->_file;
+ }
+
+ /**
+ * Read the cache file and return the content
+ *
+ * @return string content of the cache file
+ * @access private
+ */
+ function _read()
+ {
+ $fp = @fopen($this->_file, "rb");
+ if ($this->_fileLocking) @flock($fp, LOCK_SH);
+ if ($fp) {
+ // because the filesize can be cached by PHP itself...
+ clearstatcache();
+ $length = @filesize($this->_file);
+ if(version_compare(PHP_VERSION, '5.3.0', 'lt'))
+ {
+ $mqr = get_magic_quotes_runtime();
+ set_magic_quotes_runtime(0);
+ }
+ if ($this->_readControl) {
+ $hashControl = @fread($fp, 32);
+ $length = $length - 32;
+ }
+ $data = @fread($fp, $length);
+ if(isset($mqr))
+ set_magic_quotes_runtime($mqr);
+ if ($this->_fileLocking) @flock($fp, LOCK_UN);
+ @fclose($fp);
+ if ($this->_readControl) {
+ $hashData = $this->_hash($data, $this->_readControlType);
+ if ($hashData != $hashControl) {
+ @touch($this->_file, time() - 2*abs($this->_lifeTime));
+ return false;
+ }
+ }
+ return $data;
+ }
+ $this->raiseError('Cache_Lite : Unable to read cache !', -2);
+ return false;
+ }
+
+ /**
+ * Write the given data in the cache file
+ *
+ * @param string $data data to put in cache
+ * @return boolean true if ok
+ * @access private
+ */
+ function _write($data)
+ {
+ $fp = @fopen($this->_file, "wb");
+ if ($fp) {
+ if ($this->_fileLocking) @flock($fp, LOCK_EX);
+ if ($this->_readControl) {
+ @fwrite($fp, $this->_hash($data, $this->_readControlType), 32);
+ }
+ $len = strlen($data);
+ @fwrite($fp, $data, $len);
+ if ($this->_fileLocking) @flock($fp, LOCK_UN);
+ @fclose($fp);
+ return true;
+ }
+ $this->raiseError('Cache_Lite : Unable to write cache !', -1);
+ return false;
+ }
+
+ /**
+ * Write the given data in the cache file and control it just after to avoid
+ * corrupted cache entries
+ *
+ * @param string $data data to put in cache
+ * @return boolean true if the test is ok
+ * @access private
+ */
+ function _writeAndControl($data)
+ {
+ $this->_write($data);
+ $dataRead = $this->_read($data);
+ return ($dataRead==$data);
+ }
+
+ /**
+ * Make a control key with the string containing datas
+ *
+ * @param string $data data
+ * @param string $controlType type of control 'md5', 'crc32' or 'strlen'
+ * @return string control key
+ * @access private
+ */
+ function _hash($data, $controlType)
+ {
+ switch ($controlType) {
+ case 'md5':
+ return md5($data);
+ case 'crc32':
+ return sprintf('% 32d', crc32($data));
+ case 'strlen':
+ return sprintf('% 32d', strlen($data));
+ default:
+ $this->raiseError('Unknown controlType ! '.
+ '(available values are only \'md5\', \'crc32\', \'strlen\')', -5);
+ }
+ }
+
+}
+
+?>
diff --git a/framework/I18N/core/util.php b/framework/I18N/core/util.php
index c0092f19..c618b33a 100644
--- a/framework/I18N/core/util.php
+++ b/framework/I18N/core/util.php
@@ -1,188 +1,188 @@
-<?php
-
-/**
- * I18N Utility file.
- *
- * This program is free software; you can redistribute it and/or modify
- * it under the terms of the BSD License.
- *
- * Copyright(c) 2004 by Wei Zhuo. All rights reserved.
- *
- * To contact the author write to <weizhuo[at]gmail[dot]com>
- * The latest version of PRADO can be obtained from:
- * {@link http://prado.sourceforge.net/}
- *
- * @author Wei Zhuo <weizhuo[at]gmail[dot]com>
- * @version $Revision: 1.3 $ $Date: 2005/08/27 03:21:12 $
- * @package System.I18N.core
- */
-
-
- /**
- * For a given DSN (database connection string), return some information
- * about the DSN. This function comes from PEAR's DB package.
- *
- * LICENSE: This source file is subject to version 3.0 of the PHP license
- * that is available through the world-wide-web at the following URI:
- * http://www.php.net/license/3_0.txt. If you did not receive a copy of
- * the PHP License and are unable to obtain it through the web, please
- * send a note to license@php.net so we can mail you a copy immediately.
- *
- * @param string DSN format, similar to PEAR's DB
- * @return array DSN information.
- * @author Stig Bakken <ssb@php.net>
- * @author Tomas V.V.Cox <cox@idecnet.com>
- * @author Daniel Convissor <danielc@php.net>
- * @copyright 1997-2005 The PHP Group
- * @license http://www.php.net/license/3_0.txt PHP License 3.0
- * @link http://pear.php.net/package/DB
- */
- function parseDSN($dsn)
- {
- if (is_array($dsn)) {
- return $dsn;
- }
-
- $parsed = array(
- 'phptype' => false,
- 'dbsyntax' => false,
- 'username' => false,
- 'password' => false,
- 'protocol' => false,
- 'hostspec' => false,
- 'port' => false,
- 'socket' => false,
- 'database' => false
- );
-
- // Find phptype and dbsyntax
- if (($pos = strpos($dsn, '://')) !== false) {
- $str = substr($dsn, 0, $pos);
- $dsn = substr($dsn, $pos + 3);
- } else {
- $str = $dsn;
- $dsn = null;
- }
-
- // Get phptype and dbsyntax
- // $str => phptype(dbsyntax)
- if (preg_match('|^(.+?)\((.*?)\)$|', $str, $arr)) {
- $parsed['phptype'] = $arr[1];
- $parsed['dbsyntax'] = (empty($arr[2])) ? $arr[1] : $arr[2];
- } else {
- $parsed['phptype'] = $str;
- $parsed['dbsyntax'] = $str;
- }
-
- if (empty($dsn)) {
- return $parsed;
- }
-
- // Get (if found): username and password
- // $dsn => username:password@protocol+hostspec/database
- if (($at = strrpos($dsn,'@')) !== false) {
- $str = substr($dsn, 0, $at);
- $dsn = substr($dsn, $at + 1);
- if (($pos = strpos($str, ':')) !== false) {
- $parsed['username'] = rawurldecode(substr($str, 0, $pos));
- $parsed['password'] = rawurldecode(substr($str, $pos + 1));
- } else {
- $parsed['username'] = rawurldecode($str);
- }
- }
-
- // Find protocol and hostspec
-
- // $dsn => proto(proto_opts)/database
- if (preg_match('|^([^(]+)\((.*?)\)/?(.*?)$|', $dsn, $match)) {
- $proto = $match[1];
- $proto_opts = (!empty($match[2])) ? $match[2] : false;
- $dsn = $match[3];
-
- // $dsn => protocol+hostspec/database (old format)
- } else {
- if (strpos($dsn, '+') !== false) {
- list($proto, $dsn) = explode('+', $dsn, 2);
- }
- if (strpos($dsn, '/') !== false) {
- list($proto_opts, $dsn) = explode('/', $dsn, 2);
- } else {
- $proto_opts = $dsn;
- $dsn = null;
- }
- }
-
- // process the different protocol options
- $parsed['protocol'] = (!empty($proto)) ? $proto : 'tcp';
- $proto_opts = rawurldecode($proto_opts);
- if ($parsed['protocol'] == 'tcp') {
- if (strpos($proto_opts, ':') !== false) {
- list($parsed['hostspec'], $parsed['port']) = explode(':', $proto_opts);
- } else {
- $parsed['hostspec'] = $proto_opts;
- }
- } elseif ($parsed['protocol'] == 'unix') {
- $parsed['socket'] = $proto_opts;
- }
-
- // Get dabase if any
- // $dsn => database
- if (!empty($dsn)) {
- // /database
- if (($pos = strpos($dsn, '?')) === false) {
- $parsed['database'] = $dsn;
- // /database?param1=value1&param2=value2
- } else {
- $parsed['database'] = substr($dsn, 0, $pos);
- $dsn = substr($dsn, $pos + 1);
- if (strpos($dsn, '&') !== false) {
- $opts = explode('&', $dsn);
- } else { // database?param1=value1
- $opts = array($dsn);
- }
- foreach ($opts as $opt) {
- list($key, $value) = explode('=', $opt);
- if (!isset($parsed[$key])) { // don't allow params overwrite
- $parsed[$key] = rawurldecode($value);
- }
- }
- }
- }
-
- return $parsed;
- }
-
-
- /**
- * Convert strings to UTF-8 via iconv. NB, the result may not by UTF-8
- * if the conversion failed.
- * @param string string to convert to UTF-8
- * @return string UTF-8 encoded string, original string if iconv failed.
- */
- function I18N_toUTF8($string, $from)
- {
- if($from != 'UTF-8')
- {
- $s = iconv($from,'UTF-8',$string); //to UTF-8
- return $s !== false ? $s : $string; //it could return false
- }
- return $string;
- }
-
- /**
- * Convert UTF-8 strings to a different encoding. NB. The result
- * may not have been encoded if iconv fails.
- * @param string the UTF-8 string for conversion
- * @return string encoded string.
- */
- function I18N_toEncoding($string, $to)
- {
- if($to != 'UTF-8')
- {
- $s = iconv('UTF-8', $to, $string);
- return $s !== false ? $s : $string;
- }
- return $string;
- }
-
+<?php
+
+/**
+ * I18N Utility file.
+ *
+ * This program is free software; you can redistribute it and/or modify
+ * it under the terms of the BSD License.
+ *
+ * Copyright(c) 2004 by Wei Zhuo. All rights reserved.
+ *
+ * To contact the author write to <weizhuo[at]gmail[dot]com>
+ * The latest version of PRADO can be obtained from:
+ * {@link http://prado.sourceforge.net/}
+ *
+ * @author Wei Zhuo <weizhuo[at]gmail[dot]com>
+ * @version $Revision: 1.3 $ $Date: 2005/08/27 03:21:12 $
+ * @package System.I18N.core
+ */
+
+
+ /**
+ * For a given DSN (database connection string), return some information
+ * about the DSN. This function comes from PEAR's DB package.
+ *
+ * LICENSE: This source file is subject to version 3.0 of the PHP license
+ * that is available through the world-wide-web at the following URI:
+ * http://www.php.net/license/3_0.txt. If you did not receive a copy of
+ * the PHP License and are unable to obtain it through the web, please
+ * send a note to license@php.net so we can mail you a copy immediately.
+ *
+ * @param string DSN format, similar to PEAR's DB
+ * @return array DSN information.
+ * @author Stig Bakken <ssb@php.net>
+ * @author Tomas V.V.Cox <cox@idecnet.com>
+ * @author Daniel Convissor <danielc@php.net>
+ * @copyright 1997-2005 The PHP Group
+ * @license http://www.php.net/license/3_0.txt PHP License 3.0
+ * @link http://pear.php.net/package/DB
+ */
+ function parseDSN($dsn)
+ {
+ if (is_array($dsn)) {
+ return $dsn;
+ }
+
+ $parsed = array(
+ 'phptype' => false,
+ 'dbsyntax' => false,
+ 'username' => false,
+ 'password' => false,
+ 'protocol' => false,
+ 'hostspec' => false,
+ 'port' => false,
+ 'socket' => false,
+ 'database' => false
+ );
+
+ // Find phptype and dbsyntax
+ if (($pos = strpos($dsn, '://')) !== false) {
+ $str = substr($dsn, 0, $pos);
+ $dsn = substr($dsn, $pos + 3);
+ } else {
+ $str = $dsn;
+ $dsn = null;
+ }
+
+ // Get phptype and dbsyntax
+ // $str => phptype(dbsyntax)
+ if (preg_match('|^(.+?)\((.*?)\)$|', $str, $arr)) {
+ $parsed['phptype'] = $arr[1];
+ $parsed['dbsyntax'] = (empty($arr[2])) ? $arr[1] : $arr[2];
+ } else {
+ $parsed['phptype'] = $str;
+ $parsed['dbsyntax'] = $str;
+ }
+
+ if (empty($dsn)) {
+ return $parsed;
+ }
+
+ // Get (if found): username and password
+ // $dsn => username:password@protocol+hostspec/database
+ if (($at = strrpos($dsn,'@')) !== false) {
+ $str = substr($dsn, 0, $at);
+ $dsn = substr($dsn, $at + 1);
+ if (($pos = strpos($str, ':')) !== false) {
+ $parsed['username'] = rawurldecode(substr($str, 0, $pos));
+ $parsed['password'] = rawurldecode(substr($str, $pos + 1));
+ } else {
+ $parsed['username'] = rawurldecode($str);
+ }
+ }
+
+ // Find protocol and hostspec
+
+ // $dsn => proto(proto_opts)/database
+ if (preg_match('|^([^(]+)\((.*?)\)/?(.*?)$|', $dsn, $match)) {
+ $proto = $match[1];
+ $proto_opts = (!empty($match[2])) ? $match[2] : false;
+ $dsn = $match[3];
+
+ // $dsn => protocol+hostspec/database (old format)
+ } else {
+ if (strpos($dsn, '+') !== false) {
+ list($proto, $dsn) = explode('+', $dsn, 2);
+ }
+ if (strpos($dsn, '/') !== false) {
+ list($proto_opts, $dsn) = explode('/', $dsn, 2);
+ } else {
+ $proto_opts = $dsn;
+ $dsn = null;
+ }
+ }
+
+ // process the different protocol options
+ $parsed['protocol'] = (!empty($proto)) ? $proto : 'tcp';
+ $proto_opts = rawurldecode($proto_opts);
+ if ($parsed['protocol'] == 'tcp') {
+ if (strpos($proto_opts, ':') !== false) {
+ list($parsed['hostspec'], $parsed['port']) = explode(':', $proto_opts);
+ } else {
+ $parsed['hostspec'] = $proto_opts;
+ }
+ } elseif ($parsed['protocol'] == 'unix') {
+ $parsed['socket'] = $proto_opts;
+ }
+
+ // Get dabase if any
+ // $dsn => database
+ if (!empty($dsn)) {
+ // /database
+ if (($pos = strpos($dsn, '?')) === false) {
+ $parsed['database'] = $dsn;
+ // /database?param1=value1&param2=value2
+ } else {
+ $parsed['database'] = substr($dsn, 0, $pos);
+ $dsn = substr($dsn, $pos + 1);
+ if (strpos($dsn, '&') !== false) {
+ $opts = explode('&', $dsn);
+ } else { // database?param1=value1
+ $opts = array($dsn);
+ }
+ foreach ($opts as $opt) {
+ list($key, $value) = explode('=', $opt);
+ if (!isset($parsed[$key])) { // don't allow params overwrite
+ $parsed[$key] = rawurldecode($value);
+ }
+ }
+ }
+ }
+
+ return $parsed;
+ }
+
+
+ /**
+ * Convert strings to UTF-8 via iconv. NB, the result may not by UTF-8
+ * if the conversion failed.
+ * @param string string to convert to UTF-8
+ * @return string UTF-8 encoded string, original string if iconv failed.
+ */
+ function I18N_toUTF8($string, $from)
+ {
+ if($from != 'UTF-8')
+ {
+ $s = iconv($from,'UTF-8',$string); //to UTF-8
+ return $s !== false ? $s : $string; //it could return false
+ }
+ return $string;
+ }
+
+ /**
+ * Convert UTF-8 strings to a different encoding. NB. The result
+ * may not have been encoded if iconv fails.
+ * @param string the UTF-8 string for conversion
+ * @return string encoded string.
+ */
+ function I18N_toEncoding($string, $to)
+ {
+ if($to != 'UTF-8')
+ {
+ $s = iconv('UTF-8', $to, $string);
+ return $s !== false ? $s : $string;
+ }
+ return $string;
+ }
+
?> \ No newline at end of file
diff --git a/framework/IO/TTarFileExtractor.php b/framework/IO/TTarFileExtractor.php
index 74bb32b8..78120d57 100644
--- a/framework/IO/TTarFileExtractor.php
+++ b/framework/IO/TTarFileExtractor.php
@@ -1,574 +1,574 @@
-<?php
-/**
- * TTarFileExtractor class file
- *
- * @author Vincent Blavet <vincent@phpconcept.net>
- * @copyright Copyright &copy; 1997-2003 The PHP Group
- * @version $Id$
- * @package System.IO
- */
-
-/* vim: set ts=4 sw=4: */
-// +----------------------------------------------------------------------+
-// | PHP Version 4 |
-// +----------------------------------------------------------------------+
-// | Copyright (c) 1997-2003 The PHP Group |
-// +----------------------------------------------------------------------+
-// | This source file is subject to version 3.0 of the PHP license, |
-// | that is bundled with this package in the file LICENSE, and is |
-// | available through the world-wide-web at the following url: |
-// | http://www.php.net/license/3_0.txt. |
-// | If you did not receive a copy of the PHP license and are unable to |
-// | obtain it through the world-wide-web, please send a note to |
-// | license@php.net so we can mail you a copy immediately. |
-// +----------------------------------------------------------------------+
-// | Author: Vincent Blavet <vincent@phpconcept.net> |
-// +----------------------------------------------------------------------+
-//
-// $Id$
-
-/**
- * TTarFileExtractor class
- *
- * @author Vincent Blavet <vincent@phpconcept.net>
- * @version $Id$
- * @package System.IO
- * @since 3.0
- */
-class TTarFileExtractor
-{
- /**
- * @var string Name of the Tar
- */
- private $_tarname='';
-
- /**
- * @var file descriptor
- */
- private $_file=0;
-
- /**
- * @var string Local Tar name of a remote Tar (http:// or ftp://)
- */
- private $_temp_tarname='';
-
- /**
- * Archive_Tar Class constructor. This flavour of the constructor only
- * declare a new Archive_Tar object, identifying it by the name of the
- * tar file.
- *
- * @param string $p_tarname The name of the tar archive to create
- * @access public
- */
- public function __construct($p_tarname)
- {
- $this->_tarname = $p_tarname;
- }
-
- public function __destruct()
- {
- $this->_close();
- // ----- Look for a local copy to delete
- if ($this->_temp_tarname != '')
- @unlink($this->_temp_tarname);
- }
-
- public function extract($p_path='')
- {
- return $this->extractModify($p_path, '');
- }
-
- /**
- * This method extract all the content of the archive in the directory
- * indicated by $p_path. When relevant the memorized path of the
- * files/dir can be modified by removing the $p_remove_path path at the
- * beginning of the file/dir path.
- * While extracting a file, if the directory path does not exists it is
- * created.
- * While extracting a file, if the file already exists it is replaced
- * without looking for last modification date.
- * While extracting a file, if the file already exists and is write
- * protected, the extraction is aborted.
- * While extracting a file, if a directory with the same name already
- * exists, the extraction is aborted.
- * While extracting a directory, if a file with the same name already
- * exists, the extraction is aborted.
- * While extracting a file/directory if the destination directory exist
- * and is write protected, or does not exist but can not be created,
- * the extraction is aborted.
- * If after extraction an extracted file does not show the correct
- * stored file size, the extraction is aborted.
- * When the extraction is aborted, a PEAR error text is set and false
- * is returned. However the result can be a partial extraction that may
- * need to be manually cleaned.
- *
- * @param string $p_path The path of the directory where the
- * files/dir need to by extracted.
- * @param string $p_remove_path Part of the memorized path that can be
- * removed if present at the beginning of
- * the file/dir path.
- * @return boolean true on success, false on error.
- * @access public
- */
- protected function extractModify($p_path, $p_remove_path)
- {
- $v_result = true;
- $v_list_detail = array();
-
- if ($v_result = $this->_openRead()) {
- $v_result = $this->_extractList($p_path, $v_list_detail,
- "complete", 0, $p_remove_path);
- $this->_close();
- }
-
- return $v_result;
- }
-
- protected function _error($p_message)
- {
- throw new Exception($p_message);
- }
-
- private function _isArchive($p_filename=null)
- {
- if ($p_filename == null) {
- $p_filename = $this->_tarname;
- }
- clearstatcache();
- return @is_file($p_filename);
- }
-
- private function _openRead()
- {
- if (strtolower(substr($this->_tarname, 0, 7)) == 'http://') {
-
- // ----- Look if a local copy need to be done
- if ($this->_temp_tarname == '') {
- $this->_temp_tarname = uniqid('tar').'.tmp';
- if (!$v_file_from = @fopen($this->_tarname, 'rb')) {
- $this->_error('Unable to open in read mode \''
- .$this->_tarname.'\'');
- $this->_temp_tarname = '';
- return false;
- }
- if (!$v_file_to = @fopen($this->_temp_tarname, 'wb')) {
- $this->_error('Unable to open in write mode \''
- .$this->_temp_tarname.'\'');
- $this->_temp_tarname = '';
- return false;
- }
- while ($v_data = @fread($v_file_from, 1024))
- @fwrite($v_file_to, $v_data);
- @fclose($v_file_from);
- @fclose($v_file_to);
- }
-
- // ----- File to open if the local copy
- $v_filename = $this->_temp_tarname;
-
- } else
- // ----- File to open if the normal Tar file
- $v_filename = $this->_tarname;
-
- $this->_file = @fopen($v_filename, "rb");
-
- if ($this->_file == 0) {
- $this->_error('Unable to open in read mode \''.$v_filename.'\'');
- return false;
- }
-
- return true;
- }
-
- private function _close()
- {
- //if (isset($this->_file)) {
- if (is_resource($this->_file))
- {
- @fclose($this->_file);
- $this->_file = 0;
- }
-
- // ----- Look if a local copy need to be erase
- // Note that it might be interesting to keep the url for a time : ToDo
- if ($this->_temp_tarname != '') {
- @unlink($this->_temp_tarname);
- $this->_temp_tarname = '';
- }
-
- return true;
- }
-
- private function _cleanFile()
- {
- $this->_close();
-
- // ----- Look for a local copy
- if ($this->_temp_tarname != '') {
- // ----- Remove the local copy but not the remote tarname
- @unlink($this->_temp_tarname);
- $this->_temp_tarname = '';
- } else {
- // ----- Remove the local tarname file
- @unlink($this->_tarname);
- }
- $this->_tarname = '';
-
- return true;
- }
-
- private function _readBlock()
- {
- $v_block = null;
- if (is_resource($this->_file)) {
- $v_block = @fread($this->_file, 512);
- }
- return $v_block;
- }
-
- private function _jumpBlock($p_len=null)
- {
- if (is_resource($this->_file)) {
- if ($p_len === null)
- $p_len = 1;
-
- @fseek($this->_file, @ftell($this->_file)+($p_len*512));
- }
- return true;
- }
-
- private function _readHeader($v_binary_data, &$v_header)
- {
- if (strlen($v_binary_data)==0) {
- $v_header['filename'] = '';
- return true;
- }
-
- if (strlen($v_binary_data) != 512) {
- $v_header['filename'] = '';
- $this->_error('Invalid block size : '.strlen($v_binary_data));
- return false;
- }
-
- // ----- Calculate the checksum
- $v_checksum = 0;
- // ..... First part of the header
- for ($i=0; $i<148; $i++)
- $v_checksum+=ord(substr($v_binary_data,$i,1));
- // ..... Ignore the checksum value and replace it by ' ' (space)
- for ($i=148; $i<156; $i++)
- $v_checksum += ord(' ');
- // ..... Last part of the header
- for ($i=156; $i<512; $i++)
- $v_checksum+=ord(substr($v_binary_data,$i,1));
-
- $v_data = unpack("a100filename/a8mode/a8uid/a8gid/a12size/a12mtime/"
- ."a8checksum/a1typeflag/a100link/a6magic/a2version/"
- ."a32uname/a32gname/a8devmajor/a8devminor",
- $v_binary_data);
-
- // ----- Extract the checksum
- $v_header['checksum'] = OctDec(trim($v_data['checksum']));
- if ($v_header['checksum'] != $v_checksum) {
- $v_header['filename'] = '';
-
- // ----- Look for last block (empty block)
- if (($v_checksum == 256) && ($v_header['checksum'] == 0))
- return true;
-
- $this->_error('Invalid checksum for file "'.$v_data['filename']
- .'" : '.$v_checksum.' calculated, '
- .$v_header['checksum'].' expected');
- return false;
- }
-
- // ----- Extract the properties
- $v_header['filename'] = trim($v_data['filename']);
- $v_header['mode'] = OctDec(trim($v_data['mode']));
- $v_header['uid'] = OctDec(trim($v_data['uid']));
- $v_header['gid'] = OctDec(trim($v_data['gid']));
- $v_header['size'] = OctDec(trim($v_data['size']));
- $v_header['mtime'] = OctDec(trim($v_data['mtime']));
- if (($v_header['typeflag'] = $v_data['typeflag']) == "5") {
- $v_header['size'] = 0;
- }
- return true;
- }
-
- private function _readLongHeader(&$v_header)
- {
- $v_filename = '';
- $n = floor($v_header['size']/512);
- for ($i=0; $i<$n; $i++) {
- $v_content = $this->_readBlock();
- $v_filename .= $v_content;
- }
- if (($v_header['size'] % 512) != 0) {
- $v_content = $this->_readBlock();
- $v_filename .= $v_content;
- }
-
- // ----- Read the next header
- $v_binary_data = $this->_readBlock();
-
- if (!$this->_readHeader($v_binary_data, $v_header))
- return false;
-
- $v_header['filename'] = $v_filename;
-
- return true;
- }
-
- protected function _extractList($p_path, &$p_list_detail, $p_mode,
- $p_file_list, $p_remove_path)
- {
- $v_result=true;
- $v_nb = 0;
- $v_extract_all = true;
- $v_listing = false;
-
- $p_path = $this->_translateWinPath($p_path, false);
- if ($p_path == '' || (substr($p_path, 0, 1) != '/'
- && substr($p_path, 0, 3) != "../" && !strpos($p_path, ':'))) {
- $p_path = "./".$p_path;
- }
- $p_remove_path = $this->_translateWinPath($p_remove_path);
-
- // ----- Look for path to remove format (should end by /)
- if (($p_remove_path != '') && (substr($p_remove_path, -1) != '/'))
- $p_remove_path .= '/';
- $p_remove_path_size = strlen($p_remove_path);
-
- switch ($p_mode) {
- case "complete" :
- $v_extract_all = true;
- $v_listing = false;
- break;
- case "partial" :
- $v_extract_all = false;
- $v_listing = false;
- break;
- case "list" :
- $v_extract_all = false;
- $v_listing = true;
- break;
- default :
- $this->_error('Invalid extract mode ('.$p_mode.')');
- return false;
- }
-
- clearstatcache();
-
- while (strlen($v_binary_data = $this->_readBlock()) != 0)
- {
- $v_extract_file = false;
- $v_extraction_stopped = 0;
-
- if (!$this->_readHeader($v_binary_data, $v_header))
- return false;
-
- if ($v_header['filename'] == '') {
- continue;
- }
-
- // ----- Look for long filename
- if ($v_header['typeflag'] == 'L') {
- if (!$this->_readLongHeader($v_header))
- return false;
- }
-
- if ((!$v_extract_all) && (is_array($p_file_list))) {
- // ----- By default no unzip if the file is not found
- $v_extract_file = false;
-
- for ($i=0; $i<sizeof($p_file_list); $i++) {
- // ----- Look if it is a directory
- if (substr($p_file_list[$i], -1) == '/') {
- // ----- Look if the directory is in the filename path
- if ((strlen($v_header['filename']) > strlen($p_file_list[$i]))
- && (substr($v_header['filename'], 0, strlen($p_file_list[$i]))
- == $p_file_list[$i])) {
- $v_extract_file = true;
- break;
- }
- }
-
- // ----- It is a file, so compare the file names
- elseif ($p_file_list[$i] == $v_header['filename']) {
- $v_extract_file = true;
- break;
- }
- }
- } else {
- $v_extract_file = true;
- }
-
- // ----- Look if this file need to be extracted
- if (($v_extract_file) && (!$v_listing))
- {
- if (($p_remove_path != '')
- && (substr($v_header['filename'], 0, $p_remove_path_size)
- == $p_remove_path))
- $v_header['filename'] = substr($v_header['filename'],
- $p_remove_path_size);
- if (($p_path != './') && ($p_path != '/')) {
- while (substr($p_path, -1) == '/')
- $p_path = substr($p_path, 0, strlen($p_path)-1);
-
- if (substr($v_header['filename'], 0, 1) == '/')
- $v_header['filename'] = $p_path.$v_header['filename'];
- else
- $v_header['filename'] = $p_path.'/'.$v_header['filename'];
- }
- if (file_exists($v_header['filename'])) {
- if ( (@is_dir($v_header['filename']))
- && ($v_header['typeflag'] == '')) {
- $this->_error('File '.$v_header['filename']
- .' already exists as a directory');
- return false;
- }
- if ( ($this->_isArchive($v_header['filename']))
- && ($v_header['typeflag'] == "5")) {
- $this->_error('Directory '.$v_header['filename']
- .' already exists as a file');
- return false;
- }
- if (!is_writeable($v_header['filename'])) {
- $this->_error('File '.$v_header['filename']
- .' already exists and is write protected');
- return false;
- }
- if (filemtime($v_header['filename']) > $v_header['mtime']) {
- // To be completed : An error or silent no replace ?
- }
- }
-
- // ----- Check the directory availability and create it if necessary
- elseif (($v_result
- = $this->_dirCheck(($v_header['typeflag'] == "5"
- ?$v_header['filename']
- :dirname($v_header['filename'])))) != 1) {
- $this->_error('Unable to create path for '.$v_header['filename']);
- return false;
- }
-
- if ($v_extract_file) {
- if ($v_header['typeflag'] == "5") {
- if (!@file_exists($v_header['filename'])) {
- if (!@mkdir($v_header['filename'], PRADO_CHMOD)) {
- $this->_error('Unable to create directory {'
- .$v_header['filename'].'}');
- return false;
- }
- chmod($v_header['filename'], PRADO_CHMOD);
- }
- } else {
- if (($v_dest_file = @fopen($v_header['filename'], "wb")) == 0) {
- $this->_error('Error while opening {'.$v_header['filename']
- .'} in write binary mode');
- return false;
- } else {
- $n = floor($v_header['size']/512);
- for ($i=0; $i<$n; $i++) {
- $v_content = $this->_readBlock();
- fwrite($v_dest_file, $v_content, 512);
- }
- if (($v_header['size'] % 512) != 0) {
- $v_content = $this->_readBlock();
- fwrite($v_dest_file, $v_content, ($v_header['size'] % 512));
- }
-
- @fclose($v_dest_file);
-
- // ----- Change the file mode, mtime
- @touch($v_header['filename'], $v_header['mtime']);
- // To be completed
- //chmod($v_header[filename], DecOct($v_header[mode]));
- }
-
- // ----- Check the file size
- clearstatcache();
- if (filesize($v_header['filename']) != $v_header['size']) {
- $this->_error('Extracted file '.$v_header['filename']
- .' does not have the correct file size \''
- .filesize($v_header['filename'])
- .'\' ('.$v_header['size']
- .' expected). Archive may be corrupted.');
- return false;
- }
- }
- } else {
- $this->_jumpBlock(ceil(($v_header['size']/512)));
- }
- } else {
- $this->_jumpBlock(ceil(($v_header['size']/512)));
- }
-
- /* TBC : Seems to be unused ...
- if ($this->_compress)
- $v_end_of_file = @gzeof($this->_file);
- else
- $v_end_of_file = @feof($this->_file);
- */
-
- if ($v_listing || $v_extract_file || $v_extraction_stopped) {
- // ----- Log extracted files
- if (($v_file_dir = dirname($v_header['filename']))
- == $v_header['filename'])
- $v_file_dir = '';
- if ((substr($v_header['filename'], 0, 1) == '/') && ($v_file_dir == ''))
- $v_file_dir = '/';
-
- $p_list_detail[$v_nb++] = $v_header;
- }
- }
-
- return true;
- }
-
- /**
- * Check if a directory exists and create it (including parent
- * dirs) if not.
- *
- * @param string $p_dir directory to check
- *
- * @return bool true if the directory exists or was created
- */
- protected function _dirCheck($p_dir)
- {
- if ((@is_dir($p_dir)) || ($p_dir == ''))
- return true;
-
- $p_parent_dir = dirname($p_dir);
-
- if (($p_parent_dir != $p_dir) &&
- ($p_parent_dir != '') &&
- (!$this->_dirCheck($p_parent_dir)))
- return false;
-
- if (!@mkdir($p_dir, PRADO_CHMOD)) {
- $this->_error("Unable to create directory '$p_dir'");
- return false;
- }
- chmod($p_dir,PRADO_CHMOD);
-
- return true;
- }
-
- protected function _translateWinPath($p_path, $p_remove_disk_letter=true)
- {
- if (substr(PHP_OS, 0, 3) == 'WIN') {
- // ----- Look for potential disk letter
- if ( ($p_remove_disk_letter)
- && (($v_position = strpos($p_path, ':')) != false)) {
- $p_path = substr($p_path, $v_position+1);
- }
- // ----- Change potential windows directory separator
- if ((strpos($p_path, '\\') > 0) || (substr($p_path, 0,1) == '\\')) {
- $p_path = strtr($p_path, '\\', '/');
- }
- }
- return $p_path;
- }
-}
+<?php
+/**
+ * TTarFileExtractor class file
+ *
+ * @author Vincent Blavet <vincent@phpconcept.net>
+ * @copyright Copyright &copy; 1997-2003 The PHP Group
+ * @version $Id$
+ * @package System.IO
+ */
+
+/* vim: set ts=4 sw=4: */
+// +----------------------------------------------------------------------+
+// | PHP Version 4 |
+// +----------------------------------------------------------------------+
+// | Copyright (c) 1997-2003 The PHP Group |
+// +----------------------------------------------------------------------+
+// | This source file is subject to version 3.0 of the PHP license, |
+// | that is bundled with this package in the file LICENSE, and is |
+// | available through the world-wide-web at the following url: |
+// | http://www.php.net/license/3_0.txt. |
+// | If you did not receive a copy of the PHP license and are unable to |
+// | obtain it through the world-wide-web, please send a note to |
+// | license@php.net so we can mail you a copy immediately. |
+// +----------------------------------------------------------------------+
+// | Author: Vincent Blavet <vincent@phpconcept.net> |
+// +----------------------------------------------------------------------+
+//
+// $Id$
+
+/**
+ * TTarFileExtractor class
+ *
+ * @author Vincent Blavet <vincent@phpconcept.net>
+ * @version $Id$
+ * @package System.IO
+ * @since 3.0
+ */
+class TTarFileExtractor
+{
+ /**
+ * @var string Name of the Tar
+ */
+ private $_tarname='';
+
+ /**
+ * @var file descriptor
+ */
+ private $_file=0;
+
+ /**
+ * @var string Local Tar name of a remote Tar (http:// or ftp://)
+ */
+ private $_temp_tarname='';
+
+ /**
+ * Archive_Tar Class constructor. This flavour of the constructor only
+ * declare a new Archive_Tar object, identifying it by the name of the
+ * tar file.
+ *
+ * @param string $p_tarname The name of the tar archive to create
+ * @access public
+ */
+ public function __construct($p_tarname)
+ {
+ $this->_tarname = $p_tarname;
+ }
+
+ public function __destruct()
+ {
+ $this->_close();
+ // ----- Look for a local copy to delete
+ if ($this->_temp_tarname != '')
+ @unlink($this->_temp_tarname);
+ }
+
+ public function extract($p_path='')
+ {
+ return $this->extractModify($p_path, '');
+ }
+
+ /**
+ * This method extract all the content of the archive in the directory
+ * indicated by $p_path. When relevant the memorized path of the
+ * files/dir can be modified by removing the $p_remove_path path at the
+ * beginning of the file/dir path.
+ * While extracting a file, if the directory path does not exists it is
+ * created.
+ * While extracting a file, if the file already exists it is replaced
+ * without looking for last modification date.
+ * While extracting a file, if the file already exists and is write
+ * protected, the extraction is aborted.
+ * While extracting a file, if a directory with the same name already
+ * exists, the extraction is aborted.
+ * While extracting a directory, if a file with the same name already
+ * exists, the extraction is aborted.
+ * While extracting a file/directory if the destination directory exist
+ * and is write protected, or does not exist but can not be created,
+ * the extraction is aborted.
+ * If after extraction an extracted file does not show the correct
+ * stored file size, the extraction is aborted.
+ * When the extraction is aborted, a PEAR error text is set and false
+ * is returned. However the result can be a partial extraction that may
+ * need to be manually cleaned.
+ *
+ * @param string $p_path The path of the directory where the
+ * files/dir need to by extracted.
+ * @param string $p_remove_path Part of the memorized path that can be
+ * removed if present at the beginning of
+ * the file/dir path.
+ * @return boolean true on success, false on error.
+ * @access public
+ */
+ protected function extractModify($p_path, $p_remove_path)
+ {
+ $v_result = true;
+ $v_list_detail = array();
+
+ if ($v_result = $this->_openRead()) {
+ $v_result = $this->_extractList($p_path, $v_list_detail,
+ "complete", 0, $p_remove_path);
+ $this->_close();
+ }
+
+ return $v_result;
+ }
+
+ protected function _error($p_message)
+ {
+ throw new Exception($p_message);
+ }
+
+ private function _isArchive($p_filename=null)
+ {
+ if ($p_filename == null) {
+ $p_filename = $this->_tarname;
+ }
+ clearstatcache();
+ return @is_file($p_filename);
+ }
+
+ private function _openRead()
+ {
+ if (strtolower(substr($this->_tarname, 0, 7)) == 'http://') {
+
+ // ----- Look if a local copy need to be done
+ if ($this->_temp_tarname == '') {
+ $this->_temp_tarname = uniqid('tar').'.tmp';
+ if (!$v_file_from = @fopen($this->_tarname, 'rb')) {
+ $this->_error('Unable to open in read mode \''
+ .$this->_tarname.'\'');
+ $this->_temp_tarname = '';
+ return false;
+ }
+ if (!$v_file_to = @fopen($this->_temp_tarname, 'wb')) {
+ $this->_error('Unable to open in write mode \''
+ .$this->_temp_tarname.'\'');
+ $this->_temp_tarname = '';
+ return false;
+ }
+ while ($v_data = @fread($v_file_from, 1024))
+ @fwrite($v_file_to, $v_data);
+ @fclose($v_file_from);
+ @fclose($v_file_to);
+ }
+
+ // ----- File to open if the local copy
+ $v_filename = $this->_temp_tarname;
+
+ } else
+ // ----- File to open if the normal Tar file
+ $v_filename = $this->_tarname;
+
+ $this->_file = @fopen($v_filename, "rb");
+
+ if ($this->_file == 0) {
+ $this->_error('Unable to open in read mode \''.$v_filename.'\'');
+ return false;
+ }
+
+ return true;
+ }
+
+ private function _close()
+ {
+ //if (isset($this->_file)) {
+ if (is_resource($this->_file))
+ {
+ @fclose($this->_file);
+ $this->_file = 0;
+ }
+
+ // ----- Look if a local copy need to be erase
+ // Note that it might be interesting to keep the url for a time : ToDo
+ if ($this->_temp_tarname != '') {
+ @unlink($this->_temp_tarname);
+ $this->_temp_tarname = '';
+ }
+
+ return true;
+ }
+
+ private function _cleanFile()
+ {
+ $this->_close();
+
+ // ----- Look for a local copy
+ if ($this->_temp_tarname != '') {
+ // ----- Remove the local copy but not the remote tarname
+ @unlink($this->_temp_tarname);
+ $this->_temp_tarname = '';
+ } else {
+ // ----- Remove the local tarname file
+ @unlink($this->_tarname);
+ }
+ $this->_tarname = '';
+
+ return true;
+ }
+
+ private function _readBlock()
+ {
+ $v_block = null;
+ if (is_resource($this->_file)) {
+ $v_block = @fread($this->_file, 512);
+ }
+ return $v_block;
+ }
+
+ private function _jumpBlock($p_len=null)
+ {
+ if (is_resource($this->_file)) {
+ if ($p_len === null)
+ $p_len = 1;
+
+ @fseek($this->_file, @ftell($this->_file)+($p_len*512));
+ }
+ return true;
+ }
+
+ private function _readHeader($v_binary_data, &$v_header)
+ {
+ if (strlen($v_binary_data)==0) {
+ $v_header['filename'] = '';
+ return true;
+ }
+
+ if (strlen($v_binary_data) != 512) {
+ $v_header['filename'] = '';
+ $this->_error('Invalid block size : '.strlen($v_binary_data));
+ return false;
+ }
+
+ // ----- Calculate the checksum
+ $v_checksum = 0;
+ // ..... First part of the header
+ for ($i=0; $i<148; $i++)
+ $v_checksum+=ord(substr($v_binary_data,$i,1));
+ // ..... Ignore the checksum value and replace it by ' ' (space)
+ for ($i=148; $i<156; $i++)
+ $v_checksum += ord(' ');
+ // ..... Last part of the header
+ for ($i=156; $i<512; $i++)
+ $v_checksum+=ord(substr($v_binary_data,$i,1));
+
+ $v_data = unpack("a100filename/a8mode/a8uid/a8gid/a12size/a12mtime/"
+ ."a8checksum/a1typeflag/a100link/a6magic/a2version/"
+ ."a32uname/a32gname/a8devmajor/a8devminor",
+ $v_binary_data);
+
+ // ----- Extract the checksum
+ $v_header['checksum'] = OctDec(trim($v_data['checksum']));
+ if ($v_header['checksum'] != $v_checksum) {
+ $v_header['filename'] = '';
+
+ // ----- Look for last block (empty block)
+ if (($v_checksum == 256) && ($v_header['checksum'] == 0))
+ return true;
+
+ $this->_error('Invalid checksum for file "'.$v_data['filename']
+ .'" : '.$v_checksum.' calculated, '
+ .$v_header['checksum'].' expected');
+ return false;
+ }
+
+ // ----- Extract the properties
+ $v_header['filename'] = trim($v_data['filename']);
+ $v_header['mode'] = OctDec(trim($v_data['mode']));
+ $v_header['uid'] = OctDec(trim($v_data['uid']));
+ $v_header['gid'] = OctDec(trim($v_data['gid']));
+ $v_header['size'] = OctDec(trim($v_data['size']));
+ $v_header['mtime'] = OctDec(trim($v_data['mtime']));
+ if (($v_header['typeflag'] = $v_data['typeflag']) == "5") {
+ $v_header['size'] = 0;
+ }
+ return true;
+ }
+
+ private function _readLongHeader(&$v_header)
+ {
+ $v_filename = '';
+ $n = floor($v_header['size']/512);
+ for ($i=0; $i<$n; $i++) {
+ $v_content = $this->_readBlock();
+ $v_filename .= $v_content;
+ }
+ if (($v_header['size'] % 512) != 0) {
+ $v_content = $this->_readBlock();
+ $v_filename .= $v_content;
+ }
+
+ // ----- Read the next header
+ $v_binary_data = $this->_readBlock();
+
+ if (!$this->_readHeader($v_binary_data, $v_header))
+ return false;
+
+ $v_header['filename'] = $v_filename;
+
+ return true;
+ }
+
+ protected function _extractList($p_path, &$p_list_detail, $p_mode,
+ $p_file_list, $p_remove_path)
+ {
+ $v_result=true;
+ $v_nb = 0;
+ $v_extract_all = true;
+ $v_listing = false;
+
+ $p_path = $this->_translateWinPath($p_path, false);
+ if ($p_path == '' || (substr($p_path, 0, 1) != '/'
+ && substr($p_path, 0, 3) != "../" && !strpos($p_path, ':'))) {
+ $p_path = "./".$p_path;
+ }
+ $p_remove_path = $this->_translateWinPath($p_remove_path);
+
+ // ----- Look for path to remove format (should end by /)
+ if (($p_remove_path != '') && (substr($p_remove_path, -1) != '/'))
+ $p_remove_path .= '/';
+ $p_remove_path_size = strlen($p_remove_path);
+
+ switch ($p_mode) {
+ case "complete" :
+ $v_extract_all = true;
+ $v_listing = false;
+ break;
+ case "partial" :
+ $v_extract_all = false;
+ $v_listing = false;
+ break;
+ case "list" :
+ $v_extract_all = false;
+ $v_listing = true;
+ break;
+ default :
+ $this->_error('Invalid extract mode ('.$p_mode.')');
+ return false;
+ }
+
+ clearstatcache();
+
+ while (strlen($v_binary_data = $this->_readBlock()) != 0)
+ {
+ $v_extract_file = false;
+ $v_extraction_stopped = 0;
+
+ if (!$this->_readHeader($v_binary_data, $v_header))
+ return false;
+
+ if ($v_header['filename'] == '') {
+ continue;
+ }
+
+ // ----- Look for long filename
+ if ($v_header['typeflag'] == 'L') {
+ if (!$this->_readLongHeader($v_header))
+ return false;
+ }
+
+ if ((!$v_extract_all) && (is_array($p_file_list))) {
+ // ----- By default no unzip if the file is not found
+ $v_extract_file = false;
+
+ for ($i=0; $i<sizeof($p_file_list); $i++) {
+ // ----- Look if it is a directory
+ if (substr($p_file_list[$i], -1) == '/') {
+ // ----- Look if the directory is in the filename path
+ if ((strlen($v_header['filename']) > strlen($p_file_list[$i]))
+ && (substr($v_header['filename'], 0, strlen($p_file_list[$i]))
+ == $p_file_list[$i])) {
+ $v_extract_file = true;
+ break;
+ }
+ }
+
+ // ----- It is a file, so compare the file names
+ elseif ($p_file_list[$i] == $v_header['filename']) {
+ $v_extract_file = true;
+ break;
+ }
+ }
+ } else {
+ $v_extract_file = true;
+ }
+
+ // ----- Look if this file need to be extracted
+ if (($v_extract_file) && (!$v_listing))
+ {
+ if (($p_remove_path != '')
+ && (substr($v_header['filename'], 0, $p_remove_path_size)
+ == $p_remove_path))
+ $v_header['filename'] = substr($v_header['filename'],
+ $p_remove_path_size);
+ if (($p_path != './') && ($p_path != '/')) {
+ while (substr($p_path, -1) == '/')
+ $p_path = substr($p_path, 0, strlen($p_path)-1);
+
+ if (substr($v_header['filename'], 0, 1) == '/')
+ $v_header['filename'] = $p_path.$v_header['filename'];
+ else
+ $v_header['filename'] = $p_path.'/'.$v_header['filename'];
+ }
+ if (file_exists($v_header['filename'])) {
+ if ( (@is_dir($v_header['filename']))
+ && ($v_header['typeflag'] == '')) {
+ $this->_error('File '.$v_header['filename']
+ .' already exists as a directory');
+ return false;
+ }
+ if ( ($this->_isArchive($v_header['filename']))
+ && ($v_header['typeflag'] == "5")) {
+ $this->_error('Directory '.$v_header['filename']
+ .' already exists as a file');
+ return false;
+ }
+ if (!is_writeable($v_header['filename'])) {
+ $this->_error('File '.$v_header['filename']
+ .' already exists and is write protected');
+ return false;
+ }
+ if (filemtime($v_header['filename']) > $v_header['mtime']) {
+ // To be completed : An error or silent no replace ?
+ }
+ }
+
+ // ----- Check the directory availability and create it if necessary
+ elseif (($v_result
+ = $this->_dirCheck(($v_header['typeflag'] == "5"
+ ?$v_header['filename']
+ :dirname($v_header['filename'])))) != 1) {
+ $this->_error('Unable to create path for '.$v_header['filename']);
+ return false;
+ }
+
+ if ($v_extract_file) {
+ if ($v_header['typeflag'] == "5") {
+ if (!@file_exists($v_header['filename'])) {
+ if (!@mkdir($v_header['filename'], PRADO_CHMOD)) {
+ $this->_error('Unable to create directory {'
+ .$v_header['filename'].'}');
+ return false;
+ }
+ chmod($v_header['filename'], PRADO_CHMOD);
+ }
+ } else {
+ if (($v_dest_file = @fopen($v_header['filename'], "wb")) == 0) {
+ $this->_error('Error while opening {'.$v_header['filename']
+ .'} in write binary mode');
+ return false;
+ } else {
+ $n = floor($v_header['size']/512);
+ for ($i=0; $i<$n; $i++) {
+ $v_content = $this->_readBlock();
+ fwrite($v_dest_file, $v_content, 512);
+ }
+ if (($v_header['size'] % 512) != 0) {
+ $v_content = $this->_readBlock();
+ fwrite($v_dest_file, $v_content, ($v_header['size'] % 512));
+ }
+
+ @fclose($v_dest_file);
+
+ // ----- Change the file mode, mtime
+ @touch($v_header['filename'], $v_header['mtime']);
+ // To be completed
+ //chmod($v_header[filename], DecOct($v_header[mode]));
+ }
+
+ // ----- Check the file size
+ clearstatcache();
+ if (filesize($v_header['filename']) != $v_header['size']) {
+ $this->_error('Extracted file '.$v_header['filename']
+ .' does not have the correct file size \''
+ .filesize($v_header['filename'])
+ .'\' ('.$v_header['size']
+ .' expected). Archive may be corrupted.');
+ return false;
+ }
+ }
+ } else {
+ $this->_jumpBlock(ceil(($v_header['size']/512)));
+ }
+ } else {
+ $this->_jumpBlock(ceil(($v_header['size']/512)));
+ }
+
+ /* TBC : Seems to be unused ...
+ if ($this->_compress)
+ $v_end_of_file = @gzeof($this->_file);
+ else
+ $v_end_of_file = @feof($this->_file);
+ */
+
+ if ($v_listing || $v_extract_file || $v_extraction_stopped) {
+ // ----- Log extracted files
+ if (($v_file_dir = dirname($v_header['filename']))
+ == $v_header['filename'])
+ $v_file_dir = '';
+ if ((substr($v_header['filename'], 0, 1) == '/') && ($v_file_dir == ''))
+ $v_file_dir = '/';
+
+ $p_list_detail[$v_nb++] = $v_header;
+ }
+ }
+
+ return true;
+ }
+
+ /**
+ * Check if a directory exists and create it (including parent
+ * dirs) if not.
+ *
+ * @param string $p_dir directory to check
+ *
+ * @return bool true if the directory exists or was created
+ */
+ protected function _dirCheck($p_dir)
+ {
+ if ((@is_dir($p_dir)) || ($p_dir == ''))
+ return true;
+
+ $p_parent_dir = dirname($p_dir);
+
+ if (($p_parent_dir != $p_dir) &&
+ ($p_parent_dir != '') &&
+ (!$this->_dirCheck($p_parent_dir)))
+ return false;
+
+ if (!@mkdir($p_dir, PRADO_CHMOD)) {
+ $this->_error("Unable to create directory '$p_dir'");
+ return false;
+ }
+ chmod($p_dir,PRADO_CHMOD);
+
+ return true;
+ }
+
+ protected function _translateWinPath($p_path, $p_remove_disk_letter=true)
+ {
+ if (substr(PHP_OS, 0, 3) == 'WIN') {
+ // ----- Look for potential disk letter
+ if ( ($p_remove_disk_letter)
+ && (($v_position = strpos($p_path, ':')) != false)) {
+ $p_path = substr($p_path, $v_position+1);
+ }
+ // ----- Change potential windows directory separator
+ if ((strpos($p_path, '\\') > 0) || (substr($p_path, 0,1) == '\\')) {
+ $p_path = strtr($p_path, '\\', '/');
+ }
+ }
+ return $p_path;
+ }
+}
?> \ No newline at end of file
diff --git a/framework/IO/TTextWriter.php b/framework/IO/TTextWriter.php
index 344344cc..38421539 100644
--- a/framework/IO/TTextWriter.php
+++ b/framework/IO/TTextWriter.php
@@ -1,59 +1,59 @@
-<?php
-/**
- * TTextWriter class file
- *
- * @author Qiang Xue <qiang.xue@gmail.com>
- * @link http://www.pradosoft.com/
+<?php
+/**
+ * TTextWriter class file
+ *
+ * @author Qiang Xue <qiang.xue@gmail.com>
+ * @link http://www.pradosoft.com/
* @copyright Copyright &copy; 2005-2012 PradoSoft
- * @license http://www.pradosoft.com/license/
- * @version $Id$
- * @package System.IO
- */
-
-/**
- * TTextWriter class.
- *
- * TTextWriter implements a memory-based text writer.
- * Content written by TTextWriter are stored in memory
- * and can be obtained by calling {@link flush()}.
- *
- * @author Qiang Xue <qiang.xue@gmail.com>
- * @version $Id$
- * @package System.IO
- * @since 3.0
- */
-class TTextWriter extends TComponent implements ITextWriter
-{
- private $_str='';
-
- /**
- * Flushes the content that has been written.
- * @return string the content being flushed
- */
- public function flush()
- {
- $str=$this->_str;
- $this->_str='';
- return $str;
- }
-
- /**
- * Writes a string.
- * @param string string to be written
- */
- public function write($str)
- {
- $this->_str.=$str;
- }
-
- /**
- * Writers a string and terminates it with a newline.
- * @param string content to be written
- * @see write
- */
- public function writeLine($str='')
- {
- $this->write($str."\n");
- }
-}
-
+ * @license http://www.pradosoft.com/license/
+ * @version $Id$
+ * @package System.IO
+ */
+
+/**
+ * TTextWriter class.
+ *
+ * TTextWriter implements a memory-based text writer.
+ * Content written by TTextWriter are stored in memory
+ * and can be obtained by calling {@link flush()}.
+ *
+ * @author Qiang Xue <qiang.xue@gmail.com>
+ * @version $Id$
+ * @package System.IO
+ * @since 3.0
+ */
+class TTextWriter extends TComponent implements ITextWriter
+{
+ private $_str='';
+
+ /**
+ * Flushes the content that has been written.
+ * @return string the content being flushed
+ */
+ public function flush()
+ {
+ $str=$this->_str;
+ $this->_str='';
+ return $str;
+ }
+
+ /**
+ * Writes a string.
+ * @param string string to be written
+ */
+ public function write($str)
+ {
+ $this->_str.=$str;
+ }
+
+ /**
+ * Writers a string and terminates it with a newline.
+ * @param string content to be written
+ * @see write
+ */
+ public function writeLine($str='')
+ {
+ $this->write($str."\n");
+ }
+}
+
diff --git a/framework/Security/IUserManager.php b/framework/Security/IUserManager.php
index 2769db8f..19431bd9 100644
--- a/framework/Security/IUserManager.php
+++ b/framework/Security/IUserManager.php
@@ -1,58 +1,58 @@
-<?php
-/**
- * IUserManager interface file
- *
- * @author Qiang Xue <qiang.xue@gmail.com>
- * @link http://www.pradosoft.com/
+<?php
+/**
+ * IUserManager interface file
+ *
+ * @author Qiang Xue <qiang.xue@gmail.com>
+ * @link http://www.pradosoft.com/
* @copyright Copyright &copy; 2005-2012 PradoSoft
- * @license http://www.pradosoft.com/license/
- * @version $Id$
- * @package System.Security
- */
-
-/**
- * IUserManager interface
- *
- * IUserManager specifies the interface that must be implemented by
- * a user manager class if it is to be used together with {@link TAuthManager}
- * and {@link TUser}.
- *
- * @author Qiang Xue <qiang.xue@gmail.com>
- * @version $Id$
- * @package System.Security
- * @since 3.0
- */
-interface IUserManager
-{
- /**
- * @return string name for a guest user.
- */
- public function getGuestName();
- /**
- * Returns a user instance given the user name.
- * @param string user name, null if it is a guest.
- * @return TUser the user instance, null if the specified username is not in the user database.
- */
- public function getUser($username=null);
- /**
- * Returns a user instance according to auth data stored in a cookie.
- * @param THttpCookie the cookie storing user authentication information
- * @return TUser the user instance generated based on the cookie auth data, null if the cookie does not have valid auth data.
- * @since 3.1.1
- */
- public function getUserFromCookie($cookie);
- /**
- * Saves user auth data into a cookie.
- * @param THttpCookie the cookie to receive the user auth data.
- * @since 3.1.1
- */
- public function saveUserToCookie($cookie);
- /**
- * Validates if the username and password are correct.
- * @param string user name
- * @param string password
- * @return boolean true if validation is successful, false otherwise.
- */
- public function validateUser($username,$password);
-}
-
+ * @license http://www.pradosoft.com/license/
+ * @version $Id$
+ * @package System.Security
+ */
+
+/**
+ * IUserManager interface
+ *
+ * IUserManager specifies the interface that must be implemented by
+ * a user manager class if it is to be used together with {@link TAuthManager}
+ * and {@link TUser}.
+ *
+ * @author Qiang Xue <qiang.xue@gmail.com>
+ * @version $Id$
+ * @package System.Security
+ * @since 3.0
+ */
+interface IUserManager
+{
+ /**
+ * @return string name for a guest user.
+ */
+ public function getGuestName();
+ /**
+ * Returns a user instance given the user name.
+ * @param string user name, null if it is a guest.
+ * @return TUser the user instance, null if the specified username is not in the user database.
+ */
+ public function getUser($username=null);
+ /**
+ * Returns a user instance according to auth data stored in a cookie.
+ * @param THttpCookie the cookie storing user authentication information
+ * @return TUser the user instance generated based on the cookie auth data, null if the cookie does not have valid auth data.
+ * @since 3.1.1
+ */
+ public function getUserFromCookie($cookie);
+ /**
+ * Saves user auth data into a cookie.
+ * @param THttpCookie the cookie to receive the user auth data.
+ * @since 3.1.1
+ */
+ public function saveUserToCookie($cookie);
+ /**
+ * Validates if the username and password are correct.
+ * @param string user name
+ * @param string password
+ * @return boolean true if validation is successful, false otherwise.
+ */
+ public function validateUser($username,$password);
+}
+
diff --git a/framework/Security/TAuthManager.php b/framework/Security/TAuthManager.php
index 92836195..6a774a8e 100644
--- a/framework/Security/TAuthManager.php
+++ b/framework/Security/TAuthManager.php
@@ -1,457 +1,457 @@
-<?php
-/**
- * TAuthManager class file
- *
- * @author Qiang Xue <qiang.xue@gmail.com>
- * @link http://www.pradosoft.com/
- * @copyright Copyright &copy; 2005-2012 PradoSoft
- * @license http://www.pradosoft.com/license/
- * @version $Id$
- * @package System.Security
- */
-
-/**
- * Using IUserManager interface
- */
-Prado::using('System.Security.IUserManager');
-
-/**
- * TAuthManager class
- *
- * TAuthManager performs user authentication and authorization for a Prado application.
- * TAuthManager works together with a {@link IUserManager} module that can be
- * specified via the {@link setUserManager UserManager} property.
- * If an authorization fails, TAuthManager will try to redirect the client
- * browser to a login page that is specified via the {@link setLoginPage LoginPage}.
- * To login or logout a user, call {@link login} or {@link logout}, respectively.
- *
- * The {@link setAuthExpire AuthExpire} property can be used to define the time
- * in seconds after which the authentication should expire.
- * {@link setAllowAutoLogin AllowAutoLogin} specifies if the login information
- * should be stored in a cookie to perform automatic login. Enabling this
- * feature will cause that {@link setAuthExpire AuthExpire} has no effect
- * since the user will be logged in again on authentication expiration.
- *
- * To load TAuthManager, configure it in application configuration as follows,
- * <module id="auth" class="System.Security.TAuthManager" UserManager="users" LoginPage="login" />
- * <module id="users" class="System.Security.TUserManager" />
- *
- * @author Qiang Xue <qiang.xue@gmail.com>
- * @version $Id$
- * @package System.Security
- * @since 3.0
- */
-class TAuthManager extends TModule
-{
- /**
- * GET variable name for return url
- */
- const RETURN_URL_VAR='ReturnUrl';
- /**
- * @var boolean if the module has been initialized
- */
- private $_initialized=false;
- /**
- * @var IUserManager user manager instance
- */
- private $_userManager;
- /**
- * @var string login page
- */
- private $_loginPage;
- /**
- * @var boolean whether authorization should be skipped
- */
- private $_skipAuthorization=false;
- /**
- * @var string the session var name for storing return URL
- */
- private $_returnUrlVarName;
- /**
- * @var boolean whether to allow auto login (using cookie)
- */
- private $_allowAutoLogin=false;
- /**
- * @var string variable name used to store user session or cookie
- */
- private $_userKey;
- /**
- * @var integer authentication expiration time in seconds. Defaults to zero (no expiration)
- */
- private $_authExpire=0;
-
- /**
- * Initializes this module.
- * This method is required by the IModule interface.
- * @param TXmlElement configuration for this module, can be null
- * @throws TConfigurationException if user manager does not exist or is not IUserManager
- */
- public function init($config)
- {
- if($this->_userManager===null)
- throw new TConfigurationException('authmanager_usermanager_required');
- if($this->_returnUrlVarName===null)
- $this->_returnUrlVarName=$this->getApplication()->getID().':'.self::RETURN_URL_VAR;
- $application=$this->getApplication();
- if(is_string($this->_userManager))
- {
- if(($users=$application->getModule($this->_userManager))===null)
- throw new TConfigurationException('authmanager_usermanager_inexistent',$this->_userManager);
- if(!($users instanceof IUserManager))
- throw new TConfigurationException('authmanager_usermanager_invalid',$this->_userManager);
- $this->_userManager=$users;
- }
- $application->attachEventHandler('OnAuthentication',array($this,'doAuthentication'));
- $application->attachEventHandler('OnEndRequest',array($this,'leave'));
- $application->attachEventHandler('OnAuthorization',array($this,'doAuthorization'));
- $this->_initialized=true;
- }
-
- /**
- * @return IUserManager user manager instance
- */
- public function getUserManager()
- {
- return $this->_userManager;
- }
-
- /**
- * @param string|IUserManager the user manager module ID or the user manager object
- * @throws TInvalidOperationException if the module has been initialized or the user manager object is not IUserManager
- */
- public function setUserManager($provider)
- {
- if($this->_initialized)
- throw new TInvalidOperationException('authmanager_usermanager_unchangeable');
- if(!is_string($provider) && !($provider instanceof IUserManager))
- throw new TConfigurationException('authmanager_usermanager_invalid',$this->_userManager);
- $this->_userManager=$provider;
- }
-
- /**
- * @return string path of login page should login is required
- */
- public function getLoginPage()
- {
- return $this->_loginPage;
- }
-
- /**
- * Sets the login page that the client browser will be redirected to if login is needed.
- * Login page should be specified in the format of page path.
- * @param string path of login page should login is required
- * @see TPageService
- */
- public function setLoginPage($pagePath)
- {
- $this->_loginPage=$pagePath;
- }
-
- /**
- * Performs authentication.
- * This is the event handler attached to application's Authentication event.
- * Do not call this method directly.
- * @param mixed sender of the Authentication event
- * @param mixed event parameter
- */
- public function doAuthentication($sender,$param)
- {
- $this->onAuthenticate($param);
-
- $service=$this->getService();
- if(($service instanceof TPageService) && $service->getRequestedPagePath()===$this->getLoginPage())
- $this->_skipAuthorization=true;
- }
-
- /**
- * Performs authorization.
- * This is the event handler attached to application's Authorization event.
- * Do not call this method directly.
- * @param mixed sender of the Authorization event
- * @param mixed event parameter
- */
- public function doAuthorization($sender,$param)
- {
- if(!$this->_skipAuthorization)
- {
- $this->onAuthorize($param);
- }
- }
-
- /**
- * Performs login redirect if authorization fails.
- * This is the event handler attached to application's EndRequest event.
- * Do not call this method directly.
- * @param mixed sender of the event
- * @param mixed event parameter
- */
- public function leave($sender,$param)
- {
- $application=$this->getApplication();
- if($application->getResponse()->getStatusCode()===401)
- {
- $service=$application->getService();
- if($service instanceof TPageService)
- {
- $returnUrl=$application->getRequest()->getRequestUri();
- $this->setReturnUrl($returnUrl);
- $url=$service->constructUrl($this->getLoginPage());
- $application->getResponse()->redirect($url);
- }
- }
- }
-
- /**
- * @return string the name of the session variable storing return URL. It defaults to 'AppID:ReturnUrl'
- */
- public function getReturnUrlVarName()
- {
- return $this->_returnUrlVarName;
- }
-
- /**
- * @param string the name of the session variable storing return URL.
- */
- public function setReturnUrlVarName($value)
- {
- $this->_returnUrlVarName=$value;
- }
-
- /**
- * @return string URL that the browser should be redirected to when login succeeds.
- */
- public function getReturnUrl()
- {
- return $this->getSession()->itemAt($this->getReturnUrlVarName());
- }
-
- /**
- * Sets the URL that the browser should be redirected to when login succeeds.
- * @param string the URL to be redirected to.
- */
- public function setReturnUrl($value)
- {
- $this->getSession()->add($this->getReturnUrlVarName(),$value);
- }
-
- /**
- * @return boolean whether to allow remembering login so that the user logs on automatically next time. Defaults to false.
- * @since 3.1.1
- */
- public function getAllowAutoLogin()
- {
- return $this->_allowAutoLogin;
- }
-
- /**
- * @param boolean whether to allow remembering login so that the user logs on automatically next time. Users have to enable cookie to make use of this feature.
- * @since 3.1.1
- */
- public function setAllowAutoLogin($value)
- {
- $this->_allowAutoLogin=TPropertyValue::ensureBoolean($value);
- }
-
- /**
- * @return integer authentication expiration time in seconds. Defaults to zero (no expiration).
- * @since 3.1.3
- */
- public function getAuthExpire()
- {
- return $this->_authExpire;
- }
-
- /**
- * @param integer authentication expiration time in seconds. Defaults to zero (no expiration).
- * @since 3.1.3
- */
- public function setAuthExpire($value)
- {
- $this->_authExpire=TPropertyValue::ensureInteger($value);
- }
-
- /**
- * Performs the real authentication work.
- * An OnAuthenticate event will be raised if there is any handler attached to it.
- * If the application already has a non-null user, it will return without further authentication.
- * Otherwise, user information will be restored from session data.
- * @param mixed parameter to be passed to OnAuthenticate event
- * @throws TConfigurationException if session module does not exist.
- */
- public function onAuthenticate($param)
- {
- $application=$this->getApplication();
-
- // restoring user info from session
- if(($session=$application->getSession())===null)
- throw new TConfigurationException('authmanager_session_required');
- $session->open();
- $sessionInfo=$session->itemAt($this->getUserKey());
- $user=$this->_userManager->getUser(null)->loadFromString($sessionInfo);
-
- // check for authentication expiration
- $isAuthExpired = $this->_authExpire>0 && !$user->getIsGuest() &&
- ($expiretime=$session->itemAt('AuthExpireTime')) && $expiretime<time();
-
- // try authenticating through cookie if possible
- if($this->getAllowAutoLogin() && ($user->getIsGuest() || $isAuthExpired))
- {
- $cookie=$this->getRequest()->getCookies()->itemAt($this->getUserKey());
- if($cookie instanceof THttpCookie)
- {
- if(($user2=$this->_userManager->getUserFromCookie($cookie))!==null)
- {
- $user=$user2;
- $this->updateSessionUser($user);
- // user is restored from cookie, auth may not expire
- $isAuthExpired = false;
- }
- }
- }
-
- $application->setUser($user);
-
- // handle authentication expiration or update expiration time
- if($isAuthExpired)
- $this->onAuthExpire($param);
- else
- $session->add('AuthExpireTime', time() + $this->_authExpire);
-
- // event handler gets a chance to do further auth work
- if($this->hasEventHandler('OnAuthenticate'))
- $this->raiseEvent('OnAuthenticate',$this,$application);
- }
-
- /**
- * Performs user logout on authentication expiration.
- * An 'OnAuthExpire' event will be raised if there is any handler attached to it.
- * @param mixed parameter to be passed to OnAuthExpire event.
- */
- public function onAuthExpire($param)
- {
- $this->logout();
- if($this->hasEventHandler('OnAuthExpire'))
- $this->raiseEvent('OnAuthExpire',$this,$param);
- }
-
- /**
- * Performs the real authorization work.
- * Authorization rules obtained from the application will be used to check
- * if a user is allowed. If authorization fails, the response status code
- * will be set as 401 and the application terminates.
- * @param mixed parameter to be passed to OnAuthorize event
- */
- public function onAuthorize($param)
- {
- $application=$this->getApplication();
- if($this->hasEventHandler('OnAuthorize'))
- $this->raiseEvent('OnAuthorize',$this,$application);
- if(!$application->getAuthorizationRules()->isUserAllowed($application->getUser(),$application->getRequest()->getRequestType(),$application->getRequest()->getUserHostAddress()))
- {
- $application->getResponse()->setStatusCode(401);
- $application->completeRequest();
- }
- }
-
- /**
- * @return string a unique variable name for storing user session/cookie data
- * @since 3.1.1
- */
- public function getUserKey()
- {
- if($this->_userKey===null)
- $this->_userKey=$this->generateUserKey();
- return $this->_userKey;
- }
-
- /**
- * @return string a key used to store user information in session
- * @since 3.1.1
- */
- protected function generateUserKey()
- {
- return md5($this->getApplication()->getUniqueID().'prado:user');
- }
-
- /**
- * Updates the user data stored in session.
- * @param IUser user object
- * @throws new TConfigurationException if session module is not loaded.
- */
- public function updateSessionUser($user)
- {
- if(!$user->getIsGuest())
- {
- if(($session=$this->getSession())===null)
- throw new TConfigurationException('authmanager_session_required');
- else
- $session->add($this->getUserKey(),$user->saveToString());
- }
- }
-
- /**
- * Switches to a new user.
- * This method will logout the current user first and login with a new one (without password.)
- * @param string the new username
- * @return boolean if the switch is successful
- */
- public function switchUser($username)
- {
- if(($user=$this->_userManager->getUser($username))===null)
- return false;
- $this->updateSessionUser($user);
- $this->getApplication()->setUser($user);
- return true;
- }
-
- /**
- * Logs in a user with username and password.
- * The username and password will be used to validate if login is successful.
- * If yes, a user object will be created for the application.
- * @param string username
- * @param string password
- * @param integer number of seconds that automatic login will remain effective. If 0, it means user logs out when session ends. This parameter is added since 3.1.1.
- * @return boolean if login is successful
- */
- public function login($username,$password,$expire=0)
- {
- if($this->_userManager->validateUser($username,$password))
- {
- if(($user=$this->_userManager->getUser($username))===null)
- return false;
- $this->updateSessionUser($user);
- $this->getApplication()->setUser($user);
-
- if($expire>0)
- {
- $cookie=new THttpCookie($this->getUserKey(),'');
- $cookie->setExpire(time()+$expire);
- $this->_userManager->saveUserToCookie($cookie);
- $this->getResponse()->getCookies()->add($cookie);
- }
- return true;
- }
- else
- return false;
- }
-
- /**
- * Logs out a user.
- * User session will be destroyed after this method is called.
- * @throws TConfigurationException if session module is not loaded.
- */
- public function logout()
- {
- if(($session=$this->getSession())===null)
- throw new TConfigurationException('authmanager_session_required');
- $this->getApplication()->getUser()->setIsGuest(true);
- $session->destroy();
- if($this->getAllowAutoLogin())
- {
- $cookie=new THttpCookie($this->getUserKey(),'');
- $this->getResponse()->getCookies()->add($cookie);
- }
- }
-}
-
-?>
+<?php
+/**
+ * TAuthManager class file
+ *
+ * @author Qiang Xue <qiang.xue@gmail.com>
+ * @link http://www.pradosoft.com/
+ * @copyright Copyright &copy; 2005-2012 PradoSoft
+ * @license http://www.pradosoft.com/license/
+ * @version $Id$
+ * @package System.Security
+ */
+
+/**
+ * Using IUserManager interface
+ */
+Prado::using('System.Security.IUserManager');
+
+/**
+ * TAuthManager class
+ *
+ * TAuthManager performs user authentication and authorization for a Prado application.
+ * TAuthManager works together with a {@link IUserManager} module that can be
+ * specified via the {@link setUserManager UserManager} property.
+ * If an authorization fails, TAuthManager will try to redirect the client
+ * browser to a login page that is specified via the {@link setLoginPage LoginPage}.
+ * To login or logout a user, call {@link login} or {@link logout}, respectively.
+ *
+ * The {@link setAuthExpire AuthExpire} property can be used to define the time
+ * in seconds after which the authentication should expire.
+ * {@link setAllowAutoLogin AllowAutoLogin} specifies if the login information
+ * should be stored in a cookie to perform automatic login. Enabling this
+ * feature will cause that {@link setAuthExpire AuthExpire} has no effect
+ * since the user will be logged in again on authentication expiration.
+ *
+ * To load TAuthManager, configure it in application configuration as follows,
+ * <module id="auth" class="System.Security.TAuthManager" UserManager="users" LoginPage="login" />
+ * <module id="users" class="System.Security.TUserManager" />
+ *
+ * @author Qiang Xue <qiang.xue@gmail.com>
+ * @version $Id$
+ * @package System.Security
+ * @since 3.0
+ */
+class TAuthManager extends TModule
+{
+ /**
+ * GET variable name for return url
+ */
+ const RETURN_URL_VAR='ReturnUrl';
+ /**
+ * @var boolean if the module has been initialized
+ */
+ private $_initialized=false;
+ /**
+ * @var IUserManager user manager instance
+ */
+ private $_userManager;
+ /**
+ * @var string login page
+ */
+ private $_loginPage;
+ /**
+ * @var boolean whether authorization should be skipped
+ */
+ private $_skipAuthorization=false;
+ /**
+ * @var string the session var name for storing return URL
+ */
+ private $_returnUrlVarName;
+ /**
+ * @var boolean whether to allow auto login (using cookie)
+ */
+ private $_allowAutoLogin=false;
+ /**
+ * @var string variable name used to store user session or cookie
+ */
+ private $_userKey;
+ /**
+ * @var integer authentication expiration time in seconds. Defaults to zero (no expiration)
+ */
+ private $_authExpire=0;
+
+ /**
+ * Initializes this module.
+ * This method is required by the IModule interface.
+ * @param TXmlElement configuration for this module, can be null
+ * @throws TConfigurationException if user manager does not exist or is not IUserManager
+ */
+ public function init($config)
+ {
+ if($this->_userManager===null)
+ throw new TConfigurationException('authmanager_usermanager_required');
+ if($this->_returnUrlVarName===null)
+ $this->_returnUrlVarName=$this->getApplication()->getID().':'.self::RETURN_URL_VAR;
+ $application=$this->getApplication();
+ if(is_string($this->_userManager))
+ {
+ if(($users=$application->getModule($this->_userManager))===null)
+ throw new TConfigurationException('authmanager_usermanager_inexistent',$this->_userManager);
+ if(!($users instanceof IUserManager))
+ throw new TConfigurationException('authmanager_usermanager_invalid',$this->_userManager);
+ $this->_userManager=$users;
+ }
+ $application->attachEventHandler('OnAuthentication',array($this,'doAuthentication'));
+ $application->attachEventHandler('OnEndRequest',array($this,'leave'));
+ $application->attachEventHandler('OnAuthorization',array($this,'doAuthorization'));
+ $this->_initialized=true;
+ }
+
+ /**
+ * @return IUserManager user manager instance
+ */
+ public function getUserManager()
+ {
+ return $this->_userManager;
+ }
+
+ /**
+ * @param string|IUserManager the user manager module ID or the user manager object
+ * @throws TInvalidOperationException if the module has been initialized or the user manager object is not IUserManager
+ */
+ public function setUserManager($provider)
+ {
+ if($this->_initialized)
+ throw new TInvalidOperationException('authmanager_usermanager_unchangeable');
+ if(!is_string($provider) && !($provider instanceof IUserManager))
+ throw new TConfigurationException('authmanager_usermanager_invalid',$this->_userManager);
+ $this->_userManager=$provider;
+ }
+
+ /**
+ * @return string path of login page should login is required
+ */
+ public function getLoginPage()
+ {
+ return $this->_loginPage;
+ }
+
+ /**
+ * Sets the login page that the client browser will be redirected to if login is needed.
+ * Login page should be specified in the format of page path.
+ * @param string path of login page should login is required
+ * @see TPageService
+ */
+ public function setLoginPage($pagePath)
+ {
+ $this->_loginPage=$pagePath;
+ }
+
+ /**
+ * Performs authentication.
+ * This is the event handler attached to application's Authentication event.
+ * Do not call this method directly.
+ * @param mixed sender of the Authentication event
+ * @param mixed event parameter
+ */
+ public function doAuthentication($sender,$param)
+ {
+ $this->onAuthenticate($param);
+
+ $service=$this->getService();
+ if(($service instanceof TPageService) && $service->getRequestedPagePath()===$this->getLoginPage())
+ $this->_skipAuthorization=true;
+ }
+
+ /**
+ * Performs authorization.
+ * This is the event handler attached to application's Authorization event.
+ * Do not call this method directly.
+ * @param mixed sender of the Authorization event
+ * @param mixed event parameter
+ */
+ public function doAuthorization($sender,$param)
+ {
+ if(!$this->_skipAuthorization)
+ {
+ $this->onAuthorize($param);
+ }
+ }
+
+ /**
+ * Performs login redirect if authorization fails.
+ * This is the event handler attached to application's EndRequest event.
+ * Do not call this method directly.
+ * @param mixed sender of the event
+ * @param mixed event parameter
+ */
+ public function leave($sender,$param)
+ {
+ $application=$this->getApplication();
+ if($application->getResponse()->getStatusCode()===401)
+ {
+ $service=$application->getService();
+ if($service instanceof TPageService)
+ {
+ $returnUrl=$application->getRequest()->getRequestUri();
+ $this->setReturnUrl($returnUrl);
+ $url=$service->constructUrl($this->getLoginPage());
+ $application->getResponse()->redirect($url);
+ }
+ }
+ }
+
+ /**
+ * @return string the name of the session variable storing return URL. It defaults to 'AppID:ReturnUrl'
+ */
+ public function getReturnUrlVarName()
+ {
+ return $this->_returnUrlVarName;
+ }
+
+ /**
+ * @param string the name of the session variable storing return URL.
+ */
+ public function setReturnUrlVarName($value)
+ {
+ $this->_returnUrlVarName=$value;
+ }
+
+ /**
+ * @return string URL that the browser should be redirected to when login succeeds.
+ */
+ public function getReturnUrl()
+ {
+ return $this->getSession()->itemAt($this->getReturnUrlVarName());
+ }
+
+ /**
+ * Sets the URL that the browser should be redirected to when login succeeds.
+ * @param string the URL to be redirected to.
+ */
+ public function setReturnUrl($value)
+ {
+ $this->getSession()->add($this->getReturnUrlVarName(),$value);
+ }
+
+ /**
+ * @return boolean whether to allow remembering login so that the user logs on automatically next time. Defaults to false.
+ * @since 3.1.1
+ */
+ public function getAllowAutoLogin()
+ {
+ return $this->_allowAutoLogin;
+ }
+
+ /**
+ * @param boolean whether to allow remembering login so that the user logs on automatically next time. Users have to enable cookie to make use of this feature.
+ * @since 3.1.1
+ */
+ public function setAllowAutoLogin($value)
+ {
+ $this->_allowAutoLogin=TPropertyValue::ensureBoolean($value);
+ }
+
+ /**
+ * @return integer authentication expiration time in seconds. Defaults to zero (no expiration).
+ * @since 3.1.3
+ */
+ public function getAuthExpire()
+ {
+ return $this->_authExpire;
+ }
+
+ /**
+ * @param integer authentication expiration time in seconds. Defaults to zero (no expiration).
+ * @since 3.1.3
+ */
+ public function setAuthExpire($value)
+ {
+ $this->_authExpire=TPropertyValue::ensureInteger($value);
+ }
+
+ /**
+ * Performs the real authentication work.
+ * An OnAuthenticate event will be raised if there is any handler attached to it.
+ * If the application already has a non-null user, it will return without further authentication.
+ * Otherwise, user information will be restored from session data.
+ * @param mixed parameter to be passed to OnAuthenticate event
+ * @throws TConfigurationException if session module does not exist.
+ */
+ public function onAuthenticate($param)
+ {
+ $application=$this->getApplication();
+
+ // restoring user info from session
+ if(($session=$application->getSession())===null)
+ throw new TConfigurationException('authmanager_session_required');
+ $session->open();
+ $sessionInfo=$session->itemAt($this->getUserKey());
+ $user=$this->_userManager->getUser(null)->loadFromString($sessionInfo);
+
+ // check for authentication expiration
+ $isAuthExpired = $this->_authExpire>0 && !$user->getIsGuest() &&
+ ($expiretime=$session->itemAt('AuthExpireTime')) && $expiretime<time();
+
+ // try authenticating through cookie if possible
+ if($this->getAllowAutoLogin() && ($user->getIsGuest() || $isAuthExpired))
+ {
+ $cookie=$this->getRequest()->getCookies()->itemAt($this->getUserKey());
+ if($cookie instanceof THttpCookie)
+ {
+ if(($user2=$this->_userManager->getUserFromCookie($cookie))!==null)
+ {
+ $user=$user2;
+ $this->updateSessionUser($user);
+ // user is restored from cookie, auth may not expire
+ $isAuthExpired = false;
+ }
+ }
+ }
+
+ $application->setUser($user);
+
+ // handle authentication expiration or update expiration time
+ if($isAuthExpired)
+ $this->onAuthExpire($param);
+ else
+ $session->add('AuthExpireTime', time() + $this->_authExpire);
+
+ // event handler gets a chance to do further auth work
+ if($this->hasEventHandler('OnAuthenticate'))
+ $this->raiseEvent('OnAuthenticate',$this,$application);
+ }
+
+ /**
+ * Performs user logout on authentication expiration.
+ * An 'OnAuthExpire' event will be raised if there is any handler attached to it.
+ * @param mixed parameter to be passed to OnAuthExpire event.
+ */
+ public function onAuthExpire($param)
+ {
+ $this->logout();
+ if($this->hasEventHandler('OnAuthExpire'))
+ $this->raiseEvent('OnAuthExpire',$this,$param);
+ }
+
+ /**
+ * Performs the real authorization work.
+ * Authorization rules obtained from the application will be used to check
+ * if a user is allowed. If authorization fails, the response status code
+ * will be set as 401 and the application terminates.
+ * @param mixed parameter to be passed to OnAuthorize event
+ */
+ public function onAuthorize($param)
+ {
+ $application=$this->getApplication();
+ if($this->hasEventHandler('OnAuthorize'))
+ $this->raiseEvent('OnAuthorize',$this,$application);
+ if(!$application->getAuthorizationRules()->isUserAllowed($application->getUser(),$application->getRequest()->getRequestType(),$application->getRequest()->getUserHostAddress()))
+ {
+ $application->getResponse()->setStatusCode(401);
+ $application->completeRequest();
+ }
+ }
+
+ /**
+ * @return string a unique variable name for storing user session/cookie data
+ * @since 3.1.1
+ */
+ public function getUserKey()
+ {
+ if($this->_userKey===null)
+ $this->_userKey=$this->generateUserKey();
+ return $this->_userKey;
+ }
+
+ /**
+ * @return string a key used to store user information in session
+ * @since 3.1.1
+ */
+ protected function generateUserKey()
+ {
+ return md5($this->getApplication()->getUniqueID().'prado:user');
+ }
+
+ /**
+ * Updates the user data stored in session.
+ * @param IUser user object
+ * @throws new TConfigurationException if session module is not loaded.
+ */
+ public function updateSessionUser($user)
+ {
+ if(!$user->getIsGuest())
+ {
+ if(($session=$this->getSession())===null)
+ throw new TConfigurationException('authmanager_session_required');
+ else
+ $session->add($this->getUserKey(),$user->saveToString());
+ }
+ }
+
+ /**
+ * Switches to a new user.
+ * This method will logout the current user first and login with a new one (without password.)
+ * @param string the new username
+ * @return boolean if the switch is successful
+ */
+ public function switchUser($username)
+ {
+ if(($user=$this->_userManager->getUser($username))===null)
+ return false;
+ $this->updateSessionUser($user);
+ $this->getApplication()->setUser($user);
+ return true;
+ }
+
+ /**
+ * Logs in a user with username and password.
+ * The username and password will be used to validate if login is successful.
+ * If yes, a user object will be created for the application.
+ * @param string username
+ * @param string password
+ * @param integer number of seconds that automatic login will remain effective. If 0, it means user logs out when session ends. This parameter is added since 3.1.1.
+ * @return boolean if login is successful
+ */
+ public function login($username,$password,$expire=0)
+ {
+ if($this->_userManager->validateUser($username,$password))
+ {
+ if(($user=$this->_userManager->getUser($username))===null)
+ return false;
+ $this->updateSessionUser($user);
+ $this->getApplication()->setUser($user);
+
+ if($expire>0)
+ {
+ $cookie=new THttpCookie($this->getUserKey(),'');
+ $cookie->setExpire(time()+$expire);
+ $this->_userManager->saveUserToCookie($cookie);
+ $this->getResponse()->getCookies()->add($cookie);
+ }
+ return true;
+ }
+ else
+ return false;
+ }
+
+ /**
+ * Logs out a user.
+ * User session will be destroyed after this method is called.
+ * @throws TConfigurationException if session module is not loaded.
+ */
+ public function logout()
+ {
+ if(($session=$this->getSession())===null)
+ throw new TConfigurationException('authmanager_session_required');
+ $this->getApplication()->getUser()->setIsGuest(true);
+ $session->destroy();
+ if($this->getAllowAutoLogin())
+ {
+ $cookie=new THttpCookie($this->getUserKey(),'');
+ $this->getResponse()->getCookies()->add($cookie);
+ }
+ }
+}
+
+?>
diff --git a/framework/Security/TAuthorizationRule.php b/framework/Security/TAuthorizationRule.php
index 6c12d301..4eb32b10 100644
--- a/framework/Security/TAuthorizationRule.php
+++ b/framework/Security/TAuthorizationRule.php
@@ -1,296 +1,296 @@
-<?php
-/**
- * TAuthorizationRule, TAuthorizationRuleCollection class file
- *
- * @author Qiang Xue <qiang.xue@gmail.com>
- * @link http://www.pradosoft.com/
+<?php
+/**
+ * TAuthorizationRule, TAuthorizationRuleCollection class file
+ *
+ * @author Qiang Xue <qiang.xue@gmail.com>
+ * @link http://www.pradosoft.com/
* @copyright Copyright &copy; 2005-2012 PradoSoft
- * @license http://www.pradosoft.com/license/
- * @version $Id$
- * @package System.Security
- */
-/**
- * TAuthorizationRule class
- *
- * TAuthorizationRule represents a single authorization rule.
- * A rule is specified by an action (required), a list of users (optional),
- * a list of roles (optional), a verb (optional), and a list of IP rules (optional).
- * Action can be either 'allow' or 'deny'.
- * Guest (anonymous, unauthenticated) users are represented by question mark '?'.
- * All users (including guest users) are represented by asterisk '*'.
- * Authenticated users are represented by '@'.
- * Users/roles are case-insensitive.
- * Different users/roles are separated by comma ','.
- * Verb can be either 'get' or 'post'. If it is absent, it means both.
- * IP rules are separated by comma ',' and can contain wild card in the rules (e.g. '192.132.23.33, 192.122.*.*')
- *
- * @author Qiang Xue <qiang.xue@gmail.com>
- * @version $Id$
- * @package System.Security
- * @since 3.0
- */
-class TAuthorizationRule extends TComponent
-{
- /**
- * @var string action, either 'allow' or 'deny'
- */
- private $_action;
- /**
- * @var array list of user IDs
- */
- private $_users;
- /**
- * @var array list of roles
- */
- private $_roles;
- /**
- * @var string verb, may be empty, 'get', or 'post'.
- */
- private $_verb;
- /**
- * @var string IP patterns
- */
- private $_ipRules;
- /**
- * @var boolean if this rule applies to everyone
- */
- private $_everyone;
- /**
- * @var boolean if this rule applies to guest user
- */
- private $_guest;
- /**
- * @var boolean if this rule applies to authenticated users
- */
- private $_authenticated;
-
- /**
- * Constructor.
- * @param string action, either 'deny' or 'allow'
- * @param string a comma separated user list
- * @param string a comma separated role list
- * @param string verb, can be empty, 'get', or 'post'
- * @param string IP rules (separated by comma, can contain wild card *)
- */
- public function __construct($action,$users,$roles,$verb='',$ipRules='')
- {
- $action=strtolower(trim($action));
- if($action==='allow' || $action==='deny')
- $this->_action=$action;
- else
- throw new TInvalidDataValueException('authorizationrule_action_invalid',$action);
- $this->_users=array();
- $this->_roles=array();
- $this->_ipRules=array();
- $this->_everyone=false;
- $this->_guest=false;
- $this->_authenticated=false;
-
- if(trim($users)==='')
- $users='*';
- foreach(explode(',',$users) as $user)
- {
- if(($user=trim(strtolower($user)))!=='')
- {
- if($user==='*')
- {
- $this->_everyone=true;
- break;
- }
- else if($user==='?')
- $this->_guest=true;
- else if($user==='@')
- $this->_authenticated=true;
- else
- $this->_users[]=$user;
- }
- }
-
- if(trim($roles)==='')
- $roles='*';
- foreach(explode(',',$roles) as $role)
- {
- if(($role=trim(strtolower($role)))!=='')
- $this->_roles[]=$role;
- }
-
- if(($verb=trim(strtolower($verb)))==='')
- $verb='*';
- if($verb==='*' || $verb==='get' || $verb==='post')
- $this->_verb=$verb;
- else
- throw new TInvalidDataValueException('authorizationrule_verb_invalid',$verb);
-
- if(trim($ipRules)==='')
- $ipRules='*';
- foreach(explode(',',$ipRules) as $ipRule)
- {
- if(($ipRule=trim($ipRule))!=='')
- $this->_ipRules[]=$ipRule;
- }
- }
-
- /**
- * @return string action, either 'allow' or 'deny'
- */
- public function getAction()
- {
- return $this->_action;
- }
-
- /**
- * @return array list of user IDs
- */
- public function getUsers()
- {
- return $this->_users;
- }
-
- /**
- * @return array list of roles
- */
- public function getRoles()
- {
- return $this->_roles;
- }
-
- /**
- * @return string verb, may be empty, 'get', or 'post'.
- */
- public function getVerb()
- {
- return $this->_verb;
- }
-
- /**
- * @return array list of IP rules.
- * @since 3.1.1
- */
- public function getIPRules()
- {
- return $this->_ipRules;
- }
-
- /**
- * @return boolean if this rule applies to everyone
- */
- public function getGuestApplied()
- {
- return $this->_guest || $this->_everyone;
- }
-
- /**
- * @return boolean if this rule applies to everyone
- */
- public function getEveryoneApplied()
- {
- return $this->_everyone;
- }
-
- /**
- * @return boolean if this rule applies to authenticated users
- */
- public function getAuthenticatedApplied()
- {
- return $this->_authenticated || $this->_everyone;
- }
-
- /**
- * @param IUser the user object
- * @param string the request verb (GET, PUT)
- * @param string the request IP address
- * @return integer 1 if the user is allowed, -1 if the user is denied, 0 if the rule does not apply to the user
- */
- public function isUserAllowed(IUser $user,$verb,$ip)
- {
- if($this->isVerbMatched($verb) && $this->isIpMatched($ip) && $this->isUserMatched($user) && $this->isRoleMatched($user))
- return ($this->_action==='allow')?1:-1;
- else
- return 0;
- }
-
- private function isIpMatched($ip)
- {
- if(empty($this->_ipRules))
- return 1;
- foreach($this->_ipRules as $rule)
- {
- if($rule==='*' || $rule===$ip || (($pos=strpos($rule,'*'))!==false && strncmp($ip,$rule,$pos)===0))
- return 1;
- }
- return 0;
- }
-
- private function isUserMatched($user)
- {
- return ($this->_everyone || ($this->_guest && $user->getIsGuest()) || ($this->_authenticated && !$user->getIsGuest()) || in_array(strtolower($user->getName()),$this->_users));
- }
-
- private function isRoleMatched($user)
- {
- foreach($this->_roles as $role)
- {
- if($role==='*' || $user->isInRole($role))
- return true;
- }
- return false;
- }
-
- private function isVerbMatched($verb)
- {
- return ($this->_verb==='*' || strcasecmp($verb,$this->_verb)===0);
- }
-}
-
-
-/**
- * TAuthorizationRuleCollection class.
- * TAuthorizationRuleCollection represents a collection of authorization rules {@link TAuthorizationRule}.
- * To check if a user is allowed, call {@link isUserAllowed}.
- *
- * @author Qiang Xue <qiang.xue@gmail.com>
- * @version $Id$
- * @package System.Security
- * @since 3.0
- */
-class TAuthorizationRuleCollection extends TList
-{
- /**
- * @param IUser the user to be authorized
- * @param string verb, can be empty, 'post' or 'get'.
- * @param string the request IP address
- * @return boolean whether the user is allowed
- */
- public function isUserAllowed($user,$verb,$ip)
- {
- if($user instanceof IUser)
- {
- $verb=strtolower(trim($verb));
- foreach($this as $rule)
- {
- if(($decision=$rule->isUserAllowed($user,$verb,$ip))!==0)
- return ($decision>0);
- }
- return true;
- }
- else
- return false;
- }
-
- /**
- * Inserts an item at the specified position.
- * This overrides the parent implementation by performing additional
- * operations for each newly added TAuthorizationRule object.
- * @param integer the specified position.
- * @param mixed new item
- * @throws TInvalidDataTypeException if the item to be inserted is not a TAuthorizationRule object.
- */
- public function insertAt($index,$item)
- {
- if($item instanceof TAuthorizationRule)
- parent::insertAt($index,$item);
- else
- throw new TInvalidDataTypeException('authorizationrulecollection_authorizationrule_required');
- }
-}
-
+ * @license http://www.pradosoft.com/license/
+ * @version $Id$
+ * @package System.Security
+ */
+/**
+ * TAuthorizationRule class
+ *
+ * TAuthorizationRule represents a single authorization rule.
+ * A rule is specified by an action (required), a list of users (optional),
+ * a list of roles (optional), a verb (optional), and a list of IP rules (optional).
+ * Action can be either 'allow' or 'deny'.
+ * Guest (anonymous, unauthenticated) users are represented by question mark '?'.
+ * All users (including guest users) are represented by asterisk '*'.
+ * Authenticated users are represented by '@'.
+ * Users/roles are case-insensitive.
+ * Different users/roles are separated by comma ','.
+ * Verb can be either 'get' or 'post'. If it is absent, it means both.
+ * IP rules are separated by comma ',' and can contain wild card in the rules (e.g. '192.132.23.33, 192.122.*.*')
+ *
+ * @author Qiang Xue <qiang.xue@gmail.com>
+ * @version $Id$
+ * @package System.Security
+ * @since 3.0
+ */
+class TAuthorizationRule extends TComponent
+{
+ /**
+ * @var string action, either 'allow' or 'deny'
+ */
+ private $_action;
+ /**
+ * @var array list of user IDs
+ */
+ private $_users;
+ /**
+ * @var array list of roles
+ */
+ private $_roles;
+ /**
+ * @var string verb, may be empty, 'get', or 'post'.
+ */
+ private $_verb;
+ /**
+ * @var string IP patterns
+ */
+ private $_ipRules;
+ /**
+ * @var boolean if this rule applies to everyone
+ */
+ private $_everyone;
+ /**
+ * @var boolean if this rule applies to guest user
+ */
+ private $_guest;
+ /**
+ * @var boolean if this rule applies to authenticated users
+ */
+ private $_authenticated;
+
+ /**
+ * Constructor.
+ * @param string action, either 'deny' or 'allow'
+ * @param string a comma separated user list
+ * @param string a comma separated role list
+ * @param string verb, can be empty, 'get', or 'post'
+ * @param string IP rules (separated by comma, can contain wild card *)
+ */
+ public function __construct($action,$users,$roles,$verb='',$ipRules='')
+ {
+ $action=strtolower(trim($action));
+ if($action==='allow' || $action==='deny')
+ $this->_action=$action;
+ else
+ throw new TInvalidDataValueException('authorizationrule_action_invalid',$action);
+ $this->_users=array();
+ $this->_roles=array();
+ $this->_ipRules=array();
+ $this->_everyone=false;
+ $this->_guest=false;
+ $this->_authenticated=false;
+
+ if(trim($users)==='')
+ $users='*';
+ foreach(explode(',',$users) as $user)
+ {
+ if(($user=trim(strtolower($user)))!=='')
+ {
+ if($user==='*')
+ {
+ $this->_everyone=true;
+ break;
+ }
+ else if($user==='?')
+ $this->_guest=true;
+ else if($user==='@')
+ $this->_authenticated=true;
+ else
+ $this->_users[]=$user;
+ }
+ }
+
+ if(trim($roles)==='')
+ $roles='*';
+ foreach(explode(',',$roles) as $role)
+ {
+ if(($role=trim(strtolower($role)))!=='')
+ $this->_roles[]=$role;
+ }
+
+ if(($verb=trim(strtolower($verb)))==='')
+ $verb='*';
+ if($verb==='*' || $verb==='get' || $verb==='post')
+ $this->_verb=$verb;
+ else
+ throw new TInvalidDataValueException('authorizationrule_verb_invalid',$verb);
+
+ if(trim($ipRules)==='')
+ $ipRules='*';
+ foreach(explode(',',$ipRules) as $ipRule)
+ {
+ if(($ipRule=trim($ipRule))!=='')
+ $this->_ipRules[]=$ipRule;
+ }
+ }
+
+ /**
+ * @return string action, either 'allow' or 'deny'
+ */
+ public function getAction()
+ {
+ return $this->_action;
+ }
+
+ /**
+ * @return array list of user IDs
+ */
+ public function getUsers()
+ {
+ return $this->_users;
+ }
+
+ /**
+ * @return array list of roles
+ */
+ public function getRoles()
+ {
+ return $this->_roles;
+ }
+
+ /**
+ * @return string verb, may be empty, 'get', or 'post'.
+ */
+ public function getVerb()
+ {
+ return $this->_verb;
+ }
+
+ /**
+ * @return array list of IP rules.
+ * @since 3.1.1
+ */
+ public function getIPRules()
+ {
+ return $this->_ipRules;
+ }
+
+ /**
+ * @return boolean if this rule applies to everyone
+ */
+ public function getGuestApplied()
+ {
+ return $this->_guest || $this->_everyone;
+ }
+
+ /**
+ * @return boolean if this rule applies to everyone
+ */
+ public function getEveryoneApplied()
+ {
+ return $this->_everyone;
+ }
+
+ /**
+ * @return boolean if this rule applies to authenticated users
+ */
+ public function getAuthenticatedApplied()
+ {
+ return $this->_authenticated || $this->_everyone;
+ }
+
+ /**
+ * @param IUser the user object
+ * @param string the request verb (GET, PUT)
+ * @param string the request IP address
+ * @return integer 1 if the user is allowed, -1 if the user is denied, 0 if the rule does not apply to the user
+ */
+ public function isUserAllowed(IUser $user,$verb,$ip)
+ {
+ if($this->isVerbMatched($verb) && $this->isIpMatched($ip) && $this->isUserMatched($user) && $this->isRoleMatched($user))
+ return ($this->_action==='allow')?1:-1;
+ else
+ return 0;
+ }
+
+ private function isIpMatched($ip)
+ {
+ if(empty($this->_ipRules))
+ return 1;
+ foreach($this->_ipRules as $rule)
+ {
+ if($rule==='*' || $rule===$ip || (($pos=strpos($rule,'*'))!==false && strncmp($ip,$rule,$pos)===0))
+ return 1;
+ }
+ return 0;
+ }
+
+ private function isUserMatched($user)
+ {
+ return ($this->_everyone || ($this->_guest && $user->getIsGuest()) || ($this->_authenticated && !$user->getIsGuest()) || in_array(strtolower($user->getName()),$this->_users));
+ }
+
+ private function isRoleMatched($user)
+ {
+ foreach($this->_roles as $role)
+ {
+ if($role==='*' || $user->isInRole($role))
+ return true;
+ }
+ return false;
+ }
+
+ private function isVerbMatched($verb)
+ {
+ return ($this->_verb==='*' || strcasecmp($verb,$this->_verb)===0);
+ }
+}
+
+
+/**
+ * TAuthorizationRuleCollection class.
+ * TAuthorizationRuleCollection represents a collection of authorization rules {@link TAuthorizationRule}.
+ * To check if a user is allowed, call {@link isUserAllowed}.
+ *
+ * @author Qiang Xue <qiang.xue@gmail.com>
+ * @version $Id$
+ * @package System.Security
+ * @since 3.0
+ */
+class TAuthorizationRuleCollection extends TList
+{
+ /**
+ * @param IUser the user to be authorized
+ * @param string verb, can be empty, 'post' or 'get'.
+ * @param string the request IP address
+ * @return boolean whether the user is allowed
+ */
+ public function isUserAllowed($user,$verb,$ip)
+ {
+ if($user instanceof IUser)
+ {
+ $verb=strtolower(trim($verb));
+ foreach($this as $rule)
+ {
+ if(($decision=$rule->isUserAllowed($user,$verb,$ip))!==0)
+ return ($decision>0);
+ }
+ return true;
+ }
+ else
+ return false;
+ }
+
+ /**
+ * Inserts an item at the specified position.
+ * This overrides the parent implementation by performing additional
+ * operations for each newly added TAuthorizationRule object.
+ * @param integer the specified position.
+ * @param mixed new item
+ * @throws TInvalidDataTypeException if the item to be inserted is not a TAuthorizationRule object.
+ */
+ public function insertAt($index,$item)
+ {
+ if($item instanceof TAuthorizationRule)
+ parent::insertAt($index,$item);
+ else
+ throw new TInvalidDataTypeException('authorizationrulecollection_authorizationrule_required');
+ }
+}
+
diff --git a/framework/Security/TDbUserManager.php b/framework/Security/TDbUserManager.php
index 11dcdadd..8c875148 100644
--- a/framework/Security/TDbUserManager.php
+++ b/framework/Security/TDbUserManager.php
@@ -1,320 +1,320 @@
-<?php
-/**
- * TDbUserManager class
- *
- * @author Qiang Xue <qiang.xue@gmail.com>
- * @link http://www.pradosoft.com/
+<?php
+/**
+ * TDbUserManager class
+ *
+ * @author Qiang Xue <qiang.xue@gmail.com>
+ * @link http://www.pradosoft.com/
* @copyright Copyright &copy; 2005-2012 PradoSoft
- * @license http://www.pradosoft.com/license/
- * @version $Id$
- * @package System.Security
- */
-
-/**
- * Using IUserManager interface
- */
-Prado::using('System.Security.IUserManager');
-Prado::using('System.Data.TDataSourceConfig');
-Prado::using('System.Security.TUser');
-
-/**
- * TDbUserManager class
- *
- * TDbUserManager manages user accounts that are stored in a database.
- * TDbUserManager is mainly designed to be used together with {@link TAuthManager}
- * which manages how users are authenticated and authorized in a Prado application.
- *
- * To use TDbUserManager together with TAuthManager, configure them in
- * the application configuration like following:
- * <code>
- * <module id="db"
- * class="System.Data.TDataSourceConfig" ..../>
- * <module id="users"
- * class="System.Security.TDbUserManager"
- * UserClass="Path.To.MyUserClass"
- * ConnectionID="db" />
- * <module id="auth"
- * class="System.Security.TAuthManager"
- * UserManager="users" LoginPage="Path.To.LoginPage" />
- * </code>
- *
- * In the above, {@link setUserClass UserClass} specifies what class will be used
- * to create user instance. The class must extend from {@link TDbUser}.
- * {@link setConnectionID ConnectionID} refers to the ID of a {@link TDataSourceConfig} module
- * which specifies how to establish database connection to retrieve user information.
- *
- * @author Qiang Xue <qiang.xue@gmail.com>
- * @version $Id$
- * @package System.Security
- * @since 3.1.0
- */
-class TDbUserManager extends TModule implements IUserManager
-{
- private $_connID='';
- private $_conn;
- private $_guestName='Guest';
- private $_userClass='';
- private $_userFactory;
-
- /**
- * Initializes the module.
- * This method is required by IModule and is invoked by application.
- * @param TXmlElement module configuration
- */
- public function init($config)
- {
- if($this->_userClass==='')
- throw new TConfigurationException('dbusermanager_userclass_required');
- $this->_userFactory=Prado::createComponent($this->_userClass,$this);
- if(!($this->_userFactory instanceof TDbUser))
- throw new TInvalidDataTypeException('dbusermanager_userclass_invalid',$this->_userClass);
- }
-
- /**
- * @return string the user class name in namespace format. Defaults to empty string, meaning not set.
- */
- public function getUserClass()
- {
- return $this->_userClass;
- }
-
- /**
- * @param string the user class name in namespace format. The user class must extend from {@link TDbUser}.
- */
- public function setUserClass($value)
- {
- $this->_userClass=$value;
- }
-
- /**
- * @return string guest name, defaults to 'Guest'
- */
- public function getGuestName()
- {
- return $this->_guestName;
- }
-
- /**
- * @param string name to be used for guest users.
- */
- public function setGuestName($value)
- {
- $this->_guestName=$value;
- }
-
- /**
- * Validates if the username and password are correct.
- * @param string user name
- * @param string password
- * @return boolean true if validation is successful, false otherwise.
- */
- public function validateUser($username,$password)
- {
- return $this->_userFactory->validateUser($username,$password);
- }
-
- /**
- * Returns a user instance given the user name.
- * @param string user name, null if it is a guest.
- * @return TUser the user instance, null if the specified username is not in the user database.
- */
- public function getUser($username=null)
- {
- if($username===null)
- {
- $user=Prado::createComponent($this->_userClass,$this);
- $user->setIsGuest(true);
- return $user;
- }
- else
- return $this->_userFactory->createUser($username);
- }
-
- /**
- * @return string the ID of a TDataSourceConfig module. Defaults to empty string, meaning not set.
- */
- public function getConnectionID()
- {
- return $this->_connID;
- }
-
- /**
- * Sets the ID of a TDataSourceConfig module.
- * The datasource module will be used to establish the DB connection
- * that will be used by the user manager.
- * @param string module ID.
- */
- public function setConnectionID($value)
- {
- $this->_connID=$value;
- }
-
- /**
- * @return TDbConnection the database connection that may be used to retrieve user data.
- */
- public function getDbConnection()
- {
- if($this->_conn===null)
- {
- $this->_conn=$this->createDbConnection($this->_connID);
- $this->_conn->setActive(true);
- }
- return $this->_conn;
- }
-
- /**
- * Creates the DB connection.
- * @param string the module ID for TDataSourceConfig
- * @return TDbConnection the created DB connection
- * @throws TConfigurationException if module ID is invalid or empty
- */
- protected function createDbConnection($connectionID)
- {
- if($connectionID!=='')
- {
- $conn=$this->getApplication()->getModule($connectionID);
- if($conn instanceof TDataSourceConfig)
- return $conn->getDbConnection();
- else
- throw new TConfigurationException('dbusermanager_connectionid_invalid',$connectionID);
- }
- else
- throw new TConfigurationException('dbusermanager_connectionid_required');
- }
-
- /**
- * Returns a user instance according to auth data stored in a cookie.
- * @param THttpCookie the cookie storing user authentication information
- * @return TDbUser the user instance generated based on the cookie auth data, null if the cookie does not have valid auth data.
- * @since 3.1.1
- */
- public function getUserFromCookie($cookie)
- {
- return $this->_userFactory->createUserFromCookie($cookie);
- }
-
- /**
- * Saves user auth data into a cookie.
- * @param THttpCookie the cookie to receive the user auth data.
- * @since 3.1.1
- */
- public function saveUserToCookie($cookie)
- {
- $user=$this->getApplication()->getUser();
- if($user instanceof TDbUser)
- $user->saveUserToCookie($cookie);
- }
-}
-
-
-/**
- * TDbUser class
- *
- * TDbUser is the base user class for using together with {@link TDbUserManager}.
- * Two methods are declared and must be implemented in the descendant classes:
- * - {@link validateUser()}: validates if username and password are correct entries.
- * - {@link createUser()}: creates a new user instance given the username
- *
- * @author Qiang Xue <qiang.xue@gmail.com>
- * @version $Id$
- * @package System.Security
- * @since 3.1.0
- */
-abstract class TDbUser extends TUser
-{
- private $_connection;
-
- /**
- * Returns a database connection that may be used to retrieve data from database.
- *
- * @return TDbConnection database connection that may be used to retrieve data from database
- */
- public function getDbConnection()
- {
- if($this->_connection===null)
- {
- $userManager=$this->getManager();
- if($userManager instanceof TDbUserManager)
- {
- $connection=$userManager->getDbConnection();
- if($connection instanceof TDbConnection)
- {
- $connection->setActive(true);
- $this->_connection=$connection;
- }
- }
- if($this->_connection===null)
- throw new TConfigurationException('dbuser_dbconnection_invalid');
- }
- return $this->_connection;
- }
-
- /**
- * Validates if username and password are correct entries.
- * Usually, this is accomplished by checking if the user database
- * contains this (username, password) pair.
- * You may use {@link getDbConnection DbConnection} to deal with database.
- * @param string username (case-sensitive)
- * @param string password
- * @return boolean whether the validation succeeds
- */
- abstract public function validateUser($username,$password);
-
- /**
- * Creates a new user instance given the username.
- * This method usually needs to retrieve necessary user information
- * (e.g. role, name, rank, etc.) from the user database according to
- * the specified username. The newly created user instance should be
- * initialized with these information.
- *
- * If the username is invalid (not found in the user database), null
- * should be returned.
- *
- * You may use {@link getDbConnection DbConnection} to deal with database.
- *
- * @param string username (case-sensitive)
- * @return TDbUser the newly created and initialized user instance
- */
- abstract public function createUser($username);
-
- /**
- * Creates a new user instance given the cookie containing auth data.
- *
- * This method is invoked when {@link TAuthManager::setAllowAutoLogin AllowAutoLogin} is set true.
- * The default implementation simply returns null, meaning no user instance can be created
- * from the given cookie.
- *
- * If you want to support automatic login (remember login), you should override this method.
- * Typically, you obtain the username and a unique token from the cookie's value.
- * You then verify the token is valid and use the username to create a user instance.
- *
- * @param THttpCookie the cookie storing user authentication information
- * @return TDbUser the user instance generated based on the cookie auth data, null if the cookie does not have valid auth data.
- * @see saveUserToCookie
- * @since 3.1.1
- */
- public function createUserFromCookie($cookie)
- {
- return null;
- }
-
- /**
- * Saves necessary auth data into a cookie.
- * This method is invoked when {@link TAuthManager::rememberLogin} is invoked.
- * The default implementation does nothing, meaning auth data is not stored in the cookie
- * (and thus automatic login is not supported.)
- *
- * If you want to support automatic login (remember login), you should override this method.
- * Typically, you generate a unique token according to the current login information
- * and save it together with the username in the cookie's value.
- * You should avoid revealing the password in the generated token.
- *
- * @param THttpCookie the cookie to store the user auth information
- * @see createUserFromCookie
- * @since 3.1.1
- */
- public function saveUserToCookie($cookie)
- {
- }
-}
-
+ * @license http://www.pradosoft.com/license/
+ * @version $Id$
+ * @package System.Security
+ */
+
+/**
+ * Using IUserManager interface
+ */
+Prado::using('System.Security.IUserManager');
+Prado::using('System.Data.TDataSourceConfig');
+Prado::using('System.Security.TUser');
+
+/**
+ * TDbUserManager class
+ *
+ * TDbUserManager manages user accounts that are stored in a database.
+ * TDbUserManager is mainly designed to be used together with {@link TAuthManager}
+ * which manages how users are authenticated and authorized in a Prado application.
+ *
+ * To use TDbUserManager together with TAuthManager, configure them in
+ * the application configuration like following:
+ * <code>
+ * <module id="db"
+ * class="System.Data.TDataSourceConfig" ..../>
+ * <module id="users"
+ * class="System.Security.TDbUserManager"
+ * UserClass="Path.To.MyUserClass"
+ * ConnectionID="db" />
+ * <module id="auth"
+ * class="System.Security.TAuthManager"
+ * UserManager="users" LoginPage="Path.To.LoginPage" />
+ * </code>
+ *
+ * In the above, {@link setUserClass UserClass} specifies what class will be used
+ * to create user instance. The class must extend from {@link TDbUser}.
+ * {@link setConnectionID ConnectionID} refers to the ID of a {@link TDataSourceConfig} module
+ * which specifies how to establish database connection to retrieve user information.
+ *
+ * @author Qiang Xue <qiang.xue@gmail.com>
+ * @version $Id$
+ * @package System.Security
+ * @since 3.1.0
+ */
+class TDbUserManager extends TModule implements IUserManager
+{
+ private $_connID='';
+ private $_conn;
+ private $_guestName='Guest';
+ private $_userClass='';
+ private $_userFactory;
+
+ /**
+ * Initializes the module.
+ * This method is required by IModule and is invoked by application.
+ * @param TXmlElement module configuration
+ */
+ public function init($config)
+ {
+ if($this->_userClass==='')
+ throw new TConfigurationException('dbusermanager_userclass_required');
+ $this->_userFactory=Prado::createComponent($this->_userClass,$this);
+ if(!($this->_userFactory instanceof TDbUser))
+ throw new TInvalidDataTypeException('dbusermanager_userclass_invalid',$this->_userClass);
+ }
+
+ /**
+ * @return string the user class name in namespace format. Defaults to empty string, meaning not set.
+ */
+ public function getUserClass()
+ {
+ return $this->_userClass;
+ }
+
+ /**
+ * @param string the user class name in namespace format. The user class must extend from {@link TDbUser}.
+ */
+ public function setUserClass($value)
+ {
+ $this->_userClass=$value;
+ }
+
+ /**
+ * @return string guest name, defaults to 'Guest'
+ */
+ public function getGuestName()
+ {
+ return $this->_guestName;
+ }
+
+ /**
+ * @param string name to be used for guest users.
+ */
+ public function setGuestName($value)
+ {
+ $this->_guestName=$value;
+ }
+
+ /**
+ * Validates if the username and password are correct.
+ * @param string user name
+ * @param string password
+ * @return boolean true if validation is successful, false otherwise.
+ */
+ public function validateUser($username,$password)
+ {
+ return $this->_userFactory->validateUser($username,$password);
+ }
+
+ /**
+ * Returns a user instance given the user name.
+ * @param string user name, null if it is a guest.
+ * @return TUser the user instance, null if the specified username is not in the user database.
+ */
+ public function getUser($username=null)
+ {
+ if($username===null)
+ {
+ $user=Prado::createComponent($this->_userClass,$this);
+ $user->setIsGuest(true);
+ return $user;
+ }
+ else
+ return $this->_userFactory->createUser($username);
+ }
+
+ /**
+ * @return string the ID of a TDataSourceConfig module. Defaults to empty string, meaning not set.
+ */
+ public function getConnectionID()
+ {
+ return $this->_connID;
+ }
+
+ /**
+ * Sets the ID of a TDataSourceConfig module.
+ * The datasource module will be used to establish the DB connection
+ * that will be used by the user manager.
+ * @param string module ID.
+ */
+ public function setConnectionID($value)
+ {
+ $this->_connID=$value;
+ }
+
+ /**
+ * @return TDbConnection the database connection that may be used to retrieve user data.
+ */
+ public function getDbConnection()
+ {
+ if($this->_conn===null)
+ {
+ $this->_conn=$this->createDbConnection($this->_connID);
+ $this->_conn->setActive(true);
+ }
+ return $this->_conn;
+ }
+
+ /**
+ * Creates the DB connection.
+ * @param string the module ID for TDataSourceConfig
+ * @return TDbConnection the created DB connection
+ * @throws TConfigurationException if module ID is invalid or empty
+ */
+ protected function createDbConnection($connectionID)
+ {
+ if($connectionID!=='')
+ {
+ $conn=$this->getApplication()->getModule($connectionID);
+ if($conn instanceof TDataSourceConfig)
+ return $conn->getDbConnection();
+ else
+ throw new TConfigurationException('dbusermanager_connectionid_invalid',$connectionID);
+ }
+ else
+ throw new TConfigurationException('dbusermanager_connectionid_required');
+ }
+
+ /**
+ * Returns a user instance according to auth data stored in a cookie.
+ * @param THttpCookie the cookie storing user authentication information
+ * @return TDbUser the user instance generated based on the cookie auth data, null if the cookie does not have valid auth data.
+ * @since 3.1.1
+ */
+ public function getUserFromCookie($cookie)
+ {
+ return $this->_userFactory->createUserFromCookie($cookie);
+ }
+
+ /**
+ * Saves user auth data into a cookie.
+ * @param THttpCookie the cookie to receive the user auth data.
+ * @since 3.1.1
+ */
+ public function saveUserToCookie($cookie)
+ {
+ $user=$this->getApplication()->getUser();
+ if($user instanceof TDbUser)
+ $user->saveUserToCookie($cookie);
+ }
+}
+
+
+/**
+ * TDbUser class
+ *
+ * TDbUser is the base user class for using together with {@link TDbUserManager}.
+ * Two methods are declared and must be implemented in the descendant classes:
+ * - {@link validateUser()}: validates if username and password are correct entries.
+ * - {@link createUser()}: creates a new user instance given the username
+ *
+ * @author Qiang Xue <qiang.xue@gmail.com>
+ * @version $Id$
+ * @package System.Security
+ * @since 3.1.0
+ */
+abstract class TDbUser extends TUser
+{
+ private $_connection;
+
+ /**
+ * Returns a database connection that may be used to retrieve data from database.
+ *
+ * @return TDbConnection database connection that may be used to retrieve data from database
+ */
+ public function getDbConnection()
+ {
+ if($this->_connection===null)
+ {
+ $userManager=$this->getManager();
+ if($userManager instanceof TDbUserManager)
+ {
+ $connection=$userManager->getDbConnection();
+ if($connection instanceof TDbConnection)
+ {
+ $connection->setActive(true);
+ $this->_connection=$connection;
+ }
+ }
+ if($this->_connection===null)
+ throw new TConfigurationException('dbuser_dbconnection_invalid');
+ }
+ return $this->_connection;
+ }
+
+ /**
+ * Validates if username and password are correct entries.
+ * Usually, this is accomplished by checking if the user database
+ * contains this (username, password) pair.
+ * You may use {@link getDbConnection DbConnection} to deal with database.
+ * @param string username (case-sensitive)
+ * @param string password
+ * @return boolean whether the validation succeeds
+ */
+ abstract public function validateUser($username,$password);
+
+ /**
+ * Creates a new user instance given the username.
+ * This method usually needs to retrieve necessary user information
+ * (e.g. role, name, rank, etc.) from the user database according to
+ * the specified username. The newly created user instance should be
+ * initialized with these information.
+ *
+ * If the username is invalid (not found in the user database), null
+ * should be returned.
+ *
+ * You may use {@link getDbConnection DbConnection} to deal with database.
+ *
+ * @param string username (case-sensitive)
+ * @return TDbUser the newly created and initialized user instance
+ */
+ abstract public function createUser($username);
+
+ /**
+ * Creates a new user instance given the cookie containing auth data.
+ *
+ * This method is invoked when {@link TAuthManager::setAllowAutoLogin AllowAutoLogin} is set true.
+ * The default implementation simply returns null, meaning no user instance can be created
+ * from the given cookie.
+ *
+ * If you want to support automatic login (remember login), you should override this method.
+ * Typically, you obtain the username and a unique token from the cookie's value.
+ * You then verify the token is valid and use the username to create a user instance.
+ *
+ * @param THttpCookie the cookie storing user authentication information
+ * @return TDbUser the user instance generated based on the cookie auth data, null if the cookie does not have valid auth data.
+ * @see saveUserToCookie
+ * @since 3.1.1
+ */
+ public function createUserFromCookie($cookie)
+ {
+ return null;
+ }
+
+ /**
+ * Saves necessary auth data into a cookie.
+ * This method is invoked when {@link TAuthManager::rememberLogin} is invoked.
+ * The default implementation does nothing, meaning auth data is not stored in the cookie
+ * (and thus automatic login is not supported.)
+ *
+ * If you want to support automatic login (remember login), you should override this method.
+ * Typically, you generate a unique token according to the current login information
+ * and save it together with the username in the cookie's value.
+ * You should avoid revealing the password in the generated token.
+ *
+ * @param THttpCookie the cookie to store the user auth information
+ * @see createUserFromCookie
+ * @since 3.1.1
+ */
+ public function saveUserToCookie($cookie)
+ {
+ }
+}
+
diff --git a/framework/Security/TUser.php b/framework/Security/TUser.php
index b282234b..2b367255 100644
--- a/framework/Security/TUser.php
+++ b/framework/Security/TUser.php
@@ -1,222 +1,222 @@
-<?php
-/**
- * TUser class file.
- *
- * @author Qiang Xue <qiang.xue@gmail.com>
- * @link http://www.pradosoft.com/
+<?php
+/**
+ * TUser class file.
+ *
+ * @author Qiang Xue <qiang.xue@gmail.com>
+ * @link http://www.pradosoft.com/
* @copyright Copyright &copy; 2005-2012 PradoSoft
- * @license http://www.pradosoft.com/license/
- * @version $Id$
- * @package System.Security
- */
-
-/**
- * Using IUserManager interface
- */
-Prado::using('System.Security.IUserManager');
-
-/**
- * TUser class
- *
- * TUser implements basic user functionality for a Prado application.
- * To get the name of the user, use {@link getName Name} property.
- * The property {@link getIsGuest IsGuest} tells if the user a guest/anonymous user.
- * To obtain or test the roles that the user is in, use property
- * {@link getRoles Roles} and call {@link isInRole()}, respectively.
- *
- * TUser is meant to be used together with {@link IUserManager}.
- *
- * @author Qiang Xue <qiang.xue@gmail.com>
- * @version $Id$
- * @package System.Security
- * @since 3.0
- */
-class TUser extends TComponent implements IUser
-{
- /**
- * @var array persistent state
- */
- private $_state;
- /**
- * @var boolean whether user state is changed
- */
- private $_stateChanged=false;
- /**
- * @var IUserManager user manager
- */
- private $_manager;
-
- /**
- * Constructor.
- * @param IUserManager user manager
- */
- public function __construct(IUserManager $manager)
- {
- $this->_state=array();
- $this->_manager=$manager;
- $this->setName($manager->getGuestName());
- }
-
- /**
- * @return IUserManager user manager
- */
- public function getManager()
- {
- return $this->_manager;
- }
-
- /**
- * @return string username, defaults to empty string.
- */
- public function getName()
- {
- return $this->getState('Name','');
- }
-
- /**
- * @param string username
- */
- public function setName($value)
- {
- $this->setState('Name',$value,'');
- }
-
- /**
- * @return boolean if the user is a guest, defaults to true.
- */
- public function getIsGuest()
- {
- return $this->getState('IsGuest',true);
- }
-
- /**
- * @param boolean if the user is a guest
- */
- public function setIsGuest($value)
- {
- if($isGuest=TPropertyValue::ensureBoolean($value))
- {
- $this->setName($this->_manager->getGuestName());
- $this->setRoles(array());
- }
- $this->setState('IsGuest',$isGuest);
- }
-
- /**
- * @return array list of roles that the user is of
- */
- public function getRoles()
- {
- return $this->getState('Roles',array());
- }
-
- /**
- * @return array|string list of roles that the user is of. If it is a string, roles are assumed by separated by comma
- */
- public function setRoles($value)
- {
- if(is_array($value))
- $this->setState('Roles',$value,array());
- else
- {
- $roles=array();
- foreach(explode(',',$value) as $role)
- {
- if(($role=trim($role))!=='')
- $roles[]=$role;
- }
- $this->setState('Roles',$roles,array());
- }
- }
-
- /**
- * @param string role to be tested. Note, role is case-insensitive.
- * @return boolean whether the user is of this role
- */
- public function isInRole($role)
- {
- foreach($this->getRoles() as $r)
- if(strcasecmp($role,$r)===0)
- return true;
- return false;
- }
-
- /**
- * @return string user data that is serialized and will be stored in session
- */
- public function saveToString()
- {
- return serialize($this->_state);
- }
-
- /**
- * @param string user data that is serialized and restored from session
- * @return IUser the user object
- */
- public function loadFromString($data)
- {
- if(!empty($data))
- $this->_state=unserialize($data);
- if(!is_array($this->_state))
- $this->_state=array();
- return $this;
- }
-
- /**
- * Returns the value of a variable that is stored in user session.
- *
- * This function is designed to be used by TUser descendant classes
- * who want to store additional user information in user session.
- * A variable, if stored in user session using {@link setState} can be
- * retrieved back using this function.
- *
- * @param string variable name
- * @param mixed default value
- * @return mixed the value of the variable. If it doesn't exist, the provided default value will be returned
- * @see setState
- */
- protected function getState($key,$defaultValue=null)
- {
- return isset($this->_state[$key])?$this->_state[$key]:$defaultValue;
- }
-
- /**
- * Stores a variable in user session.
- *
- * This function is designed to be used by TUser descendant classes
- * who want to store additional user information in user session.
- * By storing a variable using this function, the variable may be retrieved
- * back later using {@link getState}. The variable will be persistent
- * across page requests during a user session.
- *
- * @param string variable name
- * @param mixed variable value
- * @param mixed default value. If $value===$defaultValue, the variable will be removed from persistent storage.
- * @see getState
- */
- protected function setState($key,$value,$defaultValue=null)
- {
- if($value===$defaultValue)
- unset($this->_state[$key]);
- else
- $this->_state[$key]=$value;
- $this->_stateChanged=true;
- }
-
- /**
- * @return boolean whether user session state is changed (i.e., setState() is called)
- */
- public function getStateChanged()
- {
- return $this->_stateChanged;
- }
-
- /**
- * @param boolean whether user session state is changed
- */
- public function setStateChanged($value)
- {
- $this->_stateChanged=TPropertyValue::ensureBoolean($value);
- }
-}
-
+ * @license http://www.pradosoft.com/license/
+ * @version $Id$
+ * @package System.Security
+ */
+
+/**
+ * Using IUserManager interface
+ */
+Prado::using('System.Security.IUserManager');
+
+/**
+ * TUser class
+ *
+ * TUser implements basic user functionality for a Prado application.
+ * To get the name of the user, use {@link getName Name} property.
+ * The property {@link getIsGuest IsGuest} tells if the user a guest/anonymous user.
+ * To obtain or test the roles that the user is in, use property
+ * {@link getRoles Roles} and call {@link isInRole()}, respectively.
+ *
+ * TUser is meant to be used together with {@link IUserManager}.
+ *
+ * @author Qiang Xue <qiang.xue@gmail.com>
+ * @version $Id$
+ * @package System.Security
+ * @since 3.0
+ */
+class TUser extends TComponent implements IUser
+{
+ /**
+ * @var array persistent state
+ */
+ private $_state;
+ /**
+ * @var boolean whether user state is changed
+ */
+ private $_stateChanged=false;
+ /**
+ * @var IUserManager user manager
+ */
+ private $_manager;
+
+ /**
+ * Constructor.
+ * @param IUserManager user manager
+ */
+ public function __construct(IUserManager $manager)
+ {
+ $this->_state=array();
+ $this->_manager=$manager;
+ $this->setName($manager->getGuestName());
+ }
+
+ /**
+ * @return IUserManager user manager
+ */
+ public function getManager()
+ {
+ return $this->_manager;
+ }
+
+ /**
+ * @return string username, defaults to empty string.
+ */
+ public function getName()
+ {
+ return $this->getState('Name','');
+ }
+
+ /**
+ * @param string username
+ */
+ public function setName($value)
+ {
+ $this->setState('Name',$value,'');
+ }
+
+ /**
+ * @return boolean if the user is a guest, defaults to true.
+ */
+ public function getIsGuest()
+ {
+ return $this->getState('IsGuest',true);
+ }
+
+ /**
+ * @param boolean if the user is a guest
+ */
+ public function setIsGuest($value)
+ {
+ if($isGuest=TPropertyValue::ensureBoolean($value))
+ {
+ $this->setName($this->_manager->getGuestName());
+ $this->setRoles(array());
+ }
+ $this->setState('IsGuest',$isGuest);
+ }
+
+ /**
+ * @return array list of roles that the user is of
+ */
+ public function getRoles()
+ {
+ return $this->getState('Roles',array());
+ }
+
+ /**
+ * @return array|string list of roles that the user is of. If it is a string, roles are assumed by separated by comma
+ */
+ public function setRoles($value)
+ {
+ if(is_array($value))
+ $this->setState('Roles',$value,array());
+ else
+ {
+ $roles=array();
+ foreach(explode(',',$value) as $role)
+ {
+ if(($role=trim($role))!=='')
+ $roles[]=$role;
+ }
+ $this->setState('Roles',$roles,array());
+ }
+ }
+
+ /**
+ * @param string role to be tested. Note, role is case-insensitive.
+ * @return boolean whether the user is of this role
+ */
+ public function isInRole($role)
+ {
+ foreach($this->getRoles() as $r)
+ if(strcasecmp($role,$r)===0)
+ return true;
+ return false;
+ }
+
+ /**
+ * @return string user data that is serialized and will be stored in session
+ */
+ public function saveToString()
+ {
+ return serialize($this->_state);
+ }
+
+ /**
+ * @param string user data that is serialized and restored from session
+ * @return IUser the user object
+ */
+ public function loadFromString($data)
+ {
+ if(!empty($data))
+ $this->_state=unserialize($data);
+ if(!is_array($this->_state))
+ $this->_state=array();
+ return $this;
+ }
+
+ /**
+ * Returns the value of a variable that is stored in user session.
+ *
+ * This function is designed to be used by TUser descendant classes
+ * who want to store additional user information in user session.
+ * A variable, if stored in user session using {@link setState} can be
+ * retrieved back using this function.
+ *
+ * @param string variable name
+ * @param mixed default value
+ * @return mixed the value of the variable. If it doesn't exist, the provided default value will be returned
+ * @see setState
+ */
+ protected function getState($key,$defaultValue=null)
+ {
+ return isset($this->_state[$key])?$this->_state[$key]:$defaultValue;
+ }
+
+ /**
+ * Stores a variable in user session.
+ *
+ * This function is designed to be used by TUser descendant classes
+ * who want to store additional user information in user session.
+ * By storing a variable using this function, the variable may be retrieved
+ * back later using {@link getState}. The variable will be persistent
+ * across page requests during a user session.
+ *
+ * @param string variable name
+ * @param mixed variable value
+ * @param mixed default value. If $value===$defaultValue, the variable will be removed from persistent storage.
+ * @see getState
+ */
+ protected function setState($key,$value,$defaultValue=null)
+ {
+ if($value===$defaultValue)
+ unset($this->_state[$key]);
+ else
+ $this->_state[$key]=$value;
+ $this->_stateChanged=true;
+ }
+
+ /**
+ * @return boolean whether user session state is changed (i.e., setState() is called)
+ */
+ public function getStateChanged()
+ {
+ return $this->_stateChanged;
+ }
+
+ /**
+ * @param boolean whether user session state is changed
+ */
+ public function setStateChanged($value)
+ {
+ $this->_stateChanged=TPropertyValue::ensureBoolean($value);
+ }
+}
+
diff --git a/framework/Security/TUserManager.php b/framework/Security/TUserManager.php
index 418da79c..c66ce8ad 100644
--- a/framework/Security/TUserManager.php
+++ b/framework/Security/TUserManager.php
@@ -1,402 +1,402 @@
-<?php
-/**
- * TUserManager class
- *
- * @author Qiang Xue <qiang.xue@gmail.com>
- * @link http://www.pradosoft.com/
+<?php
+/**
+ * TUserManager class
+ *
+ * @author Qiang Xue <qiang.xue@gmail.com>
+ * @link http://www.pradosoft.com/
* @copyright Copyright &copy; 2005-2012 PradoSoft
- * @license http://www.pradosoft.com/license/
- * @version $Id$
- * @package System.Security
- */
-
-/**
- * Using TUser class
- */
-Prado::using('System.Security.TUser');
-
-/**
- * TUserManager class
- *
- * TUserManager manages a static list of users {@link TUser}.
- * The user information is specified via module configuration using the following XML syntax,
- * <code>
- * <module id="users" class="System.Security.TUserManager" PasswordMode="Clear">
- * <user name="Joe" password="demo" />
- * <user name="John" password="demo" />
- * <role name="Administrator" users="John" />
- * <role name="Writer" users="Joe,John" />
- * </module>
- * </code>
- *
- * PHP configuration style:
- * <code>
- * array(
- * 'users' => array(
- * 'class' => 'System.Security.TUserManager',
- * 'properties' => array(
- * 'PasswordMode' => 'Clear',
- * ),
- * 'users' => array(
- * array('name'=>'Joe','password'=>'demo'),
- * array('name'=>'John','password'=>'demo'),
- * ),
- * 'roles' => array(
- * array('name'=>'Administrator','users'=>'John'),
- * array('name'=>'Writer','users'=>'Joe,John'),
- * ),
- * ),
- * )
- * </code>
- *
- * In addition, user information can also be loaded from an external file
- * specified by {@link setUserFile UserFile} property. Note, the property
- * only accepts a file path in namespace format. The user file format is
- * similar to the above sample.
- *
- * The user passwords may be specified as clear text, SH1 or MD5 hashed by setting
- * {@link setPasswordMode PasswordMode} as <b>Clear</b>, <b>SHA1</b> or <b>MD5</b>.
- * The default name for a guest user is <b>Guest</b>. It may be changed
- * by setting {@link setGuestName GuestName} property.
- *
- * TUserManager may be used together with {@link TAuthManager} which manages
- * how users are authenticated and authorized in a Prado application.
- *
- * @author Qiang Xue <qiang.xue@gmail.com>
- * @author Carl Mathisen <carl@kamikazemedia.no>
- * @version $Id$
- * @package System.Security
- * @since 3.0
- */
-class TUserManager extends TModule implements IUserManager
-{
- /**
- * extension name to the user file
- */
- const USER_FILE_EXT='.xml';
-
- /**
- * @var array list of users managed by this module
- */
- private $_users=array();
- /**
- * @var array list of roles managed by this module
- */
- private $_roles=array();
- /**
- * @var string guest name
- */
- private $_guestName='Guest';
- /**
- * @var TUserManagerPasswordMode password mode
- */
- private $_passwordMode=TUserManagerPasswordMode::MD5;
- /**
- * @var boolean whether the module has been initialized
- */
- private $_initialized=false;
- /**
- * @var string user/role information file
- */
- private $_userFile=null;
-
- /**
- * Initializes the module.
- * This method is required by IModule and is invoked by application.
- * It loads user/role information from the module configuration.
- * @param mixed module configuration
- */
- public function init($config)
- {
- $this->loadUserData($config);
- if($this->_userFile!==null)
- {
- if($this->getApplication()->getConfigurationType()==TApplication::CONFIG_TYPE_PHP)
- {
- $userFile = include $this->_userFile;
- $this->loadUserDataFromPhp($userFile);
- }
- else
- {
- $dom=new TXmlDocument;
- $dom->loadFromFile($this->_userFile);
- $this->loadUserDataFromXml($dom);
- }
- }
- $this->_initialized=true;
- }
-
- /*
- * Loads user/role information
- * @param mixed the variable containing the user information
- */
- private function loadUserData($config)
- {
- if($this->getApplication()->getConfigurationType()==TApplication::CONFIG_TYPE_PHP)
- $this->loadUserDataFromPhp($config);
- else
- $this->loadUserDataFromXml($config);
- }
-
- /**
- * Loads user/role information from an php array.
- * @param array the array containing the user information
- */
- private function loadUserDataFromPhp($config)
- {
- if(isset($config['users']) && is_array($config['users']))
- {
- foreach($config['users'] as $user)
- {
- $name = trim(strtolower(isset($user['name'])?$user['name']:''));
- $password = isset($user['password'])?$user['password']:'';
- $this->_users[$name] = $password;
- $roles = isset($user['roles'])?$user['roles']:'';
- if($roles!=='')
- {
- foreach(explode(',',$roles) as $role)
- {
- if(($role=trim($role))!=='')
- $this->_roles[$name][]=$role;
- }
- }
- }
- }
- if(isset($config['roles']) && is_array($config['roles']))
- {
- foreach($config['roles'] as $role)
- {
- $name = isset($role['name'])?$role['name']:'';
- $users = isset($role['users'])?$role['users']:'';
- foreach(explode(',',$users) as $user)
- {
- if(($user=trim($user))!=='')
- $this->_roles[strtolower($user)][]=$name;
- }
- }
- }
- }
-
- /**
- * Loads user/role information from an XML node.
- * @param TXmlElement the XML node containing the user information
- */
- private function loadUserDataFromXml($xmlNode)
- {
- foreach($xmlNode->getElementsByTagName('user') as $node)
- {
- $name=trim(strtolower($node->getAttribute('name')));
- $this->_users[$name]=$node->getAttribute('password');
- if(($roles=trim($node->getAttribute('roles')))!=='')
- {
- foreach(explode(',',$roles) as $role)
- {
- if(($role=trim($role))!=='')
- $this->_roles[$name][]=$role;
- }
- }
- }
- foreach($xmlNode->getElementsByTagName('role') as $node)
- {
- foreach(explode(',',$node->getAttribute('users')) as $user)
- {
- if(($user=trim($user))!=='')
- $this->_roles[strtolower($user)][]=$node->getAttribute('name');
- }
- }
- }
-
- /**
- * Returns an array of all users.
- * Each array element represents a single user.
- * The array key is the username in lower case, and the array value is the
- * corresponding user password.
- * @return array list of users
- */
- public function getUsers()
- {
- return $this->_users;
- }
-
- /**
- * Returns an array of user role information.
- * Each array element represents the roles for a single user.
- * The array key is the username in lower case, and the array value is
- * the roles (represented as an array) that the user is in.
- * @return array list of user role information
- */
- public function getRoles()
- {
- return $this->_roles;
- }
-
- /**
- * @return string the full path to the file storing user/role information
- */
- public function getUserFile()
- {
- return $this->_userFile;
- }
-
- /**
- * @param string user/role data file path (in namespace form). The file format is XML
- * whose content is similar to that user/role block in application configuration.
- * @throws TInvalidOperationException if the module is already initialized
- * @throws TConfigurationException if the file is not in proper namespace format
- */
- public function setUserFile($value)
- {
- if($this->_initialized)
- throw new TInvalidOperationException('usermanager_userfile_unchangeable');
- else if(($this->_userFile=Prado::getPathOfNamespace($value,self::USER_FILE_EXT))===null || !is_file($this->_userFile))
- throw new TConfigurationException('usermanager_userfile_invalid',$value);
- }
-
- /**
- * @return string guest name, defaults to 'Guest'
- */
- public function getGuestName()
- {
- return $this->_guestName;
- }
-
- /**
- * @param string name to be used for guest users.
- */
- public function setGuestName($value)
- {
- $this->_guestName=$value;
- }
-
- /**
- * @return TUserManagerPasswordMode how password is stored, clear text, or MD5 or SHA1 hashed. Default to TUserManagerPasswordMode::MD5.
- */
- public function getPasswordMode()
- {
- return $this->_passwordMode;
- }
-
- /**
- * @param TUserManagerPasswordMode how password is stored, clear text, or MD5 or SHA1 hashed.
- */
- public function setPasswordMode($value)
- {
- $this->_passwordMode=TPropertyValue::ensureEnum($value,'TUserManagerPasswordMode');
- }
-
- /**
- * Validates if the username and password are correct.
- * @param string user name
- * @param string password
- * @return boolean true if validation is successful, false otherwise.
- */
- public function validateUser($username,$password)
- {
- if($this->_passwordMode===TUserManagerPasswordMode::MD5)
- $password=md5($password);
- else if($this->_passwordMode===TUserManagerPasswordMode::SHA1)
- $password=sha1($password);
- $username=strtolower($username);
- return (isset($this->_users[$username]) && $this->_users[$username]===$password);
- }
-
- /**
- * Returns a user instance given the user name.
- * @param string user name, null if it is a guest.
- * @return TUser the user instance, null if the specified username is not in the user database.
- */
- public function getUser($username=null)
- {
- if($username===null)
- {
- $user=new TUser($this);
- $user->setIsGuest(true);
- return $user;
- }
- else
- {
- $username=strtolower($username);
- if(isset($this->_users[$username]))
- {
- $user=new TUser($this);
- $user->setName($username);
- $user->setIsGuest(false);
- if(isset($this->_roles[$username]))
- $user->setRoles($this->_roles[$username]);
- return $user;
- }
- else
- return null;
- }
- }
-
- /**
- * Returns a user instance according to auth data stored in a cookie.
- * @param THttpCookie the cookie storing user authentication information
- * @return TUser the user instance generated based on the cookie auth data, null if the cookie does not have valid auth data.
- * @since 3.1.1
- */
- public function getUserFromCookie($cookie)
- {
- if(($data=$cookie->getValue())!=='')
- {
- $data=unserialize($data);
- if(is_array($data) && count($data)===2)
- {
- list($username,$token)=$data;
- if(isset($this->_users[$username]) && $token===md5($username.$this->_users[$username]))
- return $this->getUser($username);
- }
- }
- return null;
- }
-
- /**
- * Saves user auth data into a cookie.
- * @param THttpCookie the cookie to receive the user auth data.
- * @since 3.1.1
- */
- public function saveUserToCookie($cookie)
- {
- $user=$this->getApplication()->getUser();
- $username=strtolower($user->getName());
- if(isset($this->_users[$username]))
- {
- $data=array($username,md5($username.$this->_users[$username]));
- $cookie->setValue(serialize($data));
- }
- }
-
- /**
- * Sets a user as a guest.
- * User name is changed as guest name, and roles are emptied.
- * @param TUser the user to be changed to a guest.
- */
- public function switchToGuest($user)
- {
- $user->setIsGuest(true);
- }
-}
-
-/**
- * TUserManagerPasswordMode class.
- * TUserManagerPasswordMode defines the enumerable type for the possible modes
- * that user passwords can be specified for a {@link TUserManager}.
- *
- * The following enumerable values are defined:
- * - Clear: the password is in plain text
- * - MD5: the password is recorded as the MD5 hash value of the original password
- * - SHA1: the password is recorded as the SHA1 hash value of the original password
- *
- * @author Qiang Xue <qiang.xue@gmail.com>
- * @version $Id$
- * @package System.Security
- * @since 3.0.4
- */
-class TUserManagerPasswordMode extends TEnumerable
-{
- const Clear='Clear';
- const MD5='MD5';
- const SHA1='SHA1';
-}
-
+ * @license http://www.pradosoft.com/license/
+ * @version $Id$
+ * @package System.Security
+ */
+
+/**
+ * Using TUser class
+ */
+Prado::using('System.Security.TUser');
+
+/**
+ * TUserManager class
+ *
+ * TUserManager manages a static list of users {@link TUser}.
+ * The user information is specified via module configuration using the following XML syntax,
+ * <code>
+ * <module id="users" class="System.Security.TUserManager" PasswordMode="Clear">
+ * <user name="Joe" password="demo" />
+ * <user name="John" password="demo" />
+ * <role name="Administrator" users="John" />
+ * <role name="Writer" users="Joe,John" />
+ * </module>
+ * </code>
+ *
+ * PHP configuration style:
+ * <code>
+ * array(
+ * 'users' => array(
+ * 'class' => 'System.Security.TUserManager',
+ * 'properties' => array(
+ * 'PasswordMode' => 'Clear',
+ * ),
+ * 'users' => array(
+ * array('name'=>'Joe','password'=>'demo'),
+ * array('name'=>'John','password'=>'demo'),
+ * ),
+ * 'roles' => array(
+ * array('name'=>'Administrator','users'=>'John'),
+ * array('name'=>'Writer','users'=>'Joe,John'),
+ * ),
+ * ),
+ * )
+ * </code>
+ *
+ * In addition, user information can also be loaded from an external file
+ * specified by {@link setUserFile UserFile} property. Note, the property
+ * only accepts a file path in namespace format. The user file format is
+ * similar to the above sample.
+ *
+ * The user passwords may be specified as clear text, SH1 or MD5 hashed by setting
+ * {@link setPasswordMode PasswordMode} as <b>Clear</b>, <b>SHA1</b> or <b>MD5</b>.
+ * The default name for a guest user is <b>Guest</b>. It may be changed
+ * by setting {@link setGuestName GuestName} property.
+ *
+ * TUserManager may be used together with {@link TAuthManager} which manages
+ * how users are authenticated and authorized in a Prado application.
+ *
+ * @author Qiang Xue <qiang.xue@gmail.com>
+ * @author Carl Mathisen <carl@kamikazemedia.no>
+ * @version $Id$
+ * @package System.Security
+ * @since 3.0
+ */
+class TUserManager extends TModule implements IUserManager
+{
+ /**
+ * extension name to the user file
+ */
+ const USER_FILE_EXT='.xml';
+
+ /**
+ * @var array list of users managed by this module
+ */
+ private $_users=array();
+ /**
+ * @var array list of roles managed by this module
+ */
+ private $_roles=array();
+ /**
+ * @var string guest name
+ */
+ private $_guestName='Guest';
+ /**
+ * @var TUserManagerPasswordMode password mode
+ */
+ private $_passwordMode=TUserManagerPasswordMode::MD5;
+ /**
+ * @var boolean whether the module has been initialized
+ */
+ private $_initialized=false;
+ /**
+ * @var string user/role information file
+ */
+ private $_userFile=null;
+
+ /**
+ * Initializes the module.
+ * This method is required by IModule and is invoked by application.
+ * It loads user/role information from the module configuration.
+ * @param mixed module configuration
+ */
+ public function init($config)
+ {
+ $this->loadUserData($config);
+ if($this->_userFile!==null)
+ {
+ if($this->getApplication()->getConfigurationType()==TApplication::CONFIG_TYPE_PHP)
+ {
+ $userFile = include $this->_userFile;
+ $this->loadUserDataFromPhp($userFile);
+ }
+ else
+ {
+ $dom=new TXmlDocument;
+ $dom->loadFromFile($this->_userFile);
+ $this->loadUserDataFromXml($dom);
+ }
+ }
+ $this->_initialized=true;
+ }
+
+ /*
+ * Loads user/role information
+ * @param mixed the variable containing the user information
+ */
+ private function loadUserData($config)
+ {
+ if($this->getApplication()->getConfigurationType()==TApplication::CONFIG_TYPE_PHP)
+ $this->loadUserDataFromPhp($config);
+ else
+ $this->loadUserDataFromXml($config);
+ }
+
+ /**
+ * Loads user/role information from an php array.
+ * @param array the array containing the user information
+ */
+ private function loadUserDataFromPhp($config)
+ {
+ if(isset($config['users']) && is_array($config['users']))
+ {
+ foreach($config['users'] as $user)
+ {
+ $name = trim(strtolower(isset($user['name'])?$user['name']:''));
+ $password = isset($user['password'])?$user['password']:'';
+ $this->_users[$name] = $password;
+ $roles = isset($user['roles'])?$user['roles']:'';
+ if($roles!=='')
+ {
+ foreach(explode(',',$roles) as $role)
+ {
+ if(($role=trim($role))!=='')
+ $this->_roles[$name][]=$role;
+ }
+ }
+ }
+ }
+ if(isset($config['roles']) && is_array($config['roles']))
+ {
+ foreach($config['roles'] as $role)
+ {
+ $name = isset($role['name'])?$role['name']:'';
+ $users = isset($role['users'])?$role['users']:'';
+ foreach(explode(',',$users) as $user)
+ {
+ if(($user=trim($user))!=='')
+ $this->_roles[strtolower($user)][]=$name;
+ }
+ }
+ }
+ }
+
+ /**
+ * Loads user/role information from an XML node.
+ * @param TXmlElement the XML node containing the user information
+ */
+ private function loadUserDataFromXml($xmlNode)
+ {
+ foreach($xmlNode->getElementsByTagName('user') as $node)
+ {
+ $name=trim(strtolower($node->getAttribute('name')));
+ $this->_users[$name]=$node->getAttribute('password');
+ if(($roles=trim($node->getAttribute('roles')))!=='')
+ {
+ foreach(explode(',',$roles) as $role)
+ {
+ if(($role=trim($role))!=='')
+ $this->_roles[$name][]=$role;
+ }
+ }
+ }
+ foreach($xmlNode->getElementsByTagName('role') as $node)
+ {
+ foreach(explode(',',$node->getAttribute('users')) as $user)
+ {
+ if(($user=trim($user))!=='')
+ $this->_roles[strtolower($user)][]=$node->getAttribute('name');
+ }
+ }
+ }
+
+ /**
+ * Returns an array of all users.
+ * Each array element represents a single user.
+ * The array key is the username in lower case, and the array value is the
+ * corresponding user password.
+ * @return array list of users
+ */
+ public function getUsers()
+ {
+ return $this->_users;
+ }
+
+ /**
+ * Returns an array of user role information.
+ * Each array element represents the roles for a single user.
+ * The array key is the username in lower case, and the array value is
+ * the roles (represented as an array) that the user is in.
+ * @return array list of user role information
+ */
+ public function getRoles()
+ {
+ return $this->_roles;
+ }
+
+ /**
+ * @return string the full path to the file storing user/role information
+ */
+ public function getUserFile()
+ {
+ return $this->_userFile;
+ }
+
+ /**
+ * @param string user/role data file path (in namespace form). The file format is XML
+ * whose content is similar to that user/role block in application configuration.
+ * @throws TInvalidOperationException if the module is already initialized
+ * @throws TConfigurationException if the file is not in proper namespace format
+ */
+ public function setUserFile($value)
+ {
+ if($this->_initialized)
+ throw new TInvalidOperationException('usermanager_userfile_unchangeable');
+ else if(($this->_userFile=Prado::getPathOfNamespace($value,self::USER_FILE_EXT))===null || !is_file($this->_userFile))
+ throw new TConfigurationException('usermanager_userfile_invalid',$value);
+ }
+
+ /**
+ * @return string guest name, defaults to 'Guest'
+ */
+ public function getGuestName()
+ {
+ return $this->_guestName;
+ }
+
+ /**
+ * @param string name to be used for guest users.
+ */
+ public function setGuestName($value)
+ {
+ $this->_guestName=$value;
+ }
+
+ /**
+ * @return TUserManagerPasswordMode how password is stored, clear text, or MD5 or SHA1 hashed. Default to TUserManagerPasswordMode::MD5.
+ */
+ public function getPasswordMode()
+ {
+ return $this->_passwordMode;
+ }
+
+ /**
+ * @param TUserManagerPasswordMode how password is stored, clear text, or MD5 or SHA1 hashed.
+ */
+ public function setPasswordMode($value)
+ {
+ $this->_passwordMode=TPropertyValue::ensureEnum($value,'TUserManagerPasswordMode');
+ }
+
+ /**
+ * Validates if the username and password are correct.
+ * @param string user name
+ * @param string password
+ * @return boolean true if validation is successful, false otherwise.
+ */
+ public function validateUser($username,$password)
+ {
+ if($this->_passwordMode===TUserManagerPasswordMode::MD5)
+ $password=md5($password);
+ else if($this->_passwordMode===TUserManagerPasswordMode::SHA1)
+ $password=sha1($password);
+ $username=strtolower($username);
+ return (isset($this->_users[$username]) && $this->_users[$username]===$password);
+ }
+
+ /**
+ * Returns a user instance given the user name.
+ * @param string user name, null if it is a guest.
+ * @return TUser the user instance, null if the specified username is not in the user database.
+ */
+ public function getUser($username=null)
+ {
+ if($username===null)
+ {
+ $user=new TUser($this);
+ $user->setIsGuest(true);
+ return $user;
+ }
+ else
+ {
+ $username=strtolower($username);
+ if(isset($this->_users[$username]))
+ {
+ $user=new TUser($this);
+ $user->setName($username);
+ $user->setIsGuest(false);
+ if(isset($this->_roles[$username]))
+ $user->setRoles($this->_roles[$username]);
+ return $user;
+ }
+ else
+ return null;
+ }
+ }
+
+ /**
+ * Returns a user instance according to auth data stored in a cookie.
+ * @param THttpCookie the cookie storing user authentication information
+ * @return TUser the user instance generated based on the cookie auth data, null if the cookie does not have valid auth data.
+ * @since 3.1.1
+ */
+ public function getUserFromCookie($cookie)
+ {
+ if(($data=$cookie->getValue())!=='')
+ {
+ $data=unserialize($data);
+ if(is_array($data) && count($data)===2)
+ {
+ list($username,$token)=$data;
+ if(isset($this->_users[$username]) && $token===md5($username.$this->_users[$username]))
+ return $this->getUser($username);
+ }
+ }
+ return null;
+ }
+
+ /**
+ * Saves user auth data into a cookie.
+ * @param THttpCookie the cookie to receive the user auth data.
+ * @since 3.1.1
+ */
+ public function saveUserToCookie($cookie)
+ {
+ $user=$this->getApplication()->getUser();
+ $username=strtolower($user->getName());
+ if(isset($this->_users[$username]))
+ {
+ $data=array($username,md5($username.$this->_users[$username]));
+ $cookie->setValue(serialize($data));
+ }
+ }
+
+ /**
+ * Sets a user as a guest.
+ * User name is changed as guest name, and roles are emptied.
+ * @param TUser the user to be changed to a guest.
+ */
+ public function switchToGuest($user)
+ {
+ $user->setIsGuest(true);
+ }
+}
+
+/**
+ * TUserManagerPasswordMode class.
+ * TUserManagerPasswordMode defines the enumerable type for the possible modes
+ * that user passwords can be specified for a {@link TUserManager}.
+ *
+ * The following enumerable values are defined:
+ * - Clear: the password is in plain text
+ * - MD5: the password is recorded as the MD5 hash value of the original password
+ * - SHA1: the password is recorded as the SHA1 hash value of the original password
+ *
+ * @author Qiang Xue <qiang.xue@gmail.com>
+ * @version $Id$
+ * @package System.Security
+ * @since 3.0.4
+ */
+class TUserManagerPasswordMode extends TEnumerable
+{
+ const Clear='Clear';
+ const MD5='MD5';
+ const SHA1='SHA1';
+}
+
diff --git a/framework/TApplicationComponent.php b/framework/TApplicationComponent.php
index 0c0420e9..80c59dad 100644
--- a/framework/TApplicationComponent.php
+++ b/framework/TApplicationComponent.php
@@ -1,118 +1,118 @@
-<?php
-/**
- * TApplicationComponent class
- *
- * @author Qiang Xue <qiang.xue@gmail.com>
- * @link http://www.pradosoft.com/
+<?php
+/**
+ * TApplicationComponent class
+ *
+ * @author Qiang Xue <qiang.xue@gmail.com>
+ * @link http://www.pradosoft.com/
* @copyright Copyright &copy; 2005-2012 PradoSoft
- * @license http://www.pradosoft.com/license/
- * @version $Id$
- * @package System
- */
-
-/**
- * TApplicationComponent class
- *
- * TApplicationComponent is the base class for all components that are
- * application-related, such as controls, modules, services, etc.
- *
- * TApplicationComponent mainly defines a few properties that are shortcuts
- * to some commonly used methods. The {@link getApplication Application}
- * property gives the application instance that this component belongs to;
- * {@link getService Service} gives the current running service;
- * {@link getRequest Request}, {@link getResponse Response} and {@link getSession Session}
- * return the request and response modules, respectively;
- * And {@link getUser User} gives the current user instance.
- *
- * Besides, TApplicationComponent defines two shortcut methods for
- * publishing private files: {@link publishAsset} and {@link publishFilePath}.
- *
- * @author Qiang Xue <qiang.xue@gmail.com>
- * @version $Id$
- * @package System
- * @since 3.0
- */
-class TApplicationComponent extends TComponent
-{
- /**
- * @return TApplication current application instance
- */
- public function getApplication()
- {
- return Prado::getApplication();
- }
-
- /**
- * @return IService the current service
- */
- public function getService()
- {
- return Prado::getApplication()->getService();
- }
-
- /**
- * @return THttpRequest the current user request
- */
- public function getRequest()
- {
- return Prado::getApplication()->getRequest();
- }
-
- /**
- * @return THttpResponse the response
- */
- public function getResponse()
- {
- return Prado::getApplication()->getResponse();
- }
-
- /**
- * @return THttpSession user session
- */
- public function getSession()
- {
- return Prado::getApplication()->getSession();
- }
-
- /**
- * @return IUser information about the current user
- */
- public function getUser()
- {
- return Prado::getApplication()->getUser();
- }
-
- /**
- * Publishes a private asset and gets its URL.
- * This method will publish a private asset (file or directory)
- * and gets the URL to the asset. Note, if the asset refers to
- * a directory, all contents under that directory will be published.
- * Also note, it is recommended that you supply a class name as the second
- * parameter to the method (e.g. publishAsset($assetPath,__CLASS__) ).
- * By doing so, you avoid the issue that child classes may not work properly
- * because the asset path will be relative to the directory containing the child class file.
- *
- * @param string path of the asset that is relative to the directory containing the specified class file.
- * @param string name of the class whose containing directory will be prepend to the asset path. If null, it means get_class($this).
- * @return string URL to the asset path.
- */
- public function publishAsset($assetPath,$className=null)
- {
- if($className===null)
- $className=get_class($this);
- $class=new ReflectionClass($className);
- $fullPath=dirname($class->getFileName()).DIRECTORY_SEPARATOR.$assetPath;
- return $this->publishFilePath($fullPath);
- }
-
- /**
- * Publishes a file or directory and returns its URL.
- * @param string absolute path of the file or directory to be published
- * @return string URL to the published file or directory
- */
- public function publishFilePath($fullPath)
- {
- return Prado::getApplication()->getAssetManager()->publishFilePath($fullPath);
- }
-}
-
+ * @license http://www.pradosoft.com/license/
+ * @version $Id$
+ * @package System
+ */
+
+/**
+ * TApplicationComponent class
+ *
+ * TApplicationComponent is the base class for all components that are
+ * application-related, such as controls, modules, services, etc.
+ *
+ * TApplicationComponent mainly defines a few properties that are shortcuts
+ * to some commonly used methods. The {@link getApplication Application}
+ * property gives the application instance that this component belongs to;
+ * {@link getService Service} gives the current running service;
+ * {@link getRequest Request}, {@link getResponse Response} and {@link getSession Session}
+ * return the request and response modules, respectively;
+ * And {@link getUser User} gives the current user instance.
+ *
+ * Besides, TApplicationComponent defines two shortcut methods for
+ * publishing private files: {@link publishAsset} and {@link publishFilePath}.
+ *
+ * @author Qiang Xue <qiang.xue@gmail.com>
+ * @version $Id$
+ * @package System
+ * @since 3.0
+ */
+class TApplicationComponent extends TComponent
+{
+ /**
+ * @return TApplication current application instance
+ */
+ public function getApplication()
+ {
+ return Prado::getApplication();
+ }
+
+ /**
+ * @return IService the current service
+ */
+ public function getService()
+ {
+ return Prado::getApplication()->getService();
+ }
+
+ /**
+ * @return THttpRequest the current user request
+ */
+ public function getRequest()
+ {
+ return Prado::getApplication()->getRequest();
+ }
+
+ /**
+ * @return THttpResponse the response
+ */
+ public function getResponse()
+ {
+ return Prado::getApplication()->getResponse();
+ }
+
+ /**
+ * @return THttpSession user session
+ */
+ public function getSession()
+ {
+ return Prado::getApplication()->getSession();
+ }
+
+ /**
+ * @return IUser information about the current user
+ */
+ public function getUser()
+ {
+ return Prado::getApplication()->getUser();
+ }
+
+ /**
+ * Publishes a private asset and gets its URL.
+ * This method will publish a private asset (file or directory)
+ * and gets the URL to the asset. Note, if the asset refers to
+ * a directory, all contents under that directory will be published.
+ * Also note, it is recommended that you supply a class name as the second
+ * parameter to the method (e.g. publishAsset($assetPath,__CLASS__) ).
+ * By doing so, you avoid the issue that child classes may not work properly
+ * because the asset path will be relative to the directory containing the child class file.
+ *
+ * @param string path of the asset that is relative to the directory containing the specified class file.
+ * @param string name of the class whose containing directory will be prepend to the asset path. If null, it means get_class($this).
+ * @return string URL to the asset path.
+ */
+ public function publishAsset($assetPath,$className=null)
+ {
+ if($className===null)
+ $className=get_class($this);
+ $class=new ReflectionClass($className);
+ $fullPath=dirname($class->getFileName()).DIRECTORY_SEPARATOR.$assetPath;
+ return $this->publishFilePath($fullPath);
+ }
+
+ /**
+ * Publishes a file or directory and returns its URL.
+ * @param string absolute path of the file or directory to be published
+ * @return string URL to the published file or directory
+ */
+ public function publishFilePath($fullPath)
+ {
+ return Prado::getApplication()->getAssetManager()->publishFilePath($fullPath);
+ }
+}
+
diff --git a/framework/TModule.php b/framework/TModule.php
index bce04d4e..517a7dcd 100644
--- a/framework/TModule.php
+++ b/framework/TModule.php
@@ -1,56 +1,56 @@
-<?php
-/**
- * TModule class file.
- *
- * @author Qiang Xue <qiang.xue@gmail.com>
- * @link http://www.pradosoft.com/
+<?php
+/**
+ * TModule class file.
+ *
+ * @author Qiang Xue <qiang.xue@gmail.com>
+ * @link http://www.pradosoft.com/
* @copyright Copyright &copy; 2005-2012 PradoSoft
- * @license http://www.pradosoft.com/license/
- * @version $Id$
- * @package System
- */
-
-/**
- * TModule class.
- *
- * TModule implements the basic methods required by IModule and may be
- * used as the basic class for application modules.
- *
- * @author Qiang Xue <qiang.xue@gmail.com>
- * @version $Id$
- * @package System
- * @since 3.0
- */
-abstract class TModule extends TApplicationComponent implements IModule
-{
- /**
- * @var string module id
- */
- private $_id;
-
- /**
- * Initializes the module.
- * This method is required by IModule and is invoked by application.
- * @param TXmlElement module configuration
- */
- public function init($config)
- {
- }
-
- /**
- * @return string id of this module
- */
- public function getID()
- {
- return $this->_id;
- }
-
- /**
- * @param string id of this module
- */
- public function setID($value)
- {
- $this->_id=$value;
- }
-}
-
+ * @license http://www.pradosoft.com/license/
+ * @version $Id$
+ * @package System
+ */
+
+/**
+ * TModule class.
+ *
+ * TModule implements the basic methods required by IModule and may be
+ * used as the basic class for application modules.
+ *
+ * @author Qiang Xue <qiang.xue@gmail.com>
+ * @version $Id$
+ * @package System
+ * @since 3.0
+ */
+abstract class TModule extends TApplicationComponent implements IModule
+{
+ /**
+ * @var string module id
+ */
+ private $_id;
+
+ /**
+ * Initializes the module.
+ * This method is required by IModule and is invoked by application.
+ * @param TXmlElement module configuration
+ */
+ public function init($config)
+ {
+ }
+
+ /**
+ * @return string id of this module
+ */
+ public function getID()
+ {
+ return $this->_id;
+ }
+
+ /**
+ * @param string id of this module
+ */
+ public function setID($value)
+ {
+ $this->_id=$value;
+ }
+}
+
diff --git a/framework/TShellApplication.php b/framework/TShellApplication.php
index 30fb3029..bb847c0b 100644
--- a/framework/TShellApplication.php
+++ b/framework/TShellApplication.php
@@ -1,48 +1,48 @@
-<?php
-/**
- * TShellApplication class file
- *
- * @author Qiang Xue <qiang.xue@gmail.com>
- * @link http://www.pradosoft.com/
- * @copyright Copyright &copy; 2005-2012 PradoSoft
- * @license http://www.pradosoft.com/license/
- * @version $Id$
- * @package System
- */
-
-/**
- * TShellApplication class.
- *
- * TShellApplication is the base class for developing command-line PRADO
- * tools that share the same configurations as their Web application counterparts.
- *
- * A typical usage of TShellApplication in a command-line PHP script is as follows:
- * <code>
- * require_once('path/to/prado.php');
- * $application=new TShellApplication('path/to/application.xml');
- * $application->run();
- * // perform command-line tasks here
- * </code>
- *
- * Since the application instance has access to all configurations, including
- * path aliases, modules and parameters, the command-line script has nearly the same
- * accessibility to resources as the PRADO Web applications.
- *
- * @author Qiang Xue <qiang.xue@gmail.com>
- * @version $Id$
- * @package System
- * @since 3.1.0
- */
-class TShellApplication extends TApplication
-{
- /**
- * Runs the application.
- * This method overrides the parent implementation by initializing
- * application with configurations specified when it is created.
- */
- public function run()
- {
- $this->initApplication();
- }
-}
-
+<?php
+/**
+ * TShellApplication class file
+ *
+ * @author Qiang Xue <qiang.xue@gmail.com>
+ * @link http://www.pradosoft.com/
+ * @copyright Copyright &copy; 2005-2012 PradoSoft
+ * @license http://www.pradosoft.com/license/
+ * @version $Id$
+ * @package System
+ */
+
+/**
+ * TShellApplication class.
+ *
+ * TShellApplication is the base class for developing command-line PRADO
+ * tools that share the same configurations as their Web application counterparts.
+ *
+ * A typical usage of TShellApplication in a command-line PHP script is as follows:
+ * <code>
+ * require_once('path/to/prado.php');
+ * $application=new TShellApplication('path/to/application.xml');
+ * $application->run();
+ * // perform command-line tasks here
+ * </code>
+ *
+ * Since the application instance has access to all configurations, including
+ * path aliases, modules and parameters, the command-line script has nearly the same
+ * accessibility to resources as the PRADO Web applications.
+ *
+ * @author Qiang Xue <qiang.xue@gmail.com>
+ * @version $Id$
+ * @package System
+ * @since 3.1.0
+ */
+class TShellApplication extends TApplication
+{
+ /**
+ * Runs the application.
+ * This method overrides the parent implementation by initializing
+ * application with configurations specified when it is created.
+ */
+ public function run()
+ {
+ $this->initApplication();
+ }
+}
+
diff --git a/framework/Util/TDataFieldAccessor.php b/framework/Util/TDataFieldAccessor.php
index e0181033..b96cf0c9 100644
--- a/framework/Util/TDataFieldAccessor.php
+++ b/framework/Util/TDataFieldAccessor.php
@@ -1,82 +1,82 @@
-<?php
-/**
- * TDataFieldAccessor class file
- *
- * @author Qiang Xue <qiang.xue@gmail.com>
- * @link http://www.pradosoft.com/
- * @copyright Copyright &copy; 2005-2012 PradoSoft
- * @license http://www.pradosoft.com/license/
- * @version $Id$
- * @package System.Util
- */
-
-/**
- * TDataFieldAccessor class
- *
- * TDataFieldAccessor is a utility class that provides access to a field of some data.
- * The accessor attempts to obtain the field value in the following order:
- * - If the data is an array, then the field is treated as an array index
- * and the corresponding element value is returned;
- * - If the data is a TMap or TList object, then the field is treated as a key
- * into the map or list, and the corresponding value is returned.
- * - If the data is an object, the field is treated as a property or sub-property
- * defined with getter methods. For example, if the object has a method called
- * getMyValue(), then field 'MyValue' will retrieve the result of this method call.
- * If getMyValue() returns an object which contains a method getMySubValue(),
- * then field 'MyValue.MySubValue' will return that method call result.
- *
- * @author Qiang Xue <qiang.xue@gmail.com>
- * @version $Id$
- * @package System.Util
- * @since 3.0
- */
-class TDataFieldAccessor
-{
- /**
- * Evaluates the data value at the specified field.
- * - If the data is an array, then the field is treated as an array index
- * and the corresponding element value is returned;
- * - If the data is a TMap or TList object, then the field is treated as a key
- * into the map or list, and the corresponding value is returned.
- * - If the data is an object, the field is treated as a property or sub-property
- * defined with getter methods. For example, if the object has a method called
- * getMyValue(), then field 'MyValue' will retrieve the result of this method call.
- * If getMyValue() returns an object which contains a method getMySubValue(),
- * then field 'MyValue.MySubValue' will return that method call result.
- * @param mixed data containing the field value, can be an array, TMap, TList or object.
- * @param mixed field value
- * @return mixed value at the specified field
- * @throws TInvalidDataValueException if field or data is invalid
- */
- public static function getDataFieldValue($data,$field)
- {
- try
- {
- if(is_array($data) || ($data instanceof ArrayAccess))
- return $data[$field];
- else if(is_object($data))
- {
- if(strpos($field,'.')===false) // simple field
- {
- if(method_exists($data, 'get'.$field))
- return call_user_func(array($data,'get'.$field));
- else
- return $data->{$field};
- }
- else // field in the format of xxx.yyy.zzz
- {
- $object=$data;
- foreach(explode('.',$field) as $f)
- $object = TDataFieldAccessor::getDataFieldValue($object, $f);
- return $object;
- }
- }
- }
- catch(Exception $e)
- {
- throw new TInvalidDataValueException('datafieldaccessor_datafield_invalid',$field,$e->getMessage());
- }
- throw new TInvalidDataValueException('datafieldaccessor_data_invalid',$field);
- }
-}
-
+<?php
+/**
+ * TDataFieldAccessor class file
+ *
+ * @author Qiang Xue <qiang.xue@gmail.com>
+ * @link http://www.pradosoft.com/
+ * @copyright Copyright &copy; 2005-2012 PradoSoft
+ * @license http://www.pradosoft.com/license/
+ * @version $Id$
+ * @package System.Util
+ */
+
+/**
+ * TDataFieldAccessor class
+ *
+ * TDataFieldAccessor is a utility class that provides access to a field of some data.
+ * The accessor attempts to obtain the field value in the following order:
+ * - If the data is an array, then the field is treated as an array index
+ * and the corresponding element value is returned;
+ * - If the data is a TMap or TList object, then the field is treated as a key
+ * into the map or list, and the corresponding value is returned.
+ * - If the data is an object, the field is treated as a property or sub-property
+ * defined with getter methods. For example, if the object has a method called
+ * getMyValue(), then field 'MyValue' will retrieve the result of this method call.
+ * If getMyValue() returns an object which contains a method getMySubValue(),
+ * then field 'MyValue.MySubValue' will return that method call result.
+ *
+ * @author Qiang Xue <qiang.xue@gmail.com>
+ * @version $Id$
+ * @package System.Util
+ * @since 3.0
+ */
+class TDataFieldAccessor
+{
+ /**
+ * Evaluates the data value at the specified field.
+ * - If the data is an array, then the field is treated as an array index
+ * and the corresponding element value is returned;
+ * - If the data is a TMap or TList object, then the field is treated as a key
+ * into the map or list, and the corresponding value is returned.
+ * - If the data is an object, the field is treated as a property or sub-property
+ * defined with getter methods. For example, if the object has a method called
+ * getMyValue(), then field 'MyValue' will retrieve the result of this method call.
+ * If getMyValue() returns an object which contains a method getMySubValue(),
+ * then field 'MyValue.MySubValue' will return that method call result.
+ * @param mixed data containing the field value, can be an array, TMap, TList or object.
+ * @param mixed field value
+ * @return mixed value at the specified field
+ * @throws TInvalidDataValueException if field or data is invalid
+ */
+ public static function getDataFieldValue($data,$field)
+ {
+ try
+ {
+ if(is_array($data) || ($data instanceof ArrayAccess))
+ return $data[$field];
+ else if(is_object($data))
+ {
+ if(strpos($field,'.')===false) // simple field
+ {
+ if(method_exists($data, 'get'.$field))
+ return call_user_func(array($data,'get'.$field));
+ else
+ return $data->{$field};
+ }
+ else // field in the format of xxx.yyy.zzz
+ {
+ $object=$data;
+ foreach(explode('.',$field) as $f)
+ $object = TDataFieldAccessor::getDataFieldValue($object, $f);
+ return $object;
+ }
+ }
+ }
+ catch(Exception $e)
+ {
+ throw new TInvalidDataValueException('datafieldaccessor_datafield_invalid',$field,$e->getMessage());
+ }
+ throw new TInvalidDataValueException('datafieldaccessor_data_invalid',$field);
+ }
+}
+
diff --git a/framework/Util/TDateTimeStamp.php b/framework/Util/TDateTimeStamp.php
index 50c669d7..8232d924 100644
--- a/framework/Util/TDateTimeStamp.php
+++ b/framework/Util/TDateTimeStamp.php
@@ -1,703 +1,703 @@
-<?php
-/**
- * TDateTimeStamp class file.
- *
- * COPYRIGHT
- * (c) 2003-2005 John Lim and released under BSD-style license except for code by
- * jackbbs, which includes getTimeStamp, getGMTDiff, isLeapYear
- * and originally found at http://www.php.net/manual/en/function.mktime.php
- *
- * @author Wei Zhuo <weizhuo[at]gamil[dot]com>
- * @link http://www.pradosoft.com/
- * @copyright Copyright &copy; 2005-2012 PradoSoft
- * @license http://www.pradosoft.com/license/
- * @version $Id$
- * @package System.Util
- */
-
-/*
- This code was originally for windows. But apparently this problem happens
- also with Linux, RH 7.3 and later!
-
- glibc-2.2.5-34 and greater has been changed to return -1 for dates <
- 1970. This used to work. The problem exists with RedHat 7.3 and 8.0
- echo (mktime(0, 0, 0, 1, 1, 1960)); // prints -1
-
- References:
- http://bugs.php.net/bug.php?id=20048&edit=2
- http://lists.debian.org/debian-glibc/2002/debian-glibc-200205/msg00010.html
-*/
-
-if (!defined('ADODB_ALLOW_NEGATIVE_TS')
- && !defined('ADODB_NO_NEGATIVE_TS')) define('ADODB_NO_NEGATIVE_TS',1);
-
-/**
- * TDateTimeStamp Class
- *
- * TDateTimeStamp Class is adpated from the ADOdb Date Library,
- * part of the ADOdb abstraction library
- * Download: http://phplens.com/phpeverywhere/
- *
- * http://phplens.com/phpeverywhere/adodb_date_library
- *
- * PHP native date functions use integer timestamps for computations.
- * Because of this, dates are restricted to the years 1901-2038 on Unix
- * and 1970-2038 on Windows due to integer overflow for dates beyond
- * those years. This library overcomes these limitations by replacing the
- * native function's signed integers (normally 32-bits) with PHP floating
- * point numbers (normally 64-bits).
- *
- * Dates from 100 A.D. to 3000 A.D. and later have been tested. The minimum
- * is 100 A.D. as <100 will invoke the 2 => 4 digit year conversion.
- * The maximum is billions of years in the future, but this is a theoretical
- * limit as the computation of that year would take too long with the
- * current implementation of {@link getTimeStamp}.
- *
- * PERFORMANCE
- * For high speed, this library uses the native date functions where
- * possible, and only switches to PHP code when the dates fall outside
- * the 32-bit signed integer range.
- *
- * @author Wei Zhuo <weizhuo[at]gmail[dot]com>
- * @version $Id$
- * @package System.Util
- * @since 3.0.4
- */
-class TDateTimeStamp
-{
- protected static $_month_normal = array("",31,28,31,30,31,30,31,31,30,31,30,31);
- protected static $_month_leaf = array("",31,29,31,30,31,30,31,31,30,31,30,31);
-
- /**
- * Gets day of week, 0 = Sunday,... 6=Saturday.
- * Algorithm from PEAR::Date_Calc
- */
- public function getDayofWeek($year, $month, $day)
- {
- /*
- Pope Gregory removed 10 days - October 5 to October 14 - from the year 1582 and
- proclaimed that from that time onwards 3 days would be dropped from the calendar
- every 400 years.
-
- Thursday, October 4, 1582 (Julian) was followed immediately by Friday, October 15, 1582 (Gregorian).
- */
- if ($year <= 1582)
- {
- if ($year < 1582 ||
- ($year == 1582 && ($month < 10 || ($month == 10 && $day < 15))))
- {
- $greg_correction = 3;
- }
- else
- {
- $greg_correction = 0;
- }
- }
- else
- {
- $greg_correction = 0;
- }
-
- if($month > 2)
- $month -= 2;
- else
- {
- $month += 10;
- $year--;
- }
-
- $day = floor((13 * $month - 1) / 5) +
- $day + ($year % 100) +
- floor(($year % 100) / 4) +
- floor(($year / 100) / 4) - 2 *
- floor($year / 100) + 77 + $greg_correction;
-
- return $day - 7 * floor($day / 7);
- }
-
- /**
- * Checks for leap year, returns true if it is. No 2-digit year check. Also
- * handles julian calendar correctly.
- * @param float year to check
- * @return boolean true if is leap year
- */
- public function isLeapYear($year)
- {
- $year = $this->digitCheck($year);
- if ($year % 4 != 0)
- return false;
-
- if ($year % 400 == 0)
- return true;
- // if gregorian calendar (>1582), century not-divisible by 400 is not leap
- else if ($year > 1582 && $year % 100 == 0 )
- return false;
- return true;
- }
-
- /**
- * Fix 2-digit years. Works for any century.
- * Assumes that if 2-digit is more than 30 years in future, then previous century.
- * @return integer change two digit year into multiple digits
- */
- protected function digitCheck($y)
- {
- if ($y < 100){
- $yr = (integer) date("Y");
- $century = (integer) ($yr /100);
-
- if ($yr%100 > 50) {
- $c1 = $century + 1;
- $c0 = $century;
- } else {
- $c1 = $century;
- $c0 = $century - 1;
- }
- $c1 *= 100;
- // if 2-digit year is less than 30 years in future, set it to this century
- // otherwise if more than 30 years in future, then we set 2-digit year to the prev century.
- if (($y + $c1) < $yr+30) $y = $y + $c1;
- else $y = $y + $c0*100;
- }
- return $y;
- }
-
- public function get4DigitYear($y)
- {
- return $this->digitCheck($y);
- }
-
- /**
- * @return integer get local time zone offset from GMT
- */
- public function getGMTDiff()
- {
- static $TZ;
- if (isset($TZ)) return $TZ;
-
- $TZ = mktime(0,0,0,1,2,1970) - gmmktime(0,0,0,1,2,1970);
- return $TZ;
- }
-
- /**
- * @return array an array with date info.
- */
- function getDate($d=false,$fast=false)
- {
- if ($d === false) return getdate();
- // check if number in 32-bit signed range
- if ((abs($d) <= 0x7FFFFFFF))
- {
- if (!defined('ADODB_NO_NEGATIVE_TS') || $d >= 0) // if windows, must be +ve integer
- return @getdate($d);
- }
- return $this->_getDateInternal($d);
- }
-
-
-
- /**
- * Low-level function that returns the getdate() array. We have a special
- * $fast flag, which if set to true, will return fewer array values,
- * and is much faster as it does not calculate dow, etc.
- * @param float original date
- * @param boolean false to compute the day of the week, default is true
- * @param boolean true to calculate the GMT dates
- * @return array an array with date info.
- */
- protected function _getDateInternal($origd=false,$fast=true,$is_gmt=false)
- {
- static $YRS;
-
- $d = $origd - ($is_gmt ? 0 : $this->getGMTDiff());
-
- $_day_power = 86400;
- $_hour_power = 3600;
- $_min_power = 60;
-
- if ($d < -12219321600)
- $d -= 86400*10; // if 15 Oct 1582 or earlier, gregorian correction
-
- $_month_table_normal =& self::$_month_normal;
- $_month_table_leaf = & self::$_month_leaf;
-
- $d366 = $_day_power * 366;
- $d365 = $_day_power * 365;
-
- if ($d < 0)
- {
- if (empty($YRS))
- $YRS = array(
- 1970 => 0,
- 1960 => -315619200,
- 1950 => -631152000,
- 1940 => -946771200,
- 1930 => -1262304000,
- 1920 => -1577923200,
- 1910 => -1893456000,
- 1900 => -2208988800,
- 1890 => -2524521600,
- 1880 => -2840140800,
- 1870 => -3155673600,
- 1860 => -3471292800,
- 1850 => -3786825600,
- 1840 => -4102444800,
- 1830 => -4417977600,
- 1820 => -4733596800,
- 1810 => -5049129600,
- 1800 => -5364662400,
- 1790 => -5680195200,
- 1780 => -5995814400,
- 1770 => -6311347200,
- 1760 => -6626966400,
- 1750 => -6942499200,
- 1740 => -7258118400,
- 1730 => -7573651200,
- 1720 => -7889270400,
- 1710 => -8204803200,
- 1700 => -8520336000,
- 1690 => -8835868800,
- 1680 => -9151488000,
- 1670 => -9467020800,
- 1660 => -9782640000,
- 1650 => -10098172800,
- 1640 => -10413792000,
- 1630 => -10729324800,
- 1620 => -11044944000,
- 1610 => -11360476800,
- 1600 => -11676096000);
-
- if ($is_gmt)
- $origd = $d;
- // The valid range of a 32bit signed timestamp is typically from
- // Fri, 13 Dec 1901 20:45:54 GMT to Tue, 19 Jan 2038 03:14:07 GMT
- //
-
- # old algorithm iterates through all years. new algorithm does it in
- # 10 year blocks
-
- /*
- # old algo
- for ($a = 1970 ; --$a >= 0;) {
- $lastd = $d;
-
- if ($leaf = _adodb_is_leap_year($a)) $d += $d366;
- else $d += $d365;
-
- if ($d >= 0) {
- $year = $a;
- break;
- }
- }
- */
-
- $lastsecs = 0;
- $lastyear = 1970;
- foreach($YRS as $year => $secs)
- {
- if ($d >= $secs)
- {
- $a = $lastyear;
- break;
- }
- $lastsecs = $secs;
- $lastyear = $year;
- }
-
- $d -= $lastsecs;
- if (!isset($a)) $a = $lastyear;
-
- //echo ' yr=',$a,' ', $d,'.';
-
- for (; --$a >= 0;)
- {
- $lastd = $d;
-
- if ($leaf = $this->isLeapYear($a))
- $d += $d366;
- else
- $d += $d365;
-
- if ($d >= 0)
- {
- $year = $a;
- break;
- }
- }
- /**/
-
- $secsInYear = 86400 * ($leaf ? 366 : 365) + $lastd;
-
- $d = $lastd;
- $mtab = ($leaf) ? $_month_table_leaf : $_month_table_normal;
- for ($a = 13 ; --$a > 0;)
- {
- $lastd = $d;
- $d += $mtab[$a] * $_day_power;
- if ($d >= 0)
- {
- $month = $a;
- $ndays = $mtab[$a];
- break;
- }
- }
-
- $d = $lastd;
- $day = $ndays + ceil(($d+1) / ($_day_power));
-
- $d += ($ndays - $day+1)* $_day_power;
- $hour = floor($d/$_hour_power);
-
- } else {
- for ($a = 1970 ;; $a++)
- {
- $lastd = $d;
-
- if ($leaf = $this->isLeapYear($a)) $d -= $d366;
- else $d -= $d365;
- if ($d < 0)
- {
- $year = $a;
- break;
- }
- }
- $secsInYear = $lastd;
- $d = $lastd;
- $mtab = ($leaf) ? $_month_table_leaf : $_month_table_normal;
- for ($a = 1 ; $a <= 12; $a++)
- {
- $lastd = $d;
- $d -= $mtab[$a] * $_day_power;
- if ($d < 0)
- {
- $month = $a;
- $ndays = $mtab[$a];
- break;
- }
- }
- $d = $lastd;
- $day = ceil(($d+1) / $_day_power);
- $d = $d - ($day-1) * $_day_power;
- $hour = floor($d /$_hour_power);
- }
-
- $d -= $hour * $_hour_power;
- $min = floor($d/$_min_power);
- $secs = $d - $min * $_min_power;
- if ($fast)
- {
- return array(
- 'seconds' => $secs,
- 'minutes' => $min,
- 'hours' => $hour,
- 'mday' => $day,
- 'mon' => $month,
- 'year' => $year,
- 'yday' => floor($secsInYear/$_day_power),
- 'leap' => $leaf,
- 'ndays' => $ndays
- );
- }
-
-
- $dow = $this->getDayofWeek($year,$month,$day);
-
- return array(
- 'seconds' => $secs,
- 'minutes' => $min,
- 'hours' => $hour,
- 'mday' => $day,
- 'wday' => $dow,
- 'mon' => $month,
- 'year' => $year,
- 'yday' => floor($secsInYear/$_day_power),
- 'weekday' => gmdate('l',$_day_power*(3+$dow)),
- 'month' => gmdate('F',mktime(0,0,0,$month,2,1971)),
- 0 => $origd
- );
- }
-
- /**
- * @return boolean true if valid date, semantic check only.
- */
- public function isValidDate($y,$m,$d)
- {
- if ($this->isLeapYear($y))
- $marr =& self::$_month_leaf;
- else
- $marr =& self::$_month_normal;
-
- if ($m > 12 || $m < 1) return false;
-
- if ($d > 31 || $d < 1) return false;
-
- if ($marr[$m] < $d) return false;
-
- if ($y < 1000 && $y > 3000) return false;
-
- return true;
- }
-
- /**
- * @return string formatted date based on timestamp $d
- */
- function formatDate($fmt,$d=false,$is_gmt=false)
- {
- if ($d === false)
- return ($is_gmt)? @gmdate($fmt): @date($fmt);
-
- // check if number in 32-bit signed range
- if ((abs($d) <= 0x7FFFFFFF))
- {
- // if windows, must be +ve integer
- if (!defined('ADODB_NO_NEGATIVE_TS') || $d >= 0)
- return ($is_gmt)? @gmdate($fmt,$d): @date($fmt,$d);
- }
-
- $_day_power = 86400;
-
- $arr = $this->getDate($d,true,$is_gmt);
-
- $year = $arr['year'];
- $month = $arr['mon'];
- $day = $arr['mday'];
- $hour = $arr['hours'];
- $min = $arr['minutes'];
- $secs = $arr['seconds'];
-
- $max = strlen($fmt);
- $dates = '';
-
- $isphp5 = PHP_VERSION >= 5;
-
- /*
- at this point, we have the following integer vars to manipulate:
- $year, $month, $day, $hour, $min, $secs
- */
- for ($i=0; $i < $max; $i++)
- {
- switch($fmt[$i])
- {
- case 'T': $dates .= date('T');break;
- // YEAR
- case 'L': $dates .= $arr['leap'] ? '1' : '0'; break;
- case 'r': // Thu, 21 Dec 2000 16:01:07 +0200
-
- // 4.3.11 uses '04 Jun 2004'
- // 4.3.8 uses ' 4 Jun 2004'
- $dates .= gmdate('D',$_day_power*(3+$this->getDayOfWeek($year,$month,$day))).', '
- . ($day<10?'0'.$day:$day) . ' '.date('M',mktime(0,0,0,$month,2,1971)).' '.$year.' ';
-
- if ($hour < 10) $dates .= '0'.$hour; else $dates .= $hour;
-
- if ($min < 10) $dates .= ':0'.$min; else $dates .= ':'.$min;
-
- if ($secs < 10) $dates .= ':0'.$secs; else $dates .= ':'.$secs;
-
- $gmt = $this->getGMTDiff();
- if ($isphp5)
- $dates .= sprintf(' %s%04d',($gmt<=0)?'+':'-',abs($gmt)/36);
- else
- $dates .= sprintf(' %s%04d',($gmt<0)?'+':'-',abs($gmt)/36);
- break;
-
- case 'Y': $dates .= $year; break;
- case 'y': $dates .= substr($year,strlen($year)-2,2); break;
- // MONTH
- case 'm': if ($month<10) $dates .= '0'.$month; else $dates .= $month; break;
- case 'Q': $dates .= ($month+3)>>2; break;
- case 'n': $dates .= $month; break;
- case 'M': $dates .= date('M',mktime(0,0,0,$month,2,1971)); break;
- case 'F': $dates .= date('F',mktime(0,0,0,$month,2,1971)); break;
- // DAY
- case 't': $dates .= $arr['ndays']; break;
- case 'z': $dates .= $arr['yday']; break;
- case 'w': $dates .= $this->getDayOfWeek($year,$month,$day); break;
- case 'l': $dates .= gmdate('l',$_day_power*(3+$this->getDayOfWeek($year,$month,$day))); break;
- case 'D': $dates .= gmdate('D',$_day_power*(3+$this->getDayOfWeek($year,$month,$day))); break;
- case 'j': $dates .= $day; break;
- case 'd': if ($day<10) $dates .= '0'.$day; else $dates .= $day; break;
- case 'S':
- $d10 = $day % 10;
- if ($d10 == 1) $dates .= 'st';
- else if ($d10 == 2 && $day != 12) $dates .= 'nd';
- else if ($d10 == 3) $dates .= 'rd';
- else $dates .= 'th';
- break;
-
- // HOUR
- case 'Z':
- $dates .= ($is_gmt) ? 0 : -$this->getGMTDiff(); break;
- case 'O':
- $gmt = ($is_gmt) ? 0 : $this->getGMTDiff();
-
- if ($isphp5)
- $dates .= sprintf('%s%04d',($gmt<=0)?'+':'-',abs($gmt)/36);
- else
- $dates .= sprintf('%s%04d',($gmt<0)?'+':'-',abs($gmt)/36);
- break;
-
- case 'H':
- if ($hour < 10) $dates .= '0'.$hour;
- else $dates .= $hour;
- break;
- case 'h':
- if ($hour > 12) $hh = $hour - 12;
- else {
- if ($hour == 0) $hh = '12';
- else $hh = $hour;
- }
-
- if ($hh < 10) $dates .= '0'.$hh;
- else $dates .= $hh;
- break;
-
- case 'G':
- $dates .= $hour;
- break;
-
- case 'g':
- if ($hour > 12) $hh = $hour - 12;
- else {
- if ($hour == 0) $hh = '12';
- else $hh = $hour;
- }
- $dates .= $hh;
- break;
- // MINUTES
- case 'i': if ($min < 10) $dates .= '0'.$min; else $dates .= $min; break;
- // SECONDS
- case 'U': $dates .= $d; break;
- case 's': if ($secs < 10) $dates .= '0'.$secs; else $dates .= $secs; break;
- // AM/PM
- // Note 00:00 to 11:59 is AM, while 12:00 to 23:59 is PM
- case 'a':
- if ($hour>=12) $dates .= 'pm';
- else $dates .= 'am';
- break;
- case 'A':
- if ($hour>=12) $dates .= 'PM';
- else $dates .= 'AM';
- break;
- default:
- $dates .= $fmt[$i]; break;
- // ESCAPE
- case "\\":
- $i++;
- if ($i < $max) $dates .= $fmt[$i];
- break;
- }
- }
- return $dates;
- }
-
- /**
- * Not a very fast algorithm - O(n) operation. Could be optimized to O(1).
- * @return integer|float a timestamp given a local time. Originally by jackbbs.
- */
- function getTimeStamp($hr,$min,$sec,$mon=false,$day=false,$year=false,$is_gmt=false)
- {
-
- if ($mon === false)
- return $is_gmt? @gmmktime($hr,$min,$sec): @mktime($hr,$min,$sec);
-
- // for windows, we don't check 1970 because with timezone differences,
- // 1 Jan 1970 could generate negative timestamp, which is illegal
- if (1971 <= $year && $year < 2038 || !defined('ADODB_NO_NEGATIVE_TS')
- && (1901 < $year && $year < 2038))
- {
- return $is_gmt ? @gmmktime($hr,$min,$sec,$mon,$day,$year)
- : @mktime($hr,$min,$sec,$mon,$day,$year);
- }
-
- $gmt_different = ($is_gmt) ? 0 : $this->getGMTDiff();
-
- /*
- # disabled because some people place large values in $sec.
- # however we need it for $mon because we use an array...
- $hr = intval($hr);
- $min = intval($min);
- $sec = intval($sec);
- */
- $mon = (int)$mon;
- $day = (int)$day;
- $year = (int)$year;
-
-
- $year = $this->digitCheck($year);
-
- if ($mon > 12)
- {
- $y = floor($mon / 12);
- $year += $y;
- $mon -= $y*12;
- }
- else if ($mon < 1)
- {
- $y = ceil((1-$mon) / 12);
- $year -= $y;
- $mon += $y*12;
- }
-
- $_day_power = 86400;
- $_hour_power = 3600;
- $_min_power = 60;
-
- $_month_table_normal = & self::$_month_normal;
- $_month_table_leaf = & self::$_month_leaf;
-
- $_total_date = 0;
- if ($year >= 1970)
- {
- for ($a = 1970 ; $a <= $year; $a++)
- {
- $leaf = $this->isLeapYear($a);
- if ($leaf == true) {
- $loop_table = $_month_table_leaf;
- $_add_date = 366;
- } else {
- $loop_table = $_month_table_normal;
- $_add_date = 365;
- }
- if ($a < $year) {
- $_total_date += $_add_date;
- } else {
- for($b=1;$b<$mon;$b++) {
- $_total_date += $loop_table[$b];
- }
- }
- }
- $_total_date +=$day-1;
- $ret = $_total_date * $_day_power + $hr * $_hour_power + $min * $_min_power + $sec + $gmt_different;
-
- } else {
- for ($a = 1969 ; $a >= $year; $a--) {
- $leaf = $this->isLeapYear($a);
- if ($leaf == true) {
- $loop_table = $_month_table_leaf;
- $_add_date = 366;
- } else {
- $loop_table = $_month_table_normal;
- $_add_date = 365;
- }
- if ($a > $year) { $_total_date += $_add_date;
- } else {
- for($b=12;$b>$mon;$b--) {
- $_total_date += $loop_table[$b];
- }
- }
- }
- $_total_date += $loop_table[$mon] - $day;
-
- $_day_time = $hr * $_hour_power + $min * $_min_power + $sec;
- $_day_time = $_day_power - $_day_time;
- $ret = -( $_total_date * $_day_power + $_day_time - $gmt_different);
- if ($ret < -12220185600) $ret += 10*86400; // if earlier than 5 Oct 1582 - gregorian correction
- else if ($ret < -12219321600) $ret = -12219321600; // if in limbo, reset to 15 Oct 1582.
- }
- //print " dmy=$day/$mon/$year $hr:$min:$sec => " .$ret;
- return $ret;
- }
-}
-
-?>
+<?php
+/**
+ * TDateTimeStamp class file.
+ *
+ * COPYRIGHT
+ * (c) 2003-2005 John Lim and released under BSD-style license except for code by
+ * jackbbs, which includes getTimeStamp, getGMTDiff, isLeapYear
+ * and originally found at http://www.php.net/manual/en/function.mktime.php
+ *
+ * @author Wei Zhuo <weizhuo[at]gamil[dot]com>
+ * @link http://www.pradosoft.com/
+ * @copyright Copyright &copy; 2005-2012 PradoSoft
+ * @license http://www.pradosoft.com/license/
+ * @version $Id$
+ * @package System.Util
+ */
+
+/*
+ This code was originally for windows. But apparently this problem happens
+ also with Linux, RH 7.3 and later!
+
+ glibc-2.2.5-34 and greater has been changed to return -1 for dates <
+ 1970. This used to work. The problem exists with RedHat 7.3 and 8.0
+ echo (mktime(0, 0, 0, 1, 1, 1960)); // prints -1
+
+ References:
+ http://bugs.php.net/bug.php?id=20048&edit=2
+ http://lists.debian.org/debian-glibc/2002/debian-glibc-200205/msg00010.html
+*/
+
+if (!defined('ADODB_ALLOW_NEGATIVE_TS')
+ && !defined('ADODB_NO_NEGATIVE_TS')) define('ADODB_NO_NEGATIVE_TS',1);
+
+/**
+ * TDateTimeStamp Class
+ *
+ * TDateTimeStamp Class is adpated from the ADOdb Date Library,
+ * part of the ADOdb abstraction library
+ * Download: http://phplens.com/phpeverywhere/
+ *
+ * http://phplens.com/phpeverywhere/adodb_date_library
+ *
+ * PHP native date functions use integer timestamps for computations.
+ * Because of this, dates are restricted to the years 1901-2038 on Unix
+ * and 1970-2038 on Windows due to integer overflow for dates beyond
+ * those years. This library overcomes these limitations by replacing the
+ * native function's signed integers (normally 32-bits) with PHP floating
+ * point numbers (normally 64-bits).
+ *
+ * Dates from 100 A.D. to 3000 A.D. and later have been tested. The minimum
+ * is 100 A.D. as <100 will invoke the 2 => 4 digit year conversion.
+ * The maximum is billions of years in the future, but this is a theoretical
+ * limit as the computation of that year would take too long with the
+ * current implementation of {@link getTimeStamp}.
+ *
+ * PERFORMANCE
+ * For high speed, this library uses the native date functions where
+ * possible, and only switches to PHP code when the dates fall outside
+ * the 32-bit signed integer range.
+ *
+ * @author Wei Zhuo <weizhuo[at]gmail[dot]com>
+ * @version $Id$
+ * @package System.Util
+ * @since 3.0.4
+ */
+class TDateTimeStamp
+{
+ protected static $_month_normal = array("",31,28,31,30,31,30,31,31,30,31,30,31);
+ protected static $_month_leaf = array("",31,29,31,30,31,30,31,31,30,31,30,31);
+
+ /**
+ * Gets day of week, 0 = Sunday,... 6=Saturday.
+ * Algorithm from PEAR::Date_Calc
+ */
+ public function getDayofWeek($year, $month, $day)
+ {
+ /*
+ Pope Gregory removed 10 days - October 5 to October 14 - from the year 1582 and
+ proclaimed that from that time onwards 3 days would be dropped from the calendar
+ every 400 years.
+
+ Thursday, October 4, 1582 (Julian) was followed immediately by Friday, October 15, 1582 (Gregorian).
+ */
+ if ($year <= 1582)
+ {
+ if ($year < 1582 ||
+ ($year == 1582 && ($month < 10 || ($month == 10 && $day < 15))))
+ {
+ $greg_correction = 3;
+ }
+ else
+ {
+ $greg_correction = 0;
+ }
+ }
+ else
+ {
+ $greg_correction = 0;
+ }
+
+ if($month > 2)
+ $month -= 2;
+ else
+ {
+ $month += 10;
+ $year--;
+ }
+
+ $day = floor((13 * $month - 1) / 5) +
+ $day + ($year % 100) +
+ floor(($year % 100) / 4) +
+ floor(($year / 100) / 4) - 2 *
+ floor($year / 100) + 77 + $greg_correction;
+
+ return $day - 7 * floor($day / 7);
+ }
+
+ /**
+ * Checks for leap year, returns true if it is. No 2-digit year check. Also
+ * handles julian calendar correctly.
+ * @param float year to check
+ * @return boolean true if is leap year
+ */
+ public function isLeapYear($year)
+ {
+ $year = $this->digitCheck($year);
+ if ($year % 4 != 0)
+ return false;
+
+ if ($year % 400 == 0)
+ return true;
+ // if gregorian calendar (>1582), century not-divisible by 400 is not leap
+ else if ($year > 1582 && $year % 100 == 0 )
+ return false;
+ return true;
+ }
+
+ /**
+ * Fix 2-digit years. Works for any century.
+ * Assumes that if 2-digit is more than 30 years in future, then previous century.
+ * @return integer change two digit year into multiple digits
+ */
+ protected function digitCheck($y)
+ {
+ if ($y < 100){
+ $yr = (integer) date("Y");
+ $century = (integer) ($yr /100);
+
+ if ($yr%100 > 50) {
+ $c1 = $century + 1;
+ $c0 = $century;
+ } else {
+ $c1 = $century;
+ $c0 = $century - 1;
+ }
+ $c1 *= 100;
+ // if 2-digit year is less than 30 years in future, set it to this century
+ // otherwise if more than 30 years in future, then we set 2-digit year to the prev century.
+ if (($y + $c1) < $yr+30) $y = $y + $c1;
+ else $y = $y + $c0*100;
+ }
+ return $y;
+ }
+
+ public function get4DigitYear($y)
+ {
+ return $this->digitCheck($y);
+ }
+
+ /**
+ * @return integer get local time zone offset from GMT
+ */
+ public function getGMTDiff()
+ {
+ static $TZ;
+ if (isset($TZ)) return $TZ;
+
+ $TZ = mktime(0,0,0,1,2,1970) - gmmktime(0,0,0,1,2,1970);
+ return $TZ;
+ }
+
+ /**
+ * @return array an array with date info.
+ */
+ function getDate($d=false,$fast=false)
+ {
+ if ($d === false) return getdate();
+ // check if number in 32-bit signed range
+ if ((abs($d) <= 0x7FFFFFFF))
+ {
+ if (!defined('ADODB_NO_NEGATIVE_TS') || $d >= 0) // if windows, must be +ve integer
+ return @getdate($d);
+ }
+ return $this->_getDateInternal($d);
+ }
+
+
+
+ /**
+ * Low-level function that returns the getdate() array. We have a special
+ * $fast flag, which if set to true, will return fewer array values,
+ * and is much faster as it does not calculate dow, etc.
+ * @param float original date
+ * @param boolean false to compute the day of the week, default is true
+ * @param boolean true to calculate the GMT dates
+ * @return array an array with date info.
+ */
+ protected function _getDateInternal($origd=false,$fast=true,$is_gmt=false)
+ {
+ static $YRS;
+
+ $d = $origd - ($is_gmt ? 0 : $this->getGMTDiff());
+
+ $_day_power = 86400;
+ $_hour_power = 3600;
+ $_min_power = 60;
+
+ if ($d < -12219321600)
+ $d -= 86400*10; // if 15 Oct 1582 or earlier, gregorian correction
+
+ $_month_table_normal =& self::$_month_normal;
+ $_month_table_leaf = & self::$_month_leaf;
+
+ $d366 = $_day_power * 366;
+ $d365 = $_day_power * 365;
+
+ if ($d < 0)
+ {
+ if (empty($YRS))
+ $YRS = array(
+ 1970 => 0,
+ 1960 => -315619200,
+ 1950 => -631152000,
+ 1940 => -946771200,
+ 1930 => -1262304000,
+ 1920 => -1577923200,
+ 1910 => -1893456000,
+ 1900 => -2208988800,
+ 1890 => -2524521600,
+ 1880 => -2840140800,
+ 1870 => -3155673600,
+ 1860 => -3471292800,
+ 1850 => -3786825600,
+ 1840 => -4102444800,
+ 1830 => -4417977600,
+ 1820 => -4733596800,
+ 1810 => -5049129600,
+ 1800 => -5364662400,
+ 1790 => -5680195200,
+ 1780 => -5995814400,
+ 1770 => -6311347200,
+ 1760 => -6626966400,
+ 1750 => -6942499200,
+ 1740 => -7258118400,
+ 1730 => -7573651200,
+ 1720 => -7889270400,
+ 1710 => -8204803200,
+ 1700 => -8520336000,
+ 1690 => -8835868800,
+ 1680 => -9151488000,
+ 1670 => -9467020800,
+ 1660 => -9782640000,
+ 1650 => -10098172800,
+ 1640 => -10413792000,
+ 1630 => -10729324800,
+ 1620 => -11044944000,
+ 1610 => -11360476800,
+ 1600 => -11676096000);
+
+ if ($is_gmt)
+ $origd = $d;
+ // The valid range of a 32bit signed timestamp is typically from
+ // Fri, 13 Dec 1901 20:45:54 GMT to Tue, 19 Jan 2038 03:14:07 GMT
+ //
+
+ # old algorithm iterates through all years. new algorithm does it in
+ # 10 year blocks
+
+ /*
+ # old algo
+ for ($a = 1970 ; --$a >= 0;) {
+ $lastd = $d;
+
+ if ($leaf = _adodb_is_leap_year($a)) $d += $d366;
+ else $d += $d365;
+
+ if ($d >= 0) {
+ $year = $a;
+ break;
+ }
+ }
+ */
+
+ $lastsecs = 0;
+ $lastyear = 1970;
+ foreach($YRS as $year => $secs)
+ {
+ if ($d >= $secs)
+ {
+ $a = $lastyear;
+ break;
+ }
+ $lastsecs = $secs;
+ $lastyear = $year;
+ }
+
+ $d -= $lastsecs;
+ if (!isset($a)) $a = $lastyear;
+
+ //echo ' yr=',$a,' ', $d,'.';
+
+ for (; --$a >= 0;)
+ {
+ $lastd = $d;
+
+ if ($leaf = $this->isLeapYear($a))
+ $d += $d366;
+ else
+ $d += $d365;
+
+ if ($d >= 0)
+ {
+ $year = $a;
+ break;
+ }
+ }
+ /**/
+
+ $secsInYear = 86400 * ($leaf ? 366 : 365) + $lastd;
+
+ $d = $lastd;
+ $mtab = ($leaf) ? $_month_table_leaf : $_month_table_normal;
+ for ($a = 13 ; --$a > 0;)
+ {
+ $lastd = $d;
+ $d += $mtab[$a] * $_day_power;
+ if ($d >= 0)
+ {
+ $month = $a;
+ $ndays = $mtab[$a];
+ break;
+ }
+ }
+
+ $d = $lastd;
+ $day = $ndays + ceil(($d+1) / ($_day_power));
+
+ $d += ($ndays - $day+1)* $_day_power;
+ $hour = floor($d/$_hour_power);
+
+ } else {
+ for ($a = 1970 ;; $a++)
+ {
+ $lastd = $d;
+
+ if ($leaf = $this->isLeapYear($a)) $d -= $d366;
+ else $d -= $d365;
+ if ($d < 0)
+ {
+ $year = $a;
+ break;
+ }
+ }
+ $secsInYear = $lastd;
+ $d = $lastd;
+ $mtab = ($leaf) ? $_month_table_leaf : $_month_table_normal;
+ for ($a = 1 ; $a <= 12; $a++)
+ {
+ $lastd = $d;
+ $d -= $mtab[$a] * $_day_power;
+ if ($d < 0)
+ {
+ $month = $a;
+ $ndays = $mtab[$a];
+ break;
+ }
+ }
+ $d = $lastd;
+ $day = ceil(($d+1) / $_day_power);
+ $d = $d - ($day-1) * $_day_power;
+ $hour = floor($d /$_hour_power);
+ }
+
+ $d -= $hour * $_hour_power;
+ $min = floor($d/$_min_power);
+ $secs = $d - $min * $_min_power;
+ if ($fast)
+ {
+ return array(
+ 'seconds' => $secs,
+ 'minutes' => $min,
+ 'hours' => $hour,
+ 'mday' => $day,
+ 'mon' => $month,
+ 'year' => $year,
+ 'yday' => floor($secsInYear/$_day_power),
+ 'leap' => $leaf,
+ 'ndays' => $ndays
+ );
+ }
+
+
+ $dow = $this->getDayofWeek($year,$month,$day);
+
+ return array(
+ 'seconds' => $secs,
+ 'minutes' => $min,
+ 'hours' => $hour,
+ 'mday' => $day,
+ 'wday' => $dow,
+ 'mon' => $month,
+ 'year' => $year,
+ 'yday' => floor($secsInYear/$_day_power),
+ 'weekday' => gmdate('l',$_day_power*(3+$dow)),
+ 'month' => gmdate('F',mktime(0,0,0,$month,2,1971)),
+ 0 => $origd
+ );
+ }
+
+ /**
+ * @return boolean true if valid date, semantic check only.
+ */
+ public function isValidDate($y,$m,$d)
+ {
+ if ($this->isLeapYear($y))
+ $marr =& self::$_month_leaf;
+ else
+ $marr =& self::$_month_normal;
+
+ if ($m > 12 || $m < 1) return false;
+
+ if ($d > 31 || $d < 1) return false;
+
+ if ($marr[$m] < $d) return false;
+
+ if ($y < 1000 && $y > 3000) return false;
+
+ return true;
+ }
+
+ /**
+ * @return string formatted date based on timestamp $d
+ */
+ function formatDate($fmt,$d=false,$is_gmt=false)
+ {
+ if ($d === false)
+ return ($is_gmt)? @gmdate($fmt): @date($fmt);
+
+ // check if number in 32-bit signed range
+ if ((abs($d) <= 0x7FFFFFFF))
+ {
+ // if windows, must be +ve integer
+ if (!defined('ADODB_NO_NEGATIVE_TS') || $d >= 0)
+ return ($is_gmt)? @gmdate($fmt,$d): @date($fmt,$d);
+ }
+
+ $_day_power = 86400;
+
+ $arr = $this->getDate($d,true,$is_gmt);
+
+ $year = $arr['year'];
+ $month = $arr['mon'];
+ $day = $arr['mday'];
+ $hour = $arr['hours'];
+ $min = $arr['minutes'];
+ $secs = $arr['seconds'];
+
+ $max = strlen($fmt);
+ $dates = '';
+
+ $isphp5 = PHP_VERSION >= 5;
+
+ /*
+ at this point, we have the following integer vars to manipulate:
+ $year, $month, $day, $hour, $min, $secs
+ */
+ for ($i=0; $i < $max; $i++)
+ {
+ switch($fmt[$i])
+ {
+ case 'T': $dates .= date('T');break;
+ // YEAR
+ case 'L': $dates .= $arr['leap'] ? '1' : '0'; break;
+ case 'r': // Thu, 21 Dec 2000 16:01:07 +0200
+
+ // 4.3.11 uses '04 Jun 2004'
+ // 4.3.8 uses ' 4 Jun 2004'
+ $dates .= gmdate('D',$_day_power*(3+$this->getDayOfWeek($year,$month,$day))).', '
+ . ($day<10?'0'.$day:$day) . ' '.date('M',mktime(0,0,0,$month,2,1971)).' '.$year.' ';
+
+ if ($hour < 10) $dates .= '0'.$hour; else $dates .= $hour;
+
+ if ($min < 10) $dates .= ':0'.$min; else $dates .= ':'.$min;
+
+ if ($secs < 10) $dates .= ':0'.$secs; else $dates .= ':'.$secs;
+
+ $gmt = $this->getGMTDiff();
+ if ($isphp5)
+ $dates .= sprintf(' %s%04d',($gmt<=0)?'+':'-',abs($gmt)/36);
+ else
+ $dates .= sprintf(' %s%04d',($gmt<0)?'+':'-',abs($gmt)/36);
+ break;
+
+ case 'Y': $dates .= $year; break;
+ case 'y': $dates .= substr($year,strlen($year)-2,2); break;
+ // MONTH
+ case 'm': if ($month<10) $dates .= '0'.$month; else $dates .= $month; break;
+ case 'Q': $dates .= ($month+3)>>2; break;
+ case 'n': $dates .= $month; break;
+ case 'M': $dates .= date('M',mktime(0,0,0,$month,2,1971)); break;
+ case 'F': $dates .= date('F',mktime(0,0,0,$month,2,1971)); break;
+ // DAY
+ case 't': $dates .= $arr['ndays']; break;
+ case 'z': $dates .= $arr['yday']; break;
+ case 'w': $dates .= $this->getDayOfWeek($year,$month,$day); break;
+ case 'l': $dates .= gmdate('l',$_day_power*(3+$this->getDayOfWeek($year,$month,$day))); break;
+ case 'D': $dates .= gmdate('D',$_day_power*(3+$this->getDayOfWeek($year,$month,$day))); break;
+ case 'j': $dates .= $day; break;
+ case 'd': if ($day<10) $dates .= '0'.$day; else $dates .= $day; break;
+ case 'S':
+ $d10 = $day % 10;
+ if ($d10 == 1) $dates .= 'st';
+ else if ($d10 == 2 && $day != 12) $dates .= 'nd';
+ else if ($d10 == 3) $dates .= 'rd';
+ else $dates .= 'th';
+ break;
+
+ // HOUR
+ case 'Z':
+ $dates .= ($is_gmt) ? 0 : -$this->getGMTDiff(); break;
+ case 'O':
+ $gmt = ($is_gmt) ? 0 : $this->getGMTDiff();
+
+ if ($isphp5)
+ $dates .= sprintf('%s%04d',($gmt<=0)?'+':'-',abs($gmt)/36);
+ else
+ $dates .= sprintf('%s%04d',($gmt<0)?'+':'-',abs($gmt)/36);
+ break;
+
+ case 'H':
+ if ($hour < 10) $dates .= '0'.$hour;
+ else $dates .= $hour;
+ break;
+ case 'h':
+ if ($hour > 12) $hh = $hour - 12;
+ else {
+ if ($hour == 0) $hh = '12';
+ else $hh = $hour;
+ }
+
+ if ($hh < 10) $dates .= '0'.$hh;
+ else $dates .= $hh;
+ break;
+
+ case 'G':
+ $dates .= $hour;
+ break;
+
+ case 'g':
+ if ($hour > 12) $hh = $hour - 12;
+ else {
+ if ($hour == 0) $hh = '12';
+ else $hh = $hour;
+ }
+ $dates .= $hh;
+ break;
+ // MINUTES
+ case 'i': if ($min < 10) $dates .= '0'.$min; else $dates .= $min; break;
+ // SECONDS
+ case 'U': $dates .= $d; break;
+ case 's': if ($secs < 10) $dates .= '0'.$secs; else $dates .= $secs; break;
+ // AM/PM
+ // Note 00:00 to 11:59 is AM, while 12:00 to 23:59 is PM
+ case 'a':
+ if ($hour>=12) $dates .= 'pm';
+ else $dates .= 'am';
+ break;
+ case 'A':
+ if ($hour>=12) $dates .= 'PM';
+ else $dates .= 'AM';
+ break;
+ default:
+ $dates .= $fmt[$i]; break;
+ // ESCAPE
+ case "\\":
+ $i++;
+ if ($i < $max) $dates .= $fmt[$i];
+ break;
+ }
+ }
+ return $dates;
+ }
+
+ /**
+ * Not a very fast algorithm - O(n) operation. Could be optimized to O(1).
+ * @return integer|float a timestamp given a local time. Originally by jackbbs.
+ */
+ function getTimeStamp($hr,$min,$sec,$mon=false,$day=false,$year=false,$is_gmt=false)
+ {
+
+ if ($mon === false)
+ return $is_gmt? @gmmktime($hr,$min,$sec): @mktime($hr,$min,$sec);
+
+ // for windows, we don't check 1970 because with timezone differences,
+ // 1 Jan 1970 could generate negative timestamp, which is illegal
+ if (1971 <= $year && $year < 2038 || !defined('ADODB_NO_NEGATIVE_TS')
+ && (1901 < $year && $year < 2038))
+ {
+ return $is_gmt ? @gmmktime($hr,$min,$sec,$mon,$day,$year)
+ : @mktime($hr,$min,$sec,$mon,$day,$year);
+ }
+
+ $gmt_different = ($is_gmt) ? 0 : $this->getGMTDiff();
+
+ /*
+ # disabled because some people place large values in $sec.
+ # however we need it for $mon because we use an array...
+ $hr = intval($hr);
+ $min = intval($min);
+ $sec = intval($sec);
+ */
+ $mon = (int)$mon;
+ $day = (int)$day;
+ $year = (int)$year;
+
+
+ $year = $this->digitCheck($year);
+
+ if ($mon > 12)
+ {
+ $y = floor($mon / 12);
+ $year += $y;
+ $mon -= $y*12;
+ }
+ else if ($mon < 1)
+ {
+ $y = ceil((1-$mon) / 12);
+ $year -= $y;
+ $mon += $y*12;
+ }
+
+ $_day_power = 86400;
+ $_hour_power = 3600;
+ $_min_power = 60;
+
+ $_month_table_normal = & self::$_month_normal;
+ $_month_table_leaf = & self::$_month_leaf;
+
+ $_total_date = 0;
+ if ($year >= 1970)
+ {
+ for ($a = 1970 ; $a <= $year; $a++)
+ {
+ $leaf = $this->isLeapYear($a);
+ if ($leaf == true) {
+ $loop_table = $_month_table_leaf;
+ $_add_date = 366;
+ } else {
+ $loop_table = $_month_table_normal;
+ $_add_date = 365;
+ }
+ if ($a < $year) {
+ $_total_date += $_add_date;
+ } else {
+ for($b=1;$b<$mon;$b++) {
+ $_total_date += $loop_table[$b];
+ }
+ }
+ }
+ $_total_date +=$day-1;
+ $ret = $_total_date * $_day_power + $hr * $_hour_power + $min * $_min_power + $sec + $gmt_different;
+
+ } else {
+ for ($a = 1969 ; $a >= $year; $a--) {
+ $leaf = $this->isLeapYear($a);
+ if ($leaf == true) {
+ $loop_table = $_month_table_leaf;
+ $_add_date = 366;
+ } else {
+ $loop_table = $_month_table_normal;
+ $_add_date = 365;
+ }
+ if ($a > $year) { $_total_date += $_add_date;
+ } else {
+ for($b=12;$b>$mon;$b--) {
+ $_total_date += $loop_table[$b];
+ }
+ }
+ }
+ $_total_date += $loop_table[$mon] - $day;
+
+ $_day_time = $hr * $_hour_power + $min * $_min_power + $sec;
+ $_day_time = $_day_power - $_day_time;
+ $ret = -( $_total_date * $_day_power + $_day_time - $gmt_different);
+ if ($ret < -12220185600) $ret += 10*86400; // if earlier than 5 Oct 1582 - gregorian correction
+ else if ($ret < -12219321600) $ret = -12219321600; // if in limbo, reset to 15 Oct 1582.
+ }
+ //print " dmy=$day/$mon/$year $hr:$min:$sec => " .$ret;
+ return $ret;
+ }
+}
+
+?>
diff --git a/framework/Util/TLogRouter.php b/framework/Util/TLogRouter.php
index 20b0c663..14895899 100644
--- a/framework/Util/TLogRouter.php
+++ b/framework/Util/TLogRouter.php
@@ -1,1207 +1,1207 @@
-<?php
-/**
- * TLogRouter, TLogRoute, TFileLogRoute, TEmailLogRoute class file
- *
- * @author Qiang Xue <qiang.xue@gmail.com>
- * @link http://www.pradosoft.com/
- * @copyright Copyright &copy; 2005-2012 PradoSoft
- * @license http://www.pradosoft.com/license/
- * @version $Id$
- * @package System.Util
- */
-
-Prado::using('System.Data.TDbConnection');
-
-/**
- * TLogRouter class.
- *
- * TLogRouter manages routes that record log messages in different media different ways.
- * For example, a file log route {@link TFileLogRoute} records log messages
- * in log files. An email log route {@link TEmailLogRoute} sends log messages
- * to email addresses.
- *
- * Log routes may be configured in application or page folder configuration files
- * or an external configuration file specified by {@link setConfigFile ConfigFile}.
- * The format is as follows,
- * <code>
- * <route class="TFileLogRoute" Categories="System.Web.UI" Levels="Warning" />
- * <route class="TEmailLogRoute" Categories="Application" Levels="Fatal" Emails="admin@pradosoft.com" />
- * </code>
- * PHP configuration style:
- * <code>
- *
- * </code>
- * You can specify multiple routes with different filtering conditions and different
- * targets, even if the routes are of the same type.
- *
- * @author Qiang Xue <qiang.xue@gmail.com>
- * @author Carl G. Mathisen <carlgmathisen@gmail.com>
- * @version $Id$
- * @package System.Util
- * @since 3.0
- */
-class TLogRouter extends TModule
-{
- /**
- * @var array list of routes available
- */
- private $_routes=array();
- /**
- * @var string external configuration file
- */
- private $_configFile=null;
-
- /**
- * Initializes this module.
- * This method is required by the IModule interface.
- * @param mixed configuration for this module, can be null
- * @throws TConfigurationException if {@link getConfigFile ConfigFile} is invalid.
- */
- public function init($config)
- {
- if($this->_configFile!==null)
- {
- if(is_file($this->_configFile))
- {
- if($this->getApplication()->getConfigurationType()==TApplication::CONFIG_TYPE_PHP)
- {
- $phpConfig = include $this->_configFile;
- $this->loadConfig($phpConfig);
- }
- else
- {
- $dom=new TXmlDocument;
- $dom->loadFromFile($this->_configFile);
- $this->loadConfig($dom);
- }
- }
- else
- throw new TConfigurationException('logrouter_configfile_invalid',$this->_configFile);
- }
- $this->loadConfig($config);
- $this->getApplication()->attachEventHandler('OnEndRequest',array($this,'collectLogs'));
- }
-
- /**
- * Loads configuration from an XML element or PHP array
- * @param mixed configuration node
- * @throws TConfigurationException if log route class or type is not specified
- */
- private function loadConfig($config)
- {
- if(is_array($config))
- {
- if(isset($config['routes']) && is_array($config['routes']))
- {
- foreach($config['routes'] as $route)
- {
- $properties = isset($route['properties'])?$route['properties']:array();
- if(!isset($route['class']))
- throw new TConfigurationException('logrouter_routeclass_required');
- $route=Prado::createComponent($route['class']);
- if(!($route instanceof TLogRoute))
- throw new TConfigurationException('logrouter_routetype_invalid');
- foreach($properties as $name=>$value)
- $route->setSubproperty($name,$value);
- $this->_routes[]=$route;
- $route->init($route);
- }
- }
- }
- else
- {
- foreach($config->getElementsByTagName('route') as $routeConfig)
- {
- $properties=$routeConfig->getAttributes();
- if(($class=$properties->remove('class'))===null)
- throw new TConfigurationException('logrouter_routeclass_required');
- $route=Prado::createComponent($class);
- if(!($route instanceof TLogRoute))
- throw new TConfigurationException('logrouter_routetype_invalid');
- foreach($properties as $name=>$value)
- $route->setSubproperty($name,$value);
- $this->_routes[]=$route;
- $route->init($routeConfig);
- }
- }
- }
-
- /**
- * Adds a TLogRoute instance to the log router.
- *
- * @param TLogRoute $route
- * @throws TInvalidDataTypeException if the route object is invalid
- */
- public function addRoute($route)
- {
- if(!($route instanceof TLogRoute))
- throw new TInvalidDataTypeException('logrouter_routetype_invalid');
- $this->_routes[]=$route;
- $route->init(null);
- }
-
- /**
- * @return string external configuration file. Defaults to null.
- */
- public function getConfigFile()
- {
- return $this->_configFile;
- }
-
- /**
- * @param string external configuration file in namespace format. The file
- * must be suffixed with '.xml'.
- * @throws TConfigurationException if the file is invalid.
- */
- public function setConfigFile($value)
- {
- if(($this->_configFile=Prado::getPathOfNamespace($value,$this->getApplication()->getConfigurationFileExt()))===null)
- throw new TConfigurationException('logrouter_configfile_invalid',$value);
- }
-
- /**
- * Collects log messages from a logger.
- * This method is an event handler to application's EndRequest event.
- * @param mixed event parameter
- */
- public function collectLogs($param)
- {
- $logger=Prado::getLogger();
- foreach($this->_routes as $route)
- $route->collectLogs($logger);
- }
-}
-
-/**
- * TLogRoute class.
- *
- * TLogRoute is the base class for all log route classes.
- * A log route object retrieves log messages from a logger and sends it
- * somewhere, such as files, emails.
- * The messages being retrieved may be filtered first before being sent
- * to the destination. The filters include log level filter and log category filter.
- *
- * To specify level filter, set {@link setLevels Levels} property,
- * which takes a string of comma-separated desired level names (e.g. 'Error, Debug').
- * To specify category filter, set {@link setCategories Categories} property,
- * which takes a string of comma-separated desired category names (e.g. 'System.Web, System.IO').
- *
- * Level filter and category filter are combinational, i.e., only messages
- * satisfying both filter conditions will they be returned.
- *
- * @author Qiang Xue <qiang.xue@gmail.com>
- * @version $Id$
- * @package System.Util
- * @since 3.0
- */
-abstract class TLogRoute extends TApplicationComponent
-{
- /**
- * @var array lookup table for level names
- */
- protected static $_levelNames=array(
- TLogger::DEBUG=>'Debug',
- TLogger::INFO=>'Info',
- TLogger::NOTICE=>'Notice',
- TLogger::WARNING=>'Warning',
- TLogger::ERROR=>'Error',
- TLogger::ALERT=>'Alert',
- TLogger::FATAL=>'Fatal'
- );
- /**
- * @var array lookup table for level values
- */
- protected static $_levelValues=array(
- 'debug'=>TLogger::DEBUG,
- 'info'=>TLogger::INFO,
- 'notice'=>TLogger::NOTICE,
- 'warning'=>TLogger::WARNING,
- 'error'=>TLogger::ERROR,
- 'alert'=>TLogger::ALERT,
- 'fatal'=>TLogger::FATAL
- );
- /**
- * @var integer log level filter (bits)
- */
- private $_levels=null;
- /**
- * @var array log category filter
- */
- private $_categories=null;
-
- /**
- * Initializes the route.
- * @param TXmlElement configurations specified in {@link TLogRouter}.
- */
- public function init($config)
- {
- }
-
- /**
- * @return integer log level filter
- */
- public function getLevels()
- {
- return $this->_levels;
- }
-
- /**
- * @param integer|string integer log level filter (in bits). If the value is
- * a string, it is assumed to be comma-separated level names. Valid level names
- * include 'Debug', 'Info', 'Notice', 'Warning', 'Error', 'Alert' and 'Fatal'.
- */
- public function setLevels($levels)
- {
- if(is_integer($levels))
- $this->_levels=$levels;
- else
- {
- $this->_levels=null;
- $levels=strtolower($levels);
- foreach(explode(',',$levels) as $level)
- {
- $level=trim($level);
- if(isset(self::$_levelValues[$level]))
- $this->_levels|=self::$_levelValues[$level];
- }
- }
- }
-
- /**
- * @return array list of categories to be looked for
- */
- public function getCategories()
- {
- return $this->_categories;
- }
-
- /**
- * @param array|string list of categories to be looked for. If the value is a string,
- * it is assumed to be comma-separated category names.
- */
- public function setCategories($categories)
- {
- if(is_array($categories))
- $this->_categories=$categories;
- else
- {
- $this->_categories=null;
- foreach(explode(',',$categories) as $category)
- {
- if(($category=trim($category))!=='')
- $this->_categories[]=$category;
- }
- }
- }
-
- /**
- * @param integer level value
- * @return string level name
- */
- protected function getLevelName($level)
- {
- return isset(self::$_levelNames[$level])?self::$_levelNames[$level]:'Unknown';
- }
-
- /**
- * @param string level name
- * @return integer level value
- */
- protected function getLevelValue($level)
- {
- return isset(self::$_levelValues[$level])?self::$_levelValues[$level]:0;
- }
-
- /**
- * Formats a log message given different fields.
- * @param string message content
- * @param integer message level
- * @param string message category
- * @param integer timestamp
- * @return string formatted message
- */
- protected function formatLogMessage($message,$level,$category,$time)
- {
- return @gmdate('M d H:i:s',$time).' ['.$this->getLevelName($level).'] ['.$category.'] '.$message."\n";
- }
-
- /**
- * Retrieves log messages from logger to log route specific destination.
- * @param TLogger logger instance
- */
- public function collectLogs(TLogger $logger)
- {
- $logs=$logger->getLogs($this->getLevels(),$this->getCategories());
- if(!empty($logs))
- $this->processLogs($logs);
- }
-
- /**
- * Processes log messages and sends them to specific destination.
- * Derived child classes must implement this method.
- * @param array list of messages. Each array elements represents one message
- * with the following structure:
- * array(
- * [0] => message
- * [1] => level
- * [2] => category
- * [3] => timestamp);
- */
- abstract protected function processLogs($logs);
-}
-
-/**
- * TFileLogRoute class.
- *
- * TFileLogRoute records log messages in files.
- * The log files are stored under {@link setLogPath LogPath} and the file name
- * is specified by {@link setLogFile LogFile}. If the size of the log file is
- * greater than {@link setMaxFileSize MaxFileSize} (in kilo-bytes), a rotation
- * is performed, which renames the current log file by suffixing the file name
- * with '.1'. All existing log files are moved backwards one place, i.e., '.2'
- * to '.3', '.1' to '.2'. The property {@link setMaxLogFiles MaxLogFiles}
- * specifies how many files to be kept.
- *
- * @author Qiang Xue <qiang.xue@gmail.com>
- * @version $Id$
- * @package System.Util
- * @since 3.0
- */
-class TFileLogRoute extends TLogRoute
-{
- /**
- * @var integer maximum log file size
- */
- private $_maxFileSize=512; // in KB
- /**
- * @var integer number of log files used for rotation
- */
- private $_maxLogFiles=2;
- /**
- * @var string directory storing log files
- */
- private $_logPath=null;
- /**
- * @var string log file name
- */
- private $_logFile='prado.log';
-
- /**
- * @return string directory storing log files. Defaults to application runtime path.
- */
- public function getLogPath()
- {
- if($this->_logPath===null)
- $this->_logPath=$this->getApplication()->getRuntimePath();
- return $this->_logPath;
- }
-
- /**
- * @param string directory (in namespace format) storing log files.
- * @throws TConfigurationException if log path is invalid
- */
- public function setLogPath($value)
- {
- if(($this->_logPath=Prado::getPathOfNamespace($value))===null || !is_dir($this->_logPath) || !is_writable($this->_logPath))
- throw new TConfigurationException('filelogroute_logpath_invalid',$value);
- }
-
- /**
- * @return string log file name. Defaults to 'prado.log'.
- */
- public function getLogFile()
- {
- return $this->_logFile;
- }
-
- /**
- * @param string log file name
- */
- public function setLogFile($value)
- {
- $this->_logFile=$value;
- }
-
- /**
- * @return integer maximum log file size in kilo-bytes (KB). Defaults to 1024 (1MB).
- */
- public function getMaxFileSize()
- {
- return $this->_maxFileSize;
- }
-
- /**
- * @param integer maximum log file size in kilo-bytes (KB).
- * @throws TInvalidDataValueException if the value is smaller than 1.
- */
- public function setMaxFileSize($value)
- {
- $this->_maxFileSize=TPropertyValue::ensureInteger($value);
- if($this->_maxFileSize<=0)
- throw new TInvalidDataValueException('filelogroute_maxfilesize_invalid');
- }
-
- /**
- * @return integer number of files used for rotation. Defaults to 2.
- */
- public function getMaxLogFiles()
- {
- return $this->_maxLogFiles;
- }
-
- /**
- * @param integer number of files used for rotation.
- */
- public function setMaxLogFiles($value)
- {
- $this->_maxLogFiles=TPropertyValue::ensureInteger($value);
- if($this->_maxLogFiles<1)
- throw new TInvalidDataValueException('filelogroute_maxlogfiles_invalid');
- }
-
- /**
- * Saves log messages in files.
- * @param array list of log messages
- */
- protected function processLogs($logs)
- {
- $logFile=$this->getLogPath().DIRECTORY_SEPARATOR.$this->getLogFile();
- if(@filesize($logFile)>$this->_maxFileSize*1024)
- $this->rotateFiles();
- foreach($logs as $log)
- error_log($this->formatLogMessage($log[0],$log[1],$log[2],$log[3]),3,$logFile);
- }
-
- /**
- * Rotates log files.
- */
- protected function rotateFiles()
- {
- $file=$this->getLogPath().DIRECTORY_SEPARATOR.$this->getLogFile();
- for($i=$this->_maxLogFiles;$i>0;--$i)
- {
- $rotateFile=$file.'.'.$i;
- if(is_file($rotateFile))
- {
- if($i===$this->_maxLogFiles)
- unlink($rotateFile);
- else
- rename($rotateFile,$file.'.'.($i+1));
- }
- }
- if(is_file($file))
- rename($file,$file.'.1');
- }
-}
-
-/**
- * TEmailLogRoute class.
- *
- * TEmailLogRoute sends selected log messages to email addresses.
- * The target email addresses may be specified via {@link setEmails Emails} property.
- * Optionally, you may set the email {@link setSubject Subject} and the
- * {@link setSentFrom SentFrom} address.
- *
- * @author Qiang Xue <qiang.xue@gmail.com>
- * @version $Id$
- * @package System.Util
- * @since 3.0
- */
-class TEmailLogRoute extends TLogRoute
-{
- /**
- * Regex pattern for email address.
- */
- const EMAIL_PATTERN='/^([0-9a-zA-Z]+[-._+&])*[0-9a-zA-Z]+@([-0-9a-zA-Z]+[.])+[a-zA-Z]{2,6}$/';
- /**
- * Default email subject.
- */
- const DEFAULT_SUBJECT='Prado Application Log';
- /**
- * @var array list of destination email addresses.
- */
- private $_emails=array();
- /**
- * @var string email subject
- */
- private $_subject='';
- /**
- * @var string email sent from address
- */
- private $_from='';
-
- /**
- * Initializes the route.
- * @param TXmlElement configurations specified in {@link TLogRouter}.
- * @throws TConfigurationException if {@link getSentFrom SentFrom} is empty and
- * 'sendmail_from' in php.ini is also empty.
- */
- public function init($config)
- {
- if($this->_from==='')
- $this->_from=ini_get('sendmail_from');
- if($this->_from==='')
- throw new TConfigurationException('emaillogroute_sentfrom_required');
- }
-
- /**
- * Sends log messages to specified email addresses.
- * @param array list of log messages
- */
- protected function processLogs($logs)
- {
- $message='';
- foreach($logs as $log)
- $message.=$this->formatLogMessage($log[0],$log[1],$log[2],$log[3]);
- $message=wordwrap($message,70);
- $returnPath = ini_get('sendmail_path') ? "Return-Path:{$this->_from}\r\n" : '';
- foreach($this->_emails as $email)
- mail($email,$this->getSubject(),$message,"From:{$this->_from}\r\n{$returnPath}");
-
- }
-
- /**
- * @return array list of destination email addresses
- */
- public function getEmails()
- {
- return $this->_emails;
- }
-
- /**
- * @return array|string list of destination email addresses. If the value is
- * a string, it is assumed to be comma-separated email addresses.
- */
- public function setEmails($emails)
- {
- if(is_array($emails))
- $this->_emails=$emails;
- else
- {
- $this->_emails=array();
- foreach(explode(',',$emails) as $email)
- {
- $email=trim($email);
- if(preg_match(self::EMAIL_PATTERN,$email))
- $this->_emails[]=$email;
- }
- }
- }
-
- /**
- * @return string email subject. Defaults to TEmailLogRoute::DEFAULT_SUBJECT
- */
- public function getSubject()
- {
- if($this->_subject===null)
- $this->_subject=self::DEFAULT_SUBJECT;
- return $this->_subject;
- }
-
- /**
- * @param string email subject.
- */
- public function setSubject($value)
- {
- $this->_subject=$value;
- }
-
- /**
- * @return string send from address of the email
- */
- public function getSentFrom()
- {
- return $this->_from;
- }
-
- /**
- * @param string send from address of the email
- */
- public function setSentFrom($value)
- {
- $this->_from=$value;
- }
-}
-
-/**
- * TBrowserLogRoute class.
- *
- * TBrowserLogRoute prints selected log messages in the response.
- *
- * @author Xiang Wei Zhuo <weizhuo[at]gmail[dot]com>
- * @version $Id$
- * @package System.Util
- * @since 3.0
- */
-class TBrowserLogRoute extends TLogRoute
-{
- /**
- * @var string css class for indentifying the table structure in the dom tree
- */
- private $_cssClass=null;
-
- public function processLogs($logs)
- {
- if(empty($logs) || $this->getApplication()->getMode()==='Performance') return;
- $first = $logs[0][3];
- $even = true;
- $response = $this->getApplication()->getResponse();
- $response->write($this->renderHeader());
- for($i=0,$n=count($logs);$i<$n;++$i)
- {
- if ($i<$n-1)
- {
- $timing['delta'] = $logs[$i+1][3] - $logs[$i][3];
- $timing['total'] = $logs[$i+1][3] - $first;
- }
- else
- {
- $timing['delta'] = '?';
- $timing['total'] = $logs[$i][3] - $first;
- }
- $timing['even'] = !($even = !$even);
- $response->write($this->renderMessage($logs[$i],$timing));
- }
- $response->write($this->renderFooter());
- }
-
- /**
- * @param string the css class of the control
- */
- public function setCssClass($value)
- {
- $this->_cssClass = TPropertyValue::ensureString($value);
- }
-
- /**
- * @return string the css class of the control
- */
- public function getCssClass()
- {
- return TPropertyValue::ensureString($this->_cssClass);
- }
-
- protected function renderHeader()
- {
- $string = '';
- if($className=$this->getCssClass())
- {
- $string = <<<EOD
-<table class="$className">
- <tr class="header">
- <th colspan="5">
- Application Log
- </th>
- </tr><tr class="description">
- <th>&nbsp;</th>
- <th>Category</th><th>Message</th><th>Time Spent (s)</th><th>Cumulated Time Spent (s)</th>
- </tr>
-EOD;
- }
- else
- {
- $string = <<<EOD
-<table cellspacing="0" cellpadding="2" border="0" width="100%" style="table-layout:auto">
- <tr>
- <th style="background-color: black; color:white;" colspan="5">
- Application Log
- </th>
- </tr><tr style="background-color: #ccc; color:black">
- <th style="width: 15px">&nbsp;</th>
- <th style="width: auto">Category</th><th style="width: auto">Message</th><th style="width: 120px">Time Spent (s)</th><th style="width: 150px">Cumulated Time Spent (s)</th>
- </tr>
-EOD;
- }
- return $string;
- }
-
- protected function renderMessage($log, $info)
- {
- $string = '';
- $total = sprintf('%0.6f', $info['total']);
- $delta = sprintf('%0.6f', $info['delta']);
- $msg = preg_replace('/\(line[^\)]+\)$/','',$log[0]); //remove line number info
- $msg = THttpUtility::htmlEncode($msg);
- if($this->getCssClass())
- {
- $colorCssClass = $log[1];
- $messageCssClass = $info['even'] ? 'even' : 'odd';
- $string = <<<EOD
- <tr class="message level$colorCssClass $messageCssClass">
- <td class="code">&nbsp;</td>
- <td class="category">{$log[2]}</td>
- <td class="message">{$msg}</td>
- <td class="time">{$delta}</td>
- <td class="cumulatedtime">{$total}</td>
- </tr>
-EOD;
- }
- else
- {
- $bgcolor = $info['even'] ? "#fff" : "#eee";
- $color = $this->getColorLevel($log[1]);
- $string = <<<EOD
- <tr style="background-color: {$bgcolor}; color:#000">
- <td style="border:1px solid silver;background-color: $color;">&nbsp;</td>
- <td>{$log[2]}</td>
- <td>{$msg}</td>
- <td style="text-align:center">{$delta}</td>
- <td style="text-align:center">{$total}</td>
- </tr>
-EOD;
- }
- return $string;
- }
-
- protected function getColorLevel($level)
- {
- switch($level)
- {
- case TLogger::DEBUG: return 'green';
- case TLogger::INFO: return 'black';
- case TLogger::NOTICE: return '#3333FF';
- case TLogger::WARNING: return '#33FFFF';
- case TLogger::ERROR: return '#ff9933';
- case TLogger::ALERT: return '#ff00ff';
- case TLogger::FATAL: return 'red';
- }
- return '';
- }
-
- protected function renderFooter()
- {
- $string = '';
- if($this->getCssClass())
- {
- $string .= '<tr class="footer"><td colspan="5">';
- foreach(self::$_levelValues as $name => $level)
- {
- $string .= '<span class="level'.$level.'">'.strtoupper($name)."</span>";
- }
- }
- else
- {
- $string .= "<tr><td colspan=\"5\" style=\"text-align:center; background-color:black; border-top: 1px solid #ccc; padding:0.2em;\">";
- foreach(self::$_levelValues as $name => $level)
- {
- $string .= "<span style=\"color:white; border:1px solid white; background-color:".$this->getColorLevel($level);
- $string .= ";margin: 0.5em; padding:0.01em;\">".strtoupper($name)."</span>";
- }
- }
- $string .= '</td></tr></table>';
- return $string;
- }
-}
-
-
-/**
- * TDbLogRoute class
- *
- * TDbLogRoute stores log messages in a database table.
- * To specify the database table, set {@link setConnectionID ConnectionID} to be
- * the ID of a {@link TDataSourceConfig} module and {@link setLogTableName LogTableName}.
- * If they are not setting, an SQLite3 database named 'sqlite3.log' will be created and used
- * under the runtime directory.
- *
- * By default, the database table name is 'pradolog'. It has the following structure:
- * <code>
- * CREATE TABLE pradolog
- * (
- * log_id INTEGER NOT NULL PRIMARY KEY,
- * level INTEGER,
- * category VARCHAR(128),
- * logtime VARCHAR(20),
- * message VARCHAR(255)
- * );
- * </code>
- *
- * @author Qiang Xue <qiang.xue@gmail.com>
- * @version $Id$
- * @package System.Util
- * @since 3.1.2
- */
-class TDbLogRoute extends TLogRoute
-{
- /**
- * @var string the ID of TDataSourceConfig module
- */
- private $_connID='';
- /**
- * @var TDbConnection the DB connection instance
- */
- private $_db;
- /**
- * @var string name of the DB log table
- */
- private $_logTable='pradolog';
- /**
- * @var boolean whether the log DB table should be created automatically
- */
- private $_autoCreate=true;
-
- /**
- * Destructor.
- * Disconnect the db connection.
- */
- public function __destruct()
- {
- if($this->_db!==null)
- $this->_db->setActive(false);
- }
-
- /**
- * Initializes this module.
- * This method is required by the IModule interface.
- * It initializes the database for logging purpose.
- * @param TXmlElement configuration for this module, can be null
- * @throws TConfigurationException if the DB table does not exist.
- */
- public function init($config)
- {
- $db=$this->getDbConnection();
- $db->setActive(true);
-
- $sql='SELECT * FROM '.$this->_logTable.' WHERE 0=1';
- try
- {
- $db->createCommand($sql)->query()->close();
- }
- catch(Exception $e)
- {
- // DB table not exists
- if($this->_autoCreate)
- $this->createDbTable();
- else
- throw new TConfigurationException('db_logtable_inexistent',$this->_logTable);
- }
-
- parent::init($config);
- }
-
- /**
- * Stores log messages into database.
- * @param array list of log messages
- */
- protected function processLogs($logs)
- {
- $sql='INSERT INTO '.$this->_logTable.'(level, category, logtime, message) VALUES (:level, :category, :logtime, :message)';
- $command=$this->getDbConnection()->createCommand($sql);
- foreach($logs as $log)
- {
- $command->bindValue(':message',$log[0]);
- $command->bindValue(':level',$log[1]);
- $command->bindValue(':category',$log[2]);
- $command->bindValue(':logtime',$log[3]);
- $command->execute();
- }
- }
-
- /**
- * Creates the DB table for storing log messages.
- * @todo create sequence for PostgreSQL
- */
- protected function createDbTable()
- {
- $db = $this->getDbConnection();
- $driver=$db->getDriverName();
- $autoidAttributes = '';
- if($driver==='mysql')
- $autoidAttributes = 'AUTO_INCREMENT';
-
- $sql='CREATE TABLE '.$this->_logTable.' (
- log_id INTEGER NOT NULL PRIMARY KEY ' . $autoidAttributes . ',
- level INTEGER,
- category VARCHAR(128),
- logtime VARCHAR(20),
- message VARCHAR(255))';
- $db->createCommand($sql)->execute();
- }
-
- /**
- * Creates the DB connection.
- * @param string the module ID for TDataSourceConfig
- * @return TDbConnection the created DB connection
- * @throws TConfigurationException if module ID is invalid or empty
- */
- protected function createDbConnection()
- {
- if($this->_connID!=='')
- {
- $config=$this->getApplication()->getModule($this->_connID);
- if($config instanceof TDataSourceConfig)
- return $config->getDbConnection();
- else
- throw new TConfigurationException('dblogroute_connectionid_invalid',$this->_connID);
- }
- else
- {
- $db=new TDbConnection;
- // default to SQLite3 database
- $dbFile=$this->getApplication()->getRuntimePath().'/sqlite3.log';
- $db->setConnectionString('sqlite:'.$dbFile);
- return $db;
- }
- }
-
- /**
- * @return TDbConnection the DB connection instance
- */
- public function getDbConnection()
- {
- if($this->_db===null)
- $this->_db=$this->createDbConnection();
- return $this->_db;
- }
-
- /**
- * @return string the ID of a {@link TDataSourceConfig} module. Defaults to empty string, meaning not set.
- */
- public function getConnectionID()
- {
- return $this->_connID;
- }
-
- /**
- * Sets the ID of a TDataSourceConfig module.
- * The datasource module will be used to establish the DB connection for this log route.
- * @param string ID of the {@link TDataSourceConfig} module
- */
- public function setConnectionID($value)
- {
- $this->_connID=$value;
- }
-
- /**
- * @return string the name of the DB table to store log content. Defaults to 'pradolog'.
- * @see setAutoCreateLogTable
- */
- public function getLogTableName()
- {
- return $this->_logTable;
- }
-
- /**
- * Sets the name of the DB table to store log content.
- * Note, if {@link setAutoCreateLogTable AutoCreateLogTable} is false
- * and you want to create the DB table manually by yourself,
- * you need to make sure the DB table is of the following structure:
- * (key CHAR(128) PRIMARY KEY, value BLOB, expire INT)
- * @param string the name of the DB table to store log content
- * @see setAutoCreateLogTable
- */
- public function setLogTableName($value)
- {
- $this->_logTable=$value;
- }
-
- /**
- * @return boolean whether the log DB table should be automatically created if not exists. Defaults to true.
- * @see setAutoCreateLogTable
- */
- public function getAutoCreateLogTable()
- {
- return $this->_autoCreate;
- }
-
- /**
- * @param boolean whether the log DB table should be automatically created if not exists.
- * @see setLogTableName
- */
- public function setAutoCreateLogTable($value)
- {
- $this->_autoCreate=TPropertyValue::ensureBoolean($value);
- }
-
-}
-
-/**
- * TFirebugLogRoute class.
- *
- * TFirebugLogRoute prints selected log messages in the firebug log console.
- *
- * {@link http://www.getfirebug.com/ FireBug Website}
- *
- * @author Enrico Stahn <mail@enricostahn.com>, Christophe Boulain <Christophe.Boulain@gmail.com>
- * @version $Id$
- * @package System.Util
- * @since 3.1.2
- */
-class TFirebugLogRoute extends TBrowserLogRoute
-{
- protected function renderHeader ()
- {
- $string = <<<EOD
-
-<script type="text/javascript">
-/*<![CDATA[*/
-if (typeof(console) == 'object')
-{
- console.log ("[Cumulated Time] [Time] [Level] [Category] [Message]");
-
-EOD;
-
- return $string;
- }
-
- protected function renderMessage ($log, $info)
- {
- $logfunc = $this->getFirebugLoggingFunction($log[1]);
- $total = sprintf('%0.6f', $info['total']);
- $delta = sprintf('%0.6f', $info['delta']);
- $msg = trim($this->formatLogMessage($log[0], $log[1], $log[2], ''));
- $msg = preg_replace('/\(line[^\)]+\)$/', '', $msg); //remove line number info
- $msg = "[{$total}] [{$delta}] ".$msg; // Add time spent and cumulated time spent
- $string = $logfunc . '(\'' . addslashes($msg) . '\');' . "\n";
-
- return $string;
- }
-
-
- protected function renderFooter ()
- {
- $string = <<<EOD
-
-}
-</script>
-
-EOD;
-
- return $string;
- }
-
- protected function getFirebugLoggingFunction($level)
- {
- switch ($level)
- {
- case TLogger::DEBUG:
- case TLogger::INFO:
- case TLogger::NOTICE:
- return 'console.log';
- case TLogger::WARNING:
- return 'console.warn';
- case TLogger::ERROR:
- case TLogger::ALERT:
- case TLogger::FATAL:
- return 'console.error';
- default:
- return 'console.log';
- }
- }
-
-}
-
-/**
- * TFirePhpLogRoute class.
- *
- * TFirePhpLogRoute prints log messages in the firebug log console via firephp.
- *
- * {@link http://www.getfirebug.com/ FireBug Website}
- * {@link http://www.firephp.org/ FirePHP Website}
- *
- * @author Yves Berkholz <godzilla80[at]gmx[dot]net>
- * @version $Id$
- * @package System.Util
- * @since 3.1.5
- */
-class TFirePhpLogRoute extends TLogRoute
-{
- /**
- * Default group label
- */
- const DEFAULT_LABEL = 'System.Util.TLogRouter(TFirePhpLogRoute)';
-
- private $_groupLabel = null;
-
- public function processLogs($logs)
- {
- if(empty($logs) || $this->getApplication()->getMode()==='Performance')
- return;
-
- if(headers_sent()) {
- echo '
- <div style="width:100%; background-color:darkred; color:#FFF; padding:2px">
- TFirePhpLogRoute.GroupLabel "<i>' . $this -> getGroupLabel() . '</i>" -
- Routing to FirePHP impossible, because headers already sent!
- </div>
- ';
- $fallback = new TBrowserLogRoute();
- $fallback->processLogs($logs);
- return;
- }
-
- require_once Prado::getPathOfNamespace('System.3rdParty.FirePHPCore') . '/FirePHP.class.php';
- $firephp = FirePHP::getInstance(true);
- $firephp->setOptions(array('useNativeJsonEncode' => false));
- $firephp->group($this->getGroupLabel(), array('Collapsed' => true));
- $firephp->log('Time, Message');
-
- $first = $logs[0][3];
- $c = count($logs);
- for($i=0,$n=$c;$i<$n;++$i)
- {
- $message = $logs[$i][0];
- $level = $logs[$i][1];
- $category = $logs[$i][2];
-
- if ($i<$n-1)
- {
- $delta = $logs[$i+1][3] - $logs[$i][3];
- $total = $logs[$i+1][3] - $first;
- }
- else
- {
- $delta = '?';
- $total = $logs[$i][3] - $first;
- }
-
- $message = sPrintF('+%0.6f: %s', $delta, preg_replace('/\(line[^\)]+\)$/', '', $message));
- $firephp->fb($message, $category, self::translateLogLevel($level));
- }
- $firephp->log(sPrintF('%0.6f', $total), 'Cumulated Time');
- $firephp->groupEnd();
- }
-
- /**
- * Translates a PRADO log level attribute into one understood by FirePHP for correct visualization
- * @param string prado log level
- * @return string FirePHP log level
- */
- protected static function translateLogLevel($level)
- {
- switch($level)
- {
- case TLogger::INFO:
- return FirePHP::INFO;
- case TLogger::DEBUG:
- case TLogger::NOTICE:
- return FirePHP::LOG;
- case TLogger::WARNING:
- return FirePHP::WARN;
- case TLogger::ERROR:
- case TLogger::ALERT:
- case TLogger::FATAL:
- return FirePHP::ERROR;
- default:
- return FirePHP::LOG;
- }
- }
-
- /**
- * @return string group label. Defaults to TFirePhpLogRoute::DEFAULT_LABEL
- */
- public function getGroupLabel()
- {
- if($this->_groupLabel===null)
- $this->_groupLabel=self::DEFAULT_LABEL;
-
- return $this->_groupLabel;
- }
-
- /**
- * @param string group label.
- */
- public function setGroupLabel($value)
- {
- $this->_groupLabel=$value;
- }
-}
+<?php
+/**
+ * TLogRouter, TLogRoute, TFileLogRoute, TEmailLogRoute class file
+ *
+ * @author Qiang Xue <qiang.xue@gmail.com>
+ * @link http://www.pradosoft.com/
+ * @copyright Copyright &copy; 2005-2012 PradoSoft
+ * @license http://www.pradosoft.com/license/
+ * @version $Id$
+ * @package System.Util
+ */
+
+Prado::using('System.Data.TDbConnection');
+
+/**
+ * TLogRouter class.
+ *
+ * TLogRouter manages routes that record log messages in different media different ways.
+ * For example, a file log route {@link TFileLogRoute} records log messages
+ * in log files. An email log route {@link TEmailLogRoute} sends log messages
+ * to email addresses.
+ *
+ * Log routes may be configured in application or page folder configuration files
+ * or an external configuration file specified by {@link setConfigFile ConfigFile}.
+ * The format is as follows,
+ * <code>
+ * <route class="TFileLogRoute" Categories="System.Web.UI" Levels="Warning" />
+ * <route class="TEmailLogRoute" Categories="Application" Levels="Fatal" Emails="admin@pradosoft.com" />
+ * </code>
+ * PHP configuration style:
+ * <code>
+ *
+ * </code>
+ * You can specify multiple routes with different filtering conditions and different
+ * targets, even if the routes are of the same type.
+ *
+ * @author Qiang Xue <qiang.xue@gmail.com>
+ * @author Carl G. Mathisen <carlgmathisen@gmail.com>
+ * @version $Id$
+ * @package System.Util
+ * @since 3.0
+ */
+class TLogRouter extends TModule
+{
+ /**
+ * @var array list of routes available
+ */
+ private $_routes=array();
+ /**
+ * @var string external configuration file
+ */
+ private $_configFile=null;
+
+ /**
+ * Initializes this module.
+ * This method is required by the IModule interface.
+ * @param mixed configuration for this module, can be null
+ * @throws TConfigurationException if {@link getConfigFile ConfigFile} is invalid.
+ */
+ public function init($config)
+ {
+ if($this->_configFile!==null)
+ {
+ if(is_file($this->_configFile))
+ {
+ if($this->getApplication()->getConfigurationType()==TApplication::CONFIG_TYPE_PHP)
+ {
+ $phpConfig = include $this->_configFile;
+ $this->loadConfig($phpConfig);
+ }
+ else
+ {
+ $dom=new TXmlDocument;
+ $dom->loadFromFile($this->_configFile);
+ $this->loadConfig($dom);
+ }
+ }
+ else
+ throw new TConfigurationException('logrouter_configfile_invalid',$this->_configFile);
+ }
+ $this->loadConfig($config);
+ $this->getApplication()->attachEventHandler('OnEndRequest',array($this,'collectLogs'));
+ }
+
+ /**
+ * Loads configuration from an XML element or PHP array
+ * @param mixed configuration node
+ * @throws TConfigurationException if log route class or type is not specified
+ */
+ private function loadConfig($config)
+ {
+ if(is_array($config))
+ {
+ if(isset($config['routes']) && is_array($config['routes']))
+ {
+ foreach($config['routes'] as $route)
+ {
+ $properties = isset($route['properties'])?$route['properties']:array();
+ if(!isset($route['class']))
+ throw new TConfigurationException('logrouter_routeclass_required');
+ $route=Prado::createComponent($route['class']);
+ if(!($route instanceof TLogRoute))
+ throw new TConfigurationException('logrouter_routetype_invalid');
+ foreach($properties as $name=>$value)
+ $route->setSubproperty($name,$value);
+ $this->_routes[]=$route;
+ $route->init($route);
+ }
+ }
+ }
+ else
+ {
+ foreach($config->getElementsByTagName('route') as $routeConfig)
+ {
+ $properties=$routeConfig->getAttributes();
+ if(($class=$properties->remove('class'))===null)
+ throw new TConfigurationException('logrouter_routeclass_required');
+ $route=Prado::createComponent($class);
+ if(!($route instanceof TLogRoute))
+ throw new TConfigurationException('logrouter_routetype_invalid');
+ foreach($properties as $name=>$value)
+ $route->setSubproperty($name,$value);
+ $this->_routes[]=$route;
+ $route->init($routeConfig);
+ }
+ }
+ }
+
+ /**
+ * Adds a TLogRoute instance to the log router.
+ *
+ * @param TLogRoute $route
+ * @throws TInvalidDataTypeException if the route object is invalid
+ */
+ public function addRoute($route)
+ {
+ if(!($route instanceof TLogRoute))
+ throw new TInvalidDataTypeException('logrouter_routetype_invalid');
+ $this->_routes[]=$route;
+ $route->init(null);
+ }
+
+ /**
+ * @return string external configuration file. Defaults to null.
+ */
+ public function getConfigFile()
+ {
+ return $this->_configFile;
+ }
+
+ /**
+ * @param string external configuration file in namespace format. The file
+ * must be suffixed with '.xml'.
+ * @throws TConfigurationException if the file is invalid.
+ */
+ public function setConfigFile($value)
+ {
+ if(($this->_configFile=Prado::getPathOfNamespace($value,$this->getApplication()->getConfigurationFileExt()))===null)
+ throw new TConfigurationException('logrouter_configfile_invalid',$value);
+ }
+
+ /**
+ * Collects log messages from a logger.
+ * This method is an event handler to application's EndRequest event.
+ * @param mixed event parameter
+ */
+ public function collectLogs($param)
+ {
+ $logger=Prado::getLogger();
+ foreach($this->_routes as $route)
+ $route->collectLogs($logger);
+ }
+}
+
+/**
+ * TLogRoute class.
+ *
+ * TLogRoute is the base class for all log route classes.
+ * A log route object retrieves log messages from a logger and sends it
+ * somewhere, such as files, emails.
+ * The messages being retrieved may be filtered first before being sent
+ * to the destination. The filters include log level filter and log category filter.
+ *
+ * To specify level filter, set {@link setLevels Levels} property,
+ * which takes a string of comma-separated desired level names (e.g. 'Error, Debug').
+ * To specify category filter, set {@link setCategories Categories} property,
+ * which takes a string of comma-separated desired category names (e.g. 'System.Web, System.IO').
+ *
+ * Level filter and category filter are combinational, i.e., only messages
+ * satisfying both filter conditions will they be returned.
+ *
+ * @author Qiang Xue <qiang.xue@gmail.com>
+ * @version $Id$
+ * @package System.Util
+ * @since 3.0
+ */
+abstract class TLogRoute extends TApplicationComponent
+{
+ /**
+ * @var array lookup table for level names
+ */
+ protected static $_levelNames=array(
+ TLogger::DEBUG=>'Debug',
+ TLogger::INFO=>'Info',
+ TLogger::NOTICE=>'Notice',
+ TLogger::WARNING=>'Warning',
+ TLogger::ERROR=>'Error',
+ TLogger::ALERT=>'Alert',
+ TLogger::FATAL=>'Fatal'
+ );
+ /**
+ * @var array lookup table for level values
+ */
+ protected static $_levelValues=array(
+ 'debug'=>TLogger::DEBUG,
+ 'info'=>TLogger::INFO,
+ 'notice'=>TLogger::NOTICE,
+ 'warning'=>TLogger::WARNING,
+ 'error'=>TLogger::ERROR,
+ 'alert'=>TLogger::ALERT,
+ 'fatal'=>TLogger::FATAL
+ );
+ /**
+ * @var integer log level filter (bits)
+ */
+ private $_levels=null;
+ /**
+ * @var array log category filter
+ */
+ private $_categories=null;
+
+ /**
+ * Initializes the route.
+ * @param TXmlElement configurations specified in {@link TLogRouter}.
+ */
+ public function init($config)
+ {
+ }
+
+ /**
+ * @return integer log level filter
+ */
+ public function getLevels()
+ {
+ return $this->_levels;
+ }
+
+ /**
+ * @param integer|string integer log level filter (in bits). If the value is
+ * a string, it is assumed to be comma-separated level names. Valid level names
+ * include 'Debug', 'Info', 'Notice', 'Warning', 'Error', 'Alert' and 'Fatal'.
+ */
+ public function setLevels($levels)
+ {
+ if(is_integer($levels))
+ $this->_levels=$levels;
+ else
+ {
+ $this->_levels=null;
+ $levels=strtolower($levels);
+ foreach(explode(',',$levels) as $level)
+ {
+ $level=trim($level);
+ if(isset(self::$_levelValues[$level]))
+ $this->_levels|=self::$_levelValues[$level];
+ }
+ }
+ }
+
+ /**
+ * @return array list of categories to be looked for
+ */
+ public function getCategories()
+ {
+ return $this->_categories;
+ }
+
+ /**
+ * @param array|string list of categories to be looked for. If the value is a string,
+ * it is assumed to be comma-separated category names.
+ */
+ public function setCategories($categories)
+ {
+ if(is_array($categories))
+ $this->_categories=$categories;
+ else
+ {
+ $this->_categories=null;
+ foreach(explode(',',$categories) as $category)
+ {
+ if(($category=trim($category))!=='')
+ $this->_categories[]=$category;
+ }
+ }
+ }
+
+ /**
+ * @param integer level value
+ * @return string level name
+ */
+ protected function getLevelName($level)
+ {
+ return isset(self::$_levelNames[$level])?self::$_levelNames[$level]:'Unknown';
+ }
+
+ /**
+ * @param string level name
+ * @return integer level value
+ */
+ protected function getLevelValue($level)
+ {
+ return isset(self::$_levelValues[$level])?self::$_levelValues[$level]:0;
+ }
+
+ /**
+ * Formats a log message given different fields.
+ * @param string message content
+ * @param integer message level
+ * @param string message category
+ * @param integer timestamp
+ * @return string formatted message
+ */
+ protected function formatLogMessage($message,$level,$category,$time)
+ {
+ return @gmdate('M d H:i:s',$time).' ['.$this->getLevelName($level).'] ['.$category.'] '.$message."\n";
+ }
+
+ /**
+ * Retrieves log messages from logger to log route specific destination.
+ * @param TLogger logger instance
+ */
+ public function collectLogs(TLogger $logger)
+ {
+ $logs=$logger->getLogs($this->getLevels(),$this->getCategories());
+ if(!empty($logs))
+ $this->processLogs($logs);
+ }
+
+ /**
+ * Processes log messages and sends them to specific destination.
+ * Derived child classes must implement this method.
+ * @param array list of messages. Each array elements represents one message
+ * with the following structure:
+ * array(
+ * [0] => message
+ * [1] => level
+ * [2] => category
+ * [3] => timestamp);
+ */
+ abstract protected function processLogs($logs);
+}
+
+/**
+ * TFileLogRoute class.
+ *
+ * TFileLogRoute records log messages in files.
+ * The log files are stored under {@link setLogPath LogPath} and the file name
+ * is specified by {@link setLogFile LogFile}. If the size of the log file is
+ * greater than {@link setMaxFileSize MaxFileSize} (in kilo-bytes), a rotation
+ * is performed, which renames the current log file by suffixing the file name
+ * with '.1'. All existing log files are moved backwards one place, i.e., '.2'
+ * to '.3', '.1' to '.2'. The property {@link setMaxLogFiles MaxLogFiles}
+ * specifies how many files to be kept.
+ *
+ * @author Qiang Xue <qiang.xue@gmail.com>
+ * @version $Id$
+ * @package System.Util
+ * @since 3.0
+ */
+class TFileLogRoute extends TLogRoute
+{
+ /**
+ * @var integer maximum log file size
+ */
+ private $_maxFileSize=512; // in KB
+ /**
+ * @var integer number of log files used for rotation
+ */
+ private $_maxLogFiles=2;
+ /**
+ * @var string directory storing log files
+ */
+ private $_logPath=null;
+ /**
+ * @var string log file name
+ */
+ private $_logFile='prado.log';
+
+ /**
+ * @return string directory storing log files. Defaults to application runtime path.
+ */
+ public function getLogPath()
+ {
+ if($this->_logPath===null)
+ $this->_logPath=$this->getApplication()->getRuntimePath();
+ return $this->_logPath;
+ }
+
+ /**
+ * @param string directory (in namespace format) storing log files.
+ * @throws TConfigurationException if log path is invalid
+ */
+ public function setLogPath($value)
+ {
+ if(($this->_logPath=Prado::getPathOfNamespace($value))===null || !is_dir($this->_logPath) || !is_writable($this->_logPath))
+ throw new TConfigurationException('filelogroute_logpath_invalid',$value);
+ }
+
+ /**
+ * @return string log file name. Defaults to 'prado.log'.
+ */
+ public function getLogFile()
+ {
+ return $this->_logFile;
+ }
+
+ /**
+ * @param string log file name
+ */
+ public function setLogFile($value)
+ {
+ $this->_logFile=$value;
+ }
+
+ /**
+ * @return integer maximum log file size in kilo-bytes (KB). Defaults to 1024 (1MB).
+ */
+ public function getMaxFileSize()
+ {
+ return $this->_maxFileSize;
+ }
+
+ /**
+ * @param integer maximum log file size in kilo-bytes (KB).
+ * @throws TInvalidDataValueException if the value is smaller than 1.
+ */
+ public function setMaxFileSize($value)
+ {
+ $this->_maxFileSize=TPropertyValue::ensureInteger($value);
+ if($this->_maxFileSize<=0)
+ throw new TInvalidDataValueException('filelogroute_maxfilesize_invalid');
+ }
+
+ /**
+ * @return integer number of files used for rotation. Defaults to 2.
+ */
+ public function getMaxLogFiles()
+ {
+ return $this->_maxLogFiles;
+ }
+
+ /**
+ * @param integer number of files used for rotation.
+ */
+ public function setMaxLogFiles($value)
+ {
+ $this->_maxLogFiles=TPropertyValue::ensureInteger($value);
+ if($this->_maxLogFiles<1)
+ throw new TInvalidDataValueException('filelogroute_maxlogfiles_invalid');
+ }
+
+ /**
+ * Saves log messages in files.
+ * @param array list of log messages
+ */
+ protected function processLogs($logs)
+ {
+ $logFile=$this->getLogPath().DIRECTORY_SEPARATOR.$this->getLogFile();
+ if(@filesize($logFile)>$this->_maxFileSize*1024)
+ $this->rotateFiles();
+ foreach($logs as $log)
+ error_log($this->formatLogMessage($log[0],$log[1],$log[2],$log[3]),3,$logFile);
+ }
+
+ /**
+ * Rotates log files.
+ */
+ protected function rotateFiles()
+ {
+ $file=$this->getLogPath().DIRECTORY_SEPARATOR.$this->getLogFile();
+ for($i=$this->_maxLogFiles;$i>0;--$i)
+ {
+ $rotateFile=$file.'.'.$i;
+ if(is_file($rotateFile))
+ {
+ if($i===$this->_maxLogFiles)
+ unlink($rotateFile);
+ else
+ rename($rotateFile,$file.'.'.($i+1));
+ }
+ }
+ if(is_file($file))
+ rename($file,$file.'.1');
+ }
+}
+
+/**
+ * TEmailLogRoute class.
+ *
+ * TEmailLogRoute sends selected log messages to email addresses.
+ * The target email addresses may be specified via {@link setEmails Emails} property.
+ * Optionally, you may set the email {@link setSubject Subject} and the
+ * {@link setSentFrom SentFrom} address.
+ *
+ * @author Qiang Xue <qiang.xue@gmail.com>
+ * @version $Id$
+ * @package System.Util
+ * @since 3.0
+ */
+class TEmailLogRoute extends TLogRoute
+{
+ /**
+ * Regex pattern for email address.
+ */
+ const EMAIL_PATTERN='/^([0-9a-zA-Z]+[-._+&])*[0-9a-zA-Z]+@([-0-9a-zA-Z]+[.])+[a-zA-Z]{2,6}$/';
+ /**
+ * Default email subject.
+ */
+ const DEFAULT_SUBJECT='Prado Application Log';
+ /**
+ * @var array list of destination email addresses.
+ */
+ private $_emails=array();
+ /**
+ * @var string email subject
+ */
+ private $_subject='';
+ /**
+ * @var string email sent from address
+ */
+ private $_from='';
+
+ /**
+ * Initializes the route.
+ * @param TXmlElement configurations specified in {@link TLogRouter}.
+ * @throws TConfigurationException if {@link getSentFrom SentFrom} is empty and
+ * 'sendmail_from' in php.ini is also empty.
+ */
+ public function init($config)
+ {
+ if($this->_from==='')
+ $this->_from=ini_get('sendmail_from');
+ if($this->_from==='')
+ throw new TConfigurationException('emaillogroute_sentfrom_required');
+ }
+
+ /**
+ * Sends log messages to specified email addresses.
+ * @param array list of log messages
+ */
+ protected function processLogs($logs)
+ {
+ $message='';
+ foreach($logs as $log)
+ $message.=$this->formatLogMessage($log[0],$log[1],$log[2],$log[3]);
+ $message=wordwrap($message,70);
+ $returnPath = ini_get('sendmail_path') ? "Return-Path:{$this->_from}\r\n" : '';
+ foreach($this->_emails as $email)
+ mail($email,$this->getSubject(),$message,"From:{$this->_from}\r\n{$returnPath}");
+
+ }
+
+ /**
+ * @return array list of destination email addresses
+ */
+ public function getEmails()
+ {
+ return $this->_emails;
+ }
+
+ /**
+ * @return array|string list of destination email addresses. If the value is
+ * a string, it is assumed to be comma-separated email addresses.
+ */
+ public function setEmails($emails)
+ {
+ if(is_array($emails))
+ $this->_emails=$emails;
+ else
+ {
+ $this->_emails=array();
+ foreach(explode(',',$emails) as $email)
+ {
+ $email=trim($email);
+ if(preg_match(self::EMAIL_PATTERN,$email))
+ $this->_emails[]=$email;
+ }
+ }
+ }
+
+ /**
+ * @return string email subject. Defaults to TEmailLogRoute::DEFAULT_SUBJECT
+ */
+ public function getSubject()
+ {
+ if($this->_subject===null)
+ $this->_subject=self::DEFAULT_SUBJECT;
+ return $this->_subject;
+ }
+
+ /**
+ * @param string email subject.
+ */
+ public function setSubject($value)
+ {
+ $this->_subject=$value;
+ }
+
+ /**
+ * @return string send from address of the email
+ */
+ public function getSentFrom()
+ {
+ return $this->_from;
+ }
+
+ /**
+ * @param string send from address of the email
+ */
+ public function setSentFrom($value)
+ {
+ $this->_from=$value;
+ }
+}
+
+/**
+ * TBrowserLogRoute class.
+ *
+ * TBrowserLogRoute prints selected log messages in the response.
+ *
+ * @author Xiang Wei Zhuo <weizhuo[at]gmail[dot]com>
+ * @version $Id$
+ * @package System.Util
+ * @since 3.0
+ */
+class TBrowserLogRoute extends TLogRoute
+{
+ /**
+ * @var string css class for indentifying the table structure in the dom tree
+ */
+ private $_cssClass=null;
+
+ public function processLogs($logs)
+ {
+ if(empty($logs) || $this->getApplication()->getMode()==='Performance') return;
+ $first = $logs[0][3];
+ $even = true;
+ $response = $this->getApplication()->getResponse();
+ $response->write($this->renderHeader());
+ for($i=0,$n=count($logs);$i<$n;++$i)
+ {
+ if ($i<$n-1)
+ {
+ $timing['delta'] = $logs[$i+1][3] - $logs[$i][3];
+ $timing['total'] = $logs[$i+1][3] - $first;
+ }
+ else
+ {
+ $timing['delta'] = '?';
+ $timing['total'] = $logs[$i][3] - $first;
+ }
+ $timing['even'] = !($even = !$even);
+ $response->write($this->renderMessage($logs[$i],$timing));
+ }
+ $response->write($this->renderFooter());
+ }
+
+ /**
+ * @param string the css class of the control
+ */
+ public function setCssClass($value)
+ {
+ $this->_cssClass = TPropertyValue::ensureString($value);
+ }
+
+ /**
+ * @return string the css class of the control
+ */
+ public function getCssClass()
+ {
+ return TPropertyValue::ensureString($this->_cssClass);
+ }
+
+ protected function renderHeader()
+ {
+ $string = '';
+ if($className=$this->getCssClass())
+ {
+ $string = <<<EOD
+<table class="$className">
+ <tr class="header">
+ <th colspan="5">
+ Application Log
+ </th>
+ </tr><tr class="description">
+ <th>&nbsp;</th>
+ <th>Category</th><th>Message</th><th>Time Spent (s)</th><th>Cumulated Time Spent (s)</th>
+ </tr>
+EOD;
+ }
+ else
+ {
+ $string = <<<EOD
+<table cellspacing="0" cellpadding="2" border="0" width="100%" style="table-layout:auto">
+ <tr>
+ <th style="background-color: black; color:white;" colspan="5">
+ Application Log
+ </th>
+ </tr><tr style="background-color: #ccc; color:black">
+ <th style="width: 15px">&nbsp;</th>
+ <th style="width: auto">Category</th><th style="width: auto">Message</th><th style="width: 120px">Time Spent (s)</th><th style="width: 150px">Cumulated Time Spent (s)</th>
+ </tr>
+EOD;
+ }
+ return $string;
+ }
+
+ protected function renderMessage($log, $info)
+ {
+ $string = '';
+ $total = sprintf('%0.6f', $info['total']);
+ $delta = sprintf('%0.6f', $info['delta']);
+ $msg = preg_replace('/\(line[^\)]+\)$/','',$log[0]); //remove line number info
+ $msg = THttpUtility::htmlEncode($msg);
+ if($this->getCssClass())
+ {
+ $colorCssClass = $log[1];
+ $messageCssClass = $info['even'] ? 'even' : 'odd';
+ $string = <<<EOD
+ <tr class="message level$colorCssClass $messageCssClass">
+ <td class="code">&nbsp;</td>
+ <td class="category">{$log[2]}</td>
+ <td class="message">{$msg}</td>
+ <td class="time">{$delta}</td>
+ <td class="cumulatedtime">{$total}</td>
+ </tr>
+EOD;
+ }
+ else
+ {
+ $bgcolor = $info['even'] ? "#fff" : "#eee";
+ $color = $this->getColorLevel($log[1]);
+ $string = <<<EOD
+ <tr style="background-color: {$bgcolor}; color:#000">
+ <td style="border:1px solid silver;background-color: $color;">&nbsp;</td>
+ <td>{$log[2]}</td>
+ <td>{$msg}</td>
+ <td style="text-align:center">{$delta}</td>
+ <td style="text-align:center">{$total}</td>
+ </tr>
+EOD;
+ }
+ return $string;
+ }
+
+ protected function getColorLevel($level)
+ {
+ switch($level)
+ {
+ case TLogger::DEBUG: return 'green';
+ case TLogger::INFO: return 'black';
+ case TLogger::NOTICE: return '#3333FF';
+ case TLogger::WARNING: return '#33FFFF';
+ case TLogger::ERROR: return '#ff9933';
+ case TLogger::ALERT: return '#ff00ff';
+ case TLogger::FATAL: return 'red';
+ }
+ return '';
+ }
+
+ protected function renderFooter()
+ {
+ $string = '';
+ if($this->getCssClass())
+ {
+ $string .= '<tr class="footer"><td colspan="5">';
+ foreach(self::$_levelValues as $name => $level)
+ {
+ $string .= '<span class="level'.$level.'">'.strtoupper($name)."</span>";
+ }
+ }
+ else
+ {
+ $string .= "<tr><td colspan=\"5\" style=\"text-align:center; background-color:black; border-top: 1px solid #ccc; padding:0.2em;\">";
+ foreach(self::$_levelValues as $name => $level)
+ {
+ $string .= "<span style=\"color:white; border:1px solid white; background-color:".$this->getColorLevel($level);
+ $string .= ";margin: 0.5em; padding:0.01em;\">".strtoupper($name)."</span>";
+ }
+ }
+ $string .= '</td></tr></table>';
+ return $string;
+ }
+}
+
+
+/**
+ * TDbLogRoute class
+ *
+ * TDbLogRoute stores log messages in a database table.
+ * To specify the database table, set {@link setConnectionID ConnectionID} to be
+ * the ID of a {@link TDataSourceConfig} module and {@link setLogTableName LogTableName}.
+ * If they are not setting, an SQLite3 database named 'sqlite3.log' will be created and used
+ * under the runtime directory.
+ *
+ * By default, the database table name is 'pradolog'. It has the following structure:
+ * <code>
+ * CREATE TABLE pradolog
+ * (
+ * log_id INTEGER NOT NULL PRIMARY KEY,
+ * level INTEGER,
+ * category VARCHAR(128),
+ * logtime VARCHAR(20),
+ * message VARCHAR(255)
+ * );
+ * </code>
+ *
+ * @author Qiang Xue <qiang.xue@gmail.com>
+ * @version $Id$
+ * @package System.Util
+ * @since 3.1.2
+ */
+class TDbLogRoute extends TLogRoute
+{
+ /**
+ * @var string the ID of TDataSourceConfig module
+ */
+ private $_connID='';
+ /**
+ * @var TDbConnection the DB connection instance
+ */
+ private $_db;
+ /**
+ * @var string name of the DB log table
+ */
+ private $_logTable='pradolog';
+ /**
+ * @var boolean whether the log DB table should be created automatically
+ */
+ private $_autoCreate=true;
+
+ /**
+ * Destructor.
+ * Disconnect the db connection.
+ */
+ public function __destruct()
+ {
+ if($this->_db!==null)
+ $this->_db->setActive(false);
+ }
+
+ /**
+ * Initializes this module.
+ * This method is required by the IModule interface.
+ * It initializes the database for logging purpose.
+ * @param TXmlElement configuration for this module, can be null
+ * @throws TConfigurationException if the DB table does not exist.
+ */
+ public function init($config)
+ {
+ $db=$this->getDbConnection();
+ $db->setActive(true);
+
+ $sql='SELECT * FROM '.$this->_logTable.' WHERE 0=1';
+ try
+ {
+ $db->createCommand($sql)->query()->close();
+ }
+ catch(Exception $e)
+ {
+ // DB table not exists
+ if($this->_autoCreate)
+ $this->createDbTable();
+ else
+ throw new TConfigurationException('db_logtable_inexistent',$this->_logTable);
+ }
+
+ parent::init($config);
+ }
+
+ /**
+ * Stores log messages into database.
+ * @param array list of log messages
+ */
+ protected function processLogs($logs)
+ {
+ $sql='INSERT INTO '.$this->_logTable.'(level, category, logtime, message) VALUES (:level, :category, :logtime, :message)';
+ $command=$this->getDbConnection()->createCommand($sql);
+ foreach($logs as $log)
+ {
+ $command->bindValue(':message',$log[0]);
+ $command->bindValue(':level',$log[1]);
+ $command->bindValue(':category',$log[2]);
+ $command->bindValue(':logtime',$log[3]);
+ $command->execute();
+ }
+ }
+
+ /**
+ * Creates the DB table for storing log messages.
+ * @todo create sequence for PostgreSQL
+ */
+ protected function createDbTable()
+ {
+ $db = $this->getDbConnection();
+ $driver=$db->getDriverName();
+ $autoidAttributes = '';
+ if($driver==='mysql')
+ $autoidAttributes = 'AUTO_INCREMENT';
+
+ $sql='CREATE TABLE '.$this->_logTable.' (
+ log_id INTEGER NOT NULL PRIMARY KEY ' . $autoidAttributes . ',
+ level INTEGER,
+ category VARCHAR(128),
+ logtime VARCHAR(20),
+ message VARCHAR(255))';
+ $db->createCommand($sql)->execute();
+ }
+
+ /**
+ * Creates the DB connection.
+ * @param string the module ID for TDataSourceConfig
+ * @return TDbConnection the created DB connection
+ * @throws TConfigurationException if module ID is invalid or empty
+ */
+ protected function createDbConnection()
+ {
+ if($this->_connID!=='')
+ {
+ $config=$this->getApplication()->getModule($this->_connID);
+ if($config instanceof TDataSourceConfig)
+ return $config->getDbConnection();
+ else
+ throw new TConfigurationException('dblogroute_connectionid_invalid',$this->_connID);
+ }
+ else
+ {
+ $db=new TDbConnection;
+ // default to SQLite3 database
+ $dbFile=$this->getApplication()->getRuntimePath().'/sqlite3.log';
+ $db->setConnectionString('sqlite:'.$dbFile);
+ return $db;
+ }
+ }
+
+ /**
+ * @return TDbConnection the DB connection instance
+ */
+ public function getDbConnection()
+ {
+ if($this->_db===null)
+ $this->_db=$this->createDbConnection();
+ return $this->_db;
+ }
+
+ /**
+ * @return string the ID of a {@link TDataSourceConfig} module. Defaults to empty string, meaning not set.
+ */
+ public function getConnectionID()
+ {
+ return $this->_connID;
+ }
+
+ /**
+ * Sets the ID of a TDataSourceConfig module.
+ * The datasource module will be used to establish the DB connection for this log route.
+ * @param string ID of the {@link TDataSourceConfig} module
+ */
+ public function setConnectionID($value)
+ {
+ $this->_connID=$value;
+ }
+
+ /**
+ * @return string the name of the DB table to store log content. Defaults to 'pradolog'.
+ * @see setAutoCreateLogTable
+ */
+ public function getLogTableName()
+ {
+ return $this->_logTable;
+ }
+
+ /**
+ * Sets the name of the DB table to store log content.
+ * Note, if {@link setAutoCreateLogTable AutoCreateLogTable} is false
+ * and you want to create the DB table manually by yourself,
+ * you need to make sure the DB table is of the following structure:
+ * (key CHAR(128) PRIMARY KEY, value BLOB, expire INT)
+ * @param string the name of the DB table to store log content
+ * @see setAutoCreateLogTable
+ */
+ public function setLogTableName($value)
+ {
+ $this->_logTable=$value;
+ }
+
+ /**
+ * @return boolean whether the log DB table should be automatically created if not exists. Defaults to true.
+ * @see setAutoCreateLogTable
+ */
+ public function getAutoCreateLogTable()
+ {
+ return $this->_autoCreate;
+ }
+
+ /**
+ * @param boolean whether the log DB table should be automatically created if not exists.
+ * @see setLogTableName
+ */
+ public function setAutoCreateLogTable($value)
+ {
+ $this->_autoCreate=TPropertyValue::ensureBoolean($value);
+ }
+
+}
+
+/**
+ * TFirebugLogRoute class.
+ *
+ * TFirebugLogRoute prints selected log messages in the firebug log console.
+ *
+ * {@link http://www.getfirebug.com/ FireBug Website}
+ *
+ * @author Enrico Stahn <mail@enricostahn.com>, Christophe Boulain <Christophe.Boulain@gmail.com>
+ * @version $Id$
+ * @package System.Util
+ * @since 3.1.2
+ */
+class TFirebugLogRoute extends TBrowserLogRoute
+{
+ protected function renderHeader ()
+ {
+ $string = <<<EOD
+
+<script type="text/javascript">
+/*<![CDATA[*/
+if (typeof(console) == 'object')
+{
+ console.log ("[Cumulated Time] [Time] [Level] [Category] [Message]");
+
+EOD;
+
+ return $string;
+ }
+
+ protected function renderMessage ($log, $info)
+ {
+ $logfunc = $this->getFirebugLoggingFunction($log[1]);
+ $total = sprintf('%0.6f', $info['total']);
+ $delta = sprintf('%0.6f', $info['delta']);
+ $msg = trim($this->formatLogMessage($log[0], $log[1], $log[2], ''));
+ $msg = preg_replace('/\(line[^\)]+\)$/', '', $msg); //remove line number info
+ $msg = "[{$total}] [{$delta}] ".$msg; // Add time spent and cumulated time spent
+ $string = $logfunc . '(\'' . addslashes($msg) . '\');' . "\n";
+
+ return $string;
+ }
+
+
+ protected function renderFooter ()
+ {
+ $string = <<<EOD
+
+}
+</script>
+
+EOD;
+
+ return $string;
+ }
+
+ protected function getFirebugLoggingFunction($level)
+ {
+ switch ($level)
+ {
+ case TLogger::DEBUG:
+ case TLogger::INFO:
+ case TLogger::NOTICE:
+ return 'console.log';
+ case TLogger::WARNING:
+ return 'console.warn';
+ case TLogger::ERROR:
+ case TLogger::ALERT:
+ case TLogger::FATAL:
+ return 'console.error';
+ default:
+ return 'console.log';
+ }
+ }
+
+}
+
+/**
+ * TFirePhpLogRoute class.
+ *
+ * TFirePhpLogRoute prints log messages in the firebug log console via firephp.
+ *
+ * {@link http://www.getfirebug.com/ FireBug Website}
+ * {@link http://www.firephp.org/ FirePHP Website}
+ *
+ * @author Yves Berkholz <godzilla80[at]gmx[dot]net>
+ * @version $Id$
+ * @package System.Util
+ * @since 3.1.5
+ */
+class TFirePhpLogRoute extends TLogRoute
+{
+ /**
+ * Default group label
+ */
+ const DEFAULT_LABEL = 'System.Util.TLogRouter(TFirePhpLogRoute)';
+
+ private $_groupLabel = null;
+
+ public function processLogs($logs)
+ {
+ if(empty($logs) || $this->getApplication()->getMode()==='Performance')
+ return;
+
+ if(headers_sent()) {
+ echo '
+ <div style="width:100%; background-color:darkred; color:#FFF; padding:2px">
+ TFirePhpLogRoute.GroupLabel "<i>' . $this -> getGroupLabel() . '</i>" -
+ Routing to FirePHP impossible, because headers already sent!
+ </div>
+ ';
+ $fallback = new TBrowserLogRoute();
+ $fallback->processLogs($logs);
+ return;
+ }
+
+ require_once Prado::getPathOfNamespace('System.3rdParty.FirePHPCore') . '/FirePHP.class.php';
+ $firephp = FirePHP::getInstance(true);
+ $firephp->setOptions(array('useNativeJsonEncode' => false));
+ $firephp->group($this->getGroupLabel(), array('Collapsed' => true));
+ $firephp->log('Time, Message');
+
+ $first = $logs[0][3];
+ $c = count($logs);
+ for($i=0,$n=$c;$i<$n;++$i)
+ {
+ $message = $logs[$i][0];
+ $level = $logs[$i][1];
+ $category = $logs[$i][2];
+
+ if ($i<$n-1)
+ {
+ $delta = $logs[$i+1][3] - $logs[$i][3];
+ $total = $logs[$i+1][3] - $first;
+ }
+ else
+ {
+ $delta = '?';
+ $total = $logs[$i][3] - $first;
+ }
+
+ $message = sPrintF('+%0.6f: %s', $delta, preg_replace('/\(line[^\)]+\)$/', '', $message));
+ $firephp->fb($message, $category, self::translateLogLevel($level));
+ }
+ $firephp->log(sPrintF('%0.6f', $total), 'Cumulated Time');
+ $firephp->groupEnd();
+ }
+
+ /**
+ * Translates a PRADO log level attribute into one understood by FirePHP for correct visualization
+ * @param string prado log level
+ * @return string FirePHP log level
+ */
+ protected static function translateLogLevel($level)
+ {
+ switch($level)
+ {
+ case TLogger::INFO:
+ return FirePHP::INFO;
+ case TLogger::DEBUG:
+ case TLogger::NOTICE:
+ return FirePHP::LOG;
+ case TLogger::WARNING:
+ return FirePHP::WARN;
+ case TLogger::ERROR:
+ case TLogger::ALERT:
+ case TLogger::FATAL:
+ return FirePHP::ERROR;
+ default:
+ return FirePHP::LOG;
+ }
+ }
+
+ /**
+ * @return string group label. Defaults to TFirePhpLogRoute::DEFAULT_LABEL
+ */
+ public function getGroupLabel()
+ {
+ if($this->_groupLabel===null)
+ $this->_groupLabel=self::DEFAULT_LABEL;
+
+ return $this->_groupLabel;
+ }
+
+ /**
+ * @param string group label.
+ */
+ public function setGroupLabel($value)
+ {
+ $this->_groupLabel=$value;
+ }
+}
diff --git a/framework/Util/TLogger.php b/framework/Util/TLogger.php
index 97334629..6ad5df91 100644
--- a/framework/Util/TLogger.php
+++ b/framework/Util/TLogger.php
@@ -1,236 +1,236 @@
-<?php
-/**
- * TLogger class file
- *
- * @author Qiang Xue <qiang.xue@gmail.com>
- * @link http://www.pradosoft.com/
- * @copyright Copyright &copy; 2005-2012 PradoSoft
- * @license http://www.pradosoft.com/license/
- * @version $Id$
- * @package System.Util
- */
-
-/**
- * TLogger class.
- *
- * TLogger records log messages in memory and implements the methods to
- * retrieve the messages with filter conditions, including log levels,
- * log categories, and by control.
- *
- * @author Qiang Xue <qiang.xue@gmail.com>
- * @version $Id$
- * @package System.Util
- * @since 3.0
- */
-class TLogger extends TComponent
-{
- /**
- * Log levels.
- */
- const DEBUG=0x01;
- const INFO=0x02;
- const NOTICE=0x04;
- const WARNING=0x08;
- const ERROR=0x10;
- const ALERT=0x20;
- const FATAL=0x40;
- /**
- * @var array log messages
- */
- private $_logs=array();
- /**
- * @var integer log levels (bits) to be filtered
- */
- private $_levels;
- /**
- * @var array list of categories to be filtered
- */
- private $_categories;
- /**
- * @var array list of control client ids to be filtered
- */
- private $_controls;
- /**
- * @var float timestamp used to filter
- */
- private $_timestamp;
-
- /**
- * Logs a message.
- * Messages logged by this method may be retrieved via {@link getLogs}.
- * @param string message to be logged
- * @param integer level of the message. Valid values include
- * TLogger::DEBUG, TLogger::INFO, TLogger::NOTICE, TLogger::WARNING,
- * TLogger::ERROR, TLogger::ALERT, TLogger::FATAL.
- * @param string category of the message
- * @param string|TControl control of the message
- */
- public function log($message,$level,$category='Uncategorized', $ctl=null)
- {
- if($ctl) {
- if($ctl instanceof TControl)
- $ctl = $ctl->ClientId;
- else if(!is_string($ctl))
- $ctl = null;
- } else
- $ctl = null;
- $this->_logs[]=array($message,$level,$category,microtime(true),memory_get_usage(),$ctl);
- }
-
- /**
- * Retrieves log messages.
- * Messages may be filtered by log levels and/or categories and/or control client ids and/or timestamp.
- * A level filter is specified by an integer, whose bits indicate the levels interested.
- * For example, (TLogger::INFO | TLogger::WARNING) specifies INFO and WARNING levels.
- * A category filter is specified by an array of categories to filter.
- * A message whose category name starts with any filtering category
- * will be returned. For example, a category filter array('System.Web','System.IO')
- * will return messages under categories such as 'System.Web', 'System.IO',
- * 'System.Web.UI', 'System.Web.UI.WebControls', etc.
- * A control client id filter is specified by an array of control client id
- * A message whose control client id starts with any filtering naming panels
- * will be returned. For example, a category filter array('ctl0_body_header',
- * 'ctl0_body_content_sidebar')
- * will return messages under categories such as 'ctl0_body_header', 'ctl0_body_content_sidebar',
- * 'ctl0_body_header_title', 'ctl0_body_content_sidebar_savebutton', etc.
- * A timestamp filter is specified as an interger or float number.
- * A message whose registered timestamp is less or equal the filter value will be returned.
- * Level filter, category filter, control filter and timestamp filter are combinational, i.e., only messages
- * satisfying all filter conditions will they be returned.
- * @param integer level filter
- * @param array category filter
- * @param array control filter
- * @return array list of messages. Each array elements represents one message
- * with the following structure:
- * array(
- * [0] => message
- * [1] => level
- * [2] => category
- * [3] => timestamp (by microtime(), float number));
- * [4] => memory in bytes
- * [5] => control client id
- */
- public function getLogs($levels=null,$categories=null,$controls=null,$timestamp=null)
- {
- $this->_levels=$levels;
- $this->_categories=$categories;
- $this->_controls=$controls;
- $this->_timestamp=$timestamp;
- if(empty($levels) && empty($categories) && empty($controls) && is_null($timestamp))
- return $this->_logs;
- $logs = $this->_logs;
- if(!empty($levels))
- $logs = array_values(array_filter( array_filter($logs,array($this,'filterByLevels')) ));
- if(!empty($categories))
- $logs = array_values(array_filter( array_filter($logs,array($this,'filterByCategories')) ));
- if(!empty($controls))
- $logs = array_values(array_filter( array_filter($logs,array($this,'filterByControl')) ));
- if(!is_null($timestamp))
- $logs = array_values(array_filter( array_filter($logs,array($this,'filterByTimeStamp')) ));
- return $logs;
- }
-
- /**
- * Deletes log messages from the queue.
- * Messages may be filtered by log levels and/or categories and/or control client ids and/or timestamp.
- * A level filter is specified by an integer, whose bits indicate the levels interested.
- * For example, (TLogger::INFO | TLogger::WARNING) specifies INFO and WARNING levels.
- * A category filter is specified by an array of categories to filter.
- * A message whose category name starts with any filtering category
- * will be deleted. For example, a category filter array('System.Web','System.IO')
- * will delete messages under categories such as 'System.Web', 'System.IO',
- * 'System.Web.UI', 'System.Web.UI.WebControls', etc.
- * A control client id filter is specified by an array of control client id
- * A message whose control client id starts with any filtering naming panels
- * will be deleted. For example, a category filter array('ctl0_body_header',
- * 'ctl0_body_content_sidebar')
- * will delete messages under categories such as 'ctl0_body_header', 'ctl0_body_content_sidebar',
- * 'ctl0_body_header_title', 'ctl0_body_content_sidebar_savebutton', etc.
- * A timestamp filter is specified as an interger or float number.
- * A message whose registered timestamp is less or equal the filter value will be returned.
- * Level filter, category filter, control filter and timestamp filter are combinational, i.e., only messages
- * satisfying all filter conditions will they be returned.
- * @param integer level filter
- * @param array category filter
- * @param array control filter
- */
- public function deleteLogs($levels=null,$categories=null,$controls=null,$timestamp=null)
- {
- $this->_levels=$levels;
- $this->_categories=$categories;
- $this->_controls=$controls;
- $this->_timestamp=$timestamp;
- if(empty($levels) && empty($categories) && empty($controls) && is_null($timestamp))
- {
- $this->_logs=array();
- return;
- }
- $logs = $this->_logs;
- if(!empty($levels))
- $logs = array_filter( array_filter($logs,array($this,'filterByLevels')) );
- if(!empty($categories))
- $logs = array_filter( array_filter($logs,array($this,'filterByCategories')) );
- if(!empty($controls))
- $logs = array_filter( array_filter($logs,array($this,'filterByControl')) );
- if(!is_null($timestamp))
- $logs = array_filter( array_filter($logs,array($this,'filterByTimeStamp')) );
- $this->_logs = array_values( array_diff_key($this->_logs, $logs) );
- }
-
- /**
- * Filter function used by {@link getLogs}.
- * @param array element to be filtered
- */
- private function filterByCategories($value)
- {
- foreach($this->_categories as $category)
- {
- // element 2 is the category
- if($value[2]===$category || strpos($value[2],$category.'.')===0)
- return $value;
- }
- return false;
- }
-
- /**
- * Filter function used by {@link getLogs}
- * @param array element to be filtered
- */
- private function filterByLevels($value)
- {
- // element 1 are the levels
- if($value[1] & $this->_levels)
- return $value;
- else
- return false;
- }
-
- /**
- * Filter function used by {@link getLogs}
- * @param array element to be filtered
- */
- private function filterByControl($value)
- {
- // element 5 are the control client ids
- foreach($this->_controls as $control)
- {
- if($value[5]===$control || strpos($value[5],$control)===0)
- return $value;
- }
- return false;
- }
-
- /**
- * Filter function used by {@link getLogs}
- * @param array element to be filtered
- */
- private function filterByTimeStamp($value)
- {
- // element 3 is the timestamp
- if($value[3] <= $this->_timestamp)
- return $value;
- else
- return false;
- }
-}
-
+<?php
+/**
+ * TLogger class file
+ *
+ * @author Qiang Xue <qiang.xue@gmail.com>
+ * @link http://www.pradosoft.com/
+ * @copyright Copyright &copy; 2005-2012 PradoSoft
+ * @license http://www.pradosoft.com/license/
+ * @version $Id$
+ * @package System.Util
+ */
+
+/**
+ * TLogger class.
+ *
+ * TLogger records log messages in memory and implements the methods to
+ * retrieve the messages with filter conditions, including log levels,
+ * log categories, and by control.
+ *
+ * @author Qiang Xue <qiang.xue@gmail.com>
+ * @version $Id$
+ * @package System.Util
+ * @since 3.0
+ */
+class TLogger extends TComponent
+{
+ /**
+ * Log levels.
+ */
+ const DEBUG=0x01;
+ const INFO=0x02;
+ const NOTICE=0x04;
+ const WARNING=0x08;
+ const ERROR=0x10;
+ const ALERT=0x20;
+ const FATAL=0x40;
+ /**
+ * @var array log messages
+ */
+ private $_logs=array();
+ /**
+ * @var integer log levels (bits) to be filtered
+ */
+ private $_levels;
+ /**
+ * @var array list of categories to be filtered
+ */
+ private $_categories;
+ /**
+ * @var array list of control client ids to be filtered
+ */
+ private $_controls;
+ /**
+ * @var float timestamp used to filter
+ */
+ private $_timestamp;
+
+ /**
+ * Logs a message.
+ * Messages logged by this method may be retrieved via {@link getLogs}.
+ * @param string message to be logged
+ * @param integer level of the message. Valid values include
+ * TLogger::DEBUG, TLogger::INFO, TLogger::NOTICE, TLogger::WARNING,
+ * TLogger::ERROR, TLogger::ALERT, TLogger::FATAL.
+ * @param string category of the message
+ * @param string|TControl control of the message
+ */
+ public function log($message,$level,$category='Uncategorized', $ctl=null)
+ {
+ if($ctl) {
+ if($ctl instanceof TControl)
+ $ctl = $ctl->ClientId;
+ else if(!is_string($ctl))
+ $ctl = null;
+ } else
+ $ctl = null;
+ $this->_logs[]=array($message,$level,$category,microtime(true),memory_get_usage(),$ctl);
+ }
+
+ /**
+ * Retrieves log messages.
+ * Messages may be filtered by log levels and/or categories and/or control client ids and/or timestamp.
+ * A level filter is specified by an integer, whose bits indicate the levels interested.
+ * For example, (TLogger::INFO | TLogger::WARNING) specifies INFO and WARNING levels.
+ * A category filter is specified by an array of categories to filter.
+ * A message whose category name starts with any filtering category
+ * will be returned. For example, a category filter array('System.Web','System.IO')
+ * will return messages under categories such as 'System.Web', 'System.IO',
+ * 'System.Web.UI', 'System.Web.UI.WebControls', etc.
+ * A control client id filter is specified by an array of control client id
+ * A message whose control client id starts with any filtering naming panels
+ * will be returned. For example, a category filter array('ctl0_body_header',
+ * 'ctl0_body_content_sidebar')
+ * will return messages under categories such as 'ctl0_body_header', 'ctl0_body_content_sidebar',
+ * 'ctl0_body_header_title', 'ctl0_body_content_sidebar_savebutton', etc.
+ * A timestamp filter is specified as an interger or float number.
+ * A message whose registered timestamp is less or equal the filter value will be returned.
+ * Level filter, category filter, control filter and timestamp filter are combinational, i.e., only messages
+ * satisfying all filter conditions will they be returned.
+ * @param integer level filter
+ * @param array category filter
+ * @param array control filter
+ * @return array list of messages. Each array elements represents one message
+ * with the following structure:
+ * array(
+ * [0] => message
+ * [1] => level
+ * [2] => category
+ * [3] => timestamp (by microtime(), float number));
+ * [4] => memory in bytes
+ * [5] => control client id
+ */
+ public function getLogs($levels=null,$categories=null,$controls=null,$timestamp=null)
+ {
+ $this->_levels=$levels;
+ $this->_categories=$categories;
+ $this->_controls=$controls;
+ $this->_timestamp=$timestamp;
+ if(empty($levels) && empty($categories) && empty($controls) && is_null($timestamp))
+ return $this->_logs;
+ $logs = $this->_logs;
+ if(!empty($levels))
+ $logs = array_values(array_filter( array_filter($logs,array($this,'filterByLevels')) ));
+ if(!empty($categories))
+ $logs = array_values(array_filter( array_filter($logs,array($this,'filterByCategories')) ));
+ if(!empty($controls))
+ $logs = array_values(array_filter( array_filter($logs,array($this,'filterByControl')) ));
+ if(!is_null($timestamp))
+ $logs = array_values(array_filter( array_filter($logs,array($this,'filterByTimeStamp')) ));
+ return $logs;
+ }
+
+ /**
+ * Deletes log messages from the queue.
+ * Messages may be filtered by log levels and/or categories and/or control client ids and/or timestamp.
+ * A level filter is specified by an integer, whose bits indicate the levels interested.
+ * For example, (TLogger::INFO | TLogger::WARNING) specifies INFO and WARNING levels.
+ * A category filter is specified by an array of categories to filter.
+ * A message whose category name starts with any filtering category
+ * will be deleted. For example, a category filter array('System.Web','System.IO')
+ * will delete messages under categories such as 'System.Web', 'System.IO',
+ * 'System.Web.UI', 'System.Web.UI.WebControls', etc.
+ * A control client id filter is specified by an array of control client id
+ * A message whose control client id starts with any filtering naming panels
+ * will be deleted. For example, a category filter array('ctl0_body_header',
+ * 'ctl0_body_content_sidebar')
+ * will delete messages under categories such as 'ctl0_body_header', 'ctl0_body_content_sidebar',
+ * 'ctl0_body_header_title', 'ctl0_body_content_sidebar_savebutton', etc.
+ * A timestamp filter is specified as an interger or float number.
+ * A message whose registered timestamp is less or equal the filter value will be returned.
+ * Level filter, category filter, control filter and timestamp filter are combinational, i.e., only messages
+ * satisfying all filter conditions will they be returned.
+ * @param integer level filter
+ * @param array category filter
+ * @param array control filter
+ */
+ public function deleteLogs($levels=null,$categories=null,$controls=null,$timestamp=null)
+ {
+ $this->_levels=$levels;
+ $this->_categories=$categories;
+ $this->_controls=$controls;
+ $this->_timestamp=$timestamp;
+ if(empty($levels) && empty($categories) && empty($controls) && is_null($timestamp))
+ {
+ $this->_logs=array();
+ return;
+ }
+ $logs = $this->_logs;
+ if(!empty($levels))
+ $logs = array_filter( array_filter($logs,array($this,'filterByLevels')) );
+ if(!empty($categories))
+ $logs = array_filter( array_filter($logs,array($this,'filterByCategories')) );
+ if(!empty($controls))
+ $logs = array_filter( array_filter($logs,array($this,'filterByControl')) );
+ if(!is_null($timestamp))
+ $logs = array_filter( array_filter($logs,array($this,'filterByTimeStamp')) );
+ $this->_logs = array_values( array_diff_key($this->_logs, $logs) );
+ }
+
+ /**
+ * Filter function used by {@link getLogs}.
+ * @param array element to be filtered
+ */
+ private function filterByCategories($value)
+ {
+ foreach($this->_categories as $category)
+ {
+ // element 2 is the category
+ if($value[2]===$category || strpos($value[2],$category.'.')===0)
+ return $value;
+ }
+ return false;
+ }
+
+ /**
+ * Filter function used by {@link getLogs}
+ * @param array element to be filtered
+ */
+ private function filterByLevels($value)
+ {
+ // element 1 are the levels
+ if($value[1] & $this->_levels)
+ return $value;
+ else
+ return false;
+ }
+
+ /**
+ * Filter function used by {@link getLogs}
+ * @param array element to be filtered
+ */
+ private function filterByControl($value)
+ {
+ // element 5 are the control client ids
+ foreach($this->_controls as $control)
+ {
+ if($value[5]===$control || strpos($value[5],$control)===0)
+ return $value;
+ }
+ return false;
+ }
+
+ /**
+ * Filter function used by {@link getLogs}
+ * @param array element to be filtered
+ */
+ private function filterByTimeStamp($value)
+ {
+ // element 3 is the timestamp
+ if($value[3] <= $this->_timestamp)
+ return $value;
+ else
+ return false;
+ }
+}
+
diff --git a/framework/Util/TParameterModule.php b/framework/Util/TParameterModule.php
index 31f109c1..a142e4ae 100644
--- a/framework/Util/TParameterModule.php
+++ b/framework/Util/TParameterModule.php
@@ -1,173 +1,173 @@
-<?php
-/**
- * TParameterModule class
- *
- * @author Qiang Xue <qiang.xue@gmail.com>
- * @link http://www.pradosoft.com/
- * @copyright Copyright &copy; 2005-2012 PradoSoft
- * @license http://www.pradosoft.com/license/
- * @version $Id$
- * @package System.Util
- */
-
-/**
- * TParameterModule class
- *
- * TParameterModule enables loading application parameters from external
- * storage other than the application configuration.
- * To load parameters from an XML file, configure the module by setting
- * its {@link setParameterFile ParameterFile} property.
- * Note, the property only accepts a file path in namespace format with
- * file extension being '.xml'. The file format is as follows, which is
- * similar to the parameter portion in an application configuration,
- * <code>
- * <parameters>
- * <parameter id="param1" value="paramValue1" />
- * <parameter id="param2" Property1="Value1" Property2="Value2" ... />
- * </parameters>
- * </code>
- *
- * In addition, any content enclosed within the module tag is also treated
- * as parameters, e.g.,
- * <code>
- * <module class="System.Util.TParameterModule">
- * <parameter id="param1" value="paramValue1" />
- * <parameter id="param2" Property1="Value1" Property2="Value2" ... />
- * </module>
- * </code>
- *
- * If a parameter is defined both in the external file and within the module
- * tag, the former takes precedence.
- *
- * @author Qiang Xue <qiang.xue@gmail.com>
- * @author Carl G. Mathisen <carlgmathisen@gmail.com>
- * @version $Id$
- * @package System.Util
- * @since 3.0
- */
-class TParameterModule extends TModule
-{
- /**
- * @deprecated since 3.2
- */
- const PARAM_FILE_EXT='.xml';
- private $_initialized=false;
- private $_paramFile=null;
-
- /**
- * Initializes the module by loading parameters.
- * @param mixed content enclosed within the module tag
- */
- public function init($config)
- {
- $this->loadParameters($config);
- if($this->_paramFile!==null)
- {
- $configFile = null;
- if($this->getApplication()->getConfigurationType()==TApplication::CONFIG_TYPE_XML && ($cache=$this->getApplication()->getCache())!==null)
- {
- $cacheKey='TParameterModule:'.$this->_paramFile;
- if(($configFile=$cache->get($cacheKey))===false)
- {
- $cacheFile=new TXmlDocument;
- $cacheFile->loadFromFile($this->_paramFile);
- $cache->set($cacheKey,$cacheFile,0,new TFileCacheDependency($this->_paramFile));
- }
- }
- else
- {
- if($this->getApplication()->getConfigurationType()==TApplication::CONFIG_TYPE_PHP)
- {
- $configFile = include $this->_paramFile;
- }
- else
- {
- $configFile=new TXmlDocument;
- $configFile->loadFromFile($this->_paramFile);
- }
- }
- $this->loadParameters($configFile);
- }
- $this->_initialized=true;
- }
-
- /**
- * Loads parameters into application.
- * @param mixed XML of PHP representation of the parameters
- * @throws TConfigurationException if the parameter file format is invalid
- */
- protected function loadParameters($config)
- {
- $parameters=array();
- if(is_array($config))
- {
- foreach($config as $id => $parameter)
- {
- if(is_array($parameter) && isset($parameter['class']))
- {
- $properties = isset($parameter['properties'])?$parameter['properties']:array();
- $parameters[$id]=array($parameter['class'],$properties);
- }
- else
- {
- $parameters[$id] = $parameter;
- }
- }
- }
- else if($config instanceof TXmlElement)
- {
- foreach($config->getElementsByTagName('parameter') as $node)
- {
- $properties=$node->getAttributes();
- if(($id=$properties->remove('id'))===null)
- throw new TConfigurationException('parametermodule_parameterid_required');
- if(($type=$properties->remove('class'))===null)
- {
- if(($value=$properties->remove('value'))===null)
- $parameters[$id]=$node;
- else
- $parameters[$id]=$value;
- }
- else
- $parameters[$id]=array($type,$properties->toArray());
- }
- }
-
- $appParams=$this->getApplication()->getParameters();
- foreach($parameters as $id=>$parameter)
- {
- if(is_array($parameter))
- {
- $component=Prado::createComponent($parameter[0]);
- foreach($parameter[1] as $name=>$value)
- $component->setSubProperty($name,$value);
- $appParams->add($id,$component);
- }
- else
- $appParams->add($id,$parameter);
- }
- }
-
- /**
- * @return string the parameter file path
- */
- public function getParameterFile()
- {
- return $this->_paramFile;
- }
-
- /**
- * @param string the parameter file path. It must be in namespace format
- * and the file extension is '.xml'.
- * @throws TInvalidOperationException if the module is initialized
- * @throws TConfigurationException if the file is invalid
- */
- public function setParameterFile($value)
- {
- if($this->_initialized)
- throw new TInvalidOperationException('parametermodule_parameterfile_unchangeable');
- else if(($this->_paramFile=Prado::getPathOfNamespace($value,$this->getApplication()->getConfigurationFileExt()))===null || !is_file($this->_paramFile))
- throw new TConfigurationException('parametermodule_parameterfile_invalid',$value);
- }
-}
-
+<?php
+/**
+ * TParameterModule class
+ *
+ * @author Qiang Xue <qiang.xue@gmail.com>
+ * @link http://www.pradosoft.com/
+ * @copyright Copyright &copy; 2005-2012 PradoSoft
+ * @license http://www.pradosoft.com/license/
+ * @version $Id$
+ * @package System.Util
+ */
+
+/**
+ * TParameterModule class
+ *
+ * TParameterModule enables loading application parameters from external
+ * storage other than the application configuration.
+ * To load parameters from an XML file, configure the module by setting
+ * its {@link setParameterFile ParameterFile} property.
+ * Note, the property only accepts a file path in namespace format with
+ * file extension being '.xml'. The file format is as follows, which is
+ * similar to the parameter portion in an application configuration,
+ * <code>
+ * <parameters>
+ * <parameter id="param1" value="paramValue1" />
+ * <parameter id="param2" Property1="Value1" Property2="Value2" ... />
+ * </parameters>
+ * </code>
+ *
+ * In addition, any content enclosed within the module tag is also treated
+ * as parameters, e.g.,
+ * <code>
+ * <module class="System.Util.TParameterModule">
+ * <parameter id="param1" value="paramValue1" />
+ * <parameter id="param2" Property1="Value1" Property2="Value2" ... />
+ * </module>
+ * </code>
+ *
+ * If a parameter is defined both in the external file and within the module
+ * tag, the former takes precedence.
+ *
+ * @author Qiang Xue <qiang.xue@gmail.com>
+ * @author Carl G. Mathisen <carlgmathisen@gmail.com>
+ * @version $Id$
+ * @package System.Util
+ * @since 3.0
+ */
+class TParameterModule extends TModule
+{
+ /**
+ * @deprecated since 3.2
+ */
+ const PARAM_FILE_EXT='.xml';
+ private $_initialized=false;
+ private $_paramFile=null;
+
+ /**
+ * Initializes the module by loading parameters.
+ * @param mixed content enclosed within the module tag
+ */
+ public function init($config)
+ {
+ $this->loadParameters($config);
+ if($this->_paramFile!==null)
+ {
+ $configFile = null;
+ if($this->getApplication()->getConfigurationType()==TApplication::CONFIG_TYPE_XML && ($cache=$this->getApplication()->getCache())!==null)
+ {
+ $cacheKey='TParameterModule:'.$this->_paramFile;
+ if(($configFile=$cache->get($cacheKey))===false)
+ {
+ $cacheFile=new TXmlDocument;
+ $cacheFile->loadFromFile($this->_paramFile);
+ $cache->set($cacheKey,$cacheFile,0,new TFileCacheDependency($this->_paramFile));
+ }
+ }
+ else
+ {
+ if($this->getApplication()->getConfigurationType()==TApplication::CONFIG_TYPE_PHP)
+ {
+ $configFile = include $this->_paramFile;
+ }
+ else
+ {
+ $configFile=new TXmlDocument;
+ $configFile->loadFromFile($this->_paramFile);
+ }
+ }
+ $this->loadParameters($configFile);
+ }
+ $this->_initialized=true;
+ }
+
+ /**
+ * Loads parameters into application.
+ * @param mixed XML of PHP representation of the parameters
+ * @throws TConfigurationException if the parameter file format is invalid
+ */
+ protected function loadParameters($config)
+ {
+ $parameters=array();
+ if(is_array($config))
+ {
+ foreach($config as $id => $parameter)
+ {
+ if(is_array($parameter) && isset($parameter['class']))
+ {
+ $properties = isset($parameter['properties'])?$parameter['properties']:array();
+ $parameters[$id]=array($parameter['class'],$properties);
+ }
+ else
+ {
+ $parameters[$id] = $parameter;
+ }
+ }
+ }
+ else if($config instanceof TXmlElement)
+ {
+ foreach($config->getElementsByTagName('parameter') as $node)
+ {
+ $properties=$node->getAttributes();
+ if(($id=$properties->remove('id'))===null)
+ throw new TConfigurationException('parametermodule_parameterid_required');
+ if(($type=$properties->remove('class'))===null)
+ {
+ if(($value=$properties->remove('value'))===null)
+ $parameters[$id]=$node;
+ else
+ $parameters[$id]=$value;
+ }
+ else
+ $parameters[$id]=array($type,$properties->toArray());
+ }
+ }
+
+ $appParams=$this->getApplication()->getParameters();
+ foreach($parameters as $id=>$parameter)
+ {
+ if(is_array($parameter))
+ {
+ $component=Prado::createComponent($parameter[0]);
+ foreach($parameter[1] as $name=>$value)
+ $component->setSubProperty($name,$value);
+ $appParams->add($id,$component);
+ }
+ else
+ $appParams->add($id,$parameter);
+ }
+ }
+
+ /**
+ * @return string the parameter file path
+ */
+ public function getParameterFile()
+ {
+ return $this->_paramFile;
+ }
+
+ /**
+ * @param string the parameter file path. It must be in namespace format
+ * and the file extension is '.xml'.
+ * @throws TInvalidOperationException if the module is initialized
+ * @throws TConfigurationException if the file is invalid
+ */
+ public function setParameterFile($value)
+ {
+ if($this->_initialized)
+ throw new TInvalidOperationException('parametermodule_parameterfile_unchangeable');
+ else if(($this->_paramFile=Prado::getPathOfNamespace($value,$this->getApplication()->getConfigurationFileExt()))===null || !is_file($this->_paramFile))
+ throw new TConfigurationException('parametermodule_parameterfile_invalid',$value);
+ }
+}
+
diff --git a/framework/Util/TSimpleDateFormatter.php b/framework/Util/TSimpleDateFormatter.php
index 78b2666f..6b1ec51f 100644
--- a/framework/Util/TSimpleDateFormatter.php
+++ b/framework/Util/TSimpleDateFormatter.php
@@ -1,376 +1,376 @@
-<?php
-/**
- * TSimpleDateFormatter class file
- *
- * @author Wei Zhuo <weizhuo[at]gmail[dot]com>
- * @link http://www.pradosoft.com/
- * @copyright Copyright &copy; 2005-2012 PradoSoft
- * @license http://www.pradosoft.com/license/
- * @version $Id$
- * @package System.Util
- */
-
-/**
- * TSimpleDateFormatter class.
- *
- * Formats and parses dates using the SimpleDateFormat pattern.
- * This pattern is compatible with the I18N and java's SimpleDateFormatter.
- * <code>
- * Pattern | Description
- * ----------------------------------------------------
- * d | Day of month 1 to 31, no padding
- * dd | Day of monath 01 to 31, zero leading
- * M | Month digit 1 to 12, no padding
- * MM | Month digit 01 to 12, zero leading
- * yy | 2 year digit, e.g., 96, 05
- * yyyy | 4 year digit, e.g., 2005
- * ----------------------------------------------------
- * </code>
- *
- * Usage example, to format a date
- * <code>
- * $formatter = new TSimpleDateFormatter("dd/MM/yyy");
- * echo $formatter->format(time());
- * </code>
- *
- * To parse the date string into a date timestamp.
- * <code>
- * $formatter = new TSimpleDateFormatter("d-M-yyy");
- * echo $formatter->parse("24-6-2005");
- * </code>
- *
- * @author Wei Zhuo <weizhuo[at]gmail[dot]com>
- * @version $Id$
- * @package System.Util
- * @since 3.0
- */
-class TSimpleDateFormatter
-{
- /**
- * Formatting pattern.
- * @var string
- */
- private $pattern;
-
- /**
- * Charset, default is 'UTF-8'
- * @var string
- */
- private $charset = 'UTF-8';
-
- /**
- * Constructor, create a new date time formatter.
- * @param string formatting pattern.
- * @param string pattern and value charset
- */
- public function __construct($pattern, $charset='UTF-8')
- {
- $this->setPattern($pattern);
- $this->setCharset($charset);
- }
-
- /**
- * @return string formatting pattern.
- */
- public function getPattern()
- {
- return $this->pattern;
- }
-
- /**
- * @param string formatting pattern.
- */
- public function setPattern($pattern)
- {
- $this->pattern = $pattern;
- }
-
- /**
- * @return string formatting charset.
- */
- public function getCharset()
- {
- return $this->charset;
- }
-
- /**
- * @param string formatting charset.
- */
- public function setCharset($charset)
- {
- $this->charset = $charset;
- }
-
- /**
- * Format the date according to the pattern.
- * @param string|int the date to format, either integer or a string readable by strtotime.
- * @return string formatted date.
- */
- public function format($value)
- {
- $date = $this->getDate($value);
- $bits['yyyy'] = $date['year'];
- $bits['yy'] = substr("{$date['year']}", -2);
-
- $bits['MM'] = str_pad("{$date['mon']}", 2, '0', STR_PAD_LEFT);
- $bits['M'] = $date['mon'];
-
- $bits['dd'] = str_pad("{$date['mday']}", 2, '0', STR_PAD_LEFT);
- $bits['d'] = $date['mday'];
-
- $pattern = preg_replace('/M{3,4}/', 'MM', $this->pattern);
- return str_replace(array_keys($bits), $bits, $pattern);
- }
-
- public function getMonthPattern()
- {
- if(is_int(strpos($this->pattern, 'MMMM')))
- return 'MMMM';
- if(is_int(strpos($this->pattern, 'MMM')))
- return 'MMM';
- if(is_int(strpos($this->pattern, 'MM')))
- return 'MM';
- if(is_int(strpos($this->pattern, 'M')))
- return 'M';
- return false;
- }
-
- public function getDayPattern()
- {
- if(is_int(strpos($this->pattern, 'dd')))
- return 'dd';
- if(is_int(strpos($this->pattern, 'd')))
- return 'd';
- return false;
- }
-
- public function getYearPattern()
- {
- if(is_int(strpos($this->pattern, 'yyyy')))
- return 'yyyy';
- if(is_int(strpos($this->pattern, 'yy')))
- return 'yy';
- return false;
- }
-
- public function getDayMonthYearOrdering()
- {
- $ordering = array();
- if(is_int($day= strpos($this->pattern, 'd')))
- $ordering['day'] = $day;
- if(is_int($month= strpos($this->pattern, 'M')))
- $ordering['month'] = $month;
- if(is_int($year= strpos($this->pattern, 'yy')))
- $ordering['year'] = $year;
- asort($ordering);
- return array_keys($ordering);
- }
-
- /**
- * Gets the time stamp from string or integer.
- * @param string|int date to parse
- * @return array date info array
- */
- private function getDate($value)
- {
- if(!is_string($value))
- {
- $s = Prado::createComponent('System.Util.TDateTimeStamp');
- return $s->getDate($value);
- }
- $date = @strtotime($value);
- if($date < 0)
- throw new TInvalidDataValueException('invalid_date', $value);
- return @getdate($date);
- }
-
- /**
- * @return boolean true if the given value matches with the date pattern.
- */
- public function isValidDate($value)
- {
- if($value === null) {
- return false;
- } else {
- return $this->parse($value, false) !== null;
- }
- }
-
- /**
- * Parse the string according to the pattern.
- * @param string|int date string or integer to parse
- * @return int date time stamp
- * @throws TInvalidDataValueException if date string is malformed.
- */
- public function parse($value,$defaultToCurrentTime=true)
- {
- if(is_int($value) || is_float($value))
- return $value;
- else if(!is_string($value))
- throw new TInvalidDataValueException('date_to_parse_must_be_string', $value);
-
- if(empty($this->pattern)) return time();
-
- $date = time();
-
- if($this->length(trim($value)) < 1)
- return $defaultToCurrentTime ? $date : null;
-
- $pattern = $this->pattern;
-
- $i_val = 0;
- $i_format = 0;
- $pattern_length = $this->length($pattern);
- $c = '';
- $token='';
- $x=null; $y=null;
-
-
- if($defaultToCurrentTime)
- {
- $year = "{$date['year']}";
- $month = $date['mon'];
- $day = $date['mday'];
- }
- else
- {
- $year = null;
- $month = null;
- $day = null;
- }
-
- while ($i_format < $pattern_length)
- {
- $c = $this->charAt($pattern,$i_format);
- $token='';
- while ($this->charEqual($pattern, $i_format, $c)
- && ($i_format < $pattern_length))
- {
- $token .= $this->charAt($pattern, $i_format++);
- }
-
- if ($token=='yyyy' || $token=='yy' || $token=='y')
- {
- if ($token=='yyyy') { $x=4;$y=4; }
- if ($token=='yy') { $x=2;$y=2; }
- if ($token=='y') { $x=2;$y=4; }
- $year = $this->getInteger($value,$i_val,$x,$y);
- if($year === null)
- return null;
- //throw new TInvalidDataValueException('Invalid year', $value);
- $i_val += strlen($year);
- if(strlen($year) == 2)
- {
- $iYear = (int)$year;
- if($iYear > 70)
- $year = $iYear + 1900;
- else
- $year = $iYear + 2000;
- }
- $year = (int)$year;
- }
- elseif($token=='MM' || $token=='M')
- {
- $month=$this->getInteger($value,$i_val,
- $this->length($token),2);
- $iMonth = (int)$month;
- if($month === null || $iMonth < 1 || $iMonth > 12 )
- return null;
- //throw new TInvalidDataValueException('Invalid month', $value);
- $i_val += strlen($month);
- $month = $iMonth;
- }
- elseif ($token=='dd' || $token=='d')
- {
- $day = $this->getInteger($value,$i_val,
- $this->length($token), 2);
- $iDay = (int)$day;
- if($day === null || $iDay < 1 || $iDay >31)
- return null;
- //throw new TInvalidDataValueException('Invalid day', $value);
- $i_val += strlen($day);
- $day = $iDay;
- }
- else
- {
- if($this->substring($value, $i_val, $this->length($token)) != $token)
- return null;
- //throw new TInvalidDataValueException("Subpattern '{$this->pattern}' mismatch", $value);
- else
- $i_val += $this->length($token);
- }
- }
- if ($i_val != $this->length($value))
- return null;
- //throw new TInvalidDataValueException("Pattern '{$this->pattern}' mismatch", $value);
- if(!$defaultToCurrentTime && ($month === null || $day === null || $year === null))
- return null;
- else
- {
- if(empty($year)) {
- $year = date('Y');
- }
- $day = (int)$day <= 0 ? 1 : (int)$day;
- $month = (int)$month <= 0 ? 1 : (int)$month;
- $s = Prado::createComponent('System.Util.TDateTimeStamp');
- return $s->getTimeStamp(0, 0, 0, $month, $day, $year);
- }
- }
-
- /**
- * Calculate the length of a string, may be consider iconv_strlen?
- */
- private function length($string)
- {
- //use iconv_strlen or just strlen?
- return strlen($string);
- }
-
- /**
- * Get the char at a position.
- */
- private function charAt($string, $pos)
- {
- return $this->substring($string, $pos, 1);
- }
-
- /**
- * Gets a portion of a string, uses iconv_substr.
- */
- private function substring($string, $start, $length)
- {
- return iconv_substr($string, $start, $length);
- }
-
- /**
- * Returns true if char at position equals a particular char.
- */
- private function charEqual($string, $pos, $char)
- {
- return $this->charAt($string, $pos) == $char;
- }
-
- /**
- * Gets integer from part of a string, allows integers of any length.
- * @param string string to retrieve the integer from.
- * @param int starting position
- * @param int minimum integer length
- * @param int maximum integer length
- * @return string integer portion of the string, null otherwise
- */
- private function getInteger($str,$i,$minlength,$maxlength)
- {
- //match for digits backwards
- for ($x = $maxlength; $x >= $minlength; $x--)
- {
- $token= $this->substring($str, $i,$x);
- if ($this->length($token) < $minlength)
- return null;
- if (preg_match('/^\d+$/', $token))
- return $token;
- }
- return null;
- }
-}
-
-?>
+<?php
+/**
+ * TSimpleDateFormatter class file
+ *
+ * @author Wei Zhuo <weizhuo[at]gmail[dot]com>
+ * @link http://www.pradosoft.com/
+ * @copyright Copyright &copy; 2005-2012 PradoSoft
+ * @license http://www.pradosoft.com/license/
+ * @version $Id$
+ * @package System.Util
+ */
+
+/**
+ * TSimpleDateFormatter class.
+ *
+ * Formats and parses dates using the SimpleDateFormat pattern.
+ * This pattern is compatible with the I18N and java's SimpleDateFormatter.
+ * <code>
+ * Pattern | Description
+ * ----------------------------------------------------
+ * d | Day of month 1 to 31, no padding
+ * dd | Day of monath 01 to 31, zero leading
+ * M | Month digit 1 to 12, no padding
+ * MM | Month digit 01 to 12, zero leading
+ * yy | 2 year digit, e.g., 96, 05
+ * yyyy | 4 year digit, e.g., 2005
+ * ----------------------------------------------------
+ * </code>
+ *
+ * Usage example, to format a date
+ * <code>
+ * $formatter = new TSimpleDateFormatter("dd/MM/yyy");
+ * echo $formatter->format(time());
+ * </code>
+ *
+ * To parse the date string into a date timestamp.
+ * <code>
+ * $formatter = new TSimpleDateFormatter("d-M-yyy");
+ * echo $formatter->parse("24-6-2005");
+ * </code>
+ *
+ * @author Wei Zhuo <weizhuo[at]gmail[dot]com>
+ * @version $Id$
+ * @package System.Util
+ * @since 3.0
+ */
+class TSimpleDateFormatter
+{
+ /**
+ * Formatting pattern.
+ * @var string
+ */
+ private $pattern;
+
+ /**
+ * Charset, default is 'UTF-8'
+ * @var string
+ */
+ private $charset = 'UTF-8';
+
+ /**
+ * Constructor, create a new date time formatter.
+ * @param string formatting pattern.
+ * @param string pattern and value charset
+ */
+ public function __construct($pattern, $charset='UTF-8')
+ {
+ $this->setPattern($pattern);
+ $this->setCharset($charset);
+ }
+
+ /**
+ * @return string formatting pattern.
+ */
+ public function getPattern()
+ {
+ return $this->pattern;
+ }
+
+ /**
+ * @param string formatting pattern.
+ */
+ public function setPattern($pattern)
+ {
+ $this->pattern = $pattern;
+ }
+
+ /**
+ * @return string formatting charset.
+ */
+ public function getCharset()
+ {
+ return $this->charset;
+ }
+
+ /**
+ * @param string formatting charset.
+ */
+ public function setCharset($charset)
+ {
+ $this->charset = $charset;
+ }
+
+ /**
+ * Format the date according to the pattern.
+ * @param string|int the date to format, either integer or a string readable by strtotime.
+ * @return string formatted date.
+ */
+ public function format($value)
+ {
+ $date = $this->getDate($value);
+ $bits['yyyy'] = $date['year'];
+ $bits['yy'] = substr("{$date['year']}", -2);
+
+ $bits['MM'] = str_pad("{$date['mon']}", 2, '0', STR_PAD_LEFT);
+ $bits['M'] = $date['mon'];
+
+ $bits['dd'] = str_pad("{$date['mday']}", 2, '0', STR_PAD_LEFT);
+ $bits['d'] = $date['mday'];
+
+ $pattern = preg_replace('/M{3,4}/', 'MM', $this->pattern);
+ return str_replace(array_keys($bits), $bits, $pattern);
+ }
+
+ public function getMonthPattern()
+ {
+ if(is_int(strpos($this->pattern, 'MMMM')))
+ return 'MMMM';
+ if(is_int(strpos($this->pattern, 'MMM')))
+ return 'MMM';
+ if(is_int(strpos($this->pattern, 'MM')))
+ return 'MM';
+ if(is_int(strpos($this->pattern, 'M')))
+ return 'M';
+ return false;
+ }
+
+ public function getDayPattern()
+ {
+ if(is_int(strpos($this->pattern, 'dd')))
+ return 'dd';
+ if(is_int(strpos($this->pattern, 'd')))
+ return 'd';
+ return false;
+ }
+
+ public function getYearPattern()
+ {
+ if(is_int(strpos($this->pattern, 'yyyy')))
+ return 'yyyy';
+ if(is_int(strpos($this->pattern, 'yy')))
+ return 'yy';
+ return false;
+ }
+
+ public function getDayMonthYearOrdering()
+ {
+ $ordering = array();
+ if(is_int($day= strpos($this->pattern, 'd')))
+ $ordering['day'] = $day;
+ if(is_int($month= strpos($this->pattern, 'M')))
+ $ordering['month'] = $month;
+ if(is_int($year= strpos($this->pattern, 'yy')))
+ $ordering['year'] = $year;
+ asort($ordering);
+ return array_keys($ordering);
+ }
+
+ /**
+ * Gets the time stamp from string or integer.
+ * @param string|int date to parse
+ * @return array date info array
+ */
+ private function getDate($value)
+ {
+ if(!is_string($value))
+ {
+ $s = Prado::createComponent('System.Util.TDateTimeStamp');
+ return $s->getDate($value);
+ }
+ $date = @strtotime($value);
+ if($date < 0)
+ throw new TInvalidDataValueException('invalid_date', $value);
+ return @getdate($date);
+ }
+
+ /**
+ * @return boolean true if the given value matches with the date pattern.
+ */
+ public function isValidDate($value)
+ {
+ if($value === null) {
+ return false;
+ } else {
+ return $this->parse($value, false) !== null;
+ }
+ }
+
+ /**
+ * Parse the string according to the pattern.
+ * @param string|int date string or integer to parse
+ * @return int date time stamp
+ * @throws TInvalidDataValueException if date string is malformed.
+ */
+ public function parse($value,$defaultToCurrentTime=true)
+ {
+ if(is_int($value) || is_float($value))
+ return $value;
+ else if(!is_string($value))
+ throw new TInvalidDataValueException('date_to_parse_must_be_string', $value);
+
+ if(empty($this->pattern)) return time();
+
+ $date = time();
+
+ if($this->length(trim($value)) < 1)
+ return $defaultToCurrentTime ? $date : null;
+
+ $pattern = $this->pattern;
+
+ $i_val = 0;
+ $i_format = 0;
+ $pattern_length = $this->length($pattern);
+ $c = '';
+ $token='';
+ $x=null; $y=null;
+
+
+ if($defaultToCurrentTime)
+ {
+ $year = "{$date['year']}";
+ $month = $date['mon'];
+ $day = $date['mday'];
+ }
+ else
+ {
+ $year = null;
+ $month = null;
+ $day = null;
+ }
+
+ while ($i_format < $pattern_length)
+ {
+ $c = $this->charAt($pattern,$i_format);
+ $token='';
+ while ($this->charEqual($pattern, $i_format, $c)
+ && ($i_format < $pattern_length))
+ {
+ $token .= $this->charAt($pattern, $i_format++);
+ }
+
+ if ($token=='yyyy' || $token=='yy' || $token=='y')
+ {
+ if ($token=='yyyy') { $x=4;$y=4; }
+ if ($token=='yy') { $x=2;$y=2; }
+ if ($token=='y') { $x=2;$y=4; }
+ $year = $this->getInteger($value,$i_val,$x,$y);
+ if($year === null)
+ return null;
+ //throw new TInvalidDataValueException('Invalid year', $value);
+ $i_val += strlen($year);
+ if(strlen($year) == 2)
+ {
+ $iYear = (int)$year;
+ if($iYear > 70)
+ $year = $iYear + 1900;
+ else
+ $year = $iYear + 2000;
+ }
+ $year = (int)$year;
+ }
+ elseif($token=='MM' || $token=='M')
+ {
+ $month=$this->getInteger($value,$i_val,
+ $this->length($token),2);
+ $iMonth = (int)$month;
+ if($month === null || $iMonth < 1 || $iMonth > 12 )
+ return null;
+ //throw new TInvalidDataValueException('Invalid month', $value);
+ $i_val += strlen($month);
+ $month = $iMonth;
+ }
+ elseif ($token=='dd' || $token=='d')
+ {
+ $day = $this->getInteger($value,$i_val,
+ $this->length($token), 2);
+ $iDay = (int)$day;
+ if($day === null || $iDay < 1 || $iDay >31)
+ return null;
+ //throw new TInvalidDataValueException('Invalid day', $value);
+ $i_val += strlen($day);
+ $day = $iDay;
+ }
+ else
+ {
+ if($this->substring($value, $i_val, $this->length($token)) != $token)
+ return null;
+ //throw new TInvalidDataValueException("Subpattern '{$this->pattern}' mismatch", $value);
+ else
+ $i_val += $this->length($token);
+ }
+ }
+ if ($i_val != $this->length($value))
+ return null;
+ //throw new TInvalidDataValueException("Pattern '{$this->pattern}' mismatch", $value);
+ if(!$defaultToCurrentTime && ($month === null || $day === null || $year === null))
+ return null;
+ else
+ {
+ if(empty($year)) {
+ $year = date('Y');
+ }
+ $day = (int)$day <= 0 ? 1 : (int)$day;
+ $month = (int)$month <= 0 ? 1 : (int)$month;
+ $s = Prado::createComponent('System.Util.TDateTimeStamp');
+ return $s->getTimeStamp(0, 0, 0, $month, $day, $year);
+ }
+ }
+
+ /**
+ * Calculate the length of a string, may be consider iconv_strlen?
+ */
+ private function length($string)
+ {
+ //use iconv_strlen or just strlen?
+ return strlen($string);
+ }
+
+ /**
+ * Get the char at a position.
+ */
+ private function charAt($string, $pos)
+ {
+ return $this->substring($string, $pos, 1);
+ }
+
+ /**
+ * Gets a portion of a string, uses iconv_substr.
+ */
+ private function substring($string, $start, $length)
+ {
+ return iconv_substr($string, $start, $length);
+ }
+
+ /**
+ * Returns true if char at position equals a particular char.
+ */
+ private function charEqual($string, $pos, $char)
+ {
+ return $this->charAt($string, $pos) == $char;
+ }
+
+ /**
+ * Gets integer from part of a string, allows integers of any length.
+ * @param string string to retrieve the integer from.
+ * @param int starting position
+ * @param int minimum integer length
+ * @param int maximum integer length
+ * @return string integer portion of the string, null otherwise
+ */
+ private function getInteger($str,$i,$minlength,$maxlength)
+ {
+ //match for digits backwards
+ for ($x = $maxlength; $x >= $minlength; $x--)
+ {
+ $token= $this->substring($str, $i,$x);
+ if ($this->length($token) < $minlength)
+ return null;
+ if (preg_match('/^\d+$/', $token))
+ return $token;
+ }
+ return null;
+ }
+}
+
+?>
diff --git a/framework/Util/TVarDumper.php b/framework/Util/TVarDumper.php
index 0ea10e71..c2f712ac 100644
--- a/framework/Util/TVarDumper.php
+++ b/framework/Util/TVarDumper.php
@@ -1,128 +1,128 @@
-<?php
-/**
- * TVarDumper class file
- *
- * @author Qiang Xue <qiang.xue@gmail.com>
- * @link http://www.pradosoft.com/
+<?php
+/**
+ * TVarDumper class file
+ *
+ * @author Qiang Xue <qiang.xue@gmail.com>
+ * @link http://www.pradosoft.com/
* @copyright Copyright &copy; 2005-2012 PradoSoft
- * @license http://www.pradosoft.com/license/
- * @version $Id$
- * @package System.Util
- */
-
-/**
- * TVarDumper class.
- *
- * TVarDumper is intended to replace the buggy PHP function var_dump and print_r.
- * It can correctly identify the recursively referenced objects in a complex
- * object structure. It also has a recursive depth control to avoid indefinite
- * recursive display of some peculiar variables.
- *
- * TVarDumper can be used as follows,
- * <code>
- * echo TVarDumper::dump($var);
- * </code>
- *
- * @author Qiang Xue <qiang.xue@gmail.com>
- * @version $Id$
- * @package System.Util
- * @since 3.0
- */
-class TVarDumper
-{
- private static $_objects;
- private static $_output;
- private static $_depth;
-
- /**
- * Converts a variable into a string representation.
- * This method achieves the similar functionality as var_dump and print_r
- * but is more robust when handling complex objects such as PRADO controls.
- * @param mixed variable to be dumped
- * @param integer maximum depth that the dumper should go into the variable. Defaults to 10.
- * @return string the string representation of the variable
- */
- public static function dump($var,$depth=10,$highlight=false)
- {
- self::$_output='';
- self::$_objects=array();
- self::$_depth=$depth;
- self::dumpInternal($var,0);
- if($highlight)
- {
- $result=highlight_string("<?php\n".self::$_output,true);
- return preg_replace('/&lt;\\?php<br \\/>/','',$result,1);
- }
- else
- return self::$_output;
- }
-
- private static function dumpInternal($var,$level)
- {
- switch(gettype($var))
- {
- case 'boolean':
- self::$_output.=$var?'true':'false';
- break;
- case 'integer':
- self::$_output.="$var";
- break;
- case 'double':
- self::$_output.="$var";
- break;
- case 'string':
- self::$_output.="'$var'";
- break;
- case 'resource':
- self::$_output.='{resource}';
- break;
- case 'NULL':
- self::$_output.="null";
- break;
- case 'unknown type':
- self::$_output.='{unknown}';
- break;
- case 'array':
- if(self::$_depth<=$level)
- self::$_output.='array(...)';
- else if(empty($var))
- self::$_output.='array()';
- else
- {
- $keys=array_keys($var);
- $spaces=str_repeat(' ',$level*4);
- self::$_output.="array\n".$spaces.'(';
- foreach($keys as $key)
- {
- self::$_output.="\n".$spaces." [$key] => ";
- self::$_output.=self::dumpInternal($var[$key],$level+1);
- }
- self::$_output.="\n".$spaces.')';
- }
- break;
- case 'object':
- if(($id=array_search($var,self::$_objects,true))!==false)
- self::$_output.=get_class($var).'#'.($id+1).'(...)';
- else if(self::$_depth<=$level)
- self::$_output.=get_class($var).'(...)';
- else
- {
- $id=array_push(self::$_objects,$var);
- $className=get_class($var);
- $members=(array)$var;
- $keys=array_keys($members);
- $spaces=str_repeat(' ',$level*4);
- self::$_output.="$className#$id\n".$spaces.'(';
- foreach($keys as $key)
- {
- $keyDisplay=strtr(trim($key),array("\0"=>':'));
- self::$_output.="\n".$spaces." [$keyDisplay] => ";
- self::$_output.=self::dumpInternal($members[$key],$level+1);
- }
- self::$_output.="\n".$spaces.')';
- }
- break;
- }
- }
-}
-
+ * @license http://www.pradosoft.com/license/
+ * @version $Id$
+ * @package System.Util
+ */
+
+/**
+ * TVarDumper class.
+ *
+ * TVarDumper is intended to replace the buggy PHP function var_dump and print_r.
+ * It can correctly identify the recursively referenced objects in a complex
+ * object structure. It also has a recursive depth control to avoid indefinite
+ * recursive display of some peculiar variables.
+ *
+ * TVarDumper can be used as follows,
+ * <code>
+ * echo TVarDumper::dump($var);
+ * </code>
+ *
+ * @author Qiang Xue <qiang.xue@gmail.com>
+ * @version $Id$
+ * @package System.Util
+ * @since 3.0
+ */
+class TVarDumper
+{
+ private static $_objects;
+ private static $_output;
+ private static $_depth;
+
+ /**
+ * Converts a variable into a string representation.
+ * This method achieves the similar functionality as var_dump and print_r
+ * but is more robust when handling complex objects such as PRADO controls.
+ * @param mixed variable to be dumped
+ * @param integer maximum depth that the dumper should go into the variable. Defaults to 10.
+ * @return string the string representation of the variable
+ */
+ public static function dump($var,$depth=10,$highlight=false)
+ {
+ self::$_output='';
+ self::$_objects=array();
+ self::$_depth=$depth;
+ self::dumpInternal($var,0);
+ if($highlight)
+ {
+ $result=highlight_string("<?php\n".self::$_output,true);
+ return preg_replace('/&lt;\\?php<br \\/>/','',$result,1);
+ }
+ else
+ return self::$_output;
+ }
+
+ private static function dumpInternal($var,$level)
+ {
+ switch(gettype($var))
+ {
+ case 'boolean':
+ self::$_output.=$var?'true':'false';
+ break;
+ case 'integer':
+ self::$_output.="$var";
+ break;
+ case 'double':
+ self::$_output.="$var";
+ break;
+ case 'string':
+ self::$_output.="'$var'";
+ break;
+ case 'resource':
+ self::$_output.='{resource}';
+ break;
+ case 'NULL':
+ self::$_output.="null";
+ break;
+ case 'unknown type':
+ self::$_output.='{unknown}';
+ break;
+ case 'array':
+ if(self::$_depth<=$level)
+ self::$_output.='array(...)';
+ else if(empty($var))
+ self::$_output.='array()';
+ else
+ {
+ $keys=array_keys($var);
+ $spaces=str_repeat(' ',$level*4);
+ self::$_output.="array\n".$spaces.'(';
+ foreach($keys as $key)
+ {
+ self::$_output.="\n".$spaces." [$key] => ";
+ self::$_output.=self::dumpInternal($var[$key],$level+1);
+ }
+ self::$_output.="\n".$spaces.')';
+ }
+ break;
+ case 'object':
+ if(($id=array_search($var,self::$_objects,true))!==false)
+ self::$_output.=get_class($var).'#'.($id+1).'(...)';
+ else if(self::$_depth<=$level)
+ self::$_output.=get_class($var).'(...)';
+ else
+ {
+ $id=array_push(self::$_objects,$var);
+ $className=get_class($var);
+ $members=(array)$var;
+ $keys=array_keys($members);
+ $spaces=str_repeat(' ',$level*4);
+ self::$_output.="$className#$id\n".$spaces.'(';
+ foreach($keys as $key)
+ {
+ $keyDisplay=strtr(trim($key),array("\0"=>':'));
+ self::$_output.="\n".$spaces." [$keyDisplay] => ";
+ self::$_output.=self::dumpInternal($members[$key],$level+1);
+ }
+ self::$_output.="\n".$spaces.')';
+ }
+ break;
+ }
+ }
+}
+
diff --git a/framework/Web/Javascripts/JSMin.php b/framework/Web/Javascripts/JSMin.php
index 6ed24033..95beff38 100644
--- a/framework/Web/Javascripts/JSMin.php
+++ b/framework/Web/Javascripts/JSMin.php
@@ -1,290 +1,290 @@
-<?php
-/**
- * jsmin.php - PHP implementation of Douglas Crockford's JSMin.
- *
- * This is pretty much a direct port of jsmin.c to PHP with just a few
- * PHP-specific performance tweaks. Also, whereas jsmin.c reads from stdin and
- * outputs to stdout, this library accepts a string as input and returns another
- * string as output.
- *
- * PHP 5 or higher is required.
- *
- * Permission is hereby granted to use this version of the library under the
- * same terms as jsmin.c, which has the following license:
- *
- * --
- * Copyright (c) 2002 Douglas Crockford (www.crockford.com)
- *
- * Permission is hereby granted, free of charge, to any person obtaining a copy of
- * this software and associated documentation files (the "Software"), to deal in
- * the Software without restriction, including without limitation the rights to
- * use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies
- * of the Software, and to permit persons to whom the Software is furnished to do
- * so, subject to the following conditions:
- *
- * The above copyright notice and this permission notice shall be included in all
- * copies or substantial portions of the Software.
- *
- * The Software shall be used for Good, not Evil.
- *
- * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
- * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
- * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
- * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
- * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
- * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
- * SOFTWARE.
- * --
- *
- * @package JSMin
- * @author Ryan Grove <ryan@wonko.com>
- * @copyright 2002 Douglas Crockford <douglas@crockford.com> (jsmin.c)
- * @copyright 2008 Ryan Grove <ryan@wonko.com> (PHP port)
- * @license http://opensource.org/licenses/mit-license.php MIT License
- * @version 1.1.1 (2008-03-02)
- * @link http://code.google.com/p/jsmin-php/
- */
-
-class JSMin {
- const ORD_LF = 10;
- const ORD_SPACE = 32;
-
- protected $a = '';
- protected $b = '';
- protected $input = '';
- protected $inputIndex = 0;
- protected $inputLength = 0;
- protected $lookAhead = null;
- protected $output = '';
-
- // -- Public Static Methods --------------------------------------------------
-
- public static function minify($js) {
- $jsmin = new JSMin($js);
- return $jsmin->min();
- }
-
- // -- Public Instance Methods ------------------------------------------------
-
- public function __construct($input) {
- $this->input = str_replace("\r\n", "\n", $input);
- $this->inputLength = strlen($this->input);
- }
-
- // -- Protected Instance Methods ---------------------------------------------
-
- protected function action($d) {
- switch($d) {
- case 1:
- $this->output .= $this->a;
-
- case 2:
- $this->a = $this->b;
-
- if ($this->a === "'" || $this->a === '"') {
- for (;;) {
- $this->output .= $this->a;
- $this->a = $this->get();
-
- if ($this->a === $this->b) {
- break;
- }
-
- if (ord($this->a) <= self::ORD_LF) {
- throw new JSMinException('Unterminated string literal.');
- }
-
- if ($this->a === '\\') {
- $this->output .= $this->a;
- $this->a = $this->get();
- }
- }
- }
-
- case 3:
- $this->b = $this->next();
-
- if ($this->b === '/' && (
- $this->a === '(' || $this->a === ',' || $this->a === '=' ||
- $this->a === ':' || $this->a === '[' || $this->a === '!' ||
- $this->a === '&' || $this->a === '|' || $this->a === '?')) {
-
- $this->output .= $this->a . $this->b;
-
- for (;;) {
- $this->a = $this->get();
-
- if ($this->a === '/') {
- break;
- } elseif ($this->a === '\\') {
- $this->output .= $this->a;
- $this->a = $this->get();
- } elseif (ord($this->a) <= self::ORD_LF) {
- throw new JSMinException('Unterminated regular expression '.
- 'literal.');
- }
-
- $this->output .= $this->a;
- }
-
- $this->b = $this->next();
- }
- }
- }
-
- protected function get() {
- $c = $this->lookAhead;
- $this->lookAhead = null;
-
- if ($c === null) {
- if ($this->inputIndex < $this->inputLength) {
- $c = $this->input[$this->inputIndex];
- $this->inputIndex += 1;
- } else {
- $c = null;
- }
- }
-
- if ($c === "\r") {
- return "\n";
- }
-
- if ($c === null || $c === "\n" || ord($c) >= self::ORD_SPACE) {
- return $c;
- }
-
- return ' ';
- }
-
- protected function isAlphaNum($c) {
- return ord($c) > 126 || $c === '\\' || preg_match('/^[\w\$]$/', $c) === 1;
- }
-
- protected function min() {
- $this->a = "\n";
- $this->action(3);
-
- while ($this->a !== null) {
- switch ($this->a) {
- case ' ':
- if ($this->isAlphaNum($this->b)) {
- $this->action(1);
- } else {
- $this->action(2);
- }
- break;
-
- case "\n":
- switch ($this->b) {
- case '{':
- case '[':
- case '(':
- case '+':
- case '-':
- $this->action(1);
- break;
-
- case ' ':
- $this->action(3);
- break;
-
- default:
- if ($this->isAlphaNum($this->b)) {
- $this->action(1);
- }
- else {
- $this->action(2);
- }
- }
- break;
-
- default:
- switch ($this->b) {
- case ' ':
- if ($this->isAlphaNum($this->a)) {
- $this->action(1);
- break;
- }
-
- $this->action(3);
- break;
-
- case "\n":
- switch ($this->a) {
- case '}':
- case ']':
- case ')':
- case '+':
- case '-':
- case '"':
- case "'":
- $this->action(1);
- break;
-
- default:
- if ($this->isAlphaNum($this->a)) {
- $this->action(1);
- }
- else {
- $this->action(3);
- }
- }
- break;
-
- default:
- $this->action(1);
- break;
- }
- }
- }
-
- return $this->output;
- }
-
- protected function next() {
- $c = $this->get();
-
- if ($c === '/') {
- switch($this->peek()) {
- case '/':
- for (;;) {
- $c = $this->get();
-
- if (ord($c) <= self::ORD_LF) {
- return $c;
- }
- }
-
- case '*':
- $this->get();
-
- for (;;) {
- switch($this->get()) {
- case '*':
- if ($this->peek() === '/') {
- $this->get();
- return ' ';
- }
- break;
-
- case null:
- throw new JSMinException('Unterminated comment.');
- }
- }
-
- default:
- return $c;
- }
- }
-
- return $c;
- }
-
- protected function peek() {
- $this->lookAhead = $this->get();
- return $this->lookAhead;
- }
-}
-
-// -- Exceptions ---------------------------------------------------------------
-class JSMinException extends Exception {}
+<?php
+/**
+ * jsmin.php - PHP implementation of Douglas Crockford's JSMin.
+ *
+ * This is pretty much a direct port of jsmin.c to PHP with just a few
+ * PHP-specific performance tweaks. Also, whereas jsmin.c reads from stdin and
+ * outputs to stdout, this library accepts a string as input and returns another
+ * string as output.
+ *
+ * PHP 5 or higher is required.
+ *
+ * Permission is hereby granted to use this version of the library under the
+ * same terms as jsmin.c, which has the following license:
+ *
+ * --
+ * Copyright (c) 2002 Douglas Crockford (www.crockford.com)
+ *
+ * Permission is hereby granted, free of charge, to any person obtaining a copy of
+ * this software and associated documentation files (the "Software"), to deal in
+ * the Software without restriction, including without limitation the rights to
+ * use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies
+ * of the Software, and to permit persons to whom the Software is furnished to do
+ * so, subject to the following conditions:
+ *
+ * The above copyright notice and this permission notice shall be included in all
+ * copies or substantial portions of the Software.
+ *
+ * The Software shall be used for Good, not Evil.
+ *
+ * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
+ * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
+ * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
+ * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
+ * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
+ * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
+ * SOFTWARE.
+ * --
+ *
+ * @package JSMin
+ * @author Ryan Grove <ryan@wonko.com>
+ * @copyright 2002 Douglas Crockford <douglas@crockford.com> (jsmin.c)
+ * @copyright 2008 Ryan Grove <ryan@wonko.com> (PHP port)
+ * @license http://opensource.org/licenses/mit-license.php MIT License
+ * @version 1.1.1 (2008-03-02)
+ * @link http://code.google.com/p/jsmin-php/
+ */
+
+class JSMin {
+ const ORD_LF = 10;
+ const ORD_SPACE = 32;
+
+ protected $a = '';
+ protected $b = '';
+ protected $input = '';
+ protected $inputIndex = 0;
+ protected $inputLength = 0;
+ protected $lookAhead = null;
+ protected $output = '';
+
+ // -- Public Static Methods --------------------------------------------------
+
+ public static function minify($js) {
+ $jsmin = new JSMin($js);
+ return $jsmin->min();
+ }
+
+ // -- Public Instance Methods ------------------------------------------------
+
+ public function __construct($input) {
+ $this->input = str_replace("\r\n", "\n", $input);
+ $this->inputLength = strlen($this->input);
+ }
+
+ // -- Protected Instance Methods ---------------------------------------------
+
+ protected function action($d) {
+ switch($d) {
+ case 1:
+ $this->output .= $this->a;
+
+ case 2:
+ $this->a = $this->b;
+
+ if ($this->a === "'" || $this->a === '"') {
+ for (;;) {
+ $this->output .= $this->a;
+ $this->a = $this->get();
+
+ if ($this->a === $this->b) {
+ break;
+ }
+
+ if (ord($this->a) <= self::ORD_LF) {
+ throw new JSMinException('Unterminated string literal.');
+ }
+
+ if ($this->a === '\\') {
+ $this->output .= $this->a;
+ $this->a = $this->get();
+ }
+ }
+ }
+
+ case 3:
+ $this->b = $this->next();
+
+ if ($this->b === '/' && (
+ $this->a === '(' || $this->a === ',' || $this->a === '=' ||
+ $this->a === ':' || $this->a === '[' || $this->a === '!' ||
+ $this->a === '&' || $this->a === '|' || $this->a === '?')) {
+
+ $this->output .= $this->a . $this->b;
+
+ for (;;) {
+ $this->a = $this->get();
+
+ if ($this->a === '/') {
+ break;
+ } elseif ($this->a === '\\') {
+ $this->output .= $this->a;
+ $this->a = $this->get();
+ } elseif (ord($this->a) <= self::ORD_LF) {
+ throw new JSMinException('Unterminated regular expression '.
+ 'literal.');
+ }
+
+ $this->output .= $this->a;
+ }
+
+ $this->b = $this->next();
+ }
+ }
+ }
+
+ protected function get() {
+ $c = $this->lookAhead;
+ $this->lookAhead = null;
+
+ if ($c === null) {
+ if ($this->inputIndex < $this->inputLength) {
+ $c = $this->input[$this->inputIndex];
+ $this->inputIndex += 1;
+ } else {
+ $c = null;
+ }
+ }
+
+ if ($c === "\r") {
+ return "\n";
+ }
+
+ if ($c === null || $c === "\n" || ord($c) >= self::ORD_SPACE) {
+ return $c;
+ }
+
+ return ' ';
+ }
+
+ protected function isAlphaNum($c) {
+ return ord($c) > 126 || $c === '\\' || preg_match('/^[\w\$]$/', $c) === 1;
+ }
+
+ protected function min() {
+ $this->a = "\n";
+ $this->action(3);
+
+ while ($this->a !== null) {
+ switch ($this->a) {
+ case ' ':
+ if ($this->isAlphaNum($this->b)) {
+ $this->action(1);
+ } else {
+ $this->action(2);
+ }
+ break;
+
+ case "\n":
+ switch ($this->b) {
+ case '{':
+ case '[':
+ case '(':
+ case '+':
+ case '-':
+ $this->action(1);
+ break;
+
+ case ' ':
+ $this->action(3);
+ break;
+
+ default:
+ if ($this->isAlphaNum($this->b)) {
+ $this->action(1);
+ }
+ else {
+ $this->action(2);
+ }
+ }
+ break;
+
+ default:
+ switch ($this->b) {
+ case ' ':
+ if ($this->isAlphaNum($this->a)) {
+ $this->action(1);
+ break;
+ }
+
+ $this->action(3);
+ break;
+
+ case "\n":
+ switch ($this->a) {
+ case '}':
+ case ']':
+ case ')':
+ case '+':
+ case '-':
+ case '"':
+ case "'":
+ $this->action(1);
+ break;
+
+ default:
+ if ($this->isAlphaNum($this->a)) {
+ $this->action(1);
+ }
+ else {
+ $this->action(3);
+ }
+ }
+ break;
+
+ default:
+ $this->action(1);
+ break;
+ }
+ }
+ }
+
+ return $this->output;
+ }
+
+ protected function next() {
+ $c = $this->get();
+
+ if ($c === '/') {
+ switch($this->peek()) {
+ case '/':
+ for (;;) {
+ $c = $this->get();
+
+ if (ord($c) <= self::ORD_LF) {
+ return $c;
+ }
+ }
+
+ case '*':
+ $this->get();
+
+ for (;;) {
+ switch($this->get()) {
+ case '*':
+ if ($this->peek() === '/') {
+ $this->get();
+ return ' ';
+ }
+ break;
+
+ case null:
+ throw new JSMinException('Unterminated comment.');
+ }
+ }
+
+ default:
+ return $c;
+ }
+ }
+
+ return $c;
+ }
+
+ protected function peek() {
+ $this->lookAhead = $this->get();
+ return $this->lookAhead;
+ }
+}
+
+// -- Exceptions ---------------------------------------------------------------
+class JSMinException extends Exception {}
diff --git a/framework/Web/Javascripts/TJavaScript.php b/framework/Web/Javascripts/TJavaScript.php
index 9e5be75b..3d062e5c 100644
--- a/framework/Web/Javascripts/TJavaScript.php
+++ b/framework/Web/Javascripts/TJavaScript.php
@@ -1,283 +1,283 @@
-<?php
-/**
- * TJavaScript class file
- *
- * @author Wei Zhuo<weizhuo[at]gmail[dot]com>
- * @link http://www.pradosoft.com/
- * @copyright Copyright &copy; 2005-2012 PradoSoft
- * @license http://www.pradosoft.com/license/
- * @version $Id$
- * @package System.Web.Javascripts
- */
-
-/**
- * TJavaScript class.
- *
- * TJavaScript is a utility class containing commonly-used javascript-related
- * functions.
- *
- * @author Wei Zhuo<weizhuo[at]gmail[dot]com>
- * @version $Id$
- * @package System.Web.Javascripts
- * @since 3.0
- */
-class TJavaScript
-{
- /**
- * Renders a list of javascript files
- * @param array URLs to the javascript files
- * @return string rendering result
- */
- public static function renderScriptFiles($files)
- {
- $str='';
- foreach($files as $file)
- $str.= self::renderScriptFile($file);
- return $str;
- }
-
- /**
- * Renders a javascript file
- * @param string URL to the javascript file
- * @return string rendering result
- */
- public static function renderScriptFile($file)
- {
- return '<script type="text/javascript" src="'.THttpUtility::htmlEncode($file)."\"></script>\n";
- }
-
- /**
- * Renders a list of javascript blocks
- * @param array javascript blocks
- * @return string rendering result
- */
- public static function renderScriptBlocks($scripts)
- {
- if(count($scripts))
- return "<script type=\"text/javascript\">\n/*<![CDATA[*/\n".implode("\n",$scripts)."\n/*]]>*/\n</script>\n";
- else
- return '';
- }
-
- /**
- * Renders javascript block
- * @param string javascript block
- * @return string rendering result
- */
- public static function renderScriptBlock($script)
- {
- return "<script type=\"text/javascript\">\n/*<![CDATA[*/\n{$script}\n/*]]>*/\n</script>\n";
- }
-
- /**
- * Quotes a javascript string.
- * After processing, the string is safely enclosed within a pair of
- * quotation marks and can serve as a javascript string.
- * @param string string to be quoted
- * @return string the quoted string
- */
- public static function quoteString($js)
- {
- return self::jsonEncode($js,JSON_HEX_QUOT | JSON_HEX_APOS | JSON_HEX_TAG);
- }
-
- /**
- * @return Marks a string as a javascript function. Once marke, the string is considered as a
- * raw javascript function that is not supposed to be encoded by {@link encode}
- */
- public static function quoteJsLiteral($js)
- {
- if($js instanceof TJavaScriptLiteral)
- return $js;
- else
- return new TJavaScriptLiteral($js);
- }
-
- /**
- * Deprecated, use {@link quoteJsLiteral} instead
- */
- public static function quoteFunction($js)
- {
- return self::quoteJsLiteral($js);
- }
-
- /**
- * @return boolean true if the parameter is marked as a javascript function, i.e. if it's considered as a
- * raw javascript function that is not supposed to be encoded by {@link encode}
- */
- public static function isJsLiteral($js)
- {
- return ($js instanceof TJavaScriptLiteral);
- }
-
- /**
- * Deprecated, use {@link isJsLiteral} instead
- */
- public static function isFunction($js)
- {
- return self::isJsLiteral($js);
- }
-
- /**
- * Encodes a PHP variable into javascript representation.
- *
- * Example:
- * <code>
- * $options['onLoading'] = "doit";
- * $options['onComplete'] = "more";
- * echo TJavaScript::encode($options);
- * //expects the following javascript code
- * // {'onLoading':'doit','onComplete':'more'}
- * </code>
- *
- * For higher complexity data structures use {@link jsonEncode} and {@link jsonDecode}
- * to serialize and unserialize.
- *
- * @param mixed PHP variable to be encoded
- * @param boolean whether the output is a map or a list.
- * @since 3.1.5
- * @param boolean wether to encode empty strings too. Default to false for BC.
- * @return string the encoded string
- */
- public static function encode($value,$toMap=true,$encodeEmptyStrings=false)
- {
- if(is_string($value))
- return self::quoteString($value);
- else if(is_bool($value))
- return $value?'true':'false';
- else if(is_array($value))
- {
- $results='';
- if(($n=count($value))>0 && array_keys($value)!==range(0,$n-1))
- {
- foreach($value as $k=>$v)
- {
- if($v!=='' || $encodeEmptyStrings)
- {
- if($results!=='')
- $results.=',';
- $results.="'$k':".self::encode($v,$toMap,$encodeEmptyStrings);
- }
- }
- return '{'.$results.'}';
- }
- else
- {
- foreach($value as $v)
- {
- if($v!=='' || $encodeEmptyStrings)
- {
- if($results!=='')
- $results.=',';
- $results.=self::encode($v,$toMap, $encodeEmptyStrings);
- }
- }
- return '['.$results.']';
- }
- }
- else if(is_integer($value))
- return "$value";
- else if(is_float($value))
- {
- switch($value)
- {
- case -INF:
- return 'Number.NEGATIVE_INFINITY';
- break;
- case INF:
- return 'Number.POSITIVE_INFINITY';
- break;
- default:
- $locale=localeConv();
- if($locale['decimal_point']=='.')
- return "$value";
- else
- return str_replace($locale['decimal_point'], '.', "$value");
- break;
- }
- }
- else if(is_object($value))
- if ($value instanceof TJavaScriptLiteral)
- return $value->toJavaScriptLiteral();
- else
- return self::encode(get_object_vars($value),$toMap);
- else if($value===null)
- return 'null';
- else
- return '';
- }
-
- /**
- * Encodes a PHP variable into javascript string.
- * This method invokes json_encode to perform the encoding.
- * @param mixed variable to be encoded
- * @return string encoded string
- */
- public static function jsonEncode($value, $options = 0)
- {
- if (is_string($value) &&
- ($g=Prado::getApplication()->getGlobalization(false))!==null &&
- strtoupper($enc=$g->getCharset())!='UTF-8')
- $value=iconv($enc, 'UTF-8', $value);
- $s = json_encode($value,$options);
- self::checkJsonError();
- return $s;
- }
-
- /**
- * Decodes a javascript string into PHP variable.
- * This method invokes json_decode to perform the decoding.
- * @param string string to be decoded
- * @param bool whether to convert returned objects to associative arrays
- * @param int recursion depth
- * @return mixed decoded variable
- */
- public static function jsonDecode($value, $assoc = false, $depth = 512)
- {
- $s= json_decode($value, $assoc, $depth);
- self::checkJsonError();
- return $s;
- }
-
- private static function checkJsonError()
- {
- switch ($err = json_last_error())
- {
- case JSON_ERROR_NONE:
- return;
- break;
- case JSON_ERROR_DEPTH:
- $msg = 'Maximum stack depth exceeded';
- break;
- case JSON_ERROR_STATE_MISMATCH:
- $msg = 'Underflow or the modes mismatch';
- break;
- case JSON_ERROR_CTRL_CHAR:
- $msg = 'Unexpected control character found';
- break;
- case JSON_ERROR_SYNTAX:
- $msg = 'Syntax error, malformed JSON';
- break;
- case JSON_ERROR_UTF8:
- $msg = 'Malformed UTF-8 characters, possibly incorrectly encoded';
- break;
- default:
- $msg = 'Unknown error';
- break;
- }
- throw new Exception("JSON error ($err): $msg");
- }
-
- /**
- * Minimize the size of a javascript script.
- * This method is based on Douglas Crockford's JSMin.
- * @param string code that you want to minimzie
- * @return minimized version of the code
- */
- public static function JSMin($code)
- {
- Prado::using('System.Web.Javascripts.JSMin');
- return JSMin::minify($code);
- }
-}
-
+<?php
+/**
+ * TJavaScript class file
+ *
+ * @author Wei Zhuo<weizhuo[at]gmail[dot]com>
+ * @link http://www.pradosoft.com/
+ * @copyright Copyright &copy; 2005-2012 PradoSoft
+ * @license http://www.pradosoft.com/license/
+ * @version $Id$
+ * @package System.Web.Javascripts
+ */
+
+/**
+ * TJavaScript class.
+ *
+ * TJavaScript is a utility class containing commonly-used javascript-related
+ * functions.
+ *
+ * @author Wei Zhuo<weizhuo[at]gmail[dot]com>
+ * @version $Id$
+ * @package System.Web.Javascripts
+ * @since 3.0
+ */
+class TJavaScript
+{
+ /**
+ * Renders a list of javascript files
+ * @param array URLs to the javascript files
+ * @return string rendering result
+ */
+ public static function renderScriptFiles($files)
+ {
+ $str='';
+ foreach($files as $file)
+ $str.= self::renderScriptFile($file);
+ return $str;
+ }
+
+ /**
+ * Renders a javascript file
+ * @param string URL to the javascript file
+ * @return string rendering result
+ */
+ public static function renderScriptFile($file)
+ {
+ return '<script type="text/javascript" src="'.THttpUtility::htmlEncode($file)."\"></script>\n";
+ }
+
+ /**
+ * Renders a list of javascript blocks
+ * @param array javascript blocks
+ * @return string rendering result
+ */
+ public static function renderScriptBlocks($scripts)
+ {
+ if(count($scripts))
+ return "<script type=\"text/javascript\">\n/*<![CDATA[*/\n".implode("\n",$scripts)."\n/*]]>*/\n</script>\n";
+ else
+ return '';
+ }
+
+ /**
+ * Renders javascript block
+ * @param string javascript block
+ * @return string rendering result
+ */
+ public static function renderScriptBlock($script)
+ {
+ return "<script type=\"text/javascript\">\n/*<![CDATA[*/\n{$script}\n/*]]>*/\n</script>\n";
+ }
+
+ /**
+ * Quotes a javascript string.
+ * After processing, the string is safely enclosed within a pair of
+ * quotation marks and can serve as a javascript string.
+ * @param string string to be quoted
+ * @return string the quoted string
+ */
+ public static function quoteString($js)
+ {
+ return self::jsonEncode($js,JSON_HEX_QUOT | JSON_HEX_APOS | JSON_HEX_TAG);
+ }
+
+ /**
+ * @return Marks a string as a javascript function. Once marke, the string is considered as a
+ * raw javascript function that is not supposed to be encoded by {@link encode}
+ */
+ public static function quoteJsLiteral($js)
+ {
+ if($js instanceof TJavaScriptLiteral)
+ return $js;
+ else
+ return new TJavaScriptLiteral($js);
+ }
+
+ /**
+ * Deprecated, use {@link quoteJsLiteral} instead
+ */
+ public static function quoteFunction($js)
+ {
+ return self::quoteJsLiteral($js);
+ }
+
+ /**
+ * @return boolean true if the parameter is marked as a javascript function, i.e. if it's considered as a
+ * raw javascript function that is not supposed to be encoded by {@link encode}
+ */
+ public static function isJsLiteral($js)
+ {
+ return ($js instanceof TJavaScriptLiteral);
+ }
+
+ /**
+ * Deprecated, use {@link isJsLiteral} instead
+ */
+ public static function isFunction($js)
+ {
+ return self::isJsLiteral($js);
+ }
+
+ /**
+ * Encodes a PHP variable into javascript representation.
+ *
+ * Example:
+ * <code>
+ * $options['onLoading'] = "doit";
+ * $options['onComplete'] = "more";
+ * echo TJavaScript::encode($options);
+ * //expects the following javascript code
+ * // {'onLoading':'doit','onComplete':'more'}
+ * </code>
+ *
+ * For higher complexity data structures use {@link jsonEncode} and {@link jsonDecode}
+ * to serialize and unserialize.
+ *
+ * @param mixed PHP variable to be encoded
+ * @param boolean whether the output is a map or a list.
+ * @since 3.1.5
+ * @param boolean wether to encode empty strings too. Default to false for BC.
+ * @return string the encoded string
+ */
+ public static function encode($value,$toMap=true,$encodeEmptyStrings=false)
+ {
+ if(is_string($value))
+ return self::quoteString($value);
+ else if(is_bool($value))
+ return $value?'true':'false';
+ else if(is_array($value))
+ {
+ $results='';
+ if(($n=count($value))>0 && array_keys($value)!==range(0,$n-1))
+ {
+ foreach($value as $k=>$v)
+ {
+ if($v!=='' || $encodeEmptyStrings)
+ {
+ if($results!=='')
+ $results.=',';
+ $results.="'$k':".self::encode($v,$toMap,$encodeEmptyStrings);
+ }
+ }
+ return '{'.$results.'}';
+ }
+ else
+ {
+ foreach($value as $v)
+ {
+ if($v!=='' || $encodeEmptyStrings)
+ {
+ if($results!=='')
+ $results.=',';
+ $results.=self::encode($v,$toMap, $encodeEmptyStrings);
+ }
+ }
+ return '['.$results.']';
+ }
+ }
+ else if(is_integer($value))
+ return "$value";
+ else if(is_float($value))
+ {
+ switch($value)
+ {
+ case -INF:
+ return 'Number.NEGATIVE_INFINITY';
+ break;
+ case INF:
+ return 'Number.POSITIVE_INFINITY';
+ break;
+ default:
+ $locale=localeConv();
+ if($locale['decimal_point']=='.')
+ return "$value";
+ else
+ return str_replace($locale['decimal_point'], '.', "$value");
+ break;
+ }
+ }
+ else if(is_object($value))
+ if ($value instanceof TJavaScriptLiteral)
+ return $value->toJavaScriptLiteral();
+ else
+ return self::encode(get_object_vars($value),$toMap);
+ else if($value===null)
+ return 'null';
+ else
+ return '';
+ }
+
+ /**
+ * Encodes a PHP variable into javascript string.
+ * This method invokes json_encode to perform the encoding.
+ * @param mixed variable to be encoded
+ * @return string encoded string
+ */
+ public static function jsonEncode($value, $options = 0)
+ {
+ if (is_string($value) &&
+ ($g=Prado::getApplication()->getGlobalization(false))!==null &&
+ strtoupper($enc=$g->getCharset())!='UTF-8')
+ $value=iconv($enc, 'UTF-8', $value);
+ $s = json_encode($value,$options);
+ self::checkJsonError();
+ return $s;
+ }
+
+ /**
+ * Decodes a javascript string into PHP variable.
+ * This method invokes json_decode to perform the decoding.
+ * @param string string to be decoded
+ * @param bool whether to convert returned objects to associative arrays
+ * @param int recursion depth
+ * @return mixed decoded variable
+ */
+ public static function jsonDecode($value, $assoc = false, $depth = 512)
+ {
+ $s= json_decode($value, $assoc, $depth);
+ self::checkJsonError();
+ return $s;
+ }
+
+ private static function checkJsonError()
+ {
+ switch ($err = json_last_error())
+ {
+ case JSON_ERROR_NONE:
+ return;
+ break;
+ case JSON_ERROR_DEPTH:
+ $msg = 'Maximum stack depth exceeded';
+ break;
+ case JSON_ERROR_STATE_MISMATCH:
+ $msg = 'Underflow or the modes mismatch';
+ break;
+ case JSON_ERROR_CTRL_CHAR:
+ $msg = 'Unexpected control character found';
+ break;
+ case JSON_ERROR_SYNTAX:
+ $msg = 'Syntax error, malformed JSON';
+ break;
+ case JSON_ERROR_UTF8:
+ $msg = 'Malformed UTF-8 characters, possibly incorrectly encoded';
+ break;
+ default:
+ $msg = 'Unknown error';
+ break;
+ }
+ throw new Exception("JSON error ($err): $msg");
+ }
+
+ /**
+ * Minimize the size of a javascript script.
+ * This method is based on Douglas Crockford's JSMin.
+ * @param string code that you want to minimzie
+ * @return minimized version of the code
+ */
+ public static function JSMin($code)
+ {
+ Prado::using('System.Web.Javascripts.JSMin');
+ return JSMin::minify($code);
+ }
+}
+
diff --git a/framework/Web/Javascripts/packages.php b/framework/Web/Javascripts/packages.php
index 316716d6..4e4d3994 100644
--- a/framework/Web/Javascripts/packages.php
+++ b/framework/Web/Javascripts/packages.php
@@ -1,121 +1,121 @@
-<?php
-
-//$Id$
-
-// To make future upgrades easier
-if (!defined('PROTOTYPE_DIR')) define ('PROTOTYPE_DIR', 'prototype-1.7');
-if (!defined('SCRIPTACULOUS_DIR')) define ('SCRIPTACULOUS_DIR', 'scriptaculous-1.9.0');
-
-//package names and its contents (files relative to the current directory)
-$packages = array(
- 'prototype' => array(
- PROTOTYPE_DIR.'/prototype.js',
- SCRIPTACULOUS_DIR.'/builder.js',
- ),
- 'prado' => array(
- 'prado/prado.js',
- 'prado/scriptaculous-adapter.js',
- 'prado/controls/controls.js',
- SCRIPTACULOUS_DIR.'/effects.js'
- ),
-
- 'effects' => array(
- SCRIPTACULOUS_DIR.'/effects.js'
- ),
-
- 'logger' => array(
- 'prado/logger/logger.js',
- ),
-
- 'validator' => array(
- 'prado/validator/validation3.js'
- ),
-
- 'datepicker' => array(
- 'prado/datepicker/datepicker.js'
- ),
-
- 'colorpicker' => array(
- 'prado/colorpicker/colorpicker.js'
- ),
-
- 'ajax' => array(
- SCRIPTACULOUS_DIR.'/controls.js',
- 'prado/activecontrols/json2.js',
- 'prado/activecontrols/ajax3.js',
- 'prado/activecontrols/activecontrols3.js',
- ),
-
- 'dragdrop'=>array(
- SCRIPTACULOUS_DIR.'/dragdrop.js',
- 'prado/activecontrols/dragdrop.js'
- ),
-
- 'dragdropextra'=>array(
- 'prado/activecontrols/dragdropextra.js',
- ),
-
- 'slider'=>array(
- 'prado/controls/slider.js'
- ),
-
- 'keyboard'=>array(
- 'prado/controls/keyboard.js'
- ),
-
- 'tabpanel'=>array(
- 'prado/controls/tabpanel.js'
- ),
-
- 'activedatepicker' => array(
- 'prado/activecontrols/activedatepicker.js'
- ),
-
- 'activefileupload' => array(
- 'prado/activefileupload/activefileupload.js'
- ),
-
- 'accordion'=>array(
- 'prado/controls/accordion.js'
- ),
-
- 'htmlarea'=>array(
- 'prado/controls/htmlarea.js'
- ),
-
- 'ratings' => array(
- 'prado/ratings/ratings.js',
- ),
-
- 'inlineeditor' => array(
- 'prado/activecontrols/inlineeditor.js'
- ),
-
-);
-
-
-//package names and their dependencies
-$dependencies = array(
- 'prototype' => array('prototype'),
- 'prado' => array('prototype', 'prado'),
- 'effects' => array('prototype', 'prado', 'effects'),
- 'validator' => array('prototype', 'prado', 'validator'),
- 'logger' => array('prototype', 'prado', 'logger'),
- 'datepicker' => array('prototype', 'prado', 'datepicker'),
- 'colorpicker' => array('prototype', 'prado', 'colorpicker'),
- 'ajax' => array('prototype', 'prado', 'effects', 'ajax'),
- 'dragdrop' => array('prototype', 'prado', 'effects', 'ajax', 'dragdrop'),
- 'slider' => array('prototype', 'prado', 'slider'),
- 'keyboard' => array('prototype', 'prado', 'keyboard'),
- 'tabpanel' => array('prototype', 'prado', 'tabpanel'),
- 'activedatepicker' => array('prototype', 'prado', 'datepicker', 'ajax', 'activedatepicker'),
- 'activefileupload' => array('prototype', 'prado', 'effects', 'ajax', 'activefileupload'),
- 'dragdropextra' => array('prototype', 'prado', 'effects', 'ajax', 'dragdrop','dragdropextra'),
- 'accordion' => array('prototype', 'prado', 'effects', 'accordion'),
- 'htmlarea' => array('prototype', 'prado', 'htmlarea'),
- 'ratings' => array('prototype', 'prado', 'effects', 'ajax', 'ratings'),
- 'inlineeditor' => array('prototype', 'prado', 'effects', 'ajax', 'inlineeditor'),
-);
-
-return array($packages, $dependencies);
-
+<?php
+
+//$Id$
+
+// To make future upgrades easier
+if (!defined('PROTOTYPE_DIR')) define ('PROTOTYPE_DIR', 'prototype-1.7');
+if (!defined('SCRIPTACULOUS_DIR')) define ('SCRIPTACULOUS_DIR', 'scriptaculous-1.9.0');
+
+//package names and its contents (files relative to the current directory)
+$packages = array(
+ 'prototype' => array(
+ PROTOTYPE_DIR.'/prototype.js',
+ SCRIPTACULOUS_DIR.'/builder.js',
+ ),
+ 'prado' => array(
+ 'prado/prado.js',
+ 'prado/scriptaculous-adapter.js',
+ 'prado/controls/controls.js',
+ SCRIPTACULOUS_DIR.'/effects.js'
+ ),
+
+ 'effects' => array(
+ SCRIPTACULOUS_DIR.'/effects.js'
+ ),
+
+ 'logger' => array(
+ 'prado/logger/logger.js',
+ ),
+
+ 'validator' => array(
+ 'prado/validator/validation3.js'
+ ),
+
+ 'datepicker' => array(
+ 'prado/datepicker/datepicker.js'
+ ),
+
+ 'colorpicker' => array(
+ 'prado/colorpicker/colorpicker.js'
+ ),
+
+ 'ajax' => array(
+ SCRIPTACULOUS_DIR.'/controls.js',
+ 'prado/activecontrols/json2.js',
+ 'prado/activecontrols/ajax3.js',
+ 'prado/activecontrols/activecontrols3.js',
+ ),
+
+ 'dragdrop'=>array(
+ SCRIPTACULOUS_DIR.'/dragdrop.js',
+ 'prado/activecontrols/dragdrop.js'
+ ),
+
+ 'dragdropextra'=>array(
+ 'prado/activecontrols/dragdropextra.js',
+ ),
+
+ 'slider'=>array(
+ 'prado/controls/slider.js'
+ ),
+
+ 'keyboard'=>array(
+ 'prado/controls/keyboard.js'
+ ),
+
+ 'tabpanel'=>array(
+ 'prado/controls/tabpanel.js'
+ ),
+
+ 'activedatepicker' => array(
+ 'prado/activecontrols/activedatepicker.js'
+ ),
+
+ 'activefileupload' => array(
+ 'prado/activefileupload/activefileupload.js'
+ ),
+
+ 'accordion'=>array(
+ 'prado/controls/accordion.js'
+ ),
+
+ 'htmlarea'=>array(
+ 'prado/controls/htmlarea.js'
+ ),
+
+ 'ratings' => array(
+ 'prado/ratings/ratings.js',
+ ),
+
+ 'inlineeditor' => array(
+ 'prado/activecontrols/inlineeditor.js'
+ ),
+
+);
+
+
+//package names and their dependencies
+$dependencies = array(
+ 'prototype' => array('prototype'),
+ 'prado' => array('prototype', 'prado'),
+ 'effects' => array('prototype', 'prado', 'effects'),
+ 'validator' => array('prototype', 'prado', 'validator'),
+ 'logger' => array('prototype', 'prado', 'logger'),
+ 'datepicker' => array('prototype', 'prado', 'datepicker'),
+ 'colorpicker' => array('prototype', 'prado', 'colorpicker'),
+ 'ajax' => array('prototype', 'prado', 'effects', 'ajax'),
+ 'dragdrop' => array('prototype', 'prado', 'effects', 'ajax', 'dragdrop'),
+ 'slider' => array('prototype', 'prado', 'slider'),
+ 'keyboard' => array('prototype', 'prado', 'keyboard'),
+ 'tabpanel' => array('prototype', 'prado', 'tabpanel'),
+ 'activedatepicker' => array('prototype', 'prado', 'datepicker', 'ajax', 'activedatepicker'),
+ 'activefileupload' => array('prototype', 'prado', 'effects', 'ajax', 'activefileupload'),
+ 'dragdropextra' => array('prototype', 'prado', 'effects', 'ajax', 'dragdrop','dragdropextra'),
+ 'accordion' => array('prototype', 'prado', 'effects', 'accordion'),
+ 'htmlarea' => array('prototype', 'prado', 'htmlarea'),
+ 'ratings' => array('prototype', 'prado', 'effects', 'ajax', 'ratings'),
+ 'inlineeditor' => array('prototype', 'prado', 'effects', 'ajax', 'inlineeditor'),
+);
+
+return array($packages, $dependencies);
+
diff --git a/framework/Web/Javascripts/source/prado/activecontrols/activecontrols3.js b/framework/Web/Javascripts/source/prado/activecontrols/activecontrols3.js
index 7dbdbe2a..3e6fe5b7 100644
--- a/framework/Web/Javascripts/source/prado/activecontrols/activecontrols3.js
+++ b/framework/Web/Javascripts/source/prado/activecontrols/activecontrols3.js
@@ -1,410 +1,410 @@
-/**
- * Generic postback control.
- */
-Prado.WebUI.CallbackControl = Class.extend(Prado.WebUI.PostBackControl,
-{
- onPostBack : function(event, options)
- {
- var request = new Prado.CallbackRequest(options.EventTarget, options);
- request.dispatch();
- Event.stop(event);
- }
-});
-
-/**
- * TActiveButton control.
- */
-Prado.WebUI.TActiveButton = Class.extend(Prado.WebUI.CallbackControl);
-/**
- * TActiveLinkButton control.
- */
-Prado.WebUI.TActiveLinkButton = Class.extend(Prado.WebUI.CallbackControl);
-
-Prado.WebUI.TActiveImageButton = Class.extend(Prado.WebUI.TImageButton,
-{
- onPostBack : function(event, options)
- {
- this.addXYInput(event,options);
- var request = new Prado.CallbackRequest(options.EventTarget, options);
- request.dispatch();
- Event.stop(event);
- this.removeXYInput(event,options);
- }
-});
-/**
- * Active check box.
- */
-Prado.WebUI.TActiveCheckBox = Class.extend(Prado.WebUI.CallbackControl,
-{
- onPostBack : function(event, options)
- {
- var request = new Prado.CallbackRequest(options.EventTarget, options);
- if(request.dispatch()==false)
- Event.stop(event);
- }
-});
-
-/**
- * TActiveRadioButton control.
- */
-Prado.WebUI.TActiveRadioButton = Class.extend(Prado.WebUI.TActiveCheckBox);
-
-
-Prado.WebUI.TActiveCheckBoxList = Base.extend(
-{
- constructor : function(options)
- {
- Prado.Registry.set(options.ListID, this);
- for(var i = 0; i<options.ItemCount; i++)
- {
- var checkBoxOptions = Object.extend(
- {
- ID : options.ListID+"_c"+i,
- EventTarget : options.ListName+"$c"+i
- }, options);
- new Prado.WebUI.TActiveCheckBox(checkBoxOptions);
- }
- }
-});
-
-Prado.WebUI.TActiveRadioButtonList = Prado.WebUI.TActiveCheckBoxList;
-
-/**
- * TActiveTextBox control, handles onchange event.
- */
-Prado.WebUI.TActiveTextBox = Class.extend(Prado.WebUI.TTextBox,
-{
- onInit : function(options)
- {
- this.options=options;
- if(options['TextMode'] != 'MultiLine')
- this.observe(this.element, "keydown", this.handleReturnKey.bind(this));
- if(this.options['AutoPostBack']==true)
- this.observe(this.element, "change", this.doCallback.bindEvent(this,options));
- },
-
- doCallback : function(event, options)
- {
- var request = new Prado.CallbackRequest(options.EventTarget, options);
- request.dispatch();
- if (!Prototype.Browser.IE)
- Event.stop(event);
- }
-});
-
-/**
- * TAutoComplete control.
- */
-Prado.WebUI.TAutoComplete = Class.extend(Autocompleter.Base, Prado.WebUI.TActiveTextBox.prototype);
-Prado.WebUI.TAutoComplete = Class.extend(Prado.WebUI.TAutoComplete,
-{
- initialize : function(options)
- {
- this.options = options;
- this.observers = new Array();
- this.hasResults = false;
- this.baseInitialize(options.ID, options.ResultPanel, options);
- Object.extend(this.options,
- {
- onSuccess : this.onComplete.bind(this)
- });
-
- if(options.AutoPostBack)
- this.onInit(options);
-
- Prado.Registry.set(options.ID, this);
- },
-
- doCallback : function(event, options)
- {
- if(!this.active)
- {
- var request = new Prado.CallbackRequest(this.options.EventTarget, options);
- request.dispatch();
- Event.stop(event);
- }
- },
-
- //Overrides parent implementation, fires onchange event.
- onClick: function(event)
- {
- var element = Event.findElement(event, 'LI');
- this.index = element.autocompleteIndex;
- this.selectEntry();
- this.hide();
- Event.fireEvent(this.element, "change");
- },
-
- getUpdatedChoices : function()
- {
- var options = new Array(this.getToken(),"__TAutoComplete_onSuggest__");
- Prado.Callback(this.options.EventTarget, options, null, this.options);
- },
-
- /**
- * Overrides parent implements, don't update if no results.
- */
- selectEntry: function()
- {
- if(this.hasResults)
- {
- this.active = false;
- this.updateElement(this.getCurrentEntry());
- var options = [this.index, "__TAutoComplete_onSuggestionSelected__"];
- Prado.Callback(this.options.EventTarget, options, null, this.options);
- }
- },
-
- onComplete : function(request, boundary)
- {
- var result = Prado.Element.extractContent(request.transport.responseText, boundary);
- if(typeof(result) == "string")
- {
- if(result.length > 0)
- {
- this.hasResults = true;
- this.updateChoices(result);
- }
- else
- {
- this.active = false;
- this.hasResults = false;
- this.hide();
- }
- }
- }
-});
-
-/**
- * Time Triggered Callback class.
- */
-Prado.WebUI.TTimeTriggeredCallback = Class.create(Prado.WebUI.Control,
-{
- onInit : function(options)
- {
- this.options = Object.extend({ Interval : 1 }, options || {});
- Prado.WebUI.TTimeTriggeredCallback.registerTimer(this);
- },
-
- startTimer : function()
- {
- if(typeof(this.timer) == 'undefined' || this.timer == null)
- this.timer = this.setInterval(this.onTimerEvent.bind(this),this.options.Interval*1000);
- },
-
- stopTimer : function()
- {
- if(typeof(this.timer) != 'undefined')
- {
- this.clearInterval(this.timer);
- this.timer = null;
- }
- },
-
- resetTimer : function()
- {
- if(typeof(this.timer) != 'undefined')
- {
- this.clearInterval(this.timer);
- this.timer = null;
- this.timer = this.setInterval(this.onTimerEvent.bind(this),this.options.Interval*1000);
- }
- },
-
- onTimerEvent : function()
- {
- var request = new Prado.CallbackRequest(this.options.EventTarget, this.options);
- request.dispatch();
- },
-
- setTimerInterval : function(value)
- {
- if (this.options.Interval != value){
- this.options.Interval = value;
- this.resetTimer();
- }
- },
-
- onDone: function()
- {
- this.stopTimer();
- }
-});
-
-Object.extend(Prado.WebUI.TTimeTriggeredCallback,
-{
-
- //class methods
-
- timers : {},
-
- registerTimer : function(timer)
- {
- Prado.WebUI.TTimeTriggeredCallback.timers[timer.options.ID] = timer;
- },
-
- start : function(id)
- {
- if(Prado.WebUI.TTimeTriggeredCallback.timers[id])
- Prado.WebUI.TTimeTriggeredCallback.timers[id].startTimer();
- },
-
- stop : function(id)
- {
- if(Prado.WebUI.TTimeTriggeredCallback.timers[id])
- Prado.WebUI.TTimeTriggeredCallback.timers[id].stopTimer();
- },
-
- setTimerInterval : function (id,value)
- {
- if(Prado.WebUI.TTimeTriggeredCallback.timers[id])
- Prado.WebUI.TTimeTriggeredCallback.timers[id].setTimerInterval(value);
- }
-});
-
-Prado.WebUI.ActiveListControl = Class.create(Prado.WebUI.Control,
-{
- onInit : function(options)
- {
- if(this.element)
- {
- this.options = options;
- this.observe(this.element, "change", this.doCallback.bind(this));
- }
- },
-
- doCallback : function(event)
- {
- var request = new Prado.CallbackRequest(this.options.EventTarget, this.options);
- request.dispatch();
- Event.stop(event);
- }
-});
-
-Prado.WebUI.TActiveDropDownList = Class.create(Prado.WebUI.ActiveListControl);
-Prado.WebUI.TActiveListBox = Class.create(Prado.WebUI.ActiveListControl);
-
-/**
- * Observe event of a particular control to trigger a callback request.
- */
-Prado.WebUI.TEventTriggeredCallback = Class.create(Prado.WebUI.Control,
-{
- onInit : function(options)
- {
- this.options = options || {} ;
- var element = $(options['ControlID']);
- if(element)
- this.observe(element, this.getEventName(element), this.doCallback.bind(this));
- },
-
- getEventName : function(element)
- {
- var name = this.options.EventName;
- if(typeof(name) == "undefined" && element.type)
- {
- switch (element.type.toLowerCase())
- {
- case 'password':
- case 'text':
- case 'textarea':
- case 'select-one':
- case 'select-multiple':
- return 'change';
- }
- }
- return typeof(name) == "undefined" || name == "undefined" ? 'click' : name;
- },
-
- doCallback : function(event)
- {
- var request = new Prado.CallbackRequest(this.options.EventTarget, this.options);
- request.dispatch();
- if(this.options.StopEvent == true)
- Event.stop(event);
- }
-});
-
-/**
- * Observe changes to a property of a particular control to trigger a callback.
- */
-Prado.WebUI.TValueTriggeredCallback = Class.create(Prado.WebUI.Control,
-{
- count : 1,
-
- observing : true,
-
- onInit : function(options)
- {
- this.options = options || {} ;
- this.options.PropertyName = this.options.PropertyName || 'value';
- var element = $(options['ControlID']);
- this.value = element ? element[this.options.PropertyName] : undefined;
- Prado.WebUI.TValueTriggeredCallback.register(this);
- this.startObserving();
- },
-
- stopObserving : function()
- {
- this.clearTimeout(this.timer);
- this.observing = false;
- },
-
- startObserving : function()
- {
- this.timer = this.setTimeout(this.checkChanges.bind(this), this.options.Interval*1000);
- },
-
- checkChanges : function()
- {
- var element = $(this.options.ControlID);
- if(element)
- {
- var value = element[this.options.PropertyName];
- if(this.value != value)
- {
- this.doCallback(this.value, value);
- this.value = value;
- this.count=1;
- }
- else
- this.count = this.count + this.options.Decay;
- if(this.observing)
- this.time = this.setTimeout(this.checkChanges.bind(this),
- parseInt(this.options.Interval*1000*this.count));
- }
- },
-
- doCallback : function(oldValue, newValue)
- {
- var request = new Prado.CallbackRequest(this.options.EventTarget, this.options);
- var param = {'OldValue' : oldValue, 'NewValue' : newValue};
- request.setCallbackParameter(param);
- request.dispatch();
- },
-
- onDone : function()
- {
- if (this.observing)
- this.stopObserving();
- }
-});
-
-Object.extend(Prado.WebUI.TValueTriggeredCallback,
-{
- //class methods
-
- timers : {},
-
- register : function(timer)
- {
- Prado.WebUI.TValueTriggeredCallback.timers[timer.options.ID] = timer;
- },
-
- stop : function(id)
- {
- Prado.WebUI.TValueTriggeredCallback.timers[id].stopObserving();
- }
-});
-
-Prado.WebUI.TActiveTableCell = Class.create(Prado.WebUI.CallbackControl);
-Prado.WebUI.TActiveTableRow = Class.create(Prado.WebUI.CallbackControl);
+/**
+ * Generic postback control.
+ */
+Prado.WebUI.CallbackControl = Class.extend(Prado.WebUI.PostBackControl,
+{
+ onPostBack : function(event, options)
+ {
+ var request = new Prado.CallbackRequest(options.EventTarget, options);
+ request.dispatch();
+ Event.stop(event);
+ }
+});
+
+/**
+ * TActiveButton control.
+ */
+Prado.WebUI.TActiveButton = Class.extend(Prado.WebUI.CallbackControl);
+/**
+ * TActiveLinkButton control.
+ */
+Prado.WebUI.TActiveLinkButton = Class.extend(Prado.WebUI.CallbackControl);
+
+Prado.WebUI.TActiveImageButton = Class.extend(Prado.WebUI.TImageButton,
+{
+ onPostBack : function(event, options)
+ {
+ this.addXYInput(event,options);
+ var request = new Prado.CallbackRequest(options.EventTarget, options);
+ request.dispatch();
+ Event.stop(event);
+ this.removeXYInput(event,options);
+ }
+});
+/**
+ * Active check box.
+ */
+Prado.WebUI.TActiveCheckBox = Class.extend(Prado.WebUI.CallbackControl,
+{
+ onPostBack : function(event, options)
+ {
+ var request = new Prado.CallbackRequest(options.EventTarget, options);
+ if(request.dispatch()==false)
+ Event.stop(event);
+ }
+});
+
+/**
+ * TActiveRadioButton control.
+ */
+Prado.WebUI.TActiveRadioButton = Class.extend(Prado.WebUI.TActiveCheckBox);
+
+
+Prado.WebUI.TActiveCheckBoxList = Base.extend(
+{
+ constructor : function(options)
+ {
+ Prado.Registry.set(options.ListID, this);
+ for(var i = 0; i<options.ItemCount; i++)
+ {
+ var checkBoxOptions = Object.extend(
+ {
+ ID : options.ListID+"_c"+i,
+ EventTarget : options.ListName+"$c"+i
+ }, options);
+ new Prado.WebUI.TActiveCheckBox(checkBoxOptions);
+ }
+ }
+});
+
+Prado.WebUI.TActiveRadioButtonList = Prado.WebUI.TActiveCheckBoxList;
+
+/**
+ * TActiveTextBox control, handles onchange event.
+ */
+Prado.WebUI.TActiveTextBox = Class.extend(Prado.WebUI.TTextBox,
+{
+ onInit : function(options)
+ {
+ this.options=options;
+ if(options['TextMode'] != 'MultiLine')
+ this.observe(this.element, "keydown", this.handleReturnKey.bind(this));
+ if(this.options['AutoPostBack']==true)
+ this.observe(this.element, "change", this.doCallback.bindEvent(this,options));
+ },
+
+ doCallback : function(event, options)
+ {
+ var request = new Prado.CallbackRequest(options.EventTarget, options);
+ request.dispatch();
+ if (!Prototype.Browser.IE)
+ Event.stop(event);
+ }
+});
+
+/**
+ * TAutoComplete control.
+ */
+Prado.WebUI.TAutoComplete = Class.extend(Autocompleter.Base, Prado.WebUI.TActiveTextBox.prototype);
+Prado.WebUI.TAutoComplete = Class.extend(Prado.WebUI.TAutoComplete,
+{
+ initialize : function(options)
+ {
+ this.options = options;
+ this.observers = new Array();
+ this.hasResults = false;
+ this.baseInitialize(options.ID, options.ResultPanel, options);
+ Object.extend(this.options,
+ {
+ onSuccess : this.onComplete.bind(this)
+ });
+
+ if(options.AutoPostBack)
+ this.onInit(options);
+
+ Prado.Registry.set(options.ID, this);
+ },
+
+ doCallback : function(event, options)
+ {
+ if(!this.active)
+ {
+ var request = new Prado.CallbackRequest(this.options.EventTarget, options);
+ request.dispatch();
+ Event.stop(event);
+ }
+ },
+
+ //Overrides parent implementation, fires onchange event.
+ onClick: function(event)
+ {
+ var element = Event.findElement(event, 'LI');
+ this.index = element.autocompleteIndex;
+ this.selectEntry();
+ this.hide();
+ Event.fireEvent(this.element, "change");
+ },
+
+ getUpdatedChoices : function()
+ {
+ var options = new Array(this.getToken(),"__TAutoComplete_onSuggest__");
+ Prado.Callback(this.options.EventTarget, options, null, this.options);
+ },
+
+ /**
+ * Overrides parent implements, don't update if no results.
+ */
+ selectEntry: function()
+ {
+ if(this.hasResults)
+ {
+ this.active = false;
+ this.updateElement(this.getCurrentEntry());
+ var options = [this.index, "__TAutoComplete_onSuggestionSelected__"];
+ Prado.Callback(this.options.EventTarget, options, null, this.options);
+ }
+ },
+
+ onComplete : function(request, boundary)
+ {
+ var result = Prado.Element.extractContent(request.transport.responseText, boundary);
+ if(typeof(result) == "string")
+ {
+ if(result.length > 0)
+ {
+ this.hasResults = true;
+ this.updateChoices(result);
+ }
+ else
+ {
+ this.active = false;
+ this.hasResults = false;
+ this.hide();
+ }
+ }
+ }
+});
+
+/**
+ * Time Triggered Callback class.
+ */
+Prado.WebUI.TTimeTriggeredCallback = Class.create(Prado.WebUI.Control,
+{
+ onInit : function(options)
+ {
+ this.options = Object.extend({ Interval : 1 }, options || {});
+ Prado.WebUI.TTimeTriggeredCallback.registerTimer(this);
+ },
+
+ startTimer : function()
+ {
+ if(typeof(this.timer) == 'undefined' || this.timer == null)
+ this.timer = this.setInterval(this.onTimerEvent.bind(this),this.options.Interval*1000);
+ },
+
+ stopTimer : function()
+ {
+ if(typeof(this.timer) != 'undefined')
+ {
+ this.clearInterval(this.timer);
+ this.timer = null;
+ }
+ },
+
+ resetTimer : function()
+ {
+ if(typeof(this.timer) != 'undefined')
+ {
+ this.clearInterval(this.timer);
+ this.timer = null;
+ this.timer = this.setInterval(this.onTimerEvent.bind(this),this.options.Interval*1000);
+ }
+ },
+
+ onTimerEvent : function()
+ {
+ var request = new Prado.CallbackRequest(this.options.EventTarget, this.options);
+ request.dispatch();
+ },
+
+ setTimerInterval : function(value)
+ {
+ if (this.options.Interval != value){
+ this.options.Interval = value;
+ this.resetTimer();
+ }
+ },
+
+ onDone: function()
+ {
+ this.stopTimer();
+ }
+});
+
+Object.extend(Prado.WebUI.TTimeTriggeredCallback,
+{
+
+ //class methods
+
+ timers : {},
+
+ registerTimer : function(timer)
+ {
+ Prado.WebUI.TTimeTriggeredCallback.timers[timer.options.ID] = timer;
+ },
+
+ start : function(id)
+ {
+ if(Prado.WebUI.TTimeTriggeredCallback.timers[id])
+ Prado.WebUI.TTimeTriggeredCallback.timers[id].startTimer();
+ },
+
+ stop : function(id)
+ {
+ if(Prado.WebUI.TTimeTriggeredCallback.timers[id])
+ Prado.WebUI.TTimeTriggeredCallback.timers[id].stopTimer();
+ },
+
+ setTimerInterval : function (id,value)
+ {
+ if(Prado.WebUI.TTimeTriggeredCallback.timers[id])
+ Prado.WebUI.TTimeTriggeredCallback.timers[id].setTimerInterval(value);
+ }
+});
+
+Prado.WebUI.ActiveListControl = Class.create(Prado.WebUI.Control,
+{
+ onInit : function(options)
+ {
+ if(this.element)
+ {
+ this.options = options;
+ this.observe(this.element, "change", this.doCallback.bind(this));
+ }
+ },
+
+ doCallback : function(event)
+ {
+ var request = new Prado.CallbackRequest(this.options.EventTarget, this.options);
+ request.dispatch();
+ Event.stop(event);
+ }
+});
+
+Prado.WebUI.TActiveDropDownList = Class.create(Prado.WebUI.ActiveListControl);
+Prado.WebUI.TActiveListBox = Class.create(Prado.WebUI.ActiveListControl);
+
+/**
+ * Observe event of a particular control to trigger a callback request.
+ */
+Prado.WebUI.TEventTriggeredCallback = Class.create(Prado.WebUI.Control,
+{
+ onInit : function(options)
+ {
+ this.options = options || {} ;
+ var element = $(options['ControlID']);
+ if(element)
+ this.observe(element, this.getEventName(element), this.doCallback.bind(this));
+ },
+
+ getEventName : function(element)
+ {
+ var name = this.options.EventName;
+ if(typeof(name) == "undefined" && element.type)
+ {
+ switch (element.type.toLowerCase())
+ {
+ case 'password':
+ case 'text':
+ case 'textarea':
+ case 'select-one':
+ case 'select-multiple':
+ return 'change';
+ }
+ }
+ return typeof(name) == "undefined" || name == "undefined" ? 'click' : name;
+ },
+
+ doCallback : function(event)
+ {
+ var request = new Prado.CallbackRequest(this.options.EventTarget, this.options);
+ request.dispatch();
+ if(this.options.StopEvent == true)
+ Event.stop(event);
+ }
+});
+
+/**
+ * Observe changes to a property of a particular control to trigger a callback.
+ */
+Prado.WebUI.TValueTriggeredCallback = Class.create(Prado.WebUI.Control,
+{
+ count : 1,
+
+ observing : true,
+
+ onInit : function(options)
+ {
+ this.options = options || {} ;
+ this.options.PropertyName = this.options.PropertyName || 'value';
+ var element = $(options['ControlID']);
+ this.value = element ? element[this.options.PropertyName] : undefined;
+ Prado.WebUI.TValueTriggeredCallback.register(this);
+ this.startObserving();
+ },
+
+ stopObserving : function()
+ {
+ this.clearTimeout(this.timer);
+ this.observing = false;
+ },
+
+ startObserving : function()
+ {
+ this.timer = this.setTimeout(this.checkChanges.bind(this), this.options.Interval*1000);
+ },
+
+ checkChanges : function()
+ {
+ var element = $(this.options.ControlID);
+ if(element)
+ {
+ var value = element[this.options.PropertyName];
+ if(this.value != value)
+ {
+ this.doCallback(this.value, value);
+ this.value = value;
+ this.count=1;
+ }
+ else
+ this.count = this.count + this.options.Decay;
+ if(this.observing)
+ this.time = this.setTimeout(this.checkChanges.bind(this),
+ parseInt(this.options.Interval*1000*this.count));
+ }
+ },
+
+ doCallback : function(oldValue, newValue)
+ {
+ var request = new Prado.CallbackRequest(this.options.EventTarget, this.options);
+ var param = {'OldValue' : oldValue, 'NewValue' : newValue};
+ request.setCallbackParameter(param);
+ request.dispatch();
+ },
+
+ onDone : function()
+ {
+ if (this.observing)
+ this.stopObserving();
+ }
+});
+
+Object.extend(Prado.WebUI.TValueTriggeredCallback,
+{
+ //class methods
+
+ timers : {},
+
+ register : function(timer)
+ {
+ Prado.WebUI.TValueTriggeredCallback.timers[timer.options.ID] = timer;
+ },
+
+ stop : function(id)
+ {
+ Prado.WebUI.TValueTriggeredCallback.timers[id].stopObserving();
+ }
+});
+
+Prado.WebUI.TActiveTableCell = Class.create(Prado.WebUI.CallbackControl);
+Prado.WebUI.TActiveTableRow = Class.create(Prado.WebUI.CallbackControl);
diff --git a/framework/Web/Javascripts/source/prado/activecontrols/activedatepicker.js b/framework/Web/Javascripts/source/prado/activecontrols/activedatepicker.js
index 1b0b1492..f7f63026 100755
--- a/framework/Web/Javascripts/source/prado/activecontrols/activedatepicker.js
+++ b/framework/Web/Javascripts/source/prado/activecontrols/activedatepicker.js
@@ -1,87 +1,87 @@
-/**
- * TActiveDatePicker control
- */
-Prado.WebUI.TActiveDatePicker = Class.create(Prado.WebUI.TDatePicker,
-{
- onInit : function(options)
- {
- this.options = options || [];
- this.control = $(options.ID);
- this.dateSlot = new Array(42);
- this.weekSlot = new Array(6);
- this.minimalDaysInFirstWeek = 4;
- this.selectedDate = this.newDate();
- this.positionMode = 'Bottom';
-
-
- //which element to trigger to show the calendar
- if(this.options.Trigger)
- {
- this.trigger = $(this.options.Trigger) ;
- var triggerEvent = this.options.TriggerEvent || "click";
- }
- else
- {
- this.trigger = this.control;
- var triggerEvent = this.options.TriggerEvent || "focus";
- }
-
- // Popup position
- if(this.options.PositionMode == 'Top')
- {
- this.positionMode = this.options.PositionMode;
- }
-
- Object.extend(this,options);
-
- if (this.options.ShowCalendar)
- this.observe(this.trigger, triggerEvent, this.show.bindEvent(this));
-
- // Listen to change event
- if(this.options.InputMode == "TextBox")
- {
- this.observe(this.control, "change", this.onDateChanged.bindEvent(this));
- }
- else
- {
- var day = Prado.WebUI.TDatePicker.getDayListControl(this.control);
- var month = Prado.WebUI.TDatePicker.getMonthListControl(this.control);
- var year = Prado.WebUI.TDatePicker.getYearListControl(this.control);
- if (day) this.observe (day, "change", this.onDateChanged.bindEvent(this));
- if (month) this.observe (month, "change", this.onDateChanged.bindEvent(this));
- if (year) this.observe (year, "change", this.onDateChanged.bindEvent(this));
-
- }
-
- },
-
- // Respond to change event on the textbox or dropdown list
- // This method raises OnDateChanged event on client side if it has been defined,
- // and raise the callback request
- onDateChanged : function ()
- {
- var date;
- if (this.options.InputMode == "TextBox")
- {
- date=this.control.value;
- }
- else
- {
- var day = Prado.WebUI.TDatePicker.getDayListControl(this.control);
- if (day) day=day.selectedIndex+1;
- var month = Prado.WebUI.TDatePicker.getMonthListControl(this.control);
- if (month) month=month.selectedIndex;
- var year = Prado.WebUI.TDatePicker.getYearListControl(this.control);
- if (year) year=year.value;
- date=new Date(year, month, day, 0,0,0).SimpleFormat(this.Format, this);
- }
- if (typeof(this.options.OnDateChanged) == "function") this.options.OnDateChanged(this, date);
-
- if(this.options['AutoPostBack']==true)
- {
- // Make callback request
- var request = new Prado.CallbackRequest(this.options.EventTarget,this.options);
- request.dispatch();
- }
- }
-});
+/**
+ * TActiveDatePicker control
+ */
+Prado.WebUI.TActiveDatePicker = Class.create(Prado.WebUI.TDatePicker,
+{
+ onInit : function(options)
+ {
+ this.options = options || [];
+ this.control = $(options.ID);
+ this.dateSlot = new Array(42);
+ this.weekSlot = new Array(6);
+ this.minimalDaysInFirstWeek = 4;
+ this.selectedDate = this.newDate();
+ this.positionMode = 'Bottom';
+
+
+ //which element to trigger to show the calendar
+ if(this.options.Trigger)
+ {
+ this.trigger = $(this.options.Trigger) ;
+ var triggerEvent = this.options.TriggerEvent || "click";
+ }
+ else
+ {
+ this.trigger = this.control;
+ var triggerEvent = this.options.TriggerEvent || "focus";
+ }
+
+ // Popup position
+ if(this.options.PositionMode == 'Top')
+ {
+ this.positionMode = this.options.PositionMode;
+ }
+
+ Object.extend(this,options);
+
+ if (this.options.ShowCalendar)
+ this.observe(this.trigger, triggerEvent, this.show.bindEvent(this));
+
+ // Listen to change event
+ if(this.options.InputMode == "TextBox")
+ {
+ this.observe(this.control, "change", this.onDateChanged.bindEvent(this));
+ }
+ else
+ {
+ var day = Prado.WebUI.TDatePicker.getDayListControl(this.control);
+ var month = Prado.WebUI.TDatePicker.getMonthListControl(this.control);
+ var year = Prado.WebUI.TDatePicker.getYearListControl(this.control);
+ if (day) this.observe (day, "change", this.onDateChanged.bindEvent(this));
+ if (month) this.observe (month, "change", this.onDateChanged.bindEvent(this));
+ if (year) this.observe (year, "change", this.onDateChanged.bindEvent(this));
+
+ }
+
+ },
+
+ // Respond to change event on the textbox or dropdown list
+ // This method raises OnDateChanged event on client side if it has been defined,
+ // and raise the callback request
+ onDateChanged : function ()
+ {
+ var date;
+ if (this.options.InputMode == "TextBox")
+ {
+ date=this.control.value;
+ }
+ else
+ {
+ var day = Prado.WebUI.TDatePicker.getDayListControl(this.control);
+ if (day) day=day.selectedIndex+1;
+ var month = Prado.WebUI.TDatePicker.getMonthListControl(this.control);
+ if (month) month=month.selectedIndex;
+ var year = Prado.WebUI.TDatePicker.getYearListControl(this.control);
+ if (year) year=year.value;
+ date=new Date(year, month, day, 0,0,0).SimpleFormat(this.Format, this);
+ }
+ if (typeof(this.options.OnDateChanged) == "function") this.options.OnDateChanged(this, date);
+
+ if(this.options['AutoPostBack']==true)
+ {
+ // Make callback request
+ var request = new Prado.CallbackRequest(this.options.EventTarget,this.options);
+ request.dispatch();
+ }
+ }
+});
diff --git a/framework/Web/Javascripts/source/prado/activecontrols/ajax3.js b/framework/Web/Javascripts/source/prado/activecontrols/ajax3.js
index 995e8e97..55ef64cb 100644
--- a/framework/Web/Javascripts/source/prado/activecontrols/ajax3.js
+++ b/framework/Web/Javascripts/source/prado/activecontrols/ajax3.js
@@ -1,1144 +1,1144 @@
-
-Prado.AjaxRequest = Class.create();
-Prado.AjaxRequest.prototype = Object.clone(Ajax.Request.prototype);
-
-/**
- * Override Prototype's response implementation.
- */
-Object.extend(Prado.AjaxRequest.prototype,
-{
- /*initialize: function(request)
- {
- this.CallbackRequest = request;
- this.transport = Ajax.getTransport();
- this.setOptions(request.options);
- this.request(request.url);
- },*/
-
- /**
- * Customize the response, dispatch onXXX response code events, and
- * tries to execute response actions (javascript statements).
- */
- respondToReadyState : function(readyState)
- {
- var event = Ajax.Request.Events[readyState];
- var transport = this.transport, json = this.getBodyDataPart(Prado.CallbackRequest.DATA_HEADER);
-
- if (event == 'Complete')
- {
- var redirectUrl = this.getBodyContentPart(Prado.CallbackRequest.REDIRECT_HEADER);
- if (redirectUrl)
- document.location.href = redirectUrl;
-
- if ((this.getHeader('Content-type') || '').match(/^text\/javascript/i))
- {
- try
- {
- json = eval('(' + transport.responseText + ')');
- }
- catch (e)
- {
- if(typeof(json) == "string")
- json = Prado.CallbackRequest.decode(result);
- }
- }
-
- try
- {
- Prado.CallbackRequest.updatePageState(this,transport);
- Prado.CallbackRequest.checkHiddenFields(this,transport);
- var obj = this;
- Prado.CallbackRequest.loadAssets(this,transport, function()
-
- {
- try
- {
- Ajax.Responders.dispatch('on' + transport.status, obj, transport, json);
- Prado.CallbackRequest.dispatchActions(transport,obj.getBodyDataPart(Prado.CallbackRequest.ACTION_HEADER));
-
- (
- obj.options['on' + obj.transport.status]
- ||
- obj.options['on' + (obj.success() ? 'Success' : 'Failure')]
- ||
- Prototype.emptyFunction
- ) (obj, json);
- }
- catch (e)
- {
- obj.dispatchException(e);
- }
- }
- );
- }
- catch (e)
- {
- this.dispatchException(e);
- }
- }
-
- try {
- (this.options['on' + event] || Prototype.emptyFunction)(this, json);
- Ajax.Responders.dispatch('on' + event, this, transport, json);
- } catch (e) {
- this.dispatchException(e);
- }
-
- /* Avoid memory leak in MSIE: clean up the oncomplete event handler */
- if (event == 'Complete')
- this.transport.onreadystatechange = Prototype.emptyFunction;
- },
-
- /**
- * Gets header data assuming JSON encoding.
- * @param string header name
- * @return object header data as javascript structures.
- */
- getHeaderData : function(name)
- {
- return this.getJsonData(this.getHeader(name));
- },
-
- getBodyContentPart : function(name)
- {
- if(typeof(this.transport.responseText)=="string")
- return Prado.Element.extractContent(this.transport.responseText, name);
- },
-
- getJsonData : function(json)
- {
- try
- {
- return eval('(' + json + ')');
- }
- catch (e)
- {
- if(typeof(json) == "string")
- return Prado.CallbackRequest.decode(json);
- }
- },
-
- getBodyDataPart : function(name)
- {
- return this.getJsonData(this.getBodyContentPart(name));
- }
-});
-
-/**
- * Prado Callback client-side request handler.
- */
-Prado.CallbackRequest = Class.create();
-
-/**
- * Static definitions.
- */
-Object.extend(Prado.CallbackRequest,
-{
- /**
- * Callback request target POST field name.
- */
- FIELD_CALLBACK_TARGET : 'PRADO_CALLBACK_TARGET',
- /**
- * Callback request parameter POST field name.
- */
- FIELD_CALLBACK_PARAMETER : 'PRADO_CALLBACK_PARAMETER',
- /**
- * Callback request page state field name,
- */
- FIELD_CALLBACK_PAGESTATE : 'PRADO_PAGESTATE',
-
- FIELD_POSTBACK_TARGET : 'PRADO_POSTBACK_TARGET',
-
- FIELD_POSTBACK_PARAMETER : 'PRADO_POSTBACK_PARAMETER',
-
- /**
- * List of form fields that will be collected during callback.
- */
- PostDataLoaders : [],
- /**
- * Response data header name.
- */
- DATA_HEADER : 'X-PRADO-DATA',
- /**
- * Response javascript execution statement header name.
- */
- ACTION_HEADER : 'X-PRADO-ACTIONS',
- /**
- * Response errors/exceptions header name.
- */
- ERROR_HEADER : 'X-PRADO-ERROR',
- /**
- * Page state header name.
- */
- PAGESTATE_HEADER : 'X-PRADO-PAGESTATE',
- /**
- * Script list header name.
- */
- SCRIPTLIST_HEADER : 'X-PRADO-SCRIPTLIST',
- /**
- * Stylesheet list header name.
- */
- STYLESHEETLIST_HEADER : 'X-PRADO-STYLESHEETLIST',
- /**
- * Hidden field list header name.
- */
- HIDDENFIELDLIST_HEADER : 'X-PRADO-HIDDENFIELDLIST',
-
- REDIRECT_HEADER : 'X-PRADO-REDIRECT',
-
- requestQueue : [],
-
- //all request objects
- requests : {},
-
- getRequestById : function(id)
- {
- var requests = Prado.CallbackRequest.requests;
- if(typeof(requests[id]) != "undefined")
- return requests[id];
- },
-
- dispatch : function(id)
- {
- var requests = Prado.CallbackRequest.requests;
- if(typeof(requests[id]) != "undefined")
- requests[id].dispatch();
- },
-
- /**
- * Add ids of inputs element to post in the request.
- */
- addPostLoaders : function(ids)
- {
- var self = Prado.CallbackRequest;
- self.PostDataLoaders = self.PostDataLoaders.concat(ids);
- var list = [];
- self.PostDataLoaders.each(function(id)
- {
- if(list.indexOf(id) < 0)
- list.push(id);
- });
- self.PostDataLoaders = list;
- },
-
- /**
- * Dispatch callback response actions.
- */
- dispatchActions : function(transport,actions)
- {
- var self = Prado.CallbackRequest;
- if(actions && actions.length > 0)
- actions.each(self.__run.bind(self,transport));
- },
-
- /**
- * Prase and evaluate a Callback clien-side action
- */
- __run : function(transport, command)
- {
- var self = Prado.CallbackRequest;
- self.transport = transport;
- for(var method in command)
- {
- try
- {
- method.toFunction().apply(self,command[method]);
- }
- catch(e)
- {
- if(typeof(Logger) != "undefined")
- self.Exception.onException(null,e);
- else
- debugger;
- }
- }
- },
-
- /**
- * Respond to Prado Callback request exceptions.
- */
- Exception :
- {
- /**
- * Server returns 500 exception. Just log it.
- */
- "on500" : function(request, transport, data)
- {
- var e = request.getHeaderData(Prado.CallbackRequest.ERROR_HEADER);
- if (e)
- Logger.error("Callback Server Error "+e.code, this.formatException(e));
- else
- Logger.error("Callback Server Error Unknown",'');
- },
-
- /**
- * Callback OnComplete event,logs reponse and data to console.
- */
- 'on200' : function(request, transport, data)
- {
- if(transport.status < 500)
- {
- var msg = 'HTTP '+transport.status+" with response : \n";
- if(transport.responseText.trim().length >0)
- {
- var f = RegExp('(<!--X-PRADO[^>]+-->)([\\s\\S\\w\\W]*)(<!--//X-PRADO[^>]+-->)',"m");
- msg += transport.responseText.replace(f,'') + "\n";
- }
- if(typeof(data)!="undefined" && data != null)
- msg += "Data : \n"+inspect(data)+"\n";
- data = request.getBodyDataPart(Prado.CallbackRequest.ACTION_HEADER);
- if(data && data.length > 0)
- {
- msg += "Actions : \n";
- data.each(function(action)
- {
- msg += inspect(action)+"\n";
- });
- }
- Logger.info(msg);
- }
- },
-
- /**
- * Uncaught exceptions during callback response.
- */
- onException : function(request,e)
- {
- var msg = "";
- $H(e).each(function(item)
- {
- msg += item.key+": "+item.value+"\n";
- })
- Logger.error('Uncaught Callback Client Exception:', msg);
- },
-
- /**
- * Formats the exception message for display in console.
- */
- formatException : function(e)
- {
- var msg = e.type + " with message \""+e.message+"\"";
- msg += " in "+e.file+"("+e.line+")\n";
- msg += "Stack trace:\n";
- var trace = e.trace;
- for(var i = 0; i<trace.length; i++)
- {
- msg += " #"+i+" "+trace[i].file;
- msg += "("+trace[i].line+"): ";
- msg += trace[i]["class"]+"->"+trace[i]["function"]+"()"+"\n";
- }
- msg += e.version+" "+e.time+"\n";
- return msg;
- }
- },
-
- /**
- * @return string JSON encoded data.
- */
- encode : function(data)
- {
- return Prado.JSON.stringify(data);
- },
-
- /**
- * @return mixed javascript data decoded from string using JSON decoding.
- */
- decode : function(data)
- {
- if(typeof(data) == "string" && data.trim().length > 0)
- return Prado.JSON.parse(data);
- else
- return null;
- },
-
- /**
- * Dispatch a normal request, no timeouts or aborting of requests.
- */
- dispatchNormalRequest : function(callback)
- {
- callback.options.postBody = callback._getPostData(),
- callback.request(callback.url);
- return true;
- },
-
- /**
- * Abort the current priority request in progress.
- */
- tryNextRequest : function()
- {
- var self = Prado.CallbackRequest;
- //Logger.debug('trying next request');
- if(typeof(self.currentRequest) == 'undefined' || self.currentRequest==null)
- {
- if(self.requestQueue.length > 0)
- return self.dispatchQueue();
- //else
- //Logger.warn('empty queque');
- }
- //else
- //Logger.warn('current request ' + self.currentRequest.id);
- },
-
- /*
- * Checks which scripts are used by the response and ensures they're loaded
- */
- loadScripts : function(request, transport, callback)
- {
- var self = Prado.CallbackRequest;
- var data = request.getBodyContentPart(self.SCRIPTLIST_HEADER);
- if (!this.ScriptsToLoad) this.ScriptsToLoad = new Array();
- this.ScriptLoadFinishedCallback = callback;
- if (typeof(data) == "string" && data.length > 0)
- {
- json = Prado.CallbackRequest.decode(data);
- if(typeof(json) != "object")
- Logger.warn("Invalid script list:"+data);
- else
- for(var key in json)
- if (/^\d+$/.test(key))
- {
- var url = json[key];
- if (!Prado.ScriptManager.isAssetLoaded(url))
- this.ScriptsToLoad.push(url);
- }
- }
- this.loadNextScript();
- },
-
- loadNextScript: function()
- {
- var done = (!this.ScriptsToLoad || (this.ScriptsToLoad.length==0));
- if (!done)
- {
- var url = this.ScriptsToLoad.shift(); var obj = this;
- if (
- Prado.ScriptManager.ensureAssetIsLoaded(url,
- function() {
- obj.loadNextScript();
- }
- )
- )
- this.loadNextScript();
- }
- else
- {
- if (this.ScriptLoadFinishedCallback)
- {
- var cb = this.ScriptLoadFinishedCallback;
- this.ScriptLoadFinishedCallback = null;
- cb();
- }
- }
- },
-
- loadStyleSheetsAsync : function(request, transport)
- {
- var self = Prado.CallbackRequest;
- var data = request.getBodyContentPart(self.STYLESHEETLIST_HEADER);
- if (typeof(data) == "string" && data.length > 0)
- {
- json = Prado.CallbackRequest.decode(data);
- if(typeof(json) != "object")
- Logger.warn("Invalid stylesheet list:"+data);
- else
- for(var key in json)
- if (/^\d+$/.test(key))
- Prado.StyleSheetManager.ensureAssetIsLoaded(json[key],null);
- }
- },
-
- loadStyleSheets : function(request, transport, callback)
- {
- var self = Prado.CallbackRequest;
- var data = request.getBodyContentPart(self.STYLESHEETLIST_HEADER);
- if (!this.StyleSheetsToLoad) this.StyleSheetsToLoad = new Array();
- this.StyleSheetLoadFinishedCallback = callback;
- if (typeof(data) == "string" && data.length > 0)
- {
- json = Prado.CallbackRequest.decode(data);
- if(typeof(json) != "object")
- Logger.warn("Invalid stylesheet list:"+data);
- else
- for(var key in json)
- if (/^\d+$/.test(key))
- {
- var url = json[key];
- if (!Prado.StyleSheetManager.isAssetLoaded(url))
- this.StyleSheetsToLoad.push(url);
- }
- }
- this.loadNextStyleSheet();
- },
-
- loadNextStyleSheet: function()
- {
- var done = (!this.StyleSheetsToLoad || (this.StyleSheetsToLoad.length==0));
- if (!done)
- {
- var url = this.StyleSheetsToLoad.shift(); var obj = this;
- if (
- Prado.StyleSheetManager.ensureAssetIsLoaded(url,
- function() {
- obj.loadNextStyleSheet();
- }
- )
- )
- this.loadNextStyleSheet();
- }
- else
- {
- if (this.StyleSheetLoadFinishedCallback)
- {
- var cb = this.StyleSheetLoadFinishedCallback;
- this.StyleSheetLoadFinishedCallback = null;
- cb();
- }
- }
- },
-
- /*
- * Checks which assets are used by the response and ensures they're loaded
- */
- loadAssets : function(request, transport, callback)
- {
- /*
-
- ! This is the callback-based loader for stylesheets, which loads them one-by-one, and
- ! waits for all of them to be loaded before loading scripts and processing the rest of
- ! the callback.
- !
- ! That however is not neccessary, as stylesheets can be loaded asynchronously too.
- !
- ! I leave this code here for the case that this turns out to be a compatibility issue
- ! (for ex. I can imagine some scripts trying to access stylesheet properties and such)
- ! so if need can be reactivated. If you do so, comment out the async stylesheet loader below!
-
- var obj = this;
- this.loadStyleSheets(request,transport, function() {
- obj.loadScripts(request,transport,callback);
- });
-
- */
-
- this.loadStyleSheetsAsync(request,transport);
-
- this.loadScripts(request,transport,callback);
- },
-
- checkHiddenField: function(name, value)
- {
- var id = name.replace(':','_');
- if (!document.getElementById(id))
- {
- var field = document.createElement('input');
- field.setAttribute('type','hidden');
- field.id = id;
- field.name = name;
- field.value = value;
- document.body.appendChild(field);
- }
- },
-
- checkHiddenFields : function(request, transport)
- {
- var self = Prado.CallbackRequest;
- var data = request.getBodyContentPart(self.HIDDENFIELDLIST_HEADER);
- if (typeof(data) == "string" && data.length > 0)
- {
- json = Prado.CallbackRequest.decode(data);
- if(typeof(json) != "object")
- Logger.warn("Invalid hidden field list:"+data);
- else
- for(var key in json)
- this.checkHiddenField(key,json[key]);
- }
- },
-
- /**
- * Updates the page state. It will update only if EnablePageStateUpdate and
- * HasPriority options are both true.
- */
- updatePageState : function(request, transport)
- {
- var self = Prado.CallbackRequest;
- var pagestate = $(self.FIELD_CALLBACK_PAGESTATE);
- var enabled = request.ActiveControl.EnablePageStateUpdate && request.ActiveControl.HasPriority;
- var aborted = typeof(self.currentRequest) == 'undefined' || self.currentRequest == null;
- if(enabled && !aborted && pagestate)
- {
- var data = request.getBodyContentPart(self.PAGESTATE_HEADER);
- if(typeof(data) == "string" && data.length > 0)
- pagestate.value = data;
- else
- {
- if(typeof(Logger) != "undefined")
- Logger.warn("Missing page state:"+data);
- //Logger.warn('## bad state: setting current request to null');
- self.endCurrentRequest();
- //self.tryNextRequest();
- return false;
- }
- }
- self.endCurrentRequest();
- //Logger.warn('## state updated: setting current request to null');
- //self.tryNextRequest();
- return true;
- },
-
- enqueue : function(callback)
- {
- var self = Prado.CallbackRequest;
- self.requestQueue.push(callback);
- //Logger.warn("equeued "+callback.id+", current queque length="+self.requestQueue.length);
- self.tryNextRequest();
- },
-
- dispatchQueue : function()
- {
- var self = Prado.CallbackRequest;
- //Logger.warn("dispatching queque, length="+self.requestQueue.length+" request="+self.currentRequest);
- var callback = self.requestQueue.shift();
- self.currentRequest = callback;
-
- //get data
- callback.options.postBody = callback._getPostData(),
-
- //callback.request = new Prado.AjaxRequest(callback);
- callback.timeout = setTimeout(function()
- {
- //Logger.warn("priority timeout");
- self.abortRequest(callback.id);
- },callback.ActiveControl.RequestTimeOut);
- callback.request(callback.url);
- //Logger.debug("dispatched "+self.currentRequest.id + " ...")
- },
-
- endCurrentRequest : function()
- {
- var self = Prado.CallbackRequest;
- if(typeof(self.currentRequest) != 'undefined' && self.currentRequest != null)
- clearTimeout(self.currentRequest.timeout);
- self.currentRequest=null;
- },
-
- abortRequest : function(id)
- {
- //Logger.warn("abort id="+id);
- var self = Prado.CallbackRequest;
- if(typeof(self.currentRequest) != 'undefined'
- && self.currentRequest != null && self.currentRequest.id == id)
- {
- var request = self.currentRequest;
- if(request.transport.readyState < 4)
- request.transport.abort();
- //Logger.warn('## aborted: setting current request to null');
- self.endCurrentRequest();
- }
- self.tryNextRequest();
- }
-});
-
-/**
- * Automatically aborts the current request when a priority request has returned.
- */
-Ajax.Responders.register({onComplete : function(request)
-{
- if(request && request instanceof Prado.AjaxRequest)
- {
- if(request.ActiveControl.HasPriority)
- Prado.CallbackRequest.tryNextRequest();
- }
-}});
-
-//Add HTTP exception respones when logger is enabled.
-Event.OnLoad(function()
-{
- if(typeof Logger != "undefined")
- Ajax.Responders.register(Prado.CallbackRequest.Exception);
-});
-
-/**
- * Create and prepare a new callback request.
- * Call the dispatch() method to start the callback request.
- * <code>
- * request = new Prado.CallbackRequest(UniqueID, callback);
- * request.dispatch();
- * </code>
- */
-Prado.CallbackRequest.prototype = Object.extend(Prado.AjaxRequest.prototype,
-{
-
- /**
- * Prepare and inititate a callback request.
- */
- initialize : function(id, options)
- {
- /**
- * Callback URL, same url as the current page.
- */
- this.url = this.getCallbackUrl();
-
- this.transport = Ajax.getTransport();
- this.Enabled = true;
- this.id = id;
- this.randomId = this.randomString();
-
- if(typeof(id)=="string"){
- Prado.CallbackRequest.requests[id+"__"+this.randomId] = this;
- }
-
- this.setOptions(Object.extend(
- {
- RequestTimeOut : 30000, // 30 second timeout.
- EnablePageStateUpdate : true,
- HasPriority : true,
- CausesValidation : true,
- ValidationGroup : null,
- PostInputs : true
- }, options || {}));
-
- this.ActiveControl = this.options;
- Prado.CallbackRequest.requests[id+"__"+this.randomId].ActiveControl = this.options;
- },
-
- /**
- * Sets the request options
- * @return {Array} request options.
- */
- setOptions: function(options){
-
- this.options = {
- method: 'post',
- asynchronous: true,
- contentType: 'application/x-www-form-urlencoded',
- encoding: 'UTF-8',
- parameters: '',
- evalJSON: true,
- evalJS: true
- };
-
- Object.extend(this.options, options || { });
-
- this.options.method = this.options.method.toLowerCase();
- if(Object.isString(this.options.parameters)){
- this.options.parameters = this.options.parameters.toQueryParams();
- }
- },
-
- /**
- * Gets the url from the forms that contains the PRADO_PAGESTATE
- * @return {String} callback url.
- */
- getCallbackUrl : function()
- {
- return $('PRADO_PAGESTATE').form.action;
- },
-
- /**
- * Sets the request parameter
- * @param {Object} parameter value
- */
- setCallbackParameter : function(value)
- {
- var requestId = this.id+"__"+this.randomId;
- this.ActiveControl['CallbackParameter'] = value;
- Prado.CallbackRequest.requests[requestId].ActiveControl['CallbackParameter'] = value;
- },
-
- /**
- * @return {Object} request paramater value.
- */
- getCallbackParameter : function()
- {
- return Prado.CallbackRequest.requests[this.id+"__"+this.randomId].ActiveControl['CallbackParameter'];
- },
-
- /**
- * Sets the callback request timeout.
- * @param {integer} timeout in milliseconds
- */
- setRequestTimeOut : function(timeout)
- {
- this.ActiveControl['RequestTimeOut'] = timeout;
- },
-
- /**
- * @return {integer} request timeout in milliseconds
- */
- getRequestTimeOut : function()
- {
- return this.ActiveControl['RequestTimeOut'];
- },
-
- /**
- * Set true to enable validation on callback dispatch.
- * @param {boolean} true to validate
- */
- setCausesValidation : function(validate)
- {
- this.ActiveControl['CausesValidation'] = validate;
- },
-
- /**
- * @return {boolean} validate on request dispatch
- */
- getCausesValidation : function()
- {
- return this.ActiveControl['CausesValidation'];
- },
-
- /**
- * Sets the validation group to validate during request dispatch.
- * @param {string} validation group name
- */
- setValidationGroup : function(group)
- {
- this.ActiveControl['ValidationGroup'] = group;
- },
-
- /**
- * @return {string} validation group name.
- */
- getValidationGroup : function()
- {
- return this.ActiveControl['ValidationGroup'];
- },
-
- /**
- * Dispatch the callback request.
- */
- dispatch : function()
- {
- //Logger.info("dispatching request");
- //trigger tinyMCE to save data.
- if(typeof tinyMCE != "undefined")
- tinyMCE.triggerSave();
-
- if(this.ActiveControl.CausesValidation && typeof(Prado.Validation) != "undefined")
- {
- var form = this.ActiveControl.Form || Prado.Validation.getForm();
- if(Prado.Validation.validate(form,this.ActiveControl.ValidationGroup,this) == false)
- return false;
- }
-
- if(this.ActiveControl.onPreDispatch)
- this.ActiveControl.onPreDispatch(this,null);
-
- if(!this.Enabled)
- return;
-
- // Opera don't have onLoading/onLoaded state, so, simulate them just
- // before sending the request.
- if (Prototype.Browser.Opera)
- {
- if (this.ActiveControl.onLoading)
- {
- this.ActiveControl.onLoading(this,null);
- Ajax.Responders.dispatch('onLoading',this, this.transport,null);
- }
- if (this.ActiveControl.onLoaded)
- {
- this.ActiveControl.onLoaded(this,null);
- Ajax.Responders.dispatch('onLoaded',this, this.transport,null);
- }
- }
-
- var result;
- if(this.ActiveControl.HasPriority)
- {
- return Prado.CallbackRequest.enqueue(this);
- //return Prado.CallbackRequest.dispatchPriorityRequest(this);
- }
- else
- return Prado.CallbackRequest.dispatchNormalRequest(this);
- },
-
- abort : function()
- {
- return Prado.CallbackRequest.abortRequest(this.id);
- },
-
- /**
- * Collects the form inputs, encode the parameters, and sets the callback
- * target id. The resulting string is the request content body.
- * @return string request body content containing post data.
- */
- _getPostData : function()
- {
- var data = {};
- var callback = Prado.CallbackRequest;
- if(this.ActiveControl.PostInputs != false)
- {
- callback.PostDataLoaders.each(function(name)
- {
- var elements=$A(document.getElementsByName(name));
- if(elements.size() == 0)
- {
- name += '[]';
- elements=$A(document.getElementsByName(name));
- }
- elements.each(function(element)
- {
- //IE will try to get elements with ID == name as well.
- if(element.type && element.name == name)
- {
- var value = $F(element);
- if(typeof(value) != "undefined" && value != null)
- data[name] = value;
- }
- })
- })
- }
- if(typeof(this.ActiveControl.CallbackParameter) != "undefined")
- data[callback.FIELD_CALLBACK_PARAMETER] = callback.encode(this.getCallbackParameter());
- var pageState = $F(callback.FIELD_CALLBACK_PAGESTATE);
- if(typeof(pageState) != "undefined")
- data[callback.FIELD_CALLBACK_PAGESTATE] = pageState;
- data[callback.FIELD_CALLBACK_TARGET] = this.id;
- if(this.ActiveControl.EventTarget)
- data[callback.FIELD_POSTBACK_TARGET] = this.ActiveControl.EventTarget;
- if(this.ActiveControl.EventParameter)
- data[callback.FIELD_POSTBACK_PARAMETER] = this.ActiveControl.EventParameter;
- return $H(data).toQueryString();
- },
-
- /**
- * Creates a random string with a length of 8 chars.
- * @return string
- */
- randomString : function()
- {
- chars = "abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ1234567890";
- randomString = "";
- for(x=0;x<8;x++)
- randomString += chars.charAt(Math.floor(Math.random() * 62));
- return randomString
- }
-});
-
-/**
- * Create a new callback request using default settings.
- * @param string callback handler unique ID.
- * @param mixed parameter to pass to callback handler on the server side.
- * @param function client side onSuccess event handler.
- * @param object additional request options.
- * @return boolean always false.
- */
-Prado.Callback = function(UniqueID, parameter, onSuccess, options)
-{
- var callback =
- {
- 'CallbackParameter' : parameter || '',
- 'onSuccess' : onSuccess || Prototype.emptyFunction
- };
-
- Object.extend(callback, options || {});
-
- var request = new Prado.CallbackRequest(UniqueID, callback);
- request.dispatch();
- return false;
-};
-
-
-
-/**
- * Asset manager classes for lazy loading of scripts and stylesheets
- * @author Gabor Berczi (gabor.berczi@devworx.hu)
- */
-
-if (typeof(Prado.AssetManagerClass)=="undefined") {
-
- Prado.AssetManagerClass = Class.create();
- Prado.AssetManagerClass.prototype = {
-
- initialize: function() {
- this.loadedAssets = new Array();
- this.discoverLoadedAssets();
- },
-
-
- /**
- * Detect which assets are already loaded by page markup.
- * This is done by looking up all <asset> elements and registering the values of their src attributes.
- */
- discoverLoadedAssets: function() {
-
- // wait until document has finished loading to avoid javascript errors
- if (!document.body) return;
-
- var assets = this.findAssetUrlsInMarkup();
- for(var i=0;i<assets.length;i++)
- this.markAssetAsLoaded(assets[i]);
- },
-
- /**
- * Extend url to a fully qualified url.
- * @param string url
- */
- makeFullUrl: function(url) {
-
- // this is not intended to be a fully blown url "canonicalizator",
- // just to handle the most common and basic asset paths used by Prado
-
- if (!this.baseUri) this.baseUri = window.location;
-
- if (url.indexOf('://')==-1)
- {
- var a = document.createElement('a');
- a.href = url;
-
- if (a.href.indexOf('://')!=-1)
- url = a.href;
- else
- {
- var path = a.pathname;
- if (path.substr(0,1)!='/') path = '/'+path;
- url = this.baseUri.protocol+'//'+this.baseUri.host+path;
- }
- }
- return url;
- },
-
- isAssetLoaded: function(url) {
- url = this.makeFullUrl(url);
- return (this.loadedAssets.indexOf(url)!=-1);
- },
-
- /**
- * Mark asset as being already loaded
- * @param string url of the asset
- */
- markAssetAsLoaded: function(url) {
- url = this.makeFullUrl(url);
- if (this.loadedAssets.indexOf(url)==-1)
- this.loadedAssets.push(url);
- },
-
- assetReadyStateChanged: function(url, element, callback, finalevent) {
- if (finalevent || (element.readyState == 'loaded') || (element.readyState == 'complete'))
- if (!element.assetCallbackFired)
- {
- element.assetCallbackFired = true;
- callback(url,element);
- }
- },
-
- assetLoadFailed: function(url, element, callback) {
- debugger;
- element.assetCallbackFired = true;
- if(typeof Logger != "undefined")
- Logger.error("Failed to load asset: "+url, this);
- if (!element.assetCallbackFired)
- callback(url,element,false);
- },
-
- /**
- * Load a new asset dynamically into the page.
- * Please not thet loading is asynchronous and therefore you can't assume that
- * the asset is loaded and ready when returning from this function.
- * @param string url of the asset to load
- * @param callback will be called when the asset has loaded (or failed to load)
- */
- startAssetLoad: function(url, callback) {
-
- // create new <asset> element in page header
- var asset = this.createAssetElement(url);
-
- if (callback)
- {
- asset.onreadystatechange = this.assetReadyStateChanged.bind(this, url, asset, callback, false);
- asset.onload = this.assetReadyStateChanged.bind(this, url, asset, callback, true);
- asset.onerror = this.assetLoadFailed.bind(this, url, asset, callback);
- asset.assetCallbackFired = false;
- }
-
- var head = document.getElementsByTagName('head')[0];
- head.appendChild(asset);
-
- // mark this asset as loaded
- this.markAssetAsLoaded(url);
-
- return (callback!=false);
- },
-
- /**
- * Check whether a asset is loaded into the page, and if itsn't, load it now
- * @param string url of the asset to check/load
- * @return boolean returns true if asset is already loaded, or false, if loading has just started. callback will be called when loading has finished.
- */
- ensureAssetIsLoaded: function(url, callback) {
- url = this.makeFullUrl(url);
- if (this.loadedAssets.indexOf(url)==-1)
- {
- this.startAssetLoad(url,callback);
- return false;
- }
- else
- return true;
- }
-
- }
-
-};
-
- Prado.ScriptManagerClass = Class.extend(Prado.AssetManagerClass, {
-
- findAssetUrlsInMarkup: function() {
- var urls = new Array();
- var scripts = document.getElementsByTagName('script');
- for(var i=0;i<scripts.length;i++)
- {
- var e = scripts[i]; var src = e.src;
- if (src!="")
- urls.push(src);
- }
- return urls;
- },
-
- createAssetElement: function(url) {
- var asset = document.createElement('script');
- asset.type = 'text/javascript';
- asset.src = url;
-// asset.async = false; // HTML5 only
- return asset;
- }
-
- });
-
- Prado.StyleSheetManagerClass = Class.extend(Prado.AssetManagerClass, {
-
- findAssetUrlsInMarkup: function() {
- var urls = new Array();
- var scripts = document.getElementsByTagName('link');
- for(var i=0;i<scripts.length;i++)
- {
- var e = scripts[i]; var href = e.href;
- if ((e.rel=="stylesheet") && (href.length>0))
- urls.push(href);
- }
- return urls;
- },
-
- createAssetElement: function(url) {
- var asset = document.createElement('link');
- asset.rel = 'stylesheet';
- asset.media = 'screen';
- asset.setAttribute('type', 'text/css');
- asset.href = url;
-// asset.async = false; // HTML5 only
- return asset;
- }
-
- });
-
- if (typeof(Prado.ScriptManager)=="undefined") Prado.ScriptManager = new Prado.ScriptManagerClass();
- if (typeof(Prado.StyleSheetManager)=="undefined") Prado.StyleSheetManager = new Prado.StyleSheetManagerClass();
-
- // make sure we scan for loaded scripts again when the page has been loaded
- var discover = function() {
- Prado.ScriptManager.discoverLoadedAssets();
- Prado.StyleSheetManager.discoverLoadedAssets();
- }
- if (window.attachEvent) window.attachEvent('onload', discover);
- else if (window.addEventListener) window.addEventListener('load', discover, false);
-
+
+Prado.AjaxRequest = Class.create();
+Prado.AjaxRequest.prototype = Object.clone(Ajax.Request.prototype);
+
+/**
+ * Override Prototype's response implementation.
+ */
+Object.extend(Prado.AjaxRequest.prototype,
+{
+ /*initialize: function(request)
+ {
+ this.CallbackRequest = request;
+ this.transport = Ajax.getTransport();
+ this.setOptions(request.options);
+ this.request(request.url);
+ },*/
+
+ /**
+ * Customize the response, dispatch onXXX response code events, and
+ * tries to execute response actions (javascript statements).
+ */
+ respondToReadyState : function(readyState)
+ {
+ var event = Ajax.Request.Events[readyState];
+ var transport = this.transport, json = this.getBodyDataPart(Prado.CallbackRequest.DATA_HEADER);
+
+ if (event == 'Complete')
+ {
+ var redirectUrl = this.getBodyContentPart(Prado.CallbackRequest.REDIRECT_HEADER);
+ if (redirectUrl)
+ document.location.href = redirectUrl;
+
+ if ((this.getHeader('Content-type') || '').match(/^text\/javascript/i))
+ {
+ try
+ {
+ json = eval('(' + transport.responseText + ')');
+ }
+ catch (e)
+ {
+ if(typeof(json) == "string")
+ json = Prado.CallbackRequest.decode(result);
+ }
+ }
+
+ try
+ {
+ Prado.CallbackRequest.updatePageState(this,transport);
+ Prado.CallbackRequest.checkHiddenFields(this,transport);
+ var obj = this;
+ Prado.CallbackRequest.loadAssets(this,transport, function()
+
+ {
+ try
+ {
+ Ajax.Responders.dispatch('on' + transport.status, obj, transport, json);
+ Prado.CallbackRequest.dispatchActions(transport,obj.getBodyDataPart(Prado.CallbackRequest.ACTION_HEADER));
+
+ (
+ obj.options['on' + obj.transport.status]
+ ||
+ obj.options['on' + (obj.success() ? 'Success' : 'Failure')]
+ ||
+ Prototype.emptyFunction
+ ) (obj, json);
+ }
+ catch (e)
+ {
+ obj.dispatchException(e);
+ }
+ }
+ );
+ }
+ catch (e)
+ {
+ this.dispatchException(e);
+ }
+ }
+
+ try {
+ (this.options['on' + event] || Prototype.emptyFunction)(this, json);
+ Ajax.Responders.dispatch('on' + event, this, transport, json);
+ } catch (e) {
+ this.dispatchException(e);
+ }
+
+ /* Avoid memory leak in MSIE: clean up the oncomplete event handler */
+ if (event == 'Complete')
+ this.transport.onreadystatechange = Prototype.emptyFunction;
+ },
+
+ /**
+ * Gets header data assuming JSON encoding.
+ * @param string header name
+ * @return object header data as javascript structures.
+ */
+ getHeaderData : function(name)
+ {
+ return this.getJsonData(this.getHeader(name));
+ },
+
+ getBodyContentPart : function(name)
+ {
+ if(typeof(this.transport.responseText)=="string")
+ return Prado.Element.extractContent(this.transport.responseText, name);
+ },
+
+ getJsonData : function(json)
+ {
+ try
+ {
+ return eval('(' + json + ')');
+ }
+ catch (e)
+ {
+ if(typeof(json) == "string")
+ return Prado.CallbackRequest.decode(json);
+ }
+ },
+
+ getBodyDataPart : function(name)
+ {
+ return this.getJsonData(this.getBodyContentPart(name));
+ }
+});
+
+/**
+ * Prado Callback client-side request handler.
+ */
+Prado.CallbackRequest = Class.create();
+
+/**
+ * Static definitions.
+ */
+Object.extend(Prado.CallbackRequest,
+{
+ /**
+ * Callback request target POST field name.
+ */
+ FIELD_CALLBACK_TARGET : 'PRADO_CALLBACK_TARGET',
+ /**
+ * Callback request parameter POST field name.
+ */
+ FIELD_CALLBACK_PARAMETER : 'PRADO_CALLBACK_PARAMETER',
+ /**
+ * Callback request page state field name,
+ */
+ FIELD_CALLBACK_PAGESTATE : 'PRADO_PAGESTATE',
+
+ FIELD_POSTBACK_TARGET : 'PRADO_POSTBACK_TARGET',
+
+ FIELD_POSTBACK_PARAMETER : 'PRADO_POSTBACK_PARAMETER',
+
+ /**
+ * List of form fields that will be collected during callback.
+ */
+ PostDataLoaders : [],
+ /**
+ * Response data header name.
+ */
+ DATA_HEADER : 'X-PRADO-DATA',
+ /**
+ * Response javascript execution statement header name.
+ */
+ ACTION_HEADER : 'X-PRADO-ACTIONS',
+ /**
+ * Response errors/exceptions header name.
+ */
+ ERROR_HEADER : 'X-PRADO-ERROR',
+ /**
+ * Page state header name.
+ */
+ PAGESTATE_HEADER : 'X-PRADO-PAGESTATE',
+ /**
+ * Script list header name.
+ */
+ SCRIPTLIST_HEADER : 'X-PRADO-SCRIPTLIST',
+ /**
+ * Stylesheet list header name.
+ */
+ STYLESHEETLIST_HEADER : 'X-PRADO-STYLESHEETLIST',
+ /**
+ * Hidden field list header name.
+ */
+ HIDDENFIELDLIST_HEADER : 'X-PRADO-HIDDENFIELDLIST',
+
+ REDIRECT_HEADER : 'X-PRADO-REDIRECT',
+
+ requestQueue : [],
+
+ //all request objects
+ requests : {},
+
+ getRequestById : function(id)
+ {
+ var requests = Prado.CallbackRequest.requests;
+ if(typeof(requests[id]) != "undefined")
+ return requests[id];
+ },
+
+ dispatch : function(id)
+ {
+ var requests = Prado.CallbackRequest.requests;
+ if(typeof(requests[id]) != "undefined")
+ requests[id].dispatch();
+ },
+
+ /**
+ * Add ids of inputs element to post in the request.
+ */
+ addPostLoaders : function(ids)
+ {
+ var self = Prado.CallbackRequest;
+ self.PostDataLoaders = self.PostDataLoaders.concat(ids);
+ var list = [];
+ self.PostDataLoaders.each(function(id)
+ {
+ if(list.indexOf(id) < 0)
+ list.push(id);
+ });
+ self.PostDataLoaders = list;
+ },
+
+ /**
+ * Dispatch callback response actions.
+ */
+ dispatchActions : function(transport,actions)
+ {
+ var self = Prado.CallbackRequest;
+ if(actions && actions.length > 0)
+ actions.each(self.__run.bind(self,transport));
+ },
+
+ /**
+ * Prase and evaluate a Callback clien-side action
+ */
+ __run : function(transport, command)
+ {
+ var self = Prado.CallbackRequest;
+ self.transport = transport;
+ for(var method in command)
+ {
+ try
+ {
+ method.toFunction().apply(self,command[method]);
+ }
+ catch(e)
+ {
+ if(typeof(Logger) != "undefined")
+ self.Exception.onException(null,e);
+ else
+ debugger;
+ }
+ }
+ },
+
+ /**
+ * Respond to Prado Callback request exceptions.
+ */
+ Exception :
+ {
+ /**
+ * Server returns 500 exception. Just log it.
+ */
+ "on500" : function(request, transport, data)
+ {
+ var e = request.getHeaderData(Prado.CallbackRequest.ERROR_HEADER);
+ if (e)
+ Logger.error("Callback Server Error "+e.code, this.formatException(e));
+ else
+ Logger.error("Callback Server Error Unknown",'');
+ },
+
+ /**
+ * Callback OnComplete event,logs reponse and data to console.
+ */
+ 'on200' : function(request, transport, data)
+ {
+ if(transport.status < 500)
+ {
+ var msg = 'HTTP '+transport.status+" with response : \n";
+ if(transport.responseText.trim().length >0)
+ {
+ var f = RegExp('(<!--X-PRADO[^>]+-->)([\\s\\S\\w\\W]*)(<!--//X-PRADO[^>]+-->)',"m");
+ msg += transport.responseText.replace(f,'') + "\n";
+ }
+ if(typeof(data)!="undefined" && data != null)
+ msg += "Data : \n"+inspect(data)+"\n";
+ data = request.getBodyDataPart(Prado.CallbackRequest.ACTION_HEADER);
+ if(data && data.length > 0)
+ {
+ msg += "Actions : \n";
+ data.each(function(action)
+ {
+ msg += inspect(action)+"\n";
+ });
+ }
+ Logger.info(msg);
+ }
+ },
+
+ /**
+ * Uncaught exceptions during callback response.
+ */
+ onException : function(request,e)
+ {
+ var msg = "";
+ $H(e).each(function(item)
+ {
+ msg += item.key+": "+item.value+"\n";
+ })
+ Logger.error('Uncaught Callback Client Exception:', msg);
+ },
+
+ /**
+ * Formats the exception message for display in console.
+ */
+ formatException : function(e)
+ {
+ var msg = e.type + " with message \""+e.message+"\"";
+ msg += " in "+e.file+"("+e.line+")\n";
+ msg += "Stack trace:\n";
+ var trace = e.trace;
+ for(var i = 0; i<trace.length; i++)
+ {
+ msg += " #"+i+" "+trace[i].file;
+ msg += "("+trace[i].line+"): ";
+ msg += trace[i]["class"]+"->"+trace[i]["function"]+"()"+"\n";
+ }
+ msg += e.version+" "+e.time+"\n";
+ return msg;
+ }
+ },
+
+ /**
+ * @return string JSON encoded data.
+ */
+ encode : function(data)
+ {
+ return Prado.JSON.stringify(data);
+ },
+
+ /**
+ * @return mixed javascript data decoded from string using JSON decoding.
+ */
+ decode : function(data)
+ {
+ if(typeof(data) == "string" && data.trim().length > 0)
+ return Prado.JSON.parse(data);
+ else
+ return null;
+ },
+
+ /**
+ * Dispatch a normal request, no timeouts or aborting of requests.
+ */
+ dispatchNormalRequest : function(callback)
+ {
+ callback.options.postBody = callback._getPostData(),
+ callback.request(callback.url);
+ return true;
+ },
+
+ /**
+ * Abort the current priority request in progress.
+ */
+ tryNextRequest : function()
+ {
+ var self = Prado.CallbackRequest;
+ //Logger.debug('trying next request');
+ if(typeof(self.currentRequest) == 'undefined' || self.currentRequest==null)
+ {
+ if(self.requestQueue.length > 0)
+ return self.dispatchQueue();
+ //else
+ //Logger.warn('empty queque');
+ }
+ //else
+ //Logger.warn('current request ' + self.currentRequest.id);
+ },
+
+ /*
+ * Checks which scripts are used by the response and ensures they're loaded
+ */
+ loadScripts : function(request, transport, callback)
+ {
+ var self = Prado.CallbackRequest;
+ var data = request.getBodyContentPart(self.SCRIPTLIST_HEADER);
+ if (!this.ScriptsToLoad) this.ScriptsToLoad = new Array();
+ this.ScriptLoadFinishedCallback = callback;
+ if (typeof(data) == "string" && data.length > 0)
+ {
+ json = Prado.CallbackRequest.decode(data);
+ if(typeof(json) != "object")
+ Logger.warn("Invalid script list:"+data);
+ else
+ for(var key in json)
+ if (/^\d+$/.test(key))
+ {
+ var url = json[key];
+ if (!Prado.ScriptManager.isAssetLoaded(url))
+ this.ScriptsToLoad.push(url);
+ }
+ }
+ this.loadNextScript();
+ },
+
+ loadNextScript: function()
+ {
+ var done = (!this.ScriptsToLoad || (this.ScriptsToLoad.length==0));
+ if (!done)
+ {
+ var url = this.ScriptsToLoad.shift(); var obj = this;
+ if (
+ Prado.ScriptManager.ensureAssetIsLoaded(url,
+ function() {
+ obj.loadNextScript();
+ }
+ )
+ )
+ this.loadNextScript();
+ }
+ else
+ {
+ if (this.ScriptLoadFinishedCallback)
+ {
+ var cb = this.ScriptLoadFinishedCallback;
+ this.ScriptLoadFinishedCallback = null;
+ cb();
+ }
+ }
+ },
+
+ loadStyleSheetsAsync : function(request, transport)
+ {
+ var self = Prado.CallbackRequest;
+ var data = request.getBodyContentPart(self.STYLESHEETLIST_HEADER);
+ if (typeof(data) == "string" && data.length > 0)
+ {
+ json = Prado.CallbackRequest.decode(data);
+ if(typeof(json) != "object")
+ Logger.warn("Invalid stylesheet list:"+data);
+ else
+ for(var key in json)
+ if (/^\d+$/.test(key))
+ Prado.StyleSheetManager.ensureAssetIsLoaded(json[key],null);
+ }
+ },
+
+ loadStyleSheets : function(request, transport, callback)
+ {
+ var self = Prado.CallbackRequest;
+ var data = request.getBodyContentPart(self.STYLESHEETLIST_HEADER);
+ if (!this.StyleSheetsToLoad) this.StyleSheetsToLoad = new Array();
+ this.StyleSheetLoadFinishedCallback = callback;
+ if (typeof(data) == "string" && data.length > 0)
+ {
+ json = Prado.CallbackRequest.decode(data);
+ if(typeof(json) != "object")
+ Logger.warn("Invalid stylesheet list:"+data);
+ else
+ for(var key in json)
+ if (/^\d+$/.test(key))
+ {
+ var url = json[key];
+ if (!Prado.StyleSheetManager.isAssetLoaded(url))
+ this.StyleSheetsToLoad.push(url);
+ }
+ }
+ this.loadNextStyleSheet();
+ },
+
+ loadNextStyleSheet: function()
+ {
+ var done = (!this.StyleSheetsToLoad || (this.StyleSheetsToLoad.length==0));
+ if (!done)
+ {
+ var url = this.StyleSheetsToLoad.shift(); var obj = this;
+ if (
+ Prado.StyleSheetManager.ensureAssetIsLoaded(url,
+ function() {
+ obj.loadNextStyleSheet();
+ }
+ )
+ )
+ this.loadNextStyleSheet();
+ }
+ else
+ {
+ if (this.StyleSheetLoadFinishedCallback)
+ {
+ var cb = this.StyleSheetLoadFinishedCallback;
+ this.StyleSheetLoadFinishedCallback = null;
+ cb();
+ }
+ }
+ },
+
+ /*
+ * Checks which assets are used by the response and ensures they're loaded
+ */
+ loadAssets : function(request, transport, callback)
+ {
+ /*
+
+ ! This is the callback-based loader for stylesheets, which loads them one-by-one, and
+ ! waits for all of them to be loaded before loading scripts and processing the rest of
+ ! the callback.
+ !
+ ! That however is not neccessary, as stylesheets can be loaded asynchronously too.
+ !
+ ! I leave this code here for the case that this turns out to be a compatibility issue
+ ! (for ex. I can imagine some scripts trying to access stylesheet properties and such)
+ ! so if need can be reactivated. If you do so, comment out the async stylesheet loader below!
+
+ var obj = this;
+ this.loadStyleSheets(request,transport, function() {
+ obj.loadScripts(request,transport,callback);
+ });
+
+ */
+
+ this.loadStyleSheetsAsync(request,transport);
+
+ this.loadScripts(request,transport,callback);
+ },
+
+ checkHiddenField: function(name, value)
+ {
+ var id = name.replace(':','_');
+ if (!document.getElementById(id))
+ {
+ var field = document.createElement('input');
+ field.setAttribute('type','hidden');
+ field.id = id;
+ field.name = name;
+ field.value = value;
+ document.body.appendChild(field);
+ }
+ },
+
+ checkHiddenFields : function(request, transport)
+ {
+ var self = Prado.CallbackRequest;
+ var data = request.getBodyContentPart(self.HIDDENFIELDLIST_HEADER);
+ if (typeof(data) == "string" && data.length > 0)
+ {
+ json = Prado.CallbackRequest.decode(data);
+ if(typeof(json) != "object")
+ Logger.warn("Invalid hidden field list:"+data);
+ else
+ for(var key in json)
+ this.checkHiddenField(key,json[key]);
+ }
+ },
+
+ /**
+ * Updates the page state. It will update only if EnablePageStateUpdate and
+ * HasPriority options are both true.
+ */
+ updatePageState : function(request, transport)
+ {
+ var self = Prado.CallbackRequest;
+ var pagestate = $(self.FIELD_CALLBACK_PAGESTATE);
+ var enabled = request.ActiveControl.EnablePageStateUpdate && request.ActiveControl.HasPriority;
+ var aborted = typeof(self.currentRequest) == 'undefined' || self.currentRequest == null;
+ if(enabled && !aborted && pagestate)
+ {
+ var data = request.getBodyContentPart(self.PAGESTATE_HEADER);
+ if(typeof(data) == "string" && data.length > 0)
+ pagestate.value = data;
+ else
+ {
+ if(typeof(Logger) != "undefined")
+ Logger.warn("Missing page state:"+data);
+ //Logger.warn('## bad state: setting current request to null');
+ self.endCurrentRequest();
+ //self.tryNextRequest();
+ return false;
+ }
+ }
+ self.endCurrentRequest();
+ //Logger.warn('## state updated: setting current request to null');
+ //self.tryNextRequest();
+ return true;
+ },
+
+ enqueue : function(callback)
+ {
+ var self = Prado.CallbackRequest;
+ self.requestQueue.push(callback);
+ //Logger.warn("equeued "+callback.id+", current queque length="+self.requestQueue.length);
+ self.tryNextRequest();
+ },
+
+ dispatchQueue : function()
+ {
+ var self = Prado.CallbackRequest;
+ //Logger.warn("dispatching queque, length="+self.requestQueue.length+" request="+self.currentRequest);
+ var callback = self.requestQueue.shift();
+ self.currentRequest = callback;
+
+ //get data
+ callback.options.postBody = callback._getPostData(),
+
+ //callback.request = new Prado.AjaxRequest(callback);
+ callback.timeout = setTimeout(function()
+ {
+ //Logger.warn("priority timeout");
+ self.abortRequest(callback.id);
+ },callback.ActiveControl.RequestTimeOut);
+ callback.request(callback.url);
+ //Logger.debug("dispatched "+self.currentRequest.id + " ...")
+ },
+
+ endCurrentRequest : function()
+ {
+ var self = Prado.CallbackRequest;
+ if(typeof(self.currentRequest) != 'undefined' && self.currentRequest != null)
+ clearTimeout(self.currentRequest.timeout);
+ self.currentRequest=null;
+ },
+
+ abortRequest : function(id)
+ {
+ //Logger.warn("abort id="+id);
+ var self = Prado.CallbackRequest;
+ if(typeof(self.currentRequest) != 'undefined'
+ && self.currentRequest != null && self.currentRequest.id == id)
+ {
+ var request = self.currentRequest;
+ if(request.transport.readyState < 4)
+ request.transport.abort();
+ //Logger.warn('## aborted: setting current request to null');
+ self.endCurrentRequest();
+ }
+ self.tryNextRequest();
+ }
+});
+
+/**
+ * Automatically aborts the current request when a priority request has returned.
+ */
+Ajax.Responders.register({onComplete : function(request)
+{
+ if(request && request instanceof Prado.AjaxRequest)
+ {
+ if(request.ActiveControl.HasPriority)
+ Prado.CallbackRequest.tryNextRequest();
+ }
+}});
+
+//Add HTTP exception respones when logger is enabled.
+Event.OnLoad(function()
+{
+ if(typeof Logger != "undefined")
+ Ajax.Responders.register(Prado.CallbackRequest.Exception);
+});
+
+/**
+ * Create and prepare a new callback request.
+ * Call the dispatch() method to start the callback request.
+ * <code>
+ * request = new Prado.CallbackRequest(UniqueID, callback);
+ * request.dispatch();
+ * </code>
+ */
+Prado.CallbackRequest.prototype = Object.extend(Prado.AjaxRequest.prototype,
+{
+
+ /**
+ * Prepare and inititate a callback request.
+ */
+ initialize : function(id, options)
+ {
+ /**
+ * Callback URL, same url as the current page.
+ */
+ this.url = this.getCallbackUrl();
+
+ this.transport = Ajax.getTransport();
+ this.Enabled = true;
+ this.id = id;
+ this.randomId = this.randomString();
+
+ if(typeof(id)=="string"){
+ Prado.CallbackRequest.requests[id+"__"+this.randomId] = this;
+ }
+
+ this.setOptions(Object.extend(
+ {
+ RequestTimeOut : 30000, // 30 second timeout.
+ EnablePageStateUpdate : true,
+ HasPriority : true,
+ CausesValidation : true,
+ ValidationGroup : null,
+ PostInputs : true
+ }, options || {}));
+
+ this.ActiveControl = this.options;
+ Prado.CallbackRequest.requests[id+"__"+this.randomId].ActiveControl = this.options;
+ },
+
+ /**
+ * Sets the request options
+ * @return {Array} request options.
+ */
+ setOptions: function(options){
+
+ this.options = {
+ method: 'post',
+ asynchronous: true,
+ contentType: 'application/x-www-form-urlencoded',
+ encoding: 'UTF-8',
+ parameters: '',
+ evalJSON: true,
+ evalJS: true
+ };
+
+ Object.extend(this.options, options || { });
+
+ this.options.method = this.options.method.toLowerCase();
+ if(Object.isString(this.options.parameters)){
+ this.options.parameters = this.options.parameters.toQueryParams();
+ }
+ },
+
+ /**
+ * Gets the url from the forms that contains the PRADO_PAGESTATE
+ * @return {String} callback url.
+ */
+ getCallbackUrl : function()
+ {
+ return $('PRADO_PAGESTATE').form.action;
+ },
+
+ /**
+ * Sets the request parameter
+ * @param {Object} parameter value
+ */
+ setCallbackParameter : function(value)
+ {
+ var requestId = this.id+"__"+this.randomId;
+ this.ActiveControl['CallbackParameter'] = value;
+ Prado.CallbackRequest.requests[requestId].ActiveControl['CallbackParameter'] = value;
+ },
+
+ /**
+ * @return {Object} request paramater value.
+ */
+ getCallbackParameter : function()
+ {
+ return Prado.CallbackRequest.requests[this.id+"__"+this.randomId].ActiveControl['CallbackParameter'];
+ },
+
+ /**
+ * Sets the callback request timeout.
+ * @param {integer} timeout in milliseconds
+ */
+ setRequestTimeOut : function(timeout)
+ {
+ this.ActiveControl['RequestTimeOut'] = timeout;
+ },
+
+ /**
+ * @return {integer} request timeout in milliseconds
+ */
+ getRequestTimeOut : function()
+ {
+ return this.ActiveControl['RequestTimeOut'];
+ },
+
+ /**
+ * Set true to enable validation on callback dispatch.
+ * @param {boolean} true to validate
+ */
+ setCausesValidation : function(validate)
+ {
+ this.ActiveControl['CausesValidation'] = validate;
+ },
+
+ /**
+ * @return {boolean} validate on request dispatch
+ */
+ getCausesValidation : function()
+ {
+ return this.ActiveControl['CausesValidation'];
+ },
+
+ /**
+ * Sets the validation group to validate during request dispatch.
+ * @param {string} validation group name
+ */
+ setValidationGroup : function(group)
+ {
+ this.ActiveControl['ValidationGroup'] = group;
+ },
+
+ /**
+ * @return {string} validation group name.
+ */
+ getValidationGroup : function()
+ {
+ return this.ActiveControl['ValidationGroup'];
+ },
+
+ /**
+ * Dispatch the callback request.
+ */
+ dispatch : function()
+ {
+ //Logger.info("dispatching request");
+ //trigger tinyMCE to save data.
+ if(typeof tinyMCE != "undefined")
+ tinyMCE.triggerSave();
+
+ if(this.ActiveControl.CausesValidation && typeof(Prado.Validation) != "undefined")
+ {
+ var form = this.ActiveControl.Form || Prado.Validation.getForm();
+ if(Prado.Validation.validate(form,this.ActiveControl.ValidationGroup,this) == false)
+ return false;
+ }
+
+ if(this.ActiveControl.onPreDispatch)
+ this.ActiveControl.onPreDispatch(this,null);
+
+ if(!this.Enabled)
+ return;
+
+ // Opera don't have onLoading/onLoaded state, so, simulate them just
+ // before sending the request.
+ if (Prototype.Browser.Opera)
+ {
+ if (this.ActiveControl.onLoading)
+ {
+ this.ActiveControl.onLoading(this,null);
+ Ajax.Responders.dispatch('onLoading',this, this.transport,null);
+ }
+ if (this.ActiveControl.onLoaded)
+ {
+ this.ActiveControl.onLoaded(this,null);
+ Ajax.Responders.dispatch('onLoaded',this, this.transport,null);
+ }
+ }
+
+ var result;
+ if(this.ActiveControl.HasPriority)
+ {
+ return Prado.CallbackRequest.enqueue(this);
+ //return Prado.CallbackRequest.dispatchPriorityRequest(this);
+ }
+ else
+ return Prado.CallbackRequest.dispatchNormalRequest(this);
+ },
+
+ abort : function()
+ {
+ return Prado.CallbackRequest.abortRequest(this.id);
+ },
+
+ /**
+ * Collects the form inputs, encode the parameters, and sets the callback
+ * target id. The resulting string is the request content body.
+ * @return string request body content containing post data.
+ */
+ _getPostData : function()
+ {
+ var data = {};
+ var callback = Prado.CallbackRequest;
+ if(this.ActiveControl.PostInputs != false)
+ {
+ callback.PostDataLoaders.each(function(name)
+ {
+ var elements=$A(document.getElementsByName(name));
+ if(elements.size() == 0)
+ {
+ name += '[]';
+ elements=$A(document.getElementsByName(name));
+ }
+ elements.each(function(element)
+ {
+ //IE will try to get elements with ID == name as well.
+ if(element.type && element.name == name)
+ {
+ var value = $F(element);
+ if(typeof(value) != "undefined" && value != null)
+ data[name] = value;
+ }
+ })
+ })
+ }
+ if(typeof(this.ActiveControl.CallbackParameter) != "undefined")
+ data[callback.FIELD_CALLBACK_PARAMETER] = callback.encode(this.getCallbackParameter());
+ var pageState = $F(callback.FIELD_CALLBACK_PAGESTATE);
+ if(typeof(pageState) != "undefined")
+ data[callback.FIELD_CALLBACK_PAGESTATE] = pageState;
+ data[callback.FIELD_CALLBACK_TARGET] = this.id;
+ if(this.ActiveControl.EventTarget)
+ data[callback.FIELD_POSTBACK_TARGET] = this.ActiveControl.EventTarget;
+ if(this.ActiveControl.EventParameter)
+ data[callback.FIELD_POSTBACK_PARAMETER] = this.ActiveControl.EventParameter;
+ return $H(data).toQueryString();
+ },
+
+ /**
+ * Creates a random string with a length of 8 chars.
+ * @return string
+ */
+ randomString : function()
+ {
+ chars = "abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ1234567890";
+ randomString = "";
+ for(x=0;x<8;x++)
+ randomString += chars.charAt(Math.floor(Math.random() * 62));
+ return randomString
+ }
+});
+
+/**
+ * Create a new callback request using default settings.
+ * @param string callback handler unique ID.
+ * @param mixed parameter to pass to callback handler on the server side.
+ * @param function client side onSuccess event handler.
+ * @param object additional request options.
+ * @return boolean always false.
+ */
+Prado.Callback = function(UniqueID, parameter, onSuccess, options)
+{
+ var callback =
+ {
+ 'CallbackParameter' : parameter || '',
+ 'onSuccess' : onSuccess || Prototype.emptyFunction
+ };
+
+ Object.extend(callback, options || {});
+
+ var request = new Prado.CallbackRequest(UniqueID, callback);
+ request.dispatch();
+ return false;
+};
+
+
+
+/**
+ * Asset manager classes for lazy loading of scripts and stylesheets
+ * @author Gabor Berczi (gabor.berczi@devworx.hu)
+ */
+
+if (typeof(Prado.AssetManagerClass)=="undefined") {
+
+ Prado.AssetManagerClass = Class.create();
+ Prado.AssetManagerClass.prototype = {
+
+ initialize: function() {
+ this.loadedAssets = new Array();
+ this.discoverLoadedAssets();
+ },
+
+
+ /**
+ * Detect which assets are already loaded by page markup.
+ * This is done by looking up all <asset> elements and registering the values of their src attributes.
+ */
+ discoverLoadedAssets: function() {
+
+ // wait until document has finished loading to avoid javascript errors
+ if (!document.body) return;
+
+ var assets = this.findAssetUrlsInMarkup();
+ for(var i=0;i<assets.length;i++)
+ this.markAssetAsLoaded(assets[i]);
+ },
+
+ /**
+ * Extend url to a fully qualified url.
+ * @param string url
+ */
+ makeFullUrl: function(url) {
+
+ // this is not intended to be a fully blown url "canonicalizator",
+ // just to handle the most common and basic asset paths used by Prado
+
+ if (!this.baseUri) this.baseUri = window.location;
+
+ if (url.indexOf('://')==-1)
+ {
+ var a = document.createElement('a');
+ a.href = url;
+
+ if (a.href.indexOf('://')!=-1)
+ url = a.href;
+ else
+ {
+ var path = a.pathname;
+ if (path.substr(0,1)!='/') path = '/'+path;
+ url = this.baseUri.protocol+'//'+this.baseUri.host+path;
+ }
+ }
+ return url;
+ },
+
+ isAssetLoaded: function(url) {
+ url = this.makeFullUrl(url);
+ return (this.loadedAssets.indexOf(url)!=-1);
+ },
+
+ /**
+ * Mark asset as being already loaded
+ * @param string url of the asset
+ */
+ markAssetAsLoaded: function(url) {
+ url = this.makeFullUrl(url);
+ if (this.loadedAssets.indexOf(url)==-1)
+ this.loadedAssets.push(url);
+ },
+
+ assetReadyStateChanged: function(url, element, callback, finalevent) {
+ if (finalevent || (element.readyState == 'loaded') || (element.readyState == 'complete'))
+ if (!element.assetCallbackFired)
+ {
+ element.assetCallbackFired = true;
+ callback(url,element);
+ }
+ },
+
+ assetLoadFailed: function(url, element, callback) {
+ debugger;
+ element.assetCallbackFired = true;
+ if(typeof Logger != "undefined")
+ Logger.error("Failed to load asset: "+url, this);
+ if (!element.assetCallbackFired)
+ callback(url,element,false);
+ },
+
+ /**
+ * Load a new asset dynamically into the page.
+ * Please not thet loading is asynchronous and therefore you can't assume that
+ * the asset is loaded and ready when returning from this function.
+ * @param string url of the asset to load
+ * @param callback will be called when the asset has loaded (or failed to load)
+ */
+ startAssetLoad: function(url, callback) {
+
+ // create new <asset> element in page header
+ var asset = this.createAssetElement(url);
+
+ if (callback)
+ {
+ asset.onreadystatechange = this.assetReadyStateChanged.bind(this, url, asset, callback, false);
+ asset.onload = this.assetReadyStateChanged.bind(this, url, asset, callback, true);
+ asset.onerror = this.assetLoadFailed.bind(this, url, asset, callback);
+ asset.assetCallbackFired = false;
+ }
+
+ var head = document.getElementsByTagName('head')[0];
+ head.appendChild(asset);
+
+ // mark this asset as loaded
+ this.markAssetAsLoaded(url);
+
+ return (callback!=false);
+ },
+
+ /**
+ * Check whether a asset is loaded into the page, and if itsn't, load it now
+ * @param string url of the asset to check/load
+ * @return boolean returns true if asset is already loaded, or false, if loading has just started. callback will be called when loading has finished.
+ */
+ ensureAssetIsLoaded: function(url, callback) {
+ url = this.makeFullUrl(url);
+ if (this.loadedAssets.indexOf(url)==-1)
+ {
+ this.startAssetLoad(url,callback);
+ return false;
+ }
+ else
+ return true;
+ }
+
+ }
+
+};
+
+ Prado.ScriptManagerClass = Class.extend(Prado.AssetManagerClass, {
+
+ findAssetUrlsInMarkup: function() {
+ var urls = new Array();
+ var scripts = document.getElementsByTagName('script');
+ for(var i=0;i<scripts.length;i++)
+ {
+ var e = scripts[i]; var src = e.src;
+ if (src!="")
+ urls.push(src);
+ }
+ return urls;
+ },
+
+ createAssetElement: function(url) {
+ var asset = document.createElement('script');
+ asset.type = 'text/javascript';
+ asset.src = url;
+// asset.async = false; // HTML5 only
+ return asset;
+ }
+
+ });
+
+ Prado.StyleSheetManagerClass = Class.extend(Prado.AssetManagerClass, {
+
+ findAssetUrlsInMarkup: function() {
+ var urls = new Array();
+ var scripts = document.getElementsByTagName('link');
+ for(var i=0;i<scripts.length;i++)
+ {
+ var e = scripts[i]; var href = e.href;
+ if ((e.rel=="stylesheet") && (href.length>0))
+ urls.push(href);
+ }
+ return urls;
+ },
+
+ createAssetElement: function(url) {
+ var asset = document.createElement('link');
+ asset.rel = 'stylesheet';
+ asset.media = 'screen';
+ asset.setAttribute('type', 'text/css');
+ asset.href = url;
+// asset.async = false; // HTML5 only
+ return asset;
+ }
+
+ });
+
+ if (typeof(Prado.ScriptManager)=="undefined") Prado.ScriptManager = new Prado.ScriptManagerClass();
+ if (typeof(Prado.StyleSheetManager)=="undefined") Prado.StyleSheetManager = new Prado.StyleSheetManagerClass();
+
+ // make sure we scan for loaded scripts again when the page has been loaded
+ var discover = function() {
+ Prado.ScriptManager.discoverLoadedAssets();
+ Prado.StyleSheetManager.discoverLoadedAssets();
+ }
+ if (window.attachEvent) window.attachEvent('onload', discover);
+ else if (window.addEventListener) window.addEventListener('load', discover, false);
+
diff --git a/framework/Web/Javascripts/source/prado/activecontrols/dragdrop.js b/framework/Web/Javascripts/source/prado/activecontrols/dragdrop.js
index 59c62cc2..511c2ab9 100755
--- a/framework/Web/Javascripts/source/prado/activecontrols/dragdrop.js
+++ b/framework/Web/Javascripts/source/prado/activecontrols/dragdrop.js
@@ -1,61 +1,61 @@
-/**
- * DropContainer control
- */
-
-Prado.WebUI.DropContainer = Class.create(Prado.WebUI.CallbackControl,
-{
- onInit: function(options)
- {
- this.options = options;
- Object.extend (this.options,
- {
- onDrop: this.onDrop.bind(this)
- });
-
- Droppables.add (options.ID, this.options);
- },
-
- onDrop: function(dragElement, dropElement, event)
- {
- var elementId=dragElement.id.replace(/clone_/,"");
- var req = new Prado.CallbackRequest(this.options.EventTarget, this.options);
- var curleft = curtop = 0;
- var obj = dropElement;
- if (obj.offsetParent) {
- curleft = obj.offsetLeft
- curtop = obj.offsetTop
- while (obj = obj.offsetParent) {
- curleft += obj.offsetLeft
- curtop += obj.offsetTop
- }
- }
- var scrOfX = 0, scrOfY = 0;
- if( typeof( window.pageYOffset ) == 'number' ) {
- //Netscape compliant
- scrOfY = window.pageYOffset;
- scrOfX = window.pageXOffset;
- } else if( document.body && ( document.body.scrollLeft || document.body.scrollTop ) ) {
- //DOM compliant
- scrOfY = document.body.scrollTop;
- scrOfX = document.body.scrollLeft;
- } else if( document.documentElement && ( document.documentElement.scrollLeft || document.documentElement.scrollTop ) ) {
- //IE6 standards compliant mode
- scrOfY = document.documentElement.scrollTop;
- scrOfX = document.documentElement.scrollLeft;
- }
- req.setCallbackParameter({
- DragElementID : elementId,
- ScreenX : event.screenX,
- ScreenY : event.screenY,
- OffsetX : event.offsetX || event.clientX - curleft + scrOfX,
- OffsetY : event.offsetY || event.clientY - curtop + scrOfY,
- ClientX : event.clientX,
- ClientY : event.clientY,
- AltKey : event.altKey,
- CtrlKey : event.ctrlKey,
- ShiftKey : event.shiftKey
- });
- req.dispatch();
-
- }
-});
+/**
+ * DropContainer control
+ */
+
+Prado.WebUI.DropContainer = Class.create(Prado.WebUI.CallbackControl,
+{
+ onInit: function(options)
+ {
+ this.options = options;
+ Object.extend (this.options,
+ {
+ onDrop: this.onDrop.bind(this)
+ });
+
+ Droppables.add (options.ID, this.options);
+ },
+
+ onDrop: function(dragElement, dropElement, event)
+ {
+ var elementId=dragElement.id.replace(/clone_/,"");
+ var req = new Prado.CallbackRequest(this.options.EventTarget, this.options);
+ var curleft = curtop = 0;
+ var obj = dropElement;
+ if (obj.offsetParent) {
+ curleft = obj.offsetLeft
+ curtop = obj.offsetTop
+ while (obj = obj.offsetParent) {
+ curleft += obj.offsetLeft
+ curtop += obj.offsetTop
+ }
+ }
+ var scrOfX = 0, scrOfY = 0;
+ if( typeof( window.pageYOffset ) == 'number' ) {
+ //Netscape compliant
+ scrOfY = window.pageYOffset;
+ scrOfX = window.pageXOffset;
+ } else if( document.body && ( document.body.scrollLeft || document.body.scrollTop ) ) {
+ //DOM compliant
+ scrOfY = document.body.scrollTop;
+ scrOfX = document.body.scrollLeft;
+ } else if( document.documentElement && ( document.documentElement.scrollLeft || document.documentElement.scrollTop ) ) {
+ //IE6 standards compliant mode
+ scrOfY = document.documentElement.scrollTop;
+ scrOfX = document.documentElement.scrollLeft;
+ }
+ req.setCallbackParameter({
+ DragElementID : elementId,
+ ScreenX : event.screenX,
+ ScreenY : event.screenY,
+ OffsetX : event.offsetX || event.clientX - curleft + scrOfX,
+ OffsetY : event.offsetY || event.clientY - curtop + scrOfY,
+ ClientX : event.clientX,
+ ClientY : event.clientY,
+ AltKey : event.altKey,
+ CtrlKey : event.ctrlKey,
+ ShiftKey : event.shiftKey
+ });
+ req.dispatch();
+
+ }
+});
diff --git a/framework/Web/Javascripts/source/prado/activecontrols/inlineeditor.js b/framework/Web/Javascripts/source/prado/activecontrols/inlineeditor.js
index a53ac8fd..0260c219 100644
--- a/framework/Web/Javascripts/source/prado/activecontrols/inlineeditor.js
+++ b/framework/Web/Javascripts/source/prado/activecontrols/inlineeditor.js
@@ -1,302 +1,302 @@
-Prado.WebUI.TInPlaceTextBox = Class.create(Prado.WebUI.Control,
-{
- onInit : function(options)
- {
-
- this.isSaving = false;
- this.isEditing = false;
- this.editField = null;
- this.readOnly = options.ReadOnly;
-
- this.options = Object.extend(
- {
- LoadTextFromSource : false,
- TextMode : 'SingleLine'
-
- }, options || {});
- this.element = $(this.options.ID);
- Prado.WebUI.TInPlaceTextBox.register(this);
- this.createEditorInput();
- this.initializeListeners();
- },
-
- /**
- * Initialize the listeners.
- */
- initializeListeners : function()
- {
- this.onclickListener = this.enterEditMode.bindAsEventListener(this);
- this.observe(this.element, 'click', this.onclickListener);
- if (this.options.ExternalControl)
- this.observe($(this.options.ExternalControl), 'click', this.onclickListener);
- },
-
- /**
- * Changes the panel to an editable input.
- * @param {Event} evt event source
- */
- enterEditMode : function(evt)
- {
- if (this.isSaving || this.isEditing || this.readOnly) return;
- this.isEditing = true;
- this.onEnterEditMode();
- this.createEditorInput();
- this.showTextBox();
- this.editField.disabled = false;
- if(this.options.LoadTextOnEdit)
- this.loadExternalText();
- Prado.Element.focus(this.editField);
- if (evt)
- Event.stop(evt);
- return false;
- },
-
- exitEditMode : function(evt)
- {
- this.isEditing = false;
- this.isSaving = false;
- this.editField.disabled = false;
- this.element.innerHTML = this.editField.value;
- this.showLabel();
- },
-
- showTextBox : function()
- {
- Element.hide(this.element);
- Element.show(this.editField);
- },
-
- showLabel : function()
- {
- Element.show(this.element);
- Element.hide(this.editField);
- },
-
- /**
- * Create the edit input field.
- */
- createEditorInput : function()
- {
- if(this.editField == null)
- this.createTextBox();
-
- this.editField.value = this.getText();
- },
-
- loadExternalText : function()
- {
- this.editField.disabled = true;
- this.onLoadingText();
- var options = new Array('__InlineEditor_loadExternalText__', this.getText());
- var request = new Prado.CallbackRequest(this.options.EventTarget, this.options);
- request.setCausesValidation(false);
- request.setCallbackParameter(options);
- request.ActiveControl.onSuccess = this.onloadExternalTextSuccess.bind(this);
- request.ActiveControl.onFailure = this.onloadExternalTextFailure.bind(this);
- request.dispatch();
- },
-
- /**
- * Create a new input textbox or textarea
- */
- createTextBox : function()
- {
- var cssClass= this.element.className || '';
- var inputName = this.options.EventTarget;
- var options = {'className' : cssClass, name : inputName, id : this.options.TextBoxID};
- if(this.options.TextMode == 'SingleLine')
- {
- if(this.options.MaxLength > 0)
- options['maxlength'] = this.options.MaxLength;
- if(this.options.Columns > 0)
- options['size'] = this.options.Columns;
- this.editField = INPUT(options);
- }
- else
- {
- if(this.options.Rows > 0)
- options['rows'] = this.options.Rows;
- if(this.options.Columns > 0)
- options['cols'] = this.options.Columns;
- if(this.options.Wrap)
- options['wrap'] = 'off';
- this.editField = TEXTAREA(options);
- }
-
- this.editField.style.display="none";
- this.element.parentNode.insertBefore(this.editField,this.element)
-
- //handle return key within single line textbox
- if(this.options.TextMode == 'SingleLine')
- {
- this.observe(this.editField, "keydown", function(e)
- {
- if(Event.keyCode(e) == Event.KEY_RETURN)
- {
- var target = Event.element(e);
- if(target)
- {
- Event.fireEvent(target, "blur");
- Event.stop(e);
- }
- }
- });
- }
-
- this.observe(this.editField, "blur", this.onTextBoxBlur.bind(this));
- this.observe(this.editField, "keypress", this.onKeyPressed.bind(this));
- },
-
- /**
- * @return {String} panel inner html text.
- */
- getText: function()
- {
- return this.element.innerHTML;
- },
-
- /**
- * Edit mode entered, calls optional event handlers.
- */
- onEnterEditMode : function()
- {
- if(typeof(this.options.onEnterEditMode) == "function")
- this.options.onEnterEditMode(this,null);
- },
-
- onTextBoxBlur : function(e)
- {
- var text = this.element.innerHTML;
- if(this.options.AutoPostBack && text != this.editField.value)
- {
- if(this.isEditing)
- this.onTextChanged(text);
- }
- else
- {
- this.element.innerHTML = this.editField.value;
- this.isEditing = false;
- if(this.options.AutoHide)
- this.showLabel();
- }
- },
-
- onKeyPressed : function(e)
- {
- if (Event.keyCode(e) == Event.KEY_ESC)
- {
- this.editField.value = this.getText();
- this.isEditing = false;
- if(this.options.AutoHide)
- this.showLabel();
- }
- else if (Event.keyCode(e) == Event.KEY_RETURN && this.options.TextMode != 'MultiLine')
- Event.stop(e);
- },
-
- /**
- * When the text input value has changed.
- * @param {String} original text
- */
- onTextChanged : function(text)
- {
- var request = new Prado.CallbackRequest(this.options.EventTarget, this.options);
- request.setCallbackParameter(text);
- request.ActiveControl.onSuccess = this.onTextChangedSuccess.bind(this);
- request.ActiveControl.onFailure = this.onTextChangedFailure.bind(this);
- if(request.dispatch())
- {
- this.isSaving = true;
- this.editField.disabled = true;
- }
- },
-
- /**
- * When loading external text.
- */
- onLoadingText : function()
- {
- //Logger.info("on loading text");
- },
-
- onloadExternalTextSuccess : function(request, parameter)
- {
- this.isEditing = true;
- this.editField.disabled = false;
- this.editField.value = this.getText();
- Prado.Element.focus(this.editField);
- if(typeof(this.options.onSuccess)=="function")
- this.options.onSuccess(sender,parameter);
- },
-
- onloadExternalTextFailure : function(request, parameter)
- {
- this.isSaving = false;
- this.isEditing = false;
- this.showLabel();
- if(typeof(this.options.onFailure)=="function")
- this.options.onFailure(sender,parameter);
- },
-
- /**
- * Text change successfully.
- * @param {Object} sender
- * @param {Object} parameter
- */
- onTextChangedSuccess : function(sender, parameter)
- {
- this.isSaving = false;
- this.isEditing = false;
- if(this.options.AutoHide)
- this.showLabel();
- this.element.innerHTML = parameter == null ? this.editField.value : parameter;
- this.editField.disabled = false;
- if(typeof(this.options.onSuccess)=="function")
- this.options.onSuccess(sender,parameter);
- },
-
- onTextChangedFailure : function(sender, parameter)
- {
- this.editField.disabled = false;
- this.isSaving = false;
- this.isEditing = false;
- if(typeof(this.options.onFailure)=="function")
- this.options.onFailure(sender,parameter);
- }
-});
-
-
-Object.extend(Prado.WebUI.TInPlaceTextBox,
-{
- //class methods
-
- textboxes : {},
-
- register : function(obj)
- {
- Prado.WebUI.TInPlaceTextBox.textboxes[obj.options.TextBoxID] = obj;
- },
-
- setDisplayTextBox : function(id,value)
- {
- var textbox = Prado.WebUI.TInPlaceTextBox.textboxes[id];
- if(textbox)
- {
- if(value)
- textbox.enterEditMode(null);
- else
- {
- textbox.exitEditMode(null);
- }
- }
- },
-
- setReadOnly : function(id, value)
- {
- var textbox = Prado.WebUI.TInPlaceTextBox.textboxes[id];
- if (textbox)
- {
- textbox.readOnly=value;
- }
- }
+Prado.WebUI.TInPlaceTextBox = Class.create(Prado.WebUI.Control,
+{
+ onInit : function(options)
+ {
+
+ this.isSaving = false;
+ this.isEditing = false;
+ this.editField = null;
+ this.readOnly = options.ReadOnly;
+
+ this.options = Object.extend(
+ {
+ LoadTextFromSource : false,
+ TextMode : 'SingleLine'
+
+ }, options || {});
+ this.element = $(this.options.ID);
+ Prado.WebUI.TInPlaceTextBox.register(this);
+ this.createEditorInput();
+ this.initializeListeners();
+ },
+
+ /**
+ * Initialize the listeners.
+ */
+ initializeListeners : function()
+ {
+ this.onclickListener = this.enterEditMode.bindAsEventListener(this);
+ this.observe(this.element, 'click', this.onclickListener);
+ if (this.options.ExternalControl)
+ this.observe($(this.options.ExternalControl), 'click', this.onclickListener);
+ },
+
+ /**
+ * Changes the panel to an editable input.
+ * @param {Event} evt event source
+ */
+ enterEditMode : function(evt)
+ {
+ if (this.isSaving || this.isEditing || this.readOnly) return;
+ this.isEditing = true;
+ this.onEnterEditMode();
+ this.createEditorInput();
+ this.showTextBox();
+ this.editField.disabled = false;
+ if(this.options.LoadTextOnEdit)
+ this.loadExternalText();
+ Prado.Element.focus(this.editField);
+ if (evt)
+ Event.stop(evt);
+ return false;
+ },
+
+ exitEditMode : function(evt)
+ {
+ this.isEditing = false;
+ this.isSaving = false;
+ this.editField.disabled = false;
+ this.element.innerHTML = this.editField.value;
+ this.showLabel();
+ },
+
+ showTextBox : function()
+ {
+ Element.hide(this.element);
+ Element.show(this.editField);
+ },
+
+ showLabel : function()
+ {
+ Element.show(this.element);
+ Element.hide(this.editField);
+ },
+
+ /**
+ * Create the edit input field.
+ */
+ createEditorInput : function()
+ {
+ if(this.editField == null)
+ this.createTextBox();
+
+ this.editField.value = this.getText();
+ },
+
+ loadExternalText : function()
+ {
+ this.editField.disabled = true;
+ this.onLoadingText();
+ var options = new Array('__InlineEditor_loadExternalText__', this.getText());
+ var request = new Prado.CallbackRequest(this.options.EventTarget, this.options);
+ request.setCausesValidation(false);
+ request.setCallbackParameter(options);
+ request.ActiveControl.onSuccess = this.onloadExternalTextSuccess.bind(this);
+ request.ActiveControl.onFailure = this.onloadExternalTextFailure.bind(this);
+ request.dispatch();
+ },
+
+ /**
+ * Create a new input textbox or textarea
+ */
+ createTextBox : function()
+ {
+ var cssClass= this.element.className || '';
+ var inputName = this.options.EventTarget;
+ var options = {'className' : cssClass, name : inputName, id : this.options.TextBoxID};
+ if(this.options.TextMode == 'SingleLine')
+ {
+ if(this.options.MaxLength > 0)
+ options['maxlength'] = this.options.MaxLength;
+ if(this.options.Columns > 0)
+ options['size'] = this.options.Columns;
+ this.editField = INPUT(options);
+ }
+ else
+ {
+ if(this.options.Rows > 0)
+ options['rows'] = this.options.Rows;
+ if(this.options.Columns > 0)
+ options['cols'] = this.options.Columns;
+ if(this.options.Wrap)
+ options['wrap'] = 'off';
+ this.editField = TEXTAREA(options);
+ }
+
+ this.editField.style.display="none";
+ this.element.parentNode.insertBefore(this.editField,this.element)
+
+ //handle return key within single line textbox
+ if(this.options.TextMode == 'SingleLine')
+ {
+ this.observe(this.editField, "keydown", function(e)
+ {
+ if(Event.keyCode(e) == Event.KEY_RETURN)
+ {
+ var target = Event.element(e);
+ if(target)
+ {
+ Event.fireEvent(target, "blur");
+ Event.stop(e);
+ }
+ }
+ });
+ }
+
+ this.observe(this.editField, "blur", this.onTextBoxBlur.bind(this));
+ this.observe(this.editField, "keypress", this.onKeyPressed.bind(this));
+ },
+
+ /**
+ * @return {String} panel inner html text.
+ */
+ getText: function()
+ {
+ return this.element.innerHTML;
+ },
+
+ /**
+ * Edit mode entered, calls optional event handlers.
+ */
+ onEnterEditMode : function()
+ {
+ if(typeof(this.options.onEnterEditMode) == "function")
+ this.options.onEnterEditMode(this,null);
+ },
+
+ onTextBoxBlur : function(e)
+ {
+ var text = this.element.innerHTML;
+ if(this.options.AutoPostBack && text != this.editField.value)
+ {
+ if(this.isEditing)
+ this.onTextChanged(text);
+ }
+ else
+ {
+ this.element.innerHTML = this.editField.value;
+ this.isEditing = false;
+ if(this.options.AutoHide)
+ this.showLabel();
+ }
+ },
+
+ onKeyPressed : function(e)
+ {
+ if (Event.keyCode(e) == Event.KEY_ESC)
+ {
+ this.editField.value = this.getText();
+ this.isEditing = false;
+ if(this.options.AutoHide)
+ this.showLabel();
+ }
+ else if (Event.keyCode(e) == Event.KEY_RETURN && this.options.TextMode != 'MultiLine')
+ Event.stop(e);
+ },
+
+ /**
+ * When the text input value has changed.
+ * @param {String} original text
+ */
+ onTextChanged : function(text)
+ {
+ var request = new Prado.CallbackRequest(this.options.EventTarget, this.options);
+ request.setCallbackParameter(text);
+ request.ActiveControl.onSuccess = this.onTextChangedSuccess.bind(this);
+ request.ActiveControl.onFailure = this.onTextChangedFailure.bind(this);
+ if(request.dispatch())
+ {
+ this.isSaving = true;
+ this.editField.disabled = true;
+ }
+ },
+
+ /**
+ * When loading external text.
+ */
+ onLoadingText : function()
+ {
+ //Logger.info("on loading text");
+ },
+
+ onloadExternalTextSuccess : function(request, parameter)
+ {
+ this.isEditing = true;
+ this.editField.disabled = false;
+ this.editField.value = this.getText();
+ Prado.Element.focus(this.editField);
+ if(typeof(this.options.onSuccess)=="function")
+ this.options.onSuccess(sender,parameter);
+ },
+
+ onloadExternalTextFailure : function(request, parameter)
+ {
+ this.isSaving = false;
+ this.isEditing = false;
+ this.showLabel();
+ if(typeof(this.options.onFailure)=="function")
+ this.options.onFailure(sender,parameter);
+ },
+
+ /**
+ * Text change successfully.
+ * @param {Object} sender
+ * @param {Object} parameter
+ */
+ onTextChangedSuccess : function(sender, parameter)
+ {
+ this.isSaving = false;
+ this.isEditing = false;
+ if(this.options.AutoHide)
+ this.showLabel();
+ this.element.innerHTML = parameter == null ? this.editField.value : parameter;
+ this.editField.disabled = false;
+ if(typeof(this.options.onSuccess)=="function")
+ this.options.onSuccess(sender,parameter);
+ },
+
+ onTextChangedFailure : function(sender, parameter)
+ {
+ this.editField.disabled = false;
+ this.isSaving = false;
+ this.isEditing = false;
+ if(typeof(this.options.onFailure)=="function")
+ this.options.onFailure(sender,parameter);
+ }
+});
+
+
+Object.extend(Prado.WebUI.TInPlaceTextBox,
+{
+ //class methods
+
+ textboxes : {},
+
+ register : function(obj)
+ {
+ Prado.WebUI.TInPlaceTextBox.textboxes[obj.options.TextBoxID] = obj;
+ },
+
+ setDisplayTextBox : function(id,value)
+ {
+ var textbox = Prado.WebUI.TInPlaceTextBox.textboxes[id];
+ if(textbox)
+ {
+ if(value)
+ textbox.enterEditMode(null);
+ else
+ {
+ textbox.exitEditMode(null);
+ }
+ }
+ },
+
+ setReadOnly : function(id, value)
+ {
+ var textbox = Prado.WebUI.TInPlaceTextBox.textboxes[id];
+ if (textbox)
+ {
+ textbox.readOnly=value;
+ }
+ }
}); \ No newline at end of file
diff --git a/framework/Web/Javascripts/source/prado/colorpicker/colorpicker.js b/framework/Web/Javascripts/source/prado/colorpicker/colorpicker.js
index 164295cd..142745cf 100644
--- a/framework/Web/Javascripts/source/prado/colorpicker/colorpicker.js
+++ b/framework/Web/Javascripts/source/prado/colorpicker/colorpicker.js
@@ -1,780 +1,780 @@
-//-------------------- ricoColor.js
-if(typeof(Rico) == "undefined") Rico = {};
-
-Rico.Color = Class.create();
-
-Rico.Color.prototype = {
-
- initialize: function(red, green, blue) {
- this.rgb = { r: red, g : green, b : blue };
- },
-
- setRed: function(r) {
- this.rgb.r = r;
- },
-
- setGreen: function(g) {
- this.rgb.g = g;
- },
-
- setBlue: function(b) {
- this.rgb.b = b;
- },
-
- setHue: function(h) {
-
- // get an HSB model, and set the new hue...
- var hsb = this.asHSB();
- hsb.h = h;
-
- // convert back to RGB...
- this.rgb = Rico.Color.HSBtoRGB(hsb.h, hsb.s, hsb.b);
- },
-
- setSaturation: function(s) {
- // get an HSB model, and set the new hue...
- var hsb = this.asHSB();
- hsb.s = s;
-
- // convert back to RGB and set values...
- this.rgb = Rico.Color.HSBtoRGB(hsb.h, hsb.s, hsb.b);
- },
-
- setBrightness: function(b) {
- // get an HSB model, and set the new hue...
- var hsb = this.asHSB();
- hsb.b = b;
-
- // convert back to RGB and set values...
- this.rgb = Rico.Color.HSBtoRGB( hsb.h, hsb.s, hsb.b );
- },
-
- darken: function(percent) {
- var hsb = this.asHSB();
- this.rgb = Rico.Color.HSBtoRGB(hsb.h, hsb.s, Math.max(hsb.b - percent,0));
- },
-
- brighten: function(percent) {
- var hsb = this.asHSB();
- this.rgb = Rico.Color.HSBtoRGB(hsb.h, hsb.s, Math.min(hsb.b + percent,1));
- },
-
- blend: function(other) {
- this.rgb.r = Math.floor((this.rgb.r + other.rgb.r)/2);
- this.rgb.g = Math.floor((this.rgb.g + other.rgb.g)/2);
- this.rgb.b = Math.floor((this.rgb.b + other.rgb.b)/2);
- },
-
- isBright: function() {
- var hsb = this.asHSB();
- return this.asHSB().b > 0.5;
- },
-
- isDark: function() {
- return ! this.isBright();
- },
-
- asRGB: function() {
- return "rgb(" + this.rgb.r + "," + this.rgb.g + "," + this.rgb.b + ")";
- },
-
- asHex: function() {
- return "#" + this.rgb.r.toColorPart() + this.rgb.g.toColorPart() + this.rgb.b.toColorPart();
- },
-
- asHSB: function() {
- return Rico.Color.RGBtoHSB(this.rgb.r, this.rgb.g, this.rgb.b);
- },
-
- toString: function() {
- return this.asHex();
- }
-
-};
-
-Rico.Color.createFromHex = function(hexCode) {
-
- if ( hexCode.indexOf('#') == 0 )
- hexCode = hexCode.substring(1);
-
- var red = "ff", green = "ff", blue="ff";
- if(hexCode.length > 4)
- {
- red = hexCode.substring(0,2);
- green = hexCode.substring(2,4);
- blue = hexCode.substring(4,6);
- }
- else if(hexCode.length > 0 & hexCode.length < 4)
- {
- var r = hexCode.substring(0,1);
- var g = hexCode.substring(1,2);
- var b = hexCode.substring(2);
- red = r+r;
- green = g+g;
- blue = b+b;
- }
- return new Rico.Color( parseInt(red,16), parseInt(green,16), parseInt(blue,16) );
-};
-
-/**
- * Factory method for creating a color from the background of
- * an HTML element.
- */
-Rico.Color.createColorFromBackground = function(elem) {
-
- var actualColor = Element.getStyle($(elem), "background-color");
- if ( actualColor == "transparent" && elem.parent )
- return Rico.Color.createColorFromBackground(elem.parent);
-
- if ( actualColor == null )
- return new Rico.Color(255,255,255);
-
- if ( actualColor.indexOf("rgb(") == 0 ) {
- var colors = actualColor.substring(4, actualColor.length - 1 );
- var colorArray = colors.split(",");
- return new Rico.Color( parseInt( colorArray[0] ),
- parseInt( colorArray[1] ),
- parseInt( colorArray[2] ) );
-
- }
- else if ( actualColor.indexOf("#") == 0 ) {
- return Rico.Color.createFromHex(actualColor);
- }
- else
- return new Rico.Color(255,255,255);
-};
-
-Rico.Color.HSBtoRGB = function(hue, saturation, brightness) {
-
- var red = 0;
- var green = 0;
- var blue = 0;
-
- if (saturation == 0) {
- red = parseInt(brightness * 255.0 + 0.5);
- green = red;
- blue = red;
- }
- else {
- var h = (hue - Math.floor(hue)) * 6.0;
- var f = h - Math.floor(h);
- var p = brightness * (1.0 - saturation);
- var q = brightness * (1.0 - saturation * f);
- var t = brightness * (1.0 - (saturation * (1.0 - f)));
-
- switch (parseInt(h)) {
- case 0:
- red = (brightness * 255.0 + 0.5);
- green = (t * 255.0 + 0.5);
- blue = (p * 255.0 + 0.5);
- break;
- case 1:
- red = (q * 255.0 + 0.5);
- green = (brightness * 255.0 + 0.5);
- blue = (p * 255.0 + 0.5);
- break;
- case 2:
- red = (p * 255.0 + 0.5);
- green = (brightness * 255.0 + 0.5);
- blue = (t * 255.0 + 0.5);
- break;
- case 3:
- red = (p * 255.0 + 0.5);
- green = (q * 255.0 + 0.5);
- blue = (brightness * 255.0 + 0.5);
- break;
- case 4:
- red = (t * 255.0 + 0.5);
- green = (p * 255.0 + 0.5);
- blue = (brightness * 255.0 + 0.5);
- break;
- case 5:
- red = (brightness * 255.0 + 0.5);
- green = (p * 255.0 + 0.5);
- blue = (q * 255.0 + 0.5);
- break;
- }
- }
-
- return { r : parseInt(red), g : parseInt(green) , b : parseInt(blue) };
-};
-
-Rico.Color.RGBtoHSB = function(r, g, b) {
-
- var hue;
- var saturation;
- var brightness;
-
- var cmax = (r > g) ? r : g;
- if (b > cmax)
- cmax = b;
-
- var cmin = (r < g) ? r : g;
- if (b < cmin)
- cmin = b;
-
- brightness = cmax / 255.0;
- if (cmax != 0)
- saturation = (cmax - cmin)/cmax;
- else
- saturation = 0;
-
- if (saturation == 0)
- hue = 0;
- else {
- var redc = (cmax - r)/(cmax - cmin);
- var greenc = (cmax - g)/(cmax - cmin);
- var bluec = (cmax - b)/(cmax - cmin);
-
- if (r == cmax)
- hue = bluec - greenc;
- else if (g == cmax)
- hue = 2.0 + redc - bluec;
- else
- hue = 4.0 + greenc - redc;
-
- hue = hue / 6.0;
- if (hue < 0)
- hue = hue + 1.0;
- }
-
- return { h : hue, s : saturation, b : brightness };
-};
-
-
-Prado.WebUI.TColorPicker = Class.create();
-
-Object.extend(Prado.WebUI.TColorPicker,
-{
- palettes:
- {
- Small : [["fff", "fcc", "fc9", "ff9", "ffc", "9f9", "9ff", "cff", "ccf", "fcf"],
- ["ccc", "f66", "f96", "ff6", "ff3", "6f9", "3ff", "6ff", "99f", "f9f"],
- ["c0c0c0", "f00", "f90", "fc6", "ff0", "3f3", "6cc", "3cf", "66c", "c6c"],
- ["999", "c00", "f60", "fc3", "fc0", "3c0", "0cc", "36f", "63f", "c3c"],
- ["666", "900", "c60", "c93", "990", "090", "399", "33f", "60c", "939"],
- ["333", "600", "930", "963", "660", "060", "366", "009", "339", "636"],
- ["000", "300", "630", "633", "330", "030", "033", "006", "309", "303"]],
-
- Tiny : [["ffffff"/*white*/, "00ff00"/*lime*/, "008000"/*green*/, "0000ff"/*blue*/],
- ["c0c0c0"/*silver*/, "ffff00"/*yellow*/, "ff00ff"/*fuchsia*/, "000080"/*navy*/],
- ["808080"/*gray*/, "ff0000"/*red*/, "800080"/*purple*/, "000000"/*black*/]]
- },
-
- UIImages :
- {
- 'button.gif' : 'button.gif',
-// 'target_black.gif' : 'target_black.gif',
-// 'target_white.gif' : 'target_white.gif',
- 'background.png' : 'background.png'
-// 'slider.gif' : 'slider.gif',
-// 'hue.gif' : 'hue.gif'
- }
-});
-
-Object.extend(Prado.WebUI.TColorPicker.prototype,
-{
- initialize : function(options)
- {
- var basics =
- {
- Palette : 'Small',
- ClassName : 'TColorPicker',
- Mode : 'Basic',
- OKButtonText : 'OK',
- CancelButtonText : 'Cancel',
- ShowColorPicker : true
- }
-
- this.element = null;
- this.showing = false;
-
- options = Object.extend(basics, options);
- this.options = options;
- this.input = $(options['ID']);
- this.button = $(options['ID']+'_button');
- this._buttonOnClick = this.buttonOnClick.bind(this);
- if(options['ShowColorPicker'])
- Event.observe(this.button, "click", this._buttonOnClick);
- Event.observe(this.input, "change", this.updatePicker.bind(this));
-
- Prado.Registry.set(options.ID, this);
- },
-
- updatePicker : function(e)
- {
- var color = Rico.Color.createFromHex(this.input.value);
- this.button.style.backgroundColor = color.toString();
- },
-
- buttonOnClick : function(event)
- {
- var mode = this.options['Mode'];
- if(this.element == null)
- {
- var constructor = mode == "Basic" ? "getBasicPickerContainer": "getFullPickerContainer"
- this.element = this[constructor](this.options['ID'], this.options['Palette'])
- this.input.parentNode.appendChild(this.element);
- this.element.style.display = "none";
-
- if(Prado.Browser().ie)
- {
- this.iePopUp = document.createElement('iframe');
- this.iePopUp.src = Prado.WebUI.TColorPicker.UIImages['button.gif'];
- this.iePopUp.style.position = "absolute"
- this.iePopUp.scrolling="no"
- this.iePopUp.frameBorder="0"
- this.input.parentNode.appendChild(this.iePopUp);
- }
- if(mode == "Full")
- this.initializeFullPicker();
- }
- this.show(mode);
- },
-
- show : function(type)
- {
- if(!this.showing)
- {
- var pos = this.input.positionedOffset();
- pos[1] += this.input.offsetHeight;
-
- this.element.style.top = (pos[1]-1) + "px";
- this.element.style.left = pos[0] + "px";
- this.element.style.display = "block";
-
- this.ieHack(type);
-
- //observe for clicks on the document body
- this._documentClickEvent = this.hideOnClick.bindEvent(this, type);
- this._documentKeyDownEvent = this.keyPressed.bindEvent(this, type);
- Event.observe(document.body, "click", this._documentClickEvent);
- Event.observe(document,"keydown", this._documentKeyDownEvent);
- this.showing = true;
-
- if(type == "Full")
- {
- this.observeMouseMovement();
- var color = Rico.Color.createFromHex(this.input.value);
- this.inputs.oldColor.style.backgroundColor = color.asHex();
- this.setColor(color,true);
- }
- }
- },
-
- hide : function(event)
- {
- if(this.showing)
- {
- if(this.iePopUp)
- this.iePopUp.style.display = "none";
-
- this.element.style.display = "none";
- this.showing = false;
- Event.stopObserving(document.body, "click", this._documentClickEvent);
- Event.stopObserving(document,"keydown", this._documentKeyDownEvent);
-
- if(this._observingMouseMove)
- {
- Event.stopObserving(document.body, "mousemove", this._onMouseMove);
- this._observingMouseMove = false;
- }
- }
- },
-
- keyPressed : function(event,type)
- {
- if(Event.keyCode(event) == Event.KEY_ESC)
- this.hide(event,type);
- },
-
- hideOnClick : function(ev)
- {
- if(!this.showing) return;
- var el = Event.element(ev);
- var within = false;
- do
- { within = within || String(el.className).indexOf('FullColorPicker') > -1
- within = within || el == this.button;
- within = within || el == this.input;
- if(within) break;
- el = el.parentNode;
- }
- while(el);
- if(!within) this.hide(ev);
- },
-
- ieHack : function()
- {
- // IE hack
- if(this.iePopUp)
- {
- this.iePopUp.style.display = "block";
- this.iePopUp.style.top = (this.element.offsetTop) + "px";
- this.iePopUp.style.left = (this.element.offsetLeft)+ "px";
- this.iePopUp.style.width = Math.abs(this.element.offsetWidth)+ "px";
- this.iePopUp.style.height = (this.element.offsetHeight + 1)+ "px";
- }
- },
-
- getBasicPickerContainer : function(pickerID, palette)
- {
- var table = TABLE({className:'basic_colors palette_'+palette},TBODY());
- var colors = Prado.WebUI.TColorPicker.palettes[palette];
- var pickerOnClick = this.cellOnClick.bind(this);
- colors.each(function(color)
- {
- var row = document.createElement("tr");
- color.each(function(c)
- {
- var td = document.createElement("td");
- var img = IMG({src:Prado.WebUI.TColorPicker.UIImages['button.gif'],width:16,height:16});
- img.style.backgroundColor = "#"+c;
- Event.observe(img,"click", pickerOnClick);
- Event.observe(img,"mouseover", function(e)
- {
- Element.addClassName(Event.element(e), "pickerhover");
- });
- Event.observe(img,"mouseout", function(e)
- {
- Element.removeClassName(Event.element(e), "pickerhover");
- });
- td.appendChild(img);
- row.appendChild(td);
- });
- table.childNodes[0].appendChild(row);
- });
- return DIV({className:this.options['ClassName']+" BasicColorPicker",
- id:pickerID+"_picker"}, table);
- },
-
- cellOnClick : function(e)
- {
- var el = Event.element(e);
- if(el.tagName.toLowerCase() != "img")
- return;
- var color = Rico.Color.createColorFromBackground(el);
- this.updateColor(color);
- },
-
- updateColor : function(color)
- {
- this.input.value = color.toString().toUpperCase();
- this.button.style.backgroundColor = color.toString();
- if(typeof(this.onChange) == "function")
- this.onChange(color);
- if(this.options.OnColorSelected)
- this.options.OnColorSelected(this,color);
- },
-
- getFullPickerContainer : function(pickerID)
- {
- //create the 3 buttons
- this.buttons =
- {
- //Less : INPUT({value:'Less Colors', className:'button', type:'button'}),
- OK : INPUT({value:this.options.OKButtonText, className:'button', type:'button'}),
- Cancel : INPUT({value:this.options.CancelButtonText, className:'button', type:'button'})
- };
-
- //create the 6 inputs
- var inputs = {};
- ['H','S','V','R','G','B'].each(function(type)
- {
- inputs[type] = INPUT({type:'text',size:'3',maxlength:'3'});
- });
-
- //create the HEX input
- inputs['HEX'] = INPUT({className:'hex',type:'text',size:'6',maxlength:'6'});
- this.inputs = inputs;
-
- var images = Prado.WebUI.TColorPicker.UIImages;
-
- this.inputs['currentColor'] = SPAN({className:'currentColor'});
- this.inputs['oldColor'] = SPAN({className:'oldColor'});
-
- var inputsTable =
- TABLE({className:'inputs'}, TBODY(null,
- TR(null,
- TD({className:'currentcolor',colSpan:2},
- this.inputs['currentColor'], this.inputs['oldColor'])),
-
- TR(null,
- TD(null,'H:'),
- TD(null,this.inputs['H'], '??')),
-
- TR(null,
- TD(null,'S:'),
- TD(null,this.inputs['S'], '%')),
-
- TR(null,
- TD(null,'V:'),
- TD(null,this.inputs['V'], '%')),
-
- TR(null,
- TD({className:'gap'},'R:'),
- TD({className:'gap'},this.inputs['R'])),
-
- TR(null,
- TD(null,'G:'),
- TD(null, this.inputs['G'])),
-
- TR(null,
- TD(null,'B:'),
- TD(null, this.inputs['B'])),
-
- TR(null,
- TD({className:'gap'},'#'),
- TD({className:'gap'},this.inputs['HEX']))
- ));
-
- var UIimages =
- {
- selector : SPAN({className:'selector'}),
- background : SPAN({className:'colorpanel'}),
- slider : SPAN({className:'slider'}),
- hue : SPAN({className:'strip'})
- }
-
- //png alpha channels for IE
- if(Prado.Browser().ie)
- {
- var filter = "filter:progid:DXImageTransform.Microsoft.AlphaImageLoader";
- UIimages['background'] = SPAN({className:'colorpanel',style:filter+"(src='"+images['background.png']+"' sizingMethod=scale);"})
- }
-
- this.inputs = Object.extend(this.inputs, UIimages);
-
- var pickerTable =
- TABLE(null,TBODY(null,
- TR({className:'selection'},
- TD({className:'colors'},UIimages['selector'],UIimages['background']),
- TD({className:'hue'},UIimages['slider'],UIimages['hue']),
- TD({className:'inputs'}, inputsTable)
- ),
- TR({className:'options'},
- TD({colSpan:3},
- this.buttons['OK'],
- this.buttons['Cancel'])
- )
- ));
-
- return DIV({className:this.options['ClassName']+" FullColorPicker",
- id:pickerID+"_picker"},pickerTable);
- },
-
- initializeFullPicker : function()
- {
- var color = Rico.Color.createFromHex(this.input.value);
- this.inputs.oldColor.style.backgroundColor = color.asHex();
- this.setColor(color,true);
-
- var i = 0;
- for(var type in this.inputs)
- {
- Event.observe(this.inputs[type], "change",
- this.onInputChanged.bindEvent(this,type));
- i++;
-
- if(i > 6) break;
- }
-
- this.isMouseDownOnColor = false;
- this.isMouseDownOnHue = false;
-
- this._onColorMouseDown = this.onColorMouseDown.bind(this);
- this._onHueMouseDown = this.onHueMouseDown.bind(this);
- this._onMouseUp = this.onMouseUp.bind(this);
- this._onMouseMove = this.onMouseMove.bind(this);
-
- Event.observe(this.inputs.background, "mousedown", this._onColorMouseDown);
- Event.observe(this.inputs.selector, "mousedown", this._onColorMouseDown);
- Event.observe(this.inputs.hue, "mousedown", this._onHueMouseDown);
- Event.observe(this.inputs.slider, "mousedown", this._onHueMouseDown);
-
- Event.observe(document.body, "mouseup", this._onMouseUp);
-
- this.observeMouseMovement();
-
- Event.observe(this.buttons.Cancel, "click", this.hide.bindEvent(this,this.options['Mode']));
- Event.observe(this.buttons.OK, "click", this.onOKClicked.bind(this));
- },
-
- observeMouseMovement : function()
- {
- if(!this._observingMouseMove)
- {
- Event.observe(document.body, "mousemove", this._onMouseMove);
- this._observingMouseMove = true;
- }
- },
-
- onColorMouseDown : function(ev)
- {
- this.isMouseDownOnColor = true;
- this.onMouseMove(ev);
- Event.stop(ev);
- },
-
- onHueMouseDown : function(ev)
- {
- this.isMouseDownOnHue = true;
- this.onMouseMove(ev);
- Event.stop(ev);
- },
-
- onMouseUp : function(ev)
- {
- this.isMouseDownOnColor = false;
- this.isMouseDownOnHue = false;
- Event.stop(ev);
- },
-
- onMouseMove : function(ev)
- {
- if(this.isMouseDownOnColor)
- this.changeSV(ev);
- if(this.isMouseDownOnHue)
- this.changeH(ev);
- Event.stop(ev);
- },
-
- changeSV : function(ev)
- {
- var px = Event.pointerX(ev);
- var py = Event.pointerY(ev);
- var pos = this.inputs.background.cumulativeOffset();
-
- var x = this.truncate(px - pos[0],0,255);
- var y = this.truncate(py - pos[1],0,255);
-
-
- var s = x/255;
- var b = (255-y)/255;
-
- var current_s = parseInt(this.inputs.S.value);
- var current_b = parseInt(this.inputs.V.value);
-
- if(current_s == parseInt(s*100) && current_b == parseInt(b*100)) return;
-
- var h = this.truncate(this.inputs.H.value,0,360)/360;
-
- var color = new Rico.Color();
- color.rgb = Rico.Color.HSBtoRGB(h,s,b);
-
-
- this.inputs.selector.style.left = x+"px";
- this.inputs.selector.style.top = y+"px";
-
- this.inputs.currentColor.style.backgroundColor = color.asHex();
-
- return this.setColor(color);
- },
-
- changeH : function(ev)
- {
- var py = Event.pointerY(ev);
- var pos = this.inputs.background.cumulativeOffset();
- var y = this.truncate(py - pos[1],0,255);
-
- var h = (255-y)/255;
- var current_h = this.truncate(this.inputs.H.value,0,360);
- current_h = current_h == 0 ? 360 : current_h;
- if(current_h == parseInt(h*360)) return;
-
- var s = parseInt(this.inputs.S.value)/100;
- var b = parseInt(this.inputs.V.value)/100;
- var color = new Rico.Color();
- color.rgb = Rico.Color.HSBtoRGB(h,s,b);
-
- var hue = new Rico.Color(color.rgb.r,color.rgb.g,color.rgb.b);
- hue.setSaturation(1); hue.setBrightness(1);
-
- this.inputs.background.style.backgroundColor = hue.asHex();
- this.inputs.currentColor.style.backgroundColor = color.asHex();
-
- this.inputs.slider.style.top = this.truncate(y,0,255)+"px";
- return this.setColor(color);
-
- },
-
- onOKClicked : function(ev)
- {
- var r = this.truncate(this.inputs.R.value,0,255);///255;
- var g = this.truncate(this.inputs.G.value,0,255);///255;
- var b = this.truncate(this.inputs.B.value,0,255);///255;
- var color = new Rico.Color(r,g,b);
- this.updateColor(color);
- this.inputs.oldColor.style.backgroundColor = color.asHex();
- this.hide(ev);
- },
-
- onInputChanged : function(ev, type)
- {
- if(this.isMouseDownOnColor || isMouseDownOnHue)
- return;
-
-
- switch(type)
- {
- case "H": case "S": case "V":
- var h = this.truncate(this.inputs.H.value,0,360)/360;
- var s = this.truncate(this.inputs.S.value,0,100)/100;
- var b = this.truncate(this.inputs.V.value,0,100)/100;
- var color = new Rico.Color();
- color.rgb = Rico.Color.HSBtoRGB(h,s,b);
- return this.setColor(color,true);
- case "R": case "G": case "B":
- var r = this.truncate(this.inputs.R.value,0,255);///255;
- var g = this.truncate(this.inputs.G.value,0,255);///255;
- var b = this.truncate(this.inputs.B.value,0,255);///255;
- var color = new Rico.Color(r,g,b);
- return this.setColor(color,true);
- case "HEX":
- var color = Rico.Color.createFromHex(this.inputs.HEX.value);
- return this.setColor(color,true);
- }
- },
-
- setColor : function(color, update)
- {
- var hsb = color.asHSB();
-
- this.inputs.H.value = parseInt(hsb.h*360);
- this.inputs.S.value = parseInt(hsb.s*100);
- this.inputs.V.value = parseInt(hsb.b*100);
- this.inputs.R.value = color.rgb.r;
- this.inputs.G.value = color.rgb.g;
- this.inputs.B.value = color.rgb.b;
- this.inputs.HEX.value = color.asHex().substring(1).toUpperCase();
-
- var images = Prado.WebUI.TColorPicker.UIImages;
-
- var changeCss = color.isBright() ? 'removeClassName' : 'addClassName';
- Element[changeCss](this.inputs.selector, 'target_white');
-
- if(update)
- this.updateSelectors(color);
- },
-
- updateSelectors : function(color)
- {
- var hsb = color.asHSB();
- var pos = [hsb.s*255, hsb.b*255, hsb.h*255];
-
- this.inputs.selector.style.left = this.truncate(pos[0],0,255)+"px";
- this.inputs.selector.style.top = this.truncate(255-pos[1],0,255)+"px";
- this.inputs.slider.style.top = this.truncate(255-pos[2],0,255)+"px";
-
- var hue = new Rico.Color(color.rgb.r,color.rgb.g,color.rgb.b);
- hue.setSaturation(1); hue.setBrightness(1);
- this.inputs.background.style.backgroundColor = hue.asHex();
- this.inputs.currentColor.style.backgroundColor = color.asHex();
- },
-
- truncate : function(value, min, max)
- {
- value = parseInt(value);
- return value < min ? min : value > max ? max : value;
- }
-});
+//-------------------- ricoColor.js
+if(typeof(Rico) == "undefined") Rico = {};
+
+Rico.Color = Class.create();
+
+Rico.Color.prototype = {
+
+ initialize: function(red, green, blue) {
+ this.rgb = { r: red, g : green, b : blue };
+ },
+
+ setRed: function(r) {
+ this.rgb.r = r;
+ },
+
+ setGreen: function(g) {
+ this.rgb.g = g;
+ },
+
+ setBlue: function(b) {
+ this.rgb.b = b;
+ },
+
+ setHue: function(h) {
+
+ // get an HSB model, and set the new hue...
+ var hsb = this.asHSB();
+ hsb.h = h;
+
+ // convert back to RGB...
+ this.rgb = Rico.Color.HSBtoRGB(hsb.h, hsb.s, hsb.b);
+ },
+
+ setSaturation: function(s) {
+ // get an HSB model, and set the new hue...
+ var hsb = this.asHSB();
+ hsb.s = s;
+
+ // convert back to RGB and set values...
+ this.rgb = Rico.Color.HSBtoRGB(hsb.h, hsb.s, hsb.b);
+ },
+
+ setBrightness: function(b) {
+ // get an HSB model, and set the new hue...
+ var hsb = this.asHSB();
+ hsb.b = b;
+
+ // convert back to RGB and set values...
+ this.rgb = Rico.Color.HSBtoRGB( hsb.h, hsb.s, hsb.b );
+ },
+
+ darken: function(percent) {
+ var hsb = this.asHSB();
+ this.rgb = Rico.Color.HSBtoRGB(hsb.h, hsb.s, Math.max(hsb.b - percent,0));
+ },
+
+ brighten: function(percent) {
+ var hsb = this.asHSB();
+ this.rgb = Rico.Color.HSBtoRGB(hsb.h, hsb.s, Math.min(hsb.b + percent,1));
+ },
+
+ blend: function(other) {
+ this.rgb.r = Math.floor((this.rgb.r + other.rgb.r)/2);
+ this.rgb.g = Math.floor((this.rgb.g + other.rgb.g)/2);
+ this.rgb.b = Math.floor((this.rgb.b + other.rgb.b)/2);
+ },
+
+ isBright: function() {
+ var hsb = this.asHSB();
+ return this.asHSB().b > 0.5;
+ },
+
+ isDark: function() {
+ return ! this.isBright();
+ },
+
+ asRGB: function() {
+ return "rgb(" + this.rgb.r + "," + this.rgb.g + "," + this.rgb.b + ")";
+ },
+
+ asHex: function() {
+ return "#" + this.rgb.r.toColorPart() + this.rgb.g.toColorPart() + this.rgb.b.toColorPart();
+ },
+
+ asHSB: function() {
+ return Rico.Color.RGBtoHSB(this.rgb.r, this.rgb.g, this.rgb.b);
+ },
+
+ toString: function() {
+ return this.asHex();
+ }
+
+};
+
+Rico.Color.createFromHex = function(hexCode) {
+
+ if ( hexCode.indexOf('#') == 0 )
+ hexCode = hexCode.substring(1);
+
+ var red = "ff", green = "ff", blue="ff";
+ if(hexCode.length > 4)
+ {
+ red = hexCode.substring(0,2);
+ green = hexCode.substring(2,4);
+ blue = hexCode.substring(4,6);
+ }
+ else if(hexCode.length > 0 & hexCode.length < 4)
+ {
+ var r = hexCode.substring(0,1);
+ var g = hexCode.substring(1,2);
+ var b = hexCode.substring(2);
+ red = r+r;
+ green = g+g;
+ blue = b+b;
+ }
+ return new Rico.Color( parseInt(red,16), parseInt(green,16), parseInt(blue,16) );
+};
+
+/**
+ * Factory method for creating a color from the background of
+ * an HTML element.
+ */
+Rico.Color.createColorFromBackground = function(elem) {
+
+ var actualColor = Element.getStyle($(elem), "background-color");
+ if ( actualColor == "transparent" && elem.parent )
+ return Rico.Color.createColorFromBackground(elem.parent);
+
+ if ( actualColor == null )
+ return new Rico.Color(255,255,255);
+
+ if ( actualColor.indexOf("rgb(") == 0 ) {
+ var colors = actualColor.substring(4, actualColor.length - 1 );
+ var colorArray = colors.split(",");
+ return new Rico.Color( parseInt( colorArray[0] ),
+ parseInt( colorArray[1] ),
+ parseInt( colorArray[2] ) );
+
+ }
+ else if ( actualColor.indexOf("#") == 0 ) {
+ return Rico.Color.createFromHex(actualColor);
+ }
+ else
+ return new Rico.Color(255,255,255);
+};
+
+Rico.Color.HSBtoRGB = function(hue, saturation, brightness) {
+
+ var red = 0;
+ var green = 0;
+ var blue = 0;
+
+ if (saturation == 0) {
+ red = parseInt(brightness * 255.0 + 0.5);
+ green = red;
+ blue = red;
+ }
+ else {
+ var h = (hue - Math.floor(hue)) * 6.0;
+ var f = h - Math.floor(h);
+ var p = brightness * (1.0 - saturation);
+ var q = brightness * (1.0 - saturation * f);
+ var t = brightness * (1.0 - (saturation * (1.0 - f)));
+
+ switch (parseInt(h)) {
+ case 0:
+ red = (brightness * 255.0 + 0.5);
+ green = (t * 255.0 + 0.5);
+ blue = (p * 255.0 + 0.5);
+ break;
+ case 1:
+ red = (q * 255.0 + 0.5);
+ green = (brightness * 255.0 + 0.5);
+ blue = (p * 255.0 + 0.5);
+ break;
+ case 2:
+ red = (p * 255.0 + 0.5);
+ green = (brightness * 255.0 + 0.5);
+ blue = (t * 255.0 + 0.5);
+ break;
+ case 3:
+ red = (p * 255.0 + 0.5);
+ green = (q * 255.0 + 0.5);
+ blue = (brightness * 255.0 + 0.5);
+ break;
+ case 4:
+ red = (t * 255.0 + 0.5);
+ green = (p * 255.0 + 0.5);
+ blue = (brightness * 255.0 + 0.5);
+ break;
+ case 5:
+ red = (brightness * 255.0 + 0.5);
+ green = (p * 255.0 + 0.5);
+ blue = (q * 255.0 + 0.5);
+ break;
+ }
+ }
+
+ return { r : parseInt(red), g : parseInt(green) , b : parseInt(blue) };
+};
+
+Rico.Color.RGBtoHSB = function(r, g, b) {
+
+ var hue;
+ var saturation;
+ var brightness;
+
+ var cmax = (r > g) ? r : g;
+ if (b > cmax)
+ cmax = b;
+
+ var cmin = (r < g) ? r : g;
+ if (b < cmin)
+ cmin = b;
+
+ brightness = cmax / 255.0;
+ if (cmax != 0)
+ saturation = (cmax - cmin)/cmax;
+ else
+ saturation = 0;
+
+ if (saturation == 0)
+ hue = 0;
+ else {
+ var redc = (cmax - r)/(cmax - cmin);
+ var greenc = (cmax - g)/(cmax - cmin);
+ var bluec = (cmax - b)/(cmax - cmin);
+
+ if (r == cmax)
+ hue = bluec - greenc;
+ else if (g == cmax)
+ hue = 2.0 + redc - bluec;
+ else
+ hue = 4.0 + greenc - redc;
+
+ hue = hue / 6.0;
+ if (hue < 0)
+ hue = hue + 1.0;
+ }
+
+ return { h : hue, s : saturation, b : brightness };
+};
+
+
+Prado.WebUI.TColorPicker = Class.create();
+
+Object.extend(Prado.WebUI.TColorPicker,
+{
+ palettes:
+ {
+ Small : [["fff", "fcc", "fc9", "ff9", "ffc", "9f9", "9ff", "cff", "ccf", "fcf"],
+ ["ccc", "f66", "f96", "ff6", "ff3", "6f9", "3ff", "6ff", "99f", "f9f"],
+ ["c0c0c0", "f00", "f90", "fc6", "ff0", "3f3", "6cc", "3cf", "66c", "c6c"],
+ ["999", "c00", "f60", "fc3", "fc0", "3c0", "0cc", "36f", "63f", "c3c"],
+ ["666", "900", "c60", "c93", "990", "090", "399", "33f", "60c", "939"],
+ ["333", "600", "930", "963", "660", "060", "366", "009", "339", "636"],
+ ["000", "300", "630", "633", "330", "030", "033", "006", "309", "303"]],
+
+ Tiny : [["ffffff"/*white*/, "00ff00"/*lime*/, "008000"/*green*/, "0000ff"/*blue*/],
+ ["c0c0c0"/*silver*/, "ffff00"/*yellow*/, "ff00ff"/*fuchsia*/, "000080"/*navy*/],
+ ["808080"/*gray*/, "ff0000"/*red*/, "800080"/*purple*/, "000000"/*black*/]]
+ },
+
+ UIImages :
+ {
+ 'button.gif' : 'button.gif',
+// 'target_black.gif' : 'target_black.gif',
+// 'target_white.gif' : 'target_white.gif',
+ 'background.png' : 'background.png'
+// 'slider.gif' : 'slider.gif',
+// 'hue.gif' : 'hue.gif'
+ }
+});
+
+Object.extend(Prado.WebUI.TColorPicker.prototype,
+{
+ initialize : function(options)
+ {
+ var basics =
+ {
+ Palette : 'Small',
+ ClassName : 'TColorPicker',
+ Mode : 'Basic',
+ OKButtonText : 'OK',
+ CancelButtonText : 'Cancel',
+ ShowColorPicker : true
+ }
+
+ this.element = null;
+ this.showing = false;
+
+ options = Object.extend(basics, options);
+ this.options = options;
+ this.input = $(options['ID']);
+ this.button = $(options['ID']+'_button');
+ this._buttonOnClick = this.buttonOnClick.bind(this);
+ if(options['ShowColorPicker'])
+ Event.observe(this.button, "click", this._buttonOnClick);
+ Event.observe(this.input, "change", this.updatePicker.bind(this));
+
+ Prado.Registry.set(options.ID, this);
+ },
+
+ updatePicker : function(e)
+ {
+ var color = Rico.Color.createFromHex(this.input.value);
+ this.button.style.backgroundColor = color.toString();
+ },
+
+ buttonOnClick : function(event)
+ {
+ var mode = this.options['Mode'];
+ if(this.element == null)
+ {
+ var constructor = mode == "Basic" ? "getBasicPickerContainer": "getFullPickerContainer"
+ this.element = this[constructor](this.options['ID'], this.options['Palette'])
+ this.input.parentNode.appendChild(this.element);
+ this.element.style.display = "none";
+
+ if(Prado.Browser().ie)
+ {
+ this.iePopUp = document.createElement('iframe');
+ this.iePopUp.src = Prado.WebUI.TColorPicker.UIImages['button.gif'];
+ this.iePopUp.style.position = "absolute"
+ this.iePopUp.scrolling="no"
+ this.iePopUp.frameBorder="0"
+ this.input.parentNode.appendChild(this.iePopUp);
+ }
+ if(mode == "Full")
+ this.initializeFullPicker();
+ }
+ this.show(mode);
+ },
+
+ show : function(type)
+ {
+ if(!this.showing)
+ {
+ var pos = this.input.positionedOffset();
+ pos[1] += this.input.offsetHeight;
+
+ this.element.style.top = (pos[1]-1) + "px";
+ this.element.style.left = pos[0] + "px";
+ this.element.style.display = "block";
+
+ this.ieHack(type);
+
+ //observe for clicks on the document body
+ this._documentClickEvent = this.hideOnClick.bindEvent(this, type);
+ this._documentKeyDownEvent = this.keyPressed.bindEvent(this, type);
+ Event.observe(document.body, "click", this._documentClickEvent);
+ Event.observe(document,"keydown", this._documentKeyDownEvent);
+ this.showing = true;
+
+ if(type == "Full")
+ {
+ this.observeMouseMovement();
+ var color = Rico.Color.createFromHex(this.input.value);
+ this.inputs.oldColor.style.backgroundColor = color.asHex();
+ this.setColor(color,true);
+ }
+ }
+ },
+
+ hide : function(event)
+ {
+ if(this.showing)
+ {
+ if(this.iePopUp)
+ this.iePopUp.style.display = "none";
+
+ this.element.style.display = "none";
+ this.showing = false;
+ Event.stopObserving(document.body, "click", this._documentClickEvent);
+ Event.stopObserving(document,"keydown", this._documentKeyDownEvent);
+
+ if(this._observingMouseMove)
+ {
+ Event.stopObserving(document.body, "mousemove", this._onMouseMove);
+ this._observingMouseMove = false;
+ }
+ }
+ },
+
+ keyPressed : function(event,type)
+ {
+ if(Event.keyCode(event) == Event.KEY_ESC)
+ this.hide(event,type);
+ },
+
+ hideOnClick : function(ev)
+ {
+ if(!this.showing) return;
+ var el = Event.element(ev);
+ var within = false;
+ do
+ { within = within || String(el.className).indexOf('FullColorPicker') > -1
+ within = within || el == this.button;
+ within = within || el == this.input;
+ if(within) break;
+ el = el.parentNode;
+ }
+ while(el);
+ if(!within) this.hide(ev);
+ },
+
+ ieHack : function()
+ {
+ // IE hack
+ if(this.iePopUp)
+ {
+ this.iePopUp.style.display = "block";
+ this.iePopUp.style.top = (this.element.offsetTop) + "px";
+ this.iePopUp.style.left = (this.element.offsetLeft)+ "px";
+ this.iePopUp.style.width = Math.abs(this.element.offsetWidth)+ "px";
+ this.iePopUp.style.height = (this.element.offsetHeight + 1)+ "px";
+ }
+ },
+
+ getBasicPickerContainer : function(pickerID, palette)
+ {
+ var table = TABLE({className:'basic_colors palette_'+palette},TBODY());
+ var colors = Prado.WebUI.TColorPicker.palettes[palette];
+ var pickerOnClick = this.cellOnClick.bind(this);
+ colors.each(function(color)
+ {
+ var row = document.createElement("tr");
+ color.each(function(c)
+ {
+ var td = document.createElement("td");
+ var img = IMG({src:Prado.WebUI.TColorPicker.UIImages['button.gif'],width:16,height:16});
+ img.style.backgroundColor = "#"+c;
+ Event.observe(img,"click", pickerOnClick);
+ Event.observe(img,"mouseover", function(e)
+ {
+ Element.addClassName(Event.element(e), "pickerhover");
+ });
+ Event.observe(img,"mouseout", function(e)
+ {
+ Element.removeClassName(Event.element(e), "pickerhover");
+ });
+ td.appendChild(img);
+ row.appendChild(td);
+ });
+ table.childNodes[0].appendChild(row);
+ });
+ return DIV({className:this.options['ClassName']+" BasicColorPicker",
+ id:pickerID+"_picker"}, table);
+ },
+
+ cellOnClick : function(e)
+ {
+ var el = Event.element(e);
+ if(el.tagName.toLowerCase() != "img")
+ return;
+ var color = Rico.Color.createColorFromBackground(el);
+ this.updateColor(color);
+ },
+
+ updateColor : function(color)
+ {
+ this.input.value = color.toString().toUpperCase();
+ this.button.style.backgroundColor = color.toString();
+ if(typeof(this.onChange) == "function")
+ this.onChange(color);
+ if(this.options.OnColorSelected)
+ this.options.OnColorSelected(this,color);
+ },
+
+ getFullPickerContainer : function(pickerID)
+ {
+ //create the 3 buttons
+ this.buttons =
+ {
+ //Less : INPUT({value:'Less Colors', className:'button', type:'button'}),
+ OK : INPUT({value:this.options.OKButtonText, className:'button', type:'button'}),
+ Cancel : INPUT({value:this.options.CancelButtonText, className:'button', type:'button'})
+ };
+
+ //create the 6 inputs
+ var inputs = {};
+ ['H','S','V','R','G','B'].each(function(type)
+ {
+ inputs[type] = INPUT({type:'text',size:'3',maxlength:'3'});
+ });
+
+ //create the HEX input
+ inputs['HEX'] = INPUT({className:'hex',type:'text',size:'6',maxlength:'6'});
+ this.inputs = inputs;
+
+ var images = Prado.WebUI.TColorPicker.UIImages;
+
+ this.inputs['currentColor'] = SPAN({className:'currentColor'});
+ this.inputs['oldColor'] = SPAN({className:'oldColor'});
+
+ var inputsTable =
+ TABLE({className:'inputs'}, TBODY(null,
+ TR(null,
+ TD({className:'currentcolor',colSpan:2},
+ this.inputs['currentColor'], this.inputs['oldColor'])),
+
+ TR(null,
+ TD(null,'H:'),
+ TD(null,this.inputs['H'], '??')),
+
+ TR(null,
+ TD(null,'S:'),
+ TD(null,this.inputs['S'], '%')),
+
+ TR(null,
+ TD(null,'V:'),
+ TD(null,this.inputs['V'], '%')),
+
+ TR(null,
+ TD({className:'gap'},'R:'),
+ TD({className:'gap'},this.inputs['R'])),
+
+ TR(null,
+ TD(null,'G:'),
+ TD(null, this.inputs['G'])),
+
+ TR(null,
+ TD(null,'B:'),
+ TD(null, this.inputs['B'])),
+
+ TR(null,
+ TD({className:'gap'},'#'),
+ TD({className:'gap'},this.inputs['HEX']))
+ ));
+
+ var UIimages =
+ {
+ selector : SPAN({className:'selector'}),
+ background : SPAN({className:'colorpanel'}),
+ slider : SPAN({className:'slider'}),
+ hue : SPAN({className:'strip'})
+ }
+
+ //png alpha channels for IE
+ if(Prado.Browser().ie)
+ {
+ var filter = "filter:progid:DXImageTransform.Microsoft.AlphaImageLoader";
+ UIimages['background'] = SPAN({className:'colorpanel',style:filter+"(src='"+images['background.png']+"' sizingMethod=scale);"})
+ }
+
+ this.inputs = Object.extend(this.inputs, UIimages);
+
+ var pickerTable =
+ TABLE(null,TBODY(null,
+ TR({className:'selection'},
+ TD({className:'colors'},UIimages['selector'],UIimages['background']),
+ TD({className:'hue'},UIimages['slider'],UIimages['hue']),
+ TD({className:'inputs'}, inputsTable)
+ ),
+ TR({className:'options'},
+ TD({colSpan:3},
+ this.buttons['OK'],
+ this.buttons['Cancel'])
+ )
+ ));
+
+ return DIV({className:this.options['ClassName']+" FullColorPicker",
+ id:pickerID+"_picker"},pickerTable);
+ },
+
+ initializeFullPicker : function()
+ {
+ var color = Rico.Color.createFromHex(this.input.value);
+ this.inputs.oldColor.style.backgroundColor = color.asHex();
+ this.setColor(color,true);
+
+ var i = 0;
+ for(var type in this.inputs)
+ {
+ Event.observe(this.inputs[type], "change",
+ this.onInputChanged.bindEvent(this,type));
+ i++;
+
+ if(i > 6) break;
+ }
+
+ this.isMouseDownOnColor = false;
+ this.isMouseDownOnHue = false;
+
+ this._onColorMouseDown = this.onColorMouseDown.bind(this);
+ this._onHueMouseDown = this.onHueMouseDown.bind(this);
+ this._onMouseUp = this.onMouseUp.bind(this);
+ this._onMouseMove = this.onMouseMove.bind(this);
+
+ Event.observe(this.inputs.background, "mousedown", this._onColorMouseDown);
+ Event.observe(this.inputs.selector, "mousedown", this._onColorMouseDown);
+ Event.observe(this.inputs.hue, "mousedown", this._onHueMouseDown);
+ Event.observe(this.inputs.slider, "mousedown", this._onHueMouseDown);
+
+ Event.observe(document.body, "mouseup", this._onMouseUp);
+
+ this.observeMouseMovement();
+
+ Event.observe(this.buttons.Cancel, "click", this.hide.bindEvent(this,this.options['Mode']));
+ Event.observe(this.buttons.OK, "click", this.onOKClicked.bind(this));
+ },
+
+ observeMouseMovement : function()
+ {
+ if(!this._observingMouseMove)
+ {
+ Event.observe(document.body, "mousemove", this._onMouseMove);
+ this._observingMouseMove = true;
+ }
+ },
+
+ onColorMouseDown : function(ev)
+ {
+ this.isMouseDownOnColor = true;
+ this.onMouseMove(ev);
+ Event.stop(ev);
+ },
+
+ onHueMouseDown : function(ev)
+ {
+ this.isMouseDownOnHue = true;
+ this.onMouseMove(ev);
+ Event.stop(ev);
+ },
+
+ onMouseUp : function(ev)
+ {
+ this.isMouseDownOnColor = false;
+ this.isMouseDownOnHue = false;
+ Event.stop(ev);
+ },
+
+ onMouseMove : function(ev)
+ {
+ if(this.isMouseDownOnColor)
+ this.changeSV(ev);
+ if(this.isMouseDownOnHue)
+ this.changeH(ev);
+ Event.stop(ev);
+ },
+
+ changeSV : function(ev)
+ {
+ var px = Event.pointerX(ev);
+ var py = Event.pointerY(ev);
+ var pos = this.inputs.background.cumulativeOffset();
+
+ var x = this.truncate(px - pos[0],0,255);
+ var y = this.truncate(py - pos[1],0,255);
+
+
+ var s = x/255;
+ var b = (255-y)/255;
+
+ var current_s = parseInt(this.inputs.S.value);
+ var current_b = parseInt(this.inputs.V.value);
+
+ if(current_s == parseInt(s*100) && current_b == parseInt(b*100)) return;
+
+ var h = this.truncate(this.inputs.H.value,0,360)/360;
+
+ var color = new Rico.Color();
+ color.rgb = Rico.Color.HSBtoRGB(h,s,b);
+
+
+ this.inputs.selector.style.left = x+"px";
+ this.inputs.selector.style.top = y+"px";
+
+ this.inputs.currentColor.style.backgroundColor = color.asHex();
+
+ return this.setColor(color);
+ },
+
+ changeH : function(ev)
+ {
+ var py = Event.pointerY(ev);
+ var pos = this.inputs.background.cumulativeOffset();
+ var y = this.truncate(py - pos[1],0,255);
+
+ var h = (255-y)/255;
+ var current_h = this.truncate(this.inputs.H.value,0,360);
+ current_h = current_h == 0 ? 360 : current_h;
+ if(current_h == parseInt(h*360)) return;
+
+ var s = parseInt(this.inputs.S.value)/100;
+ var b = parseInt(this.inputs.V.value)/100;
+ var color = new Rico.Color();
+ color.rgb = Rico.Color.HSBtoRGB(h,s,b);
+
+ var hue = new Rico.Color(color.rgb.r,color.rgb.g,color.rgb.b);
+ hue.setSaturation(1); hue.setBrightness(1);
+
+ this.inputs.background.style.backgroundColor = hue.asHex();
+ this.inputs.currentColor.style.backgroundColor = color.asHex();
+
+ this.inputs.slider.style.top = this.truncate(y,0,255)+"px";
+ return this.setColor(color);
+
+ },
+
+ onOKClicked : function(ev)
+ {
+ var r = this.truncate(this.inputs.R.value,0,255);///255;
+ var g = this.truncate(this.inputs.G.value,0,255);///255;
+ var b = this.truncate(this.inputs.B.value,0,255);///255;
+ var color = new Rico.Color(r,g,b);
+ this.updateColor(color);
+ this.inputs.oldColor.style.backgroundColor = color.asHex();
+ this.hide(ev);
+ },
+
+ onInputChanged : function(ev, type)
+ {
+ if(this.isMouseDownOnColor || isMouseDownOnHue)
+ return;
+
+
+ switch(type)
+ {
+ case "H": case "S": case "V":
+ var h = this.truncate(this.inputs.H.value,0,360)/360;
+ var s = this.truncate(this.inputs.S.value,0,100)/100;
+ var b = this.truncate(this.inputs.V.value,0,100)/100;
+ var color = new Rico.Color();
+ color.rgb = Rico.Color.HSBtoRGB(h,s,b);
+ return this.setColor(color,true);
+ case "R": case "G": case "B":
+ var r = this.truncate(this.inputs.R.value,0,255);///255;
+ var g = this.truncate(this.inputs.G.value,0,255);///255;
+ var b = this.truncate(this.inputs.B.value,0,255);///255;
+ var color = new Rico.Color(r,g,b);
+ return this.setColor(color,true);
+ case "HEX":
+ var color = Rico.Color.createFromHex(this.inputs.HEX.value);
+ return this.setColor(color,true);
+ }
+ },
+
+ setColor : function(color, update)
+ {
+ var hsb = color.asHSB();
+
+ this.inputs.H.value = parseInt(hsb.h*360);
+ this.inputs.S.value = parseInt(hsb.s*100);
+ this.inputs.V.value = parseInt(hsb.b*100);
+ this.inputs.R.value = color.rgb.r;
+ this.inputs.G.value = color.rgb.g;
+ this.inputs.B.value = color.rgb.b;
+ this.inputs.HEX.value = color.asHex().substring(1).toUpperCase();
+
+ var images = Prado.WebUI.TColorPicker.UIImages;
+
+ var changeCss = color.isBright() ? 'removeClassName' : 'addClassName';
+ Element[changeCss](this.inputs.selector, 'target_white');
+
+ if(update)
+ this.updateSelectors(color);
+ },
+
+ updateSelectors : function(color)
+ {
+ var hsb = color.asHSB();
+ var pos = [hsb.s*255, hsb.b*255, hsb.h*255];
+
+ this.inputs.selector.style.left = this.truncate(pos[0],0,255)+"px";
+ this.inputs.selector.style.top = this.truncate(255-pos[1],0,255)+"px";
+ this.inputs.slider.style.top = this.truncate(255-pos[2],0,255)+"px";
+
+ var hue = new Rico.Color(color.rgb.r,color.rgb.g,color.rgb.b);
+ hue.setSaturation(1); hue.setBrightness(1);
+ this.inputs.background.style.backgroundColor = hue.asHex();
+ this.inputs.currentColor.style.backgroundColor = color.asHex();
+ },
+
+ truncate : function(value, min, max)
+ {
+ value = parseInt(value);
+ return value < min ? min : value > max ? max : value;
+ }
+});
diff --git a/framework/Web/Javascripts/source/prado/controls/controls.js b/framework/Web/Javascripts/source/prado/controls/controls.js
index bbc54e9e..fd8a4c91 100644
--- a/framework/Web/Javascripts/source/prado/controls/controls.js
+++ b/framework/Web/Javascripts/source/prado/controls/controls.js
@@ -1,517 +1,517 @@
-Prado.WebUI = Class.create();
-
-Prado.WebUI.Control = Class.create({
-
- initialize : function(options)
- {
- this.registered = false;
- this.ID = options.ID;
- this.element = $(this.ID);
- this.observers = new Array();
- this.intervals = new Array();
- var e;
- if (e = Prado.Registry.get(this.ID))
- this.replace(e, options);
- else
- this.register(options);
-
- if (this === Prado.Registry.get(this.ID))
- {
- this.registered = true;
- if(this.onInit)
- this.onInit(options);
- }
- },
-
- /**
- * Registers the control wrapper in the Prado client side control registry
- * @param array control wrapper options
- */
- register : function(options)
- {
- return Prado.Registry.set(options.ID, this);
- },
-
- /**
- * De-registers the control wrapper in the Prado client side control registry
- */
- deregister : function()
- {
- // extra check so we don't ever deregister another wrapper
- if (Prado.Registry.get(this.ID)===this)
- return Prado.Registry.unset(this.ID);
- else
- debugger; // invoke debugger - this should never happen
- },
-
- /**
- * Replaces and control wrapper for an already existing control in the Prado client side control registry
- * @param object reference to the old wrapper
- * @param array control wrapper options
- */
- replace : function(oldwrapper, options)
- {
- // if there's some advanced state management in the wrapper going on, then
- // this method could be used either to copy the current state of the control
- // from the old wrapper to this new one (which then could live on, while the old
- // one could get destroyed), or to copy the new, changed options to the old wrapper,
- // (which could then left intact to keep working, while this new wrapper could be
- // disposed of by exiting its initialization without installing any handlers or
- // leaving any references to it)
- //
-
- // for now this method is simply deinitializing and deregistering the old wrapper,
- // and then registering the new wrapper for the control id
-
- if (oldwrapper.deinitialize)
- oldwrapper.deinitialize();
-
- return this.register(options);
- },
-
- /**
- * Registers an event observer which will be automatically disposed of when the wrapper
- * is deregistered
- * @param element DOM element reference or id to attach the event handler to
- * @param string event name to observe
- * @param handler event handler function
- */
- observe: function(element, eventName, handler)
- {
- var e = { _element: element, _eventName: eventName, _handler: handler };
- this.observers.push(e);
- return Event.observe(e._element,e._eventName,e._handler);
- },
-
- /**
- * Checks whether an event observer is installed and returns its index
- * @param element DOM element reference or id the event handler was attached to
- * @param string event name observed
- * @param handler event handler function
- * @result int false if the event handler is not installed, or 1-based index when installed
- */
- findObserver: function(element, eventName, handler)
- {
- var e = { _element: element, _eventName: eventName, _handler: handler };
- var idx = -1;
- for(var i=0;i<this.observers.length;i++)
- {
- var o = this.observers[i];
- if ((o._element===element) && (o._eventName===eventName) && (o._handler===handler))
- {
- idx = i;
- break;
- }
- }
- return idx;
- },
-
-
- /**
- * Degisters an event observer from the list of automatically disposed handlers
- * @param element DOM element reference or id the event handler was attached to
- * @param string event name observed
- * @param handler event handler function
- */
- stopObserving: function(element, eventName, handler)
- {
- var idx = this.findObserver(element,eventName,handler);
- if (idx!=-1)
- this.observers = this.observers.without(this.observers[idx]);
- else
- debugger; // shouldn't happen
-
- return Event.stopObserving(element,eventName,handler);
- },
-
- /**
- * Registers a code snippet or function to be executed after a delay, if the
- * wrapper hasn't been destroyed in the meantime
- * @param code function or code snippet to execute
- * @param int number of milliseconds to wait before executing
- * @return int unique ID that can be used to cancel the scheduled execution
- */
- setTimeout: function(func, delay)
- {
- if (!Object.isFunction(func))
- {
- var expr = func;
- func = function() { return eval(expr); }
- };
- var obj = this;
- return window.setTimeout(function() {
- if (!obj.isLingering())
- func();
- obj = null;
- },delay);
- },
-
- /**
- * Cancels a previously scheduled code snippet or function
- * @param int unique ID returned by setTimeout()
- */
- clearTimeout: function(timeoutid)
- {
- return window.clearTimeout(timeoutid);
- },
-
- /**
- * Registers a code snippet or function to be executed periodically, up until the
- * wrapper gets destroyed or the schedule cancelled using cancelInterval()
- * @param code function or code snippet to execute
- * @param int number of milliseconds to wait before executing
- * @return int unique ID that can be used to cancel the interval (see clearInterval() method)
- */
- setInterval: function(func, delay)
- {
- if (!Object.isFunction(func)) func = function() { eval(func); };
- var obj = this;
- var h = window.setInterval(function() {
- if (!obj.isLingering())
- func();
- },delay);
- this.intervals.push(h);
- return h;
- },
-
- /**
- * Deregisters a snipper or function previously registered with setInterval()
- * @param int unique ID of interval (returned by setInterval() previously)
- */
- clearInterval: function(intervalid)
- {
- window.clearInterval(intervalid);
- this.intervals = this.intervals.without(intervalid);
- },
-
- /**
- * Tells whether this is a wrapper that has already been deregistered and is lingering
- * @return bool true if object
- */
- isLingering: function()
- {
- return !this.registered;
- },
-
- /**
- * Deinitializes the control wrapper by calling the onDone method and the deregistering it
- * @param array control wrapper options
- */
- deinitialize : function()
- {
- if (this.registered)
- {
- if(this.onDone)
- this.onDone();
-
- // automatically stop all intervals
- while (this.intervals.length>0)
- window.clearInterval(this.intervals.pop());
-
- // automatically deregister all installed observers
- while (this.observers.length>0)
- {
- var e = this.observers.pop();
- Event.stopObserving(e._element,e._eventName,e._handler);
- }
- }
- else
- debugger; // shouldn't happen
-
- this.deregister();
-
- this.registered = false;
- }
-
-});
-
-Prado.WebUI.PostBackControl = Class.create(Prado.WebUI.Control, {
-
- onInit : function(options)
- {
- this._elementOnClick = null;
-
- if (!this.element)
- debugger; // element not found
- else
- {
- //capture the element's onclick function
- if(typeof(this.element.onclick)=="function")
- {
- this._elementOnClick = this.element.onclick.bind(this.element);
- this.element.onclick = null;
- }
- this.observe(this.element, "click", this.elementClicked.bindEvent(this,options));
- }
- },
-
- elementClicked : function(event, options)
- {
- var src = Event.element(event);
- var doPostBack = true;
- var onclicked = null;
-
- if(this._elementOnClick)
- {
- var onclicked = this._elementOnClick(event);
- if(typeof(onclicked) == "boolean")
- doPostBack = onclicked;
- }
- if(doPostBack && !Prado.Element.isDisabled(src))
- this.onPostBack(event,options);
- if(typeof(onclicked) == "boolean" && !onclicked)
- Event.stop(event);
- },
-
- onPostBack : function(event, options)
- {
- Prado.PostBack(event,options);
- }
-
-});
-
-Prado.WebUI.TButton = Class.create(Prado.WebUI.PostBackControl);
-Prado.WebUI.TLinkButton = Class.create(Prado.WebUI.PostBackControl);
-Prado.WebUI.TCheckBox = Class.create(Prado.WebUI.PostBackControl);
-Prado.WebUI.TBulletedList = Class.create(Prado.WebUI.PostBackControl);
-Prado.WebUI.TImageMap = Class.create(Prado.WebUI.PostBackControl);
-
-/**
- * TImageButton client-side behaviour. With validation, Firefox needs
- * to capture the x,y point of the clicked image in hidden form fields.
- */
-Prado.WebUI.TImageButton = Class.create(Prado.WebUI.PostBackControl,
-{
- /**
- * Override parent onPostBack function, tried to add hidden forms
- * inputs to capture x,y clicked point.
- */
- onPostBack : function(event, options)
- {
- this.addXYInput(event,options);
- Prado.PostBack(event, options);
- this.removeXYInput(event,options);
- },
-
- /**
- * Add hidden inputs to capture the x,y point clicked on the image.
- * @param event DOM click event.
- * @param array image button options.
- */
- addXYInput : function(event,options)
- {
- var imagePos = this.element.cumulativeOffset();
- var clickedPos = [event.clientX, event.clientY];
- var x = clickedPos[0]-imagePos[0]+1;
- var y = clickedPos[1]-imagePos[1]+1;
- x = x < 0 ? 0 : x;
- y = y < 0 ? 0 : y;
- var id = options['EventTarget'];
- var x_input = $(id+"_x");
- var y_input = $(id+"_y");
- if(x_input)
- {
- x_input.value = x;
- }
- else
- {
- x_input = INPUT({type:'hidden',name:id+'_x','id':id+'_x',value:x});
- this.element.parentNode.appendChild(x_input);
- }
- if(y_input)
- {
- y_input.value = y;
- }
- else
- {
- y_input = INPUT({type:'hidden',name:id+'_y','id':id+'_y',value:y});
- this.element.parentNode.appendChild(y_input);
- }
- },
-
- /**
- * Remove hidden inputs for x,y-click capturing
- * @param event DOM click event.
- * @param array image button options.
- */
- removeXYInput : function(event,options)
- {
- var id = options['EventTarget'];
- this.element.parentNode.removeChild($(id+"_x"));
- this.element.parentNode.removeChild($(id+"_y"));
- }
-});
-
-
-/**
- * Radio button, only initialize if not already checked.
- */
-Prado.WebUI.TRadioButton = Class.create(Prado.WebUI.PostBackControl,
-{
- initialize : function($super, options)
- {
- this.element = $(options['ID']);
- if(this.element)
- {
- if(!this.element.checked)
- $super(options);
- }
- }
-});
-
-
-Prado.WebUI.TTextBox = Class.create(Prado.WebUI.PostBackControl,
-{
- onInit : function(options)
- {
- this.options=options;
- if(this.options['TextMode'] != 'MultiLine')
- this.observe(this.element, "keydown", this.handleReturnKey.bind(this));
- if(this.options['AutoPostBack']==true)
- this.observe(this.element, "change", Prado.PostBack.bindEvent(this,options));
- },
-
- handleReturnKey : function(e)
- {
- if(Event.keyCode(e) == Event.KEY_RETURN)
- {
- var target = Event.element(e);
- if(target)
- {
- if(this.options['AutoPostBack']==true)
- {
- Event.fireEvent(target, "change");
- Event.stop(e);
- }
- else
- {
- if(this.options['CausesValidation'] && typeof(Prado.Validation) != "undefined")
- {
- if(!Prado.Validation.validate(this.options['FormID'], this.options['ValidationGroup'], $(this.options['ID'])))
- return Event.stop(e);
- }
- }
- }
- }
- }
-});
-
-Prado.WebUI.TListControl = Class.create(Prado.WebUI.PostBackControl,
-{
- onInit : function(options)
- {
- this.observe(this.element, "change", Prado.PostBack.bindEvent(this,options));
- }
-});
-
-Prado.WebUI.TListBox = Class.create(Prado.WebUI.TListControl);
-Prado.WebUI.TDropDownList = Class.create(Prado.WebUI.TListControl);
-
-Prado.WebUI.DefaultButton = Class.create(Prado.WebUI.Control,
-{
- onInit : function(options)
- {
- this.options = options;
- this.observe(options['Panel'], 'keydown', this.triggerEvent.bindEvent(this));
- },
-
- triggerEvent : function(ev, target)
- {
- var enterPressed = Event.keyCode(ev) == Event.KEY_RETURN;
- var isTextArea = Event.element(ev).tagName.toLowerCase() == "textarea";
- var isValidButton = Event.element(ev).tagName.toLowerCase() == "input" && Event.element(ev).type.toLowerCase() == "submit";
-
- if(enterPressed && !isTextArea && !isValidButton)
- {
- var defaultButton = $(this.options['Target']);
- if(defaultButton)
- {
- this.triggered = true;
- Event.fireEvent(defaultButton, this.options['Event']);
- Event.stop(ev);
- }
- }
- }
-});
-
-Prado.WebUI.TTextHighlighter = Class.create();
-Prado.WebUI.TTextHighlighter.prototype =
-{
- initialize:function(id)
- {
- if(!window.clipboardData) return;
- var options =
- {
- href : 'javascript:;/'+'/copy code to clipboard',
- onclick : 'Prado.WebUI.TTextHighlighter.copy(this)',
- onmouseover : 'Prado.WebUI.TTextHighlighter.hover(this)',
- onmouseout : 'Prado.WebUI.TTextHighlighter.out(this)'
- }
- var div = DIV({className:'copycode'}, A(options, 'Copy Code'));
- document.write(DIV(null,div).innerHTML);
- }
-};
-
-Object.extend(Prado.WebUI.TTextHighlighter,
-{
- copy : function(obj)
- {
- var parent = obj.parentNode.parentNode.parentNode;
- var text = '';
- for(var i = 0; i < parent.childNodes.length; i++)
- {
- var node = parent.childNodes[i];
- if(node.innerText)
- text += node.innerText == 'Copy Code' ? '' : node.innerText;
- else
- text += node.nodeValue;
- }
- if(text.length > 0)
- window.clipboardData.setData("Text", text);
- },
-
- hover : function(obj)
- {
- obj.parentNode.className = "copycode copycode_hover";
- },
-
- out : function(obj)
- {
- obj.parentNode.className = "copycode";
- }
-});
-
-
-Prado.WebUI.TCheckBoxList = Base.extend(
-{
- constructor : function(options)
- {
- Prado.Registry.set(options.ListID, this);
- for(var i = 0; i<options.ItemCount; i++)
- {
- var checkBoxOptions = Object.extend(
- {
- ID : options.ListID+"_c"+i,
- EventTarget : options.ListName+"$c"+i
- }, options);
- new Prado.WebUI.TCheckBox(checkBoxOptions);
- }
- }
-});
-
-Prado.WebUI.TRadioButtonList = Base.extend(
-{
- constructor : function(options)
- {
- Prado.Registry.set(options.ListID, this);
- for(var i = 0; i<options.ItemCount; i++)
- {
- var radioButtonOptions = Object.extend(
- {
- ID : options.ListID+"_c"+i,
- EventTarget : options.ListName+"$c"+i
- }, options);
- new Prado.WebUI.TRadioButton(radioButtonOptions);
- }
- }
-});
+Prado.WebUI = Class.create();
+
+Prado.WebUI.Control = Class.create({
+
+ initialize : function(options)
+ {
+ this.registered = false;
+ this.ID = options.ID;
+ this.element = $(this.ID);
+ this.observers = new Array();
+ this.intervals = new Array();
+ var e;
+ if (e = Prado.Registry.get(this.ID))
+ this.replace(e, options);
+ else
+ this.register(options);
+
+ if (this === Prado.Registry.get(this.ID))
+ {
+ this.registered = true;
+ if(this.onInit)
+ this.onInit(options);
+ }
+ },
+
+ /**
+ * Registers the control wrapper in the Prado client side control registry
+ * @param array control wrapper options
+ */
+ register : function(options)
+ {
+ return Prado.Registry.set(options.ID, this);
+ },
+
+ /**
+ * De-registers the control wrapper in the Prado client side control registry
+ */
+ deregister : function()
+ {
+ // extra check so we don't ever deregister another wrapper
+ if (Prado.Registry.get(this.ID)===this)
+ return Prado.Registry.unset(this.ID);
+ else
+ debugger; // invoke debugger - this should never happen
+ },
+
+ /**
+ * Replaces and control wrapper for an already existing control in the Prado client side control registry
+ * @param object reference to the old wrapper
+ * @param array control wrapper options
+ */
+ replace : function(oldwrapper, options)
+ {
+ // if there's some advanced state management in the wrapper going on, then
+ // this method could be used either to copy the current state of the control
+ // from the old wrapper to this new one (which then could live on, while the old
+ // one could get destroyed), or to copy the new, changed options to the old wrapper,
+ // (which could then left intact to keep working, while this new wrapper could be
+ // disposed of by exiting its initialization without installing any handlers or
+ // leaving any references to it)
+ //
+
+ // for now this method is simply deinitializing and deregistering the old wrapper,
+ // and then registering the new wrapper for the control id
+
+ if (oldwrapper.deinitialize)
+ oldwrapper.deinitialize();
+
+ return this.register(options);
+ },
+
+ /**
+ * Registers an event observer which will be automatically disposed of when the wrapper
+ * is deregistered
+ * @param element DOM element reference or id to attach the event handler to
+ * @param string event name to observe
+ * @param handler event handler function
+ */
+ observe: function(element, eventName, handler)
+ {
+ var e = { _element: element, _eventName: eventName, _handler: handler };
+ this.observers.push(e);
+ return Event.observe(e._element,e._eventName,e._handler);
+ },
+
+ /**
+ * Checks whether an event observer is installed and returns its index
+ * @param element DOM element reference or id the event handler was attached to
+ * @param string event name observed
+ * @param handler event handler function
+ * @result int false if the event handler is not installed, or 1-based index when installed
+ */
+ findObserver: function(element, eventName, handler)
+ {
+ var e = { _element: element, _eventName: eventName, _handler: handler };
+ var idx = -1;
+ for(var i=0;i<this.observers.length;i++)
+ {
+ var o = this.observers[i];
+ if ((o._element===element) && (o._eventName===eventName) && (o._handler===handler))
+ {
+ idx = i;
+ break;
+ }
+ }
+ return idx;
+ },
+
+
+ /**
+ * Degisters an event observer from the list of automatically disposed handlers
+ * @param element DOM element reference or id the event handler was attached to
+ * @param string event name observed
+ * @param handler event handler function
+ */
+ stopObserving: function(element, eventName, handler)
+ {
+ var idx = this.findObserver(element,eventName,handler);
+ if (idx!=-1)
+ this.observers = this.observers.without(this.observers[idx]);
+ else
+ debugger; // shouldn't happen
+
+ return Event.stopObserving(element,eventName,handler);
+ },
+
+ /**
+ * Registers a code snippet or function to be executed after a delay, if the
+ * wrapper hasn't been destroyed in the meantime
+ * @param code function or code snippet to execute
+ * @param int number of milliseconds to wait before executing
+ * @return int unique ID that can be used to cancel the scheduled execution
+ */
+ setTimeout: function(func, delay)
+ {
+ if (!Object.isFunction(func))
+ {
+ var expr = func;
+ func = function() { return eval(expr); }
+ };
+ var obj = this;
+ return window.setTimeout(function() {
+ if (!obj.isLingering())
+ func();
+ obj = null;
+ },delay);
+ },
+
+ /**
+ * Cancels a previously scheduled code snippet or function
+ * @param int unique ID returned by setTimeout()
+ */
+ clearTimeout: function(timeoutid)
+ {
+ return window.clearTimeout(timeoutid);
+ },
+
+ /**
+ * Registers a code snippet or function to be executed periodically, up until the
+ * wrapper gets destroyed or the schedule cancelled using cancelInterval()
+ * @param code function or code snippet to execute
+ * @param int number of milliseconds to wait before executing
+ * @return int unique ID that can be used to cancel the interval (see clearInterval() method)
+ */
+ setInterval: function(func, delay)
+ {
+ if (!Object.isFunction(func)) func = function() { eval(func); };
+ var obj = this;
+ var h = window.setInterval(function() {
+ if (!obj.isLingering())
+ func();
+ },delay);
+ this.intervals.push(h);
+ return h;
+ },
+
+ /**
+ * Deregisters a snipper or function previously registered with setInterval()
+ * @param int unique ID of interval (returned by setInterval() previously)
+ */
+ clearInterval: function(intervalid)
+ {
+ window.clearInterval(intervalid);
+ this.intervals = this.intervals.without(intervalid);
+ },
+
+ /**
+ * Tells whether this is a wrapper that has already been deregistered and is lingering
+ * @return bool true if object
+ */
+ isLingering: function()
+ {
+ return !this.registered;
+ },
+
+ /**
+ * Deinitializes the control wrapper by calling the onDone method and the deregistering it
+ * @param array control wrapper options
+ */
+ deinitialize : function()
+ {
+ if (this.registered)
+ {
+ if(this.onDone)
+ this.onDone();
+
+ // automatically stop all intervals
+ while (this.intervals.length>0)
+ window.clearInterval(this.intervals.pop());
+
+ // automatically deregister all installed observers
+ while (this.observers.length>0)
+ {
+ var e = this.observers.pop();
+ Event.stopObserving(e._element,e._eventName,e._handler);
+ }
+ }
+ else
+ debugger; // shouldn't happen
+
+ this.deregister();
+
+ this.registered = false;
+ }
+
+});
+
+Prado.WebUI.PostBackControl = Class.create(Prado.WebUI.Control, {
+
+ onInit : function(options)
+ {
+ this._elementOnClick = null;
+
+ if (!this.element)
+ debugger; // element not found
+ else
+ {
+ //capture the element's onclick function
+ if(typeof(this.element.onclick)=="function")
+ {
+ this._elementOnClick = this.element.onclick.bind(this.element);
+ this.element.onclick = null;
+ }
+ this.observe(this.element, "click", this.elementClicked.bindEvent(this,options));
+ }
+ },
+
+ elementClicked : function(event, options)
+ {
+ var src = Event.element(event);
+ var doPostBack = true;
+ var onclicked = null;
+
+ if(this._elementOnClick)
+ {
+ var onclicked = this._elementOnClick(event);
+ if(typeof(onclicked) == "boolean")
+ doPostBack = onclicked;
+ }
+ if(doPostBack && !Prado.Element.isDisabled(src))
+ this.onPostBack(event,options);
+ if(typeof(onclicked) == "boolean" && !onclicked)
+ Event.stop(event);
+ },
+
+ onPostBack : function(event, options)
+ {
+ Prado.PostBack(event,options);
+ }
+
+});
+
+Prado.WebUI.TButton = Class.create(Prado.WebUI.PostBackControl);
+Prado.WebUI.TLinkButton = Class.create(Prado.WebUI.PostBackControl);
+Prado.WebUI.TCheckBox = Class.create(Prado.WebUI.PostBackControl);
+Prado.WebUI.TBulletedList = Class.create(Prado.WebUI.PostBackControl);
+Prado.WebUI.TImageMap = Class.create(Prado.WebUI.PostBackControl);
+
+/**
+ * TImageButton client-side behaviour. With validation, Firefox needs
+ * to capture the x,y point of the clicked image in hidden form fields.
+ */
+Prado.WebUI.TImageButton = Class.create(Prado.WebUI.PostBackControl,
+{
+ /**
+ * Override parent onPostBack function, tried to add hidden forms
+ * inputs to capture x,y clicked point.
+ */
+ onPostBack : function(event, options)
+ {
+ this.addXYInput(event,options);
+ Prado.PostBack(event, options);
+ this.removeXYInput(event,options);
+ },
+
+ /**
+ * Add hidden inputs to capture the x,y point clicked on the image.
+ * @param event DOM click event.
+ * @param array image button options.
+ */
+ addXYInput : function(event,options)
+ {
+ var imagePos = this.element.cumulativeOffset();
+ var clickedPos = [event.clientX, event.clientY];
+ var x = clickedPos[0]-imagePos[0]+1;
+ var y = clickedPos[1]-imagePos[1]+1;
+ x = x < 0 ? 0 : x;
+ y = y < 0 ? 0 : y;
+ var id = options['EventTarget'];
+ var x_input = $(id+"_x");
+ var y_input = $(id+"_y");
+ if(x_input)
+ {
+ x_input.value = x;
+ }
+ else
+ {
+ x_input = INPUT({type:'hidden',name:id+'_x','id':id+'_x',value:x});
+ this.element.parentNode.appendChild(x_input);
+ }
+ if(y_input)
+ {
+ y_input.value = y;
+ }
+ else
+ {
+ y_input = INPUT({type:'hidden',name:id+'_y','id':id+'_y',value:y});
+ this.element.parentNode.appendChild(y_input);
+ }
+ },
+
+ /**
+ * Remove hidden inputs for x,y-click capturing
+ * @param event DOM click event.
+ * @param array image button options.
+ */
+ removeXYInput : function(event,options)
+ {
+ var id = options['EventTarget'];
+ this.element.parentNode.removeChild($(id+"_x"));
+ this.element.parentNode.removeChild($(id+"_y"));
+ }
+});
+
+
+/**
+ * Radio button, only initialize if not already checked.
+ */
+Prado.WebUI.TRadioButton = Class.create(Prado.WebUI.PostBackControl,
+{
+ initialize : function($super, options)
+ {
+ this.element = $(options['ID']);
+ if(this.element)
+ {
+ if(!this.element.checked)
+ $super(options);
+ }
+ }
+});
+
+
+Prado.WebUI.TTextBox = Class.create(Prado.WebUI.PostBackControl,
+{
+ onInit : function(options)
+ {
+ this.options=options;
+ if(this.options['TextMode'] != 'MultiLine')
+ this.observe(this.element, "keydown", this.handleReturnKey.bind(this));
+ if(this.options['AutoPostBack']==true)
+ this.observe(this.element, "change", Prado.PostBack.bindEvent(this,options));
+ },
+
+ handleReturnKey : function(e)
+ {
+ if(Event.keyCode(e) == Event.KEY_RETURN)
+ {
+ var target = Event.element(e);
+ if(target)
+ {
+ if(this.options['AutoPostBack']==true)
+ {
+ Event.fireEvent(target, "change");
+ Event.stop(e);
+ }
+ else
+ {
+ if(this.options['CausesValidation'] && typeof(Prado.Validation) != "undefined")
+ {
+ if(!Prado.Validation.validate(this.options['FormID'], this.options['ValidationGroup'], $(this.options['ID'])))
+ return Event.stop(e);
+ }
+ }
+ }
+ }
+ }
+});
+
+Prado.WebUI.TListControl = Class.create(Prado.WebUI.PostBackControl,
+{
+ onInit : function(options)
+ {
+ this.observe(this.element, "change", Prado.PostBack.bindEvent(this,options));
+ }
+});
+
+Prado.WebUI.TListBox = Class.create(Prado.WebUI.TListControl);
+Prado.WebUI.TDropDownList = Class.create(Prado.WebUI.TListControl);
+
+Prado.WebUI.DefaultButton = Class.create(Prado.WebUI.Control,
+{
+ onInit : function(options)
+ {
+ this.options = options;
+ this.observe(options['Panel'], 'keydown', this.triggerEvent.bindEvent(this));
+ },
+
+ triggerEvent : function(ev, target)
+ {
+ var enterPressed = Event.keyCode(ev) == Event.KEY_RETURN;
+ var isTextArea = Event.element(ev).tagName.toLowerCase() == "textarea";
+ var isValidButton = Event.element(ev).tagName.toLowerCase() == "input" && Event.element(ev).type.toLowerCase() == "submit";
+
+ if(enterPressed && !isTextArea && !isValidButton)
+ {
+ var defaultButton = $(this.options['Target']);
+ if(defaultButton)
+ {
+ this.triggered = true;
+ Event.fireEvent(defaultButton, this.options['Event']);
+ Event.stop(ev);
+ }
+ }
+ }
+});
+
+Prado.WebUI.TTextHighlighter = Class.create();
+Prado.WebUI.TTextHighlighter.prototype =
+{
+ initialize:function(id)
+ {
+ if(!window.clipboardData) return;
+ var options =
+ {
+ href : 'javascript:;/'+'/copy code to clipboard',
+ onclick : 'Prado.WebUI.TTextHighlighter.copy(this)',
+ onmouseover : 'Prado.WebUI.TTextHighlighter.hover(this)',
+ onmouseout : 'Prado.WebUI.TTextHighlighter.out(this)'
+ }
+ var div = DIV({className:'copycode'}, A(options, 'Copy Code'));
+ document.write(DIV(null,div).innerHTML);
+ }
+};
+
+Object.extend(Prado.WebUI.TTextHighlighter,
+{
+ copy : function(obj)
+ {
+ var parent = obj.parentNode.parentNode.parentNode;
+ var text = '';
+ for(var i = 0; i < parent.childNodes.length; i++)
+ {
+ var node = parent.childNodes[i];
+ if(node.innerText)
+ text += node.innerText == 'Copy Code' ? '' : node.innerText;
+ else
+ text += node.nodeValue;
+ }
+ if(text.length > 0)
+ window.clipboardData.setData("Text", text);
+ },
+
+ hover : function(obj)
+ {
+ obj.parentNode.className = "copycode copycode_hover";
+ },
+
+ out : function(obj)
+ {
+ obj.parentNode.className = "copycode";
+ }
+});
+
+
+Prado.WebUI.TCheckBoxList = Base.extend(
+{
+ constructor : function(options)
+ {
+ Prado.Registry.set(options.ListID, this);
+ for(var i = 0; i<options.ItemCount; i++)
+ {
+ var checkBoxOptions = Object.extend(
+ {
+ ID : options.ListID+"_c"+i,
+ EventTarget : options.ListName+"$c"+i
+ }, options);
+ new Prado.WebUI.TCheckBox(checkBoxOptions);
+ }
+ }
+});
+
+Prado.WebUI.TRadioButtonList = Base.extend(
+{
+ constructor : function(options)
+ {
+ Prado.Registry.set(options.ListID, this);
+ for(var i = 0; i<options.ItemCount; i++)
+ {
+ var radioButtonOptions = Object.extend(
+ {
+ ID : options.ListID+"_c"+i,
+ EventTarget : options.ListName+"$c"+i
+ }, options);
+ new Prado.WebUI.TRadioButton(radioButtonOptions);
+ }
+ }
+});
diff --git a/framework/Web/Javascripts/source/prado/controls/htmlarea.js b/framework/Web/Javascripts/source/prado/controls/htmlarea.js
index 4cb37c6f..56d4cf16 100644
--- a/framework/Web/Javascripts/source/prado/controls/htmlarea.js
+++ b/framework/Web/Javascripts/source/prado/controls/htmlarea.js
@@ -1,149 +1,149 @@
-
-/*
- *
- * HtmlArea (tinyMCE) wrapper
- *
- * @author Gabor Berczi <gabor.berczi@devworx.hu>
- *
-*/
-
-
-Prado.WebUI.THtmlArea = Class.create(Prado.WebUI.Control,
-{
- initialize: function($super, options)
- {
- options.ID = options.EditorOptions.elements;
- $super(options);
- },
-
- onInit : function(options)
- {
- this.options = options;
-
- var obj = this;
- this.ajaxresponder = {
- onComplete : function(request)
- {
- if(request && (request instanceof Prado.AjaxRequest))
- obj.checkInstance();
- }
- };
- this.registerAjaxHook();
-
- this.registerInstance();
- },
-
- registerInstance: function()
- {
- if (typeof tinyMCE_GZ == 'undefined')
- {
- if (typeof tinyMCE == 'undefined')
- {
- if (typeof Prado.CallbackRequest != 'undefined')
- if (typeof Prado.CallbackRequest.transport != 'undefined')
- {
- // we're in a callback
- // try it again in some time, as tinyMCE is most likely still loading
- this.setTimeout(this.registerInstance.bind(this), 50);
- return;
- }
- throw "TinyMCE libraries must be loaded first";
- }
- Prado.WebUI.THtmlArea.tinyMCELoadState = 255;
- this.initInstance();
- }
- else
- if (Prado.WebUI.THtmlArea.tinyMCELoadState==255)
- this.initInstance();
- else
- {
- Prado.WebUI.THtmlArea.pendingRegistrations.push(this.options.ID);
- if (Prado.WebUI.THtmlArea.tinyMCELoadState==0)
- {
- Prado.WebUI.THtmlArea.tinyMCELoadState = 1;
- tinyMCE_GZ.init(
- this.options.CompressionOptions,
- this.compressedScriptsLoaded.bind(this)
- );
- }
- }
- },
-
- compressedScriptsLoaded: function()
- {
- Prado.WebUI.THtmlArea.tinyMCELoadState = 255;
- tinymce.dom.Event._pageInit();
- var wrapper;
- while(Prado.WebUI.THtmlArea.pendingRegistrations.length>0)
- if (wrapper = Prado.Registry.get(Prado.WebUI.THtmlArea.pendingRegistrations.pop()))
- wrapper.initInstance();
- },
-
- initInstance: function()
- {
- tinyMCE.init(this.options.EditorOptions);
- },
-
- checkInstance: function()
- {
- if (!document.getElementById(this.ID))
- this.deinitialize();
- },
-
- removePreviousInstance: function()
- {
- for(var i=0;i<tinyMCE.editors.length;i++)
- if (tinyMCE.editors[i].id==this.ID)
- {
- tinyMCE.editors.splice(i,1); // ugly hack, but works
- this.deRegisterAjaxHook();
- this.deregister();
- i--;
- }
- },
-
- registerAjaxHook: function()
- {
- if (typeof(Ajax)!="undefined")
- if (typeof(Ajax.Responders)!="undefined")
- Ajax.Responders.register(this.ajaxresponder);
- },
-
-
- deRegisterAjaxHook: function()
- {
- if (typeof(Ajax)!="undefined")
- if (typeof(Ajax.Responders)!="undefined")
- Ajax.Responders.unregister(this.ajaxresponder);
- },
-
- onDone: function()
- {
- // check for previous tinyMCE registration, and try to remove it gracefully first
- var prev = tinyMCE.get(this.ID);
- if (prev)
- try
- {
- tinyMCE.execCommand('mceFocus', false, this.ID);
- tinyMCE.execCommand('mceRemoveControl', false, this.ID);
- }
- catch (e)
- {
- // suppress error here in case editor can't be properly removed
- // (happens when <textarea> has been removed from DOM tree without deinitialzing the tinyMCE editor first)
- }
-
- // doublecheck editor instance here and remove manually from tinyMCE-registry if neccessary
- this.removePreviousInstance();
-
- this.deRegisterAjaxHook();
- }
-});
-
-Object.extend(Prado.WebUI.THtmlArea,
-{
- pendingRegistrations : [],
- tinyMCELoadState : 0
-});
-
-
+
+/*
+ *
+ * HtmlArea (tinyMCE) wrapper
+ *
+ * @author Gabor Berczi <gabor.berczi@devworx.hu>
+ *
+*/
+
+
+Prado.WebUI.THtmlArea = Class.create(Prado.WebUI.Control,
+{
+ initialize: function($super, options)
+ {
+ options.ID = options.EditorOptions.elements;
+ $super(options);
+ },
+
+ onInit : function(options)
+ {
+ this.options = options;
+
+ var obj = this;
+ this.ajaxresponder = {
+ onComplete : function(request)
+ {
+ if(request && (request instanceof Prado.AjaxRequest))
+ obj.checkInstance();
+ }
+ };
+ this.registerAjaxHook();
+
+ this.registerInstance();
+ },
+
+ registerInstance: function()
+ {
+ if (typeof tinyMCE_GZ == 'undefined')
+ {
+ if (typeof tinyMCE == 'undefined')
+ {
+ if (typeof Prado.CallbackRequest != 'undefined')
+ if (typeof Prado.CallbackRequest.transport != 'undefined')
+ {
+ // we're in a callback
+ // try it again in some time, as tinyMCE is most likely still loading
+ this.setTimeout(this.registerInstance.bind(this), 50);
+ return;
+ }
+ throw "TinyMCE libraries must be loaded first";
+ }
+ Prado.WebUI.THtmlArea.tinyMCELoadState = 255;
+ this.initInstance();
+ }
+ else
+ if (Prado.WebUI.THtmlArea.tinyMCELoadState==255)
+ this.initInstance();
+ else
+ {
+ Prado.WebUI.THtmlArea.pendingRegistrations.push(this.options.ID);
+ if (Prado.WebUI.THtmlArea.tinyMCELoadState==0)
+ {
+ Prado.WebUI.THtmlArea.tinyMCELoadState = 1;
+ tinyMCE_GZ.init(
+ this.options.CompressionOptions,
+ this.compressedScriptsLoaded.bind(this)
+ );
+ }
+ }
+ },
+
+ compressedScriptsLoaded: function()
+ {
+ Prado.WebUI.THtmlArea.tinyMCELoadState = 255;
+ tinymce.dom.Event._pageInit();
+ var wrapper;
+ while(Prado.WebUI.THtmlArea.pendingRegistrations.length>0)
+ if (wrapper = Prado.Registry.get(Prado.WebUI.THtmlArea.pendingRegistrations.pop()))
+ wrapper.initInstance();
+ },
+
+ initInstance: function()
+ {
+ tinyMCE.init(this.options.EditorOptions);
+ },
+
+ checkInstance: function()
+ {
+ if (!document.getElementById(this.ID))
+ this.deinitialize();
+ },
+
+ removePreviousInstance: function()
+ {
+ for(var i=0;i<tinyMCE.editors.length;i++)
+ if (tinyMCE.editors[i].id==this.ID)
+ {
+ tinyMCE.editors.splice(i,1); // ugly hack, but works
+ this.deRegisterAjaxHook();
+ this.deregister();
+ i--;
+ }
+ },
+
+ registerAjaxHook: function()
+ {
+ if (typeof(Ajax)!="undefined")
+ if (typeof(Ajax.Responders)!="undefined")
+ Ajax.Responders.register(this.ajaxresponder);
+ },
+
+
+ deRegisterAjaxHook: function()
+ {
+ if (typeof(Ajax)!="undefined")
+ if (typeof(Ajax.Responders)!="undefined")
+ Ajax.Responders.unregister(this.ajaxresponder);
+ },
+
+ onDone: function()
+ {
+ // check for previous tinyMCE registration, and try to remove it gracefully first
+ var prev = tinyMCE.get(this.ID);
+ if (prev)
+ try
+ {
+ tinyMCE.execCommand('mceFocus', false, this.ID);
+ tinyMCE.execCommand('mceRemoveControl', false, this.ID);
+ }
+ catch (e)
+ {
+ // suppress error here in case editor can't be properly removed
+ // (happens when <textarea> has been removed from DOM tree without deinitialzing the tinyMCE editor first)
+ }
+
+ // doublecheck editor instance here and remove manually from tinyMCE-registry if neccessary
+ this.removePreviousInstance();
+
+ this.deRegisterAjaxHook();
+ }
+});
+
+Object.extend(Prado.WebUI.THtmlArea,
+{
+ pendingRegistrations : [],
+ tinyMCELoadState : 0
+});
+
+
diff --git a/framework/Web/Javascripts/source/prado/controls/keyboard.js b/framework/Web/Javascripts/source/prado/controls/keyboard.js
index 5b8a6b15..25541074 100644
--- a/framework/Web/Javascripts/source/prado/controls/keyboard.js
+++ b/framework/Web/Javascripts/source/prado/controls/keyboard.js
@@ -1,161 +1,161 @@
-Prado.WebUI.TKeyboard = Class.create(Prado.WebUI.Control,
-{
- onInit : function(options)
- {
- this.cssClass = options['CssClass'];
- this.forControl = document.getElementById(options['ForControl']);
- this.autoHide = options['AutoHide'];
-
- this.flagShift = false;
- this.flagCaps = false;
- this.flagHover = false;
- this.flagFocus = false;
-
- this.keys = new Array
- (
- new Array('` ~ D', '1 ! D', '2 @ D', '3 # D', '4 $ D', '5 % D', '6 ^ D', '7 &amp; D', '8 * D', '9 ( D', '0 ) D', '- _ D', '= + D', 'Bksp Bksp Bksp'),
- new Array('Del Del Del', 'q Q L', 'w W L', 'e E L', 'r R L', 't T L', 'y Y L', 'u U L', 'i I L', 'o O L', 'p P L', '[ { D', '] } D', '\\ | \\'),
- new Array('Caps Caps Caps', 'a A L', 's S L', 'd D L', 'f F L', 'g G L', 'h H L', 'j J L', 'k K L', 'l L L', '; : D', '\' " D', 'Exit Exit Exit'),
- new Array('Shift Shift Shift', 'z Z L', 'x X L', 'c C L', 'v V L', 'b B L', 'n N L', 'm M L', ', &lt; D', '. &gt; D', '/ ? D', 'Shift Shift Shift')
- );
-
- if (this.isObject(this.forControl))
- {
- this.forControl.keyboard = this;
- this.forControl.onfocus = function() {this.keyboard.show(); };
- this.forControl.onblur = function() {if (this.keyboard.flagHover == false) this.keyboard.hide();};
- this.forControl.onkeydown = function(e) {if (!e) e = window.event; var key = (e.keyCode)?e.keyCode:e.which; if(key == 9) this.keyboard.hide();;};
- this.forControl.onselect = this.saveSelection;
- this.forControl.onclick = this.saveSelection;
- this.forControl.onkeyup = this.saveSelection;
- }
-
- this.render();
-
- this.tagKeyboard.onmouseover = function() {this.keyboard.flagHover = true;};
- this.tagKeyboard.onmouseout = function() {this.keyboard.flagHover = false;};
-
- if (!this.autoHide) this.show();
- },
-
- isObject : function(a)
- {
- return (typeof a == 'object' && !!a) || typeof a == 'function';
- },
-
- createElement : function(tagName, attributes, parent)
- {
- var tagElement = document.createElement(tagName);
- if (this.isObject(attributes)) for (attribute in attributes) tagElement[attribute] = attributes[attribute];
- if (this.isObject(parent)) parent.appendChild(tagElement);
- return tagElement;
- },
-
- onmouseover : function()
- {
- this.className += ' Hover';
- },
-
- onmouseout : function()
- {
- this.className = this.className.replace(/( Hover| Active)/ig, '');
- },
-
- onmousedown : function()
- {
- this.className += ' Active';
- },
-
- onmouseup : function()
- {
- this.className = this.className.replace(/( Active)/ig, '');
- this.keyboard.type(this.innerHTML);
- },
-
- render : function()
- {
- this.tagKeyboard = this.createElement('div', {className: this.cssClass, onselectstart: function() {return false;}}, this.element);
- this.tagKeyboard.keyboard = this;
-
- for (var line = 0; line < this.keys.length; line++)
- {
- var tagLine = this.createElement('div', {className: 'Line'}, this.tagKeyboard);
- for (var key = 0; key < this.keys[line].length; key++)
- {
- var split = this.keys[line][key].split(' ');
- var tagKey = this.createElement('div', {className: 'Key ' + split[2]}, tagLine);
- var tagKey1 = this.createElement('div', {className: 'Key1', innerHTML: split[0], keyboard: this, onmouseover: this.onmouseover, onmouseout: this.onmouseout, onmousedown: this.onmousedown, onmouseup: this.onmouseup}, tagKey);
- var tagKey2 = this.createElement('div', {className: 'Key2', innerHTML: split[1], keyboard: this, onmouseover: this.onmouseover, onmouseout: this.onmouseout, onmousedown: this.onmousedown, onmouseup: this.onmouseup}, tagKey);
- }
- }
- },
-
- isShown : function()
- {
- return (this.tagKeyboard.style.visibility.toLowerCase() == 'visible');
- },
-
- show : function()
- {
- if (this.isShown() == false) this.tagKeyboard.style.visibility = 'visible';
- },
-
- hide : function()
- {
- if (this.isShown() == true && this.autoHide) {this.tagKeyboard.style.visibility = 'hidden'; }
- },
-
- type : function(key)
- {
- var input = this.forControl;
- var command = key.toLowerCase();
-
- if (command == 'exit') {this.hide();}
- else if (input != 'undefined' && input != null && command == 'bksp') {this.insert(input, 'bksp');}
- else if (input != 'undefined' && input != null && command == 'del') {this.insert(input, 'del');}
- else if (command == 'shift') {this.tagKeyboard.className = this.flagShift?'Keyboard Off':'Keyboard Shift';this.flagShift = this.flagShift?false:true;}
- else if (command == 'caps') {this.tagKeyboard.className = this.caps?'Keyboard Off':'Keyboard Caps';this.caps = this.caps?false:true;}
- else if (input != 'undefined' && input != null)
- {
- if (this.flagShift == true) {this.flagShift = false; this.tagKeyboard.className = 'Keyboard Off';}
- key = key.replace(/&gt;/, '>'); key = key.replace(/&lt;/, '<'); key = key.replace(/&amp;/, '&');
- this.insert(input, key);
- }
-
- if (command != 'exit') input.focus();
- },
-
- saveSelection : function()
- {
- if (this.keyboard.forControl.createTextRange)
- {
- this.keyboard.selection = document.selection.createRange().duplicate();
- return;
- }
- },
-
- insert : function(field, value)
- {
- if (this.forControl.createTextRange && this.selection)
- {
- if (value == 'bksp') {this.selection.moveStart("character", -1); this.selection.text = '';}
- else if (value == 'del') {this.selection.moveEnd("character", 1); this.selection.text = '';}
- else {this.selection.text = value;}
- this.selection.select();
- }
- else
- {
- var selectStart = this.forControl.selectionStart;
- var selectEnd = this.forControl.selectionEnd;
- var start = (this.forControl.value).substring(0, selectStart);
- var end = (this.forControl.value).substring(selectEnd, this.forControl.textLength);
-
- if (value == 'bksp') {start = start.substring(0, start.length - 1); selectStart -= 1; value = '';}
- if (value == 'del') {end = end.substring(1, end.length); value = '';}
-
- this.forControl.value = start + value + end;
- this.forControl.selectionStart = selectEnd + value.length;
- this.forControl.selectionEnd = selectStart + value.length;
- }
- }
-});
+Prado.WebUI.TKeyboard = Class.create(Prado.WebUI.Control,
+{
+ onInit : function(options)
+ {
+ this.cssClass = options['CssClass'];
+ this.forControl = document.getElementById(options['ForControl']);
+ this.autoHide = options['AutoHide'];
+
+ this.flagShift = false;
+ this.flagCaps = false;
+ this.flagHover = false;
+ this.flagFocus = false;
+
+ this.keys = new Array
+ (
+ new Array('` ~ D', '1 ! D', '2 @ D', '3 # D', '4 $ D', '5 % D', '6 ^ D', '7 &amp; D', '8 * D', '9 ( D', '0 ) D', '- _ D', '= + D', 'Bksp Bksp Bksp'),
+ new Array('Del Del Del', 'q Q L', 'w W L', 'e E L', 'r R L', 't T L', 'y Y L', 'u U L', 'i I L', 'o O L', 'p P L', '[ { D', '] } D', '\\ | \\'),
+ new Array('Caps Caps Caps', 'a A L', 's S L', 'd D L', 'f F L', 'g G L', 'h H L', 'j J L', 'k K L', 'l L L', '; : D', '\' " D', 'Exit Exit Exit'),
+ new Array('Shift Shift Shift', 'z Z L', 'x X L', 'c C L', 'v V L', 'b B L', 'n N L', 'm M L', ', &lt; D', '. &gt; D', '/ ? D', 'Shift Shift Shift')
+ );
+
+ if (this.isObject(this.forControl))
+ {
+ this.forControl.keyboard = this;
+ this.forControl.onfocus = function() {this.keyboard.show(); };
+ this.forControl.onblur = function() {if (this.keyboard.flagHover == false) this.keyboard.hide();};
+ this.forControl.onkeydown = function(e) {if (!e) e = window.event; var key = (e.keyCode)?e.keyCode:e.which; if(key == 9) this.keyboard.hide();;};
+ this.forControl.onselect = this.saveSelection;
+ this.forControl.onclick = this.saveSelection;
+ this.forControl.onkeyup = this.saveSelection;
+ }
+
+ this.render();
+
+ this.tagKeyboard.onmouseover = function() {this.keyboard.flagHover = true;};
+ this.tagKeyboard.onmouseout = function() {this.keyboard.flagHover = false;};
+
+ if (!this.autoHide) this.show();
+ },
+
+ isObject : function(a)
+ {
+ return (typeof a == 'object' && !!a) || typeof a == 'function';
+ },
+
+ createElement : function(tagName, attributes, parent)
+ {
+ var tagElement = document.createElement(tagName);
+ if (this.isObject(attributes)) for (attribute in attributes) tagElement[attribute] = attributes[attribute];
+ if (this.isObject(parent)) parent.appendChild(tagElement);
+ return tagElement;
+ },
+
+ onmouseover : function()
+ {
+ this.className += ' Hover';
+ },
+
+ onmouseout : function()
+ {
+ this.className = this.className.replace(/( Hover| Active)/ig, '');
+ },
+
+ onmousedown : function()
+ {
+ this.className += ' Active';
+ },
+
+ onmouseup : function()
+ {
+ this.className = this.className.replace(/( Active)/ig, '');
+ this.keyboard.type(this.innerHTML);
+ },
+
+ render : function()
+ {
+ this.tagKeyboard = this.createElement('div', {className: this.cssClass, onselectstart: function() {return false;}}, this.element);
+ this.tagKeyboard.keyboard = this;
+
+ for (var line = 0; line < this.keys.length; line++)
+ {
+ var tagLine = this.createElement('div', {className: 'Line'}, this.tagKeyboard);
+ for (var key = 0; key < this.keys[line].length; key++)
+ {
+ var split = this.keys[line][key].split(' ');
+ var tagKey = this.createElement('div', {className: 'Key ' + split[2]}, tagLine);
+ var tagKey1 = this.createElement('div', {className: 'Key1', innerHTML: split[0], keyboard: this, onmouseover: this.onmouseover, onmouseout: this.onmouseout, onmousedown: this.onmousedown, onmouseup: this.onmouseup}, tagKey);
+ var tagKey2 = this.createElement('div', {className: 'Key2', innerHTML: split[1], keyboard: this, onmouseover: this.onmouseover, onmouseout: this.onmouseout, onmousedown: this.onmousedown, onmouseup: this.onmouseup}, tagKey);
+ }
+ }
+ },
+
+ isShown : function()
+ {
+ return (this.tagKeyboard.style.visibility.toLowerCase() == 'visible');
+ },
+
+ show : function()
+ {
+ if (this.isShown() == false) this.tagKeyboard.style.visibility = 'visible';
+ },
+
+ hide : function()
+ {
+ if (this.isShown() == true && this.autoHide) {this.tagKeyboard.style.visibility = 'hidden'; }
+ },
+
+ type : function(key)
+ {
+ var input = this.forControl;
+ var command = key.toLowerCase();
+
+ if (command == 'exit') {this.hide();}
+ else if (input != 'undefined' && input != null && command == 'bksp') {this.insert(input, 'bksp');}
+ else if (input != 'undefined' && input != null && command == 'del') {this.insert(input, 'del');}
+ else if (command == 'shift') {this.tagKeyboard.className = this.flagShift?'Keyboard Off':'Keyboard Shift';this.flagShift = this.flagShift?false:true;}
+ else if (command == 'caps') {this.tagKeyboard.className = this.caps?'Keyboard Off':'Keyboard Caps';this.caps = this.caps?false:true;}
+ else if (input != 'undefined' && input != null)
+ {
+ if (this.flagShift == true) {this.flagShift = false; this.tagKeyboard.className = 'Keyboard Off';}
+ key = key.replace(/&gt;/, '>'); key = key.replace(/&lt;/, '<'); key = key.replace(/&amp;/, '&');
+ this.insert(input, key);
+ }
+
+ if (command != 'exit') input.focus();
+ },
+
+ saveSelection : function()
+ {
+ if (this.keyboard.forControl.createTextRange)
+ {
+ this.keyboard.selection = document.selection.createRange().duplicate();
+ return;
+ }
+ },
+
+ insert : function(field, value)
+ {
+ if (this.forControl.createTextRange && this.selection)
+ {
+ if (value == 'bksp') {this.selection.moveStart("character", -1); this.selection.text = '';}
+ else if (value == 'del') {this.selection.moveEnd("character", 1); this.selection.text = '';}
+ else {this.selection.text = value;}
+ this.selection.select();
+ }
+ else
+ {
+ var selectStart = this.forControl.selectionStart;
+ var selectEnd = this.forControl.selectionEnd;
+ var start = (this.forControl.value).substring(0, selectStart);
+ var end = (this.forControl.value).substring(selectEnd, this.forControl.textLength);
+
+ if (value == 'bksp') {start = start.substring(0, start.length - 1); selectStart -= 1; value = '';}
+ if (value == 'del') {end = end.substring(1, end.length); value = '';}
+
+ this.forControl.value = start + value + end;
+ this.forControl.selectionStart = selectEnd + value.length;
+ this.forControl.selectionEnd = selectStart + value.length;
+ }
+ }
+});
diff --git a/framework/Web/Javascripts/source/prado/controls/tabpanel.js b/framework/Web/Javascripts/source/prado/controls/tabpanel.js
index 157664e3..bd0a7494 100644
--- a/framework/Web/Javascripts/source/prado/controls/tabpanel.js
+++ b/framework/Web/Javascripts/source/prado/controls/tabpanel.js
@@ -1,60 +1,60 @@
-Prado.WebUI.TTabPanel = Class.create(Prado.WebUI.Control,
-{
- onInit : function(options)
- {
- this.views = options.Views;
- this.viewsvis = options.ViewsVis;
- this.hiddenField = $(options.ID+'_1');
- this.activeCssClass = options.ActiveCssClass;
- this.normalCssClass = options.NormalCssClass;
- var length = options.Views.length;
- for(var i = 0; i<length; i++)
- {
- var item = options.Views[i];
- var element = $(item+'_0');
- if (element && options.ViewsVis[i])
- {
- this.observe(element, "click", this.elementClicked.bindEvent(this,item));
- if (options.AutoSwitch)
- this.observe(element, "mouseenter", this.elementClicked.bindEvent(this,item));
- }
-
- if(element)
- {
- var view = $(options.Views[i]);
- if (view)
- if(this.hiddenField.value == i)
- {
- element.className=this.activeCssClass;
- view.show();
- } else {
- element.className=this.normalCssClass;
- view.hide();
- }
- }
- }
- },
-
- elementClicked : function(event,viewID)
- {
- var length = this.views.length;
- for(var i = 0; i<length; i++)
- {
- var item = this.views[i];
- if ($(item))
- {
- if(item == viewID)
- {
- $(item+'_0').className=this.activeCssClass;
- $(item).show();
- this.hiddenField.value=i;
- }
- else
- {
- $(item+'_0').className=this.normalCssClass;
- $(item).hide();
- }
- }
- }
- }
-});
+Prado.WebUI.TTabPanel = Class.create(Prado.WebUI.Control,
+{
+ onInit : function(options)
+ {
+ this.views = options.Views;
+ this.viewsvis = options.ViewsVis;
+ this.hiddenField = $(options.ID+'_1');
+ this.activeCssClass = options.ActiveCssClass;
+ this.normalCssClass = options.NormalCssClass;
+ var length = options.Views.length;
+ for(var i = 0; i<length; i++)
+ {
+ var item = options.Views[i];
+ var element = $(item+'_0');
+ if (element && options.ViewsVis[i])
+ {
+ this.observe(element, "click", this.elementClicked.bindEvent(this,item));
+ if (options.AutoSwitch)
+ this.observe(element, "mouseenter", this.elementClicked.bindEvent(this,item));
+ }
+
+ if(element)
+ {
+ var view = $(options.Views[i]);
+ if (view)
+ if(this.hiddenField.value == i)
+ {
+ element.className=this.activeCssClass;
+ view.show();
+ } else {
+ element.className=this.normalCssClass;
+ view.hide();
+ }
+ }
+ }
+ },
+
+ elementClicked : function(event,viewID)
+ {
+ var length = this.views.length;
+ for(var i = 0; i<length; i++)
+ {
+ var item = this.views[i];
+ if ($(item))
+ {
+ if(item == viewID)
+ {
+ $(item+'_0').className=this.activeCssClass;
+ $(item).show();
+ this.hiddenField.value=i;
+ }
+ else
+ {
+ $(item+'_0').className=this.normalCssClass;
+ $(item).hide();
+ }
+ }
+ }
+ }
+});
diff --git a/framework/Web/Javascripts/source/prado/datepicker/datepicker.js b/framework/Web/Javascripts/source/prado/datepicker/datepicker.js
index e92904c8..ad7eb019 100644
--- a/framework/Web/Javascripts/source/prado/datepicker/datepicker.js
+++ b/framework/Web/Javascripts/source/prado/datepicker/datepicker.js
@@ -1,790 +1,790 @@
-Prado.WebUI.TDatePicker = Class.create(Prado.WebUI.Control,
-{
- MonthNames : [ "January", "February", "March", "April",
- "May", "June", "July", "August",
- "September", "October", "November", "December"
- ],
- AbbreviatedMonthNames : ["Jan", "Feb", "Mar", "Apr", "May",
- "Jun", "Jul", "Aug", "Sep", "Oct", "Nov", "Dec"],
-
- ShortWeekDayNames : ["Sun", "Mon", "Tue", "Wed", "Thu", "Fri", "Sat" ],
-
- Format : "yyyy-MM-dd",
-
- FirstDayOfWeek : 1, // 0 for sunday
-
- ClassName : "",
-
- CalendarStyle : "default",
-
- FromYear : 2005, UpToYear: 2020,
-
- onInit : function(options)
- {
- this.options = options || [];
- this.control = $(options.ID);
- this.dateSlot = new Array(42);
- this.weekSlot = new Array(6);
- this.minimalDaysInFirstWeek = 4;
- this.positionMode = 'Bottom';
-
- Prado.Registry.set(options.ID, this);
-
- //which element to trigger to show the calendar
- if(this.options.Trigger)
- {
- this.trigger = $(this.options.Trigger) ;
- var triggerEvent = this.options.TriggerEvent || "click";
- }
- else
- {
- this.trigger = this.control;
- var triggerEvent = this.options.TriggerEvent || "focus";
- }
-
- // Popup position
- if(this.options.PositionMode == 'Top')
- {
- this.positionMode = this.options.PositionMode;
- }
-
- Object.extend(this,options);
- // generate default date _after_ extending options
- this.selectedDate = this.newDate();
-
- Event.observe(this.trigger, triggerEvent, this.show.bindEvent(this));
-
- // Listen to change event if needed
- if (typeof(this.options.OnDateChanged) == "function")
- {
- if(this.options.InputMode == "TextBox")
- {
- Event.observe(this.control, "change", this.onDateChanged.bindEvent(this));
- }
- else
- {
- var day = Prado.WebUI.TDatePicker.getDayListControl(this.control);
- var month = Prado.WebUI.TDatePicker.getMonthListControl(this.control);
- var year = Prado.WebUI.TDatePicker.getYearListControl(this.control);
- Event.observe (day, "change", this.onDateChanged.bindEvent(this));
- Event.observe (month, "change", this.onDateChanged.bindEvent(this));
- Event.observe (year, "change", this.onDateChanged.bindEvent(this));
-
- }
-
-
- }
-
- },
-
- create : function()
- {
- if(typeof(this._calDiv) != "undefined")
- return;
-
- var div;
- var table;
- var tbody;
- var tr;
- var td;
-
- // Create the top-level div element
- this._calDiv = document.createElement("div");
- this._calDiv.className = "TDatePicker_"+this.CalendarStyle+" "+this.ClassName;
- this._calDiv.style.display = "none";
- this._calDiv.style.position = "absolute"
-
- // header div
- div = document.createElement("div");
- div.className = "calendarHeader";
- this._calDiv.appendChild(div);
-
- table = document.createElement("table");
- table.style.cellSpacing = 0;
- div.appendChild(table);
-
- tbody = document.createElement("tbody");
- table.appendChild(tbody);
-
- tr = document.createElement("tr");
- tbody.appendChild(tr);
-
- // Previous Month Button
- td = document.createElement("td");
- var previousMonth = document.createElement("input");
- previousMonth.className = "prevMonthButton button";
- previousMonth.type = "button"
- previousMonth.value = "<<";
- td.appendChild(previousMonth);
- tr.appendChild(td);
-
-
-
- //
- // Create the month drop down
- //
- td = document.createElement("td");
- tr.appendChild(td);
- this._monthSelect = document.createElement("select");
- this._monthSelect.className = "months";
- for (var i = 0 ; i < this.MonthNames.length ; i++) {
- var opt = document.createElement("option");
- opt.innerHTML = this.MonthNames[i];
- opt.value = i;
- if (i == this.selectedDate.getMonth()) {
- opt.selected = true;
- }
- this._monthSelect.appendChild(opt);
- }
- td.appendChild(this._monthSelect);
-
-
- //
- // Create the year drop down
- //
- td = document.createElement("td");
- td.className = "labelContainer";
- tr.appendChild(td);
- this._yearSelect = document.createElement("select");
- for(var i=this.FromYear; i <= this.UpToYear; ++i) {
- var opt = document.createElement("option");
- opt.innerHTML = i;
- opt.value = i;
- if (i == this.selectedDate.getFullYear()) {
- opt.selected = false;
- }
- this._yearSelect.appendChild(opt);
- }
- td.appendChild(this._yearSelect);
-
-
- td = document.createElement("td");
- var nextMonth = document.createElement("input");
- nextMonth.className = "nextMonthButton button";
- nextMonth.type = "button";
- nextMonth.value = ">>";
- td.appendChild(nextMonth);
- tr.appendChild(td);
-
- // Calendar body
- div = document.createElement("div");
- div.className = "calendarBody";
- this._calDiv.appendChild(div);
- var calendarBody = div;
-
- // Create the inside of calendar body
-
- var text;
- table = document.createElement("table");
- table.align="center";
- table.className = "grid";
-
- div.appendChild(table);
- var thead = document.createElement("thead");
- table.appendChild(thead);
- tr = document.createElement("tr");
- thead.appendChild(tr);
-
- for(i=0; i < 7; ++i) {
- td = document.createElement("th");
- text = document.createTextNode(this.ShortWeekDayNames[(i+this.FirstDayOfWeek)%7]);
- td.appendChild(text);
- td.className = "weekDayHead";
- tr.appendChild(td);
- }
-
- // Date grid
- tbody = document.createElement("tbody");
- table.appendChild(tbody);
-
- for(var week=0; week<6; ++week) {
- tr = document.createElement("tr");
- tbody.appendChild(tr);
-
- for(var day=0; day<7; ++day) {
- td = document.createElement("td");
- td.className = "calendarDate";
- text = document.createTextNode(String.fromCharCode(160));
- td.appendChild(text);
-
- tr.appendChild(td);
- var tmp = new Object();
- tmp.tag = "DATE";
- tmp.value = -1;
- tmp.data = text;
- this.dateSlot[(week*7)+day] = tmp;
-
- Event.observe(td, "mouseover", this.hover.bindEvent(this));
- Event.observe(td, "mouseout", this.hover.bindEvent(this));
-
- }
- }
-
- // Calendar Footer
- div = document.createElement("div");
- div.className = "calendarFooter";
- this._calDiv.appendChild(div);
-
- var todayButton = document.createElement("input");
- todayButton.type="button";
- todayButton.className = "todayButton";
- var today = this.newDate();
- var buttonText = today.SimpleFormat(this.Format,this);
- todayButton.value = buttonText;
- div.appendChild(todayButton);
-
- if(Prado.Browser().ie)
- {
- this.iePopUp = document.createElement('iframe');
- this.iePopUp.src = Prado.WebUI.TDatePicker.spacer;
- this.iePopUp.style.position = "absolute"
- this.iePopUp.scrolling="no"
- this.iePopUp.frameBorder="0"
- this.control.parentNode.appendChild(this.iePopUp);
- }
-
- this.control.parentNode.appendChild(this._calDiv);
-
- this.update();
- this.updateHeader();
-
- this.ieHack(true);
-
- // IE55+ extension
- previousMonth.hideFocus = true;
- nextMonth.hideFocus = true;
- todayButton.hideFocus = true;
- // end IE55+ extension
-
- // hook up events
- Event.observe(previousMonth, "click", this.prevMonth.bindEvent(this));
- Event.observe(nextMonth, "click", this.nextMonth.bindEvent(this));
- Event.observe(todayButton, "click", this.selectToday.bindEvent(this));
- //Event.observe(clearButton, "click", this.clearSelection.bindEvent(this));
- Event.observe(this._monthSelect, "change", this.monthSelect.bindEvent(this));
- Event.observe(this._yearSelect, "change", this.yearSelect.bindEvent(this));
-
- // ie, opera
- Event.observe(this._calDiv, "mousewheel", this.mouseWheelChange.bindEvent(this));
- // ff
- Event.observe(this._calDiv, "DOMMouseScroll", this.mouseWheelChange.bindEvent(this));
-
- Event.observe(calendarBody, "click", this.selectDate.bindEvent(this));
-
- Prado.Element.focus(this.control);
-
- },
-
- ieHack : function(cleanup)
- {
- // IE hack
- if(this.iePopUp)
- {
- this.iePopUp.style.display = "block";
- this.iePopUp.style.left = (this._calDiv.offsetLeft -1)+ "px";
- this.iePopUp.style.top = (this._calDiv.offsetTop -1 ) + "px";
- this.iePopUp.style.width = Math.abs(this._calDiv.offsetWidth -2)+ "px";
- this.iePopUp.style.height = (this._calDiv.offsetHeight + 1)+ "px";
- if(cleanup) this.iePopUp.style.display = "none";
- }
- },
-
- keyPressed : function(ev)
- {
- if(!this.showing) return;
- if (!ev) ev = document.parentWindow.event;
- var kc = ev.keyCode != null ? ev.keyCode : ev.charCode;
-
- if(kc == Event.KEY_RETURN || kc == Event.KEY_SPACEBAR || kc == Event.KEY_TAB)
- {
- this.setSelectedDate(this.selectedDate);
- Event.stop(ev);
- this.hide();
- }
- if(kc == Event.KEY_ESC)
- {
- Event.stop(ev); this.hide();
- }
-
- var getDaysPerMonth = function (nMonth, nYear)
- {
- nMonth = (nMonth + 12) % 12;
- var days= [31,28,31,30,31,30,31,31,30,31,30,31];
- var res = days[nMonth];
- if (nMonth == 1) //feburary, leap years has 29
- res += nYear % 4 == 0 && !(nYear % 400 == 0) ? 1 : 0;
- return res;
- }
-
- if(kc < 37 || kc > 40) return true;
-
- var current = this.selectedDate;
- var d = current.valueOf();
- if(kc == Event.KEY_LEFT)
- {
- if(ev.ctrlKey || ev.shiftKey) // -1 month
- {
- current.setDate( Math.min(current.getDate(), getDaysPerMonth(current.getMonth() - 1,current.getFullYear())) ); // no need to catch dec -> jan for the year
- d = current.setMonth( current.getMonth() - 1 );
- }
- else
- d -= 86400000; //-1 day
- }
- else if (kc == Event.KEY_RIGHT)
- {
- if(ev.ctrlKey || ev.shiftKey) // +1 month
- {
- current.setDate( Math.min(current.getDate(), getDaysPerMonth(current.getMonth() + 1,current.getFullYear())) ); // no need to catch dec -> jan for the year
- d = current.setMonth( current.getMonth() + 1 );
- }
- else
- d += 86400000; //+1 day
- }
- else if (kc == Event.KEY_UP)
- {
- if(ev.ctrlKey || ev.shiftKey) //-1 year
- {
- current.setDate( Math.min(current.getDate(), getDaysPerMonth(current.getMonth(),current.getFullYear() - 1)) ); // no need to catch dec -> jan for the year
- d = current.setFullYear( current.getFullYear() - 1 );
- }
- else
- d -= 604800000; // -7 days
- }
- else if (kc == Event.KEY_DOWN)
- {
- if(ev.ctrlKey || ev.shiftKey) // +1 year
- {
- current.setDate( Math.min(current.getDate(), getDaysPerMonth(current.getMonth(),current.getFullYear() + 1)) ); // no need to catch dec -> jan for the year
- d = current.setFullYear( current.getFullYear() + 1 );
- }
- else
- d += 7 * 24 * 61 * 60 * 1000; // +7 days
- }
- this.setSelectedDate(d);
- Event.stop(ev);
- },
-
- selectDate : function(ev)
- {
- var el = Event.element(ev);
- while (el.nodeType != 1)
- el = el.parentNode;
-
- while (el != null && el.tagName && el.tagName.toLowerCase() != "td")
- el = el.parentNode;
-
- // if no td found, return
- if (el == null || el.tagName == null || el.tagName.toLowerCase() != "td")
- return;
-
- var d = this.newDate(this.selectedDate);
- var n = Number(el.firstChild.data);
- if (isNaN(n) || n <= 0 || n == null)
- return;
-
- d.setDate(n);
- this.setSelectedDate(d);
- this.hide();
- },
-
- selectToday : function()
- {
- if(this.selectedDate.toISODate() == this.newDate().toISODate())
- this.hide();
-
- this.setSelectedDate(this.newDate());
- },
-
- clearSelection : function()
- {
- this.setSelectedDate(this.newDate());
- this.hide();
- },
-
- monthSelect : function(ev)
- {
- this.setMonth(Form.Element.getValue(Event.element(ev)));
- },
-
- yearSelect : function(ev)
- {
- this.setYear(Form.Element.getValue(Event.element(ev)));
- },
-
- mouseWheelChange : function (event)
- {
- var delta = 0;
- if (!event) event = document.parentWindow.event;
- if (event.wheelDelta) {
- delta = event.wheelDelta/120;
- if (window.opera) delta = -delta;
- } else if (event.detail) { delta = -event.detail/3; }
-
- var d = this.newDate(this.selectedDate);
- var m = d.getMonth() + Math.round(delta);
- this.setMonth(m,true);
- return false;
- },
-
- // Respond to change event on the textbox or dropdown list
- // This method raises OnDateChanged event on client side if it has been defined
- onDateChanged : function ()
- {
- if (this.options.OnDateChanged)
- {
- var date;
- if (this.options.InputMode == "TextBox")
- {
- date=this.control.value;
- }
- else
- {
- var day = Prado.WebUI.TDatePicker.getDayListControl(this.control).selectedIndex+1;
- var month = Prado.WebUI.TDatePicker.getMonthListControl(this.control).selectedIndex;
- var year = Prado.WebUI.TDatePicker.getYearListControl(this.control).value;
- date=new Date(year, month, day, 0,0,0).SimpleFormat(this.Format, this);
- }
- this.options.OnDateChanged(this, date);
- }
- },
-
- fireChangeEvent: function(element, capped)
- {
- if (capped)
- {
- var obj = this;
-
- if (typeof(obj.changeeventtimer)!="undefined")
- {
- clearTimeout(obj.changeeventtimer);
- obj.changeeventtimer = null;
- }
- obj.changeeventtimer = setTimeout(
- function() { obj.changeeventtimer = null; Event.fireEvent(element, "change"); },
- 1500
- );
- }
- else
- Event.fireEvent(element, "change");
- },
-
- onChange : function(ref, date, capevents)
- {
- if(this.options.InputMode == "TextBox")
- {
- this.control.value = this.formatDate();
- this.fireChangeEvent(this.control, capevents);
- }
- else
- {
- var day = Prado.WebUI.TDatePicker.getDayListControl(this.control);
- var month = Prado.WebUI.TDatePicker.getMonthListControl(this.control);
- var year = Prado.WebUI.TDatePicker.getYearListControl(this.control);
- var date = this.selectedDate;
- if(day)
- {
- day.selectedIndex = date.getDate()-1;
- }
- if(month)
- {
- month.selectedIndex = date.getMonth();
- }
- if(year)
- {
- var years = year.options;
- var currentYear = date.getFullYear();
- for(var i = 0; i < years.length; i++)
- years[i].selected = years[i].value.toInteger() == currentYear;
- }
- this.fireChangeEvent(day || month || year, capevents);
- }
- },
-
- formatDate : function()
- {
- return this.selectedDate ? this.selectedDate.SimpleFormat(this.Format,this) : '';
- },
-
- newDate : function(date)
- {
- if(!date)
- date = new Date();
- if(typeof(date) == "string" || typeof(date) == "number")
- date = new Date(date);
- return new Date(Math.min(Math.max(date.getFullYear(),this.FromYear),this.UpToYear), date.getMonth(), date.getDate(), 0,0,0);
- },
-
- setSelectedDate : function(date, capevents)
- {
- if (date == null)
- return;
- var old=this.selectedDate;
- this.selectedDate = this.newDate(date);
- var dateChanged=(old - this.selectedDate != 0) || ( this.options.InputMode == "TextBox" && this.control.value != this.formatDate());
-
- this.updateHeader();
- this.update();
- if (dateChanged && typeof(this.onChange) == "function")
- this.onChange(this, date, capevents);
- },
-
- getElement : function()
- {
- return this._calDiv;
- },
-
- getSelectedDate : function ()
- {
- return this.selectedDate == null ? null : this.newDate(this.selectedDate);
- },
-
- setYear : function(year)
- {
- var d = this.newDate(this.selectedDate);
- d.setFullYear(year);
- this.setSelectedDate(d);
- },
-
- setMonth : function (month, capevents)
- {
- var d = this.newDate(this.selectedDate);
- d.setDate(Math.min(d.getDate(), this.getDaysPerMonth(month,d.getFullYear())));
- d.setMonth(month);
- this.setSelectedDate(d,capevents);
- },
-
- nextMonth : function ()
- {
- this.setMonth(this.selectedDate.getMonth()+1);
- },
-
- prevMonth : function ()
- {
- this.setMonth(this.selectedDate.getMonth()-1);
- },
-
- getDaysPerMonth : function (month, year)
- {
- month = (Number(month)+12) % 12;
- var days = [31,28,31,30,31,30,31,31,30,31,30,31];
- var res = days[month];
- if (month == 1 && ((!(year % 4) && (year % 100)) || !(year % 400))) //feburary, leap years has 29
- res++;
- return res;
- },
-
- getDatePickerOffsetHeight : function()
- {
- if(this.options.InputMode == "TextBox")
- return this.control.offsetHeight;
-
- var control = Prado.WebUI.TDatePicker.getDayListControl(this.control);
- if(control) return control.offsetHeight;
-
- var control = Prado.WebUI.TDatePicker.getMonthListControl(this.control);
- if(control) return control.offsetHeight;
-
- var control = Prado.WebUI.TDatePicker.getYearListControl(this.control);
- if(control) return control.offsetHeight;
- return 0;
- },
-
- show : function()
- {
- this.create();
-
- if(!this.showing)
- {
- var pos = this.control.positionedOffset();
-
- pos[1] += this.getDatePickerOffsetHeight();
- this._calDiv.style.top = (pos[1]-1) + "px";
- this._calDiv.style.display = "block";
- this._calDiv.style.left = pos[0] + "px";
-
- this.documentClickEvent = this.hideOnClick.bindEvent(this);
- this.documentKeyDownEvent = this.keyPressed.bindEvent(this);
- Event.observe(document.body, "click", this.documentClickEvent);
- var date = this.getDateFromInput();
- if(date)
- {
- this.selectedDate = date;
- this.setSelectedDate(date);
- }
- Event.observe(document,"keydown", this.documentKeyDownEvent);
- this.showing = true;
-
- if(this.positionMode=='Top')
- {
- this._calDiv.style.top = ((pos[1]-1) - this.getDatePickerOffsetHeight() - this._calDiv.offsetHeight) + 'px';
- if(Prado.Browser().ie)
- this.iePopup = this._calDiv.style.top;
- }
- this.ieHack(false);
- }
- },
-
- getDateFromInput : function()
- {
- if(this.options.InputMode == "TextBox")
- return Date.SimpleParse($F(this.control), this.Format);
- else
- return Prado.WebUI.TDatePicker.getDropDownDate(this.control);
- },
-
- //hide the calendar when clicked outside any calendar
- hideOnClick : function(ev)
- {
- if(!this.showing) return;
- var el = Event.element(ev);
- var within = false;
- do
- {
- within = within || (el.className && Element.hasClassName(el, "TDatePicker_"+this.CalendarStyle));
- within = within || el == this.trigger;
- within = within || el == this.control;
- if(within) break;
- el = el.parentNode;
- }
- while(el);
- if(!within) this.hide();
- },
-
-
- hide : function()
- {
- if(this.showing)
- {
- this._calDiv.style.display = "none";
- if(this.iePopUp)
- this.iePopUp.style.display = "none";
- this.showing = false;
- Event.stopObserving(document.body, "click", this.documentClickEvent);
- Event.stopObserving(document,"keydown", this.documentKeyDownEvent);
- }
- },
-
- update : function()
- {
- // Calculate the number of days in the month for the selected date
- var date = this.selectedDate;
- var today = (this.newDate()).toISODate();
-
- var selected = date.toISODate();
- var d1 = new Date(date.getFullYear(), date.getMonth(), 1);
- var d2 = new Date(date.getFullYear(), date.getMonth()+1, 1);
- var monthLength = Math.round((d2 - d1) / (24 * 60 * 60 * 1000));
-
- // Find out the weekDay index for the first of this month
- var firstIndex = (d1.getDay() - this.FirstDayOfWeek) % 7 ;
- if (firstIndex < 0)
- firstIndex += 7;
-
- var index = 0;
- while (index < firstIndex) {
- this.dateSlot[index].value = -1;
- this.dateSlot[index].data.data = String.fromCharCode(160);
- this.dateSlot[index].data.parentNode.className = "empty";
- index++;
- }
-
- for (var i = 1; i <= monthLength; i++, index++) {
- var slot = this.dateSlot[index];
- var slotNode = slot.data.parentNode;
- slot.value = i;
- slot.data.data = i;
- slotNode.className = "date";
- //slotNode.style.color = "";
- if (d1.toISODate() == today) {
- slotNode.className += " today";
- }
- if (d1.toISODate() == selected) {
- // slotNode.style.color = "blue";
- slotNode.className += " selected";
- }
- d1 = new Date(d1.getFullYear(), d1.getMonth(), d1.getDate()+1);
- }
-
- var lastDateIndex = index;
-
- while(index < 42) {
- this.dateSlot[index].value = -1;
- this.dateSlot[index].data.data = String.fromCharCode(160);
- this.dateSlot[index].data.parentNode.className = "empty";
- ++index;
- }
-
- },
-
- hover : function(ev)
- {
- if(Event.element(ev).tagName)
- {
- if(ev.type == "mouseover")
- Event.element(ev).addClassName("hover");
- else
- Event.element(ev).removeClassName("hover");
- }
- },
-
- updateHeader : function () {
-
- var options = this._monthSelect.options;
- var m = this.selectedDate.getMonth();
- for(var i=0; i < options.length; ++i) {
- options[i].selected = false;
- if (options[i].value == m) {
- options[i].selected = true;
- }
- }
-
- options = this._yearSelect.options;
- var year = this.selectedDate.getFullYear();
- for(var i=0; i < options.length; ++i) {
- options[i].selected = false;
- if (options[i].value == year) {
- options[i].selected = true;
- }
- }
-
- }
-});
-
-Object.extend(Prado.WebUI.TDatePicker,
-{
- /**
- * @return Date the date from drop down list options.
- */
- getDropDownDate : function(control)
- {
- var now=new Date();
- var year=now.getFullYear();
- var month=now.getMonth();
- var day=1;
-
- var month_list = Prado.WebUI.TDatePicker.getMonthListControl(control);
- var day_list = Prado.WebUI.TDatePicker.getDayListControl(control);
- var year_list = Prado.WebUI.TDatePicker.getYearListControl(control);
-
- var day = day_list ? $F(day_list) : 1;
- var month = month_list ? $F(month_list) : now.getMonth();
- var year = year_list ? $F(year_list) : now.getFullYear();
-
- return new Date(year,month,day, 0, 0, 0);
- },
-
- getYearListControl : function(control)
- {
- return $(control.id+"_year");
- },
-
- getMonthListControl : function(control)
- {
- return $(control.id+"_month");
- },
-
- getDayListControl : function(control)
- {
- return $(control.id+"_day");
- }
+Prado.WebUI.TDatePicker = Class.create(Prado.WebUI.Control,
+{
+ MonthNames : [ "January", "February", "March", "April",
+ "May", "June", "July", "August",
+ "September", "October", "November", "December"
+ ],
+ AbbreviatedMonthNames : ["Jan", "Feb", "Mar", "Apr", "May",
+ "Jun", "Jul", "Aug", "Sep", "Oct", "Nov", "Dec"],
+
+ ShortWeekDayNames : ["Sun", "Mon", "Tue", "Wed", "Thu", "Fri", "Sat" ],
+
+ Format : "yyyy-MM-dd",
+
+ FirstDayOfWeek : 1, // 0 for sunday
+
+ ClassName : "",
+
+ CalendarStyle : "default",
+
+ FromYear : 2005, UpToYear: 2020,
+
+ onInit : function(options)
+ {
+ this.options = options || [];
+ this.control = $(options.ID);
+ this.dateSlot = new Array(42);
+ this.weekSlot = new Array(6);
+ this.minimalDaysInFirstWeek = 4;
+ this.positionMode = 'Bottom';
+
+ Prado.Registry.set(options.ID, this);
+
+ //which element to trigger to show the calendar
+ if(this.options.Trigger)
+ {
+ this.trigger = $(this.options.Trigger) ;
+ var triggerEvent = this.options.TriggerEvent || "click";
+ }
+ else
+ {
+ this.trigger = this.control;
+ var triggerEvent = this.options.TriggerEvent || "focus";
+ }
+
+ // Popup position
+ if(this.options.PositionMode == 'Top')
+ {
+ this.positionMode = this.options.PositionMode;
+ }
+
+ Object.extend(this,options);
+ // generate default date _after_ extending options
+ this.selectedDate = this.newDate();
+
+ Event.observe(this.trigger, triggerEvent, this.show.bindEvent(this));
+
+ // Listen to change event if needed
+ if (typeof(this.options.OnDateChanged) == "function")
+ {
+ if(this.options.InputMode == "TextBox")
+ {
+ Event.observe(this.control, "change", this.onDateChanged.bindEvent(this));
+ }
+ else
+ {
+ var day = Prado.WebUI.TDatePicker.getDayListControl(this.control);
+ var month = Prado.WebUI.TDatePicker.getMonthListControl(this.control);
+ var year = Prado.WebUI.TDatePicker.getYearListControl(this.control);
+ Event.observe (day, "change", this.onDateChanged.bindEvent(this));
+ Event.observe (month, "change", this.onDateChanged.bindEvent(this));
+ Event.observe (year, "change", this.onDateChanged.bindEvent(this));
+
+ }
+
+
+ }
+
+ },
+
+ create : function()
+ {
+ if(typeof(this._calDiv) != "undefined")
+ return;
+
+ var div;
+ var table;
+ var tbody;
+ var tr;
+ var td;
+
+ // Create the top-level div element
+ this._calDiv = document.createElement("div");
+ this._calDiv.className = "TDatePicker_"+this.CalendarStyle+" "+this.ClassName;
+ this._calDiv.style.display = "none";
+ this._calDiv.style.position = "absolute"
+
+ // header div
+ div = document.createElement("div");
+ div.className = "calendarHeader";
+ this._calDiv.appendChild(div);
+
+ table = document.createElement("table");
+ table.style.cellSpacing = 0;
+ div.appendChild(table);
+
+ tbody = document.createElement("tbody");
+ table.appendChild(tbody);
+
+ tr = document.createElement("tr");
+ tbody.appendChild(tr);
+
+ // Previous Month Button
+ td = document.createElement("td");
+ var previousMonth = document.createElement("input");
+ previousMonth.className = "prevMonthButton button";
+ previousMonth.type = "button"
+ previousMonth.value = "<<";
+ td.appendChild(previousMonth);
+ tr.appendChild(td);
+
+
+
+ //
+ // Create the month drop down
+ //
+ td = document.createElement("td");
+ tr.appendChild(td);
+ this._monthSelect = document.createElement("select");
+ this._monthSelect.className = "months";
+ for (var i = 0 ; i < this.MonthNames.length ; i++) {
+ var opt = document.createElement("option");
+ opt.innerHTML = this.MonthNames[i];
+ opt.value = i;
+ if (i == this.selectedDate.getMonth()) {
+ opt.selected = true;
+ }
+ this._monthSelect.appendChild(opt);
+ }
+ td.appendChild(this._monthSelect);
+
+
+ //
+ // Create the year drop down
+ //
+ td = document.createElement("td");
+ td.className = "labelContainer";
+ tr.appendChild(td);
+ this._yearSelect = document.createElement("select");
+ for(var i=this.FromYear; i <= this.UpToYear; ++i) {
+ var opt = document.createElement("option");
+ opt.innerHTML = i;
+ opt.value = i;
+ if (i == this.selectedDate.getFullYear()) {
+ opt.selected = false;
+ }
+ this._yearSelect.appendChild(opt);
+ }
+ td.appendChild(this._yearSelect);
+
+
+ td = document.createElement("td");
+ var nextMonth = document.createElement("input");
+ nextMonth.className = "nextMonthButton button";
+ nextMonth.type = "button";
+ nextMonth.value = ">>";
+ td.appendChild(nextMonth);
+ tr.appendChild(td);
+
+ // Calendar body
+ div = document.createElement("div");
+ div.className = "calendarBody";
+ this._calDiv.appendChild(div);
+ var calendarBody = div;
+
+ // Create the inside of calendar body
+
+ var text;
+ table = document.createElement("table");
+ table.align="center";
+ table.className = "grid";
+
+ div.appendChild(table);
+ var thead = document.createElement("thead");
+ table.appendChild(thead);
+ tr = document.createElement("tr");
+ thead.appendChild(tr);
+
+ for(i=0; i < 7; ++i) {
+ td = document.createElement("th");
+ text = document.createTextNode(this.ShortWeekDayNames[(i+this.FirstDayOfWeek)%7]);
+ td.appendChild(text);
+ td.className = "weekDayHead";
+ tr.appendChild(td);
+ }
+
+ // Date grid
+ tbody = document.createElement("tbody");
+ table.appendChild(tbody);
+
+ for(var week=0; week<6; ++week) {
+ tr = document.createElement("tr");
+ tbody.appendChild(tr);
+
+ for(var day=0; day<7; ++day) {
+ td = document.createElement("td");
+ td.className = "calendarDate";
+ text = document.createTextNode(String.fromCharCode(160));
+ td.appendChild(text);
+
+ tr.appendChild(td);
+ var tmp = new Object();
+ tmp.tag = "DATE";
+ tmp.value = -1;
+ tmp.data = text;
+ this.dateSlot[(week*7)+day] = tmp;
+
+ Event.observe(td, "mouseover", this.hover.bindEvent(this));
+ Event.observe(td, "mouseout", this.hover.bindEvent(this));
+
+ }
+ }
+
+ // Calendar Footer
+ div = document.createElement("div");
+ div.className = "calendarFooter";
+ this._calDiv.appendChild(div);
+
+ var todayButton = document.createElement("input");
+ todayButton.type="button";
+ todayButton.className = "todayButton";
+ var today = this.newDate();
+ var buttonText = today.SimpleFormat(this.Format,this);
+ todayButton.value = buttonText;
+ div.appendChild(todayButton);
+
+ if(Prado.Browser().ie)
+ {
+ this.iePopUp = document.createElement('iframe');
+ this.iePopUp.src = Prado.WebUI.TDatePicker.spacer;
+ this.iePopUp.style.position = "absolute"
+ this.iePopUp.scrolling="no"
+ this.iePopUp.frameBorder="0"
+ this.control.parentNode.appendChild(this.iePopUp);
+ }
+
+ this.control.parentNode.appendChild(this._calDiv);
+
+ this.update();
+ this.updateHeader();
+
+ this.ieHack(true);
+
+ // IE55+ extension
+ previousMonth.hideFocus = true;
+ nextMonth.hideFocus = true;
+ todayButton.hideFocus = true;
+ // end IE55+ extension
+
+ // hook up events
+ Event.observe(previousMonth, "click", this.prevMonth.bindEvent(this));
+ Event.observe(nextMonth, "click", this.nextMonth.bindEvent(this));
+ Event.observe(todayButton, "click", this.selectToday.bindEvent(this));
+ //Event.observe(clearButton, "click", this.clearSelection.bindEvent(this));
+ Event.observe(this._monthSelect, "change", this.monthSelect.bindEvent(this));
+ Event.observe(this._yearSelect, "change", this.yearSelect.bindEvent(this));
+
+ // ie, opera
+ Event.observe(this._calDiv, "mousewheel", this.mouseWheelChange.bindEvent(this));
+ // ff
+ Event.observe(this._calDiv, "DOMMouseScroll", this.mouseWheelChange.bindEvent(this));
+
+ Event.observe(calendarBody, "click", this.selectDate.bindEvent(this));
+
+ Prado.Element.focus(this.control);
+
+ },
+
+ ieHack : function(cleanup)
+ {
+ // IE hack
+ if(this.iePopUp)
+ {
+ this.iePopUp.style.display = "block";
+ this.iePopUp.style.left = (this._calDiv.offsetLeft -1)+ "px";
+ this.iePopUp.style.top = (this._calDiv.offsetTop -1 ) + "px";
+ this.iePopUp.style.width = Math.abs(this._calDiv.offsetWidth -2)+ "px";
+ this.iePopUp.style.height = (this._calDiv.offsetHeight + 1)+ "px";
+ if(cleanup) this.iePopUp.style.display = "none";
+ }
+ },
+
+ keyPressed : function(ev)
+ {
+ if(!this.showing) return;
+ if (!ev) ev = document.parentWindow.event;
+ var kc = ev.keyCode != null ? ev.keyCode : ev.charCode;
+
+ if(kc == Event.KEY_RETURN || kc == Event.KEY_SPACEBAR || kc == Event.KEY_TAB)
+ {
+ this.setSelectedDate(this.selectedDate);
+ Event.stop(ev);
+ this.hide();
+ }
+ if(kc == Event.KEY_ESC)
+ {
+ Event.stop(ev); this.hide();
+ }
+
+ var getDaysPerMonth = function (nMonth, nYear)
+ {
+ nMonth = (nMonth + 12) % 12;
+ var days= [31,28,31,30,31,30,31,31,30,31,30,31];
+ var res = days[nMonth];
+ if (nMonth == 1) //feburary, leap years has 29
+ res += nYear % 4 == 0 && !(nYear % 400 == 0) ? 1 : 0;
+ return res;
+ }
+
+ if(kc < 37 || kc > 40) return true;
+
+ var current = this.selectedDate;
+ var d = current.valueOf();
+ if(kc == Event.KEY_LEFT)
+ {
+ if(ev.ctrlKey || ev.shiftKey) // -1 month
+ {
+ current.setDate( Math.min(current.getDate(), getDaysPerMonth(current.getMonth() - 1,current.getFullYear())) ); // no need to catch dec -> jan for the year
+ d = current.setMonth( current.getMonth() - 1 );
+ }
+ else
+ d -= 86400000; //-1 day
+ }
+ else if (kc == Event.KEY_RIGHT)
+ {
+ if(ev.ctrlKey || ev.shiftKey) // +1 month
+ {
+ current.setDate( Math.min(current.getDate(), getDaysPerMonth(current.getMonth() + 1,current.getFullYear())) ); // no need to catch dec -> jan for the year
+ d = current.setMonth( current.getMonth() + 1 );
+ }
+ else
+ d += 86400000; //+1 day
+ }
+ else if (kc == Event.KEY_UP)
+ {
+ if(ev.ctrlKey || ev.shiftKey) //-1 year
+ {
+ current.setDate( Math.min(current.getDate(), getDaysPerMonth(current.getMonth(),current.getFullYear() - 1)) ); // no need to catch dec -> jan for the year
+ d = current.setFullYear( current.getFullYear() - 1 );
+ }
+ else
+ d -= 604800000; // -7 days
+ }
+ else if (kc == Event.KEY_DOWN)
+ {
+ if(ev.ctrlKey || ev.shiftKey) // +1 year
+ {
+ current.setDate( Math.min(current.getDate(), getDaysPerMonth(current.getMonth(),current.getFullYear() + 1)) ); // no need to catch dec -> jan for the year
+ d = current.setFullYear( current.getFullYear() + 1 );
+ }
+ else
+ d += 7 * 24 * 61 * 60 * 1000; // +7 days
+ }
+ this.setSelectedDate(d);
+ Event.stop(ev);
+ },
+
+ selectDate : function(ev)
+ {
+ var el = Event.element(ev);
+ while (el.nodeType != 1)
+ el = el.parentNode;
+
+ while (el != null && el.tagName && el.tagName.toLowerCase() != "td")
+ el = el.parentNode;
+
+ // if no td found, return
+ if (el == null || el.tagName == null || el.tagName.toLowerCase() != "td")
+ return;
+
+ var d = this.newDate(this.selectedDate);
+ var n = Number(el.firstChild.data);
+ if (isNaN(n) || n <= 0 || n == null)
+ return;
+
+ d.setDate(n);
+ this.setSelectedDate(d);
+ this.hide();
+ },
+
+ selectToday : function()
+ {
+ if(this.selectedDate.toISODate() == this.newDate().toISODate())
+ this.hide();
+
+ this.setSelectedDate(this.newDate());
+ },
+
+ clearSelection : function()
+ {
+ this.setSelectedDate(this.newDate());
+ this.hide();
+ },
+
+ monthSelect : function(ev)
+ {
+ this.setMonth(Form.Element.getValue(Event.element(ev)));
+ },
+
+ yearSelect : function(ev)
+ {
+ this.setYear(Form.Element.getValue(Event.element(ev)));
+ },
+
+ mouseWheelChange : function (event)
+ {
+ var delta = 0;
+ if (!event) event = document.parentWindow.event;
+ if (event.wheelDelta) {
+ delta = event.wheelDelta/120;
+ if (window.opera) delta = -delta;
+ } else if (event.detail) { delta = -event.detail/3; }
+
+ var d = this.newDate(this.selectedDate);
+ var m = d.getMonth() + Math.round(delta);
+ this.setMonth(m,true);
+ return false;
+ },
+
+ // Respond to change event on the textbox or dropdown list
+ // This method raises OnDateChanged event on client side if it has been defined
+ onDateChanged : function ()
+ {
+ if (this.options.OnDateChanged)
+ {
+ var date;
+ if (this.options.InputMode == "TextBox")
+ {
+ date=this.control.value;
+ }
+ else
+ {
+ var day = Prado.WebUI.TDatePicker.getDayListControl(this.control).selectedIndex+1;
+ var month = Prado.WebUI.TDatePicker.getMonthListControl(this.control).selectedIndex;
+ var year = Prado.WebUI.TDatePicker.getYearListControl(this.control).value;
+ date=new Date(year, month, day, 0,0,0).SimpleFormat(this.Format, this);
+ }
+ this.options.OnDateChanged(this, date);
+ }
+ },
+
+ fireChangeEvent: function(element, capped)
+ {
+ if (capped)
+ {
+ var obj = this;
+
+ if (typeof(obj.changeeventtimer)!="undefined")
+ {
+ clearTimeout(obj.changeeventtimer);
+ obj.changeeventtimer = null;
+ }
+ obj.changeeventtimer = setTimeout(
+ function() { obj.changeeventtimer = null; Event.fireEvent(element, "change"); },
+ 1500
+ );
+ }
+ else
+ Event.fireEvent(element, "change");
+ },
+
+ onChange : function(ref, date, capevents)
+ {
+ if(this.options.InputMode == "TextBox")
+ {
+ this.control.value = this.formatDate();
+ this.fireChangeEvent(this.control, capevents);
+ }
+ else
+ {
+ var day = Prado.WebUI.TDatePicker.getDayListControl(this.control);
+ var month = Prado.WebUI.TDatePicker.getMonthListControl(this.control);
+ var year = Prado.WebUI.TDatePicker.getYearListControl(this.control);
+ var date = this.selectedDate;
+ if(day)
+ {
+ day.selectedIndex = date.getDate()-1;
+ }
+ if(month)
+ {
+ month.selectedIndex = date.getMonth();
+ }
+ if(year)
+ {
+ var years = year.options;
+ var currentYear = date.getFullYear();
+ for(var i = 0; i < years.length; i++)
+ years[i].selected = years[i].value.toInteger() == currentYear;
+ }
+ this.fireChangeEvent(day || month || year, capevents);
+ }
+ },
+
+ formatDate : function()
+ {
+ return this.selectedDate ? this.selectedDate.SimpleFormat(this.Format,this) : '';
+ },
+
+ newDate : function(date)
+ {
+ if(!date)
+ date = new Date();
+ if(typeof(date) == "string" || typeof(date) == "number")
+ date = new Date(date);
+ return new Date(Math.min(Math.max(date.getFullYear(),this.FromYear),this.UpToYear), date.getMonth(), date.getDate(), 0,0,0);
+ },
+
+ setSelectedDate : function(date, capevents)
+ {
+ if (date == null)
+ return;
+ var old=this.selectedDate;
+ this.selectedDate = this.newDate(date);
+ var dateChanged=(old - this.selectedDate != 0) || ( this.options.InputMode == "TextBox" && this.control.value != this.formatDate());
+
+ this.updateHeader();
+ this.update();
+ if (dateChanged && typeof(this.onChange) == "function")
+ this.onChange(this, date, capevents);
+ },
+
+ getElement : function()
+ {
+ return this._calDiv;
+ },
+
+ getSelectedDate : function ()
+ {
+ return this.selectedDate == null ? null : this.newDate(this.selectedDate);
+ },
+
+ setYear : function(year)
+ {
+ var d = this.newDate(this.selectedDate);
+ d.setFullYear(year);
+ this.setSelectedDate(d);
+ },
+
+ setMonth : function (month, capevents)
+ {
+ var d = this.newDate(this.selectedDate);
+ d.setDate(Math.min(d.getDate(), this.getDaysPerMonth(month,d.getFullYear())));
+ d.setMonth(month);
+ this.setSelectedDate(d,capevents);
+ },
+
+ nextMonth : function ()
+ {
+ this.setMonth(this.selectedDate.getMonth()+1);
+ },
+
+ prevMonth : function ()
+ {
+ this.setMonth(this.selectedDate.getMonth()-1);
+ },
+
+ getDaysPerMonth : function (month, year)
+ {
+ month = (Number(month)+12) % 12;
+ var days = [31,28,31,30,31,30,31,31,30,31,30,31];
+ var res = days[month];
+ if (month == 1 && ((!(year % 4) && (year % 100)) || !(year % 400))) //feburary, leap years has 29
+ res++;
+ return res;
+ },
+
+ getDatePickerOffsetHeight : function()
+ {
+ if(this.options.InputMode == "TextBox")
+ return this.control.offsetHeight;
+
+ var control = Prado.WebUI.TDatePicker.getDayListControl(this.control);
+ if(control) return control.offsetHeight;
+
+ var control = Prado.WebUI.TDatePicker.getMonthListControl(this.control);
+ if(control) return control.offsetHeight;
+
+ var control = Prado.WebUI.TDatePicker.getYearListControl(this.control);
+ if(control) return control.offsetHeight;
+ return 0;
+ },
+
+ show : function()
+ {
+ this.create();
+
+ if(!this.showing)
+ {
+ var pos = this.control.positionedOffset();
+
+ pos[1] += this.getDatePickerOffsetHeight();
+ this._calDiv.style.top = (pos[1]-1) + "px";
+ this._calDiv.style.display = "block";
+ this._calDiv.style.left = pos[0] + "px";
+
+ this.documentClickEvent = this.hideOnClick.bindEvent(this);
+ this.documentKeyDownEvent = this.keyPressed.bindEvent(this);
+ Event.observe(document.body, "click", this.documentClickEvent);
+ var date = this.getDateFromInput();
+ if(date)
+ {
+ this.selectedDate = date;
+ this.setSelectedDate(date);
+ }
+ Event.observe(document,"keydown", this.documentKeyDownEvent);
+ this.showing = true;
+
+ if(this.positionMode=='Top')
+ {
+ this._calDiv.style.top = ((pos[1]-1) - this.getDatePickerOffsetHeight() - this._calDiv.offsetHeight) + 'px';
+ if(Prado.Browser().ie)
+ this.iePopup = this._calDiv.style.top;
+ }
+ this.ieHack(false);
+ }
+ },
+
+ getDateFromInput : function()
+ {
+ if(this.options.InputMode == "TextBox")
+ return Date.SimpleParse($F(this.control), this.Format);
+ else
+ return Prado.WebUI.TDatePicker.getDropDownDate(this.control);
+ },
+
+ //hide the calendar when clicked outside any calendar
+ hideOnClick : function(ev)
+ {
+ if(!this.showing) return;
+ var el = Event.element(ev);
+ var within = false;
+ do
+ {
+ within = within || (el.className && Element.hasClassName(el, "TDatePicker_"+this.CalendarStyle));
+ within = within || el == this.trigger;
+ within = within || el == this.control;
+ if(within) break;
+ el = el.parentNode;
+ }
+ while(el);
+ if(!within) this.hide();
+ },
+
+
+ hide : function()
+ {
+ if(this.showing)
+ {
+ this._calDiv.style.display = "none";
+ if(this.iePopUp)
+ this.iePopUp.style.display = "none";
+ this.showing = false;
+ Event.stopObserving(document.body, "click", this.documentClickEvent);
+ Event.stopObserving(document,"keydown", this.documentKeyDownEvent);
+ }
+ },
+
+ update : function()
+ {
+ // Calculate the number of days in the month for the selected date
+ var date = this.selectedDate;
+ var today = (this.newDate()).toISODate();
+
+ var selected = date.toISODate();
+ var d1 = new Date(date.getFullYear(), date.getMonth(), 1);
+ var d2 = new Date(date.getFullYear(), date.getMonth()+1, 1);
+ var monthLength = Math.round((d2 - d1) / (24 * 60 * 60 * 1000));
+
+ // Find out the weekDay index for the first of this month
+ var firstIndex = (d1.getDay() - this.FirstDayOfWeek) % 7 ;
+ if (firstIndex < 0)
+ firstIndex += 7;
+
+ var index = 0;
+ while (index < firstIndex) {
+ this.dateSlot[index].value = -1;
+ this.dateSlot[index].data.data = String.fromCharCode(160);
+ this.dateSlot[index].data.parentNode.className = "empty";
+ index++;
+ }
+
+ for (var i = 1; i <= monthLength; i++, index++) {
+ var slot = this.dateSlot[index];
+ var slotNode = slot.data.parentNode;
+ slot.value = i;
+ slot.data.data = i;
+ slotNode.className = "date";
+ //slotNode.style.color = "";
+ if (d1.toISODate() == today) {
+ slotNode.className += " today";
+ }
+ if (d1.toISODate() == selected) {
+ // slotNode.style.color = "blue";
+ slotNode.className += " selected";
+ }
+ d1 = new Date(d1.getFullYear(), d1.getMonth(), d1.getDate()+1);
+ }
+
+ var lastDateIndex = index;
+
+ while(index < 42) {
+ this.dateSlot[index].value = -1;
+ this.dateSlot[index].data.data = String.fromCharCode(160);
+ this.dateSlot[index].data.parentNode.className = "empty";
+ ++index;
+ }
+
+ },
+
+ hover : function(ev)
+ {
+ if(Event.element(ev).tagName)
+ {
+ if(ev.type == "mouseover")
+ Event.element(ev).addClassName("hover");
+ else
+ Event.element(ev).removeClassName("hover");
+ }
+ },
+
+ updateHeader : function () {
+
+ var options = this._monthSelect.options;
+ var m = this.selectedDate.getMonth();
+ for(var i=0; i < options.length; ++i) {
+ options[i].selected = false;
+ if (options[i].value == m) {
+ options[i].selected = true;
+ }
+ }
+
+ options = this._yearSelect.options;
+ var year = this.selectedDate.getFullYear();
+ for(var i=0; i < options.length; ++i) {
+ options[i].selected = false;
+ if (options[i].value == year) {
+ options[i].selected = true;
+ }
+ }
+
+ }
+});
+
+Object.extend(Prado.WebUI.TDatePicker,
+{
+ /**
+ * @return Date the date from drop down list options.
+ */
+ getDropDownDate : function(control)
+ {
+ var now=new Date();
+ var year=now.getFullYear();
+ var month=now.getMonth();
+ var day=1;
+
+ var month_list = Prado.WebUI.TDatePicker.getMonthListControl(control);
+ var day_list = Prado.WebUI.TDatePicker.getDayListControl(control);
+ var year_list = Prado.WebUI.TDatePicker.getYearListControl(control);
+
+ var day = day_list ? $F(day_list) : 1;
+ var month = month_list ? $F(month_list) : now.getMonth();
+ var year = year_list ? $F(year_list) : now.getFullYear();
+
+ return new Date(year,month,day, 0, 0, 0);
+ },
+
+ getYearListControl : function(control)
+ {
+ return $(control.id+"_year");
+ },
+
+ getMonthListControl : function(control)
+ {
+ return $(control.id+"_month");
+ },
+
+ getDayListControl : function(control)
+ {
+ return $(control.id+"_day");
+ }
}); \ No newline at end of file
diff --git a/framework/Web/Javascripts/source/prado/logger/logger.js b/framework/Web/Javascripts/source/prado/logger/logger.js
index a48f401a..55cc1aa3 100644
--- a/framework/Web/Javascripts/source/prado/logger/logger.js
+++ b/framework/Web/Javascripts/source/prado/logger/logger.js
@@ -1,753 +1,753 @@
-/*
-
-Created By: Corey Johnson
-E-mail: probablyCorey@gmail.com
-
-Requires: Prototype Javascript library (http://prototype.conio.net/)
-
-Use it all you want. Just remember to give me some credit :)
-
-*/
-
-// ------------
-// Custom Event
-// ------------
-
-CustomEvent = Class.create();
-CustomEvent.prototype = {
- initialize : function() {
- this.listeners = []
- },
-
- addListener : function(method) {
- this.listeners.push(method)
- },
-
- removeListener : function(method) {
- var foundIndexes = this._findListenerIndexes(method)
-
- for(var i = 0; i < foundIndexes.length; i++) {
- this.listeners.splice(foundIndexes[i], 1)
- }
- },
-
- dispatch : function(handler) {
- for(var i = 0; i < this.listeners.length; i++) {
- try {
- this.listeners[i](handler)
- }
- catch (e) {
- alert("Could not run the listener " + this.listeners[i] + ". " + e)
- }
- }
- },
-
- // Private Methods
- // ---------------
- _findListenerIndexes : function(method) {
- var indexes = []
- for(var i = 0; i < this.listeners.length; i++) {
- if (this.listeners[i] == method) {
- indexes.push(i)
- }
- }
-
- return indexes
- }
-};
-
-// ------
-// Cookie
-// ------
-
-var Cookie = {
- set : function(name, value, expirationInDays, path) {
- var cookie = escape(name) + "=" + escape(value)
-
- if (expirationInDays) {
- var date = new Date()
- date.setDate(date.getDate() + expirationInDays)
- cookie += "; expires=" + date.toGMTString()
- }
-
- if (path) {
- cookie += ";path=" + path
- }
-
- document.cookie = cookie
-
- if (value && (expirationInDays == undefined || expirationInDays > 0) && !this.get(name)) {
- Logger.error("Cookie (" + name + ") was not set correctly... The value was " + value.toString().length + " charachters long (This may be over the cookie limit)");
- }
- },
-
- get : function(name) {
- var pattern = "(^|;)\\s*" + escape(name) + "=([^;]+)"
-
- var m = document.cookie.match(pattern)
- if (m && m[2]) {
- return unescape(m[2])
- }
- else return null
- },
-
- getAll : function() {
- var cookies = document.cookie.split(';')
- var cookieArray = []
-
- for (var i = 0; i < cookies.length; i++) {
- try {
- var name = unescape(cookies[i].match(/^\s*([^=]+)/m)[1])
- var value = unescape(cookies[i].match(/=(.*$)/m)[1])
- }
- catch (e) {
- continue
- }
-
- cookieArray.push({name : name, value : value})
-
- if (cookieArray[name] != undefined) {
- Logger.waring("Trying to retrieve cookie named(" + name + "). There appears to be another property with this name though.");
- }
-
- cookieArray[name] = value
- }
-
- return cookieArray
- },
-
- clear : function(name) {
- this.set(name, "", -1)
- },
-
- clearAll : function() {
- var cookies = this.getAll()
-
- for(var i = 0; i < cookies.length; i++) {
- this.clear(cookies[i].name)
- }
-
- }
-};
-
-// ------
-// Logger
-// -----
-
-Logger = {
- logEntries : [],
-
- onupdate : new CustomEvent(),
- onclear : new CustomEvent(),
-
-
- // Logger output
- log : function(message, tag) {
- var logEntry = new LogEntry(message, tag || "info")
- this.logEntries.push(logEntry)
- this.onupdate.dispatch(logEntry)
- },
-
- info : function(message) {
- this.log(message, 'info')
- if(typeof(console) != "undefined")
- console.info(message);
- },
-
- debug : function(message) {
- this.log(message, 'debug')
- if(typeof(console) != "undefined")
- console.debug(message);
- },
-
- warn : function(message) {
- this.log(message, 'warning')
- if(typeof(console) != "undefined")
- console.warn(message);
- },
-
- error : function(message, error) {
- this.log(message + ": \n" + error, 'error')
- if(typeof(console) != "undefined")
- console.error(message + ": \n" + error);
-
- },
-
- clear : function () {
- this.logEntries = []
- this.onclear.dispatch()
- }
-};
-
-LogEntry = Class.create()
-LogEntry.prototype = {
- initialize : function(message, tag) {
- this.message = message
- this.tag = tag
- }
-};
-
-LogConsole = Class.create();
-LogConsole.prototype = {
-
- // Properties
- // ----------
- commandHistory : [],
- commandIndex : 0,
-
- hidden : true,
-
- // Methods
- // -------
-
- initialize : function(toggleKey) {
- this.outputCount = 0
- this.tagPattern = Cookie.get('tagPattern') || ".*"
-
- // I hate writing javascript in HTML... but what's a better alternative
- this.logElement = document.createElement('div')
- document.body.appendChild(this.logElement)
- Element.hide(this.logElement)
-
- this.logElement.style.position = "absolute"
- this.logElement.style.left = '0px'
- this.logElement.style.width = '100%'
-
- this.logElement.style.textAlign = "left"
- this.logElement.style.fontFamily = "lucida console"
- this.logElement.style.fontSize = "100%"
- this.logElement.style.backgroundColor = 'darkgray'
- this.logElement.style.opacity = 0.9
- this.logElement.style.zIndex = 2000
-
- // Add toolbarElement
- this.toolbarElement = document.createElement('div')
- this.logElement.appendChild(this.toolbarElement)
- this.toolbarElement.style.padding = "0 0 0 2px"
-
- // Add buttons
- this.buttonsContainerElement = document.createElement('span')
- this.toolbarElement.appendChild(this.buttonsContainerElement)
-
- this.buttonsContainerElement.innerHTML += '<button onclick="logConsole.toggle()" style="float:right;color:black">close</button>'
- this.buttonsContainerElement.innerHTML += '<button onclick="Logger.clear()" style="float:right;color:black">clear</button>'
- if(!Prado.Inspector.disabled)
- this.buttonsContainerElement.innerHTML += '<button onclick="Prado.Inspector.inspect()" style="float:right;color:black; margin-right:15px;">Object Tree</button>'
-
-
- //Add Tag Filter
- this.tagFilterContainerElement = document.createElement('span')
- this.toolbarElement.appendChild(this.tagFilterContainerElement)
- this.tagFilterContainerElement.style.cssFloat = 'left'
- this.tagFilterContainerElement.appendChild(document.createTextNode("Log Filter"))
-
- this.tagFilterElement = document.createElement('input')
- this.tagFilterContainerElement.appendChild(this.tagFilterElement)
- this.tagFilterElement.style.width = '200px'
- this.tagFilterElement.value = this.tagPattern
- this.tagFilterElement.setAttribute('autocomplete', 'off') // So Firefox doesn't flip out
-
- Event.observe(this.tagFilterElement, 'keyup', this.updateTags.bind(this))
- Event.observe(this.tagFilterElement, 'click', function() {this.tagFilterElement.select()}.bind(this))
-
- // Add outputElement
- this.outputElement = document.createElement('div')
- this.logElement.appendChild(this.outputElement)
- this.outputElement.style.overflow = "auto"
- this.outputElement.style.clear = "both"
- this.outputElement.style.height = "200px"
- this.outputElement.style.backgroundColor = 'black'
-
- this.inputContainerElement = document.createElement('div')
- this.inputContainerElement.style.width = "100%"
- this.logElement.appendChild(this.inputContainerElement)
-
- this.inputElement = document.createElement('input')
- this.inputContainerElement.appendChild(this.inputElement)
- this.inputElement.style.width = '100%'
- this.inputElement.style.borderWidth = '0px' // Inputs with 100% width always seem to be too large (I HATE THEM) they only work if the border, margin and padding are 0
- this.inputElement.style.margin = '0px'
- this.inputElement.style.padding = '0px'
- this.inputElement.value = 'Type command here'
- this.inputElement.setAttribute('autocomplete', 'off') // So Firefox doesn't flip out
-
- Event.observe(this.inputElement, 'keyup', this.handleInput.bind(this))
- Event.observe(this.inputElement, 'click', function() {this.inputElement.select()}.bind(this))
-
- if(document.all && !window.opera)
- {
- window.setInterval(this.repositionWindow.bind(this), 500)
- }
- else
- {
- this.logElement.style.position="fixed";
- this.logElement.style.bottom="0px";
- }
- var self=this;
- Event.observe(document, 'keydown', function(e)
- {
- if((e.altKey==true) && Event.keyCode(e) == toggleKey ) //Alt+J | Ctrl+J
- self.toggle();
- });
-
- // Listen to the logger....
- Logger.onupdate.addListener(this.logUpdate.bind(this))
- Logger.onclear.addListener(this.clear.bind(this))
-
- // Preload log element with the log entries that have been entered
- for (var i = 0; i < Logger.logEntries.length; i++) {
- this.logUpdate(Logger.logEntries[i])
- }
-
- // Feed all errors into the logger (For some unknown reason I can only get this to work
- // with an inline event declaration)
- Event.observe(window, 'error', function(msg, url, lineNumber) {Logger.error("Error in (" + (url || location) + ") on line "+lineNumber+"", msg)})
-
- // Allow acess key link
- var accessElement = document.createElement('span')
- accessElement.innerHTML = '<button style="position:absolute;top:-100px" onclick="javascript:logConsole.toggle()" accesskey="d"></button>'
- document.body.appendChild(accessElement)
-
- if (Cookie.get('ConsoleVisible') == 'true') {
- this.toggle()
- }
- },
-
- toggle : function() {
- if (this.logElement.style.display == 'none') {
- this.show()
- }
- else {
- this.hide()
- }
- },
-
- show : function() {
- Element.show(this.logElement)
- this.outputElement.scrollTop = this.outputElement.scrollHeight // Scroll to bottom when toggled
- if(document.all && !window.opera)
- this.repositionWindow();
- Cookie.set('ConsoleVisible', 'true')
- this.inputElement.select()
- this.hidden = false;
- },
-
- hide : function() {
- this.hidden = true;
- Element.hide(this.logElement)
- Cookie.set('ConsoleVisible', 'false')
- },
-
- output : function(message, style) {
- // If we are at the bottom of the window, then keep scrolling with the output
- var shouldScroll = (this.outputElement.scrollTop + (2 * this.outputElement.clientHeight)) >= this.outputElement.scrollHeight
-
- this.outputCount++
- style = (style ? style += ';' : '')
- style += 'padding:1px;margin:0 0 5px 0'
-
- if (this.outputCount % 2 == 0) style += ";background-color:#101010"
-
- message = message || "undefined"
- message = message.toString().escapeHTML()
-
- this.outputElement.innerHTML += "<pre style='" + style + "'>" + message + "</pre>"
-
- if (shouldScroll) {
- this.outputElement.scrollTop = this.outputElement.scrollHeight
- }
- },
-
- updateTags : function() {
- var pattern = this.tagFilterElement.value
-
- if (this.tagPattern == pattern) return
-
- try {
- new RegExp(pattern)
- }
- catch (e) {
- return
- }
-
- this.tagPattern = pattern
- Cookie.set('tagPattern', this.tagPattern)
-
- this.outputElement.innerHTML = ""
-
- // Go through each log entry again
- this.outputCount = 0;
- for (var i = 0; i < Logger.logEntries.length; i++) {
- this.logUpdate(Logger.logEntries[i])
- }
- },
-
- repositionWindow : function() {
- var offset = window.pageYOffset || document.documentElement.scrollTop || document.body.scrollTop
- var pageHeight = self.innerHeight || document.documentElement.clientHeight || document.body.clientHeight
- this.logElement.style.top = (offset + pageHeight - Element.getHeight(this.logElement)) + "px"
- },
-
- // Event Handlers
- // --------------
-
- logUpdate : function(logEntry) {
- if (logEntry.tag.search(new RegExp(this.tagPattern, 'igm')) == -1) return
- var style = ''
- if (logEntry.tag.search(/error/) != -1) style += 'color:red'
- else if (logEntry.tag.search(/warning/) != -1) style += 'color:orange'
- else if (logEntry.tag.search(/debug/) != -1) style += 'color:green'
- else if (logEntry.tag.search(/info/) != -1) style += 'color:white'
- else style += 'color:yellow'
-
- this.output(logEntry.message, style)
- },
-
- clear : function(e) {
- this.outputElement.innerHTML = ""
- },
-
- handleInput : function(e) {
- if (e.keyCode == Event.KEY_RETURN ) {
- var command = this.inputElement.value
-
- switch(command) {
- case "clear":
- Logger.clear()
- break
-
- default:
- var consoleOutput = ""
-
- try {
- consoleOutput = eval(this.inputElement.value)
- }
- catch (e) {
- Logger.error("Problem parsing input <" + command + ">", e)
- break
- }
-
- Logger.log(consoleOutput)
- break
- }
-
- if (this.inputElement.value != "" && this.inputElement.value != this.commandHistory[0]) {
- this.commandHistory.unshift(this.inputElement.value)
- }
-
- this.commandIndex = 0
- this.inputElement.value = ""
- }
- else if (e.keyCode == Event.KEY_UP && this.commandHistory.length > 0) {
- this.inputElement.value = this.commandHistory[this.commandIndex]
-
- if (this.commandIndex < this.commandHistory.length - 1) {
- this.commandIndex += 1
- }
- }
- else if (e.keyCode == Event.KEY_DOWN && this.commandHistory.length > 0) {
- if (this.commandIndex > 0) {
- this.commandIndex -= 1
- }
-
- this.inputElement.value = this.commandHistory[this.commandIndex]
- }
- else {
- this.commandIndex = 0
- }
- }
-};
-
-
-// -------------------------
-// Helper Functions And Junk
-// -------------------------
-function inspect(o)
-{
- var objtype = typeof(o);
- if (objtype == "undefined") {
- return "undefined";
- } else if (objtype == "number" || objtype == "boolean") {
- return o + "";
- } else if (o === null) {
- return "null";
- }
-
- try {
- var ostring = (o + "");
- } catch (e) {
- return "[" + typeof(o) + "]";
- }
-
- if (typeof(o) == "function")
- {
- o = ostring.replace(/^\s+/, "");
- var idx = o.indexOf("{");
- if (idx != -1) {
- o = o.substr(0, idx) + "{...}";
- }
- return o;
- }
-
- var reprString = function (o)
- {
- return ('"' + o.replace(/(["\\])/g, '\\$1') + '"'
- ).replace(/[\f]/g, "\\f"
- ).replace(/[\b]/g, "\\b"
- ).replace(/[\n]/g, "\\n"
- ).replace(/[\t]/g, "\\t"
- ).replace(/[\r]/g, "\\r");
- };
-
- if (objtype == "string") {
- return reprString(o);
- }
- // recurse
- var me = arguments.callee;
- // short-circuit for objects that support "json" serialization
- // if they return "self" then just pass-through...
- var newObj;
- if (typeof(o.__json__) == "function") {
- newObj = o.__json__();
- if (o !== newObj) {
- return me(newObj);
- }
- }
- if (typeof(o.json) == "function") {
- newObj = o.json();
- if (o !== newObj) {
- return me(newObj);
- }
- }
- // array
- if (objtype != "function" && typeof(o.length) == "number") {
- var res = [];
- for (var i = 0; i < o.length; i++) {
- var val = me(o[i]);
- if (typeof(val) != "string") {
- val = "undefined";
- }
- res.push(val);
- }
- return "[" + res.join(", ") + "]";
- }
-
- // generic object code path
- res = [];
- for (var k in o) {
- var useKey;
- if (typeof(k) == "number") {
- useKey = '"' + k + '"';
- } else if (typeof(k) == "string") {
- useKey = reprString(k);
- } else {
- // skip non-string or number keys
- continue;
- }
- val = me(o[k]);
- if (typeof(val) != "string") {
- // skip non-serializable values
- continue;
- }
- res.push(useKey + ":" + val);
- }
- return "{" + res.join(", ") + "}";
-};
-
-Array.prototype.contains = function(object) {
- for(var i = 0; i < this.length; i++) {
- if (object == this[i]) return true
- }
-
- return false
-};
-
-// Helper Alias for simple logging
-var puts = function() {return Logger.log(arguments[0], arguments[1])};
-
-/*************************************
-
- Javascript Object Tree
- version 1.0
- last revision:04.11.2004
- steve@slayeroffice.com
- http://slayeroffice.com
-
- (c)2004 S.G. Chipman
-
- Please notify me of any modifications
- you make to this code so that I can
- update the version hosted on slayeroffice.com
-
-
-************************************/
-if(typeof Prado == "undefined")
- var Prado = {};
-Prado.Inspector =
-{
- d : document,
- types : new Array(),
- objs : new Array(),
- hidden : new Array(),
- opera : window.opera,
- displaying : '',
- nameList : new Array(),
-
- format : function(str) {
- if(typeof(str) != "string") return str;
- str=str.replace(/</g,"&lt;");
- str=str.replace(/>/g,"&gt;");
- return str;
- },
-
- parseJS : function(obj) {
- var name;
- if(typeof obj == "string") { name = obj; obj = eval(obj); }
- win= typeof obj == 'undefined' ? window : obj;
- this.displaying = name ? name : win.toString();
- for(js in win) {
- try {
- if(win[js] && js.toString().indexOf("Inspector")==-1 && (win[js]+"").indexOf("[native code]")==-1) {
-
- t=typeof(win[js]);
- if(!this.objs[t.toString()]) {
- this.types[this.types.length]=t;
- this.objs[t]={};
- this.nameList[t] = new Array();
- }
- this.nameList[t].push(js);
- this.objs[t][js] = this.format(win[js]+"");
- }
- } catch(err) { }
- }
-
- for(i=0;i<this.types.length;i++)
- this.nameList[this.types[i]].sort();
- },
-
- show : function(objID) {
- this.d.getElementById(objID).style.display=this.hidden[objID]?"none":"block";
- this.hidden[objID]=this.hidden[objID]?0:1;
- },
-
- changeSpan : function(spanID) {
- if(this.d.getElementById(spanID).innerHTML.indexOf("+")>-1){
- this.d.getElementById(spanID).innerHTML="[-]";
- } else {
- this.d.getElementById(spanID).innerHTML="[+]";
- }
- },
-
- buildInspectionLevel : function()
- {
- var display = this.displaying;
- var list = display.split(".");
- var links = ["<a href=\"javascript:var_dump()\">[object Window]</a>"];
- var name = '';
- if(display.indexOf("[object ") >= 0) return links.join(".");
- for(var i = 0; i < list.length; i++)
- {
- name += (name.length ? "." : "") + list[i];
- links[i+1] = "<a href=\"javascript:var_dump('"+name+"')\">"+list[i]+"</a>";
- }
- return links.join(".");
- },
-
- buildTree : function() {
- mHTML = "<div>Inspecting "+this.buildInspectionLevel()+"</div>";
- mHTML +="<ul class=\"topLevel\">";
- this.types.sort();
- var so_objIndex=0;
- for(i=0;i<this.types.length;i++)
- {
- mHTML+="<li style=\"cursor:pointer;\" onclick=\"Prado.Inspector.show('ul"+i+"');Prado.Inspector.changeSpan('sp" + i + "')\"><span id=\"sp" + i + "\">[+]</span><b>" + this.types[i] + "</b> (" + this.nameList[this.types[i]].length + ")</li><ul style=\"display:none;\" id=\"ul"+i+"\">";
- this.hidden["ul"+i]=0;
- for(e=0;e<this.nameList[this.types[i]].length;e++)
- {
- var prop = this.nameList[this.types[i]][e];
- var value = this.objs[this.types[i]][prop]
- var more = "";
- if(value.indexOf("[object ") >= 0 && /^[a-zA-Z_]/.test(prop))
- {
- if(this.displaying.indexOf("[object ") < 0)
- more = " <a href=\"javascript:var_dump('"+this.displaying+"."+prop+"')\"><b>more</b></a>";
- else if(this.displaying.indexOf("[object Window]") >= 0)
- more = " <a href=\"javascript:var_dump('"+prop+"')\"><b>more</b></a>";
- }
- mHTML+="<li style=\"cursor:pointer;\" onclick=\"Prado.Inspector.show('mul" + so_objIndex + "');Prado.Inspector.changeSpan('sk" + so_objIndex + "')\"><span id=\"sk" + so_objIndex + "\">[+]</span>" + prop + "</li><ul id=\"mul" + so_objIndex + "\" style=\"display:none;\"><li style=\"list-style-type:none;\"><pre>" + value + more + "</pre></li></ul>";
- this.hidden["mul"+so_objIndex]=0;
- so_objIndex++;
- }
- mHTML+="</ul>";
- }
- mHTML+="</ul>";
- this.d.getElementById("so_mContainer").innerHTML =mHTML;
- },
-
- handleKeyEvent : function(e) {
- keyCode=document.all?window.event.keyCode:e.keyCode;
- if(keyCode==27) {
- this.cleanUp();
- }
- },
-
- cleanUp : function()
- {
- if(this.d.getElementById("so_mContainer"))
- {
- this.d.body.removeChild(this.d.getElementById("so_mContainer"));
- this.d.body.removeChild(this.d.getElementById("so_mStyle"));
- if(typeof Event != "undefined")
- Event.stopObserving(this.d, "keydown", this.dKeyDownEvent);
- this.types = new Array();
- this.objs = new Array();
- this.hidden = new Array();
- }
- },
-
- disabled : document.all && !this.opera,
-
- inspect : function(obj)
- {
- if(this.disabled)return alert("Sorry, this only works in Mozilla and Firefox currently.");
- this.cleanUp();
- mObj=this.d.body.appendChild(this.d.createElement("div"));
- mObj.id="so_mContainer";
- sObj=this.d.body.appendChild(this.d.createElement("style"));
- sObj.id="so_mStyle";
- sObj.type="text/css";
- sObj.innerHTML = this.style;
- this.dKeyDownEvent = this.handleKeyEvent.bind(this);
- if(typeof Event != "undefined")
- Event.observe(this.d, "keydown", this.dKeyDownEvent);
-
- this.parseJS(obj);
- this.buildTree();
-
- cObj=mObj.appendChild(this.d.createElement("div"));
- cObj.className="credits";
- cObj.innerHTML = "<b>[esc] to <a href=\"javascript:Prado.Inspector.cleanUp();\">close</a></b><br />Javascript Object Tree V2.0.";
-
- window.scrollTo(0,0);
- },
-
- style : "#so_mContainer { position:absolute; top:5px; left:5px; background-color:#E3EBED; text-align:left; font:9pt verdana; width:85%; border:2px solid #000; padding:5px; z-index:1000; color:#000; } " +
- "#so_mContainer ul { padding-left:20px; } " +
- "#so_mContainer ul li { display:block; list-style-type:none; list-style-image:url(); line-height:2em; -moz-border-radius:.75em; font:10px verdana; padding:0; margin:2px; color:#000; } " +
- "#so_mContainer li:hover { background-color:#E3EBED; } " +
- "#so_mContainer ul li span { position:relative; width:15px; height:15px; margin-right:4px; } " +
- "#so_mContainer pre { background-color:#F9FAFB; border:1px solid #638DA1; height:auto; padding:5px; font:9px verdana; color:#000; } " +
- "#so_mContainer .topLevel { margin:0; padding:0; } " +
- "#so_mContainer .credits { float:left; width:200px; font:6.5pt verdana; color:#000; padding:2px; margin-left:5px; text-align:left; border-top:1px solid #000; margin-top:15px; width:75%; } " +
- "#so_mContainer .credits a { font:9px verdana; font-weight:bold; color:#004465; text-decoration:none; background-color:transparent; }"
-};
-
-//similar function to var_dump in PHP, brings up the javascript object tree UI.
-function var_dump(obj)
-{
- Prado.Inspector.inspect(obj);
-}
-
-//similar function to print_r for PHP
-var print_r = inspect;
-
+/*
+
+Created By: Corey Johnson
+E-mail: probablyCorey@gmail.com
+
+Requires: Prototype Javascript library (http://prototype.conio.net/)
+
+Use it all you want. Just remember to give me some credit :)
+
+*/
+
+// ------------
+// Custom Event
+// ------------
+
+CustomEvent = Class.create();
+CustomEvent.prototype = {
+ initialize : function() {
+ this.listeners = []
+ },
+
+ addListener : function(method) {
+ this.listeners.push(method)
+ },
+
+ removeListener : function(method) {
+ var foundIndexes = this._findListenerIndexes(method)
+
+ for(var i = 0; i < foundIndexes.length; i++) {
+ this.listeners.splice(foundIndexes[i], 1)
+ }
+ },
+
+ dispatch : function(handler) {
+ for(var i = 0; i < this.listeners.length; i++) {
+ try {
+ this.listeners[i](handler)
+ }
+ catch (e) {
+ alert("Could not run the listener " + this.listeners[i] + ". " + e)
+ }
+ }
+ },
+
+ // Private Methods
+ // ---------------
+ _findListenerIndexes : function(method) {
+ var indexes = []
+ for(var i = 0; i < this.listeners.length; i++) {
+ if (this.listeners[i] == method) {
+ indexes.push(i)
+ }
+ }
+
+ return indexes
+ }
+};
+
+// ------
+// Cookie
+// ------
+
+var Cookie = {
+ set : function(name, value, expirationInDays, path) {
+ var cookie = escape(name) + "=" + escape(value)
+
+ if (expirationInDays) {
+ var date = new Date()
+ date.setDate(date.getDate() + expirationInDays)
+ cookie += "; expires=" + date.toGMTString()
+ }
+
+ if (path) {
+ cookie += ";path=" + path
+ }
+
+ document.cookie = cookie
+
+ if (value && (expirationInDays == undefined || expirationInDays > 0) && !this.get(name)) {
+ Logger.error("Cookie (" + name + ") was not set correctly... The value was " + value.toString().length + " charachters long (This may be over the cookie limit)");
+ }
+ },
+
+ get : function(name) {
+ var pattern = "(^|;)\\s*" + escape(name) + "=([^;]+)"
+
+ var m = document.cookie.match(pattern)
+ if (m && m[2]) {
+ return unescape(m[2])
+ }
+ else return null
+ },
+
+ getAll : function() {
+ var cookies = document.cookie.split(';')
+ var cookieArray = []
+
+ for (var i = 0; i < cookies.length; i++) {
+ try {
+ var name = unescape(cookies[i].match(/^\s*([^=]+)/m)[1])
+ var value = unescape(cookies[i].match(/=(.*$)/m)[1])
+ }
+ catch (e) {
+ continue
+ }
+
+ cookieArray.push({name : name, value : value})
+
+ if (cookieArray[name] != undefined) {
+ Logger.waring("Trying to retrieve cookie named(" + name + "). There appears to be another property with this name though.");
+ }
+
+ cookieArray[name] = value
+ }
+
+ return cookieArray
+ },
+
+ clear : function(name) {
+ this.set(name, "", -1)
+ },
+
+ clearAll : function() {
+ var cookies = this.getAll()
+
+ for(var i = 0; i < cookies.length; i++) {
+ this.clear(cookies[i].name)
+ }
+
+ }
+};
+
+// ------
+// Logger
+// -----
+
+Logger = {
+ logEntries : [],
+
+ onupdate : new CustomEvent(),
+ onclear : new CustomEvent(),
+
+
+ // Logger output
+ log : function(message, tag) {
+ var logEntry = new LogEntry(message, tag || "info")
+ this.logEntries.push(logEntry)
+ this.onupdate.dispatch(logEntry)
+ },
+
+ info : function(message) {
+ this.log(message, 'info')
+ if(typeof(console) != "undefined")
+ console.info(message);
+ },
+
+ debug : function(message) {
+ this.log(message, 'debug')
+ if(typeof(console) != "undefined")
+ console.debug(message);
+ },
+
+ warn : function(message) {
+ this.log(message, 'warning')
+ if(typeof(console) != "undefined")
+ console.warn(message);
+ },
+
+ error : function(message, error) {
+ this.log(message + ": \n" + error, 'error')
+ if(typeof(console) != "undefined")
+ console.error(message + ": \n" + error);
+
+ },
+
+ clear : function () {
+ this.logEntries = []
+ this.onclear.dispatch()
+ }
+};
+
+LogEntry = Class.create()
+LogEntry.prototype = {
+ initialize : function(message, tag) {
+ this.message = message
+ this.tag = tag
+ }
+};
+
+LogConsole = Class.create();
+LogConsole.prototype = {
+
+ // Properties
+ // ----------
+ commandHistory : [],
+ commandIndex : 0,
+
+ hidden : true,
+
+ // Methods
+ // -------
+
+ initialize : function(toggleKey) {
+ this.outputCount = 0
+ this.tagPattern = Cookie.get('tagPattern') || ".*"
+
+ // I hate writing javascript in HTML... but what's a better alternative
+ this.logElement = document.createElement('div')
+ document.body.appendChild(this.logElement)
+ Element.hide(this.logElement)
+
+ this.logElement.style.position = "absolute"
+ this.logElement.style.left = '0px'
+ this.logElement.style.width = '100%'
+
+ this.logElement.style.textAlign = "left"
+ this.logElement.style.fontFamily = "lucida console"
+ this.logElement.style.fontSize = "100%"
+ this.logElement.style.backgroundColor = 'darkgray'
+ this.logElement.style.opacity = 0.9
+ this.logElement.style.zIndex = 2000
+
+ // Add toolbarElement
+ this.toolbarElement = document.createElement('div')
+ this.logElement.appendChild(this.toolbarElement)
+ this.toolbarElement.style.padding = "0 0 0 2px"
+
+ // Add buttons
+ this.buttonsContainerElement = document.createElement('span')
+ this.toolbarElement.appendChild(this.buttonsContainerElement)
+
+ this.buttonsContainerElement.innerHTML += '<button onclick="logConsole.toggle()" style="float:right;color:black">close</button>'
+ this.buttonsContainerElement.innerHTML += '<button onclick="Logger.clear()" style="float:right;color:black">clear</button>'
+ if(!Prado.Inspector.disabled)
+ this.buttonsContainerElement.innerHTML += '<button onclick="Prado.Inspector.inspect()" style="float:right;color:black; margin-right:15px;">Object Tree</button>'
+
+
+ //Add Tag Filter
+ this.tagFilterContainerElement = document.createElement('span')
+ this.toolbarElement.appendChild(this.tagFilterContainerElement)
+ this.tagFilterContainerElement.style.cssFloat = 'left'
+ this.tagFilterContainerElement.appendChild(document.createTextNode("Log Filter"))
+
+ this.tagFilterElement = document.createElement('input')
+ this.tagFilterContainerElement.appendChild(this.tagFilterElement)
+ this.tagFilterElement.style.width = '200px'
+ this.tagFilterElement.value = this.tagPattern
+ this.tagFilterElement.setAttribute('autocomplete', 'off') // So Firefox doesn't flip out
+
+ Event.observe(this.tagFilterElement, 'keyup', this.updateTags.bind(this))
+ Event.observe(this.tagFilterElement, 'click', function() {this.tagFilterElement.select()}.bind(this))
+
+ // Add outputElement
+ this.outputElement = document.createElement('div')
+ this.logElement.appendChild(this.outputElement)
+ this.outputElement.style.overflow = "auto"
+ this.outputElement.style.clear = "both"
+ this.outputElement.style.height = "200px"
+ this.outputElement.style.backgroundColor = 'black'
+
+ this.inputContainerElement = document.createElement('div')
+ this.inputContainerElement.style.width = "100%"
+ this.logElement.appendChild(this.inputContainerElement)
+
+ this.inputElement = document.createElement('input')
+ this.inputContainerElement.appendChild(this.inputElement)
+ this.inputElement.style.width = '100%'
+ this.inputElement.style.borderWidth = '0px' // Inputs with 100% width always seem to be too large (I HATE THEM) they only work if the border, margin and padding are 0
+ this.inputElement.style.margin = '0px'
+ this.inputElement.style.padding = '0px'
+ this.inputElement.value = 'Type command here'
+ this.inputElement.setAttribute('autocomplete', 'off') // So Firefox doesn't flip out
+
+ Event.observe(this.inputElement, 'keyup', this.handleInput.bind(this))
+ Event.observe(this.inputElement, 'click', function() {this.inputElement.select()}.bind(this))
+
+ if(document.all && !window.opera)
+ {
+ window.setInterval(this.repositionWindow.bind(this), 500)
+ }
+ else
+ {
+ this.logElement.style.position="fixed";
+ this.logElement.style.bottom="0px";
+ }
+ var self=this;
+ Event.observe(document, 'keydown', function(e)
+ {
+ if((e.altKey==true) && Event.keyCode(e) == toggleKey ) //Alt+J | Ctrl+J
+ self.toggle();
+ });
+
+ // Listen to the logger....
+ Logger.onupdate.addListener(this.logUpdate.bind(this))
+ Logger.onclear.addListener(this.clear.bind(this))
+
+ // Preload log element with the log entries that have been entered
+ for (var i = 0; i < Logger.logEntries.length; i++) {
+ this.logUpdate(Logger.logEntries[i])
+ }
+
+ // Feed all errors into the logger (For some unknown reason I can only get this to work
+ // with an inline event declaration)
+ Event.observe(window, 'error', function(msg, url, lineNumber) {Logger.error("Error in (" + (url || location) + ") on line "+lineNumber+"", msg)})
+
+ // Allow acess key link
+ var accessElement = document.createElement('span')
+ accessElement.innerHTML = '<button style="position:absolute;top:-100px" onclick="javascript:logConsole.toggle()" accesskey="d"></button>'
+ document.body.appendChild(accessElement)
+
+ if (Cookie.get('ConsoleVisible') == 'true') {
+ this.toggle()
+ }
+ },
+
+ toggle : function() {
+ if (this.logElement.style.display == 'none') {
+ this.show()
+ }
+ else {
+ this.hide()
+ }
+ },
+
+ show : function() {
+ Element.show(this.logElement)
+ this.outputElement.scrollTop = this.outputElement.scrollHeight // Scroll to bottom when toggled
+ if(document.all && !window.opera)
+ this.repositionWindow();
+ Cookie.set('ConsoleVisible', 'true')
+ this.inputElement.select()
+ this.hidden = false;
+ },
+
+ hide : function() {
+ this.hidden = true;
+ Element.hide(this.logElement)
+ Cookie.set('ConsoleVisible', 'false')
+ },
+
+ output : function(message, style) {
+ // If we are at the bottom of the window, then keep scrolling with the output
+ var shouldScroll = (this.outputElement.scrollTop + (2 * this.outputElement.clientHeight)) >= this.outputElement.scrollHeight
+
+ this.outputCount++
+ style = (style ? style += ';' : '')
+ style += 'padding:1px;margin:0 0 5px 0'
+
+ if (this.outputCount % 2 == 0) style += ";background-color:#101010"
+
+ message = message || "undefined"
+ message = message.toString().escapeHTML()
+
+ this.outputElement.innerHTML += "<pre style='" + style + "'>" + message + "</pre>"
+
+ if (shouldScroll) {
+ this.outputElement.scrollTop = this.outputElement.scrollHeight
+ }
+ },
+
+ updateTags : function() {
+ var pattern = this.tagFilterElement.value
+
+ if (this.tagPattern == pattern) return
+
+ try {
+ new RegExp(pattern)
+ }
+ catch (e) {
+ return
+ }
+
+ this.tagPattern = pattern
+ Cookie.set('tagPattern', this.tagPattern)
+
+ this.outputElement.innerHTML = ""
+
+ // Go through each log entry again
+ this.outputCount = 0;
+ for (var i = 0; i < Logger.logEntries.length; i++) {
+ this.logUpdate(Logger.logEntries[i])
+ }
+ },
+
+ repositionWindow : function() {
+ var offset = window.pageYOffset || document.documentElement.scrollTop || document.body.scrollTop
+ var pageHeight = self.innerHeight || document.documentElement.clientHeight || document.body.clientHeight
+ this.logElement.style.top = (offset + pageHeight - Element.getHeight(this.logElement)) + "px"
+ },
+
+ // Event Handlers
+ // --------------
+
+ logUpdate : function(logEntry) {
+ if (logEntry.tag.search(new RegExp(this.tagPattern, 'igm')) == -1) return
+ var style = ''
+ if (logEntry.tag.search(/error/) != -1) style += 'color:red'
+ else if (logEntry.tag.search(/warning/) != -1) style += 'color:orange'
+ else if (logEntry.tag.search(/debug/) != -1) style += 'color:green'
+ else if (logEntry.tag.search(/info/) != -1) style += 'color:white'
+ else style += 'color:yellow'
+
+ this.output(logEntry.message, style)
+ },
+
+ clear : function(e) {
+ this.outputElement.innerHTML = ""
+ },
+
+ handleInput : function(e) {
+ if (e.keyCode == Event.KEY_RETURN ) {
+ var command = this.inputElement.value
+
+ switch(command) {
+ case "clear":
+ Logger.clear()
+ break
+
+ default:
+ var consoleOutput = ""
+
+ try {
+ consoleOutput = eval(this.inputElement.value)
+ }
+ catch (e) {
+ Logger.error("Problem parsing input <" + command + ">", e)
+ break
+ }
+
+ Logger.log(consoleOutput)
+ break
+ }
+
+ if (this.inputElement.value != "" && this.inputElement.value != this.commandHistory[0]) {
+ this.commandHistory.unshift(this.inputElement.value)
+ }
+
+ this.commandIndex = 0
+ this.inputElement.value = ""
+ }
+ else if (e.keyCode == Event.KEY_UP && this.commandHistory.length > 0) {
+ this.inputElement.value = this.commandHistory[this.commandIndex]
+
+ if (this.commandIndex < this.commandHistory.length - 1) {
+ this.commandIndex += 1
+ }
+ }
+ else if (e.keyCode == Event.KEY_DOWN && this.commandHistory.length > 0) {
+ if (this.commandIndex > 0) {
+ this.commandIndex -= 1
+ }
+
+ this.inputElement.value = this.commandHistory[this.commandIndex]
+ }
+ else {
+ this.commandIndex = 0
+ }
+ }
+};
+
+
+// -------------------------
+// Helper Functions And Junk
+// -------------------------
+function inspect(o)
+{
+ var objtype = typeof(o);
+ if (objtype == "undefined") {
+ return "undefined";
+ } else if (objtype == "number" || objtype == "boolean") {
+ return o + "";
+ } else if (o === null) {
+ return "null";
+ }
+
+ try {
+ var ostring = (o + "");
+ } catch (e) {
+ return "[" + typeof(o) + "]";
+ }
+
+ if (typeof(o) == "function")
+ {
+ o = ostring.replace(/^\s+/, "");
+ var idx = o.indexOf("{");
+ if (idx != -1) {
+ o = o.substr(0, idx) + "{...}";
+ }
+ return o;
+ }
+
+ var reprString = function (o)
+ {
+ return ('"' + o.replace(/(["\\])/g, '\\$1') + '"'
+ ).replace(/[\f]/g, "\\f"
+ ).replace(/[\b]/g, "\\b"
+ ).replace(/[\n]/g, "\\n"
+ ).replace(/[\t]/g, "\\t"
+ ).replace(/[\r]/g, "\\r");
+ };
+
+ if (objtype == "string") {
+ return reprString(o);
+ }
+ // recurse
+ var me = arguments.callee;
+ // short-circuit for objects that support "json" serialization
+ // if they return "self" then just pass-through...
+ var newObj;
+ if (typeof(o.__json__) == "function") {
+ newObj = o.__json__();
+ if (o !== newObj) {
+ return me(newObj);
+ }
+ }
+ if (typeof(o.json) == "function") {
+ newObj = o.json();
+ if (o !== newObj) {
+ return me(newObj);
+ }
+ }
+ // array
+ if (objtype != "function" && typeof(o.length) == "number") {
+ var res = [];
+ for (var i = 0; i < o.length; i++) {
+ var val = me(o[i]);
+ if (typeof(val) != "string") {
+ val = "undefined";
+ }
+ res.push(val);
+ }
+ return "[" + res.join(", ") + "]";
+ }
+
+ // generic object code path
+ res = [];
+ for (var k in o) {
+ var useKey;
+ if (typeof(k) == "number") {
+ useKey = '"' + k + '"';
+ } else if (typeof(k) == "string") {
+ useKey = reprString(k);
+ } else {
+ // skip non-string or number keys
+ continue;
+ }
+ val = me(o[k]);
+ if (typeof(val) != "string") {
+ // skip non-serializable values
+ continue;
+ }
+ res.push(useKey + ":" + val);
+ }
+ return "{" + res.join(", ") + "}";
+};
+
+Array.prototype.contains = function(object) {
+ for(var i = 0; i < this.length; i++) {
+ if (object == this[i]) return true
+ }
+
+ return false
+};
+
+// Helper Alias for simple logging
+var puts = function() {return Logger.log(arguments[0], arguments[1])};
+
+/*************************************
+
+ Javascript Object Tree
+ version 1.0
+ last revision:04.11.2004
+ steve@slayeroffice.com
+ http://slayeroffice.com
+
+ (c)2004 S.G. Chipman
+
+ Please notify me of any modifications
+ you make to this code so that I can
+ update the version hosted on slayeroffice.com
+
+
+************************************/
+if(typeof Prado == "undefined")
+ var Prado = {};
+Prado.Inspector =
+{
+ d : document,
+ types : new Array(),
+ objs : new Array(),
+ hidden : new Array(),
+ opera : window.opera,
+ displaying : '',
+ nameList : new Array(),
+
+ format : function(str) {
+ if(typeof(str) != "string") return str;
+ str=str.replace(/</g,"&lt;");
+ str=str.replace(/>/g,"&gt;");
+ return str;
+ },
+
+ parseJS : function(obj) {
+ var name;
+ if(typeof obj == "string") { name = obj; obj = eval(obj); }
+ win= typeof obj == 'undefined' ? window : obj;
+ this.displaying = name ? name : win.toString();
+ for(js in win) {
+ try {
+ if(win[js] && js.toString().indexOf("Inspector")==-1 && (win[js]+"").indexOf("[native code]")==-1) {
+
+ t=typeof(win[js]);
+ if(!this.objs[t.toString()]) {
+ this.types[this.types.length]=t;
+ this.objs[t]={};
+ this.nameList[t] = new Array();
+ }
+ this.nameList[t].push(js);
+ this.objs[t][js] = this.format(win[js]+"");
+ }
+ } catch(err) { }
+ }
+
+ for(i=0;i<this.types.length;i++)
+ this.nameList[this.types[i]].sort();
+ },
+
+ show : function(objID) {
+ this.d.getElementById(objID).style.display=this.hidden[objID]?"none":"block";
+ this.hidden[objID]=this.hidden[objID]?0:1;
+ },
+
+ changeSpan : function(spanID) {
+ if(this.d.getElementById(spanID).innerHTML.indexOf("+")>-1){
+ this.d.getElementById(spanID).innerHTML="[-]";
+ } else {
+ this.d.getElementById(spanID).innerHTML="[+]";
+ }
+ },
+
+ buildInspectionLevel : function()
+ {
+ var display = this.displaying;
+ var list = display.split(".");
+ var links = ["<a href=\"javascript:var_dump()\">[object Window]</a>"];
+ var name = '';
+ if(display.indexOf("[object ") >= 0) return links.join(".");
+ for(var i = 0; i < list.length; i++)
+ {
+ name += (name.length ? "." : "") + list[i];
+ links[i+1] = "<a href=\"javascript:var_dump('"+name+"')\">"+list[i]+"</a>";
+ }
+ return links.join(".");
+ },
+
+ buildTree : function() {
+ mHTML = "<div>Inspecting "+this.buildInspectionLevel()+"</div>";
+ mHTML +="<ul class=\"topLevel\">";
+ this.types.sort();
+ var so_objIndex=0;
+ for(i=0;i<this.types.length;i++)
+ {
+ mHTML+="<li style=\"cursor:pointer;\" onclick=\"Prado.Inspector.show('ul"+i+"');Prado.Inspector.changeSpan('sp" + i + "')\"><span id=\"sp" + i + "\">[+]</span><b>" + this.types[i] + "</b> (" + this.nameList[this.types[i]].length + ")</li><ul style=\"display:none;\" id=\"ul"+i+"\">";
+ this.hidden["ul"+i]=0;
+ for(e=0;e<this.nameList[this.types[i]].length;e++)
+ {
+ var prop = this.nameList[this.types[i]][e];
+ var value = this.objs[this.types[i]][prop]
+ var more = "";
+ if(value.indexOf("[object ") >= 0 && /^[a-zA-Z_]/.test(prop))
+ {
+ if(this.displaying.indexOf("[object ") < 0)
+ more = " <a href=\"javascript:var_dump('"+this.displaying+"."+prop+"')\"><b>more</b></a>";
+ else if(this.displaying.indexOf("[object Window]") >= 0)
+ more = " <a href=\"javascript:var_dump('"+prop+"')\"><b>more</b></a>";
+ }
+ mHTML+="<li style=\"cursor:pointer;\" onclick=\"Prado.Inspector.show('mul" + so_objIndex + "');Prado.Inspector.changeSpan('sk" + so_objIndex + "')\"><span id=\"sk" + so_objIndex + "\">[+]</span>" + prop + "</li><ul id=\"mul" + so_objIndex + "\" style=\"display:none;\"><li style=\"list-style-type:none;\"><pre>" + value + more + "</pre></li></ul>";
+ this.hidden["mul"+so_objIndex]=0;
+ so_objIndex++;
+ }
+ mHTML+="</ul>";
+ }
+ mHTML+="</ul>";
+ this.d.getElementById("so_mContainer").innerHTML =mHTML;
+ },
+
+ handleKeyEvent : function(e) {
+ keyCode=document.all?window.event.keyCode:e.keyCode;
+ if(keyCode==27) {
+ this.cleanUp();
+ }
+ },
+
+ cleanUp : function()
+ {
+ if(this.d.getElementById("so_mContainer"))
+ {
+ this.d.body.removeChild(this.d.getElementById("so_mContainer"));
+ this.d.body.removeChild(this.d.getElementById("so_mStyle"));
+ if(typeof Event != "undefined")
+ Event.stopObserving(this.d, "keydown", this.dKeyDownEvent);
+ this.types = new Array();
+ this.objs = new Array();
+ this.hidden = new Array();
+ }
+ },
+
+ disabled : document.all && !this.opera,
+
+ inspect : function(obj)
+ {
+ if(this.disabled)return alert("Sorry, this only works in Mozilla and Firefox currently.");
+ this.cleanUp();
+ mObj=this.d.body.appendChild(this.d.createElement("div"));
+ mObj.id="so_mContainer";
+ sObj=this.d.body.appendChild(this.d.createElement("style"));
+ sObj.id="so_mStyle";
+ sObj.type="text/css";
+ sObj.innerHTML = this.style;
+ this.dKeyDownEvent = this.handleKeyEvent.bind(this);
+ if(typeof Event != "undefined")
+ Event.observe(this.d, "keydown", this.dKeyDownEvent);
+
+ this.parseJS(obj);
+ this.buildTree();
+
+ cObj=mObj.appendChild(this.d.createElement("div"));
+ cObj.className="credits";
+ cObj.innerHTML = "<b>[esc] to <a href=\"javascript:Prado.Inspector.cleanUp();\">close</a></b><br />Javascript Object Tree V2.0.";
+
+ window.scrollTo(0,0);
+ },
+
+ style : "#so_mContainer { position:absolute; top:5px; left:5px; background-color:#E3EBED; text-align:left; font:9pt verdana; width:85%; border:2px solid #000; padding:5px; z-index:1000; color:#000; } " +
+ "#so_mContainer ul { padding-left:20px; } " +
+ "#so_mContainer ul li { display:block; list-style-type:none; list-style-image:url(); line-height:2em; -moz-border-radius:.75em; font:10px verdana; padding:0; margin:2px; color:#000; } " +
+ "#so_mContainer li:hover { background-color:#E3EBED; } " +
+ "#so_mContainer ul li span { position:relative; width:15px; height:15px; margin-right:4px; } " +
+ "#so_mContainer pre { background-color:#F9FAFB; border:1px solid #638DA1; height:auto; padding:5px; font:9px verdana; color:#000; } " +
+ "#so_mContainer .topLevel { margin:0; padding:0; } " +
+ "#so_mContainer .credits { float:left; width:200px; font:6.5pt verdana; color:#000; padding:2px; margin-left:5px; text-align:left; border-top:1px solid #000; margin-top:15px; width:75%; } " +
+ "#so_mContainer .credits a { font:9px verdana; font-weight:bold; color:#004465; text-decoration:none; background-color:transparent; }"
+};
+
+//similar function to var_dump in PHP, brings up the javascript object tree UI.
+function var_dump(obj)
+{
+ Prado.Inspector.inspect(obj);
+}
+
+//similar function to print_r for PHP
+var print_r = inspect;
+
diff --git a/framework/Web/Javascripts/source/prado/prado.js b/framework/Web/Javascripts/source/prado/prado.js
index ce789456..2fcb2c1e 100644
--- a/framework/Web/Javascripts/source/prado/prado.js
+++ b/framework/Web/Javascripts/source/prado/prado.js
@@ -1,94 +1,94 @@
-/**
- * Prado base namespace
- * @namespace Prado
- */
-var Prado =
-{
- /**
- * Version of Prado clientscripts
- * @var Version
- */
- Version: '3.2',
-
- /**
- * Registry for Prado components
- * @var Registry
- */
- Registry: $H(),
-
- /**
- * Returns browser information.
- * <pre>
- * var browser = Prado.Browser();
- * alert(browser.ie); //should ouput true if IE, false otherwise
- * </pre>
- * @function {object} ?
- * @version 1.0
- * @returns browserinfo
- * @... {string} agent - Reported user agent
- * @... {string} ver - Reported agent version
- * @... {0|1} dom - 1 for DOM browsers
- * @... {0|1} ns4 - 1 for Netscape 4
- * @... {0|1} ns6 - 1 for Netscape 6 and Firefox
- * @... {boolean} ie3 - true for IE 3
- * @... {0|1} ie5 - 1 for IE 5
- * @... {0|1} ie6 - 1 for IE 6
- * @... {0|1} ie4 - 1 for IE 4
- * @... {0|1} ie - 1 for IE 4-6
- * @... {0|1} hotjava - 1 for HotJava
- * @... {0|1} ver3 - 1 for IE3 and HotJava
- * @... {0|1} opera - 1 for Opera
- * @... {boolean} opera7 - true for Opera 7
- * @... {0|1} operaOld - 1 for older Opera
- * @... {0|1} bw - 1 for IE 4-6, Netscape 4&6, Firefox and Opera
- * @... {boolean} mac - true for mac systems
- * @... {static} Version - Version of returned structure (1.0)
- */
- Browser : function()
- {
- var info = { Version : "1.0" };
- var is_major = parseInt( navigator.appVersion );
- info.nver = is_major;
- info.ver = navigator.appVersion;
- info.agent = navigator.userAgent;
- info.dom = document.getElementById ? 1 : 0;
- info.opera = window.opera ? 1 : 0;
- info.ie5 = ( info.ver.indexOf( "MSIE 5" ) > -1 && info.dom && !info.opera ) ? 1 : 0;
- info.ie6 = ( info.ver.indexOf( "MSIE 6" ) > -1 && info.dom && !info.opera ) ? 1 : 0;
- info.ie4 = ( document.all && !info.dom && !info.opera ) ? 1 : 0;
- info.ie = info.ie4 || info.ie5 || info.ie6;
- info.mac = info.agent.indexOf( "Mac" ) > -1;
- info.ns6 = ( info.dom && parseInt( info.ver ) >= 5 ) ? 1 : 0;
- info.ie3 = ( info.ver.indexOf( "MSIE" ) && ( is_major < 4 ) );
- info.hotjava = ( info.agent.toLowerCase().indexOf( 'hotjava' ) != -1 ) ? 1 : 0;
- info.ns4 = ( document.layers && !info.dom && !info.hotjava ) ? 1 : 0;
- info.bw = ( info.ie6 || info.ie5 || info.ie4 || info.ns4 || info.ns6 || info.opera );
- info.ver3 = ( info.hotjava || info.ie3 );
- info.opera7 = ( ( info.agent.toLowerCase().indexOf( 'opera 7' ) > -1 ) || ( info.agent.toLowerCase().indexOf( 'opera/7' ) > -1 ) );
- info.operaOld = info.opera && !info.opera7;
- return info;
- },
-
- /**
- * Import CSS from Url.
- * @function ?
- * @param doc - document DOM object
- * @param css_file - Url to CSS file
- */
- ImportCss : function(doc, css_file)
- {
- if (Prado.Browser().ie)
- var styleSheet = doc.createStyleSheet(css_file);
- else
- {
- var elm = doc.createElement("link");
-
- elm.rel = "stylesheet";
- elm.href = css_file;
- var headArr;
-
- if (headArr = doc.getElementsByTagName("head"))
- headArr[0].appendChild(elm);
- }
- }
-};
+/**
+ * Prado base namespace
+ * @namespace Prado
+ */
+var Prado =
+{
+ /**
+ * Version of Prado clientscripts
+ * @var Version
+ */
+ Version: '3.2',
+
+ /**
+ * Registry for Prado components
+ * @var Registry
+ */
+ Registry: $H(),
+
+ /**
+ * Returns browser information.
+ * <pre>
+ * var browser = Prado.Browser();
+ * alert(browser.ie); //should ouput true if IE, false otherwise
+ * </pre>
+ * @function {object} ?
+ * @version 1.0
+ * @returns browserinfo
+ * @... {string} agent - Reported user agent
+ * @... {string} ver - Reported agent version
+ * @... {0|1} dom - 1 for DOM browsers
+ * @... {0|1} ns4 - 1 for Netscape 4
+ * @... {0|1} ns6 - 1 for Netscape 6 and Firefox
+ * @... {boolean} ie3 - true for IE 3
+ * @... {0|1} ie5 - 1 for IE 5
+ * @... {0|1} ie6 - 1 for IE 6
+ * @... {0|1} ie4 - 1 for IE 4
+ * @... {0|1} ie - 1 for IE 4-6
+ * @... {0|1} hotjava - 1 for HotJava
+ * @... {0|1} ver3 - 1 for IE3 and HotJava
+ * @... {0|1} opera - 1 for Opera
+ * @... {boolean} opera7 - true for Opera 7
+ * @... {0|1} operaOld - 1 for older Opera
+ * @... {0|1} bw - 1 for IE 4-6, Netscape 4&6, Firefox and Opera
+ * @... {boolean} mac - true for mac systems
+ * @... {static} Version - Version of returned structure (1.0)
+ */
+ Browser : function()
+ {
+ var info = { Version : "1.0" };
+ var is_major = parseInt( navigator.appVersion );
+ info.nver = is_major;
+ info.ver = navigator.appVersion;
+ info.agent = navigator.userAgent;
+ info.dom = document.getElementById ? 1 : 0;
+ info.opera = window.opera ? 1 : 0;
+ info.ie5 = ( info.ver.indexOf( "MSIE 5" ) > -1 && info.dom && !info.opera ) ? 1 : 0;
+ info.ie6 = ( info.ver.indexOf( "MSIE 6" ) > -1 && info.dom && !info.opera ) ? 1 : 0;
+ info.ie4 = ( document.all && !info.dom && !info.opera ) ? 1 : 0;
+ info.ie = info.ie4 || info.ie5 || info.ie6;
+ info.mac = info.agent.indexOf( "Mac" ) > -1;
+ info.ns6 = ( info.dom && parseInt( info.ver ) >= 5 ) ? 1 : 0;
+ info.ie3 = ( info.ver.indexOf( "MSIE" ) && ( is_major < 4 ) );
+ info.hotjava = ( info.agent.toLowerCase().indexOf( 'hotjava' ) != -1 ) ? 1 : 0;
+ info.ns4 = ( document.layers && !info.dom && !info.hotjava ) ? 1 : 0;
+ info.bw = ( info.ie6 || info.ie5 || info.ie4 || info.ns4 || info.ns6 || info.opera );
+ info.ver3 = ( info.hotjava || info.ie3 );
+ info.opera7 = ( ( info.agent.toLowerCase().indexOf( 'opera 7' ) > -1 ) || ( info.agent.toLowerCase().indexOf( 'opera/7' ) > -1 ) );
+ info.operaOld = info.opera && !info.opera7;
+ return info;
+ },
+
+ /**
+ * Import CSS from Url.
+ * @function ?
+ * @param doc - document DOM object
+ * @param css_file - Url to CSS file
+ */
+ ImportCss : function(doc, css_file)
+ {
+ if (Prado.Browser().ie)
+ var styleSheet = doc.createStyleSheet(css_file);
+ else
+ {
+ var elm = doc.createElement("link");
+
+ elm.rel = "stylesheet";
+ elm.href = css_file;
+ var headArr;
+
+ if (headArr = doc.getElementsByTagName("head"))
+ headArr[0].appendChild(elm);
+ }
+ }
+};
diff --git a/framework/Web/Javascripts/source/prado/ratings/ratings.js b/framework/Web/Javascripts/source/prado/ratings/ratings.js
index c7322983..1369c740 100644
--- a/framework/Web/Javascripts/source/prado/ratings/ratings.js
+++ b/framework/Web/Javascripts/source/prado/ratings/ratings.js
@@ -1,206 +1,206 @@
-Prado.WebUI.TRatingList = Base.extend(
-{
- selectedIndex : -1,
- rating: -1,
- readOnly : false,
-
- constructor : function(options)
- {
- var cap = $(options.CaptionID);
- this.options = Object.extend(
- {
- caption : cap ? cap.innerHTML : ''
- }, options || {});
-
- Prado.WebUI.TRatingList.register(this);
- this._init();
- Prado.Registry.set(options.ListID, this);
- this.selectedIndex = options.SelectedIndex;
- this.rating = options.Rating;
- this.readOnly = options.ReadOnly
- if(options.Rating <= 0 && options.SelectedIndex >= 0)
- this.rating = options.SelectedIndex+1;
- this.setReadOnly(this.readOnly);
- },
-
- _init: function(options)
- {
- Element.addClassName($(this.options.ListID),this.options.Style);
- this.radios = new Array();
- this._mouseOvers = new Array();
- this._mouseOuts = new Array();
- this._clicks = new Array();
- var index=0;
- for(var i = 0; i<this.options.ItemCount; i++)
- {
- var radio = $(this.options.ListID+'_c'+i);
- var td = radio.parentNode.parentNode;
- if(radio && td.tagName.toLowerCase()=='td')
- {
- this.radios.push(radio);
- this._mouseOvers.push(this.hover.bindEvent(this,index));
- this._mouseOuts.push(this.recover.bindEvent(this,index));
- this._clicks.push(this.click.bindEvent(this,index));
- index++;
- Element.addClassName(td,"rating");
- }
- }
- },
-
- hover : function(ev,index)
- {
- if(this.readOnly==true) return;
- for(var i = 0; i<this.radios.length; i++)
- {
- var node = this.radios[i].parentNode.parentNode;
- var action = i <= index ? 'addClassName' : 'removeClassName'
- Element[action](node,"rating_hover");
- Element.removeClassName(node,"rating_selected");
- Element.removeClassName(node,"rating_half");
- }
- this.showCaption(this.getIndexCaption(index));
- },
-
- recover : function(ev,index)
- {
- if(this.readOnly==true) return;
- this.showRating(this.rating);
- this.showCaption(this.options.caption);
- },
-
- click : function(ev, index)
- {
- if(this.readOnly==true) return;
- for(var i = 0; i<this.radios.length; i++)
- this.radios[i].checked = (i == index);
- this.selectedIndex = index;
- this.setRating(index+1);
-
- if(this.options['AutoPostBack']==true){
- this.dispatchRequest(ev);
- }
- },
-
- dispatchRequest : function(ev)
- {
- var requestOptions = Object.extend(
- {
- ID : this.options.ListID+"_c"+this.selectedIndex,
- EventTarget : this.options.ListName+"$c"+this.selectedIndex
- },this.options);
- Prado.PostBack(ev, requestOptions);
- },
-
- setRating : function(value)
- {
- this.rating = value;
- var base = Math.floor(value-1);
- var remainder = value - base-1;
- var halfMax = this.options.HalfRating["1"];
- var index = remainder > halfMax ? base+1 : base;
- for(var i = 0; i<this.radios.length; i++)
- this.radios[i].checked = (i == index);
-
- var caption = this.getIndexCaption(index);
- this.setCaption(caption);
- this.showCaption(caption);
-
- this.showRating(this.rating);
- },
-
- showRating: function(value)
- {
- var base = Math.floor(value-1);
- var remainder = value - base-1;
- var halfMin = this.options.HalfRating["0"];
- var halfMax = this.options.HalfRating["1"];
- var index = remainder > halfMax ? base+1 : base;
- var hasHalf = remainder >= halfMin && remainder <= halfMax;
- for(var i = 0; i<this.radios.length; i++)
- {
- var node = this.radios[i].parentNode.parentNode;
- var action = i > index ? 'removeClassName' : 'addClassName';
- Element[action](node, "rating_selected");
- if(i==index+1 && hasHalf)
- Element.addClassName(node, "rating_half");
- else
- Element.removeClassName(node, "rating_half");
- Element.removeClassName(node,"rating_hover");
- }
- },
-
- getIndexCaption : function(index)
- {
- return index > -1 ? this.radios[index].value : this.options.caption;
- },
-
- showCaption : function(value)
- {
- var caption = $(this.options.CaptionID);
- if(caption) caption.innerHTML = value;
- $(this.options.ListID).title = value;
- },
-
- setCaption : function(value)
- {
- this.options.caption = value;
- this.showCaption(value);
- },
-
- setReadOnly : function(value)
- {
- this.readOnly = value;
- for(var i = 0; i<this.radios.length; i++)
- {
-
- var action = value ? 'addClassName' : 'removeClassName';
- Element[action](this.radios[i].parentNode.parentNode, "rating_disabled");
-
- var action = value ? 'stopObserving' : 'observe';
- var td = this.radios[i].parentNode.parentNode;
- Event[action](td, "mouseover", this._mouseOvers[i]);
- Event[action](td, "mouseout", this._mouseOuts[i]);
- Event[action](td, "click", this._clicks[i]);
- }
-
- this.showRating(this.rating);
- }
-},
-{
-ratings : {},
-register : function(rating)
-{
- Prado.WebUI.TRatingList.ratings[rating.options.ListID] = rating;
-},
-
-setReadOnly : function(id,value)
-{
- Prado.WebUI.TRatingList.ratings[id].setReadOnly(value);
-},
-
-setRating : function(id,value)
-{
- Prado.WebUI.TRatingList.ratings[id].setRating(value);
-},
-
-setCaption : function(id,value)
-{
- Prado.WebUI.TRatingList.ratings[id].setCaption(value);
-}
-});
-
-Prado.WebUI.TActiveRatingList = Prado.WebUI.TRatingList.extend(
-{
- dispatchRequest : function(ev)
- {
- var requestOptions = Object.extend(
- {
- ID : this.options.ListID+"_c"+this.selectedIndex,
- EventTarget : this.options.ListName+"$c"+this.selectedIndex
- },this.options);
- var request = new Prado.CallbackRequest(requestOptions.EventTarget, requestOptions);
- if(request.dispatch()==false)
- Event.stop(ev);
- }
-
-});
+Prado.WebUI.TRatingList = Base.extend(
+{
+ selectedIndex : -1,
+ rating: -1,
+ readOnly : false,
+
+ constructor : function(options)
+ {
+ var cap = $(options.CaptionID);
+ this.options = Object.extend(
+ {
+ caption : cap ? cap.innerHTML : ''
+ }, options || {});
+
+ Prado.WebUI.TRatingList.register(this);
+ this._init();
+ Prado.Registry.set(options.ListID, this);
+ this.selectedIndex = options.SelectedIndex;
+ this.rating = options.Rating;
+ this.readOnly = options.ReadOnly
+ if(options.Rating <= 0 && options.SelectedIndex >= 0)
+ this.rating = options.SelectedIndex+1;
+ this.setReadOnly(this.readOnly);
+ },
+
+ _init: function(options)
+ {
+ Element.addClassName($(this.options.ListID),this.options.Style);
+ this.radios = new Array();
+ this._mouseOvers = new Array();
+ this._mouseOuts = new Array();
+ this._clicks = new Array();
+ var index=0;
+ for(var i = 0; i<this.options.ItemCount; i++)
+ {
+ var radio = $(this.options.ListID+'_c'+i);
+ var td = radio.parentNode.parentNode;
+ if(radio && td.tagName.toLowerCase()=='td')
+ {
+ this.radios.push(radio);
+ this._mouseOvers.push(this.hover.bindEvent(this,index));
+ this._mouseOuts.push(this.recover.bindEvent(this,index));
+ this._clicks.push(this.click.bindEvent(this,index));
+ index++;
+ Element.addClassName(td,"rating");
+ }
+ }
+ },
+
+ hover : function(ev,index)
+ {
+ if(this.readOnly==true) return;
+ for(var i = 0; i<this.radios.length; i++)
+ {
+ var node = this.radios[i].parentNode.parentNode;
+ var action = i <= index ? 'addClassName' : 'removeClassName'
+ Element[action](node,"rating_hover");
+ Element.removeClassName(node,"rating_selected");
+ Element.removeClassName(node,"rating_half");
+ }
+ this.showCaption(this.getIndexCaption(index));
+ },
+
+ recover : function(ev,index)
+ {
+ if(this.readOnly==true) return;
+ this.showRating(this.rating);
+ this.showCaption(this.options.caption);
+ },
+
+ click : function(ev, index)
+ {
+ if(this.readOnly==true) return;
+ for(var i = 0; i<this.radios.length; i++)
+ this.radios[i].checked = (i == index);
+ this.selectedIndex = index;
+ this.setRating(index+1);
+
+ if(this.options['AutoPostBack']==true){
+ this.dispatchRequest(ev);
+ }
+ },
+
+ dispatchRequest : function(ev)
+ {
+ var requestOptions = Object.extend(
+ {
+ ID : this.options.ListID+"_c"+this.selectedIndex,
+ EventTarget : this.options.ListName+"$c"+this.selectedIndex
+ },this.options);
+ Prado.PostBack(ev, requestOptions);
+ },
+
+ setRating : function(value)
+ {
+ this.rating = value;
+ var base = Math.floor(value-1);
+ var remainder = value - base-1;
+ var halfMax = this.options.HalfRating["1"];
+ var index = remainder > halfMax ? base+1 : base;
+ for(var i = 0; i<this.radios.length; i++)
+ this.radios[i].checked = (i == index);
+
+ var caption = this.getIndexCaption(index);
+ this.setCaption(caption);
+ this.showCaption(caption);
+
+ this.showRating(this.rating);
+ },
+
+ showRating: function(value)
+ {
+ var base = Math.floor(value-1);
+ var remainder = value - base-1;
+ var halfMin = this.options.HalfRating["0"];
+ var halfMax = this.options.HalfRating["1"];
+ var index = remainder > halfMax ? base+1 : base;
+ var hasHalf = remainder >= halfMin && remainder <= halfMax;
+ for(var i = 0; i<this.radios.length; i++)
+ {
+ var node = this.radios[i].parentNode.parentNode;
+ var action = i > index ? 'removeClassName' : 'addClassName';
+ Element[action](node, "rating_selected");
+ if(i==index+1 && hasHalf)
+ Element.addClassName(node, "rating_half");
+ else
+ Element.removeClassName(node, "rating_half");
+ Element.removeClassName(node,"rating_hover");
+ }
+ },
+
+ getIndexCaption : function(index)
+ {
+ return index > -1 ? this.radios[index].value : this.options.caption;
+ },
+
+ showCaption : function(value)
+ {
+ var caption = $(this.options.CaptionID);
+ if(caption) caption.innerHTML = value;
+ $(this.options.ListID).title = value;
+ },
+
+ setCaption : function(value)
+ {
+ this.options.caption = value;
+ this.showCaption(value);
+ },
+
+ setReadOnly : function(value)
+ {
+ this.readOnly = value;
+ for(var i = 0; i<this.radios.length; i++)
+ {
+
+ var action = value ? 'addClassName' : 'removeClassName';
+ Element[action](this.radios[i].parentNode.parentNode, "rating_disabled");
+
+ var action = value ? 'stopObserving' : 'observe';
+ var td = this.radios[i].parentNode.parentNode;
+ Event[action](td, "mouseover", this._mouseOvers[i]);
+ Event[action](td, "mouseout", this._mouseOuts[i]);
+ Event[action](td, "click", this._clicks[i]);
+ }
+
+ this.showRating(this.rating);
+ }
+},
+{
+ratings : {},
+register : function(rating)
+{
+ Prado.WebUI.TRatingList.ratings[rating.options.ListID] = rating;
+},
+
+setReadOnly : function(id,value)
+{
+ Prado.WebUI.TRatingList.ratings[id].setReadOnly(value);
+},
+
+setRating : function(id,value)
+{
+ Prado.WebUI.TRatingList.ratings[id].setRating(value);
+},
+
+setCaption : function(id,value)
+{
+ Prado.WebUI.TRatingList.ratings[id].setCaption(value);
+}
+});
+
+Prado.WebUI.TActiveRatingList = Prado.WebUI.TRatingList.extend(
+{
+ dispatchRequest : function(ev)
+ {
+ var requestOptions = Object.extend(
+ {
+ ID : this.options.ListID+"_c"+this.selectedIndex,
+ EventTarget : this.options.ListName+"$c"+this.selectedIndex
+ },this.options);
+ var request = new Prado.CallbackRequest(requestOptions.EventTarget, requestOptions);
+ if(request.dispatch()==false)
+ Event.stop(ev);
+ }
+
+});
diff --git a/framework/Web/Javascripts/source/prado/scriptaculous-adapter.js b/framework/Web/Javascripts/source/prado/scriptaculous-adapter.js
index 2cdc34e6..c1b7f814 100644
--- a/framework/Web/Javascripts/source/prado/scriptaculous-adapter.js
+++ b/framework/Web/Javascripts/source/prado/scriptaculous-adapter.js
@@ -1,1396 +1,1396 @@
-/**
- * Utilities and extions to Prototype/Scriptaculous
- * @file scriptaculous-adapter.js
- */
-
-/**
- * Extension to
- * <a href="http://www.prototypejs.org/api/function" target="_blank">Prototype's Function</a>
- * @namespace Function
- */
-/**
- * Similar to bindAsEventLister, but takes additional arguments.
- * @function Function.bindEvent
- */
-Function.prototype.bindEvent = function()
-{
- var __method = this, args = $A(arguments), object = args.shift();
- return function(event)
- {
- return __method.apply(object, [event || window.event].concat(args));
- }
-};
-
-/**
- * Extension to
- * <a href="http://www.prototypejs.org/api/class" target="_blank">Prototype's Class</a>
- * @namespace Class
- */
-
-/**
- * Creates a new class by copying class definition from
- * the <tt>base</tt> and optional <tt>definition</tt>.
- * @function {Class} Class.extend
- * @param {function} base - Base class to copy from.
- * @param {optional Array} - Additional definition
- * @returns Constructor for the extended class
- */
-Class.extend = function(base, definition)
-{
- var component = Class.create();
- Object.extend(component.prototype, base.prototype);
- if(definition)
- Object.extend(component.prototype, definition);
- return component;
-};
-
-/**
- * Base, version 1.0.2
- * Copyright 2006, Dean Edwards
- * License: http://creativecommons.org/licenses/LGPL/2.1/
- * @class Base
- */
-var Base = function() {
- if (arguments.length) {
- if (this == window) { // cast an object to this class
- Base.prototype.extend.call(arguments[0], arguments.callee.prototype);
- } else {
- this.extend(arguments[0]);
- }
- }
-};
-
-Base.version = "1.0.2";
-
-Base.prototype = {
- extend: function(source, value) {
- var extend = Base.prototype.extend;
- if (arguments.length == 2) {
- var ancestor = this[source];
- // overriding?
- if ((ancestor instanceof Function) && (value instanceof Function) &&
- ancestor.valueOf() != value.valueOf() && /\bbase\b/.test(value)) {
- var method = value;
- // var _prototype = this.constructor.prototype;
- // var fromPrototype = !Base._prototyping && _prototype[source] == ancestor;
- value = function() {
- var previous = this.base;
- // this.base = fromPrototype ? _prototype[source] : ancestor;
- this.base = ancestor;
- var returnValue = method.apply(this, arguments);
- this.base = previous;
- return returnValue;
- };
- // point to the underlying method
- value.valueOf = function() {
- return method;
- };
- value.toString = function() {
- return String(method);
- };
- }
- return this[source] = value;
- } else if (source) {
- var _prototype = {toSource: null};
- // do the "toString" and other methods manually
- var _protected = ["toString", "valueOf"];
- // if we are prototyping then include the constructor
- if (Base._prototyping) _protected[2] = "constructor";
- var name;
- for (var i = 0; (name = _protected[i]); i++) {
- if (source[name] != _prototype[name]) {
- extend.call(this, name, source[name]);
- }
- }
- // copy each of the source object's properties to this object
- for (var name in source) {
- if (!_prototype[name]) {
- extend.call(this, name, source[name]);
- }
- }
- }
- return this;
- },
-
- base: function() {
- // call this method from any other method to invoke that method's ancestor
- }
-};
-
-Base.extend = function(_instance, _static) {
- var extend = Base.prototype.extend;
- if (!_instance) _instance = {};
- // build the prototype
- Base._prototyping = true;
- var _prototype = new this;
- extend.call(_prototype, _instance);
- var constructor = _prototype.constructor;
- _prototype.constructor = this;
- delete Base._prototyping;
- // create the wrapper for the constructor function
- var klass = function() {
- if (!Base._prototyping) constructor.apply(this, arguments);
- this.constructor = klass;
- };
- klass.prototype = _prototype;
- // build the class interface
- klass.extend = this.extend;
- klass.implement = this.implement;
- klass.toString = function() {
- return String(constructor);
- };
- extend.call(klass, _static);
- // single instance
- var object = constructor ? klass : _prototype;
- // class initialisation
- if (object.init instanceof Function) object.init();
- return object;
-};
-
-Base.implement = function(_interface) {
- if (_interface instanceof Function) _interface = _interface.prototype;
- this.prototype.extend(_interface);
-};
-
-/**
- * Performs a PostBack using javascript.
- * @function Prado.PostBack
- * @param event - Event that triggered this postback
- * @param options - Postback options
- * @... {string} FormID - Form that should be posted back
- * @... {optional boolean} CausesValidation - Validate before PostBack if true
- * @... {optional string} ValidationGroup - Group to Validate
- * @... {optional string} ID - Validation ID
- * @... {optional string} PostBackUrl - Postback URL
- * @... {optional boolean} TrackFocus - Keep track of focused element if true
- * @... {string} EventTarget - Id of element that triggered PostBack
- * @... {string} EventParameter - EventParameter for PostBack
- */
-Prado.PostBack = function(event,options)
-{
- var form = $(options['FormID']);
- var canSubmit = true;
-
- if(options['CausesValidation'] && typeof(Prado.Validation) != "undefined")
- {
- if(!Prado.Validation.validate(options['FormID'], options['ValidationGroup'], $(options['ID'])))
- return Event.stop(event);
- }
-
- if(options['PostBackUrl'] && options['PostBackUrl'].length > 0)
- form.action = options['PostBackUrl'];
-
- if(options['TrackFocus'])
- {
- var lastFocus = $('PRADO_LASTFOCUS');
- if(lastFocus)
- {
- var active = document.activeElement; //where did this come from
- if(active)
- lastFocus.value = active.id;
- else
- lastFocus.value = options['EventTarget'];
- }
- }
-
- $('PRADO_POSTBACK_TARGET').value = options['EventTarget'];
- $('PRADO_POSTBACK_PARAMETER').value = options['EventParameter'];
- /**
- * Since google toolbar prevents browser default action,
- * we will always disable default client-side browser action
- */
- /*if(options['StopEvent']) */
- Event.stop(event);
- Event.fireEvent(form,"submit");
-};
-
-/**
- * Prado utilities to manipulate DOM elements.
- * @object Prado.Element
- */
-Prado.Element =
-{
- /**
- * Set the value of a particular element.
- * @function ?
- * @param {string} element - Element id
- * @param {string} value - New element value
- */
- setValue : function(element, value)
- {
- var el = $(element);
- if(el && typeof(el.value) != "undefined")
- el.value = value;
- },
-
- /**
- * Select options from a selectable element.
- * @function ?
- * @param {string} element - Element id
- * @param {string} method - Name of any {@link Prado.Element.Selection} method
- * @param {array|boolean|string} value - Values that should be selected
- * @param {int} total - Number of elements
- */
- select : function(element, method, value, total)
- {
- var el = $(element);
- if(!el) return;
- var selection = Prado.Element.Selection;
- if(typeof(selection[method]) == "function")
- {
- var control = selection.isSelectable(el) ? [el] : selection.getListElements(element,total);
- selection[method](control, value);
- }
- },
-
- /**
- * Trigger a click event on a DOM element.
- * @function ?
- * @param {string} element - Element id
- */
- click : function(element)
- {
- var el = $(element);
- if(el)
- el.click();
- },
-
- /**
- * Check if an DOM element is disabled.
- * @function {boolean} ?
- * @param {string} element - Element id
- * @returns true if element is disabled
- */
- isDisabled : function(element)
- {
- if(!element.attributes['disabled']) //FF
- return false;
- var value = element.attributes['disabled'].nodeValue;
- if(typeof(value)=="string")
- return value.toLowerCase() == "disabled";
- else
- return value == true;
- },
-
- /**
- * Sets an attribute of a DOM element.
- * @function ?
- * @param {string} element - Element id
- * @param {string} attribute - Name of attribute
- * @param {string} value - Value of attribute
- */
- setAttribute : function(element, attribute, value)
- {
- var el = $(element);
- if(!el) return;
- if((attribute == "disabled" || attribute == "multiple") && value==false)
- el.removeAttribute(attribute);
- else if(attribute.match(/^on/i)) //event methods
- {
- try
- {
- eval("(func = function(event){"+value+"})");
- el[attribute] = func;
- }
- catch(e)
- {
- debugger;
- throw "Error in evaluating '"+value+"' for attribute "+attribute+" for element "+element.id;
- }
- }
- else
- el.setAttribute(attribute, value);
- },
-
- /**
- * Sets the options for a select element.
- * @function ?
- * @param {string} element - Element id
- * @param {array[]} options - Array of options, each an array of structure
- * [ "optionText" , "optionValue" , "optionGroup" ]
- */
- setOptions : function(element, options)
- {
- var el = $(element);
- if(!el) return;
- var previousGroup = null;
- var optGroup=null;
- if(el && el.tagName.toLowerCase() == "select")
- {
- while(el.childNodes.length > 0)
- el.removeChild(el.lastChild);
-
- var optDom = Prado.Element.createOptions(options);
- for(var i = 0; i < optDom.length; i++)
- el.appendChild(optDom[i]);
- }
- },
-
- /**
- * Create opt-group options from an array of options.
- * @function {array} ?
- * @param {array[]} options - Array of options, each an array of structure
- * [ "optionText" , "optionValue" , "optionGroup" ]
- * @returns Array of option DOM elements
- */
- createOptions : function(options)
- {
- var previousGroup = null;
- var optgroup=null;
- var result = [];
- for(var i = 0; i<options.length; i++)
- {
- var option = options[i];
- if(option.length > 2)
- {
- var group = option[2];
- if(group!=previousGroup)
- {
- if(previousGroup!=null && optgroup!=null)
- {
- result.push(optgroup);
- previousGroup=null;
- optgroup=null;
- }
- optgroup = document.createElement('optgroup');
- optgroup.label = group;
- previousGroup = group;
- }
- }
- var opt = document.createElement('option');
- opt.text = option[0];
- opt.innerText = option[0];
- opt.value = option[1];
- if(optgroup!=null)
- optgroup.appendChild(opt);
- else
- result.push(opt);
- }
- if(optgroup!=null)
- result.push(optgroup);
- return result;
- },
-
- /**
- * Set focus (delayed) on a particular element.
- * @function ?
- * @param {string} element - Element id
- */
- focus : function(element)
- {
- var obj = $(element);
- if(typeof(obj) != "undefined" && typeof(obj.focus) != "undefined")
- setTimeout(function(){ obj.focus(); }, 100);
- return false;
- },
-
- /**
- * Replace a DOM element either with given content or
- * with content from a CallBack response boundary
- * using a replacement method.
- * @function ?
- * @param {string|element} element - DOM element or element id
- * @param {string} method - Name of method to use for replacement
- * @param {optional string} content - New content of element
- * @param {optional string} boundary - Boundary of new content
- */
- replace : function(element, method, content, boundary)
- {
- if(boundary)
- {
- var result = Prado.Element.extractContent(this.transport.responseText, boundary);
- if(result != null)
- content = result;
- }
- if(typeof(element) == "string")
- {
- if($(element))
- method.toFunction().apply(this,[element,""+content]);
- }
- else
- {
- method.toFunction().apply(this,[""+content]);
- }
- },
-
- /**
- * Appends a javascript block to the document.
- * @function ?
- * @param {string} boundary - Boundary containing the javascript code
- */
- appendScriptBlock : function(boundary)
- {
- var content = Prado.Element.extractContent(this.transport.responseText, boundary);
- if(content == null)
- return;
-
- var el = document.createElement("script");
- el.type = "text/javascript";
- el.id = 'inline_' + boundary;
- el.text = content;
-
- (document.getElementsByTagName('head')[0] || document.documentElement).appendChild(el);
- el.parentNode.removeChild(el);
- },
-
- /**
- * Extract content from a text by its boundary id.
- * Boundaries have this form:
- * <pre>
- * &lt;!--123456--&gt;Democontent&lt;!--//123456--&gt;
- * </pre>
- * @function {string} ?
- * @param {string} text - Text that contains boundaries
- * @param {string} boundary - Boundary id
- * @returns Content from given boundaries
- */
- extractContent : function(text, boundary)
- {
- var tagStart = '<!--'+boundary+'-->';
- var tagEnd = '<!--//'+boundary+'-->';
- var start = text.indexOf(tagStart);
- if(start > -1)
- {
- start += tagStart.length;
- var end = text.indexOf(tagEnd,start);
- if(end > -1)
- return text.substring(start,end);
- }
- return null;
- /*var f = RegExp('(?:<!--'+boundary+'-->)((?:.|\n|\r)+?)(?:<!--//'+boundary+'-->)',"m");
- var result = text.match(f);
- if(result && result.length >= 2)
- return result[1];
- else
- return null;*/
- },
-
- /**
- * Evaluate a javascript snippet from a string.
- * @function ?
- * @param {string} content - String containing the script
- */
- evaluateScript : function(content)
- {
- try
- {
- content.evalScripts();
- }
- catch(e)
- {
- if(typeof(Logger) != "undefined")
- Logger.error('Error during evaluation of script "'+content+'"');
- else
- debugger;
- throw e;
- }
- },
-
- /**
- * Set CSS style with Camelized keys.
- * See <a href="http://www.prototypejs.org/api/element/setstyle" target="_blank">Prototype's
- * Element.setStyle</a> for details.
- * @function ?
- * @param {string|element} element - DOM element or element id
- * @param {object} styles - Object with style properties/values
- */
- setStyle : function (element, styles)
- {
- var s = {}
- // Camelize all styles keys
- for (var property in styles)
- {
- s[property.camelize()]=styles[property].camelize();
- }
- Element.setStyle(element, s);
- }
-};
-
-/**
- * Utilities for selections.
- * @object Prado.Element.Selection
- */
-Prado.Element.Selection =
-{
- /**
- * Check if an DOM element can be selected.
- * @function {boolean} ?
- * @param {element} el - DOM elemet
- * @returns true if element is selectable
- */
- isSelectable : function(el)
- {
- if(el && el.type)
- {
- switch(el.type.toLowerCase())
- {
- case 'checkbox':
- case 'radio':
- case 'select':
- case 'select-multiple':
- case 'select-one':
- return true;
- }
- }
- return false;
- },
-
- /**
- * Set checked attribute of a checkbox or radiobutton to value.
- * @function {boolean} ?
- * @param {element} el - DOM element
- * @param {boolean} value - New value of checked attribute
- * @returns New value of checked attribute
- */
- inputValue : function(el, value)
- {
- switch(el.type.toLowerCase())
- {
- case 'checkbox':
- case 'radio':
- return el.checked = value;
- }
- },
-
- /**
- * Set selected attribute for elements options by value.
- * If value is boolean, all elements options selected attribute will be set
- * to value. Otherwhise all options that have the given value will be selected.
- * @function ?
- * @param {element[]} elements - Array of selectable DOM elements
- * @param {boolean|string} value - Value of options that should be selected or boolean value of selection status
- */
- selectValue : function(elements, value)
- {
- elements.each(function(el)
- {
- $A(el.options).each(function(option)
- {
- if(typeof(value) == "boolean")
- option.selected = value;
- else if(option.value == value)
- option.selected = true;
- });
- })
- },
-
- /**
- * Set selected attribute for elements options by array of values.
- * @function ?
- * @param {element[]} elements - Array of selectable DOM elements
- * @param {string[]} value - Array of values to select
- */
- selectValues : function(elements, values)
- {
- var selection = this;
- values.each(function(value)
- {
- selection.selectValue(elements,value);
- })
- },
-
- /**
- * Set selected attribute for elements options by option index.
- * @function ?
- * @param {element[]} elements - Array of selectable DOM elements
- * @param {int} index - Index of option to select
- */
- selectIndex : function(elements, index)
- {
- elements.each(function(el)
- {
- if(el.type.toLowerCase() == 'select-one')
- el.selectedIndex = index;
- else
- {
- for(var i = 0; i<el.length; i++)
- {
- if(i == index)
- el.options[i].selected = true;
- }
- }
- })
- },
-
- /**
- * Set selected attribute to true for all elements options.
- * @function ?
- * @param {element[]} elements - Array of selectable DOM elements
- */
- selectAll : function(elements)
- {
- elements.each(function(el)
- {
- if(el.type.toLowerCase() != 'select-one')
- {
- $A(el.options).each(function(option)
- {
- option.selected = true;
- })
- }
- })
- },
-
- /**
- * Toggle the selected attribute for elements options.
- * @function ?
- * @param {element[]} elements - Array of selectable DOM elements
- */
- selectInvert : function(elements)
- {
- elements.each(function(el)
- {
- if(el.type.toLowerCase() != 'select-one')
- {
- $A(el.options).each(function(option)
- {
- option.selected = !options.selected;
- })
- }
- })
- },
-
- /**
- * Set selected attribute for elements options by array of option indices.
- * @function ?
- * @param {element[]} elements - Array of selectable DOM elements
- * @param {int[]} indices - Array of option indices to select
- */
- selectIndices : function(elements, indices)
- {
- var selection = this;
- indices.each(function(index)
- {
- selection.selectIndex(elements,index);
- })
- },
-
- /**
- * Unselect elements.
- * @function ?
- * @param {element[]} elements - Array of selectable DOM elements
- */
- selectClear : function(elements)
- {
- elements.each(function(el)
- {
- el.selectedIndex = -1;
- })
- },
-
- /**
- * Get list elements of an element.
- * @function {element[]} ?
- * @param {element[]} elements - Array of selectable DOM elements
- * @param {int} total - Number of list elements to return
- * @returns Array of list DOM elements
- */
- getListElements : function(element, total)
- {
- var elements = new Array();
- var el;
- for(var i = 0; i < total; i++)
- {
- el = $(element+"_c"+i);
- if(el)
- elements.push(el);
- }
- return elements;
- },
-
- /**
- * Set checked attribute of elements by value.
- * If value is boolean, checked attribute will be set to value.
- * Otherwhise all elements that have the given value will be checked.
- * @function ?
- * @param {element[]} elements - Array of checkable DOM elements
- * @param {boolean|String} value - Value that should be checked or boolean value of checked status
- *
- */
- checkValue : function(elements, value)
- {
- elements.each(function(el)
- {
- if(typeof(value) == "boolean")
- el.checked = value;
- else if(el.value == value)
- el.checked = true;
- });
- },
-
- /**
- * Set checked attribute of elements by array of values.
- * @function ?
- * @param {element[]} elements - Array of checkable DOM elements
- * @param {string[]} values - Values that should be checked
- *
- */
- checkValues : function(elements, values)
- {
- var selection = this;
- values.each(function(value)
- {
- selection.checkValue(elements, value);
- })
- },
-
- /**
- * Set checked attribute of elements by list index.
- * @function ?
- * @param {element[]} elements - Array of checkable DOM elements
- * @param {int} index - Index of element to set checked
- */
- checkIndex : function(elements, index)
- {
- for(var i = 0; i<elements.length; i++)
- {
- if(i == index)
- elements[i].checked = true;
- }
- },
-
- /**
- * Set checked attribute of elements by array of list indices.
- * @function ?
- * @param {element[]} elements - Array of selectable DOM elements
- * @param {int[]} indices - Array of list indices to set checked
- */
- checkIndices : function(elements, indices)
- {
- var selection = this;
- indices.each(function(index)
- {
- selection.checkIndex(elements, index);
- })
- },
-
- /**
- * Uncheck elements.
- * @function ?
- * @param {element[]} elements - Array of checkable DOM elements
- */
- checkClear : function(elements)
- {
- elements.each(function(el)
- {
- el.checked = false;
- });
- },
-
- /**
- * Set checked attribute of all elements to true.
- * @function ?
- * @param {element[]} elements - Array of checkable DOM elements
- */
- checkAll : function(elements)
- {
- elements.each(function(el)
- {
- el.checked = true;
- })
- },
-
- /**
- * Toggle the checked attribute of elements.
- * @function ?
- * @param {element[]} elements - Array of selectable DOM elements
- */
- checkInvert : function(elements)
- {
- elements.each(function(el)
- {
- el.checked != el.checked;
- })
- }
-};
-
-
-/**
- * Utilities for insertion.
- * @object Prado.Element.Insert
- */
-Prado.Element.Insert =
-{
- /**
- * Append content to element
- * @function ?
- * @param {element} element - DOM element that content should be appended to
- * @param {element} content - DOM element to append
- */
- append: function(element, content)
- {
- $(element).insert(content);
- },
-
- /**
- * Prepend content to element
- * @function ?
- * @param {element} element - DOM element that content should be prepended to
- * @param {element} content - DOM element to prepend
- */
- prepend: function(element, content)
- {
- $(element).insert({top:content});
- },
-
- /**
- * Insert content after element
- * @function ?
- * @param {element} element - DOM element that content should be inserted after
- * @param {element} content - DOM element to insert
- */
- after: function(element, content)
- {
- $(element).insert({after:content});
- },
-
- /**
- * Insert content before element
- * @function ?
- * @param {element} element - DOM element that content should be inserted before
- * @param {element} content - DOM element to insert
- */
- before: function(element, content)
- {
- $(element).insert({before:content});
- }
-};
-
-
-/**
- * Extension to
- * <a href="http://wiki.script.aculo.us/scriptaculous/show/builder" target="_blank">Scriptaculous' Builder</a>
- * @namespace Builder
- */
-
-Object.extend(Builder,
-{
- /**
- * Export scriptaculous builder utilities as window[functions]
- * @function ?
- */
- exportTags:function()
- {
- var tags=["BUTTON","TT","PRE","H1","H2","H3","BR","CANVAS","HR","LABEL","TEXTAREA","FORM","STRONG","SELECT","OPTION","OPTGROUP","LEGEND","FIELDSET","P","UL","OL","LI","TD","TR","THEAD","TBODY","TFOOT","TABLE","TH","INPUT","SPAN","A","DIV","IMG", "CAPTION"];
- tags.each(function(tag)
- {
- window[tag]=function()
- {
- var args=$A(arguments);
- if(args.length==0)
- return Builder.node(tag,null);
- if(args.length==1)
- return Builder.node(tag,args[0]);
- if(args.length>1)
- return Builder.node(tag,args.shift(),args);
-
- };
- });
- }
-});
-Builder.exportTags();
-
-/**
- * Extension to
- * <a href="http://www.prototypejs.org/api/string" target="_blank">Prototype's String</a>
- * @namespace String
- */
-Object.extend(String.prototype, {
-
- /**
- * Add padding to string
- * @function {string} ?
- * @param {string} side - "left" to pad the string on the left, "right" to pad right.
- * @param {int} len - Minimum string length.
- * @param {string} chr - Character(s) to pad
- * @returns Padded string
- */
- pad : function(side, len, chr) {
- if (!chr) chr = ' ';
- var s = this;
- var left = side.toLowerCase()=='left';
- while (s.length<len) s = left? chr + s : s + chr;
- return s;
- },
-
- /**
- * Add left padding to string
- * @function {string} ?
- * @param {int} len - Minimum string length.
- * @param {string} chr - Character(s) to pad
- * @returns Padded string
- */
- padLeft : function(len, chr) {
- return this.pad('left',len,chr);
- },
-
- /**
- * Add right padding to string
- * @function {string} ?
- * @param {int} len - Minimum string length.
- * @param {string} chr - Character(s) to pad
- * @returns Padded string
- */
- padRight : function(len, chr) {
- return this.pad('right',len,chr);
- },
-
- /**
- * Add zeros to the right of string
- * @function {string} ?
- * @param {int} len - Minimum string length.
- * @returns Padded string
- */
- zerofill : function(len) {
- return this.padLeft(len,'0');
- },
-
- /**
- * Remove white spaces from both ends of string.
- * @function {string} ?
- * @returns Trimmed string
- */
- trim : function() {
- return this.replace(/^\s+|\s+$/g,'');
- },
-
- /**
- * Remove white spaces from the left side of string.
- * @function {string} ?
- * @returns Trimmed string
- */
- trimLeft : function() {
- return this.replace(/^\s+/,'');
- },
-
- /**
- * Remove white spaces from the right side of string.
- * @function {string} ?
- * @returns Trimmed string
- */
- trimRight : function() {
- return this.replace(/\s+$/,'');
- },
-
- /**
- * Convert period separated function names into a function reference.
- * <br />Example:
- * <pre>
- * "Prado.AJAX.Callback.Action.setValue".toFunction()
- * </pre>
- * @function {function} ?
- * @returns Reference to the corresponding function
- */
- toFunction : function()
- {
- var commands = this.split(/\./);
- var command = window;
- commands.each(function(action)
- {
- if(command[new String(action)])
- command=command[new String(action)];
- });
- if(typeof(command) == "function")
- return command;
- else
- {
- if(typeof Logger != "undefined")
- Logger.error("Missing function", this);
-
- throw new Error ("Missing function '"+this+"'");
- }
- },
-
- /**
- * Convert string into integer, returns null if not integer.
- * @function {int} ?
- * @returns Integer, null if string does not represent an integer.
- */
- toInteger : function()
- {
- var exp = /^\s*[-\+]?\d+\s*$/;
- if (this.match(exp) == null)
- return null;
- var num = parseInt(this, 10);
- return (isNaN(num) ? null : num);
- },
-
- /**
- * Convert string into a double/float value. <b>Internationalization
- * is not supported</b>
- * @function {double} ?
- * @param {string} decimalchar - Decimal character, defaults to "."
- * @returns Double, null if string does not represent a float value
- */
- toDouble : function(decimalchar)
- {
- if(this.length <= 0) return null;
- decimalchar = decimalchar || ".";
- var exp = new RegExp("^\\s*([-\\+])?(\\d+)?(\\" + decimalchar + "(\\d+))?\\s*$");
- var m = this.match(exp);
-
- if (m == null)
- return null;
- m[1] = m[1] || "";
- m[2] = m[2] || "0";
- m[4] = m[4] || "0";
-
- var cleanInput = m[1] + (m[2].length>0 ? m[2] : "0") + "." + m[4];
- var num = parseFloat(cleanInput);
- return (isNaN(num) ? null : num);
- },
-
- /**
- * Convert strings that represent a currency value to float.
- * E.g. "10,000.50" will become "10000.50". The number
- * of dicimal digits, grouping and decimal characters can be specified.
- * <i>The currency input format is <b>very</b> strict, null will be returned if
- * the pattern does not match</i>.
- * @function {double} ?
- * @param {string} groupchar - Grouping character, defaults to ","
- * @param {int} digits - Number of decimal digits
- * @param {string} decimalchar - Decimal character, defaults to "."
- * @returns Double, null if string does not represent a currency value
- */
- toCurrency : function(groupchar, digits, decimalchar)
- {
- groupchar = groupchar || ",";
- decimalchar = decimalchar || ".";
- digits = typeof(digits) == "undefined" ? 2 : digits;
-
- var exp = new RegExp("^\\s*([-\\+])?(((\\d+)\\" + groupchar + ")*)(\\d+)"
- + ((digits > 0) ? "(\\" + decimalchar + "(\\d{1," + digits + "}))?" : "")
- + "\\s*$");
- var m = this.match(exp);
- if (m == null)
- return null;
- var intermed = m[2] + m[5] ;
- var cleanInput = m[1] + intermed.replace(
- new RegExp("(\\" + groupchar + ")", "g"), "")
- + ((digits > 0) ? "." + m[7] : "");
- var num = parseFloat(cleanInput);
- return (isNaN(num) ? null : num);
- },
-
- /**
- * Converts the string to a date by finding values that matches the
- * date format pattern.
- * @function {Date} ?
- * @param {string} format - Date format pattern, e.g. MM-dd-yyyy
- * @returns Date extracted from the string
- */
- toDate : function(format)
- {
- return Date.SimpleParse(this, format);
- }
-});
-
-/**
- * Extension to
- * <a href="http://www.prototypejs.org/api/event" target="_blank">Prototype's Event</a>
- * @namespace Event
- */
-Object.extend(Event,
-{
- /**
- * Register a function to be executed when the page is loaded.
- * Note that the page is only loaded if all resources (e.g. images)
- * are loaded.
- * <br />Example:
- * <br />Show an alert box with message "Page Loaded!" when the
- * page finished loading.
- * <pre>
- * Event.OnLoad(function(){ alert("Page Loaded!"); });
- * </pre>
- * @function ?
- * @param {function} fn - Function to execute when page is loaded.
- */
- OnLoad : function (fn)
- {
- // opera onload is in document, not window
- var w = document.addEventListener &&
- !window.addEventListener ? document : window;
- Event.observe(w,'load',fn);
- },
-
- /**
- * Returns the unicode character generated by key.
- * @param {event} e - Keyboard event
- * @function {int} ?
- * @returns Unicode character code generated by the key that was struck.
- */
- keyCode : function(e)
- {
- return e.keyCode != null ? e.keyCode : e.charCode
- },
-
- /**
- * Checks if an Event is of type HTMLEvent.
- * @function {boolean} ?
- * @param {string} type - Event type or event name.
- * @return true if event is of type HTMLEvent.
- */
- isHTMLEvent : function(type)
- {
- var events = ['abort', 'blur', 'change', 'error', 'focus',
- 'load', 'reset', 'resize', 'scroll', 'select',
- 'submit', 'unload'];
- return events.include(type);
- },
-
- /**
- * Checks if an Event is a mouse event.
- * @function {boolean} ?
- * @param {string} type - Event type or event name
- * @return true if event is of type MouseEvent.
- */
- isMouseEvent : function(type)
- {
- var events = ['click', 'mousedown', 'mousemove', 'mouseout',
- 'mouseover', 'mouseup'];
- return events.include(type);
- },
-
- /**
- * Dispatch the DOM event of a given <tt>type</tt> on a DOM
- * <tt>element</tt>. Only HTMLEvent and MouseEvent can be
- * dispatched, keyboard events or UIEvent can not be dispatch
- * via javascript consistently.
- * For the "submit" event the submit() method is called.
- * @function ?
- * @param {element|string} element - Element id string or DOM element.
- * @param {string} type - Event type to dispatch.
- */
- fireEvent : function(element,type)
- {
- element = $(element);
- if(type == "submit")
- return element.submit();
- if(document.createEvent)
- {
- if(Event.isHTMLEvent(type))
- {
- var event = document.createEvent('HTMLEvents');
- event.initEvent(type, true, true);
- }
- else if(Event.isMouseEvent(type))
- {
- var event = document.createEvent('MouseEvents');
- if (event.initMouseEvent)
- {
- event.initMouseEvent(type,true,true,
- document.defaultView, 1, 0, 0, 0, 0, false,
- false, false, false, 0, null);
- }
- else
- {
- // Safari
- // TODO we should be initialising other mouse-event related attributes here
- event.initEvent(type, true, true);
- }
- }
- element.dispatchEvent(event);
- }
- else if(document.createEventObject)
- {
- var evObj = document.createEventObject();
- element.fireEvent('on'+type, evObj);
- }
- else if(typeof(element['on'+type]) == "function")
- element['on'+type]();
- }
-});
-
-
-/**
- * Extension to
- * <a href="http://www.prototypejs.org/api/date" target="_blank">Prototype's Date</a>
- * @namespace Date
- */
-Object.extend(Date.prototype,
-{
- /**
- * SimpleFormat
- * @function ?
- * @param {string} format - TODO
- * @param {string} data - TODO
- * @returns TODO
- */
- SimpleFormat: function(format, data)
- {
- data = data || {};
- var bits = new Array();
- bits['d'] = this.getDate();
- bits['dd'] = String(this.getDate()).zerofill(2);
-
- bits['M'] = this.getMonth()+1;
- bits['MM'] = String(this.getMonth()+1).zerofill(2);
- if(data.AbbreviatedMonthNames)
- bits['MMM'] = data.AbbreviatedMonthNames[this.getMonth()];
- if(data.MonthNames)
- bits['MMMM'] = data.MonthNames[this.getMonth()];
- var yearStr = "" + this.getFullYear();
- yearStr = (yearStr.length == 2) ? '19' + yearStr: yearStr;
- bits['yyyy'] = yearStr;
- bits['yy'] = bits['yyyy'].toString().substr(2,2);
-
- // do some funky regexs to replace the format string
- // with the real values
- var frm = new String(format);
- for (var sect in bits)
- {
- var reg = new RegExp("\\b"+sect+"\\b" ,"g");
- frm = frm.replace(reg, bits[sect]);
- }
- return frm;
- },
-
- /**
- * toISODate
- * @function {string} ?
- * @returns TODO
- */
- toISODate : function()
- {
- var y = this.getFullYear();
- var m = String(this.getMonth() + 1).zerofill(2);
- var d = String(this.getDate()).zerofill(2);
- return String(y) + String(m) + String(d);
- }
-});
-
-Object.extend(Date,
-{
- /**
- * SimpleParse
- * @function ?
- * @param {string} format - TODO
- * @param {string} data - TODO
- * @returns TODO
- */
- SimpleParse: function(value, format)
- {
- var val=String(value);
- format=String(format);
-
- if(val.length <= 0) return null;
-
- if(format.length <= 0) return new Date(value);
-
- var isInteger = function (val)
- {
- var digits="1234567890";
- for (var i=0; i < val.length; i++)
- {
- if (digits.indexOf(val.charAt(i))==-1) { return false; }
- }
- return true;
- };
-
- var getInt = function(str,i,minlength,maxlength)
- {
- for (var x=maxlength; x>=minlength; x--)
- {
- var token=str.substring(i,i+x);
- if (token.length < minlength) { return null; }
- if (isInteger(token)) { return token; }
- }
- return null;
- };
-
- var i_val=0;
- var i_format=0;
- var c="";
- var token="";
- var token2="";
- var x,y;
- var now=new Date();
- var year=now.getFullYear();
- var month=now.getMonth()+1;
- var date=1;
-
- while (i_format < format.length)
- {
- // Get next token from format string
- c=format.charAt(i_format);
- token="";
- while ((format.charAt(i_format)==c) && (i_format < format.length))
- {
- token += format.charAt(i_format++);
- }
-
- // Extract contents of value based on format token
- if (token=="yyyy" || token=="yy" || token=="y")
- {
- if (token=="yyyy") { x=4;y=4; }
- if (token=="yy") { x=2;y=2; }
- if (token=="y") { x=2;y=4; }
- year=getInt(val,i_val,x,y);
- if (year==null) { return null; }
- i_val += year.length;
- if (year.length==2)
- {
- if (year > 70) { year=1900+(year-0); }
- else { year=2000+(year-0); }
- }
- }
-
- else if (token=="MM"||token=="M")
- {
- month=getInt(val,i_val,token.length,2);
- if(month==null||(month<1)||(month>12)){return null;}
- i_val+=month.length;
- }
- else if (token=="dd"||token=="d")
- {
- date=getInt(val,i_val,token.length,2);
- if(date==null||(date<1)||(date>31)){return null;}
- i_val+=date.length;
- }
- else
- {
- if (val.substring(i_val,i_val+token.length)!=token) {return null;}
- else {i_val+=token.length;}
- }
- }
-
- // If there are any trailing characters left in the value, it doesn't match
- if (i_val != val.length) { return null; }
-
- // Is date valid for month?
- if (month==2)
- {
- // Check for leap year
- if ( ( (year%4==0)&&(year%100 != 0) ) || (year%400==0) ) { // leap year
- if (date > 29){ return null; }
- }
- else { if (date > 28) { return null; } }
- }
-
- if ((month==4)||(month==6)||(month==9)||(month==11))
- {
- if (date > 30) { return null; }
- }
-
- var newdate=new Date(year,month-1,date, 0, 0, 0);
- return newdate;
- }
-});
-
-/**
- * Prado utilities for effects.
- * @object Prado.Effect
- */
-Prado.Effect =
-{
- /**
- * Highlights an element
- * @function ?
- * @param {element} element - DOM element to highlight
- * @param {optional object} options - Highlight options
- */
- Highlight : function (element,options)
- {
- new Effect.Highlight(element,options);
- }
-};
+/**
+ * Utilities and extions to Prototype/Scriptaculous
+ * @file scriptaculous-adapter.js
+ */
+
+/**
+ * Extension to
+ * <a href="http://www.prototypejs.org/api/function" target="_blank">Prototype's Function</a>
+ * @namespace Function
+ */
+/**
+ * Similar to bindAsEventLister, but takes additional arguments.
+ * @function Function.bindEvent
+ */
+Function.prototype.bindEvent = function()
+{
+ var __method = this, args = $A(arguments), object = args.shift();
+ return function(event)
+ {
+ return __method.apply(object, [event || window.event].concat(args));
+ }
+};
+
+/**
+ * Extension to
+ * <a href="http://www.prototypejs.org/api/class" target="_blank">Prototype's Class</a>
+ * @namespace Class
+ */
+
+/**
+ * Creates a new class by copying class definition from
+ * the <tt>base</tt> and optional <tt>definition</tt>.
+ * @function {Class} Class.extend
+ * @param {function} base - Base class to copy from.
+ * @param {optional Array} - Additional definition
+ * @returns Constructor for the extended class
+ */
+Class.extend = function(base, definition)
+{
+ var component = Class.create();
+ Object.extend(component.prototype, base.prototype);
+ if(definition)
+ Object.extend(component.prototype, definition);
+ return component;
+};
+
+/**
+ * Base, version 1.0.2
+ * Copyright 2006, Dean Edwards
+ * License: http://creativecommons.org/licenses/LGPL/2.1/
+ * @class Base
+ */
+var Base = function() {
+ if (arguments.length) {
+ if (this == window) { // cast an object to this class
+ Base.prototype.extend.call(arguments[0], arguments.callee.prototype);
+ } else {
+ this.extend(arguments[0]);
+ }
+ }
+};
+
+Base.version = "1.0.2";
+
+Base.prototype = {
+ extend: function(source, value) {
+ var extend = Base.prototype.extend;
+ if (arguments.length == 2) {
+ var ancestor = this[source];
+ // overriding?
+ if ((ancestor instanceof Function) && (value instanceof Function) &&
+ ancestor.valueOf() != value.valueOf() && /\bbase\b/.test(value)) {
+ var method = value;
+ // var _prototype = this.constructor.prototype;
+ // var fromPrototype = !Base._prototyping && _prototype[source] == ancestor;
+ value = function() {
+ var previous = this.base;
+ // this.base = fromPrototype ? _prototype[source] : ancestor;
+ this.base = ancestor;
+ var returnValue = method.apply(this, arguments);
+ this.base = previous;
+ return returnValue;
+ };
+ // point to the underlying method
+ value.valueOf = function() {
+ return method;
+ };
+ value.toString = function() {
+ return String(method);
+ };
+ }
+ return this[source] = value;
+ } else if (source) {
+ var _prototype = {toSource: null};
+ // do the "toString" and other methods manually
+ var _protected = ["toString", "valueOf"];
+ // if we are prototyping then include the constructor
+ if (Base._prototyping) _protected[2] = "constructor";
+ var name;
+ for (var i = 0; (name = _protected[i]); i++) {
+ if (source[name] != _prototype[name]) {
+ extend.call(this, name, source[name]);
+ }
+ }
+ // copy each of the source object's properties to this object
+ for (var name in source) {
+ if (!_prototype[name]) {
+ extend.call(this, name, source[name]);
+ }
+ }
+ }
+ return this;
+ },
+
+ base: function() {
+ // call this method from any other method to invoke that method's ancestor
+ }
+};
+
+Base.extend = function(_instance, _static) {
+ var extend = Base.prototype.extend;
+ if (!_instance) _instance = {};
+ // build the prototype
+ Base._prototyping = true;
+ var _prototype = new this;
+ extend.call(_prototype, _instance);
+ var constructor = _prototype.constructor;
+ _prototype.constructor = this;
+ delete Base._prototyping;
+ // create the wrapper for the constructor function
+ var klass = function() {
+ if (!Base._prototyping) constructor.apply(this, arguments);
+ this.constructor = klass;
+ };
+ klass.prototype = _prototype;
+ // build the class interface
+ klass.extend = this.extend;
+ klass.implement = this.implement;
+ klass.toString = function() {
+ return String(constructor);
+ };
+ extend.call(klass, _static);
+ // single instance
+ var object = constructor ? klass : _prototype;
+ // class initialisation
+ if (object.init instanceof Function) object.init();
+ return object;
+};
+
+Base.implement = function(_interface) {
+ if (_interface instanceof Function) _interface = _interface.prototype;
+ this.prototype.extend(_interface);
+};
+
+/**
+ * Performs a PostBack using javascript.
+ * @function Prado.PostBack
+ * @param event - Event that triggered this postback
+ * @param options - Postback options
+ * @... {string} FormID - Form that should be posted back
+ * @... {optional boolean} CausesValidation - Validate before PostBack if true
+ * @... {optional string} ValidationGroup - Group to Validate
+ * @... {optional string} ID - Validation ID
+ * @... {optional string} PostBackUrl - Postback URL
+ * @... {optional boolean} TrackFocus - Keep track of focused element if true
+ * @... {string} EventTarget - Id of element that triggered PostBack
+ * @... {string} EventParameter - EventParameter for PostBack
+ */
+Prado.PostBack = function(event,options)
+{
+ var form = $(options['FormID']);
+ var canSubmit = true;
+
+ if(options['CausesValidation'] && typeof(Prado.Validation) != "undefined")
+ {
+ if(!Prado.Validation.validate(options['FormID'], options['ValidationGroup'], $(options['ID'])))
+ return Event.stop(event);
+ }
+
+ if(options['PostBackUrl'] && options['PostBackUrl'].length > 0)
+ form.action = options['PostBackUrl'];
+
+ if(options['TrackFocus'])
+ {
+ var lastFocus = $('PRADO_LASTFOCUS');
+ if(lastFocus)
+ {
+ var active = document.activeElement; //where did this come from
+ if(active)
+ lastFocus.value = active.id;
+ else
+ lastFocus.value = options['EventTarget'];
+ }
+ }
+
+ $('PRADO_POSTBACK_TARGET').value = options['EventTarget'];
+ $('PRADO_POSTBACK_PARAMETER').value = options['EventParameter'];
+ /**
+ * Since google toolbar prevents browser default action,
+ * we will always disable default client-side browser action
+ */
+ /*if(options['StopEvent']) */
+ Event.stop(event);
+ Event.fireEvent(form,"submit");
+};
+
+/**
+ * Prado utilities to manipulate DOM elements.
+ * @object Prado.Element
+ */
+Prado.Element =
+{
+ /**
+ * Set the value of a particular element.
+ * @function ?
+ * @param {string} element - Element id
+ * @param {string} value - New element value
+ */
+ setValue : function(element, value)
+ {
+ var el = $(element);
+ if(el && typeof(el.value) != "undefined")
+ el.value = value;
+ },
+
+ /**
+ * Select options from a selectable element.
+ * @function ?
+ * @param {string} element - Element id
+ * @param {string} method - Name of any {@link Prado.Element.Selection} method
+ * @param {array|boolean|string} value - Values that should be selected
+ * @param {int} total - Number of elements
+ */
+ select : function(element, method, value, total)
+ {
+ var el = $(element);
+ if(!el) return;
+ var selection = Prado.Element.Selection;
+ if(typeof(selection[method]) == "function")
+ {
+ var control = selection.isSelectable(el) ? [el] : selection.getListElements(element,total);
+ selection[method](control, value);
+ }
+ },
+
+ /**
+ * Trigger a click event on a DOM element.
+ * @function ?
+ * @param {string} element - Element id
+ */
+ click : function(element)
+ {
+ var el = $(element);
+ if(el)
+ el.click();
+ },
+
+ /**
+ * Check if an DOM element is disabled.
+ * @function {boolean} ?
+ * @param {string} element - Element id
+ * @returns true if element is disabled
+ */
+ isDisabled : function(element)
+ {
+ if(!element.attributes['disabled']) //FF
+ return false;
+ var value = element.attributes['disabled'].nodeValue;
+ if(typeof(value)=="string")
+ return value.toLowerCase() == "disabled";
+ else
+ return value == true;
+ },
+
+ /**
+ * Sets an attribute of a DOM element.
+ * @function ?
+ * @param {string} element - Element id
+ * @param {string} attribute - Name of attribute
+ * @param {string} value - Value of attribute
+ */
+ setAttribute : function(element, attribute, value)
+ {
+ var el = $(element);
+ if(!el) return;
+ if((attribute == "disabled" || attribute == "multiple") && value==false)
+ el.removeAttribute(attribute);
+ else if(attribute.match(/^on/i)) //event methods
+ {
+ try
+ {
+ eval("(func = function(event){"+value+"})");
+ el[attribute] = func;
+ }
+ catch(e)
+ {
+ debugger;
+ throw "Error in evaluating '"+value+"' for attribute "+attribute+" for element "+element.id;
+ }
+ }
+ else
+ el.setAttribute(attribute, value);
+ },
+
+ /**
+ * Sets the options for a select element.
+ * @function ?
+ * @param {string} element - Element id
+ * @param {array[]} options - Array of options, each an array of structure
+ * [ "optionText" , "optionValue" , "optionGroup" ]
+ */
+ setOptions : function(element, options)
+ {
+ var el = $(element);
+ if(!el) return;
+ var previousGroup = null;
+ var optGroup=null;
+ if(el && el.tagName.toLowerCase() == "select")
+ {
+ while(el.childNodes.length > 0)
+ el.removeChild(el.lastChild);
+
+ var optDom = Prado.Element.createOptions(options);
+ for(var i = 0; i < optDom.length; i++)
+ el.appendChild(optDom[i]);
+ }
+ },
+
+ /**
+ * Create opt-group options from an array of options.
+ * @function {array} ?
+ * @param {array[]} options - Array of options, each an array of structure
+ * [ "optionText" , "optionValue" , "optionGroup" ]
+ * @returns Array of option DOM elements
+ */
+ createOptions : function(options)
+ {
+ var previousGroup = null;
+ var optgroup=null;
+ var result = [];
+ for(var i = 0; i<options.length; i++)
+ {
+ var option = options[i];
+ if(option.length > 2)
+ {
+ var group = option[2];
+ if(group!=previousGroup)
+ {
+ if(previousGroup!=null && optgroup!=null)
+ {
+ result.push(optgroup);
+ previousGroup=null;
+ optgroup=null;
+ }
+ optgroup = document.createElement('optgroup');
+ optgroup.label = group;
+ previousGroup = group;
+ }
+ }
+ var opt = document.createElement('option');
+ opt.text = option[0];
+ opt.innerText = option[0];
+ opt.value = option[1];
+ if(optgroup!=null)
+ optgroup.appendChild(opt);
+ else
+ result.push(opt);
+ }
+ if(optgroup!=null)
+ result.push(optgroup);
+ return result;
+ },
+
+ /**
+ * Set focus (delayed) on a particular element.
+ * @function ?
+ * @param {string} element - Element id
+ */
+ focus : function(element)
+ {
+ var obj = $(element);
+ if(typeof(obj) != "undefined" && typeof(obj.focus) != "undefined")
+ setTimeout(function(){ obj.focus(); }, 100);
+ return false;
+ },
+
+ /**
+ * Replace a DOM element either with given content or
+ * with content from a CallBack response boundary
+ * using a replacement method.
+ * @function ?
+ * @param {string|element} element - DOM element or element id
+ * @param {string} method - Name of method to use for replacement
+ * @param {optional string} content - New content of element
+ * @param {optional string} boundary - Boundary of new content
+ */
+ replace : function(element, method, content, boundary)
+ {
+ if(boundary)
+ {
+ var result = Prado.Element.extractContent(this.transport.responseText, boundary);
+ if(result != null)
+ content = result;
+ }
+ if(typeof(element) == "string")
+ {
+ if($(element))
+ method.toFunction().apply(this,[element,""+content]);
+ }
+ else
+ {
+ method.toFunction().apply(this,[""+content]);
+ }
+ },
+
+ /**
+ * Appends a javascript block to the document.
+ * @function ?
+ * @param {string} boundary - Boundary containing the javascript code
+ */
+ appendScriptBlock : function(boundary)
+ {
+ var content = Prado.Element.extractContent(this.transport.responseText, boundary);
+ if(content == null)
+ return;
+
+ var el = document.createElement("script");
+ el.type = "text/javascript";
+ el.id = 'inline_' + boundary;
+ el.text = content;
+
+ (document.getElementsByTagName('head')[0] || document.documentElement).appendChild(el);
+ el.parentNode.removeChild(el);
+ },
+
+ /**
+ * Extract content from a text by its boundary id.
+ * Boundaries have this form:
+ * <pre>
+ * &lt;!--123456--&gt;Democontent&lt;!--//123456--&gt;
+ * </pre>
+ * @function {string} ?
+ * @param {string} text - Text that contains boundaries
+ * @param {string} boundary - Boundary id
+ * @returns Content from given boundaries
+ */
+ extractContent : function(text, boundary)
+ {
+ var tagStart = '<!--'+boundary+'-->';
+ var tagEnd = '<!--//'+boundary+'-->';
+ var start = text.indexOf(tagStart);
+ if(start > -1)
+ {
+ start += tagStart.length;
+ var end = text.indexOf(tagEnd,start);
+ if(end > -1)
+ return text.substring(start,end);
+ }
+ return null;
+ /*var f = RegExp('(?:<!--'+boundary+'-->)((?:.|\n|\r)+?)(?:<!--//'+boundary+'-->)',"m");
+ var result = text.match(f);
+ if(result && result.length >= 2)
+ return result[1];
+ else
+ return null;*/
+ },
+
+ /**
+ * Evaluate a javascript snippet from a string.
+ * @function ?
+ * @param {string} content - String containing the script
+ */
+ evaluateScript : function(content)
+ {
+ try
+ {
+ content.evalScripts();
+ }
+ catch(e)
+ {
+ if(typeof(Logger) != "undefined")
+ Logger.error('Error during evaluation of script "'+content+'"');
+ else
+ debugger;
+ throw e;
+ }
+ },
+
+ /**
+ * Set CSS style with Camelized keys.
+ * See <a href="http://www.prototypejs.org/api/element/setstyle" target="_blank">Prototype's
+ * Element.setStyle</a> for details.
+ * @function ?
+ * @param {string|element} element - DOM element or element id
+ * @param {object} styles - Object with style properties/values
+ */
+ setStyle : function (element, styles)
+ {
+ var s = {}
+ // Camelize all styles keys
+ for (var property in styles)
+ {
+ s[property.camelize()]=styles[property].camelize();
+ }
+ Element.setStyle(element, s);
+ }
+};
+
+/**
+ * Utilities for selections.
+ * @object Prado.Element.Selection
+ */
+Prado.Element.Selection =
+{
+ /**
+ * Check if an DOM element can be selected.
+ * @function {boolean} ?
+ * @param {element} el - DOM elemet
+ * @returns true if element is selectable
+ */
+ isSelectable : function(el)
+ {
+ if(el && el.type)
+ {
+ switch(el.type.toLowerCase())
+ {
+ case 'checkbox':
+ case 'radio':
+ case 'select':
+ case 'select-multiple':
+ case 'select-one':
+ return true;
+ }
+ }
+ return false;
+ },
+
+ /**
+ * Set checked attribute of a checkbox or radiobutton to value.
+ * @function {boolean} ?
+ * @param {element} el - DOM element
+ * @param {boolean} value - New value of checked attribute
+ * @returns New value of checked attribute
+ */
+ inputValue : function(el, value)
+ {
+ switch(el.type.toLowerCase())
+ {
+ case 'checkbox':
+ case 'radio':
+ return el.checked = value;
+ }
+ },
+
+ /**
+ * Set selected attribute for elements options by value.
+ * If value is boolean, all elements options selected attribute will be set
+ * to value. Otherwhise all options that have the given value will be selected.
+ * @function ?
+ * @param {element[]} elements - Array of selectable DOM elements
+ * @param {boolean|string} value - Value of options that should be selected or boolean value of selection status
+ */
+ selectValue : function(elements, value)
+ {
+ elements.each(function(el)
+ {
+ $A(el.options).each(function(option)
+ {
+ if(typeof(value) == "boolean")
+ option.selected = value;
+ else if(option.value == value)
+ option.selected = true;
+ });
+ })
+ },
+
+ /**
+ * Set selected attribute for elements options by array of values.
+ * @function ?
+ * @param {element[]} elements - Array of selectable DOM elements
+ * @param {string[]} value - Array of values to select
+ */
+ selectValues : function(elements, values)
+ {
+ var selection = this;
+ values.each(function(value)
+ {
+ selection.selectValue(elements,value);
+ })
+ },
+
+ /**
+ * Set selected attribute for elements options by option index.
+ * @function ?
+ * @param {element[]} elements - Array of selectable DOM elements
+ * @param {int} index - Index of option to select
+ */
+ selectIndex : function(elements, index)
+ {
+ elements.each(function(el)
+ {
+ if(el.type.toLowerCase() == 'select-one')
+ el.selectedIndex = index;
+ else
+ {
+ for(var i = 0; i<el.length; i++)
+ {
+ if(i == index)
+ el.options[i].selected = true;
+ }
+ }
+ })
+ },
+
+ /**
+ * Set selected attribute to true for all elements options.
+ * @function ?
+ * @param {element[]} elements - Array of selectable DOM elements
+ */
+ selectAll : function(elements)
+ {
+ elements.each(function(el)
+ {
+ if(el.type.toLowerCase() != 'select-one')
+ {
+ $A(el.options).each(function(option)
+ {
+ option.selected = true;
+ })
+ }
+ })
+ },
+
+ /**
+ * Toggle the selected attribute for elements options.
+ * @function ?
+ * @param {element[]} elements - Array of selectable DOM elements
+ */
+ selectInvert : function(elements)
+ {
+ elements.each(function(el)
+ {
+ if(el.type.toLowerCase() != 'select-one')
+ {
+ $A(el.options).each(function(option)
+ {
+ option.selected = !options.selected;
+ })
+ }
+ })
+ },
+
+ /**
+ * Set selected attribute for elements options by array of option indices.
+ * @function ?
+ * @param {element[]} elements - Array of selectable DOM elements
+ * @param {int[]} indices - Array of option indices to select
+ */
+ selectIndices : function(elements, indices)
+ {
+ var selection = this;
+ indices.each(function(index)
+ {
+ selection.selectIndex(elements,index);
+ })
+ },
+
+ /**
+ * Unselect elements.
+ * @function ?
+ * @param {element[]} elements - Array of selectable DOM elements
+ */
+ selectClear : function(elements)
+ {
+ elements.each(function(el)
+ {
+ el.selectedIndex = -1;
+ })
+ },
+
+ /**
+ * Get list elements of an element.
+ * @function {element[]} ?
+ * @param {element[]} elements - Array of selectable DOM elements
+ * @param {int} total - Number of list elements to return
+ * @returns Array of list DOM elements
+ */
+ getListElements : function(element, total)
+ {
+ var elements = new Array();
+ var el;
+ for(var i = 0; i < total; i++)
+ {
+ el = $(element+"_c"+i);
+ if(el)
+ elements.push(el);
+ }
+ return elements;
+ },
+
+ /**
+ * Set checked attribute of elements by value.
+ * If value is boolean, checked attribute will be set to value.
+ * Otherwhise all elements that have the given value will be checked.
+ * @function ?
+ * @param {element[]} elements - Array of checkable DOM elements
+ * @param {boolean|String} value - Value that should be checked or boolean value of checked status
+ *
+ */
+ checkValue : function(elements, value)
+ {
+ elements.each(function(el)
+ {
+ if(typeof(value) == "boolean")
+ el.checked = value;
+ else if(el.value == value)
+ el.checked = true;
+ });
+ },
+
+ /**
+ * Set checked attribute of elements by array of values.
+ * @function ?
+ * @param {element[]} elements - Array of checkable DOM elements
+ * @param {string[]} values - Values that should be checked
+ *
+ */
+ checkValues : function(elements, values)
+ {
+ var selection = this;
+ values.each(function(value)
+ {
+ selection.checkValue(elements, value);
+ })
+ },
+
+ /**
+ * Set checked attribute of elements by list index.
+ * @function ?
+ * @param {element[]} elements - Array of checkable DOM elements
+ * @param {int} index - Index of element to set checked
+ */
+ checkIndex : function(elements, index)
+ {
+ for(var i = 0; i<elements.length; i++)
+ {
+ if(i == index)
+ elements[i].checked = true;
+ }
+ },
+
+ /**
+ * Set checked attribute of elements by array of list indices.
+ * @function ?
+ * @param {element[]} elements - Array of selectable DOM elements
+ * @param {int[]} indices - Array of list indices to set checked
+ */
+ checkIndices : function(elements, indices)
+ {
+ var selection = this;
+ indices.each(function(index)
+ {
+ selection.checkIndex(elements, index);
+ })
+ },
+
+ /**
+ * Uncheck elements.
+ * @function ?
+ * @param {element[]} elements - Array of checkable DOM elements
+ */
+ checkClear : function(elements)
+ {
+ elements.each(function(el)
+ {
+ el.checked = false;
+ });
+ },
+
+ /**
+ * Set checked attribute of all elements to true.
+ * @function ?
+ * @param {element[]} elements - Array of checkable DOM elements
+ */
+ checkAll : function(elements)
+ {
+ elements.each(function(el)
+ {
+ el.checked = true;
+ })
+ },
+
+ /**
+ * Toggle the checked attribute of elements.
+ * @function ?
+ * @param {element[]} elements - Array of selectable DOM elements
+ */
+ checkInvert : function(elements)
+ {
+ elements.each(function(el)
+ {
+ el.checked != el.checked;
+ })
+ }
+};
+
+
+/**
+ * Utilities for insertion.
+ * @object Prado.Element.Insert
+ */
+Prado.Element.Insert =
+{
+ /**
+ * Append content to element
+ * @function ?
+ * @param {element} element - DOM element that content should be appended to
+ * @param {element} content - DOM element to append
+ */
+ append: function(element, content)
+ {
+ $(element).insert(content);
+ },
+
+ /**
+ * Prepend content to element
+ * @function ?
+ * @param {element} element - DOM element that content should be prepended to
+ * @param {element} content - DOM element to prepend
+ */
+ prepend: function(element, content)
+ {
+ $(element).insert({top:content});
+ },
+
+ /**
+ * Insert content after element
+ * @function ?
+ * @param {element} element - DOM element that content should be inserted after
+ * @param {element} content - DOM element to insert
+ */
+ after: function(element, content)
+ {
+ $(element).insert({after:content});
+ },
+
+ /**
+ * Insert content before element
+ * @function ?
+ * @param {element} element - DOM element that content should be inserted before
+ * @param {element} content - DOM element to insert
+ */
+ before: function(element, content)
+ {
+ $(element).insert({before:content});
+ }
+};
+
+
+/**
+ * Extension to
+ * <a href="http://wiki.script.aculo.us/scriptaculous/show/builder" target="_blank">Scriptaculous' Builder</a>
+ * @namespace Builder
+ */
+
+Object.extend(Builder,
+{
+ /**
+ * Export scriptaculous builder utilities as window[functions]
+ * @function ?
+ */
+ exportTags:function()
+ {
+ var tags=["BUTTON","TT","PRE","H1","H2","H3","BR","CANVAS","HR","LABEL","TEXTAREA","FORM","STRONG","SELECT","OPTION","OPTGROUP","LEGEND","FIELDSET","P","UL","OL","LI","TD","TR","THEAD","TBODY","TFOOT","TABLE","TH","INPUT","SPAN","A","DIV","IMG", "CAPTION"];
+ tags.each(function(tag)
+ {
+ window[tag]=function()
+ {
+ var args=$A(arguments);
+ if(args.length==0)
+ return Builder.node(tag,null);
+ if(args.length==1)
+ return Builder.node(tag,args[0]);
+ if(args.length>1)
+ return Builder.node(tag,args.shift(),args);
+
+ };
+ });
+ }
+});
+Builder.exportTags();
+
+/**
+ * Extension to
+ * <a href="http://www.prototypejs.org/api/string" target="_blank">Prototype's String</a>
+ * @namespace String
+ */
+Object.extend(String.prototype, {
+
+ /**
+ * Add padding to string
+ * @function {string} ?
+ * @param {string} side - "left" to pad the string on the left, "right" to pad right.
+ * @param {int} len - Minimum string length.
+ * @param {string} chr - Character(s) to pad
+ * @returns Padded string
+ */
+ pad : function(side, len, chr) {
+ if (!chr) chr = ' ';
+ var s = this;
+ var left = side.toLowerCase()=='left';
+ while (s.length<len) s = left? chr + s : s + chr;
+ return s;
+ },
+
+ /**
+ * Add left padding to string
+ * @function {string} ?
+ * @param {int} len - Minimum string length.
+ * @param {string} chr - Character(s) to pad
+ * @returns Padded string
+ */
+ padLeft : function(len, chr) {
+ return this.pad('left',len,chr);
+ },
+
+ /**
+ * Add right padding to string
+ * @function {string} ?
+ * @param {int} len - Minimum string length.
+ * @param {string} chr - Character(s) to pad
+ * @returns Padded string
+ */
+ padRight : function(len, chr) {
+ return this.pad('right',len,chr);
+ },
+
+ /**
+ * Add zeros to the right of string
+ * @function {string} ?
+ * @param {int} len - Minimum string length.
+ * @returns Padded string
+ */
+ zerofill : function(len) {
+ return this.padLeft(len,'0');
+ },
+
+ /**
+ * Remove white spaces from both ends of string.
+ * @function {string} ?
+ * @returns Trimmed string
+ */
+ trim : function() {
+ return this.replace(/^\s+|\s+$/g,'');
+ },
+
+ /**
+ * Remove white spaces from the left side of string.
+ * @function {string} ?
+ * @returns Trimmed string
+ */
+ trimLeft : function() {
+ return this.replace(/^\s+/,'');
+ },
+
+ /**
+ * Remove white spaces from the right side of string.
+ * @function {string} ?
+ * @returns Trimmed string
+ */
+ trimRight : function() {
+ return this.replace(/\s+$/,'');
+ },
+
+ /**
+ * Convert period separated function names into a function reference.
+ * <br />Example:
+ * <pre>
+ * "Prado.AJAX.Callback.Action.setValue".toFunction()
+ * </pre>
+ * @function {function} ?
+ * @returns Reference to the corresponding function
+ */
+ toFunction : function()
+ {
+ var commands = this.split(/\./);
+ var command = window;
+ commands.each(function(action)
+ {
+ if(command[new String(action)])
+ command=command[new String(action)];
+ });
+ if(typeof(command) == "function")
+ return command;
+ else
+ {
+ if(typeof Logger != "undefined")
+ Logger.error("Missing function", this);
+
+ throw new Error ("Missing function '"+this+"'");
+ }
+ },
+
+ /**
+ * Convert string into integer, returns null if not integer.
+ * @function {int} ?
+ * @returns Integer, null if string does not represent an integer.
+ */
+ toInteger : function()
+ {
+ var exp = /^\s*[-\+]?\d+\s*$/;
+ if (this.match(exp) == null)
+ return null;
+ var num = parseInt(this, 10);
+ return (isNaN(num) ? null : num);
+ },
+
+ /**
+ * Convert string into a double/float value. <b>Internationalization
+ * is not supported</b>
+ * @function {double} ?
+ * @param {string} decimalchar - Decimal character, defaults to "."
+ * @returns Double, null if string does not represent a float value
+ */
+ toDouble : function(decimalchar)
+ {
+ if(this.length <= 0) return null;
+ decimalchar = decimalchar || ".";
+ var exp = new RegExp("^\\s*([-\\+])?(\\d+)?(\\" + decimalchar + "(\\d+))?\\s*$");
+ var m = this.match(exp);
+
+ if (m == null)
+ return null;
+ m[1] = m[1] || "";
+ m[2] = m[2] || "0";
+ m[4] = m[4] || "0";
+
+ var cleanInput = m[1] + (m[2].length>0 ? m[2] : "0") + "." + m[4];
+ var num = parseFloat(cleanInput);
+ return (isNaN(num) ? null : num);
+ },
+
+ /**
+ * Convert strings that represent a currency value to float.
+ * E.g. "10,000.50" will become "10000.50". The number
+ * of dicimal digits, grouping and decimal characters can be specified.
+ * <i>The currency input format is <b>very</b> strict, null will be returned if
+ * the pattern does not match</i>.
+ * @function {double} ?
+ * @param {string} groupchar - Grouping character, defaults to ","
+ * @param {int} digits - Number of decimal digits
+ * @param {string} decimalchar - Decimal character, defaults to "."
+ * @returns Double, null if string does not represent a currency value
+ */
+ toCurrency : function(groupchar, digits, decimalchar)
+ {
+ groupchar = groupchar || ",";
+ decimalchar = decimalchar || ".";
+ digits = typeof(digits) == "undefined" ? 2 : digits;
+
+ var exp = new RegExp("^\\s*([-\\+])?(((\\d+)\\" + groupchar + ")*)(\\d+)"
+ + ((digits > 0) ? "(\\" + decimalchar + "(\\d{1," + digits + "}))?" : "")
+ + "\\s*$");
+ var m = this.match(exp);
+ if (m == null)
+ return null;
+ var intermed = m[2] + m[5] ;
+ var cleanInput = m[1] + intermed.replace(
+ new RegExp("(\\" + groupchar + ")", "g"), "")
+ + ((digits > 0) ? "." + m[7] : "");
+ var num = parseFloat(cleanInput);
+ return (isNaN(num) ? null : num);
+ },
+
+ /**
+ * Converts the string to a date by finding values that matches the
+ * date format pattern.
+ * @function {Date} ?
+ * @param {string} format - Date format pattern, e.g. MM-dd-yyyy
+ * @returns Date extracted from the string
+ */
+ toDate : function(format)
+ {
+ return Date.SimpleParse(this, format);
+ }
+});
+
+/**
+ * Extension to
+ * <a href="http://www.prototypejs.org/api/event" target="_blank">Prototype's Event</a>
+ * @namespace Event
+ */
+Object.extend(Event,
+{
+ /**
+ * Register a function to be executed when the page is loaded.
+ * Note that the page is only loaded if all resources (e.g. images)
+ * are loaded.
+ * <br />Example:
+ * <br />Show an alert box with message "Page Loaded!" when the
+ * page finished loading.
+ * <pre>
+ * Event.OnLoad(function(){ alert("Page Loaded!"); });
+ * </pre>
+ * @function ?
+ * @param {function} fn - Function to execute when page is loaded.
+ */
+ OnLoad : function (fn)
+ {
+ // opera onload is in document, not window
+ var w = document.addEventListener &&
+ !window.addEventListener ? document : window;
+ Event.observe(w,'load',fn);
+ },
+
+ /**
+ * Returns the unicode character generated by key.
+ * @param {event} e - Keyboard event
+ * @function {int} ?
+ * @returns Unicode character code generated by the key that was struck.
+ */
+ keyCode : function(e)
+ {
+ return e.keyCode != null ? e.keyCode : e.charCode
+ },
+
+ /**
+ * Checks if an Event is of type HTMLEvent.
+ * @function {boolean} ?
+ * @param {string} type - Event type or event name.
+ * @return true if event is of type HTMLEvent.
+ */
+ isHTMLEvent : function(type)
+ {
+ var events = ['abort', 'blur', 'change', 'error', 'focus',
+ 'load', 'reset', 'resize', 'scroll', 'select',
+ 'submit', 'unload'];
+ return events.include(type);
+ },
+
+ /**
+ * Checks if an Event is a mouse event.
+ * @function {boolean} ?
+ * @param {string} type - Event type or event name
+ * @return true if event is of type MouseEvent.
+ */
+ isMouseEvent : function(type)
+ {
+ var events = ['click', 'mousedown', 'mousemove', 'mouseout',
+ 'mouseover', 'mouseup'];
+ return events.include(type);
+ },
+
+ /**
+ * Dispatch the DOM event of a given <tt>type</tt> on a DOM
+ * <tt>element</tt>. Only HTMLEvent and MouseEvent can be
+ * dispatched, keyboard events or UIEvent can not be dispatch
+ * via javascript consistently.
+ * For the "submit" event the submit() method is called.
+ * @function ?
+ * @param {element|string} element - Element id string or DOM element.
+ * @param {string} type - Event type to dispatch.
+ */
+ fireEvent : function(element,type)
+ {
+ element = $(element);
+ if(type == "submit")
+ return element.submit();
+ if(document.createEvent)
+ {
+ if(Event.isHTMLEvent(type))
+ {
+ var event = document.createEvent('HTMLEvents');
+ event.initEvent(type, true, true);
+ }
+ else if(Event.isMouseEvent(type))
+ {
+ var event = document.createEvent('MouseEvents');
+ if (event.initMouseEvent)
+ {
+ event.initMouseEvent(type,true,true,
+ document.defaultView, 1, 0, 0, 0, 0, false,
+ false, false, false, 0, null);
+ }
+ else
+ {
+ // Safari
+ // TODO we should be initialising other mouse-event related attributes here
+ event.initEvent(type, true, true);
+ }
+ }
+ element.dispatchEvent(event);
+ }
+ else if(document.createEventObject)
+ {
+ var evObj = document.createEventObject();
+ element.fireEvent('on'+type, evObj);
+ }
+ else if(typeof(element['on'+type]) == "function")
+ element['on'+type]();
+ }
+});
+
+
+/**
+ * Extension to
+ * <a href="http://www.prototypejs.org/api/date" target="_blank">Prototype's Date</a>
+ * @namespace Date
+ */
+Object.extend(Date.prototype,
+{
+ /**
+ * SimpleFormat
+ * @function ?
+ * @param {string} format - TODO
+ * @param {string} data - TODO
+ * @returns TODO
+ */
+ SimpleFormat: function(format, data)
+ {
+ data = data || {};
+ var bits = new Array();
+ bits['d'] = this.getDate();
+ bits['dd'] = String(this.getDate()).zerofill(2);
+
+ bits['M'] = this.getMonth()+1;
+ bits['MM'] = String(this.getMonth()+1).zerofill(2);
+ if(data.AbbreviatedMonthNames)
+ bits['MMM'] = data.AbbreviatedMonthNames[this.getMonth()];
+ if(data.MonthNames)
+ bits['MMMM'] = data.MonthNames[this.getMonth()];
+ var yearStr = "" + this.getFullYear();
+ yearStr = (yearStr.length == 2) ? '19' + yearStr: yearStr;
+ bits['yyyy'] = yearStr;
+ bits['yy'] = bits['yyyy'].toString().substr(2,2);
+
+ // do some funky regexs to replace the format string
+ // with the real values
+ var frm = new String(format);
+ for (var sect in bits)
+ {
+ var reg = new RegExp("\\b"+sect+"\\b" ,"g");
+ frm = frm.replace(reg, bits[sect]);
+ }
+ return frm;
+ },
+
+ /**
+ * toISODate
+ * @function {string} ?
+ * @returns TODO
+ */
+ toISODate : function()
+ {
+ var y = this.getFullYear();
+ var m = String(this.getMonth() + 1).zerofill(2);
+ var d = String(this.getDate()).zerofill(2);
+ return String(y) + String(m) + String(d);
+ }
+});
+
+Object.extend(Date,
+{
+ /**
+ * SimpleParse
+ * @function ?
+ * @param {string} format - TODO
+ * @param {string} data - TODO
+ * @returns TODO
+ */
+ SimpleParse: function(value, format)
+ {
+ var val=String(value);
+ format=String(format);
+
+ if(val.length <= 0) return null;
+
+ if(format.length <= 0) return new Date(value);
+
+ var isInteger = function (val)
+ {
+ var digits="1234567890";
+ for (var i=0; i < val.length; i++)
+ {
+ if (digits.indexOf(val.charAt(i))==-1) { return false; }
+ }
+ return true;
+ };
+
+ var getInt = function(str,i,minlength,maxlength)
+ {
+ for (var x=maxlength; x>=minlength; x--)
+ {
+ var token=str.substring(i,i+x);
+ if (token.length < minlength) { return null; }
+ if (isInteger(token)) { return token; }
+ }
+ return null;
+ };
+
+ var i_val=0;
+ var i_format=0;
+ var c="";
+ var token="";
+ var token2="";
+ var x,y;
+ var now=new Date();
+ var year=now.getFullYear();
+ var month=now.getMonth()+1;
+ var date=1;
+
+ while (i_format < format.length)
+ {
+ // Get next token from format string
+ c=format.charAt(i_format);
+ token="";
+ while ((format.charAt(i_format)==c) && (i_format < format.length))
+ {
+ token += format.charAt(i_format++);
+ }
+
+ // Extract contents of value based on format token
+ if (token=="yyyy" || token=="yy" || token=="y")
+ {
+ if (token=="yyyy") { x=4;y=4; }
+ if (token=="yy") { x=2;y=2; }
+ if (token=="y") { x=2;y=4; }
+ year=getInt(val,i_val,x,y);
+ if (year==null) { return null; }
+ i_val += year.length;
+ if (year.length==2)
+ {
+ if (year > 70) { year=1900+(year-0); }
+ else { year=2000+(year-0); }
+ }
+ }
+
+ else if (token=="MM"||token=="M")
+ {
+ month=getInt(val,i_val,token.length,2);
+ if(month==null||(month<1)||(month>12)){return null;}
+ i_val+=month.length;
+ }
+ else if (token=="dd"||token=="d")
+ {
+ date=getInt(val,i_val,token.length,2);
+ if(date==null||(date<1)||(date>31)){return null;}
+ i_val+=date.length;
+ }
+ else
+ {
+ if (val.substring(i_val,i_val+token.length)!=token) {return null;}
+ else {i_val+=token.length;}
+ }
+ }
+
+ // If there are any trailing characters left in the value, it doesn't match
+ if (i_val != val.length) { return null; }
+
+ // Is date valid for month?
+ if (month==2)
+ {
+ // Check for leap year
+ if ( ( (year%4==0)&&(year%100 != 0) ) || (year%400==0) ) { // leap year
+ if (date > 29){ return null; }
+ }
+ else { if (date > 28) { return null; } }
+ }
+
+ if ((month==4)||(month==6)||(month==9)||(month==11))
+ {
+ if (date > 30) { return null; }
+ }
+
+ var newdate=new Date(year,month-1,date, 0, 0, 0);
+ return newdate;
+ }
+});
+
+/**
+ * Prado utilities for effects.
+ * @object Prado.Effect
+ */
+Prado.Effect =
+{
+ /**
+ * Highlights an element
+ * @function ?
+ * @param {element} element - DOM element to highlight
+ * @param {optional object} options - Highlight options
+ */
+ Highlight : function (element,options)
+ {
+ new Effect.Highlight(element,options);
+ }
+};
diff --git a/framework/Web/Javascripts/source/prado/validator/validation3.js b/framework/Web/Javascripts/source/prado/validator/validation3.js
index 597b4b5b..1fd1b570 100644
--- a/framework/Web/Javascripts/source/prado/validator/validation3.js
+++ b/framework/Web/Javascripts/source/prado/validator/validation3.js
@@ -1,1943 +1,1943 @@
-/**
- * Prado client-side javascript validation fascade.
- *
- * <p>There are 4 basic classes: {@link Prado.Validation},
- * {@link Prado.ValidationManager}, {@link Prado.WebUI.TValidationSummary}
- * and {@link Prado.WebUI.TBaseValidator},
- * that interact together to perform validation.
- * The {@link Prado.Validation} class co-ordinates together the
- * validation scheme and is responsible for maintaining references
- * to ValidationManagers.</p>
- *
- * <p>The {@link Prado.ValidationManager} class is responsible for
- * maintaining refereneces
- * to individual validators, validation summaries and their associated
- * groupings.</p>
- *
- * <p>The {@link Prado.WebUI.TValidationSummary} takes care of displaying
- * the validator error messages
- * as html output or an alert output.</p>
- *
- * <p>The {@link Prado.WebUI.TBaseValidator} is the base class for all
- * validators and contains
- * methods to interact with the actual inputs, data type conversion.</p>
- *
- * <p>An instance of {@link Prado.ValidationManager} must be instantiated first for a
- * particular form before instantiating validators and summaries.</p>
- *
- * <p>Usage example: adding a required field to a text box input with
- * ID "input1" in a form with ID "form1".</p>
- * <pre>
- * &lt;script type="text/javascript" src="../prado.js"&gt;&lt;/script&gt;
- * &lt;script type="text/javascript" src="../validator.js"&gt;&lt;/script&gt;
- * &lt;form id="form1" action="..."&gt;
- * &lt;div&gt;
- * &lt;input type="text" id="input1" /&gt;
- * &lt;span id="validator1" style="display:none; color:red"&gt;*&lt;/span&gt;
- * &lt;input type="submit text="submit" /&gt;
- * &lt;script type="text/javascript"&gt;
- * new Prado.ValidationManager({FormID : 'form1'});
- * var options =
- * {
- * ID : 'validator1',
- * FormID : 'form1',
- * ErrorMessage : '*',
- * ControlToValidate : 'input1'
- * }
- * new Prado.WebUI.TRequiredFieldValidator(options);
- * new Prado.WebUI.TValidationSummary({ID:'summary1',FormID:'form1'});
- *
- * //watch the form onsubmit event, check validators, stop if not valid.
- * Event.observe("form1", "submit" function(ev)
- * {
- * if(Prado.WebUI.Validation.isValid("form1") == false)
- * Event.stop(ev);
- * });
- * &lt;/script&gt;
- * &lt;/div&gt;
- * &lt;/form&gt;
- * </pre>
- *
- * @module validation
- */
-
-Prado.Validation = Class.create();
-
-/**
- * Global Validation Object.
- *
- * <p>To validate the inputs of a particular form, call
- * <code>{@link Prado.Validation.validate}(formID, groupID)</code>
- * where <tt>formID</tt> is the HTML form ID, and the optional
- * <tt>groupID</tt> if present will only validate the validators
- * in a particular group.</p>
- * <p>Use <code>{@link Prado.Validation.validateControl}(controlClientID)</code>
- * to trigger validation for a single control.</p>
- *
- * @object {static} Prado.Validation
- */
-Object.extend(Prado.Validation,
-{
- /**
- * Hash of registered validation managers
- * @var managers
- */
- managers : {},
-
- /**
- * Validate the validators (those that <strong>DO NOT</strong>
- * belong to a particular group) in the form specified by the
- * <tt>formID</tt> parameter. If <tt>groupID</tt> is specified
- * only validators belonging to that group will be validated.
- * @function {boolean} ?
- * @param {string} formID - ID of the form to validate
- * @param {string} groupID - ID of the ValidationGroup to validate.
- * @param {element} invoker - DOM element that calls for validation
- * @returns true if validation succeeded
- */
- validate : function(formID, groupID, invoker)
- {
- formID = formID || this.getForm();
- if(this.managers[formID])
- {
- return this.managers[formID].validate(groupID, invoker);
- }
- else
- {
- throw new Error("Form '"+formID+"' is not registered with Prado.Validation");
- }
- },
-
- /**
- * Validate all validators of a specific control.
- * @function {boolean} ?
- * @param {string} id - ID of DOM element to validate
- * @return true if all validators are valid or no validators present, false otherwise.
- */
- validateControl : function(id)
- {
- var formId=this.getForm();
-
- if (this.managers[formId])
- {
- return this.managers[formId].validateControl(id);
- } else {
- throw new Error("A validation manager needs to be created first.");
- }
- },
-
- /**
- * Return first registered form
- * @function {string} ?
- * @returns ID of first form.
- */
- getForm : function()
- {
- var keys = $H(this.managers).keys();
- return keys[0];
- },
-
- /**
- * Check if the validators are valid for a particular form (and group).
- * The validators states will not be changed.
- * The <tt>validate</tt> function should be called first.
- * @function {boolean} ?
- * @param {string} formID - ID of the form to validate
- * @param {string} groupID - ID of the ValiationGroup to validate.
- * @return true if form is valid
- */
- isValid : function(formID, groupID)
- {
- formID = formID || this.getForm();
- if(this.managers[formID])
- return this.managers[formID].isValid(groupID);
- return true;
- },
-
- /**
- * Reset the validators for a given group.
- * The group is searched in the first registered form.
- * @function ?
- * @param {string} groupID - ID of the ValidationGroup to reset.
- */
- reset : function(groupID)
- {
- var formID = this.getForm();
- if(this.managers[formID])
- this.managers[formID].reset(groupID);
- },
-
- /**
- * Add a new validator to a particular form.
- * @function {ValidationManager} ?
- * @param {string} formID - ID of the form that the validator belongs to.
- * @param {TBaseValidator} validator - Validator object
- * @return ValidationManager for the form
- */
- addValidator : function(formID, validator)
- {
- if(this.managers[formID])
- this.managers[formID].addValidator(validator);
- else
- throw new Error("A validation manager for form '"+formID+"' needs to be created first.");
- return this.managers[formID];
- },
-
- /**
- * Add a new validation summary.
- * @function {ValidationManager} ?
- * @param {string} formID - ID of the form that the validation summary belongs to.
- * @param {TValidationSummary} validator - TValidationSummary object
- * @return ValidationManager for the form
- */
- addSummary : function(formID, validator)
- {
- if(this.managers[formID])
- this.managers[formID].addSummary(validator);
- else
- throw new Error("A validation manager for form '"+formID+"' needs to be created first.");
- return this.managers[formID];
- },
-
- setErrorMessage : function(validatorID, message)
- {
- $H(Prado.Validation.managers).each(function(manager)
- {
- manager[1].validators.each(function(validator)
- {
- if(validator.options.ID == validatorID)
- {
- validator.options.ErrorMessage = message;
- $(validatorID).innerHTML = message;
- }
- });
- });
- },
-
- updateActiveCustomValidator : function(validatorID, isValid)
- {
- $H(Prado.Validation.managers).each(function(manager)
- {
- manager[1].validators.each(function(validator)
- {
- if(validator.options.ID == validatorID)
- {
- validator.updateIsValid(isValid);
- }
- });
- });
- }
-});
-
-/**
- * Manages validators for a particular HTML form.
- *
- * <p>The manager contains references to all the validators
- * summaries, and their groupings for a particular form.
- * Generally, {@link Prado.Validation} methods should be called rather
- * than calling directly the ValidationManager.</p>
- *
- * @class Prado.ValidationManager
- */
-Prado.ValidationManager = Class.create();
-Prado.ValidationManager.prototype =
-{
- /**
- * Hash of registered validators by control's clientID
- * @var controls
- */
- controls: {},
-
- /**
- * Initialize ValidationManager.
- * @constructor {protected} ?
- * @param {object} options - Options for initialization
- * @... {string} FormID - ID of form of this manager
- */
- initialize : function(options)
- {
- if(!Prado.Validation.managers[options.FormID])
- {
- /**
- * List of validators
- * @var {TBaseValidator[]} validators
- */
- this.validators = [];
- /**
- * List of validation summaries
- * @var {TValidationSummary[]} summaries
- */
- this.summaries = [];
- /**
- * List of ValidationGroups
- * @var {string[]} groups
- */
- this.groups = [];
- /**
- * Options of this ValidationManager
- * @var {object} options
- */
- this.options = {};
-
- this.options = options;
-
- Prado.Validation.managers[options.FormID] = this;
- }
- else
- {
- var manager = Prado.Validation.managers[options.FormID];
- this.validators = manager.validators;
- this.summaries = manager.summaries;
- this.groups = manager.groups;
- this.options = manager.options;
- }
- },
-
- /**
- * Reset all validators in the given group.
- * If group is null, validators without a group are used.
- * @function ?
- * @param {string} group - ID of ValidationGroup
- */
- reset : function(group)
- {
- this.validatorPartition(group)[0].invoke('reset');
- this.updateSummary(group, true);
- },
-
- /**
- * Validate the validators managed by this validation manager.
- * If group is set, only validate validators in that group.
- * @function {boolean} ?
- * @param {optional string} group - ID of ValidationGroup
- * @param {element} source - DOM element that calls for validation
- * @return true if all validators are valid, false otherwise.
- */
- validate : function(group, source)
- {
- var partition = this.validatorPartition(group);
- var valid = partition[0].invoke('validate', source).all();
- this.focusOnError(partition[0]);
- partition[1].invoke('hide');
- this.updateSummary(group, true);
- return valid;
- },
-
- /**
- * Perform validation for all validators of a single control.
- * @function {boolean} ?
- * @param {string} id - ID of DOM element to validate
- * @return true if all validators are valid or no validators present, false otherwise.
- */
- validateControl : function (id)
- {
- return this.controls[id] ? this.controls[id].invoke('validate',null).all() : true;
- },
-
- /**
- * Focus on the first validator that is invalid and options.FocusOnError is true.
- * @function ?
- * @param {TBaseValidator[]} validators - Array of validator objects
- */
- focusOnError : function(validators)
- {
- for(var i = 0; i < validators.length; i++)
- {
- if(!validators[i].isValid && validators[i].options.FocusOnError)
- return Prado.Element.focus(validators[i].options.FocusElementID);
- }
- },
-
- /**
- * Get all validators in a group and all other validators.
- * Returns an array with two arrays of validators. The first
- * array contains all validators in the group if group is given,
- * otherwhise all validators without a group. The second array
- * contains all other validators.
- * @function {[ TBaseValidator[] , TBaseValidator[] ]} ?
- * @param {optional string} group - ID of ValidationGroup
- * @return Array with two arrays of validators.
- */
- validatorPartition : function(group)
- {
- return group ? this.validatorsInGroup(group) : this.validatorsWithoutGroup();
- },
-
- /**
- * Get all validators in a group.
- * Returns an array with two arrays of validators. The first
- * array contains all validators in the group. The second array
- * contains all other validators.
- * @function {[ TBaseValidator[] , TBaseValidator[] ]} ?
- * @param {optional string} groupID - ID of ValidationGroup
- * @return Array with two arrays of validators.
- */
- validatorsInGroup : function(groupID)
- {
- if(this.groups.include(groupID))
- {
- return this.validators.partition(function(val)
- {
- return val.group == groupID;
- });
- }
- else
- return [[],[]];
- },
-
- /**
- * Get all validators without a group.
- * Returns an array with two arrays of validators. The first
- * array contains all validators without a group. The second
- * array contains all other validators.
- * @function {[ TBaseValidator[] , TBaseValidator[] ]} ?
- * @return Array with two arrays of validators: Array[0] has all
- * validators without a group, Array[1] all other validators.
- */
- validatorsWithoutGroup : function()
- {
- return this.validators.partition(function(val)
- {
- return !val.group;
- });
- },
-
- /**
- * Get the state of validators.
- * If group is set, only validators in that group are checked.
- * Otherwhise only validators without a group are checked.
- * @function {booelan} ?
- * @param {optional string} group - ID of ValidationGroup
- * @return true if all validators (in a group, if supplied) are valid.
- */
- isValid : function(group)
- {
- return this.validatorPartition(group)[0].pluck('isValid').all();
- },
-
- /**
- * Add a validator to this manager.
- * @function ?
- * @param {TBaseValidator} validator - Validator object
- */
- addValidator : function(validator)
- {
- // Remove previously registered validator with same ID
- // to prevent stale validators created by AJAX updates
- this.removeValidator(validator);
-
- this.validators.push(validator);
- if(validator.group && !this.groups.include(validator.group))
- this.groups.push(validator.group);
-
- if (typeof this.controls[validator.control.id] === 'undefined')
- this.controls[validator.control.id] = Array();
- this.controls[validator.control.id].push(validator);
- },
-
- /**
- * Add a validation summary.
- * @function ?
- * @param {TValidationSummary} summary - Validation summary.
- */
- addSummary : function(summary)
- {
- this.summaries.push(summary);
- },
-
- /**
- * Remove a validator from this manager
- * @function ?
- * @param {TBaseValidator} validator - Validator object
- */
- removeValidator : function(validator)
- {
- this.validators = this.validators.reject(function(v)
- {
- return (v.options.ID==validator.options.ID);
- });
- if (this.controls[validator.control.id])
- this.controls[validator.control.id].reject( function(v)
- {
- return (v.options.ID==validator.options.ID)
- });
- },
-
- /**
- * Gets validators with errors.
- * If group is set, only validators in that group are returned.
- * Otherwhise only validators without a group are returned.
- * @function {TBaseValidator[]} ?
- * @param {optional string} group - ID of ValidationGroup
- * @return array list of validators with error.
- */
- getValidatorsWithError : function(group)
- {
- return this.validatorPartition(group)[0].findAll(function(validator)
- {
- return !validator.isValid;
- });
- },
-
- /**
- * Update the summary of a particular group.
- * If group is set, only the summary for validators in that
- * group is updated. Otherwhise only the summary for validators
- * without a group is updated.
- * @function ?
- * @param {optional string} group - ID of ValidationGroup
- * @param {boolean} refresh - Wether the summary should be refreshed
- */
- updateSummary : function(group, refresh)
- {
- var validators = this.getValidatorsWithError(group);
- this.summaries.each(function(summary)
- {
- var inGroup = group && summary.group == group;
- var noGroup = !group || !summary.group;
- if(inGroup || noGroup)
- summary.updateSummary(validators, refresh);
- else
- summary.hideSummary(true);
- });
- }
-};
-
-/**
- * TValidationSummary displays a summary of validation errors.
- *
- * <p>The summary is displayed inline on a Web page,
- * in a message box, or both. By default, a validation summary will collect
- * <tt>ErrorMessage</tt> of all failed validators on the page. If
- * <tt>ValidationGroup</tt> is not empty, only those validators who belong
- * to the group will show their error messages in the summary.</p>
- *
- * <p>The summary can be displayed as a list, as a bulleted list, or as a single
- * paragraph based on the <tt>DisplayMode</tt> option.
- * The messages shown can be prefixed with <tt>HeaderText</tt>.</p>
- *
- * <p>The summary can be displayed on the Web page and in a message box by setting
- * the <tt>ShowSummary</tt> and <tt>ShowMessageBox</tt>
- * options, respectively.</p>
- *
- * @class Prado.WebUI.TValidationSummary
- */
-Prado.WebUI.TValidationSummary = Class.create();
-Prado.WebUI.TValidationSummary.prototype =
-{
- /**
- * Initialize TValidationSummary.
- * @constructor {protected} ?
- * @param {object} options - Options for initialization
- * @... {string} ID - ID of validation summary element
- * @... {string} FormID - ID of form of this manager
- * @... {optional string} ValidationGroup - ID of ValidationGroup.
- * @... {optional boolean} ShowMessageBox - true to show the summary in an alert box.
- * @... {optional boolean} ShowSummary - true to show the inline summary.
- * @... {optional string} HeaderText - Summary header text
- * @... {optional string} DisplayMode - Summary display style, 'BulletList', 'List', 'SingleParagraph'
- * @... {optional boolean} Refresh - true to update the summary upon validator state change.
- * @... {optional string} Display - Display mode, 'None', 'Fixed', 'Dynamic'.
- * @... {optional boolean} ScrollToSummary - true to scroll to the validation summary upon refresh.
- * @... {optional function} OnHideSummary - Called on hide event.
- * @... {optional function} OnShowSummary - Called on show event.
- */
- initialize : function(options)
- {
- /**
- * Validator options
- * @var {object} options
- */
- this.options = options;
- /**
- * ValidationGroup
- * @var {string} group
- */
- this.group = options.ValidationGroup;
- /**
- * Summary DOM element
- * @var {element} messages
- */
- this.messages = $(options.ID);
- Prado.Registry.set(options.ID, this);
- if(this.messages)
- {
- /**
- * Current visibility state of summary
- * @var {boolean} visible
- */
- this.visible = this.messages.style.visibility != "hidden"
- this.visible = this.visible && this.messages.style.display != "none";
- Prado.Validation.addSummary(options.FormID, this);
- }
- },
-
- /**
- * Update the validation summary.
- * @function ?
- * @param {TBaseValidator[]} validators - List of validators that failed validation.
- * @param {boolean} update - true if visible summary should be updated
- */
- updateSummary : function(validators, update)
- {
- if(validators.length <= 0)
- {
- if(update || this.options.Refresh != false)
- {
- return this.hideSummary(validators);
- }
- return;
- }
-
- var refresh = update || this.visible == false || this.options.Refresh != false;
- // Also, do not refresh summary if at least 1 validator is waiting for callback response.
- // This will avoid the flickering of summary if the validator passes its test
- refresh = refresh && validators.any(function(v) { return !v.requestDispatched; });
-
- if(this.options.ShowSummary != false && refresh)
- {
- this.updateHTMLMessages(this.getMessages(validators));
- this.showSummary(validators);
- }
-
- if(this.options.ScrollToSummary != false && refresh)
- window.scrollTo(this.messages.offsetLeft-20, this.messages.offsetTop-20);
-
- if(this.options.ShowMessageBox == true && refresh)
- {
- this.alertMessages(this.getMessages(validators));
- this.visible = true;
- }
- },
-
- /**
- * Display the validator error messages as inline HTML.
- * @function ?
- * @param {string[]} messages - Array of error messages.
- */
- updateHTMLMessages : function(messages)
- {
- while(this.messages.childNodes.length > 0)
- this.messages.removeChild(this.messages.lastChild);
- this.messages.insert(this.formatSummary(messages));
- },
-
- /**
- * Display the validator error messages as an alert box.
- * @function ?
- * @param {string[]} messages - Array of error messages.
- */
- alertMessages : function(messages)
- {
- var text = this.formatMessageBox(messages);
- setTimeout(function(){ alert(text); },20);
- },
-
- /**
- * Get messages from validators.
- * @function {string[]} ?
- * @param {TBaseValidator[]} validators - Array of validators.
- * @return Array of validator error messages.
- */
- getMessages : function(validators)
- {
- var messages = [];
- validators.each(function(validator)
- {
- var message = validator.getErrorMessage();
- if(typeof(message) == 'string' && message.length > 0)
- messages.push(message);
- })
- return messages;
- },
-
- /**
- * Hide the validation summary.
- * @function ?
- * @param {TBaseValidator[]} validators - Array of validators.
- */
- hideSummary : function(validators)
- { if(typeof(this.options.OnHideSummary) == "function")
- {
- this.messages.style.visibility="visible";
- this.options.OnHideSummary(this,validators)
- }
- else
- {
- this.messages.style.visibility="hidden";
- if(this.options.Display == "None" || this.options.Display == "Dynamic")
- this.messages.hide();
- }
- this.visible = false;
- },
-
- /**
- * Shows the validation summary.
- * @function ?
- * @param {TBaseValidator[]} validators - Array of validators.
- */
- showSummary : function(validators)
- {
- this.messages.style.visibility="visible";
- if(typeof(this.options.OnShowSummary) == "function")
- this.options.OnShowSummary(this,validators);
- else
- this.messages.show();
- this.visible = true;
- },
-
- /**
- * Return the format parameters for the summary.
- * @function {object} ?
- * @param {string} type - Format type: "List", "SingleParagraph", "HeaderOnly" or "BulletList" (default)
- * @return Object with format parameters:
- * @... {string} header - Text for header
- * @... {string} first - Text to prepend before message list
- * @... {string} pre - Text to prepend before each message
- * @... {string} post - Text to append after each message
- * @... {string} first - Text to append after message list
- */
- formats : function(type)
- {
- switch(type)
- {
- case "SimpleList":
- return { header : "<br />", first : "", pre : "", post : "<br />", last : ""};
- case "SingleParagraph":
- return { header : " ", first : "", pre : "", post : " ", last : "<br />"};
- case "HeaderOnly":
- return { header : "", first : "<!--", pre : "", post : "", last : "-->"};
- case "BulletList":
- default:
- return { header : "", first : "<ul>", pre : "<li>", post : "</li>", last : "</ul>"};
- }
- },
-
- /**
- * Format the message summary.
- * @function {string} ?
- * @param {string[]} messages - Array of error messages.
- * @return Formatted message
- */
- formatSummary : function(messages)
- {
- var format = this.formats(this.options.DisplayMode);
- var output = this.options.HeaderText ? this.options.HeaderText + format.header : "";
- output += format.first;
- messages.each(function(message)
- {
- output += message.length > 0 ? format.pre + message + format.post : "";
- });
-// for(var i = 0; i < messages.length; i++)
- // output += (messages[i].length>0) ? format.pre + messages[i] + format.post : "";
- output += format.last;
- return output;
- },
- /**
- * Format the message alert box.
- * @function {string} ?
- * @param {string[]} messages - Array of error messages.
- * @return Formatted message for alert
- */
- formatMessageBox : function(messages)
- {
- if(this.options.DisplayMode == 'HeaderOnly' && this.options.HeaderText)
- return this.options.HeaderText;
-
- var output = this.options.HeaderText ? this.options.HeaderText + "\n" : "";
- for(var i = 0; i < messages.length; i++)
- {
- switch(this.options.DisplayMode)
- {
- case "List":
- output += messages[i] + "\n";
- break;
- case "BulletList":
- default:
- output += " - " + messages[i] + "\n";
- break;
- case "SingleParagraph":
- output += messages[i] + " ";
- break;
- }
- }
- return output;
- }
-};
-
-/**
- * TBaseValidator serves as the base class for validator controls.
- *
- * <p>Validation is performed when a postback control, such as a TButton,
- * a TLinkButton or a TTextBox (under AutoPostBack mode) is submitting
- * the page and its <tt>CausesValidation</tt> option is true.
- * The input control to be validated is specified by <tt>ControlToValidate</tt>
- * option.</p>
- *
- * @class Prado.WebUI.TBaseValidator
- */
-Prado.WebUI.TBaseValidator = Class.create(Prado.WebUI.Control,
-{
- /**
- * Initialize TBaseValidator.
- * @constructor {protected} ?
- * @param {object} options - Options for initialization.
- * @... {string} ID - ID of validator
- * @... {string} FormID - ID of form of this manager.
- * @... {string} ControlToValidate - ID of control to validate.
- * @... {optional string} InitialValue - Initial value of control to validate.
- * @... {optional string} ErrorMessage - Validation error message.
- * @... {optional string} ValidationGroup - ID of ValidationGroup.
- * @... {optional string} Display - Display mode, 'None', 'Fixed', 'Dynamic'.
- * @... {optional boolean} ObserveChanges - True to observer changes of ControlToValidate
- * @... {optional boolean} FocusOnError - True to focus on validation error.
- * @... {optional string} FocusElementID - ID of element to focus on error.
- * @... {optional string} ControlCssClass - Css class to use on ControlToValidate on error
- * @... {optional function} OnValidate - Called immediately after validation.
- * @... {optional function} OnValidationSuccess - Called after successful validation.
- * @... {optional function} OnValidationError - Called after validation error.
- */
- initialize : function(options)
- {
- this.observers = new Array();
- this.intervals = new Array();
-
- /* options.OnValidate = options.OnValidate || Prototype.emptyFunction;
- options.OnSuccess = options.OnSuccess || Prototype.emptyFunction;
- options.OnError = options.OnError || Prototype.emptyFunction;
- */
- /**
- * Wether the validator is enabled (default true)
- * @var {boolean} enabled
- */
- this.enabled = options.Enabled;
- /**
- * Visibility state of validator(default false)
- * @var {boolean} visible
- */
- this.visible = false;
- /**
- * State of validation (default true)
- * @var {boolean} isValid
- */
- this.isValid = true;
- /**
- * DOM elements that are observed by this validator
- * @var {private element[]} _isObserving
- */
- this._isObserving = {};
- /**
- * ValidationGroup
- * @var {string} group
- */
- this.group = null;
- /**
- * Wether a request was dispatched (default false)
- * @var {boolean} requestDispatched
- */
- this.requestDispatched = false;
-
- /**
- * Validator options
- * @var {object} options
- */
- this.options = options;
- /**
- * DOM element of control to validate
- * @var {element} control
- */
- this.control = $(options.ControlToValidate);
- /**
- * DOM element of validator
- * @var {element} message
- */
- this.message = $(options.ID);
-
- Prado.Registry.set(options.ID, this);
-
- if (this.onInit) this.onInit();
-
- if(this.control && this.message)
- {
- this.group = options.ValidationGroup;
-
- /**
- * ValidationManager of this validator
- * @var {ValidationManager} manager
- */
- this.manager = Prado.Validation.addValidator(options.FormID, this);
- }
- },
-
- /**
- * Get error message.
- * @function {string} ?
- * @return Validation error message.
- */
- getErrorMessage : function()
- {
- return this.options.ErrorMessage;
- },
-
- /**
- * Update the validator.
- * Updating the validator control will set the validator
- * <tt>visible</tt> property to true.
- * @function ?
- */
- updateControl: function()
- {
- this.refreshControlAndMessage();
-
- //if(this.options.FocusOnError && !this.isValid )
- // Prado.Element.focus(this.options.FocusElementID);
-
- this.visible = true;
- },
-
- /**
- * Updates span and input CSS class.
- * @function ?
- */
- refreshControlAndMessage : function()
- {
- this.visible = true;
- if(this.message)
- {
- if(this.options.Display == "Dynamic")
- {
- var msg=this.message;
- this.isValid ? setTimeout(function() { msg.hide(); }, 250) : msg.show();
- }
- this.message.style.visibility = this.isValid ? "hidden" : "visible";
- }
- if(this.control)
- this.updateControlCssClass(this.control, this.isValid);
- },
-
- /**
- * Update CSS class of control to validate.
- * Add a css class to the input control if validator is invalid,
- * removes the css class if valid.
- * @function ?
- * @param {element} control - DOM element of control to validate
- * @param {boolean} valid - Validation state of control
- */
- updateControlCssClass : function(control, valid)
- {
- var CssClass = this.options.ControlCssClass;
- if(typeof(CssClass) == "string" && CssClass.length > 0)
- {
- if(valid)
- {
- if (control.lastValidator == this.options.ID)
- {
- control.lastValidator = null;
- control.removeClassName(CssClass);
- }
- }
- else
- {
- control.lastValidator = this.options.ID;
- control.addClassName(CssClass);
- }
- }
- },
-
- /**
- * Hide the validator messages and remove any validation changes.
- * @function ?
- */
- hide : function()
- {
- this.reset();
- this.visible = false;
- },
-
- /**
- * Reset validator.
- * Sets isValid = true and updates the validator display.
- * @function ?
- */
- reset : function()
- {
- this.isValid = true;
- this.updateControl();
- },
-
- /**
- * Perform validation.
- * Calls evaluateIsValid() function to set the value of isValid property.
- * Triggers onValidate event and onSuccess or onError event.
- * @function {boolean} ?
- * @param {element} invoker - DOM element that triggered validation
- * @return Valdation state of control.
- */
- validate : function(invoker)
- {
- //try to find the control.
- if(!this.control)
- this.control = $(this.options.ControlToValidate);
-
- if(!this.control || this.control.disabled)
- {
- this.isValid = true;
- return this.isValid;
- }
-
- if(typeof(this.options.OnValidate) == "function")
- {
- if(this.requestDispatched == false)
- this.options.OnValidate(this, invoker);
- }
-
- if(this.enabled && !this.control.getAttribute('disabled'))
- this.isValid = this.evaluateIsValid();
- else
- this.isValid = true;
-
- this.updateValidationDisplay(invoker);
- this.observeChanges(this.control);
-
- return this.isValid;
- },
-
- /**
- * Update validation display.
- * Updates the validation messages and the control to validate.
- * @param {element} invoker - DOM element that triggered validation
- */
- updateValidationDisplay : function(invoker)
- {
- if(this.isValid)
- {
- if(typeof(this.options.OnValidationSuccess) == "function")
- {
- if(this.requestDispatched == false)
- {
- this.refreshControlAndMessage();
- this.options.OnValidationSuccess(this, invoker);
- }
- }
- else
- this.updateControl();
- }
- else
- {
- if(typeof(this.options.OnValidationError) == "function")
- {
- if(this.requestDispatched == false)
- {
- this.refreshControlAndMessage();
- this.options.OnValidationError(this, invoker)
- }
- }
- else
- this.updateControl();
- }
- },
-
- /**
- * Add control to observe for changes.
- * Re-validates upon change. If the validator is not visible,
- * no updates are propagated.
- * @function ?
- * @param {element} control - DOM element of control to observe
- */
- observeChanges : function(control)
- {
- if(!control) return;
-
- var canObserveChanges = this.options.ObserveChanges != false;
- var currentlyObserving = this._isObserving[control.id+this.options.ID];
-
- if(canObserveChanges && !currentlyObserving)
- {
- var validator = this;
-
- this.observe(control, 'change', function()
- {
- if(validator.visible)
- {
- validator.validate();
- validator.manager.updateSummary(validator.group);
- }
- });
- this._isObserving[control.id+this.options.ID] = true;
- }
- },
-
- /**
- * Trim a string.
- * @function {string} ?
- * @param {string} value - String that should be trimmed.
- * @return Trimmed string, empty string if value is not string.
- */
- trim : function(value)
- {
- return typeof(value) == "string" ? value.trim() : "";
- },
-
- /**
- * Convert the value to a specific data type.
- * @function {mixed|null} ?
- * @param {string} dataType - Data type: "Integer", "Double", "Date" or "String"
- * @param {mixed} value - Value to convert.
- * @return Converted data value.
- */
- convert : function(dataType, value)
- {
- if(typeof(value) == "undefined")
- value = this.getValidationValue();
- var string = new String(value);
- switch(dataType)
- {
- case "Integer":
- return string.toInteger();
- case "Double" :
- case "Float" :
- return string.toDouble(this.options.DecimalChar);
- case "Date":
- if(typeof(value) != "string")
- return value;
- else
- {
- var value = string.toDate(this.options.DateFormat);
- if(value && typeof(value.getTime) == "function")
- return value.getTime();
- else
- return null;
- }
- case "String":
- return string.toString();
- }
- return value;
- },
-
- /**
- * Get value that should be validated.
- * The ControlType property comes from TBaseValidator::getClientControlClass()
- * Be sure to update the TBaseValidator::$_clientClass if new cases are added.
- * @function {mixed} ?
- * @param {optional element} control - Control to get value from (default: this.control)
- * @return Control value to validate
- */
- getRawValidationValue : function(control)
- {
- if(!control)
- control = this.control
- switch(this.options.ControlType)
- {
- case 'TDatePicker':
- if(control.type == "text")
- {
- var value = this.trim($F(control));
-
- if(this.options.DateFormat)
- {
- var date = value.toDate(this.options.DateFormat);
- return date == null ? value : date;
- }
- else
- return value;
- }
- else
- {
- this.observeDatePickerChanges();
-
- return Prado.WebUI.TDatePicker.getDropDownDate(control);//.getTime();
- }
- case 'THtmlArea':
- if(typeof tinyMCE != "undefined")
- tinyMCE.triggerSave();
- return $F(control);
- case 'TRadioButton':
- if(this.options.GroupName)
- return this.getRadioButtonGroupValue();
- default:
- if(this.isListControlType())
- return this.getFirstSelectedListValue();
- else
- return $F(control);
- }
- },
-
- /**
- * Get a trimmed value that should be validated.
- * The ControlType property comes from TBaseValidator::getClientControlClass()
- * Be sure to update the TBaseValidator::$_clientClass if new cases are added.
- * @function {mixed} ?
- * @param {optional element} control - Control to get value fron (default: this.control)
- * @return Control value to validate
- */
- getValidationValue : function(control)
- {
- var value = this.getRawValidationValue(control);
- if(!control)
- control = this.control
- switch(this.options.ControlType)
- {
- case 'TDatePicker':
- return value;
- case 'THtmlArea':
- return this.trim(value);
- case 'TRadioButton':
- return value;
- default:
- if(this.isListControlType())
- return value;
- else
- return this.trim(value);
- }
- },
-
- /**
- * Get value of radio button group
- * @function {string} ?
- * @return Value of a radio button group
- */
- getRadioButtonGroupValue : function()
- {
- var name = this.control.name;
- var value = "";
- $A(document.getElementsByName(name)).each(function(el)
- {
- if(el.checked)
- value = el.value;
- });
- return value;
- },
-
- /**
- * Observe changes in the drop down list date picker, IE only.
- * @function ?
- */
- observeDatePickerChanges : function()
- {
- if(Prado.Browser().ie)
- {
- var DatePicker = Prado.WebUI.TDatePicker;
- this.observeChanges(DatePicker.getDayListControl(this.control));
- this.observeChanges(DatePicker.getMonthListControl(this.control));
- this.observeChanges(DatePicker.getYearListControl(this.control));
- }
- },
-
- /**
- * Gets number of selections and their values.
- * @function {object} ?
- * @param {element[]} elements - Elements to get values from.
- * @param {string} initialValue - Initial value of element
- * @return Object:
- * @... {mixed[]} values - Array of selected values
- * @... {int} checks - Number of selections
- */
- getSelectedValuesAndChecks : function(elements, initialValue)
- {
- var checked = 0;
- var values = [];
- var isSelected = this.isCheckBoxType(elements[0]) ? 'checked' : 'selected';
- elements.each(function(element)
- {
- if(element[isSelected] && element.value != initialValue)
- {
- checked++;
- values.push(element.value);
- }
- });
- return {'checks' : checked, 'values' : values};
- },
-
- /**
- * Get list elements of TCheckBoxList or TListBox.
- * Gets an array of the list control item input elements, for TCheckBoxList
- * checkbox input elements are returned, for TListBox HTML option elements
- * are returned.
- * @function {element[]} ?
- * @return Array of list control option DOM elements.
- */
- getListElements : function()
- {
- switch(this.options.ControlType)
- {
- case 'TCheckBoxList': case 'TRadioButtonList':
- var elements = [];
- for(var i = 0; i < this.options.TotalItems; i++)
- {
- var element = $(this.options.ControlToValidate+"_c"+i);
- if(this.isCheckBoxType(element))
- elements.push(element);
- }
- return elements;
- case 'TListBox':
- var elements = [];
- var element = $(this.options.ControlToValidate);
- var type;
- if(element && (type = element.type.toLowerCase()))
- {
- if(type == "select-one" || type == "select-multiple")
- elements = $A(element.options);
- }
- return elements;
- default:
- return [];
- }
- },
-
- /**
- * Check if control is of type checkbox or radio.
- * @function {boolean} ?
- * @param {element} element - DOM element to check.
- * @return True if element is of checkbox or radio type.
- */
- isCheckBoxType : function(element)
- {
- if(element && element.type)
- {
- var type = element.type.toLowerCase();
- return type == "checkbox" || type == "radio";
- }
- return false;
- },
-
- /**
- * Check if control to validate is a TListControl type.
- * @function {boolean} ?
- * @return True if control to validate is a TListControl type.
- */
- isListControlType : function()
- {
- var list = ['TCheckBoxList', 'TRadioButtonList', 'TListBox'];
- return list.include(this.options.ControlType);
- },
-
- /**
- * Get first selected list value or initial value if none found.
- * @function {string} ?
- * @return First selected list value, initial value if none found.
- */
- getFirstSelectedListValue : function()
- {
- var initial = "";
- if(typeof(this.options.InitialValue) != "undefined")
- initial = this.options.InitialValue;
- var elements = this.getListElements();
- var selection = this.getSelectedValuesAndChecks(elements, initial);
- return selection.values.length > 0 ? selection.values[0] : initial;
- }
-});
-
-
-/**
- * TRequiredFieldValidator makes the associated input control a required field.
- *
- * <p>The input control fails validation if its value does not change from
- * the <tt>InitialValue</tt> option upon losing focus.</p>
- *
- * @class Prado.WebUI.TRequiredFieldValidator
- * @extends Prado.WebUI.TBaseValidator
- */
-Prado.WebUI.TRequiredFieldValidator = Class.extend(Prado.WebUI.TBaseValidator,
-{
- /**
- * Evaluate validation state
- * @function {boolean} ?
- * @return True if the input value is not empty nor equal to the initial value.
- */
- evaluateIsValid : function()
- {
- var a = this.getValidationValue();
- var b = this.trim(this.options.InitialValue);
- return(a != b);
- }
-});
-
-
-/**
- * TCompareValidator compares the value entered by the user into an input
- * control with the value entered into another input control or a constant value.
- *
- * <p>To compare the associated input control with another input control,
- * set the <tt>ControlToCompare</tt> option to the ID path
- * of the control to compare with. To compare the associated input control with
- * a constant value, specify the constant value to compare with by setting the
- * <tt>ValueToCompare</tt> option.</p>
- *
- * <p>The <tt>DataType</tt> property is used to specify the data type
- * of both comparison values. Both values are automatically converted to this data
- * type before the comparison operation is performed. The following value types are supported:
- * - <b>Integer</b> A 32-bit signed integer data type.
- * - <b>Float</b> A double-precision floating point number data type.
- * - <b>Date</b> A date data type. The format can be set by the <tt>DateFormat</tt> option.
- * - <b>String</b> A string data type.</p>
- *
- * Use the <tt>Operator</tt> property to specify the type of comparison
- * to perform. Valid operators include Equal, NotEqual, GreaterThan, GreaterThanEqual,
- * LessThan and LessThanEqual.
- *
- * @class Prado.WebUI.TCompareValidator
- * @extends Prado.WebUI.TBaseValidator
- */
-Prado.WebUI.TCompareValidator = Class.extend(Prado.WebUI.TBaseValidator,
-{
- /**
- * Additional constructor options.
- * @constructor initialize
- * @param {object} options - Additional constructor options:
- * @... {string} ControlToCompare - Control with compare value.
- * @... {string} ValueToCompare - Value to compare.
- * @... {string} Operator - Type of comparison: "Equal", "NotEqual", "GreaterThan",
- * "GreaterThanEqual", "LessThan" or "LessThanEqual".
- * @... {string} Type - Type of values: "Integer", "Float", "Date" or "String".
- * @... {string} DateFormat - Valid date format.
- */
-
- //_observingComparee : false,
-
- /**
- * Evaluate validation state
- * @function {boolean} ?
- * @return True if comparision condition is met.
- */
- evaluateIsValid : function()
- {
- var value = this.getValidationValue();
- if (value.length <= 0)
- return true;
-
- var comparee = $(this.options.ControlToCompare);
-
- if(comparee)
- var compareTo = this.getValidationValue(comparee);
- else
- var compareTo = this.options.ValueToCompare || "";
-
- var isValid = this.compare(value, compareTo);
-
- if(comparee)
- {
- this.updateControlCssClass(comparee, isValid);
- this.observeChanges(comparee);
- }
- return isValid;
- },
-
- /**
- * Compare two operands.
- * The operand values are casted to type defined
- * by <tt>DataType</tt> option. False is returned if the first
- * operand converts to null. Returns true if the second operand
- * converts to null. The comparision is done based on the
- * <tt>Operator</tt> option.
- * @function ?
- * @param {mixed} operand1 - First operand.
- * @param {mixed} operand2 - Second operand.
- */
- compare : function(operand1, operand2)
- {
- var op1, op2;
- if((op1 = this.convert(this.options.DataType, operand1)) == null)
- return false;
- if ((op2 = this.convert(this.options.DataType, operand2)) == null)
- return true;
- switch (this.options.Operator)
- {
- case "NotEqual":
- return (op1 != op2);
- case "GreaterThan":
- return (op1 > op2);
- case "GreaterThanEqual":
- return (op1 >= op2);
- case "LessThan":
- return (op1 < op2);
- case "LessThanEqual":
- return (op1 <= op2);
- default:
- return (op1 == op2);
- }
- }
-});
-
-/**
- * TCustomValidator performs user-defined client-side validation on an
- * input component.
- *
- * <p>To create a client-side validation function, add the client-side
- * validation javascript function to the page template.
- * The function should have the following signature:</p>
- *
- * <pre>
- * &lt;script type="text/javascript"&gt;
- * function ValidationFunctionName(sender, parameter)
- * {
- * if(parameter == ...)
- * return true;
- * else
- * return false;
- * }
- * &lt;/script&gt;
- * </pre>
- *
- * <p>Use the <tt>ClientValidationFunction</tt> option
- * to specify the name of the client-side validation script function associated
- * with the TCustomValidator.</p>
- *
- * @class Prado.WebUI.TCustomValidator
- * @extends Prado.WebUI.TBaseValidator
- */
-Prado.WebUI.TCustomValidator = Class.extend(Prado.WebUI.TBaseValidator,
-{
- /**
- * Additional constructor options.
- * @constructor initialize
- * @param {object} options - Additional constructor options:
- * @... {function} ClientValidationFunction - Custom validation function.
- */
-
- /**
- * Evaluate validation state
- * Returns true if no valid custom validation function is present.
- * @function {boolean} ?
- * @return True if custom validation returned true.
- */
- evaluateIsValid : function()
- {
- var value = this.getValidationValue();
- var clientFunction = this.options.ClientValidationFunction;
- if(typeof(clientFunction) == "string" && clientFunction.length > 0)
- {
- var validate = clientFunction.toFunction();
- return validate(this, value);
- }
- return true;
- }
-});
-
-/**
- * Uses callback request to perform validation.
- *
- * @class Prado.WebUI.TActiveCustomValidator
- * @extends Prado.WebUI.TBaseValidator
- */
-Prado.WebUI.TActiveCustomValidator = Class.extend(Prado.WebUI.TBaseValidator,
-{
- /**
- * Override the parent implementation to store the invoker, in order to
- * re-validate after the callback has returned
- * Calls evaluateIsValid() function to set the value of isValid property.
- * Triggers onValidate event and onSuccess or onError event.
- * @function {boolean} ?
- * @param {element} invoker - DOM element that triggered validation
- * @return True if valid.
- */
- validate : function(invoker)
- {
- this.invoker = invoker;
-
- //try to find the control.
- if(!this.control)
- this.control = $(this.options.ControlToValidate);
-
- if(!this.control || this.control.disabled)
- {
- this.isValid = true;
- return this.isValid;
- }
-
- if(typeof(this.options.OnValidate) == "function")
- {
- if(this.requestDispatched == false)
- this.options.OnValidate(this, invoker);
- }
-
- return true;
- },
-
- /**
- * Send CallBack to start serverside validation.
- * @function {boolean} ?
- * @return True if valid.
- */
- evaluateIsValid : function()
- {
- return this.isValid;
- },
-
- /**
- * Parse CallBack response data on success.
- * @function ?
- * @param {CallbackRequest} request - CallbackRequest.
- * @param {string} data - Response data.
- */
- updateIsValid : function(data)
- {
- this.isValid = data;
- this.requestDispatched = false;
- if(typeof(this.options.onSuccess) == "function")
- this.options.onSuccess(null,data);
- this.updateValidationDisplay();
- this.manager.updateSummary(this.group);
- }
-});
-
-/**
- * TRangeValidator tests whether an input value is within a specified range.
- *
- * <p>TRangeValidator uses three key properties to perform its validation.</p>
- *
- * <p>The <tt>MinValue</tt> and <tt>MaxValue</tt> options specify the minimum
- * and maximum values of the valid range.</p>
- * <p>The <tt>DataType</tt> option is
- * used to specify the data type of the value and the minimum and maximum range values.
- * The values are converted to this data type before the validation
- * operation is performed. The following value types are supported:</p>
- *
- * - <b>Integer</b> A 32-bit signed integer data type.<br />
- * - <b>Float</b> A double-precision floating point number data type.<br />
- * - <b>Date</b> A date data type. The date format can be specified by<br />
- * setting <tt>DateFormat</tt> option, which must be recognizable
- * by <tt>Date.SimpleParse</tt> javascript function.
- * - <b>String</b> A string data type.
- *
- * @class Prado.WebUI.TRangeValidator
- * @extends Prado.WebUI.TBaseValidator
- */
-Prado.WebUI.TRangeValidator = Class.extend(Prado.WebUI.TBaseValidator,
-{
- /**
- * Additional constructor options.
- * @constructor initialize
- * @param {object} options - Additional constructor options:
- * @... {string} MinValue - Minimum range value
- * @... {string} MaxValue - Maximum range value
- * @... {string} DataType - Value data type: "Integer", "Float", "Date" or "String"
- * @... {string} DateFormat - Date format for data type Date.
- */
-
- /**
- * Evaluate validation state
- * @function {boolean} ?
- * @return True if value is in range or value is empty,
- * false otherwhise and when type conversion failed.
- */
- evaluateIsValid : function()
- {
- var value = this.getValidationValue();
- if(value.length <= 0)
- return true;
- if(typeof(this.options.DataType) == "undefined")
- this.options.DataType = "String";
-
- if(this.options.DataType != "StringLength")
- {
- var min = this.convert(this.options.DataType, this.options.MinValue || null);
- var max = this.convert(this.options.DataType, this.options.MaxValue || null);
- value = this.convert(this.options.DataType, value);
- }
- else
- {
- var min = this.options.MinValue || 0;
- var max = this.options.MaxValue || Number.POSITIVE_INFINITY;
- value = value.length;
- }
-
- if(value == null)
- return false;
-
- var valid = true;
-
- if(min != null)
- valid = valid && (this.options.StrictComparison ? value > min : value >= min);
- if(max != null)
- valid = valid && (this.options.StrictComparison ? value < max : value <= max);
- return valid;
- }
-});
-
-/**
- * TRegularExpressionValidator validates whether the value of an associated
- * input component matches the pattern specified by a regular expression.
- *
- * @class Prado.WebUI.TRegularExpressionValidator
- * @extends Prado.WebUI.TBaseValidator
- */
-Prado.WebUI.TRegularExpressionValidator = Class.extend(Prado.WebUI.TBaseValidator,
-{
- /**
- * Additional constructor option.
- * @constructor initialize
- * @param {object} options - Additional constructor option:
- * @... {string} ValidationExpression - Regular expression to match against.
- * @... {string} PatternModifiers - Pattern modifiers: combinations of g, i, and m
- */
-
- /**
- * Evaluate validation state
- * @function {boolean} ?
- * @return True if value matches regular expression or value is empty.
- */
- evaluateIsValid : function()
- {
- var value = this.getRawValidationValue();
- if (value.length <= 0)
- return true;
-
- var rx = new RegExp('^'+this.options.ValidationExpression+'$',this.options.PatternModifiers);
- var matches = rx.exec(value);
- return (matches != null && value == matches[0]);
- }
-});
-
-/**
- * TEmailAddressValidator validates whether the value of an associated
- * input component is a valid email address.
- *
- * @class Prado.WebUI.TEmailAddressValidator
- * @extends Prado.WebUI.TRegularExpressionValidator
- */
-Prado.WebUI.TEmailAddressValidator = Prado.WebUI.TRegularExpressionValidator;
-
-
-/**
- * TListControlValidator checks the number of selection and their values
- * for a TListControl that allows multiple selections.
- *
- * @class Prado.WebUI.TListControlValidator
- * @extends Prado.WebUI.TBaseValidator
- */
-Prado.WebUI.TListControlValidator = Class.extend(Prado.WebUI.TBaseValidator,
-{
- /**
- * Evaluate validation state
- * @function {boolean} ?
- * @return True if number of selections and/or their values match requirements.
- */
- evaluateIsValid : function()
- {
- var elements = this.getListElements();
- if(elements && elements.length <= 0)
- return true;
-
- this.observeListElements(elements);
-
- var selection = this.getSelectedValuesAndChecks(elements);
- return this.isValidList(selection.checks, selection.values);
- },
-
- /**
- * Observe list elements for of changes (only IE)
- * @function ?
- * @param {element[]} elements - Array of DOM elements to observe
- */
- observeListElements : function(elements)
- {
- if(Prado.Browser().ie && this.isCheckBoxType(elements[0]))
- {
- var validator = this;
- elements.each(function(element)
- {
- validator.observeChanges(element);
- });
- }
- },
-
- /**
- * Check if list is valid.
- * Determine if the number of checked values and the checked values
- * satisfy the required number of checks and/or the checked values
- * equal to the required values.
- * @function {boolean} ?
- * @param {int} checked - Number of required checked values
- * @param {string[]} values - Array of required checked values
- * @return True if checked values and number of checks are satisfied.
- */
- isValidList : function(checked, values)
- {
- var exists = true;
-
- //check the required values
- var required = this.getRequiredValues();
- if(required.length > 0)
- {
- if(values.length < required.length)
- return false;
- required.each(function(requiredValue)
- {
- exists = exists && values.include(requiredValue);
- });
- }
-
- var min = typeof(this.options.Min) == "undefined" ?
- Number.NEGATIVE_INFINITY : this.options.Min;
- var max = typeof(this.options.Max) == "undefined" ?
- Number.POSITIVE_INFINITY : this.options.Max;
- return exists && checked >= min && checked <= max;
- },
-
- /**
- * Get list of required values.
- * @function {string[]} ?
- * @return Array of required values that must be selected.
- */
- getRequiredValues : function()
- {
- var required = [];
- if(this.options.Required && this.options.Required.length > 0)
- required = this.options.Required.split(/,\s*/);
- return required;
- }
-});
-
-
-/**
- * TDataTypeValidator verifies if the input data is of the type specified
- * by <tt>DataType</tt> option.
- *
- * <p>The following data types are supported:</p>
- *
- * - <b>Integer</b> A 32-bit signed integer data type.<br />
- * - <b>Float</b> A double-precision floating point number data type.<br />
- * - <b>Date</b> A date data type.<br />
- * - <b>String</b> A string data type.<br />
- *
- * <p>For <b>Date</b> type, the option <tt>DateFormat</tt>
- * will be used to determine how to parse the date string.</p>
- *
- * @class Prado.WebUI.TDataTypeValidator
- * @extends Prado.WebUI.TBaseValidator
- */
-Prado.WebUI.TDataTypeValidator = Class.extend(Prado.WebUI.TBaseValidator,
-{
- /**
- * Additional constructor option.
- * @constructor initialize
- * @param {object} options - Additional constructor option:
- * @... {string} DataType - Value data type: "Integer", "Float", "Date" or "String"
- * @... {string} DateFormat - Date format for data type Date.
- */
-
- /**
- * Evaluate validation state
- * @function {boolean} ?
- * @return True if value matches required data type.
- */
- evaluateIsValid : function()
- {
- var value = this.getValidationValue();
- if(value.length <= 0)
- return true;
- return this.convert(this.options.DataType, value) != null;
- }
-});
-
-/**
- * TCaptchaValidator verifies if the input data is the same as
- * the token shown in the associated CAPTCHA control.
- *
- * @class Prado.WebUI.TCaptchaValidator
- * @extends Prado.WebUI.TBaseValidator
- */
-Prado.WebUI.TCaptchaValidator = Class.extend(Prado.WebUI.TBaseValidator,
-{
- /**
- * Evaluate validation state
- * @function {boolean} ?
- * @return True if value matches captcha text
- */
- evaluateIsValid : function()
- {
- var a = this.getValidationValue();
- var h = 0;
- if (this.options.CaseSensitive==false)
- a = a.toUpperCase();
- for(var i = a.length-1; i >= 0; --i)
- h += a.charCodeAt(i);
- return h == this.options.TokenHash;
- },
-
- crc32 : function(str)
- {
- function Utf8Encode(string)
- {
- string = string.replace(/\r\n/g,"\n");
- var utftext = "";
-
- for (var n = 0; n < string.length; n++)
- {
- var c = string.charCodeAt(n);
-
- if (c < 128) {
- utftext += String.fromCharCode(c);
- }
- else if((c > 127) && (c < 2048)) {
- utftext += String.fromCharCode((c >> 6) | 192);
- utftext += String.fromCharCode((c & 63) | 128);
- }
- else {
- utftext += String.fromCharCode((c >> 12) | 224);
- utftext += String.fromCharCode(((c >> 6) & 63) | 128);
- utftext += String.fromCharCode((c & 63) | 128);
- }
- }
-
- return utftext;
- };
-
- str = Utf8Encode(str);
-
- var table = "00000000 77073096 EE0E612C 990951BA 076DC419 706AF48F E963A535 9E6495A3 0EDB8832 79DCB8A4 E0D5E91E 97D2D988 09B64C2B 7EB17CBD E7B82D07 90BF1D91 1DB71064 6AB020F2 F3B97148 84BE41DE 1ADAD47D 6DDDE4EB F4D4B551 83D385C7 136C9856 646BA8C0 FD62F97A 8A65C9EC 14015C4F 63066CD9 FA0F3D63 8D080DF5 3B6E20C8 4C69105E D56041E4 A2677172 3C03E4D1 4B04D447 D20D85FD A50AB56B 35B5A8FA 42B2986C DBBBC9D6 ACBCF940 32D86CE3 45DF5C75 DCD60DCF ABD13D59 26D930AC 51DE003A C8D75180 BFD06116 21B4F4B5 56B3C423 CFBA9599 B8BDA50F 2802B89E 5F058808 C60CD9B2 B10BE924 2F6F7C87 58684C11 C1611DAB B6662D3D 76DC4190 01DB7106 98D220BC EFD5102A 71B18589 06B6B51F 9FBFE4A5 E8B8D433 7807C9A2 0F00F934 9609A88E E10E9818 7F6A0DBB 086D3D2D 91646C97 E6635C01 6B6B51F4 1C6C6162 856530D8 F262004E 6C0695ED 1B01A57B 8208F4C1 F50FC457 65B0D9C6 12B7E950 8BBEB8EA FCB9887C 62DD1DDF 15DA2D49 8CD37CF3 FBD44C65 4DB26158 3AB551CE A3BC0074 D4BB30E2 4ADFA541 3DD895D7 A4D1C46D D3D6F4FB 4369E96A 346ED9FC AD678846 DA60B8D0 44042D73 33031DE5 AA0A4C5F DD0D7CC9 5005713C 270241AA BE0B1010 C90C2086 5768B525 206F85B3 B966D409 CE61E49F 5EDEF90E 29D9C998 B0D09822 C7D7A8B4 59B33D17 2EB40D81 B7BD5C3B C0BA6CAD EDB88320 9ABFB3B6 03B6E20C 74B1D29A EAD54739 9DD277AF 04DB2615 73DC1683 E3630B12 94643B84 0D6D6A3E 7A6A5AA8 E40ECF0B 9309FF9D 0A00AE27 7D079EB1 F00F9344 8708A3D2 1E01F268 6906C2FE F762575D 806567CB 196C3671 6E6B06E7 FED41B76 89D32BE0 10DA7A5A 67DD4ACC F9B9DF6F 8EBEEFF9 17B7BE43 60B08ED5 D6D6A3E8 A1D1937E 38D8C2C4 4FDFF252 D1BB67F1 A6BC5767 3FB506DD 48B2364B D80D2BDA AF0A1B4C 36034AF6 41047A60 DF60EFC3 A867DF55 316E8EEF 4669BE79 CB61B38C BC66831A 256FD2A0 5268E236 CC0C7795 BB0B4703 220216B9 5505262F C5BA3BBE B2BD0B28 2BB45A92 5CB36A04 C2D7FFA7 B5D0CF31 2CD99E8B 5BDEAE1D 9B64C2B0 EC63F226 756AA39C 026D930A 9C0906A9 EB0E363F 72076785 05005713 95BF4A82 E2B87A14 7BB12BAE 0CB61B38 92D28E9B E5D5BE0D 7CDCEFB7 0BDBDF21 86D3D2D4 F1D4E242 68DDB3F8 1FDA836E 81BE16CD F6B9265B 6FB077E1 18B74777 88085AE6 FF0F6A70 66063BCA 11010B5C 8F659EFF F862AE69 616BFFD3 166CCF45 A00AE278 D70DD2EE 4E048354 3903B3C2 A7672661 D06016F7 4969474D 3E6E77DB AED16A4A D9D65ADC 40DF0B66 37D83BF0 A9BCAE53 DEBB9EC5 47B2CF7F 30B5FFE9 BDBDF21C CABAC28A 53B39330 24B4A3A6 BAD03605 CDD70693 54DE5729 23D967BF B3667A2E C4614AB8 5D681B02 2A6F2B94 B40BBE37 C30C8EA1 5A05DF1B 2D02EF8D";
- var crc = 0;
- var x = 0;
- var y = 0;
-
- crc = crc ^ (-1);
- for( var i = 0, iTop = str.length; i < iTop; i++ )
- {
- y = ( crc ^ str.charCodeAt( i ) ) & 0xFF;
- x = "0x" + table.substr( y * 9, 8 );
- crc = ( crc >>> 8 ) ^ x;
- }
- return crc ^ (-1);
- }
-});
-
-
-/**
- * TReCaptchaValidator client-side control.
- *
- * @class Prado.WebUI.TReCaptchaValidator
- * @extends Prado.WebUI.TBaseValidator
- */
-Prado.WebUI.TReCaptchaValidator = Class.create(Prado.WebUI.TBaseValidator,
-{
- onInit : function()
- {
- var obj = this;
- var elements = document.getElementsByName(this.options.ResponseFieldName);
- if (elements)
- if (elements.length>=1)
- {
- this.observe(elements[0],'change',function() { obj.responseChanged() });
- this.observe(elements[0],'keydown',function() { obj.responseChanged() });
- }
- },
-
- responseChanged: function()
- {
- var field = $(this.options.ID+'_1');
- if (field.value=='1') return;
- field.value = '1';
- Prado.Validation.validateControl(this.options.ID);
- },
-
- /**
- * Evaluate validation state
- * @function {boolean} ?
- * @return True if the captcha has validate, False otherwise.
- */
- evaluateIsValid : function()
- {
- return ($(this.options.ID+'_1').value=='1');
- }
-});
-
+/**
+ * Prado client-side javascript validation fascade.
+ *
+ * <p>There are 4 basic classes: {@link Prado.Validation},
+ * {@link Prado.ValidationManager}, {@link Prado.WebUI.TValidationSummary}
+ * and {@link Prado.WebUI.TBaseValidator},
+ * that interact together to perform validation.
+ * The {@link Prado.Validation} class co-ordinates together the
+ * validation scheme and is responsible for maintaining references
+ * to ValidationManagers.</p>
+ *
+ * <p>The {@link Prado.ValidationManager} class is responsible for
+ * maintaining refereneces
+ * to individual validators, validation summaries and their associated
+ * groupings.</p>
+ *
+ * <p>The {@link Prado.WebUI.TValidationSummary} takes care of displaying
+ * the validator error messages
+ * as html output or an alert output.</p>
+ *
+ * <p>The {@link Prado.WebUI.TBaseValidator} is the base class for all
+ * validators and contains
+ * methods to interact with the actual inputs, data type conversion.</p>
+ *
+ * <p>An instance of {@link Prado.ValidationManager} must be instantiated first for a
+ * particular form before instantiating validators and summaries.</p>
+ *
+ * <p>Usage example: adding a required field to a text box input with
+ * ID "input1" in a form with ID "form1".</p>
+ * <pre>
+ * &lt;script type="text/javascript" src="../prado.js"&gt;&lt;/script&gt;
+ * &lt;script type="text/javascript" src="../validator.js"&gt;&lt;/script&gt;
+ * &lt;form id="form1" action="..."&gt;
+ * &lt;div&gt;
+ * &lt;input type="text" id="input1" /&gt;
+ * &lt;span id="validator1" style="display:none; color:red"&gt;*&lt;/span&gt;
+ * &lt;input type="submit text="submit" /&gt;
+ * &lt;script type="text/javascript"&gt;
+ * new Prado.ValidationManager({FormID : 'form1'});
+ * var options =
+ * {
+ * ID : 'validator1',
+ * FormID : 'form1',
+ * ErrorMessage : '*',
+ * ControlToValidate : 'input1'
+ * }
+ * new Prado.WebUI.TRequiredFieldValidator(options);
+ * new Prado.WebUI.TValidationSummary({ID:'summary1',FormID:'form1'});
+ *
+ * //watch the form onsubmit event, check validators, stop if not valid.
+ * Event.observe("form1", "submit" function(ev)
+ * {
+ * if(Prado.WebUI.Validation.isValid("form1") == false)
+ * Event.stop(ev);
+ * });
+ * &lt;/script&gt;
+ * &lt;/div&gt;
+ * &lt;/form&gt;
+ * </pre>
+ *
+ * @module validation
+ */
+
+Prado.Validation = Class.create();
+
+/**
+ * Global Validation Object.
+ *
+ * <p>To validate the inputs of a particular form, call
+ * <code>{@link Prado.Validation.validate}(formID, groupID)</code>
+ * where <tt>formID</tt> is the HTML form ID, and the optional
+ * <tt>groupID</tt> if present will only validate the validators
+ * in a particular group.</p>
+ * <p>Use <code>{@link Prado.Validation.validateControl}(controlClientID)</code>
+ * to trigger validation for a single control.</p>
+ *
+ * @object {static} Prado.Validation
+ */
+Object.extend(Prado.Validation,
+{
+ /**
+ * Hash of registered validation managers
+ * @var managers
+ */
+ managers : {},
+
+ /**
+ * Validate the validators (those that <strong>DO NOT</strong>
+ * belong to a particular group) in the form specified by the
+ * <tt>formID</tt> parameter. If <tt>groupID</tt> is specified
+ * only validators belonging to that group will be validated.
+ * @function {boolean} ?
+ * @param {string} formID - ID of the form to validate
+ * @param {string} groupID - ID of the ValidationGroup to validate.
+ * @param {element} invoker - DOM element that calls for validation
+ * @returns true if validation succeeded
+ */
+ validate : function(formID, groupID, invoker)
+ {
+ formID = formID || this.getForm();
+ if(this.managers[formID])
+ {
+ return this.managers[formID].validate(groupID, invoker);
+ }
+ else
+ {
+ throw new Error("Form '"+formID+"' is not registered with Prado.Validation");
+ }
+ },
+
+ /**
+ * Validate all validators of a specific control.
+ * @function {boolean} ?
+ * @param {string} id - ID of DOM element to validate
+ * @return true if all validators are valid or no validators present, false otherwise.
+ */
+ validateControl : function(id)
+ {
+ var formId=this.getForm();
+
+ if (this.managers[formId])
+ {
+ return this.managers[formId].validateControl(id);
+ } else {
+ throw new Error("A validation manager needs to be created first.");
+ }
+ },
+
+ /**
+ * Return first registered form
+ * @function {string} ?
+ * @returns ID of first form.
+ */
+ getForm : function()
+ {
+ var keys = $H(this.managers).keys();
+ return keys[0];
+ },
+
+ /**
+ * Check if the validators are valid for a particular form (and group).
+ * The validators states will not be changed.
+ * The <tt>validate</tt> function should be called first.
+ * @function {boolean} ?
+ * @param {string} formID - ID of the form to validate
+ * @param {string} groupID - ID of the ValiationGroup to validate.
+ * @return true if form is valid
+ */
+ isValid : function(formID, groupID)
+ {
+ formID = formID || this.getForm();
+ if(this.managers[formID])
+ return this.managers[formID].isValid(groupID);
+ return true;
+ },
+
+ /**
+ * Reset the validators for a given group.
+ * The group is searched in the first registered form.
+ * @function ?
+ * @param {string} groupID - ID of the ValidationGroup to reset.
+ */
+ reset : function(groupID)
+ {
+ var formID = this.getForm();
+ if(this.managers[formID])
+ this.managers[formID].reset(groupID);
+ },
+
+ /**
+ * Add a new validator to a particular form.
+ * @function {ValidationManager} ?
+ * @param {string} formID - ID of the form that the validator belongs to.
+ * @param {TBaseValidator} validator - Validator object
+ * @return ValidationManager for the form
+ */
+ addValidator : function(formID, validator)
+ {
+ if(this.managers[formID])
+ this.managers[formID].addValidator(validator);
+ else
+ throw new Error("A validation manager for form '"+formID+"' needs to be created first.");
+ return this.managers[formID];
+ },
+
+ /**
+ * Add a new validation summary.
+ * @function {ValidationManager} ?
+ * @param {string} formID - ID of the form that the validation summary belongs to.
+ * @param {TValidationSummary} validator - TValidationSummary object
+ * @return ValidationManager for the form
+ */
+ addSummary : function(formID, validator)
+ {
+ if(this.managers[formID])
+ this.managers[formID].addSummary(validator);
+ else
+ throw new Error("A validation manager for form '"+formID+"' needs to be created first.");
+ return this.managers[formID];
+ },
+
+ setErrorMessage : function(validatorID, message)
+ {
+ $H(Prado.Validation.managers).each(function(manager)
+ {
+ manager[1].validators.each(function(validator)
+ {
+ if(validator.options.ID == validatorID)
+ {
+ validator.options.ErrorMessage = message;
+ $(validatorID).innerHTML = message;
+ }
+ });
+ });
+ },
+
+ updateActiveCustomValidator : function(validatorID, isValid)
+ {
+ $H(Prado.Validation.managers).each(function(manager)
+ {
+ manager[1].validators.each(function(validator)
+ {
+ if(validator.options.ID == validatorID)
+ {
+ validator.updateIsValid(isValid);
+ }
+ });
+ });
+ }
+});
+
+/**
+ * Manages validators for a particular HTML form.
+ *
+ * <p>The manager contains references to all the validators
+ * summaries, and their groupings for a particular form.
+ * Generally, {@link Prado.Validation} methods should be called rather
+ * than calling directly the ValidationManager.</p>
+ *
+ * @class Prado.ValidationManager
+ */
+Prado.ValidationManager = Class.create();
+Prado.ValidationManager.prototype =
+{
+ /**
+ * Hash of registered validators by control's clientID
+ * @var controls
+ */
+ controls: {},
+
+ /**
+ * Initialize ValidationManager.
+ * @constructor {protected} ?
+ * @param {object} options - Options for initialization
+ * @... {string} FormID - ID of form of this manager
+ */
+ initialize : function(options)
+ {
+ if(!Prado.Validation.managers[options.FormID])
+ {
+ /**
+ * List of validators
+ * @var {TBaseValidator[]} validators
+ */
+ this.validators = [];
+ /**
+ * List of validation summaries
+ * @var {TValidationSummary[]} summaries
+ */
+ this.summaries = [];
+ /**
+ * List of ValidationGroups
+ * @var {string[]} groups
+ */
+ this.groups = [];
+ /**
+ * Options of this ValidationManager
+ * @var {object} options
+ */
+ this.options = {};
+
+ this.options = options;
+
+ Prado.Validation.managers[options.FormID] = this;
+ }
+ else
+ {
+ var manager = Prado.Validation.managers[options.FormID];
+ this.validators = manager.validators;
+ this.summaries = manager.summaries;
+ this.groups = manager.groups;
+ this.options = manager.options;
+ }
+ },
+
+ /**
+ * Reset all validators in the given group.
+ * If group is null, validators without a group are used.
+ * @function ?
+ * @param {string} group - ID of ValidationGroup
+ */
+ reset : function(group)
+ {
+ this.validatorPartition(group)[0].invoke('reset');
+ this.updateSummary(group, true);
+ },
+
+ /**
+ * Validate the validators managed by this validation manager.
+ * If group is set, only validate validators in that group.
+ * @function {boolean} ?
+ * @param {optional string} group - ID of ValidationGroup
+ * @param {element} source - DOM element that calls for validation
+ * @return true if all validators are valid, false otherwise.
+ */
+ validate : function(group, source)
+ {
+ var partition = this.validatorPartition(group);
+ var valid = partition[0].invoke('validate', source).all();
+ this.focusOnError(partition[0]);
+ partition[1].invoke('hide');
+ this.updateSummary(group, true);
+ return valid;
+ },
+
+ /**
+ * Perform validation for all validators of a single control.
+ * @function {boolean} ?
+ * @param {string} id - ID of DOM element to validate
+ * @return true if all validators are valid or no validators present, false otherwise.
+ */
+ validateControl : function (id)
+ {
+ return this.controls[id] ? this.controls[id].invoke('validate',null).all() : true;
+ },
+
+ /**
+ * Focus on the first validator that is invalid and options.FocusOnError is true.
+ * @function ?
+ * @param {TBaseValidator[]} validators - Array of validator objects
+ */
+ focusOnError : function(validators)
+ {
+ for(var i = 0; i < validators.length; i++)
+ {
+ if(!validators[i].isValid && validators[i].options.FocusOnError)
+ return Prado.Element.focus(validators[i].options.FocusElementID);
+ }
+ },
+
+ /**
+ * Get all validators in a group and all other validators.
+ * Returns an array with two arrays of validators. The first
+ * array contains all validators in the group if group is given,
+ * otherwhise all validators without a group. The second array
+ * contains all other validators.
+ * @function {[ TBaseValidator[] , TBaseValidator[] ]} ?
+ * @param {optional string} group - ID of ValidationGroup
+ * @return Array with two arrays of validators.
+ */
+ validatorPartition : function(group)
+ {
+ return group ? this.validatorsInGroup(group) : this.validatorsWithoutGroup();
+ },
+
+ /**
+ * Get all validators in a group.
+ * Returns an array with two arrays of validators. The first
+ * array contains all validators in the group. The second array
+ * contains all other validators.
+ * @function {[ TBaseValidator[] , TBaseValidator[] ]} ?
+ * @param {optional string} groupID - ID of ValidationGroup
+ * @return Array with two arrays of validators.
+ */
+ validatorsInGroup : function(groupID)
+ {
+ if(this.groups.include(groupID))
+ {
+ return this.validators.partition(function(val)
+ {
+ return val.group == groupID;
+ });
+ }
+ else
+ return [[],[]];
+ },
+
+ /**
+ * Get all validators without a group.
+ * Returns an array with two arrays of validators. The first
+ * array contains all validators without a group. The second
+ * array contains all other validators.
+ * @function {[ TBaseValidator[] , TBaseValidator[] ]} ?
+ * @return Array with two arrays of validators: Array[0] has all
+ * validators without a group, Array[1] all other validators.
+ */
+ validatorsWithoutGroup : function()
+ {
+ return this.validators.partition(function(val)
+ {
+ return !val.group;
+ });
+ },
+
+ /**
+ * Get the state of validators.
+ * If group is set, only validators in that group are checked.
+ * Otherwhise only validators without a group are checked.
+ * @function {booelan} ?
+ * @param {optional string} group - ID of ValidationGroup
+ * @return true if all validators (in a group, if supplied) are valid.
+ */
+ isValid : function(group)
+ {
+ return this.validatorPartition(group)[0].pluck('isValid').all();
+ },
+
+ /**
+ * Add a validator to this manager.
+ * @function ?
+ * @param {TBaseValidator} validator - Validator object
+ */
+ addValidator : function(validator)
+ {
+ // Remove previously registered validator with same ID
+ // to prevent stale validators created by AJAX updates
+ this.removeValidator(validator);
+
+ this.validators.push(validator);
+ if(validator.group && !this.groups.include(validator.group))
+ this.groups.push(validator.group);
+
+ if (typeof this.controls[validator.control.id] === 'undefined')
+ this.controls[validator.control.id] = Array();
+ this.controls[validator.control.id].push(validator);
+ },
+
+ /**
+ * Add a validation summary.
+ * @function ?
+ * @param {TValidationSummary} summary - Validation summary.
+ */
+ addSummary : function(summary)
+ {
+ this.summaries.push(summary);
+ },
+
+ /**
+ * Remove a validator from this manager
+ * @function ?
+ * @param {TBaseValidator} validator - Validator object
+ */
+ removeValidator : function(validator)
+ {
+ this.validators = this.validators.reject(function(v)
+ {
+ return (v.options.ID==validator.options.ID);
+ });
+ if (this.controls[validator.control.id])
+ this.controls[validator.control.id].reject( function(v)
+ {
+ return (v.options.ID==validator.options.ID)
+ });
+ },
+
+ /**
+ * Gets validators with errors.
+ * If group is set, only validators in that group are returned.
+ * Otherwhise only validators without a group are returned.
+ * @function {TBaseValidator[]} ?
+ * @param {optional string} group - ID of ValidationGroup
+ * @return array list of validators with error.
+ */
+ getValidatorsWithError : function(group)
+ {
+ return this.validatorPartition(group)[0].findAll(function(validator)
+ {
+ return !validator.isValid;
+ });
+ },
+
+ /**
+ * Update the summary of a particular group.
+ * If group is set, only the summary for validators in that
+ * group is updated. Otherwhise only the summary for validators
+ * without a group is updated.
+ * @function ?
+ * @param {optional string} group - ID of ValidationGroup
+ * @param {boolean} refresh - Wether the summary should be refreshed
+ */
+ updateSummary : function(group, refresh)
+ {
+ var validators = this.getValidatorsWithError(group);
+ this.summaries.each(function(summary)
+ {
+ var inGroup = group && summary.group == group;
+ var noGroup = !group || !summary.group;
+ if(inGroup || noGroup)
+ summary.updateSummary(validators, refresh);
+ else
+ summary.hideSummary(true);
+ });
+ }
+};
+
+/**
+ * TValidationSummary displays a summary of validation errors.
+ *
+ * <p>The summary is displayed inline on a Web page,
+ * in a message box, or both. By default, a validation summary will collect
+ * <tt>ErrorMessage</tt> of all failed validators on the page. If
+ * <tt>ValidationGroup</tt> is not empty, only those validators who belong
+ * to the group will show their error messages in the summary.</p>
+ *
+ * <p>The summary can be displayed as a list, as a bulleted list, or as a single
+ * paragraph based on the <tt>DisplayMode</tt> option.
+ * The messages shown can be prefixed with <tt>HeaderText</tt>.</p>
+ *
+ * <p>The summary can be displayed on the Web page and in a message box by setting
+ * the <tt>ShowSummary</tt> and <tt>ShowMessageBox</tt>
+ * options, respectively.</p>
+ *
+ * @class Prado.WebUI.TValidationSummary
+ */
+Prado.WebUI.TValidationSummary = Class.create();
+Prado.WebUI.TValidationSummary.prototype =
+{
+ /**
+ * Initialize TValidationSummary.
+ * @constructor {protected} ?
+ * @param {object} options - Options for initialization
+ * @... {string} ID - ID of validation summary element
+ * @... {string} FormID - ID of form of this manager
+ * @... {optional string} ValidationGroup - ID of ValidationGroup.
+ * @... {optional boolean} ShowMessageBox - true to show the summary in an alert box.
+ * @... {optional boolean} ShowSummary - true to show the inline summary.
+ * @... {optional string} HeaderText - Summary header text
+ * @... {optional string} DisplayMode - Summary display style, 'BulletList', 'List', 'SingleParagraph'
+ * @... {optional boolean} Refresh - true to update the summary upon validator state change.
+ * @... {optional string} Display - Display mode, 'None', 'Fixed', 'Dynamic'.
+ * @... {optional boolean} ScrollToSummary - true to scroll to the validation summary upon refresh.
+ * @... {optional function} OnHideSummary - Called on hide event.
+ * @... {optional function} OnShowSummary - Called on show event.
+ */
+ initialize : function(options)
+ {
+ /**
+ * Validator options
+ * @var {object} options
+ */
+ this.options = options;
+ /**
+ * ValidationGroup
+ * @var {string} group
+ */
+ this.group = options.ValidationGroup;
+ /**
+ * Summary DOM element
+ * @var {element} messages
+ */
+ this.messages = $(options.ID);
+ Prado.Registry.set(options.ID, this);
+ if(this.messages)
+ {
+ /**
+ * Current visibility state of summary
+ * @var {boolean} visible
+ */
+ this.visible = this.messages.style.visibility != "hidden"
+ this.visible = this.visible && this.messages.style.display != "none";
+ Prado.Validation.addSummary(options.FormID, this);
+ }
+ },
+
+ /**
+ * Update the validation summary.
+ * @function ?
+ * @param {TBaseValidator[]} validators - List of validators that failed validation.
+ * @param {boolean} update - true if visible summary should be updated
+ */
+ updateSummary : function(validators, update)
+ {
+ if(validators.length <= 0)
+ {
+ if(update || this.options.Refresh != false)
+ {
+ return this.hideSummary(validators);
+ }
+ return;
+ }
+
+ var refresh = update || this.visible == false || this.options.Refresh != false;
+ // Also, do not refresh summary if at least 1 validator is waiting for callback response.
+ // This will avoid the flickering of summary if the validator passes its test
+ refresh = refresh && validators.any(function(v) { return !v.requestDispatched; });
+
+ if(this.options.ShowSummary != false && refresh)
+ {
+ this.updateHTMLMessages(this.getMessages(validators));
+ this.showSummary(validators);
+ }
+
+ if(this.options.ScrollToSummary != false && refresh)
+ window.scrollTo(this.messages.offsetLeft-20, this.messages.offsetTop-20);
+
+ if(this.options.ShowMessageBox == true && refresh)
+ {
+ this.alertMessages(this.getMessages(validators));
+ this.visible = true;
+ }
+ },
+
+ /**
+ * Display the validator error messages as inline HTML.
+ * @function ?
+ * @param {string[]} messages - Array of error messages.
+ */
+ updateHTMLMessages : function(messages)
+ {
+ while(this.messages.childNodes.length > 0)
+ this.messages.removeChild(this.messages.lastChild);
+ this.messages.insert(this.formatSummary(messages));
+ },
+
+ /**
+ * Display the validator error messages as an alert box.
+ * @function ?
+ * @param {string[]} messages - Array of error messages.
+ */
+ alertMessages : function(messages)
+ {
+ var text = this.formatMessageBox(messages);
+ setTimeout(function(){ alert(text); },20);
+ },
+
+ /**
+ * Get messages from validators.
+ * @function {string[]} ?
+ * @param {TBaseValidator[]} validators - Array of validators.
+ * @return Array of validator error messages.
+ */
+ getMessages : function(validators)
+ {
+ var messages = [];
+ validators.each(function(validator)
+ {
+ var message = validator.getErrorMessage();
+ if(typeof(message) == 'string' && message.length > 0)
+ messages.push(message);
+ })
+ return messages;
+ },
+
+ /**
+ * Hide the validation summary.
+ * @function ?
+ * @param {TBaseValidator[]} validators - Array of validators.
+ */
+ hideSummary : function(validators)
+ { if(typeof(this.options.OnHideSummary) == "function")
+ {
+ this.messages.style.visibility="visible";
+ this.options.OnHideSummary(this,validators)
+ }
+ else
+ {
+ this.messages.style.visibility="hidden";
+ if(this.options.Display == "None" || this.options.Display == "Dynamic")
+ this.messages.hide();
+ }
+ this.visible = false;
+ },
+
+ /**
+ * Shows the validation summary.
+ * @function ?
+ * @param {TBaseValidator[]} validators - Array of validators.
+ */
+ showSummary : function(validators)
+ {
+ this.messages.style.visibility="visible";
+ if(typeof(this.options.OnShowSummary) == "function")
+ this.options.OnShowSummary(this,validators);
+ else
+ this.messages.show();
+ this.visible = true;
+ },
+
+ /**
+ * Return the format parameters for the summary.
+ * @function {object} ?
+ * @param {string} type - Format type: "List", "SingleParagraph", "HeaderOnly" or "BulletList" (default)
+ * @return Object with format parameters:
+ * @... {string} header - Text for header
+ * @... {string} first - Text to prepend before message list
+ * @... {string} pre - Text to prepend before each message
+ * @... {string} post - Text to append after each message
+ * @... {string} first - Text to append after message list
+ */
+ formats : function(type)
+ {
+ switch(type)
+ {
+ case "SimpleList":
+ return { header : "<br />", first : "", pre : "", post : "<br />", last : ""};
+ case "SingleParagraph":
+ return { header : " ", first : "", pre : "", post : " ", last : "<br />"};
+ case "HeaderOnly":
+ return { header : "", first : "<!--", pre : "", post : "", last : "-->"};
+ case "BulletList":
+ default:
+ return { header : "", first : "<ul>", pre : "<li>", post : "</li>", last : "</ul>"};
+ }
+ },
+
+ /**
+ * Format the message summary.
+ * @function {string} ?
+ * @param {string[]} messages - Array of error messages.
+ * @return Formatted message
+ */
+ formatSummary : function(messages)
+ {
+ var format = this.formats(this.options.DisplayMode);
+ var output = this.options.HeaderText ? this.options.HeaderText + format.header : "";
+ output += format.first;
+ messages.each(function(message)
+ {
+ output += message.length > 0 ? format.pre + message + format.post : "";
+ });
+// for(var i = 0; i < messages.length; i++)
+ // output += (messages[i].length>0) ? format.pre + messages[i] + format.post : "";
+ output += format.last;
+ return output;
+ },
+ /**
+ * Format the message alert box.
+ * @function {string} ?
+ * @param {string[]} messages - Array of error messages.
+ * @return Formatted message for alert
+ */
+ formatMessageBox : function(messages)
+ {
+ if(this.options.DisplayMode == 'HeaderOnly' && this.options.HeaderText)
+ return this.options.HeaderText;
+
+ var output = this.options.HeaderText ? this.options.HeaderText + "\n" : "";
+ for(var i = 0; i < messages.length; i++)
+ {
+ switch(this.options.DisplayMode)
+ {
+ case "List":
+ output += messages[i] + "\n";
+ break;
+ case "BulletList":
+ default:
+ output += " - " + messages[i] + "\n";
+ break;
+ case "SingleParagraph":
+ output += messages[i] + " ";
+ break;
+ }
+ }
+ return output;
+ }
+};
+
+/**
+ * TBaseValidator serves as the base class for validator controls.
+ *
+ * <p>Validation is performed when a postback control, such as a TButton,
+ * a TLinkButton or a TTextBox (under AutoPostBack mode) is submitting
+ * the page and its <tt>CausesValidation</tt> option is true.
+ * The input control to be validated is specified by <tt>ControlToValidate</tt>
+ * option.</p>
+ *
+ * @class Prado.WebUI.TBaseValidator
+ */
+Prado.WebUI.TBaseValidator = Class.create(Prado.WebUI.Control,
+{
+ /**
+ * Initialize TBaseValidator.
+ * @constructor {protected} ?
+ * @param {object} options - Options for initialization.
+ * @... {string} ID - ID of validator
+ * @... {string} FormID - ID of form of this manager.
+ * @... {string} ControlToValidate - ID of control to validate.
+ * @... {optional string} InitialValue - Initial value of control to validate.
+ * @... {optional string} ErrorMessage - Validation error message.
+ * @... {optional string} ValidationGroup - ID of ValidationGroup.
+ * @... {optional string} Display - Display mode, 'None', 'Fixed', 'Dynamic'.
+ * @... {optional boolean} ObserveChanges - True to observer changes of ControlToValidate
+ * @... {optional boolean} FocusOnError - True to focus on validation error.
+ * @... {optional string} FocusElementID - ID of element to focus on error.
+ * @... {optional string} ControlCssClass - Css class to use on ControlToValidate on error
+ * @... {optional function} OnValidate - Called immediately after validation.
+ * @... {optional function} OnValidationSuccess - Called after successful validation.
+ * @... {optional function} OnValidationError - Called after validation error.
+ */
+ initialize : function(options)
+ {
+ this.observers = new Array();
+ this.intervals = new Array();
+
+ /* options.OnValidate = options.OnValidate || Prototype.emptyFunction;
+ options.OnSuccess = options.OnSuccess || Prototype.emptyFunction;
+ options.OnError = options.OnError || Prototype.emptyFunction;
+ */
+ /**
+ * Wether the validator is enabled (default true)
+ * @var {boolean} enabled
+ */
+ this.enabled = options.Enabled;
+ /**
+ * Visibility state of validator(default false)
+ * @var {boolean} visible
+ */
+ this.visible = false;
+ /**
+ * State of validation (default true)
+ * @var {boolean} isValid
+ */
+ this.isValid = true;
+ /**
+ * DOM elements that are observed by this validator
+ * @var {private element[]} _isObserving
+ */
+ this._isObserving = {};
+ /**
+ * ValidationGroup
+ * @var {string} group
+ */
+ this.group = null;
+ /**
+ * Wether a request was dispatched (default false)
+ * @var {boolean} requestDispatched
+ */
+ this.requestDispatched = false;
+
+ /**
+ * Validator options
+ * @var {object} options
+ */
+ this.options = options;
+ /**
+ * DOM element of control to validate
+ * @var {element} control
+ */
+ this.control = $(options.ControlToValidate);
+ /**
+ * DOM element of validator
+ * @var {element} message
+ */
+ this.message = $(options.ID);
+
+ Prado.Registry.set(options.ID, this);
+
+ if (this.onInit) this.onInit();
+
+ if(this.control && this.message)
+ {
+ this.group = options.ValidationGroup;
+
+ /**
+ * ValidationManager of this validator
+ * @var {ValidationManager} manager
+ */
+ this.manager = Prado.Validation.addValidator(options.FormID, this);
+ }
+ },
+
+ /**
+ * Get error message.
+ * @function {string} ?
+ * @return Validation error message.
+ */
+ getErrorMessage : function()
+ {
+ return this.options.ErrorMessage;
+ },
+
+ /**
+ * Update the validator.
+ * Updating the validator control will set the validator
+ * <tt>visible</tt> property to true.
+ * @function ?
+ */
+ updateControl: function()
+ {
+ this.refreshControlAndMessage();
+
+ //if(this.options.FocusOnError && !this.isValid )
+ // Prado.Element.focus(this.options.FocusElementID);
+
+ this.visible = true;
+ },
+
+ /**
+ * Updates span and input CSS class.
+ * @function ?
+ */
+ refreshControlAndMessage : function()
+ {
+ this.visible = true;
+ if(this.message)
+ {
+ if(this.options.Display == "Dynamic")
+ {
+ var msg=this.message;
+ this.isValid ? setTimeout(function() { msg.hide(); }, 250) : msg.show();
+ }
+ this.message.style.visibility = this.isValid ? "hidden" : "visible";
+ }
+ if(this.control)
+ this.updateControlCssClass(this.control, this.isValid);
+ },
+
+ /**
+ * Update CSS class of control to validate.
+ * Add a css class to the input control if validator is invalid,
+ * removes the css class if valid.
+ * @function ?
+ * @param {element} control - DOM element of control to validate
+ * @param {boolean} valid - Validation state of control
+ */
+ updateControlCssClass : function(control, valid)
+ {
+ var CssClass = this.options.ControlCssClass;
+ if(typeof(CssClass) == "string" && CssClass.length > 0)
+ {
+ if(valid)
+ {
+ if (control.lastValidator == this.options.ID)
+ {
+ control.lastValidator = null;
+ control.removeClassName(CssClass);
+ }
+ }
+ else
+ {
+ control.lastValidator = this.options.ID;
+ control.addClassName(CssClass);
+ }
+ }
+ },
+
+ /**
+ * Hide the validator messages and remove any validation changes.
+ * @function ?
+ */
+ hide : function()
+ {
+ this.reset();
+ this.visible = false;
+ },
+
+ /**
+ * Reset validator.
+ * Sets isValid = true and updates the validator display.
+ * @function ?
+ */
+ reset : function()
+ {
+ this.isValid = true;
+ this.updateControl();
+ },
+
+ /**
+ * Perform validation.
+ * Calls evaluateIsValid() function to set the value of isValid property.
+ * Triggers onValidate event and onSuccess or onError event.
+ * @function {boolean} ?
+ * @param {element} invoker - DOM element that triggered validation
+ * @return Valdation state of control.
+ */
+ validate : function(invoker)
+ {
+ //try to find the control.
+ if(!this.control)
+ this.control = $(this.options.ControlToValidate);
+
+ if(!this.control || this.control.disabled)
+ {
+ this.isValid = true;
+ return this.isValid;
+ }
+
+ if(typeof(this.options.OnValidate) == "function")
+ {
+ if(this.requestDispatched == false)
+ this.options.OnValidate(this, invoker);
+ }
+
+ if(this.enabled && !this.control.getAttribute('disabled'))
+ this.isValid = this.evaluateIsValid();
+ else
+ this.isValid = true;
+
+ this.updateValidationDisplay(invoker);
+ this.observeChanges(this.control);
+
+ return this.isValid;
+ },
+
+ /**
+ * Update validation display.
+ * Updates the validation messages and the control to validate.
+ * @param {element} invoker - DOM element that triggered validation
+ */
+ updateValidationDisplay : function(invoker)
+ {
+ if(this.isValid)
+ {
+ if(typeof(this.options.OnValidationSuccess) == "function")
+ {
+ if(this.requestDispatched == false)
+ {
+ this.refreshControlAndMessage();
+ this.options.OnValidationSuccess(this, invoker);
+ }
+ }
+ else
+ this.updateControl();
+ }
+ else
+ {
+ if(typeof(this.options.OnValidationError) == "function")
+ {
+ if(this.requestDispatched == false)
+ {
+ this.refreshControlAndMessage();
+ this.options.OnValidationError(this, invoker)
+ }
+ }
+ else
+ this.updateControl();
+ }
+ },
+
+ /**
+ * Add control to observe for changes.
+ * Re-validates upon change. If the validator is not visible,
+ * no updates are propagated.
+ * @function ?
+ * @param {element} control - DOM element of control to observe
+ */
+ observeChanges : function(control)
+ {
+ if(!control) return;
+
+ var canObserveChanges = this.options.ObserveChanges != false;
+ var currentlyObserving = this._isObserving[control.id+this.options.ID];
+
+ if(canObserveChanges && !currentlyObserving)
+ {
+ var validator = this;
+
+ this.observe(control, 'change', function()
+ {
+ if(validator.visible)
+ {
+ validator.validate();
+ validator.manager.updateSummary(validator.group);
+ }
+ });
+ this._isObserving[control.id+this.options.ID] = true;
+ }
+ },
+
+ /**
+ * Trim a string.
+ * @function {string} ?
+ * @param {string} value - String that should be trimmed.
+ * @return Trimmed string, empty string if value is not string.
+ */
+ trim : function(value)
+ {
+ return typeof(value) == "string" ? value.trim() : "";
+ },
+
+ /**
+ * Convert the value to a specific data type.
+ * @function {mixed|null} ?
+ * @param {string} dataType - Data type: "Integer", "Double", "Date" or "String"
+ * @param {mixed} value - Value to convert.
+ * @return Converted data value.
+ */
+ convert : function(dataType, value)
+ {
+ if(typeof(value) == "undefined")
+ value = this.getValidationValue();
+ var string = new String(value);
+ switch(dataType)
+ {
+ case "Integer":
+ return string.toInteger();
+ case "Double" :
+ case "Float" :
+ return string.toDouble(this.options.DecimalChar);
+ case "Date":
+ if(typeof(value) != "string")
+ return value;
+ else
+ {
+ var value = string.toDate(this.options.DateFormat);
+ if(value && typeof(value.getTime) == "function")
+ return value.getTime();
+ else
+ return null;
+ }
+ case "String":
+ return string.toString();
+ }
+ return value;
+ },
+
+ /**
+ * Get value that should be validated.
+ * The ControlType property comes from TBaseValidator::getClientControlClass()
+ * Be sure to update the TBaseValidator::$_clientClass if new cases are added.
+ * @function {mixed} ?
+ * @param {optional element} control - Control to get value from (default: this.control)
+ * @return Control value to validate
+ */
+ getRawValidationValue : function(control)
+ {
+ if(!control)
+ control = this.control
+ switch(this.options.ControlType)
+ {
+ case 'TDatePicker':
+ if(control.type == "text")
+ {
+ var value = this.trim($F(control));
+
+ if(this.options.DateFormat)
+ {
+ var date = value.toDate(this.options.DateFormat);
+ return date == null ? value : date;
+ }
+ else
+ return value;
+ }
+ else
+ {
+ this.observeDatePickerChanges();
+
+ return Prado.WebUI.TDatePicker.getDropDownDate(control);//.getTime();
+ }
+ case 'THtmlArea':
+ if(typeof tinyMCE != "undefined")
+ tinyMCE.triggerSave();
+ return $F(control);
+ case 'TRadioButton':
+ if(this.options.GroupName)
+ return this.getRadioButtonGroupValue();
+ default:
+ if(this.isListControlType())
+ return this.getFirstSelectedListValue();
+ else
+ return $F(control);
+ }
+ },
+
+ /**
+ * Get a trimmed value that should be validated.
+ * The ControlType property comes from TBaseValidator::getClientControlClass()
+ * Be sure to update the TBaseValidator::$_clientClass if new cases are added.
+ * @function {mixed} ?
+ * @param {optional element} control - Control to get value fron (default: this.control)
+ * @return Control value to validate
+ */
+ getValidationValue : function(control)
+ {
+ var value = this.getRawValidationValue(control);
+ if(!control)
+ control = this.control
+ switch(this.options.ControlType)
+ {
+ case 'TDatePicker':
+ return value;
+ case 'THtmlArea':
+ return this.trim(value);
+ case 'TRadioButton':
+ return value;
+ default:
+ if(this.isListControlType())
+ return value;
+ else
+ return this.trim(value);
+ }
+ },
+
+ /**
+ * Get value of radio button group
+ * @function {string} ?
+ * @return Value of a radio button group
+ */
+ getRadioButtonGroupValue : function()
+ {
+ var name = this.control.name;
+ var value = "";
+ $A(document.getElementsByName(name)).each(function(el)
+ {
+ if(el.checked)
+ value = el.value;
+ });
+ return value;
+ },
+
+ /**
+ * Observe changes in the drop down list date picker, IE only.
+ * @function ?
+ */
+ observeDatePickerChanges : function()
+ {
+ if(Prado.Browser().ie)
+ {
+ var DatePicker = Prado.WebUI.TDatePicker;
+ this.observeChanges(DatePicker.getDayListControl(this.control));
+ this.observeChanges(DatePicker.getMonthListControl(this.control));
+ this.observeChanges(DatePicker.getYearListControl(this.control));
+ }
+ },
+
+ /**
+ * Gets number of selections and their values.
+ * @function {object} ?
+ * @param {element[]} elements - Elements to get values from.
+ * @param {string} initialValue - Initial value of element
+ * @return Object:
+ * @... {mixed[]} values - Array of selected values
+ * @... {int} checks - Number of selections
+ */
+ getSelectedValuesAndChecks : function(elements, initialValue)
+ {
+ var checked = 0;
+ var values = [];
+ var isSelected = this.isCheckBoxType(elements[0]) ? 'checked' : 'selected';
+ elements.each(function(element)
+ {
+ if(element[isSelected] && element.value != initialValue)
+ {
+ checked++;
+ values.push(element.value);
+ }
+ });
+ return {'checks' : checked, 'values' : values};
+ },
+
+ /**
+ * Get list elements of TCheckBoxList or TListBox.
+ * Gets an array of the list control item input elements, for TCheckBoxList
+ * checkbox input elements are returned, for TListBox HTML option elements
+ * are returned.
+ * @function {element[]} ?
+ * @return Array of list control option DOM elements.
+ */
+ getListElements : function()
+ {
+ switch(this.options.ControlType)
+ {
+ case 'TCheckBoxList': case 'TRadioButtonList':
+ var elements = [];
+ for(var i = 0; i < this.options.TotalItems; i++)
+ {
+ var element = $(this.options.ControlToValidate+"_c"+i);
+ if(this.isCheckBoxType(element))
+ elements.push(element);
+ }
+ return elements;
+ case 'TListBox':
+ var elements = [];
+ var element = $(this.options.ControlToValidate);
+ var type;
+ if(element && (type = element.type.toLowerCase()))
+ {
+ if(type == "select-one" || type == "select-multiple")
+ elements = $A(element.options);
+ }
+ return elements;
+ default:
+ return [];
+ }
+ },
+
+ /**
+ * Check if control is of type checkbox or radio.
+ * @function {boolean} ?
+ * @param {element} element - DOM element to check.
+ * @return True if element is of checkbox or radio type.
+ */
+ isCheckBoxType : function(element)
+ {
+ if(element && element.type)
+ {
+ var type = element.type.toLowerCase();
+ return type == "checkbox" || type == "radio";
+ }
+ return false;
+ },
+
+ /**
+ * Check if control to validate is a TListControl type.
+ * @function {boolean} ?
+ * @return True if control to validate is a TListControl type.
+ */
+ isListControlType : function()
+ {
+ var list = ['TCheckBoxList', 'TRadioButtonList', 'TListBox'];
+ return list.include(this.options.ControlType);
+ },
+
+ /**
+ * Get first selected list value or initial value if none found.
+ * @function {string} ?
+ * @return First selected list value, initial value if none found.
+ */
+ getFirstSelectedListValue : function()
+ {
+ var initial = "";
+ if(typeof(this.options.InitialValue) != "undefined")
+ initial = this.options.InitialValue;
+ var elements = this.getListElements();
+ var selection = this.getSelectedValuesAndChecks(elements, initial);
+ return selection.values.length > 0 ? selection.values[0] : initial;
+ }
+});
+
+
+/**
+ * TRequiredFieldValidator makes the associated input control a required field.
+ *
+ * <p>The input control fails validation if its value does not change from
+ * the <tt>InitialValue</tt> option upon losing focus.</p>
+ *
+ * @class Prado.WebUI.TRequiredFieldValidator
+ * @extends Prado.WebUI.TBaseValidator
+ */
+Prado.WebUI.TRequiredFieldValidator = Class.extend(Prado.WebUI.TBaseValidator,
+{
+ /**
+ * Evaluate validation state
+ * @function {boolean} ?
+ * @return True if the input value is not empty nor equal to the initial value.
+ */
+ evaluateIsValid : function()
+ {
+ var a = this.getValidationValue();
+ var b = this.trim(this.options.InitialValue);
+ return(a != b);
+ }
+});
+
+
+/**
+ * TCompareValidator compares the value entered by the user into an input
+ * control with the value entered into another input control or a constant value.
+ *
+ * <p>To compare the associated input control with another input control,
+ * set the <tt>ControlToCompare</tt> option to the ID path
+ * of the control to compare with. To compare the associated input control with
+ * a constant value, specify the constant value to compare with by setting the
+ * <tt>ValueToCompare</tt> option.</p>
+ *
+ * <p>The <tt>DataType</tt> property is used to specify the data type
+ * of both comparison values. Both values are automatically converted to this data
+ * type before the comparison operation is performed. The following value types are supported:
+ * - <b>Integer</b> A 32-bit signed integer data type.
+ * - <b>Float</b> A double-precision floating point number data type.
+ * - <b>Date</b> A date data type. The format can be set by the <tt>DateFormat</tt> option.
+ * - <b>String</b> A string data type.</p>
+ *
+ * Use the <tt>Operator</tt> property to specify the type of comparison
+ * to perform. Valid operators include Equal, NotEqual, GreaterThan, GreaterThanEqual,
+ * LessThan and LessThanEqual.
+ *
+ * @class Prado.WebUI.TCompareValidator
+ * @extends Prado.WebUI.TBaseValidator
+ */
+Prado.WebUI.TCompareValidator = Class.extend(Prado.WebUI.TBaseValidator,
+{
+ /**
+ * Additional constructor options.
+ * @constructor initialize
+ * @param {object} options - Additional constructor options:
+ * @... {string} ControlToCompare - Control with compare value.
+ * @... {string} ValueToCompare - Value to compare.
+ * @... {string} Operator - Type of comparison: "Equal", "NotEqual", "GreaterThan",
+ * "GreaterThanEqual", "LessThan" or "LessThanEqual".
+ * @... {string} Type - Type of values: "Integer", "Float", "Date" or "String".
+ * @... {string} DateFormat - Valid date format.
+ */
+
+ //_observingComparee : false,
+
+ /**
+ * Evaluate validation state
+ * @function {boolean} ?
+ * @return True if comparision condition is met.
+ */
+ evaluateIsValid : function()
+ {
+ var value = this.getValidationValue();
+ if (value.length <= 0)
+ return true;
+
+ var comparee = $(this.options.ControlToCompare);
+
+ if(comparee)
+ var compareTo = this.getValidationValue(comparee);
+ else
+ var compareTo = this.options.ValueToCompare || "";
+
+ var isValid = this.compare(value, compareTo);
+
+ if(comparee)
+ {
+ this.updateControlCssClass(comparee, isValid);
+ this.observeChanges(comparee);
+ }
+ return isValid;
+ },
+
+ /**
+ * Compare two operands.
+ * The operand values are casted to type defined
+ * by <tt>DataType</tt> option. False is returned if the first
+ * operand converts to null. Returns true if the second operand
+ * converts to null. The comparision is done based on the
+ * <tt>Operator</tt> option.
+ * @function ?
+ * @param {mixed} operand1 - First operand.
+ * @param {mixed} operand2 - Second operand.
+ */
+ compare : function(operand1, operand2)
+ {
+ var op1, op2;
+ if((op1 = this.convert(this.options.DataType, operand1)) == null)
+ return false;
+ if ((op2 = this.convert(this.options.DataType, operand2)) == null)
+ return true;
+ switch (this.options.Operator)
+ {
+ case "NotEqual":
+ return (op1 != op2);
+ case "GreaterThan":
+ return (op1 > op2);
+ case "GreaterThanEqual":
+ return (op1 >= op2);
+ case "LessThan":
+ return (op1 < op2);
+ case "LessThanEqual":
+ return (op1 <= op2);
+ default:
+ return (op1 == op2);
+ }
+ }
+});
+
+/**
+ * TCustomValidator performs user-defined client-side validation on an
+ * input component.
+ *
+ * <p>To create a client-side validation function, add the client-side
+ * validation javascript function to the page template.
+ * The function should have the following signature:</p>
+ *
+ * <pre>
+ * &lt;script type="text/javascript"&gt;
+ * function ValidationFunctionName(sender, parameter)
+ * {
+ * if(parameter == ...)
+ * return true;
+ * else
+ * return false;
+ * }
+ * &lt;/script&gt;
+ * </pre>
+ *
+ * <p>Use the <tt>ClientValidationFunction</tt> option
+ * to specify the name of the client-side validation script function associated
+ * with the TCustomValidator.</p>
+ *
+ * @class Prado.WebUI.TCustomValidator
+ * @extends Prado.WebUI.TBaseValidator
+ */
+Prado.WebUI.TCustomValidator = Class.extend(Prado.WebUI.TBaseValidator,
+{
+ /**
+ * Additional constructor options.
+ * @constructor initialize
+ * @param {object} options - Additional constructor options:
+ * @... {function} ClientValidationFunction - Custom validation function.
+ */
+
+ /**
+ * Evaluate validation state
+ * Returns true if no valid custom validation function is present.
+ * @function {boolean} ?
+ * @return True if custom validation returned true.
+ */
+ evaluateIsValid : function()
+ {
+ var value = this.getValidationValue();
+ var clientFunction = this.options.ClientValidationFunction;
+ if(typeof(clientFunction) == "string" && clientFunction.length > 0)
+ {
+ var validate = clientFunction.toFunction();
+ return validate(this, value);
+ }
+ return true;
+ }
+});
+
+/**
+ * Uses callback request to perform validation.
+ *
+ * @class Prado.WebUI.TActiveCustomValidator
+ * @extends Prado.WebUI.TBaseValidator
+ */
+Prado.WebUI.TActiveCustomValidator = Class.extend(Prado.WebUI.TBaseValidator,
+{
+ /**
+ * Override the parent implementation to store the invoker, in order to
+ * re-validate after the callback has returned
+ * Calls evaluateIsValid() function to set the value of isValid property.
+ * Triggers onValidate event and onSuccess or onError event.
+ * @function {boolean} ?
+ * @param {element} invoker - DOM element that triggered validation
+ * @return True if valid.
+ */
+ validate : function(invoker)
+ {
+ this.invoker = invoker;
+
+ //try to find the control.
+ if(!this.control)
+ this.control = $(this.options.ControlToValidate);
+
+ if(!this.control || this.control.disabled)
+ {
+ this.isValid = true;
+ return this.isValid;
+ }
+
+ if(typeof(this.options.OnValidate) == "function")
+ {
+ if(this.requestDispatched == false)
+ this.options.OnValidate(this, invoker);
+ }
+
+ return true;
+ },
+
+ /**
+ * Send CallBack to start serverside validation.
+ * @function {boolean} ?
+ * @return True if valid.
+ */
+ evaluateIsValid : function()
+ {
+ return this.isValid;
+ },
+
+ /**
+ * Parse CallBack response data on success.
+ * @function ?
+ * @param {CallbackRequest} request - CallbackRequest.
+ * @param {string} data - Response data.
+ */
+ updateIsValid : function(data)
+ {
+ this.isValid = data;
+ this.requestDispatched = false;
+ if(typeof(this.options.onSuccess) == "function")
+ this.options.onSuccess(null,data);
+ this.updateValidationDisplay();
+ this.manager.updateSummary(this.group);
+ }
+});
+
+/**
+ * TRangeValidator tests whether an input value is within a specified range.
+ *
+ * <p>TRangeValidator uses three key properties to perform its validation.</p>
+ *
+ * <p>The <tt>MinValue</tt> and <tt>MaxValue</tt> options specify the minimum
+ * and maximum values of the valid range.</p>
+ * <p>The <tt>DataType</tt> option is
+ * used to specify the data type of the value and the minimum and maximum range values.
+ * The values are converted to this data type before the validation
+ * operation is performed. The following value types are supported:</p>
+ *
+ * - <b>Integer</b> A 32-bit signed integer data type.<br />
+ * - <b>Float</b> A double-precision floating point number data type.<br />
+ * - <b>Date</b> A date data type. The date format can be specified by<br />
+ * setting <tt>DateFormat</tt> option, which must be recognizable
+ * by <tt>Date.SimpleParse</tt> javascript function.
+ * - <b>String</b> A string data type.
+ *
+ * @class Prado.WebUI.TRangeValidator
+ * @extends Prado.WebUI.TBaseValidator
+ */
+Prado.WebUI.TRangeValidator = Class.extend(Prado.WebUI.TBaseValidator,
+{
+ /**
+ * Additional constructor options.
+ * @constructor initialize
+ * @param {object} options - Additional constructor options:
+ * @... {string} MinValue - Minimum range value
+ * @... {string} MaxValue - Maximum range value
+ * @... {string} DataType - Value data type: "Integer", "Float", "Date" or "String"
+ * @... {string} DateFormat - Date format for data type Date.
+ */
+
+ /**
+ * Evaluate validation state
+ * @function {boolean} ?
+ * @return True if value is in range or value is empty,
+ * false otherwhise and when type conversion failed.
+ */
+ evaluateIsValid : function()
+ {
+ var value = this.getValidationValue();
+ if(value.length <= 0)
+ return true;
+ if(typeof(this.options.DataType) == "undefined")
+ this.options.DataType = "String";
+
+ if(this.options.DataType != "StringLength")
+ {
+ var min = this.convert(this.options.DataType, this.options.MinValue || null);
+ var max = this.convert(this.options.DataType, this.options.MaxValue || null);
+ value = this.convert(this.options.DataType, value);
+ }
+ else
+ {
+ var min = this.options.MinValue || 0;
+ var max = this.options.MaxValue || Number.POSITIVE_INFINITY;
+ value = value.length;
+ }
+
+ if(value == null)
+ return false;
+
+ var valid = true;
+
+ if(min != null)
+ valid = valid && (this.options.StrictComparison ? value > min : value >= min);
+ if(max != null)
+ valid = valid && (this.options.StrictComparison ? value < max : value <= max);
+ return valid;
+ }
+});
+
+/**
+ * TRegularExpressionValidator validates whether the value of an associated
+ * input component matches the pattern specified by a regular expression.
+ *
+ * @class Prado.WebUI.TRegularExpressionValidator
+ * @extends Prado.WebUI.TBaseValidator
+ */
+Prado.WebUI.TRegularExpressionValidator = Class.extend(Prado.WebUI.TBaseValidator,
+{
+ /**
+ * Additional constructor option.
+ * @constructor initialize
+ * @param {object} options - Additional constructor option:
+ * @... {string} ValidationExpression - Regular expression to match against.
+ * @... {string} PatternModifiers - Pattern modifiers: combinations of g, i, and m
+ */
+
+ /**
+ * Evaluate validation state
+ * @function {boolean} ?
+ * @return True if value matches regular expression or value is empty.
+ */
+ evaluateIsValid : function()
+ {
+ var value = this.getRawValidationValue();
+ if (value.length <= 0)
+ return true;
+
+ var rx = new RegExp('^'+this.options.ValidationExpression+'$',this.options.PatternModifiers);
+ var matches = rx.exec(value);
+ return (matches != null && value == matches[0]);
+ }
+});
+
+/**
+ * TEmailAddressValidator validates whether the value of an associated
+ * input component is a valid email address.
+ *
+ * @class Prado.WebUI.TEmailAddressValidator
+ * @extends Prado.WebUI.TRegularExpressionValidator
+ */
+Prado.WebUI.TEmailAddressValidator = Prado.WebUI.TRegularExpressionValidator;
+
+
+/**
+ * TListControlValidator checks the number of selection and their values
+ * for a TListControl that allows multiple selections.
+ *
+ * @class Prado.WebUI.TListControlValidator
+ * @extends Prado.WebUI.TBaseValidator
+ */
+Prado.WebUI.TListControlValidator = Class.extend(Prado.WebUI.TBaseValidator,
+{
+ /**
+ * Evaluate validation state
+ * @function {boolean} ?
+ * @return True if number of selections and/or their values match requirements.
+ */
+ evaluateIsValid : function()
+ {
+ var elements = this.getListElements();
+ if(elements && elements.length <= 0)
+ return true;
+
+ this.observeListElements(elements);
+
+ var selection = this.getSelectedValuesAndChecks(elements);
+ return this.isValidList(selection.checks, selection.values);
+ },
+
+ /**
+ * Observe list elements for of changes (only IE)
+ * @function ?
+ * @param {element[]} elements - Array of DOM elements to observe
+ */
+ observeListElements : function(elements)
+ {
+ if(Prado.Browser().ie && this.isCheckBoxType(elements[0]))
+ {
+ var validator = this;
+ elements.each(function(element)
+ {
+ validator.observeChanges(element);
+ });
+ }
+ },
+
+ /**
+ * Check if list is valid.
+ * Determine if the number of checked values and the checked values
+ * satisfy the required number of checks and/or the checked values
+ * equal to the required values.
+ * @function {boolean} ?
+ * @param {int} checked - Number of required checked values
+ * @param {string[]} values - Array of required checked values
+ * @return True if checked values and number of checks are satisfied.
+ */
+ isValidList : function(checked, values)
+ {
+ var exists = true;
+
+ //check the required values
+ var required = this.getRequiredValues();
+ if(required.length > 0)
+ {
+ if(values.length < required.length)
+ return false;
+ required.each(function(requiredValue)
+ {
+ exists = exists && values.include(requiredValue);
+ });
+ }
+
+ var min = typeof(this.options.Min) == "undefined" ?
+ Number.NEGATIVE_INFINITY : this.options.Min;
+ var max = typeof(this.options.Max) == "undefined" ?
+ Number.POSITIVE_INFINITY : this.options.Max;
+ return exists && checked >= min && checked <= max;
+ },
+
+ /**
+ * Get list of required values.
+ * @function {string[]} ?
+ * @return Array of required values that must be selected.
+ */
+ getRequiredValues : function()
+ {
+ var required = [];
+ if(this.options.Required && this.options.Required.length > 0)
+ required = this.options.Required.split(/,\s*/);
+ return required;
+ }
+});
+
+
+/**
+ * TDataTypeValidator verifies if the input data is of the type specified
+ * by <tt>DataType</tt> option.
+ *
+ * <p>The following data types are supported:</p>
+ *
+ * - <b>Integer</b> A 32-bit signed integer data type.<br />
+ * - <b>Float</b> A double-precision floating point number data type.<br />
+ * - <b>Date</b> A date data type.<br />
+ * - <b>String</b> A string data type.<br />
+ *
+ * <p>For <b>Date</b> type, the option <tt>DateFormat</tt>
+ * will be used to determine how to parse the date string.</p>
+ *
+ * @class Prado.WebUI.TDataTypeValidator
+ * @extends Prado.WebUI.TBaseValidator
+ */
+Prado.WebUI.TDataTypeValidator = Class.extend(Prado.WebUI.TBaseValidator,
+{
+ /**
+ * Additional constructor option.
+ * @constructor initialize
+ * @param {object} options - Additional constructor option:
+ * @... {string} DataType - Value data type: "Integer", "Float", "Date" or "String"
+ * @... {string} DateFormat - Date format for data type Date.
+ */
+
+ /**
+ * Evaluate validation state
+ * @function {boolean} ?
+ * @return True if value matches required data type.
+ */
+ evaluateIsValid : function()
+ {
+ var value = this.getValidationValue();
+ if(value.length <= 0)
+ return true;
+ return this.convert(this.options.DataType, value) != null;
+ }
+});
+
+/**
+ * TCaptchaValidator verifies if the input data is the same as
+ * the token shown in the associated CAPTCHA control.
+ *
+ * @class Prado.WebUI.TCaptchaValidator
+ * @extends Prado.WebUI.TBaseValidator
+ */
+Prado.WebUI.TCaptchaValidator = Class.extend(Prado.WebUI.TBaseValidator,
+{
+ /**
+ * Evaluate validation state
+ * @function {boolean} ?
+ * @return True if value matches captcha text
+ */
+ evaluateIsValid : function()
+ {
+ var a = this.getValidationValue();
+ var h = 0;
+ if (this.options.CaseSensitive==false)
+ a = a.toUpperCase();
+ for(var i = a.length-1; i >= 0; --i)
+ h += a.charCodeAt(i);
+ return h == this.options.TokenHash;
+ },
+
+ crc32 : function(str)
+ {
+ function Utf8Encode(string)
+ {
+ string = string.replace(/\r\n/g,"\n");
+ var utftext = "";
+
+ for (var n = 0; n < string.length; n++)
+ {
+ var c = string.charCodeAt(n);
+
+ if (c < 128) {
+ utftext += String.fromCharCode(c);
+ }
+ else if((c > 127) && (c < 2048)) {
+ utftext += String.fromCharCode((c >> 6) | 192);
+ utftext += String.fromCharCode((c & 63) | 128);
+ }
+ else {
+ utftext += String.fromCharCode((c >> 12) | 224);
+ utftext += String.fromCharCode(((c >> 6) & 63) | 128);
+ utftext += String.fromCharCode((c & 63) | 128);
+ }
+ }
+
+ return utftext;
+ };
+
+ str = Utf8Encode(str);
+
+ var table = "00000000 77073096 EE0E612C 990951BA 076DC419 706AF48F E963A535 9E6495A3 0EDB8832 79DCB8A4 E0D5E91E 97D2D988 09B64C2B 7EB17CBD E7B82D07 90BF1D91 1DB71064 6AB020F2 F3B97148 84BE41DE 1ADAD47D 6DDDE4EB F4D4B551 83D385C7 136C9856 646BA8C0 FD62F97A 8A65C9EC 14015C4F 63066CD9 FA0F3D63 8D080DF5 3B6E20C8 4C69105E D56041E4 A2677172 3C03E4D1 4B04D447 D20D85FD A50AB56B 35B5A8FA 42B2986C DBBBC9D6 ACBCF940 32D86CE3 45DF5C75 DCD60DCF ABD13D59 26D930AC 51DE003A C8D75180 BFD06116 21B4F4B5 56B3C423 CFBA9599 B8BDA50F 2802B89E 5F058808 C60CD9B2 B10BE924 2F6F7C87 58684C11 C1611DAB B6662D3D 76DC4190 01DB7106 98D220BC EFD5102A 71B18589 06B6B51F 9FBFE4A5 E8B8D433 7807C9A2 0F00F934 9609A88E E10E9818 7F6A0DBB 086D3D2D 91646C97 E6635C01 6B6B51F4 1C6C6162 856530D8 F262004E 6C0695ED 1B01A57B 8208F4C1 F50FC457 65B0D9C6 12B7E950 8BBEB8EA FCB9887C 62DD1DDF 15DA2D49 8CD37CF3 FBD44C65 4DB26158 3AB551CE A3BC0074 D4BB30E2 4ADFA541 3DD895D7 A4D1C46D D3D6F4FB 4369E96A 346ED9FC AD678846 DA60B8D0 44042D73 33031DE5 AA0A4C5F DD0D7CC9 5005713C 270241AA BE0B1010 C90C2086 5768B525 206F85B3 B966D409 CE61E49F 5EDEF90E 29D9C998 B0D09822 C7D7A8B4 59B33D17 2EB40D81 B7BD5C3B C0BA6CAD EDB88320 9ABFB3B6 03B6E20C 74B1D29A EAD54739 9DD277AF 04DB2615 73DC1683 E3630B12 94643B84 0D6D6A3E 7A6A5AA8 E40ECF0B 9309FF9D 0A00AE27 7D079EB1 F00F9344 8708A3D2 1E01F268 6906C2FE F762575D 806567CB 196C3671 6E6B06E7 FED41B76 89D32BE0 10DA7A5A 67DD4ACC F9B9DF6F 8EBEEFF9 17B7BE43 60B08ED5 D6D6A3E8 A1D1937E 38D8C2C4 4FDFF252 D1BB67F1 A6BC5767 3FB506DD 48B2364B D80D2BDA AF0A1B4C 36034AF6 41047A60 DF60EFC3 A867DF55 316E8EEF 4669BE79 CB61B38C BC66831A 256FD2A0 5268E236 CC0C7795 BB0B4703 220216B9 5505262F C5BA3BBE B2BD0B28 2BB45A92 5CB36A04 C2D7FFA7 B5D0CF31 2CD99E8B 5BDEAE1D 9B64C2B0 EC63F226 756AA39C 026D930A 9C0906A9 EB0E363F 72076785 05005713 95BF4A82 E2B87A14 7BB12BAE 0CB61B38 92D28E9B E5D5BE0D 7CDCEFB7 0BDBDF21 86D3D2D4 F1D4E242 68DDB3F8 1FDA836E 81BE16CD F6B9265B 6FB077E1 18B74777 88085AE6 FF0F6A70 66063BCA 11010B5C 8F659EFF F862AE69 616BFFD3 166CCF45 A00AE278 D70DD2EE 4E048354 3903B3C2 A7672661 D06016F7 4969474D 3E6E77DB AED16A4A D9D65ADC 40DF0B66 37D83BF0 A9BCAE53 DEBB9EC5 47B2CF7F 30B5FFE9 BDBDF21C CABAC28A 53B39330 24B4A3A6 BAD03605 CDD70693 54DE5729 23D967BF B3667A2E C4614AB8 5D681B02 2A6F2B94 B40BBE37 C30C8EA1 5A05DF1B 2D02EF8D";
+ var crc = 0;
+ var x = 0;
+ var y = 0;
+
+ crc = crc ^ (-1);
+ for( var i = 0, iTop = str.length; i < iTop; i++ )
+ {
+ y = ( crc ^ str.charCodeAt( i ) ) & 0xFF;
+ x = "0x" + table.substr( y * 9, 8 );
+ crc = ( crc >>> 8 ) ^ x;
+ }
+ return crc ^ (-1);
+ }
+});
+
+
+/**
+ * TReCaptchaValidator client-side control.
+ *
+ * @class Prado.WebUI.TReCaptchaValidator
+ * @extends Prado.WebUI.TBaseValidator
+ */
+Prado.WebUI.TReCaptchaValidator = Class.create(Prado.WebUI.TBaseValidator,
+{
+ onInit : function()
+ {
+ var obj = this;
+ var elements = document.getElementsByName(this.options.ResponseFieldName);
+ if (elements)
+ if (elements.length>=1)
+ {
+ this.observe(elements[0],'change',function() { obj.responseChanged() });
+ this.observe(elements[0],'keydown',function() { obj.responseChanged() });
+ }
+ },
+
+ responseChanged: function()
+ {
+ var field = $(this.options.ID+'_1');
+ if (field.value=='1') return;
+ field.value = '1';
+ Prado.Validation.validateControl(this.options.ID);
+ },
+
+ /**
+ * Evaluate validation state
+ * @function {boolean} ?
+ * @return True if the captcha has validate, False otherwise.
+ */
+ evaluateIsValid : function()
+ {
+ return ($(this.options.ID+'_1').value=='1');
+ }
+});
+
diff --git a/framework/Web/Services/TFeedService.php b/framework/Web/Services/TFeedService.php
index ab1b9c35..4f757d8f 100644
--- a/framework/Web/Services/TFeedService.php
+++ b/framework/Web/Services/TFeedService.php
@@ -1,187 +1,187 @@
-<?php
-/**
- * TFeedService and TFeed class file
- *
- * @author Qiang Xue <qiang.xue@gmail.com>
- * @author Knut Urdalen <knut.urdalen@gmail.com>
- * @link http://www.pradosoft.com
- * @copyright Copyright &copy; 2005-2012 PradoSoft
- * @license http://www.pradosoft.com/license/
- * @version $Id$
- * @package System.Web.Services
- */
-
-/**
- * TFeedService class
- *
- * TFeedService provides to end-users feed content.
- *
- * TFeedService manages a set of feeds. The service parameter, referring
- * to the ID of the feed, specifies which feed content to be provided to end-users.
- *
- * To use TFeedService, configure it in application configuration as follows,
- * <code>
- * <service id="feed" class="System.Web.Services.TFeedService">
- * <feed id="ch1" class="Path.To.FeedClass1" .../>
- * <feed id="ch2" class="Path.To.FeedClass2" .../>
- * <feed id="ch3" class="Path.To.FeedClass3" .../>
- * </service>
- * </code>
- * where each &lt;feed&gt; element specifies a feed identified by its "id" value (case-sensitive).
- *
- * PHP configuration style:
- * <code>
- * array(
- * 'feed' => array(
- * 'ch1' => array(
- * 'class' => 'Path.To.FeedClass1',
- * 'properties' => array(
- * ...
- * ),
- * ),
- * )
- * </code>
- *
- * The class attribute indicates which PHP class will provide the actual feed
- * content. Note, the class must implement {@link IFeedContentProvider} interface.
- * Other initial properties for the feed class may also be specified in the
- * corresponding &lt;feed&gt; element.
- *
- * To retrieve the feed content identified by "ch2", use the URL
- * <code>/path/to/index.php?feed=ch2</code>
- *
- * @author Qiang Xue <qiang.xue@gmail.com>
- * @author Knut Urdalen <knut.urdalen@gmail.com>
- * @author Carl G. Mathisen <carlgmathisen@gmail.com>
- * @package System.Web.Services
- * @since 3.1
- */
-class TFeedService extends TService
-{
- private $_feeds=array();
-
- /**
- * Initializes this module.
- * This method is required by the IModule interface.
- * @param mixed configuration for this module, can be null
- */
- public function init($config)
- {
- if($this->getApplication()->getConfigurationType()==TApplication::CONFIG_TYPE_PHP)
- {
- if(is_array($config))
- {
- foreach($config as $id => $feed)
- $this->_feeds[$id] = $feed;
- }
- }
- else
- {
- foreach($config->getElementsByTagName('feed') as $feed)
- {
- if(($id=$feed->getAttributes()->remove('id'))!==null)
- $this->_feeds[$id]=$feed;
- else
- throw new TConfigurationException('feedservice_id_required');
- }
- }
- }
-
- /**
- * @return string the requested feed path
- */
- protected function determineRequestedFeedPath()
- {
- return $this->getRequest()->getServiceParameter();
- }
-
- /**
- * Runs the service.
- * This method is invoked by application automatically.
- */
- public function run()
- {
- $id=$this->getRequest()->getServiceParameter();
- if(isset($this->_feeds[$id]))
- {
- $feedConfig=$this->_feeds[$id];
- $properties = array();
- $feed = null;
- if($this->getApplication()->getConfigurationType()==TApplication::CONFIG_TYPE_PHP)
- {
- if(isset($feedConfig['class']))
- {
- $feed=Prado::createComponent($feedConfig['class']);
- if($service instanceof IFeedContentProvider)
- $properties=isset($feedConfig['properties'])?$feedConfig['properties']:array();
- else
- throw new TConfigurationException('jsonservice_response_type_invalid',$id);
- }
- else
- throw new TConfigurationException('jsonservice_class_required',$id);
- }
- else
- {
- $properties=$feedConfig->getAttributes();
- if(($class=$properties->remove('class'))!==null)
- {
- $feed=Prado::createComponent($class);
- if(!($feed instanceof IFeedContentProvider))
- throw new TConfigurationException('feedservice_feedtype_invalid',$id);
- }
- else
- throw new TConfigurationException('feedservice_class_required',$id);
- }
-
- // init feed properties
- foreach($properties as $name=>$value)
- $feed->setSubproperty($name,$value);
- $feed->init($feedConfig);
-
- $content=$feed->getFeedContent();
- //$this->getResponse()->setContentType('application/rss+xml');
- $this->getResponse()->setContentType($feed->getContentType());
- $this->getResponse()->write($content);
- }
- else
- throw new THttpException(404,'feedservice_feed_unknown',$id);
- }
-}
-
-/**
- * IFeedContentProvider interface.
- *
- * IFeedContentProvider interface must be implemented by a feed class who
- * provides feed content.
- *
- * @author Qiang Xue <qiang.xue@gmail.com>
- * @author Knut Urdalen <knut.urdalen@gmail.com>
- * @package System.Web.Services
- * @since 3.1
- */
-interface IFeedContentProvider
-{
- /**
- * Initializes the feed content provider.
- * This method is invoked (before {@link getFeedContent})
- * when the feed provider is requested by a user.
- * @param TXmlElement configurations specified within the &lt;feed&gt; element
- * corresponding to this feed provider when configuring {@link TFeedService}.
- */
- public function init($config);
- /**
- * @return string feed content in proper XML format
- */
- public function getFeedContent();
- /**
- * Sets the content type of the feed content to be sent.
- * Some examples are:
- * RSS 1.0 feed: application/rdf+xml
- * RSS 2.0 feed: application/rss+xml or application/xml or text/xml
- * ATOM feed: application/atom+xml
- * @return string the content type for the feed content.
- * @since 3.1.1
- */
- public function getContentType();
-}
-
+<?php
+/**
+ * TFeedService and TFeed class file
+ *
+ * @author Qiang Xue <qiang.xue@gmail.com>
+ * @author Knut Urdalen <knut.urdalen@gmail.com>
+ * @link http://www.pradosoft.com
+ * @copyright Copyright &copy; 2005-2012 PradoSoft
+ * @license http://www.pradosoft.com/license/
+ * @version $Id$
+ * @package System.Web.Services
+ */
+
+/**
+ * TFeedService class
+ *
+ * TFeedService provides to end-users feed content.
+ *
+ * TFeedService manages a set of feeds. The service parameter, referring
+ * to the ID of the feed, specifies which feed content to be provided to end-users.
+ *
+ * To use TFeedService, configure it in application configuration as follows,
+ * <code>
+ * <service id="feed" class="System.Web.Services.TFeedService">
+ * <feed id="ch1" class="Path.To.FeedClass1" .../>
+ * <feed id="ch2" class="Path.To.FeedClass2" .../>
+ * <feed id="ch3" class="Path.To.FeedClass3" .../>
+ * </service>
+ * </code>
+ * where each &lt;feed&gt; element specifies a feed identified by its "id" value (case-sensitive).
+ *
+ * PHP configuration style:
+ * <code>
+ * array(
+ * 'feed' => array(
+ * 'ch1' => array(
+ * 'class' => 'Path.To.FeedClass1',
+ * 'properties' => array(
+ * ...
+ * ),
+ * ),
+ * )
+ * </code>
+ *
+ * The class attribute indicates which PHP class will provide the actual feed
+ * content. Note, the class must implement {@link IFeedContentProvider} interface.
+ * Other initial properties for the feed class may also be specified in the
+ * corresponding &lt;feed&gt; element.
+ *
+ * To retrieve the feed content identified by "ch2", use the URL
+ * <code>/path/to/index.php?feed=ch2</code>
+ *
+ * @author Qiang Xue <qiang.xue@gmail.com>
+ * @author Knut Urdalen <knut.urdalen@gmail.com>
+ * @author Carl G. Mathisen <carlgmathisen@gmail.com>
+ * @package System.Web.Services
+ * @since 3.1
+ */
+class TFeedService extends TService
+{
+ private $_feeds=array();
+
+ /**
+ * Initializes this module.
+ * This method is required by the IModule interface.
+ * @param mixed configuration for this module, can be null
+ */
+ public function init($config)
+ {
+ if($this->getApplication()->getConfigurationType()==TApplication::CONFIG_TYPE_PHP)
+ {
+ if(is_array($config))
+ {
+ foreach($config as $id => $feed)
+ $this->_feeds[$id] = $feed;
+ }
+ }
+ else
+ {
+ foreach($config->getElementsByTagName('feed') as $feed)
+ {
+ if(($id=$feed->getAttributes()->remove('id'))!==null)
+ $this->_feeds[$id]=$feed;
+ else
+ throw new TConfigurationException('feedservice_id_required');
+ }
+ }
+ }
+
+ /**
+ * @return string the requested feed path
+ */
+ protected function determineRequestedFeedPath()
+ {
+ return $this->getRequest()->getServiceParameter();
+ }
+
+ /**
+ * Runs the service.
+ * This method is invoked by application automatically.
+ */
+ public function run()
+ {
+ $id=$this->getRequest()->getServiceParameter();
+ if(isset($this->_feeds[$id]))
+ {
+ $feedConfig=$this->_feeds[$id];
+ $properties = array();
+ $feed = null;
+ if($this->getApplication()->getConfigurationType()==TApplication::CONFIG_TYPE_PHP)
+ {
+ if(isset($feedConfig['class']))
+ {
+ $feed=Prado::createComponent($feedConfig['class']);
+ if($service instanceof IFeedContentProvider)
+ $properties=isset($feedConfig['properties'])?$feedConfig['properties']:array();
+ else
+ throw new TConfigurationException('jsonservice_response_type_invalid',$id);
+ }
+ else
+ throw new TConfigurationException('jsonservice_class_required',$id);
+ }
+ else
+ {
+ $properties=$feedConfig->getAttributes();
+ if(($class=$properties->remove('class'))!==null)
+ {
+ $feed=Prado::createComponent($class);
+ if(!($feed instanceof IFeedContentProvider))
+ throw new TConfigurationException('feedservice_feedtype_invalid',$id);
+ }
+ else
+ throw new TConfigurationException('feedservice_class_required',$id);
+ }
+
+ // init feed properties
+ foreach($properties as $name=>$value)
+ $feed->setSubproperty($name,$value);
+ $feed->init($feedConfig);
+
+ $content=$feed->getFeedContent();
+ //$this->getResponse()->setContentType('application/rss+xml');
+ $this->getResponse()->setContentType($feed->getContentType());
+ $this->getResponse()->write($content);
+ }
+ else
+ throw new THttpException(404,'feedservice_feed_unknown',$id);
+ }
+}
+
+/**
+ * IFeedContentProvider interface.
+ *
+ * IFeedContentProvider interface must be implemented by a feed class who
+ * provides feed content.
+ *
+ * @author Qiang Xue <qiang.xue@gmail.com>
+ * @author Knut Urdalen <knut.urdalen@gmail.com>
+ * @package System.Web.Services
+ * @since 3.1
+ */
+interface IFeedContentProvider
+{
+ /**
+ * Initializes the feed content provider.
+ * This method is invoked (before {@link getFeedContent})
+ * when the feed provider is requested by a user.
+ * @param TXmlElement configurations specified within the &lt;feed&gt; element
+ * corresponding to this feed provider when configuring {@link TFeedService}.
+ */
+ public function init($config);
+ /**
+ * @return string feed content in proper XML format
+ */
+ public function getFeedContent();
+ /**
+ * Sets the content type of the feed content to be sent.
+ * Some examples are:
+ * RSS 1.0 feed: application/rdf+xml
+ * RSS 2.0 feed: application/rss+xml or application/xml or text/xml
+ * ATOM feed: application/atom+xml
+ * @return string the content type for the feed content.
+ * @since 3.1.1
+ */
+ public function getContentType();
+}
+
diff --git a/framework/Web/Services/TJsonService.php b/framework/Web/Services/TJsonService.php
index 13710101..b4e87e27 100644
--- a/framework/Web/Services/TJsonService.php
+++ b/framework/Web/Services/TJsonService.php
@@ -1,213 +1,213 @@
-<?php
-/**
- * TJsonService and TJsonResponse class file.
- *
- * @author Wei Zhuo <weizhuo[at]gamil[dot]com>
- * @link http://www.pradosoft.com/
- * @copyright Copyright &copy; 2005-2012 PradoSoft
- * @license http://www.pradosoft.com/license/
- * @version $Id$
- * @package System.Web.Services
- */
-
-/**
- * TJsonService class provides to end-users javascript content response in
- * JSON format.
- *
- * TJsonService manages a set of {@link TJsonResponse}, each
- * representing specific response with javascript content.
- * The service parameter, referring to the ID of the service, specifies
- * which javascript content to be provided to end-users.
- *
- * To use TJsonService, configure it in application configuration as follows,
- * <code>
- * <service id="json" class="System.Web.Services.TJsonService">
- * <json id="get_article" class="Path.To.JsonResponseClass1" .../>
- * <json id="register_rating" class="Path.To.JsonResponseClass2" .../>
- * </service>
- * </code>
- * where each JSON response is specified via a &lt;json&gt; element.
- * Initial property values can be configured in a &lt;json&gt; element.
- *
- *
- * PHP configuration style:
- * <code>
- * 'services' => array(
- * 'get_article' => array(
- * 'class' => 'Path.To.JsonResponseClass1',
- * 'properties' => array(
- * ...
- * )
- * )
- * )
- * </code>
- *
- * To retrieve the JSON content provided by "get_article", use the URL
- * <code>index.php?json=get_article</code>
- *
- * @author Wei Zhuo <weizhuo[at]gmail[dot]com>
- * @author Carl G. Mathisen <carlgmathisen@gmail.com>
- * @version $Id$
- * @package System.Web.Services
- * @since 3.1
- */
-class TJsonService extends TService
-{
- /**
- * @var array registered services
- */
- private $_services=array();
-
- /**
- * Initializes this module.
- * This method is required by the IModule interface.
- * @param mixed configuration for this module, can be null
- */
- public function init($xml)
- {
- $this->loadJsonServices($xml);
- }
-
- /**
- * Load the service definitions.
- * @param mixed configuration for this module, can be null
- */
- protected function loadJsonServices($config)
- {
- if($this->getApplication()->getConfigurationType()==TApplication::CONFIG_TYPE_PHP)
- {
- if(is_array($config))
- {
- foreach($config['json'] as $id => $json)
- $this->_services[$id] = $json;
- }
- }
- else
- {
- foreach($config->getElementsByTagName('json') as $json)
- {
- if(($id=$json->getAttribute('id'))!==null)
- $this->_services[$id]=$json;
- else
- throw new TConfigurationException('jsonservice_id_required');
- }
- }
- }
-
- /**
- * Runs the service.
- * This method is invoked by application automatically.
- */
- public function run()
- {
- $id=$this->getRequest()->getServiceParameter();
- if(isset($this->_services[$id]))
- {
- $serviceConfig=$this->_services[$id];
- if($this->getApplication()->getConfigurationType()==TApplication::CONFIG_TYPE_PHP)
- {
- if(isset($serviceConfig['class']))
- {
- $service=Prado::createComponent($serviceConfig['class']);
- if($service instanceof TJsonResponse)
- {
- $properties = isset($serviceConfig['properties'])?$serviceConfig['properties']:array();
- $this->createJsonResponse($service,$properties,$serviceConfig);
- }
- else
- throw new TConfigurationException('jsonservice_response_type_invalid',$id);
- }
- else
- throw new TConfigurationException('jsonservice_class_required',$id);
- }
- else
- {
- $properties=$serviceConfig->getAttributes();
- if(($class=$properties->remove('class'))!==null)
- {
- $service=Prado::createComponent($class);
- if($service instanceof TJsonResponse)
- $this->createJsonResponse($service,$properties,$serviceConfig);
- else
- throw new TConfigurationException('jsonservice_response_type_invalid',$id);
- }
- else
- throw new TConfigurationException('jsonservice_class_required',$id);
- }
- }
- else
- throw new THttpException(404,'jsonservice_provider_unknown',$id);
- }
-
- /**
- * Renders content provided by TJsonResponse::getJsonContent() as
- * javascript in JSON format.
- */
- protected function createJsonResponse($service,$properties,$config)
- {
- // init service properties
- foreach($properties as $name=>$value)
- $service->setSubproperty($name,$value);
- $service->init($config);
-
- //send content if not null
- if(($content=$service->getJsonContent())!==null)
- {
- $response = $this->getResponse();
- $response->setContentType('text/javascript');
- $response->setCharset('UTF-8');
- //send content
- $response->write(TJavaScript::jsonEncode($content));
- }
- }
-}
-
-/**
- * TJsonResponse Class
- *
- * TJsonResponse is the base class for all JSON response provider classes.
- *
- * Derived classes must implement {@link getJsonContent()} to return
- * an object or literals to be converted to JSON format. The response
- * will be empty if the returned content is null.
- *
- * @author Wei Zhuo <weizhuo[at]gmail[dot]com>
- * @version $Id$
- * @package System.Web.Services
- * @since 3.1
- */
-abstract class TJsonResponse extends TApplicationComponent
-{
- private $_id='';
-
- /**
- * Initializes the feed.
- * @param TXmlElement configurations specified in {@link TJsonService}.
- */
- public function init($config)
- {
- }
-
- /**
- * @return string ID of this response
- */
- public function getID()
- {
- return $this->_id;
- }
-
- /**
- * @param string ID of this response
- */
- public function setID($value)
- {
- $this->_id=$value;
- }
-
- /**
- * @return object json response content, null to suppress output.
- */
- abstract public function getJsonContent();
-}
-
-?>
+<?php
+/**
+ * TJsonService and TJsonResponse class file.
+ *
+ * @author Wei Zhuo <weizhuo[at]gamil[dot]com>
+ * @link http://www.pradosoft.com/
+ * @copyright Copyright &copy; 2005-2012 PradoSoft
+ * @license http://www.pradosoft.com/license/
+ * @version $Id$
+ * @package System.Web.Services
+ */
+
+/**
+ * TJsonService class provides to end-users javascript content response in
+ * JSON format.
+ *
+ * TJsonService manages a set of {@link TJsonResponse}, each
+ * representing specific response with javascript content.
+ * The service parameter, referring to the ID of the service, specifies
+ * which javascript content to be provided to end-users.
+ *
+ * To use TJsonService, configure it in application configuration as follows,
+ * <code>
+ * <service id="json" class="System.Web.Services.TJsonService">
+ * <json id="get_article" class="Path.To.JsonResponseClass1" .../>
+ * <json id="register_rating" class="Path.To.JsonResponseClass2" .../>
+ * </service>
+ * </code>
+ * where each JSON response is specified via a &lt;json&gt; element.
+ * Initial property values can be configured in a &lt;json&gt; element.
+ *
+ *
+ * PHP configuration style:
+ * <code>
+ * 'services' => array(
+ * 'get_article' => array(
+ * 'class' => 'Path.To.JsonResponseClass1',
+ * 'properties' => array(
+ * ...
+ * )
+ * )
+ * )
+ * </code>
+ *
+ * To retrieve the JSON content provided by "get_article", use the URL
+ * <code>index.php?json=get_article</code>
+ *
+ * @author Wei Zhuo <weizhuo[at]gmail[dot]com>
+ * @author Carl G. Mathisen <carlgmathisen@gmail.com>
+ * @version $Id$
+ * @package System.Web.Services
+ * @since 3.1
+ */
+class TJsonService extends TService
+{
+ /**
+ * @var array registered services
+ */
+ private $_services=array();
+
+ /**
+ * Initializes this module.
+ * This method is required by the IModule interface.
+ * @param mixed configuration for this module, can be null
+ */
+ public function init($xml)
+ {
+ $this->loadJsonServices($xml);
+ }
+
+ /**
+ * Load the service definitions.
+ * @param mixed configuration for this module, can be null
+ */
+ protected function loadJsonServices($config)
+ {
+ if($this->getApplication()->getConfigurationType()==TApplication::CONFIG_TYPE_PHP)
+ {
+ if(is_array($config))
+ {
+ foreach($config['json'] as $id => $json)
+ $this->_services[$id] = $json;
+ }
+ }
+ else
+ {
+ foreach($config->getElementsByTagName('json') as $json)
+ {
+ if(($id=$json->getAttribute('id'))!==null)
+ $this->_services[$id]=$json;
+ else
+ throw new TConfigurationException('jsonservice_id_required');
+ }
+ }
+ }
+
+ /**
+ * Runs the service.
+ * This method is invoked by application automatically.
+ */
+ public function run()
+ {
+ $id=$this->getRequest()->getServiceParameter();
+ if(isset($this->_services[$id]))
+ {
+ $serviceConfig=$this->_services[$id];
+ if($this->getApplication()->getConfigurationType()==TApplication::CONFIG_TYPE_PHP)
+ {
+ if(isset($serviceConfig['class']))
+ {
+ $service=Prado::createComponent($serviceConfig['class']);
+ if($service instanceof TJsonResponse)
+ {
+ $properties = isset($serviceConfig['properties'])?$serviceConfig['properties']:array();
+ $this->createJsonResponse($service,$properties,$serviceConfig);
+ }
+ else
+ throw new TConfigurationException('jsonservice_response_type_invalid',$id);
+ }
+ else
+ throw new TConfigurationException('jsonservice_class_required',$id);
+ }
+ else
+ {
+ $properties=$serviceConfig->getAttributes();
+ if(($class=$properties->remove('class'))!==null)
+ {
+ $service=Prado::createComponent($class);
+ if($service instanceof TJsonResponse)
+ $this->createJsonResponse($service,$properties,$serviceConfig);
+ else
+ throw new TConfigurationException('jsonservice_response_type_invalid',$id);
+ }
+ else
+ throw new TConfigurationException('jsonservice_class_required',$id);
+ }
+ }
+ else
+ throw new THttpException(404,'jsonservice_provider_unknown',$id);
+ }
+
+ /**
+ * Renders content provided by TJsonResponse::getJsonContent() as
+ * javascript in JSON format.
+ */
+ protected function createJsonResponse($service,$properties,$config)
+ {
+ // init service properties
+ foreach($properties as $name=>$value)
+ $service->setSubproperty($name,$value);
+ $service->init($config);
+
+ //send content if not null
+ if(($content=$service->getJsonContent())!==null)
+ {
+ $response = $this->getResponse();
+ $response->setContentType('text/javascript');
+ $response->setCharset('UTF-8');
+ //send content
+ $response->write(TJavaScript::jsonEncode($content));
+ }
+ }
+}
+
+/**
+ * TJsonResponse Class
+ *
+ * TJsonResponse is the base class for all JSON response provider classes.
+ *
+ * Derived classes must implement {@link getJsonContent()} to return
+ * an object or literals to be converted to JSON format. The response
+ * will be empty if the returned content is null.
+ *
+ * @author Wei Zhuo <weizhuo[at]gmail[dot]com>
+ * @version $Id$
+ * @package System.Web.Services
+ * @since 3.1
+ */
+abstract class TJsonResponse extends TApplicationComponent
+{
+ private $_id='';
+
+ /**
+ * Initializes the feed.
+ * @param TXmlElement configurations specified in {@link TJsonService}.
+ */
+ public function init($config)
+ {
+ }
+
+ /**
+ * @return string ID of this response
+ */
+ public function getID()
+ {
+ return $this->_id;
+ }
+
+ /**
+ * @param string ID of this response
+ */
+ public function setID($value)
+ {
+ $this->_id=$value;
+ }
+
+ /**
+ * @return object json response content, null to suppress output.
+ */
+ abstract public function getJsonContent();
+}
+
+?>
diff --git a/framework/Web/Services/TPageService.php b/framework/Web/Services/TPageService.php
index 4576a080..2d74f2a1 100644
--- a/framework/Web/Services/TPageService.php
+++ b/framework/Web/Services/TPageService.php
@@ -1,893 +1,893 @@
-<?php
-/**
- * TPageService class file.
- *
- * @author Qiang Xue <qiang.xue@gmail.com>
- * @link http://www.pradosoft.com/
- * @copyright Copyright &copy; 2005-2012 PradoSoft
- * @license http://www.pradosoft.com/license/
- * @version $Id$
- * @package System.Web.Services
- */
-
-/**
- * Include classes to be used by page service
- */
-Prado::using('System.Web.UI.TPage');
-Prado::using('System.Web.UI.TTemplateManager');
-Prado::using('System.Web.UI.TThemeManager');
-
-/**
- * TPageService class.
- *
- * TPageService implements the service for serving user page requests.
- *
- * Pages that are available to client users are stored under a directory specified by
- * {@link setBasePath BasePath}. The directory may contain subdirectories.
- * Pages serving for a similar goal are usually placed under the same directory.
- * A directory may contain a configuration file <b>config.xml</b> whose content
- * is similar to that of application configuration file.
- *
- * A page is requested via page path, which is a dot-connected directory names
- * appended by the page name. Assume '<BasePath>/Users/Admin' is the directory
- * containing the page 'Update'. Then the page can be requested via 'Users.Admin.Update'.
- * By default, the {@link setBasePath BasePath} of the page service is the "pages"
- * directory under the application base path. You may change this default
- * by setting {@link setBasePath BasePath} with a different path you prefer.
- *
- * Page name refers to the file name (without extension) of the page template.
- * In order to differentiate from the common control template files, the extension
- * name of the page template files must be '.page'. If there is a PHP file with
- * the same page name under the same directory as the template file, that file
- * will be considered as the page class file and the file name is the page class name.
- * If such a file is not found, the page class is assumed as {@link TPage}.
- *
- * Modules can be configured and loaded in page directory configurations.
- * Configuration of a module in a subdirectory will overwrite its parent
- * directory's configuration, if both configurations refer to the same module.
- *
- * By default, TPageService will automatically load two modules:
- * - {@link TTemplateManager} : manages page and control templates
- * - {@link TThemeManager} : manages themes used in a Prado application
- *
- * In page directory configurations, static authorization rules can also be specified,
- * which governs who and which roles can access particular pages.
- * Refer to {@link TAuthorizationRule} for more details about authorization rules.
- * Page authorization rules can be configured within an <authorization> tag in
- * each page directory configuration as follows,
- * <authorization>
- * <deny pages="Update" users="?" />
- * <allow pages="Admin" roles="administrator" />
- * <deny pages="Admin" users="*" />
- * </authorization>
- * where the 'pages' attribute may be filled with a sequence of comma-separated
- * page IDs. If 'pages' attribute does not appear in a rule, the rule will be
- * applied to all pages in this directory and all subdirectories (recursively).
- * Application of authorization rules are in a bottom-up fashion, starting from
- * the directory containing the requested page up to all parent directories.
- * The first matching rule will be used. The last rule always allows all users
- * accessing to any resources.
- *
- * @author Qiang Xue <qiang.xue@gmail.com>
- * @author Carl G. Mathisen <carlgmathisen@gmail.com>
- * @version $Id$
- * @package System.Web.Services
- * @since 3.0
- */
-class TPageService extends TService
-{
- /**
- * Configuration file name
- */
- const CONFIG_FILE_XML='config.xml';
- /**
- * Configuration file name
- */
- const CONFIG_FILE_PHP='config.php';
- /**
- * Default base path
- */
- const DEFAULT_BASEPATH='Pages';
- /**
- * Fallback base path - used to be the default up to Prado < 3.2
- */
- const FALLBACK_BASEPATH='pages';
- /**
- * Prefix of ID used for storing parsed configuration in cache
- */
- const CONFIG_CACHE_PREFIX='prado:pageservice:';
- /**
- * Page template file extension
- */
- const PAGE_FILE_EXT='.page';
- /**
- * @var string root path of pages
- */
- private $_basePath=null;
- /**
- * @var string base path class in namespace format
- */
- private $_basePageClass='TPage';
- /**
- * @var string clientscript manager class in namespace format
- * @since 3.1.7
- */
- private $_clientScriptManagerClass='System.Web.UI.TClientScriptManager';
- /**
- * @var string default page
- */
- private $_defaultPage='Home';
- /**
- * @var string requested page (path)
- */
- private $_pagePath=null;
- /**
- * @var TPage the requested page
- */
- private $_page=null;
- /**
- * @var array list of initial page property values
- */
- private $_properties=array();
- /**
- * @var boolean whether service is initialized
- */
- private $_initialized=false;
- /**
- * @var TThemeManager theme manager
- */
- private $_themeManager=null;
- /**
- * @var TTemplateManager template manager
- */
- private $_templateManager=null;
-
- /**
- * Initializes the service.
- * This method is required by IService interface and is invoked by application.
- * @param TXmlElement service configuration
- */
- public function init($config)
- {
- Prado::trace("Initializing TPageService",'System.Web.Services.TPageService');
-
- $pageConfig=$this->loadPageConfig($config);
-
- $this->initPageContext($pageConfig);
-
- $this->_initialized=true;
- }
-
- /**
- * Initializes page context.
- * Page context includes path alias settings, namespace usages,
- * parameter initialization, module loadings, page initial properties
- * and authorization rules.
- * @param TPageConfiguration
- */
- protected function initPageContext($pageConfig)
- {
- $application=$this->getApplication();
- foreach($pageConfig->getApplicationConfigurations() as $appConfig)
- $application->applyConfiguration($appConfig);
-
- $this->applyConfiguration($pageConfig);
- }
-
- /**
- * Applies a page configuration.
- * @param TPageConfiguration the configuration
- */
- protected function applyConfiguration($config)
- {
- // initial page properties (to be set when page runs)
- $this->_properties=array_merge($this->_properties, $config->getProperties());
- $this->getApplication()->getAuthorizationRules()->mergeWith($config->getRules());
- $pagePath=$this->getRequestedPagePath();
- // external configurations
- foreach($config->getExternalConfigurations() as $filePath=>$params)
- {
- list($configPagePath,$condition)=$params;
- if($condition!==true)
- $condition=$this->evaluateExpression($condition);
- if($condition)
- {
- if(($path=Prado::getPathOfNamespace($filePath,Prado::getApplication()->getConfigurationFileExt()))===null || !is_file($path))
- throw new TConfigurationException('pageservice_includefile_invalid',$filePath);
- $c=new TPageConfiguration($pagePath);
- $c->loadFromFile($path,$configPagePath);
- $this->applyConfiguration($c);
- }
- }
-
- }
-
- /**
- * Determines the requested page path.
- * @return string page path requested
- */
- protected function determineRequestedPagePath()
- {
- $pagePath=$this->getRequest()->getServiceParameter();
- if(empty($pagePath))
- $pagePath=$this->getDefaultPage();
- return $pagePath;
- }
-
- /**
- * Collects configuration for a page.
- * @param TXmlElement additional configuration specified in the application configuration
- * @return TPageConfiguration
- */
- protected function loadPageConfig($config)
- {
- $application=$this->getApplication();
- $pagePath=$this->getRequestedPagePath();
- if(($cache=$application->getCache())===null)
- {
- $pageConfig=new TPageConfiguration($pagePath);
- if($config!==null)
- {
- if($application->getConfigurationType()==TApplication::CONFIG_TYPE_PHP)
- $pageConfig->loadPageConfigurationFromPhp($config,$application->getBasePath(),'');
- else
- $pageConfig->loadPageConfigurationFromXml($config,$application->getBasePath(),'');
- }
- $pageConfig->loadFromFiles($this->getBasePath());
- }
- else
- {
- $configCached=true;
- $currentTimestamp=array();
- $arr=$cache->get(self::CONFIG_CACHE_PREFIX.$this->getID().$pagePath);
- if(is_array($arr))
- {
- list($pageConfig,$timestamps)=$arr;
- if($application->getMode()!==TApplicationMode::Performance)
- {
- foreach($timestamps as $fileName=>$timestamp)
- {
- if($fileName===0) // application config file
- {
- $appConfigFile=$application->getConfigurationFile();
- $currentTimestamp[0]=$appConfigFile===null?0:@filemtime($appConfigFile);
- if($currentTimestamp[0]>$timestamp || ($timestamp>0 && !$currentTimestamp[0]))
- $configCached=false;
- }
- else
- {
- $currentTimestamp[$fileName]=@filemtime($fileName);
- if($currentTimestamp[$fileName]>$timestamp || ($timestamp>0 && !$currentTimestamp[$fileName]))
- $configCached=false;
- }
- }
- }
- }
- else
- {
- $configCached=false;
- $paths=explode('.',$pagePath);
- $configPath=$this->getBasePath();
- $fileName = $this->getApplication()->getConfigurationType()==TApplication::CONFIG_TYPE_PHP
- ? self::CONFIG_FILE_PHP
- : self::CONFIG_FILE_XML;
- foreach($paths as $path)
- {
- $configFile=$configPath.DIRECTORY_SEPARATOR.$fileName;
- $currentTimestamp[$configFile]=@filemtime($configFile);
- $configPath.=DIRECTORY_SEPARATOR.$path;
- }
- $appConfigFile=$application->getConfigurationFile();
- $currentTimestamp[0]=$appConfigFile===null?0:@filemtime($appConfigFile);
- }
- if(!$configCached)
- {
- $pageConfig=new TPageConfiguration($pagePath);
- if($config!==null)
- {
- if($application->getConfigurationType()==TApplication::CONFIG_TYPE_PHP)
- $pageConfig->loadPageConfigurationFromPhp($config,$application->getBasePath(),'');
- else
- $pageConfig->loadPageConfigurationFromXml($config,$application->getBasePath(),'');
- }
- $pageConfig->loadFromFiles($this->getBasePath());
- $cache->set(self::CONFIG_CACHE_PREFIX.$this->getID().$pagePath,array($pageConfig,$currentTimestamp));
- }
- }
- return $pageConfig;
- }
-
- /**
- * @return TTemplateManager template manager
- */
- public function getTemplateManager()
- {
- if(!$this->_templateManager)
- {
- $this->_templateManager=new TTemplateManager;
- $this->_templateManager->init(null);
- }
- return $this->_templateManager;
- }
-
- /**
- * @param TTemplateManager template manager
- */
- public function setTemplateManager(TTemplateManager $value)
- {
- $this->_templateManager=$value;
- }
-
- /**
- * @return TThemeManager theme manager
- */
- public function getThemeManager()
- {
- if(!$this->_themeManager)
- {
- $this->_themeManager=new TThemeManager;
- $this->_themeManager->init(null);
- }
- return $this->_themeManager;
- }
-
- /**
- * @param TThemeManager theme manager
- */
- public function setThemeManager(TThemeManager $value)
- {
- $this->_themeManager=$value;
- }
-
- /**
- * @return string the requested page path
- */
- public function getRequestedPagePath()
- {
- if($this->_pagePath===null)
- {
- $this->_pagePath=strtr($this->determineRequestedPagePath(),'/\\','..');
- if(empty($this->_pagePath))
- throw new THttpException(404,'pageservice_page_required');
- }
- return $this->_pagePath;
- }
-
- /**
- * @return TPage the requested page
- */
- public function getRequestedPage()
- {
- return $this->_page;
- }
-
- /**
- * @return string default page path to be served if no explicit page is request. Defaults to 'Home'.
- */
- public function getDefaultPage()
- {
- return $this->_defaultPage;
- }
-
- /**
- * @param string default page path to be served if no explicit page is request
- * @throws TInvalidOperationException if the page service is initialized
- */
- public function setDefaultPage($value)
- {
- if($this->_initialized)
- throw new TInvalidOperationException('pageservice_defaultpage_unchangeable');
- else
- $this->_defaultPage=$value;
- }
-
- /**
- * @return string the URL for the default page
- */
- public function getDefaultPageUrl()
- {
- return $this->constructUrl($this->getDefaultPage());
- }
-
- /**
- * @return string the root directory for storing pages. Defaults to the 'pages' directory under the application base path.
- */
- public function getBasePath()
- {
- if($this->_basePath===null)
- {
- $basePath=$this->getApplication()->getBasePath().DIRECTORY_SEPARATOR.self::DEFAULT_BASEPATH;
- if(($this->_basePath=realpath($basePath))===false || !is_dir($this->_basePath))
- {
- $basePath=$this->getApplication()->getBasePath().DIRECTORY_SEPARATOR.self::FALLBACK_BASEPATH;
- if(($this->_basePath=realpath($basePath))===false || !is_dir($this->_basePath))
- throw new TConfigurationException('pageservice_basepath_invalid',$basePath);
- }
- }
- return $this->_basePath;
- }
-
- /**
- * @param string root directory (in namespace form) storing pages
- * @throws TInvalidOperationException if the service is initialized already or basepath is invalid
- */
- public function setBasePath($value)
- {
- if($this->_initialized)
- throw new TInvalidOperationException('pageservice_basepath_unchangeable');
- else if(($path=Prado::getPathOfNamespace($value))===null || !is_dir($path))
- throw new TConfigurationException('pageservice_basepath_invalid',$value);
- $this->_basePath=realpath($path);
- }
-
- /**
- * Sets the base page class name (in namespace format).
- * If a page only has a template file without page class file,
- * this base page class will be instantiated.
- * @param string class name
- */
- public function setBasePageClass($value)
- {
- $this->_basePageClass=$value;
- }
-
- /**
- * @return string base page class name in namespace format. Defaults to 'TPage'.
- */
- public function getBasePageClass()
- {
- return $this->_basePageClass;
- }
-
- /**
- * Sets the clientscript manager class (in namespace format).
- * @param string class name
- * @since 3.1.7
- */
- public function setClientScriptManagerClass($value)
- {
- $this->_clientScriptManagerClass=$value;
- }
-
- /**
- * @return string clientscript manager class in namespace format. Defaults to 'System.Web.UI.TClientScriptManager'.
- * @since 3.1.7
- */
- public function getClientScriptManagerClass()
- {
- return $this->_clientScriptManagerClass;
- }
-
- /**
- * Runs the service.
- * This will create the requested page, initializes it with the property values
- * specified in the configuration, and executes the page.
- */
- public function run()
- {
- Prado::trace("Running page service",'System.Web.Services.TPageService');
- $this->_page=$this->createPage($this->getRequestedPagePath());
- $this->runPage($this->_page,$this->_properties);
- }
-
- /**
- * Creates a page instance based on requested page path.
- * @param string requested page path
- * @return TPage the requested page instance
- * @throws THttpException if requested page path is invalid
- * @throws TConfigurationException if the page class cannot be found
- */
- protected function createPage($pagePath)
- {
- $path=$this->getBasePath().DIRECTORY_SEPARATOR.strtr($pagePath,'.',DIRECTORY_SEPARATOR);
- $hasTemplateFile=is_file($path.self::PAGE_FILE_EXT);
- $hasClassFile=is_file($path.Prado::CLASS_FILE_EXT);
-
- if(!$hasTemplateFile && !$hasClassFile)
- throw new THttpException(404,'pageservice_page_unknown',$pagePath);
-
- if($hasClassFile)
- {
- $className=basename($path);
- if(!class_exists($className,false))
- include_once($path.Prado::CLASS_FILE_EXT);
- }
- else
- {
- $className=$this->getBasePageClass();
- Prado::using($className);
- if(($pos=strrpos($className,'.'))!==false)
- $className=substr($className,$pos+1);
- }
-
- if(!class_exists($className,false) || ($className!=='TPage' && !is_subclass_of($className,'TPage')))
- throw new THttpException(404,'pageservice_page_unknown',$pagePath);
-
- $page=new $className;
- $page->setPagePath($pagePath);
-
- if($hasTemplateFile)
- $page->setTemplate($this->getTemplateManager()->getTemplateByFileName($path.self::PAGE_FILE_EXT));
-
- return $page;
- }
-
- /**
- * Executes a page.
- * @param TPage the page instance to be run
- * @param array list of initial page properties
- */
- protected function runPage($page,$properties)
- {
- foreach($properties as $name=>$value)
- $page->setSubProperty($name,$value);
- $page->run($this->getResponse()->createHtmlWriter());
- }
-
- /**
- * Constructs a URL with specified page path and GET parameters.
- * @param string page path
- * @param array list of GET parameters, null if no GET parameters required
- * @param boolean whether to encode the ampersand in URL, defaults to true.
- * @param boolean whether to encode the GET parameters (their names and values), defaults to true.
- * @return string URL for the page and GET parameters
- */
- public function constructUrl($pagePath,$getParams=null,$encodeAmpersand=true,$encodeGetItems=true)
- {
- return $this->getRequest()->constructUrl($this->getID(),$pagePath,$getParams,$encodeAmpersand,$encodeGetItems);
- }
-}
-
-
-/**
- * TPageConfiguration class
- *
- * TPageConfiguration represents the configuration for a page.
- * The page is specified by a dot-connected path.
- * Configurations along this path are merged together to be provided for the page.
- *
- * @author Qiang Xue <qiang.xue@gmail.com>
- * @version $Id$
- * @package System.Web.Services
- * @since 3.0
- */
-class TPageConfiguration extends TComponent
-{
- /**
- * @var array list of application configurations
- */
- private $_appConfigs=array();
- /**
- * @var array list of page initial property values
- */
- private $_properties=array();
- /**
- * @var TAuthorizationRuleCollection list of authorization rules
- */
- private $_rules=array();
- /**
- * @var array list of included configurations
- */
- private $_includes=array();
- /**
- * @var string the currently request page in the format of Path.To.PageName
- */
- private $_pagePath='';
-
- /**
- * Constructor.
- * @param string the currently request page in the format of Path.To.PageName
- */
- public function __construct($pagePath)
- {
- $this->_pagePath=$pagePath;
- }
-
- /**
- * @return array list of external configuration files. Each element is like $filePath=>$condition
- */
- public function getExternalConfigurations()
- {
- return $this->_includes;
- }
-
- /**
- * Returns list of page initial property values.
- * Each array element represents a single property with the key
- * being the property name and the value the initial property value.
- * @return array list of page initial property values
- */
- public function getProperties()
- {
- return $this->_properties;
- }
-
- /**
- * Returns list of authorization rules.
- * The authorization rules are aggregated (bottom-up) from configuration files
- * along the path to the specified page.
- * @return TAuthorizationRuleCollection collection of authorization rules
- */
- public function getRules()
- {
- return $this->_rules;
- }
-
- /**
- * @return array list of application configurations specified along page path
- */
- public function getApplicationConfigurations()
- {
- return $this->_appConfigs;
- }
-
- /**
- * Loads configuration for a page specified in a path format.
- * @param string root path for pages
- */
- public function loadFromFiles($basePath)
- {
- $paths=explode('.',$this->_pagePath);
- $page=array_pop($paths);
- $path=$basePath;
- $configPagePath='';
- $fileName = Prado::getApplication()->getConfigurationType()==TApplication::CONFIG_TYPE_PHP
- ? TPageService::CONFIG_FILE_PHP
- : TPageService::CONFIG_FILE_XML;
- foreach($paths as $p)
- {
- $this->loadFromFile($path.DIRECTORY_SEPARATOR.$fileName,$configPagePath);
- $path.=DIRECTORY_SEPARATOR.$p;
- if($configPagePath==='')
- $configPagePath=$p;
- else
- $configPagePath.='.'.$p;
- }
- $this->loadFromFile($path.DIRECTORY_SEPARATOR.$fileName,$configPagePath);
- $this->_rules=new TAuthorizationRuleCollection($this->_rules);
- }
-
- /**
- * Loads a specific config file.
- * @param string config file name
- * @param string the page path that the config file is associated with. The page path doesn't include the page name.
- */
- public function loadFromFile($fname,$configPagePath)
- {
- Prado::trace("Loading page configuration file $fname",'System.Web.Services.TPageService');
- if(empty($fname) || !is_file($fname))
- return;
-
- if(Prado::getApplication()->getConfigurationType()==TApplication::CONFIG_TYPE_PHP)
- {
- $fcontent = include $fname;
- $this->loadFromPhp($fcontent,dirname($fname),$configPagePath);
- }
- else
- {
- $dom=new TXmlDocument;
- if($dom->loadFromFile($fname))
- $this->loadFromXml($dom,dirname($fname),$configPagePath);
- else
- throw new TConfigurationException('pageserviceconf_file_invalid',$fname);
- }
- }
-
- public function loadFromPhp($config,$configPath,$configPagePath)
- {
- $this->loadApplicationConfigurationFromPhp($config,$configPath);
- $this->loadPageConfigurationFromPhp($config,$configPath,$configPagePath);
- }
-
- /**
- * Loads a page configuration.
- * The configuration includes information for both application
- * and page service.
- * @param TXmlElement config xml element
- * @param string the directory containing this configuration
- * @param string the page path that the config XML is associated with. The page path doesn't include the page name.
- */
- public function loadFromXml($dom,$configPath,$configPagePath)
- {
- $this->loadApplicationConfigurationFromXml($dom,$configPath);
- $this->loadPageConfigurationFromXml($dom,$configPath,$configPagePath);
- }
-
- public function loadApplicationConfigurationFromPhp($config,$configPath)
- {
- $appConfig=new TApplicationConfiguration;
- $appConfig->loadFromPhp($config,$configPath);
- $this->_appConfigs[]=$appConfig;
- }
-
- /**
- * Loads the configuration specific for application part
- * @param TXmlElement config xml element
- * @param string base path corresponding to this xml element
- */
- public function loadApplicationConfigurationFromXml($dom,$configPath)
- {
- $appConfig=new TApplicationConfiguration;
- $appConfig->loadFromXml($dom,$configPath);
- $this->_appConfigs[]=$appConfig;
- }
-
- public function loadPageConfigurationFromPhp($config, $configPath, $configPagePath)
- {
- // authorization
- if(isset($config['authorization']) && is_array($config['authorization']))
- {
- $rules = array();
- foreach($config['authorization'] as $authorization)
- {
- $patterns=isset($authorization['pages'])?$authorization['pages']:'';
- $ruleApplies=false;
- if(empty($patterns) || trim($patterns)==='*') // null or empty string
- $ruleApplies=true;
- else
- {
- foreach(explode(',',$patterns) as $pattern)
- {
- if(($pattern=trim($pattern))!=='')
- {
- // we know $configPagePath and $this->_pagePath
- if($configPagePath!=='') // prepend the pattern with ConfigPagePath
- $pattern=$configPagePath.'.'.$pattern;
- if(strcasecmp($pattern,$this->_pagePath)===0)
- {
- $ruleApplies=true;
- break;
- }
- if($pattern[strlen($pattern)-1]==='*') // try wildcard matching
- {
- if(strncasecmp($this->_pagePath,$pattern,strlen($pattern)-1)===0)
- {
- $ruleApplies=true;
- break;
- }
- }
- }
- }
- }
- if($ruleApplies)
- {
- $action = isset($authorization['action'])?$authorization['action']:'';
- $users = isset($authorization['users'])?$authorization['users']:'';
- $roles = isset($authorization['roles'])?$authorization['roles']:'';
- $verb = isset($authorization['verb'])?$authorization['verb']:'';
- $ips = isset($authorization['ips'])?$authorization['ips']:'';
- $rules[]=new TAuthorizationRule($action,$users,$roles,$verb,$ips);
- }
- }
- $this->_rules=array_merge($rules,$this->_rules);
- }
- // pages
- if(isset($config['pages']) && is_array($config['pages']))
- {
- if(isset($config['pages']['properties']))
- {
- $this->_properties = array_merge($this->_properties, $config['pages']['properties']);
- unset($config['pages']['properties']);
- }
- foreach($config['pages'] as $id => $page)
- {
- $properties = array();
- if(isset($page['properties']))
- {
- $properties=$page['properties'];
- unset($page['properties']);
- }
- $matching=false;
- $id=($configPagePath==='')?$id:$configPagePath.'.'.$id;
- if(strcasecmp($id,$this->_pagePath)===0)
- $matching=true;
- else if($id[strlen($id)-1]==='*') // try wildcard matching
- $matching=strncasecmp($this->_pagePath,$id,strlen($id)-1)===0;
- if($matching)
- $this->_properties=array_merge($this->_properties,$properties);
- }
- }
-
- // external configurations
- if(isset($config['includes']) && is_array($config['includes']))
- {
- foreach($config['includes'] as $include)
- {
- $when = isset($include['when'])?true:false;
- if(!isset($include['file']))
- throw new TConfigurationException('pageserviceconf_includefile_required');
- $filePath = $include['file'];
- if(isset($this->_includes[$filePath]))
- $this->_includes[$filePath]=array($configPagePath,'('.$this->_includes[$filePath][1].') || ('.$when.')');
- else
- $this->_includes[$filePath]=array($configPagePath,$when);
- }
- }
- }
-
- /**
- * Loads the configuration specific for page service.
- * @param TXmlElement config xml element
- * @param string base path corresponding to this xml element
- * @param string the page path that the config XML is associated with. The page path doesn't include the page name.
- */
- public function loadPageConfigurationFromXml($dom,$configPath,$configPagePath)
- {
- // authorization
- if(($authorizationNode=$dom->getElementByTagName('authorization'))!==null)
- {
- $rules=array();
- foreach($authorizationNode->getElements() as $node)
- {
- $patterns=$node->getAttribute('pages');
- $ruleApplies=false;
- if(empty($patterns) || trim($patterns)==='*') // null or empty string
- $ruleApplies=true;
- else
- {
- foreach(explode(',',$patterns) as $pattern)
- {
- if(($pattern=trim($pattern))!=='')
- {
- // we know $configPagePath and $this->_pagePath
- if($configPagePath!=='') // prepend the pattern with ConfigPagePath
- $pattern=$configPagePath.'.'.$pattern;
- if(strcasecmp($pattern,$this->_pagePath)===0)
- {
- $ruleApplies=true;
- break;
- }
- if($pattern[strlen($pattern)-1]==='*') // try wildcard matching
- {
- if(strncasecmp($this->_pagePath,$pattern,strlen($pattern)-1)===0)
- {
- $ruleApplies=true;
- break;
- }
- }
- }
- }
- }
- if($ruleApplies)
- $rules[]=new TAuthorizationRule($node->getTagName(),$node->getAttribute('users'),$node->getAttribute('roles'),$node->getAttribute('verb'),$node->getAttribute('ips'));
- }
- $this->_rules=array_merge($rules,$this->_rules);
- }
-
- // pages
- if(($pagesNode=$dom->getElementByTagName('pages'))!==null)
- {
- $this->_properties=array_merge($this->_properties,$pagesNode->getAttributes()->toArray());
- // at the page folder
- foreach($pagesNode->getElementsByTagName('page') as $node)
- {
- $properties=$node->getAttributes();
- $id=$properties->remove('id');
- if(empty($id))
- throw new TConfigurationException('pageserviceconf_page_invalid',$configPath);
- $matching=false;
- $id=($configPagePath==='')?$id:$configPagePath.'.'.$id;
- if(strcasecmp($id,$this->_pagePath)===0)
- $matching=true;
- else if($id[strlen($id)-1]==='*') // try wildcard matching
- $matching=strncasecmp($this->_pagePath,$id,strlen($id)-1)===0;
- if($matching)
- $this->_properties=array_merge($this->_properties,$properties->toArray());
- }
- }
-
- // external configurations
- foreach($dom->getElementsByTagName('include') as $node)
- {
- if(($when=$node->getAttribute('when'))===null)
- $when=true;
- if(($filePath=$node->getAttribute('file'))===null)
- throw new TConfigurationException('pageserviceconf_includefile_required');
- if(isset($this->_includes[$filePath]))
- $this->_includes[$filePath]=array($configPagePath,'('.$this->_includes[$filePath][1].') || ('.$when.')');
- else
- $this->_includes[$filePath]=array($configPagePath,$when);
- }
- }
-}
-
+<?php
+/**
+ * TPageService class file.
+ *
+ * @author Qiang Xue <qiang.xue@gmail.com>
+ * @link http://www.pradosoft.com/
+ * @copyright Copyright &copy; 2005-2012 PradoSoft
+ * @license http://www.pradosoft.com/license/
+ * @version $Id$
+ * @package System.Web.Services
+ */
+
+/**
+ * Include classes to be used by page service
+ */
+Prado::using('System.Web.UI.TPage');
+Prado::using('System.Web.UI.TTemplateManager');
+Prado::using('System.Web.UI.TThemeManager');
+
+/**
+ * TPageService class.
+ *
+ * TPageService implements the service for serving user page requests.
+ *
+ * Pages that are available to client users are stored under a directory specified by
+ * {@link setBasePath BasePath}. The directory may contain subdirectories.
+ * Pages serving for a similar goal are usually placed under the same directory.
+ * A directory may contain a configuration file <b>config.xml</b> whose content
+ * is similar to that of application configuration file.
+ *
+ * A page is requested via page path, which is a dot-connected directory names
+ * appended by the page name. Assume '<BasePath>/Users/Admin' is the directory
+ * containing the page 'Update'. Then the page can be requested via 'Users.Admin.Update'.
+ * By default, the {@link setBasePath BasePath} of the page service is the "pages"
+ * directory under the application base path. You may change this default
+ * by setting {@link setBasePath BasePath} with a different path you prefer.
+ *
+ * Page name refers to the file name (without extension) of the page template.
+ * In order to differentiate from the common control template files, the extension
+ * name of the page template files must be '.page'. If there is a PHP file with
+ * the same page name under the same directory as the template file, that file
+ * will be considered as the page class file and the file name is the page class name.
+ * If such a file is not found, the page class is assumed as {@link TPage}.
+ *
+ * Modules can be configured and loaded in page directory configurations.
+ * Configuration of a module in a subdirectory will overwrite its parent
+ * directory's configuration, if both configurations refer to the same module.
+ *
+ * By default, TPageService will automatically load two modules:
+ * - {@link TTemplateManager} : manages page and control templates
+ * - {@link TThemeManager} : manages themes used in a Prado application
+ *
+ * In page directory configurations, static authorization rules can also be specified,
+ * which governs who and which roles can access particular pages.
+ * Refer to {@link TAuthorizationRule} for more details about authorization rules.
+ * Page authorization rules can be configured within an <authorization> tag in
+ * each page directory configuration as follows,
+ * <authorization>
+ * <deny pages="Update" users="?" />
+ * <allow pages="Admin" roles="administrator" />
+ * <deny pages="Admin" users="*" />
+ * </authorization>
+ * where the 'pages' attribute may be filled with a sequence of comma-separated
+ * page IDs. If 'pages' attribute does not appear in a rule, the rule will be
+ * applied to all pages in this directory and all subdirectories (recursively).
+ * Application of authorization rules are in a bottom-up fashion, starting from
+ * the directory containing the requested page up to all parent directories.
+ * The first matching rule will be used. The last rule always allows all users
+ * accessing to any resources.
+ *
+ * @author Qiang Xue <qiang.xue@gmail.com>
+ * @author Carl G. Mathisen <carlgmathisen@gmail.com>
+ * @version $Id$
+ * @package System.Web.Services
+ * @since 3.0
+ */
+class TPageService extends TService
+{
+ /**
+ * Configuration file name
+ */
+ const CONFIG_FILE_XML='config.xml';
+ /**
+ * Configuration file name
+ */
+ const CONFIG_FILE_PHP='config.php';
+ /**
+ * Default base path
+ */
+ const DEFAULT_BASEPATH='Pages';
+ /**
+ * Fallback base path - used to be the default up to Prado < 3.2
+ */
+ const FALLBACK_BASEPATH='pages';
+ /**
+ * Prefix of ID used for storing parsed configuration in cache
+ */
+ const CONFIG_CACHE_PREFIX='prado:pageservice:';
+ /**
+ * Page template file extension
+ */
+ const PAGE_FILE_EXT='.page';
+ /**
+ * @var string root path of pages
+ */
+ private $_basePath=null;
+ /**
+ * @var string base path class in namespace format
+ */
+ private $_basePageClass='TPage';
+ /**
+ * @var string clientscript manager class in namespace format
+ * @since 3.1.7
+ */
+ private $_clientScriptManagerClass='System.Web.UI.TClientScriptManager';
+ /**
+ * @var string default page
+ */
+ private $_defaultPage='Home';
+ /**
+ * @var string requested page (path)
+ */
+ private $_pagePath=null;
+ /**
+ * @var TPage the requested page
+ */
+ private $_page=null;
+ /**
+ * @var array list of initial page property values
+ */
+ private $_properties=array();
+ /**
+ * @var boolean whether service is initialized
+ */
+ private $_initialized=false;
+ /**
+ * @var TThemeManager theme manager
+ */
+ private $_themeManager=null;
+ /**
+ * @var TTemplateManager template manager
+ */
+ private $_templateManager=null;
+
+ /**
+ * Initializes the service.
+ * This method is required by IService interface and is invoked by application.
+ * @param TXmlElement service configuration
+ */
+ public function init($config)
+ {
+ Prado::trace("Initializing TPageService",'System.Web.Services.TPageService');
+
+ $pageConfig=$this->loadPageConfig($config);
+
+ $this->initPageContext($pageConfig);
+
+ $this->_initialized=true;
+ }
+
+ /**
+ * Initializes page context.
+ * Page context includes path alias settings, namespace usages,
+ * parameter initialization, module loadings, page initial properties
+ * and authorization rules.
+ * @param TPageConfiguration
+ */
+ protected function initPageContext($pageConfig)
+ {
+ $application=$this->getApplication();
+ foreach($pageConfig->getApplicationConfigurations() as $appConfig)
+ $application->applyConfiguration($appConfig);
+
+ $this->applyConfiguration($pageConfig);
+ }
+
+ /**
+ * Applies a page configuration.
+ * @param TPageConfiguration the configuration
+ */
+ protected function applyConfiguration($config)
+ {
+ // initial page properties (to be set when page runs)
+ $this->_properties=array_merge($this->_properties, $config->getProperties());
+ $this->getApplication()->getAuthorizationRules()->mergeWith($config->getRules());
+ $pagePath=$this->getRequestedPagePath();
+ // external configurations
+ foreach($config->getExternalConfigurations() as $filePath=>$params)
+ {
+ list($configPagePath,$condition)=$params;
+ if($condition!==true)
+ $condition=$this->evaluateExpression($condition);
+ if($condition)
+ {
+ if(($path=Prado::getPathOfNamespace($filePath,Prado::getApplication()->getConfigurationFileExt()))===null || !is_file($path))
+ throw new TConfigurationException('pageservice_includefile_invalid',$filePath);
+ $c=new TPageConfiguration($pagePath);
+ $c->loadFromFile($path,$configPagePath);
+ $this->applyConfiguration($c);
+ }
+ }
+
+ }
+
+ /**
+ * Determines the requested page path.
+ * @return string page path requested
+ */
+ protected function determineRequestedPagePath()
+ {
+ $pagePath=$this->getRequest()->getServiceParameter();
+ if(empty($pagePath))
+ $pagePath=$this->getDefaultPage();
+ return $pagePath;
+ }
+
+ /**
+ * Collects configuration for a page.
+ * @param TXmlElement additional configuration specified in the application configuration
+ * @return TPageConfiguration
+ */
+ protected function loadPageConfig($config)
+ {
+ $application=$this->getApplication();
+ $pagePath=$this->getRequestedPagePath();
+ if(($cache=$application->getCache())===null)
+ {
+ $pageConfig=new TPageConfiguration($pagePath);
+ if($config!==null)
+ {
+ if($application->getConfigurationType()==TApplication::CONFIG_TYPE_PHP)
+ $pageConfig->loadPageConfigurationFromPhp($config,$application->getBasePath(),'');
+ else
+ $pageConfig->loadPageConfigurationFromXml($config,$application->getBasePath(),'');
+ }
+ $pageConfig->loadFromFiles($this->getBasePath());
+ }
+ else
+ {
+ $configCached=true;
+ $currentTimestamp=array();
+ $arr=$cache->get(self::CONFIG_CACHE_PREFIX.$this->getID().$pagePath);
+ if(is_array($arr))
+ {
+ list($pageConfig,$timestamps)=$arr;
+ if($application->getMode()!==TApplicationMode::Performance)
+ {
+ foreach($timestamps as $fileName=>$timestamp)
+ {
+ if($fileName===0) // application config file
+ {
+ $appConfigFile=$application->getConfigurationFile();
+ $currentTimestamp[0]=$appConfigFile===null?0:@filemtime($appConfigFile);
+ if($currentTimestamp[0]>$timestamp || ($timestamp>0 && !$currentTimestamp[0]))
+ $configCached=false;
+ }
+ else
+ {
+ $currentTimestamp[$fileName]=@filemtime($fileName);
+ if($currentTimestamp[$fileName]>$timestamp || ($timestamp>0 && !$currentTimestamp[$fileName]))
+ $configCached=false;
+ }
+ }
+ }
+ }
+ else
+ {
+ $configCached=false;
+ $paths=explode('.',$pagePath);
+ $configPath=$this->getBasePath();
+ $fileName = $this->getApplication()->getConfigurationType()==TApplication::CONFIG_TYPE_PHP
+ ? self::CONFIG_FILE_PHP
+ : self::CONFIG_FILE_XML;
+ foreach($paths as $path)
+ {
+ $configFile=$configPath.DIRECTORY_SEPARATOR.$fileName;
+ $currentTimestamp[$configFile]=@filemtime($configFile);
+ $configPath.=DIRECTORY_SEPARATOR.$path;
+ }
+ $appConfigFile=$application->getConfigurationFile();
+ $currentTimestamp[0]=$appConfigFile===null?0:@filemtime($appConfigFile);
+ }
+ if(!$configCached)
+ {
+ $pageConfig=new TPageConfiguration($pagePath);
+ if($config!==null)
+ {
+ if($application->getConfigurationType()==TApplication::CONFIG_TYPE_PHP)
+ $pageConfig->loadPageConfigurationFromPhp($config,$application->getBasePath(),'');
+ else
+ $pageConfig->loadPageConfigurationFromXml($config,$application->getBasePath(),'');
+ }
+ $pageConfig->loadFromFiles($this->getBasePath());
+ $cache->set(self::CONFIG_CACHE_PREFIX.$this->getID().$pagePath,array($pageConfig,$currentTimestamp));
+ }
+ }
+ return $pageConfig;
+ }
+
+ /**
+ * @return TTemplateManager template manager
+ */
+ public function getTemplateManager()
+ {
+ if(!$this->_templateManager)
+ {
+ $this->_templateManager=new TTemplateManager;
+ $this->_templateManager->init(null);
+ }
+ return $this->_templateManager;
+ }
+
+ /**
+ * @param TTemplateManager template manager
+ */
+ public function setTemplateManager(TTemplateManager $value)
+ {
+ $this->_templateManager=$value;
+ }
+
+ /**
+ * @return TThemeManager theme manager
+ */
+ public function getThemeManager()
+ {
+ if(!$this->_themeManager)
+ {
+ $this->_themeManager=new TThemeManager;
+ $this->_themeManager->init(null);
+ }
+ return $this->_themeManager;
+ }
+
+ /**
+ * @param TThemeManager theme manager
+ */
+ public function setThemeManager(TThemeManager $value)
+ {
+ $this->_themeManager=$value;
+ }
+
+ /**
+ * @return string the requested page path
+ */
+ public function getRequestedPagePath()
+ {
+ if($this->_pagePath===null)
+ {
+ $this->_pagePath=strtr($this->determineRequestedPagePath(),'/\\','..');
+ if(empty($this->_pagePath))
+ throw new THttpException(404,'pageservice_page_required');
+ }
+ return $this->_pagePath;
+ }
+
+ /**
+ * @return TPage the requested page
+ */
+ public function getRequestedPage()
+ {
+ return $this->_page;
+ }
+
+ /**
+ * @return string default page path to be served if no explicit page is request. Defaults to 'Home'.
+ */
+ public function getDefaultPage()
+ {
+ return $this->_defaultPage;
+ }
+
+ /**
+ * @param string default page path to be served if no explicit page is request
+ * @throws TInvalidOperationException if the page service is initialized
+ */
+ public function setDefaultPage($value)
+ {
+ if($this->_initialized)
+ throw new TInvalidOperationException('pageservice_defaultpage_unchangeable');
+ else
+ $this->_defaultPage=$value;
+ }
+
+ /**
+ * @return string the URL for the default page
+ */
+ public function getDefaultPageUrl()
+ {
+ return $this->constructUrl($this->getDefaultPage());
+ }
+
+ /**
+ * @return string the root directory for storing pages. Defaults to the 'pages' directory under the application base path.
+ */
+ public function getBasePath()
+ {
+ if($this->_basePath===null)
+ {
+ $basePath=$this->getApplication()->getBasePath().DIRECTORY_SEPARATOR.self::DEFAULT_BASEPATH;
+ if(($this->_basePath=realpath($basePath))===false || !is_dir($this->_basePath))
+ {
+ $basePath=$this->getApplication()->getBasePath().DIRECTORY_SEPARATOR.self::FALLBACK_BASEPATH;
+ if(($this->_basePath=realpath($basePath))===false || !is_dir($this->_basePath))
+ throw new TConfigurationException('pageservice_basepath_invalid',$basePath);
+ }
+ }
+ return $this->_basePath;
+ }
+
+ /**
+ * @param string root directory (in namespace form) storing pages
+ * @throws TInvalidOperationException if the service is initialized already or basepath is invalid
+ */
+ public function setBasePath($value)
+ {
+ if($this->_initialized)
+ throw new TInvalidOperationException('pageservice_basepath_unchangeable');
+ else if(($path=Prado::getPathOfNamespace($value))===null || !is_dir($path))
+ throw new TConfigurationException('pageservice_basepath_invalid',$value);
+ $this->_basePath=realpath($path);
+ }
+
+ /**
+ * Sets the base page class name (in namespace format).
+ * If a page only has a template file without page class file,
+ * this base page class will be instantiated.
+ * @param string class name
+ */
+ public function setBasePageClass($value)
+ {
+ $this->_basePageClass=$value;
+ }
+
+ /**
+ * @return string base page class name in namespace format. Defaults to 'TPage'.
+ */
+ public function getBasePageClass()
+ {
+ return $this->_basePageClass;
+ }
+
+ /**
+ * Sets the clientscript manager class (in namespace format).
+ * @param string class name
+ * @since 3.1.7
+ */
+ public function setClientScriptManagerClass($value)
+ {
+ $this->_clientScriptManagerClass=$value;
+ }
+
+ /**
+ * @return string clientscript manager class in namespace format. Defaults to 'System.Web.UI.TClientScriptManager'.
+ * @since 3.1.7
+ */
+ public function getClientScriptManagerClass()
+ {
+ return $this->_clientScriptManagerClass;
+ }
+
+ /**
+ * Runs the service.
+ * This will create the requested page, initializes it with the property values
+ * specified in the configuration, and executes the page.
+ */
+ public function run()
+ {
+ Prado::trace("Running page service",'System.Web.Services.TPageService');
+ $this->_page=$this->createPage($this->getRequestedPagePath());
+ $this->runPage($this->_page,$this->_properties);
+ }
+
+ /**
+ * Creates a page instance based on requested page path.
+ * @param string requested page path
+ * @return TPage the requested page instance
+ * @throws THttpException if requested page path is invalid
+ * @throws TConfigurationException if the page class cannot be found
+ */
+ protected function createPage($pagePath)
+ {
+ $path=$this->getBasePath().DIRECTORY_SEPARATOR.strtr($pagePath,'.',DIRECTORY_SEPARATOR);
+ $hasTemplateFile=is_file($path.self::PAGE_FILE_EXT);
+ $hasClassFile=is_file($path.Prado::CLASS_FILE_EXT);
+
+ if(!$hasTemplateFile && !$hasClassFile)
+ throw new THttpException(404,'pageservice_page_unknown',$pagePath);
+
+ if($hasClassFile)
+ {
+ $className=basename($path);
+ if(!class_exists($className,false))
+ include_once($path.Prado::CLASS_FILE_EXT);
+ }
+ else
+ {
+ $className=$this->getBasePageClass();
+ Prado::using($className);
+ if(($pos=strrpos($className,'.'))!==false)
+ $className=substr($className,$pos+1);
+ }
+
+ if(!class_exists($className,false) || ($className!=='TPage' && !is_subclass_of($className,'TPage')))
+ throw new THttpException(404,'pageservice_page_unknown',$pagePath);
+
+ $page=new $className;
+ $page->setPagePath($pagePath);
+
+ if($hasTemplateFile)
+ $page->setTemplate($this->getTemplateManager()->getTemplateByFileName($path.self::PAGE_FILE_EXT));
+
+ return $page;
+ }
+
+ /**
+ * Executes a page.
+ * @param TPage the page instance to be run
+ * @param array list of initial page properties
+ */
+ protected function runPage($page,$properties)
+ {
+ foreach($properties as $name=>$value)
+ $page->setSubProperty($name,$value);
+ $page->run($this->getResponse()->createHtmlWriter());
+ }
+
+ /**
+ * Constructs a URL with specified page path and GET parameters.
+ * @param string page path
+ * @param array list of GET parameters, null if no GET parameters required
+ * @param boolean whether to encode the ampersand in URL, defaults to true.
+ * @param boolean whether to encode the GET parameters (their names and values), defaults to true.
+ * @return string URL for the page and GET parameters
+ */
+ public function constructUrl($pagePath,$getParams=null,$encodeAmpersand=true,$encodeGetItems=true)
+ {
+ return $this->getRequest()->constructUrl($this->getID(),$pagePath,$getParams,$encodeAmpersand,$encodeGetItems);
+ }
+}
+
+
+/**
+ * TPageConfiguration class
+ *
+ * TPageConfiguration represents the configuration for a page.
+ * The page is specified by a dot-connected path.
+ * Configurations along this path are merged together to be provided for the page.
+ *
+ * @author Qiang Xue <qiang.xue@gmail.com>
+ * @version $Id$
+ * @package System.Web.Services
+ * @since 3.0
+ */
+class TPageConfiguration extends TComponent
+{
+ /**
+ * @var array list of application configurations
+ */
+ private $_appConfigs=array();
+ /**
+ * @var array list of page initial property values
+ */
+ private $_properties=array();
+ /**
+ * @var TAuthorizationRuleCollection list of authorization rules
+ */
+ private $_rules=array();
+ /**
+ * @var array list of included configurations
+ */
+ private $_includes=array();
+ /**
+ * @var string the currently request page in the format of Path.To.PageName
+ */
+ private $_pagePath='';
+
+ /**
+ * Constructor.
+ * @param string the currently request page in the format of Path.To.PageName
+ */
+ public function __construct($pagePath)
+ {
+ $this->_pagePath=$pagePath;
+ }
+
+ /**
+ * @return array list of external configuration files. Each element is like $filePath=>$condition
+ */
+ public function getExternalConfigurations()
+ {
+ return $this->_includes;
+ }
+
+ /**
+ * Returns list of page initial property values.
+ * Each array element represents a single property with the key
+ * being the property name and the value the initial property value.
+ * @return array list of page initial property values
+ */
+ public function getProperties()
+ {
+ return $this->_properties;
+ }
+
+ /**
+ * Returns list of authorization rules.
+ * The authorization rules are aggregated (bottom-up) from configuration files
+ * along the path to the specified page.
+ * @return TAuthorizationRuleCollection collection of authorization rules
+ */
+ public function getRules()
+ {
+ return $this->_rules;
+ }
+
+ /**
+ * @return array list of application configurations specified along page path
+ */
+ public function getApplicationConfigurations()
+ {
+ return $this->_appConfigs;
+ }
+
+ /**
+ * Loads configuration for a page specified in a path format.
+ * @param string root path for pages
+ */
+ public function loadFromFiles($basePath)
+ {
+ $paths=explode('.',$this->_pagePath);
+ $page=array_pop($paths);
+ $path=$basePath;
+ $configPagePath='';
+ $fileName = Prado::getApplication()->getConfigurationType()==TApplication::CONFIG_TYPE_PHP
+ ? TPageService::CONFIG_FILE_PHP
+ : TPageService::CONFIG_FILE_XML;
+ foreach($paths as $p)
+ {
+ $this->loadFromFile($path.DIRECTORY_SEPARATOR.$fileName,$configPagePath);
+ $path.=DIRECTORY_SEPARATOR.$p;
+ if($configPagePath==='')
+ $configPagePath=$p;
+ else
+ $configPagePath.='.'.$p;
+ }
+ $this->loadFromFile($path.DIRECTORY_SEPARATOR.$fileName,$configPagePath);
+ $this->_rules=new TAuthorizationRuleCollection($this->_rules);
+ }
+
+ /**
+ * Loads a specific config file.
+ * @param string config file name
+ * @param string the page path that the config file is associated with. The page path doesn't include the page name.
+ */
+ public function loadFromFile($fname,$configPagePath)
+ {
+ Prado::trace("Loading page configuration file $fname",'System.Web.Services.TPageService');
+ if(empty($fname) || !is_file($fname))
+ return;
+
+ if(Prado::getApplication()->getConfigurationType()==TApplication::CONFIG_TYPE_PHP)
+ {
+ $fcontent = include $fname;
+ $this->loadFromPhp($fcontent,dirname($fname),$configPagePath);
+ }
+ else
+ {
+ $dom=new TXmlDocument;
+ if($dom->loadFromFile($fname))
+ $this->loadFromXml($dom,dirname($fname),$configPagePath);
+ else
+ throw new TConfigurationException('pageserviceconf_file_invalid',$fname);
+ }
+ }
+
+ public function loadFromPhp($config,$configPath,$configPagePath)
+ {
+ $this->loadApplicationConfigurationFromPhp($config,$configPath);
+ $this->loadPageConfigurationFromPhp($config,$configPath,$configPagePath);
+ }
+
+ /**
+ * Loads a page configuration.
+ * The configuration includes information for both application
+ * and page service.
+ * @param TXmlElement config xml element
+ * @param string the directory containing this configuration
+ * @param string the page path that the config XML is associated with. The page path doesn't include the page name.
+ */
+ public function loadFromXml($dom,$configPath,$configPagePath)
+ {
+ $this->loadApplicationConfigurationFromXml($dom,$configPath);
+ $this->loadPageConfigurationFromXml($dom,$configPath,$configPagePath);
+ }
+
+ public function loadApplicationConfigurationFromPhp($config,$configPath)
+ {
+ $appConfig=new TApplicationConfiguration;
+ $appConfig->loadFromPhp($config,$configPath);
+ $this->_appConfigs[]=$appConfig;
+ }
+
+ /**
+ * Loads the configuration specific for application part
+ * @param TXmlElement config xml element
+ * @param string base path corresponding to this xml element
+ */
+ public function loadApplicationConfigurationFromXml($dom,$configPath)
+ {
+ $appConfig=new TApplicationConfiguration;
+ $appConfig->loadFromXml($dom,$configPath);
+ $this->_appConfigs[]=$appConfig;
+ }
+
+ public function loadPageConfigurationFromPhp($config, $configPath, $configPagePath)
+ {
+ // authorization
+ if(isset($config['authorization']) && is_array($config['authorization']))
+ {
+ $rules = array();
+ foreach($config['authorization'] as $authorization)
+ {
+ $patterns=isset($authorization['pages'])?$authorization['pages']:'';
+ $ruleApplies=false;
+ if(empty($patterns) || trim($patterns)==='*') // null or empty string
+ $ruleApplies=true;
+ else
+ {
+ foreach(explode(',',$patterns) as $pattern)
+ {
+ if(($pattern=trim($pattern))!=='')
+ {
+ // we know $configPagePath and $this->_pagePath
+ if($configPagePath!=='') // prepend the pattern with ConfigPagePath
+ $pattern=$configPagePath.'.'.$pattern;
+ if(strcasecmp($pattern,$this->_pagePath)===0)
+ {
+ $ruleApplies=true;
+ break;
+ }
+ if($pattern[strlen($pattern)-1]==='*') // try wildcard matching
+ {
+ if(strncasecmp($this->_pagePath,$pattern,strlen($pattern)-1)===0)
+ {
+ $ruleApplies=true;
+ break;
+ }
+ }
+ }
+ }
+ }
+ if($ruleApplies)
+ {
+ $action = isset($authorization['action'])?$authorization['action']:'';
+ $users = isset($authorization['users'])?$authorization['users']:'';
+ $roles = isset($authorization['roles'])?$authorization['roles']:'';
+ $verb = isset($authorization['verb'])?$authorization['verb']:'';
+ $ips = isset($authorization['ips'])?$authorization['ips']:'';
+ $rules[]=new TAuthorizationRule($action,$users,$roles,$verb,$ips);
+ }
+ }
+ $this->_rules=array_merge($rules,$this->_rules);
+ }
+ // pages
+ if(isset($config['pages']) && is_array($config['pages']))
+ {
+ if(isset($config['pages']['properties']))
+ {
+ $this->_properties = array_merge($this->_properties, $config['pages']['properties']);
+ unset($config['pages']['properties']);
+ }
+ foreach($config['pages'] as $id => $page)
+ {
+ $properties = array();
+ if(isset($page['properties']))
+ {
+ $properties=$page['properties'];
+ unset($page['properties']);
+ }
+ $matching=false;
+ $id=($configPagePath==='')?$id:$configPagePath.'.'.$id;
+ if(strcasecmp($id,$this->_pagePath)===0)
+ $matching=true;
+ else if($id[strlen($id)-1]==='*') // try wildcard matching
+ $matching=strncasecmp($this->_pagePath,$id,strlen($id)-1)===0;
+ if($matching)
+ $this->_properties=array_merge($this->_properties,$properties);
+ }
+ }
+
+ // external configurations
+ if(isset($config['includes']) && is_array($config['includes']))
+ {
+ foreach($config['includes'] as $include)
+ {
+ $when = isset($include['when'])?true:false;
+ if(!isset($include['file']))
+ throw new TConfigurationException('pageserviceconf_includefile_required');
+ $filePath = $include['file'];
+ if(isset($this->_includes[$filePath]))
+ $this->_includes[$filePath]=array($configPagePath,'('.$this->_includes[$filePath][1].') || ('.$when.')');
+ else
+ $this->_includes[$filePath]=array($configPagePath,$when);
+ }
+ }
+ }
+
+ /**
+ * Loads the configuration specific for page service.
+ * @param TXmlElement config xml element
+ * @param string base path corresponding to this xml element
+ * @param string the page path that the config XML is associated with. The page path doesn't include the page name.
+ */
+ public function loadPageConfigurationFromXml($dom,$configPath,$configPagePath)
+ {
+ // authorization
+ if(($authorizationNode=$dom->getElementByTagName('authorization'))!==null)
+ {
+ $rules=array();
+ foreach($authorizationNode->getElements() as $node)
+ {
+ $patterns=$node->getAttribute('pages');
+ $ruleApplies=false;
+ if(empty($patterns) || trim($patterns)==='*') // null or empty string
+ $ruleApplies=true;
+ else
+ {
+ foreach(explode(',',$patterns) as $pattern)
+ {
+ if(($pattern=trim($pattern))!=='')
+ {
+ // we know $configPagePath and $this->_pagePath
+ if($configPagePath!=='') // prepend the pattern with ConfigPagePath
+ $pattern=$configPagePath.'.'.$pattern;
+ if(strcasecmp($pattern,$this->_pagePath)===0)
+ {
+ $ruleApplies=true;
+ break;
+ }
+ if($pattern[strlen($pattern)-1]==='*') // try wildcard matching
+ {
+ if(strncasecmp($this->_pagePath,$pattern,strlen($pattern)-1)===0)
+ {
+ $ruleApplies=true;
+ break;
+ }
+ }
+ }
+ }
+ }
+ if($ruleApplies)
+ $rules[]=new TAuthorizationRule($node->getTagName(),$node->getAttribute('users'),$node->getAttribute('roles'),$node->getAttribute('verb'),$node->getAttribute('ips'));
+ }
+ $this->_rules=array_merge($rules,$this->_rules);
+ }
+
+ // pages
+ if(($pagesNode=$dom->getElementByTagName('pages'))!==null)
+ {
+ $this->_properties=array_merge($this->_properties,$pagesNode->getAttributes()->toArray());
+ // at the page folder
+ foreach($pagesNode->getElementsByTagName('page') as $node)
+ {
+ $properties=$node->getAttributes();
+ $id=$properties->remove('id');
+ if(empty($id))
+ throw new TConfigurationException('pageserviceconf_page_invalid',$configPath);
+ $matching=false;
+ $id=($configPagePath==='')?$id:$configPagePath.'.'.$id;
+ if(strcasecmp($id,$this->_pagePath)===0)
+ $matching=true;
+ else if($id[strlen($id)-1]==='*') // try wildcard matching
+ $matching=strncasecmp($this->_pagePath,$id,strlen($id)-1)===0;
+ if($matching)
+ $this->_properties=array_merge($this->_properties,$properties->toArray());
+ }
+ }
+
+ // external configurations
+ foreach($dom->getElementsByTagName('include') as $node)
+ {
+ if(($when=$node->getAttribute('when'))===null)
+ $when=true;
+ if(($filePath=$node->getAttribute('file'))===null)
+ throw new TConfigurationException('pageserviceconf_includefile_required');
+ if(isset($this->_includes[$filePath]))
+ $this->_includes[$filePath]=array($configPagePath,'('.$this->_includes[$filePath][1].') || ('.$when.')');
+ else
+ $this->_includes[$filePath]=array($configPagePath,$when);
+ }
+ }
+}
+
diff --git a/framework/Web/TAssetManager.php b/framework/Web/TAssetManager.php
index e4fcbe19..d0aa9b18 100644
--- a/framework/Web/TAssetManager.php
+++ b/framework/Web/TAssetManager.php
@@ -1,357 +1,357 @@
-<?php
-/**
- * TAssetManager class
- *
- * @author Qiang Xue <qiang.xue@gmail.com>
- * @link http://www.pradosoft.com/
- * @copyright Copyright &copy; 2005-2012 PradoSoft
- * @license http://www.pradosoft.com/license/
- * @version $Id$
- * @package System.Web
- */
-
-/**
- * TAssetManager class
- *
- * TAssetManager provides a scheme to allow web clients visiting
- * private files that are normally web-inaccessible.
- *
- * TAssetManager will copy the file to be published into a web-accessible
- * directory. The default base directory for storing the file is "assets", which
- * should be under the application directory. This can be changed by setting
- * the {@link setBasePath BasePath} property together with the
- * {@link setBaseUrl BaseUrl} property that refers to the URL for accessing the base path.
- *
- * By default, TAssetManager will not publish a file or directory if it already
- * exists in the publishing directory and has an older modification time.
- * If the application mode is set as 'Performance', the modification time check
- * will be skipped. You can explicitly require a modification time check
- * with the function {@link publishFilePath}. This is usually
- * very useful during development.
- *
- * TAssetManager may be configured in application configuration file as follows,
- * <code>
- * <module id="asset" BasePath="Application.assets" BaseUrl="/assets" />
- * </code>
- * where {@link getBasePath BasePath} and {@link getBaseUrl BaseUrl} are
- * configurable properties of TAssetManager. Make sure that BasePath is a namespace
- * pointing to a valid directory writable by the Web server process.
- *
- * @author Qiang Xue <qiang.xue@gmail.com>
- * @version $Id$
- * @package System.Web
- * @since 3.0
- */
-class TAssetManager extends TModule
-{
- /**
- * Default web accessible base path for storing private files
- */
- const DEFAULT_BASEPATH='assets';
- /**
- * @var string base web accessible path for storing private files
- */
- private $_basePath=null;
- /**
- * @var string base URL for accessing the publishing directory.
- */
- private $_baseUrl=null;
- /**
- * @var boolean whether to use timestamp checking to ensure files are published with up-to-date versions.
- */
- private $_checkTimestamp=false;
- /**
- * @var TApplication application instance
- */
- private $_application;
- /**
- * @var array published assets
- */
- private $_published=array();
- /**
- * @var boolean whether the module is initialized
- */
- private $_initialized=false;
-
- /**
- * Initializes the module.
- * This method is required by IModule and is invoked by application.
- * @param TXmlElement module configuration
- */
- public function init($config)
- {
- $application=$this->getApplication();
- if($this->_basePath===null)
- $this->_basePath=dirname($application->getRequest()->getApplicationFilePath()).DIRECTORY_SEPARATOR.self::DEFAULT_BASEPATH;
- if(!is_writable($this->_basePath) || !is_dir($this->_basePath))
- throw new TConfigurationException('assetmanager_basepath_invalid',$this->_basePath);
- if($this->_baseUrl===null)
- $this->_baseUrl=rtrim(dirname($application->getRequest()->getApplicationUrl()),'/\\').'/'.self::DEFAULT_BASEPATH;
- $application->setAssetManager($this);
- $this->_initialized=true;
- }
-
- /**
- * @return string the root directory storing published asset files
- */
- public function getBasePath()
- {
- return $this->_basePath;
- }
-
- /**
- * Sets the root directory storing published asset files.
- * The directory must be in namespace format.
- * @param string the root directory storing published asset files
- * @throws TInvalidOperationException if the module is initialized already
- */
- public function setBasePath($value)
- {
- if($this->_initialized)
- throw new TInvalidOperationException('assetmanager_basepath_unchangeable');
- else
- {
- $this->_basePath=Prado::getPathOfNamespace($value);
- if($this->_basePath===null || !is_dir($this->_basePath) || !is_writable($this->_basePath))
- throw new TInvalidDataValueException('assetmanager_basepath_invalid',$value);
- }
- }
-
- /**
- * @return string the base url that the published asset files can be accessed
- */
- public function getBaseUrl()
- {
- return $this->_baseUrl;
- }
-
- /**
- * @param string the base url that the published asset files can be accessed
- * @throws TInvalidOperationException if the module is initialized already
- */
- public function setBaseUrl($value)
- {
- if($this->_initialized)
- throw new TInvalidOperationException('assetmanager_baseurl_unchangeable');
- else
- $this->_baseUrl=rtrim($value,'/');
- }
-
- /**
- * Publishes a file or a directory (recursively).
- * This method will copy the content in a directory (recursively) to
- * a web accessible directory and returns the URL for the directory.
- * If the application is not in performance mode, the file modification
- * time will be used to make sure the published file is latest or not.
- * If not, a file copy will be performed.
- * @param string the path to be published
- * @param boolean If true, file modification time will be checked even if the application
- * is in performance mode.
- * @return string an absolute URL to the published directory
- * @throws TInvalidDataValueException if the file path to be published is
- * invalid
- */
- public function publishFilePath($path,$checkTimestamp=false)
- {
- if(isset($this->_published[$path]))
- return $this->_published[$path];
- else if(empty($path) || ($fullpath=realpath($path))===false)
- throw new TInvalidDataValueException('assetmanager_filepath_invalid',$path);
- else if(is_file($fullpath))
- {
- $dir=$this->hash(dirname($fullpath));
- $fileName=basename($fullpath);
- $dst=$this->_basePath.DIRECTORY_SEPARATOR.$dir;
- if(!is_file($dst.DIRECTORY_SEPARATOR.$fileName) || $checkTimestamp || $this->getApplication()->getMode()!==TApplicationMode::Performance)
- $this->copyFile($fullpath,$dst);
- return $this->_published[$path]=$this->_baseUrl.'/'.$dir.'/'.$fileName;
- }
- else
- {
- $dir=$this->hash($fullpath);
- if(!is_dir($this->_basePath.DIRECTORY_SEPARATOR.$dir) || $checkTimestamp || $this->getApplication()->getMode()!==TApplicationMode::Performance)
- {
- Prado::trace("Publishing directory $fullpath",'System.Web.UI.TAssetManager');
- $this->copyDirectory($fullpath,$this->_basePath.DIRECTORY_SEPARATOR.$dir);
- }
- return $this->_published[$path]=$this->_baseUrl.'/'.$dir;
- }
- }
-
- /**
- * @return array List of published assets
- * @since 3.1.6
- */
- public function getPublished()
- {
- return $this->_published;
- }
-
- /**
- * @param $values List of published assets
- * @since 3.1.6
- */
- protected function setPublished($values=array())
- {
- $this->_published = $values;
- }
-
- /**
- * Returns the published path of a file path.
- * This method does not perform any publishing. It merely tells you
- * if the file path is published, where it will go.
- * @param string directory or file path being published
- * @return string the published file path
- */
- public function getPublishedPath($path)
- {
- $path=realpath($path);
- if(is_file($path))
- return $this->_basePath.DIRECTORY_SEPARATOR.$this->hash(dirname($path)).DIRECTORY_SEPARATOR.basename($path);
- else
- return $this->_basePath.DIRECTORY_SEPARATOR.$this->hash($path);
- }
-
- /**
- * Returns the URL of a published file path.
- * This method does not perform any publishing. It merely tells you
- * if the file path is published, what the URL will be to access it.
- * @param string directory or file path being published
- * @return string the published URL for the file path
- */
- public function getPublishedUrl($path)
- {
- $path=realpath($path);
- if(is_file($path))
- return $this->_baseUrl.'/'.$this->hash(dirname($path)).'/'.basename($path);
- else
- return $this->_baseUrl.'/'.$this->hash($path);
- }
-
- /**
- * Generate a CRC32 hash for the directory path. Collisions are higher
- * than MD5 but generates a much smaller hash string.
- * @param string string to be hashed.
- * @return string hashed string.
- */
- protected function hash($dir)
- {
- return sprintf('%x',crc32($dir.Prado::getVersion()));
- }
-
- /**
- * Copies a file to a directory.
- * Copying is done only when the destination file does not exist
- * or has an older file modification time.
- * @param string source file path
- * @param string destination directory (if not exists, it will be created)
- */
- protected function copyFile($src,$dst)
- {
- if(!is_dir($dst))
- {
- @mkdir($dst);
- @chmod($dst, PRADO_CHMOD);
- }
- $dstFile=$dst.DIRECTORY_SEPARATOR.basename($src);
- if(@filemtime($dstFile)<@filemtime($src))
- {
- Prado::trace("Publishing file $src to $dstFile",'System.Web.TAssetManager');
- @copy($src,$dstFile);
- }
- }
-
- /**
- * Copies a directory recursively as another.
- * If the destination directory does not exist, it will be created.
- * File modification time is used to ensure the copied files are latest.
- * @param string the source directory
- * @param string the destination directory
- * @todo a generic solution to ignore certain directories and files
- */
- public function copyDirectory($src,$dst)
- {
- if(!is_dir($dst))
- {
- @mkdir($dst);
- @chmod($dst, PRADO_CHMOD);
- }
- if($folder=@opendir($src))
- {
- while($file=@readdir($folder))
- {
- if($file==='.' || $file==='..' || $file==='.svn')
- continue;
- else if(is_file($src.DIRECTORY_SEPARATOR.$file))
- {
- if(@filemtime($dst.DIRECTORY_SEPARATOR.$file)<@filemtime($src.DIRECTORY_SEPARATOR.$file))
- {
- @copy($src.DIRECTORY_SEPARATOR.$file,$dst.DIRECTORY_SEPARATOR.$file);
- @chmod($dst.DIRECTORY_SEPARATOR.$file, PRADO_CHMOD);
- }
- }
- else
- $this->copyDirectory($src.DIRECTORY_SEPARATOR.$file,$dst.DIRECTORY_SEPARATOR.$file);
- }
- closedir($folder);
- } else {
- throw new TInvalidDataValueException('assetmanager_source_directory_invalid', $src);
- }
- }
-
- /**
- * Publish a tar file by extracting its contents to the assets directory.
- * Each tar file must be accomplished with its own MD5 check sum file.
- * The MD5 file is published when the tar contents are successfully
- * extracted to the assets directory. The presence of the MD5 file
- * as published asset assumes that the tar file has already been extracted.
- * @param string tar filename
- * @param string MD5 checksum for the corresponding tar file.
- * @param boolean Wether or not to check the time stamp of the file for publishing. Defaults to false.
- * @return string URL path to the directory where the tar file was extracted.
- */
- public function publishTarFile($tarfile, $md5sum, $checkTimestamp=false)
- {
- if(isset($this->_published[$md5sum]))
- return $this->_published[$md5sum];
- else if(($fullpath=realpath($md5sum))===false || !is_file($fullpath))
- throw new TInvalidDataValueException('assetmanager_tarchecksum_invalid',$md5sum);
- else
- {
- $dir=$this->hash(dirname($fullpath));
- $fileName=basename($fullpath);
- $dst=$this->_basePath.DIRECTORY_SEPARATOR.$dir;
- if(!is_file($dst.DIRECTORY_SEPARATOR.$fileName) || $checkTimestamp || $this->getApplication()->getMode()!==TApplicationMode::Performance)
- {
- if(@filemtime($dst.DIRECTORY_SEPARATOR.$fileName)<@filemtime($fullpath))
- {
- $this->copyFile($fullpath,$dst);
- $this->deployTarFile($tarfile,$dst);
- }
- }
- return $this->_published[$md5sum]=$this->_baseUrl.'/'.$dir;
- }
- }
-
- /**
- * Extracts the tar file to the destination directory.
- * N.B Tar file must not be compressed.
- * @param string tar file
- * @param string path where the contents of tar file are to be extracted
- * @return boolean true if extract successful, false otherwise.
- */
- protected function deployTarFile($path,$destination)
- {
- if(($fullpath=realpath($path))===false || !is_file($fullpath))
- throw new TIOException('assetmanager_tarfile_invalid',$path);
- else
- {
- Prado::using('System.IO.TTarFileExtractor');
- $tar = new TTarFileExtractor($fullpath);
- return $tar->extract($destination);
- }
- }
-
-}
-
-?>
+<?php
+/**
+ * TAssetManager class
+ *
+ * @author Qiang Xue <qiang.xue@gmail.com>
+ * @link http://www.pradosoft.com/
+ * @copyright Copyright &copy; 2005-2012 PradoSoft
+ * @license http://www.pradosoft.com/license/
+ * @version $Id$
+ * @package System.Web
+ */
+
+/**
+ * TAssetManager class
+ *
+ * TAssetManager provides a scheme to allow web clients visiting
+ * private files that are normally web-inaccessible.
+ *
+ * TAssetManager will copy the file to be published into a web-accessible
+ * directory. The default base directory for storing the file is "assets", which
+ * should be under the application directory. This can be changed by setting
+ * the {@link setBasePath BasePath} property together with the
+ * {@link setBaseUrl BaseUrl} property that refers to the URL for accessing the base path.
+ *
+ * By default, TAssetManager will not publish a file or directory if it already
+ * exists in the publishing directory and has an older modification time.
+ * If the application mode is set as 'Performance', the modification time check
+ * will be skipped. You can explicitly require a modification time check
+ * with the function {@link publishFilePath}. This is usually
+ * very useful during development.
+ *
+ * TAssetManager may be configured in application configuration file as follows,
+ * <code>
+ * <module id="asset" BasePath="Application.assets" BaseUrl="/assets" />
+ * </code>
+ * where {@link getBasePath BasePath} and {@link getBaseUrl BaseUrl} are
+ * configurable properties of TAssetManager. Make sure that BasePath is a namespace
+ * pointing to a valid directory writable by the Web server process.
+ *
+ * @author Qiang Xue <qiang.xue@gmail.com>
+ * @version $Id$
+ * @package System.Web
+ * @since 3.0
+ */
+class TAssetManager extends TModule
+{
+ /**
+ * Default web accessible base path for storing private files
+ */
+ const DEFAULT_BASEPATH='assets';
+ /**
+ * @var string base web accessible path for storing private files
+ */
+ private $_basePath=null;
+ /**
+ * @var string base URL for accessing the publishing directory.
+ */
+ private $_baseUrl=null;
+ /**
+ * @var boolean whether to use timestamp checking to ensure files are published with up-to-date versions.
+ */
+ private $_checkTimestamp=false;
+ /**
+ * @var TApplication application instance
+ */
+ private $_application;
+ /**
+ * @var array published assets
+ */
+ private $_published=array();
+ /**
+ * @var boolean whether the module is initialized
+ */
+ private $_initialized=false;
+
+ /**
+ * Initializes the module.
+ * This method is required by IModule and is invoked by application.
+ * @param TXmlElement module configuration
+ */
+ public function init($config)
+ {
+ $application=$this->getApplication();
+ if($this->_basePath===null)
+ $this->_basePath=dirname($application->getRequest()->getApplicationFilePath()).DIRECTORY_SEPARATOR.self::DEFAULT_BASEPATH;
+ if(!is_writable($this->_basePath) || !is_dir($this->_basePath))
+ throw new TConfigurationException('assetmanager_basepath_invalid',$this->_basePath);
+ if($this->_baseUrl===null)
+ $this->_baseUrl=rtrim(dirname($application->getRequest()->getApplicationUrl()),'/\\').'/'.self::DEFAULT_BASEPATH;
+ $application->setAssetManager($this);
+ $this->_initialized=true;
+ }
+
+ /**
+ * @return string the root directory storing published asset files
+ */
+ public function getBasePath()
+ {
+ return $this->_basePath;
+ }
+
+ /**
+ * Sets the root directory storing published asset files.
+ * The directory must be in namespace format.
+ * @param string the root directory storing published asset files
+ * @throws TInvalidOperationException if the module is initialized already
+ */
+ public function setBasePath($value)
+ {
+ if($this->_initialized)
+ throw new TInvalidOperationException('assetmanager_basepath_unchangeable');
+ else
+ {
+ $this->_basePath=Prado::getPathOfNamespace($value);
+ if($this->_basePath===null || !is_dir($this->_basePath) || !is_writable($this->_basePath))
+ throw new TInvalidDataValueException('assetmanager_basepath_invalid',$value);
+ }
+ }
+
+ /**
+ * @return string the base url that the published asset files can be accessed
+ */
+ public function getBaseUrl()
+ {
+ return $this->_baseUrl;
+ }
+
+ /**
+ * @param string the base url that the published asset files can be accessed
+ * @throws TInvalidOperationException if the module is initialized already
+ */
+ public function setBaseUrl($value)
+ {
+ if($this->_initialized)
+ throw new TInvalidOperationException('assetmanager_baseurl_unchangeable');
+ else
+ $this->_baseUrl=rtrim($value,'/');
+ }
+
+ /**
+ * Publishes a file or a directory (recursively).
+ * This method will copy the content in a directory (recursively) to
+ * a web accessible directory and returns the URL for the directory.
+ * If the application is not in performance mode, the file modification
+ * time will be used to make sure the published file is latest or not.
+ * If not, a file copy will be performed.
+ * @param string the path to be published
+ * @param boolean If true, file modification time will be checked even if the application
+ * is in performance mode.
+ * @return string an absolute URL to the published directory
+ * @throws TInvalidDataValueException if the file path to be published is
+ * invalid
+ */
+ public function publishFilePath($path,$checkTimestamp=false)
+ {
+ if(isset($this->_published[$path]))
+ return $this->_published[$path];
+ else if(empty($path) || ($fullpath=realpath($path))===false)
+ throw new TInvalidDataValueException('assetmanager_filepath_invalid',$path);
+ else if(is_file($fullpath))
+ {
+ $dir=$this->hash(dirname($fullpath));
+ $fileName=basename($fullpath);
+ $dst=$this->_basePath.DIRECTORY_SEPARATOR.$dir;
+ if(!is_file($dst.DIRECTORY_SEPARATOR.$fileName) || $checkTimestamp || $this->getApplication()->getMode()!==TApplicationMode::Performance)
+ $this->copyFile($fullpath,$dst);
+ return $this->_published[$path]=$this->_baseUrl.'/'.$dir.'/'.$fileName;
+ }
+ else
+ {
+ $dir=$this->hash($fullpath);
+ if(!is_dir($this->_basePath.DIRECTORY_SEPARATOR.$dir) || $checkTimestamp || $this->getApplication()->getMode()!==TApplicationMode::Performance)
+ {
+ Prado::trace("Publishing directory $fullpath",'System.Web.UI.TAssetManager');
+ $this->copyDirectory($fullpath,$this->_basePath.DIRECTORY_SEPARATOR.$dir);
+ }
+ return $this->_published[$path]=$this->_baseUrl.'/'.$dir;
+ }
+ }
+
+ /**
+ * @return array List of published assets
+ * @since 3.1.6
+ */
+ public function getPublished()
+ {
+ return $this->_published;
+ }
+
+ /**
+ * @param $values List of published assets
+ * @since 3.1.6
+ */
+ protected function setPublished($values=array())
+ {
+ $this->_published = $values;
+ }
+
+ /**
+ * Returns the published path of a file path.
+ * This method does not perform any publishing. It merely tells you
+ * if the file path is published, where it will go.
+ * @param string directory or file path being published
+ * @return string the published file path
+ */
+ public function getPublishedPath($path)
+ {
+ $path=realpath($path);
+ if(is_file($path))
+ return $this->_basePath.DIRECTORY_SEPARATOR.$this->hash(dirname($path)).DIRECTORY_SEPARATOR.basename($path);
+ else
+ return $this->_basePath.DIRECTORY_SEPARATOR.$this->hash($path);
+ }
+
+ /**
+ * Returns the URL of a published file path.
+ * This method does not perform any publishing. It merely tells you
+ * if the file path is published, what the URL will be to access it.
+ * @param string directory or file path being published
+ * @return string the published URL for the file path
+ */
+ public function getPublishedUrl($path)
+ {
+ $path=realpath($path);
+ if(is_file($path))
+ return $this->_baseUrl.'/'.$this->hash(dirname($path)).'/'.basename($path);
+ else
+ return $this->_baseUrl.'/'.$this->hash($path);
+ }
+
+ /**
+ * Generate a CRC32 hash for the directory path. Collisions are higher
+ * than MD5 but generates a much smaller hash string.
+ * @param string string to be hashed.
+ * @return string hashed string.
+ */
+ protected function hash($dir)
+ {
+ return sprintf('%x',crc32($dir.Prado::getVersion()));
+ }
+
+ /**
+ * Copies a file to a directory.
+ * Copying is done only when the destination file does not exist
+ * or has an older file modification time.
+ * @param string source file path
+ * @param string destination directory (if not exists, it will be created)
+ */
+ protected function copyFile($src,$dst)
+ {
+ if(!is_dir($dst))
+ {
+ @mkdir($dst);
+ @chmod($dst, PRADO_CHMOD);
+ }
+ $dstFile=$dst.DIRECTORY_SEPARATOR.basename($src);
+ if(@filemtime($dstFile)<@filemtime($src))
+ {
+ Prado::trace("Publishing file $src to $dstFile",'System.Web.TAssetManager');
+ @copy($src,$dstFile);
+ }
+ }
+
+ /**
+ * Copies a directory recursively as another.
+ * If the destination directory does not exist, it will be created.
+ * File modification time is used to ensure the copied files are latest.
+ * @param string the source directory
+ * @param string the destination directory
+ * @todo a generic solution to ignore certain directories and files
+ */
+ public function copyDirectory($src,$dst)
+ {
+ if(!is_dir($dst))
+ {
+ @mkdir($dst);
+ @chmod($dst, PRADO_CHMOD);
+ }
+ if($folder=@opendir($src))
+ {
+ while($file=@readdir($folder))
+ {
+ if($file==='.' || $file==='..' || $file==='.svn')
+ continue;
+ else if(is_file($src.DIRECTORY_SEPARATOR.$file))
+ {
+ if(@filemtime($dst.DIRECTORY_SEPARATOR.$file)<@filemtime($src.DIRECTORY_SEPARATOR.$file))
+ {
+ @copy($src.DIRECTORY_SEPARATOR.$file,$dst.DIRECTORY_SEPARATOR.$file);
+ @chmod($dst.DIRECTORY_SEPARATOR.$file, PRADO_CHMOD);
+ }
+ }
+ else
+ $this->copyDirectory($src.DIRECTORY_SEPARATOR.$file,$dst.DIRECTORY_SEPARATOR.$file);
+ }
+ closedir($folder);
+ } else {
+ throw new TInvalidDataValueException('assetmanager_source_directory_invalid', $src);
+ }
+ }
+
+ /**
+ * Publish a tar file by extracting its contents to the assets directory.
+ * Each tar file must be accomplished with its own MD5 check sum file.
+ * The MD5 file is published when the tar contents are successfully
+ * extracted to the assets directory. The presence of the MD5 file
+ * as published asset assumes that the tar file has already been extracted.
+ * @param string tar filename
+ * @param string MD5 checksum for the corresponding tar file.
+ * @param boolean Wether or not to check the time stamp of the file for publishing. Defaults to false.
+ * @return string URL path to the directory where the tar file was extracted.
+ */
+ public function publishTarFile($tarfile, $md5sum, $checkTimestamp=false)
+ {
+ if(isset($this->_published[$md5sum]))
+ return $this->_published[$md5sum];
+ else if(($fullpath=realpath($md5sum))===false || !is_file($fullpath))
+ throw new TInvalidDataValueException('assetmanager_tarchecksum_invalid',$md5sum);
+ else
+ {
+ $dir=$this->hash(dirname($fullpath));
+ $fileName=basename($fullpath);
+ $dst=$this->_basePath.DIRECTORY_SEPARATOR.$dir;
+ if(!is_file($dst.DIRECTORY_SEPARATOR.$fileName) || $checkTimestamp || $this->getApplication()->getMode()!==TApplicationMode::Performance)
+ {
+ if(@filemtime($dst.DIRECTORY_SEPARATOR.$fileName)<@filemtime($fullpath))
+ {
+ $this->copyFile($fullpath,$dst);
+ $this->deployTarFile($tarfile,$dst);
+ }
+ }
+ return $this->_published[$md5sum]=$this->_baseUrl.'/'.$dir;
+ }
+ }
+
+ /**
+ * Extracts the tar file to the destination directory.
+ * N.B Tar file must not be compressed.
+ * @param string tar file
+ * @param string path where the contents of tar file are to be extracted
+ * @return boolean true if extract successful, false otherwise.
+ */
+ protected function deployTarFile($path,$destination)
+ {
+ if(($fullpath=realpath($path))===false || !is_file($fullpath))
+ throw new TIOException('assetmanager_tarfile_invalid',$path);
+ else
+ {
+ Prado::using('System.IO.TTarFileExtractor');
+ $tar = new TTarFileExtractor($fullpath);
+ return $tar->extract($destination);
+ }
+ }
+
+}
+
+?>
diff --git a/framework/Web/THttpResponse.php b/framework/Web/THttpResponse.php
index 57459362..987bf63b 100644
--- a/framework/Web/THttpResponse.php
+++ b/framework/Web/THttpResponse.php
@@ -1,719 +1,719 @@
-<?php
-/**
- * THttpResponse class
- *
- * @author Qiang Xue <qiang.xue@gmail.com>
- * @link http://www.pradosoft.com/
- * @copyright Copyright &copy; 2005-2012 PradoSoft
- * @license http://www.pradosoft.com/license/
- * @version $Id$
- * @package System.Web
- */
-
-/**
- * Includes the THttpResponse adapter.
- */
-Prado::using('System.Web.THttpResponseAdapter');
-
-/**
- * THttpResponse class
- *
- * THttpResponse implements the mechanism for sending output to client users.
- *
- * To output a string to client, use {@link write()}. By default, the output is
- * buffered until {@link flush()} is called or the application ends. The output in
- * the buffer can also be cleaned by {@link clear()}. To disable output buffering,
- * set BufferOutput property to false.
- *
- * To send cookies to client, use {@link getCookies()}.
- * To redirect client browser to a new URL, use {@link redirect()}.
- * To send a file to client, use {@link writeFile()}.
- *
- * By default, THttpResponse is registered with {@link TApplication} as the
- * response module. It can be accessed via {@link TApplication::getResponse()}.
- *
- * THttpResponse may be configured in application configuration file as follows
- *
- * <module id="response" class="System.Web.THttpResponse" CacheExpire="20" CacheControl="nocache" BufferOutput="true" />
- *
- * where {@link getCacheExpire CacheExpire}, {@link getCacheControl CacheControl}
- * and {@link getBufferOutput BufferOutput} are optional properties of THttpResponse.
- *
- * THttpResponse sends charset header if either {@link setCharset() Charset}
- * or {@link TGlobalization::setCharset() TGlobalization.Charset} is set.
- *
- * Since 3.1.2, HTTP status code can be set with the {@link setStatusCode StatusCode} property.
- *
- * Note: Some HTTP Status codes can require additional header or body information. So, if you use {@link setStatusCode StatusCode}
- * in your application, be sure to add theses informations.
- * E.g : to make an http authentication :
- * <code>
- * public function clickAuth ($sender, $param)
- * {
- * $response=$this->getResponse();
- * $response->setStatusCode(401);
- * $response->appendHeader('WWW-Authenticate: Basic realm="Test"');
- * }
- * </code>
- *
- * This event handler will sent the 401 status code (Unauthorized) to the browser, with the WWW-Authenticate header field. This
- * will force the browser to ask for a username and a password.
- *
- * @author Qiang Xue <qiang.xue@gmail.com>
- * @version $Id$
- * @package System.Web
- * @since 3.0
- */
-class THttpResponse extends TModule implements ITextWriter
-{
- const DEFAULT_CONTENTTYPE = 'text/html';
- const DEFAULT_CHARSET = 'UTF-8';
-
- /**
- * @var The differents defined status code by RFC 2616 {@link http://www.faqs.org/rfcs/rfc2616}
- */
- private static $HTTP_STATUS_CODES = array(
- 100 => 'Continue', 101 => 'Switching Protocols',
- 200 => 'OK', 201 => 'Created', 202 => 'Accepted', 203 => 'Non-Authoritative Information', 204 => 'No Content', 205 => 'Reset Content', 206 => 'Partial Content',
- 300 => 'Multiple Choices', 301 => 'Moved Permanently', 302 => 'Found', 303 => 'See Other', 304 => 'Not Modified', 305 => 'Use Proxy', 307 => 'Temporary Redirect',
- 400 => 'Bad Request', 401 => 'Unauthorized', 402 => 'Payment Required', 403 => 'Forbidden', 404 => 'Not Found', 405 => 'Method Not Allowed', 406 => 'Not Acceptable', 407 => 'Proxy Authentication Required', 408 => 'Request Time-out', 409 => 'Conflict', 410 => 'Gone', 411 => 'Length Required', 412 => 'Precondition Failed', 413 => 'Request Entity Too Large', 414 => 'Request-URI Too Large', 415 => 'Unsupported Media Type', 416 => 'Requested range not satisfiable', 417 => 'Expectation Failed',
- 500 => 'Internal Server Error', 501 => 'Not Implemented', 502 => 'Bad Gateway', 503 => 'Service Unavailable', 504 => 'Gateway Time-out', 505 => 'HTTP Version not supported'
- );
-
- /**
- * @var boolean whether to buffer output
- */
- private $_bufferOutput=true;
- /**
- * @var boolean if the application is initialized
- */
- private $_initialized=false;
- /**
- * @var THttpCookieCollection list of cookies to return
- */
- private $_cookies=null;
- /**
- * @var integer response status code
- */
- private $_status=200;
- /**
- * @var string reason correspond to status code
- */
- private $_reason='OK';
- /**
- * @var string HTML writer type
- */
- private $_htmlWriterType='System.Web.UI.THtmlWriter';
- /**
- * @var string content type
- */
- private $_contentType=null;
- /**
- * @var string|boolean character set, e.g. UTF-8 or false if no character set should be send to client
- */
- private $_charset='';
- /**
- * @var THttpResponseAdapter adapter.
- */
- private $_adapter;
- /**
- * @var boolean whether http response header has been sent
- */
- private $_httpHeaderSent;
- /**
- * @var boolean whether content-type header has been sent
- */
- private $_contentTypeHeaderSent;
-
- /**
- * Destructor.
- * Flushes any existing content in buffer.
- */
- public function __destruct()
- {
- //if($this->_bufferOutput)
- // @ob_end_flush();
- }
-
- /**
- * @param THttpResponseAdapter response adapter
- */
- public function setAdapter(THttpResponseAdapter $adapter)
- {
- $this->_adapter=$adapter;
- }
-
- /**
- * @return THttpResponseAdapter response adapter, null if not exist.
- */
- public function getAdapter()
- {
- return $this->_adapter;
- }
-
- /**
- * @return boolean true if adapter exists, false otherwise.
- */
- public function getHasAdapter()
- {
- return $this->_adapter!==null;
- }
-
- /**
- * Initializes the module.
- * This method is required by IModule and is invoked by application.
- * It starts output buffer if it is enabled.
- * @param TXmlElement module configuration
- */
- public function init($config)
- {
- if($this->_bufferOutput)
- ob_start();
- $this->_initialized=true;
- $this->getApplication()->setResponse($this);
- }
-
- /**
- * @return integer time-to-live for cached session pages in minutes, this has no effect for nocache limiter. Defaults to 180.
- */
- public function getCacheExpire()
- {
- return session_cache_expire();
- }
-
- /**
- * @param integer time-to-live for cached session pages in minutes, this has no effect for nocache limiter.
- */
- public function setCacheExpire($value)
- {
- session_cache_expire(TPropertyValue::ensureInteger($value));
- }
-
- /**
- * @return string cache control method to use for session pages
- */
- public function getCacheControl()
- {
- return session_cache_limiter();
- }
-
- /**
- * @param string cache control method to use for session pages. Valid values
- * include none/nocache/private/private_no_expire/public
- */
- public function setCacheControl($value)
- {
- session_cache_limiter(TPropertyValue::ensureEnum($value,array('none','nocache','private','private_no_expire','public')));
- }
-
- /**
- * @return string content type, default is text/html
- */
- public function setContentType($type)
- {
- if ($this->_contentTypeHeaderSent)
- throw new Exception('Unable to alter content-type as it has been already sent');
- $this->_contentType = $type;
- }
-
- /**
- * @return string current content type
- */
- public function getContentType()
- {
- return $this->_contentType;
- }
-
- /**
- * @return string|boolean output charset.
- */
- public function getCharset()
- {
- return $this->_charset;
- }
-
- /**
- * @param string|boolean output charset.
- */
- public function setCharset($charset)
- {
- $this->_charset = (strToLower($charset) === 'false') ? false : (string)$charset;
- }
-
- /**
- * @return boolean whether to enable output buffer
- */
- public function getBufferOutput()
- {
- return $this->_bufferOutput;
- }
-
- /**
- * @param boolean whether to enable output buffer
- * @throws TInvalidOperationException if session is started already
- */
- public function setBufferOutput($value)
- {
- if($this->_initialized)
- throw new TInvalidOperationException('httpresponse_bufferoutput_unchangeable');
- else
- $this->_bufferOutput=TPropertyValue::ensureBoolean($value);
- }
-
- /**
- * @return integer HTTP status code, defaults to 200
- */
- public function getStatusCode()
- {
- return $this->_status;
- }
-
- /**
- * Set the HTTP status code for the response.
- * The code and its reason will be sent to client using the currently requested http protocol version (see {@link THttpRequest::getHttpProtocolVersion})
- * Keep in mind that HTTP/1.0 clients might not understand all status codes from HTTP/1.1
- *
- * @param integer HTTP status code
- * @param string HTTP status reason, defaults to standard HTTP reasons
- */
- public function setStatusCode($status, $reason=null)
- {
- if ($this->_httpHeaderSent)
- throw new Exception('Unable to alter response as HTTP header already sent');
- $status=TPropertyValue::ensureInteger($status);
- if(isset(self::$HTTP_STATUS_CODES[$status])) {
- $this->_reason=self::$HTTP_STATUS_CODES[$status];
- }else{
- if($reason===null || $reason==='') {
- throw new TInvalidDataValueException("response_status_reason_missing");
- }
- $reason=TPropertyValue::ensureString($reason);
- if(strpos($reason, "\r")!=false || strpos($reason, "\n")!=false) {
- throw new TInvalidDataValueException("response_status_reason_barchars");
- }
- $this->_reason=$reason;
- }
- $this->_status=$status;
- }
-
- /**
- * @param string HTTP status reason
- */
- public function getStatusReason() {
- return $this->_reason;
- }
-
- /**
- * @return THttpCookieCollection list of output cookies
- */
- public function getCookies()
- {
- if($this->_cookies===null)
- $this->_cookies=new THttpCookieCollection($this);
- return $this->_cookies;
- }
-
- /**
- * Outputs a string.
- * It may not be sent back to user immediately if output buffer is enabled.
- * @param string string to be output
- */
- public function write($str)
- {
- // when starting output make sure we send the headers first
- if (!$this->_bufferOutput and !$this->_httpHeaderSent)
- $this->ensureHeadersSent();
- echo $str;
- }
-
- /**
- * Sends a file back to user.
- * Make sure not to output anything else after calling this method.
- * @param string file name
- * @param string content to be set. If null, the content will be read from the server file pointed to by $fileName.
- * @param string mime type of the content.
- * @param array list of headers to be sent. Each array element represents a header string (e.g. 'Content-Type: text/plain').
- * @param boolean force download of file, even if browser able to display inline. Defaults to 'true'.
- * @param string force a specific file name on client side. Defaults to 'null' means auto-detect.
- * @param integer size of file or content in bytes if already known. Defaults to 'null' means auto-detect.
- * @throws TInvalidDataValueException if the file cannot be found
- */
- public function writeFile($fileName,$content=null,$mimeType=null,$headers=null,$forceDownload=true,$clientFileName=null,$fileSize=null)
- {
- static $defaultMimeTypes=array(
- 'css'=>'text/css',
- 'gif'=>'image/gif',
- 'png'=>'image/png',
- 'jpg'=>'image/jpeg',
- 'jpeg'=>'image/jpeg',
- 'htm'=>'text/html',
- 'html'=>'text/html',
- 'js'=>'javascript/js',
- 'pdf'=>'application/pdf',
- 'xls'=>'application/vnd.ms-excel',
- );
-
- if($mimeType===null)
- {
- $mimeType='text/plain';
- if(function_exists('mime_content_type'))
- $mimeType=mime_content_type($fileName);
- else if(($ext=strrchr($fileName,'.'))!==false)
- {
- $ext=substr($ext,1);
- if(isset($defaultMimeTypes[$ext]))
- $mimeType=$defaultMimeTypes[$ext];
- }
- }
-
- if($clientFileName===null)
- $clientFileName=basename($fileName);
- else
- $clientFileName=basename($clientFileName);
-
- if($fileSize===null || $fileSize < 0)
- $fileSize = ($content===null?filesize($fileName):strlen($content));
-
- $this->sendHttpHeader();
- if(is_array($headers))
- {
- foreach($headers as $h)
- header($h);
- }
- else
- {
- header('Pragma: public');
- header('Expires: 0');
- header('Cache-Control: must-revalidate, post-check=0, pre-check=0');
- header("Content-Type: $mimeType");
- $this->_contentTypeHeaderSent = true;
- }
-
- header('Content-Length: '.$fileSize);
- header("Content-Disposition: " . ($forceDownload ? 'attachment' : 'inline') . "; filename=\"$clientFileName\"");
- header('Content-Transfer-Encoding: binary');
- if($content===null)
- readfile($fileName);
- else
- echo $content;
- }
-
- /**
- * Redirects the browser to the specified URL.
- * The current application will be terminated after this method is invoked.
- * @param string URL to be redirected to. If the URL is a relative one, the base URL of
- * the current request will be inserted at the beginning.
- */
- public function redirect($url)
- {
- if($this->getHasAdapter())
- $this->_adapter->httpRedirect($url);
- else
- $this->httpRedirect($url);
- }
-
- /**
- * Redirect the browser to another URL and exists the current application.
- * This method is used internally. Please use {@link redirect} instead.
- *
- * @since 3.1.5
- * You can set the set {@link setStatusCode StatusCode} to a value between 300 and 399 before
- * calling this function to change the type of redirection.
- * If not specified, StatusCode will be 302 (Found) by default
- *
- * @param string URL to be redirected to. If the URL is a relative one, the base URL of
- * the current request will be inserted at the beginning.
- */
- public function httpRedirect($url)
- {
- $this->ensureHeadersSent();
-
- if($url[0]==='/')
- $url=$this->getRequest()->getBaseUrl().$url;
- if ($this->_status >= 300 && $this->_status < 400)
- // The status code has been modified to a valid redirection status, send it
- header('Location: '.str_replace('&amp;','&',$url), true, $this->_status);
- else
- header('Location: '.str_replace('&amp;','&',$url));
-
- if(!$this->getApplication()->getRequestCompleted())
- $this->getApplication()->onEndRequest();
-
- exit();
- }
-
- /**
- * Reloads the current page.
- * The effect of this method call is the same as user pressing the
- * refresh button on his browser (without post data).
- **/
- public function reload()
- {
- $this->redirect($this->getRequest()->getRequestUri());
- }
-
- /**
- * Flush the response contents and headers.
- */
- public function flush($continueBuffering = true)
- {
- if($this->getHasAdapter())
- $this->_adapter->flushContent($continueBuffering);
- else
- $this->flushContent($continueBuffering);
- }
-
- /**
- * Ensures that HTTP response and content-type headers are sent
- */
- public function ensureHeadersSent()
- {
- $this->ensureHttpHeaderSent();
- $this->ensureContentTypeHeaderSent();
- }
-
- /**
- * Outputs the buffered content, sends content-type and charset header.
- * This method is used internally. Please use {@link flush} instead.
- * @param boolean whether to continue buffering after flush if buffering was active
- */
- public function flushContent($continueBuffering = true)
- {
- Prado::trace("Flushing output",'System.Web.THttpResponse');
- $this->ensureHeadersSent();
- if($this->_bufferOutput)
- {
- // avoid forced send of http headers (ob_flush() does that) if there's no output yet
- if (ob_get_length()>0)
- {
- if (!$continueBuffering)
- {
- $this->_bufferOutput = false;
- ob_end_flush();
- }
- else
- ob_flush();
- flush();
- }
- }
- else
- flush();
- }
-
- /**
- * Ensures that the HTTP header with the status code and status reason are sent
- */
- protected function ensureHttpHeaderSent()
- {
- if (!$this->_httpHeaderSent)
- $this->sendHttpHeader();
- }
-
- /**
- * Send the HTTP header with the status code (defaults to 200) and status reason (defaults to OK)
- */
- protected function sendHttpHeader()
- {
- if (($version=$this->getRequest()->getHttpProtocolVersion())==='')
- header (' ', true, $this->_status);
- else
- header($version.' '.$this->_status.' '.$this->_reason, true, $this->_status);
- $this->_httpHeaderSent = true;
- }
-
- /**
- * Ensures that the HTTP header with the status code and status reason are sent
- */
- protected function ensureContentTypeHeaderSent()
- {
- if (!$this->_contentTypeHeaderSent)
- $this->sendContentTypeHeader();
- }
-
- /**
- * Sends content type header with optional charset.
- */
- protected function sendContentTypeHeader()
- {
- $contentType=$this->_contentType===null?self::DEFAULT_CONTENTTYPE:$this->_contentType;
- $charset=$this->getCharset();
- if($charset === false) {
- $this->appendHeader('Content-Type: '.$contentType);
- return;
- }
-
- if($charset==='' && ($globalization=$this->getApplication()->getGlobalization(false))!==null)
- $charset=$globalization->getCharset();
-
- if($charset==='') $charset = self::DEFAULT_CHARSET;
- $this->appendHeader('Content-Type: '.$contentType.';charset='.$charset);
-
- $this->_contentTypeHeaderSent = true;
- }
-
- /**
- * Returns the content in the output buffer.
- * The buffer will NOT be cleared after calling this method.
- * Use {@link clear()} is you want to clear the buffer.
- * @return string output that is in the buffer.
- */
- public function getContents()
- {
- Prado::trace("Retrieving output",'System.Web.THttpResponse');
- return $this->_bufferOutput?ob_get_contents():'';
- }
-
- /**
- * Clears any existing buffered content.
- */
- public function clear()
- {
- if($this->_bufferOutput)
- ob_clean();
- Prado::trace("Clearing output",'System.Web.THttpResponse');
- }
-
- /**
- * @param integer|null Either {@link CASE_UPPER} or {@link CASE_LOWER} or as is null (default)
- * @return array
- */
- public function getHeaders($case=null)
- {
- $result = array();
- $headers = headers_list();
- foreach($headers as $header) {
- $tmp = explode(':', $header);
- $key = trim(array_shift($tmp));
- $value = trim(implode(':', $tmp));
- if(isset($result[$key]))
- $result[$key] .= ', ' . $value;
- else
- $result[$key] = $value;
- }
-
- if($case !== null)
- return array_change_key_case($result, $case);
-
- return $result;
- }
-
- /**
- * Sends a header.
- * @param string header
- * @param boolean whether the header should replace a previous similar header, or add a second header of the same type
- */
- public function appendHeader($value, $replace=true)
- {
- Prado::trace("Sending header '$value'",'System.Web.THttpResponse');
- header($value, $replace);
- }
-
- /**
- * Writes a log message into error log.
- * This method is simple wrapper of PHP function error_log.
- * @param string The error message that should be logged
- * @param integer where the error should go
- * @param string The destination. Its meaning depends on the message parameter as described above
- * @param string The extra headers. It's used when the message parameter is set to 1. This message type uses the same internal function as mail() does.
- * @see http://us2.php.net/manual/en/function.error-log.php
- */
- public function appendLog($message,$messageType=0,$destination='',$extraHeaders='')
- {
- error_log($message,$messageType,$destination,$extraHeaders);
- }
-
- /**
- * Sends a cookie.
- * Do not call this method directly. Operate with the result of {@link getCookies} instead.
- * @param THttpCookie cook to be sent
- */
- public function addCookie($cookie)
- {
- $request=$this->getRequest();
- if($request->getEnableCookieValidation())
- {
- $value=$this->getApplication()->getSecurityManager()->hashData($cookie->getValue());
- setcookie(
- $cookie->getName(),
- $value,
- $cookie->getExpire(),
- $cookie->getPath(),
- $cookie->getDomain(),
- $cookie->getSecure(),
- $cookie->getHttpOnly()
- );
- }
- else {
- setcookie(
- $cookie->getName(),
- $cookie->getValue(),
- $cookie->getExpire(),
- $cookie->getPath(),
- $cookie->getDomain(),
- $cookie->getSecure(),
- $cookie->getHttpOnly()
- );
- }
- }
-
- /**
- * Deletes a cookie.
- * Do not call this method directly. Operate with the result of {@link getCookies} instead.
- * @param THttpCookie cook to be deleted
- */
- public function removeCookie($cookie)
- {
- setcookie(
- $cookie->getName(),
- null,
- 0,
- $cookie->getPath(),
- $cookie->getDomain(),
- $cookie->getSecure(),
- $cookie->getHttpOnly()
- );
- }
-
- /**
- * @return string the type of HTML writer to be used, defaults to THtmlWriter
- */
- public function getHtmlWriterType()
- {
- return $this->_htmlWriterType;
- }
-
- /**
- * @param string the type of HTML writer to be used, may be the class name or the namespace
- */
- public function setHtmlWriterType($value)
- {
- $this->_htmlWriterType=$value;
- }
-
- /**
- * Creates a new instance of HTML writer.
- * If the type of the HTML writer is not supplied, {@link getHtmlWriterType HtmlWriterType} will be assumed.
- * @param string type of the HTML writer to be created. If null, {@link getHtmlWriterType HtmlWriterType} will be assumed.
- */
- public function createHtmlWriter($type=null)
- {
- if($type===null)
- $type=$this->getHtmlWriterType();
- if($this->getHasAdapter())
- return $this->_adapter->createNewHtmlWriter($type, $this);
- else
- return $this->createNewHtmlWriter($type, $this);
- }
-
- /**
- * Create a new html writer instance.
- * This method is used internally. Please use {@link createHtmlWriter} instead.
- * @param string type of HTML writer to be created.
- * @param ITextWriter text writer holding the contents.
- */
- public function createNewHtmlWriter($type, $writer)
- {
- return Prado::createComponent($type, $writer);
- }
-}
-
+<?php
+/**
+ * THttpResponse class
+ *
+ * @author Qiang Xue <qiang.xue@gmail.com>
+ * @link http://www.pradosoft.com/
+ * @copyright Copyright &copy; 2005-2012 PradoSoft
+ * @license http://www.pradosoft.com/license/
+ * @version $Id$
+ * @package System.Web
+ */
+
+/**
+ * Includes the THttpResponse adapter.
+ */
+Prado::using('System.Web.THttpResponseAdapter');
+
+/**
+ * THttpResponse class
+ *
+ * THttpResponse implements the mechanism for sending output to client users.
+ *
+ * To output a string to client, use {@link write()}. By default, the output is
+ * buffered until {@link flush()} is called or the application ends. The output in
+ * the buffer can also be cleaned by {@link clear()}. To disable output buffering,
+ * set BufferOutput property to false.
+ *
+ * To send cookies to client, use {@link getCookies()}.
+ * To redirect client browser to a new URL, use {@link redirect()}.
+ * To send a file to client, use {@link writeFile()}.
+ *
+ * By default, THttpResponse is registered with {@link TApplication} as the
+ * response module. It can be accessed via {@link TApplication::getResponse()}.
+ *
+ * THttpResponse may be configured in application configuration file as follows
+ *
+ * <module id="response" class="System.Web.THttpResponse" CacheExpire="20" CacheControl="nocache" BufferOutput="true" />
+ *
+ * where {@link getCacheExpire CacheExpire}, {@link getCacheControl CacheControl}
+ * and {@link getBufferOutput BufferOutput} are optional properties of THttpResponse.
+ *
+ * THttpResponse sends charset header if either {@link setCharset() Charset}
+ * or {@link TGlobalization::setCharset() TGlobalization.Charset} is set.
+ *
+ * Since 3.1.2, HTTP status code can be set with the {@link setStatusCode StatusCode} property.
+ *
+ * Note: Some HTTP Status codes can require additional header or body information. So, if you use {@link setStatusCode StatusCode}
+ * in your application, be sure to add theses informations.
+ * E.g : to make an http authentication :
+ * <code>
+ * public function clickAuth ($sender, $param)
+ * {
+ * $response=$this->getResponse();
+ * $response->setStatusCode(401);
+ * $response->appendHeader('WWW-Authenticate: Basic realm="Test"');
+ * }
+ * </code>
+ *
+ * This event handler will sent the 401 status code (Unauthorized) to the browser, with the WWW-Authenticate header field. This
+ * will force the browser to ask for a username and a password.
+ *
+ * @author Qiang Xue <qiang.xue@gmail.com>
+ * @version $Id$
+ * @package System.Web
+ * @since 3.0
+ */
+class THttpResponse extends TModule implements ITextWriter
+{
+ const DEFAULT_CONTENTTYPE = 'text/html';
+ const DEFAULT_CHARSET = 'UTF-8';
+
+ /**
+ * @var The differents defined status code by RFC 2616 {@link http://www.faqs.org/rfcs/rfc2616}
+ */
+ private static $HTTP_STATUS_CODES = array(
+ 100 => 'Continue', 101 => 'Switching Protocols',
+ 200 => 'OK', 201 => 'Created', 202 => 'Accepted', 203 => 'Non-Authoritative Information', 204 => 'No Content', 205 => 'Reset Content', 206 => 'Partial Content',
+ 300 => 'Multiple Choices', 301 => 'Moved Permanently', 302 => 'Found', 303 => 'See Other', 304 => 'Not Modified', 305 => 'Use Proxy', 307 => 'Temporary Redirect',
+ 400 => 'Bad Request', 401 => 'Unauthorized', 402 => 'Payment Required', 403 => 'Forbidden', 404 => 'Not Found', 405 => 'Method Not Allowed', 406 => 'Not Acceptable', 407 => 'Proxy Authentication Required', 408 => 'Request Time-out', 409 => 'Conflict', 410 => 'Gone', 411 => 'Length Required', 412 => 'Precondition Failed', 413 => 'Request Entity Too Large', 414 => 'Request-URI Too Large', 415 => 'Unsupported Media Type', 416 => 'Requested range not satisfiable', 417 => 'Expectation Failed',
+ 500 => 'Internal Server Error', 501 => 'Not Implemented', 502 => 'Bad Gateway', 503 => 'Service Unavailable', 504 => 'Gateway Time-out', 505 => 'HTTP Version not supported'
+ );
+
+ /**
+ * @var boolean whether to buffer output
+ */
+ private $_bufferOutput=true;
+ /**
+ * @var boolean if the application is initialized
+ */
+ private $_initialized=false;
+ /**
+ * @var THttpCookieCollection list of cookies to return
+ */
+ private $_cookies=null;
+ /**
+ * @var integer response status code
+ */
+ private $_status=200;
+ /**
+ * @var string reason correspond to status code
+ */
+ private $_reason='OK';
+ /**
+ * @var string HTML writer type
+ */
+ private $_htmlWriterType='System.Web.UI.THtmlWriter';
+ /**
+ * @var string content type
+ */
+ private $_contentType=null;
+ /**
+ * @var string|boolean character set, e.g. UTF-8 or false if no character set should be send to client
+ */
+ private $_charset='';
+ /**
+ * @var THttpResponseAdapter adapter.
+ */
+ private $_adapter;
+ /**
+ * @var boolean whether http response header has been sent
+ */
+ private $_httpHeaderSent;
+ /**
+ * @var boolean whether content-type header has been sent
+ */
+ private $_contentTypeHeaderSent;
+
+ /**
+ * Destructor.
+ * Flushes any existing content in buffer.
+ */
+ public function __destruct()
+ {
+ //if($this->_bufferOutput)
+ // @ob_end_flush();
+ }
+
+ /**
+ * @param THttpResponseAdapter response adapter
+ */
+ public function setAdapter(THttpResponseAdapter $adapter)
+ {
+ $this->_adapter=$adapter;
+ }
+
+ /**
+ * @return THttpResponseAdapter response adapter, null if not exist.
+ */
+ public function getAdapter()
+ {
+ return $this->_adapter;
+ }
+
+ /**
+ * @return boolean true if adapter exists, false otherwise.
+ */
+ public function getHasAdapter()
+ {
+ return $this->_adapter!==null;
+ }
+
+ /**
+ * Initializes the module.
+ * This method is required by IModule and is invoked by application.
+ * It starts output buffer if it is enabled.
+ * @param TXmlElement module configuration
+ */
+ public function init($config)
+ {
+ if($this->_bufferOutput)
+ ob_start();
+ $this->_initialized=true;
+ $this->getApplication()->setResponse($this);
+ }
+
+ /**
+ * @return integer time-to-live for cached session pages in minutes, this has no effect for nocache limiter. Defaults to 180.
+ */
+ public function getCacheExpire()
+ {
+ return session_cache_expire();
+ }
+
+ /**
+ * @param integer time-to-live for cached session pages in minutes, this has no effect for nocache limiter.
+ */
+ public function setCacheExpire($value)
+ {
+ session_cache_expire(TPropertyValue::ensureInteger($value));
+ }
+
+ /**
+ * @return string cache control method to use for session pages
+ */
+ public function getCacheControl()
+ {
+ return session_cache_limiter();
+ }
+
+ /**
+ * @param string cache control method to use for session pages. Valid values
+ * include none/nocache/private/private_no_expire/public
+ */
+ public function setCacheControl($value)
+ {
+ session_cache_limiter(TPropertyValue::ensureEnum($value,array('none','nocache','private','private_no_expire','public')));
+ }
+
+ /**
+ * @return string content type, default is text/html
+ */
+ public function setContentType($type)
+ {
+ if ($this->_contentTypeHeaderSent)
+ throw new Exception('Unable to alter content-type as it has been already sent');
+ $this->_contentType = $type;
+ }
+
+ /**
+ * @return string current content type
+ */
+ public function getContentType()
+ {
+ return $this->_contentType;
+ }
+
+ /**
+ * @return string|boolean output charset.
+ */
+ public function getCharset()
+ {
+ return $this->_charset;
+ }
+
+ /**
+ * @param string|boolean output charset.
+ */
+ public function setCharset($charset)
+ {
+ $this->_charset = (strToLower($charset) === 'false') ? false : (string)$charset;
+ }
+
+ /**
+ * @return boolean whether to enable output buffer
+ */
+ public function getBufferOutput()
+ {
+ return $this->_bufferOutput;
+ }
+
+ /**
+ * @param boolean whether to enable output buffer
+ * @throws TInvalidOperationException if session is started already
+ */
+ public function setBufferOutput($value)
+ {
+ if($this->_initialized)
+ throw new TInvalidOperationException('httpresponse_bufferoutput_unchangeable');
+ else
+ $this->_bufferOutput=TPropertyValue::ensureBoolean($value);
+ }
+
+ /**
+ * @return integer HTTP status code, defaults to 200
+ */
+ public function getStatusCode()
+ {
+ return $this->_status;
+ }
+
+ /**
+ * Set the HTTP status code for the response.
+ * The code and its reason will be sent to client using the currently requested http protocol version (see {@link THttpRequest::getHttpProtocolVersion})
+ * Keep in mind that HTTP/1.0 clients might not understand all status codes from HTTP/1.1
+ *
+ * @param integer HTTP status code
+ * @param string HTTP status reason, defaults to standard HTTP reasons
+ */
+ public function setStatusCode($status, $reason=null)
+ {
+ if ($this->_httpHeaderSent)
+ throw new Exception('Unable to alter response as HTTP header already sent');
+ $status=TPropertyValue::ensureInteger($status);
+ if(isset(self::$HTTP_STATUS_CODES[$status])) {
+ $this->_reason=self::$HTTP_STATUS_CODES[$status];
+ }else{
+ if($reason===null || $reason==='') {
+ throw new TInvalidDataValueException("response_status_reason_missing");
+ }
+ $reason=TPropertyValue::ensureString($reason);
+ if(strpos($reason, "\r")!=false || strpos($reason, "\n")!=false) {
+ throw new TInvalidDataValueException("response_status_reason_barchars");
+ }
+ $this->_reason=$reason;
+ }
+ $this->_status=$status;
+ }
+
+ /**
+ * @param string HTTP status reason
+ */
+ public function getStatusReason() {
+ return $this->_reason;
+ }
+
+ /**
+ * @return THttpCookieCollection list of output cookies
+ */
+ public function getCookies()
+ {
+ if($this->_cookies===null)
+ $this->_cookies=new THttpCookieCollection($this);
+ return $this->_cookies;
+ }
+
+ /**
+ * Outputs a string.
+ * It may not be sent back to user immediately if output buffer is enabled.
+ * @param string string to be output
+ */
+ public function write($str)
+ {
+ // when starting output make sure we send the headers first
+ if (!$this->_bufferOutput and !$this->_httpHeaderSent)
+ $this->ensureHeadersSent();
+ echo $str;
+ }
+
+ /**
+ * Sends a file back to user.
+ * Make sure not to output anything else after calling this method.
+ * @param string file name
+ * @param string content to be set. If null, the content will be read from the server file pointed to by $fileName.
+ * @param string mime type of the content.
+ * @param array list of headers to be sent. Each array element represents a header string (e.g. 'Content-Type: text/plain').
+ * @param boolean force download of file, even if browser able to display inline. Defaults to 'true'.
+ * @param string force a specific file name on client side. Defaults to 'null' means auto-detect.
+ * @param integer size of file or content in bytes if already known. Defaults to 'null' means auto-detect.
+ * @throws TInvalidDataValueException if the file cannot be found
+ */
+ public function writeFile($fileName,$content=null,$mimeType=null,$headers=null,$forceDownload=true,$clientFileName=null,$fileSize=null)
+ {
+ static $defaultMimeTypes=array(
+ 'css'=>'text/css',
+ 'gif'=>'image/gif',
+ 'png'=>'image/png',
+ 'jpg'=>'image/jpeg',
+ 'jpeg'=>'image/jpeg',
+ 'htm'=>'text/html',
+ 'html'=>'text/html',
+ 'js'=>'javascript/js',
+ 'pdf'=>'application/pdf',
+ 'xls'=>'application/vnd.ms-excel',
+ );
+
+ if($mimeType===null)
+ {
+ $mimeType='text/plain';
+ if(function_exists('mime_content_type'))
+ $mimeType=mime_content_type($fileName);
+ else if(($ext=strrchr($fileName,'.'))!==false)
+ {
+ $ext=substr($ext,1);
+ if(isset($defaultMimeTypes[$ext]))
+ $mimeType=$defaultMimeTypes[$ext];
+ }
+ }
+
+ if($clientFileName===null)
+ $clientFileName=basename($fileName);
+ else
+ $clientFileName=basename($clientFileName);
+
+ if($fileSize===null || $fileSize < 0)
+ $fileSize = ($content===null?filesize($fileName):strlen($content));
+
+ $this->sendHttpHeader();
+ if(is_array($headers))
+ {
+ foreach($headers as $h)
+ header($h);
+ }
+ else
+ {
+ header('Pragma: public');
+ header('Expires: 0');
+ header('Cache-Control: must-revalidate, post-check=0, pre-check=0');
+ header("Content-Type: $mimeType");
+ $this->_contentTypeHeaderSent = true;
+ }
+
+ header('Content-Length: '.$fileSize);
+ header("Content-Disposition: " . ($forceDownload ? 'attachment' : 'inline') . "; filename=\"$clientFileName\"");
+ header('Content-Transfer-Encoding: binary');
+ if($content===null)
+ readfile($fileName);
+ else
+ echo $content;
+ }
+
+ /**
+ * Redirects the browser to the specified URL.
+ * The current application will be terminated after this method is invoked.
+ * @param string URL to be redirected to. If the URL is a relative one, the base URL of
+ * the current request will be inserted at the beginning.
+ */
+ public function redirect($url)
+ {
+ if($this->getHasAdapter())
+ $this->_adapter->httpRedirect($url);
+ else
+ $this->httpRedirect($url);
+ }
+
+ /**
+ * Redirect the browser to another URL and exists the current application.
+ * This method is used internally. Please use {@link redirect} instead.
+ *
+ * @since 3.1.5
+ * You can set the set {@link setStatusCode StatusCode} to a value between 300 and 399 before
+ * calling this function to change the type of redirection.
+ * If not specified, StatusCode will be 302 (Found) by default
+ *
+ * @param string URL to be redirected to. If the URL is a relative one, the base URL of
+ * the current request will be inserted at the beginning.
+ */
+ public function httpRedirect($url)
+ {
+ $this->ensureHeadersSent();
+
+ if($url[0]==='/')
+ $url=$this->getRequest()->getBaseUrl().$url;
+ if ($this->_status >= 300 && $this->_status < 400)
+ // The status code has been modified to a valid redirection status, send it
+ header('Location: '.str_replace('&amp;','&',$url), true, $this->_status);
+ else
+ header('Location: '.str_replace('&amp;','&',$url));
+
+ if(!$this->getApplication()->getRequestCompleted())
+ $this->getApplication()->onEndRequest();
+
+ exit();
+ }
+
+ /**
+ * Reloads the current page.
+ * The effect of this method call is the same as user pressing the
+ * refresh button on his browser (without post data).
+ **/
+ public function reload()
+ {
+ $this->redirect($this->getRequest()->getRequestUri());
+ }
+
+ /**
+ * Flush the response contents and headers.
+ */
+ public function flush($continueBuffering = true)
+ {
+ if($this->getHasAdapter())
+ $this->_adapter->flushContent($continueBuffering);
+ else
+ $this->flushContent($continueBuffering);
+ }
+
+ /**
+ * Ensures that HTTP response and content-type headers are sent
+ */
+ public function ensureHeadersSent()
+ {
+ $this->ensureHttpHeaderSent();
+ $this->ensureContentTypeHeaderSent();
+ }
+
+ /**
+ * Outputs the buffered content, sends content-type and charset header.
+ * This method is used internally. Please use {@link flush} instead.
+ * @param boolean whether to continue buffering after flush if buffering was active
+ */
+ public function flushContent($continueBuffering = true)
+ {
+ Prado::trace("Flushing output",'System.Web.THttpResponse');
+ $this->ensureHeadersSent();
+ if($this->_bufferOutput)
+ {
+ // avoid forced send of http headers (ob_flush() does that) if there's no output yet
+ if (ob_get_length()>0)
+ {
+ if (!$continueBuffering)
+ {
+ $this->_bufferOutput = false;
+ ob_end_flush();
+ }
+ else
+ ob_flush();
+ flush();
+ }
+ }
+ else
+ flush();
+ }
+
+ /**
+ * Ensures that the HTTP header with the status code and status reason are sent
+ */
+ protected function ensureHttpHeaderSent()
+ {
+ if (!$this->_httpHeaderSent)
+ $this->sendHttpHeader();
+ }
+
+ /**
+ * Send the HTTP header with the status code (defaults to 200) and status reason (defaults to OK)
+ */
+ protected function sendHttpHeader()
+ {
+ if (($version=$this->getRequest()->getHttpProtocolVersion())==='')
+ header (' ', true, $this->_status);
+ else
+ header($version.' '.$this->_status.' '.$this->_reason, true, $this->_status);
+ $this->_httpHeaderSent = true;
+ }
+
+ /**
+ * Ensures that the HTTP header with the status code and status reason are sent
+ */
+ protected function ensureContentTypeHeaderSent()
+ {
+ if (!$this->_contentTypeHeaderSent)
+ $this->sendContentTypeHeader();
+ }
+
+ /**
+ * Sends content type header with optional charset.
+ */
+ protected function sendContentTypeHeader()
+ {
+ $contentType=$this->_contentType===null?self::DEFAULT_CONTENTTYPE:$this->_contentType;
+ $charset=$this->getCharset();
+ if($charset === false) {
+ $this->appendHeader('Content-Type: '.$contentType);
+ return;
+ }
+
+ if($charset==='' && ($globalization=$this->getApplication()->getGlobalization(false))!==null)
+ $charset=$globalization->getCharset();
+
+ if($charset==='') $charset = self::DEFAULT_CHARSET;
+ $this->appendHeader('Content-Type: '.$contentType.';charset='.$charset);
+
+ $this->_contentTypeHeaderSent = true;
+ }
+
+ /**
+ * Returns the content in the output buffer.
+ * The buffer will NOT be cleared after calling this method.
+ * Use {@link clear()} is you want to clear the buffer.
+ * @return string output that is in the buffer.
+ */
+ public function getContents()
+ {
+ Prado::trace("Retrieving output",'System.Web.THttpResponse');
+ return $this->_bufferOutput?ob_get_contents():'';
+ }
+
+ /**
+ * Clears any existing buffered content.
+ */
+ public function clear()
+ {
+ if($this->_bufferOutput)
+ ob_clean();
+ Prado::trace("Clearing output",'System.Web.THttpResponse');
+ }
+
+ /**
+ * @param integer|null Either {@link CASE_UPPER} or {@link CASE_LOWER} or as is null (default)
+ * @return array
+ */
+ public function getHeaders($case=null)
+ {
+ $result = array();
+ $headers = headers_list();
+ foreach($headers as $header) {
+ $tmp = explode(':', $header);
+ $key = trim(array_shift($tmp));
+ $value = trim(implode(':', $tmp));
+ if(isset($result[$key]))
+ $result[$key] .= ', ' . $value;
+ else
+ $result[$key] = $value;
+ }
+
+ if($case !== null)
+ return array_change_key_case($result, $case);
+
+ return $result;
+ }
+
+ /**
+ * Sends a header.
+ * @param string header
+ * @param boolean whether the header should replace a previous similar header, or add a second header of the same type
+ */
+ public function appendHeader($value, $replace=true)
+ {
+ Prado::trace("Sending header '$value'",'System.Web.THttpResponse');
+ header($value, $replace);
+ }
+
+ /**
+ * Writes a log message into error log.
+ * This method is simple wrapper of PHP function error_log.
+ * @param string The error message that should be logged
+ * @param integer where the error should go
+ * @param string The destination. Its meaning depends on the message parameter as described above
+ * @param string The extra headers. It's used when the message parameter is set to 1. This message type uses the same internal function as mail() does.
+ * @see http://us2.php.net/manual/en/function.error-log.php
+ */
+ public function appendLog($message,$messageType=0,$destination='',$extraHeaders='')
+ {
+ error_log($message,$messageType,$destination,$extraHeaders);
+ }
+
+ /**
+ * Sends a cookie.
+ * Do not call this method directly. Operate with the result of {@link getCookies} instead.
+ * @param THttpCookie cook to be sent
+ */
+ public function addCookie($cookie)
+ {
+ $request=$this->getRequest();
+ if($request->getEnableCookieValidation())
+ {
+ $value=$this->getApplication()->getSecurityManager()->hashData($cookie->getValue());
+ setcookie(
+ $cookie->getName(),
+ $value,
+ $cookie->getExpire(),
+ $cookie->getPath(),
+ $cookie->getDomain(),
+ $cookie->getSecure(),
+ $cookie->getHttpOnly()
+ );
+ }
+ else {
+ setcookie(
+ $cookie->getName(),
+ $cookie->getValue(),
+ $cookie->getExpire(),
+ $cookie->getPath(),
+ $cookie->getDomain(),
+ $cookie->getSecure(),
+ $cookie->getHttpOnly()
+ );
+ }
+ }
+
+ /**
+ * Deletes a cookie.
+ * Do not call this method directly. Operate with the result of {@link getCookies} instead.
+ * @param THttpCookie cook to be deleted
+ */
+ public function removeCookie($cookie)
+ {
+ setcookie(
+ $cookie->getName(),
+ null,
+ 0,
+ $cookie->getPath(),
+ $cookie->getDomain(),
+ $cookie->getSecure(),
+ $cookie->getHttpOnly()
+ );
+ }
+
+ /**
+ * @return string the type of HTML writer to be used, defaults to THtmlWriter
+ */
+ public function getHtmlWriterType()
+ {
+ return $this->_htmlWriterType;
+ }
+
+ /**
+ * @param string the type of HTML writer to be used, may be the class name or the namespace
+ */
+ public function setHtmlWriterType($value)
+ {
+ $this->_htmlWriterType=$value;
+ }
+
+ /**
+ * Creates a new instance of HTML writer.
+ * If the type of the HTML writer is not supplied, {@link getHtmlWriterType HtmlWriterType} will be assumed.
+ * @param string type of the HTML writer to be created. If null, {@link getHtmlWriterType HtmlWriterType} will be assumed.
+ */
+ public function createHtmlWriter($type=null)
+ {
+ if($type===null)
+ $type=$this->getHtmlWriterType();
+ if($this->getHasAdapter())
+ return $this->_adapter->createNewHtmlWriter($type, $this);
+ else
+ return $this->createNewHtmlWriter($type, $this);
+ }
+
+ /**
+ * Create a new html writer instance.
+ * This method is used internally. Please use {@link createHtmlWriter} instead.
+ * @param string type of HTML writer to be created.
+ * @param ITextWriter text writer holding the contents.
+ */
+ public function createNewHtmlWriter($type, $writer)
+ {
+ return Prado::createComponent($type, $writer);
+ }
+}
+
diff --git a/framework/Web/THttpSession.php b/framework/Web/THttpSession.php
index 762a87f7..55d5f8b6 100644
--- a/framework/Web/THttpSession.php
+++ b/framework/Web/THttpSession.php
@@ -1,730 +1,730 @@
-<?php
-/**
- * THttpSession class
- *
- * @author Qiang Xue <qiang.xue@gmail.com>
- * @link http://www.pradosoft.com/
- * @copyright Copyright &copy; 2005-2012 PradoSoft
- * @license http://www.pradosoft.com/license/
- * @version $Id$
- * @package System.Web
- */
-
-/**
- * THttpSession class
- *
- * THttpSession provides session-level data management and the related configurations.
- * To start the session, call {@link open}; to complete and send out session data, call {@link close};
- * to destroy the session, call {@link destroy}. If AutoStart is true, then the session
- * will be started once the session module is loaded and initialized.
- *
- * To access data stored in session, use THttpSession like an associative array. For example,
- * <code>
- * $session=new THttpSession;
- * $session->open();
- * $value1=$session['name1']; // get session variable 'name1'
- * $value2=$session['name2']; // get session variable 'name2'
- * foreach($session as $name=>$value) // traverse all session variables
- * $session['name3']=$value3; // set session variable 'name3'
- * </code>
- *
- * The following configurations are available for session:
- * {@link setAutoStart AutoStart}, {@link setCookieMode CookieMode},
- * {@link setSavePath SavePath},
- * {@link setUseCustomStorage UseCustomStorage}, {@link setGCProbability GCProbability},
- * {@link setTimeout Timeout}.
- * See the corresponding setter and getter documentation for more information.
- * Note, these properties must be set before the session is started.
- *
- * THttpSession can be inherited with customized session storage method.
- * Override {@link _open}, {@link _close}, {@link _read}, {@link _write}, {@link _destroy} and {@link _gc}
- * and set {@link setUseCustomStorage UseCustomStorage} to true.
- * Then, the session data will be stored using the above methods.
- *
- * By default, THttpSession is registered with {@link TApplication} as the
- * request module. It can be accessed via {@link TApplication::getSession()}.
- *
- * THttpSession may be configured in application configuration file as follows,
- * <code>
- * <module id="session" class="THttpSession" SessionName="SSID" SavePath="/tmp"
- * CookieMode="Allow" UseCustomStorage="false" AutoStart="true" GCProbability="1"
- * UseTransparentSessionID="true" TimeOut="3600" />
- * </code>
- * where {@link getSessionName SessionName}, {@link getSavePath SavePath},
- * {@link getCookieMode CookieMode}, {@link getUseCustomStorage
- * UseCustomStorage}, {@link getAutoStart AutoStart}, {@link getGCProbability
- * GCProbability}, {@link getUseTransparentSessionID UseTransparentSessionID}
- * and {@link getTimeout TimeOut} are configurable properties of THttpSession.
- *
- * @author Qiang Xue <qiang.xue@gmail.com>
- * @version $Id$
- * @package System.Web
- * @since 3.0
- */
-class THttpSession extends TApplicationComponent implements IteratorAggregate,ArrayAccess,Countable,IModule
-{
- /**
- * @var boolean whether this module has been initialized
- */
- private $_initialized=false;
- /**
- * @var boolean whether the session has started
- */
- private $_started=false;
- /**
- * @var boolean whether the session should be started when the module is initialized
- */
- private $_autoStart=false;
- /**
- * @var THttpCookie cookie to be used to store session ID and other data
- */
- private $_cookie=null;
- /**
- * @var string module id
- */
- private $_id;
- /**
- * @var boolean
- */
- private $_customStorage=false;
-
- /**
- * @return string id of this module
- */
- public function getID()
- {
- return $this->_id;
- }
-
- /**
- * @param string id of this module
- */
- public function setID($value)
- {
- $this->_id=$value;
- }
-
- /**
- * Initializes the module.
- * This method is required by IModule.
- * If AutoStart is true, the session will be started.
- * @param TXmlElement module configuration
- */
- public function init($config)
- {
- if($this->_autoStart)
- $this->open();
- $this->_initialized=true;
- $this->getApplication()->setSession($this);
- register_shutdown_function(array($this, "close"));
- }
-
- /**
- * Starts the session if it has not started yet.
- */
- public function open()
- {
- if(!$this->_started)
- {
- if($this->_customStorage)
- session_set_save_handler(array($this,'_open'),array($this,'_close'),array($this,'_read'),array($this,'_write'),array($this,'_destroy'),array($this,'_gc'));
- if($this->_cookie!==null)
- session_set_cookie_params($this->_cookie->getExpire(),$this->_cookie->getPath(),$this->_cookie->getDomain(),$this->_cookie->getSecure());
- if(ini_get('session.auto_start')!=='1')
- session_start();
- $this->_started=true;
- }
- }
-
- /**
- * Ends the current session and store session data.
- */
- public function close()
- {
- if($this->_started)
- {
- session_write_close();
- $this->_started=false;
- }
- }
-
- /**
- * Destroys all data registered to a session.
- */
- public function destroy()
- {
- if($this->_started)
- {
- session_destroy();
- $this->_started=false;
- }
- }
-
- /**
- * Update the current session id with a newly generated one
- *
- * @param boolean $deleteOld Whether to delete the old associated session or not.
- * @return string old session id
- * @link http://php.net/manual/en/function.session-regenerate-id.php
- */
- public function regenerate($deleteOld=false)
- {
- $old = $this->getSessionID();
- session_regenerate_id($deleteOld);
- return $old;
- }
-
- /**
- * @return boolean whether the session has started
- */
- public function getIsStarted()
- {
- return $this->_started;
- }
-
- /**
- * @return string the current session ID
- */
- public function getSessionID()
- {
- return session_id();
- }
-
- /**
- * @param string the session ID for the current session
- * @throws TInvalidOperationException if session is started already
- */
- public function setSessionID($value)
- {
- if($this->_started)
- throw new TInvalidOperationException('httpsession_sessionid_unchangeable');
- else
- session_id($value);
- }
-
- /**
- * @return string the current session name
- */
- public function getSessionName()
- {
- return session_name();
- }
-
- /**
- * @param string the session name for the current session, must be an alphanumeric string, defaults to PHPSESSID
- * @throws TInvalidOperationException if session is started already
- */
- public function setSessionName($value)
- {
- if($this->_started)
- throw new TInvalidOperationException('httpsession_sessionname_unchangeable');
- else if(ctype_alnum($value))
- session_name($value);
- else
- throw new TInvalidDataValueException('httpsession_sessionname_invalid',$value);
- }
-
- /**
- * @return string the current session save path, defaults to '/tmp'.
- */
- public function getSavePath()
- {
- return session_save_path();
- }
-
- /**
- * @param string the current session save path
- * @throws TInvalidOperationException if session is started already
- */
- public function setSavePath($value)
- {
- if($this->_started)
- throw new TInvalidOperationException('httpsession_savepath_unchangeable');
- else if(is_dir($value))
- session_save_path($value);
- else
- throw new TInvalidDataValueException('httpsession_savepath_invalid',$value);
- }
-
- /**
- * @return boolean whether to use user-specified handlers to store session data. Defaults to false.
- */
- public function getUseCustomStorage()
- {
- return $this->_customStorage;
- }
-
- /**
- * @param boolean whether to use user-specified handlers to store session data.
- * If true, make sure the methods {@link _open}, {@link _close}, {@link _read},
- * {@link _write}, {@link _destroy}, and {@link _gc} are overridden in child
- * class, because they will be used as the callback handlers.
- */
- public function setUseCustomStorage($value)
- {
- $this->_customStorage=TPropertyValue::ensureBoolean($value);
- }
-
- /**
- * @return THttpCookie cookie that will be used to store session ID
- */
- public function getCookie()
- {
- if($this->_cookie===null)
- $this->_cookie=new THttpCookie($this->getSessionName(),$this->getSessionID());
- return $this->_cookie;
- }
-
- /**
- * @return THttpSessionCookieMode how to use cookie to store session ID. Defaults to THttpSessionCookieMode::Allow.
- */
- public function getCookieMode()
- {
- if(ini_get('session.use_cookies')==='0')
- return THttpSessionCookieMode::None;
- else if(ini_get('session.use_only_cookies')==='0')
- return THttpSessionCookieMode::Allow;
- else
- return THttpSessionCookieMode::Only;
- }
-
- /**
- * @param THttpSessionCookieMode how to use cookie to store session ID
- * @throws TInvalidOperationException if session is started already
- */
- public function setCookieMode($value)
- {
- if($this->_started)
- throw new TInvalidOperationException('httpsession_cookiemode_unchangeable');
- else
- {
- $value=TPropertyValue::ensureEnum($value,'THttpSessionCookieMode');
- if($value===THttpSessionCookieMode::None)
- ini_set('session.use_cookies','0');
- else if($value===THttpSessionCookieMode::Allow)
- {
- ini_set('session.use_cookies','1');
- ini_set('session.use_only_cookies','0');
- }
- else
- {
- ini_set('session.use_cookies','1');
- ini_set('session.use_only_cookies','1');
- ini_set('session.use_trans_sid', 0);
- }
- }
- }
-
- /**
- * @return boolean whether the session should be automatically started when the session module is initialized, defaults to false.
- */
- public function getAutoStart()
- {
- return $this->_autoStart;
- }
-
- /**
- * @param boolean whether the session should be automatically started when the session module is initialized, defaults to false.
- * @throws TInvalidOperationException if session is started already
- */
- public function setAutoStart($value)
- {
- if($this->_initialized)
- throw new TInvalidOperationException('httpsession_autostart_unchangeable');
- else
- $this->_autoStart=TPropertyValue::ensureBoolean($value);
- }
-
- /**
- * @return integer the probability (percentage) that the gc (garbage collection) process is started on every session initialization, defaults to 1 meaning 1% chance.
- */
- public function getGCProbability()
- {
- return TPropertyValue::ensureInteger(ini_get('session.gc_probability'));
- }
-
- /**
- * @param integer the probability (percentage) that the gc (garbage collection) process is started on every session initialization.
- * @throws TInvalidOperationException if session is started already
- * @throws TInvalidDataValueException if the value is beyond [0,100].
- */
- public function setGCProbability($value)
- {
- if($this->_started)
- throw new TInvalidOperationException('httpsession_gcprobability_unchangeable');
- else
- {
- $value=TPropertyValue::ensureInteger($value);
- if($value>=0 && $value<=100)
- {
- ini_set('session.gc_probability',$value);
- ini_set('session.gc_divisor','100');
- }
- else
- throw new TInvalidDataValueException('httpsession_gcprobability_invalid',$value);
- }
- }
-
- /**
- * @return boolean whether transparent sid support is enabled or not, defaults to false.
- */
- public function getUseTransparentSessionID()
- {
- return ini_get('session.use_trans_sid')==='1';
- }
-
- /**
- * @param boolean whether transparent sid support is enabled or not.
- */
- public function setUseTransparentSessionID($value)
- {
- if($this->_started)
- throw new TInvalidOperationException('httpsession_transid_unchangeable');
- else
- {
- $value=TPropertyValue::ensureBoolean($value);
- if ($value && $this->getCookieMode()==THttpSessionCookieMode::Only)
- throw new TInvalidOperationException('httpsession_transid_cookieonly');
- ini_set('session.use_trans_sid',$value?'1':'0');
- }
- }
-
- /**
- * @return integer the number of seconds after which data will be seen as 'garbage' and cleaned up, defaults to 1440 seconds.
- */
- public function getTimeout()
- {
- return TPropertyValue::ensureInteger(ini_get('session.gc_maxlifetime'));
- }
-
- /**
- * @param integer the number of seconds after which data will be seen as 'garbage' and cleaned up
- * @throws TInvalidOperationException if session is started already
- */
- public function setTimeout($value)
- {
- if($this->_started)
- throw new TInvalidOperationException('httpsession_maxlifetime_unchangeable');
- else
- ini_set('session.gc_maxlifetime',$value);
- }
-
- /**
- * Session open handler.
- * This method should be overridden if {@link setUseCustomStorage UseCustomStorage} is set true.
- * @param string session save path
- * @param string session name
- * @return boolean whether session is opened successfully
- */
- public function _open($savePath,$sessionName)
- {
- return true;
- }
-
- /**
- * Session close handler.
- * This method should be overridden if {@link setUseCustomStorage UseCustomStorage} is set true.
- * @return boolean whether session is closed successfully
- */
- public function _close()
- {
- return true;
- }
-
- /**
- * Session read handler.
- * This method should be overridden if {@link setUseCustomStorage UseCustomStorage} is set true.
- * @param string session ID
- * @return string the session data
- */
- public function _read($id)
- {
- return '';
- }
-
- /**
- * Session write handler.
- * This method should be overridden if {@link setUseCustomStorage UseCustomStorage} is set true.
- * @param string session ID
- * @param string session data
- * @return boolean whether session write is successful
- */
- public function _write($id,$data)
- {
- return true;
- }
-
- /**
- * Session destroy handler.
- * This method should be overridden if {@link setUseCustomStorage UseCustomStorage} is set true.
- * @param string session ID
- * @return boolean whether session is destroyed successfully
- */
- public function _destroy($id)
- {
- return true;
- }
-
- /**
- * Session GC (garbage collection) handler.
- * This method should be overridden if {@link setUseCustomStorage UseCustomStorage} is set true.
- * @param integer the number of seconds after which data will be seen as 'garbage' and cleaned up.
- * @return boolean whether session is GCed successfully
- */
- public function _gc($maxLifetime)
- {
- return true;
- }
-
- //------ The following methods enable THttpSession to be TMap-like -----
-
- /**
- * Returns an iterator for traversing the session variables.
- * This method is required by the interface IteratorAggregate.
- * @return TSessionIterator an iterator for traversing the session variables.
- */
- public function getIterator()
- {
- return new TSessionIterator;
- }
-
- /**
- * @return integer the number of session variables
- */
- public function getCount()
- {
- return count($_SESSION);
- }
-
- /**
- * Returns the number of items in the session.
- * This method is required by Countable interface.
- * @return integer number of items in the session.
- */
- public function count()
- {
- return $this->getCount();
- }
-
- /**
- * @return array the list of session variable names
- */
- public function getKeys()
- {
- return array_keys($_SESSION);
- }
-
- /**
- * Returns the session variable value with the session variable name.
- * This method is exactly the same as {@link offsetGet}.
- * @param mixed the session variable name
- * @return mixed the session variable value, null if no such variable exists
- */
- public function itemAt($key)
- {
- return isset($_SESSION[$key]) ? $_SESSION[$key] : null;
- }
-
- /**
- * Adds a session variable.
- * Note, if the specified name already exists, the old value will be removed first.
- * @param mixed session variable name
- * @param mixed session variable value
- */
- public function add($key,$value)
- {
- $_SESSION[$key]=$value;
- }
-
- /**
- * Removes a session variable.
- * @param mixed the name of the session variable to be removed
- * @return mixed the removed value, null if no such session variable.
- */
- public function remove($key)
- {
- if(isset($_SESSION[$key]))
- {
- $value=$_SESSION[$key];
- unset($_SESSION[$key]);
- return $value;
- }
- else
- return null;
- }
-
- /**
- * Removes all session variables
- */
- public function clear()
- {
- foreach(array_keys($_SESSION) as $key)
- unset($_SESSION[$key]);
- }
-
- /**
- * @param mixed session variable name
- * @return boolean whether there is the named session variable
- */
- public function contains($key)
- {
- return isset($_SESSION[$key]);
- }
-
- /**
- * @return array the list of all session variables in array
- */
- public function toArray()
- {
- return $_SESSION;
- }
-
- /**
- * This method is required by the interface ArrayAccess.
- * @param mixed the offset to check on
- * @return boolean
- */
- public function offsetExists($offset)
- {
- return isset($_SESSION[$offset]);
- }
-
- /**
- * This method is required by the interface ArrayAccess.
- * @param integer the offset to retrieve element.
- * @return mixed the element at the offset, null if no element is found at the offset
- */
- public function offsetGet($offset)
- {
- return isset($_SESSION[$offset]) ? $_SESSION[$offset] : null;
- }
-
- /**
- * This method is required by the interface ArrayAccess.
- * @param integer the offset to set element
- * @param mixed the element value
- */
- public function offsetSet($offset,$item)
- {
- $_SESSION[$offset]=$item;
- }
-
- /**
- * This method is required by the interface ArrayAccess.
- * @param mixed the offset to unset element
- */
- public function offsetUnset($offset)
- {
- unset($_SESSION[$offset]);
- }
-}
-
-/**
- * TSessionIterator class
- *
- * TSessionIterator implements Iterator interface.
- *
- * TSessionIterator is used by THttpSession. It allows THttpSession to return a new iterator
- * for traversing the session variables.
- *
- * @author Qiang Xue <qiang.xue@gmail.com>
- * @version $Id$
- * @package System.Web
- * @since 3.0
- */
-class TSessionIterator implements Iterator
-{
- /**
- * @var array list of keys in the map
- */
- private $_keys;
- /**
- * @var mixed current key
- */
- private $_key;
-
- /**
- * Constructor.
- * @param array the data to be iterated through
- */
- public function __construct()
- {
- $this->_keys=array_keys($_SESSION);
- }
-
- /**
- * Rewinds internal array pointer.
- * This method is required by the interface Iterator.
- */
- public function rewind()
- {
- $this->_key=reset($this->_keys);
- }
-
- /**
- * Returns the key of the current array element.
- * This method is required by the interface Iterator.
- * @return mixed the key of the current array element
- */
- public function key()
- {
- return $this->_key;
- }
-
- /**
- * Returns the current array element.
- * This method is required by the interface Iterator.
- * @return mixed the current array element
- */
- public function current()
- {
- return isset($_SESSION[$this->_key])?$_SESSION[$this->_key]:null;
- }
-
- /**
- * Moves the internal pointer to the next array element.
- * This method is required by the interface Iterator.
- */
- public function next()
- {
- do
- {
- $this->_key=next($this->_keys);
- }
- while(!isset($_SESSION[$this->_key]) && $this->_key!==false);
- }
-
- /**
- * Returns whether there is an element at current position.
- * This method is required by the interface Iterator.
- * @return boolean
- */
- public function valid()
- {
- return $this->_key!==false;
- }
-}
-
-
-/**
- * THttpSessionCookieMode class.
- * THttpSessionCookieMode defines the enumerable type for the possible methods of
- * using cookies to store session ID.
- *
- * The following enumerable values are defined:
- * - None: not using cookie.
- * - Allow: using cookie.
- * - Only: using cookie only.
- *
- * @author Qiang Xue <qiang.xue@gmail.com>
- * @version $Id$
- * @package System.Web
- * @since 3.0.4
- */
-class THttpSessionCookieMode extends TEnumerable
-{
- const None='None';
- const Allow='Allow';
- const Only='Only';
-}
-
+<?php
+/**
+ * THttpSession class
+ *
+ * @author Qiang Xue <qiang.xue@gmail.com>
+ * @link http://www.pradosoft.com/
+ * @copyright Copyright &copy; 2005-2012 PradoSoft
+ * @license http://www.pradosoft.com/license/
+ * @version $Id$
+ * @package System.Web
+ */
+
+/**
+ * THttpSession class
+ *
+ * THttpSession provides session-level data management and the related configurations.
+ * To start the session, call {@link open}; to complete and send out session data, call {@link close};
+ * to destroy the session, call {@link destroy}. If AutoStart is true, then the session
+ * will be started once the session module is loaded and initialized.
+ *
+ * To access data stored in session, use THttpSession like an associative array. For example,
+ * <code>
+ * $session=new THttpSession;
+ * $session->open();
+ * $value1=$session['name1']; // get session variable 'name1'
+ * $value2=$session['name2']; // get session variable 'name2'
+ * foreach($session as $name=>$value) // traverse all session variables
+ * $session['name3']=$value3; // set session variable 'name3'
+ * </code>
+ *
+ * The following configurations are available for session:
+ * {@link setAutoStart AutoStart}, {@link setCookieMode CookieMode},
+ * {@link setSavePath SavePath},
+ * {@link setUseCustomStorage UseCustomStorage}, {@link setGCProbability GCProbability},
+ * {@link setTimeout Timeout}.
+ * See the corresponding setter and getter documentation for more information.
+ * Note, these properties must be set before the session is started.
+ *
+ * THttpSession can be inherited with customized session storage method.
+ * Override {@link _open}, {@link _close}, {@link _read}, {@link _write}, {@link _destroy} and {@link _gc}
+ * and set {@link setUseCustomStorage UseCustomStorage} to true.
+ * Then, the session data will be stored using the above methods.
+ *
+ * By default, THttpSession is registered with {@link TApplication} as the
+ * request module. It can be accessed via {@link TApplication::getSession()}.
+ *
+ * THttpSession may be configured in application configuration file as follows,
+ * <code>
+ * <module id="session" class="THttpSession" SessionName="SSID" SavePath="/tmp"
+ * CookieMode="Allow" UseCustomStorage="false" AutoStart="true" GCProbability="1"
+ * UseTransparentSessionID="true" TimeOut="3600" />
+ * </code>
+ * where {@link getSessionName SessionName}, {@link getSavePath SavePath},
+ * {@link getCookieMode CookieMode}, {@link getUseCustomStorage
+ * UseCustomStorage}, {@link getAutoStart AutoStart}, {@link getGCProbability
+ * GCProbability}, {@link getUseTransparentSessionID UseTransparentSessionID}
+ * and {@link getTimeout TimeOut} are configurable properties of THttpSession.
+ *
+ * @author Qiang Xue <qiang.xue@gmail.com>
+ * @version $Id$
+ * @package System.Web
+ * @since 3.0
+ */
+class THttpSession extends TApplicationComponent implements IteratorAggregate,ArrayAccess,Countable,IModule
+{
+ /**
+ * @var boolean whether this module has been initialized
+ */
+ private $_initialized=false;
+ /**
+ * @var boolean whether the session has started
+ */
+ private $_started=false;
+ /**
+ * @var boolean whether the session should be started when the module is initialized
+ */
+ private $_autoStart=false;
+ /**
+ * @var THttpCookie cookie to be used to store session ID and other data
+ */
+ private $_cookie=null;
+ /**
+ * @var string module id
+ */
+ private $_id;
+ /**
+ * @var boolean
+ */
+ private $_customStorage=false;
+
+ /**
+ * @return string id of this module
+ */
+ public function getID()
+ {
+ return $this->_id;
+ }
+
+ /**
+ * @param string id of this module
+ */
+ public function setID($value)
+ {
+ $this->_id=$value;
+ }
+
+ /**
+ * Initializes the module.
+ * This method is required by IModule.
+ * If AutoStart is true, the session will be started.
+ * @param TXmlElement module configuration
+ */
+ public function init($config)
+ {
+ if($this->_autoStart)
+ $this->open();
+ $this->_initialized=true;
+ $this->getApplication()->setSession($this);
+ register_shutdown_function(array($this, "close"));
+ }
+
+ /**
+ * Starts the session if it has not started yet.
+ */
+ public function open()
+ {
+ if(!$this->_started)
+ {
+ if($this->_customStorage)
+ session_set_save_handler(array($this,'_open'),array($this,'_close'),array($this,'_read'),array($this,'_write'),array($this,'_destroy'),array($this,'_gc'));
+ if($this->_cookie!==null)
+ session_set_cookie_params($this->_cookie->getExpire(),$this->_cookie->getPath(),$this->_cookie->getDomain(),$this->_cookie->getSecure());
+ if(ini_get('session.auto_start')!=='1')
+ session_start();
+ $this->_started=true;
+ }
+ }
+
+ /**
+ * Ends the current session and store session data.
+ */
+ public function close()
+ {
+ if($this->_started)
+ {
+ session_write_close();
+ $this->_started=false;
+ }
+ }
+
+ /**
+ * Destroys all data registered to a session.
+ */
+ public function destroy()
+ {
+ if($this->_started)
+ {
+ session_destroy();
+ $this->_started=false;
+ }
+ }
+
+ /**
+ * Update the current session id with a newly generated one
+ *
+ * @param boolean $deleteOld Whether to delete the old associated session or not.
+ * @return string old session id
+ * @link http://php.net/manual/en/function.session-regenerate-id.php
+ */
+ public function regenerate($deleteOld=false)
+ {
+ $old = $this->getSessionID();
+ session_regenerate_id($deleteOld);
+ return $old;
+ }
+
+ /**
+ * @return boolean whether the session has started
+ */
+ public function getIsStarted()
+ {
+ return $this->_started;
+ }
+
+ /**
+ * @return string the current session ID
+ */
+ public function getSessionID()
+ {
+ return session_id();
+ }
+
+ /**
+ * @param string the session ID for the current session
+ * @throws TInvalidOperationException if session is started already
+ */
+ public function setSessionID($value)
+ {
+ if($this->_started)
+ throw new TInvalidOperationException('httpsession_sessionid_unchangeable');
+ else
+ session_id($value);
+ }
+
+ /**
+ * @return string the current session name
+ */
+ public function getSessionName()
+ {
+ return session_name();
+ }
+
+ /**
+ * @param string the session name for the current session, must be an alphanumeric string, defaults to PHPSESSID
+ * @throws TInvalidOperationException if session is started already
+ */
+ public function setSessionName($value)
+ {
+ if($this->_started)
+ throw new TInvalidOperationException('httpsession_sessionname_unchangeable');
+ else if(ctype_alnum($value))
+ session_name($value);
+ else
+ throw new TInvalidDataValueException('httpsession_sessionname_invalid',$value);
+ }
+
+ /**
+ * @return string the current session save path, defaults to '/tmp'.
+ */
+ public function getSavePath()
+ {
+ return session_save_path();
+ }
+
+ /**
+ * @param string the current session save path
+ * @throws TInvalidOperationException if session is started already
+ */
+ public function setSavePath($value)
+ {
+ if($this->_started)
+ throw new TInvalidOperationException('httpsession_savepath_unchangeable');
+ else if(is_dir($value))
+ session_save_path($value);
+ else
+ throw new TInvalidDataValueException('httpsession_savepath_invalid',$value);
+ }
+
+ /**
+ * @return boolean whether to use user-specified handlers to store session data. Defaults to false.
+ */
+ public function getUseCustomStorage()
+ {
+ return $this->_customStorage;
+ }
+
+ /**
+ * @param boolean whether to use user-specified handlers to store session data.
+ * If true, make sure the methods {@link _open}, {@link _close}, {@link _read},
+ * {@link _write}, {@link _destroy}, and {@link _gc} are overridden in child
+ * class, because they will be used as the callback handlers.
+ */
+ public function setUseCustomStorage($value)
+ {
+ $this->_customStorage=TPropertyValue::ensureBoolean($value);
+ }
+
+ /**
+ * @return THttpCookie cookie that will be used to store session ID
+ */
+ public function getCookie()
+ {
+ if($this->_cookie===null)
+ $this->_cookie=new THttpCookie($this->getSessionName(),$this->getSessionID());
+ return $this->_cookie;
+ }
+
+ /**
+ * @return THttpSessionCookieMode how to use cookie to store session ID. Defaults to THttpSessionCookieMode::Allow.
+ */
+ public function getCookieMode()
+ {
+ if(ini_get('session.use_cookies')==='0')
+ return THttpSessionCookieMode::None;
+ else if(ini_get('session.use_only_cookies')==='0')
+ return THttpSessionCookieMode::Allow;
+ else
+ return THttpSessionCookieMode::Only;
+ }
+
+ /**
+ * @param THttpSessionCookieMode how to use cookie to store session ID
+ * @throws TInvalidOperationException if session is started already
+ */
+ public function setCookieMode($value)
+ {
+ if($this->_started)
+ throw new TInvalidOperationException('httpsession_cookiemode_unchangeable');
+ else
+ {
+ $value=TPropertyValue::ensureEnum($value,'THttpSessionCookieMode');
+ if($value===THttpSessionCookieMode::None)
+ ini_set('session.use_cookies','0');
+ else if($value===THttpSessionCookieMode::Allow)
+ {
+ ini_set('session.use_cookies','1');
+ ini_set('session.use_only_cookies','0');
+ }
+ else
+ {
+ ini_set('session.use_cookies','1');
+ ini_set('session.use_only_cookies','1');
+ ini_set('session.use_trans_sid', 0);
+ }
+ }
+ }
+
+ /**
+ * @return boolean whether the session should be automatically started when the session module is initialized, defaults to false.
+ */
+ public function getAutoStart()
+ {
+ return $this->_autoStart;
+ }
+
+ /**
+ * @param boolean whether the session should be automatically started when the session module is initialized, defaults to false.
+ * @throws TInvalidOperationException if session is started already
+ */
+ public function setAutoStart($value)
+ {
+ if($this->_initialized)
+ throw new TInvalidOperationException('httpsession_autostart_unchangeable');
+ else
+ $this->_autoStart=TPropertyValue::ensureBoolean($value);
+ }
+
+ /**
+ * @return integer the probability (percentage) that the gc (garbage collection) process is started on every session initialization, defaults to 1 meaning 1% chance.
+ */
+ public function getGCProbability()
+ {
+ return TPropertyValue::ensureInteger(ini_get('session.gc_probability'));
+ }
+
+ /**
+ * @param integer the probability (percentage) that the gc (garbage collection) process is started on every session initialization.
+ * @throws TInvalidOperationException if session is started already
+ * @throws TInvalidDataValueException if the value is beyond [0,100].
+ */
+ public function setGCProbability($value)
+ {
+ if($this->_started)
+ throw new TInvalidOperationException('httpsession_gcprobability_unchangeable');
+ else
+ {
+ $value=TPropertyValue::ensureInteger($value);
+ if($value>=0 && $value<=100)
+ {
+ ini_set('session.gc_probability',$value);
+ ini_set('session.gc_divisor','100');
+ }
+ else
+ throw new TInvalidDataValueException('httpsession_gcprobability_invalid',$value);
+ }
+ }
+
+ /**
+ * @return boolean whether transparent sid support is enabled or not, defaults to false.
+ */
+ public function getUseTransparentSessionID()
+ {
+ return ini_get('session.use_trans_sid')==='1';
+ }
+
+ /**
+ * @param boolean whether transparent sid support is enabled or not.
+ */
+ public function setUseTransparentSessionID($value)
+ {
+ if($this->_started)
+ throw new TInvalidOperationException('httpsession_transid_unchangeable');
+ else
+ {
+ $value=TPropertyValue::ensureBoolean($value);
+ if ($value && $this->getCookieMode()==THttpSessionCookieMode::Only)
+ throw new TInvalidOperationException('httpsession_transid_cookieonly');
+ ini_set('session.use_trans_sid',$value?'1':'0');
+ }
+ }
+
+ /**
+ * @return integer the number of seconds after which data will be seen as 'garbage' and cleaned up, defaults to 1440 seconds.
+ */
+ public function getTimeout()
+ {
+ return TPropertyValue::ensureInteger(ini_get('session.gc_maxlifetime'));
+ }
+
+ /**
+ * @param integer the number of seconds after which data will be seen as 'garbage' and cleaned up
+ * @throws TInvalidOperationException if session is started already
+ */
+ public function setTimeout($value)
+ {
+ if($this->_started)
+ throw new TInvalidOperationException('httpsession_maxlifetime_unchangeable');
+ else
+ ini_set('session.gc_maxlifetime',$value);
+ }
+
+ /**
+ * Session open handler.
+ * This method should be overridden if {@link setUseCustomStorage UseCustomStorage} is set true.
+ * @param string session save path
+ * @param string session name
+ * @return boolean whether session is opened successfully
+ */
+ public function _open($savePath,$sessionName)
+ {
+ return true;
+ }
+
+ /**
+ * Session close handler.
+ * This method should be overridden if {@link setUseCustomStorage UseCustomStorage} is set true.
+ * @return boolean whether session is closed successfully
+ */
+ public function _close()
+ {
+ return true;
+ }
+
+ /**
+ * Session read handler.
+ * This method should be overridden if {@link setUseCustomStorage UseCustomStorage} is set true.
+ * @param string session ID
+ * @return string the session data
+ */
+ public function _read($id)
+ {
+ return '';
+ }
+
+ /**
+ * Session write handler.
+ * This method should be overridden if {@link setUseCustomStorage UseCustomStorage} is set true.
+ * @param string session ID
+ * @param string session data
+ * @return boolean whether session write is successful
+ */
+ public function _write($id,$data)
+ {
+ return true;
+ }
+
+ /**
+ * Session destroy handler.
+ * This method should be overridden if {@link setUseCustomStorage UseCustomStorage} is set true.
+ * @param string session ID
+ * @return boolean whether session is destroyed successfully
+ */
+ public function _destroy($id)
+ {
+ return true;
+ }
+
+ /**
+ * Session GC (garbage collection) handler.
+ * This method should be overridden if {@link setUseCustomStorage UseCustomStorage} is set true.
+ * @param integer the number of seconds after which data will be seen as 'garbage' and cleaned up.
+ * @return boolean whether session is GCed successfully
+ */
+ public function _gc($maxLifetime)
+ {
+ return true;
+ }
+
+ //------ The following methods enable THttpSession to be TMap-like -----
+
+ /**
+ * Returns an iterator for traversing the session variables.
+ * This method is required by the interface IteratorAggregate.
+ * @return TSessionIterator an iterator for traversing the session variables.
+ */
+ public function getIterator()
+ {
+ return new TSessionIterator;
+ }
+
+ /**
+ * @return integer the number of session variables
+ */
+ public function getCount()
+ {
+ return count($_SESSION);
+ }
+
+ /**
+ * Returns the number of items in the session.
+ * This method is required by Countable interface.
+ * @return integer number of items in the session.
+ */
+ public function count()
+ {
+ return $this->getCount();
+ }
+
+ /**
+ * @return array the list of session variable names
+ */
+ public function getKeys()
+ {
+ return array_keys($_SESSION);
+ }
+
+ /**
+ * Returns the session variable value with the session variable name.
+ * This method is exactly the same as {@link offsetGet}.
+ * @param mixed the session variable name
+ * @return mixed the session variable value, null if no such variable exists
+ */
+ public function itemAt($key)
+ {
+ return isset($_SESSION[$key]) ? $_SESSION[$key] : null;
+ }
+
+ /**
+ * Adds a session variable.
+ * Note, if the specified name already exists, the old value will be removed first.
+ * @param mixed session variable name
+ * @param mixed session variable value
+ */
+ public function add($key,$value)
+ {
+ $_SESSION[$key]=$value;
+ }
+
+ /**
+ * Removes a session variable.
+ * @param mixed the name of the session variable to be removed
+ * @return mixed the removed value, null if no such session variable.
+ */
+ public function remove($key)
+ {
+ if(isset($_SESSION[$key]))
+ {
+ $value=$_SESSION[$key];
+ unset($_SESSION[$key]);
+ return $value;
+ }
+ else
+ return null;
+ }
+
+ /**
+ * Removes all session variables
+ */
+ public function clear()
+ {
+ foreach(array_keys($_SESSION) as $key)
+ unset($_SESSION[$key]);
+ }
+
+ /**
+ * @param mixed session variable name
+ * @return boolean whether there is the named session variable
+ */
+ public function contains($key)
+ {
+ return isset($_SESSION[$key]);
+ }
+
+ /**
+ * @return array the list of all session variables in array
+ */
+ public function toArray()
+ {
+ return $_SESSION;
+ }
+
+ /**
+ * This method is required by the interface ArrayAccess.
+ * @param mixed the offset to check on
+ * @return boolean
+ */
+ public function offsetExists($offset)
+ {
+ return isset($_SESSION[$offset]);
+ }
+
+ /**
+ * This method is required by the interface ArrayAccess.
+ * @param integer the offset to retrieve element.
+ * @return mixed the element at the offset, null if no element is found at the offset
+ */
+ public function offsetGet($offset)
+ {
+ return isset($_SESSION[$offset]) ? $_SESSION[$offset] : null;
+ }
+
+ /**
+ * This method is required by the interface ArrayAccess.
+ * @param integer the offset to set element
+ * @param mixed the element value
+ */
+ public function offsetSet($offset,$item)
+ {
+ $_SESSION[$offset]=$item;
+ }
+
+ /**
+ * This method is required by the interface ArrayAccess.
+ * @param mixed the offset to unset element
+ */
+ public function offsetUnset($offset)
+ {
+ unset($_SESSION[$offset]);
+ }
+}
+
+/**
+ * TSessionIterator class
+ *
+ * TSessionIterator implements Iterator interface.
+ *
+ * TSessionIterator is used by THttpSession. It allows THttpSession to return a new iterator
+ * for traversing the session variables.
+ *
+ * @author Qiang Xue <qiang.xue@gmail.com>
+ * @version $Id$
+ * @package System.Web
+ * @since 3.0
+ */
+class TSessionIterator implements Iterator
+{
+ /**
+ * @var array list of keys in the map
+ */
+ private $_keys;
+ /**
+ * @var mixed current key
+ */
+ private $_key;
+
+ /**
+ * Constructor.
+ * @param array the data to be iterated through
+ */
+ public function __construct()
+ {
+ $this->_keys=array_keys($_SESSION);
+ }
+
+ /**
+ * Rewinds internal array pointer.
+ * This method is required by the interface Iterator.
+ */
+ public function rewind()
+ {
+ $this->_key=reset($this->_keys);
+ }
+
+ /**
+ * Returns the key of the current array element.
+ * This method is required by the interface Iterator.
+ * @return mixed the key of the current array element
+ */
+ public function key()
+ {
+ return $this->_key;
+ }
+
+ /**
+ * Returns the current array element.
+ * This method is required by the interface Iterator.
+ * @return mixed the current array element
+ */
+ public function current()
+ {
+ return isset($_SESSION[$this->_key])?$_SESSION[$this->_key]:null;
+ }
+
+ /**
+ * Moves the internal pointer to the next array element.
+ * This method is required by the interface Iterator.
+ */
+ public function next()
+ {
+ do
+ {
+ $this->_key=next($this->_keys);
+ }
+ while(!isset($_SESSION[$this->_key]) && $this->_key!==false);
+ }
+
+ /**
+ * Returns whether there is an element at current position.
+ * This method is required by the interface Iterator.
+ * @return boolean
+ */
+ public function valid()
+ {
+ return $this->_key!==false;
+ }
+}
+
+
+/**
+ * THttpSessionCookieMode class.
+ * THttpSessionCookieMode defines the enumerable type for the possible methods of
+ * using cookies to store session ID.
+ *
+ * The following enumerable values are defined:
+ * - None: not using cookie.
+ * - Allow: using cookie.
+ * - Only: using cookie only.
+ *
+ * @author Qiang Xue <qiang.xue@gmail.com>
+ * @version $Id$
+ * @package System.Web
+ * @since 3.0.4
+ */
+class THttpSessionCookieMode extends TEnumerable
+{
+ const None='None';
+ const Allow='Allow';
+ const Only='Only';
+}
+
diff --git a/framework/Web/THttpUtility.php b/framework/Web/THttpUtility.php
index 9e0bf4bb..a7a0f813 100644
--- a/framework/Web/THttpUtility.php
+++ b/framework/Web/THttpUtility.php
@@ -1,62 +1,62 @@
-<?php
-/**
- * THttpUtility class file
- *
- * @author Qiang Xue <qiang.xue@gmail.com>
- * @link http://www.pradosoft.com/
- * @copyright Copyright &copy; 2005-2012 PradoSoft
- * @license http://www.pradosoft.com/license/
- * @version $Id$
- * @package System.Web
- */
-
-/**
- * THttpUtility class
- *
- * @author Qiang Xue <qiang.xue@gmail.com>
- * @version $Id$
- * @package System.Web
- * @since 3.0
- */
-class THttpUtility
-{
- private static $_encodeTable=array('<'=>'&lt;','>'=>'&gt;','"'=>'&quot;');
- private static $_decodeTable=array('&lt;'=>'<','&gt;'=>'>','&quot;'=>'"');
- private static $_stripTable=array('&lt;'=>'','&gt;'=>'','&quot;'=>'');
-
- /**
- * HTML-encodes a string.
- * This method translates the following characters to their corresponding
- * HTML entities: <, >, "
- * Note, unlike {@link htmlspecialchars}, & is not translated.
- * @param string string to be encoded
- * @return string encoded string
- */
- public static function htmlEncode($s)
- {
- return strtr($s,self::$_encodeTable);
- }
-
- /**
- * HTML-decodes a string.
- * It is the inverse of {@link htmlEncode}.
- * @param string string to be decoded
- * @return string decoded string
- */
- public static function htmlDecode($s)
- {
- return strtr($s,self::$_decodeTable);
- }
-
- /**
- * This method strips the following characters from a string:
- * HTML entities: <, >, "
- * @param string string to be encoded
- * @return string encoded string
- */
- public static function htmlStrip($s)
- {
- return strtr($s,self::$_stripTable);
- }
-}
-
+<?php
+/**
+ * THttpUtility class file
+ *
+ * @author Qiang Xue <qiang.xue@gmail.com>
+ * @link http://www.pradosoft.com/
+ * @copyright Copyright &copy; 2005-2012 PradoSoft
+ * @license http://www.pradosoft.com/license/
+ * @version $Id$
+ * @package System.Web
+ */
+
+/**
+ * THttpUtility class
+ *
+ * @author Qiang Xue <qiang.xue@gmail.com>
+ * @version $Id$
+ * @package System.Web
+ * @since 3.0
+ */
+class THttpUtility
+{
+ private static $_encodeTable=array('<'=>'&lt;','>'=>'&gt;','"'=>'&quot;');
+ private static $_decodeTable=array('&lt;'=>'<','&gt;'=>'>','&quot;'=>'"');
+ private static $_stripTable=array('&lt;'=>'','&gt;'=>'','&quot;'=>'');
+
+ /**
+ * HTML-encodes a string.
+ * This method translates the following characters to their corresponding
+ * HTML entities: <, >, "
+ * Note, unlike {@link htmlspecialchars}, & is not translated.
+ * @param string string to be encoded
+ * @return string encoded string
+ */
+ public static function htmlEncode($s)
+ {
+ return strtr($s,self::$_encodeTable);
+ }
+
+ /**
+ * HTML-decodes a string.
+ * It is the inverse of {@link htmlEncode}.
+ * @param string string to be decoded
+ * @return string decoded string
+ */
+ public static function htmlDecode($s)
+ {
+ return strtr($s,self::$_decodeTable);
+ }
+
+ /**
+ * This method strips the following characters from a string:
+ * HTML entities: <, >, "
+ * @param string string to be encoded
+ * @return string encoded string
+ */
+ public static function htmlStrip($s)
+ {
+ return strtr($s,self::$_stripTable);
+ }
+}
+
diff --git a/framework/Web/TUrlManager.php b/framework/Web/TUrlManager.php
index f4846e28..b5a0a5be 100644
--- a/framework/Web/TUrlManager.php
+++ b/framework/Web/TUrlManager.php
@@ -1,141 +1,141 @@
-<?php
-/**
- * TUrlManager class file
- *
- * @author Qiang Xue <qiang.xue@gmail.com>
- * @link http://www.pradosoft.com/
+<?php
+/**
+ * TUrlManager class file
+ *
+ * @author Qiang Xue <qiang.xue@gmail.com>
+ * @link http://www.pradosoft.com/
* @copyright Copyright &copy; 2005-2012 PradoSoft
- * @license http://www.pradosoft.com/license/
- * @version $Id $
- * @package System.Web
- */
-
-/**
- * TUrlManager class
- *
- * TUrlManager is the base class for managing URLs that can be
- * recognized by PRADO applications. It provides the default implementation
- * for parsing and constructing URLs.
- *
- * Derived classes may override {@link constructUrl} and {@link parseUrl}
- * to provide customized URL schemes.
- *
- * By default, {@link THttpRequest} uses TUrlManager as its URL manager.
- * If you want to use your customized URL manager, load your manager class
- * as an application module and set {@link THttpRequest::setUrlManager THttpRequest.UrlManager}
- * with the ID of your URL manager module.
- *
- * @author Qiang Xue <qiang.xue@gmail.com>
- * @version $Id $
- * @package System.Web
- * @since 3.0.6
- */
-class TUrlManager extends TModule
-{
- /**
- * Constructs a URL that can be recognized by PRADO.
- *
- * This method provides the actual implementation used by {@link THttpRequest::constructUrl}.
- * Override this method if you want to provide your own way of URL formatting.
- * If you do so, you may also need to override {@link parseUrl} so that the URL can be properly parsed.
- *
- * The URL is constructed as the following format:
- * /entryscript.php?serviceID=serviceParameter&get1=value1&...
- * If {@link THttpRequest::setUrlFormat THttpRequest.UrlFormat} is 'Path',
- * the following format is used instead:
- * /entryscript.php/serviceID/serviceParameter/get1,value1/get2,value2...
- * @param string service ID
- * @param string service parameter
- * @param array GET parameters, null if not provided
- * @param boolean whether to encode the ampersand in URL
- * @param boolean whether to encode the GET parameters (their names and values)
- * @return string URL
- * @see parseUrl
- */
- public function constructUrl($serviceID,$serviceParam,$getItems,$encodeAmpersand,$encodeGetItems)
- {
- $url=$serviceID.'='.urlencode($serviceParam);
- $amp=$encodeAmpersand?'&amp;':'&';
- $request=$this->getRequest();
- if(is_array($getItems) || $getItems instanceof Traversable)
- {
- if($encodeGetItems)
- {
- foreach($getItems as $name=>$value)
- {
- if(is_array($value))
- {
- $name=urlencode($name.'[]');
- foreach($value as $v)
- $url.=$amp.$name.'='.urlencode($v);
- }
- else
- $url.=$amp.urlencode($name).'='.urlencode($value);
- }
- }
- else
- {
- foreach($getItems as $name=>$value)
- {
- if(is_array($value))
- {
- foreach($value as $v)
- $url.=$amp.$name.'[]='.$v;
- }
- else
- $url.=$amp.$name.'='.$value;
- }
- }
- }
- if($request->getUrlFormat()===THttpRequestUrlFormat::Path)
- return $request->getApplicationUrl().'/'.strtr($url,array($amp=>'/','?'=>'/','='=>$request->getUrlParamSeparator()));
- else
- return $request->getApplicationUrl().'?'.$url;
- }
-
- /**
- * Parses the request URL and returns an array of input parameters.
- * This method is automatically invoked by {@link THttpRequest} when
- * handling a user request.
- *
- * In general, this method should parse the path info part of the requesting URL
- * and generate an array of name-value pairs according to some scheme.
- * The current implementation deals with both 'Get' and 'Path' URL formats.
- *
- * You may override this method to support customized URL format.
- * @return array list of input parameters, indexed by parameter names
- * @see constructUrl
- */
- public function parseUrl()
- {
- $request=$this->getRequest();
- $pathInfo=trim($request->getPathInfo(),'/');
- if($request->getUrlFormat()===THttpRequestUrlFormat::Path && $pathInfo!=='')
- {
- $separator=$request->getUrlParamSeparator();
- $paths=explode('/',$pathInfo);
- $getVariables=array();
- foreach($paths as $path)
- {
- if(($path=trim($path))!=='')
- {
- if(($pos=strpos($path,$separator))!==false)
- {
- $name=substr($path,0,$pos);
- $value=substr($path,$pos+1);
- if(($pos=strpos($name,'[]'))!==false)
- $getVariables[substr($name,0,$pos)][]=$value;
- else
- $getVariables[$name]=$value;
- }
- else
- $getVariables[$path]='';
- }
- }
- return $getVariables;
- }
- else
- return array();
- }
-}
-
+ * @license http://www.pradosoft.com/license/
+ * @version $Id $
+ * @package System.Web
+ */
+
+/**
+ * TUrlManager class
+ *
+ * TUrlManager is the base class for managing URLs that can be
+ * recognized by PRADO applications. It provides the default implementation
+ * for parsing and constructing URLs.
+ *
+ * Derived classes may override {@link constructUrl} and {@link parseUrl}
+ * to provide customized URL schemes.
+ *
+ * By default, {@link THttpRequest} uses TUrlManager as its URL manager.
+ * If you want to use your customized URL manager, load your manager class
+ * as an application module and set {@link THttpRequest::setUrlManager THttpRequest.UrlManager}
+ * with the ID of your URL manager module.
+ *
+ * @author Qiang Xue <qiang.xue@gmail.com>
+ * @version $Id $
+ * @package System.Web
+ * @since 3.0.6
+ */
+class TUrlManager extends TModule
+{
+ /**
+ * Constructs a URL that can be recognized by PRADO.
+ *
+ * This method provides the actual implementation used by {@link THttpRequest::constructUrl}.
+ * Override this method if you want to provide your own way of URL formatting.
+ * If you do so, you may also need to override {@link parseUrl} so that the URL can be properly parsed.
+ *
+ * The URL is constructed as the following format:
+ * /entryscript.php?serviceID=serviceParameter&get1=value1&...
+ * If {@link THttpRequest::setUrlFormat THttpRequest.UrlFormat} is 'Path',
+ * the following format is used instead:
+ * /entryscript.php/serviceID/serviceParameter/get1,value1/get2,value2...
+ * @param string service ID
+ * @param string service parameter
+ * @param array GET parameters, null if not provided
+ * @param boolean whether to encode the ampersand in URL
+ * @param boolean whether to encode the GET parameters (their names and values)
+ * @return string URL
+ * @see parseUrl
+ */
+ public function constructUrl($serviceID,$serviceParam,$getItems,$encodeAmpersand,$encodeGetItems)
+ {
+ $url=$serviceID.'='.urlencode($serviceParam);
+ $amp=$encodeAmpersand?'&amp;':'&';
+ $request=$this->getRequest();
+ if(is_array($getItems) || $getItems instanceof Traversable)
+ {
+ if($encodeGetItems)
+ {
+ foreach($getItems as $name=>$value)
+ {
+ if(is_array($value))
+ {
+ $name=urlencode($name.'[]');
+ foreach($value as $v)
+ $url.=$amp.$name.'='.urlencode($v);
+ }
+ else
+ $url.=$amp.urlencode($name).'='.urlencode($value);
+ }
+ }
+ else
+ {
+ foreach($getItems as $name=>$value)
+ {
+ if(is_array($value))
+ {
+ foreach($value as $v)
+ $url.=$amp.$name.'[]='.$v;
+ }
+ else
+ $url.=$amp.$name.'='.$value;
+ }
+ }
+ }
+ if($request->getUrlFormat()===THttpRequestUrlFormat::Path)
+ return $request->getApplicationUrl().'/'.strtr($url,array($amp=>'/','?'=>'/','='=>$request->getUrlParamSeparator()));
+ else
+ return $request->getApplicationUrl().'?'.$url;
+ }
+
+ /**
+ * Parses the request URL and returns an array of input parameters.
+ * This method is automatically invoked by {@link THttpRequest} when
+ * handling a user request.
+ *
+ * In general, this method should parse the path info part of the requesting URL
+ * and generate an array of name-value pairs according to some scheme.
+ * The current implementation deals with both 'Get' and 'Path' URL formats.
+ *
+ * You may override this method to support customized URL format.
+ * @return array list of input parameters, indexed by parameter names
+ * @see constructUrl
+ */
+ public function parseUrl()
+ {
+ $request=$this->getRequest();
+ $pathInfo=trim($request->getPathInfo(),'/');
+ if($request->getUrlFormat()===THttpRequestUrlFormat::Path && $pathInfo!=='')
+ {
+ $separator=$request->getUrlParamSeparator();
+ $paths=explode('/',$pathInfo);
+ $getVariables=array();
+ foreach($paths as $path)
+ {
+ if(($path=trim($path))!=='')
+ {
+ if(($pos=strpos($path,$separator))!==false)
+ {
+ $name=substr($path,0,$pos);
+ $value=substr($path,$pos+1);
+ if(($pos=strpos($name,'[]'))!==false)
+ $getVariables[substr($name,0,$pos)][]=$value;
+ else
+ $getVariables[$name]=$value;
+ }
+ else
+ $getVariables[$path]='';
+ }
+ }
+ return $getVariables;
+ }
+ else
+ return array();
+ }
+}
+
diff --git a/framework/Web/TUrlMapping.php b/framework/Web/TUrlMapping.php
index 1cae4ee4..19891da1 100644
--- a/framework/Web/TUrlMapping.php
+++ b/framework/Web/TUrlMapping.php
@@ -1,434 +1,434 @@
-<?php
-/**
- * TUrlMapping, TUrlMappingPattern and TUrlMappingPatternSecureConnection class file.
- *
- * @author Wei Zhuo <weizhuo[at]gamil[dot]com>
- * @link http://www.pradosoft.com/
+<?php
+/**
+ * TUrlMapping, TUrlMappingPattern and TUrlMappingPatternSecureConnection class file.
+ *
+ * @author Wei Zhuo <weizhuo[at]gamil[dot]com>
+ * @link http://www.pradosoft.com/
* @copyright Copyright &copy; 2005-2012 PradoSoft
- * @license http://www.pradosoft.com/license/
- * @version $Id$
- * @package System.Web
- */
-
-Prado::using('System.Web.TUrlManager');
-Prado::using('System.Collections.TAttributeCollection');
-
-/**
- * TUrlMapping Class
- *
- * The TUrlMapping module allows PRADO to construct and recognize URLs
- * based on specific patterns.
- *
- * TUrlMapping consists of a list of URL patterns which are used to match
- * against the currently requested URL. The first matching pattern will then
- * be used to decompose the URL into request parameters (accessible through
- * <code>$this->Request['paramname']</code>).
- *
- * The patterns can also be used to construct customized URLs. In this case,
- * the parameters in an applied pattern will be replaced with the corresponding
- * GET variable values.
- *
- * Since it is derived from {@link TUrlManager}, it should be configured globally
- * in the application configuration like the following,
- * <code>
- * <module id="request" class="THttpRequest" UrlManager="friendly-url" />
- * <module id="friendly-url" class="System.Web.TUrlMapping" EnableCustomUrl="true">
- * <url ServiceParameter="Posts.ViewPost" pattern="post/{id}/" parameters.id="\d+" />
- * <url ServiceParameter="Posts.ListPost" pattern="archive/{time}/" parameters.time="\d{6}" />
- * <url ServiceParameter="Posts.ListPost" pattern="category/{cat}/" parameters.cat="\d+" />
- * </module>
- * </code>
- *
- * In the above, each <tt>&lt;url&gt;</tt> element specifies a URL pattern represented
- * as a {@link TUrlMappingPattern} internally. You may create your own pattern classes
- * by extending {@link TUrlMappingPattern} and specifying the <tt>&lt;class&gt;</tt> attribute
- * in the element.
- *
- * The patterns can be also be specified in an external file using the {@link setConfigFile ConfigFile} property.
- *
- * The URL mapping are evaluated in order, only the first mapping that matches
- * the URL will be used. Cascaded mapping can be achieved by placing the URL mappings
- * in particular order. For example, placing the most specific mappings first.
- *
- * Only the PATH_INFO part of the URL is used to match the available patterns. The matching
- * is strict in the sense that the whole pattern must match the whole PATH_INFO of the URL.
- *
- * From PRADO v3.1.1, TUrlMapping also provides support for constructing URLs according to
- * the specified pattern. You may enable this functionality by setting {@link setEnableCustomUrl EnableCustomUrl} to true.
- * When you call THttpRequest::constructUrl() (or via TPageService::constructUrl()),
- * TUrlMapping will examine the available URL mapping patterns using their {@link TUrlMappingPattern::getServiceParameter ServiceParameter}
- * and {@link TUrlMappingPattern::getPattern Pattern} properties. A pattern is applied if its
- * {@link TUrlMappingPattern::getServiceParameter ServiceParameter} matches the service parameter passed
- * to constructUrl() and every parameter in the {@link getPattern Pattern} is found
- * in the GET variables.
- *
- * @author Wei Zhuo <weizhuo[at]gmail[dot]com>
- * @version $Id$
- * @package System.Web
- * @since 3.0.5
- */
-class TUrlMapping extends TUrlManager
-{
- /**
- * @var TUrlMappingPattern[] list of patterns.
- */
- protected $_patterns=array();
- /**
- * @var TUrlMappingPattern matched pattern.
- */
- private $_matched;
- /**
- * @var string external configuration file
- */
- private $_configFile=null;
- /**
- * @var boolean whether to enable custom contructUrl
- */
- private $_customUrl=false;
- /**
- * @var array rules for constructing URLs
- */
- protected $_constructRules=array();
-
- private $_urlPrefix='';
-
- private $_defaultMappingClass='TUrlMappingPattern';
-
- /**
- * Initializes this module.
- * This method is required by the IModule interface.
- * @param mixed configuration for this module, can be null
- * @throws TConfigurationException if module is configured in the global scope.
- */
- public function init($config)
- {
- parent::init($config);
- if($this->getRequest()->getRequestResolved())
- throw new TConfigurationException('urlmapping_global_required');
- if($this->_configFile!==null)
- $this->loadConfigFile();
- $this->loadUrlMappings($config);
- if($this->_urlPrefix==='')
- $this->_urlPrefix=$this->getRequest()->getApplicationUrl();
- $this->_urlPrefix=rtrim($this->_urlPrefix,'/');
- }
-
- /**
- * Initialize the module from configuration file.
- * @throws TConfigurationException if {@link getConfigFile ConfigFile} is invalid.
- */
- protected function loadConfigFile()
- {
- if(is_file($this->_configFile))
- {
- if($this->getApplication()->getConfigurationType()==TApplication::CONFIG_TYPE_PHP)
- {
- $config = include $this->_configFile;
- $this->loadUrlMappings($dom);
- }
- else
- {
- $dom=new TXmlDocument;
- $dom->loadFromFile($this->_configFile);
- $this->loadUrlMappings($dom);
- }
- }
- else
- throw new TConfigurationException('urlmapping_configfile_inexistent',$this->_configFile);
- }
-
- /**
- * Returns a value indicating whether to enable custom constructUrl.
- * If true, constructUrl() will make use of the URL mapping rules to
- * construct valid URLs.
- * @return boolean whether to enable custom constructUrl. Defaults to false.
- * @since 3.1.1
- */
- public function getEnableCustomUrl()
- {
- return $this->_customUrl;
- }
-
- /**
- * Sets a value indicating whether to enable custom constructUrl.
- * If true, constructUrl() will make use of the URL mapping rules to
- * construct valid URLs.
- * @param boolean whether to enable custom constructUrl.
- * @since 3.1.1
- */
- public function setEnableCustomUrl($value)
- {
- $this->_customUrl=TPropertyValue::ensureBoolean($value);
- }
-
- /**
- * @return string the part that will be prefixed to the constructed URLs. Defaults to the requested script path (e.g. /path/to/index.php for a URL http://hostname/path/to/index.php)
- * @since 3.1.1
- */
- public function getUrlPrefix()
- {
- return $this->_urlPrefix;
- }
-
- /**
- * @param string the part that will be prefixed to the constructed URLs. This is used by constructUrl() when EnableCustomUrl is set true.
- * @see getUrlPrefix
- * @since 3.1.1
- */
- public function setUrlPrefix($value)
- {
- $this->_urlPrefix=$value;
- }
-
- /**
- * @return string external configuration file. Defaults to null.
- */
- public function getConfigFile()
- {
- return $this->_configFile;
- }
-
- /**
- * @param string external configuration file in namespace format. The file
- * must be suffixed with '.xml'.
- * @throws TInvalidDataValueException if the file is invalid.
- */
- public function setConfigFile($value)
- {
- if(($this->_configFile=Prado::getPathOfNamespace($value,$this->getApplication()->getConfigurationFileExt()))===null)
- throw new TConfigurationException('urlmapping_configfile_invalid',$value);
- }
-
- /**
- * @return string the default class of URL mapping patterns. Defaults to TUrlMappingPattern.
- * @since 3.1.1
- */
- public function getDefaultMappingClass()
- {
- return $this->_defaultMappingClass;
- }
-
- /**
- * Sets the default class of URL mapping patterns.
- * When a URL matching pattern does not specify "class" attribute, it will default to the class
- * specified by this property. You may use either a class name or a namespace format of class (if the class needs to be included first.)
- * @param string the default class of URL mapping patterns.
- * @since 3.1.1
- */
- public function setDefaultMappingClass($value)
- {
- $this->_defaultMappingClass=$value;
- }
-
- /**
- * Load and configure each url mapping pattern.
- * @param mixed configuration node
- * @throws TConfigurationException if specific pattern class is invalid
- */
- protected function loadUrlMappings($config)
- {
- $defaultClass = $this->getDefaultMappingClass();
-
- if(is_array($config))
- {
- if(isset($config['urls']) && is_array($config['urls']))
- {
- foreach($config['urls'] as $url)
- {
- $class=null;
- if(!isset($url['class']))
- $class=$defaultClass;
- $pattern=Prado::createComponent($class,$this);
- $properties = isset($url['properties'])?$url['properties']:array();
- $this->buildUrlMapping($class,$pattern,$properties,$url);
- }
- }
- }
- else
- {
- foreach($config->getElementsByTagName('url') as $url)
- {
- $properties=$url->getAttributes();
- if(($class=$properties->remove('class'))===null)
- $class=$defaultClass;
- $pattern=Prado::createComponent($class,$this);
- $this->buildUrlMapping($class,$pattern,$properties,$url);
- }
- }
- }
-
- private function buildUrlMapping($class, $pattern, $properties, $url)
- {
- $pattern=Prado::createComponent($class,$this);
- if(!($pattern instanceof TUrlMappingPattern))
- throw new TConfigurationException('urlmapping_urlmappingpattern_required');
- foreach($properties as $name=>$value)
- $pattern->setSubproperty($name,$value);
-
- if($url instanceof TXmlElement) {
- $text = $url -> getValue();
- if($text) {
- $text = preg_replace('/(\s+)/S', '', $text);
- if(($regExp = $pattern->getRegularExpression()) !== '')
- trigger_error(sPrintF('%s.RegularExpression property value "%s" for ServiceID="%s" and ServiceParameter="%s" was replaced by node value "%s"',
- get_class($pattern),
- $regExp,
- $pattern->getServiceID(),
- $pattern->getServiceParameter(),
- $text),
- E_USER_NOTICE);
- $pattern->setRegularExpression($text);
- }
- }
-
- $this->_patterns[]=$pattern;
- $pattern->init($url);
-
- $key=$pattern->getServiceID().':'.$pattern->getServiceParameter();
- $this->_constructRules[$key][]=$pattern;
- }
-
- /**
- * Parses the request URL and returns an array of input parameters.
- * This method overrides the parent implementation.
- * The input parameters do not include GET and POST variables.
- * This method uses the request URL path to find the first matching pattern. If found
- * the matched pattern parameters are used to return as the input parameters.
- * @return array list of input parameters
- */
- public function parseUrl()
- {
- $request=$this->getRequest();
- foreach($this->_patterns as $pattern)
- {
- $matches=$pattern->getPatternMatches($request);
- if(count($matches)>0)
- {
- $this->_matched=$pattern;
- $params=array();
- foreach($matches as $key=>$value)
- {
- if(is_string($key))
- $params[$key]=$value;
- }
- if (!$pattern->getIsWildCardPattern())
- $params[$pattern->getServiceID()]=$pattern->getServiceParameter();
- return $params;
- }
- }
- return parent::parseUrl();
- }
-
- /**
- * Constructs a URL that can be recognized by PRADO.
- *
- * This method provides the actual implementation used by {@link THttpRequest::constructUrl}.
- * Override this method if you want to provide your own way of URL formatting.
- * If you do so, you may also need to override {@link parseUrl} so that the URL can be properly parsed.
- *
- * The URL is constructed as the following format:
- * /entryscript.php?serviceID=serviceParameter&get1=value1&...
- * If {@link THttpRequest::setUrlFormat THttpRequest.UrlFormat} is 'Path',
- * the following format is used instead:
- * /entryscript.php/serviceID/serviceParameter/get1,value1/get2,value2...
- * @param string service ID
- * @param string service parameter
- * @param array GET parameters, null if not provided
- * @param boolean whether to encode the ampersand in URL
- * @param boolean whether to encode the GET parameters (their names and values)
- * @return string URL
- * @see parseUrl
- * @since 3.1.1
- */
- public function constructUrl($serviceID,$serviceParam,$getItems,$encodeAmpersand,$encodeGetItems)
- {
- if($this->_customUrl)
- {
- if(!(is_array($getItems) || ($getItems instanceof Traversable)))
- $getItems=array();
- $key=$serviceID.':'.$serviceParam;
+ * @license http://www.pradosoft.com/license/
+ * @version $Id$
+ * @package System.Web
+ */
+
+Prado::using('System.Web.TUrlManager');
+Prado::using('System.Collections.TAttributeCollection');
+
+/**
+ * TUrlMapping Class
+ *
+ * The TUrlMapping module allows PRADO to construct and recognize URLs
+ * based on specific patterns.
+ *
+ * TUrlMapping consists of a list of URL patterns which are used to match
+ * against the currently requested URL. The first matching pattern will then
+ * be used to decompose the URL into request parameters (accessible through
+ * <code>$this->Request['paramname']</code>).
+ *
+ * The patterns can also be used to construct customized URLs. In this case,
+ * the parameters in an applied pattern will be replaced with the corresponding
+ * GET variable values.
+ *
+ * Since it is derived from {@link TUrlManager}, it should be configured globally
+ * in the application configuration like the following,
+ * <code>
+ * <module id="request" class="THttpRequest" UrlManager="friendly-url" />
+ * <module id="friendly-url" class="System.Web.TUrlMapping" EnableCustomUrl="true">
+ * <url ServiceParameter="Posts.ViewPost" pattern="post/{id}/" parameters.id="\d+" />
+ * <url ServiceParameter="Posts.ListPost" pattern="archive/{time}/" parameters.time="\d{6}" />
+ * <url ServiceParameter="Posts.ListPost" pattern="category/{cat}/" parameters.cat="\d+" />
+ * </module>
+ * </code>
+ *
+ * In the above, each <tt>&lt;url&gt;</tt> element specifies a URL pattern represented
+ * as a {@link TUrlMappingPattern} internally. You may create your own pattern classes
+ * by extending {@link TUrlMappingPattern} and specifying the <tt>&lt;class&gt;</tt> attribute
+ * in the element.
+ *
+ * The patterns can be also be specified in an external file using the {@link setConfigFile ConfigFile} property.
+ *
+ * The URL mapping are evaluated in order, only the first mapping that matches
+ * the URL will be used. Cascaded mapping can be achieved by placing the URL mappings
+ * in particular order. For example, placing the most specific mappings first.
+ *
+ * Only the PATH_INFO part of the URL is used to match the available patterns. The matching
+ * is strict in the sense that the whole pattern must match the whole PATH_INFO of the URL.
+ *
+ * From PRADO v3.1.1, TUrlMapping also provides support for constructing URLs according to
+ * the specified pattern. You may enable this functionality by setting {@link setEnableCustomUrl EnableCustomUrl} to true.
+ * When you call THttpRequest::constructUrl() (or via TPageService::constructUrl()),
+ * TUrlMapping will examine the available URL mapping patterns using their {@link TUrlMappingPattern::getServiceParameter ServiceParameter}
+ * and {@link TUrlMappingPattern::getPattern Pattern} properties. A pattern is applied if its
+ * {@link TUrlMappingPattern::getServiceParameter ServiceParameter} matches the service parameter passed
+ * to constructUrl() and every parameter in the {@link getPattern Pattern} is found
+ * in the GET variables.
+ *
+ * @author Wei Zhuo <weizhuo[at]gmail[dot]com>
+ * @version $Id$
+ * @package System.Web
+ * @since 3.0.5
+ */
+class TUrlMapping extends TUrlManager
+{
+ /**
+ * @var TUrlMappingPattern[] list of patterns.
+ */
+ protected $_patterns=array();
+ /**
+ * @var TUrlMappingPattern matched pattern.
+ */
+ private $_matched;
+ /**
+ * @var string external configuration file
+ */
+ private $_configFile=null;
+ /**
+ * @var boolean whether to enable custom contructUrl
+ */
+ private $_customUrl=false;
+ /**
+ * @var array rules for constructing URLs
+ */
+ protected $_constructRules=array();
+
+ private $_urlPrefix='';
+
+ private $_defaultMappingClass='TUrlMappingPattern';
+
+ /**
+ * Initializes this module.
+ * This method is required by the IModule interface.
+ * @param mixed configuration for this module, can be null
+ * @throws TConfigurationException if module is configured in the global scope.
+ */
+ public function init($config)
+ {
+ parent::init($config);
+ if($this->getRequest()->getRequestResolved())
+ throw new TConfigurationException('urlmapping_global_required');
+ if($this->_configFile!==null)
+ $this->loadConfigFile();
+ $this->loadUrlMappings($config);
+ if($this->_urlPrefix==='')
+ $this->_urlPrefix=$this->getRequest()->getApplicationUrl();
+ $this->_urlPrefix=rtrim($this->_urlPrefix,'/');
+ }
+
+ /**
+ * Initialize the module from configuration file.
+ * @throws TConfigurationException if {@link getConfigFile ConfigFile} is invalid.
+ */
+ protected function loadConfigFile()
+ {
+ if(is_file($this->_configFile))
+ {
+ if($this->getApplication()->getConfigurationType()==TApplication::CONFIG_TYPE_PHP)
+ {
+ $config = include $this->_configFile;
+ $this->loadUrlMappings($dom);
+ }
+ else
+ {
+ $dom=new TXmlDocument;
+ $dom->loadFromFile($this->_configFile);
+ $this->loadUrlMappings($dom);
+ }
+ }
+ else
+ throw new TConfigurationException('urlmapping_configfile_inexistent',$this->_configFile);
+ }
+
+ /**
+ * Returns a value indicating whether to enable custom constructUrl.
+ * If true, constructUrl() will make use of the URL mapping rules to
+ * construct valid URLs.
+ * @return boolean whether to enable custom constructUrl. Defaults to false.
+ * @since 3.1.1
+ */
+ public function getEnableCustomUrl()
+ {
+ return $this->_customUrl;
+ }
+
+ /**
+ * Sets a value indicating whether to enable custom constructUrl.
+ * If true, constructUrl() will make use of the URL mapping rules to
+ * construct valid URLs.
+ * @param boolean whether to enable custom constructUrl.
+ * @since 3.1.1
+ */
+ public function setEnableCustomUrl($value)
+ {
+ $this->_customUrl=TPropertyValue::ensureBoolean($value);
+ }
+
+ /**
+ * @return string the part that will be prefixed to the constructed URLs. Defaults to the requested script path (e.g. /path/to/index.php for a URL http://hostname/path/to/index.php)
+ * @since 3.1.1
+ */
+ public function getUrlPrefix()
+ {
+ return $this->_urlPrefix;
+ }
+
+ /**
+ * @param string the part that will be prefixed to the constructed URLs. This is used by constructUrl() when EnableCustomUrl is set true.
+ * @see getUrlPrefix
+ * @since 3.1.1
+ */
+ public function setUrlPrefix($value)
+ {
+ $this->_urlPrefix=$value;
+ }
+
+ /**
+ * @return string external configuration file. Defaults to null.
+ */
+ public function getConfigFile()
+ {
+ return $this->_configFile;
+ }
+
+ /**
+ * @param string external configuration file in namespace format. The file
+ * must be suffixed with '.xml'.
+ * @throws TInvalidDataValueException if the file is invalid.
+ */
+ public function setConfigFile($value)
+ {
+ if(($this->_configFile=Prado::getPathOfNamespace($value,$this->getApplication()->getConfigurationFileExt()))===null)
+ throw new TConfigurationException('urlmapping_configfile_invalid',$value);
+ }
+
+ /**
+ * @return string the default class of URL mapping patterns. Defaults to TUrlMappingPattern.
+ * @since 3.1.1
+ */
+ public function getDefaultMappingClass()
+ {
+ return $this->_defaultMappingClass;
+ }
+
+ /**
+ * Sets the default class of URL mapping patterns.
+ * When a URL matching pattern does not specify "class" attribute, it will default to the class
+ * specified by this property. You may use either a class name or a namespace format of class (if the class needs to be included first.)
+ * @param string the default class of URL mapping patterns.
+ * @since 3.1.1
+ */
+ public function setDefaultMappingClass($value)
+ {
+ $this->_defaultMappingClass=$value;
+ }
+
+ /**
+ * Load and configure each url mapping pattern.
+ * @param mixed configuration node
+ * @throws TConfigurationException if specific pattern class is invalid
+ */
+ protected function loadUrlMappings($config)
+ {
+ $defaultClass = $this->getDefaultMappingClass();
+
+ if(is_array($config))
+ {
+ if(isset($config['urls']) && is_array($config['urls']))
+ {
+ foreach($config['urls'] as $url)
+ {
+ $class=null;
+ if(!isset($url['class']))
+ $class=$defaultClass;
+ $pattern=Prado::createComponent($class,$this);
+ $properties = isset($url['properties'])?$url['properties']:array();
+ $this->buildUrlMapping($class,$pattern,$properties,$url);
+ }
+ }
+ }
+ else
+ {
+ foreach($config->getElementsByTagName('url') as $url)
+ {
+ $properties=$url->getAttributes();
+ if(($class=$properties->remove('class'))===null)
+ $class=$defaultClass;
+ $pattern=Prado::createComponent($class,$this);
+ $this->buildUrlMapping($class,$pattern,$properties,$url);
+ }
+ }
+ }
+
+ private function buildUrlMapping($class, $pattern, $properties, $url)
+ {
+ $pattern=Prado::createComponent($class,$this);
+ if(!($pattern instanceof TUrlMappingPattern))
+ throw new TConfigurationException('urlmapping_urlmappingpattern_required');
+ foreach($properties as $name=>$value)
+ $pattern->setSubproperty($name,$value);
+
+ if($url instanceof TXmlElement) {
+ $text = $url -> getValue();
+ if($text) {
+ $text = preg_replace('/(\s+)/S', '', $text);
+ if(($regExp = $pattern->getRegularExpression()) !== '')
+ trigger_error(sPrintF('%s.RegularExpression property value "%s" for ServiceID="%s" and ServiceParameter="%s" was replaced by node value "%s"',
+ get_class($pattern),
+ $regExp,
+ $pattern->getServiceID(),
+ $pattern->getServiceParameter(),
+ $text),
+ E_USER_NOTICE);
+ $pattern->setRegularExpression($text);
+ }
+ }
+
+ $this->_patterns[]=$pattern;
+ $pattern->init($url);
+
+ $key=$pattern->getServiceID().':'.$pattern->getServiceParameter();
+ $this->_constructRules[$key][]=$pattern;
+ }
+
+ /**
+ * Parses the request URL and returns an array of input parameters.
+ * This method overrides the parent implementation.
+ * The input parameters do not include GET and POST variables.
+ * This method uses the request URL path to find the first matching pattern. If found
+ * the matched pattern parameters are used to return as the input parameters.
+ * @return array list of input parameters
+ */
+ public function parseUrl()
+ {
+ $request=$this->getRequest();
+ foreach($this->_patterns as $pattern)
+ {
+ $matches=$pattern->getPatternMatches($request);
+ if(count($matches)>0)
+ {
+ $this->_matched=$pattern;
+ $params=array();
+ foreach($matches as $key=>$value)
+ {
+ if(is_string($key))
+ $params[$key]=$value;
+ }
+ if (!$pattern->getIsWildCardPattern())
+ $params[$pattern->getServiceID()]=$pattern->getServiceParameter();
+ return $params;
+ }
+ }
+ return parent::parseUrl();
+ }
+
+ /**
+ * Constructs a URL that can be recognized by PRADO.
+ *
+ * This method provides the actual implementation used by {@link THttpRequest::constructUrl}.
+ * Override this method if you want to provide your own way of URL formatting.
+ * If you do so, you may also need to override {@link parseUrl} so that the URL can be properly parsed.
+ *
+ * The URL is constructed as the following format:
+ * /entryscript.php?serviceID=serviceParameter&get1=value1&...
+ * If {@link THttpRequest::setUrlFormat THttpRequest.UrlFormat} is 'Path',
+ * the following format is used instead:
+ * /entryscript.php/serviceID/serviceParameter/get1,value1/get2,value2...
+ * @param string service ID
+ * @param string service parameter
+ * @param array GET parameters, null if not provided
+ * @param boolean whether to encode the ampersand in URL
+ * @param boolean whether to encode the GET parameters (their names and values)
+ * @return string URL
+ * @see parseUrl
+ * @since 3.1.1
+ */
+ public function constructUrl($serviceID,$serviceParam,$getItems,$encodeAmpersand,$encodeGetItems)
+ {
+ if($this->_customUrl)
+ {
+ if(!(is_array($getItems) || ($getItems instanceof Traversable)))
+ $getItems=array();
+ $key=$serviceID.':'.$serviceParam;
$wildCardKey = ($pos=strrpos($serviceParam,'.'))!==false ?
$serviceID.':'.substr($serviceParam,0,$pos).'.*' : $serviceID.':*';
- if(isset($this->_constructRules[$key]))
- {
- foreach($this->_constructRules[$key] as $rule)
- {
- if($rule->supportCustomUrl($getItems))
- return $rule->constructUrl($getItems,$encodeAmpersand,$encodeGetItems);
- }
+ if(isset($this->_constructRules[$key]))
+ {
+ foreach($this->_constructRules[$key] as $rule)
+ {
+ if($rule->supportCustomUrl($getItems))
+ return $rule->constructUrl($getItems,$encodeAmpersand,$encodeGetItems);
+ }
}
elseif(isset($this->_constructRules[$wildCardKey]))
{
- foreach($this->_constructRules[$wildCardKey] as $rule)
- {
- if($rule->supportCustomUrl($getItems))
+ foreach($this->_constructRules[$wildCardKey] as $rule)
+ {
+ if($rule->supportCustomUrl($getItems))
{
$getItems['*']= $pos ? substr($serviceParam,$pos+1) : $serviceParam;
- return $rule->constructUrl($getItems,$encodeAmpersand,$encodeGetItems);
+ return $rule->constructUrl($getItems,$encodeAmpersand,$encodeGetItems);
}
- }
- }
- }
- return parent::constructUrl($serviceID,$serviceParam,$getItems,$encodeAmpersand,$encodeGetItems);
- }
-
- /**
- * @return TUrlMappingPattern the matched pattern, null if not found.
- */
- public function getMatchingPattern()
- {
- return $this->_matched;
- }
-}
-
-/**
- * TUrlMappingPattern class.
- *
- * TUrlMappingPattern represents a pattern used to parse and construct URLs.
- * If the currently requested URL matches the pattern, it will alter
- * the THttpRequest parameters. If a constructUrl() call matches the pattern
- * parameters, the pattern will generate a valid URL. In both case, only the PATH_INFO
- * part of a URL is parsed/constructed using the pattern.
- *
- * To specify the pattern, set the {@link setPattern Pattern} property.
- * {@link setPattern Pattern} takes a string expression with
- * parameter names enclosed between a left brace '{' and a right brace '}'.
- * The patterns for each parameter can be set using {@link getParameters Parameters}
- * attribute collection. For example
- * <code>
- * <url ... pattern="articles/{year}/{month}/{day}"
- * parameters.year="\d{4}" parameters.month="\d{2}" parameters.day="\d+" />
- * </code>
- *
- * In the above example, the pattern contains 3 parameters named "year",
- * "month" and "day". The pattern for these parameters are, respectively,
- * "\d{4}" (4 digits), "\d{2}" (2 digits) and "\d+" (1 or more digits).
- * Essentially, the <tt>Parameters</tt> attribute name and values are used
- * as substrings in replacing the placeholders in the <tt>Pattern</tt> string
- * to form a complete regular expression string.
- *
- * For more complicated patterns, one may specify the pattern using a regular expression
- * by {@link setRegularExpression RegularExpression}. For example, the above pattern
- * is equivalent to the following regular expression-based pattern:
- * <code>
- * #^articles/(?P<year>\d{4})/(?P<month>\d{2})\/(?P<day>\d+)$#u
- * </code>
- * The above regular expression used the "named group" feature available in PHP.
- * If you intended to use the <tt>RegularExpression</tt> property or
- * regular expressions in CDATA sections, notice that you need to escape the slash,
- * if you are using the slash as regular expressions delimiter.
- *
- * Thus, only an url that matches the pattern will be valid. For example,
- * a URL <tt>http://example.com/index.php/articles/2006/07/21</tt> will match the above pattern,
- * while <tt>http://example.com/index.php/articles/2006/07/hello</tt> will not
- * since the "day" parameter pattern is not satisfied.
- *
- * The parameter values are available through the <tt>THttpRequest</tt> instance (e.g.
- * <tt>$this->Request['year']</tt>).
- *
- * The {@link setServiceParameter ServiceParameter} and {@link setServiceID ServiceID}
- * (the default ID is 'page') set the service parameter and service id respectively.
- *
+ }
+ }
+ }
+ return parent::constructUrl($serviceID,$serviceParam,$getItems,$encodeAmpersand,$encodeGetItems);
+ }
+
+ /**
+ * @return TUrlMappingPattern the matched pattern, null if not found.
+ */
+ public function getMatchingPattern()
+ {
+ return $this->_matched;
+ }
+}
+
+/**
+ * TUrlMappingPattern class.
+ *
+ * TUrlMappingPattern represents a pattern used to parse and construct URLs.
+ * If the currently requested URL matches the pattern, it will alter
+ * the THttpRequest parameters. If a constructUrl() call matches the pattern
+ * parameters, the pattern will generate a valid URL. In both case, only the PATH_INFO
+ * part of a URL is parsed/constructed using the pattern.
+ *
+ * To specify the pattern, set the {@link setPattern Pattern} property.
+ * {@link setPattern Pattern} takes a string expression with
+ * parameter names enclosed between a left brace '{' and a right brace '}'.
+ * The patterns for each parameter can be set using {@link getParameters Parameters}
+ * attribute collection. For example
+ * <code>
+ * <url ... pattern="articles/{year}/{month}/{day}"
+ * parameters.year="\d{4}" parameters.month="\d{2}" parameters.day="\d+" />
+ * </code>
+ *
+ * In the above example, the pattern contains 3 parameters named "year",
+ * "month" and "day". The pattern for these parameters are, respectively,
+ * "\d{4}" (4 digits), "\d{2}" (2 digits) and "\d+" (1 or more digits).
+ * Essentially, the <tt>Parameters</tt> attribute name and values are used
+ * as substrings in replacing the placeholders in the <tt>Pattern</tt> string
+ * to form a complete regular expression string.
+ *
+ * For more complicated patterns, one may specify the pattern using a regular expression
+ * by {@link setRegularExpression RegularExpression}. For example, the above pattern
+ * is equivalent to the following regular expression-based pattern:
+ * <code>
+ * #^articles/(?P<year>\d{4})/(?P<month>\d{2})\/(?P<day>\d+)$#u
+ * </code>
+ * The above regular expression used the "named group" feature available in PHP.
+ * If you intended to use the <tt>RegularExpression</tt> property or
+ * regular expressions in CDATA sections, notice that you need to escape the slash,
+ * if you are using the slash as regular expressions delimiter.
+ *
+ * Thus, only an url that matches the pattern will be valid. For example,
+ * a URL <tt>http://example.com/index.php/articles/2006/07/21</tt> will match the above pattern,
+ * while <tt>http://example.com/index.php/articles/2006/07/hello</tt> will not
+ * since the "day" parameter pattern is not satisfied.
+ *
+ * The parameter values are available through the <tt>THttpRequest</tt> instance (e.g.
+ * <tt>$this->Request['year']</tt>).
+ *
+ * The {@link setServiceParameter ServiceParameter} and {@link setServiceID ServiceID}
+ * (the default ID is 'page') set the service parameter and service id respectively.
+ *
* Since 3.1.4 you can also use simplyfied wildcard patterns to match multiple
* ServiceParameters with a single rule. The pattern must contain the placeholder
* {*} for the ServiceParameter. For example
@@ -465,225 +465,225 @@ class TUrlMapping extends TUrlManager
*
* <tt>.../index.php/admin/listuser/param1-value1/param2-value2</tt>.
*
- * @author Wei Zhuo <weizhuo[at]gmail[dot]com>
- * @version $Id$
- * @package System.Web
- * @since 3.0.5
- */
-class TUrlMappingPattern extends TComponent
-{
- /**
- * @var string service parameter such as Page class name.
- */
- private $_serviceParameter;
- /**
- * @var string service ID, default is 'page'.
- */
- private $_serviceID='page';
- /**
- * @var string url pattern to match.
- */
- private $_pattern;
- /**
- * @var TMap parameter regular expressions.
- */
- private $_parameters;
- /**
- * @var string regular expression pattern.
- */
- private $_regexp='';
-
- private $_customUrl=true;
-
- private $_manager;
-
- private $_caseSensitive=true;
-
- private $_isWildCardPattern=false;
-
- private $_urlFormat=THttpRequestUrlFormat::Get;
-
- private $_separator='/';
-
- /**
- * @var TUrlMappingPatternSecureConnection
- * @since 3.2
- */
- private $_secureConnection = TUrlMappingPatternSecureConnection::Automatic;
-
- /**
- * Constructor.
- * @param TUrlManager the URL manager instance
- */
- public function __construct(TUrlManager $manager)
- {
- $this->_manager=$manager;
- $this->_parameters=new TAttributeCollection;
- $this->_parameters->setCaseSensitive(true);
- }
-
- /**
- * @return TUrlManager the URL manager instance
- */
- public function getManager()
- {
- return $this->_manager;
- }
-
- /**
- * Initializes the pattern.
- * @param TXmlElement configuration for this module.
- * @throws TConfigurationException if service parameter is not specified
- */
- public function init($config)
- {
- if($this->_serviceParameter===null)
- throw new TConfigurationException('urlmappingpattern_serviceparameter_required', $this->getPattern());
+ * @author Wei Zhuo <weizhuo[at]gmail[dot]com>
+ * @version $Id$
+ * @package System.Web
+ * @since 3.0.5
+ */
+class TUrlMappingPattern extends TComponent
+{
+ /**
+ * @var string service parameter such as Page class name.
+ */
+ private $_serviceParameter;
+ /**
+ * @var string service ID, default is 'page'.
+ */
+ private $_serviceID='page';
+ /**
+ * @var string url pattern to match.
+ */
+ private $_pattern;
+ /**
+ * @var TMap parameter regular expressions.
+ */
+ private $_parameters;
+ /**
+ * @var string regular expression pattern.
+ */
+ private $_regexp='';
+
+ private $_customUrl=true;
+
+ private $_manager;
+
+ private $_caseSensitive=true;
+
+ private $_isWildCardPattern=false;
+
+ private $_urlFormat=THttpRequestUrlFormat::Get;
+
+ private $_separator='/';
+
+ /**
+ * @var TUrlMappingPatternSecureConnection
+ * @since 3.2
+ */
+ private $_secureConnection = TUrlMappingPatternSecureConnection::Automatic;
+
+ /**
+ * Constructor.
+ * @param TUrlManager the URL manager instance
+ */
+ public function __construct(TUrlManager $manager)
+ {
+ $this->_manager=$manager;
+ $this->_parameters=new TAttributeCollection;
+ $this->_parameters->setCaseSensitive(true);
+ }
+
+ /**
+ * @return TUrlManager the URL manager instance
+ */
+ public function getManager()
+ {
+ return $this->_manager;
+ }
+
+ /**
+ * Initializes the pattern.
+ * @param TXmlElement configuration for this module.
+ * @throws TConfigurationException if service parameter is not specified
+ */
+ public function init($config)
+ {
+ if($this->_serviceParameter===null)
+ throw new TConfigurationException('urlmappingpattern_serviceparameter_required', $this->getPattern());
if(strpos($this->_serviceParameter,'*')!==false)
$this->_isWildCardPattern=true;
- }
-
- /**
- * Substitute the parameter key value pairs as named groupings
- * in the regular expression matching pattern.
- * @return string regular expression pattern with parameter subsitution
- */
- protected function getParameterizedPattern()
- {
- $params=array();
- $values=array();
- foreach($this->_parameters as $key=>$value)
- {
- $params[]='{'.$key.'}';
- $values[]='(?P<'.$key.'>'.$value.')';
- }
+ }
+
+ /**
+ * Substitute the parameter key value pairs as named groupings
+ * in the regular expression matching pattern.
+ * @return string regular expression pattern with parameter subsitution
+ */
+ protected function getParameterizedPattern()
+ {
+ $params=array();
+ $values=array();
+ foreach($this->_parameters as $key=>$value)
+ {
+ $params[]='{'.$key.'}';
+ $values[]='(?P<'.$key.'>'.$value.')';
+ }
if ($this->getIsWildCardPattern()) {
$params[]='{*}';
// service parameter must not contain '=' and '/'
$values[]='(?P<'.$this->getServiceID().'>[^=/]+)';
}
- $params[]='/';
- $values[]='\\/';
- $regexp=str_replace($params,$values,trim($this->getPattern(),'/').'/');
+ $params[]='/';
+ $values[]='\\/';
+ $regexp=str_replace($params,$values,trim($this->getPattern(),'/').'/');
if ($this->_urlFormat===THttpRequestUrlFormat::Get)
- $regexp='/^'.$regexp.'$/u';
+ $regexp='/^'.$regexp.'$/u';
+ else
+ $regexp='/^'.$regexp.'(?P<urlparams>.*)$/u';
+
+ if(!$this->getCaseSensitive())
+ $regexp.='i';
+ return $regexp;
+ }
+
+ /**
+ * @return string full regular expression mapping pattern
+ */
+ public function getRegularExpression()
+ {
+ return $this->_regexp;
+ }
+
+ /**
+ * @param string full regular expression mapping pattern.
+ */
+ public function setRegularExpression($value)
+ {
+ $this->_regexp=$value;
+ }
+
+ /**
+ * @return boolean whether the {@link getPattern Pattern} should be treated as case sensititve. Defaults to true.
+ */
+ public function getCaseSensitive()
+ {
+ return $this->_caseSensitive;
+ }
+
+ /**
+ * @param boolean whether the {@link getPattern Pattern} should be treated as case sensititve.
+ */
+ public function setCaseSensitive($value)
+ {
+ $this->_caseSensitive=TPropertyValue::ensureBoolean($value);
+ }
+
+ /**
+ * @param string service parameter, such as page class name.
+ */
+ public function setServiceParameter($value)
+ {
+ $this->_serviceParameter=$value;
+ }
+
+ /**
+ * @return string service parameter, such as page class name.
+ */
+ public function getServiceParameter()
+ {
+ return $this->_serviceParameter;
+ }
+
+ /**
+ * @param string service id to handle.
+ */
+ public function setServiceID($value)
+ {
+ $this->_serviceID=$value;
+ }
+
+ /**
+ * @return string service id.
+ */
+ public function getServiceID()
+ {
+ return $this->_serviceID;
+ }
+
+ /**
+ * @return string url pattern to match. Defaults to ''.
+ */
+ public function getPattern()
+ {
+ return $this->_pattern;
+ }
+
+ /**
+ * @param string url pattern to match.
+ */
+ public function setPattern($value)
+ {
+ $this->_pattern = $value;
+ }
+
+ /**
+ * @return TAttributeCollection parameter key value pairs.
+ */
+ public function getParameters()
+ {
+ return $this->_parameters;
+ }
+
+ /**
+ * @param TAttributeCollection new parameter key value pairs.
+ */
+ public function setParameters($value)
+ {
+ $this->_parameters=$value;
+ }
+
+ /**
+ * Uses URL pattern (or full regular expression if available) to
+ * match the given url path.
+ * @param THttpRequest the request module
+ * @return array matched parameters, empty if no matches.
+ */
+ public function getPatternMatches($request)
+ {
+ $matches=array();
+ if(($pattern=$this->getRegularExpression())!=='')
+ preg_match($pattern,$request->getPathInfo(),$matches);
else
- $regexp='/^'.$regexp.'(?P<urlparams>.*)$/u';
-
- if(!$this->getCaseSensitive())
- $regexp.='i';
- return $regexp;
- }
-
- /**
- * @return string full regular expression mapping pattern
- */
- public function getRegularExpression()
- {
- return $this->_regexp;
- }
-
- /**
- * @param string full regular expression mapping pattern.
- */
- public function setRegularExpression($value)
- {
- $this->_regexp=$value;
- }
-
- /**
- * @return boolean whether the {@link getPattern Pattern} should be treated as case sensititve. Defaults to true.
- */
- public function getCaseSensitive()
- {
- return $this->_caseSensitive;
- }
-
- /**
- * @param boolean whether the {@link getPattern Pattern} should be treated as case sensititve.
- */
- public function setCaseSensitive($value)
- {
- $this->_caseSensitive=TPropertyValue::ensureBoolean($value);
- }
-
- /**
- * @param string service parameter, such as page class name.
- */
- public function setServiceParameter($value)
- {
- $this->_serviceParameter=$value;
- }
-
- /**
- * @return string service parameter, such as page class name.
- */
- public function getServiceParameter()
- {
- return $this->_serviceParameter;
- }
-
- /**
- * @param string service id to handle.
- */
- public function setServiceID($value)
- {
- $this->_serviceID=$value;
- }
-
- /**
- * @return string service id.
- */
- public function getServiceID()
- {
- return $this->_serviceID;
- }
-
- /**
- * @return string url pattern to match. Defaults to ''.
- */
- public function getPattern()
- {
- return $this->_pattern;
- }
-
- /**
- * @param string url pattern to match.
- */
- public function setPattern($value)
- {
- $this->_pattern = $value;
- }
-
- /**
- * @return TAttributeCollection parameter key value pairs.
- */
- public function getParameters()
- {
- return $this->_parameters;
- }
-
- /**
- * @param TAttributeCollection new parameter key value pairs.
- */
- public function setParameters($value)
- {
- $this->_parameters=$value;
- }
-
- /**
- * Uses URL pattern (or full regular expression if available) to
- * match the given url path.
- * @param THttpRequest the request module
- * @return array matched parameters, empty if no matches.
- */
- public function getPatternMatches($request)
- {
- $matches=array();
- if(($pattern=$this->getRegularExpression())!=='')
- preg_match($pattern,$request->getPathInfo(),$matches);
- else
- preg_match($this->getParameterizedPattern(),trim($request->getPathInfo(),'/').'/',$matches);
+ preg_match($this->getParameterizedPattern(),trim($request->getPathInfo(),'/').'/',$matches);
if($this->getIsWildCardPattern() && isset($matches[$this->_serviceID]))
$matches[$this->_serviceID]=str_replace('*',$matches[$this->_serviceID],$this->_serviceParameter);
@@ -708,261 +708,261 @@ class TUrlMappingPattern extends TComponent
unset($matches['urlparams']);
}
- return $matches;
- }
-
- /**
- * Returns a value indicating whether to use this pattern to construct URL.
- * @return boolean whether to enable custom constructUrl. Defaults to true.
- * @since 3.1.1
- */
- public function getEnableCustomUrl()
- {
- return $this->_customUrl;
- }
-
- /**
- * Sets a value indicating whether to enable custom constructUrl using this pattern
- * @param boolean whether to enable custom constructUrl.
- */
- public function setEnableCustomUrl($value)
- {
- $this->_customUrl=TPropertyValue::ensureBoolean($value);
- }
-
- /**
- * @return boolean whether this pattern is a wildcard pattern
- * @since 3.1.4
- */
- public function getIsWildCardPattern() {
- return $this->_isWildCardPattern;
- }
-
- /**
- * @return THttpRequestUrlFormat the format of URLs. Defaults to THttpRequestUrlFormat::Get.
- */
- public function getUrlFormat()
- {
- return $this->_urlFormat;
- }
-
- /**
- * Sets the format of URLs constructed and interpreted by this pattern.
- * A Get URL format is like index.php?name1=value1&name2=value2
- * while a Path URL format is like index.php/name1/value1/name2/value.
- * The separating character between name and value can be configured with
- * {@link setUrlParamSeparator} and defaults to '/'.
- * Changing the UrlFormat will affect {@link constructUrl} and how GET variables
- * are parsed.
- * @param THttpRequestUrlFormat the format of URLs.
- * @param since 3.1.4
- */
- public function setUrlFormat($value)
- {
- $this->_urlFormat=TPropertyValue::ensureEnum($value,'THttpRequestUrlFormat');
- }
-
- /**
- * @return string separator used to separate GET variable name and value when URL format is Path. Defaults to slash '/'.
- */
- public function getUrlParamSeparator()
- {
- return $this->_separator;
- }
-
- /**
- * @param string separator used to separate GET variable name and value when URL format is Path.
- * @throws TInvalidDataValueException if the separator is not a single character
- */
- public function setUrlParamSeparator($value)
- {
- if(strlen($value)===1)
- $this->_separator=$value;
- else
- throw new TInvalidDataValueException('httprequest_separator_invalid');
- }
-
- /**
- * @return TUrlMappingPatternSecureConnection the SecureConnection behavior. Defaults to {@link TUrlMappingPatternSecureConnection::Automatic Automatic}
- * @since 3.2
- */
- public function getSecureConnection()
- {
- return $this->_secureConnection;
- }
-
- /**
- * @param TUrlMappingPatternSecureConnection the SecureConnection behavior.
- * @since 3.2
- */
- public function setSecureConnection($value)
- {
- $this->_secureConnection = TPropertyValue::ensureEnum($value, 'TUrlMappingPatternSecureConnection');
- }
-
- /**
- * @param array list of GET items to be put in the constructed URL
- * @return boolean whether this pattern IS the one for constructing the URL with the specified GET items.
- * @since 3.1.1
- */
- public function supportCustomUrl($getItems)
- {
- if(!$this->_customUrl || $this->getPattern()===null)
- return false;
- foreach($this->_parameters as $key=>$value)
- {
- if(!isset($getItems[$key]))
- return false;
- }
- return true;
- }
-
- /**
- * Constructs a URL using this pattern.
- * @param array list of GET variables
- * @param boolean whether the ampersand should be encoded in the constructed URL
- * @param boolean whether the GET variables should be encoded in the constructed URL
- * @return string the constructed URL
- * @since 3.1.1
- */
- public function constructUrl($getItems,$encodeAmpersand,$encodeGetItems)
- {
- $extra=array();
- $replace=array();
- // for the GET variables matching the pattern, put them in the URL path
- foreach($getItems as $key=>$value)
- {
- if($this->_parameters->contains($key) || $key==='*' && $this->getIsWildCardPattern())
- $replace['{'.$key.'}']=$encodeGetItems ? rawurlencode($value) : $value;
- else
- $extra[$key]=$value;
- }
-
- $url=$this->_manager->getUrlPrefix().'/'.ltrim(strtr($this->getPattern(),$replace),'/');
-
- // for the rest of the GET variables, put them in the query string
- if(count($extra)>0)
- {
+ return $matches;
+ }
+
+ /**
+ * Returns a value indicating whether to use this pattern to construct URL.
+ * @return boolean whether to enable custom constructUrl. Defaults to true.
+ * @since 3.1.1
+ */
+ public function getEnableCustomUrl()
+ {
+ return $this->_customUrl;
+ }
+
+ /**
+ * Sets a value indicating whether to enable custom constructUrl using this pattern
+ * @param boolean whether to enable custom constructUrl.
+ */
+ public function setEnableCustomUrl($value)
+ {
+ $this->_customUrl=TPropertyValue::ensureBoolean($value);
+ }
+
+ /**
+ * @return boolean whether this pattern is a wildcard pattern
+ * @since 3.1.4
+ */
+ public function getIsWildCardPattern() {
+ return $this->_isWildCardPattern;
+ }
+
+ /**
+ * @return THttpRequestUrlFormat the format of URLs. Defaults to THttpRequestUrlFormat::Get.
+ */
+ public function getUrlFormat()
+ {
+ return $this->_urlFormat;
+ }
+
+ /**
+ * Sets the format of URLs constructed and interpreted by this pattern.
+ * A Get URL format is like index.php?name1=value1&name2=value2
+ * while a Path URL format is like index.php/name1/value1/name2/value.
+ * The separating character between name and value can be configured with
+ * {@link setUrlParamSeparator} and defaults to '/'.
+ * Changing the UrlFormat will affect {@link constructUrl} and how GET variables
+ * are parsed.
+ * @param THttpRequestUrlFormat the format of URLs.
+ * @param since 3.1.4
+ */
+ public function setUrlFormat($value)
+ {
+ $this->_urlFormat=TPropertyValue::ensureEnum($value,'THttpRequestUrlFormat');
+ }
+
+ /**
+ * @return string separator used to separate GET variable name and value when URL format is Path. Defaults to slash '/'.
+ */
+ public function getUrlParamSeparator()
+ {
+ return $this->_separator;
+ }
+
+ /**
+ * @param string separator used to separate GET variable name and value when URL format is Path.
+ * @throws TInvalidDataValueException if the separator is not a single character
+ */
+ public function setUrlParamSeparator($value)
+ {
+ if(strlen($value)===1)
+ $this->_separator=$value;
+ else
+ throw new TInvalidDataValueException('httprequest_separator_invalid');
+ }
+
+ /**
+ * @return TUrlMappingPatternSecureConnection the SecureConnection behavior. Defaults to {@link TUrlMappingPatternSecureConnection::Automatic Automatic}
+ * @since 3.2
+ */
+ public function getSecureConnection()
+ {
+ return $this->_secureConnection;
+ }
+
+ /**
+ * @param TUrlMappingPatternSecureConnection the SecureConnection behavior.
+ * @since 3.2
+ */
+ public function setSecureConnection($value)
+ {
+ $this->_secureConnection = TPropertyValue::ensureEnum($value, 'TUrlMappingPatternSecureConnection');
+ }
+
+ /**
+ * @param array list of GET items to be put in the constructed URL
+ * @return boolean whether this pattern IS the one for constructing the URL with the specified GET items.
+ * @since 3.1.1
+ */
+ public function supportCustomUrl($getItems)
+ {
+ if(!$this->_customUrl || $this->getPattern()===null)
+ return false;
+ foreach($this->_parameters as $key=>$value)
+ {
+ if(!isset($getItems[$key]))
+ return false;
+ }
+ return true;
+ }
+
+ /**
+ * Constructs a URL using this pattern.
+ * @param array list of GET variables
+ * @param boolean whether the ampersand should be encoded in the constructed URL
+ * @param boolean whether the GET variables should be encoded in the constructed URL
+ * @return string the constructed URL
+ * @since 3.1.1
+ */
+ public function constructUrl($getItems,$encodeAmpersand,$encodeGetItems)
+ {
+ $extra=array();
+ $replace=array();
+ // for the GET variables matching the pattern, put them in the URL path
+ foreach($getItems as $key=>$value)
+ {
+ if($this->_parameters->contains($key) || $key==='*' && $this->getIsWildCardPattern())
+ $replace['{'.$key.'}']=$encodeGetItems ? rawurlencode($value) : $value;
+ else
+ $extra[$key]=$value;
+ }
+
+ $url=$this->_manager->getUrlPrefix().'/'.ltrim(strtr($this->getPattern(),$replace),'/');
+
+ // for the rest of the GET variables, put them in the query string
+ if(count($extra)>0)
+ {
if ($this->_urlFormat===THttpRequestUrlFormat::Path && $this->getIsWildCardPattern()) {
foreach ($extra as $name=>$value)
$url.='/'.$name.$this->_separator.($encodeGetItems?rawurlencode($value):$value);
return $url;
}
- $url2='';
- $amp=$encodeAmpersand?'&amp;':'&';
- if($encodeGetItems)
- {
- foreach($extra as $name=>$value)
- {
- if(is_array($value))
- {
- $name=rawurlencode($name.'[]');
- foreach($value as $v)
- $url2.=$amp.$name.'='.rawurlencode($v);
- }
- else
- $url2.=$amp.rawurlencode($name).'='.rawurlencode($value);
- }
- }
- else
- {
- foreach($extra as $name=>$value)
- {
- if(is_array($value))
- {
- foreach($value as $v)
- $url2.=$amp.$name.'[]='.$v;
- }
- else
- $url2.=$amp.$name.'='.$value;
- }
- }
- $url=$url.'?'.substr($url2,strlen($amp));
- }
- return $this -> applySecureConnectionPrefix($url);
- }
-
- /**
- * Apply behavior of {@link SecureConnection} property by conditionaly prefixing
- * URL with {@link THttpRequest::getBaseUrl()}
- *
- * @param string $url
- * @return string
- * @since 3.2
- */
- protected function applySecureConnectionPrefix($url)
- {
- static $request;
- if($request === null) $request = Prado::getApplication() -> getRequest();
-
- static $isSecureConnection;
- if($isSecureConnection === null) $isSecureConnection = $request -> getIsSecureConnection();
-
- switch($this -> getSecureConnection())
- {
- case TUrlMappingPatternSecureConnection::EnableIfNotSecure:
- if($isSecureConnection) return $url;
- return $request -> getBaseUrl(true) . $url;
- break;
- case TUrlMappingPatternSecureConnection::DisableIfSecure:
- if(!$isSecureConnection) return $url;
- return $request -> getBaseUrl(false) . $url;
- break;
- case TUrlMappingPatternSecureConnection::Enable:
- return $request -> getBaseUrl(true) . $url;
- break;
- case TUrlMappingPatternSecureConnection::Disable:
- return $request -> getBaseUrl(false) . $url;
- break;
- case TUrlMappingPatternSecureConnection::Automatic:
- default:
- return $url;
- break;
- }
- }
-}
-
-/**
- * TUrlMappingPatternSecureConnection class
- *
- * TUrlMappingPatternSecureConnection defines the enumerable type for the possible SecureConnection
- * URL prefix behavior that can be used by {@link TUrlMappingPattern::constructUrl()}.
- *
- * @author Yves Berkholz <godzilla80[at]gmx[dot]net>
- * @version $Id$
- * @package System.Web
- * @since 3.2
- */
-class TUrlMappingPatternSecureConnection extends TEnumerable
-{
- /**
- * Keep current SecureConnection status
- * means no prefixing
- */
- const Automatic = 'Automatic';
-
- /**
- * Force use secured connection
- * always prefixing with https://example.com/path/to/app
- */
- const Enable = 'Enable';
-
- /**
- * Force use unsecured connection
- * always prefixing with http://example.com/path/to/app
- */
- const Disable = 'Disable';
-
- /**
- * Force use secured connection, if in unsecured mode
- * prefixing with https://example.com/path/to/app
- */
- const EnableIfNotSecure = 'EnableIfNotSecure';
-
- /**
- * Force use unsecured connection, if in secured mode
- * prefixing with https://example.com/path/to/app
- */
- const DisableIfSecure = 'DisableIfSecure';
-}
+ $url2='';
+ $amp=$encodeAmpersand?'&amp;':'&';
+ if($encodeGetItems)
+ {
+ foreach($extra as $name=>$value)
+ {
+ if(is_array($value))
+ {
+ $name=rawurlencode($name.'[]');
+ foreach($value as $v)
+ $url2.=$amp.$name.'='.rawurlencode($v);
+ }
+ else
+ $url2.=$amp.rawurlencode($name).'='.rawurlencode($value);
+ }
+ }
+ else
+ {
+ foreach($extra as $name=>$value)
+ {
+ if(is_array($value))
+ {
+ foreach($value as $v)
+ $url2.=$amp.$name.'[]='.$v;
+ }
+ else
+ $url2.=$amp.$name.'='.$value;
+ }
+ }
+ $url=$url.'?'.substr($url2,strlen($amp));
+ }
+ return $this -> applySecureConnectionPrefix($url);
+ }
+
+ /**
+ * Apply behavior of {@link SecureConnection} property by conditionaly prefixing
+ * URL with {@link THttpRequest::getBaseUrl()}
+ *
+ * @param string $url
+ * @return string
+ * @since 3.2
+ */
+ protected function applySecureConnectionPrefix($url)
+ {
+ static $request;
+ if($request === null) $request = Prado::getApplication() -> getRequest();
+
+ static $isSecureConnection;
+ if($isSecureConnection === null) $isSecureConnection = $request -> getIsSecureConnection();
+
+ switch($this -> getSecureConnection())
+ {
+ case TUrlMappingPatternSecureConnection::EnableIfNotSecure:
+ if($isSecureConnection) return $url;
+ return $request -> getBaseUrl(true) . $url;
+ break;
+ case TUrlMappingPatternSecureConnection::DisableIfSecure:
+ if(!$isSecureConnection) return $url;
+ return $request -> getBaseUrl(false) . $url;
+ break;
+ case TUrlMappingPatternSecureConnection::Enable:
+ return $request -> getBaseUrl(true) . $url;
+ break;
+ case TUrlMappingPatternSecureConnection::Disable:
+ return $request -> getBaseUrl(false) . $url;
+ break;
+ case TUrlMappingPatternSecureConnection::Automatic:
+ default:
+ return $url;
+ break;
+ }
+ }
+}
+
+/**
+ * TUrlMappingPatternSecureConnection class
+ *
+ * TUrlMappingPatternSecureConnection defines the enumerable type for the possible SecureConnection
+ * URL prefix behavior that can be used by {@link TUrlMappingPattern::constructUrl()}.
+ *
+ * @author Yves Berkholz <godzilla80[at]gmx[dot]net>
+ * @version $Id$
+ * @package System.Web
+ * @since 3.2
+ */
+class TUrlMappingPatternSecureConnection extends TEnumerable
+{
+ /**
+ * Keep current SecureConnection status
+ * means no prefixing
+ */
+ const Automatic = 'Automatic';
+
+ /**
+ * Force use secured connection
+ * always prefixing with https://example.com/path/to/app
+ */
+ const Enable = 'Enable';
+
+ /**
+ * Force use unsecured connection
+ * always prefixing with http://example.com/path/to/app
+ */
+ const Disable = 'Disable';
+
+ /**
+ * Force use secured connection, if in unsecured mode
+ * prefixing with https://example.com/path/to/app
+ */
+ const EnableIfNotSecure = 'EnableIfNotSecure';
+
+ /**
+ * Force use unsecured connection, if in secured mode
+ * prefixing with https://example.com/path/to/app
+ */
+ const DisableIfSecure = 'DisableIfSecure';
+}
diff --git a/framework/Web/UI/ActiveControls/TActiveButton.php b/framework/Web/UI/ActiveControls/TActiveButton.php
index aaa10168..15b33692 100644
--- a/framework/Web/UI/ActiveControls/TActiveButton.php
+++ b/framework/Web/UI/ActiveControls/TActiveButton.php
@@ -1,132 +1,132 @@
-<?php
-/**
- * TActiveButton class file.
- *
- * @author Wei Zhuo <weizhuo[at]gamil[dot]com>
- * @link http://www.pradosoft.com/
- * @copyright Copyright &copy; 2005-2012 PradoSoft
- * @license http://www.pradosoft.com/license/
- * @version $Id$
- * @package System.Web.UI.ActiveControls
- */
-
-/**
- * Load active control adapter.
- */
-Prado::using('System.Web.UI.ActiveControls.TActiveControlAdapter');
-
-/**
- * TActiveButton is the active control counter part to TButton.
- *
- * When a TActiveButton is clicked, rather than a normal post back request a
- * callback request is initiated.
- *
- * The {@link onCallback OnCallback} event is raised during a callback request
- * and it is raise <b>after</b> the {@link onClick OnClick} event.
- *
- * When the {@link TBaseActiveCallbackControl::setEnableUpdate ActiveControl.EnableUpdate}
- * property is true, changing the {@link setText Text} property during callback request
- * will update the button's caption upon callback response completion.
- *
- * @author Wei Zhuo <weizhuo[at]gamil[dot]com>
- * @version $Id$
- * @package System.Web.UI.ActiveControls
- * @since 3.1
- */
-class TActiveButton extends TButton implements ICallbackEventHandler, IActiveControl
-{
- /**
- * Creates a new callback control, sets the adapter to
- * TActiveControlAdapter. If you override this class, be sure to set the
- * adapter appropriately by, for example, by calling this constructor.
- */
- public function __construct()
- {
- parent::__construct();
- $this->setAdapter(new TActiveControlAdapter($this));
- }
-
- /**
- * @return TBaseActiveCallbackControl standard callback control options.
- */
- public function getActiveControl()
- {
- return $this->getAdapter()->getBaseActiveControl();
- }
-
- /**
- * @return TCallbackClientSide client side request options.
- */
- public function getClientSide()
- {
- return $this->getAdapter()->getBaseActiveControl()->getClientSide();
- }
-
- /**
- * Raises the callback event. This method is required by
- * {@link ICallbackEventHandler} interface. If {@link getCausesValidation CausesValidation}
- * is true, it will invoke the page's {@link TPage::validate validate}
- * method first. It will raise {@link onClick OnClick} event first
- * and then the {@link onCallback OnCallback} event.
- * This method is mainly used by framework and control developers.
- * @param TCallbackEventParameter the event parameter
- */
- public function raiseCallbackEvent($param)
- {
- $this->raisePostBackEvent($param);
- $this->onCallback($param);
- }
-
- /**
- * This method is invoked when a callback is requested. The method raises
- * 'OnCallback' event to fire up the event handlers. If you override this
- * method, be sure to call the parent implementation so that the event
- * handler can be invoked.
- * @param TCallbackEventParameter event parameter to be passed to the event handlers
- */
- public function onCallback($param)
- {
- $this->raiseEvent('OnCallback', $this, $param);
- }
-
- /**
- * Updates the button text on the client-side if the
- * {@link setEnableUpdate EnableUpdate} property is set to true.
- * @param string caption of the button
- */
- public function setText($value)
- {
- parent::setText($value);
- if($this->getActiveControl()->canUpdateClientSide())
- $this->getPage()->getCallbackClient()->setAttribute($this, 'value', $value);
- }
-
- /**
- * Override parent implementation, no javascript is rendered here instead
- * the javascript required for active control is registered in {@link addAttributesToRender}.
- */
- protected function renderClientControlScript($writer)
- {
- }
-
- /**
- * Ensure that the ID attribute is rendered and registers the javascript code
- * for initializing the active control.
- */
- protected function addAttributesToRender($writer)
- {
- parent::addAttributesToRender($writer);
- $writer->addAttribute('id',$this->getClientID());
- $this->getActiveControl()->registerCallbackClientScript(
- $this->getClientClassName(), $this->getPostBackOptions());
- }
-
- /**
- * @return string corresponding javascript class name for this TActiveButton.
- */
- protected function getClientClassName()
- {
- return 'Prado.WebUI.TActiveButton';
- }
-}
-
+<?php
+/**
+ * TActiveButton class file.
+ *
+ * @author Wei Zhuo <weizhuo[at]gamil[dot]com>
+ * @link http://www.pradosoft.com/
+ * @copyright Copyright &copy; 2005-2012 PradoSoft
+ * @license http://www.pradosoft.com/license/
+ * @version $Id$
+ * @package System.Web.UI.ActiveControls
+ */
+
+/**
+ * Load active control adapter.
+ */
+Prado::using('System.Web.UI.ActiveControls.TActiveControlAdapter');
+
+/**
+ * TActiveButton is the active control counter part to TButton.
+ *
+ * When a TActiveButton is clicked, rather than a normal post back request a
+ * callback request is initiated.
+ *
+ * The {@link onCallback OnCallback} event is raised during a callback request
+ * and it is raise <b>after</b> the {@link onClick OnClick} event.
+ *
+ * When the {@link TBaseActiveCallbackControl::setEnableUpdate ActiveControl.EnableUpdate}
+ * property is true, changing the {@link setText Text} property during callback request
+ * will update the button's caption upon callback response completion.
+ *
+ * @author Wei Zhuo <weizhuo[at]gamil[dot]com>
+ * @version $Id$
+ * @package System.Web.UI.ActiveControls
+ * @since 3.1
+ */
+class TActiveButton extends TButton implements ICallbackEventHandler, IActiveControl
+{
+ /**
+ * Creates a new callback control, sets the adapter to
+ * TActiveControlAdapter. If you override this class, be sure to set the
+ * adapter appropriately by, for example, by calling this constructor.
+ */
+ public function __construct()
+ {
+ parent::__construct();
+ $this->setAdapter(new TActiveControlAdapter($this));
+ }
+
+ /**
+ * @return TBaseActiveCallbackControl standard callback control options.
+ */
+ public function getActiveControl()
+ {
+ return $this->getAdapter()->getBaseActiveControl();
+ }
+
+ /**
+ * @return TCallbackClientSide client side request options.
+ */
+ public function getClientSide()
+ {
+ return $this->getAdapter()->getBaseActiveControl()->getClientSide();
+ }
+
+ /**
+ * Raises the callback event. This method is required by
+ * {@link ICallbackEventHandler} interface. If {@link getCausesValidation CausesValidation}
+ * is true, it will invoke the page's {@link TPage::validate validate}
+ * method first. It will raise {@link onClick OnClick} event first
+ * and then the {@link onCallback OnCallback} event.
+ * This method is mainly used by framework and control developers.
+ * @param TCallbackEventParameter the event parameter
+ */
+ public function raiseCallbackEvent($param)
+ {
+ $this->raisePostBackEvent($param);
+ $this->onCallback($param);
+ }
+
+ /**
+ * This method is invoked when a callback is requested. The method raises
+ * 'OnCallback' event to fire up the event handlers. If you override this
+ * method, be sure to call the parent implementation so that the event
+ * handler can be invoked.
+ * @param TCallbackEventParameter event parameter to be passed to the event handlers
+ */
+ public function onCallback($param)
+ {
+ $this->raiseEvent('OnCallback', $this, $param);
+ }
+
+ /**
+ * Updates the button text on the client-side if the
+ * {@link setEnableUpdate EnableUpdate} property is set to true.
+ * @param string caption of the button
+ */
+ public function setText($value)
+ {
+ parent::setText($value);
+ if($this->getActiveControl()->canUpdateClientSide())
+ $this->getPage()->getCallbackClient()->setAttribute($this, 'value', $value);
+ }
+
+ /**
+ * Override parent implementation, no javascript is rendered here instead
+ * the javascript required for active control is registered in {@link addAttributesToRender}.
+ */
+ protected function renderClientControlScript($writer)
+ {
+ }
+
+ /**
+ * Ensure that the ID attribute is rendered and registers the javascript code
+ * for initializing the active control.
+ */
+ protected function addAttributesToRender($writer)
+ {
+ parent::addAttributesToRender($writer);
+ $writer->addAttribute('id',$this->getClientID());
+ $this->getActiveControl()->registerCallbackClientScript(
+ $this->getClientClassName(), $this->getPostBackOptions());
+ }
+
+ /**
+ * @return string corresponding javascript class name for this TActiveButton.
+ */
+ protected function getClientClassName()
+ {
+ return 'Prado.WebUI.TActiveButton';
+ }
+}
+
diff --git a/framework/Web/UI/ActiveControls/TActiveClientScript.php b/framework/Web/UI/ActiveControls/TActiveClientScript.php
index 423918d9..2e58b6b0 100755
--- a/framework/Web/UI/ActiveControls/TActiveClientScript.php
+++ b/framework/Web/UI/ActiveControls/TActiveClientScript.php
@@ -1,82 +1,82 @@
-<?php
-/**
- * TActiveClientScript class file
- *
- * @author Wei Zhuo <weizhuo[at]gmail[dot]com>
- * @link http://www.pradosoft.com/
- * @copyright Copyright &copy; 2005-2012 PradoSoft
- * @license http://www.pradosoft.com/license/
- * @version $Id: TActiveClientScript.php 3144 2012-05-19 10:07:03Z ctrlaltca $
- * @package System.Web.UI.ActiveControls
- */
-
-/**
- * TActiveClientScript class
- *
- * This is the active counterpart of the {@link TClientScript} class.
- *
- * TActiveClientScript has the ability to render itself on ajax
- * callbacks. This means that every variable or function declared in javascript
- * code will be available to the page.
- *
- * Beware that when rendered on normal (postback) or ajax callbacks, some
- * javascript code won't behave in the same way.
- * When rendered as part of a normal/postback response, scripts will execute instantly
- * where they are in the page and in a synchronous fashion.
- * Instead, when they are rendered as part of a callback response,
- * they will be executed when all DOM modifications are complete and any dynamic
- * script file includes are loaded, out-of-band and practically all blocks at once,
- * regardless of where they actually occour in the original template/markup code.
- * This can potentially hurt compatibility and graceful fallback.
- *
- * @author Wei Zhuo <weizhuo[at]gmail[dot]com>
- * @version $Id: TActiveClientScript.php 3144 2012-05-19 10:07:03Z ctrlaltca $
- * @package System.Web.UI.ActiveControls
- * @since 3.2
- */
-
-class TActiveClientScript extends TClientScript
-{
- /**
- * Renders the custom script file.
- * @param THtmLWriter the renderer
- */
- protected function renderCustomScriptFile($writer)
- {
- if(($scriptUrl = $this->getScriptUrl())!=='')
- {
- if($this->getPage()->getIsCallback())
- {
- $cs = $this->getPage()->getClientScript();
- $uniqueid=$this->ClientID.'_custom';
- if(!$cs->isScriptFileRegistered($uniqueid))
- $cs->registerScriptFile($uniqueid, $scriptUrl);
- } else {
- $writer->write("<script type=\"text/javascript\" src=\"$scriptUrl\"></script>\n");
- }
- }
- }
-
- /**
- * Registers the body content as javascript.
- * @param THtmlWriter the renderer
- */
- protected function renderCustomScript($writer)
- {
- if($this->getHasControls())
- {
- if($this->getPage()->getIsCallback())
- {
- $extWriter= $this->getPage()->getResponse()->createHtmlWriter();
- $extWriter->write("/*<![CDATA[*/\n");
- $this->renderChildren($extWriter);
- $extWriter->write("\n/*]]>*/");
- $this->getPage()->getCallbackClient()->appendScriptBlock($extWriter);
- } else {
- $writer->write("<script type=\"text/javascript\">\n/*<![CDATA[*/\n");
- $this->renderChildren($writer);
- $writer->write("\n/*]]>*/\n</script>\n");
- }
- }
- }
-}
+<?php
+/**
+ * TActiveClientScript class file
+ *
+ * @author Wei Zhuo <weizhuo[at]gmail[dot]com>
+ * @link http://www.pradosoft.com/
+ * @copyright Copyright &copy; 2005-2012 PradoSoft
+ * @license http://www.pradosoft.com/license/
+ * @version $Id: TActiveClientScript.php 3144 2012-05-19 10:07:03Z ctrlaltca $
+ * @package System.Web.UI.ActiveControls
+ */
+
+/**
+ * TActiveClientScript class
+ *
+ * This is the active counterpart of the {@link TClientScript} class.
+ *
+ * TActiveClientScript has the ability to render itself on ajax
+ * callbacks. This means that every variable or function declared in javascript
+ * code will be available to the page.
+ *
+ * Beware that when rendered on normal (postback) or ajax callbacks, some
+ * javascript code won't behave in the same way.
+ * When rendered as part of a normal/postback response, scripts will execute instantly
+ * where they are in the page and in a synchronous fashion.
+ * Instead, when they are rendered as part of a callback response,
+ * they will be executed when all DOM modifications are complete and any dynamic
+ * script file includes are loaded, out-of-band and practically all blocks at once,
+ * regardless of where they actually occour in the original template/markup code.
+ * This can potentially hurt compatibility and graceful fallback.
+ *
+ * @author Wei Zhuo <weizhuo[at]gmail[dot]com>
+ * @version $Id: TActiveClientScript.php 3144 2012-05-19 10:07:03Z ctrlaltca $
+ * @package System.Web.UI.ActiveControls
+ * @since 3.2
+ */
+
+class TActiveClientScript extends TClientScript
+{
+ /**
+ * Renders the custom script file.
+ * @param THtmLWriter the renderer
+ */
+ protected function renderCustomScriptFile($writer)
+ {
+ if(($scriptUrl = $this->getScriptUrl())!=='')
+ {
+ if($this->getPage()->getIsCallback())
+ {
+ $cs = $this->getPage()->getClientScript();
+ $uniqueid=$this->ClientID.'_custom';
+ if(!$cs->isScriptFileRegistered($uniqueid))
+ $cs->registerScriptFile($uniqueid, $scriptUrl);
+ } else {
+ $writer->write("<script type=\"text/javascript\" src=\"$scriptUrl\"></script>\n");
+ }
+ }
+ }
+
+ /**
+ * Registers the body content as javascript.
+ * @param THtmlWriter the renderer
+ */
+ protected function renderCustomScript($writer)
+ {
+ if($this->getHasControls())
+ {
+ if($this->getPage()->getIsCallback())
+ {
+ $extWriter= $this->getPage()->getResponse()->createHtmlWriter();
+ $extWriter->write("/*<![CDATA[*/\n");
+ $this->renderChildren($extWriter);
+ $extWriter->write("\n/*]]>*/");
+ $this->getPage()->getCallbackClient()->appendScriptBlock($extWriter);
+ } else {
+ $writer->write("<script type=\"text/javascript\">\n/*<![CDATA[*/\n");
+ $this->renderChildren($writer);
+ $writer->write("\n/*]]>*/\n</script>\n");
+ }
+ }
+ }
+}
diff --git a/framework/Web/UI/ActiveControls/TActiveControlAdapter.php b/framework/Web/UI/ActiveControls/TActiveControlAdapter.php
index 8a0c8aec..7e7a82fe 100644
--- a/framework/Web/UI/ActiveControls/TActiveControlAdapter.php
+++ b/framework/Web/UI/ActiveControls/TActiveControlAdapter.php
@@ -1,575 +1,575 @@
-<?php
-/**
- * TActiveControlAdapter and TCallbackPageStateTracker class file.
- *
- * @author Wei Zhuo <weizhuo[at]gamil[dot]com>
- * @link http://www.pradosoft.com/
- * @copyright Copyright &copy; 2005-2012 PradoSoft
- * @license http://www.pradosoft.com/license/
- * @version $Id$
- * @package System.Web.UI.ActiveControls
- */
-
-/*
- * Load common active control options.
- */
-Prado::using('System.Web.UI.ActiveControls.TBaseActiveControl');
-
-/**
- * TActiveControlAdapter class.
- *
- * Customize the parent TControl class for active control classes.
- * TActiveControlAdapter instantiates a common base active control class
- * throught the {@link getBaseActiveControl BaseActiveControl} property.
- * The type of BaseActiveControl can be provided in the second parameter in the
- * constructor. Default is TBaseActiveControl or TBaseActiveCallbackControl if
- * the control adapted implements ICallbackEventHandler.
- *
- * TActiveControlAdapter will tracking viewstate changes to update the
- * corresponding client-side properties.
- *
- * @author Wei Zhuo <weizhuo[at]gmail[dot]com>
- * @version $Id$
- * @package System.Web.UI.ActiveControls
- * @since 3.1
- */
-class TActiveControlAdapter extends TControlAdapter
-{
- /**
- * @var string base active control class name.
- */
- private $_activeControlType;
- /**
- * @var TBaseActiveControl base active control instance.
- */
- private $_baseActiveControl;
- /**
- * @var TCallbackPageStateTracker view state tracker.
- */
- private $_stateTracker;
-
- /**
- * Constructor.
- * @param IActiveControl active control to adapt.
- * @param string Base active control class name.
- */
- public function __construct(IActiveControl $control, $baseCallbackClass=null)
- {
- parent::__construct($control);
- $this->setBaseControlClass($baseCallbackClass);
- }
-
- /**
- * @param string base active control instance
- */
- protected function setBaseControlClass($type)
- {
- if($type===null)
- {
- if($this->getControl() instanceof ICallbackEventHandler)
- $this->_activeControlType = 'TBaseActiveCallbackControl';
- else
- $this->_activeControlType = 'TBaseActiveControl';
- }
- else
- $this->_activeControlType = $type;
- }
-
- /**
- * Publish the ajax script
- */
- public function onPreRender($param)
- {
- parent::onPreRender($param);
- }
-
- /**
- * Renders the callback client scripts.
- */
- public function render($writer)
- {
- $this->getPage()->getClientScript()->registerPradoScript('ajax');
- $this->renderCallbackClientScripts();
- if($this->_control->getVisible(false))
- {
- parent::render($writer);
- } else {
- $writer->write("<span id=\"".$this->_control->getClientID()."\" style=\"display:none\"></span>");
- }
- }
-
- /**
- * Register the callback clientscripts and sets the post loader IDs.
- */
- protected function renderCallbackClientScripts()
- {
- $cs = $this->getPage()->getClientScript();
- $key = 'Prado.CallbackRequest.addPostLoaders';
- if(!$cs->isEndScriptRegistered($key))
- {
- $data = $this->getPage()->getPostDataLoaders();
- if(count($data) > 0)
- {
- $options = TJavaScript::encode($data,false);
- $script = "Prado.CallbackRequest.addPostLoaders({$options});";
- $cs->registerEndScript($key, $script);
- }
- }
- }
-
- /**
- * @param TBaseActiveControl change base active control
- */
- public function setBaseActiveControl($control)
- {
- $this->_baseActiveControl=$control;
- }
-
- /**
- * @return TBaseActiveControl Common active control options.
- */
- public function getBaseActiveControl()
- {
- if($this->_baseActiveControl===null)
- {
- $type = $this->_activeControlType;
- $this->_baseActiveControl = new $type($this->getControl());
- }
- return $this->_baseActiveControl;
- }
-
- /**
- * @return boolean true if the viewstate needs to be tracked.
- */
- protected function getIsTrackingPageState()
- {
- if($this->getPage()->getIsCallback())
- {
- $target = $this->getPage()->getCallbackEventTarget();
- if($target instanceof ICallbackEventHandler)
- {
- $client = $target->getActiveControl()->getClientSide();
- return $client->getEnablePageStateUpdate();
- }
- }
- return false;
- }
-
- /**
- * Starts viewstate tracking if necessary after when controls has been loaded
- */
- public function onLoad($param)
- {
- if($this->getIsTrackingPageState())
- {
- $this->_stateTracker = new TCallbackPageStateTracker($this->getControl());
- $this->_stateTracker->trackChanges();
- }
- parent::onLoad($param);
- }
-
- /**
- * Saves additional persistent control state. Respond to viewstate changes
- * if necessary.
- */
- public function saveState()
- {
- if(($this->_stateTracker!==null)
- && $this->getControl()->getActiveControl()->canUpdateClientSide(true))
- {
- $this->_stateTracker->respondToChanges();
- }
- parent::saveState();
- }
-
- /**
- * @return TCallbackPageStateTracker state tracker.
- */
- public function getStateTracker()
- {
- return $this->_stateTracker;
- }
-}
-
-/**
- * TCallbackPageStateTracker class.
- *
- * Tracking changes to the page state during callback.
- *
- * @author Wei Zhuo <weizhuo[at]gmail[dot]com>
- * @version $Id$
- * @package System.Web.UI.ActiveControls
- * @since 3.1
- */
-class TCallbackPageStateTracker
-{
- /**
- * @var TMap new view state data
- */
- private $_states;
- /**
- * @var TMap old view state data
- */
- private $_existingState;
- /**
- * @var TControl the control tracked
- */
- private $_control;
- /**
- * @var object null object.
- */
- private $_nullObject;
-
- /**
- * Constructor. Add a set of default states to track.
- * @param TControl control to track.
- */
- public function __construct($control)
- {
- $this->_control = $control;
- $this->_existingState = new TMap;
- $this->_nullObject = new stdClass;
- $this->_states = new TMap;
- $this->addStatesToTrack();
- }
-
- /**
- * Add a list of view states to track. Each state is added
- * to the StatesToTrack property with the view state name as key.
- * The value should be an array with two enteries. The first entery
- * is the name of the class that will calculate the state differences.
- * The second entry is a php function/method callback that handles
- * the changes in the viewstate.
- */
- protected function addStatesToTrack()
- {
- $states = $this->getStatesToTrack();
- $states['Visible'] = array('TScalarDiff', array($this, 'updateVisible'));
- $states['Enabled'] = array('TScalarDiff', array($this, 'updateEnabled'));
- $states['Attributes'] = array('TMapCollectionDiff', array($this, 'updateAttributes'));
- $states['Style'] = array('TStyleDiff', array($this, 'updateStyle'));
- $states['TabIndex'] = array('TScalarDiff', array($this, 'updateTabIndex'));
- $states['ToolTip'] = array('TScalarDiff', array($this, 'updateToolTip'));
- $states['AccessKey'] = array('TScalarDiff', array($this, 'updateAccessKey'));
- }
-
- /**
- * @return TMap list of viewstates to track.
- */
- protected function getStatesToTrack()
- {
- return $this->_states;
- }
-
- /**
- * Start tracking view state changes. The clone function on objects are called
- * for those viewstate having an object as value.
- */
- public function trackChanges()
- {
- foreach($this->_states as $name => $value)
- {
- $obj = $this->_control->getViewState($name);
- $this->_existingState[$name] = is_object($obj) ? clone($obj) : $obj;
- }
- }
-
- /**
- * @return array list of viewstate and the changed data.
- */
- protected function getChanges()
- {
- $changes = array();
- foreach($this->_states as $name => $details)
- {
- $new = $this->_control->getViewState($name);
- $old = $this->_existingState[$name];
- if($new !== $old)
- {
- $diff = new $details[0]($new, $old, $this->_nullObject);
- if(($change = $diff->getDifference()) !== $this->_nullObject)
- $changes[] = array($details[1],array($change));
- }
- }
- return $changes;
- }
-
- /**
- * For each of the changes call the corresponding change handlers.
- */
- public function respondToChanges()
- {
- foreach($this->getChanges() as $change)
- call_user_func_array($change[0], $change[1]);
- }
-
- /**
- * @return TCallbackClientScript callback client scripting
- */
- protected function client()
- {
- return $this->_control->getPage()->getCallbackClient();
- }
-
- /**
- * Updates the tooltip.
- * @param string new tooltip
- */
- protected function updateToolTip($value)
- {
- $this->client()->setAttribute($this->_control, 'title', $value);
- }
-
- /**
- * Updates the tab index.
- * @param integer tab index
- */
- protected function updateTabIndex($value)
- {
- $this->client()->setAttribute($this->_control, 'tabindex', $value);
- }
-
- /**
- * Updates the modifier access key
- * @param string access key
- */
- protected function updateAccessKey($value)
- {
- $this->client()->setAttribute($this->_control, 'accesskey', $value);
- }
-
- /**
- * Hides or shows the control on the client-side. The control must be
- * already rendered on the client-side.
- * @param boolean true to show the control, false to hide.
- */
- protected function updateVisible($visible)
- {
- if($visible === false)
- $this->client()->replaceContent($this->_control,"<span id=\"".$this->_control->getClientID()."\" style=\"display:none\" ></span>");
- else
- $this->client()->replaceContent($this->_control,$this->_control);
- }
-
- /**
- * Enables or Disables the control on the client-side.
- * @param boolean true to enable the control, false to disable.
- */
- protected function updateEnabled($enable)
- {
- $this->client()->setAttribute($this->_control, 'disabled', $enable===false);
- }
-
- /**
- * Updates the CSS style on the control on the client-side.
- * @param array list of new CSS style declarations.
- */
- protected function updateStyle($style)
- {
- if($style['CssClass']!==null)
- $this->client()->setAttribute($this->_control, 'class', $style['CssClass']);
- if(count($style['Style']) > 0)
- $this->client()->setStyle($this->_control, $style['Style']);
- }
-
- /**
- * Updates/adds a list of attributes on the control.
- * @param array list of attribute name-value pairs.
- */
- protected function updateAttributes($attributes)
- {
- foreach($attributes as $name => $value)
- $this->client()->setAttribute($this->_control, $name, $value);
- }
-}
-
-/**
- * Calculates the viewstate changes during the request.
- *
- * @author Wei Zhuo <weizhuo[at]gmail[dot]com>
- * @version $Id$
- * @package System.Web.UI.ActiveControls
- * @since 3.1
- */
-abstract class TViewStateDiff
-{
- /**
- * @var mixed updated viewstate
- */
- protected $_new;
- /**
- * @var mixed viewstate value at the begining of the request.
- */
- protected $_old;
- /**
- * @var object null value.
- */
- protected $_null;
-
- /**
- * Constructor.
- * @param mixed updated viewstate value.
- * @param mixed viewstate value at the begining of the request.
- * @param object representing the null value.
- */
- public function __construct($new, $old, $null)
- {
- $this->_new = $new;
- $this->_old = $old;
- $this->_null = $null;
- }
-
- /**
- * @return mixed view state changes, nullObject if no difference.
- */
- public abstract function getDifference();
-}
-
-/**
- * TScalarDiff class.
- *
- * Calculate the changes to a scalar value.
- *
- * @author Wei Zhuo <weizhuo[at]gmail[dot]com>
- * @version $Id$
- * @package System.Web.UI.ActiveControls
- * @since 3.1
- */
-class TScalarDiff extends TViewStateDiff
-{
- /**
- * @return mixed update viewstate value.
- */
- public function getDifference()
- {
- if(gettype($this->_new) === gettype($this->_old)
- && $this->_new === $this->_old)
- return $this->_null;
- else
- return $this->_new;
- }
-}
-
-/**
- * TStyleDiff class.
- *
- * Calculates the changes to the Style properties.
- *
- * @author Wei Zhuo <weizhuo[at]gmail[dot]com>
- * @version $Id$
- * @package System.Web.UI.ActiveControls
- * @since 3.1
- */
-class TStyleDiff extends TViewStateDiff
-{
- /**
- * @param TStyle control style
- * @return array all the style properties combined.
- */
- protected function getCombinedStyle($obj)
- {
- if(!($obj instanceof TStyle))
- return array();
- $style = $obj->getStyleFields();
- $style = array_merge($style,$this->getStyleFromString($obj->getCustomStyle()));
- if($obj->hasFont())
- $style = array_merge($style, $this->getStyleFromString($obj->getFont()->toString()));
- return $style;
- }
-
- /**
- * @param string CSS custom style string.
- * @param array CSS style as name-value array.
- */
- protected function getStyleFromString($string)
- {
- $style = array();
- if(!is_string($string)) return $style;
-
- foreach(explode(';',$string) as $sub)
- {
- $arr=explode(':',$sub);
- if(isset($arr[1]) && trim($arr[0])!=='')
- $style[trim($arr[0])] = trim($arr[1]);
- }
- return $style;
- }
-
- /**
- * @return string changes to the CSS class name.
- */
- protected function getCssClassDiff()
- {
- if($this->_old===null)
- {
- return ($this->_new!==null) && $this->_new->hasCssClass()
- ? $this->_new->getCssClass() : null;
- }
- else
- {
- return $this->_old->getCssClass() !== $this->_new->getCssClass() ?
- $this->_new->getCssClass() : null;
- }
- }
-
- /**
- * @return array list of changes to the control style.
- */
- protected function getStyleDiff()
- {
- $diff = array_diff_assoc(
- $this->getCombinedStyle($this->_new),
- $this->getCombinedStyle($this->_old));
- return count($diff) > 0 ? $diff : null;
- }
-
- /**
- * @return array list of changes to the control style and CSS class name.
- */
- public function getDifference()
- {
- if($this->_new===null)
- return $this->_null;
- else
- {
- $css = $this->getCssClassDiff();
- $style = $this->getStyleDiff();
- if(($css!==null) || ($style!==null))
- return array('CssClass' => $css, 'Style' => $style);
- else
- $this->_null;
- }
- }
-}
-
-/**
- * TAttributesDiff class.
- *
- * Calculate the changes to attributes collection.
- *
- * @author Wei Zhuo <weizhuo[at]gmail[dot]com>
- * @version $Id$
- * @package System.Web.UI.ActiveControls
- * @since 3.1
- */
-class TMapCollectionDiff extends TViewStateDiff
-{
- /**
- * @return array updates to the attributes collection.
- */
- public function getDifference()
- {
- if($this->_old===null)
- {
- return ($this->_new!==null) ? $this->_new->toArray() : $this->_null;
- }
- else
- {
- $new = $this->_new->toArray();
- $old = $this->_old->toArray();
- $diff = array_diff_assoc($new, $old);
- return count($diff) > 0 ? $diff : $this->_null;
- }
- }
-}
-
+<?php
+/**
+ * TActiveControlAdapter and TCallbackPageStateTracker class file.
+ *
+ * @author Wei Zhuo <weizhuo[at]gamil[dot]com>
+ * @link http://www.pradosoft.com/
+ * @copyright Copyright &copy; 2005-2012 PradoSoft
+ * @license http://www.pradosoft.com/license/
+ * @version $Id$
+ * @package System.Web.UI.ActiveControls
+ */
+
+/*
+ * Load common active control options.
+ */
+Prado::using('System.Web.UI.ActiveControls.TBaseActiveControl');
+
+/**
+ * TActiveControlAdapter class.
+ *
+ * Customize the parent TControl class for active control classes.
+ * TActiveControlAdapter instantiates a common base active control class
+ * throught the {@link getBaseActiveControl BaseActiveControl} property.
+ * The type of BaseActiveControl can be provided in the second parameter in the
+ * constructor. Default is TBaseActiveControl or TBaseActiveCallbackControl if
+ * the control adapted implements ICallbackEventHandler.
+ *
+ * TActiveControlAdapter will tracking viewstate changes to update the
+ * corresponding client-side properties.
+ *
+ * @author Wei Zhuo <weizhuo[at]gmail[dot]com>
+ * @version $Id$
+ * @package System.Web.UI.ActiveControls
+ * @since 3.1
+ */
+class TActiveControlAdapter extends TControlAdapter
+{
+ /**
+ * @var string base active control class name.
+ */
+ private $_activeControlType;
+ /**
+ * @var TBaseActiveControl base active control instance.
+ */
+ private $_baseActiveControl;
+ /**
+ * @var TCallbackPageStateTracker view state tracker.
+ */
+ private $_stateTracker;
+
+ /**
+ * Constructor.
+ * @param IActiveControl active control to adapt.
+ * @param string Base active control class name.
+ */
+ public function __construct(IActiveControl $control, $baseCallbackClass=null)
+ {
+ parent::__construct($control);
+ $this->setBaseControlClass($baseCallbackClass);
+ }
+
+ /**
+ * @param string base active control instance
+ */
+ protected function setBaseControlClass($type)
+ {
+ if($type===null)
+ {
+ if($this->getControl() instanceof ICallbackEventHandler)
+ $this->_activeControlType = 'TBaseActiveCallbackControl';
+ else
+ $this->_activeControlType = 'TBaseActiveControl';
+ }
+ else
+ $this->_activeControlType = $type;
+ }
+
+ /**
+ * Publish the ajax script
+ */
+ public function onPreRender($param)
+ {
+ parent::onPreRender($param);
+ }
+
+ /**
+ * Renders the callback client scripts.
+ */
+ public function render($writer)
+ {
+ $this->getPage()->getClientScript()->registerPradoScript('ajax');
+ $this->renderCallbackClientScripts();
+ if($this->_control->getVisible(false))
+ {
+ parent::render($writer);
+ } else {
+ $writer->write("<span id=\"".$this->_control->getClientID()."\" style=\"display:none\"></span>");
+ }
+ }
+
+ /**
+ * Register the callback clientscripts and sets the post loader IDs.
+ */
+ protected function renderCallbackClientScripts()
+ {
+ $cs = $this->getPage()->getClientScript();
+ $key = 'Prado.CallbackRequest.addPostLoaders';
+ if(!$cs->isEndScriptRegistered($key))
+ {
+ $data = $this->getPage()->getPostDataLoaders();
+ if(count($data) > 0)
+ {
+ $options = TJavaScript::encode($data,false);
+ $script = "Prado.CallbackRequest.addPostLoaders({$options});";
+ $cs->registerEndScript($key, $script);
+ }
+ }
+ }
+
+ /**
+ * @param TBaseActiveControl change base active control
+ */
+ public function setBaseActiveControl($control)
+ {
+ $this->_baseActiveControl=$control;
+ }
+
+ /**
+ * @return TBaseActiveControl Common active control options.
+ */
+ public function getBaseActiveControl()
+ {
+ if($this->_baseActiveControl===null)
+ {
+ $type = $this->_activeControlType;
+ $this->_baseActiveControl = new $type($this->getControl());
+ }
+ return $this->_baseActiveControl;
+ }
+
+ /**
+ * @return boolean true if the viewstate needs to be tracked.
+ */
+ protected function getIsTrackingPageState()
+ {
+ if($this->getPage()->getIsCallback())
+ {
+ $target = $this->getPage()->getCallbackEventTarget();
+ if($target instanceof ICallbackEventHandler)
+ {
+ $client = $target->getActiveControl()->getClientSide();
+ return $client->getEnablePageStateUpdate();
+ }
+ }
+ return false;
+ }
+
+ /**
+ * Starts viewstate tracking if necessary after when controls has been loaded
+ */
+ public function onLoad($param)
+ {
+ if($this->getIsTrackingPageState())
+ {
+ $this->_stateTracker = new TCallbackPageStateTracker($this->getControl());
+ $this->_stateTracker->trackChanges();
+ }
+ parent::onLoad($param);
+ }
+
+ /**
+ * Saves additional persistent control state. Respond to viewstate changes
+ * if necessary.
+ */
+ public function saveState()
+ {
+ if(($this->_stateTracker!==null)
+ && $this->getControl()->getActiveControl()->canUpdateClientSide(true))
+ {
+ $this->_stateTracker->respondToChanges();
+ }
+ parent::saveState();
+ }
+
+ /**
+ * @return TCallbackPageStateTracker state tracker.
+ */
+ public function getStateTracker()
+ {
+ return $this->_stateTracker;
+ }
+}
+
+/**
+ * TCallbackPageStateTracker class.
+ *
+ * Tracking changes to the page state during callback.
+ *
+ * @author Wei Zhuo <weizhuo[at]gmail[dot]com>
+ * @version $Id$
+ * @package System.Web.UI.ActiveControls
+ * @since 3.1
+ */
+class TCallbackPageStateTracker
+{
+ /**
+ * @var TMap new view state data
+ */
+ private $_states;
+ /**
+ * @var TMap old view state data
+ */
+ private $_existingState;
+ /**
+ * @var TControl the control tracked
+ */
+ private $_control;
+ /**
+ * @var object null object.
+ */
+ private $_nullObject;
+
+ /**
+ * Constructor. Add a set of default states to track.
+ * @param TControl control to track.
+ */
+ public function __construct($control)
+ {
+ $this->_control = $control;
+ $this->_existingState = new TMap;
+ $this->_nullObject = new stdClass;
+ $this->_states = new TMap;
+ $this->addStatesToTrack();
+ }
+
+ /**
+ * Add a list of view states to track. Each state is added
+ * to the StatesToTrack property with the view state name as key.
+ * The value should be an array with two enteries. The first entery
+ * is the name of the class that will calculate the state differences.
+ * The second entry is a php function/method callback that handles
+ * the changes in the viewstate.
+ */
+ protected function addStatesToTrack()
+ {
+ $states = $this->getStatesToTrack();
+ $states['Visible'] = array('TScalarDiff', array($this, 'updateVisible'));
+ $states['Enabled'] = array('TScalarDiff', array($this, 'updateEnabled'));
+ $states['Attributes'] = array('TMapCollectionDiff', array($this, 'updateAttributes'));
+ $states['Style'] = array('TStyleDiff', array($this, 'updateStyle'));
+ $states['TabIndex'] = array('TScalarDiff', array($this, 'updateTabIndex'));
+ $states['ToolTip'] = array('TScalarDiff', array($this, 'updateToolTip'));
+ $states['AccessKey'] = array('TScalarDiff', array($this, 'updateAccessKey'));
+ }
+
+ /**
+ * @return TMap list of viewstates to track.
+ */
+ protected function getStatesToTrack()
+ {
+ return $this->_states;
+ }
+
+ /**
+ * Start tracking view state changes. The clone function on objects are called
+ * for those viewstate having an object as value.
+ */
+ public function trackChanges()
+ {
+ foreach($this->_states as $name => $value)
+ {
+ $obj = $this->_control->getViewState($name);
+ $this->_existingState[$name] = is_object($obj) ? clone($obj) : $obj;
+ }
+ }
+
+ /**
+ * @return array list of viewstate and the changed data.
+ */
+ protected function getChanges()
+ {
+ $changes = array();
+ foreach($this->_states as $name => $details)
+ {
+ $new = $this->_control->getViewState($name);
+ $old = $this->_existingState[$name];
+ if($new !== $old)
+ {
+ $diff = new $details[0]($new, $old, $this->_nullObject);
+ if(($change = $diff->getDifference()) !== $this->_nullObject)
+ $changes[] = array($details[1],array($change));
+ }
+ }
+ return $changes;
+ }
+
+ /**
+ * For each of the changes call the corresponding change handlers.
+ */
+ public function respondToChanges()
+ {
+ foreach($this->getChanges() as $change)
+ call_user_func_array($change[0], $change[1]);
+ }
+
+ /**
+ * @return TCallbackClientScript callback client scripting
+ */
+ protected function client()
+ {
+ return $this->_control->getPage()->getCallbackClient();
+ }
+
+ /**
+ * Updates the tooltip.
+ * @param string new tooltip
+ */
+ protected function updateToolTip($value)
+ {
+ $this->client()->setAttribute($this->_control, 'title', $value);
+ }
+
+ /**
+ * Updates the tab index.
+ * @param integer tab index
+ */
+ protected function updateTabIndex($value)
+ {
+ $this->client()->setAttribute($this->_control, 'tabindex', $value);
+ }
+
+ /**
+ * Updates the modifier access key
+ * @param string access key
+ */
+ protected function updateAccessKey($value)
+ {
+ $this->client()->setAttribute($this->_control, 'accesskey', $value);
+ }
+
+ /**
+ * Hides or shows the control on the client-side. The control must be
+ * already rendered on the client-side.
+ * @param boolean true to show the control, false to hide.
+ */
+ protected function updateVisible($visible)
+ {
+ if($visible === false)
+ $this->client()->replaceContent($this->_control,"<span id=\"".$this->_control->getClientID()."\" style=\"display:none\" ></span>");
+ else
+ $this->client()->replaceContent($this->_control,$this->_control);
+ }
+
+ /**
+ * Enables or Disables the control on the client-side.
+ * @param boolean true to enable the control, false to disable.
+ */
+ protected function updateEnabled($enable)
+ {
+ $this->client()->setAttribute($this->_control, 'disabled', $enable===false);
+ }
+
+ /**
+ * Updates the CSS style on the control on the client-side.
+ * @param array list of new CSS style declarations.
+ */
+ protected function updateStyle($style)
+ {
+ if($style['CssClass']!==null)
+ $this->client()->setAttribute($this->_control, 'class', $style['CssClass']);
+ if(count($style['Style']) > 0)
+ $this->client()->setStyle($this->_control, $style['Style']);
+ }
+
+ /**
+ * Updates/adds a list of attributes on the control.
+ * @param array list of attribute name-value pairs.
+ */
+ protected function updateAttributes($attributes)
+ {
+ foreach($attributes as $name => $value)
+ $this->client()->setAttribute($this->_control, $name, $value);
+ }
+}
+
+/**
+ * Calculates the viewstate changes during the request.
+ *
+ * @author Wei Zhuo <weizhuo[at]gmail[dot]com>
+ * @version $Id$
+ * @package System.Web.UI.ActiveControls
+ * @since 3.1
+ */
+abstract class TViewStateDiff
+{
+ /**
+ * @var mixed updated viewstate
+ */
+ protected $_new;
+ /**
+ * @var mixed viewstate value at the begining of the request.
+ */
+ protected $_old;
+ /**
+ * @var object null value.
+ */
+ protected $_null;
+
+ /**
+ * Constructor.
+ * @param mixed updated viewstate value.
+ * @param mixed viewstate value at the begining of the request.
+ * @param object representing the null value.
+ */
+ public function __construct($new, $old, $null)
+ {
+ $this->_new = $new;
+ $this->_old = $old;
+ $this->_null = $null;
+ }
+
+ /**
+ * @return mixed view state changes, nullObject if no difference.
+ */
+ public abstract function getDifference();
+}
+
+/**
+ * TScalarDiff class.
+ *
+ * Calculate the changes to a scalar value.
+ *
+ * @author Wei Zhuo <weizhuo[at]gmail[dot]com>
+ * @version $Id$
+ * @package System.Web.UI.ActiveControls
+ * @since 3.1
+ */
+class TScalarDiff extends TViewStateDiff
+{
+ /**
+ * @return mixed update viewstate value.
+ */
+ public function getDifference()
+ {
+ if(gettype($this->_new) === gettype($this->_old)
+ && $this->_new === $this->_old)
+ return $this->_null;
+ else
+ return $this->_new;
+ }
+}
+
+/**
+ * TStyleDiff class.
+ *
+ * Calculates the changes to the Style properties.
+ *
+ * @author Wei Zhuo <weizhuo[at]gmail[dot]com>
+ * @version $Id$
+ * @package System.Web.UI.ActiveControls
+ * @since 3.1
+ */
+class TStyleDiff extends TViewStateDiff
+{
+ /**
+ * @param TStyle control style
+ * @return array all the style properties combined.
+ */
+ protected function getCombinedStyle($obj)
+ {
+ if(!($obj instanceof TStyle))
+ return array();
+ $style = $obj->getStyleFields();
+ $style = array_merge($style,$this->getStyleFromString($obj->getCustomStyle()));
+ if($obj->hasFont())
+ $style = array_merge($style, $this->getStyleFromString($obj->getFont()->toString()));
+ return $style;
+ }
+
+ /**
+ * @param string CSS custom style string.
+ * @param array CSS style as name-value array.
+ */
+ protected function getStyleFromString($string)
+ {
+ $style = array();
+ if(!is_string($string)) return $style;
+
+ foreach(explode(';',$string) as $sub)
+ {
+ $arr=explode(':',$sub);
+ if(isset($arr[1]) && trim($arr[0])!=='')
+ $style[trim($arr[0])] = trim($arr[1]);
+ }
+ return $style;
+ }
+
+ /**
+ * @return string changes to the CSS class name.
+ */
+ protected function getCssClassDiff()
+ {
+ if($this->_old===null)
+ {
+ return ($this->_new!==null) && $this->_new->hasCssClass()
+ ? $this->_new->getCssClass() : null;
+ }
+ else
+ {
+ return $this->_old->getCssClass() !== $this->_new->getCssClass() ?
+ $this->_new->getCssClass() : null;
+ }
+ }
+
+ /**
+ * @return array list of changes to the control style.
+ */
+ protected function getStyleDiff()
+ {
+ $diff = array_diff_assoc(
+ $this->getCombinedStyle($this->_new),
+ $this->getCombinedStyle($this->_old));
+ return count($diff) > 0 ? $diff : null;
+ }
+
+ /**
+ * @return array list of changes to the control style and CSS class name.
+ */
+ public function getDifference()
+ {
+ if($this->_new===null)
+ return $this->_null;
+ else
+ {
+ $css = $this->getCssClassDiff();
+ $style = $this->getStyleDiff();
+ if(($css!==null) || ($style!==null))
+ return array('CssClass' => $css, 'Style' => $style);
+ else
+ $this->_null;
+ }
+ }
+}
+
+/**
+ * TAttributesDiff class.
+ *
+ * Calculate the changes to attributes collection.
+ *
+ * @author Wei Zhuo <weizhuo[at]gmail[dot]com>
+ * @version $Id$
+ * @package System.Web.UI.ActiveControls
+ * @since 3.1
+ */
+class TMapCollectionDiff extends TViewStateDiff
+{
+ /**
+ * @return array updates to the attributes collection.
+ */
+ public function getDifference()
+ {
+ if($this->_old===null)
+ {
+ return ($this->_new!==null) ? $this->_new->toArray() : $this->_null;
+ }
+ else
+ {
+ $new = $this->_new->toArray();
+ $old = $this->_old->toArray();
+ $diff = array_diff_assoc($new, $old);
+ return count($diff) > 0 ? $diff : $this->_null;
+ }
+ }
+}
+
diff --git a/framework/Web/UI/ActiveControls/TActiveCustomValidator.php b/framework/Web/UI/ActiveControls/TActiveCustomValidator.php
index 9e09eb88..df8f45d9 100644
--- a/framework/Web/UI/ActiveControls/TActiveCustomValidator.php
+++ b/framework/Web/UI/ActiveControls/TActiveCustomValidator.php
@@ -1,265 +1,265 @@
-<?php
-/**
- * TActiveCustomValidator class file.
- *
- * @author Wei Zhuo <weizhuo[at]gamil[dot]com>
- * @link http://www.pradosoft.com/
- * @copyright Copyright &copy; 2005-2012 PradoSoft
- * @license http://www.pradosoft.com/license/
- * @version $Id$
- * @package System.Web.UI.ActiveControls
- */
-
-Prado::using('System.Web.UI.ActiveControls.TCallbackClientSide');
-
-/**
- * TActiveCustomValidator Class
- *
- * Performs custom validation using only server-side {@link onServerValidate onServerValidate}
- * validation event. The client-side uses callbacks to raise
- * the {@link onServerValidate onServerValidate} event.
- *
- * Beware that the {@link onServerValidate onServerValidate} may be
- * raised when the control to validate on the client side
- * changes value, that is, the server validation may be called many times.
- *
- * After the callback or postback, the {@link onServerValidate onServerValidate}
- * is raised once more. The {@link getIsCallback IsCallback} property
- * will be true when validation is made during a callback request.
- *
- * @author Wei Zhuo <weizhuo[at]gmail[dot]com>
- * @version $Id$
- * @package System.Web.UI.ActiveControls
- * @since 3.1
- */
-class TActiveCustomValidator extends TCustomValidator
- implements ICallbackEventHandler, IActiveControl
-{
- /**
- * @var boolean true if validation is made during a callback request.
- */
- private $_isCallback = false;
-
- /**
- * @return boolean true if validation is made during a callback request.
- */
- public function getIsCallback()
- {
- return $this->_isCallback;
- }
-
- /**
- * Creates a new callback control, sets the adapter to
- * TActiveControlAdapter. If you override this class, be sure to set the
- * adapter appropriately by, for example, by calling this constructor.
- */
- public function __construct()
- {
- parent::__construct();
- $this->setAdapter(new TActiveControlAdapter($this));
- $this->getActiveControl()->setClientSide(new TActiveCustomValidatorClientSide);
- }
-
- /**
- * @return TBaseActiveCallbackControl standard callback control options.
- */
- public function getActiveControl()
- {
- return $this->getAdapter()->getBaseActiveControl();
- }
-
- /**
- * @return TCallbackClientSide client side request options.
- */
- public function getClientSide()
- {
- return $this->getAdapter()->getBaseActiveControl()->getClientSide();
- }
-
- /**
- * Client validation function is NOT supported.
- */
- public function setClientValidationFunction($value)
- {
- throw new TNotSupportedException('tactivecustomvalidator_clientfunction_unsupported',
- get_class($this));
- }
-
- /**
- * Raises the callback event. This method is required by {@link
- * ICallbackEventHandler} interface. The {@link onServerValidate
- * OnServerValidate} event is raised first and then the
- * {@link onCallback OnCallback} event.
- * This method is mainly used by framework and control developers.
- * @param TCallbackEventParameter the event parameter
- */
- public function raiseCallbackEvent($param)
- {
- $this->_isCallback = true;
- $result = $this->onServerValidate($param->getCallbackParameter());
- $param->setResponseData($result);
- $this->onCallback($param);
- }
-
- /**
- * @param boolean whether the value is valid; this method will trigger a clientside update if needed
- */
- public function setIsValid($value)
- {
- parent::setIsValid($value);
- if($this->getActiveControl()->canUpdateClientSide())
- {
- $client = $this->getPage()->getCallbackClient();
- $func = 'Prado.Validation.updateActiveCustomValidator';
- $client->callClientFunction($func, array($this, $value));
- }
- }
-
- /**
- * This method is invoked when a callback is requested. The method raises
- * 'OnCallback' event to fire up the event handlers. If you override this
- * method, be sure to call the parent implementation so that the event
- * handler can be invoked.
- * @param TCallbackEventParameter event parameter to be passed to the event handlers
- */
- public function onCallback($param)
- {
- $this->raiseEvent('OnCallback', $this, $param);
- }
-
- /**
- * Returns an array of javascript validator options.
- * @return array javascript validator options.
- */
- protected function getClientScriptOptions()
- {
- $options=TBaseValidator::getClientScriptOptions();
- $options['EventTarget'] = $this->getUniqueID();
- return $options;
- }
-
- /**
- * Sets the text for the error message. Updates client-side erorr message.
- * @param string the error message
- */
- public function setErrorMessage($value)
- {
- parent::setErrorMessage($value);
- if($this->getActiveControl()->canUpdateClientSide())
- {
- $client = $this->getPage()->getCallbackClient();
- $func = 'Prado.Validation.setErrorMessage';
- $client->callClientFunction($func, array($this, $value));
- }
- }
-
-
- /**
- * It's mandatory for the EnableClientScript to be activated or the TActiveCustomValidator won't work.
- * @return boolean whether client-side validation is enabled.
- */
- public function getEnableClientScript()
- {
- return true;
- }
-
- /**
- * Ensure that the ID attribute is rendered and registers the javascript code
- * for initializing the active control.
- */
- protected function addAttributesToRender($writer)
- {
- parent::addAttributesToRender($writer);
- TBaseValidator::registerClientScriptValidator();
- }
-
- /**
- * @return string corresponding javascript class name for this this.
- */
- protected function getClientClassName()
- {
- return 'Prado.WebUI.TActiveCustomValidator';
- }
-}
-
-/**
- * Custom Validator callback client side options class.
- *
- * @author Wei Zhuo <weizhuo[at]gmail[dot]com>
- * @version $Id$
- * @package System.Web.UI.ActiveControls
- * @since 3.1
- */
-class TActiveCustomValidatorClientSide extends TCallbackClientSide
-{
- /**
- * @return string javascript code for client-side OnValidate event.
- */
- public function getOnValidate()
- {
- return $this->getOption('OnValidate');
- }
-
- /**
- * Client-side OnValidate validator event is raise before the validators
- * validation functions are called.
- * @param string javascript code for client-side OnValidate event.
- */
- public function setOnValidate($javascript)
- {
- $this->setFunction('OnValidate', $javascript);
- }
-
- /**
- * Client-side OnSuccess event is raise after validation is successfull.
- * This will override the default client-side validator behaviour.
- * @param string javascript code for client-side OnSuccess event.
- */
- public function setOnValidationSuccess($javascript)
- {
- $this->setFunction('OnValidationSuccess', $javascript);
- }
-
- /**
- * @return string javascript code for client-side OnSuccess event.
- */
- public function getOnValidationSuccess()
- {
- return $this->getOption('OnValidationSuccess');
- }
-
- /**
- * Client-side OnError event is raised after validation failure.
- * This will override the default client-side validator behaviour.
- * @param string javascript code for client-side OnError event.
- */
- public function setOnValidationError($javascript)
- {
- $this->setFunction('OnValidationError', $javascript);
- }
-
- /**
- * @return string javascript code for client-side OnError event.
- */
- public function getOnValidationError()
- {
- return $this->getOption('OnValidationError');
- }
-
- /**
- * @param boolean true to revalidate when the control to validate changes value.
- */
- public function setObserveChanges($value)
- {
- $this->setOption('ObserveChanges', TPropertyValue::ensureBoolean($value));
- }
-
- /**
- * @return boolean true to observe changes.
- */
- public function getObserveChanges()
- {
- $changes = $this->getOption('ObserveChanges');
- return ($changes===null) ? true : $changes;
- }
-}
+<?php
+/**
+ * TActiveCustomValidator class file.
+ *
+ * @author Wei Zhuo <weizhuo[at]gamil[dot]com>
+ * @link http://www.pradosoft.com/
+ * @copyright Copyright &copy; 2005-2012 PradoSoft
+ * @license http://www.pradosoft.com/license/
+ * @version $Id$
+ * @package System.Web.UI.ActiveControls
+ */
+
+Prado::using('System.Web.UI.ActiveControls.TCallbackClientSide');
+
+/**
+ * TActiveCustomValidator Class
+ *
+ * Performs custom validation using only server-side {@link onServerValidate onServerValidate}
+ * validation event. The client-side uses callbacks to raise
+ * the {@link onServerValidate onServerValidate} event.
+ *
+ * Beware that the {@link onServerValidate onServerValidate} may be
+ * raised when the control to validate on the client side
+ * changes value, that is, the server validation may be called many times.
+ *
+ * After the callback or postback, the {@link onServerValidate onServerValidate}
+ * is raised once more. The {@link getIsCallback IsCallback} property
+ * will be true when validation is made during a callback request.
+ *
+ * @author Wei Zhuo <weizhuo[at]gmail[dot]com>
+ * @version $Id$
+ * @package System.Web.UI.ActiveControls
+ * @since 3.1
+ */
+class TActiveCustomValidator extends TCustomValidator
+ implements ICallbackEventHandler, IActiveControl
+{
+ /**
+ * @var boolean true if validation is made during a callback request.
+ */
+ private $_isCallback = false;
+
+ /**
+ * @return boolean true if validation is made during a callback request.
+ */
+ public function getIsCallback()
+ {
+ return $this->_isCallback;
+ }
+
+ /**
+ * Creates a new callback control, sets the adapter to
+ * TActiveControlAdapter. If you override this class, be sure to set the
+ * adapter appropriately by, for example, by calling this constructor.
+ */
+ public function __construct()
+ {
+ parent::__construct();
+ $this->setAdapter(new TActiveControlAdapter($this));
+ $this->getActiveControl()->setClientSide(new TActiveCustomValidatorClientSide);
+ }
+
+ /**
+ * @return TBaseActiveCallbackControl standard callback control options.
+ */
+ public function getActiveControl()
+ {
+ return $this->getAdapter()->getBaseActiveControl();
+ }
+
+ /**
+ * @return TCallbackClientSide client side request options.
+ */
+ public function getClientSide()
+ {
+ return $this->getAdapter()->getBaseActiveControl()->getClientSide();
+ }
+
+ /**
+ * Client validation function is NOT supported.
+ */
+ public function setClientValidationFunction($value)
+ {
+ throw new TNotSupportedException('tactivecustomvalidator_clientfunction_unsupported',
+ get_class($this));
+ }
+
+ /**
+ * Raises the callback event. This method is required by {@link
+ * ICallbackEventHandler} interface. The {@link onServerValidate
+ * OnServerValidate} event is raised first and then the
+ * {@link onCallback OnCallback} event.
+ * This method is mainly used by framework and control developers.
+ * @param TCallbackEventParameter the event parameter
+ */
+ public function raiseCallbackEvent($param)
+ {
+ $this->_isCallback = true;
+ $result = $this->onServerValidate($param->getCallbackParameter());
+ $param->setResponseData($result);
+ $this->onCallback($param);
+ }
+
+ /**
+ * @param boolean whether the value is valid; this method will trigger a clientside update if needed
+ */
+ public function setIsValid($value)
+ {
+ parent::setIsValid($value);
+ if($this->getActiveControl()->canUpdateClientSide())
+ {
+ $client = $this->getPage()->getCallbackClient();
+ $func = 'Prado.Validation.updateActiveCustomValidator';
+ $client->callClientFunction($func, array($this, $value));
+ }
+ }
+
+ /**
+ * This method is invoked when a callback is requested. The method raises
+ * 'OnCallback' event to fire up the event handlers. If you override this
+ * method, be sure to call the parent implementation so that the event
+ * handler can be invoked.
+ * @param TCallbackEventParameter event parameter to be passed to the event handlers
+ */
+ public function onCallback($param)
+ {
+ $this->raiseEvent('OnCallback', $this, $param);
+ }
+
+ /**
+ * Returns an array of javascript validator options.
+ * @return array javascript validator options.
+ */
+ protected function getClientScriptOptions()
+ {
+ $options=TBaseValidator::getClientScriptOptions();
+ $options['EventTarget'] = $this->getUniqueID();
+ return $options;
+ }
+
+ /**
+ * Sets the text for the error message. Updates client-side erorr message.
+ * @param string the error message
+ */
+ public function setErrorMessage($value)
+ {
+ parent::setErrorMessage($value);
+ if($this->getActiveControl()->canUpdateClientSide())
+ {
+ $client = $this->getPage()->getCallbackClient();
+ $func = 'Prado.Validation.setErrorMessage';
+ $client->callClientFunction($func, array($this, $value));
+ }
+ }
+
+
+ /**
+ * It's mandatory for the EnableClientScript to be activated or the TActiveCustomValidator won't work.
+ * @return boolean whether client-side validation is enabled.
+ */
+ public function getEnableClientScript()
+ {
+ return true;
+ }
+
+ /**
+ * Ensure that the ID attribute is rendered and registers the javascript code
+ * for initializing the active control.
+ */
+ protected function addAttributesToRender($writer)
+ {
+ parent::addAttributesToRender($writer);
+ TBaseValidator::registerClientScriptValidator();
+ }
+
+ /**
+ * @return string corresponding javascript class name for this this.
+ */
+ protected function getClientClassName()
+ {
+ return 'Prado.WebUI.TActiveCustomValidator';
+ }
+}
+
+/**
+ * Custom Validator callback client side options class.
+ *
+ * @author Wei Zhuo <weizhuo[at]gmail[dot]com>
+ * @version $Id$
+ * @package System.Web.UI.ActiveControls
+ * @since 3.1
+ */
+class TActiveCustomValidatorClientSide extends TCallbackClientSide
+{
+ /**
+ * @return string javascript code for client-side OnValidate event.
+ */
+ public function getOnValidate()
+ {
+ return $this->getOption('OnValidate');
+ }
+
+ /**
+ * Client-side OnValidate validator event is raise before the validators
+ * validation functions are called.
+ * @param string javascript code for client-side OnValidate event.
+ */
+ public function setOnValidate($javascript)
+ {
+ $this->setFunction('OnValidate', $javascript);
+ }
+
+ /**
+ * Client-side OnSuccess event is raise after validation is successfull.
+ * This will override the default client-side validator behaviour.
+ * @param string javascript code for client-side OnSuccess event.
+ */
+ public function setOnValidationSuccess($javascript)
+ {
+ $this->setFunction('OnValidationSuccess', $javascript);
+ }
+
+ /**
+ * @return string javascript code for client-side OnSuccess event.
+ */
+ public function getOnValidationSuccess()
+ {
+ return $this->getOption('OnValidationSuccess');
+ }
+
+ /**
+ * Client-side OnError event is raised after validation failure.
+ * This will override the default client-side validator behaviour.
+ * @param string javascript code for client-side OnError event.
+ */
+ public function setOnValidationError($javascript)
+ {
+ $this->setFunction('OnValidationError', $javascript);
+ }
+
+ /**
+ * @return string javascript code for client-side OnError event.
+ */
+ public function getOnValidationError()
+ {
+ return $this->getOption('OnValidationError');
+ }
+
+ /**
+ * @param boolean true to revalidate when the control to validate changes value.
+ */
+ public function setObserveChanges($value)
+ {
+ $this->setOption('ObserveChanges', TPropertyValue::ensureBoolean($value));
+ }
+
+ /**
+ * @return boolean true to observe changes.
+ */
+ public function getObserveChanges()
+ {
+ $changes = $this->getOption('ObserveChanges');
+ return ($changes===null) ? true : $changes;
+ }
+}
diff --git a/framework/Web/UI/ActiveControls/TActiveLabel.php b/framework/Web/UI/ActiveControls/TActiveLabel.php
index 32d91cd2..c05b1744 100644
--- a/framework/Web/UI/ActiveControls/TActiveLabel.php
+++ b/framework/Web/UI/ActiveControls/TActiveLabel.php
@@ -80,7 +80,7 @@ class TActiveLabel extends TLabel implements IActiveControl
/**
* Adds attribute id to the renderer.
- * @param THtmlWriter the writer used for the rendering purpose
+ * @param THtmlWriter the writer used for the rendering purpose
*/
protected function addAttributesToRender($writer) {
$writer->addAttribute('id',$this->getClientID());
diff --git a/framework/Web/UI/ActiveControls/TActivePageAdapter.php b/framework/Web/UI/ActiveControls/TActivePageAdapter.php
index 726dd8ba..144f621e 100644
--- a/framework/Web/UI/ActiveControls/TActivePageAdapter.php
+++ b/framework/Web/UI/ActiveControls/TActivePageAdapter.php
@@ -1,401 +1,401 @@
-<?php
-/**
- * TActivePageAdapter, TCallbackErrorHandler and TInvalidCallbackException class file.
- *
- * @author Wei Zhuo <weizhuo[at]gamil[dot]com>
- * @author Gabor Berczi <gabor.berczi@devworx.hu> (lazyload additions & progressive rendering)
- * @link http://www.pradosoft.com/
- * @copyright Copyright &copy; 2005-2012 PradoSoft
- * @license http://www.pradosoft.com/license/
- * @version $Id$
- * @package System.Web.UI.ActiveControls
- */
-
-/**
- * Load callback response adapter class.
- */
-Prado::using('System.Web.UI.ActiveControls.TCallbackResponseAdapter');
-Prado::using('System.Web.UI.ActiveControls.TCallbackClientScript');
-Prado::using('System.Web.UI.ActiveControls.TCallbackEventParameter');
-
-/**
- * TActivePageAdapter class.
- *
- * Callback request handler.
- *
- * @author Wei Zhuo <weizhuo[at]gamil[dot]com>
- * @author Gabor Berczi <gabor.berczi@devworx.hu> (lazyload additions & progressive rendering)
- * @version $Id$
- * @package System.Web.UI.ActiveControls
- * @since 3.1
- */
-class TActivePageAdapter extends TControlAdapter
-{
- /**
- * Callback response data header name.
- */
- const CALLBACK_DATA_HEADER = 'X-PRADO-DATA';
- /**
- * Callback response client-side action header name.
- */
- const CALLBACK_ACTION_HEADER = 'X-PRADO-ACTIONS';
- /**
- * Callback error header name.
- */
- const CALLBACK_ERROR_HEADER = 'X-PRADO-ERROR';
- /**
- * Callback page state header name.
- */
- const CALLBACK_PAGESTATE_HEADER = 'X-PRADO-PAGESTATE';
- /**
- * Script list header name.
- */
- const CALLBACK_SCRIPTLIST_HEADER = 'X-PRADO-SCRIPTLIST';
- /**
- * Stylesheet list header name.
- */
- const CALLBACK_STYLESHEETLIST_HEADER = 'X-PRADO-STYLESHEETLIST';
- /**
- * Hidden field list header name.
- */
- const CALLBACK_HIDDENFIELDLIST_HEADER = 'X-PRADO-HIDDENFIELDLIST';
-
- /**
- * Callback redirect url header name.
- */
- const CALLBACK_REDIRECT = 'X-PRADO-REDIRECT';
-
- /**
- * @var ICallbackEventHandler callback event handler.
- */
- private $_callbackEventTarget;
- /**
- * @var mixed callback event parameter.
- */
- private $_callbackEventParameter;
- /**
- * @var TCallbackClientScript callback client script handler
- */
- private $_callbackClient;
-
- private $_controlsToRender=array();
-
- /**
- * Constructor, trap errors and exception to let the callback response
- * handle them.
- */
- public function __construct(TPage $control)
- {
- parent::__construct($control);
-
- //TODO: can this be done later?
- $response = $this->getApplication()->getResponse();
- $response->setAdapter(new TCallbackResponseAdapter($response));
-
- $this->trapCallbackErrorsExceptions();
- }
-
- /**
- * Process the callback request.
- * @param THtmlWriter html content writer.
- */
- public function processCallbackEvent($writer)
- {
- Prado::trace("ActivePage raiseCallbackEvent()",'System.Web.UI.ActiveControls.TActivePageAdapter');
- $this->raiseCallbackEvent();
- }
-
- /**
- * Register a control for defered render() call.
- * @param TControl control for defered rendering
- * @param THtmlWriter the renderer
- */
- public function registerControlToRender($control,$writer)
- {
- $id = $control->getUniqueID();
- if(!isset($this->_controlsToRender[$id]))
- $this->_controlsToRender[$id] = array($control,$writer);
- }
-
- /**
- * Trap errors and exceptions to be handled by TCallbackErrorHandler.
- */
- protected function trapCallbackErrorsExceptions()
- {
- $this->getApplication()->setErrorHandler(new TCallbackErrorHandler);
- }
-
- /**
- * Render the callback response.
- * @param THtmlWriter html content writer.
- */
- public function renderCallbackResponse($writer)
- {
- Prado::trace("ActivePage renderCallbackResponse()",'System.Web.UI.ActiveControls.TActivePageAdapter');
- if(($url = $this->getResponse()->getAdapter()->getRedirectedUrl())===null)
- $this->renderResponse($writer);
- else
- $this->redirect($url);
- }
-
- /**
- * Redirect url on the client-side using javascript.
- * @param string new url to load.
- */
- protected function redirect($url)
- {
- Prado::trace("ActivePage redirect()",'System.Web.UI.ActiveControls.TActivePageAdapter');
- $this->appendContentPart($this->getResponse(), self::CALLBACK_REDIRECT, $url);
- //$this->getResponse()->appendHeader(self::CALLBACK_REDIRECT.': '.$url);
- }
-
- /**
- * Renders the callback response by adding additional callback data and
- * javascript actions in the header and page state if required.
- * @param THtmlWriter html content writer.
- */
- protected function renderResponse($writer)
- {
- Prado::trace("ActivePage renderResponse()",'System.Web.UI.ActiveControls.TActivePageAdapter');
- //renders all the defered render() calls.
- foreach($this->_controlsToRender as $rid => $forRender)
- $forRender[0]->render($forRender[1]);
-
- $response = $this->getResponse();
-
- //send response data in header
- if($response->getHasAdapter())
- {
- $responseData = $response->getAdapter()->getResponseData();
- if($responseData!==null)
- {
- $data = TJavaScript::jsonEncode($responseData);
-
- $this->appendContentPart($response, self::CALLBACK_DATA_HEADER, $data);
- //$response->appendHeader(self::CALLBACK_DATA_HEADER.': '.$data);
- }
- }
-
- //sends page state in header
- if(($handler = $this->getCallbackEventTarget()) !== null)
- {
- if($handler->getActiveControl()->getClientSide()->getEnablePageStateUpdate())
- {
- $pagestate = $this->getPage()->getClientState();
- $this->appendContentPart($response, self::CALLBACK_PAGESTATE_HEADER, $pagestate);
- //$response->appendHeader(self::CALLBACK_PAGESTATE_HEADER.': '.$pagestate);
- }
- }
-
- //safari must receive at least 1 byte of data.
- $writer->write(" ");
-
- //output the end javascript
- if($this->getPage()->getClientScript()->hasEndScripts())
- {
- $writer = $response->createHtmlWriter();
- $this->getPage()->getClientScript()->renderEndScripts($writer);
- $this->getPage()->getCallbackClient()->evaluateScript($writer);
- }
-
- //output the actions
- $executeJavascript = $this->getCallbackClientHandler()->getClientFunctionsToExecute();
- $actions = TJavaScript::jsonEncode($executeJavascript);
- $this->appendContentPart($response, self::CALLBACK_ACTION_HEADER, $actions);
- //$response->appendHeader(self::CALLBACK_ACTION_HEADER.': '.$actions);
-
-
- $cs = $this->Page->getClientScript();
-
- // collect all stylesheet file references
- $stylesheets = $cs->getStyleSheetUrls();
- if (count($stylesheets)>0)
- $this->appendContentPart($response, self::CALLBACK_STYLESHEETLIST_HEADER, TJavaScript::jsonEncode($stylesheets));
-
- // collect all script file references
- $scripts = $cs->getScriptUrls();
- if (count($scripts)>0)
- $this->appendContentPart($response, self::CALLBACK_SCRIPTLIST_HEADER, TJavaScript::jsonEncode($scripts));
-
- // collect all hidden field references
- $fields = $cs->getHiddenFields();
- if (count($fields)>0)
- $this->appendContentPart($response, self::CALLBACK_HIDDENFIELDLIST_HEADER, TJavaScript::jsonEncode($fields));
- }
-
- /**
- * Appends data or javascript code to the body content surrounded with delimiters
- */
- private function appendContentPart($response, $delimiter, $data)
- {
- $content = $response->createHtmlWriter();
- $content->getWriter()->setBoundary($delimiter);
- $content->write($data);
- }
-
- /**
- * Trys to find the callback event handler and raise its callback event.
- * @throws TInvalidCallbackException if call back target is not found.
- * @throws TInvalidCallbackException if the requested target does not
- * implement ICallbackEventHandler.
- */
- private function raiseCallbackEvent()
- {
- if(($callbackHandler=$this->getCallbackEventTarget())!==null)
- {
- if($callbackHandler instanceof ICallbackEventHandler)
- {
- $param = $this->getCallbackEventParameter();
- $result = new TCallbackEventParameter($this->getResponse(), $param);
- $callbackHandler->raiseCallbackEvent($result);
- }
- else
- {
- throw new TInvalidCallbackException(
- 'callback_invalid_handler', $callbackHandler->getUniqueID());
- }
- }
- else
- {
- $target = $this->getRequest()->itemAt(TPage::FIELD_CALLBACK_TARGET);
- throw new TInvalidCallbackException('callback_invalid_target', $target);
- }
- }
-
- /**
- * @return TControl the control responsible for the current callback event,
- * null if nonexistent
- */
- public function getCallbackEventTarget()
- {
- if($this->_callbackEventTarget===null)
- {
- $eventTarget=$this->getRequest()->itemAt(TPage::FIELD_CALLBACK_TARGET);
- if(!empty($eventTarget))
- $this->_callbackEventTarget=$this->getPage()->findControl($eventTarget);
- }
- return $this->_callbackEventTarget;
- }
-
- /**
- * Registers a control to raise callback event in the current request.
- * @param TControl control registered to raise callback event.
- */
- public function setCallbackEventTarget(TControl $control)
- {
- $this->_callbackEventTarget=$control;
- }
-
- /**
- * Gets callback parameter. JSON encoding is assumed.
- * @return string postback event parameter
- */
- public function getCallbackEventParameter()
- {
- if($this->_callbackEventParameter===null)
- {
- $param = $this->getRequest()->itemAt(TPage::FIELD_CALLBACK_PARAMETER);
- if(strlen($param) > 0)
- $this->_callbackEventParameter=TJavaScript::jsonDecode((string)$param);
- }
- return $this->_callbackEventParameter;
- }
-
- /**
- * @param mixed postback event parameter
- */
- public function setCallbackEventParameter($value)
- {
- $this->_callbackEventParameter=$value;
- }
-
- /**
- * Gets the callback client script handler. It handlers the javascript functions
- * to be executed during the callback response.
- * @return TCallbackClientScript callback client handler.
- */
- public function getCallbackClientHandler()
- {
- if($this->_callbackClient===null)
- $this->_callbackClient = new TCallbackClientScript;
- return $this->_callbackClient;
- }
-}
-
-/**
- * TCallbackErrorHandler class.
- *
- * Captures errors and exceptions and send them back during callback response.
- * When the application is in debug mode, the error and exception stack trace
- * are shown. A TJavascriptLogger must be present on the client-side to view
- * the error stack trace.
- *
- * @author Wei Zhuo <weizhuo[at]gmail[dot]com>
- * @version $Id$
- * @package System.Web.UI.ActiveControls
- * @since 3.1
- */
-class TCallbackErrorHandler extends TErrorHandler
-{
- /**
- * Displays the exceptions to the client-side TJavascriptLogger.
- * A HTTP 500 status code is sent and the stack trace is sent as JSON encoded.
- * @param Exception exception details.
- */
- protected function displayException($exception)
- {
- if($this->getApplication()->getMode()===TApplication::STATE_DEBUG)
- {
- $response = $this->getApplication()->getResponse();
- $trace = TJavaScript::jsonEncode($this->getExceptionStackTrace($exception));
- $response->setStatusCode(500, 'Internal Server Error');
- $response->appendHeader(TActivePageAdapter::CALLBACK_ERROR_HEADER.': '.$trace);
- }
- else
- {
- error_log("Error happened while processing an existing error:\n".$exception->__toString());
- header('HTTP/1.0 500 Internal Server Error', true, 500);
- }
- $this->getApplication()->getResponse()->flush();
- }
-
- /**
- * @param Exception exception details.
- * @return array exception stack trace details.
- */
- private function getExceptionStackTrace($exception)
- {
- $data['code']=$exception->getCode() > 0 ? $exception->getCode() : 500;
- $data['file']=$exception->getFile();
- $data['line']=$exception->getLine();
- $data['trace']=$exception->getTrace();
- if($exception instanceof TPhpErrorException)
- {
- // if PHP exception, we want to show the 2nd stack level context
- // because the 1st stack level is of little use (it's in error handler)
- if(isset($trace[0]) && isset($trace[0]['file']) && isset($trace[0]['line']))
- {
- $data['file']=$trace[0]['file'];
- $data['line']=$trace[0]['line'];
- }
- }
- $data['type']=get_class($exception);
- $data['message']=$exception->getMessage();
- $data['version']=$_SERVER['SERVER_SOFTWARE'].' '.Prado::getVersion();
- $data['time']=@strftime('%Y-%m-%d %H:%M',time());
- return $data;
- }
-}
-
-/**
- * TInvalidCallbackException class.
- *
- * @author Wei Zhuo <weizhuo[at]gmail[dot]com>
- * @version $Id$
- * @package System.Web.UI.ActiveControls
- * @since 3.1
- */
-class TInvalidCallbackException extends TException
-{
-}
-
+<?php
+/**
+ * TActivePageAdapter, TCallbackErrorHandler and TInvalidCallbackException class file.
+ *
+ * @author Wei Zhuo <weizhuo[at]gamil[dot]com>
+ * @author Gabor Berczi <gabor.berczi@devworx.hu> (lazyload additions & progressive rendering)
+ * @link http://www.pradosoft.com/
+ * @copyright Copyright &copy; 2005-2012 PradoSoft
+ * @license http://www.pradosoft.com/license/
+ * @version $Id$
+ * @package System.Web.UI.ActiveControls
+ */
+
+/**
+ * Load callback response adapter class.
+ */
+Prado::using('System.Web.UI.ActiveControls.TCallbackResponseAdapter');
+Prado::using('System.Web.UI.ActiveControls.TCallbackClientScript');
+Prado::using('System.Web.UI.ActiveControls.TCallbackEventParameter');
+
+/**
+ * TActivePageAdapter class.
+ *
+ * Callback request handler.
+ *
+ * @author Wei Zhuo <weizhuo[at]gamil[dot]com>
+ * @author Gabor Berczi <gabor.berczi@devworx.hu> (lazyload additions & progressive rendering)
+ * @version $Id$
+ * @package System.Web.UI.ActiveControls
+ * @since 3.1
+ */
+class TActivePageAdapter extends TControlAdapter
+{
+ /**
+ * Callback response data header name.
+ */
+ const CALLBACK_DATA_HEADER = 'X-PRADO-DATA';
+ /**
+ * Callback response client-side action header name.
+ */
+ const CALLBACK_ACTION_HEADER = 'X-PRADO-ACTIONS';
+ /**
+ * Callback error header name.
+ */
+ const CALLBACK_ERROR_HEADER = 'X-PRADO-ERROR';
+ /**
+ * Callback page state header name.
+ */
+ const CALLBACK_PAGESTATE_HEADER = 'X-PRADO-PAGESTATE';
+ /**
+ * Script list header name.
+ */
+ const CALLBACK_SCRIPTLIST_HEADER = 'X-PRADO-SCRIPTLIST';
+ /**
+ * Stylesheet list header name.
+ */
+ const CALLBACK_STYLESHEETLIST_HEADER = 'X-PRADO-STYLESHEETLIST';
+ /**
+ * Hidden field list header name.
+ */
+ const CALLBACK_HIDDENFIELDLIST_HEADER = 'X-PRADO-HIDDENFIELDLIST';
+
+ /**
+ * Callback redirect url header name.
+ */
+ const CALLBACK_REDIRECT = 'X-PRADO-REDIRECT';
+
+ /**
+ * @var ICallbackEventHandler callback event handler.
+ */
+ private $_callbackEventTarget;
+ /**
+ * @var mixed callback event parameter.
+ */
+ private $_callbackEventParameter;
+ /**
+ * @var TCallbackClientScript callback client script handler
+ */
+ private $_callbackClient;
+
+ private $_controlsToRender=array();
+
+ /**
+ * Constructor, trap errors and exception to let the callback response
+ * handle them.
+ */
+ public function __construct(TPage $control)
+ {
+ parent::__construct($control);
+
+ //TODO: can this be done later?
+ $response = $this->getApplication()->getResponse();
+ $response->setAdapter(new TCallbackResponseAdapter($response));
+
+ $this->trapCallbackErrorsExceptions();
+ }
+
+ /**
+ * Process the callback request.
+ * @param THtmlWriter html content writer.
+ */
+ public function processCallbackEvent($writer)
+ {
+ Prado::trace("ActivePage raiseCallbackEvent()",'System.Web.UI.ActiveControls.TActivePageAdapter');
+ $this->raiseCallbackEvent();
+ }
+
+ /**
+ * Register a control for defered render() call.
+ * @param TControl control for defered rendering
+ * @param THtmlWriter the renderer
+ */
+ public function registerControlToRender($control,$writer)
+ {
+ $id = $control->getUniqueID();
+ if(!isset($this->_controlsToRender[$id]))
+ $this->_controlsToRender[$id] = array($control,$writer);
+ }
+
+ /**
+ * Trap errors and exceptions to be handled by TCallbackErrorHandler.
+ */
+ protected function trapCallbackErrorsExceptions()
+ {
+ $this->getApplication()->setErrorHandler(new TCallbackErrorHandler);
+ }
+
+ /**
+ * Render the callback response.
+ * @param THtmlWriter html content writer.
+ */
+ public function renderCallbackResponse($writer)
+ {
+ Prado::trace("ActivePage renderCallbackResponse()",'System.Web.UI.ActiveControls.TActivePageAdapter');
+ if(($url = $this->getResponse()->getAdapter()->getRedirectedUrl())===null)
+ $this->renderResponse($writer);
+ else
+ $this->redirect($url);
+ }
+
+ /**
+ * Redirect url on the client-side using javascript.
+ * @param string new url to load.
+ */
+ protected function redirect($url)
+ {
+ Prado::trace("ActivePage redirect()",'System.Web.UI.ActiveControls.TActivePageAdapter');
+ $this->appendContentPart($this->getResponse(), self::CALLBACK_REDIRECT, $url);
+ //$this->getResponse()->appendHeader(self::CALLBACK_REDIRECT.': '.$url);
+ }
+
+ /**
+ * Renders the callback response by adding additional callback data and
+ * javascript actions in the header and page state if required.
+ * @param THtmlWriter html content writer.
+ */
+ protected function renderResponse($writer)
+ {
+ Prado::trace("ActivePage renderResponse()",'System.Web.UI.ActiveControls.TActivePageAdapter');
+ //renders all the defered render() calls.
+ foreach($this->_controlsToRender as $rid => $forRender)
+ $forRender[0]->render($forRender[1]);
+
+ $response = $this->getResponse();
+
+ //send response data in header
+ if($response->getHasAdapter())
+ {
+ $responseData = $response->getAdapter()->getResponseData();
+ if($responseData!==null)
+ {
+ $data = TJavaScript::jsonEncode($responseData);
+
+ $this->appendContentPart($response, self::CALLBACK_DATA_HEADER, $data);
+ //$response->appendHeader(self::CALLBACK_DATA_HEADER.': '.$data);
+ }
+ }
+
+ //sends page state in header
+ if(($handler = $this->getCallbackEventTarget()) !== null)
+ {
+ if($handler->getActiveControl()->getClientSide()->getEnablePageStateUpdate())
+ {
+ $pagestate = $this->getPage()->getClientState();
+ $this->appendContentPart($response, self::CALLBACK_PAGESTATE_HEADER, $pagestate);
+ //$response->appendHeader(self::CALLBACK_PAGESTATE_HEADER.': '.$pagestate);
+ }
+ }
+
+ //safari must receive at least 1 byte of data.
+ $writer->write(" ");
+
+ //output the end javascript
+ if($this->getPage()->getClientScript()->hasEndScripts())
+ {
+ $writer = $response->createHtmlWriter();
+ $this->getPage()->getClientScript()->renderEndScripts($writer);
+ $this->getPage()->getCallbackClient()->evaluateScript($writer);
+ }
+
+ //output the actions
+ $executeJavascript = $this->getCallbackClientHandler()->getClientFunctionsToExecute();
+ $actions = TJavaScript::jsonEncode($executeJavascript);
+ $this->appendContentPart($response, self::CALLBACK_ACTION_HEADER, $actions);
+ //$response->appendHeader(self::CALLBACK_ACTION_HEADER.': '.$actions);
+
+
+ $cs = $this->Page->getClientScript();
+
+ // collect all stylesheet file references
+ $stylesheets = $cs->getStyleSheetUrls();
+ if (count($stylesheets)>0)
+ $this->appendContentPart($response, self::CALLBACK_STYLESHEETLIST_HEADER, TJavaScript::jsonEncode($stylesheets));
+
+ // collect all script file references
+ $scripts = $cs->getScriptUrls();
+ if (count($scripts)>0)
+ $this->appendContentPart($response, self::CALLBACK_SCRIPTLIST_HEADER, TJavaScript::jsonEncode($scripts));
+
+ // collect all hidden field references
+ $fields = $cs->getHiddenFields();
+ if (count($fields)>0)
+ $this->appendContentPart($response, self::CALLBACK_HIDDENFIELDLIST_HEADER, TJavaScript::jsonEncode($fields));
+ }
+
+ /**
+ * Appends data or javascript code to the body content surrounded with delimiters
+ */
+ private function appendContentPart($response, $delimiter, $data)
+ {
+ $content = $response->createHtmlWriter();
+ $content->getWriter()->setBoundary($delimiter);
+ $content->write($data);
+ }
+
+ /**
+ * Trys to find the callback event handler and raise its callback event.
+ * @throws TInvalidCallbackException if call back target is not found.
+ * @throws TInvalidCallbackException if the requested target does not
+ * implement ICallbackEventHandler.
+ */
+ private function raiseCallbackEvent()
+ {
+ if(($callbackHandler=$this->getCallbackEventTarget())!==null)
+ {
+ if($callbackHandler instanceof ICallbackEventHandler)
+ {
+ $param = $this->getCallbackEventParameter();
+ $result = new TCallbackEventParameter($this->getResponse(), $param);
+ $callbackHandler->raiseCallbackEvent($result);
+ }
+ else
+ {
+ throw new TInvalidCallbackException(
+ 'callback_invalid_handler', $callbackHandler->getUniqueID());
+ }
+ }
+ else
+ {
+ $target = $this->getRequest()->itemAt(TPage::FIELD_CALLBACK_TARGET);
+ throw new TInvalidCallbackException('callback_invalid_target', $target);
+ }
+ }
+
+ /**
+ * @return TControl the control responsible for the current callback event,
+ * null if nonexistent
+ */
+ public function getCallbackEventTarget()
+ {
+ if($this->_callbackEventTarget===null)
+ {
+ $eventTarget=$this->getRequest()->itemAt(TPage::FIELD_CALLBACK_TARGET);
+ if(!empty($eventTarget))
+ $this->_callbackEventTarget=$this->getPage()->findControl($eventTarget);
+ }
+ return $this->_callbackEventTarget;
+ }
+
+ /**
+ * Registers a control to raise callback event in the current request.
+ * @param TControl control registered to raise callback event.
+ */
+ public function setCallbackEventTarget(TControl $control)
+ {
+ $this->_callbackEventTarget=$control;
+ }
+
+ /**
+ * Gets callback parameter. JSON encoding is assumed.
+ * @return string postback event parameter
+ */
+ public function getCallbackEventParameter()
+ {
+ if($this->_callbackEventParameter===null)
+ {
+ $param = $this->getRequest()->itemAt(TPage::FIELD_CALLBACK_PARAMETER);
+ if(strlen($param) > 0)
+ $this->_callbackEventParameter=TJavaScript::jsonDecode((string)$param);
+ }
+ return $this->_callbackEventParameter;
+ }
+
+ /**
+ * @param mixed postback event parameter
+ */
+ public function setCallbackEventParameter($value)
+ {
+ $this->_callbackEventParameter=$value;
+ }
+
+ /**
+ * Gets the callback client script handler. It handlers the javascript functions
+ * to be executed during the callback response.
+ * @return TCallbackClientScript callback client handler.
+ */
+ public function getCallbackClientHandler()
+ {
+ if($this->_callbackClient===null)
+ $this->_callbackClient = new TCallbackClientScript;
+ return $this->_callbackClient;
+ }
+}
+
+/**
+ * TCallbackErrorHandler class.
+ *
+ * Captures errors and exceptions and send them back during callback response.
+ * When the application is in debug mode, the error and exception stack trace
+ * are shown. A TJavascriptLogger must be present on the client-side to view
+ * the error stack trace.
+ *
+ * @author Wei Zhuo <weizhuo[at]gmail[dot]com>
+ * @version $Id$
+ * @package System.Web.UI.ActiveControls
+ * @since 3.1
+ */
+class TCallbackErrorHandler extends TErrorHandler
+{
+ /**
+ * Displays the exceptions to the client-side TJavascriptLogger.
+ * A HTTP 500 status code is sent and the stack trace is sent as JSON encoded.
+ * @param Exception exception details.
+ */
+ protected function displayException($exception)
+ {
+ if($this->getApplication()->getMode()===TApplication::STATE_DEBUG)
+ {
+ $response = $this->getApplication()->getResponse();
+ $trace = TJavaScript::jsonEncode($this->getExceptionStackTrace($exception));
+ $response->setStatusCode(500, 'Internal Server Error');
+ $response->appendHeader(TActivePageAdapter::CALLBACK_ERROR_HEADER.': '.$trace);
+ }
+ else
+ {
+ error_log("Error happened while processing an existing error:\n".$exception->__toString());
+ header('HTTP/1.0 500 Internal Server Error', true, 500);
+ }
+ $this->getApplication()->getResponse()->flush();
+ }
+
+ /**
+ * @param Exception exception details.
+ * @return array exception stack trace details.
+ */
+ private function getExceptionStackTrace($exception)
+ {
+ $data['code']=$exception->getCode() > 0 ? $exception->getCode() : 500;
+ $data['file']=$exception->getFile();
+ $data['line']=$exception->getLine();
+ $data['trace']=$exception->getTrace();
+ if($exception instanceof TPhpErrorException)
+ {
+ // if PHP exception, we want to show the 2nd stack level context
+ // because the 1st stack level is of little use (it's in error handler)
+ if(isset($trace[0]) && isset($trace[0]['file']) && isset($trace[0]['line']))
+ {
+ $data['file']=$trace[0]['file'];
+ $data['line']=$trace[0]['line'];
+ }
+ }
+ $data['type']=get_class($exception);
+ $data['message']=$exception->getMessage();
+ $data['version']=$_SERVER['SERVER_SOFTWARE'].' '.Prado::getVersion();
+ $data['time']=@strftime('%Y-%m-%d %H:%M',time());
+ return $data;
+ }
+}
+
+/**
+ * TInvalidCallbackException class.
+ *
+ * @author Wei Zhuo <weizhuo[at]gmail[dot]com>
+ * @version $Id$
+ * @package System.Web.UI.ActiveControls
+ * @since 3.1
+ */
+class TInvalidCallbackException extends TException
+{
+}
+
diff --git a/framework/Web/UI/ActiveControls/TActivePanel.php b/framework/Web/UI/ActiveControls/TActivePanel.php
index ae1dd09f..1edfa57c 100644
--- a/framework/Web/UI/ActiveControls/TActivePanel.php
+++ b/framework/Web/UI/ActiveControls/TActivePanel.php
@@ -1,100 +1,100 @@
-<?php
-/**
- * TActivePanel file.
- *
- * @author Wei Zhuo <weizhuo[at]gamil[dot]com>
- * @link http://www.pradosoft.com/
- * @copyright Copyright &copy; 2005-2012 PradoSoft
- * @license http://www.pradosoft.com/license/
- * @version $Id$
- * @package System.Web.UI.ActiveControls
- */
-
-/**
- * Load active control adapter.
- */
-Prado::using('System.Web.UI.ActiveControls.TActiveControlAdapter');
-
-/**
- * TActivePanel is the TPanel active control counterpart.
- *
- * TActivePanel allows the client-side panel contents to be updated during a
- * callback response using the {@link render} method.
- *
- * Example: Assume $param is an instance of TCallbackEventParameter attached to
- * the OnCallback event of a TCallback with ID "callback1", and
- * "panel1" is the ID of a TActivePanel.
- * <code>
- * function callback1_requested($sender, $param)
- * {
- * $this->panel1->render($param->getNewWriter());
- * }
- * </code>
- *
- * @author Wei Zhuo <weizhuo[at]gmail[dot]com>
- * @version $Id$
- * @package System.Web.UI.ActiveControls
- * @since 3.1
- */
-class TActivePanel extends TPanel implements IActiveControl
-{
- /**
- * Creates a new callback control, sets the adapter to
- * TActiveControlAdapter. If you override this class, be sure to set the
- * adapter appropriately by, for example, by calling this constructor.
- */
- public function __construct()
- {
- parent::__construct();
- $this->setAdapter(new TActiveControlAdapter($this));
- }
-
- /**
- * @return TBaseActiveControl standard active control options.
- */
- public function getActiveControl()
- {
- return $this->getAdapter()->getBaseActiveControl();
- }
-
- /**
- * Adds attribute id to the renderer.
- * @param THtmlWriter the writer used for the rendering purpose
- */
- protected function addAttributesToRender($writer) {
- $writer->addAttribute('id',$this->getClientID());
- parent::addAttributesToRender($writer);
- }
-
- /**
- * Renders and replaces the panel's content on the client-side.
- * When render() is called before the OnPreRender event, such as when render()
- * is called during a callback event handler, the rendering
- * is defered until OnPreRender event is raised.
- * @param THtmlWriter html writer
- */
- public function render($writer)
- {
- if($this->getHasPreRendered())
- {
- parent::render($writer);
- if($this->getActiveControl()->canUpdateClientSide())
- $this->getPage()->getCallbackClient()->replaceContent($this,$writer);
- }
- else
- {
- $this->getPage()->getAdapter()->registerControlToRender($this,$writer);
- if ($this->getHasControls())
- {
- // If we update a TActivePanel on callback,
- // We shouldn't update all childs, because the whole content will be replaced by
- // the parent
- foreach ($this->findControlsByType('IActiveControl', false) as $control)
- {
- $control->getActiveControl()->setEnableUpdate(false);
- }
- }
- }
- }
-}
-
+<?php
+/**
+ * TActivePanel file.
+ *
+ * @author Wei Zhuo <weizhuo[at]gamil[dot]com>
+ * @link http://www.pradosoft.com/
+ * @copyright Copyright &copy; 2005-2012 PradoSoft
+ * @license http://www.pradosoft.com/license/
+ * @version $Id$
+ * @package System.Web.UI.ActiveControls
+ */
+
+/**
+ * Load active control adapter.
+ */
+Prado::using('System.Web.UI.ActiveControls.TActiveControlAdapter');
+
+/**
+ * TActivePanel is the TPanel active control counterpart.
+ *
+ * TActivePanel allows the client-side panel contents to be updated during a
+ * callback response using the {@link render} method.
+ *
+ * Example: Assume $param is an instance of TCallbackEventParameter attached to
+ * the OnCallback event of a TCallback with ID "callback1", and
+ * "panel1" is the ID of a TActivePanel.
+ * <code>
+ * function callback1_requested($sender, $param)
+ * {
+ * $this->panel1->render($param->getNewWriter());
+ * }
+ * </code>
+ *
+ * @author Wei Zhuo <weizhuo[at]gmail[dot]com>
+ * @version $Id$
+ * @package System.Web.UI.ActiveControls
+ * @since 3.1
+ */
+class TActivePanel extends TPanel implements IActiveControl
+{
+ /**
+ * Creates a new callback control, sets the adapter to
+ * TActiveControlAdapter. If you override this class, be sure to set the
+ * adapter appropriately by, for example, by calling this constructor.
+ */
+ public function __construct()
+ {
+ parent::__construct();
+ $this->setAdapter(new TActiveControlAdapter($this));
+ }
+
+ /**
+ * @return TBaseActiveControl standard active control options.
+ */
+ public function getActiveControl()
+ {
+ return $this->getAdapter()->getBaseActiveControl();
+ }
+
+ /**
+ * Adds attribute id to the renderer.
+ * @param THtmlWriter the writer used for the rendering purpose
+ */
+ protected function addAttributesToRender($writer) {
+ $writer->addAttribute('id',$this->getClientID());
+ parent::addAttributesToRender($writer);
+ }
+
+ /**
+ * Renders and replaces the panel's content on the client-side.
+ * When render() is called before the OnPreRender event, such as when render()
+ * is called during a callback event handler, the rendering
+ * is defered until OnPreRender event is raised.
+ * @param THtmlWriter html writer
+ */
+ public function render($writer)
+ {
+ if($this->getHasPreRendered())
+ {
+ parent::render($writer);
+ if($this->getActiveControl()->canUpdateClientSide())
+ $this->getPage()->getCallbackClient()->replaceContent($this,$writer);
+ }
+ else
+ {
+ $this->getPage()->getAdapter()->registerControlToRender($this,$writer);
+ if ($this->getHasControls())
+ {
+ // If we update a TActivePanel on callback,
+ // We shouldn't update all childs, because the whole content will be replaced by
+ // the parent
+ foreach ($this->findControlsByType('IActiveControl', false) as $control)
+ {
+ $control->getActiveControl()->setEnableUpdate(false);
+ }
+ }
+ }
+ }
+}
+
diff --git a/framework/Web/UI/ActiveControls/TActiveRatingList.php b/framework/Web/UI/ActiveControls/TActiveRatingList.php
index 7c878dd8..81f50dd1 100644
--- a/framework/Web/UI/ActiveControls/TActiveRatingList.php
+++ b/framework/Web/UI/ActiveControls/TActiveRatingList.php
@@ -1,133 +1,133 @@
-<?php
-/**
- * TActiveRatingList class file.
- *
- * @author Wei Zhuo <weizhuo[at]gamil[dot]com>
- * @author Bradley Booms <bradley[dot]booms[at]gmail[dot]com>
- * @link http://www.pradosoft.com/
- * @copyright Copyright &copy; 2005-2012 PradoSoft
- * @license http://www.pradosoft.com/license/
- * @version $Id$
- * @package System.Web.UI.ActiveControls
- */
-
-/**
- * TActiveRatingList Class
- *
- * Displays clickable images that represent a TRadioButtonList
- *
- * @author Wei Zhuo <weizhuo[at]gmail[dot]com>
- * @author Bradley Booms <bradley[dot]booms[at]gmail[dot]com>
- * @version $Id$
- * @package System.Web.UI.ActiveControls
- * @since 3.1
- */
-class TActiveRatingList extends TRatingList implements IActiveControl, ICallbackEventHandler
-{
- /**
- * Creates a new callback control, sets the adapter to
- * TActiveListControlAdapter. If you override this class, be sure to set the
- * adapter appropriately by, for example, by calling this constructor.
- */
- public function __construct()
- {
- $this->setAdapter(new TActiveListControlAdapter($this));
- $this->setAutoPostBack(true);
- parent::__construct();
- }
-
- /**
- * @return TBaseActiveCallbackControl standard callback control options.
- */
- public function getActiveControl()
- {
- return $this->getAdapter()->getBaseActiveControl();
- }
-
- /**
- * @return TCallbackClientSide client side request options.
- */
- public function getClientSide()
- {
- return $this->getAdapter()->getBaseActiveControl()->getClientSide();
- }
-
- /**
- * Raises the callback event. This method is required by {@link
- * ICallbackEventHandler} interface.
- * This method is mainly used by framework and control developers.
- * @param TCallbackEventParameter the event parameter
- */
- public function raiseCallbackEvent($param)
- {
- $this->onCallback($param);
- }
-
- /**
- * This method is invoked when a callback is requested. The method raises
- * 'OnCallback' event to fire up the event handlers. If you override this
- * method, be sure to call the parent implementation so that the event
- * handler can be invoked.
- * @param TCallbackEventParameter event parameter to be passed to the event handlers
- */
- public function onCallback($param)
- {
- $this->raiseEvent('OnCallback', $this, $param);
- }
-
- /**
- * @param boolean whether the items in the column can be edited
- */
- public function setReadOnly($value)
- {
- parent::setReadOnly($value);
- $value = $this->getReadOnly();
- $this->callClientFunction('setReadOnly',$value);
- }
-
- /**
- * @param float rating value, also sets the selected Index
- */
- public function setRating($value)
- {
- parent::setRating($value);
- $value = $this->getRating();
- $this->callClientFunction('setRating',$value);
- }
-
- /**
- * Calls the client-side static method for this control class.
- * @param string static method name
- * @param mixed method parmaeter
- */
- protected function callClientFunction($func,$value)
- {
- if($this->getActiveControl()->canUpdateClientSide())
- {
- $client = $this->getPage()->getCallbackClient();
- $code = parent::getClientClassName().'.'.$func;
- $client->callClientFunction($code,array($this,$value));
- }
- }
-
- /**
- * @param string caption text
- */
- public function setCaption($value)
- {
- parent::setCaption($value);
- // if it's an active control, this should not be needed.
- $this->callClientFunction('setCaption',$value);
- }
-
- /**
- * Gets the name of the javascript class responsible for performing postback for this control.
- * This method overrides the parent implementation.
- * @return string the javascript class name
- */
- protected function getClientClassName()
- {
- return 'Prado.WebUI.TActiveRatingList';
- }
-}
-
+<?php
+/**
+ * TActiveRatingList class file.
+ *
+ * @author Wei Zhuo <weizhuo[at]gamil[dot]com>
+ * @author Bradley Booms <bradley[dot]booms[at]gmail[dot]com>
+ * @link http://www.pradosoft.com/
+ * @copyright Copyright &copy; 2005-2012 PradoSoft
+ * @license http://www.pradosoft.com/license/
+ * @version $Id$
+ * @package System.Web.UI.ActiveControls
+ */
+
+/**
+ * TActiveRatingList Class
+ *
+ * Displays clickable images that represent a TRadioButtonList
+ *
+ * @author Wei Zhuo <weizhuo[at]gmail[dot]com>
+ * @author Bradley Booms <bradley[dot]booms[at]gmail[dot]com>
+ * @version $Id$
+ * @package System.Web.UI.ActiveControls
+ * @since 3.1
+ */
+class TActiveRatingList extends TRatingList implements IActiveControl, ICallbackEventHandler
+{
+ /**
+ * Creates a new callback control, sets the adapter to
+ * TActiveListControlAdapter. If you override this class, be sure to set the
+ * adapter appropriately by, for example, by calling this constructor.
+ */
+ public function __construct()
+ {
+ $this->setAdapter(new TActiveListControlAdapter($this));
+ $this->setAutoPostBack(true);
+ parent::__construct();
+ }
+
+ /**
+ * @return TBaseActiveCallbackControl standard callback control options.
+ */
+ public function getActiveControl()
+ {
+ return $this->getAdapter()->getBaseActiveControl();
+ }
+
+ /**
+ * @return TCallbackClientSide client side request options.
+ */
+ public function getClientSide()
+ {
+ return $this->getAdapter()->getBaseActiveControl()->getClientSide();
+ }
+
+ /**
+ * Raises the callback event. This method is required by {@link
+ * ICallbackEventHandler} interface.
+ * This method is mainly used by framework and control developers.
+ * @param TCallbackEventParameter the event parameter
+ */
+ public function raiseCallbackEvent($param)
+ {
+ $this->onCallback($param);
+ }
+
+ /**
+ * This method is invoked when a callback is requested. The method raises
+ * 'OnCallback' event to fire up the event handlers. If you override this
+ * method, be sure to call the parent implementation so that the event
+ * handler can be invoked.
+ * @param TCallbackEventParameter event parameter to be passed to the event handlers
+ */
+ public function onCallback($param)
+ {
+ $this->raiseEvent('OnCallback', $this, $param);
+ }
+
+ /**
+ * @param boolean whether the items in the column can be edited
+ */
+ public function setReadOnly($value)
+ {
+ parent::setReadOnly($value);
+ $value = $this->getReadOnly();
+ $this->callClientFunction('setReadOnly',$value);
+ }
+
+ /**
+ * @param float rating value, also sets the selected Index
+ */
+ public function setRating($value)
+ {
+ parent::setRating($value);
+ $value = $this->getRating();
+ $this->callClientFunction('setRating',$value);
+ }
+
+ /**
+ * Calls the client-side static method for this control class.
+ * @param string static method name
+ * @param mixed method parmaeter
+ */
+ protected function callClientFunction($func,$value)
+ {
+ if($this->getActiveControl()->canUpdateClientSide())
+ {
+ $client = $this->getPage()->getCallbackClient();
+ $code = parent::getClientClassName().'.'.$func;
+ $client->callClientFunction($code,array($this,$value));
+ }
+ }
+
+ /**
+ * @param string caption text
+ */
+ public function setCaption($value)
+ {
+ parent::setCaption($value);
+ // if it's an active control, this should not be needed.
+ $this->callClientFunction('setCaption',$value);
+ }
+
+ /**
+ * Gets the name of the javascript class responsible for performing postback for this control.
+ * This method overrides the parent implementation.
+ * @return string the javascript class name
+ */
+ protected function getClientClassName()
+ {
+ return 'Prado.WebUI.TActiveRatingList';
+ }
+}
+
diff --git a/framework/Web/UI/ActiveControls/TActiveTextBox.php b/framework/Web/UI/ActiveControls/TActiveTextBox.php
index 1e2fc46f..562f59cd 100644
--- a/framework/Web/UI/ActiveControls/TActiveTextBox.php
+++ b/framework/Web/UI/ActiveControls/TActiveTextBox.php
@@ -1,125 +1,125 @@
-<?php
-/**
- * TActiveTextBox class file.
- *
- * @author Wei Zhuo <weizhuo[at]gamil[dot]com>
- * @link http://www.pradosoft.com/
- * @copyright Copyright &copy; 2005-2012 PradoSoft
- * @license http://www.pradosoft.com/license/
- * @version $Id$
- * @package System.Web.UI.ActiveControls
- */
-
-/**
- * Load active control adapter.
- */
-Prado::using('System.Web.UI.ActiveControls.TActiveControlAdapter');
-
-/**
- * TActiveTextBox class.
- *
- * TActiveTextBox allows the {@link setText Text} property of the textbox to
- * be changed during callback. When {@link setAutoPostBack AutoPostBack} property
- * is true, changes to the textbox contents will perform a callback request causing
- * {@link onTextChanged OnTextChanged} to be fired first followed by {@link onCallback OnCallback}
- * event.
- *
- * @author Wei Zhuo <weizhuo[at]gmail[dot]com>
- * @version $Id$
- * @package System.Web.UI.ActiveControls
- * @since 3.1
- */
-class TActiveTextBox extends TTextBox implements ICallbackEventHandler, IActiveControl
-{
- /**
- * Creates a new callback control, sets the adapter to
- * TActiveControlAdapter. If you override this class, be sure to set the
- * adapter appropriately by, for example, by calling this constructor.
- */
- public function __construct()
- {
- parent::__construct();
- $this->setAdapter(new TActiveControlAdapter($this));
- }
-
- /**
- * @return TBaseActiveCallbackControl standard callback control options.
- */
- public function getActiveControl()
- {
- return $this->getAdapter()->getBaseActiveControl();
- }
-
- /**
- * @return TCallbackClientSide client side request options.
- */
- public function getClientSide()
- {
- return $this->getAdapter()->getBaseActiveControl()->getClientSide();
- }
-
- /**
- * Client-side Text property can only be updated after the OnLoad stage.
- * @param string text content for the textbox
- */
- public function setText($value)
- {
- parent::setText($value);
- if($this->getActiveControl()->canUpdateClientSide() && $this->getHasLoadedPostData())
- $this->getPage()->getCallbackClient()->setValue($this, $value);
- }
-
- /**
- * Raises the callback event. This method is required by {@link
- * ICallbackEventHandler} interface.
- * This method is mainly used by framework and control developers.
- * @param TCallbackEventParameter the event parameter
- */
- public function raiseCallbackEvent($param)
- {
- $this->onCallback($param);
- }
-
- /**
- * This method is invoked when a callback is requested. The method raises
- * 'OnCallback' event to fire up the event handlers. If you override this
- * method, be sure to call the parent implementation so that the event
- * handler can be invoked.
- * @param TCallbackEventParameter event parameter to be passed to the event handlers
- */
- public function onCallback($param)
- {
- $this->raiseEvent('OnCallback', $this, $param);
- }
-
- /**
- * Gets the name of the javascript class responsible for performing postback for this control.
- * This method overrides the parent implementation.
- * @return string the javascript class name
- */
- protected function getClientClassName()
- {
- return 'Prado.WebUI.TActiveTextBox';
- }
-
- /**
- * Override parent implementation, no javascript is rendered here instead
- * the javascript required for active control is registered in {@link addAttributesToRender}.
- */
- protected function renderClientControlScript($writer)
- {
- }
-
- /**
- * Ensure that the ID attribute is rendered and registers the javascript code
- * for initializing the active control.
- */
- protected function addAttributesToRender($writer)
- {
- parent::addAttributesToRender($writer);
- $writer->addAttribute('id',$this->getClientID());
- $this->getActiveControl()->registerCallbackClientScript(
- $this->getClientClassName(), $this->getPostBackOptions());
- }
-}
-
+<?php
+/**
+ * TActiveTextBox class file.
+ *
+ * @author Wei Zhuo <weizhuo[at]gamil[dot]com>
+ * @link http://www.pradosoft.com/
+ * @copyright Copyright &copy; 2005-2012 PradoSoft
+ * @license http://www.pradosoft.com/license/
+ * @version $Id$
+ * @package System.Web.UI.ActiveControls
+ */
+
+/**
+ * Load active control adapter.
+ */
+Prado::using('System.Web.UI.ActiveControls.TActiveControlAdapter');
+
+/**
+ * TActiveTextBox class.
+ *
+ * TActiveTextBox allows the {@link setText Text} property of the textbox to
+ * be changed during callback. When {@link setAutoPostBack AutoPostBack} property
+ * is true, changes to the textbox contents will perform a callback request causing
+ * {@link onTextChanged OnTextChanged} to be fired first followed by {@link onCallback OnCallback}
+ * event.
+ *
+ * @author Wei Zhuo <weizhuo[at]gmail[dot]com>
+ * @version $Id$
+ * @package System.Web.UI.ActiveControls
+ * @since 3.1
+ */
+class TActiveTextBox extends TTextBox implements ICallbackEventHandler, IActiveControl
+{
+ /**
+ * Creates a new callback control, sets the adapter to
+ * TActiveControlAdapter. If you override this class, be sure to set the
+ * adapter appropriately by, for example, by calling this constructor.
+ */
+ public function __construct()
+ {
+ parent::__construct();
+ $this->setAdapter(new TActiveControlAdapter($this));
+ }
+
+ /**
+ * @return TBaseActiveCallbackControl standard callback control options.
+ */
+ public function getActiveControl()
+ {
+ return $this->getAdapter()->getBaseActiveControl();
+ }
+
+ /**
+ * @return TCallbackClientSide client side request options.
+ */
+ public function getClientSide()
+ {
+ return $this->getAdapter()->getBaseActiveControl()->getClientSide();
+ }
+
+ /**
+ * Client-side Text property can only be updated after the OnLoad stage.
+ * @param string text content for the textbox
+ */
+ public function setText($value)
+ {
+ parent::setText($value);
+ if($this->getActiveControl()->canUpdateClientSide() && $this->getHasLoadedPostData())
+ $this->getPage()->getCallbackClient()->setValue($this, $value);
+ }
+
+ /**
+ * Raises the callback event. This method is required by {@link
+ * ICallbackEventHandler} interface.
+ * This method is mainly used by framework and control developers.
+ * @param TCallbackEventParameter the event parameter
+ */
+ public function raiseCallbackEvent($param)
+ {
+ $this->onCallback($param);
+ }
+
+ /**
+ * This method is invoked when a callback is requested. The method raises
+ * 'OnCallback' event to fire up the event handlers. If you override this
+ * method, be sure to call the parent implementation so that the event
+ * handler can be invoked.
+ * @param TCallbackEventParameter event parameter to be passed to the event handlers
+ */
+ public function onCallback($param)
+ {
+ $this->raiseEvent('OnCallback', $this, $param);
+ }
+
+ /**
+ * Gets the name of the javascript class responsible for performing postback for this control.
+ * This method overrides the parent implementation.
+ * @return string the javascript class name
+ */
+ protected function getClientClassName()
+ {
+ return 'Prado.WebUI.TActiveTextBox';
+ }
+
+ /**
+ * Override parent implementation, no javascript is rendered here instead
+ * the javascript required for active control is registered in {@link addAttributesToRender}.
+ */
+ protected function renderClientControlScript($writer)
+ {
+ }
+
+ /**
+ * Ensure that the ID attribute is rendered and registers the javascript code
+ * for initializing the active control.
+ */
+ protected function addAttributesToRender($writer)
+ {
+ parent::addAttributesToRender($writer);
+ $writer->addAttribute('id',$this->getClientID());
+ $this->getActiveControl()->registerCallbackClientScript(
+ $this->getClientClassName(), $this->getPostBackOptions());
+ }
+}
+
diff --git a/framework/Web/UI/ActiveControls/TAutoComplete.php b/framework/Web/UI/ActiveControls/TAutoComplete.php
index 413d5c21..ce648b02 100644
--- a/framework/Web/UI/ActiveControls/TAutoComplete.php
+++ b/framework/Web/UI/ActiveControls/TAutoComplete.php
@@ -1,440 +1,440 @@
-<?php
-/**
- * TAutoComplete class file.
- *
- * @author Wei Zhuo <weizhuo[at]gamil[dot]com>
- * @link http://www.pradosoft.com/
- * @copyright Copyright &copy; 2005-2012 PradoSoft
- * @license http://www.pradosoft.com/license/
- * @version $Id$
- * @package System.Web.UI.ActiveControls
- */
-
-/**
- * Load active text box.
- */
-Prado::using('System.Web.UI.ActiveControls.TActiveTextBox');
-Prado::using('System.Web.UI.ActiveControls.TCallbackEventParameter');
-
-/**
- * TAutoComplete class.
- *
- * TAutoComplete is a textbox that provides a list of suggestion on
- * the current partial word typed in the textbox. The suggestions are
- * requested using callbacks, and raises the {@link onSuggestion OnSuggestion}
- * event. The events of the TActiveText (from which TAutoComplete is extended from)
- * and {@link onSuggestion OnSuggestion} are mutually exculsive. That is,
- * if {@link onTextChange OnTextChange} and/or {@link onCallback OnCallback}
- * events are raise, then {@link onSuggestion OnSuggestion} will not be raise, and
- * vice versa.
- *
- * The list of suggestions should be set in the {@link onSuggestion OnSuggestion}
- * event handler. The partial word to match the suggestion is in the
- * {@link TCallbackEventParameter::getCallbackParameter TCallbackEventParameter::CallbackParameter}
- * property. The datasource of the TAutoComplete must be set using {@link setDataSource}
- * method. This sets the datasource for the suggestions repeater, available through
- * the {@link getSuggestions Suggestions} property. Header, footer templates and
- * other properties of the repeater can be access via the {@link getSuggestions Suggestions}
- * property and its sub-properties.
- *
- * The {@link setTextCssClass TextCssClass} property if set is used to find
- * the element within the Suggestions.ItemTemplate and Suggestions.AlternatingItemTemplate
- * that contains the actual text for the suggestion selected. That is,
- * only text inside elements with CSS class name equal to {@link setTextCssClass TextCssClass}
- * will be used as suggestions.
- *
- * To return the list of suggestions back to the browser, supply a non-empty data source
- * and call databind. For example,
- * <code>
- * function autocomplete_suggestion($sender, $param)
- * {
- * $token = $param->getToken(); //the partial word to match
- * $sender->setDataSource($this->getSuggestionsFor($token)); //set suggestions
- * $sender->dataBind();
- * }
- * </code>
- *
- * The suggestion will be rendered when the {@link dataBind()} method is called
- * <strong>during a callback request</strong>.
- *
- * When an suggestion is selected, that is, when the use has clicked, pressed
- * the "Enter" key, or pressed the "Tab" key, the {@link onSuggestionSelected OnSuggestionSelected}
- * event is raised. The
- * {@link TCallbackEventParameter::getCallbackParameter TCallbackEventParameter::CallbackParameter}
- * property contains the index of the selected suggestion.
- *
- * TAutoComplete allows multiple suggestions within one textbox with each
- * word or phrase separated by any characters specified in the
- * {@link setSeparator Separator} property. The {@link setFrequency Frequency}
- * and {@link setMinChars MinChars} properties sets the delay and minimum number
- * of characters typed, respectively, before requesting for sugggestions.
- *
- * Use {@link onTextChange OnTextChange} and/or {@link onCallback OnCallback} events
- * to handle post backs due to {@link setAutoPostBack AutoPostBack}.
- *
- * In the {@link getSuggestions Suggestions} TRepater item template, all HTML text elements
- * are considered as text for the suggestion. Text within HTML elements with CSS class name
- * "informal" are ignored as text for suggestions.
- *
- * @author Wei Zhuo <weizhuo[at]gmail[dot]com>
- * @version $Id$
- * @package System.Web.UI.ActiveControls
- * @since 3.1
- */
-class TAutoComplete extends TActiveTextBox implements INamingContainer
-{
- /**
- * @var ITemplate template for repeater items
- */
- private $_repeater=null;
- /**
- * @var TPanel result panel holding the suggestion items.
- */
- private $_resultPanel=null;
-
- /**
- * @return string word or token separators (delimiters).
- */
- public function getSeparator()
- {
- return $this->getViewState('tokens', '');
- }
-
- /**
- * @return string word or token separators (delimiters).
- */
- public function setSeparator($value)
- {
- $this->setViewState('tokens', TPropertyValue::ensureString($value), '');
- }
-
- /**
- * @return float maximum delay (in seconds) before requesting a suggestion.
- */
- public function getFrequency()
- {
- return $this->getViewState('frequency', '');
- }
-
- /**
- * @param float maximum delay (in seconds) before requesting a suggestion.
- * Default is 0.4.
- */
- public function setFrequency($value)
- {
- $this->setViewState('frequency', TPropertyValue::ensureFloat($value),'');
- }
-
- /**
- * @return integer minimum number of characters before requesting a suggestion.
- */
- public function getMinChars()
- {
- return $this->getViewState('minChars','');
- }
-
- /**
- * @param integer minimum number of characters before requesting a suggestion.
- */
- public function setMinChars($value)
- {
- $this->setViewState('minChars', TPropertyValue::ensureInteger($value), '');
- }
-
- /**
- * @param string Css class name of the element to use for suggestion.
- */
- public function setTextCssClass($value)
- {
- $this->setViewState('TextCssClass', $value);
- }
-
- /**
- * @return string Css class name of the element to use for suggestion.
- */
- public function getTextCssClass()
- {
- return $this->getViewState('TextCssClass');
- }
-
- /**
- * Raises the callback event. This method is overrides the parent implementation.
- * If {@link setAutoPostBack AutoPostBack} is enabled it will raise
- * {@link onTextChanged OnTextChanged} event event and then the
- * {@link onCallback OnCallback} event. The {@link onSuggest OnSuggest} event is
- * raise if the request is to find sugggestions, the {@link onTextChanged OnTextChanged}
- * and {@link onCallback OnCallback} events are <b>NOT</b> raised.
- * This method is mainly used by framework and control developers.
- * @param TCallbackEventParameter the event parameter
- */
- public function raiseCallbackEvent($param)
- {
- $token = $param->getCallbackParameter();
- if(is_array($token) && count($token) == 2)
- {
- if($token[1] === '__TAutoComplete_onSuggest__')
- {
- $parameter = new TAutoCompleteEventParameter($this->getResponse(), $token[0]);
- $this->onSuggest($parameter);
- }
- else if($token[1] === '__TAutoComplete_onSuggestionSelected__')
- {
- $parameter = new TAutoCompleteEventParameter($this->getResponse(), null, $token[0]);
- $this->onSuggestionSelected($parameter);
- }
- }
- else if($this->getAutoPostBack())
- parent::raiseCallbackEvent($param);
- }
-
- /**
- * This method is invoked when an autocomplete suggestion is requested.
- * The method raises 'OnSuggest' event. If you override this
- * method, be sure to call the parent implementation so that the event
- * handler can be invoked.
- * @param TCallbackEventParameter event parameter to be passed to the event handlers
- */
- public function onSuggest($param)
- {
- $this->raiseEvent('OnSuggest', $this, $param);
- }
-
- /**
- * This method is invoked when an autocomplete suggestion is selected.
- * The method raises 'OnSuggestionSelected' event. If you override this
- * method, be sure to call the parent implementation so that the event
- * handler can be invoked.
- * @param TCallbackEventParameter event parameter to be passed to the event handlers
- */
- public function onSuggestionSelected($param)
- {
- $this->raiseEvent('OnSuggestionSelected', $this, $param);
- }
-
- /**
- * @param array data source for suggestions.
- */
- public function setDataSource($data)
- {
- $this->getSuggestions()->setDataSource($data);
- }
-
- /**
- * Overrides parent implementation. Callback {@link renderSuggestions()} when
- * page's IsCallback property is true.
- */
- public function dataBind()
- {
- parent::dataBind();
- if($this->getPage()->getIsCallback())
- $this->renderSuggestions($this->getResponse()->createHtmlWriter());
- }
-
- /**
- * @return TPanel suggestion results panel.
- */
- public function getResultPanel()
- {
- if($this->_resultPanel===null)
- $this->_resultPanel = $this->createResultPanel();
- return $this->_resultPanel;
- }
-
- /**
- * @return TPanel new instance of result panel. Default uses TPanel.
- */
- protected function createResultPanel()
- {
- $panel = Prado::createComponent('System.Web.UI.WebControls.TPanel');
- $this->getControls()->add($panel);
- $panel->setID('result');
- return $panel;
- }
-
- /**
- * @return TRepeater suggestion list repeater
- */
- public function getSuggestions()
- {
- if($this->_repeater===null)
- $this->_repeater = $this->createRepeater();
- return $this->_repeater;
- }
-
- /**
- * @return TRepeater new instance of TRepater to render the list of suggestions.
- */
- protected function createRepeater()
- {
- $repeater = Prado::createComponent('System.Web.UI.WebControls.TRepeater');
- $repeater->setHeaderTemplate(new TAutoCompleteTemplate('<ul>'));
- $repeater->setFooterTemplate(new TAutoCompleteTemplate('</ul>'));
- $repeater->setItemTemplate(new TTemplate('<li><%# $this->DataItem %></li>',null));
- $this->getControls()->add($repeater);
- return $repeater;
- }
-
- /**
- * Renders the end tag and registers javascript effects library.
- */
- public function renderEndTag($writer)
- {
- $this->getPage()->getClientScript()->registerPradoScript('effects');
- parent::renderEndTag($writer);
- $this->renderResultPanel($writer);
- }
-
- /**
- * Renders the result panel.
- * @param THtmlWriter the renderer.
- */
- protected function renderResultPanel($writer)
- {
- $this->getResultPanel()->render($writer);
- }
-
- /**
- * Renders the suggestions during a callback respones.
- * @param THtmlWriter the renderer.
- */
- public function renderCallback($writer)
- {
- $this->renderSuggestions($writer);
- }
-
- /**
- * Renders the suggestions repeater.
- * @param THtmlWriter the renderer.
- */
- public function renderSuggestions($writer)
- {
- if($this->getActiveControl()->canUpdateClientSide())
- {
- $this->getSuggestions()->render($writer);
- $boundary = $writer->getWriter()->getBoundary();
- $this->getResponse()->getAdapter()->setResponseData($boundary);
- }
- }
-
- /**
- * @return array list of callback options.
- */
- protected function getPostBackOptions()
- {
- //disallow page state update ?
- //$this->getActiveControl()->getClientSide()->setEnablePageStateUpdate(false);
- $options = array();
- if(strlen($string = $this->getSeparator()))
- {
- $string = strtr($string,array('\t'=>"\t",'\n'=>"\n",'\r'=>"\r"));
- $token = preg_split('//', $string, -1, PREG_SPLIT_NO_EMPTY);
- $options['tokens'] = $token;
- }
- if($this->getAutoPostBack())
- {
- $options = array_merge($options,parent::getPostBackOptions());
- $options['AutoPostBack'] = true;
- }
- if(strlen($select = $this->getTextCssClass()))
- $options['select'] = $select;
- $options['ResultPanel'] = $this->getResultPanel()->getClientID();
- $options['ID'] = $this->getClientID();
- $options['EventTarget'] = $this->getUniqueID();
- if(($minchars=$this->getMinChars())!=='')
- $options['minChars'] = $minchars;
- if(($frequency=$this->getFrequency())!=='')
- $options['frequency'] = $frequency;
- $options['CausesValidation'] = $this->getCausesValidation();
- $options['ValidationGroup'] = $this->getValidationGroup();
- return $options;
- }
-
- /**
- * Override parent implementation, no javascript is rendered here instead
- * the javascript required for active control is registered in {@link addAttributesToRender}.
- */
- protected function renderClientControlScript($writer)
- {
- }
-
- /**
- * @return string corresponding javascript class name for this TActiveButton.
- */
- protected function getClientClassName()
- {
- return 'Prado.WebUI.TAutoComplete';
- }
-}
-
-/**
- * TAutCompleteEventParameter contains the {@link getToken Token} requested by
- * the user for a partial match of the suggestions.
- *
- * The {@link getSelectedIndex SelectedIndex} is a zero-based index of the
- * suggestion selected by the user, -1 if not suggestion is selected.
- *
- * @author Wei Zhuo <weizhuo[at]gmail[dot]com>
- * @version $Id$
- * @package System.Web.UI.ActiveControls
- * @since 3.1
- */
-class TAutoCompleteEventParameter extends TCallbackEventParameter
-{
- private $_selectedIndex=-1;
-
- /**
- * Creates a new TCallbackEventParameter.
- */
- public function __construct($response, $parameter, $index=-1)
- {
- parent::__construct($response, $parameter);
- $this->_selectedIndex=$index;
- }
-
- /**
- * @return int selected suggestion zero-based index, -1 if not selected.
- */
- public function getSelectedIndex()
- {
- return $this->_selectedIndex;
- }
-
- /**
- * @return string token for matching a list of suggestions.
- */
- public function getToken()
- {
- return $this->getCallbackParameter();
- }
-}
-
-/**
- * TAutoCompleteTemplate class.
- *
- * TAutoCompleteTemplate is the default template for TAutoCompleteTemplate
- * item template.
- *
- * @author Wei Zhuo <weizhuo[at]gmail[dot]com>
- * @version $Id$
- * @package System.Web.UI.ActiveControls
- * @since 3.1
- */
-class TAutoCompleteTemplate extends TComponent implements ITemplate
-{
- private $_template;
-
- public function __construct($template)
- {
- $this->_template = $template;
- }
- /**
- * Instantiates the template.
- * It creates a {@link TDataList} control.
- * @param TControl parent to hold the content within the template
- */
- public function instantiateIn($parent)
- {
- $parent->getControls()->add($this->_template);
- }
-}
-
+<?php
+/**
+ * TAutoComplete class file.
+ *
+ * @author Wei Zhuo <weizhuo[at]gamil[dot]com>
+ * @link http://www.pradosoft.com/
+ * @copyright Copyright &copy; 2005-2012 PradoSoft
+ * @license http://www.pradosoft.com/license/
+ * @version $Id$
+ * @package System.Web.UI.ActiveControls
+ */
+
+/**
+ * Load active text box.
+ */
+Prado::using('System.Web.UI.ActiveControls.TActiveTextBox');
+Prado::using('System.Web.UI.ActiveControls.TCallbackEventParameter');
+
+/**
+ * TAutoComplete class.
+ *
+ * TAutoComplete is a textbox that provides a list of suggestion on
+ * the current partial word typed in the textbox. The suggestions are
+ * requested using callbacks, and raises the {@link onSuggestion OnSuggestion}
+ * event. The events of the TActiveText (from which TAutoComplete is extended from)
+ * and {@link onSuggestion OnSuggestion} are mutually exculsive. That is,
+ * if {@link onTextChange OnTextChange} and/or {@link onCallback OnCallback}
+ * events are raise, then {@link onSuggestion OnSuggestion} will not be raise, and
+ * vice versa.
+ *
+ * The list of suggestions should be set in the {@link onSuggestion OnSuggestion}
+ * event handler. The partial word to match the suggestion is in the
+ * {@link TCallbackEventParameter::getCallbackParameter TCallbackEventParameter::CallbackParameter}
+ * property. The datasource of the TAutoComplete must be set using {@link setDataSource}
+ * method. This sets the datasource for the suggestions repeater, available through
+ * the {@link getSuggestions Suggestions} property. Header, footer templates and
+ * other properties of the repeater can be access via the {@link getSuggestions Suggestions}
+ * property and its sub-properties.
+ *
+ * The {@link setTextCssClass TextCssClass} property if set is used to find
+ * the element within the Suggestions.ItemTemplate and Suggestions.AlternatingItemTemplate
+ * that contains the actual text for the suggestion selected. That is,
+ * only text inside elements with CSS class name equal to {@link setTextCssClass TextCssClass}
+ * will be used as suggestions.
+ *
+ * To return the list of suggestions back to the browser, supply a non-empty data source
+ * and call databind. For example,
+ * <code>
+ * function autocomplete_suggestion($sender, $param)
+ * {
+ * $token = $param->getToken(); //the partial word to match
+ * $sender->setDataSource($this->getSuggestionsFor($token)); //set suggestions
+ * $sender->dataBind();
+ * }
+ * </code>
+ *
+ * The suggestion will be rendered when the {@link dataBind()} method is called
+ * <strong>during a callback request</strong>.
+ *
+ * When an suggestion is selected, that is, when the use has clicked, pressed
+ * the "Enter" key, or pressed the "Tab" key, the {@link onSuggestionSelected OnSuggestionSelected}
+ * event is raised. The
+ * {@link TCallbackEventParameter::getCallbackParameter TCallbackEventParameter::CallbackParameter}
+ * property contains the index of the selected suggestion.
+ *
+ * TAutoComplete allows multiple suggestions within one textbox with each
+ * word or phrase separated by any characters specified in the
+ * {@link setSeparator Separator} property. The {@link setFrequency Frequency}
+ * and {@link setMinChars MinChars} properties sets the delay and minimum number
+ * of characters typed, respectively, before requesting for sugggestions.
+ *
+ * Use {@link onTextChange OnTextChange} and/or {@link onCallback OnCallback} events
+ * to handle post backs due to {@link setAutoPostBack AutoPostBack}.
+ *
+ * In the {@link getSuggestions Suggestions} TRepater item template, all HTML text elements
+ * are considered as text for the suggestion. Text within HTML elements with CSS class name
+ * "informal" are ignored as text for suggestions.
+ *
+ * @author Wei Zhuo <weizhuo[at]gmail[dot]com>
+ * @version $Id$
+ * @package System.Web.UI.ActiveControls
+ * @since 3.1
+ */
+class TAutoComplete extends TActiveTextBox implements INamingContainer
+{
+ /**
+ * @var ITemplate template for repeater items
+ */
+ private $_repeater=null;
+ /**
+ * @var TPanel result panel holding the suggestion items.
+ */
+ private $_resultPanel=null;
+
+ /**
+ * @return string word or token separators (delimiters).
+ */
+ public function getSeparator()
+ {
+ return $this->getViewState('tokens', '');
+ }
+
+ /**
+ * @return string word or token separators (delimiters).
+ */
+ public function setSeparator($value)
+ {
+ $this->setViewState('tokens', TPropertyValue::ensureString($value), '');
+ }
+
+ /**
+ * @return float maximum delay (in seconds) before requesting a suggestion.
+ */
+ public function getFrequency()
+ {
+ return $this->getViewState('frequency', '');
+ }
+
+ /**
+ * @param float maximum delay (in seconds) before requesting a suggestion.
+ * Default is 0.4.
+ */
+ public function setFrequency($value)
+ {
+ $this->setViewState('frequency', TPropertyValue::ensureFloat($value),'');
+ }
+
+ /**
+ * @return integer minimum number of characters before requesting a suggestion.
+ */
+ public function getMinChars()
+ {
+ return $this->getViewState('minChars','');
+ }
+
+ /**
+ * @param integer minimum number of characters before requesting a suggestion.
+ */
+ public function setMinChars($value)
+ {
+ $this->setViewState('minChars', TPropertyValue::ensureInteger($value), '');
+ }
+
+ /**
+ * @param string Css class name of the element to use for suggestion.
+ */
+ public function setTextCssClass($value)
+ {
+ $this->setViewState('TextCssClass', $value);
+ }
+
+ /**
+ * @return string Css class name of the element to use for suggestion.
+ */
+ public function getTextCssClass()
+ {
+ return $this->getViewState('TextCssClass');
+ }
+
+ /**
+ * Raises the callback event. This method is overrides the parent implementation.
+ * If {@link setAutoPostBack AutoPostBack} is enabled it will raise
+ * {@link onTextChanged OnTextChanged} event event and then the
+ * {@link onCallback OnCallback} event. The {@link onSuggest OnSuggest} event is
+ * raise if the request is to find sugggestions, the {@link onTextChanged OnTextChanged}
+ * and {@link onCallback OnCallback} events are <b>NOT</b> raised.
+ * This method is mainly used by framework and control developers.
+ * @param TCallbackEventParameter the event parameter
+ */
+ public function raiseCallbackEvent($param)
+ {
+ $token = $param->getCallbackParameter();
+ if(is_array($token) && count($token) == 2)
+ {
+ if($token[1] === '__TAutoComplete_onSuggest__')
+ {
+ $parameter = new TAutoCompleteEventParameter($this->getResponse(), $token[0]);
+ $this->onSuggest($parameter);
+ }
+ else if($token[1] === '__TAutoComplete_onSuggestionSelected__')
+ {
+ $parameter = new TAutoCompleteEventParameter($this->getResponse(), null, $token[0]);
+ $this->onSuggestionSelected($parameter);
+ }
+ }
+ else if($this->getAutoPostBack())
+ parent::raiseCallbackEvent($param);
+ }
+
+ /**
+ * This method is invoked when an autocomplete suggestion is requested.
+ * The method raises 'OnSuggest' event. If you override this
+ * method, be sure to call the parent implementation so that the event
+ * handler can be invoked.
+ * @param TCallbackEventParameter event parameter to be passed to the event handlers
+ */
+ public function onSuggest($param)
+ {
+ $this->raiseEvent('OnSuggest', $this, $param);
+ }
+
+ /**
+ * This method is invoked when an autocomplete suggestion is selected.
+ * The method raises 'OnSuggestionSelected' event. If you override this
+ * method, be sure to call the parent implementation so that the event
+ * handler can be invoked.
+ * @param TCallbackEventParameter event parameter to be passed to the event handlers
+ */
+ public function onSuggestionSelected($param)
+ {
+ $this->raiseEvent('OnSuggestionSelected', $this, $param);
+ }
+
+ /**
+ * @param array data source for suggestions.
+ */
+ public function setDataSource($data)
+ {
+ $this->getSuggestions()->setDataSource($data);
+ }
+
+ /**
+ * Overrides parent implementation. Callback {@link renderSuggestions()} when
+ * page's IsCallback property is true.
+ */
+ public function dataBind()
+ {
+ parent::dataBind();
+ if($this->getPage()->getIsCallback())
+ $this->renderSuggestions($this->getResponse()->createHtmlWriter());
+ }
+
+ /**
+ * @return TPanel suggestion results panel.
+ */
+ public function getResultPanel()
+ {
+ if($this->_resultPanel===null)
+ $this->_resultPanel = $this->createResultPanel();
+ return $this->_resultPanel;
+ }
+
+ /**
+ * @return TPanel new instance of result panel. Default uses TPanel.
+ */
+ protected function createResultPanel()
+ {
+ $panel = Prado::createComponent('System.Web.UI.WebControls.TPanel');
+ $this->getControls()->add($panel);
+ $panel->setID('result');
+ return $panel;
+ }
+
+ /**
+ * @return TRepeater suggestion list repeater
+ */
+ public function getSuggestions()
+ {
+ if($this->_repeater===null)
+ $this->_repeater = $this->createRepeater();
+ return $this->_repeater;
+ }
+
+ /**
+ * @return TRepeater new instance of TRepater to render the list of suggestions.
+ */
+ protected function createRepeater()
+ {
+ $repeater = Prado::createComponent('System.Web.UI.WebControls.TRepeater');
+ $repeater->setHeaderTemplate(new TAutoCompleteTemplate('<ul>'));
+ $repeater->setFooterTemplate(new TAutoCompleteTemplate('</ul>'));
+ $repeater->setItemTemplate(new TTemplate('<li><%# $this->DataItem %></li>',null));
+ $this->getControls()->add($repeater);
+ return $repeater;
+ }
+
+ /**
+ * Renders the end tag and registers javascript effects library.
+ */
+ public function renderEndTag($writer)
+ {
+ $this->getPage()->getClientScript()->registerPradoScript('effects');
+ parent::renderEndTag($writer);
+ $this->renderResultPanel($writer);
+ }
+
+ /**
+ * Renders the result panel.
+ * @param THtmlWriter the renderer.
+ */
+ protected function renderResultPanel($writer)
+ {
+ $this->getResultPanel()->render($writer);
+ }
+
+ /**
+ * Renders the suggestions during a callback respones.
+ * @param THtmlWriter the renderer.
+ */
+ public function renderCallback($writer)
+ {
+ $this->renderSuggestions($writer);
+ }
+
+ /**
+ * Renders the suggestions repeater.
+ * @param THtmlWriter the renderer.
+ */
+ public function renderSuggestions($writer)
+ {
+ if($this->getActiveControl()->canUpdateClientSide())
+ {
+ $this->getSuggestions()->render($writer);
+ $boundary = $writer->getWriter()->getBoundary();
+ $this->getResponse()->getAdapter()->setResponseData($boundary);
+ }
+ }
+
+ /**
+ * @return array list of callback options.
+ */
+ protected function getPostBackOptions()
+ {
+ //disallow page state update ?
+ //$this->getActiveControl()->getClientSide()->setEnablePageStateUpdate(false);
+ $options = array();
+ if(strlen($string = $this->getSeparator()))
+ {
+ $string = strtr($string,array('\t'=>"\t",'\n'=>"\n",'\r'=>"\r"));
+ $token = preg_split('//', $string, -1, PREG_SPLIT_NO_EMPTY);
+ $options['tokens'] = $token;
+ }
+ if($this->getAutoPostBack())
+ {
+ $options = array_merge($options,parent::getPostBackOptions());
+ $options['AutoPostBack'] = true;
+ }
+ if(strlen($select = $this->getTextCssClass()))
+ $options['select'] = $select;
+ $options['ResultPanel'] = $this->getResultPanel()->getClientID();
+ $options['ID'] = $this->getClientID();
+ $options['EventTarget'] = $this->getUniqueID();
+ if(($minchars=$this->getMinChars())!=='')
+ $options['minChars'] = $minchars;
+ if(($frequency=$this->getFrequency())!=='')
+ $options['frequency'] = $frequency;
+ $options['CausesValidation'] = $this->getCausesValidation();
+ $options['ValidationGroup'] = $this->getValidationGroup();
+ return $options;
+ }
+
+ /**
+ * Override parent implementation, no javascript is rendered here instead
+ * the javascript required for active control is registered in {@link addAttributesToRender}.
+ */
+ protected function renderClientControlScript($writer)
+ {
+ }
+
+ /**
+ * @return string corresponding javascript class name for this TActiveButton.
+ */
+ protected function getClientClassName()
+ {
+ return 'Prado.WebUI.TAutoComplete';
+ }
+}
+
+/**
+ * TAutCompleteEventParameter contains the {@link getToken Token} requested by
+ * the user for a partial match of the suggestions.
+ *
+ * The {@link getSelectedIndex SelectedIndex} is a zero-based index of the
+ * suggestion selected by the user, -1 if not suggestion is selected.
+ *
+ * @author Wei Zhuo <weizhuo[at]gmail[dot]com>
+ * @version $Id$
+ * @package System.Web.UI.ActiveControls
+ * @since 3.1
+ */
+class TAutoCompleteEventParameter extends TCallbackEventParameter
+{
+ private $_selectedIndex=-1;
+
+ /**
+ * Creates a new TCallbackEventParameter.
+ */
+ public function __construct($response, $parameter, $index=-1)
+ {
+ parent::__construct($response, $parameter);
+ $this->_selectedIndex=$index;
+ }
+
+ /**
+ * @return int selected suggestion zero-based index, -1 if not selected.
+ */
+ public function getSelectedIndex()
+ {
+ return $this->_selectedIndex;
+ }
+
+ /**
+ * @return string token for matching a list of suggestions.
+ */
+ public function getToken()
+ {
+ return $this->getCallbackParameter();
+ }
+}
+
+/**
+ * TAutoCompleteTemplate class.
+ *
+ * TAutoCompleteTemplate is the default template for TAutoCompleteTemplate
+ * item template.
+ *
+ * @author Wei Zhuo <weizhuo[at]gmail[dot]com>
+ * @version $Id$
+ * @package System.Web.UI.ActiveControls
+ * @since 3.1
+ */
+class TAutoCompleteTemplate extends TComponent implements ITemplate
+{
+ private $_template;
+
+ public function __construct($template)
+ {
+ $this->_template = $template;
+ }
+ /**
+ * Instantiates the template.
+ * It creates a {@link TDataList} control.
+ * @param TControl parent to hold the content within the template
+ */
+ public function instantiateIn($parent)
+ {
+ $parent->getControls()->add($this->_template);
+ }
+}
+
diff --git a/framework/Web/UI/ActiveControls/TBaseActiveControl.php b/framework/Web/UI/ActiveControls/TBaseActiveControl.php
index d3391b71..c412a2e2 100644
--- a/framework/Web/UI/ActiveControls/TBaseActiveControl.php
+++ b/framework/Web/UI/ActiveControls/TBaseActiveControl.php
@@ -1,392 +1,392 @@
-<?php
-/**
- * TBaseActiveControl and TBaseActiveCallbackControl class file.
- *
- * @author Wei Zhuo <weizhuo[at]gamil[dot]com>
- * @link http://www.pradosoft.com/
- * @copyright Copyright &copy; 2005-2012 PradoSoft
- * @license http://www.pradosoft.com/license/
- * @version $Id$
- * @package System.Web.UI.ActiveControls
- */
-
-Prado::using('System.Web.UI.ActiveControls.TCallbackClientSide');
-
-/**
- * TBaseActiveControl class provided additional basic property for every
- * active control. An instance of TBaseActiveControl or its decendent
- * TBaseActiveCallbackControl is created by {@link TActiveControlAdapter::getBaseActiveControl()}
- * method.
- *
- * The {@link setEnableUpdate EnableUpdate} property determines wether the active
- * control is allowed to update the contents of the client-side when the callback
- * response returns.
- *
- * @author Wei Zhuo <weizhuo[at]gamil[dot]com>
- * @version $Id$
- * @package System.Web.UI.ActiveControls
- * @since 3.1
- */
-class TBaseActiveControl extends TComponent
-{
- /**
- * @var TMap map of active control options.
- */
- private $_options;
- /**
- * @var TControl attached control.
- */
- private $_control;
-
- /**
- * Constructor. Attach a base active control to an active control instance.
- * @param TControl active control
- */
- public function __construct($control)
- {
- $this->_control = $control;
- $this->_options = new TMap;
- }
-
- /**
- * Sets a named options with a value. Options are used to store and retrive
- * named values for the base active controls.
- * @param string option name.
- * @param mixed new value.
- * @param mixed default value.
- * @return mixed options value.
- */
- protected function setOption($name,$value,$default=null)
- {
- $value = ($value===null) ? $default : $value;
- if($value!==null)
- $this->_options->add($name,$value);
- }
-
- /**
- * Gets an option named value. Options are used to store and retrive
- * named values for the base active controls.
- * @param string option name.
- * @param mixed default value.
- * @return mixed options value.
- */
- protected function getOption($name,$default=null)
- {
- $item = $this->_options->itemAt($name);
- return ($item===null) ? $default : $item;
- }
-
- /**
- * @return TMap active control options
- */
- protected function getOptions()
- {
- return $this->_options;
- }
-
- /**
- * @return TPage the page containing the attached control.
- */
- protected function getPage()
- {
- return $this->_control->getPage();
- }
-
- /**
- * @return TControl the attached control.
- */
- protected function getControl()
- {
- return $this->_control;
- }
-
- /**
- * @param boolean true to allow fine grain callback updates.
- */
- public function setEnableUpdate($value)
- {
- $this->setOption('EnableUpdate', TPropertyValue::ensureBoolean($value), true);
- }
-
- /**
- * @return boolean true to allow fine grain callback updates.
- */
- public function getEnableUpdate()
- {
- return $this->getOption('EnableUpdate', true);
- }
-
- /**
- * Returns true if callback response is allowed to update the browser contents.
- * Is is true if the control is initilized, and is a callback request and
- * the {@link setEnableUpdate EnableUpdate} property is true and
- * the page is not loading post data.
- * @return boolean true if the callback response is allowed update
- * client-side contents.
- */
- public function canUpdateClientSide($bDontRequireVisibility=false)
- {
- return $this->getControl()->getHasChildInitialized()
- && $this->getPage()->getIsLoadingPostData() == false
- && $this->getPage()->getIsCallback()
- && $this->getEnableUpdate()
- && ($bDontRequireVisibility || $this->getControl()->getVisible());
- }
-}
-
-/**
- * TBaseActiveCallbackControl is a common set of options and functionality for
- * active controls that can perform callback requests.
- *
- * The properties of TBaseActiveCallbackControl can be accessed and changed from
- * each individual active controls' {@link getActiveControl ActiveControl}
- * property.
- *
- * The following example sets the validation group property of a TCallback component.
- * <code>
- * <com:TCallback ActiveControl.ValidationGroup="group1" ... />
- * </code>
- *
- * Additional client-side options and events can be set using the
- * {@link getClientSide ClientSide} property. The following example shows
- * an alert box when a TCallback component response returns successfully.
- * <code>
- * <com:TCallback ActiveControl.ClientSide.OnSuccess="alert('ok!')" ... />
- * </code>
- *
- * @author Wei Zhuo <weizhuo[at]gmail[dot]com>
- * @version $Id$
- * @package System.Web.UI.ActiveControls
- * @since 3.1
- */
-class TBaseActiveCallbackControl extends TBaseActiveControl
-{
- /**
- * Callback client-side options can be set by setting the properties of
- * the ClientSide property. E.g. <com:TCallback ActiveControl.ClientSide.OnSuccess="..." />
- * See {@link TCallbackClientSide} for details on the properties of ClientSide.
- * @return TCallbackClientSide client-side callback options.
- */
- public function getClientSide()
- {
- if(($client = $this->getOption('ClientSide'))===null)
- {
- $client = $this->createClientSide();
- $this->setOption('ClientSide', $client);
- }
- return $client;
- }
-
- /**
- * Sets the client side options. Can only be set when client side is null.
- * @param TCallbackClientSide client side options.
- */
- public function setClientSide($client)
- {
- if( $this->getOption('ClientSide')===null)
- $this->setOption('ClientSide', $client);
- else
- throw new TConfigurationException(
- 'active_controls_client_side_exists', $this->getControl()->getID());
- }
-
- /**
- * @return TCallbackClientSide callback client-side options.
- */
- protected function createClientSide()
- {
- return new TCallbackClientSide;
- }
-
- /**
- * Sets default callback options. Takes the ID of a TCallbackOptions
- * component to duplicate the client-side
- * options for this control. The {@link getClientSide ClientSide}
- * subproperties takes precedence over the CallbackOptions property.
- * @param string ID of a TCallbackOptions control from which ClientSide
- * options are cloned.
- */
- public function setCallbackOptions($value)
- {
- $this->setOption('CallbackOptions', $value, '');
- }
-
- /**
- * @return string ID of a TCallbackOptions control from which ClientSide
- * options are duplicated.
- */
- public function getCallbackOptions()
- {
- return $this->getOption('CallbackOptions', '');
- }
-
- /**
- * Returns an array of default callback client-side options. The default options
- * are obtained from the client-side options of a TCallbackOptions control with
- * ID specified by {@link setCallbackOptions CallbackOptions}.
- * @return array list of default callback client-side options.
- */
- protected function getDefaultClientSideOptions()
- {
- if(($id=$this->getCallbackOptions())!=='')
- {
- if(($pos=strrpos($id,'.'))!==false)
- {
- $control=$this->getControl()->getSubProperty(substr($id,0,$pos));
- $newid=substr($id,$pos+1);
- if ($control!==null)
- $control=$control->$newid;
- }
- else
- {
- $control=$this->getControl()->findControl($id);
- }
-
- if($control instanceof TCallbackOptions)
- return $control->getClientSide()->getOptions()->toArray();
- else
- throw new TConfigurationException('callback_invalid_callback_options', $this->getControl()->getID(), $id);
- }
-
- return array();
- }
-
- /**
- * @return boolean whether callback event trigger by this button will cause
- * input validation, default is true
- */
- public function getCausesValidation()
- {
- return $this->getOption('CausesValidation',true);
- }
-
- /**
- * @param boolean whether callback event trigger by this button will cause
- * input validation
- */
- public function setCausesValidation($value)
- {
- $this->setOption('CausesValidation',TPropertyValue::ensureBoolean($value),true);
- }
-
- /**
- * @return string the group of validators which the button causes validation
- * upon callback
- */
- public function getValidationGroup()
- {
- return $this->getOption('ValidationGroup','');
- }
-
- /**
- * @param string the group of validators which the button causes validation
- * upon callback
- */
- public function setValidationGroup($value)
- {
- $this->setOption('ValidationGroup',$value,'');
- }
-
- /**
- * @return boolean whether to perform validation if the callback is
- * requested.
- */
- public function canCauseValidation()
- {
- if($this->getCausesValidation())
- {
- $group=$this->getValidationGroup();
- return $this->getPage()->getValidators($group)->getCount()>0;
- }
- else
- return false;
- }
-
- /**
- * @param mixed callback parameter value.
- */
- public function setCallbackParameter($value)
- {
- $this->setOption('CallbackParameter', $value, '');
- }
-
- /**
- * @return mixed callback parameter value.
- */
- public function getCallbackParameter()
- {
- return $this->getOption('CallbackParameter', '');
- }
-
-
- /**
- * @return array list of callback javascript options.
- */
- protected function getClientSideOptions()
- {
- $default = $this->getDefaultClientSideOptions();
- $options = array_merge($default,$this->getClientSide()->getOptions()->toArray());
- $validate = $this->getCausesValidation();
- $options['CausesValidation']= $validate ? '' : false;
- $options['ValidationGroup']=$this->getValidationGroup();
- $options['CallbackParameter'] = $this->getCallbackParameter();
- return $options;
- }
-
- /**
- * Registers the callback control javascript code. Client-side options are
- * merged and passed to the javascript code. This method should be called by
- * Active component developers wanting to register the javascript to initialize
- * the active component with additional options offered by the
- * {@link getClientSide ClientSide} property.
- * @param string client side javascript class name.
- * @param array additional callback options.
- */
- public function registerCallbackClientScript($class,$options=null)
- {
- $cs = $this->getPage()->getClientScript();
- if(is_array($options))
- $options = array_merge($this->getClientSideOptions(),$options);
- else
- $options = $this->getClientSideOptions();
-
- //remove true as default to save bytes
- if($options['CausesValidation']===true)
- $options['CausesValidation']='';
- $cs->registerCallbackControl($class, $options);
- }
-
- /**
- * Returns the javascript callback request instance. To invoke a callback
- * request for this control call the <tt>dispatch()</tt> method on the
- * request instance. Example code in javascript
- * <code>
- * var request = <%= $this->mycallback->ActiveControl->Javascript %>;
- * request.setParameter('hello');
- * request.dispatch(); //make the callback request.
- * </code>
- *
- * Alternatively,
- * <code>
- * //dispatches immediately
- * Prado.Callback("<%= $this->mycallback->UniqueID %>",
- * $this->mycallback->ActiveControl->JsCallbackOptions);
- * </code>
- * @return string javascript client-side callback request object (javascript
- * code)
- */
- public function getJavascript()
- {
- $client = $this->getPage()->getClientScript();
- return $client->getCallbackReference($this->getControl(),$this->getClientSideOptions());
- }
-
- /**
- * @param string callback requestion options as javascript code.
- */
- public function getJsCallbackOptions()
- {
- return TJavaScript::encode($this->getClientSideOptions());
- }
-}
-
+<?php
+/**
+ * TBaseActiveControl and TBaseActiveCallbackControl class file.
+ *
+ * @author Wei Zhuo <weizhuo[at]gamil[dot]com>
+ * @link http://www.pradosoft.com/
+ * @copyright Copyright &copy; 2005-2012 PradoSoft
+ * @license http://www.pradosoft.com/license/
+ * @version $Id$
+ * @package System.Web.UI.ActiveControls
+ */
+
+Prado::using('System.Web.UI.ActiveControls.TCallbackClientSide');
+
+/**
+ * TBaseActiveControl class provided additional basic property for every
+ * active control. An instance of TBaseActiveControl or its decendent
+ * TBaseActiveCallbackControl is created by {@link TActiveControlAdapter::getBaseActiveControl()}
+ * method.
+ *
+ * The {@link setEnableUpdate EnableUpdate} property determines wether the active
+ * control is allowed to update the contents of the client-side when the callback
+ * response returns.
+ *
+ * @author Wei Zhuo <weizhuo[at]gamil[dot]com>
+ * @version $Id$
+ * @package System.Web.UI.ActiveControls
+ * @since 3.1
+ */
+class TBaseActiveControl extends TComponent
+{
+ /**
+ * @var TMap map of active control options.
+ */
+ private $_options;
+ /**
+ * @var TControl attached control.
+ */
+ private $_control;
+
+ /**
+ * Constructor. Attach a base active control to an active control instance.
+ * @param TControl active control
+ */
+ public function __construct($control)
+ {
+ $this->_control = $control;
+ $this->_options = new TMap;
+ }
+
+ /**
+ * Sets a named options with a value. Options are used to store and retrive
+ * named values for the base active controls.
+ * @param string option name.
+ * @param mixed new value.
+ * @param mixed default value.
+ * @return mixed options value.
+ */
+ protected function setOption($name,$value,$default=null)
+ {
+ $value = ($value===null) ? $default : $value;
+ if($value!==null)
+ $this->_options->add($name,$value);
+ }
+
+ /**
+ * Gets an option named value. Options are used to store and retrive
+ * named values for the base active controls.
+ * @param string option name.
+ * @param mixed default value.
+ * @return mixed options value.
+ */
+ protected function getOption($name,$default=null)
+ {
+ $item = $this->_options->itemAt($name);
+ return ($item===null) ? $default : $item;
+ }
+
+ /**
+ * @return TMap active control options
+ */
+ protected function getOptions()
+ {
+ return $this->_options;
+ }
+
+ /**
+ * @return TPage the page containing the attached control.
+ */
+ protected function getPage()
+ {
+ return $this->_control->getPage();
+ }
+
+ /**
+ * @return TControl the attached control.
+ */
+ protected function getControl()
+ {
+ return $this->_control;
+ }
+
+ /**
+ * @param boolean true to allow fine grain callback updates.
+ */
+ public function setEnableUpdate($value)
+ {
+ $this->setOption('EnableUpdate', TPropertyValue::ensureBoolean($value), true);
+ }
+
+ /**
+ * @return boolean true to allow fine grain callback updates.
+ */
+ public function getEnableUpdate()
+ {
+ return $this->getOption('EnableUpdate', true);
+ }
+
+ /**
+ * Returns true if callback response is allowed to update the browser contents.
+ * Is is true if the control is initilized, and is a callback request and
+ * the {@link setEnableUpdate EnableUpdate} property is true and
+ * the page is not loading post data.
+ * @return boolean true if the callback response is allowed update
+ * client-side contents.
+ */
+ public function canUpdateClientSide($bDontRequireVisibility=false)
+ {
+ return $this->getControl()->getHasChildInitialized()
+ && $this->getPage()->getIsLoadingPostData() == false
+ && $this->getPage()->getIsCallback()
+ && $this->getEnableUpdate()
+ && ($bDontRequireVisibility || $this->getControl()->getVisible());
+ }
+}
+
+/**
+ * TBaseActiveCallbackControl is a common set of options and functionality for
+ * active controls that can perform callback requests.
+ *
+ * The properties of TBaseActiveCallbackControl can be accessed and changed from
+ * each individual active controls' {@link getActiveControl ActiveControl}
+ * property.
+ *
+ * The following example sets the validation group property of a TCallback component.
+ * <code>
+ * <com:TCallback ActiveControl.ValidationGroup="group1" ... />
+ * </code>
+ *
+ * Additional client-side options and events can be set using the
+ * {@link getClientSide ClientSide} property. The following example shows
+ * an alert box when a TCallback component response returns successfully.
+ * <code>
+ * <com:TCallback ActiveControl.ClientSide.OnSuccess="alert('ok!')" ... />
+ * </code>
+ *
+ * @author Wei Zhuo <weizhuo[at]gmail[dot]com>
+ * @version $Id$
+ * @package System.Web.UI.ActiveControls
+ * @since 3.1
+ */
+class TBaseActiveCallbackControl extends TBaseActiveControl
+{
+ /**
+ * Callback client-side options can be set by setting the properties of
+ * the ClientSide property. E.g. <com:TCallback ActiveControl.ClientSide.OnSuccess="..." />
+ * See {@link TCallbackClientSide} for details on the properties of ClientSide.
+ * @return TCallbackClientSide client-side callback options.
+ */
+ public function getClientSide()
+ {
+ if(($client = $this->getOption('ClientSide'))===null)
+ {
+ $client = $this->createClientSide();
+ $this->setOption('ClientSide', $client);
+ }
+ return $client;
+ }
+
+ /**
+ * Sets the client side options. Can only be set when client side is null.
+ * @param TCallbackClientSide client side options.
+ */
+ public function setClientSide($client)
+ {
+ if( $this->getOption('ClientSide')===null)
+ $this->setOption('ClientSide', $client);
+ else
+ throw new TConfigurationException(
+ 'active_controls_client_side_exists', $this->getControl()->getID());
+ }
+
+ /**
+ * @return TCallbackClientSide callback client-side options.
+ */
+ protected function createClientSide()
+ {
+ return new TCallbackClientSide;
+ }
+
+ /**
+ * Sets default callback options. Takes the ID of a TCallbackOptions
+ * component to duplicate the client-side
+ * options for this control. The {@link getClientSide ClientSide}
+ * subproperties takes precedence over the CallbackOptions property.
+ * @param string ID of a TCallbackOptions control from which ClientSide
+ * options are cloned.
+ */
+ public function setCallbackOptions($value)
+ {
+ $this->setOption('CallbackOptions', $value, '');
+ }
+
+ /**
+ * @return string ID of a TCallbackOptions control from which ClientSide
+ * options are duplicated.
+ */
+ public function getCallbackOptions()
+ {
+ return $this->getOption('CallbackOptions', '');
+ }
+
+ /**
+ * Returns an array of default callback client-side options. The default options
+ * are obtained from the client-side options of a TCallbackOptions control with
+ * ID specified by {@link setCallbackOptions CallbackOptions}.
+ * @return array list of default callback client-side options.
+ */
+ protected function getDefaultClientSideOptions()
+ {
+ if(($id=$this->getCallbackOptions())!=='')
+ {
+ if(($pos=strrpos($id,'.'))!==false)
+ {
+ $control=$this->getControl()->getSubProperty(substr($id,0,$pos));
+ $newid=substr($id,$pos+1);
+ if ($control!==null)
+ $control=$control->$newid;
+ }
+ else
+ {
+ $control=$this->getControl()->findControl($id);
+ }
+
+ if($control instanceof TCallbackOptions)
+ return $control->getClientSide()->getOptions()->toArray();
+ else
+ throw new TConfigurationException('callback_invalid_callback_options', $this->getControl()->getID(), $id);
+ }
+
+ return array();
+ }
+
+ /**
+ * @return boolean whether callback event trigger by this button will cause
+ * input validation, default is true
+ */
+ public function getCausesValidation()
+ {
+ return $this->getOption('CausesValidation',true);
+ }
+
+ /**
+ * @param boolean whether callback event trigger by this button will cause
+ * input validation
+ */
+ public function setCausesValidation($value)
+ {
+ $this->setOption('CausesValidation',TPropertyValue::ensureBoolean($value),true);
+ }
+
+ /**
+ * @return string the group of validators which the button causes validation
+ * upon callback
+ */
+ public function getValidationGroup()
+ {
+ return $this->getOption('ValidationGroup','');
+ }
+
+ /**
+ * @param string the group of validators which the button causes validation
+ * upon callback
+ */
+ public function setValidationGroup($value)
+ {
+ $this->setOption('ValidationGroup',$value,'');
+ }
+
+ /**
+ * @return boolean whether to perform validation if the callback is
+ * requested.
+ */
+ public function canCauseValidation()
+ {
+ if($this->getCausesValidation())
+ {
+ $group=$this->getValidationGroup();
+ return $this->getPage()->getValidators($group)->getCount()>0;
+ }
+ else
+ return false;
+ }
+
+ /**
+ * @param mixed callback parameter value.
+ */
+ public function setCallbackParameter($value)
+ {
+ $this->setOption('CallbackParameter', $value, '');
+ }
+
+ /**
+ * @return mixed callback parameter value.
+ */
+ public function getCallbackParameter()
+ {
+ return $this->getOption('CallbackParameter', '');
+ }
+
+
+ /**
+ * @return array list of callback javascript options.
+ */
+ protected function getClientSideOptions()
+ {
+ $default = $this->getDefaultClientSideOptions();
+ $options = array_merge($default,$this->getClientSide()->getOptions()->toArray());
+ $validate = $this->getCausesValidation();
+ $options['CausesValidation']= $validate ? '' : false;
+ $options['ValidationGroup']=$this->getValidationGroup();
+ $options['CallbackParameter'] = $this->getCallbackParameter();
+ return $options;
+ }
+
+ /**
+ * Registers the callback control javascript code. Client-side options are
+ * merged and passed to the javascript code. This method should be called by
+ * Active component developers wanting to register the javascript to initialize
+ * the active component with additional options offered by the
+ * {@link getClientSide ClientSide} property.
+ * @param string client side javascript class name.
+ * @param array additional callback options.
+ */
+ public function registerCallbackClientScript($class,$options=null)
+ {
+ $cs = $this->getPage()->getClientScript();
+ if(is_array($options))
+ $options = array_merge($this->getClientSideOptions(),$options);
+ else
+ $options = $this->getClientSideOptions();
+
+ //remove true as default to save bytes
+ if($options['CausesValidation']===true)
+ $options['CausesValidation']='';
+ $cs->registerCallbackControl($class, $options);
+ }
+
+ /**
+ * Returns the javascript callback request instance. To invoke a callback
+ * request for this control call the <tt>dispatch()</tt> method on the
+ * request instance. Example code in javascript
+ * <code>
+ * var request = <%= $this->mycallback->ActiveControl->Javascript %>;
+ * request.setParameter('hello');
+ * request.dispatch(); //make the callback request.
+ * </code>
+ *
+ * Alternatively,
+ * <code>
+ * //dispatches immediately
+ * Prado.Callback("<%= $this->mycallback->UniqueID %>",
+ * $this->mycallback->ActiveControl->JsCallbackOptions);
+ * </code>
+ * @return string javascript client-side callback request object (javascript
+ * code)
+ */
+ public function getJavascript()
+ {
+ $client = $this->getPage()->getClientScript();
+ return $client->getCallbackReference($this->getControl(),$this->getClientSideOptions());
+ }
+
+ /**
+ * @param string callback requestion options as javascript code.
+ */
+ public function getJsCallbackOptions()
+ {
+ return TJavaScript::encode($this->getClientSideOptions());
+ }
+}
+
diff --git a/framework/Web/UI/ActiveControls/TCallback.php b/framework/Web/UI/ActiveControls/TCallback.php
index 7a1f54b7..662bc03f 100644
--- a/framework/Web/UI/ActiveControls/TCallback.php
+++ b/framework/Web/UI/ActiveControls/TCallback.php
@@ -1,101 +1,101 @@
-<?php
-/**
- * TCallback class file.
- *
- * @author Wei Zhuo <weizhuo[at]gmail[dot]com>
- * @link http://www.pradosoft.com/
- * @copyright Copyright &copy; 2005-2012 PradoSoft
- * @license http://www.pradosoft.com/license/
- * @version $Id$
- * @package System.Web.UI.ActiveControls
- */
-
-/**
- * Load active control adapter.
- */
-Prado::using('System.Web.UI.ActiveControls.TActiveControlAdapter');
-
-/**
- * TCallback component class.
- *
- * The TCallback provides a basic callback handler that can be invoked from the
- * client side by running the javascript code obtained from the
- * {@link TBaseActiveCallbackControl::getJavascript ActiveControl.Javascript} property.
- * The event {@link onCallback OnCallback} is raised when a callback is requested made.
- *
- * Example usage:
- * <code>
- * <com:TCallback ID="callback1" OnCallback="callback1_Requested" />
- * <script type="text/javascript">
- * function do_callback1()
- * {
- * var request = <%= $this->callback1->ActiveControl->Javascript %>;
- * request.dispatch();
- * }
- * </script>
- * <div onclick="do_callback1()">Click Me!</div>
- * </code>
- *
- * @author Wei Zhuo <weizhuo[at]gmail[dot]com>
- * @version $Id$
- * @package System.Web.UI.ActiveControls
- * @since 3.1
- */
-class TCallback extends TControl implements ICallbackEventHandler, IActiveControl
-{
- /**
- * Creates a new callback control, sets the adapter to
- * TActiveControlAdapter. If you override this class, be sure to set the
- * adapter appropriately by, for example, call this constructor.
- */
- public function __construct()
- {
- parent::__construct();
- $this->setAdapter(new TActiveControlAdapter($this));
- }
-
- /**
- * @return TBaseActiveCallbackControl standard callback options.
- */
- public function getActiveControl()
- {
- return $this->getAdapter()->getBaseActiveControl();
- }
-
- /**
- * @return TCallbackClientSide client side request options.
- */
- public function getClientSide()
- {
- return $this->getAdapter()->getBaseActiveControl()->getClientSide();
- }
-
- /**
- * Raises the callback event. This method is required by
- * {@link ICallbackEventHandler ICallbackEventHandler} interface. If
- * {@link getCausesValidation ActiveControl.CausesValidation} is true,
- * it will invoke the page's {@link TPage::validate validate} method first.
- * It will raise {@link onCallback OnCallback} event. This method is mainly
- * used by framework and control developers.
- * @param TCallbackEventParameter the event parameter
- */
- public function raiseCallbackEvent($param)
- {
- if($this->getActiveControl()->canCauseValidation())
- $this->getPage()->validate($this->getActiveControl()->getValidationGroup());
- $this->onCallback($param);
- }
-
- /**
- * This method is invoked when a callback is requested. The method raises
- * 'OnCallback' event to fire up the event handlers. If you override this
- * method, be sure to call the parent implementation so that the event
- * handler can be invoked.
- * @param TCallbackEventParameter event parameter to be passed to the event handlers
- */
- public function onCallback($param)
- {
- $this->raiseEvent('OnCallback', $this, $param);
- }
-}
-
+<?php
+/**
+ * TCallback class file.
+ *
+ * @author Wei Zhuo <weizhuo[at]gmail[dot]com>
+ * @link http://www.pradosoft.com/
+ * @copyright Copyright &copy; 2005-2012 PradoSoft
+ * @license http://www.pradosoft.com/license/
+ * @version $Id$
+ * @package System.Web.UI.ActiveControls
+ */
+
+/**
+ * Load active control adapter.
+ */
+Prado::using('System.Web.UI.ActiveControls.TActiveControlAdapter');
+
+/**
+ * TCallback component class.
+ *
+ * The TCallback provides a basic callback handler that can be invoked from the
+ * client side by running the javascript code obtained from the
+ * {@link TBaseActiveCallbackControl::getJavascript ActiveControl.Javascript} property.
+ * The event {@link onCallback OnCallback} is raised when a callback is requested made.
+ *
+ * Example usage:
+ * <code>
+ * <com:TCallback ID="callback1" OnCallback="callback1_Requested" />
+ * <script type="text/javascript">
+ * function do_callback1()
+ * {
+ * var request = <%= $this->callback1->ActiveControl->Javascript %>;
+ * request.dispatch();
+ * }
+ * </script>
+ * <div onclick="do_callback1()">Click Me!</div>
+ * </code>
+ *
+ * @author Wei Zhuo <weizhuo[at]gmail[dot]com>
+ * @version $Id$
+ * @package System.Web.UI.ActiveControls
+ * @since 3.1
+ */
+class TCallback extends TControl implements ICallbackEventHandler, IActiveControl
+{
+ /**
+ * Creates a new callback control, sets the adapter to
+ * TActiveControlAdapter. If you override this class, be sure to set the
+ * adapter appropriately by, for example, call this constructor.
+ */
+ public function __construct()
+ {
+ parent::__construct();
+ $this->setAdapter(new TActiveControlAdapter($this));
+ }
+
+ /**
+ * @return TBaseActiveCallbackControl standard callback options.
+ */
+ public function getActiveControl()
+ {
+ return $this->getAdapter()->getBaseActiveControl();
+ }
+
+ /**
+ * @return TCallbackClientSide client side request options.
+ */
+ public function getClientSide()
+ {
+ return $this->getAdapter()->getBaseActiveControl()->getClientSide();
+ }
+
+ /**
+ * Raises the callback event. This method is required by
+ * {@link ICallbackEventHandler ICallbackEventHandler} interface. If
+ * {@link getCausesValidation ActiveControl.CausesValidation} is true,
+ * it will invoke the page's {@link TPage::validate validate} method first.
+ * It will raise {@link onCallback OnCallback} event. This method is mainly
+ * used by framework and control developers.
+ * @param TCallbackEventParameter the event parameter
+ */
+ public function raiseCallbackEvent($param)
+ {
+ if($this->getActiveControl()->canCauseValidation())
+ $this->getPage()->validate($this->getActiveControl()->getValidationGroup());
+ $this->onCallback($param);
+ }
+
+ /**
+ * This method is invoked when a callback is requested. The method raises
+ * 'OnCallback' event to fire up the event handlers. If you override this
+ * method, be sure to call the parent implementation so that the event
+ * handler can be invoked.
+ * @param TCallbackEventParameter event parameter to be passed to the event handlers
+ */
+ public function onCallback($param)
+ {
+ $this->raiseEvent('OnCallback', $this, $param);
+ }
+}
+
diff --git a/framework/Web/UI/ActiveControls/TCallbackClientScript.php b/framework/Web/UI/ActiveControls/TCallbackClientScript.php
index 6dcbe3d0..291f22f2 100644
--- a/framework/Web/UI/ActiveControls/TCallbackClientScript.php
+++ b/framework/Web/UI/ActiveControls/TCallbackClientScript.php
@@ -1,705 +1,705 @@
-<?php
-/**
- * TCallbackClientScript class file
- *
- * @author Wei Zhuo <weizhuo[at]gamil[dot]com>
- * @link http://www.pradosoft.com/
- * @copyright Copyright &copy; 2005-2012 PradoSoft
- * @license http://www.pradosoft.com/license/
- * @version $Id$
- * @package System.Web.UI.ActiveControls
- */
-
-/**
- * TCallbackClientScript class.
- *
- * The TCallbackClientScript class provides corresponding methods that can be
- * executed on the client-side (i.e. the browser client that is viewing
- * the page) during a callback response.
- *
- * The avaiable methods includes setting/clicking input elements, changing Css
- * styles, hiding/showing elements, and adding visual effects to elements on the
- * page. The client-side methods can be access through the CallbackClient
- * property available in TPage.
- *
- * For example, to hide "$myTextBox" element during callback response, do
- * <code>
- * $this->getPage()->getCallbackClient()->hide($myTextBox);
- * </code>
- *
- * @author Wei Zhuo <weizhuo[at]gamil[dot]com>
- * @version $Id$
- * @package System.Web.UI.ActiveControls
- * @since 3.1
- */
-class TCallbackClientScript extends TApplicationComponent
-{
- /**
- * @var TList list of client functions to execute.
- */
- private $_actions;
-
- /**
- * Constructor.
- */
- public function __construct()
- {
- $this->_actions = new TList;
- }
-
- /**
- * @return array list of client function to be executed during callback
- * response.
- */
- public function getClientFunctionsToExecute()
- {
- return $this->_actions->toArray();
- }
-
- /**
- * Executes a client-side statement.
- * @param string javascript function name
- * @param array list of arguments for the function
- */
- public function callClientFunction($function, $params=null)
- {
- if(!is_array($params))
- $params = array($params);
-
- if(count($params) > 0)
- {
- if($params[0] instanceof TControl)
- $params[0] = $params[0]->getClientID();
- }
- $this->_actions->add(array($function => $params));
- }
-
- /**
- * Client script to set the value of a particular input element.
- * @param TControl control element to set the new value
- * @param string new value
- */
- public function setValue($input, $text)
- {
- $this->callClientFunction('Prado.Element.setValue', array($input, $text));
- }
-
- /**
- * Client script to select/clear/check a drop down list, check box list,
- * or radio button list.
- * The second parameter determines the selection method. Valid methods are
- * - <b>Value</b>, select or check by value
- * - <b>Values</b>, select or check by a list of values
- * - <b>Index</b>, select or check by index (zero based index)
- * - <b>Indices</b>, select or check by a list of index (zero based index)
- * - <b>Clear</b>, clears or selections or checks in the list
- * - <b>All</b>, select all
- * - <b>Invert</b>, invert the selection.
- * @param TControl list control
- * @param string selection method
- * @param string|int the value or index to select/check.
- * @param string selection control type, either 'check' or 'select'
- */
- public function select($control, $method='Value', $value=null, $type=null)
- {
- $method = TPropertyValue::ensureEnum($method,
- 'Value', 'Index', 'Clear', 'Indices', 'Values', 'All', 'Invert');
- $type = ($type===null) ? $this->getSelectionControlType($control) : $type;
- $total = $this->getSelectionControlIsListType($control) ? $control->getItemCount() : 1;
- $this->callClientFunction('Prado.Element.select',
- array($control, $type.$method, $value, $total));
- }
-
- private function getSelectionControlType($control)
- {
- if(is_string($control)) return 'check';
- if($control instanceof TCheckBoxList)
- return 'check';
- if($control instanceof TCheckBox)
- return 'check';
- return 'select';
- }
-
- private function getSelectionControlIsListType($control)
- {
- return $control instanceof TListControl;
- }
-
- /**
- * Client script to click on an element. <b>This client-side function is unpredictable.</b>
- *
- * @param TControl control element or element id
- */
- public function click($control)
- {
- $this->callClientFunction('Prado.Element.click', $control);
- }
-
- /**
- * Client script to check or uncheck a checkbox or radio button.
- * @param TControl control element or element id
- * @param boolean check or uncheck the checkbox or radio button.
- */
- public function check($checkbox, $checked=true)
- {
- $this->select($checkbox, "Value", $checked);
- }
-
- /**
- * Raise the client side event (given by $eventName) on a particular element.
- * @param TControl control element or element id
- * @param string Event name, e.g. "click"
- */
- public function raiseClientEvent($control, $eventName)
- {
- $this->callClientFunction('Event.fireEvent',
- array($control, strtolower($eventName)));
- }
-
- /**
- * Sets the attribute of a particular control.
- * @param TControl control element or element id
- * @param string attribute name
- * @param string attribute value
- */
- public function setAttribute($control, $name, $value)
- {
- // Attributes should be applied on Surrounding tag, except for 'disabled' attribute
- if ($control instanceof ISurroundable && strtolower($name)!=='disabled')
- $control=$control->getSurroundingTagID();
- $this->callClientFunction('Prado.Element.setAttribute',array($control, $name, $value));
- }
-
- /**
- * Sets the options of a select input element.
- * @param TControl control element or element id
- * @param TCollection a list of new options
- */
- public function setListItems($control, $items)
- {
- $options = array();
- if($control instanceof TListControl)
- {
- $promptText = $control->getPromptText();
- $promptValue = $control->getPromptValue();
-
- if($promptValue==='')
- $promptValue = $promptText;
-
- if($promptValue!=='')
- $options[] = array($promptText, $promptValue);
- }
-
- foreach($items as $item)
- {
- if($item->getHasAttributes())
- $options[] = array($item->getText(),$item->getValue(), $item->getAttributes()->itemAt('Group'));
- else
- $options[] = array($item->getText(),$item->getValue());
- }
- $this->callClientFunction('Prado.Element.setOptions', array($control, $options));
- }
-
- /**
- * Shows an element by changing its CSS display style as empty.
- * @param TControl control element or element id
- */
- public function show($element)
- {
- if ($element instanceof ISurroundable)
- $element=$element->getSurroundingTagID();
- $this->callClientFunction('Element.show', $element);
- }
-
- /**
- * Hides an element by changing its CSS display style to "none".
- * @param TControl control element or element id
- */
- public function hide($element)
- {
- if ($element instanceof ISurroundable)
- $element=$element->getSurroundingTagID();
- $this->callClientFunction('Element.hide', $element);
- }
-
- /**
- * Toggles the visibility of the element.
- * @param TControl control element or element id
- * @param string visual effect, such as, 'appear' or 'slide' or 'blind'.
- * @param array additional options.
- */
- public function toggle($element, $effect=null, $options=array())
- {
- if ($element instanceof ISurroundable)
- $element=$element->getSurroundingTagID();
- $this->callClientFunction('Element.toggle', array($element,$effect,$options));
- }
-
- /**
- * Removes an element from the HTML page.
- * @param TControl control element or element id
- */
- public function remove($element)
- {
- if ($element instanceof ISurroundable)
- $element=$element->getSurroundingTagID();
- $this->callClientFunction('Element.remove', $element);
- }
-
- public function addPostDataLoader($name)
- {
- $this->callClientFunction('Prado.CallbackRequest.addPostLoaders', $name);
- }
-
- /**
- * Update the element's innerHTML with new content.
- * @param TControl control element or element id
- * @param TControl new HTML content, if content is of a TControl, the
- * controls render method is called.
- */
- public function update($element, $content)
- {
- if ($element instanceof ISurroundable)
- $element=$element->getSurroundingTagID();
- $this->replace($element, $content, 'Element.update');
- }
-
- /**
- * Add a Css class name to the element.
- * @param TControl control element or element id
- * @param string CssClass name to add.
- */
- public function addCssClass($element, $cssClass)
- {
- if ($element instanceof ISurroundable)
- $element=$element->getSurroundingTagID();
- $this->callClientFunction('Element.addClassName', array($element, $cssClass));
- }
-
- /**
- * Remove a Css class name from the element.
- * @param TControl control element or element id
- * @param string CssClass name to remove.
- */
- public function removeCssClass($element, $cssClass)
- {
- if ($element instanceof ISurroundable)
- $element=$element->getSurroundingTagID();
- $this->callClientFunction('Element.removeClassName', array($element, $cssClass));
- }
-
- /**
- * Sets the CssClass of an element.
- * @param TControl control element or element id
- * @param string new CssClass name for the element.
- */
- /*public function setCssClass($element, $cssClass)
- {
- $this->callClientFunction('Prado.Element.CssClass.set', array($element, $cssClass));
- }*/
-
- /**
- * Scroll the top of the browser viewing area to the location of the
- * element.
- * @param TControl control element or element id
- */
- public function scrollTo($element)
- {
- if ($element instanceof ISurroundable)
- $element=$element->getSurroundingTagID();
- $this->callClientFunction('Element.scrollTo', $element);
- }
-
- /**
- * Focus on a particular element.
- * @param TControl control element or element id.
- */
- public function focus($element)
- {
- $this->callClientFunction('Prado.Element.focus', $element);
- }
-
- /**
- * Sets the style of element. The style must be a key-value array where the
- * key is the style property and the value is the style value.
- * @param TControl control element or element id
- * @param array list of key-value pairs as style property and style value.
- */
- public function setStyle($element, $styles)
- {
- if ($element instanceof ISurroundable)
- $element=$element->getSurroundingTagID();
- $this->callClientFunction('Prado.Element.setStyle', array($element, $styles));
- }
-
- /**
- * Append a HTML fragement to the element.
- * @param TControl control element or element id
- * @param string HTML fragement or the control to be rendered
- */
- public function appendContent($element, $content)
- {
- if ($element instanceof ISurroundable)
- $element=$element->getSurroundingTagID();
- $this->replace($element, $content, 'Prado.Element.Insert.append');
- }
-
- /**
- * Prepend a HTML fragement to the element.
- * @param TControl control element or element id
- * @param string HTML fragement or the control to be rendered
- */
- public function prependContent($element, $content)
- {
- if ($element instanceof ISurroundable)
- $element=$element->getSurroundingTagID();
- $this->replace($element, $content, 'Prado.Element.Insert.prepend');
- }
-
- /**
- * Insert a HTML fragement after the element.
- * @param TControl control element or element id
- * @param string HTML fragement or the control to be rendered
- */
- public function insertContentAfter($element, $content)
- {
- if ($element instanceof ISurroundable)
- $element=$element->getSurroundingTagID();
- $this->replace($element, $content, 'Prado.Element.Insert.after');
- }
-
- /**
- * Insert a HTML fragement in before the element.
- * @param TControl control element or element id
- * @param string HTML fragement or the control to be rendered
- */
- public function insertContentBefore($element, $content)
- {
- if ($element instanceof ISurroundable)
- $element=$element->getSurroundingTagID();
- $this->replace($element, $content, 'Prado.Element.Insert.before');
- }
-
- /**
- * Replace the content of an element with new content. The new content can
- * be a string or a TControl component. If the <tt>content</tt> parameter is
- * a TControl component, its rendered method will be called and its contents
- * will be used for replacement.
- * @param TControl control element or HTML element id.
- * @param string HTML fragement or the control to be rendered
- * @param string replacement method, default is to replace the outter
- * html content.
- * @param string provide a custom boundary.
- * @see insertAbout
- * @see insertBelow
- * @see insertBefore
- * @see insertAfter
- */
- protected function replace($element, $content, $method="Element.replace", $boundary=null)
- {
- if($content instanceof TControl)
- {
- $boundary = $this->getRenderedContentBoundary($content);
- $content = null;
- }
- else if($content instanceof THtmlWriter)
- {
- $boundary = $this->getResponseContentBoundary($content);
- $content = null;
- }
-
- $this->callClientFunction('Prado.Element.replace',
- array($element, $method, $content, $boundary));
- }
-
- /**
- * Replace the content of an element with new content contained in writer.
- * @param TControl control element or HTML element id.
- * @param string HTML fragement or the control to be rendered
- */
- public function replaceContent($element,$content)
- {
- if ($element instanceof ISurroundable)
- $element=$element->getSurroundingTagID();
- $this->replace($element, $content);
- }
-
- /**
- * Evaluate a block of javascript enclosed in a boundary.
- * @param THtmlWriter writer for the content.
- */
- public function evaluateScript($writer)
- {
- $this->replace(null, $writer, 'Prado.Element.evaluateScript');
- }
-
- /**
- * Appends a block of inline javascript enclosed in a boundary.
- * Similar to to evaluateScript(), but functions declared in the
- * inline block will be available to page elements.
- * @param THtmlWriter writer for the content.
- */
- public function appendScriptBlock($content)
- {
- if($content instanceof TControl)
- {
- $boundary = $this->getRenderedContentBoundary($content);
- }
- else if($content instanceof THtmlWriter)
- {
- $boundary = $this->getResponseContentBoundary($content);
- }
-
- $this->callClientFunction('Prado.Element.appendScriptBlock', array($boundary));
- }
-
- /**
- * Renders the control and return the content boundary from
- * TCallbackResponseWriter. This method should only be used by framework
- * component developers. The render() method is defered to be called in the
- * TActivePageAdapter class.
- * @param TControl control to be rendered on callback response.
- * @return string the boundary for which the rendered content is wrapped.
- */
- private function getRenderedContentBoundary($control)
- {
- $writer = $this->getResponse()->createHtmlWriter();
- $adapter = $control->getPage()->getAdapter();
- $adapter->registerControlToRender($control, $writer);
- return $writer->getWriter()->getBoundary();
- }
-
- /**
- * @param THtmlWriter the writer responsible for rendering html content.
- * @return string content boundary.
- */
- private function getResponseContentBoundary($html)
- {
- if($html instanceof THtmlWriter)
- {
- if($html->getWriter() instanceof TCallbackResponseWriter)
- return $html->getWriter()->getBoundary();
- }
- return null;
- }
-
- /**
- * Add a visual effect the element.
- * @param string visual effect function name.
- * @param TControl control element or element id
- * @param array visual effect key-value pair options.
- */
- public function visualEffect($type, $element, $options=null)
- {
- if ($element instanceof ISurroundable)
- $element=$element->getSurroundingTagID();
- $this->callClientFunction($type, array($element, $options));
- }
-
- /**
- * Visual Effect: Gradually make the element appear.
- * @param TControl control element or element id
- * @param array visual effect key-value pair options.
- */
- public function appear($element, $options=null)
- {
- if ($element instanceof ISurroundable)
- $element=$element->getSurroundingTagID();
- $this->visualEffect('Effect.Appear', $element, $options);
- }
-
- /**
- * Visual Effect: Blind down.
- * @param TControl control element or element id
- * @param array visual effect key-value pair options.
- */
- public function blindDown($element, $options=null)
- {
- if ($element instanceof ISurroundable)
- $element=$element->getSurroundingTagID();
- $this->visualEffect('Effect.BlindDown', $element, $options);
- }
-
- /**
- * Visual Effect: Blind up.
- * @param TControl control element or element id
- * @param array visual effect key-value pair options.
- */
- public function blindUp($element, $options=null)
- {
- if ($element instanceof ISurroundable)
- $element=$element->getSurroundingTagID();
- $this->visualEffect('Effect.BlindUp', $element, $options);
-
- }
-
- /**
- * Visual Effect: Drop out.
- * @param TControl control element or element id
- * @param array visual effect key-value pair options.
- */
- public function dropOut($element, $options=null)
- {
- if ($element instanceof ISurroundable)
- $element=$element->getSurroundingTagID();
- $this->visualEffect('Effect.DropOut', $element, $options);
- }
-
- /**
- * Visual Effect: Gradually fade the element.
- * @param TControl control element or element id
- * @param array visual effect key-value pair options.
- */
- public function fade($element, $options=null)
- {
- if ($element instanceof ISurroundable)
- $element=$element->getSurroundingTagID();
- $this->visualEffect('Effect.Fade', $element, $options);
- }
-
- /**
- * Visual Effect: Fold.
- * @param TControl control element or element id
- * @param array visual effect key-value pair options.
- */
- public function fold($element, $options = null)
- {
- if ($element instanceof ISurroundable)
- $element=$element->getSurroundingTagID();
- $this->visualEffect('Effect.Fold', $element, $options);
- }
-
- /**
- * Visual Effect: Gradually make an element grow to a predetermined size.
- * @param TControl control element or element id
- * @param array visual effect key-value pair options.
- */
- public function grow($element, $options=null)
- {
- if ($element instanceof ISurroundable)
- $element=$element->getSurroundingTagID();
- $this->visualEffect('Effect.Grow', $element, $options);
- }
-
- /**
- * Visual Effect: Gradually grow and fade the element.
- * @param TControl control element or element id
- * @param array visual effect key-value pair options.
- */
- public function puff($element, $options=null)
- {
- if ($element instanceof ISurroundable)
- $element=$element->getSurroundingTagID();
- $this->visualEffect('Effect.Puff', $element, $options);
- }
-
- /**
- * Visual Effect: Pulsate.
- * @param TControl control element or element id
- * @param array visual effect key-value pair options.
- */
- public function pulsate($element, $options=null)
- {
- if ($element instanceof ISurroundable)
- $element=$element->getSurroundingTagID();
- $this->visualEffect('Effect.Pulsate', $element, $options);
- }
-
- /**
- * Visual Effect: Shake the element.
- * @param TControl control element or element id
- * @param array visual effect key-value pair options.
- */
- public function shake($element, $options=null)
- {
- if ($element instanceof ISurroundable)
- $element=$element->getSurroundingTagID();
- $this->visualEffect('Effect.Shake', $element, $options);
- }
-
- /**
- * Visual Effect: Shrink the element.
- * @param TControl control element or element id
- * @param array visual effect key-value pair options.
- */
- public function shrink($element, $options=null)
- {
- if ($element instanceof ISurroundable)
- $element=$element->getSurroundingTagID();
- $this->visualEffect('Effect.Shrink', $element, $options);
- }
-
- /**
- * Visual Effect: Slide down.
- * @param TControl control element or element id
- * @param array visual effect key-value pair options.
- */
- public function slideDown($element, $options=null)
- {
- if ($element instanceof ISurroundable)
- $element=$element->getSurroundingTagID();
- $this->visualEffect('Effect.SlideDown', $element, $options);
- }
-
- /**
- * Visual Effect: Side up.
- * @param TControl control element or element id
- * @param array visual effect key-value pair options.
- */
- public function slideUp($element, $options=null)
- {
- if ($element instanceof ISurroundable)
- $element=$element->getSurroundingTagID();
- $this->visualEffect('Effect.SlideUp', $element, $options);
- }
-
- /**
- * Visual Effect: Squish the element.
- * @param TControl control element or element id
- * @param array visual effect key-value pair options.
- */
- public function squish($element, $options=null)
- {
- if ($element instanceof ISurroundable)
- $element=$element->getSurroundingTagID();
- $this->visualEffect('Effect.Squish', $element, $options);
- }
-
- /**
- * Visual Effect: Switch Off effect.
- * @param TControl control element or element id
- * @param array visual effect key-value pair options.
- */
- public function switchOff($element, $options=null)
- {
- if ($element instanceof ISurroundable)
- $element=$element->getSurroundingTagID();
- $this->visualEffect('Effect.SwitchOff', $element, $options);
- }
-
- /**
- * Visual Effect: High light the element for about 2 seconds.
- * @param TControl control element or element id
- * @param array visual effect key-value pair options.
- */
- public function highlight($element, $options=null)
- {
- if ($element instanceof ISurroundable)
- $element=$element->getSurroundingTagID();
- $this->visualEffect('Prado.Effect.Highlight', $element, $options);
- }
-
- /**
- * Set the opacity on a html element or control.
- * @param TControl control element or element id
- * @param float opacity value between 1 and 0
- */
- public function setOpacity($element, $value)
- {
- if ($element instanceof ISurroundable)
- $element=$element->getSurroundingTagID();
- $value = TPropertyValue::ensureFloat($value);
- $this->callClientFunction('Element.setOpacity', array($element,$value));
- }
-}
-
+<?php
+/**
+ * TCallbackClientScript class file
+ *
+ * @author Wei Zhuo <weizhuo[at]gamil[dot]com>
+ * @link http://www.pradosoft.com/
+ * @copyright Copyright &copy; 2005-2012 PradoSoft
+ * @license http://www.pradosoft.com/license/
+ * @version $Id$
+ * @package System.Web.UI.ActiveControls
+ */
+
+/**
+ * TCallbackClientScript class.
+ *
+ * The TCallbackClientScript class provides corresponding methods that can be
+ * executed on the client-side (i.e. the browser client that is viewing
+ * the page) during a callback response.
+ *
+ * The avaiable methods includes setting/clicking input elements, changing Css
+ * styles, hiding/showing elements, and adding visual effects to elements on the
+ * page. The client-side methods can be access through the CallbackClient
+ * property available in TPage.
+ *
+ * For example, to hide "$myTextBox" element during callback response, do
+ * <code>
+ * $this->getPage()->getCallbackClient()->hide($myTextBox);
+ * </code>
+ *
+ * @author Wei Zhuo <weizhuo[at]gamil[dot]com>
+ * @version $Id$
+ * @package System.Web.UI.ActiveControls
+ * @since 3.1
+ */
+class TCallbackClientScript extends TApplicationComponent
+{
+ /**
+ * @var TList list of client functions to execute.
+ */
+ private $_actions;
+
+ /**
+ * Constructor.
+ */
+ public function __construct()
+ {
+ $this->_actions = new TList;
+ }
+
+ /**
+ * @return array list of client function to be executed during callback
+ * response.
+ */
+ public function getClientFunctionsToExecute()
+ {
+ return $this->_actions->toArray();
+ }
+
+ /**
+ * Executes a client-side statement.
+ * @param string javascript function name
+ * @param array list of arguments for the function
+ */
+ public function callClientFunction($function, $params=null)
+ {
+ if(!is_array($params))
+ $params = array($params);
+
+ if(count($params) > 0)
+ {
+ if($params[0] instanceof TControl)
+ $params[0] = $params[0]->getClientID();
+ }
+ $this->_actions->add(array($function => $params));
+ }
+
+ /**
+ * Client script to set the value of a particular input element.
+ * @param TControl control element to set the new value
+ * @param string new value
+ */
+ public function setValue($input, $text)
+ {
+ $this->callClientFunction('Prado.Element.setValue', array($input, $text));
+ }
+
+ /**
+ * Client script to select/clear/check a drop down list, check box list,
+ * or radio button list.
+ * The second parameter determines the selection method. Valid methods are
+ * - <b>Value</b>, select or check by value
+ * - <b>Values</b>, select or check by a list of values
+ * - <b>Index</b>, select or check by index (zero based index)
+ * - <b>Indices</b>, select or check by a list of index (zero based index)
+ * - <b>Clear</b>, clears or selections or checks in the list
+ * - <b>All</b>, select all
+ * - <b>Invert</b>, invert the selection.
+ * @param TControl list control
+ * @param string selection method
+ * @param string|int the value or index to select/check.
+ * @param string selection control type, either 'check' or 'select'
+ */
+ public function select($control, $method='Value', $value=null, $type=null)
+ {
+ $method = TPropertyValue::ensureEnum($method,
+ 'Value', 'Index', 'Clear', 'Indices', 'Values', 'All', 'Invert');
+ $type = ($type===null) ? $this->getSelectionControlType($control) : $type;
+ $total = $this->getSelectionControlIsListType($control) ? $control->getItemCount() : 1;
+ $this->callClientFunction('Prado.Element.select',
+ array($control, $type.$method, $value, $total));
+ }
+
+ private function getSelectionControlType($control)
+ {
+ if(is_string($control)) return 'check';
+ if($control instanceof TCheckBoxList)
+ return 'check';
+ if($control instanceof TCheckBox)
+ return 'check';
+ return 'select';
+ }
+
+ private function getSelectionControlIsListType($control)
+ {
+ return $control instanceof TListControl;
+ }
+
+ /**
+ * Client script to click on an element. <b>This client-side function is unpredictable.</b>
+ *
+ * @param TControl control element or element id
+ */
+ public function click($control)
+ {
+ $this->callClientFunction('Prado.Element.click', $control);
+ }
+
+ /**
+ * Client script to check or uncheck a checkbox or radio button.
+ * @param TControl control element or element id
+ * @param boolean check or uncheck the checkbox or radio button.
+ */
+ public function check($checkbox, $checked=true)
+ {
+ $this->select($checkbox, "Value", $checked);
+ }
+
+ /**
+ * Raise the client side event (given by $eventName) on a particular element.
+ * @param TControl control element or element id
+ * @param string Event name, e.g. "click"
+ */
+ public function raiseClientEvent($control, $eventName)
+ {
+ $this->callClientFunction('Event.fireEvent',
+ array($control, strtolower($eventName)));
+ }
+
+ /**
+ * Sets the attribute of a particular control.
+ * @param TControl control element or element id
+ * @param string attribute name
+ * @param string attribute value
+ */
+ public function setAttribute($control, $name, $value)
+ {
+ // Attributes should be applied on Surrounding tag, except for 'disabled' attribute
+ if ($control instanceof ISurroundable && strtolower($name)!=='disabled')
+ $control=$control->getSurroundingTagID();
+ $this->callClientFunction('Prado.Element.setAttribute',array($control, $name, $value));
+ }
+
+ /**
+ * Sets the options of a select input element.
+ * @param TControl control element or element id
+ * @param TCollection a list of new options
+ */
+ public function setListItems($control, $items)
+ {
+ $options = array();
+ if($control instanceof TListControl)
+ {
+ $promptText = $control->getPromptText();
+ $promptValue = $control->getPromptValue();
+
+ if($promptValue==='')
+ $promptValue = $promptText;
+
+ if($promptValue!=='')
+ $options[] = array($promptText, $promptValue);
+ }
+
+ foreach($items as $item)
+ {
+ if($item->getHasAttributes())
+ $options[] = array($item->getText(),$item->getValue(), $item->getAttributes()->itemAt('Group'));
+ else
+ $options[] = array($item->getText(),$item->getValue());
+ }
+ $this->callClientFunction('Prado.Element.setOptions', array($control, $options));
+ }
+
+ /**
+ * Shows an element by changing its CSS display style as empty.
+ * @param TControl control element or element id
+ */
+ public function show($element)
+ {
+ if ($element instanceof ISurroundable)
+ $element=$element->getSurroundingTagID();
+ $this->callClientFunction('Element.show', $element);
+ }
+
+ /**
+ * Hides an element by changing its CSS display style to "none".
+ * @param TControl control element or element id
+ */
+ public function hide($element)
+ {
+ if ($element instanceof ISurroundable)
+ $element=$element->getSurroundingTagID();
+ $this->callClientFunction('Element.hide', $element);
+ }
+
+ /**
+ * Toggles the visibility of the element.
+ * @param TControl control element or element id
+ * @param string visual effect, such as, 'appear' or 'slide' or 'blind'.
+ * @param array additional options.
+ */
+ public function toggle($element, $effect=null, $options=array())
+ {
+ if ($element instanceof ISurroundable)
+ $element=$element->getSurroundingTagID();
+ $this->callClientFunction('Element.toggle', array($element,$effect,$options));
+ }
+
+ /**
+ * Removes an element from the HTML page.
+ * @param TControl control element or element id
+ */
+ public function remove($element)
+ {
+ if ($element instanceof ISurroundable)
+ $element=$element->getSurroundingTagID();
+ $this->callClientFunction('Element.remove', $element);
+ }
+
+ public function addPostDataLoader($name)
+ {
+ $this->callClientFunction('Prado.CallbackRequest.addPostLoaders', $name);
+ }
+
+ /**
+ * Update the element's innerHTML with new content.
+ * @param TControl control element or element id
+ * @param TControl new HTML content, if content is of a TControl, the
+ * controls render method is called.
+ */
+ public function update($element, $content)
+ {
+ if ($element instanceof ISurroundable)
+ $element=$element->getSurroundingTagID();
+ $this->replace($element, $content, 'Element.update');
+ }
+
+ /**
+ * Add a Css class name to the element.
+ * @param TControl control element or element id
+ * @param string CssClass name to add.
+ */
+ public function addCssClass($element, $cssClass)
+ {
+ if ($element instanceof ISurroundable)
+ $element=$element->getSurroundingTagID();
+ $this->callClientFunction('Element.addClassName', array($element, $cssClass));
+ }
+
+ /**
+ * Remove a Css class name from the element.
+ * @param TControl control element or element id
+ * @param string CssClass name to remove.
+ */
+ public function removeCssClass($element, $cssClass)
+ {
+ if ($element instanceof ISurroundable)
+ $element=$element->getSurroundingTagID();
+ $this->callClientFunction('Element.removeClassName', array($element, $cssClass));
+ }
+
+ /**
+ * Sets the CssClass of an element.
+ * @param TControl control element or element id
+ * @param string new CssClass name for the element.
+ */
+ /*public function setCssClass($element, $cssClass)
+ {
+ $this->callClientFunction('Prado.Element.CssClass.set', array($element, $cssClass));
+ }*/
+
+ /**
+ * Scroll the top of the browser viewing area to the location of the
+ * element.
+ * @param TControl control element or element id
+ */
+ public function scrollTo($element)
+ {
+ if ($element instanceof ISurroundable)
+ $element=$element->getSurroundingTagID();
+ $this->callClientFunction('Element.scrollTo', $element);
+ }
+
+ /**
+ * Focus on a particular element.
+ * @param TControl control element or element id.
+ */
+ public function focus($element)
+ {
+ $this->callClientFunction('Prado.Element.focus', $element);
+ }
+
+ /**
+ * Sets the style of element. The style must be a key-value array where the
+ * key is the style property and the value is the style value.
+ * @param TControl control element or element id
+ * @param array list of key-value pairs as style property and style value.
+ */
+ public function setStyle($element, $styles)
+ {
+ if ($element instanceof ISurroundable)
+ $element=$element->getSurroundingTagID();
+ $this->callClientFunction('Prado.Element.setStyle', array($element, $styles));
+ }
+
+ /**
+ * Append a HTML fragement to the element.
+ * @param TControl control element or element id
+ * @param string HTML fragement or the control to be rendered
+ */
+ public function appendContent($element, $content)
+ {
+ if ($element instanceof ISurroundable)
+ $element=$element->getSurroundingTagID();
+ $this->replace($element, $content, 'Prado.Element.Insert.append');
+ }
+
+ /**
+ * Prepend a HTML fragement to the element.
+ * @param TControl control element or element id
+ * @param string HTML fragement or the control to be rendered
+ */
+ public function prependContent($element, $content)
+ {
+ if ($element instanceof ISurroundable)
+ $element=$element->getSurroundingTagID();
+ $this->replace($element, $content, 'Prado.Element.Insert.prepend');
+ }
+
+ /**
+ * Insert a HTML fragement after the element.
+ * @param TControl control element or element id
+ * @param string HTML fragement or the control to be rendered
+ */
+ public function insertContentAfter($element, $content)
+ {
+ if ($element instanceof ISurroundable)
+ $element=$element->getSurroundingTagID();
+ $this->replace($element, $content, 'Prado.Element.Insert.after');
+ }
+
+ /**
+ * Insert a HTML fragement in before the element.
+ * @param TControl control element or element id
+ * @param string HTML fragement or the control to be rendered
+ */
+ public function insertContentBefore($element, $content)
+ {
+ if ($element instanceof ISurroundable)
+ $element=$element->getSurroundingTagID();
+ $this->replace($element, $content, 'Prado.Element.Insert.before');
+ }
+
+ /**
+ * Replace the content of an element with new content. The new content can
+ * be a string or a TControl component. If the <tt>content</tt> parameter is
+ * a TControl component, its rendered method will be called and its contents
+ * will be used for replacement.
+ * @param TControl control element or HTML element id.
+ * @param string HTML fragement or the control to be rendered
+ * @param string replacement method, default is to replace the outter
+ * html content.
+ * @param string provide a custom boundary.
+ * @see insertAbout
+ * @see insertBelow
+ * @see insertBefore
+ * @see insertAfter
+ */
+ protected function replace($element, $content, $method="Element.replace", $boundary=null)
+ {
+ if($content instanceof TControl)
+ {
+ $boundary = $this->getRenderedContentBoundary($content);
+ $content = null;
+ }
+ else if($content instanceof THtmlWriter)
+ {
+ $boundary = $this->getResponseContentBoundary($content);
+ $content = null;
+ }
+
+ $this->callClientFunction('Prado.Element.replace',
+ array($element, $method, $content, $boundary));
+ }
+
+ /**
+ * Replace the content of an element with new content contained in writer.
+ * @param TControl control element or HTML element id.
+ * @param string HTML fragement or the control to be rendered
+ */
+ public function replaceContent($element,$content)
+ {
+ if ($element instanceof ISurroundable)
+ $element=$element->getSurroundingTagID();
+ $this->replace($element, $content);
+ }
+
+ /**
+ * Evaluate a block of javascript enclosed in a boundary.
+ * @param THtmlWriter writer for the content.
+ */
+ public function evaluateScript($writer)
+ {
+ $this->replace(null, $writer, 'Prado.Element.evaluateScript');
+ }
+
+ /**
+ * Appends a block of inline javascript enclosed in a boundary.
+ * Similar to to evaluateScript(), but functions declared in the
+ * inline block will be available to page elements.
+ * @param THtmlWriter writer for the content.
+ */
+ public function appendScriptBlock($content)
+ {
+ if($content instanceof TControl)
+ {
+ $boundary = $this->getRenderedContentBoundary($content);
+ }
+ else if($content instanceof THtmlWriter)
+ {
+ $boundary = $this->getResponseContentBoundary($content);
+ }
+
+ $this->callClientFunction('Prado.Element.appendScriptBlock', array($boundary));
+ }
+
+ /**
+ * Renders the control and return the content boundary from
+ * TCallbackResponseWriter. This method should only be used by framework
+ * component developers. The render() method is defered to be called in the
+ * TActivePageAdapter class.
+ * @param TControl control to be rendered on callback response.
+ * @return string the boundary for which the rendered content is wrapped.
+ */
+ private function getRenderedContentBoundary($control)
+ {
+ $writer = $this->getResponse()->createHtmlWriter();
+ $adapter = $control->getPage()->getAdapter();
+ $adapter->registerControlToRender($control, $writer);
+ return $writer->getWriter()->getBoundary();
+ }
+
+ /**
+ * @param THtmlWriter the writer responsible for rendering html content.
+ * @return string content boundary.
+ */
+ private function getResponseContentBoundary($html)
+ {
+ if($html instanceof THtmlWriter)
+ {
+ if($html->getWriter() instanceof TCallbackResponseWriter)
+ return $html->getWriter()->getBoundary();
+ }
+ return null;
+ }
+
+ /**
+ * Add a visual effect the element.
+ * @param string visual effect function name.
+ * @param TControl control element or element id
+ * @param array visual effect key-value pair options.
+ */
+ public function visualEffect($type, $element, $options=null)
+ {
+ if ($element instanceof ISurroundable)
+ $element=$element->getSurroundingTagID();
+ $this->callClientFunction($type, array($element, $options));
+ }
+
+ /**
+ * Visual Effect: Gradually make the element appear.
+ * @param TControl control element or element id
+ * @param array visual effect key-value pair options.
+ */
+ public function appear($element, $options=null)
+ {
+ if ($element instanceof ISurroundable)
+ $element=$element->getSurroundingTagID();
+ $this->visualEffect('Effect.Appear', $element, $options);
+ }
+
+ /**
+ * Visual Effect: Blind down.
+ * @param TControl control element or element id
+ * @param array visual effect key-value pair options.
+ */
+ public function blindDown($element, $options=null)
+ {
+ if ($element instanceof ISurroundable)
+ $element=$element->getSurroundingTagID();
+ $this->visualEffect('Effect.BlindDown', $element, $options);
+ }
+
+ /**
+ * Visual Effect: Blind up.
+ * @param TControl control element or element id
+ * @param array visual effect key-value pair options.
+ */
+ public function blindUp($element, $options=null)
+ {
+ if ($element instanceof ISurroundable)
+ $element=$element->getSurroundingTagID();
+ $this->visualEffect('Effect.BlindUp', $element, $options);
+
+ }
+
+ /**
+ * Visual Effect: Drop out.
+ * @param TControl control element or element id
+ * @param array visual effect key-value pair options.
+ */
+ public function dropOut($element, $options=null)
+ {
+ if ($element instanceof ISurroundable)
+ $element=$element->getSurroundingTagID();
+ $this->visualEffect('Effect.DropOut', $element, $options);
+ }
+
+ /**
+ * Visual Effect: Gradually fade the element.
+ * @param TControl control element or element id
+ * @param array visual effect key-value pair options.
+ */
+ public function fade($element, $options=null)
+ {
+ if ($element instanceof ISurroundable)
+ $element=$element->getSurroundingTagID();
+ $this->visualEffect('Effect.Fade', $element, $options);
+ }
+
+ /**
+ * Visual Effect: Fold.
+ * @param TControl control element or element id
+ * @param array visual effect key-value pair options.
+ */
+ public function fold($element, $options = null)
+ {
+ if ($element instanceof ISurroundable)
+ $element=$element->getSurroundingTagID();
+ $this->visualEffect('Effect.Fold', $element, $options);
+ }
+
+ /**
+ * Visual Effect: Gradually make an element grow to a predetermined size.
+ * @param TControl control element or element id
+ * @param array visual effect key-value pair options.
+ */
+ public function grow($element, $options=null)
+ {
+ if ($element instanceof ISurroundable)
+ $element=$element->getSurroundingTagID();
+ $this->visualEffect('Effect.Grow', $element, $options);
+ }
+
+ /**
+ * Visual Effect: Gradually grow and fade the element.
+ * @param TControl control element or element id
+ * @param array visual effect key-value pair options.
+ */
+ public function puff($element, $options=null)
+ {
+ if ($element instanceof ISurroundable)
+ $element=$element->getSurroundingTagID();
+ $this->visualEffect('Effect.Puff', $element, $options);
+ }
+
+ /**
+ * Visual Effect: Pulsate.
+ * @param TControl control element or element id
+ * @param array visual effect key-value pair options.
+ */
+ public function pulsate($element, $options=null)
+ {
+ if ($element instanceof ISurroundable)
+ $element=$element->getSurroundingTagID();
+ $this->visualEffect('Effect.Pulsate', $element, $options);
+ }
+
+ /**
+ * Visual Effect: Shake the element.
+ * @param TControl control element or element id
+ * @param array visual effect key-value pair options.
+ */
+ public function shake($element, $options=null)
+ {
+ if ($element instanceof ISurroundable)
+ $element=$element->getSurroundingTagID();
+ $this->visualEffect('Effect.Shake', $element, $options);
+ }
+
+ /**
+ * Visual Effect: Shrink the element.
+ * @param TControl control element or element id
+ * @param array visual effect key-value pair options.
+ */
+ public function shrink($element, $options=null)
+ {
+ if ($element instanceof ISurroundable)
+ $element=$element->getSurroundingTagID();
+ $this->visualEffect('Effect.Shrink', $element, $options);
+ }
+
+ /**
+ * Visual Effect: Slide down.
+ * @param TControl control element or element id
+ * @param array visual effect key-value pair options.
+ */
+ public function slideDown($element, $options=null)
+ {
+ if ($element instanceof ISurroundable)
+ $element=$element->getSurroundingTagID();
+ $this->visualEffect('Effect.SlideDown', $element, $options);
+ }
+
+ /**
+ * Visual Effect: Side up.
+ * @param TControl control element or element id
+ * @param array visual effect key-value pair options.
+ */
+ public function slideUp($element, $options=null)
+ {
+ if ($element instanceof ISurroundable)
+ $element=$element->getSurroundingTagID();
+ $this->visualEffect('Effect.SlideUp', $element, $options);
+ }
+
+ /**
+ * Visual Effect: Squish the element.
+ * @param TControl control element or element id
+ * @param array visual effect key-value pair options.
+ */
+ public function squish($element, $options=null)
+ {
+ if ($element instanceof ISurroundable)
+ $element=$element->getSurroundingTagID();
+ $this->visualEffect('Effect.Squish', $element, $options);
+ }
+
+ /**
+ * Visual Effect: Switch Off effect.
+ * @param TControl control element or element id
+ * @param array visual effect key-value pair options.
+ */
+ public function switchOff($element, $options=null)
+ {
+ if ($element instanceof ISurroundable)
+ $element=$element->getSurroundingTagID();
+ $this->visualEffect('Effect.SwitchOff', $element, $options);
+ }
+
+ /**
+ * Visual Effect: High light the element for about 2 seconds.
+ * @param TControl control element or element id
+ * @param array visual effect key-value pair options.
+ */
+ public function highlight($element, $options=null)
+ {
+ if ($element instanceof ISurroundable)
+ $element=$element->getSurroundingTagID();
+ $this->visualEffect('Prado.Effect.Highlight', $element, $options);
+ }
+
+ /**
+ * Set the opacity on a html element or control.
+ * @param TControl control element or element id
+ * @param float opacity value between 1 and 0
+ */
+ public function setOpacity($element, $value)
+ {
+ if ($element instanceof ISurroundable)
+ $element=$element->getSurroundingTagID();
+ $value = TPropertyValue::ensureFloat($value);
+ $this->callClientFunction('Element.setOpacity', array($element,$value));
+ }
+}
+
diff --git a/framework/Web/UI/ActiveControls/TCallbackClientSide.php b/framework/Web/UI/ActiveControls/TCallbackClientSide.php
index 10231a1c..0d602fa5 100644
--- a/framework/Web/UI/ActiveControls/TCallbackClientSide.php
+++ b/framework/Web/UI/ActiveControls/TCallbackClientSide.php
@@ -1,322 +1,322 @@
-<?php
-/**
- * TCallbackClientSide class file
- *
- * @author Wei Zhuo <weizhuo[at]gamil[dot]com>
- * @link http://www.pradosoft.com/
- * @copyright Copyright &copy; 2005-2012 PradoSoft
- * @license http://www.pradosoft.com/license/
- * @version $Id$
- * @package System.Web.UI.ActiveControls
- */
-
-/**
- * TCallbackClientSide class.
- *
- * The following client side events are executing in order if the callback
- * request and response are send and received successfuly.
- *
- * - <b>onPreDispatch</b> executed before a request is dispatched.
- * - <b>onUninitialized</b> executed when callback request is uninitialized.
- * - <b>onLoading</b>* executed when callback request is initiated
- * - <b>onLoaded</b>* executed when callback request begins.
- * - <b>onInteractive</b> executed when callback request is in progress.
- * - <b>onComplete</b>executed when callback response returns.
- * - <b>onSuccess</b> executed when callback request returns and is successful.
- * - <b>onFailure</b> executed when callback request returns and fails.
- * - <b>onException</b> raised when callback request fails due to request/response errors.
- *
- * * Note that theses 2 events are not fired correctly by Opera. To make
- * them work in this browser, Prado will fire them just after onPreDispatch.
- *
- * In a general way, onUninitialized, onLoading, onLoaded and onInteractive events
- * are not implemented consistently in all browsers.When cross browser compatibility is
- * needed, it is best to avoid use them
- *
- * The OnSuccess and OnFailure events are raised when the
- * response is returned. A successful request/response will raise
- * OnSuccess event otherwise OnFailure will be raised.
- *
- * - <b>PostState</b> true to collect the form inputs and post them during callback, default is true.
- * - <b>RequestTimeOut</b> The request timeout in milliseconds.
- * - <b>HasPriority</b> true to ensure that the callback request will be sent
- * immediately and will abort existing prioritized requests. It does not affect
- * callbacks that are not prioritized.
- * - <b>EnablePageStateUpdate</b> enable the callback response to enable the
- * viewstate update. This will automatically set HasPriority to true when enabled.
- *
- * @author Wei Zhuo <weizhuo[at]gamil[dot]com>
- * @version $Id$
- * @package System.Web.UI.ActiveControls
- * @since 3.1
- */
-class TCallbackClientSide extends TClientSideOptions
-{
- /**
- * Returns javascript statement enclosed within a javascript function.
- * @param string javascript statement
- * @return string javascript statement wrapped in a javascript function
- */
- protected function ensureFunction($javascript)
- {
- return "function(sender, parameter){ {$javascript} }";
- }
-
- /**
- * @param string javascript code to be executed before a request is dispatched.
- */
- public function setOnPreDispatch($javascript)
- {
- $this->setFunction('onPreDispatch', $javascript);
- }
-
- /**
- * @return string javascript code to be executed before a request is dispatched.
- */
- public function getOnPreDispatch()
- {
- return $this->getOption('onPreDispatch');
- }
-
- /**
- * @return string javascript code for client-side onUninitialized event
- */
- public function getOnUninitialized()
- {
- return $this->getOption('onUninitialized');
- }
-
- /**
- * @param string javascript code for client-side onUninitialized event.
- */
- public function setOnUninitialized($javascript)
- {
- $this->setFunction('onUninitialized', $javascript);
- }
-
- /**
- * @return string javascript code for client-side onLoading event
- */
- public function getOnLoading()
- {
- return $this->getOption('onLoading');
- }
-
- /**
- * @param string javascript code for client-side onLoading event.
- */
- public function setOnLoading($javascript)
- {
- $this->setFunction('onLoading', $javascript);
- }
-
- /**
- * @return string javascript code for client-side onLoaded event
- */
- public function getOnLoaded()
- {
- return $this->getOption('onLoaded');
- }
-
- /**
- * @param string javascript code for client-side onLoaded event.
- */
- public function setOnLoaded($javascript)
- {
- $this->setFunction('onLoaded', $javascript);
- }
- /**
- * @return string javascript code for client-side onInteractive event
- */
- public function getOnInteractive()
- {
- return $this->getOption('onInteractive');
- }
-
- /**
- * @param string javascript code for client-side onInteractive event.
- */
- public function setOnInteractive($javascript)
- {
- $this->setFunction('onInteractive', $javascript);
- }
- /**
- * @return string javascript code for client-side onComplete event
- */
- public function getOnComplete()
- {
- return $this->getOption('onComplete');
- }
-
- /**
- * @param string javascript code for client-side onComplete event.
- */
- public function setOnComplete($javascript)
- {
- $this->setFunction('onComplete', $javascript);
- }
- /**
- * @return string javascript code for client-side onSuccess event
- */
- public function getOnSuccess()
- {
- return $this->getOption('onSuccess');
- }
-
- /**
- * @param string javascript code for client-side onSuccess event.
- */
- public function setOnSuccess($javascript)
- {
- $this->setFunction('onSuccess', $javascript);
- }
-
- /**
- * @return string javascript code for client-side onFailure event
- */
- public function getOnFailure()
- {
- return $this->getOption('onFailure');
- }
-
- /**
- * @param string javascript code for client-side onFailure event.
- */
- public function setOnFailure($javascript)
- {
- $this->setFunction('onFailure', $javascript);
- }
-
- /**
- * @return string javascript code for client-side onException event
- */
- public function getOnException()
- {
- return $this->getOption('onException');
- }
-
- /**
- * @param string javascript code for client-side onException event.
- */
- public function setOnException($javascript)
- {
- $this->setFunction('onException', $javascript);
- }
-
- /**
- * @return boolean true to post the inputs of the form on callback, default
- * is post the inputs on callback.
- */
- public function getPostState()
- {
- return $this->getOption('PostInputs');
- }
-
- /**
- * @param boolean true to post the inputs of the form with callback
- * requests. Default is to post the inputs.
- */
- public function setPostState($value)
- {
- $this->setOption('PostInputs', TPropertyValue::ensureBoolean($value));
- }
-
- /**
- * @return integer callback request timeout.
- */
- public function getRequestTimeOut()
- {
- return $this->getOption('RequestTimeOut');
- }
-
- /**
- * @param integer callback request timeout
- */
- public function setRequestTimeOut($value)
- {
- $this->setOption('RequestTimeOut', TPropertyValue::ensureInteger($value));
- }
-
- /**
- * @return boolean true if the callback request has priority and will abort
- * existing prioritized request in order to send immediately. It does not
- * affect callbacks that are not prioritized. Default is true.
- */
- public function getHasPriority()
- {
- $option = $this->getOption('HasPriority');
- return ($option===null) ? true : $option;
- }
-
- /**
- * @param boolean true to ensure that the callback request will be sent
- * immediately and will abort existing prioritized requests. It does not
- * affect callbacks that are not prioritized.
- */
- public function setHasPriority($value)
- {
- $hasPriority = TPropertyValue::ensureBoolean($value);
- $this->setOption('HasPriority', $hasPriority);
- if(!$hasPriority)
- $this->setEnablePageStateUpdate(false);
- }
-
- /**
- * Set to true to enable the callback response to enable the viewstate
- * update. This will automatically set HasPrority to true.
- * @param boolean true enables the callback response to update the
- * viewstate.
- */
- public function setEnablePageStateUpdate($value)
- {
- $enabled = TPropertyValue::ensureBoolean($value);
- $this->setOption('EnablePageStateUpdate', $enabled);
- if($enabled)
- $this->setHasPriority(true);
- }
-
- /**
- * @return boolean client-side viewstate will be updated on callback
- * response if true. Default is true.
- */
- public function getEnablePageStateUpdate()
- {
- $option = $this->getOption('EnablePageStateUpdate');
- return ($option===null) ? true : $option;
- }
-
- /**
- * @return string post back target ID
- */
- public function getPostBackTarget()
- {
- return $this->getOption('EventTarget');
- }
-
- /**
- * @param string post back target ID
- */
- public function setPostBackTarget($value)
- {
- if($value instanceof TControl)
- $value = $value->getUniqueID();
- $this->setOption('EventTarget', $value);
- }
-
- /**
- * @return string post back event parameter.
- */
- public function getPostBackParameter()
- {
- return $this->getOption('EventParameter');
- }
-
- /**
- * @param string post back event parameter.
- */
- public function setPostBackParameter($value)
- {
- $this->setOption('EventParameter', $value);
- }
-}
-
+<?php
+/**
+ * TCallbackClientSide class file
+ *
+ * @author Wei Zhuo <weizhuo[at]gamil[dot]com>
+ * @link http://www.pradosoft.com/
+ * @copyright Copyright &copy; 2005-2012 PradoSoft
+ * @license http://www.pradosoft.com/license/
+ * @version $Id$
+ * @package System.Web.UI.ActiveControls
+ */
+
+/**
+ * TCallbackClientSide class.
+ *
+ * The following client side events are executing in order if the callback
+ * request and response are send and received successfuly.
+ *
+ * - <b>onPreDispatch</b> executed before a request is dispatched.
+ * - <b>onUninitialized</b> executed when callback request is uninitialized.
+ * - <b>onLoading</b>* executed when callback request is initiated
+ * - <b>onLoaded</b>* executed when callback request begins.
+ * - <b>onInteractive</b> executed when callback request is in progress.
+ * - <b>onComplete</b>executed when callback response returns.
+ * - <b>onSuccess</b> executed when callback request returns and is successful.
+ * - <b>onFailure</b> executed when callback request returns and fails.
+ * - <b>onException</b> raised when callback request fails due to request/response errors.
+ *
+ * * Note that theses 2 events are not fired correctly by Opera. To make
+ * them work in this browser, Prado will fire them just after onPreDispatch.
+ *
+ * In a general way, onUninitialized, onLoading, onLoaded and onInteractive events
+ * are not implemented consistently in all browsers.When cross browser compatibility is
+ * needed, it is best to avoid use them
+ *
+ * The OnSuccess and OnFailure events are raised when the
+ * response is returned. A successful request/response will raise
+ * OnSuccess event otherwise OnFailure will be raised.
+ *
+ * - <b>PostState</b> true to collect the form inputs and post them during callback, default is true.
+ * - <b>RequestTimeOut</b> The request timeout in milliseconds.
+ * - <b>HasPriority</b> true to ensure that the callback request will be sent
+ * immediately and will abort existing prioritized requests. It does not affect
+ * callbacks that are not prioritized.
+ * - <b>EnablePageStateUpdate</b> enable the callback response to enable the
+ * viewstate update. This will automatically set HasPriority to true when enabled.
+ *
+ * @author Wei Zhuo <weizhuo[at]gamil[dot]com>
+ * @version $Id$
+ * @package System.Web.UI.ActiveControls
+ * @since 3.1
+ */
+class TCallbackClientSide extends TClientSideOptions
+{
+ /**
+ * Returns javascript statement enclosed within a javascript function.
+ * @param string javascript statement
+ * @return string javascript statement wrapped in a javascript function
+ */
+ protected function ensureFunction($javascript)
+ {
+ return "function(sender, parameter){ {$javascript} }";
+ }
+
+ /**
+ * @param string javascript code to be executed before a request is dispatched.
+ */
+ public function setOnPreDispatch($javascript)
+ {
+ $this->setFunction('onPreDispatch', $javascript);
+ }
+
+ /**
+ * @return string javascript code to be executed before a request is dispatched.
+ */
+ public function getOnPreDispatch()
+ {
+ return $this->getOption('onPreDispatch');
+ }
+
+ /**
+ * @return string javascript code for client-side onUninitialized event
+ */
+ public function getOnUninitialized()
+ {
+ return $this->getOption('onUninitialized');
+ }
+
+ /**
+ * @param string javascript code for client-side onUninitialized event.
+ */
+ public function setOnUninitialized($javascript)
+ {
+ $this->setFunction('onUninitialized', $javascript);
+ }
+
+ /**
+ * @return string javascript code for client-side onLoading event
+ */
+ public function getOnLoading()
+ {
+ return $this->getOption('onLoading');
+ }
+
+ /**
+ * @param string javascript code for client-side onLoading event.
+ */
+ public function setOnLoading($javascript)
+ {
+ $this->setFunction('onLoading', $javascript);
+ }
+
+ /**
+ * @return string javascript code for client-side onLoaded event
+ */
+ public function getOnLoaded()
+ {
+ return $this->getOption('onLoaded');
+ }
+
+ /**
+ * @param string javascript code for client-side onLoaded event.
+ */
+ public function setOnLoaded($javascript)
+ {
+ $this->setFunction('onLoaded', $javascript);
+ }
+ /**
+ * @return string javascript code for client-side onInteractive event
+ */
+ public function getOnInteractive()
+ {
+ return $this->getOption('onInteractive');
+ }
+
+ /**
+ * @param string javascript code for client-side onInteractive event.
+ */
+ public function setOnInteractive($javascript)
+ {
+ $this->setFunction('onInteractive', $javascript);
+ }
+ /**
+ * @return string javascript code for client-side onComplete event
+ */
+ public function getOnComplete()
+ {
+ return $this->getOption('onComplete');
+ }
+
+ /**
+ * @param string javascript code for client-side onComplete event.
+ */
+ public function setOnComplete($javascript)
+ {
+ $this->setFunction('onComplete', $javascript);
+ }
+ /**
+ * @return string javascript code for client-side onSuccess event
+ */
+ public function getOnSuccess()
+ {
+ return $this->getOption('onSuccess');
+ }
+
+ /**
+ * @param string javascript code for client-side onSuccess event.
+ */
+ public function setOnSuccess($javascript)
+ {
+ $this->setFunction('onSuccess', $javascript);
+ }
+
+ /**
+ * @return string javascript code for client-side onFailure event
+ */
+ public function getOnFailure()
+ {
+ return $this->getOption('onFailure');
+ }
+
+ /**
+ * @param string javascript code for client-side onFailure event.
+ */
+ public function setOnFailure($javascript)
+ {
+ $this->setFunction('onFailure', $javascript);
+ }
+
+ /**
+ * @return string javascript code for client-side onException event
+ */
+ public function getOnException()
+ {
+ return $this->getOption('onException');
+ }
+
+ /**
+ * @param string javascript code for client-side onException event.
+ */
+ public function setOnException($javascript)
+ {
+ $this->setFunction('onException', $javascript);
+ }
+
+ /**
+ * @return boolean true to post the inputs of the form on callback, default
+ * is post the inputs on callback.
+ */
+ public function getPostState()
+ {
+ return $this->getOption('PostInputs');
+ }
+
+ /**
+ * @param boolean true to post the inputs of the form with callback
+ * requests. Default is to post the inputs.
+ */
+ public function setPostState($value)
+ {
+ $this->setOption('PostInputs', TPropertyValue::ensureBoolean($value));
+ }
+
+ /**
+ * @return integer callback request timeout.
+ */
+ public function getRequestTimeOut()
+ {
+ return $this->getOption('RequestTimeOut');
+ }
+
+ /**
+ * @param integer callback request timeout
+ */
+ public function setRequestTimeOut($value)
+ {
+ $this->setOption('RequestTimeOut', TPropertyValue::ensureInteger($value));
+ }
+
+ /**
+ * @return boolean true if the callback request has priority and will abort
+ * existing prioritized request in order to send immediately. It does not
+ * affect callbacks that are not prioritized. Default is true.
+ */
+ public function getHasPriority()
+ {
+ $option = $this->getOption('HasPriority');
+ return ($option===null) ? true : $option;
+ }
+
+ /**
+ * @param boolean true to ensure that the callback request will be sent
+ * immediately and will abort existing prioritized requests. It does not
+ * affect callbacks that are not prioritized.
+ */
+ public function setHasPriority($value)
+ {
+ $hasPriority = TPropertyValue::ensureBoolean($value);
+ $this->setOption('HasPriority', $hasPriority);
+ if(!$hasPriority)
+ $this->setEnablePageStateUpdate(false);
+ }
+
+ /**
+ * Set to true to enable the callback response to enable the viewstate
+ * update. This will automatically set HasPrority to true.
+ * @param boolean true enables the callback response to update the
+ * viewstate.
+ */
+ public function setEnablePageStateUpdate($value)
+ {
+ $enabled = TPropertyValue::ensureBoolean($value);
+ $this->setOption('EnablePageStateUpdate', $enabled);
+ if($enabled)
+ $this->setHasPriority(true);
+ }
+
+ /**
+ * @return boolean client-side viewstate will be updated on callback
+ * response if true. Default is true.
+ */
+ public function getEnablePageStateUpdate()
+ {
+ $option = $this->getOption('EnablePageStateUpdate');
+ return ($option===null) ? true : $option;
+ }
+
+ /**
+ * @return string post back target ID
+ */
+ public function getPostBackTarget()
+ {
+ return $this->getOption('EventTarget');
+ }
+
+ /**
+ * @param string post back target ID
+ */
+ public function setPostBackTarget($value)
+ {
+ if($value instanceof TControl)
+ $value = $value->getUniqueID();
+ $this->setOption('EventTarget', $value);
+ }
+
+ /**
+ * @return string post back event parameter.
+ */
+ public function getPostBackParameter()
+ {
+ return $this->getOption('EventParameter');
+ }
+
+ /**
+ * @param string post back event parameter.
+ */
+ public function setPostBackParameter($value)
+ {
+ $this->setOption('EventParameter', $value);
+ }
+}
+
diff --git a/framework/Web/UI/ActiveControls/TCallbackEventParameter.php b/framework/Web/UI/ActiveControls/TCallbackEventParameter.php
index d4038fb5..7c532588 100644
--- a/framework/Web/UI/ActiveControls/TCallbackEventParameter.php
+++ b/framework/Web/UI/ActiveControls/TCallbackEventParameter.php
@@ -1,87 +1,87 @@
-<?php
-/**
- * TCallbackEventParameter class file.
- *
- * @author Wei Zhuo <weizhuo[at]gmail[dot]com>
- * @link http://www.pradosoft.com/
- * @copyright Copyright &copy; 2005-2012 PradoSoft
- * @license http://www.pradosoft.com/license/
- * @version $Id$
- * @package System.Web.UI.ActiveControls
- */
-
-/**
- * TCallbackEventParameter class.
- *
- * The TCallbackEventParameter provides the parameter passed during the callback
- * request in the {@link getCallbackParameter CallbackParameter} property. The
- * callback response content (e.g. new HTML content) must be rendered
- * using an THtmlWriter obtained from the {@link getNewWriter NewWriter}
- * property, which returns a <b>NEW</b> instance of TCallbackResponseWriter.
- *
- * Each instance TCallbackResponseWriter is associated with a unique
- * boundary delimited. By default each panel only renders its own content.
- * To replace the content of ONE panel with that of rendered from multiple panels
- * use the same writer instance for the panels to be rendered.
- *
- * The response data (i.e., passing results back to the client-side
- * callback handler function) can be set using {@link setResponseData ResponseData} property.
- *
- * @author Wei Zhuo <weizhuo[at]gamil[dot]com>
- * @version $Id: TActivePageAdapter.php 1648 2007-01-24 05:52:22Z wei $
- * @package System.Web.UI.ActiveControls
- * @since 3.1
- */
-class TCallbackEventParameter extends TEventParameter
-{
- /**
- * @var THttpResponse output content.
- */
- private $_response;
- /**
- * @var mixed callback request parameter.
- */
- private $_parameter;
-
- /**
- * Creates a new TCallbackEventParameter.
- */
- public function __construct($response, $parameter)
- {
- $this->_response = $response;
- $this->_parameter = $parameter;
- }
-
- /**
- * @return TCallbackResponseWriter holds the response content.
- */
- public function getNewWriter()
- {
- return $this->_response->createHtmlWriter(null);
- }
-
- /**
- * @return mixed callback request parameter.
- */
- public function getCallbackParameter()
- {
- return $this->_parameter;
- }
-
- /**
- * @param mixed callback response data.
- */
- public function setResponseData($value)
- {
- $this->_response->getAdapter()->setResponseData($value);
- }
-
- /**
- * @return mixed callback response data.
- */
- public function getResponseData()
- {
- return $this->_response->getAdapter()->getResponseData();
- }
-}
-
+<?php
+/**
+ * TCallbackEventParameter class file.
+ *
+ * @author Wei Zhuo <weizhuo[at]gmail[dot]com>
+ * @link http://www.pradosoft.com/
+ * @copyright Copyright &copy; 2005-2012 PradoSoft
+ * @license http://www.pradosoft.com/license/
+ * @version $Id$
+ * @package System.Web.UI.ActiveControls
+ */
+
+/**
+ * TCallbackEventParameter class.
+ *
+ * The TCallbackEventParameter provides the parameter passed during the callback
+ * request in the {@link getCallbackParameter CallbackParameter} property. The
+ * callback response content (e.g. new HTML content) must be rendered
+ * using an THtmlWriter obtained from the {@link getNewWriter NewWriter}
+ * property, which returns a <b>NEW</b> instance of TCallbackResponseWriter.
+ *
+ * Each instance TCallbackResponseWriter is associated with a unique
+ * boundary delimited. By default each panel only renders its own content.
+ * To replace the content of ONE panel with that of rendered from multiple panels
+ * use the same writer instance for the panels to be rendered.
+ *
+ * The response data (i.e., passing results back to the client-side
+ * callback handler function) can be set using {@link setResponseData ResponseData} property.
+ *
+ * @author Wei Zhuo <weizhuo[at]gamil[dot]com>
+ * @version $Id: TActivePageAdapter.php 1648 2007-01-24 05:52:22Z wei $
+ * @package System.Web.UI.ActiveControls
+ * @since 3.1
+ */
+class TCallbackEventParameter extends TEventParameter
+{
+ /**
+ * @var THttpResponse output content.
+ */
+ private $_response;
+ /**
+ * @var mixed callback request parameter.
+ */
+ private $_parameter;
+
+ /**
+ * Creates a new TCallbackEventParameter.
+ */
+ public function __construct($response, $parameter)
+ {
+ $this->_response = $response;
+ $this->_parameter = $parameter;
+ }
+
+ /**
+ * @return TCallbackResponseWriter holds the response content.
+ */
+ public function getNewWriter()
+ {
+ return $this->_response->createHtmlWriter(null);
+ }
+
+ /**
+ * @return mixed callback request parameter.
+ */
+ public function getCallbackParameter()
+ {
+ return $this->_parameter;
+ }
+
+ /**
+ * @param mixed callback response data.
+ */
+ public function setResponseData($value)
+ {
+ $this->_response->getAdapter()->setResponseData($value);
+ }
+
+ /**
+ * @return mixed callback response data.
+ */
+ public function getResponseData()
+ {
+ return $this->_response->getAdapter()->getResponseData();
+ }
+}
+
diff --git a/framework/Web/UI/ActiveControls/TCallbackOptions.php b/framework/Web/UI/ActiveControls/TCallbackOptions.php
index baba32e1..e75c2fde 100644
--- a/framework/Web/UI/ActiveControls/TCallbackOptions.php
+++ b/framework/Web/UI/ActiveControls/TCallbackOptions.php
@@ -1,53 +1,53 @@
-<?php
-/**
- * TCallbackOptions component class file.
- *
- * @author Wei Zhuo <weizhuo[at]gamil[dot]com>
- * @link http://www.pradosoft.com/
- * @copyright Copyright &copy; 2005-2012 PradoSoft
- * @license http://www.pradosoft.com/license/
- * @version $Id$
- * @package System.Web.UI.ActiveControls
- */
-
-/**
- * TCallbackOptions class.
- *
- * TCallbackOptions allows common set of callback client-side options
- * to be attached to other active controls.
- *
- * @author Wei Zhuo <weizhuo[at]gmail[dot]com>
- * @version $Id$
- * @package System.Web.UI.ActiveControls
- * @since 3.1
- */
-class TCallbackOptions extends TControl
-{
- /**
- * @var TCallbackClientSide client side callback options.
- */
- private $_clientSide;
-
- /**
- * Callback client-side options can be set by setting the properties of
- * the ClientSide property. E.g. <com:TCallbackOptions ClientSide.OnSuccess="..." />
- * See {@link TCallbackClientSide} for details on the properties of
- * ClientSide.
- * @return TCallbackClientSide client-side callback options.
- */
- public function getClientSide()
- {
- if($this->_clientSide===null)
- $this->_clientSide = $this->createClientSide();
- return $this->_clientSide;
- }
-
- /**
- * @return TCallbackClientSide callback client-side options.
- */
- protected function createClientSide()
- {
- return Prado::createComponent('System.Web.UI.ActiveControls.TCallbackClientSide');
- }
-}
-
+<?php
+/**
+ * TCallbackOptions component class file.
+ *
+ * @author Wei Zhuo <weizhuo[at]gamil[dot]com>
+ * @link http://www.pradosoft.com/
+ * @copyright Copyright &copy; 2005-2012 PradoSoft
+ * @license http://www.pradosoft.com/license/
+ * @version $Id$
+ * @package System.Web.UI.ActiveControls
+ */
+
+/**
+ * TCallbackOptions class.
+ *
+ * TCallbackOptions allows common set of callback client-side options
+ * to be attached to other active controls.
+ *
+ * @author Wei Zhuo <weizhuo[at]gmail[dot]com>
+ * @version $Id$
+ * @package System.Web.UI.ActiveControls
+ * @since 3.1
+ */
+class TCallbackOptions extends TControl
+{
+ /**
+ * @var TCallbackClientSide client side callback options.
+ */
+ private $_clientSide;
+
+ /**
+ * Callback client-side options can be set by setting the properties of
+ * the ClientSide property. E.g. <com:TCallbackOptions ClientSide.OnSuccess="..." />
+ * See {@link TCallbackClientSide} for details on the properties of
+ * ClientSide.
+ * @return TCallbackClientSide client-side callback options.
+ */
+ public function getClientSide()
+ {
+ if($this->_clientSide===null)
+ $this->_clientSide = $this->createClientSide();
+ return $this->_clientSide;
+ }
+
+ /**
+ * @return TCallbackClientSide callback client-side options.
+ */
+ protected function createClientSide()
+ {
+ return Prado::createComponent('System.Web.UI.ActiveControls.TCallbackClientSide');
+ }
+}
+
diff --git a/framework/Web/UI/ActiveControls/TEventTriggeredCallback.php b/framework/Web/UI/ActiveControls/TEventTriggeredCallback.php
index c28b435c..38aaabec 100644
--- a/framework/Web/UI/ActiveControls/TEventTriggeredCallback.php
+++ b/framework/Web/UI/ActiveControls/TEventTriggeredCallback.php
@@ -1,95 +1,95 @@
-<?php
-/**
- * TEventTriggeredCallback class file.
- *
- * @author Wei Zhuo <weizhuo[at]gamil[dot]com>
- * @link http://www.pradosoft.com/
- * @copyright Copyright &copy; 2005-2012 PradoSoft
- * @license http://www.pradosoft.com/license/
- * @version $Id$
- * @package System.Web.UI.ActiveControls
- */
-
-Prado::using('System.Web.UI.ActiveControls.TTriggeredCallback');
-
-/**
- * TEventTriggeredCallback Class
- *
- * Triggers a new callback request when a particular {@link setEventName EventName}
- * on a control with ID given by {@link setControlID ControlID} is raised.
- *
- * The default action of the event on the client-side can be prevented when
- * {@link setPreventDefaultAction PreventDefaultAction} is set to true.
- *
- * @author Wei Zhuo <weizhuo[at]gmail[dot]com>
- * @version $Id$
- * @package System.Web.UI.ActiveControls
- * @since 3.1
- */
-class TEventTriggeredCallback extends TTriggeredCallback
-{
- /**
- * @return string The client-side event name the trigger listens to.
- */
- public function getEventName()
- {
- return $this->getViewState('EventName', '');
- }
-
- /**
- * Sets the client-side event name that fires the callback request.
- * @param string The client-side event name the trigger listens to.
- */
- public function setEventName($value)
- {
- $this->setViewState('EventName', $value, '');
- }
-
- /**
- * @param boolean true to prevent/stop default event action.
- */
- public function setPreventDefaultAction($value)
- {
- $this->setViewState('StopEvent', TPropertyValue::ensureBoolean($value), false);
- }
-
- /**
- * @return boolean true to prevent/stop default event action.
- */
- public function getPreventDefaultAction()
- {
- return $this->getViewState('StopEvent', false);
- }
-
- /**
- * @return array list of timer options for client-side.
- */
- protected function getTriggerOptions()
- {
- $options = parent::getTriggerOptions();
- $name = preg_replace('/^on/', '', $this->getEventName());
- $options['EventName'] = strtolower($name);
- $options['StopEvent'] = $this->getPreventDefaultAction();
- return $options;
- }
-
- /**
- * Registers the javascript code for initializing the active control.
- * @param THtmlWriter the renderer.
- */
- public function render($writer)
- {
- parent::render($writer);
- $this->getActiveControl()->registerCallbackClientScript(
- $this->getClientClassName(), $this->getTriggerOptions());
- }
-
- /**
- * @return string corresponding javascript class name for TEventTriggeredCallback.
- */
- protected function getClientClassName()
- {
- return 'Prado.WebUI.TEventTriggeredCallback';
- }
-}
-
+<?php
+/**
+ * TEventTriggeredCallback class file.
+ *
+ * @author Wei Zhuo <weizhuo[at]gamil[dot]com>
+ * @link http://www.pradosoft.com/
+ * @copyright Copyright &copy; 2005-2012 PradoSoft
+ * @license http://www.pradosoft.com/license/
+ * @version $Id$
+ * @package System.Web.UI.ActiveControls
+ */
+
+Prado::using('System.Web.UI.ActiveControls.TTriggeredCallback');
+
+/**
+ * TEventTriggeredCallback Class
+ *
+ * Triggers a new callback request when a particular {@link setEventName EventName}
+ * on a control with ID given by {@link setControlID ControlID} is raised.
+ *
+ * The default action of the event on the client-side can be prevented when
+ * {@link setPreventDefaultAction PreventDefaultAction} is set to true.
+ *
+ * @author Wei Zhuo <weizhuo[at]gmail[dot]com>
+ * @version $Id$
+ * @package System.Web.UI.ActiveControls
+ * @since 3.1
+ */
+class TEventTriggeredCallback extends TTriggeredCallback
+{
+ /**
+ * @return string The client-side event name the trigger listens to.
+ */
+ public function getEventName()
+ {
+ return $this->getViewState('EventName', '');
+ }
+
+ /**
+ * Sets the client-side event name that fires the callback request.
+ * @param string The client-side event name the trigger listens to.
+ */
+ public function setEventName($value)
+ {
+ $this->setViewState('EventName', $value, '');
+ }
+
+ /**
+ * @param boolean true to prevent/stop default event action.
+ */
+ public function setPreventDefaultAction($value)
+ {
+ $this->setViewState('StopEvent', TPropertyValue::ensureBoolean($value), false);
+ }
+
+ /**
+ * @return boolean true to prevent/stop default event action.
+ */
+ public function getPreventDefaultAction()
+ {
+ return $this->getViewState('StopEvent', false);
+ }
+
+ /**
+ * @return array list of timer options for client-side.
+ */
+ protected function getTriggerOptions()
+ {
+ $options = parent::getTriggerOptions();
+ $name = preg_replace('/^on/', '', $this->getEventName());
+ $options['EventName'] = strtolower($name);
+ $options['StopEvent'] = $this->getPreventDefaultAction();
+ return $options;
+ }
+
+ /**
+ * Registers the javascript code for initializing the active control.
+ * @param THtmlWriter the renderer.
+ */
+ public function render($writer)
+ {
+ parent::render($writer);
+ $this->getActiveControl()->registerCallbackClientScript(
+ $this->getClientClassName(), $this->getTriggerOptions());
+ }
+
+ /**
+ * @return string corresponding javascript class name for TEventTriggeredCallback.
+ */
+ protected function getClientClassName()
+ {
+ return 'Prado.WebUI.TEventTriggeredCallback';
+ }
+}
+
diff --git a/framework/Web/UI/ActiveControls/TInPlaceTextBox.php b/framework/Web/UI/ActiveControls/TInPlaceTextBox.php
index aba477b9..47c8aeac 100644
--- a/framework/Web/UI/ActiveControls/TInPlaceTextBox.php
+++ b/framework/Web/UI/ActiveControls/TInPlaceTextBox.php
@@ -1,290 +1,290 @@
-<?php
-/**
- * TInPlaceTextBox class file.
- *
- * @author Wei Zhuo <weizhuo[at]gamil[dot]com>
- * @link http://www.pradosoft.com/
- * @copyright Copyright &copy; 2005-2012 PradoSoft
- * @license http://www.pradosoft.com/license/
- * @version $Id$
- * @package System.Web.UI.ActiveControls
- */
-
-Prado::using('System.Web.UI.ActiveControls.TActiveTextBox');
-
-/**
- * TInPlaceTextBox Class
- * *
- * TInPlaceTextBox is a component rendered as a label and allows its
- * contents to be edited by changing the label to a textbox when
- * the label is clicked or when another control or html element with
- * ID given by {@link setEditTriggerControlID EditTriggerControlID} is clicked.
- *
- * If the {@link OnLoadingText} event is handled, a callback request is
- * made when the label is clicked, while the request is being made the
- * textbox is disabled from editing. The {@link OnLoadingText} event allows
- * you to update the content of the textbox before the client is allowed
- * to edit the content. After the callback request returns successfully,
- * the textbox is enabled and the contents is then allowed to be edited.
- *
- * Once the textbox loses focus, if {@link setAutoPostBack AutoPostBack}
- * is true and the textbox content has changed, a callback request is made and
- * the {@link OnTextChanged} event is raised like that of the TActiveTextBox.
- * During the request, the textbox is disabled.
- *
- * After the callback request returns sucessfully, the textbox is enabled.
- * If the {@link setAutoHideTextBox AutoHideTextBox} property is true, then
- * the textbox will be hidden and the label is then shown.
- *
- * Since 3.1.2, you can set the {@link setReadOnly ReadOnly} property to make
- * the control not editable. This property can be also changed on callback
- *
- * @author Wei Zhuo <weizhuo[at]gmail[dot]com>
- * @version $Id$
- * @package System.Web.UI.ActiveControls
- * @since 3.1
- */
-class TInPlaceTextBox extends TActiveTextBox
-{
- /**
- * Sets the auto post back to true by default.
- */
- public function __construct()
- {
- parent::__construct();
- $this->setAutoPostBack(true);
- }
-
- /**
- * @param boolean true to hide the textbox after losing focus.
- */
- public function setAutoHideTextBox($value)
- {
- $this->setViewState('AutoHide', TPropertyValue::ensureBoolean($value), true);
- }
-
- /**
- * @return boolean true will hide the textbox after losing focus.
- */
- public function getAutoHideTextBox()
- {
- return $this->getViewState('AutoHide', true);
- }
-
- /**
- * @param boolean true to display the edit textbox
- */
- public function setDisplayTextBox($value)
- {
- $value = TPropertyValue::ensureBoolean($value);
- $this->setViewState('DisplayTextBox', $value,false);
- if($this->getActiveControl()->canUpdateClientSide())
- $this->callClientFunction('setDisplayTextBox',$value);
- }
-
- /**
- * @return boolean true to display the edit textbox
- */
- public function getDisplayTextBox()
- {
- return $this->getViewState('DisplayTextBox', false);
- }
-
- /**
- * Calls the client-side static method for this control class.
- * @param string static method name
- * @param mixed method parmaeter
- */
- protected function callClientFunction($func,$value)
- {
- $client = $this->getPage()->getCallbackClient();
- $code = $this->getClientClassName().'.'.$func;
- $client->callClientFunction($code,array($this,$value));
- }
-
- /**
- * @param string ID of the control that can trigger to edit the textbox
- */
- public function setEditTriggerControlID($value)
- {
- $this->setViewState('EditTriggerControlID', $value);
- }
-
- /**
- * @return string ID of the control that can trigger to edit the textbox
- */
- public function getEditTriggerControlID()
- {
- return $this->getViewState('EditTriggerControlID');
- }
-
- /**
- * @return string edit trigger control client ID.
- */
- protected function getExternalControlID()
- {
- $extID = $this->getEditTriggerControlID();
- if($extID===null) return '';
- if(($control = $this->findControl($extID))!==null)
- return $control->getClientID();
- return $extID;
- }
-
- /**
- * On callback response, the inner HTMl of the label and the
- * value of the textbox is updated
- * @param string the text value of the label
- */
- public function setText($value)
- {
- TTextBox::setText($value);
- if($this->getActiveControl()->canUpdateClientSide())
- {
- $client = $this->getPage()->getCallbackClient();
- $client->update($this->getLabelClientID(), $value);
- $client->setValue($this, $value);
- }
- }
-
- /**
- * Update ClientSide Readonly property
- * @param boolean value
- * @since 3.1.2
- */
- public function setReadOnly ($value)
- {
- $value=TPropertyValue::ensureBoolean($value);
- TTextBox::setReadOnly($value);
- if ($this->getActiveControl()->canUpdateClientSide())
- {
- $this->callClientFunction('setReadOnly', $value);
- }
- }
-
- /**
- * @return string tag name of the label.
- */
- protected function getTagName()
- {
- return 'span';
- }
-
- /**
- * Renders the body content of the label.
- * @param THtmlWriter the writer for rendering
- */
- public function renderContents($writer)
- {
- if(($text=$this->getText())==='')
- parent::renderContents($writer);
- else
- $writer->write($text);
- }
-
- /**
- * @return string label client ID
- */
- protected function getLabelClientID()
- {
- return $this->getClientID().'__label';
- }
-
- /**
- * This method is invoked when a callback is requested. The method raises
- * 'OnCallback' event to fire up the event handlers. If you override this
- * method, be sure to call the parent implementation so that the event
- * handler can be invoked.
- * @param TCallbackEventParameter event parameter to be passed to the event handlers
- */
- public function onCallback($param)
- {
- $action = $param->getCallbackParameter();
- if(is_array($action) && $action[0] === '__InlineEditor_loadExternalText__')
- {
- $parameter = new TCallbackEventParameter($this->getResponse(), $action[1]);
- $this->onLoadingText($parameter);
- }
- $this->raiseEvent('OnCallback', $this, $param);
- }
-
- /**
- * @return array callback options.
- */
- protected function getPostBackOptions()
- {
- $options = parent::getPostBackOptions();
- $options['ID'] = $this->getLabelClientID();
- $options['TextBoxID'] = $this->getClientID();
- $options['ExternalControl'] = $this->getExternalControlID();
- $options['AutoHide'] = $this->getAutoHideTextBox() == false ? '' : true;
- $options['AutoPostBack'] = $this->getAutoPostBack() == false ? '' : true;
- $options['Columns'] = $this->getColumns();
- if($this->getTextMode()==='MultiLine')
- {
- $options['Rows'] = $this->getRows();
- $options['Wrap'] = $this->getWrap()== false ? '' : true;
- }
- else
- {
- $length = $this->getMaxLength();
- $options['MaxLength'] = $length > 0 ? $length : '';
- }
-
- if($this->hasEventHandler('OnLoadingText'))
- $options['LoadTextOnEdit'] = true;
-
- $options['ReadOnly']=$this->getReadOnly();
- return $options;
- }
-
- /**
- * Raised when editing the content is requsted to be loaded from the
- * server side.
- * @param TCallbackEventParameter event parameter to be passed to the event handlers
- */
- public function onLoadingText($param)
- {
- $this->raiseEvent('OnLoadingText',$this,$param);
- }
-
- /**
- * @return string corresponding javascript class name for this TInPlaceTextBox
- */
- protected function getClientClassName()
- {
- return 'Prado.WebUI.TInPlaceTextBox';
- }
-
- /**
- * Ensure that the ID attribute is rendered and registers the javascript code
- * for initializing the active control.
- */
- protected function addAttributesToRender($writer)
- {
- //calls the TWebControl to avoid rendering other attribute normally render for a textbox.
- TWebControl::addAttributesToRender($writer);
- $writer->addAttribute('id',$this->getLabelClientID());
- $this->getActiveControl()->registerCallbackClientScript(
- $this->getClientClassName(), $this->getPostBackOptions());
- }
-
- /**
- * Registers CSS and JS.
- * This method is invoked right before the control rendering, if the control is visible.
- * @param mixed event parameter
- */
- public function onPreRender($param)
- {
- parent::onPreRender($param);
- $this->registerClientScript();
- }
-
- /**
- * Registers the relevant JavaScript.
- */
- protected function registerClientScript()
- {
- $cs=$this->getPage()->getClientScript();
- $cs->registerPradoScript('inlineeditor');
- }
-}
+<?php
+/**
+ * TInPlaceTextBox class file.
+ *
+ * @author Wei Zhuo <weizhuo[at]gamil[dot]com>
+ * @link http://www.pradosoft.com/
+ * @copyright Copyright &copy; 2005-2012 PradoSoft
+ * @license http://www.pradosoft.com/license/
+ * @version $Id$
+ * @package System.Web.UI.ActiveControls
+ */
+
+Prado::using('System.Web.UI.ActiveControls.TActiveTextBox');
+
+/**
+ * TInPlaceTextBox Class
+ * *
+ * TInPlaceTextBox is a component rendered as a label and allows its
+ * contents to be edited by changing the label to a textbox when
+ * the label is clicked or when another control or html element with
+ * ID given by {@link setEditTriggerControlID EditTriggerControlID} is clicked.
+ *
+ * If the {@link OnLoadingText} event is handled, a callback request is
+ * made when the label is clicked, while the request is being made the
+ * textbox is disabled from editing. The {@link OnLoadingText} event allows
+ * you to update the content of the textbox before the client is allowed
+ * to edit the content. After the callback request returns successfully,
+ * the textbox is enabled and the contents is then allowed to be edited.
+ *
+ * Once the textbox loses focus, if {@link setAutoPostBack AutoPostBack}
+ * is true and the textbox content has changed, a callback request is made and
+ * the {@link OnTextChanged} event is raised like that of the TActiveTextBox.
+ * During the request, the textbox is disabled.
+ *
+ * After the callback request returns sucessfully, the textbox is enabled.
+ * If the {@link setAutoHideTextBox AutoHideTextBox} property is true, then
+ * the textbox will be hidden and the label is then shown.
+ *
+ * Since 3.1.2, you can set the {@link setReadOnly ReadOnly} property to make
+ * the control not editable. This property can be also changed on callback
+ *
+ * @author Wei Zhuo <weizhuo[at]gmail[dot]com>
+ * @version $Id$
+ * @package System.Web.UI.ActiveControls
+ * @since 3.1
+ */
+class TInPlaceTextBox extends TActiveTextBox
+{
+ /**
+ * Sets the auto post back to true by default.
+ */
+ public function __construct()
+ {
+ parent::__construct();
+ $this->setAutoPostBack(true);
+ }
+
+ /**
+ * @param boolean true to hide the textbox after losing focus.
+ */
+ public function setAutoHideTextBox($value)
+ {
+ $this->setViewState('AutoHide', TPropertyValue::ensureBoolean($value), true);
+ }
+
+ /**
+ * @return boolean true will hide the textbox after losing focus.
+ */
+ public function getAutoHideTextBox()
+ {
+ return $this->getViewState('AutoHide', true);
+ }
+
+ /**
+ * @param boolean true to display the edit textbox
+ */
+ public function setDisplayTextBox($value)
+ {
+ $value = TPropertyValue::ensureBoolean($value);
+ $this->setViewState('DisplayTextBox', $value,false);
+ if($this->getActiveControl()->canUpdateClientSide())
+ $this->callClientFunction('setDisplayTextBox',$value);
+ }
+
+ /**
+ * @return boolean true to display the edit textbox
+ */
+ public function getDisplayTextBox()
+ {
+ return $this->getViewState('DisplayTextBox', false);
+ }
+
+ /**
+ * Calls the client-side static method for this control class.
+ * @param string static method name
+ * @param mixed method parmaeter
+ */
+ protected function callClientFunction($func,$value)
+ {
+ $client = $this->getPage()->getCallbackClient();
+ $code = $this->getClientClassName().'.'.$func;
+ $client->callClientFunction($code,array($this,$value));
+ }
+
+ /**
+ * @param string ID of the control that can trigger to edit the textbox
+ */
+ public function setEditTriggerControlID($value)
+ {
+ $this->setViewState('EditTriggerControlID', $value);
+ }
+
+ /**
+ * @return string ID of the control that can trigger to edit the textbox
+ */
+ public function getEditTriggerControlID()
+ {
+ return $this->getViewState('EditTriggerControlID');
+ }
+
+ /**
+ * @return string edit trigger control client ID.
+ */
+ protected function getExternalControlID()
+ {
+ $extID = $this->getEditTriggerControlID();
+ if($extID===null) return '';
+ if(($control = $this->findControl($extID))!==null)
+ return $control->getClientID();
+ return $extID;
+ }
+
+ /**
+ * On callback response, the inner HTMl of the label and the
+ * value of the textbox is updated
+ * @param string the text value of the label
+ */
+ public function setText($value)
+ {
+ TTextBox::setText($value);
+ if($this->getActiveControl()->canUpdateClientSide())
+ {
+ $client = $this->getPage()->getCallbackClient();
+ $client->update($this->getLabelClientID(), $value);
+ $client->setValue($this, $value);
+ }
+ }
+
+ /**
+ * Update ClientSide Readonly property
+ * @param boolean value
+ * @since 3.1.2
+ */
+ public function setReadOnly ($value)
+ {
+ $value=TPropertyValue::ensureBoolean($value);
+ TTextBox::setReadOnly($value);
+ if ($this->getActiveControl()->canUpdateClientSide())
+ {
+ $this->callClientFunction('setReadOnly', $value);
+ }
+ }
+
+ /**
+ * @return string tag name of the label.
+ */
+ protected function getTagName()
+ {
+ return 'span';
+ }
+
+ /**
+ * Renders the body content of the label.
+ * @param THtmlWriter the writer for rendering
+ */
+ public function renderContents($writer)
+ {
+ if(($text=$this->getText())==='')
+ parent::renderContents($writer);
+ else
+ $writer->write($text);
+ }
+
+ /**
+ * @return string label client ID
+ */
+ protected function getLabelClientID()
+ {
+ return $this->getClientID().'__label';
+ }
+
+ /**
+ * This method is invoked when a callback is requested. The method raises
+ * 'OnCallback' event to fire up the event handlers. If you override this
+ * method, be sure to call the parent implementation so that the event
+ * handler can be invoked.
+ * @param TCallbackEventParameter event parameter to be passed to the event handlers
+ */
+ public function onCallback($param)
+ {
+ $action = $param->getCallbackParameter();
+ if(is_array($action) && $action[0] === '__InlineEditor_loadExternalText__')
+ {
+ $parameter = new TCallbackEventParameter($this->getResponse(), $action[1]);
+ $this->onLoadingText($parameter);
+ }
+ $this->raiseEvent('OnCallback', $this, $param);
+ }
+
+ /**
+ * @return array callback options.
+ */
+ protected function getPostBackOptions()
+ {
+ $options = parent::getPostBackOptions();
+ $options['ID'] = $this->getLabelClientID();
+ $options['TextBoxID'] = $this->getClientID();
+ $options['ExternalControl'] = $this->getExternalControlID();
+ $options['AutoHide'] = $this->getAutoHideTextBox() == false ? '' : true;
+ $options['AutoPostBack'] = $this->getAutoPostBack() == false ? '' : true;
+ $options['Columns'] = $this->getColumns();
+ if($this->getTextMode()==='MultiLine')
+ {
+ $options['Rows'] = $this->getRows();
+ $options['Wrap'] = $this->getWrap()== false ? '' : true;
+ }
+ else
+ {
+ $length = $this->getMaxLength();
+ $options['MaxLength'] = $length > 0 ? $length : '';
+ }
+
+ if($this->hasEventHandler('OnLoadingText'))
+ $options['LoadTextOnEdit'] = true;
+
+ $options['ReadOnly']=$this->getReadOnly();
+ return $options;
+ }
+
+ /**
+ * Raised when editing the content is requsted to be loaded from the
+ * server side.
+ * @param TCallbackEventParameter event parameter to be passed to the event handlers
+ */
+ public function onLoadingText($param)
+ {
+ $this->raiseEvent('OnLoadingText',$this,$param);
+ }
+
+ /**
+ * @return string corresponding javascript class name for this TInPlaceTextBox
+ */
+ protected function getClientClassName()
+ {
+ return 'Prado.WebUI.TInPlaceTextBox';
+ }
+
+ /**
+ * Ensure that the ID attribute is rendered and registers the javascript code
+ * for initializing the active control.
+ */
+ protected function addAttributesToRender($writer)
+ {
+ //calls the TWebControl to avoid rendering other attribute normally render for a textbox.
+ TWebControl::addAttributesToRender($writer);
+ $writer->addAttribute('id',$this->getLabelClientID());
+ $this->getActiveControl()->registerCallbackClientScript(
+ $this->getClientClassName(), $this->getPostBackOptions());
+ }
+
+ /**
+ * Registers CSS and JS.
+ * This method is invoked right before the control rendering, if the control is visible.
+ * @param mixed event parameter
+ */
+ public function onPreRender($param)
+ {
+ parent::onPreRender($param);
+ $this->registerClientScript();
+ }
+
+ /**
+ * Registers the relevant JavaScript.
+ */
+ protected function registerClientScript()
+ {
+ $cs=$this->getPage()->getClientScript();
+ $cs->registerPradoScript('inlineeditor');
+ }
+}
diff --git a/framework/Web/UI/ActiveControls/TTriggeredCallback.php b/framework/Web/UI/ActiveControls/TTriggeredCallback.php
index fd1fabb1..4b89cb8e 100644
--- a/framework/Web/UI/ActiveControls/TTriggeredCallback.php
+++ b/framework/Web/UI/ActiveControls/TTriggeredCallback.php
@@ -1,71 +1,71 @@
-<?php
-/**
- * TTriggeredCallback class file.
- *
- * @author Wei Zhuo <weizhuo[at]gamil[dot]com>
- * @link http://www.pradosoft.com/
- * @copyright Copyright &copy; 2005-2012 PradoSoft
- * @license http://www.pradosoft.com/license/
- * @version $Id$
- * @package System.Web.UI.ActiveControls
- */
-
-Prado::using('System.Web.UI.ActiveControls.TCallback');
-/**
- * TTriggeredCallback abstract Class
- *
- * Base class for triggered callback controls. The {@link setControlID ControlID}
- * property sets the control ID to observe the trigger.
- *
- * @author Wei Zhuo <weizhuo[at]gmail[dot]com>
- * @version $Id$
- * @package System.Web.UI.ActiveControls
- * @since 3.1
- */
-abstract class TTriggeredCallback extends TCallback
-{
- /**
- * @return string The ID of the server control the trigger is bounded to.
- */
- public function getControlID()
- {
- return $this->getViewState('ControlID', '');
- }
-
- /**
- * @param string The ID of the server control the trigger is bounded to.
- */
- public function setControlID($value)
- {
- $this->setViewState('ControlID', $value, '');
- }
-
- /**
- * @return string target control client ID or html element ID if
- * control is not found in hierarchy.
- */
- protected function getTargetControl()
- {
- $id = $this->getControlID();
- if(($control=$this->findControl($id)) instanceof TControl)
- return $control->getClientID();
- if($id==='')
- {
- throw new TConfigurationException(
- 'ttriggeredcallback_invalid_controlid', get_class($this));
- }
- return $id;
- }
-
- /**
- * @return array list of trigger callback options.
- */
- protected function getTriggerOptions()
- {
- $options['ID'] = $this->getClientID();
- $options['EventTarget'] = $this->getUniqueID();
- $options['ControlID'] = $this->getTargetControl();
- return $options;
- }
-}
-
+<?php
+/**
+ * TTriggeredCallback class file.
+ *
+ * @author Wei Zhuo <weizhuo[at]gamil[dot]com>
+ * @link http://www.pradosoft.com/
+ * @copyright Copyright &copy; 2005-2012 PradoSoft
+ * @license http://www.pradosoft.com/license/
+ * @version $Id$
+ * @package System.Web.UI.ActiveControls
+ */
+
+Prado::using('System.Web.UI.ActiveControls.TCallback');
+/**
+ * TTriggeredCallback abstract Class
+ *
+ * Base class for triggered callback controls. The {@link setControlID ControlID}
+ * property sets the control ID to observe the trigger.
+ *
+ * @author Wei Zhuo <weizhuo[at]gmail[dot]com>
+ * @version $Id$
+ * @package System.Web.UI.ActiveControls
+ * @since 3.1
+ */
+abstract class TTriggeredCallback extends TCallback
+{
+ /**
+ * @return string The ID of the server control the trigger is bounded to.
+ */
+ public function getControlID()
+ {
+ return $this->getViewState('ControlID', '');
+ }
+
+ /**
+ * @param string The ID of the server control the trigger is bounded to.
+ */
+ public function setControlID($value)
+ {
+ $this->setViewState('ControlID', $value, '');
+ }
+
+ /**
+ * @return string target control client ID or html element ID if
+ * control is not found in hierarchy.
+ */
+ protected function getTargetControl()
+ {
+ $id = $this->getControlID();
+ if(($control=$this->findControl($id)) instanceof TControl)
+ return $control->getClientID();
+ if($id==='')
+ {
+ throw new TConfigurationException(
+ 'ttriggeredcallback_invalid_controlid', get_class($this));
+ }
+ return $id;
+ }
+
+ /**
+ * @return array list of trigger callback options.
+ */
+ protected function getTriggerOptions()
+ {
+ $options['ID'] = $this->getClientID();
+ $options['EventTarget'] = $this->getUniqueID();
+ $options['ControlID'] = $this->getTargetControl();
+ return $options;
+ }
+}
+
diff --git a/framework/Web/UI/ActiveControls/TValueTriggeredCallback.php b/framework/Web/UI/ActiveControls/TValueTriggeredCallback.php
index 58a78d08..899419ee 100644
--- a/framework/Web/UI/ActiveControls/TValueTriggeredCallback.php
+++ b/framework/Web/UI/ActiveControls/TValueTriggeredCallback.php
@@ -1,120 +1,120 @@
-<?php
-/**
- * TValueTriggeredCallback class file.
- *
- * @author Wei Zhuo <weizhuo[at]gamil[dot]com>
- * @link http://www.pradosoft.com/
- * @copyright Copyright &copy; 2005-2012 PradoSoft
- * @license http://www.pradosoft.com/license/
- * @version $Id$
- * @package System.Web.UI.ActiveControls
- */
-
-Prado::using('System.Web.UI.ActiveControls.TTriggeredCallback');
-
-/**
- * TValueTriggeredCallback Class
- *
- * Observes the value with {@link setPropertyName PropertyName} of a
- * control with {@link setControlID ControlID}. Changes to the observed
- * property value will trigger a new callback request. The property value is checked
- * for changes every{@link setInterval Interval} seconds.
- *
- * A {@link setDecayRate DecayRate} can be set to increase the polling
- * interval linearly if no changes are observed. Once a change is
- * observed, the polling interval is reset to the original value.
- *
- * @author Wei Zhuo <weizhuo[at]gmail[dot]com>
- * @version $Id$
- * @package System.Web.UI.ActiveControls
- * @since 3.1
- */
-class TValueTriggeredCallback extends TTriggeredCallback
-{
- /**
- * @return string The control property name to observe value changes.
- */
- public function getPropertyName()
- {
- return $this->getViewState('PropertyName', '');
- }
-
- /**
- * Sets the control property name to observe value changes that fires the callback request.
- * @param string The control property name to observe value changes.
- */
- public function setPropertyName($value)
- {
- $this->setViewState('PropertyName', $value, '');
- }
-
- /**
- * Sets the polling interval in seconds to observe property changes.
- * Default is 1 second.
- * @param float polling interval in seconds.
- */
- public function setInterval($value)
- {
- $this->setViewState('Interval', TPropertyValue::ensureFloat($value), 1);
- }
-
- /**
- * @return float polling interval, 1 second default.
- */
- public function getInterval()
- {
- return $this->getViewState('Interval', 1);
- }
-
- /**
- * Gets the decay rate between callbacks. Default is 0;
- * @return float decay rate between callbacks.
- */
- public function getDecayRate()
- {
- return $this->getViewState('Decay', 0);
- }
-
- /**
- * Sets the decay rate between callback. Default is 0;
- * @param float decay rate between callbacks.
- */
- public function setDecayRate($value)
- {
- $decay = TPropertyValue::ensureFloat($value);
- if($decay < 0)
- throw new TConfigurationException('callback_decay_be_not_negative', $this->getID());
- $this->setViewState('Decay', $decay);
- }
-
- /**
- * @return array list of timer options for client-side.
- */
- protected function getTriggerOptions()
- {
- $options = parent::getTriggerOptions();
- $options['PropertyName'] = $this->getPropertyName();
- $options['Interval'] = $this->getInterval();
- $options['Decay'] = $this->getDecayRate();
- return $options;
- }
-
- /**
- * Registers the javascript code for initializing the active control.
- * @param THtmlWriter the renderer.
- */
- public function render($writer)
- {
- parent::render($writer);
- $this->getActiveControl()->registerCallbackClientScript(
- $this->getClientClassName(), $this->getTriggerOptions());
- }
-
- /**
- * @return string corresponding javascript class name for TEventTriggeredCallback.
- */
- protected function getClientClassName()
- {
- return 'Prado.WebUI.TValueTriggeredCallback';
- }
-}
+<?php
+/**
+ * TValueTriggeredCallback class file.
+ *
+ * @author Wei Zhuo <weizhuo[at]gamil[dot]com>
+ * @link http://www.pradosoft.com/
+ * @copyright Copyright &copy; 2005-2012 PradoSoft
+ * @license http://www.pradosoft.com/license/
+ * @version $Id$
+ * @package System.Web.UI.ActiveControls
+ */
+
+Prado::using('System.Web.UI.ActiveControls.TTriggeredCallback');
+
+/**
+ * TValueTriggeredCallback Class
+ *
+ * Observes the value with {@link setPropertyName PropertyName} of a
+ * control with {@link setControlID ControlID}. Changes to the observed
+ * property value will trigger a new callback request. The property value is checked
+ * for changes every{@link setInterval Interval} seconds.
+ *
+ * A {@link setDecayRate DecayRate} can be set to increase the polling
+ * interval linearly if no changes are observed. Once a change is
+ * observed, the polling interval is reset to the original value.
+ *
+ * @author Wei Zhuo <weizhuo[at]gmail[dot]com>
+ * @version $Id$
+ * @package System.Web.UI.ActiveControls
+ * @since 3.1
+ */
+class TValueTriggeredCallback extends TTriggeredCallback
+{
+ /**
+ * @return string The control property name to observe value changes.
+ */
+ public function getPropertyName()
+ {
+ return $this->getViewState('PropertyName', '');
+ }
+
+ /**
+ * Sets the control property name to observe value changes that fires the callback request.
+ * @param string The control property name to observe value changes.
+ */
+ public function setPropertyName($value)
+ {
+ $this->setViewState('PropertyName', $value, '');
+ }
+
+ /**
+ * Sets the polling interval in seconds to observe property changes.
+ * Default is 1 second.
+ * @param float polling interval in seconds.
+ */
+ public function setInterval($value)
+ {
+ $this->setViewState('Interval', TPropertyValue::ensureFloat($value), 1);
+ }
+
+ /**
+ * @return float polling interval, 1 second default.
+ */
+ public function getInterval()
+ {
+ return $this->getViewState('Interval', 1);
+ }
+
+ /**
+ * Gets the decay rate between callbacks. Default is 0;
+ * @return float decay rate between callbacks.
+ */
+ public function getDecayRate()
+ {
+ return $this->getViewState('Decay', 0);
+ }
+
+ /**
+ * Sets the decay rate between callback. Default is 0;
+ * @param float decay rate between callbacks.
+ */
+ public function setDecayRate($value)
+ {
+ $decay = TPropertyValue::ensureFloat($value);
+ if($decay < 0)
+ throw new TConfigurationException('callback_decay_be_not_negative', $this->getID());
+ $this->setViewState('Decay', $decay);
+ }
+
+ /**
+ * @return array list of timer options for client-side.
+ */
+ protected function getTriggerOptions()
+ {
+ $options = parent::getTriggerOptions();
+ $options['PropertyName'] = $this->getPropertyName();
+ $options['Interval'] = $this->getInterval();
+ $options['Decay'] = $this->getDecayRate();
+ return $options;
+ }
+
+ /**
+ * Registers the javascript code for initializing the active control.
+ * @param THtmlWriter the renderer.
+ */
+ public function render($writer)
+ {
+ parent::render($writer);
+ $this->getActiveControl()->registerCallbackClientScript(
+ $this->getClientClassName(), $this->getTriggerOptions());
+ }
+
+ /**
+ * @return string corresponding javascript class name for TEventTriggeredCallback.
+ */
+ protected function getClientClassName()
+ {
+ return 'Prado.WebUI.TValueTriggeredCallback';
+ }
+}
diff --git a/framework/Web/UI/TCachePageStatePersister.php b/framework/Web/UI/TCachePageStatePersister.php
index 486c87ca..34b9203a 100644
--- a/framework/Web/UI/TCachePageStatePersister.php
+++ b/framework/Web/UI/TCachePageStatePersister.php
@@ -1,200 +1,200 @@
-<?php
-/**
- * TCachePageStatePersister class file
- *
- * @author Qiang Xue <qiang.xue@gmail.com>
- * @link http://www.pradosoft.com/
- * @copyright Copyright &copy; 2005-2012 PradoSoft
- * @license http://www.pradosoft.com/license/
- * @version $Id$
- * @package System.Web.UI
- */
-
-/**
- * TCachePageStatePersister class
- *
- * TCachePageStatePersister implements a page state persistent method based on cache.
- * Page state are stored in cache (e.g. memcache, DB cache, etc.), and only a small token
- * is passed to the client side to identify the state. This greatly reduces the size of
- * the page state that needs to be transmitted between the server and the client. Of course,
- * this is at the cost of using server side resource.
- *
- * A cache module has to be loaded in order to use TCachePageStatePersister.
- * By default, TCachePageStatePersister will use the primary cache module.
- * A non-primary cache module can be used by setting {@link setCacheModuleID CacheModuleID}.
- * Any cache module, as long as it implements the interface {@link ICache}, may be used.
- * For example, one can use {@link TDbCache}, {@link TMemCache}, {@link TAPCCache}, etc.
- *
- * TCachePageStatePersister uses {@link setCacheTimeout CacheTimeout} to limit the data
- * that stores in cache.
- *
- * Since server resource is often limited, be cautious if you plan to use TCachePageStatePersister
- * for high-traffic Web pages. You may consider using a small {@link setCacheTimeout CacheTimeout}.
- *
- * There are a couple of ways to use TCachePageStatePersister.
- * One can override the page's {@link TPage::getStatePersister()} method and
- * create a TCachePageStatePersister instance there.
- * Or one can configure the pages to use TCachePageStatePersister in page configurations
- * as follows,
- * <code>
- * <pages StatePersisterClass="System.Web.UI.TCachePageStatePersister"
- * StatePersister.CacheModuleID="mycache"
- * StatePersister.CacheTimeout="3600" />
- * </code>
- * Note in the above, we use StatePersister.CacheModuleID to configure the cache module ID
- * for the TCachePageStatePersister instance.
- *
- * The above configuration will affect the pages under the directory containing
- * this configuration and all its subdirectories.
- * To configure individual pages to use TCachePageStatePersister, use
- * <code>
- * <pages>
- * <page id="PageID" StatePersisterClass="System.Web.UI.TCachePageStatePersister" />
- * </pages>
- * </code>
- *
- * @author Qiang Xue <qiang.xue@gmail.com>
- * @version $Id$
- * @package System.Web.UI
- * @since 3.1.1
- */
-class TCachePageStatePersister extends TComponent implements IPageStatePersister
-{
- private $_prefix='statepersister';
- private $_page;
- private $_cache=null;
- private $_cacheModuleID='';
- private $_timeout=1800;
-
- /**
- * @param TPage the page that this persister works for
- */
- public function getPage()
- {
- return $this->_page;
- }
-
- /**
- * @param TPage the page that this persister works for.
- */
- public function setPage(TPage $page)
- {
- $this->_page=$page;
- }
-
- /**
- * @return string the ID of the cache module.
- */
- public function getCacheModuleID()
- {
- return $this->_cacheModuleID;
- }
-
- /**
- * @param string the ID of the cache module. If not set, the primary cache module will be used.
- */
- public function setCacheModuleID($value)
- {
- $this->_cacheModuleID=$value;
- }
-
- /**
- * @return ICache the cache module being used for data storage
- */
- public function getCache()
- {
- if($this->_cache===null)
- {
- if($this->_cacheModuleID!=='')
- $cache=Prado::getApplication()->getModule($this->_cacheModuleID);
- else
- $cache=Prado::getApplication()->getCache();
- if($cache===null || !($cache instanceof ICache))
- {
- if($this->_cacheModuleID!=='')
- throw new TConfigurationException('cachepagestatepersister_cachemoduleid_invalid',$this->_cacheModuleID);
- else
- throw new TConfigurationException('cachepagestatepersister_cache_required');
- }
- $this->_cache=$cache;
- }
- return $this->_cache;
- }
-
- /**
- * @return integer the number of seconds in which the cached state will expire. Defaults to 1800.
- */
- public function getCacheTimeout()
- {
- return $this->_timeout;
- }
-
- /**
- * @param integer the number of seconds in which the cached state will expire. 0 means never expire.
- * @throws TInvalidDataValueException if the number is smaller than 0.
- */
- public function setCacheTimeout($value)
- {
- if(($value=TPropertyValue::ensureInteger($value))>=0)
- $this->_timeout=$value;
- else
- throw new TInvalidDataValueException('cachepagestatepersister_timeout_invalid');
- }
-
- /**
- * @return string prefix of cache variable name to avoid conflict with other cache data. Defaults to 'statepersister'.
- */
- public function getKeyPrefix()
- {
- return $this->_prefix;
- }
-
- /**
- * @param string prefix of cache variable name to avoid conflict with other cache data
- */
- public function setKeyPrefix($value)
- {
- $this->_prefix=$value;
- }
-
- /**
- * @param string micro timestamp when saving state occurs
- * @return string a key that is unique per user request
- */
- protected function calculateKey($timestamp)
- {
- return $this->getKeyPrefix().':'
- . $this->_page->getRequest()->getUserHostAddress()
- . $this->_page->getPagePath()
- . $timestamp;
- }
-
- /**
- * Saves state in cache.
- * @param mixed state to be stored
- */
- public function save($data)
- {
- $timestamp=(string)microtime(true);
- $key=$this->calculateKey($timestamp);
- $this->getCache()->add($key,$data,$this->_timeout);
- $this->_page->setClientState(TPageStateFormatter::serialize($this->_page,$timestamp));
- }
-
- /**
- * Loads page state from cache.
- * @return mixed the restored state
- * @throws THttpException if page state is corrupted
- */
- public function load()
- {
- if(($timestamp=TPageStateFormatter::unserialize($this->_page,$this->_page->getRequestClientState()))!==null)
- {
- $key=$this->calculateKey($timestamp);
- if(($data=$this->getCache()->get($key))!==false)
- return $data;
- }
- throw new THttpException(400,'cachepagestatepersister_pagestate_corrupted');
- }
-}
-
+<?php
+/**
+ * TCachePageStatePersister class file
+ *
+ * @author Qiang Xue <qiang.xue@gmail.com>
+ * @link http://www.pradosoft.com/
+ * @copyright Copyright &copy; 2005-2012 PradoSoft
+ * @license http://www.pradosoft.com/license/
+ * @version $Id$
+ * @package System.Web.UI
+ */
+
+/**
+ * TCachePageStatePersister class
+ *
+ * TCachePageStatePersister implements a page state persistent method based on cache.
+ * Page state are stored in cache (e.g. memcache, DB cache, etc.), and only a small token
+ * is passed to the client side to identify the state. This greatly reduces the size of
+ * the page state that needs to be transmitted between the server and the client. Of course,
+ * this is at the cost of using server side resource.
+ *
+ * A cache module has to be loaded in order to use TCachePageStatePersister.
+ * By default, TCachePageStatePersister will use the primary cache module.
+ * A non-primary cache module can be used by setting {@link setCacheModuleID CacheModuleID}.
+ * Any cache module, as long as it implements the interface {@link ICache}, may be used.
+ * For example, one can use {@link TDbCache}, {@link TMemCache}, {@link TAPCCache}, etc.
+ *
+ * TCachePageStatePersister uses {@link setCacheTimeout CacheTimeout} to limit the data
+ * that stores in cache.
+ *
+ * Since server resource is often limited, be cautious if you plan to use TCachePageStatePersister
+ * for high-traffic Web pages. You may consider using a small {@link setCacheTimeout CacheTimeout}.
+ *
+ * There are a couple of ways to use TCachePageStatePersister.
+ * One can override the page's {@link TPage::getStatePersister()} method and
+ * create a TCachePageStatePersister instance there.
+ * Or one can configure the pages to use TCachePageStatePersister in page configurations
+ * as follows,
+ * <code>
+ * <pages StatePersisterClass="System.Web.UI.TCachePageStatePersister"
+ * StatePersister.CacheModuleID="mycache"
+ * StatePersister.CacheTimeout="3600" />
+ * </code>
+ * Note in the above, we use StatePersister.CacheModuleID to configure the cache module ID
+ * for the TCachePageStatePersister instance.
+ *
+ * The above configuration will affect the pages under the directory containing
+ * this configuration and all its subdirectories.
+ * To configure individual pages to use TCachePageStatePersister, use
+ * <code>
+ * <pages>
+ * <page id="PageID" StatePersisterClass="System.Web.UI.TCachePageStatePersister" />
+ * </pages>
+ * </code>
+ *
+ * @author Qiang Xue <qiang.xue@gmail.com>
+ * @version $Id$
+ * @package System.Web.UI
+ * @since 3.1.1
+ */
+class TCachePageStatePersister extends TComponent implements IPageStatePersister
+{
+ private $_prefix='statepersister';
+ private $_page;
+ private $_cache=null;
+ private $_cacheModuleID='';
+ private $_timeout=1800;
+
+ /**
+ * @param TPage the page that this persister works for
+ */
+ public function getPage()
+ {
+ return $this->_page;
+ }
+
+ /**
+ * @param TPage the page that this persister works for.
+ */
+ public function setPage(TPage $page)
+ {
+ $this->_page=$page;
+ }
+
+ /**
+ * @return string the ID of the cache module.
+ */
+ public function getCacheModuleID()
+ {
+ return $this->_cacheModuleID;
+ }
+
+ /**
+ * @param string the ID of the cache module. If not set, the primary cache module will be used.
+ */
+ public function setCacheModuleID($value)
+ {
+ $this->_cacheModuleID=$value;
+ }
+
+ /**
+ * @return ICache the cache module being used for data storage
+ */
+ public function getCache()
+ {
+ if($this->_cache===null)
+ {
+ if($this->_cacheModuleID!=='')
+ $cache=Prado::getApplication()->getModule($this->_cacheModuleID);
+ else
+ $cache=Prado::getApplication()->getCache();
+ if($cache===null || !($cache instanceof ICache))
+ {
+ if($this->_cacheModuleID!=='')
+ throw new TConfigurationException('cachepagestatepersister_cachemoduleid_invalid',$this->_cacheModuleID);
+ else
+ throw new TConfigurationException('cachepagestatepersister_cache_required');
+ }
+ $this->_cache=$cache;
+ }
+ return $this->_cache;
+ }
+
+ /**
+ * @return integer the number of seconds in which the cached state will expire. Defaults to 1800.
+ */
+ public function getCacheTimeout()
+ {
+ return $this->_timeout;
+ }
+
+ /**
+ * @param integer the number of seconds in which the cached state will expire. 0 means never expire.
+ * @throws TInvalidDataValueException if the number is smaller than 0.
+ */
+ public function setCacheTimeout($value)
+ {
+ if(($value=TPropertyValue::ensureInteger($value))>=0)
+ $this->_timeout=$value;
+ else
+ throw new TInvalidDataValueException('cachepagestatepersister_timeout_invalid');
+ }
+
+ /**
+ * @return string prefix of cache variable name to avoid conflict with other cache data. Defaults to 'statepersister'.
+ */
+ public function getKeyPrefix()
+ {
+ return $this->_prefix;
+ }
+
+ /**
+ * @param string prefix of cache variable name to avoid conflict with other cache data
+ */
+ public function setKeyPrefix($value)
+ {
+ $this->_prefix=$value;
+ }
+
+ /**
+ * @param string micro timestamp when saving state occurs
+ * @return string a key that is unique per user request
+ */
+ protected function calculateKey($timestamp)
+ {
+ return $this->getKeyPrefix().':'
+ . $this->_page->getRequest()->getUserHostAddress()
+ . $this->_page->getPagePath()
+ . $timestamp;
+ }
+
+ /**
+ * Saves state in cache.
+ * @param mixed state to be stored
+ */
+ public function save($data)
+ {
+ $timestamp=(string)microtime(true);
+ $key=$this->calculateKey($timestamp);
+ $this->getCache()->add($key,$data,$this->_timeout);
+ $this->_page->setClientState(TPageStateFormatter::serialize($this->_page,$timestamp));
+ }
+
+ /**
+ * Loads page state from cache.
+ * @return mixed the restored state
+ * @throws THttpException if page state is corrupted
+ */
+ public function load()
+ {
+ if(($timestamp=TPageStateFormatter::unserialize($this->_page,$this->_page->getRequestClientState()))!==null)
+ {
+ $key=$this->calculateKey($timestamp);
+ if(($data=$this->getCache()->get($key))!==false)
+ return $data;
+ }
+ throw new THttpException(400,'cachepagestatepersister_pagestate_corrupted');
+ }
+}
+
diff --git a/framework/Web/UI/TCompositeControl.php b/framework/Web/UI/TCompositeControl.php
index 285a8129..e7766ab8 100644
--- a/framework/Web/UI/TCompositeControl.php
+++ b/framework/Web/UI/TCompositeControl.php
@@ -1,38 +1,38 @@
-<?php
-/**
- * TCompositeControl class file.
- *
- * @author Qiang Xue <qiang.xue@gmail.com>
- * @link http://www.pradosoft.com/
+<?php
+/**
+ * TCompositeControl class file.
+ *
+ * @author Qiang Xue <qiang.xue@gmail.com>
+ * @link http://www.pradosoft.com/
* @copyright Copyright &copy; 2005-2012 PradoSoft
- * @license http://www.pradosoft.com/license/
- * @version $Id$
- * @package System.Web.UI
- */
-
-/**
- * TCompositeControl class.
- * TCompositeControl is the base class for controls that are composed
- * by other controls.
- *
- * @author Qiang Xue <qiang.xue@gmail.com>
- * @version $Id$
- * @package System.Web.UI
- * @since 3.0
- */
-class TCompositeControl extends TControl implements INamingContainer
-{
- /**
- * Performs the OnInit step for the control and all its child controls.
- * This method overrides the parent implementation
- * by ensuring child controls are created first.
- * Only framework developers should use this method.
- * @param TControl the naming container control
- */
- protected function initRecursive($namingContainer=null)
- {
- $this->ensureChildControls();
- parent::initRecursive($namingContainer);
- }
-}
-
+ * @license http://www.pradosoft.com/license/
+ * @version $Id$
+ * @package System.Web.UI
+ */
+
+/**
+ * TCompositeControl class.
+ * TCompositeControl is the base class for controls that are composed
+ * by other controls.
+ *
+ * @author Qiang Xue <qiang.xue@gmail.com>
+ * @version $Id$
+ * @package System.Web.UI
+ * @since 3.0
+ */
+class TCompositeControl extends TControl implements INamingContainer
+{
+ /**
+ * Performs the OnInit step for the control and all its child controls.
+ * This method overrides the parent implementation
+ * by ensuring child controls are created first.
+ * Only framework developers should use this method.
+ * @param TControl the naming container control
+ */
+ protected function initRecursive($namingContainer=null)
+ {
+ $this->ensureChildControls();
+ parent::initRecursive($namingContainer);
+ }
+}
+
diff --git a/framework/Web/UI/TControl.php b/framework/Web/UI/TControl.php
index 316098a1..2adabb55 100644
--- a/framework/Web/UI/TControl.php
+++ b/framework/Web/UI/TControl.php
@@ -1,2395 +1,2395 @@
-<?php
-/**
- * TControl, TControlCollection, TEventParameter and INamingContainer class file
- *
- * @author Qiang Xue <qiang.xue@gmail.com>
- * @link http://www.pradosoft.com/
- * @copyright Copyright &copy; 2005-2012 PradoSoft
- * @license http://www.pradosoft.com/license/
- * @version $Id$
- * @package System.Web.UI
- */
-
-/**
- * Includes TAttributeCollection and TControlAdapter class
- */
-Prado::using('System.Collections.TAttributeCollection');
-Prado::using('System.Web.UI.TControlAdapter');
-
-/**
- * TControl class
- *
- * TControl is the base class for all components on a page hierarchy.
- * It implements the following features for UI-related functionalities:
- * - databinding feature
- * - parent and child relationship
- * - naming container and containee relationship
- * - viewstate and controlstate features
- * - rendering scheme
- * - control lifecycles
- *
- * A property can be data-bound with an expression. By calling {@link dataBind},
- * expressions bound to properties will be evaluated and the results will be
- * set to the corresponding properties.
- *
- * Parent and child relationship determines how the presentation of controls are
- * enclosed within each other. A parent will determine where to place
- * the presentation of its child controls. For example, a TPanel will enclose
- * all its child controls' presentation within a div html tag. A control's parent
- * can be obtained via {@link getParent Parent} property, and its
- * {@link getControls Controls} property returns a list of the control's children,
- * including controls and static texts. The property can be manipulated
- * like an array for adding or removing a child (see {@link TList} for more details).
- *
- * A naming container control implements INamingContainer and ensures that
- * its containee controls can be differentiated by their ID property values.
- * Naming container and containee realtionship specifies a protocol to uniquely
- * identify an arbitrary control on a page hierarchy by an ID path (concatenation
- * of all naming containers' IDs and the target control's ID).
- *
- * Viewstate and controlstate are two approaches to preserve state across
- * page postback requests. ViewState is mainly related with UI specific state
- * and can be disabled if not needed. ControlState represents crucial logic state
- * and cannot be disabled.
- *
- * A control is rendered via its {@link render()} method (the method is invoked
- * by the framework.) Descendant control classes may override this method for
- * customized rendering. By default, {@link render()} invokes {@link renderChildren()}
- * which is responsible for rendering of children of the control.
- * Control's {@link getVisible Visible} property governs whether the control
- * should be rendered or not.
- *
- * Each control on a page will undergo a series of lifecycles, including
- * control construction, Init, Load, PreRender, Render, and OnUnload.
- * They work together with page lifecycles to process a page request.
- *
- * @author Qiang Xue <qiang.xue@gmail.com>
- * @version $Id$
- * @package System.Web.UI
- * @since 3.0
- */
-class TControl extends TApplicationComponent implements IRenderable, IBindable
-{
- /**
- * format of control ID
- */
- const ID_FORMAT='/^[a-zA-Z_]\\w*$/';
- /**
- * separator char between IDs in a UniqueID
- */
- const ID_SEPARATOR='$';
- /**
- * separator char between IDs in a ClientID
- */
- const CLIENT_ID_SEPARATOR='_';
- /**
- * prefix to an ID automatically generated
- */
- const AUTOMATIC_ID_PREFIX='ctl';
-
- /**
- * the stage of lifecycles that the control is currently at
- */
- const CS_CONSTRUCTED=0;
- const CS_CHILD_INITIALIZED=1;
- const CS_INITIALIZED=2;
- const CS_STATE_LOADED=3;
- const CS_LOADED=4;
- const CS_PRERENDERED=5;
-
- /**
- * State bits.
- */
- const IS_ID_SET=0x01;
- const IS_DISABLE_VIEWSTATE=0x02;
- const IS_SKIN_APPLIED=0x04;
- const IS_STYLESHEET_APPLIED=0x08;
- const IS_DISABLE_THEMING=0x10;
- const IS_CHILD_CREATED=0x20;
- const IS_CREATING_CHILD=0x40;
-
- /**
- * Indexes for the rare fields.
- * In order to save memory, rare fields will only be created if they are needed.
- */
- const RF_CONTROLS=0; // child controls
- const RF_CHILD_STATE=1; // child state field
- const RF_NAMED_CONTROLS=2; // list of controls whose namingcontainer is this control
- const RF_NAMED_CONTROLS_ID=3; // counter for automatic id
- const RF_SKIN_ID=4; // skin ID
- const RF_DATA_BINDINGS=5; // data bindings
- const RF_EVENTS=6; // event handlers
- const RF_CONTROLSTATE=7; // controlstate
- const RF_NAMED_OBJECTS=8; // controls declared with ID on template
- const RF_ADAPTER=9; // adapter
- const RF_AUTO_BINDINGS=10; // auto data bindings
-
- /**
- * @var string control ID
- */
- private $_id='';
- /**
- * @var string control unique ID
- */
- private $_uid;
- /**
- * @var TControl parent of the control
- */
- private $_parent;
- /**
- * @var TPage page that the control resides in
- */
- private $_page;
- /**
- * @var TControl naming container of the control
- */
- private $_namingContainer;
- /**
- * @var TTemplateControl control whose template contains the control
- */
- private $_tplControl;
- /**
- * @var array viewstate data
- */
- private $_viewState=array();
- /**
- * @var array temporary state (usually set in template)
- */
- private $_tempState=array();
- /**
- * @var boolean whether we should keep state in viewstate
- */
- private $_trackViewState=true;
- /**
- * @var integer the current stage of the control lifecycles
- */
- private $_stage=0;
- /**
- * @var integer representation of the state bits
- */
- private $_flags=0;
- /**
- * @var array a collection of rare control data
- */
- private $_rf=array();
-
- /**
- * Constructor.
- */
- public function __construct()
- {
- }
-
- /**
- * Returns a property value by name or a control by ID.
- * This overrides the parent implementation by allowing accessing
- * a control via its ID using the following syntax,
- * <code>
- * $menuBar=$this->menuBar;
- * </code>
- * Note, the control must be configured in the template
- * with explicit ID. If the name matches both a property and a control ID,
- * the control ID will take the precedence.
- *
- * @param string the property name or control ID
- * @return mixed the property value or the target control
- * @throws TInvalidOperationException if the property is not defined.
- * @see registerObject
- */
- public function __get($name)
- {
- if(isset($this->_rf[self::RF_NAMED_OBJECTS][$name]))
- return $this->_rf[self::RF_NAMED_OBJECTS][$name];
- else
- return parent::__get($name);
- }
-
- /**
- * @return boolean whether there is an adapter for this control
- */
- public function getHasAdapter()
- {
- return isset($this->_rf[self::RF_ADAPTER]);
- }
-
- /**
- * @return TControlAdapter control adapter. Null if not exists.
- */
- public function getAdapter()
- {
- return isset($this->_rf[self::RF_ADAPTER])?$this->_rf[self::RF_ADAPTER]:null;
- }
-
- /**
- * @param TControlAdapter control adapter
- */
- public function setAdapter(TControlAdapter $adapter)
- {
- $this->_rf[self::RF_ADAPTER]=$adapter;
- }
-
- /**
- * @return TControl the parent of this control
- */
- public function getParent()
- {
- return $this->_parent;
- }
-
- /**
- * @return TControl the naming container of this control
- */
- public function getNamingContainer()
- {
- if(!$this->_namingContainer && $this->_parent)
- {
- if($this->_parent instanceof INamingContainer)
- $this->_namingContainer=$this->_parent;
- else
- $this->_namingContainer=$this->_parent->getNamingContainer();
- }
- return $this->_namingContainer;
- }
-
- /**
- * @return TPage the page that contains this control
- */
- public function getPage()
- {
- if(!$this->_page)
- {
- if($this->_parent)
- $this->_page=$this->_parent->getPage();
- else if($this->_tplControl)
- $this->_page=$this->_tplControl->getPage();
- }
- return $this->_page;
- }
-
- /**
- * Sets the page for a control.
- * Only framework developers should use this method.
- * @param TPage the page that contains this control
- */
- public function setPage($page)
- {
- $this->_page=$page;
- }
-
- /**
- * Sets the control whose template contains this control.
- * Only framework developers should use this method.
- * @param TTemplateControl the control whose template contains this control
- */
- public function setTemplateControl($control)
- {
- $this->_tplControl=$control;
- }
-
- /**
- * @return TTemplateControl the control whose template contains this control
- */
- public function getTemplateControl()
- {
- if(!$this->_tplControl && $this->_parent)
- $this->_tplControl=$this->_parent->getTemplateControl();
- return $this->_tplControl;
- }
-
- /**
- * @return TTemplateControl the control whose template is loaded from
- * some external storage, such as file, db, and whose template ultimately
- * contains this control.
- */
- public function getSourceTemplateControl()
- {
- $control=$this;
- while(($control instanceof TControl) && ($control=$control->getTemplateControl())!==null)
- {
- if(($control instanceof TTemplateControl) && $control->getIsSourceTemplateControl())
- return $control;
- }
- return $this->getPage();
- }
-
- /**
- * Gets the lifecycle step the control is currently at.
- * This method should only be used by control developers.
- * @return integer the lifecycle step the control is currently at.
- * The value can be CS_CONSTRUCTED, CS_CHILD_INITIALIZED, CS_INITIALIZED,
- * CS_STATE_LOADED, CS_LOADED, CS_PRERENDERED.
- */
- protected function getControlStage()
- {
- return $this->_stage;
- }
-
- /**
- * Sets the lifecycle step the control is currently at.
- * This method should only be used by control developers.
- * @param integer the lifecycle step the control is currently at.
- * Valid values include CS_CONSTRUCTED, CS_CHILD_INITIALIZED, CS_INITIALIZED,
- * CS_STATE_LOADED, CS_LOADED, CS_PRERENDERED.
- */
- protected function setControlStage($value)
- {
- $this->_stage=$value;
- }
-
- /**
- * Returns the id of the control.
- * Control ID can be either manually set or automatically generated.
- * If $hideAutoID is true, automatically generated ID will be returned as an empty string.
- * @param boolean whether to hide automatically generated ID
- * @return string the ID of the control
- */
- public function getID($hideAutoID=true)
- {
- if($hideAutoID)
- return ($this->_flags & self::IS_ID_SET) ? $this->_id : '';
- else
- return $this->_id;
- }
-
- /**
- * @param string the new control ID. The value must consist of word characters [a-zA-Z0-9_] only
- * @throws TInvalidDataValueException if ID is in a bad format
- */
- public function setID($id)
- {
- if(!preg_match(self::ID_FORMAT,$id))
- throw new TInvalidDataValueException('control_id_invalid',get_class($this),$id);
- $this->_id=$id;
- $this->_flags |= self::IS_ID_SET;
- $this->clearCachedUniqueID($this instanceof INamingContainer);
- if($this->_namingContainer)
- $this->_namingContainer->clearNameTable();
- }
-
- /**
- * Returns a unique ID that identifies the control in the page hierarchy.
- * A unique ID is the contenation of all naming container controls' IDs and the control ID.
- * These IDs are separated by '$' character.
- * Control users should not rely on the specific format of UniqueID, however.
- * @return string a unique ID that identifies the control in the page hierarchy
- */
- public function getUniqueID()
- {
- if($this->_uid==='' || $this->_uid===null) // need to build the UniqueID
- {
- $this->_uid=''; // set to not-null, so that clearCachedUniqueID() may take action
- if($namingContainer=$this->getNamingContainer())
- {
- if($this->getPage()===$namingContainer)
- return ($this->_uid=$this->_id);
- else if(($prefix=$namingContainer->getUniqueID())==='')
- return $this->_id;
- else
- return ($this->_uid=$prefix.self::ID_SEPARATOR.$this->_id);
- }
- else // no naming container
- return $this->_id;
- }
- else
- return $this->_uid;
- }
-
- /**
- * Sets input focus to this control.
- */
- public function focus()
- {
- $this->getPage()->setFocus($this);
- }
-
- /**
- * Returns the client ID of the control.
- * The client ID can be used to uniquely identify
- * the control in client-side scripts (such as JavaScript).
- * Do not rely on the explicit format of the return ID.
- * @return string the client ID of the control
- */
- public function getClientID()
- {
- return strtr($this->getUniqueID(),self::ID_SEPARATOR,self::CLIENT_ID_SEPARATOR);
- }
-
- /**
- * Converts a unique ID to a client ID.
- * @param string the unique ID of a control
- * @return string the client ID of the control
- */
- public static function convertUniqueIdToClientId($uniqueID)
- {
- return strtr($uniqueID,self::ID_SEPARATOR,self::CLIENT_ID_SEPARATOR);
- }
-
- /**
- * @return string the skin ID of this control, '' if not set
- */
- public function getSkinID()
- {
- return isset($this->_rf[self::RF_SKIN_ID])?$this->_rf[self::RF_SKIN_ID]:'';
- }
-
- /**
- * @param string the skin ID of this control
- * @throws TInvalidOperationException if the SkinID is set in a stage later than PreInit, or if the skin is applied already.
- */
- public function setSkinID($value)
- {
- if(($this->_flags & self::IS_SKIN_APPLIED) || $this->_stage>=self::CS_CHILD_INITIALIZED)
- throw new TInvalidOperationException('control_skinid_unchangeable',get_class($this));
- else
- $this->_rf[self::RF_SKIN_ID]=$value;
- }
-
- /**
- * @param string the skin ID of this control
- * @throws TInvalidOperationException if the SkinID is set in a stage later than PreInit, or if the skin is applied already.
- */
- public function getIsSkinApplied()
- {
- return ($this->_flags & self::IS_SKIN_APPLIED);
- }
-
- /**
- * @return boolean whether theming is enabled for this control.
- * The theming is enabled if the control and all its parents have it enabled.
- */
- public function getEnableTheming()
- {
- if($this->_flags & self::IS_DISABLE_THEMING)
- return false;
- else
- return $this->_parent?$this->_parent->getEnableTheming():true;
- }
-
- /**
- * @param boolean whether to enable theming
- * @throws TInvalidOperationException if this method is invoked after OnPreInit
- */
- public function setEnableTheming($value)
- {
- if($this->_stage>=self::CS_CHILD_INITIALIZED)
- throw new TInvalidOperationException('control_enabletheming_unchangeable',get_class($this),$this->getUniqueID());
- else if(TPropertyValue::ensureBoolean($value))
- $this->_flags &= ~self::IS_DISABLE_THEMING;
- else
- $this->_flags |= self::IS_DISABLE_THEMING;
- }
-
- /**
- * Returns custom data associated with this control.
- * A control may be associated with some custom data for various purposes.
- * For example, a button may be associated with a string to identify itself
- * in a generic OnClick event handler.
- * @return mixed custom data associated with this control. Defaults to null.
- */
- public function getCustomData()
- {
- return $this->getViewState('CustomData',null);
- }
-
- /**
- * Associates custom data with this control.
- * Note, the custom data must be serializable and unserializable.
- * @param mixed custom data
- */
- public function setCustomData($value)
- {
- $this->setViewState('CustomData',$value,null);
- }
-
- /**
- * @return boolean whether the control has child controls
- */
- public function getHasControls()
- {
- return isset($this->_rf[self::RF_CONTROLS]) && $this->_rf[self::RF_CONTROLS]->getCount()>0;
- }
-
- /**
- * @return TControlCollection the child control collection
- */
- public function getControls()
- {
- if(!isset($this->_rf[self::RF_CONTROLS]))
- $this->_rf[self::RF_CONTROLS]=$this->createControlCollection();
- return $this->_rf[self::RF_CONTROLS];
- }
-
- /**
- * Creates a control collection object that is to be used to hold child controls
- * @return TControlCollection control collection
- * @see getControls
- */
- protected function createControlCollection()
- {
- return $this->getAllowChildControls()?new TControlCollection($this):new TEmptyControlCollection($this);
- }
-
- /**
- * Checks if a control is visible.
- * If parent check is required, then a control is visible only if the control
- * and all its ancestors are visible.
- * @param boolean whether the parents should also be checked if visible
- * @return boolean whether the control is visible (default=true).
- */
- public function getVisible($checkParents=true)
- {
- if($checkParents)
- {
- for($control=$this;$control;$control=$control->_parent)
- if(!$control->getVisible(false))
- return false;
- return true;
- }
- else
- return $this->getViewState('Visible',true);
- }
-
- /**
- * @param boolean whether the control is visible
- */
- public function setVisible($value)
- {
- $this->setViewState('Visible',TPropertyValue::ensureBoolean($value),true);
- }
-
- /**
- * Returns a value indicating whether the control is enabled.
- * A control is enabled if it allows client user interaction.
- * If $checkParents is true, all parent controls will be checked,
- * and unless they are all enabled, false will be returned.
- * The property Enabled is mainly used for {@link TWebControl}
- * derived controls.
- * @param boolean whether the parents should also be checked enabled
- * @return boolean whether the control is enabled.
- */
- public function getEnabled($checkParents=false)
- {
- if($checkParents)
- {
- for($control=$this;$control;$control=$control->_parent)
- if(!$control->getViewState('Enabled',true))
- return false;
- return true;
- }
- else
- return $this->getViewState('Enabled',true);
- }
-
- /**
- * @param boolean whether the control is to be enabled.
- */
- public function setEnabled($value)
- {
- $this->setViewState('Enabled',TPropertyValue::ensureBoolean($value),true);
- }
-
- /**
- * @return boolean whether the control has custom attributes
- */
- public function getHasAttributes()
- {
- if($attributes=$this->getViewState('Attributes',null))
- return $attributes->getCount()>0;
- else
- return false;
- }
-
- /**
- * Returns the list of custom attributes.
- * Custom attributes are name-value pairs that may be rendered
- * as HTML tags' attributes.
- * @return TAttributeCollection the list of custom attributes
- */
- public function getAttributes()
- {
- if($attributes=$this->getViewState('Attributes',null))
- return $attributes;
- else
- {
- $attributes=new TAttributeCollection;
- $this->setViewState('Attributes',$attributes,null);
- return $attributes;
- }
- }
-
- /**
- * @return boolean whether the named attribute exists
- */
- public function hasAttribute($name)
- {
- if($attributes=$this->getViewState('Attributes',null))
- return $attributes->contains($name);
- else
- return false;
- }
-
- /**
- * @return string attribute value, null if attribute does not exist
- */
- public function getAttribute($name)
- {
- if($attributes=$this->getViewState('Attributes',null))
- return $attributes->itemAt($name);
- else
- return null;
- }
-
- /**
- * Sets a custom control attribute.
- * @param string attribute name
- * @param string value of the attribute
- */
- public function setAttribute($name,$value)
- {
- $this->getAttributes()->add($name,$value);
- }
-
- /**
- * Removes the named attribute.
- * @param string the name of the attribute to be removed.
- * @return string attribute value removed, null if attribute does not exist.
- */
- public function removeAttribute($name)
- {
- if($attributes=$this->getViewState('Attributes',null))
- return $attributes->remove($name);
- else
- return null;
- }
-
- /**
- * @return boolean whether viewstate is enabled
- */
- public function getEnableViewState($checkParents=false)
- {
- if($checkParents)
- {
- for($control=$this;$control!==null;$control=$control->getParent())
- if($control->_flags & self::IS_DISABLE_VIEWSTATE)
- return false;
- return true;
- }
- else
- return !($this->_flags & self::IS_DISABLE_VIEWSTATE);
- }
-
- /**
- * @param boolean set whether to enable viewstate
- */
- public function setEnableViewState($value)
- {
- if(TPropertyValue::ensureBoolean($value))
- $this->_flags &= ~self::IS_DISABLE_VIEWSTATE;
- else
- $this->_flags |= self::IS_DISABLE_VIEWSTATE;
- }
-
- /**
- * Returns a controlstate value.
- *
- * This function is mainly used in defining getter functions for control properties
- * that must be kept in controlstate.
- * @param string the name of the controlstate value to be returned
- * @param mixed the default value. If $key is not found in controlstate, $defaultValue will be returned
- * @return mixed the controlstate value corresponding to $key
- */
- protected function getControlState($key,$defaultValue=null)
- {
- return isset($this->_rf[self::RF_CONTROLSTATE][$key])?$this->_rf[self::RF_CONTROLSTATE][$key]:$defaultValue;
- }
-
- /**
- * Sets a controlstate value.
- *
- * This function is very useful in defining setter functions for control properties
- * that must be kept in controlstate.
- * Make sure that the controlstate value must be serializable and unserializable.
- * @param string the name of the controlstate value
- * @param mixed the controlstate value to be set
- * @param mixed default value. If $value===$defaultValue, the item will be cleared from controlstate
- */
- protected function setControlState($key,$value,$defaultValue=null)
- {
- if($value===$defaultValue)
- unset($this->_rf[self::RF_CONTROLSTATE][$key]);
- else
- $this->_rf[self::RF_CONTROLSTATE][$key]=$value;
- }
-
- /**
- * Clears a controlstate value.
- * @param string the name of the controlstate value to be cleared
- */
- protected function clearControlState($key)
- {
- unset($this->_rf[self::RF_CONTROLSTATE][$key]);
- }
-
- /**
- * Sets a value indicating whether we should keep data in viewstate.
- * When it is false, data saved via setViewState() will not be persisted.
- * By default, it is true, meaning data will be persisted across postbacks.
- * @param boolean whether data should be persisted
- */
- public function trackViewState($enabled)
- {
- $this->_trackViewState=TPropertyValue::ensureBoolean($enabled);
- }
-
- /**
- * Returns a viewstate value.
- *
- * This function is very useful in defining getter functions for component properties
- * that must be kept in viewstate.
- * @param string the name of the viewstate value to be returned
- * @param mixed the default value. If $key is not found in viewstate, $defaultValue will be returned
- * @return mixed the viewstate value corresponding to $key
- */
- public function getViewState($key,$defaultValue=null)
- {
- if(isset($this->_viewState[$key]))
- return $this->_viewState[$key]!==null?$this->_viewState[$key]:$defaultValue;
- else if(isset($this->_tempState[$key]))
- {
- if(is_object($this->_tempState[$key]) && $this->_trackViewState)
- $this->_viewState[$key]=$this->_tempState[$key];
- return $this->_tempState[$key];
- }
- else
- return $defaultValue;
- }
-
- /**
- * Sets a viewstate value.
- *
- * This function is very useful in defining setter functions for control properties
- * that must be kept in viewstate.
- * Make sure that the viewstate value must be serializable and unserializable.
- * @param string the name of the viewstate value
- * @param mixed the viewstate value to be set
- * @param mixed default value. If $value===$defaultValue, the item will be cleared from the viewstate.
- */
- public function setViewState($key,$value,$defaultValue=null)
- {
- if($this->_trackViewState)
- {
- $this->_viewState[$key]=$value;
- unset($this->_tempState[$key]);
- }
- else
- {
- unset($this->_viewState[$key]);
- $this->_tempState[$key]=$value;
- }
- }
-
- /**
- * Clears a viewstate value.
- * @param string the name of the viewstate value to be cleared
- */
- public function clearViewState($key)
- {
- unset($this->_viewState[$key]);
- unset($this->_tempState[$key]);
- }
-
- /**
- * Sets up the binding between a property (or property path) and an expression.
- * The context of the expression is the template control (or the control itself if it is a page).
- * @param string the property name, or property path
- * @param string the expression
- */
- public function bindProperty($name,$expression)
- {
- $this->_rf[self::RF_DATA_BINDINGS][$name]=$expression;
- }
-
- /**
- * Breaks the binding between a property (or property path) and an expression.
- * @param string the property name (or property path)
- */
- public function unbindProperty($name)
- {
- unset($this->_rf[self::RF_DATA_BINDINGS][$name]);
- }
-
- /**
- * Sets up the binding between a property (or property path) and an expression.
- * Unlike regular databinding, the expression bound by this method
- * is automatically evaluated during {@link prerenderRecursive()}.
- * The context of the expression is the template control (or the control itself if it is a page).
- * @param string the property name, or property path
- * @param string the expression
- */
- public function autoBindProperty($name,$expression)
- {
- $this->_rf[self::RF_AUTO_BINDINGS][$name]=$expression;
- }
-
- /**
- * Performs the databinding for this control.
- */
- public function dataBind()
- {
- $this->dataBindProperties();
- $this->onDataBinding(null);
- $this->dataBindChildren();
- }
-
- /**
- * Databinding properties of the control.
- */
- protected function dataBindProperties()
- {
- Prado::trace("Data bind properties",'System.Web.UI.TControl');
- if(isset($this->_rf[self::RF_DATA_BINDINGS]))
- {
- if(($context=$this->getTemplateControl())===null)
- $context=$this;
- foreach($this->_rf[self::RF_DATA_BINDINGS] as $property=>$expression)
- $this->setSubProperty($property,$context->evaluateExpression($expression));
- }
- }
-
- /**
- * Auto databinding properties of the control.
- */
- protected function autoDataBindProperties()
- {
- if(isset($this->_rf[self::RF_AUTO_BINDINGS]))
- {
- if(($context=$this->getTemplateControl())===null)
- $context=$this;
- foreach($this->_rf[self::RF_AUTO_BINDINGS] as $property=>$expression)
- $this->setSubProperty($property,$context->evaluateExpression($expression));
- }
- }
-
- /**
- * Databinding child controls.
- */
- protected function dataBindChildren()
- {
- Prado::trace("dataBindChildren()",'System.Web.UI.TControl');
- if(isset($this->_rf[self::RF_CONTROLS]))
- {
- foreach($this->_rf[self::RF_CONTROLS] as $control)
- if($control instanceof IBindable)
- $control->dataBind();
- }
- }
-
- /**
- * @return boolean whether child controls have been created
- */
- final protected function getChildControlsCreated()
- {
- return ($this->_flags & self::IS_CHILD_CREATED)!==0;
- }
-
- /**
- * Sets a value indicating whether child controls are created.
- * If false, any existing child controls will be cleared up.
- * @param boolean whether child controls are created
- */
- final protected function setChildControlsCreated($value)
- {
- if($value)
- $this->_flags |= self::IS_CHILD_CREATED;
- else
- {
- if($this->getHasControls() && ($this->_flags & self::IS_CHILD_CREATED))
- $this->getControls()->clear();
- $this->_flags &= ~self::IS_CHILD_CREATED;
- }
- }
-
- /**
- * Ensures child controls are created.
- * If child controls are not created yet, this method will invoke
- * {@link createChildControls} to create them.
- */
- public function ensureChildControls()
- {
- if(!($this->_flags & self::IS_CHILD_CREATED) && !($this->_flags & self::IS_CREATING_CHILD))
- {
- try
- {
- $this->_flags |= self::IS_CREATING_CHILD;
- if(isset($this->_rf[self::RF_ADAPTER]))
- $this->_rf[self::RF_ADAPTER]->createChildControls();
- else
- $this->createChildControls();
- $this->_flags &= ~self::IS_CREATING_CHILD;
- $this->_flags |= self::IS_CHILD_CREATED;
- }
- catch(Exception $e)
- {
- $this->_flags &= ~self::IS_CREATING_CHILD;
- $this->_flags |= self::IS_CHILD_CREATED;
- throw $e;
- }
- }
- }
-
- /**
- * Creates child controls.
- * This method can be overriden for controls who want to have their controls.
- * Do not call this method directly. Instead, call {@link ensureChildControls}
- * to ensure child controls are created only once.
- */
- public function createChildControls()
- {
- }
-
- /**
- * Finds a control by ID path within the current naming container.
- * The current naming container is either the control itself
- * if it implements {@link INamingContainer} or the control's naming container.
- * The ID path is an ID sequence separated by {@link TControl::ID_SEPARATOR}.
- * For example, 'Repeater1.Item1.Button1' looks for a control with ID 'Button1'
- * whose naming container is 'Item1' whose naming container is 'Repeater1'.
- * @param string ID of the control to be looked up
- * @return TControl|null the control found, null if not found
- * @throws TInvalidDataValueException if a control's ID is found not unique within its naming container.
- */
- public function findControl($id)
- {
- $id=strtr($id,'.',self::ID_SEPARATOR);
- $container=($this instanceof INamingContainer)?$this:$this->getNamingContainer();
- if(!$container || !$container->getHasControls())
- return null;
- if(!isset($container->_rf[self::RF_NAMED_CONTROLS]))
- {
- $container->_rf[self::RF_NAMED_CONTROLS]=array();
- $container->fillNameTable($container,$container->_rf[self::RF_CONTROLS]);
- }
- if(($pos=strpos($id,self::ID_SEPARATOR))===false)
- return isset($container->_rf[self::RF_NAMED_CONTROLS][$id])?$container->_rf[self::RF_NAMED_CONTROLS][$id]:null;
- else
- {
- $cid=substr($id,0,$pos);
- $sid=substr($id,$pos+1);
- if(isset($container->_rf[self::RF_NAMED_CONTROLS][$cid]))
- return $container->_rf[self::RF_NAMED_CONTROLS][$cid]->findControl($sid);
- else
- return null;
- }
- }
-
- /**
- * Finds all child and grand-child controls that are of the specified type.
- * @param string the class name
- * @param boolean whether the type comparison is strict or not. If false, controls of the parent classes of the specified class will also be returned.
- * @return array list of controls found
- */
- public function findControlsByType($type,$strict=true)
- {
- $controls=array();
- if($this->getHasControls())
- {
- foreach($this->_rf[self::RF_CONTROLS] as $control)
- {
- if(is_object($control) && (get_class($control)===$type || (!$strict && ($control instanceof $type))))
- $controls[]=$control;
- if(($control instanceof TControl) && $control->getHasControls())
- $controls=array_merge($controls,$control->findControlsByType($type,$strict));
- }
- }
- return $controls;
- }
-
- /**
- * Finds all child and grand-child controls with the specified ID.
- * Note, this method is different from {@link findControl} in that
- * it searches through all controls that have this control as the ancestor
- * while {@link findcontrol} only searches through controls that have this
- * control as the direct naming container.
- * @param string the ID being looked for
- * @return array list of controls found
- */
- public function findControlsByID($id)
- {
- $controls=array();
- if($this->getHasControls())
- {
- foreach($this->_rf[self::RF_CONTROLS] as $control)
- {
- if($control instanceof TControl)
- {
- if($control->_id===$id)
- $controls[]=$control;
- $controls=array_merge($controls,$control->findControlsByID($id));
- }
- }
- }
- return $controls;
- }
-
- /**
- * Resets the control as a naming container.
- * Only framework developers should use this method.
- */
- public function clearNamingContainer()
- {
- unset($this->_rf[self::RF_NAMED_CONTROLS_ID]);
- $this->clearNameTable();
- }
-
- /**
- * Registers an object by a name.
- * A registered object can be accessed like a public member variable.
- * This method should only be used by framework and control developers.
- * @param string name of the object
- * @param object object to be declared
- * @see __get
- */
- public function registerObject($name,$object)
- {
- if(isset($this->_rf[self::RF_NAMED_OBJECTS][$name]))
- throw new TInvalidOperationException('control_object_reregistered',$name);
- $this->_rf[self::RF_NAMED_OBJECTS][$name]=$object;
- }
-
- /**
- * Unregisters an object by name.
- * @param string name of the object
- * @see registerObject
- */
- public function unregisterObject($name)
- {
- unset($this->_rf[self::RF_NAMED_OBJECTS][$name]);
- }
-
- /**
- * @return boolean whether an object has been registered with the name
- * @see registerObject
- */
- public function isObjectRegistered($name)
- {
- return isset($this->_rf[self::RF_NAMED_OBJECTS][$name]);
- }
-
- /**
- * @return boolean true if the child control has been initialized.
- */
- public function getHasChildInitialized()
- {
- return $this->getControlStage() >= self::CS_CHILD_INITIALIZED;
- }
-
- /**
- * @return boolean true if the onInit event has raised.
- */
- public function getHasInitialized()
- {
- return $this->getControlStage() >= self::CS_INITIALIZED;
- }
-
- /**
- * @return boolean true if the control has loaded post data.
- */
- public function getHasLoadedPostData()
- {
- return $this->getControlStage() >= self::CS_STATE_LOADED;
- }
-
- /**
- * @return boolean true if the onLoad event has raised.
- */
- public function getHasLoaded()
- {
- return $this->getControlStage() >= self::CS_LOADED;
- }
-
- /**
- * @return boolean true if onPreRender event has raised.
- */
- public function getHasPreRendered()
- {
- return $this->getControlStage() >= self::CS_PRERENDERED;
- }
-
- /**
- * Returns the named registered object.
- * A component with explicit ID on a template will be registered to
- * the template owner. This method allows you to obtain this component
- * with the ID.
- * @return mixed the named registered object. Null if object is not found.
- */
- public function getRegisteredObject($name)
- {
- return isset($this->_rf[self::RF_NAMED_OBJECTS][$name])?$this->_rf[self::RF_NAMED_OBJECTS][$name]:null;
- }
-
- /**
- * @return boolean whether body contents are allowed for this control. Defaults to true.
- */
- public function getAllowChildControls()
- {
- return true;
- }
-
- /**
- * Adds the object instantiated on a template to the child control collection.
- * This method overrides the parent implementation.
- * Only framework developers and control developers should use this method.
- * @param string|TComponent text string or component parsed and instantiated in template
- * @see createdOnTemplate
- */
- public function addParsedObject($object)
- {
- $this->getControls()->add($object);
- }
-
- /**
- * Clears up the child state data.
- * After a control loads its state, those state that do not belong to
- * any existing child controls are stored as child state.
- * This method will remove these state.
- * Only frameworker developers and control developers should use this method.
- */
- final protected function clearChildState()
- {
- unset($this->_rf[self::RF_CHILD_STATE]);
- }
-
- /**
- * @param TControl the potential ancestor control
- * @return boolean if the control is a descendent (parent, parent of parent, etc.)
- * of the specified control
- */
- final protected function isDescendentOf($ancestor)
- {
- $control=$this;
- while($control!==$ancestor && $control->_parent)
- $control=$control->_parent;
- return $control===$ancestor;
- }
-
- /**
- * Adds a control into the child collection of the control.
- * Control lifecycles will be caught up during the addition.
- * Only framework developers should use this method.
- * @param TControl the new child control
- */
- public function addedControl($control)
- {
- if($control->_parent)
- $control->_parent->getControls()->remove($control);
- $control->_parent=$this;
- $control->_page=$this->getPage();
- $namingContainer=($this instanceof INamingContainer)?$this:$this->_namingContainer;
- if($namingContainer)
- {
- $control->_namingContainer=$namingContainer;
- if($control->_id==='')
- $control->generateAutomaticID();
- else
- $namingContainer->clearNameTable();
- $control->clearCachedUniqueID($control instanceof INamingContainer);
- }
-
- if($this->_stage>=self::CS_CHILD_INITIALIZED)
- {
- $control->initRecursive($namingContainer);
- if($this->_stage>=self::CS_STATE_LOADED)
- {
- if(isset($this->_rf[self::RF_CHILD_STATE][$control->_id]))
- {
- $state=$this->_rf[self::RF_CHILD_STATE][$control->_id];
- unset($this->_rf[self::RF_CHILD_STATE][$control->_id]);
- }
- else
- $state=null;
- $control->loadStateRecursive($state,!($this->_flags & self::IS_DISABLE_VIEWSTATE));
- if($this->_stage>=self::CS_LOADED)
- {
- $control->loadRecursive();
- if($this->_stage>=self::CS_PRERENDERED)
- $control->preRenderRecursive();
- }
- }
- }
- }
-
- /**
- * Removes a control from the child collection of the control.
- * Only framework developers should use this method.
- * @param TControl the child control removed
- */
- public function removedControl($control)
- {
- if($this->_namingContainer)
- $this->_namingContainer->clearNameTable();
- $control->unloadRecursive();
- $control->_parent=null;
- $control->_page=null;
- $control->_namingContainer=null;
- $control->_tplControl=null;
- //$control->_stage=self::CS_CONSTRUCTED;
- if(!($control->_flags & self::IS_ID_SET))
- $control->_id='';
- else
- unset($this->_rf[self::RF_NAMED_OBJECTS][$control->_id]);
- $control->clearCachedUniqueID(true);
- }
-
- /**
- * Performs the Init step for the control and all its child controls.
- * Only framework developers should use this method.
- * @param TControl the naming container control
- */
- protected function initRecursive($namingContainer=null)
- {
- $this->ensureChildControls();
- if($this->getHasControls())
- {
- if($this instanceof INamingContainer)
- $namingContainer=$this;
- $page=$this->getPage();
- foreach($this->_rf[self::RF_CONTROLS] as $control)
- {
- if($control instanceof TControl)
- {
- $control->_namingContainer=$namingContainer;
- $control->_page=$page;
- if($control->_id==='' && $namingContainer)
- $control->generateAutomaticID();
- $control->initRecursive($namingContainer);
- }
- }
- }
- if($this->_stage<self::CS_INITIALIZED)
- {
- $this->_stage=self::CS_CHILD_INITIALIZED;
- if(($page=$this->getPage()) && $this->getEnableTheming() && !($this->_flags & self::IS_SKIN_APPLIED))
- {
- $page->applyControlSkin($this);
- $this->_flags |= self::IS_SKIN_APPLIED;
- }
- if(isset($this->_rf[self::RF_ADAPTER]))
- $this->_rf[self::RF_ADAPTER]->onInit(null);
- else
- $this->onInit(null);
- $this->_stage=self::CS_INITIALIZED;
- }
- }
-
- /**
- * Performs the Load step for the control and all its child controls.
- * Only framework developers should use this method.
- */
- protected function loadRecursive()
- {
- if($this->_stage<self::CS_LOADED)
- {
- if(isset($this->_rf[self::RF_ADAPTER]))
- $this->_rf[self::RF_ADAPTER]->onLoad(null);
- else
- $this->onLoad(null);
- }
- if($this->getHasControls())
- {
- foreach($this->_rf[self::RF_CONTROLS] as $control)
- {
- if($control instanceof TControl)
- $control->loadRecursive();
- }
- }
- if($this->_stage<self::CS_LOADED)
- $this->_stage=self::CS_LOADED;
- }
-
- /**
- * Performs the PreRender step for the control and all its child controls.
- * Only framework developers should use this method.
- */
- protected function preRenderRecursive()
- {
- $this->autoDataBindProperties();
-
- if($this->getVisible(false))
- {
- if(isset($this->_rf[self::RF_ADAPTER]))
- $this->_rf[self::RF_ADAPTER]->onPreRender(null);
- else
- $this->onPreRender(null);
- if($this->getHasControls())
- {
- foreach($this->_rf[self::RF_CONTROLS] as $control)
- {
- if($control instanceof TControl)
- $control->preRenderRecursive();
- else if($control instanceof TCompositeLiteral)
- $control->evaluateDynamicContent();
- }
- }
- $this->addToPostDataLoader();
- }
- $this->_stage=self::CS_PRERENDERED;
- }
-
- /**
- * Add controls implementing IPostBackDataHandler to post data loaders.
- */
- protected function addToPostDataLoader()
- {
- if($this instanceof IPostBackDataHandler)
- $this->getPage()->registerPostDataLoader($this);
- }
-
- /**
- * Performs the Unload step for the control and all its child controls.
- * Only framework developers should use this method.
- */
- protected function unloadRecursive()
- {
- if(!($this->_flags & self::IS_ID_SET))
- $this->_id='';
- if($this->getHasControls())
- {
- foreach($this->_rf[self::RF_CONTROLS] as $control)
- if($control instanceof TControl)
- $control->unloadRecursive();
- }
- if(isset($this->_rf[self::RF_ADAPTER]))
- $this->_rf[self::RF_ADAPTER]->onUnload(null);
- else
- $this->onUnload(null);
- }
-
- /**
- * This method is invoked when the control enters 'OnInit' stage.
- * The method raises 'OnInit' event.
- * If you override this method, be sure to call the parent implementation
- * so that the event handlers can be invoked.
- * @param TEventParameter event parameter to be passed to the event handlers
- */
- public function onInit($param)
- {
- $this->raiseEvent('OnInit',$this,$param);
- }
-
- /**
- * This method is invoked when the control enters 'OnLoad' stage.
- * The method raises 'OnLoad' event.
- * If you override this method, be sure to call the parent implementation
- * so that the event handlers can be invoked.
- * @param TEventParameter event parameter to be passed to the event handlers
- */
- public function onLoad($param)
- {
- $this->raiseEvent('OnLoad',$this,$param);
- }
-
- /**
- * Raises 'OnDataBinding' event.
- * This method is invoked when {@link dataBind} is invoked.
- * @param TEventParameter event parameter to be passed to the event handlers
- */
- public function onDataBinding($param)
- {
- Prado::trace("onDataBinding()",'System.Web.UI.TControl');
- $this->raiseEvent('OnDataBinding',$this,$param);
- }
-
-
- /**
- * This method is invoked when the control enters 'OnUnload' stage.
- * The method raises 'OnUnload' event.
- * If you override this method, be sure to call the parent implementation
- * so that the event handlers can be invoked.
- * @param TEventParameter event parameter to be passed to the event handlers
- */
- public function onUnload($param)
- {
- $this->raiseEvent('OnUnload',$this,$param);
- }
-
- /**
- * This method is invoked when the control enters 'OnPreRender' stage.
- * The method raises 'OnPreRender' event.
- * If you override this method, be sure to call the parent implementation
- * so that the event handlers can be invoked.
- * @param TEventParameter event parameter to be passed to the event handlers
- */
- public function onPreRender($param)
- {
- $this->raiseEvent('OnPreRender',$this,$param);
- }
-
- /**
- * Invokes the parent's bubbleEvent method.
- * A control who wants to bubble an event must call this method in its onEvent method.
- * @param TControl sender of the event
- * @param TEventParameter event parameter
- * @see bubbleEvent
- */
- protected function raiseBubbleEvent($sender,$param)
- {
- $control=$this;
- while($control=$control->_parent)
- {
- if($control->bubbleEvent($sender,$param))
- break;
- }
- }
-
- /**
- * This method responds to a bubbled event.
- * This method should be overriden to provide customized response to a bubbled event.
- * Check the type of event parameter to determine what event is bubbled currently.
- * @param TControl sender of the event
- * @param TEventParameter event parameters
- * @return boolean true if the event bubbling is handled and no more bubbling.
- * @see raiseBubbleEvent
- */
- public function bubbleEvent($sender,$param)
- {
- return false;
- }
-
- /**
- * Broadcasts an event.
- * The event will be sent to all controls on the current page hierarchy.
- * If a control defines the event, the event will be raised for the control.
- * If a control implements {@link IBroadcastEventReceiver}, its
- * {@link IBroadcastEventReceiver::broadcastEventReceived broadcastEventReceived()} method will
- * be invoked which gives the control a chance to respond to the event.
- * For example, when broadcasting event 'OnClick', all controls having 'OnClick'
- * event will have this event raised, and all controls implementing
- * {@link IBroadcastEventReceiver} will also have its
- * {@link IBroadcastEventReceiver::broadcastEventReceived broadcastEventReceived()}
- * invoked.
- * @param string name of the broadcast event
- * @param TControl sender of this event
- * @param TEventParameter event parameter
- */
- public function broadcastEvent($name,$sender,$param)
- {
- $rootControl=(($page=$this->getPage())===null)?$this:$page;
- $rootControl->broadcastEventInternal($name,$sender,new TBroadcastEventParameter($name,$param));
- }
-
- /**
- * Recursively broadcasts an event.
- * This method should only be used by framework developers.
- * @param string name of the broadcast event
- * @param TControl sender of the event
- * @param TBroadcastEventParameter event parameter
- */
- private function broadcastEventInternal($name,$sender,$param)
- {
- if($this->hasEvent($name))
- $this->raiseEvent($name,$sender,$param->getParameter());
- if($this instanceof IBroadcastEventReceiver)
- $this->broadcastEventReceived($sender,$param);
- if($this->getHasControls())
- {
- foreach($this->_rf[self::RF_CONTROLS] as $control)
- {
- if($control instanceof TControl)
- $control->broadcastEventInternal($name,$sender,$param);
- }
- }
- }
-
- /**
- * Traverse the whole control hierarchy rooted at this control.
- * Callback function may be invoked for each control being visited.
- * A pre-callback is invoked before traversing child controls;
- * A post-callback is invoked after traversing child controls.
- * Callback functions can be global functions or class methods.
- * They must be of the following signature:
- * <code>
- * function callback_func($control,$param) {...}
- * </code>
- * where $control refers to the control being visited and $param
- * is the parameter that is passed originally when calling this traverse function.
- *
- * @param mixed parameter to be passed to callbacks for each control
- * @param callback callback invoked before traversing child controls. If null, it is ignored.
- * @param callback callback invoked after traversing child controls. If null, it is ignored.
- */
- protected function traverseChildControls($param,$preCallback=null,$postCallback=null)
- {
- if($preCallback!==null)
- call_user_func($preCallback,$this,$param);
- if($this->getHasControls())
- {
- foreach($this->_rf[self::RF_CONTROLS] as $control)
- {
- if($control instanceof TControl)
- {
- $control->traverseChildControls($param,$preCallback,$postCallback);
- }
- }
- }
- if($postCallback!==null)
- call_user_func($postCallback,$this,$param);
- }
-
- /**
- * Renders the control.
- * Only when the control is visible will the control be rendered.
- * @param THtmlWriter the writer used for the rendering purpose
- */
- public function renderControl($writer)
- {
- if($this instanceof IActiveControl || $this->getVisible(false))
- {
- if(isset($this->_rf[self::RF_ADAPTER]))
- $this->_rf[self::RF_ADAPTER]->render($writer);
- else
- $this->render($writer);
- }
- }
-
- /**
- * Renders the control.
- * This method is invoked by {@link renderControl} when the control is visible.
- * You can override this method to provide customized rendering of the control.
- * By default, the control simply renders all its child contents.
- * @param THtmlWriter the writer used for the rendering purpose
- */
- public function render($writer)
- {
- $this->renderChildren($writer);
- }
-
- /**
- * Renders the children of the control.
- * This method iterates through all child controls and static text strings
- * and renders them in order.
- * @param THtmlWriter the writer used for the rendering purpose
- */
- public function renderChildren($writer)
- {
- if($this->getHasControls())
- {
- foreach($this->_rf[self::RF_CONTROLS] as $control)
- {
- if(is_string($control))
- $writer->write($control);
- else if($control instanceof TControl)
- $control->renderControl($writer);
- else if($control instanceof IRenderable)
- $control->render($writer);
- }
- }
- }
-
- /**
- * This method is invoked when control state is to be saved.
- * You can override this method to do last step state saving.
- * Parent implementation must be invoked.
- */
- public function saveState()
- {
- }
-
- /**
- * This method is invoked right after the control has loaded its state.
- * You can override this method to initialize data from the control state.
- * Parent implementation must be invoked.
- */
- public function loadState()
- {
- }
-
- /**
- * Loads state (viewstate and controlstate) into a control and its children.
- * This method should only be used by framework developers.
- * @param array the collection of the state
- * @param boolean whether the viewstate should be loaded
- */
- protected function loadStateRecursive(&$state,$needViewState=true)
- {
- if(is_array($state))
- {
- // A null state means the stateful properties all take default values.
- // So if the state is enabled, we have to assign the null value.
- $needViewState=($needViewState && !($this->_flags & self::IS_DISABLE_VIEWSTATE));
- if(isset($state[1]))
- {
- $this->_rf[self::RF_CONTROLSTATE]=&$state[1];
- unset($state[1]);
- }
- else
- unset($this->_rf[self::RF_CONTROLSTATE]);
- if($needViewState)
- {
- if(isset($state[0]))
- $this->_viewState=&$state[0];
- else
- $this->_viewState=array();
- }
- unset($state[0]);
- if($this->getHasControls())
- {
- foreach($this->_rf[self::RF_CONTROLS] as $control)
- {
- if($control instanceof TControl)
- {
- if(isset($state[$control->_id]))
- {
- $control->loadStateRecursive($state[$control->_id],$needViewState);
- unset($state[$control->_id]);
- }
- }
- }
- }
- if(!empty($state))
- $this->_rf[self::RF_CHILD_STATE]=&$state;
- }
- $this->_stage=self::CS_STATE_LOADED;
- if(isset($this->_rf[self::RF_ADAPTER]))
- $this->_rf[self::RF_ADAPTER]->loadState();
- else
- $this->loadState();
- }
-
- /**
- * Saves all control state (viewstate and controlstate) as a collection.
- * This method should only be used by framework developers.
- * @param boolean whether the viewstate should be saved
- * @return array the collection of the control state (including its children's state).
- */
- protected function &saveStateRecursive($needViewState=true)
- {
- if(isset($this->_rf[self::RF_ADAPTER]))
- $this->_rf[self::RF_ADAPTER]->saveState();
- else
- $this->saveState();
- $needViewState=($needViewState && !($this->_flags & self::IS_DISABLE_VIEWSTATE));
- $state=array();
- if($this->getHasControls())
- {
- foreach($this->_rf[self::RF_CONTROLS] as $control)
- {
- if($control instanceof TControl)
- $state[$control->_id]=&$control->saveStateRecursive($needViewState);
- }
- }
- if($needViewState && !empty($this->_viewState))
- $state[0]=&$this->_viewState;
- if(isset($this->_rf[self::RF_CONTROLSTATE]))
- $state[1]=&$this->_rf[self::RF_CONTROLSTATE];
- return $state;
- }
-
- /**
- * Applies a stylesheet skin to a control.
- * @param TPage the page containing the control
- * @throws TInvalidOperationException if the stylesheet skin is applied already
- */
- public function applyStyleSheetSkin($page)
- {
- if($page && !($this->_flags & self::IS_STYLESHEET_APPLIED))
- {
- $page->applyControlStyleSheet($this);
- $this->_flags |= self::IS_STYLESHEET_APPLIED;
- }
- else if($this->_flags & self::IS_STYLESHEET_APPLIED)
- throw new TInvalidOperationException('control_stylesheet_applied',get_class($this));
- }
-
- /**
- * Clears the cached UniqueID.
- * If $recursive=true, all children's cached UniqueID will be cleared as well.
- * @param boolean whether the clearing is recursive.
- */
- private function clearCachedUniqueID($recursive)
- {
- if($recursive && $this->_uid!==null && isset($this->_rf[self::RF_CONTROLS]))
- {
- foreach($this->_rf[self::RF_CONTROLS] as $control)
- if($control instanceof TControl)
- $control->clearCachedUniqueID($recursive);
- }
- $this->_uid=null;
- }
-
- /**
- * Generates an automatic ID for the control.
- */
- private function generateAutomaticID()
- {
- $this->_flags &= ~self::IS_ID_SET;
- if(!isset($this->_namingContainer->_rf[self::RF_NAMED_CONTROLS_ID]))
- $this->_namingContainer->_rf[self::RF_NAMED_CONTROLS_ID]=0;
- $id=$this->_namingContainer->_rf[self::RF_NAMED_CONTROLS_ID]++;
- $this->_id=self::AUTOMATIC_ID_PREFIX . $id;
- $this->_namingContainer->clearNameTable();
- }
-
- /**
- * Clears the list of the controls whose IDs are managed by the specified naming container.
- */
- private function clearNameTable()
- {
- unset($this->_rf[self::RF_NAMED_CONTROLS]);
- }
-
- /**
- * Updates the list of the controls whose IDs are managed by the specified naming container.
- * @param TControl the naming container
- * @param TControlCollection list of controls
- * @throws TInvalidDataValueException if a control's ID is not unique within its naming container.
- */
- private function fillNameTable($container,$controls)
- {
- foreach($controls as $control)
- {
- if($control instanceof TControl)
- {
- if($control->_id!=='')
- {
- if(isset($container->_rf[self::RF_NAMED_CONTROLS][$control->_id]))
- throw new TInvalidDataValueException('control_id_nonunique',get_class($control),$control->_id);
- else
- $container->_rf[self::RF_NAMED_CONTROLS][$control->_id]=$control;
- }
- if(!($control instanceof INamingContainer) && $control->getHasControls())
- $this->fillNameTable($container,$control->_rf[self::RF_CONTROLS]);
- }
- }
- }
-}
-
-
-/**
- * TControlCollection class
- *
- * TControlCollection implements a collection that enables
- * controls to maintain a list of their child controls.
- *
- * @author Qiang Xue <qiang.xue@gmail.com>
- * @version $Id$
- * @package System.Web.UI
- * @since 3.0
- */
-class TControlCollection extends TList
-{
- /**
- * the control that owns this collection.
- * @var TControl
- */
- private $_o;
-
- /**
- * Constructor.
- * @param TControl the control that owns this collection.
- * @param boolean whether the list is read-only
- */
- public function __construct(TControl $owner,$readOnly=false)
- {
- $this->_o=$owner;
- parent::__construct(null,$readOnly);
- }
-
- /**
- * @return TControl the control that owns this collection.
- */
- protected function getOwner()
- {
- return $this->_o;
- }
-
- /**
- * Inserts an item at the specified position.
- * This overrides the parent implementation by performing additional
- * operations for each newly added child control.
- * @param integer the speicified position.
- * @param mixed new item
- * @throws TInvalidDataTypeException if the item to be inserted is neither a string nor a TControl.
- */
- public function insertAt($index,$item)
- {
- if($item instanceof TControl)
- {
- parent::insertAt($index,$item);
- $this->_o->addedControl($item);
- }
- else if(is_string($item) || ($item instanceof IRenderable))
- parent::insertAt($index,$item);
- else
- throw new TInvalidDataTypeException('controlcollection_control_required');
- }
-
- /**
- * Removes an item at the specified position.
- * This overrides the parent implementation by performing additional
- * cleanup work when removing a child control.
- * @param integer the index of the item to be removed.
- * @return mixed the removed item.
- */
- public function removeAt($index)
- {
- $item=parent::removeAt($index);
- if($item instanceof TControl)
- $this->_o->removedControl($item);
- return $item;
- }
-
- /**
- * Overrides the parent implementation by invoking {@link TControl::clearNamingContainer}
- */
- public function clear()
- {
- parent::clear();
- if($this->_o instanceof INamingContainer)
- $this->_o->clearNamingContainer();
- }
-}
-
-/**
- * TEmptyControlCollection class
- *
- * TEmptyControlCollection implements an empty control list that prohibits adding
- * controls to it. This is useful for controls that do not allow child controls.
- *
- * @author Qiang Xue <qiang.xue@gmail.com>
- * @version $Id$
- * @package System.Web.UI
- * @since 3.0
- */
-class TEmptyControlCollection extends TControlCollection
-{
- /**
- * Constructor.
- * @param TControl the control that owns this collection.
- */
- public function __construct(TControl $owner)
- {
- parent::__construct($owner,true);
- }
-
- /**
- * Inserts an item at the specified position.
- * This overrides the parent implementation by ignoring new addition.
- * @param integer the speicified position.
- * @param mixed new item
- */
- public function insertAt($index,$item)
- {
- if(!is_string($item)) // string is possible if property tag is used. we simply ignore it in this case
- parent::insertAt($index,$item); // this will generate an exception in parent implementation
- }
-}
-
-/**
- * INamingContainer interface.
- * INamingContainer marks a control as a naming container.
- *
- * @author Qiang Xue <qiang.xue@gmail.com>
- * @version $Id$
- * @package System.Web.UI
- * @since 3.0
- */
-interface INamingContainer
-{
-}
-
-/**
- * IPostBackEventHandler interface
- *
- * If a control wants to respond to postback event, it must implement this interface.
- *
- * @author Qiang Xue <qiang.xue@gmail.com>
- * @version $Id$
- * @package System.Web.UI
- * @since 3.0
- */
-interface IPostBackEventHandler
-{
- /**
- * Raises postback event.
- * The implementation of this function should raise appropriate event(s) (e.g. OnClick, OnCommand)
- * indicating the component is responsible for the postback event.
- * @param string the parameter associated with the postback event
- */
- public function raisePostBackEvent($param);
-}
-
-/**
- * IPostBackDataHandler interface
- *
- * If a control wants to load post data, it must implement this interface.
- *
- * @author Qiang Xue <qiang.xue@gmail.com>
- * @version $Id$
- * @package System.Web.UI
- * @since 3.0
- */
-interface IPostBackDataHandler
-{
- /**
- * Loads user input data.
- * The implementation of this function can use $values[$key] to get the user input
- * data that are meant for the particular control.
- * @param string the key that can be used to retrieve data from the input data collection
- * @param array the input data collection
- * @return boolean whether the data of the control has been changed
- */
- public function loadPostData($key,$values);
- /**
- * Raises postdata changed event.
- * The implementation of this function should raise appropriate event(s) (e.g. OnTextChanged)
- * indicating the control data is changed.
- */
- public function raisePostDataChangedEvent();
- /**
- * @return boolean whether postback causes the data change. Defaults to false for non-postback state.
- */
- public function getDataChanged();
-}
-
-
-/**
- * IValidator interface
- *
- * If a control wants to validate user input, it must implement this interface.
- *
- * @author Qiang Xue <qiang.xue@gmail.com>
- * @version $Id$
- * @package System.Web.UI
- * @since 3.0
- */
-interface IValidator
-{
- /**
- * Validates certain data.
- * The implementation of this function should validate certain data
- * (e.g. data entered into TTextBox control).
- * @return boolean whether the data passes the validation
- */
- public function validate();
- /**
- * @return boolean whether the previous {@link validate()} is successful.
- */
- public function getIsValid();
- /**
- * @param boolean whether the validator validates successfully
- */
- public function setIsValid($value);
- /**
- * @return string error message during last validate
- */
- public function getErrorMessage();
- /**
- * @param string error message for the validation
- */
- public function setErrorMessage($value);
-}
-
-
-/**
- * IValidatable interface
- *
- * If a control wants to be validated by a validator, it must implement this interface.
- *
- * @author Qiang Xue <qiang.xue@gmail.com>
- * @version $Id$
- * @package System.Web.UI
- * @since 3.0
- */
-interface IValidatable
-{
- /**
- * @return mixed the value of the property to be validated.
- */
- public function getValidationPropertyValue();
- /**
- * @return boolean wether this control's validators validated successfully (must default to true)
- */
- public function getIsValid();
- /**
- * @return boolean wether this control's validators validated successfully
- */
- public function setIsValid($value);
-}
-
-/**
- * IBroadcastEventReceiver interface
- *
- * If a control wants to check broadcast event, it must implement this interface.
- *
- * @author Qiang Xue <qiang.xue@gmail.com>
- * @version $Id$
- * @package System.Web.UI
- * @since 3.0
- */
-interface IBroadcastEventReceiver
-{
- /**
- * Handles broadcast event.
- * This method is invoked automatically when an event is broadcasted.
- * Within this method, you may check the event name given in
- * the event parameter to determine whether you should respond to
- * this event.
- * @param TControl sender of the event
- * @param TBroadCastEventParameter event parameter
- */
- public function broadcastEventReceived($sender,$param);
-}
-
-/**
- * ITheme interface.
- *
- * This interface must be implemented by theme.
- *
- * @author Qiang Xue <qiang.xue@gmail.com>
- * @version $Id$
- * @package System.Web.UI
- * @since 3.0
- */
-interface ITheme
-{
- /**
- * Applies this theme to the specified control.
- * @param TControl the control to be applied with this theme
- */
- public function applySkin($control);
-}
-
-/**
- * ITemplate interface
- *
- * ITemplate specifies the interface for classes encapsulating
- * parsed template structures.
- *
- * @author Qiang Xue <qiang.xue@gmail.com>
- * @version $Id$
- * @package System.Web.UI
- * @since 3.0
- */
-interface ITemplate
-{
- /**
- * Instantiates the template.
- * Content in the template will be instantiated as components and text strings
- * and passed to the specified parent control.
- * @param TControl the parent control
- */
- public function instantiateIn($parent);
-}
-
-/**
- * IButtonControl interface
- *
- * IButtonControl specifies the common properties and events that must
- * be implemented by a button control, such as {@link TButton}, {@link TLinkButton},
- * {@link TImageButton}.
- *
- * @author Qiang Xue <qiang.xue@gmail.com>
- * @version $Id$
- * @package System.Web.UI
- * @since 3.0
- */
-interface IButtonControl
-{
- /**
- * @return string caption of the button
- */
- public function getText();
-
- /**
- * @param string caption of the button
- */
- public function setText($value);
-
- /**
- * @return boolean whether postback event trigger by this button will cause input validation
- */
- public function getCausesValidation();
-
- /**
- * @param boolean whether postback event trigger by this button will cause input validation
- */
- public function setCausesValidation($value);
-
- /**
- * @return string the command name associated with the {@link onCommand OnCommand} event.
- */
- public function getCommandName();
-
- /**
- * @param string the command name associated with the {@link onCommand OnCommand} event.
- */
- public function setCommandName($value);
-
- /**
- * @return string the parameter associated with the {@link onCommand OnCommand} event
- */
- public function getCommandParameter();
-
- /**
- * @param string the parameter associated with the {@link onCommand OnCommand} event.
- */
- public function setCommandParameter($value);
-
- /**
- * @return string the group of validators which the button causes validation upon postback
- */
- public function getValidationGroup();
-
- /**
- * @param string the group of validators which the button causes validation upon postback
- */
- public function setValidationGroup($value);
-
- /**
- * Raises <b>OnClick</b> event.
- * @param TEventParameter event parameter to be passed to the event handlers
- */
- public function onClick($param);
-
- /**
- * Raises <b>OnCommand</b> event.
- * @param TCommandEventParameter event parameter to be passed to the event handlers
- */
- public function onCommand($param);
-
- /**
- * @param boolean set by a panel to register this button as the default button for the panel.
- */
- public function setIsDefaultButton($value);
-
- /**
- * @return boolean true if this button is registered as a default button for a panel.
- */
- public function getIsDefaultButton();
-}
-
-/**
- * ISurroundable interface
- *
- * Identifies controls that may create an additional surrounding tag. The id of the
- * tag can be obtained with {@link getSurroundingTagID}.
- *
- * @package System.Web.UI
- * @since 3.1.2
- */
-interface ISurroundable
-{
- /**
- * @return string the id of the embedding tag of the control or the control's clientID if not surrounded
- */
- public function getSurroundingTagID();
-}
-
-/**
- * TBroadcastEventParameter class
- *
- * TBroadcastEventParameter encapsulates the parameter data for
- * events that are broadcasted. The name of of the event is specified via
- * {@link setName Name} property while the event parameter is via
- * {@link setParameter Parameter} property.
- *
- * @author Qiang Xue <qiang.xue@gmail.com>
- * @version $Id$
- * @package System.Web.UI
- * @since 3.0
- */
-class TBroadcastEventParameter extends TEventParameter
-{
- private $_name;
- private $_param;
-
- /**
- * Constructor.
- * @param string name of the broadcast event
- * @param mixed parameter of the broadcast event
- */
- public function __construct($name='',$parameter=null)
- {
- $this->_name=$name;
- $this->_param=$parameter;
- }
-
- /**
- * @return string name of the broadcast event
- */
- public function getName()
- {
- return $this->_name;
- }
-
- /**
- * @param string name of the broadcast event
- */
- public function setName($value)
- {
- $this->_name=$value;
- }
-
- /**
- * @return mixed parameter of the broadcast event
- */
- public function getParameter()
- {
- return $this->_param;
- }
-
- /**
- * @param mixed parameter of the broadcast event
- */
- public function setParameter($value)
- {
- $this->_param=$value;
- }
-}
-
-/**
- * TCommandEventParameter class
- *
- * TCommandEventParameter encapsulates the parameter data for <b>Command</b>
- * event of button controls. You can access the name of the command via
- * {@link getCommandName CommandName} property, and the parameter carried
- * with the command via {@link getCommandParameter CommandParameter} property.
- *
- * @author Qiang Xue <qiang.xue@gmail.com>
- * @version $Id$
- * @package System.Web.UI
- * @since 3.0
- */
-class TCommandEventParameter extends TEventParameter
-{
- private $_name;
- private $_param;
-
- /**
- * Constructor.
- * @param string name of the command
- * @param string parameter of the command
- */
- public function __construct($name='',$parameter='')
- {
- $this->_name=$name;
- $this->_param=$parameter;
- }
-
- /**
- * @return string name of the command
- */
- public function getCommandName()
- {
- return $this->_name;
- }
-
- /**
- * @return string parameter of the command
- */
- public function getCommandParameter()
- {
- return $this->_param;
- }
-}
-
-
-/**
- * TCompositeLiteral class
- *
- * TCompositeLiteral is used internally by {@link TTemplate} for representing
- * consecutive static strings, expressions and statements.
- *
- * @author Qiang Xue <qiang.xue@gmail.com>
- * @version $Id$
- * @package System.Web.UI
- * @since 3.0
- */
-class TCompositeLiteral extends TComponent implements IRenderable, IBindable
-{
- const TYPE_EXPRESSION=0;
- const TYPE_STATEMENTS=1;
- const TYPE_DATABINDING=2;
- private $_container=null;
- private $_items=array();
- private $_expressions=array();
- private $_statements=array();
- private $_bindings=array();
-
- /**
- * Constructor.
- * @param array list of items to be represented by TCompositeLiteral
- */
- public function __construct($items)
- {
- $this->_items=array();
- $this->_expressions=array();
- $this->_statements=array();
- foreach($items as $id=>$item)
- {
- if(is_array($item))
- {
- if($item[0]===self::TYPE_EXPRESSION)
- $this->_expressions[$id]=$item[1];
- else if($item[0]===self::TYPE_STATEMENTS)
- $this->_statements[$id]=$item[1];
- else if($item[0]===self::TYPE_DATABINDING)
- $this->_bindings[$id]=$item[1];
- $this->_items[$id]='';
- }
- else
- $this->_items[$id]=$item;
- }
- }
-
- /**
- * @return TComponent container of this component. It serves as the evaluation context of expressions and statements.
- */
- public function getContainer()
- {
- return $this->_container;
- }
-
- /**
- * @param TComponent container of this component. It serves as the evaluation context of expressions and statements.
- */
- public function setContainer(TComponent $value)
- {
- $this->_container=$value;
- }
-
- /**
- * Evaluates the expressions and/or statements in the component.
- */
- public function evaluateDynamicContent()
- {
- $context=$this->_container===null?$this:$this->_container;
- foreach($this->_expressions as $id=>$expression)
- $this->_items[$id]=$context->evaluateExpression($expression);
- foreach($this->_statements as $id=>$statement)
- $this->_items[$id]=$context->evaluateStatements($statement);
- }
-
- /**
- * Performs databindings.
- * This method is required by {@link IBindable}
- */
- public function dataBind()
- {
- $context=$this->_container===null?$this:$this->_container;
- foreach($this->_bindings as $id=>$binding)
- $this->_items[$id]=$context->evaluateExpression($binding);
- }
-
- /**
- * Renders the content stored in this component.
- * This method is required by {@link IRenderable}
- * @param ITextWriter
- */
- public function render($writer)
- {
- $writer->write(implode('',$this->_items));
- }
-}
-
-?>
+<?php
+/**
+ * TControl, TControlCollection, TEventParameter and INamingContainer class file
+ *
+ * @author Qiang Xue <qiang.xue@gmail.com>
+ * @link http://www.pradosoft.com/
+ * @copyright Copyright &copy; 2005-2012 PradoSoft
+ * @license http://www.pradosoft.com/license/
+ * @version $Id$
+ * @package System.Web.UI
+ */
+
+/**
+ * Includes TAttributeCollection and TControlAdapter class
+ */
+Prado::using('System.Collections.TAttributeCollection');
+Prado::using('System.Web.UI.TControlAdapter');
+
+/**
+ * TControl class
+ *
+ * TControl is the base class for all components on a page hierarchy.
+ * It implements the following features for UI-related functionalities:
+ * - databinding feature
+ * - parent and child relationship
+ * - naming container and containee relationship
+ * - viewstate and controlstate features
+ * - rendering scheme
+ * - control lifecycles
+ *
+ * A property can be data-bound with an expression. By calling {@link dataBind},
+ * expressions bound to properties will be evaluated and the results will be
+ * set to the corresponding properties.
+ *
+ * Parent and child relationship determines how the presentation of controls are
+ * enclosed within each other. A parent will determine where to place
+ * the presentation of its child controls. For example, a TPanel will enclose
+ * all its child controls' presentation within a div html tag. A control's parent
+ * can be obtained via {@link getParent Parent} property, and its
+ * {@link getControls Controls} property returns a list of the control's children,
+ * including controls and static texts. The property can be manipulated
+ * like an array for adding or removing a child (see {@link TList} for more details).
+ *
+ * A naming container control implements INamingContainer and ensures that
+ * its containee controls can be differentiated by their ID property values.
+ * Naming container and containee realtionship specifies a protocol to uniquely
+ * identify an arbitrary control on a page hierarchy by an ID path (concatenation
+ * of all naming containers' IDs and the target control's ID).
+ *
+ * Viewstate and controlstate are two approaches to preserve state across
+ * page postback requests. ViewState is mainly related with UI specific state
+ * and can be disabled if not needed. ControlState represents crucial logic state
+ * and cannot be disabled.
+ *
+ * A control is rendered via its {@link render()} method (the method is invoked
+ * by the framework.) Descendant control classes may override this method for
+ * customized rendering. By default, {@link render()} invokes {@link renderChildren()}
+ * which is responsible for rendering of children of the control.
+ * Control's {@link getVisible Visible} property governs whether the control
+ * should be rendered or not.
+ *
+ * Each control on a page will undergo a series of lifecycles, including
+ * control construction, Init, Load, PreRender, Render, and OnUnload.
+ * They work together with page lifecycles to process a page request.
+ *
+ * @author Qiang Xue <qiang.xue@gmail.com>
+ * @version $Id$
+ * @package System.Web.UI
+ * @since 3.0
+ */
+class TControl extends TApplicationComponent implements IRenderable, IBindable
+{
+ /**
+ * format of control ID
+ */
+ const ID_FORMAT='/^[a-zA-Z_]\\w*$/';
+ /**
+ * separator char between IDs in a UniqueID
+ */
+ const ID_SEPARATOR='$';
+ /**
+ * separator char between IDs in a ClientID
+ */
+ const CLIENT_ID_SEPARATOR='_';
+ /**
+ * prefix to an ID automatically generated
+ */
+ const AUTOMATIC_ID_PREFIX='ctl';
+
+ /**
+ * the stage of lifecycles that the control is currently at
+ */
+ const CS_CONSTRUCTED=0;
+ const CS_CHILD_INITIALIZED=1;
+ const CS_INITIALIZED=2;
+ const CS_STATE_LOADED=3;
+ const CS_LOADED=4;
+ const CS_PRERENDERED=5;
+
+ /**
+ * State bits.
+ */
+ const IS_ID_SET=0x01;
+ const IS_DISABLE_VIEWSTATE=0x02;
+ const IS_SKIN_APPLIED=0x04;
+ const IS_STYLESHEET_APPLIED=0x08;
+ const IS_DISABLE_THEMING=0x10;
+ const IS_CHILD_CREATED=0x20;
+ const IS_CREATING_CHILD=0x40;
+
+ /**
+ * Indexes for the rare fields.
+ * In order to save memory, rare fields will only be created if they are needed.
+ */
+ const RF_CONTROLS=0; // child controls
+ const RF_CHILD_STATE=1; // child state field
+ const RF_NAMED_CONTROLS=2; // list of controls whose namingcontainer is this control
+ const RF_NAMED_CONTROLS_ID=3; // counter for automatic id
+ const RF_SKIN_ID=4; // skin ID
+ const RF_DATA_BINDINGS=5; // data bindings
+ const RF_EVENTS=6; // event handlers
+ const RF_CONTROLSTATE=7; // controlstate
+ const RF_NAMED_OBJECTS=8; // controls declared with ID on template
+ const RF_ADAPTER=9; // adapter
+ const RF_AUTO_BINDINGS=10; // auto data bindings
+
+ /**
+ * @var string control ID
+ */
+ private $_id='';
+ /**
+ * @var string control unique ID
+ */
+ private $_uid;
+ /**
+ * @var TControl parent of the control
+ */
+ private $_parent;
+ /**
+ * @var TPage page that the control resides in
+ */
+ private $_page;
+ /**
+ * @var TControl naming container of the control
+ */
+ private $_namingContainer;
+ /**
+ * @var TTemplateControl control whose template contains the control
+ */
+ private $_tplControl;
+ /**
+ * @var array viewstate data
+ */
+ private $_viewState=array();
+ /**
+ * @var array temporary state (usually set in template)
+ */
+ private $_tempState=array();
+ /**
+ * @var boolean whether we should keep state in viewstate
+ */
+ private $_trackViewState=true;
+ /**
+ * @var integer the current stage of the control lifecycles
+ */
+ private $_stage=0;
+ /**
+ * @var integer representation of the state bits
+ */
+ private $_flags=0;
+ /**
+ * @var array a collection of rare control data
+ */
+ private $_rf=array();
+
+ /**
+ * Constructor.
+ */
+ public function __construct()
+ {
+ }
+
+ /**
+ * Returns a property value by name or a control by ID.
+ * This overrides the parent implementation by allowing accessing
+ * a control via its ID using the following syntax,
+ * <code>
+ * $menuBar=$this->menuBar;
+ * </code>
+ * Note, the control must be configured in the template
+ * with explicit ID. If the name matches both a property and a control ID,
+ * the control ID will take the precedence.
+ *
+ * @param string the property name or control ID
+ * @return mixed the property value or the target control
+ * @throws TInvalidOperationException if the property is not defined.
+ * @see registerObject
+ */
+ public function __get($name)
+ {
+ if(isset($this->_rf[self::RF_NAMED_OBJECTS][$name]))
+ return $this->_rf[self::RF_NAMED_OBJECTS][$name];
+ else
+ return parent::__get($name);
+ }
+
+ /**
+ * @return boolean whether there is an adapter for this control
+ */
+ public function getHasAdapter()
+ {
+ return isset($this->_rf[self::RF_ADAPTER]);
+ }
+
+ /**
+ * @return TControlAdapter control adapter. Null if not exists.
+ */
+ public function getAdapter()
+ {
+ return isset($this->_rf[self::RF_ADAPTER])?$this->_rf[self::RF_ADAPTER]:null;
+ }
+
+ /**
+ * @param TControlAdapter control adapter
+ */
+ public function setAdapter(TControlAdapter $adapter)
+ {
+ $this->_rf[self::RF_ADAPTER]=$adapter;
+ }
+
+ /**
+ * @return TControl the parent of this control
+ */
+ public function getParent()
+ {
+ return $this->_parent;
+ }
+
+ /**
+ * @return TControl the naming container of this control
+ */
+ public function getNamingContainer()
+ {
+ if(!$this->_namingContainer && $this->_parent)
+ {
+ if($this->_parent instanceof INamingContainer)
+ $this->_namingContainer=$this->_parent;
+ else
+ $this->_namingContainer=$this->_parent->getNamingContainer();
+ }
+ return $this->_namingContainer;
+ }
+
+ /**
+ * @return TPage the page that contains this control
+ */
+ public function getPage()
+ {
+ if(!$this->_page)
+ {
+ if($this->_parent)
+ $this->_page=$this->_parent->getPage();
+ else if($this->_tplControl)
+ $this->_page=$this->_tplControl->getPage();
+ }
+ return $this->_page;
+ }
+
+ /**
+ * Sets the page for a control.
+ * Only framework developers should use this method.
+ * @param TPage the page that contains this control
+ */
+ public function setPage($page)
+ {
+ $this->_page=$page;
+ }
+
+ /**
+ * Sets the control whose template contains this control.
+ * Only framework developers should use this method.
+ * @param TTemplateControl the control whose template contains this control
+ */
+ public function setTemplateControl($control)
+ {
+ $this->_tplControl=$control;
+ }
+
+ /**
+ * @return TTemplateControl the control whose template contains this control
+ */
+ public function getTemplateControl()
+ {
+ if(!$this->_tplControl && $this->_parent)
+ $this->_tplControl=$this->_parent->getTemplateControl();
+ return $this->_tplControl;
+ }
+
+ /**
+ * @return TTemplateControl the control whose template is loaded from
+ * some external storage, such as file, db, and whose template ultimately
+ * contains this control.
+ */
+ public function getSourceTemplateControl()
+ {
+ $control=$this;
+ while(($control instanceof TControl) && ($control=$control->getTemplateControl())!==null)
+ {
+ if(($control instanceof TTemplateControl) && $control->getIsSourceTemplateControl())
+ return $control;
+ }
+ return $this->getPage();
+ }
+
+ /**
+ * Gets the lifecycle step the control is currently at.
+ * This method should only be used by control developers.
+ * @return integer the lifecycle step the control is currently at.
+ * The value can be CS_CONSTRUCTED, CS_CHILD_INITIALIZED, CS_INITIALIZED,
+ * CS_STATE_LOADED, CS_LOADED, CS_PRERENDERED.
+ */
+ protected function getControlStage()
+ {
+ return $this->_stage;
+ }
+
+ /**
+ * Sets the lifecycle step the control is currently at.
+ * This method should only be used by control developers.
+ * @param integer the lifecycle step the control is currently at.
+ * Valid values include CS_CONSTRUCTED, CS_CHILD_INITIALIZED, CS_INITIALIZED,
+ * CS_STATE_LOADED, CS_LOADED, CS_PRERENDERED.
+ */
+ protected function setControlStage($value)
+ {
+ $this->_stage=$value;
+ }
+
+ /**
+ * Returns the id of the control.
+ * Control ID can be either manually set or automatically generated.
+ * If $hideAutoID is true, automatically generated ID will be returned as an empty string.
+ * @param boolean whether to hide automatically generated ID
+ * @return string the ID of the control
+ */
+ public function getID($hideAutoID=true)
+ {
+ if($hideAutoID)
+ return ($this->_flags & self::IS_ID_SET) ? $this->_id : '';
+ else
+ return $this->_id;
+ }
+
+ /**
+ * @param string the new control ID. The value must consist of word characters [a-zA-Z0-9_] only
+ * @throws TInvalidDataValueException if ID is in a bad format
+ */
+ public function setID($id)
+ {
+ if(!preg_match(self::ID_FORMAT,$id))
+ throw new TInvalidDataValueException('control_id_invalid',get_class($this),$id);
+ $this->_id=$id;
+ $this->_flags |= self::IS_ID_SET;
+ $this->clearCachedUniqueID($this instanceof INamingContainer);
+ if($this->_namingContainer)
+ $this->_namingContainer->clearNameTable();
+ }
+
+ /**
+ * Returns a unique ID that identifies the control in the page hierarchy.
+ * A unique ID is the contenation of all naming container controls' IDs and the control ID.
+ * These IDs are separated by '$' character.
+ * Control users should not rely on the specific format of UniqueID, however.
+ * @return string a unique ID that identifies the control in the page hierarchy
+ */
+ public function getUniqueID()
+ {
+ if($this->_uid==='' || $this->_uid===null) // need to build the UniqueID
+ {
+ $this->_uid=''; // set to not-null, so that clearCachedUniqueID() may take action
+ if($namingContainer=$this->getNamingContainer())
+ {
+ if($this->getPage()===$namingContainer)
+ return ($this->_uid=$this->_id);
+ else if(($prefix=$namingContainer->getUniqueID())==='')
+ return $this->_id;
+ else
+ return ($this->_uid=$prefix.self::ID_SEPARATOR.$this->_id);
+ }
+ else // no naming container
+ return $this->_id;
+ }
+ else
+ return $this->_uid;
+ }
+
+ /**
+ * Sets input focus to this control.
+ */
+ public function focus()
+ {
+ $this->getPage()->setFocus($this);
+ }
+
+ /**
+ * Returns the client ID of the control.
+ * The client ID can be used to uniquely identify
+ * the control in client-side scripts (such as JavaScript).
+ * Do not rely on the explicit format of the return ID.
+ * @return string the client ID of the control
+ */
+ public function getClientID()
+ {
+ return strtr($this->getUniqueID(),self::ID_SEPARATOR,self::CLIENT_ID_SEPARATOR);
+ }
+
+ /**
+ * Converts a unique ID to a client ID.
+ * @param string the unique ID of a control
+ * @return string the client ID of the control
+ */
+ public static function convertUniqueIdToClientId($uniqueID)
+ {
+ return strtr($uniqueID,self::ID_SEPARATOR,self::CLIENT_ID_SEPARATOR);
+ }
+
+ /**
+ * @return string the skin ID of this control, '' if not set
+ */
+ public function getSkinID()
+ {
+ return isset($this->_rf[self::RF_SKIN_ID])?$this->_rf[self::RF_SKIN_ID]:'';
+ }
+
+ /**
+ * @param string the skin ID of this control
+ * @throws TInvalidOperationException if the SkinID is set in a stage later than PreInit, or if the skin is applied already.
+ */
+ public function setSkinID($value)
+ {
+ if(($this->_flags & self::IS_SKIN_APPLIED) || $this->_stage>=self::CS_CHILD_INITIALIZED)
+ throw new TInvalidOperationException('control_skinid_unchangeable',get_class($this));
+ else
+ $this->_rf[self::RF_SKIN_ID]=$value;
+ }
+
+ /**
+ * @param string the skin ID of this control
+ * @throws TInvalidOperationException if the SkinID is set in a stage later than PreInit, or if the skin is applied already.
+ */
+ public function getIsSkinApplied()
+ {
+ return ($this->_flags & self::IS_SKIN_APPLIED);
+ }
+
+ /**
+ * @return boolean whether theming is enabled for this control.
+ * The theming is enabled if the control and all its parents have it enabled.
+ */
+ public function getEnableTheming()
+ {
+ if($this->_flags & self::IS_DISABLE_THEMING)
+ return false;
+ else
+ return $this->_parent?$this->_parent->getEnableTheming():true;
+ }
+
+ /**
+ * @param boolean whether to enable theming
+ * @throws TInvalidOperationException if this method is invoked after OnPreInit
+ */
+ public function setEnableTheming($value)
+ {
+ if($this->_stage>=self::CS_CHILD_INITIALIZED)
+ throw new TInvalidOperationException('control_enabletheming_unchangeable',get_class($this),$this->getUniqueID());
+ else if(TPropertyValue::ensureBoolean($value))
+ $this->_flags &= ~self::IS_DISABLE_THEMING;
+ else
+ $this->_flags |= self::IS_DISABLE_THEMING;
+ }
+
+ /**
+ * Returns custom data associated with this control.
+ * A control may be associated with some custom data for various purposes.
+ * For example, a button may be associated with a string to identify itself
+ * in a generic OnClick event handler.
+ * @return mixed custom data associated with this control. Defaults to null.
+ */
+ public function getCustomData()
+ {
+ return $this->getViewState('CustomData',null);
+ }
+
+ /**
+ * Associates custom data with this control.
+ * Note, the custom data must be serializable and unserializable.
+ * @param mixed custom data
+ */
+ public function setCustomData($value)
+ {
+ $this->setViewState('CustomData',$value,null);
+ }
+
+ /**
+ * @return boolean whether the control has child controls
+ */
+ public function getHasControls()
+ {
+ return isset($this->_rf[self::RF_CONTROLS]) && $this->_rf[self::RF_CONTROLS]->getCount()>0;
+ }
+
+ /**
+ * @return TControlCollection the child control collection
+ */
+ public function getControls()
+ {
+ if(!isset($this->_rf[self::RF_CONTROLS]))
+ $this->_rf[self::RF_CONTROLS]=$this->createControlCollection();
+ return $this->_rf[self::RF_CONTROLS];
+ }
+
+ /**
+ * Creates a control collection object that is to be used to hold child controls
+ * @return TControlCollection control collection
+ * @see getControls
+ */
+ protected function createControlCollection()
+ {
+ return $this->getAllowChildControls()?new TControlCollection($this):new TEmptyControlCollection($this);
+ }
+
+ /**
+ * Checks if a control is visible.
+ * If parent check is required, then a control is visible only if the control
+ * and all its ancestors are visible.
+ * @param boolean whether the parents should also be checked if visible
+ * @return boolean whether the control is visible (default=true).
+ */
+ public function getVisible($checkParents=true)
+ {
+ if($checkParents)
+ {
+ for($control=$this;$control;$control=$control->_parent)
+ if(!$control->getVisible(false))
+ return false;
+ return true;
+ }
+ else
+ return $this->getViewState('Visible',true);
+ }
+
+ /**
+ * @param boolean whether the control is visible
+ */
+ public function setVisible($value)
+ {
+ $this->setViewState('Visible',TPropertyValue::ensureBoolean($value),true);
+ }
+
+ /**
+ * Returns a value indicating whether the control is enabled.
+ * A control is enabled if it allows client user interaction.
+ * If $checkParents is true, all parent controls will be checked,
+ * and unless they are all enabled, false will be returned.
+ * The property Enabled is mainly used for {@link TWebControl}
+ * derived controls.
+ * @param boolean whether the parents should also be checked enabled
+ * @return boolean whether the control is enabled.
+ */
+ public function getEnabled($checkParents=false)
+ {
+ if($checkParents)
+ {
+ for($control=$this;$control;$control=$control->_parent)
+ if(!$control->getViewState('Enabled',true))
+ return false;
+ return true;
+ }
+ else
+ return $this->getViewState('Enabled',true);
+ }
+
+ /**
+ * @param boolean whether the control is to be enabled.
+ */
+ public function setEnabled($value)
+ {
+ $this->setViewState('Enabled',TPropertyValue::ensureBoolean($value),true);
+ }
+
+ /**
+ * @return boolean whether the control has custom attributes
+ */
+ public function getHasAttributes()
+ {
+ if($attributes=$this->getViewState('Attributes',null))
+ return $attributes->getCount()>0;
+ else
+ return false;
+ }
+
+ /**
+ * Returns the list of custom attributes.
+ * Custom attributes are name-value pairs that may be rendered
+ * as HTML tags' attributes.
+ * @return TAttributeCollection the list of custom attributes
+ */
+ public function getAttributes()
+ {
+ if($attributes=$this->getViewState('Attributes',null))
+ return $attributes;
+ else
+ {
+ $attributes=new TAttributeCollection;
+ $this->setViewState('Attributes',$attributes,null);
+ return $attributes;
+ }
+ }
+
+ /**
+ * @return boolean whether the named attribute exists
+ */
+ public function hasAttribute($name)
+ {
+ if($attributes=$this->getViewState('Attributes',null))
+ return $attributes->contains($name);
+ else
+ return false;
+ }
+
+ /**
+ * @return string attribute value, null if attribute does not exist
+ */
+ public function getAttribute($name)
+ {
+ if($attributes=$this->getViewState('Attributes',null))
+ return $attributes->itemAt($name);
+ else
+ return null;
+ }
+
+ /**
+ * Sets a custom control attribute.
+ * @param string attribute name
+ * @param string value of the attribute
+ */
+ public function setAttribute($name,$value)
+ {
+ $this->getAttributes()->add($name,$value);
+ }
+
+ /**
+ * Removes the named attribute.
+ * @param string the name of the attribute to be removed.
+ * @return string attribute value removed, null if attribute does not exist.
+ */
+ public function removeAttribute($name)
+ {
+ if($attributes=$this->getViewState('Attributes',null))
+ return $attributes->remove($name);
+ else
+ return null;
+ }
+
+ /**
+ * @return boolean whether viewstate is enabled
+ */
+ public function getEnableViewState($checkParents=false)
+ {
+ if($checkParents)
+ {
+ for($control=$this;$control!==null;$control=$control->getParent())
+ if($control->_flags & self::IS_DISABLE_VIEWSTATE)
+ return false;
+ return true;
+ }
+ else
+ return !($this->_flags & self::IS_DISABLE_VIEWSTATE);
+ }
+
+ /**
+ * @param boolean set whether to enable viewstate
+ */
+ public function setEnableViewState($value)
+ {
+ if(TPropertyValue::ensureBoolean($value))
+ $this->_flags &= ~self::IS_DISABLE_VIEWSTATE;
+ else
+ $this->_flags |= self::IS_DISABLE_VIEWSTATE;
+ }
+
+ /**
+ * Returns a controlstate value.
+ *
+ * This function is mainly used in defining getter functions for control properties
+ * that must be kept in controlstate.
+ * @param string the name of the controlstate value to be returned
+ * @param mixed the default value. If $key is not found in controlstate, $defaultValue will be returned
+ * @return mixed the controlstate value corresponding to $key
+ */
+ protected function getControlState($key,$defaultValue=null)
+ {
+ return isset($this->_rf[self::RF_CONTROLSTATE][$key])?$this->_rf[self::RF_CONTROLSTATE][$key]:$defaultValue;
+ }
+
+ /**
+ * Sets a controlstate value.
+ *
+ * This function is very useful in defining setter functions for control properties
+ * that must be kept in controlstate.
+ * Make sure that the controlstate value must be serializable and unserializable.
+ * @param string the name of the controlstate value
+ * @param mixed the controlstate value to be set
+ * @param mixed default value. If $value===$defaultValue, the item will be cleared from controlstate
+ */
+ protected function setControlState($key,$value,$defaultValue=null)
+ {
+ if($value===$defaultValue)
+ unset($this->_rf[self::RF_CONTROLSTATE][$key]);
+ else
+ $this->_rf[self::RF_CONTROLSTATE][$key]=$value;
+ }
+
+ /**
+ * Clears a controlstate value.
+ * @param string the name of the controlstate value to be cleared
+ */
+ protected function clearControlState($key)
+ {
+ unset($this->_rf[self::RF_CONTROLSTATE][$key]);
+ }
+
+ /**
+ * Sets a value indicating whether we should keep data in viewstate.
+ * When it is false, data saved via setViewState() will not be persisted.
+ * By default, it is true, meaning data will be persisted across postbacks.
+ * @param boolean whether data should be persisted
+ */
+ public function trackViewState($enabled)
+ {
+ $this->_trackViewState=TPropertyValue::ensureBoolean($enabled);
+ }
+
+ /**
+ * Returns a viewstate value.
+ *
+ * This function is very useful in defining getter functions for component properties
+ * that must be kept in viewstate.
+ * @param string the name of the viewstate value to be returned
+ * @param mixed the default value. If $key is not found in viewstate, $defaultValue will be returned
+ * @return mixed the viewstate value corresponding to $key
+ */
+ public function getViewState($key,$defaultValue=null)
+ {
+ if(isset($this->_viewState[$key]))
+ return $this->_viewState[$key]!==null?$this->_viewState[$key]:$defaultValue;
+ else if(isset($this->_tempState[$key]))
+ {
+ if(is_object($this->_tempState[$key]) && $this->_trackViewState)
+ $this->_viewState[$key]=$this->_tempState[$key];
+ return $this->_tempState[$key];
+ }
+ else
+ return $defaultValue;
+ }
+
+ /**
+ * Sets a viewstate value.
+ *
+ * This function is very useful in defining setter functions for control properties
+ * that must be kept in viewstate.
+ * Make sure that the viewstate value must be serializable and unserializable.
+ * @param string the name of the viewstate value
+ * @param mixed the viewstate value to be set
+ * @param mixed default value. If $value===$defaultValue, the item will be cleared from the viewstate.
+ */
+ public function setViewState($key,$value,$defaultValue=null)
+ {
+ if($this->_trackViewState)
+ {
+ $this->_viewState[$key]=$value;
+ unset($this->_tempState[$key]);
+ }
+ else
+ {
+ unset($this->_viewState[$key]);
+ $this->_tempState[$key]=$value;
+ }
+ }
+
+ /**
+ * Clears a viewstate value.
+ * @param string the name of the viewstate value to be cleared
+ */
+ public function clearViewState($key)
+ {
+ unset($this->_viewState[$key]);
+ unset($this->_tempState[$key]);
+ }
+
+ /**
+ * Sets up the binding between a property (or property path) and an expression.
+ * The context of the expression is the template control (or the control itself if it is a page).
+ * @param string the property name, or property path
+ * @param string the expression
+ */
+ public function bindProperty($name,$expression)
+ {
+ $this->_rf[self::RF_DATA_BINDINGS][$name]=$expression;
+ }
+
+ /**
+ * Breaks the binding between a property (or property path) and an expression.
+ * @param string the property name (or property path)
+ */
+ public function unbindProperty($name)
+ {
+ unset($this->_rf[self::RF_DATA_BINDINGS][$name]);
+ }
+
+ /**
+ * Sets up the binding between a property (or property path) and an expression.
+ * Unlike regular databinding, the expression bound by this method
+ * is automatically evaluated during {@link prerenderRecursive()}.
+ * The context of the expression is the template control (or the control itself if it is a page).
+ * @param string the property name, or property path
+ * @param string the expression
+ */
+ public function autoBindProperty($name,$expression)
+ {
+ $this->_rf[self::RF_AUTO_BINDINGS][$name]=$expression;
+ }
+
+ /**
+ * Performs the databinding for this control.
+ */
+ public function dataBind()
+ {
+ $this->dataBindProperties();
+ $this->onDataBinding(null);
+ $this->dataBindChildren();
+ }
+
+ /**
+ * Databinding properties of the control.
+ */
+ protected function dataBindProperties()
+ {
+ Prado::trace("Data bind properties",'System.Web.UI.TControl');
+ if(isset($this->_rf[self::RF_DATA_BINDINGS]))
+ {
+ if(($context=$this->getTemplateControl())===null)
+ $context=$this;
+ foreach($this->_rf[self::RF_DATA_BINDINGS] as $property=>$expression)
+ $this->setSubProperty($property,$context->evaluateExpression($expression));
+ }
+ }
+
+ /**
+ * Auto databinding properties of the control.
+ */
+ protected function autoDataBindProperties()
+ {
+ if(isset($this->_rf[self::RF_AUTO_BINDINGS]))
+ {
+ if(($context=$this->getTemplateControl())===null)
+ $context=$this;
+ foreach($this->_rf[self::RF_AUTO_BINDINGS] as $property=>$expression)
+ $this->setSubProperty($property,$context->evaluateExpression($expression));
+ }
+ }
+
+ /**
+ * Databinding child controls.
+ */
+ protected function dataBindChildren()
+ {
+ Prado::trace("dataBindChildren()",'System.Web.UI.TControl');
+ if(isset($this->_rf[self::RF_CONTROLS]))
+ {
+ foreach($this->_rf[self::RF_CONTROLS] as $control)
+ if($control instanceof IBindable)
+ $control->dataBind();
+ }
+ }
+
+ /**
+ * @return boolean whether child controls have been created
+ */
+ final protected function getChildControlsCreated()
+ {
+ return ($this->_flags & self::IS_CHILD_CREATED)!==0;
+ }
+
+ /**
+ * Sets a value indicating whether child controls are created.
+ * If false, any existing child controls will be cleared up.
+ * @param boolean whether child controls are created
+ */
+ final protected function setChildControlsCreated($value)
+ {
+ if($value)
+ $this->_flags |= self::IS_CHILD_CREATED;
+ else
+ {
+ if($this->getHasControls() && ($this->_flags & self::IS_CHILD_CREATED))
+ $this->getControls()->clear();
+ $this->_flags &= ~self::IS_CHILD_CREATED;
+ }
+ }
+
+ /**
+ * Ensures child controls are created.
+ * If child controls are not created yet, this method will invoke
+ * {@link createChildControls} to create them.
+ */
+ public function ensureChildControls()
+ {
+ if(!($this->_flags & self::IS_CHILD_CREATED) && !($this->_flags & self::IS_CREATING_CHILD))
+ {
+ try
+ {
+ $this->_flags |= self::IS_CREATING_CHILD;
+ if(isset($this->_rf[self::RF_ADAPTER]))
+ $this->_rf[self::RF_ADAPTER]->createChildControls();
+ else
+ $this->createChildControls();
+ $this->_flags &= ~self::IS_CREATING_CHILD;
+ $this->_flags |= self::IS_CHILD_CREATED;
+ }
+ catch(Exception $e)
+ {
+ $this->_flags &= ~self::IS_CREATING_CHILD;
+ $this->_flags |= self::IS_CHILD_CREATED;
+ throw $e;
+ }
+ }
+ }
+
+ /**
+ * Creates child controls.
+ * This method can be overriden for controls who want to have their controls.
+ * Do not call this method directly. Instead, call {@link ensureChildControls}
+ * to ensure child controls are created only once.
+ */
+ public function createChildControls()
+ {
+ }
+
+ /**
+ * Finds a control by ID path within the current naming container.
+ * The current naming container is either the control itself
+ * if it implements {@link INamingContainer} or the control's naming container.
+ * The ID path is an ID sequence separated by {@link TControl::ID_SEPARATOR}.
+ * For example, 'Repeater1.Item1.Button1' looks for a control with ID 'Button1'
+ * whose naming container is 'Item1' whose naming container is 'Repeater1'.
+ * @param string ID of the control to be looked up
+ * @return TControl|null the control found, null if not found
+ * @throws TInvalidDataValueException if a control's ID is found not unique within its naming container.
+ */
+ public function findControl($id)
+ {
+ $id=strtr($id,'.',self::ID_SEPARATOR);
+ $container=($this instanceof INamingContainer)?$this:$this->getNamingContainer();
+ if(!$container || !$container->getHasControls())
+ return null;
+ if(!isset($container->_rf[self::RF_NAMED_CONTROLS]))
+ {
+ $container->_rf[self::RF_NAMED_CONTROLS]=array();
+ $container->fillNameTable($container,$container->_rf[self::RF_CONTROLS]);
+ }
+ if(($pos=strpos($id,self::ID_SEPARATOR))===false)
+ return isset($container->_rf[self::RF_NAMED_CONTROLS][$id])?$container->_rf[self::RF_NAMED_CONTROLS][$id]:null;
+ else
+ {
+ $cid=substr($id,0,$pos);
+ $sid=substr($id,$pos+1);
+ if(isset($container->_rf[self::RF_NAMED_CONTROLS][$cid]))
+ return $container->_rf[self::RF_NAMED_CONTROLS][$cid]->findControl($sid);
+ else
+ return null;
+ }
+ }
+
+ /**
+ * Finds all child and grand-child controls that are of the specified type.
+ * @param string the class name
+ * @param boolean whether the type comparison is strict or not. If false, controls of the parent classes of the specified class will also be returned.
+ * @return array list of controls found
+ */
+ public function findControlsByType($type,$strict=true)
+ {
+ $controls=array();
+ if($this->getHasControls())
+ {
+ foreach($this->_rf[self::RF_CONTROLS] as $control)
+ {
+ if(is_object($control) && (get_class($control)===$type || (!$strict && ($control instanceof $type))))
+ $controls[]=$control;
+ if(($control instanceof TControl) && $control->getHasControls())
+ $controls=array_merge($controls,$control->findControlsByType($type,$strict));
+ }
+ }
+ return $controls;
+ }
+
+ /**
+ * Finds all child and grand-child controls with the specified ID.
+ * Note, this method is different from {@link findControl} in that
+ * it searches through all controls that have this control as the ancestor
+ * while {@link findcontrol} only searches through controls that have this
+ * control as the direct naming container.
+ * @param string the ID being looked for
+ * @return array list of controls found
+ */
+ public function findControlsByID($id)
+ {
+ $controls=array();
+ if($this->getHasControls())
+ {
+ foreach($this->_rf[self::RF_CONTROLS] as $control)
+ {
+ if($control instanceof TControl)
+ {
+ if($control->_id===$id)
+ $controls[]=$control;
+ $controls=array_merge($controls,$control->findControlsByID($id));
+ }
+ }
+ }
+ return $controls;
+ }
+
+ /**
+ * Resets the control as a naming container.
+ * Only framework developers should use this method.
+ */
+ public function clearNamingContainer()
+ {
+ unset($this->_rf[self::RF_NAMED_CONTROLS_ID]);
+ $this->clearNameTable();
+ }
+
+ /**
+ * Registers an object by a name.
+ * A registered object can be accessed like a public member variable.
+ * This method should only be used by framework and control developers.
+ * @param string name of the object
+ * @param object object to be declared
+ * @see __get
+ */
+ public function registerObject($name,$object)
+ {
+ if(isset($this->_rf[self::RF_NAMED_OBJECTS][$name]))
+ throw new TInvalidOperationException('control_object_reregistered',$name);
+ $this->_rf[self::RF_NAMED_OBJECTS][$name]=$object;
+ }
+
+ /**
+ * Unregisters an object by name.
+ * @param string name of the object
+ * @see registerObject
+ */
+ public function unregisterObject($name)
+ {
+ unset($this->_rf[self::RF_NAMED_OBJECTS][$name]);
+ }
+
+ /**
+ * @return boolean whether an object has been registered with the name
+ * @see registerObject
+ */
+ public function isObjectRegistered($name)
+ {
+ return isset($this->_rf[self::RF_NAMED_OBJECTS][$name]);
+ }
+
+ /**
+ * @return boolean true if the child control has been initialized.
+ */
+ public function getHasChildInitialized()
+ {
+ return $this->getControlStage() >= self::CS_CHILD_INITIALIZED;
+ }
+
+ /**
+ * @return boolean true if the onInit event has raised.
+ */
+ public function getHasInitialized()
+ {
+ return $this->getControlStage() >= self::CS_INITIALIZED;
+ }
+
+ /**
+ * @return boolean true if the control has loaded post data.
+ */
+ public function getHasLoadedPostData()
+ {
+ return $this->getControlStage() >= self::CS_STATE_LOADED;
+ }
+
+ /**
+ * @return boolean true if the onLoad event has raised.
+ */
+ public function getHasLoaded()
+ {
+ return $this->getControlStage() >= self::CS_LOADED;
+ }
+
+ /**
+ * @return boolean true if onPreRender event has raised.
+ */
+ public function getHasPreRendered()
+ {
+ return $this->getControlStage() >= self::CS_PRERENDERED;
+ }
+
+ /**
+ * Returns the named registered object.
+ * A component with explicit ID on a template will be registered to
+ * the template owner. This method allows you to obtain this component
+ * with the ID.
+ * @return mixed the named registered object. Null if object is not found.
+ */
+ public function getRegisteredObject($name)
+ {
+ return isset($this->_rf[self::RF_NAMED_OBJECTS][$name])?$this->_rf[self::RF_NAMED_OBJECTS][$name]:null;
+ }
+
+ /**
+ * @return boolean whether body contents are allowed for this control. Defaults to true.
+ */
+ public function getAllowChildControls()
+ {
+ return true;
+ }
+
+ /**
+ * Adds the object instantiated on a template to the child control collection.
+ * This method overrides the parent implementation.
+ * Only framework developers and control developers should use this method.
+ * @param string|TComponent text string or component parsed and instantiated in template
+ * @see createdOnTemplate
+ */
+ public function addParsedObject($object)
+ {
+ $this->getControls()->add($object);
+ }
+
+ /**
+ * Clears up the child state data.
+ * After a control loads its state, those state that do not belong to
+ * any existing child controls are stored as child state.
+ * This method will remove these state.
+ * Only frameworker developers and control developers should use this method.
+ */
+ final protected function clearChildState()
+ {
+ unset($this->_rf[self::RF_CHILD_STATE]);
+ }
+
+ /**
+ * @param TControl the potential ancestor control
+ * @return boolean if the control is a descendent (parent, parent of parent, etc.)
+ * of the specified control
+ */
+ final protected function isDescendentOf($ancestor)
+ {
+ $control=$this;
+ while($control!==$ancestor && $control->_parent)
+ $control=$control->_parent;
+ return $control===$ancestor;
+ }
+
+ /**
+ * Adds a control into the child collection of the control.
+ * Control lifecycles will be caught up during the addition.
+ * Only framework developers should use this method.
+ * @param TControl the new child control
+ */
+ public function addedControl($control)
+ {
+ if($control->_parent)
+ $control->_parent->getControls()->remove($control);
+ $control->_parent=$this;
+ $control->_page=$this->getPage();
+ $namingContainer=($this instanceof INamingContainer)?$this:$this->_namingContainer;
+ if($namingContainer)
+ {
+ $control->_namingContainer=$namingContainer;
+ if($control->_id==='')
+ $control->generateAutomaticID();
+ else
+ $namingContainer->clearNameTable();
+ $control->clearCachedUniqueID($control instanceof INamingContainer);
+ }
+
+ if($this->_stage>=self::CS_CHILD_INITIALIZED)
+ {
+ $control->initRecursive($namingContainer);
+ if($this->_stage>=self::CS_STATE_LOADED)
+ {
+ if(isset($this->_rf[self::RF_CHILD_STATE][$control->_id]))
+ {
+ $state=$this->_rf[self::RF_CHILD_STATE][$control->_id];
+ unset($this->_rf[self::RF_CHILD_STATE][$control->_id]);
+ }
+ else
+ $state=null;
+ $control->loadStateRecursive($state,!($this->_flags & self::IS_DISABLE_VIEWSTATE));
+ if($this->_stage>=self::CS_LOADED)
+ {
+ $control->loadRecursive();
+ if($this->_stage>=self::CS_PRERENDERED)
+ $control->preRenderRecursive();
+ }
+ }
+ }
+ }
+
+ /**
+ * Removes a control from the child collection of the control.
+ * Only framework developers should use this method.
+ * @param TControl the child control removed
+ */
+ public function removedControl($control)
+ {
+ if($this->_namingContainer)
+ $this->_namingContainer->clearNameTable();
+ $control->unloadRecursive();
+ $control->_parent=null;
+ $control->_page=null;
+ $control->_namingContainer=null;
+ $control->_tplControl=null;
+ //$control->_stage=self::CS_CONSTRUCTED;
+ if(!($control->_flags & self::IS_ID_SET))
+ $control->_id='';
+ else
+ unset($this->_rf[self::RF_NAMED_OBJECTS][$control->_id]);
+ $control->clearCachedUniqueID(true);
+ }
+
+ /**
+ * Performs the Init step for the control and all its child controls.
+ * Only framework developers should use this method.
+ * @param TControl the naming container control
+ */
+ protected function initRecursive($namingContainer=null)
+ {
+ $this->ensureChildControls();
+ if($this->getHasControls())
+ {
+ if($this instanceof INamingContainer)
+ $namingContainer=$this;
+ $page=$this->getPage();
+ foreach($this->_rf[self::RF_CONTROLS] as $control)
+ {
+ if($control instanceof TControl)
+ {
+ $control->_namingContainer=$namingContainer;
+ $control->_page=$page;
+ if($control->_id==='' && $namingContainer)
+ $control->generateAutomaticID();
+ $control->initRecursive($namingContainer);
+ }
+ }
+ }
+ if($this->_stage<self::CS_INITIALIZED)
+ {
+ $this->_stage=self::CS_CHILD_INITIALIZED;
+ if(($page=$this->getPage()) && $this->getEnableTheming() && !($this->_flags & self::IS_SKIN_APPLIED))
+ {
+ $page->applyControlSkin($this);
+ $this->_flags |= self::IS_SKIN_APPLIED;
+ }
+ if(isset($this->_rf[self::RF_ADAPTER]))
+ $this->_rf[self::RF_ADAPTER]->onInit(null);
+ else
+ $this->onInit(null);
+ $this->_stage=self::CS_INITIALIZED;
+ }
+ }
+
+ /**
+ * Performs the Load step for the control and all its child controls.
+ * Only framework developers should use this method.
+ */
+ protected function loadRecursive()
+ {
+ if($this->_stage<self::CS_LOADED)
+ {
+ if(isset($this->_rf[self::RF_ADAPTER]))
+ $this->_rf[self::RF_ADAPTER]->onLoad(null);
+ else
+ $this->onLoad(null);
+ }
+ if($this->getHasControls())
+ {
+ foreach($this->_rf[self::RF_CONTROLS] as $control)
+ {
+ if($control instanceof TControl)
+ $control->loadRecursive();
+ }
+ }
+ if($this->_stage<self::CS_LOADED)
+ $this->_stage=self::CS_LOADED;
+ }
+
+ /**
+ * Performs the PreRender step for the control and all its child controls.
+ * Only framework developers should use this method.
+ */
+ protected function preRenderRecursive()
+ {
+ $this->autoDataBindProperties();
+
+ if($this->getVisible(false))
+ {
+ if(isset($this->_rf[self::RF_ADAPTER]))
+ $this->_rf[self::RF_ADAPTER]->onPreRender(null);
+ else
+ $this->onPreRender(null);
+ if($this->getHasControls())
+ {
+ foreach($this->_rf[self::RF_CONTROLS] as $control)
+ {
+ if($control instanceof TControl)
+ $control->preRenderRecursive();
+ else if($control instanceof TCompositeLiteral)
+ $control->evaluateDynamicContent();
+ }
+ }
+ $this->addToPostDataLoader();
+ }
+ $this->_stage=self::CS_PRERENDERED;
+ }
+
+ /**
+ * Add controls implementing IPostBackDataHandler to post data loaders.
+ */
+ protected function addToPostDataLoader()
+ {
+ if($this instanceof IPostBackDataHandler)
+ $this->getPage()->registerPostDataLoader($this);
+ }
+
+ /**
+ * Performs the Unload step for the control and all its child controls.
+ * Only framework developers should use this method.
+ */
+ protected function unloadRecursive()
+ {
+ if(!($this->_flags & self::IS_ID_SET))
+ $this->_id='';
+ if($this->getHasControls())
+ {
+ foreach($this->_rf[self::RF_CONTROLS] as $control)
+ if($control instanceof TControl)
+ $control->unloadRecursive();
+ }
+ if(isset($this->_rf[self::RF_ADAPTER]))
+ $this->_rf[self::RF_ADAPTER]->onUnload(null);
+ else
+ $this->onUnload(null);
+ }
+
+ /**
+ * This method is invoked when the control enters 'OnInit' stage.
+ * The method raises 'OnInit' event.
+ * If you override this method, be sure to call the parent implementation
+ * so that the event handlers can be invoked.
+ * @param TEventParameter event parameter to be passed to the event handlers
+ */
+ public function onInit($param)
+ {
+ $this->raiseEvent('OnInit',$this,$param);
+ }
+
+ /**
+ * This method is invoked when the control enters 'OnLoad' stage.
+ * The method raises 'OnLoad' event.
+ * If you override this method, be sure to call the parent implementation
+ * so that the event handlers can be invoked.
+ * @param TEventParameter event parameter to be passed to the event handlers
+ */
+ public function onLoad($param)
+ {
+ $this->raiseEvent('OnLoad',$this,$param);
+ }
+
+ /**
+ * Raises 'OnDataBinding' event.
+ * This method is invoked when {@link dataBind} is invoked.
+ * @param TEventParameter event parameter to be passed to the event handlers
+ */
+ public function onDataBinding($param)
+ {
+ Prado::trace("onDataBinding()",'System.Web.UI.TControl');
+ $this->raiseEvent('OnDataBinding',$this,$param);
+ }
+
+
+ /**
+ * This method is invoked when the control enters 'OnUnload' stage.
+ * The method raises 'OnUnload' event.
+ * If you override this method, be sure to call the parent implementation
+ * so that the event handlers can be invoked.
+ * @param TEventParameter event parameter to be passed to the event handlers
+ */
+ public function onUnload($param)
+ {
+ $this->raiseEvent('OnUnload',$this,$param);
+ }
+
+ /**
+ * This method is invoked when the control enters 'OnPreRender' stage.
+ * The method raises 'OnPreRender' event.
+ * If you override this method, be sure to call the parent implementation
+ * so that the event handlers can be invoked.
+ * @param TEventParameter event parameter to be passed to the event handlers
+ */
+ public function onPreRender($param)
+ {
+ $this->raiseEvent('OnPreRender',$this,$param);
+ }
+
+ /**
+ * Invokes the parent's bubbleEvent method.
+ * A control who wants to bubble an event must call this method in its onEvent method.
+ * @param TControl sender of the event
+ * @param TEventParameter event parameter
+ * @see bubbleEvent
+ */
+ protected function raiseBubbleEvent($sender,$param)
+ {
+ $control=$this;
+ while($control=$control->_parent)
+ {
+ if($control->bubbleEvent($sender,$param))
+ break;
+ }
+ }
+
+ /**
+ * This method responds to a bubbled event.
+ * This method should be overriden to provide customized response to a bubbled event.
+ * Check the type of event parameter to determine what event is bubbled currently.
+ * @param TControl sender of the event
+ * @param TEventParameter event parameters
+ * @return boolean true if the event bubbling is handled and no more bubbling.
+ * @see raiseBubbleEvent
+ */
+ public function bubbleEvent($sender,$param)
+ {
+ return false;
+ }
+
+ /**
+ * Broadcasts an event.
+ * The event will be sent to all controls on the current page hierarchy.
+ * If a control defines the event, the event will be raised for the control.
+ * If a control implements {@link IBroadcastEventReceiver}, its
+ * {@link IBroadcastEventReceiver::broadcastEventReceived broadcastEventReceived()} method will
+ * be invoked which gives the control a chance to respond to the event.
+ * For example, when broadcasting event 'OnClick', all controls having 'OnClick'
+ * event will have this event raised, and all controls implementing
+ * {@link IBroadcastEventReceiver} will also have its
+ * {@link IBroadcastEventReceiver::broadcastEventReceived broadcastEventReceived()}
+ * invoked.
+ * @param string name of the broadcast event
+ * @param TControl sender of this event
+ * @param TEventParameter event parameter
+ */
+ public function broadcastEvent($name,$sender,$param)
+ {
+ $rootControl=(($page=$this->getPage())===null)?$this:$page;
+ $rootControl->broadcastEventInternal($name,$sender,new TBroadcastEventParameter($name,$param));
+ }
+
+ /**
+ * Recursively broadcasts an event.
+ * This method should only be used by framework developers.
+ * @param string name of the broadcast event
+ * @param TControl sender of the event
+ * @param TBroadcastEventParameter event parameter
+ */
+ private function broadcastEventInternal($name,$sender,$param)
+ {
+ if($this->hasEvent($name))
+ $this->raiseEvent($name,$sender,$param->getParameter());
+ if($this instanceof IBroadcastEventReceiver)
+ $this->broadcastEventReceived($sender,$param);
+ if($this->getHasControls())
+ {
+ foreach($this->_rf[self::RF_CONTROLS] as $control)
+ {
+ if($control instanceof TControl)
+ $control->broadcastEventInternal($name,$sender,$param);
+ }
+ }
+ }
+
+ /**
+ * Traverse the whole control hierarchy rooted at this control.
+ * Callback function may be invoked for each control being visited.
+ * A pre-callback is invoked before traversing child controls;
+ * A post-callback is invoked after traversing child controls.
+ * Callback functions can be global functions or class methods.
+ * They must be of the following signature:
+ * <code>
+ * function callback_func($control,$param) {...}
+ * </code>
+ * where $control refers to the control being visited and $param
+ * is the parameter that is passed originally when calling this traverse function.
+ *
+ * @param mixed parameter to be passed to callbacks for each control
+ * @param callback callback invoked before traversing child controls. If null, it is ignored.
+ * @param callback callback invoked after traversing child controls. If null, it is ignored.
+ */
+ protected function traverseChildControls($param,$preCallback=null,$postCallback=null)
+ {
+ if($preCallback!==null)
+ call_user_func($preCallback,$this,$param);
+ if($this->getHasControls())
+ {
+ foreach($this->_rf[self::RF_CONTROLS] as $control)
+ {
+ if($control instanceof TControl)
+ {
+ $control->traverseChildControls($param,$preCallback,$postCallback);
+ }
+ }
+ }
+ if($postCallback!==null)
+ call_user_func($postCallback,$this,$param);
+ }
+
+ /**
+ * Renders the control.
+ * Only when the control is visible will the control be rendered.
+ * @param THtmlWriter the writer used for the rendering purpose
+ */
+ public function renderControl($writer)
+ {
+ if($this instanceof IActiveControl || $this->getVisible(false))
+ {
+ if(isset($this->_rf[self::RF_ADAPTER]))
+ $this->_rf[self::RF_ADAPTER]->render($writer);
+ else
+ $this->render($writer);
+ }
+ }
+
+ /**
+ * Renders the control.
+ * This method is invoked by {@link renderControl} when the control is visible.
+ * You can override this method to provide customized rendering of the control.
+ * By default, the control simply renders all its child contents.
+ * @param THtmlWriter the writer used for the rendering purpose
+ */
+ public function render($writer)
+ {
+ $this->renderChildren($writer);
+ }
+
+ /**
+ * Renders the children of the control.
+ * This method iterates through all child controls and static text strings
+ * and renders them in order.
+ * @param THtmlWriter the writer used for the rendering purpose
+ */
+ public function renderChildren($writer)
+ {
+ if($this->getHasControls())
+ {
+ foreach($this->_rf[self::RF_CONTROLS] as $control)
+ {
+ if(is_string($control))
+ $writer->write($control);
+ else if($control instanceof TControl)
+ $control->renderControl($writer);
+ else if($control instanceof IRenderable)
+ $control->render($writer);
+ }
+ }
+ }
+
+ /**
+ * This method is invoked when control state is to be saved.
+ * You can override this method to do last step state saving.
+ * Parent implementation must be invoked.
+ */
+ public function saveState()
+ {
+ }
+
+ /**
+ * This method is invoked right after the control has loaded its state.
+ * You can override this method to initialize data from the control state.
+ * Parent implementation must be invoked.
+ */
+ public function loadState()
+ {
+ }
+
+ /**
+ * Loads state (viewstate and controlstate) into a control and its children.
+ * This method should only be used by framework developers.
+ * @param array the collection of the state
+ * @param boolean whether the viewstate should be loaded
+ */
+ protected function loadStateRecursive(&$state,$needViewState=true)
+ {
+ if(is_array($state))
+ {
+ // A null state means the stateful properties all take default values.
+ // So if the state is enabled, we have to assign the null value.
+ $needViewState=($needViewState && !($this->_flags & self::IS_DISABLE_VIEWSTATE));
+ if(isset($state[1]))
+ {
+ $this->_rf[self::RF_CONTROLSTATE]=&$state[1];
+ unset($state[1]);
+ }
+ else
+ unset($this->_rf[self::RF_CONTROLSTATE]);
+ if($needViewState)
+ {
+ if(isset($state[0]))
+ $this->_viewState=&$state[0];
+ else
+ $this->_viewState=array();
+ }
+ unset($state[0]);
+ if($this->getHasControls())
+ {
+ foreach($this->_rf[self::RF_CONTROLS] as $control)
+ {
+ if($control instanceof TControl)
+ {
+ if(isset($state[$control->_id]))
+ {
+ $control->loadStateRecursive($state[$control->_id],$needViewState);
+ unset($state[$control->_id]);
+ }
+ }
+ }
+ }
+ if(!empty($state))
+ $this->_rf[self::RF_CHILD_STATE]=&$state;
+ }
+ $this->_stage=self::CS_STATE_LOADED;
+ if(isset($this->_rf[self::RF_ADAPTER]))
+ $this->_rf[self::RF_ADAPTER]->loadState();
+ else
+ $this->loadState();
+ }
+
+ /**
+ * Saves all control state (viewstate and controlstate) as a collection.
+ * This method should only be used by framework developers.
+ * @param boolean whether the viewstate should be saved
+ * @return array the collection of the control state (including its children's state).
+ */
+ protected function &saveStateRecursive($needViewState=true)
+ {
+ if(isset($this->_rf[self::RF_ADAPTER]))
+ $this->_rf[self::RF_ADAPTER]->saveState();
+ else
+ $this->saveState();
+ $needViewState=($needViewState && !($this->_flags & self::IS_DISABLE_VIEWSTATE));
+ $state=array();
+ if($this->getHasControls())
+ {
+ foreach($this->_rf[self::RF_CONTROLS] as $control)
+ {
+ if($control instanceof TControl)
+ $state[$control->_id]=&$control->saveStateRecursive($needViewState);
+ }
+ }
+ if($needViewState && !empty($this->_viewState))
+ $state[0]=&$this->_viewState;
+ if(isset($this->_rf[self::RF_CONTROLSTATE]))
+ $state[1]=&$this->_rf[self::RF_CONTROLSTATE];
+ return $state;
+ }
+
+ /**
+ * Applies a stylesheet skin to a control.
+ * @param TPage the page containing the control
+ * @throws TInvalidOperationException if the stylesheet skin is applied already
+ */
+ public function applyStyleSheetSkin($page)
+ {
+ if($page && !($this->_flags & self::IS_STYLESHEET_APPLIED))
+ {
+ $page->applyControlStyleSheet($this);
+ $this->_flags |= self::IS_STYLESHEET_APPLIED;
+ }
+ else if($this->_flags & self::IS_STYLESHEET_APPLIED)
+ throw new TInvalidOperationException('control_stylesheet_applied',get_class($this));
+ }
+
+ /**
+ * Clears the cached UniqueID.
+ * If $recursive=true, all children's cached UniqueID will be cleared as well.
+ * @param boolean whether the clearing is recursive.
+ */
+ private function clearCachedUniqueID($recursive)
+ {
+ if($recursive && $this->_uid!==null && isset($this->_rf[self::RF_CONTROLS]))
+ {
+ foreach($this->_rf[self::RF_CONTROLS] as $control)
+ if($control instanceof TControl)
+ $control->clearCachedUniqueID($recursive);
+ }
+ $this->_uid=null;
+ }
+
+ /**
+ * Generates an automatic ID for the control.
+ */
+ private function generateAutomaticID()
+ {
+ $this->_flags &= ~self::IS_ID_SET;
+ if(!isset($this->_namingContainer->_rf[self::RF_NAMED_CONTROLS_ID]))
+ $this->_namingContainer->_rf[self::RF_NAMED_CONTROLS_ID]=0;
+ $id=$this->_namingContainer->_rf[self::RF_NAMED_CONTROLS_ID]++;
+ $this->_id=self::AUTOMATIC_ID_PREFIX . $id;
+ $this->_namingContainer->clearNameTable();
+ }
+
+ /**
+ * Clears the list of the controls whose IDs are managed by the specified naming container.
+ */
+ private function clearNameTable()
+ {
+ unset($this->_rf[self::RF_NAMED_CONTROLS]);
+ }
+
+ /**
+ * Updates the list of the controls whose IDs are managed by the specified naming container.
+ * @param TControl the naming container
+ * @param TControlCollection list of controls
+ * @throws TInvalidDataValueException if a control's ID is not unique within its naming container.
+ */
+ private function fillNameTable($container,$controls)
+ {
+ foreach($controls as $control)
+ {
+ if($control instanceof TControl)
+ {
+ if($control->_id!=='')
+ {
+ if(isset($container->_rf[self::RF_NAMED_CONTROLS][$control->_id]))
+ throw new TInvalidDataValueException('control_id_nonunique',get_class($control),$control->_id);
+ else
+ $container->_rf[self::RF_NAMED_CONTROLS][$control->_id]=$control;
+ }
+ if(!($control instanceof INamingContainer) && $control->getHasControls())
+ $this->fillNameTable($container,$control->_rf[self::RF_CONTROLS]);
+ }
+ }
+ }
+}
+
+
+/**
+ * TControlCollection class
+ *
+ * TControlCollection implements a collection that enables
+ * controls to maintain a list of their child controls.
+ *
+ * @author Qiang Xue <qiang.xue@gmail.com>
+ * @version $Id$
+ * @package System.Web.UI
+ * @since 3.0
+ */
+class TControlCollection extends TList
+{
+ /**
+ * the control that owns this collection.
+ * @var TControl
+ */
+ private $_o;
+
+ /**
+ * Constructor.
+ * @param TControl the control that owns this collection.
+ * @param boolean whether the list is read-only
+ */
+ public function __construct(TControl $owner,$readOnly=false)
+ {
+ $this->_o=$owner;
+ parent::__construct(null,$readOnly);
+ }
+
+ /**
+ * @return TControl the control that owns this collection.
+ */
+ protected function getOwner()
+ {
+ return $this->_o;
+ }
+
+ /**
+ * Inserts an item at the specified position.
+ * This overrides the parent implementation by performing additional
+ * operations for each newly added child control.
+ * @param integer the speicified position.
+ * @param mixed new item
+ * @throws TInvalidDataTypeException if the item to be inserted is neither a string nor a TControl.
+ */
+ public function insertAt($index,$item)
+ {
+ if($item instanceof TControl)
+ {
+ parent::insertAt($index,$item);
+ $this->_o->addedControl($item);
+ }
+ else if(is_string($item) || ($item instanceof IRenderable))
+ parent::insertAt($index,$item);
+ else
+ throw new TInvalidDataTypeException('controlcollection_control_required');
+ }
+
+ /**
+ * Removes an item at the specified position.
+ * This overrides the parent implementation by performing additional
+ * cleanup work when removing a child control.
+ * @param integer the index of the item to be removed.
+ * @return mixed the removed item.
+ */
+ public function removeAt($index)
+ {
+ $item=parent::removeAt($index);
+ if($item instanceof TControl)
+ $this->_o->removedControl($item);
+ return $item;
+ }
+
+ /**
+ * Overrides the parent implementation by invoking {@link TControl::clearNamingContainer}
+ */
+ public function clear()
+ {
+ parent::clear();
+ if($this->_o instanceof INamingContainer)
+ $this->_o->clearNamingContainer();
+ }
+}
+
+/**
+ * TEmptyControlCollection class
+ *
+ * TEmptyControlCollection implements an empty control list that prohibits adding
+ * controls to it. This is useful for controls that do not allow child controls.
+ *
+ * @author Qiang Xue <qiang.xue@gmail.com>
+ * @version $Id$
+ * @package System.Web.UI
+ * @since 3.0
+ */
+class TEmptyControlCollection extends TControlCollection
+{
+ /**
+ * Constructor.
+ * @param TControl the control that owns this collection.
+ */
+ public function __construct(TControl $owner)
+ {
+ parent::__construct($owner,true);
+ }
+
+ /**
+ * Inserts an item at the specified position.
+ * This overrides the parent implementation by ignoring new addition.
+ * @param integer the speicified position.
+ * @param mixed new item
+ */
+ public function insertAt($index,$item)
+ {
+ if(!is_string($item)) // string is possible if property tag is used. we simply ignore it in this case
+ parent::insertAt($index,$item); // this will generate an exception in parent implementation
+ }
+}
+
+/**
+ * INamingContainer interface.
+ * INamingContainer marks a control as a naming container.
+ *
+ * @author Qiang Xue <qiang.xue@gmail.com>
+ * @version $Id$
+ * @package System.Web.UI
+ * @since 3.0
+ */
+interface INamingContainer
+{
+}
+
+/**
+ * IPostBackEventHandler interface
+ *
+ * If a control wants to respond to postback event, it must implement this interface.
+ *
+ * @author Qiang Xue <qiang.xue@gmail.com>
+ * @version $Id$
+ * @package System.Web.UI
+ * @since 3.0
+ */
+interface IPostBackEventHandler
+{
+ /**
+ * Raises postback event.
+ * The implementation of this function should raise appropriate event(s) (e.g. OnClick, OnCommand)
+ * indicating the component is responsible for the postback event.
+ * @param string the parameter associated with the postback event
+ */
+ public function raisePostBackEvent($param);
+}
+
+/**
+ * IPostBackDataHandler interface
+ *
+ * If a control wants to load post data, it must implement this interface.
+ *
+ * @author Qiang Xue <qiang.xue@gmail.com>
+ * @version $Id$
+ * @package System.Web.UI
+ * @since 3.0
+ */
+interface IPostBackDataHandler
+{
+ /**
+ * Loads user input data.
+ * The implementation of this function can use $values[$key] to get the user input
+ * data that are meant for the particular control.
+ * @param string the key that can be used to retrieve data from the input data collection
+ * @param array the input data collection
+ * @return boolean whether the data of the control has been changed
+ */
+ public function loadPostData($key,$values);
+ /**
+ * Raises postdata changed event.
+ * The implementation of this function should raise appropriate event(s) (e.g. OnTextChanged)
+ * indicating the control data is changed.
+ */
+ public function raisePostDataChangedEvent();
+ /**
+ * @return boolean whether postback causes the data change. Defaults to false for non-postback state.
+ */
+ public function getDataChanged();
+}
+
+
+/**
+ * IValidator interface
+ *
+ * If a control wants to validate user input, it must implement this interface.
+ *
+ * @author Qiang Xue <qiang.xue@gmail.com>
+ * @version $Id$
+ * @package System.Web.UI
+ * @since 3.0
+ */
+interface IValidator
+{
+ /**
+ * Validates certain data.
+ * The implementation of this function should validate certain data
+ * (e.g. data entered into TTextBox control).
+ * @return boolean whether the data passes the validation
+ */
+ public function validate();
+ /**
+ * @return boolean whether the previous {@link validate()} is successful.
+ */
+ public function getIsValid();
+ /**
+ * @param boolean whether the validator validates successfully
+ */
+ public function setIsValid($value);
+ /**
+ * @return string error message during last validate
+ */
+ public function getErrorMessage();
+ /**
+ * @param string error message for the validation
+ */
+ public function setErrorMessage($value);
+}
+
+
+/**
+ * IValidatable interface
+ *
+ * If a control wants to be validated by a validator, it must implement this interface.
+ *
+ * @author Qiang Xue <qiang.xue@gmail.com>
+ * @version $Id$
+ * @package System.Web.UI
+ * @since 3.0
+ */
+interface IValidatable
+{
+ /**
+ * @return mixed the value of the property to be validated.
+ */
+ public function getValidationPropertyValue();
+ /**
+ * @return boolean wether this control's validators validated successfully (must default to true)
+ */
+ public function getIsValid();
+ /**
+ * @return boolean wether this control's validators validated successfully
+ */
+ public function setIsValid($value);
+}
+
+/**
+ * IBroadcastEventReceiver interface
+ *
+ * If a control wants to check broadcast event, it must implement this interface.
+ *
+ * @author Qiang Xue <qiang.xue@gmail.com>
+ * @version $Id$
+ * @package System.Web.UI
+ * @since 3.0
+ */
+interface IBroadcastEventReceiver
+{
+ /**
+ * Handles broadcast event.
+ * This method is invoked automatically when an event is broadcasted.
+ * Within this method, you may check the event name given in
+ * the event parameter to determine whether you should respond to
+ * this event.
+ * @param TControl sender of the event
+ * @param TBroadCastEventParameter event parameter
+ */
+ public function broadcastEventReceived($sender,$param);
+}
+
+/**
+ * ITheme interface.
+ *
+ * This interface must be implemented by theme.
+ *
+ * @author Qiang Xue <qiang.xue@gmail.com>
+ * @version $Id$
+ * @package System.Web.UI
+ * @since 3.0
+ */
+interface ITheme
+{
+ /**
+ * Applies this theme to the specified control.
+ * @param TControl the control to be applied with this theme
+ */
+ public function applySkin($control);
+}
+
+/**
+ * ITemplate interface
+ *
+ * ITemplate specifies the interface for classes encapsulating
+ * parsed template structures.
+ *
+ * @author Qiang Xue <qiang.xue@gmail.com>
+ * @version $Id$
+ * @package System.Web.UI
+ * @since 3.0
+ */
+interface ITemplate
+{
+ /**
+ * Instantiates the template.
+ * Content in the template will be instantiated as components and text strings
+ * and passed to the specified parent control.
+ * @param TControl the parent control
+ */
+ public function instantiateIn($parent);
+}
+
+/**
+ * IButtonControl interface
+ *
+ * IButtonControl specifies the common properties and events that must
+ * be implemented by a button control, such as {@link TButton}, {@link TLinkButton},
+ * {@link TImageButton}.
+ *
+ * @author Qiang Xue <qiang.xue@gmail.com>
+ * @version $Id$
+ * @package System.Web.UI
+ * @since 3.0
+ */
+interface IButtonControl
+{
+ /**
+ * @return string caption of the button
+ */
+ public function getText();
+
+ /**
+ * @param string caption of the button
+ */
+ public function setText($value);
+
+ /**
+ * @return boolean whether postback event trigger by this button will cause input validation
+ */
+ public function getCausesValidation();
+
+ /**
+ * @param boolean whether postback event trigger by this button will cause input validation
+ */
+ public function setCausesValidation($value);
+
+ /**
+ * @return string the command name associated with the {@link onCommand OnCommand} event.
+ */
+ public function getCommandName();
+
+ /**
+ * @param string the command name associated with the {@link onCommand OnCommand} event.
+ */
+ public function setCommandName($value);
+
+ /**
+ * @return string the parameter associated with the {@link onCommand OnCommand} event
+ */
+ public function getCommandParameter();
+
+ /**
+ * @param string the parameter associated with the {@link onCommand OnCommand} event.
+ */
+ public function setCommandParameter($value);
+
+ /**
+ * @return string the group of validators which the button causes validation upon postback
+ */
+ public function getValidationGroup();
+
+ /**
+ * @param string the group of validators which the button causes validation upon postback
+ */
+ public function setValidationGroup($value);
+
+ /**
+ * Raises <b>OnClick</b> event.
+ * @param TEventParameter event parameter to be passed to the event handlers
+ */
+ public function onClick($param);
+
+ /**
+ * Raises <b>OnCommand</b> event.
+ * @param TCommandEventParameter event parameter to be passed to the event handlers
+ */
+ public function onCommand($param);
+
+ /**
+ * @param boolean set by a panel to register this button as the default button for the panel.
+ */
+ public function setIsDefaultButton($value);
+
+ /**
+ * @return boolean true if this button is registered as a default button for a panel.
+ */
+ public function getIsDefaultButton();
+}
+
+/**
+ * ISurroundable interface
+ *
+ * Identifies controls that may create an additional surrounding tag. The id of the
+ * tag can be obtained with {@link getSurroundingTagID}.
+ *
+ * @package System.Web.UI
+ * @since 3.1.2
+ */
+interface ISurroundable
+{
+ /**
+ * @return string the id of the embedding tag of the control or the control's clientID if not surrounded
+ */
+ public function getSurroundingTagID();
+}
+
+/**
+ * TBroadcastEventParameter class
+ *
+ * TBroadcastEventParameter encapsulates the parameter data for
+ * events that are broadcasted. The name of of the event is specified via
+ * {@link setName Name} property while the event parameter is via
+ * {@link setParameter Parameter} property.
+ *
+ * @author Qiang Xue <qiang.xue@gmail.com>
+ * @version $Id$
+ * @package System.Web.UI
+ * @since 3.0
+ */
+class TBroadcastEventParameter extends TEventParameter
+{
+ private $_name;
+ private $_param;
+
+ /**
+ * Constructor.
+ * @param string name of the broadcast event
+ * @param mixed parameter of the broadcast event
+ */
+ public function __construct($name='',$parameter=null)
+ {
+ $this->_name=$name;
+ $this->_param=$parameter;
+ }
+
+ /**
+ * @return string name of the broadcast event
+ */
+ public function getName()
+ {
+ return $this->_name;
+ }
+
+ /**
+ * @param string name of the broadcast event
+ */
+ public function setName($value)
+ {
+ $this->_name=$value;
+ }
+
+ /**
+ * @return mixed parameter of the broadcast event
+ */
+ public function getParameter()
+ {
+ return $this->_param;
+ }
+
+ /**
+ * @param mixed parameter of the broadcast event
+ */
+ public function setParameter($value)
+ {
+ $this->_param=$value;
+ }
+}
+
+/**
+ * TCommandEventParameter class
+ *
+ * TCommandEventParameter encapsulates the parameter data for <b>Command</b>
+ * event of button controls. You can access the name of the command via
+ * {@link getCommandName CommandName} property, and the parameter carried
+ * with the command via {@link getCommandParameter CommandParameter} property.
+ *
+ * @author Qiang Xue <qiang.xue@gmail.com>
+ * @version $Id$
+ * @package System.Web.UI
+ * @since 3.0
+ */
+class TCommandEventParameter extends TEventParameter
+{
+ private $_name;
+ private $_param;
+
+ /**
+ * Constructor.
+ * @param string name of the command
+ * @param string parameter of the command
+ */
+ public function __construct($name='',$parameter='')
+ {
+ $this->_name=$name;
+ $this->_param=$parameter;
+ }
+
+ /**
+ * @return string name of the command
+ */
+ public function getCommandName()
+ {
+ return $this->_name;
+ }
+
+ /**
+ * @return string parameter of the command
+ */
+ public function getCommandParameter()
+ {
+ return $this->_param;
+ }
+}
+
+
+/**
+ * TCompositeLiteral class
+ *
+ * TCompositeLiteral is used internally by {@link TTemplate} for representing
+ * consecutive static strings, expressions and statements.
+ *
+ * @author Qiang Xue <qiang.xue@gmail.com>
+ * @version $Id$
+ * @package System.Web.UI
+ * @since 3.0
+ */
+class TCompositeLiteral extends TComponent implements IRenderable, IBindable
+{
+ const TYPE_EXPRESSION=0;
+ const TYPE_STATEMENTS=1;
+ const TYPE_DATABINDING=2;
+ private $_container=null;
+ private $_items=array();
+ private $_expressions=array();
+ private $_statements=array();
+ private $_bindings=array();
+
+ /**
+ * Constructor.
+ * @param array list of items to be represented by TCompositeLiteral
+ */
+ public function __construct($items)
+ {
+ $this->_items=array();
+ $this->_expressions=array();
+ $this->_statements=array();
+ foreach($items as $id=>$item)
+ {
+ if(is_array($item))
+ {
+ if($item[0]===self::TYPE_EXPRESSION)
+ $this->_expressions[$id]=$item[1];
+ else if($item[0]===self::TYPE_STATEMENTS)
+ $this->_statements[$id]=$item[1];
+ else if($item[0]===self::TYPE_DATABINDING)
+ $this->_bindings[$id]=$item[1];
+ $this->_items[$id]='';
+ }
+ else
+ $this->_items[$id]=$item;
+ }
+ }
+
+ /**
+ * @return TComponent container of this component. It serves as the evaluation context of expressions and statements.
+ */
+ public function getContainer()
+ {
+ return $this->_container;
+ }
+
+ /**
+ * @param TComponent container of this component. It serves as the evaluation context of expressions and statements.
+ */
+ public function setContainer(TComponent $value)
+ {
+ $this->_container=$value;
+ }
+
+ /**
+ * Evaluates the expressions and/or statements in the component.
+ */
+ public function evaluateDynamicContent()
+ {
+ $context=$this->_container===null?$this:$this->_container;
+ foreach($this->_expressions as $id=>$expression)
+ $this->_items[$id]=$context->evaluateExpression($expression);
+ foreach($this->_statements as $id=>$statement)
+ $this->_items[$id]=$context->evaluateStatements($statement);
+ }
+
+ /**
+ * Performs databindings.
+ * This method is required by {@link IBindable}
+ */
+ public function dataBind()
+ {
+ $context=$this->_container===null?$this:$this->_container;
+ foreach($this->_bindings as $id=>$binding)
+ $this->_items[$id]=$context->evaluateExpression($binding);
+ }
+
+ /**
+ * Renders the content stored in this component.
+ * This method is required by {@link IRenderable}
+ * @param ITextWriter
+ */
+ public function render($writer)
+ {
+ $writer->write(implode('',$this->_items));
+ }
+}
+
+?>
diff --git a/framework/Web/UI/TControlAdapter.php b/framework/Web/UI/TControlAdapter.php
index 5f06c360..a1afd353 100644
--- a/framework/Web/UI/TControlAdapter.php
+++ b/framework/Web/UI/TControlAdapter.php
@@ -1,143 +1,143 @@
-<?php
-/**
- * TControlAdapter class file.
- *
- * @author Qiang Xue <qiang.xue@gmail.com>
- * @link http://www.pradosoft.com/
- * @copyright Copyright &copy; 2005-2012 PradoSoft
- * @license http://www.pradosoft.com/license/
- * @version $Id$
- * @package System.Web.UI
- */
-
-/**
- * TControlAdapter class
- *
- * TControlAdapter is the base class for adapters that customize
- * various behaviors for the control to which the adapter is attached.
- *
- * @author Qiang Xue <qiang.xue@gmail.com>
- * @version $Id$
- * @package System.Web.UI
- * @since 3.0
- */
-class TControlAdapter extends TApplicationComponent
-{
- /**
- * @var TControl the control to which the adapter is attached
- */
- protected $_control;
-
- /**
- * Constructor.
- * @param TControl the control to which the adapter is attached
- */
- public function __construct($control)
- {
- $this->_control=$control;
- }
-
- /**
- * @return TControl the control to which this adapter is attached
- */
- public function getControl()
- {
- return $this->_control;
- }
-
- /**
- * @return TPage the page that contains the attached control
- */
- public function getPage()
- {
- return $this->_control?$this->_control->getPage():null;
- }
-
- /**
- * Creates child controls for the attached control.
- * Default implementation calls the attached control's corresponding method.
- */
- public function createChildControls()
- {
- $this->_control->createChildControls();
- }
-
- /**
- * Loads additional persistent control state.
- * Default implementation calls the attached control's corresponding method.
- */
- public function loadState()
- {
- $this->_control->loadState();
- }
-
- /**
- * Saves additional persistent control state.
- * Default implementation calls the attached control's corresponding method.
- */
- public function saveState()
- {
- $this->_control->saveState();
- }
-
- /**
- * This method is invoked when the control enters 'OnInit' stage.
- * Default implementation calls the attached control's corresponding method.
- * @param TEventParameter event parameter to be passed to the event handlers
- */
- public function onInit($param)
- {
- $this->_control->onInit($param);
- }
-
- /**
- * This method is invoked when the control enters 'OnLoad' stage.
- * Default implementation calls the attached control's corresponding method.
- * @param TEventParameter event parameter to be passed to the event handlers
- */
- public function onLoad($param)
- {
- $this->_control->onLoad($param);
- }
-
- /**
- * This method is invoked when the control enters 'OnPreRender' stage.
- * Default implementation calls the attached control's corresponding method.
- * @param TEventParameter event parameter to be passed to the event handlers
- */
- public function onPreRender($param)
- {
- $this->_control->onPreRender($param);
- }
-
- /**
- * This method is invoked when the control enters 'OnUnload' stage.
- * Default implementation calls the attached control's corresponding method.
- * @param TEventParameter event parameter to be passed to the event handlers
- */
- public function onUnload($param)
- {
- $this->_control->onUnload($param);
- }
-
- /**
- * This method is invoked when the control renders itself.
- * Default implementation calls the attached control's corresponding method.
- * @param THtmlWriter writer for the rendering purpose
- */
- public function render($writer)
- {
- $this->_control->render($writer);
- }
-
- /**
- * Renders the control's children.
- * Default implementation calls the attached control's corresponding method.
- * @param THtmlWriter writer for the rendering purpose
- */
- public function renderChildren($writer)
- {
- $this->_control->renderChildren($writer);
- }
-}
-
+<?php
+/**
+ * TControlAdapter class file.
+ *
+ * @author Qiang Xue <qiang.xue@gmail.com>
+ * @link http://www.pradosoft.com/
+ * @copyright Copyright &copy; 2005-2012 PradoSoft
+ * @license http://www.pradosoft.com/license/
+ * @version $Id$
+ * @package System.Web.UI
+ */
+
+/**
+ * TControlAdapter class
+ *
+ * TControlAdapter is the base class for adapters that customize
+ * various behaviors for the control to which the adapter is attached.
+ *
+ * @author Qiang Xue <qiang.xue@gmail.com>
+ * @version $Id$
+ * @package System.Web.UI
+ * @since 3.0
+ */
+class TControlAdapter extends TApplicationComponent
+{
+ /**
+ * @var TControl the control to which the adapter is attached
+ */
+ protected $_control;
+
+ /**
+ * Constructor.
+ * @param TControl the control to which the adapter is attached
+ */
+ public function __construct($control)
+ {
+ $this->_control=$control;
+ }
+
+ /**
+ * @return TControl the control to which this adapter is attached
+ */
+ public function getControl()
+ {
+ return $this->_control;
+ }
+
+ /**
+ * @return TPage the page that contains the attached control
+ */
+ public function getPage()
+ {
+ return $this->_control?$this->_control->getPage():null;
+ }
+
+ /**
+ * Creates child controls for the attached control.
+ * Default implementation calls the attached control's corresponding method.
+ */
+ public function createChildControls()
+ {
+ $this->_control->createChildControls();
+ }
+
+ /**
+ * Loads additional persistent control state.
+ * Default implementation calls the attached control's corresponding method.
+ */
+ public function loadState()
+ {
+ $this->_control->loadState();
+ }
+
+ /**
+ * Saves additional persistent control state.
+ * Default implementation calls the attached control's corresponding method.
+ */
+ public function saveState()
+ {
+ $this->_control->saveState();
+ }
+
+ /**
+ * This method is invoked when the control enters 'OnInit' stage.
+ * Default implementation calls the attached control's corresponding method.
+ * @param TEventParameter event parameter to be passed to the event handlers
+ */
+ public function onInit($param)
+ {
+ $this->_control->onInit($param);
+ }
+
+ /**
+ * This method is invoked when the control enters 'OnLoad' stage.
+ * Default implementation calls the attached control's corresponding method.
+ * @param TEventParameter event parameter to be passed to the event handlers
+ */
+ public function onLoad($param)
+ {
+ $this->_control->onLoad($param);
+ }
+
+ /**
+ * This method is invoked when the control enters 'OnPreRender' stage.
+ * Default implementation calls the attached control's corresponding method.
+ * @param TEventParameter event parameter to be passed to the event handlers
+ */
+ public function onPreRender($param)
+ {
+ $this->_control->onPreRender($param);
+ }
+
+ /**
+ * This method is invoked when the control enters 'OnUnload' stage.
+ * Default implementation calls the attached control's corresponding method.
+ * @param TEventParameter event parameter to be passed to the event handlers
+ */
+ public function onUnload($param)
+ {
+ $this->_control->onUnload($param);
+ }
+
+ /**
+ * This method is invoked when the control renders itself.
+ * Default implementation calls the attached control's corresponding method.
+ * @param THtmlWriter writer for the rendering purpose
+ */
+ public function render($writer)
+ {
+ $this->_control->render($writer);
+ }
+
+ /**
+ * Renders the control's children.
+ * Default implementation calls the attached control's corresponding method.
+ * @param THtmlWriter writer for the rendering purpose
+ */
+ public function renderChildren($writer)
+ {
+ $this->_control->renderChildren($writer);
+ }
+}
+
diff --git a/framework/Web/UI/TForm.php b/framework/Web/UI/TForm.php
index f57f7482..2d60a4e4 100644
--- a/framework/Web/UI/TForm.php
+++ b/framework/Web/UI/TForm.php
@@ -1,171 +1,171 @@
-<?php
-/**
- * TForm class file
- *
- * @author Qiang Xue <qiang.xue@gmail.com>
- * @link http://www.pradosoft.com/
- * @copyright Copyright &copy; 2005-2012 PradoSoft
- * @license http://www.pradosoft.com/license/
- * @version $Id$
- * @package System.Web.UI
- */
-
-/**
- * TForm class
- *
- * TForm displays an HTML form. Besides regular body content,
- * it displays hidden fields, javascript blocks and files that are registered
- * through {@link TClientScriptManager}.
- *
- * A TForm is required for a page that needs postback.
- * Each page can contain at most one TForm. If multiple HTML forms are needed,
- * please use regular HTML form tags for those forms that post to different
- * URLs.
- *
- * @author Qiang Xue <qiang.xue@gmail.com>
- * @version $Id$
- * @package System.Web.UI
- * @since 3.0
- */
-class TForm extends TControl
-{
- /**
- * Registers the form with the page.
- * @param mixed event parameter
- */
- public function onInit($param)
- {
- parent::onInit($param);
- $this->getPage()->setForm($this);
- }
-
- /**
- * Adds form specific attributes to renderer.
- * @param THtmlWriter writer
- */
- protected function addAttributesToRender($writer)
- {
- $writer->addAttribute('id',$this->getClientID());
- $writer->addAttribute('method',$this->getMethod());
- $uri=$this->getRequest()->getRequestURI();
- $writer->addAttribute('action',str_replace('&','&amp;',str_replace('&amp;','&',$uri)));
- if(($enctype=$this->getEnctype())!=='')
- $writer->addAttribute('enctype',$enctype);
-
- $attributes=$this->getAttributes();
- $attributes->remove('action');
- $writer->addAttributes($attributes);
-
- if(($butt=$this->getDefaultButton())!=='')
- {
- if(($button=$this->findControl($butt))!==null)
- $this->getPage()->getClientScript()->registerDefaultButton($this, $button);
- else
- throw new TInvalidDataValueException('form_defaultbutton_invalid',$butt);
- }
- }
-
- /**
- * Renders the form.
- * @param THtmlWriter writer
- */
- public function render($writer)
- {
- $page=$this->getPage();
-
- $this->addAttributesToRender($writer);
- $writer->renderBeginTag('form');
-
- $cs=$page->getClientScript();
- if($page->getClientSupportsJavaScript())
- {
- $cs->renderHiddenFieldsBegin($writer);
- $cs->renderScriptFilesBegin($writer);
- $cs->renderBeginScripts($writer);
-
- $page->beginFormRender($writer);
- $this->renderChildren($writer);
- $cs->renderHiddenFieldsEnd($writer);
- $page->endFormRender($writer);
-
- $cs->renderScriptFilesEnd($writer);
- $cs->renderEndScripts($writer);
- }
- else
- {
- $cs->renderHiddenFieldsBegin($writer);
-
- $page->beginFormRender($writer);
- $this->renderChildren($writer);
- $page->endFormRender($writer);
-
- $cs->renderHiddenFieldsEnd($writer);
- }
-
- $writer->renderEndTag();
- }
-
- /**
- * @return string id path to the default button control.
- */
- public function getDefaultButton()
- {
- return $this->getViewState('DefaultButton','');
- }
-
- /**
- * Sets a button to be default one in a form.
- * A default button will be clicked if a user presses 'Enter' key within
- * the form.
- * @param string id path to the default button control.
- */
- public function setDefaultButton($value)
- {
- $this->setViewState('DefaultButton',$value,'');
- }
-
- /**
- * @return string form submission method. Defaults to 'post'.
- */
- public function getMethod()
- {
- return $this->getViewState('Method','post');
- }
-
- /**
- * @param string form submission method. Valid values include 'post' and 'get'.
- */
- public function setMethod($value)
- {
- $this->setViewState('Method',TPropertyValue::ensureEnum($value,'post','get'),'post');
- }
-
- /**
- * @return string the encoding type a browser uses to post data back to the server
- */
- public function getEnctype()
- {
- return $this->getViewState('Enctype','');
- }
-
- /**
- * @param string the encoding type a browser uses to post data back to the server.
- * Commonly used types include
- * - application/x-www-form-urlencoded : Form data is encoded as name/value pairs. This is the standard encoding format.
- * - multipart/form-data : Form data is encoded as a message with a separate part for each control on the page.
- * - text/plain : Form data is encoded in plain text, without any control or formatting characters.
- */
- public function setEnctype($value)
- {
- $this->setViewState('Enctype',$value,'');
- }
-
- /**
- * @return string form name, which is equal to {@link getUniqueID UniqueID}.
- */
- public function getName()
- {
- return $this->getUniqueID();
- }
-}
-
+<?php
+/**
+ * TForm class file
+ *
+ * @author Qiang Xue <qiang.xue@gmail.com>
+ * @link http://www.pradosoft.com/
+ * @copyright Copyright &copy; 2005-2012 PradoSoft
+ * @license http://www.pradosoft.com/license/
+ * @version $Id$
+ * @package System.Web.UI
+ */
+
+/**
+ * TForm class
+ *
+ * TForm displays an HTML form. Besides regular body content,
+ * it displays hidden fields, javascript blocks and files that are registered
+ * through {@link TClientScriptManager}.
+ *
+ * A TForm is required for a page that needs postback.
+ * Each page can contain at most one TForm. If multiple HTML forms are needed,
+ * please use regular HTML form tags for those forms that post to different
+ * URLs.
+ *
+ * @author Qiang Xue <qiang.xue@gmail.com>
+ * @version $Id$
+ * @package System.Web.UI
+ * @since 3.0
+ */
+class TForm extends TControl
+{
+ /**
+ * Registers the form with the page.
+ * @param mixed event parameter
+ */
+ public function onInit($param)
+ {
+ parent::onInit($param);
+ $this->getPage()->setForm($this);
+ }
+
+ /**
+ * Adds form specific attributes to renderer.
+ * @param THtmlWriter writer
+ */
+ protected function addAttributesToRender($writer)
+ {
+ $writer->addAttribute('id',$this->getClientID());
+ $writer->addAttribute('method',$this->getMethod());
+ $uri=$this->getRequest()->getRequestURI();
+ $writer->addAttribute('action',str_replace('&','&amp;',str_replace('&amp;','&',$uri)));
+ if(($enctype=$this->getEnctype())!=='')
+ $writer->addAttribute('enctype',$enctype);
+
+ $attributes=$this->getAttributes();
+ $attributes->remove('action');
+ $writer->addAttributes($attributes);
+
+ if(($butt=$this->getDefaultButton())!=='')
+ {
+ if(($button=$this->findControl($butt))!==null)
+ $this->getPage()->getClientScript()->registerDefaultButton($this, $button);
+ else
+ throw new TInvalidDataValueException('form_defaultbutton_invalid',$butt);
+ }
+ }
+
+ /**
+ * Renders the form.
+ * @param THtmlWriter writer
+ */
+ public function render($writer)
+ {
+ $page=$this->getPage();
+
+ $this->addAttributesToRender($writer);
+ $writer->renderBeginTag('form');
+
+ $cs=$page->getClientScript();
+ if($page->getClientSupportsJavaScript())
+ {
+ $cs->renderHiddenFieldsBegin($writer);
+ $cs->renderScriptFilesBegin($writer);
+ $cs->renderBeginScripts($writer);
+
+ $page->beginFormRender($writer);
+ $this->renderChildren($writer);
+ $cs->renderHiddenFieldsEnd($writer);
+ $page->endFormRender($writer);
+
+ $cs->renderScriptFilesEnd($writer);
+ $cs->renderEndScripts($writer);
+ }
+ else
+ {
+ $cs->renderHiddenFieldsBegin($writer);
+
+ $page->beginFormRender($writer);
+ $this->renderChildren($writer);
+ $page->endFormRender($writer);
+
+ $cs->renderHiddenFieldsEnd($writer);
+ }
+
+ $writer->renderEndTag();
+ }
+
+ /**
+ * @return string id path to the default button control.
+ */
+ public function getDefaultButton()
+ {
+ return $this->getViewState('DefaultButton','');
+ }
+
+ /**
+ * Sets a button to be default one in a form.
+ * A default button will be clicked if a user presses 'Enter' key within
+ * the form.
+ * @param string id path to the default button control.
+ */
+ public function setDefaultButton($value)
+ {
+ $this->setViewState('DefaultButton',$value,'');
+ }
+
+ /**
+ * @return string form submission method. Defaults to 'post'.
+ */
+ public function getMethod()
+ {
+ return $this->getViewState('Method','post');
+ }
+
+ /**
+ * @param string form submission method. Valid values include 'post' and 'get'.
+ */
+ public function setMethod($value)
+ {
+ $this->setViewState('Method',TPropertyValue::ensureEnum($value,'post','get'),'post');
+ }
+
+ /**
+ * @return string the encoding type a browser uses to post data back to the server
+ */
+ public function getEnctype()
+ {
+ return $this->getViewState('Enctype','');
+ }
+
+ /**
+ * @param string the encoding type a browser uses to post data back to the server.
+ * Commonly used types include
+ * - application/x-www-form-urlencoded : Form data is encoded as name/value pairs. This is the standard encoding format.
+ * - multipart/form-data : Form data is encoded as a message with a separate part for each control on the page.
+ * - text/plain : Form data is encoded in plain text, without any control or formatting characters.
+ */
+ public function setEnctype($value)
+ {
+ $this->setViewState('Enctype',$value,'');
+ }
+
+ /**
+ * @return string form name, which is equal to {@link getUniqueID UniqueID}.
+ */
+ public function getName()
+ {
+ return $this->getUniqueID();
+ }
+}
+
diff --git a/framework/Web/UI/THtmlWriter.php b/framework/Web/UI/THtmlWriter.php
index 96e1a5e1..9e264c77 100644
--- a/framework/Web/UI/THtmlWriter.php
+++ b/framework/Web/UI/THtmlWriter.php
@@ -1,229 +1,229 @@
-<?php
-/**
- * THtmlWriter class file
- *
- * @author Qiang Xue <qiang.xue@gmail.com>
- * @link http://www.pradosoft.com/
- * @copyright Copyright &copy; 2005-2012 PradoSoft
- * @license http://www.pradosoft.com/license/
- * @version $Id$
- * @package System.Web.UI
- */
-
-/**
- * THtmlWriter class
- *
- * THtmlWriter is a writer that renders valid XHTML outputs.
- * It provides functions to render tags, their attributes and stylesheet fields.
- * Attribute and stylesheet values will be automatically HTML-encoded if
- * they require so. For example, the 'value' attribute in an input tag
- * will be encoded.
- *
- * A common usage of THtmlWriter is as the following sequence:
- * <code>
- * $writer->addAttribute($name1,$value1);
- * $writer->addAttribute($name2,$value2);
- * $writer->renderBeginTag($tagName);
- * // ... render contents enclosed within the tag here
- * $writer->renderEndTag();
- * </code>
- * Make sure each invocation of {@link renderBeginTag} is accompanied with
- * a {@link renderEndTag} and they are properly nested, like nesting
- * tags in HTML and XHTML.
- *
- * @author Qiang Xue <qiang.xue@gmail.com>
- * @version $Id$
- * @package System.Web.UI
- * @since 3.0
- */
-class THtmlWriter extends TApplicationComponent implements ITextWriter
-{
- /**
- * @var array list of tags are do not need a closing tag
- */
- private static $_simpleTags=array(
- 'area'=>true,
- 'base'=>true,
- 'basefont'=>true,
- 'bgsound'=>true,
- 'col'=>true,
- 'embed'=>true,
- 'frame'=>true,
- 'hr'=>true,
- 'img'=>true,
- 'input'=>true,
- 'isindex'=>true,
- 'link'=>true,
- 'meta'=>true,
- 'wbr'=>true,
- );
- /**
- * @var array list of attributes to be rendered for a tag
- */
- private $_attributes=array();
- /**
- * @var array list of openning tags
- */
- private $_openTags=array();
- /**
- * @var array list of style attributes
- */
- private $_styles=array();
- /**
- * @var ITextWriter writer
- */
- private $_writer=null;
-
- /**
- * Constructor.
- * @param ITextWriter a writer that THtmlWriter will pass its rendering result to
- */
- public function __construct($writer)
- {
- $this->_writer=$writer;
- }
-
- public function getWriter()
- {
- return $this->_writer;
- }
-
- public function setWriter($writer)
- {
- $this->_writer = $writer;
- }
- /**
- * Adds a list of attributes to be rendered.
- * @param array list of attributes to be rendered
- */
- public function addAttributes($attrs)
- {
- foreach($attrs as $name=>$value)
- $this->_attributes[THttpUtility::htmlStrip($name)]=THttpUtility::htmlEncode($value);
- }
-
- /**
- * Adds an attribute to be rendered.
- * @param string name of the attribute
- * @param string value of the attribute
- */
- public function addAttribute($name,$value)
- {
- $this->_attributes[THttpUtility::htmlStrip($name)]=THttpUtility::htmlEncode($value);
- }
-
- /**
- * Removes the named attribute from rendering
- * @param string name of the attribute to be removed
- */
- public function removeAttribute($name)
- {
- unset($this->_attributes[THttpUtility::htmlStrip($name)]);
- }
-
- /**
- * Adds a list of stylesheet attributes to be rendered.
- * @param array list of stylesheet attributes to be rendered
- */
- public function addStyleAttributes($attrs)
- {
- foreach($attrs as $name=>$value)
- $this->_styles[THttpUtility::htmlStrip($name)]=THttpUtility::htmlEncode($value);
- }
-
- /**
- * Adds a stylesheet attribute to be rendered
- * @param string stylesheet attribute name
- * @param string stylesheet attribute value
- */
- public function addStyleAttribute($name,$value)
- {
- $this->_styles[THttpUtility::htmlStrip($name)]=THttpUtility::htmlEncode($value);
- }
-
- /**
- * Removes the named stylesheet attribute from rendering
- * @param string name of the stylesheet attribute to be removed
- */
- public function removeStyleAttribute($name)
- {
- unset($this->_styles[THttpUtility::htmlStrip($name)]);
- }
-
- /**
- * Flushes the rendering result.
- * This will invoke the underlying writer's flush method.
- * @return string the content being flushed
- */
- public function flush()
- {
- return $this->_writer->flush();
- }
-
- /**
- * Renders a string.
- * @param string string to be rendered
- */
- public function write($str)
- {
- $this->_writer->write($str);
- }
-
- /**
- * Renders a string and appends a newline to it.
- * @param string string to be rendered
- */
- public function writeLine($str='')
- {
- $this->_writer->write($str."\n");
- }
-
- /**
- * Renders an HTML break.
- */
- public function writeBreak()
- {
- $this->_writer->write('<br/>');
- }
-
- /**
- * Renders the openning tag.
- * @param string tag name
- */
- public function renderBeginTag($tagName)
- {
- $str='<'.$tagName;
- foreach($this->_attributes as $name=>$value)
- $str.=' '.$name.'="'.$value.'"';
- if(!empty($this->_styles))
- {
- $str.=' style="';
- foreach($this->_styles as $name=>$value)
- $str.=$name.':'.$value.';';
- $str.='"';
- }
- if(isset(self::$_simpleTags[$tagName]))
- {
- $str.=' />';
- $this->_openTags[] = '';
- }
- else
- {
- $str.='>';
- $this->_openTags[] = $tagName;
- }
- $this->_writer->write($str);
- $this->_attributes=array();
- $this->_styles=array();
- }
-
- /**
- * Renders the closing tag.
- */
- public function renderEndTag()
- {
- if(!empty($this->_openTags) && ($tagName=array_pop($this->_openTags))!=='')
- $this->_writer->write('</'.$tagName.'>');
- }
-}
-
+<?php
+/**
+ * THtmlWriter class file
+ *
+ * @author Qiang Xue <qiang.xue@gmail.com>
+ * @link http://www.pradosoft.com/
+ * @copyright Copyright &copy; 2005-2012 PradoSoft
+ * @license http://www.pradosoft.com/license/
+ * @version $Id$
+ * @package System.Web.UI
+ */
+
+/**
+ * THtmlWriter class
+ *
+ * THtmlWriter is a writer that renders valid XHTML outputs.
+ * It provides functions to render tags, their attributes and stylesheet fields.
+ * Attribute and stylesheet values will be automatically HTML-encoded if
+ * they require so. For example, the 'value' attribute in an input tag
+ * will be encoded.
+ *
+ * A common usage of THtmlWriter is as the following sequence:
+ * <code>
+ * $writer->addAttribute($name1,$value1);
+ * $writer->addAttribute($name2,$value2);
+ * $writer->renderBeginTag($tagName);
+ * // ... render contents enclosed within the tag here
+ * $writer->renderEndTag();
+ * </code>
+ * Make sure each invocation of {@link renderBeginTag} is accompanied with
+ * a {@link renderEndTag} and they are properly nested, like nesting
+ * tags in HTML and XHTML.
+ *
+ * @author Qiang Xue <qiang.xue@gmail.com>
+ * @version $Id$
+ * @package System.Web.UI
+ * @since 3.0
+ */
+class THtmlWriter extends TApplicationComponent implements ITextWriter
+{
+ /**
+ * @var array list of tags are do not need a closing tag
+ */
+ private static $_simpleTags=array(
+ 'area'=>true,
+ 'base'=>true,
+ 'basefont'=>true,
+ 'bgsound'=>true,
+ 'col'=>true,
+ 'embed'=>true,
+ 'frame'=>true,
+ 'hr'=>true,
+ 'img'=>true,
+ 'input'=>true,
+ 'isindex'=>true,
+ 'link'=>true,
+ 'meta'=>true,
+ 'wbr'=>true,
+ );
+ /**
+ * @var array list of attributes to be rendered for a tag
+ */
+ private $_attributes=array();
+ /**
+ * @var array list of openning tags
+ */
+ private $_openTags=array();
+ /**
+ * @var array list of style attributes
+ */
+ private $_styles=array();
+ /**
+ * @var ITextWriter writer
+ */
+ private $_writer=null;
+
+ /**
+ * Constructor.
+ * @param ITextWriter a writer that THtmlWriter will pass its rendering result to
+ */
+ public function __construct($writer)
+ {
+ $this->_writer=$writer;
+ }
+
+ public function getWriter()
+ {
+ return $this->_writer;
+ }
+
+ public function setWriter($writer)
+ {
+ $this->_writer = $writer;
+ }
+ /**
+ * Adds a list of attributes to be rendered.
+ * @param array list of attributes to be rendered
+ */
+ public function addAttributes($attrs)
+ {
+ foreach($attrs as $name=>$value)
+ $this->_attributes[THttpUtility::htmlStrip($name)]=THttpUtility::htmlEncode($value);
+ }
+
+ /**
+ * Adds an attribute to be rendered.
+ * @param string name of the attribute
+ * @param string value of the attribute
+ */
+ public function addAttribute($name,$value)
+ {
+ $this->_attributes[THttpUtility::htmlStrip($name)]=THttpUtility::htmlEncode($value);
+ }
+
+ /**
+ * Removes the named attribute from rendering
+ * @param string name of the attribute to be removed
+ */
+ public function removeAttribute($name)
+ {
+ unset($this->_attributes[THttpUtility::htmlStrip($name)]);
+ }
+
+ /**
+ * Adds a list of stylesheet attributes to be rendered.
+ * @param array list of stylesheet attributes to be rendered
+ */
+ public function addStyleAttributes($attrs)
+ {
+ foreach($attrs as $name=>$value)
+ $this->_styles[THttpUtility::htmlStrip($name)]=THttpUtility::htmlEncode($value);
+ }
+
+ /**
+ * Adds a stylesheet attribute to be rendered
+ * @param string stylesheet attribute name
+ * @param string stylesheet attribute value
+ */
+ public function addStyleAttribute($name,$value)
+ {
+ $this->_styles[THttpUtility::htmlStrip($name)]=THttpUtility::htmlEncode($value);
+ }
+
+ /**
+ * Removes the named stylesheet attribute from rendering
+ * @param string name of the stylesheet attribute to be removed
+ */
+ public function removeStyleAttribute($name)
+ {
+ unset($this->_styles[THttpUtility::htmlStrip($name)]);
+ }
+
+ /**
+ * Flushes the rendering result.
+ * This will invoke the underlying writer's flush method.
+ * @return string the content being flushed
+ */
+ public function flush()
+ {
+ return $this->_writer->flush();
+ }
+
+ /**
+ * Renders a string.
+ * @param string string to be rendered
+ */
+ public function write($str)
+ {
+ $this->_writer->write($str);
+ }
+
+ /**
+ * Renders a string and appends a newline to it.
+ * @param string string to be rendered
+ */
+ public function writeLine($str='')
+ {
+ $this->_writer->write($str."\n");
+ }
+
+ /**
+ * Renders an HTML break.
+ */
+ public function writeBreak()
+ {
+ $this->_writer->write('<br/>');
+ }
+
+ /**
+ * Renders the openning tag.
+ * @param string tag name
+ */
+ public function renderBeginTag($tagName)
+ {
+ $str='<'.$tagName;
+ foreach($this->_attributes as $name=>$value)
+ $str.=' '.$name.'="'.$value.'"';
+ if(!empty($this->_styles))
+ {
+ $str.=' style="';
+ foreach($this->_styles as $name=>$value)
+ $str.=$name.':'.$value.';';
+ $str.='"';
+ }
+ if(isset(self::$_simpleTags[$tagName]))
+ {
+ $str.=' />';
+ $this->_openTags[] = '';
+ }
+ else
+ {
+ $str.='>';
+ $this->_openTags[] = $tagName;
+ }
+ $this->_writer->write($str);
+ $this->_attributes=array();
+ $this->_styles=array();
+ }
+
+ /**
+ * Renders the closing tag.
+ */
+ public function renderEndTag()
+ {
+ if(!empty($this->_openTags) && ($tagName=array_pop($this->_openTags))!=='')
+ $this->_writer->write('</'.$tagName.'>');
+ }
+}
+
diff --git a/framework/Web/UI/TPage.php b/framework/Web/UI/TPage.php
index 37326031..26a06b64 100644
--- a/framework/Web/UI/TPage.php
+++ b/framework/Web/UI/TPage.php
@@ -1,1341 +1,1341 @@
-<?php
-/**
- * TPage class file
- *
- * @author Qiang Xue <qiang.xue@gmail.com>
- * @link http://www.pradosoft.com/
- * @copyright Copyright &copy; 2005-2012 PradoSoft
- * @license http://www.pradosoft.com/license/
- * @version $Id$
- * @package System.Web.UI
- */
-
-Prado::using('System.Web.UI.WebControls.*');
-Prado::using('System.Web.UI.TControl');
-Prado::using('System.Web.UI.WebControls.TWebControl');
-Prado::using('System.Web.UI.TCompositeControl');
-Prado::using('System.Web.UI.TTemplateControl');
-Prado::using('System.Web.UI.TForm');
-Prado::using('System.Web.UI.TClientScriptManager');
-
-/**
- * TPage class
- *
- * @author Qiang Xue <qiang.xue@gmail.com>
- * @version $Id$
- * @package System.Web.UI
- * @since 3.0
- */
-class TPage extends TTemplateControl
-{
- /**
- * system post fields
- */
- const FIELD_POSTBACK_TARGET='PRADO_POSTBACK_TARGET';
- const FIELD_POSTBACK_PARAMETER='PRADO_POSTBACK_PARAMETER';
- const FIELD_LASTFOCUS='PRADO_LASTFOCUS';
- const FIELD_PAGESTATE='PRADO_PAGESTATE';
- const FIELD_CALLBACK_TARGET='PRADO_CALLBACK_TARGET';
- const FIELD_CALLBACK_PARAMETER='PRADO_CALLBACK_PARAMETER';
-
- /**
- * @var array system post fields
- */
- private static $_systemPostFields=array(
- 'PRADO_POSTBACK_TARGET'=>true,
- 'PRADO_POSTBACK_PARAMETER'=>true,
- 'PRADO_LASTFOCUS'=>true,
- 'PRADO_PAGESTATE'=>true,
- 'PRADO_CALLBACK_TARGET'=>true,
- 'PRADO_CALLBACK_PARAMETER'=>true
- );
- /**
- * @var TForm form instance
- */
- private $_form;
- /**
- * @var THead head instance
- */
- private $_head;
- /**
- * @var array list of registered validators
- */
- private $_validators=array();
- /**
- * @var boolean if validation has been performed
- */
- private $_validated=false;
- /**
- * @var TTheme page theme
- */
- private $_theme;
- /**
- * @var string page title set when Head is not in page yet
- */
- private $_title;
- /**
- * @var TTheme page stylesheet theme
- */
- private $_styleSheet;
- /**
- * @var TClientScriptManager client script manager
- */
- private $_clientScript;
- /**
- * @var TMap data post back by user
- */
- protected $_postData;
- /**
- * @var TMap postback data that is not handled during first invocation of LoadPostData.
- */
- protected $_restPostData;
- /**
- * @var array list of controls whose data have been changed due to the postback
- */
- protected $_controlsPostDataChanged=array();
- /**
- * @var array list of controls that need to load post data in the current request
- */
- protected $_controlsRequiringPostData=array();
- /**
- * @var array list of controls that need to load post data in the next postback
- */
- protected $_controlsRegisteredForPostData=array();
- /**
- * @var TControl control that needs to raise postback event
- */
- private $_postBackEventTarget;
- /**
- * @var string postback event parameter
- */
- private $_postBackEventParameter;
- /**
- * @var boolean whether the form has been rendered
- */
- protected $_formRendered=false;
- /**
- * @var boolean whether the current rendering is within a form
- */
- protected $_inFormRender=false;
- /**
- * @var TControl|string the control or the ID of the element on the page to be focused when the page is sent back to user
- */
- private $_focus;
- /**
- * @var string page path to this page
- */
- private $_pagePath='';
- /**
- * @var boolean whether page state should be HMAC validated
- */
- private $_enableStateValidation=true;
- /**
- * @var boolean whether page state should be encrypted
- */
- private $_enableStateEncryption=false;
- /**
- * @var boolean whether page state should be compressed
- * @since 3.1.6
- */
- private $_enableStateCompression=true;
- /**
- * @var string page state persister class name
- */
- private $_statePersisterClass='System.Web.UI.TPageStatePersister';
- /**
- * @var mixed page state persister
- */
- private $_statePersister;
- /**
- * @var TStack stack used to store currently active caching controls
- */
- private $_cachingStack;
- /**
- * @var string state string to be stored on the client side
- */
- private $_clientState='';
- /**
- * @var array post data loader IDs.
- */
- protected $_postDataLoaders=array();
- /**
- * @var boolean true if loading post data.
- */
- protected $_isLoadingPostData=false;
- /**
- * @var boolean whether client supports javascript
- */
- private $_enableJavaScript=true;
- /**
- * @var THtmlWriter current html render writer
- */
- private $_writer;
-
- /**
- * Constructor.
- * Sets the page object to itself.
- * Derived classes must call parent implementation.
- */
- public function __construct()
- {
- $this->setPage($this);
- }
-
- /**
- * Runs through the page lifecycles.
- * @param THtmlTextWriter the HTML writer
- */
- public function run($writer)
- {
- Prado::trace("Running page life cycles",'System.Web.UI.TPage');
- $this->_writer = $writer;
-
- $this->determinePostBackMode();
-
- if($this->getIsPostBack())
- {
- if($this->getIsCallback())
- $this->processCallbackRequest($writer);
- else
- $this->processPostBackRequest($writer);
- }
- else
- $this->processNormalRequest($writer);
-
- $this->_writer = null;
- }
-
- protected function processNormalRequest($writer)
- {
- Prado::trace("Page onPreInit()",'System.Web.UI.TPage');
- $this->onPreInit(null);
-
- Prado::trace("Page initRecursive()",'System.Web.UI.TPage');
- $this->initRecursive();
-
- Prado::trace("Page onInitComplete()",'System.Web.UI.TPage');
- $this->onInitComplete(null);
-
- Prado::trace("Page onPreLoad()",'System.Web.UI.TPage');
- $this->onPreLoad(null);
- Prado::trace("Page loadRecursive()",'System.Web.UI.TPage');
- $this->loadRecursive();
- Prado::trace("Page onLoadComplete()",'System.Web.UI.TPage');
- $this->onLoadComplete(null);
-
- Prado::trace("Page preRenderRecursive()",'System.Web.UI.TPage');
- $this->preRenderRecursive();
- Prado::trace("Page onPreRenderComplete()",'System.Web.UI.TPage');
- $this->onPreRenderComplete(null);
-
- Prado::trace("Page savePageState()",'System.Web.UI.TPage');
- $this->savePageState();
- Prado::trace("Page onSaveStateComplete()",'System.Web.UI.TPage');
- $this->onSaveStateComplete(null);
-
- Prado::trace("Page renderControl()",'System.Web.UI.TPage');
- $this->renderControl($writer);
- Prado::trace("Page unloadRecursive()",'System.Web.UI.TPage');
- $this->unloadRecursive();
- }
-
- protected function processPostBackRequest($writer)
- {
- Prado::trace("Page onPreInit()",'System.Web.UI.TPage');
- $this->onPreInit(null);
-
- Prado::trace("Page initRecursive()",'System.Web.UI.TPage');
- $this->initRecursive();
-
- Prado::trace("Page onInitComplete()",'System.Web.UI.TPage');
- $this->onInitComplete(null);
-
- $this->_restPostData=new TMap;
- Prado::trace("Page loadPageState()",'System.Web.UI.TPage');
- $this->loadPageState();
- Prado::trace("Page processPostData()",'System.Web.UI.TPage');
- $this->processPostData($this->_postData,true);
- Prado::trace("Page onPreLoad()",'System.Web.UI.TPage');
- $this->onPreLoad(null);
- Prado::trace("Page loadRecursive()",'System.Web.UI.TPage');
- $this->loadRecursive();
- Prado::trace("Page processPostData()",'System.Web.UI.TPage');
- $this->processPostData($this->_restPostData,false);
- Prado::trace("Page raiseChangedEvents()",'System.Web.UI.TPage');
- $this->raiseChangedEvents();
- Prado::trace("Page raisePostBackEvent()",'System.Web.UI.TPage');
- $this->raisePostBackEvent();
- Prado::trace("Page onLoadComplete()",'System.Web.UI.TPage');
- $this->onLoadComplete(null);
-
- Prado::trace("Page preRenderRecursive()",'System.Web.UI.TPage');
- $this->preRenderRecursive();
- Prado::trace("Page onPreRenderComplete()",'System.Web.UI.TPage');
- $this->onPreRenderComplete(null);
-
- Prado::trace("Page savePageState()",'System.Web.UI.TPage');
- $this->savePageState();
- Prado::trace("Page onSaveStateComplete()",'System.Web.UI.TPage');
- $this->onSaveStateComplete(null);
-
- Prado::trace("Page renderControl()",'System.Web.UI.TPage');
- $this->renderControl($writer);
- Prado::trace("Page unloadRecursive()",'System.Web.UI.TPage');
- $this->unloadRecursive();
- }
-
- protected static function decodeUTF8($data, $enc)
- {
- if(is_array($data))
- {
- foreach($data as $k=>$v)
- $data[$k]=self::decodeUTF8($v, $enc);
- return $data;
- } elseif(is_string($data)) {
- return iconv('UTF-8',$enc.'//IGNORE',$data);
- } else {
- return $data;
- }
- }
-
- /**
- * Sets Adapter to TActivePageAdapter and calls apter to process the
- * callback request.
- */
- protected function processCallbackRequest($writer)
- {
- Prado::using('System.Web.UI.ActiveControls.TActivePageAdapter');
-
- $this->setAdapter(new TActivePageAdapter($this));
-
- // Decode Callback postData from UTF-8 to current Charset
- if (($g=$this->getApplication()->getGlobalization(false))!==null &&
- strtoupper($enc=$g->getCharset())!='UTF-8')
- foreach ($this->_postData as $k=>$v)
- $this->_postData[$k]=self::decodeUTF8($v, $enc);
-
- Prado::trace("Page onPreInit()",'System.Web.UI.TPage');
- $this->onPreInit(null);
-
- Prado::trace("Page initRecursive()",'System.Web.UI.TPage');
- $this->initRecursive();
-
- Prado::trace("Page onInitComplete()",'System.Web.UI.TPage');
- $this->onInitComplete(null);
-
- $this->_restPostData=new TMap;
- Prado::trace("Page loadPageState()",'System.Web.UI.TPage');
- $this->loadPageState();
- Prado::trace("Page processPostData()",'System.Web.UI.TPage');
- $this->processPostData($this->_postData,true);
- Prado::trace("Page onPreLoad()",'System.Web.UI.TPage');
- $this->onPreLoad(null);
- Prado::trace("Page loadRecursive()",'System.Web.UI.TPage');
- $this->loadRecursive();
-
- Prado::trace("Page processPostData()",'System.Web.UI.TPage');
- $this->processPostData($this->_restPostData,false);
-
- Prado::trace("Page raiseChangedEvents()",'System.Web.UI.TPage');
- $this->raiseChangedEvents();
-
-
- $this->getAdapter()->processCallbackEvent($writer);
-
-/*
- Prado::trace("Page raisePostBackEvent()",'System.Web.UI.TPage');
- $this->raisePostBackEvent();
-*/
- Prado::trace("Page onLoadComplete()",'System.Web.UI.TPage');
- $this->onLoadComplete(null);
-
- Prado::trace("Page preRenderRecursive()",'System.Web.UI.TPage');
- $this->preRenderRecursive();
- Prado::trace("Page onPreRenderComplete()",'System.Web.UI.TPage');
- $this->onPreRenderComplete(null);
-
- Prado::trace("Page savePageState()",'System.Web.UI.TPage');
- $this->savePageState();
- Prado::trace("Page onSaveStateComplete()",'System.Web.UI.TPage');
- $this->onSaveStateComplete(null);
-
-/*
- Prado::trace("Page renderControl()",'System.Web.UI.TPage');
- $this->renderControl($writer);
-*/
- $this->getAdapter()->renderCallbackResponse($writer);
-
- Prado::trace("Page unloadRecursive()",'System.Web.UI.TPage');
- $this->unloadRecursive();
- }
-
- /**
- * Gets the callback client script handler that allows javascript functions
- * to be executed during the callback response.
- * @return TCallbackClientScript interface to client-side javascript code.
- */
- public function getCallbackClient()
- {
- if($this->getAdapter() !== null)
- return $this->getAdapter()->getCallbackClientHandler();
- else
- return new TCallbackClientScript();
- }
-
- /**
- * Set a new callback client handler.
- * @param TCallbackClientScript new callback client script handler.
- */
- public function setCallbackClient($client)
- {
- $this->getAdapter()->setCallbackClientHandler($client);
- }
-
- /**
- * @return TControl the control responsible for the current callback event,
- * null if nonexistent
- */
- public function getCallbackEventTarget()
- {
- return $this->getAdapter()->getCallbackEventTarget();
- }
-
- /**
- * Registers a control to raise callback event in the current request.
- * @param TControl control registered to raise callback event.
- */
- public function setCallbackEventTarget(TControl $control)
- {
- $this->getAdapter()->setCallbackEventTarget($control);
- }
-
- /**
- * Callback parameter is decoded assuming JSON encoding.
- * @return string callback event parameter
- */
- public function getCallbackEventParameter()
- {
- return $this->getAdapter()->getCallbackEventParameter();
- }
-
- /**
- * @param mixed callback event parameter
- */
- public function setCallbackEventParameter($value)
- {
- $this->getAdapter()->setCallbackEventParameter($value);
- }
-
- /**
- * Register post data loaders for Callback to collect post data.
- * This method should only be called by framework developers.
- * @param TControl control that requires post data.
- * @see TControl::preRenderRecursive();
- */
- public function registerPostDataLoader($control)
- {
- $id=is_string($control)?$control:$control->getUniqueID();
- $this->_postDataLoaders[$id] = true;
- }
-
- /**
- * Get a list of IDs of controls that are enabled and require post data.
- * @return array list of IDs implementing IPostBackDataHandler
- */
- public function getPostDataLoaders()
- {
- return array_keys($this->_postDataLoaders);
- }
-
- /**
- * @return TForm the form on the page
- */
- public function getForm()
- {
- return $this->_form;
- }
-
- /**
- * Registers a TForm instance to the page.
- * Note, a page can contain at most one TForm instance.
- * @param TForm the form on the page
- * @throws TInvalidOperationException if this method is invoked twice or more.
- */
- public function setForm(TForm $form)
- {
- if($this->_form===null)
- $this->_form=$form;
- else
- throw new TInvalidOperationException('page_form_duplicated');
- }
-
- /**
- * Returns a list of registered validators.
- * If validation group is specified, only the validators in that group will be returned.
- * @param string validation group
- * @return TList registered validators in the requested group. If the group is null, all validators will be returned.
- */
- public function getValidators($validationGroup=null)
- {
- if(!$this->_validators)
- $this->_validators=new TList;
- if(empty($validationGroup) === true)
- return $this->_validators;
- else
- {
- $list=new TList;
- foreach($this->_validators as $validator)
- if($validator->getValidationGroup()===$validationGroup)
- $list->add($validator);
- return $list;
- }
- }
-
- /**
- * Performs input validation.
- * This method will invoke the registered validators to perform the actual validation.
- * If validation group is specified, only the validators in that group will be invoked.
- * @param string validation group. If null, all validators will perform validation.
- */
- public function validate($validationGroup=null)
- {
- Prado::trace("Page validate()",'System.Web.UI.TPage');
- $this->_validated=true;
- if($this->_validators && $this->_validators->getCount())
- {
- if($validationGroup===null)
- {
- foreach($this->_validators as $validator)
- $validator->validate();
- }
- else
- {
- foreach($this->_validators as $validator)
- {
- if($validator->getValidationGroup()===$validationGroup)
- $validator->validate();
- }
- }
- }
- }
-
- /**
- * Returns whether user input is valid or not.
- * This method must be invoked after {@link validate} is called.
- * @return boolean whether the user input is valid or not.
- * @throws TInvalidOperationException if {@link validate} is not invoked yet.
- */
- public function getIsValid()
- {
- if($this->_validated)
- {
- if($this->_validators && $this->_validators->getCount())
- {
- foreach($this->_validators as $validator)
- if(!$validator->getIsValid())
- return false;
- }
- return true;
- }
- else
- throw new TInvalidOperationException('page_isvalid_unknown');
- }
-
- /**
- * @return TTheme the theme used for the page. Defaults to null.
- */
- public function getTheme()
- {
- if(is_string($this->_theme))
- $this->_theme=$this->getService()->getThemeManager()->getTheme($this->_theme);
- return $this->_theme;
- }
-
- /**
- * Sets the theme to be used for the page.
- * @param string|TTheme the theme name or the theme object to be used for the page.
- */
- public function setTheme($value)
- {
- $this->_theme=empty($value)?null:$value;
- }
-
-
- /**
- * @return TTheme the stylesheet theme used for the page. Defaults to null.
- */
- public function getStyleSheetTheme()
- {
- if(is_string($this->_styleSheet))
- $this->_styleSheet=$this->getService()->getThemeManager()->getTheme($this->_styleSheet);
- return $this->_styleSheet;
- }
-
- /**
- * Sets the stylesheet theme to be used for the page.
- * @param string|TTheme the stylesheet theme name or the stylesheet theme object to be used for the page.
- */
- public function setStyleSheetTheme($value)
- {
- $this->_styleSheet=empty($value)?null:$value;
- }
-
- /**
- * Applies a skin in the current theme to a control.
- * This method should only be used by framework developers.
- * @param TControl a control to be applied skin with
- */
- public function applyControlSkin($control)
- {
- if(($theme=$this->getTheme())!==null)
- $theme->applySkin($control);
- }
-
- /**
- * Applies a stylesheet skin in the current theme to a control.
- * This method should only be used by framework developers.
- * @param TControl a control to be applied stylesheet skin with
- */
- public function applyControlStyleSheet($control)
- {
- if(($theme=$this->getStyleSheetTheme())!==null)
- $theme->applySkin($control);
- }
-
- /**
- * @return TClientScriptManager client script manager
- */
- public function getClientScript()
- {
- if(!$this->_clientScript) {
- $className = $classPath = $this->getService()->getClientScriptManagerClass();
- Prado::using($className);
- if(($pos=strrpos($className,'.'))!==false)
- $className=substr($className,$pos+1);
-
- if(!class_exists($className,false) || ($className!=='TClientScriptManager' && !is_subclass_of($className,'TClientScriptManager')))
- throw new THttpException(404,'page_csmanagerclass_invalid',$classPath);
-
- $this->_clientScript=new $className($this);
- }
- return $this->_clientScript;
- }
-
- /**
- * Raises OnPreInit event.
- * This method is invoked right before {@link onInit OnInit} stage.
- * You may override this method to provide additional initialization that
- * should be done before {@link onInit OnInit} (e.g. setting {@link setTheme Theme} or
- * {@link setStyleSheetTheme StyleSheetTheme}).
- * Remember to call the parent implementation to ensure OnPreInit event is raised.
- * @param mixed event parameter
- */
- public function onPreInit($param)
- {
- $this->raiseEvent('OnPreInit',$this,$param);
- }
-
- /**
- * Raises OnInitComplete event.
- * This method is invoked right after {@link onInit OnInit} stage and before {@link onLoad OnLoad} stage.
- * You may override this method to provide additional initialization that
- * should be done after {@link onInit OnInit}.
- * Remember to call the parent implementation to ensure OnInitComplete event is raised.
- * @param mixed event parameter
- */
- public function onInitComplete($param)
- {
- $this->raiseEvent('OnInitComplete',$this,$param);
- }
-
- /**
- * Raises OnPreLoad event.
- * This method is invoked right before {@link onLoad OnLoad} stage.
- * You may override this method to provide additional page loading logic that
- * should be done before {@link onLoad OnLoad}.
- * Remember to call the parent implementation to ensure OnPreLoad event is raised.
- * @param mixed event parameter
- */
- public function onPreLoad($param)
- {
- $this->raiseEvent('OnPreLoad',$this,$param);
- }
-
- /**
- * Raises OnLoadComplete event.
- * This method is invoked right after {@link onLoad OnLoad} stage.
- * You may override this method to provide additional page loading logic that
- * should be done after {@link onLoad OnLoad}.
- * Remember to call the parent implementation to ensure OnLoadComplete event is raised.
- * @param mixed event parameter
- */
- public function onLoadComplete($param)
- {
- $this->raiseEvent('OnLoadComplete',$this,$param);
- }
-
- /**
- * Raises OnPreRenderComplete event.
- * This method is invoked right after {@link onPreRender OnPreRender} stage.
- * You may override this method to provide additional preparation for page rendering
- * that should be done after {@link onPreRender OnPreRender}.
- * Remember to call the parent implementation to ensure OnPreRenderComplete event is raised.
- * @param mixed event parameter
- */
- public function onPreRenderComplete($param)
- {
- $this->raiseEvent('OnPreRenderComplete',$this,$param);
- $cs=$this->getClientScript();
- $theme=$this->getTheme();
- if($theme instanceof ITheme)
- {
- foreach($theme->getStyleSheetFiles() as $url)
- $cs->registerStyleSheetFile($url,$url,$this->getCssMediaType($url));
- foreach($theme->getJavaScriptFiles() as $url)
- $cs->registerHeadScriptFile($url,$url);
- }
- $styleSheet=$this->getStyleSheetTheme();
- if($styleSheet instanceof ITheme)
- {
- foreach($styleSheet->getStyleSheetFiles() as $url)
- $cs->registerStyleSheetFile($url,$url,$this->getCssMediaType($url));
- foreach($styleSheet->getJavaScriptFiles() as $url)
- $cs->registerHeadScriptFile($url,$url);
- }
-
- if($cs->getRequiresHead() && $this->getHead()===null)
- throw new TConfigurationException('page_head_required');
- }
-
- /**
- * Determines the media type of the CSS file.
- * The media type is determined according to the following file name pattern:
- * xxx.media-type.extension
- * For example, 'mystyle.print.css' means its media type is 'print'.
- * @param string CSS URL
- * @return string media type of the CSS file
- */
- private function getCssMediaType($url)
- {
- $segs=explode('.',basename($url));
- if(isset($segs[2]))
- return $segs[count($segs)-2];
- else
- return '';
- }
-
- /**
- * Raises OnSaveStateComplete event.
- * This method is invoked right after {@link onSaveState OnSaveState} stage.
- * You may override this method to provide additional logic after page state is saved.
- * Remember to call the parent implementation to ensure OnSaveStateComplete event is raised.
- * @param mixed event parameter
- */
- public function onSaveStateComplete($param)
- {
- $this->raiseEvent('OnSaveStateComplete',$this,$param);
- }
-
- /**
- * Determines whether the current page request is a postback.
- * Call {@link getIsPostBack} to get the result.
- */
- private function determinePostBackMode()
- {
- $postData=$this->getRequest();
- if($postData->contains(self::FIELD_PAGESTATE) || $postData->contains(self::FIELD_POSTBACK_TARGET))
- $this->_postData=$postData;
- }
-
- /**
- * @return boolean whether the current page request is a postback
- */
- public function getIsPostBack()
- {
- return $this->_postData!==null;
- }
-
- /**
- * @return boolean whether this is a callback request
- */
- public function getIsCallback()
- {
- return $this->getIsPostBack() && $this->getRequest()->contains(self::FIELD_CALLBACK_TARGET);
- }
-
- /**
- * This method is invoked when control state is to be saved.
- * You can override this method to do last step state saving.
- * Parent implementation must be invoked.
- */
- public function saveState()
- {
- parent::saveState();
- $this->setViewState('ControlsRequiringPostBack',$this->_controlsRegisteredForPostData,array());
- }
-
- /**
- * This method is invoked right after the control has loaded its state.
- * You can override this method to initialize data from the control state.
- * Parent implementation must be invoked.
- */
- public function loadState()
- {
- parent::loadState();
- $this->_controlsRequiringPostData=$this->getViewState('ControlsRequiringPostBack',array());
- }
-
- /**
- * Loads page state from persistent storage.
- */
- protected function loadPageState()
- {
- Prado::trace("Loading state",'System.Web.UI.TPage');
- $state=$this->getStatePersister()->load();
- $this->loadStateRecursive($state,$this->getEnableViewState());
- }
-
- /**
- * Saves page state from persistent storage.
- */
- protected function savePageState()
- {
- Prado::trace("Saving state",'System.Web.UI.TPage');
- $state=&$this->saveStateRecursive($this->getEnableViewState());
- $this->getStatePersister()->save($state);
- }
-
- /**
- * @param string the field name
- * @return boolean whether the specified field is a system field in postback data
- */
- protected function isSystemPostField($field)
- {
- return isset(self::$_systemPostFields[$field]);
- }
-
- /**
- * Registers a control for loading post data in the next postback.
- * This method needs to be invoked if the control to load post data
- * may not have a post variable in some cases. For example, a checkbox,
- * if not checked, will not have a post value.
- * @param TControl control registered for loading post data
- */
- public function registerRequiresPostData($control)
- {
- $id=is_string($control)?$control:$control->getUniqueID();
- $this->_controlsRegisteredForPostData[$id]=true;
- $this->registerPostDataLoader($id);
- $params=func_get_args();
- foreach($this->getCachingStack() as $item)
- $item->registerAction('Page','registerRequiresPostData',array($id));
- }
-
- /**
- * @return TControl the control responsible for the current postback event, null if nonexistent
- */
- public function getPostBackEventTarget()
- {
- if($this->_postBackEventTarget===null && $this->_postData!==null)
- {
- $eventTarget=$this->_postData->itemAt(self::FIELD_POSTBACK_TARGET);
- if(!empty($eventTarget))
- $this->_postBackEventTarget=$this->findControl($eventTarget);
- }
- return $this->_postBackEventTarget;
- }
-
- /**
- * Registers a control to raise postback event in the current request.
- * @param TControl control registered to raise postback event.
- */
- public function setPostBackEventTarget(TControl $control)
- {
- $this->_postBackEventTarget=$control;
- }
-
- /**
- * @return string postback event parameter
- */
- public function getPostBackEventParameter()
- {
- if($this->_postBackEventParameter===null && $this->_postData!==null)
- {
- if(($this->_postBackEventParameter=$this->_postData->itemAt(self::FIELD_POSTBACK_PARAMETER))===null)
- $this->_postBackEventParameter='';
- }
- return $this->_postBackEventParameter;
- }
-
- /**
- * @param string postback event parameter
- */
- public function setPostBackEventParameter($value)
- {
- $this->_postBackEventParameter=$value;
- }
-
- /**
- * Processes post data.
- * @param TMap post data to be processed
- * @param boolean whether this method is invoked before {@link onLoad OnLoad}.
- */
- protected function processPostData($postData,$beforeLoad)
- {
- $this->_isLoadingPostData=true;
- if($beforeLoad)
- $this->_restPostData=new TMap;
- foreach($postData as $key=>$value)
- {
- if($this->isSystemPostField($key))
- continue;
- else if($control=$this->findControl($key))
- {
- if($control instanceof IPostBackDataHandler)
- {
- if($control->loadPostData($key,$postData))
- $this->_controlsPostDataChanged[]=$control;
- }
- else if($control instanceof IPostBackEventHandler &&
- empty($this->_postData[self::FIELD_POSTBACK_TARGET]))
- {
- $this->_postData->add(self::FIELD_POSTBACK_TARGET,$key); // not calling setPostBackEventTarget() because the control may be removed later
- }
- unset($this->_controlsRequiringPostData[$key]);
- }
- else if($beforeLoad)
- $this->_restPostData->add($key,$value);
- }
-
- foreach($this->_controlsRequiringPostData as $key=>$value)
- {
- if($control=$this->findControl($key))
- {
- if($control instanceof IPostBackDataHandler)
- {
- if($control->loadPostData($key,$this->_postData))
- $this->_controlsPostDataChanged[]=$control;
- }
- else
- throw new TInvalidDataValueException('page_postbackcontrol_invalid',$key);
- unset($this->_controlsRequiringPostData[$key]);
- }
- }
- $this->_isLoadingPostData=false;
- }
-
- /**
- * @return boolean true if loading post data.
- */
- public function getIsLoadingPostData()
- {
- return $this->_isLoadingPostData;
- }
-
- /**
- * Raises OnPostDataChangedEvent for controls whose data have been changed due to the postback.
- */
- protected function raiseChangedEvents()
- {
- foreach($this->_controlsPostDataChanged as $control)
- $control->raisePostDataChangedEvent();
- }
-
- /**
- * Raises PostBack event.
- */
- protected function raisePostBackEvent()
- {
- if(($postBackHandler=$this->getPostBackEventTarget())===null)
- $this->validate();
- else if($postBackHandler instanceof IPostBackEventHandler)
- $postBackHandler->raisePostBackEvent($this->getPostBackEventParameter());
- }
-
- /**
- * @return boolean Whether form rendering is in progress
- */
- public function getInFormRender()
- {
- return $this->_inFormRender;
- }
-
- /**
- * Ensures the control is rendered within a form.
- * @param TControl the control to be rendered
- * @throws TConfigurationException if the control is outside of the form
- */
- public function ensureRenderInForm($control)
- {
- if(!$this->getIsCallback() && !$this->_inFormRender)
- throw new TConfigurationException('page_control_outofform',get_class($control), $control ? $control->getUniqueID() : null);
- }
-
- /**
- * @internal This method is invoked by TForm at the beginning of its rendering
- */
- public function beginFormRender($writer)
- {
- if($this->_formRendered)
- throw new TConfigurationException('page_form_duplicated');
- $this->_formRendered=true;
- $this->getClientScript()->registerHiddenField(self::FIELD_PAGESTATE,$this->getClientState());
- $this->_inFormRender=true;
- }
-
- /**
- * @internal This method is invoked by TForm at the end of its rendering
- */
- public function endFormRender($writer)
- {
- if($this->_focus)
- {
- if(($this->_focus instanceof TControl) && $this->_focus->getVisible(true))
- $focus=$this->_focus->getClientID();
- else
- $focus=$this->_focus;
- $this->getClientScript()->registerFocusControl($focus);
- }
- else if($this->_postData && ($lastFocus=$this->_postData->itemAt(self::FIELD_LASTFOCUS))!==null)
- $this->getClientScript()->registerFocusControl($lastFocus);
- $this->_inFormRender=false;
- }
-
- /**
- * Sets input focus on a control after the page is rendered to users.
- * @param TControl|string control to receive focus, or the ID of the element on the page to receive focus
- */
- public function setFocus($value)
- {
- $this->_focus=$value;
- }
-
- /**
- * @return boolean whether client supports javascript. Defaults to true.
- */
- public function getClientSupportsJavaScript()
- {
- return $this->_enableJavaScript;
- }
-
- /**
- * @param boolean whether client supports javascript. If false, javascript will not be generated for controls.
- */
- public function setClientSupportsJavaScript($value)
- {
- $this->_enableJavaScript=TPropertyValue::ensureBoolean($value);
- }
-
- /**
- * @return THead page head, null if not available
- */
- public function getHead()
- {
- return $this->_head;
- }
-
- /**
- * @param THead page head
- * @throws TInvalidOperationException if a head already exists
- */
- public function setHead(THead $value)
- {
- if($this->_head)
- throw new TInvalidOperationException('page_head_duplicated');
- $this->_head=$value;
- if($this->_title!==null)
- {
- $this->_head->setTitle($this->_title);
- $this->_title=null;
- }
- }
-
- /**
- * @return string page title.
- */
- public function getTitle()
- {
- if($this->_head)
- return $this->_head->getTitle();
- else
- return $this->_title===null ? '' : $this->_title;
- }
-
- /**
- * Sets the page title.
- * Note, a {@link THead} control needs to place on the page
- * in order that this title be rendered.
- * @param string page title. This will override the title set in {@link getHead Head}.
- */
- public function setTitle($value)
- {
- if($this->_head)
- $this->_head->setTitle($value);
- else
- $this->_title=$value;
- }
-
- /**
- * Returns the state to be stored on the client side.
- * This method should only be used by framework and control developers.
- * @return string the state to be stored on the client side
- */
- public function getClientState()
- {
- return $this->_clientState;
- }
-
- /**
- * Sets the state to be stored on the client side.
- * This method should only be used by framework and control developers.
- * @param string the state to be stored on the client side
- */
- public function setClientState($state)
- {
- $this->_clientState=$state;
- }
-
- /**
- * @return string the state postback from client side
- */
- public function getRequestClientState()
- {
- return $this->getRequest()->itemAt(self::FIELD_PAGESTATE);
- }
-
- /**
- * @return string class name of the page state persister. Defaults to TPageStatePersister.
- */
- public function getStatePersisterClass()
- {
- return $this->_statePersisterClass;
- }
-
- /**
- * @param string class name of the page state persister.
- */
- public function setStatePersisterClass($value)
- {
- $this->_statePersisterClass=$value;
- }
-
- /**
- * @return IPageStatePersister page state persister
- */
- public function getStatePersister()
- {
- if($this->_statePersister===null)
- {
- $this->_statePersister=Prado::createComponent($this->_statePersisterClass);
- if(!($this->_statePersister instanceof IPageStatePersister))
- throw new TInvalidDataTypeException('page_statepersister_invalid');
- $this->_statePersister->setPage($this);
- }
- return $this->_statePersister;
- }
-
- /**
- * @return boolean whether page state should be HMAC validated. Defaults to true.
- */
- public function getEnableStateValidation()
- {
- return $this->_enableStateValidation;
- }
-
- /**
- * @param boolean whether page state should be HMAC validated.
- */
- public function setEnableStateValidation($value)
- {
- $this->_enableStateValidation=TPropertyValue::ensureBoolean($value);
- }
-
- /**
- * @return boolean whether page state should be encrypted. Defaults to false.
- */
- public function getEnableStateEncryption()
- {
- return $this->_enableStateEncryption;
- }
-
- /**
- * @param boolean whether page state should be encrypted.
- */
- public function setEnableStateEncryption($value)
- {
- $this->_enableStateEncryption=TPropertyValue::ensureBoolean($value);
- }
-
- /**
- * @return boolean whether page state should be compressed. Defaults to true.
- * @since 3.1.6
- */
- public function getEnableStateCompression()
- {
- return $this->_enableStateCompression;
- }
-
- /**
- * @param boolean whether page state should be compressed.
- * @since 3.1.6
- */
- public function setEnableStateCompression($value)
- {
- $this->_enableStateCompression=TPropertyValue::ensureBoolean($value);
- }
-
- /**
- * @return string the requested page path for this page
- */
- public function getPagePath()
- {
- return $this->_pagePath;
- }
-
- /**
- * @param string the requested page path for this page
- */
- public function setPagePath($value)
- {
- $this->_pagePath=$value;
- }
-
- /**
- * Registers an action associated with the content being cached.
- * The registered action will be replayed if the content stored
- * in the cache is served to end-users.
- * @param string context of the action method. This is a property-path
- * referring to the context object (e.g. Page, Page.ClientScript).
- * @param string method name of the context object
- * @param array list of parameters to be passed to the action method
- */
- public function registerCachingAction($context,$funcName,$funcParams)
- {
- if($this->_cachingStack)
- {
- foreach($this->_cachingStack as $cache)
- $cache->registerAction($context,$funcName,$funcParams);
- }
- }
-
- /**
- * @return TStack stack of {@link TOutputCache} objects
- */
- public function getCachingStack()
- {
- if(!$this->_cachingStack)
- $this->_cachingStack=new TStack;
- return $this->_cachingStack;
- }
-
- /**
- * Flushes output
- */
- public function flushWriter()
- {
- if ($this->_writer)
- $this->Response->write($this->_writer->flush());
- }
-}
-
-/**
- * IPageStatePersister interface.
- *
- * IPageStatePersister interface is required for all page state persister
- * classes.
- *
- * @author Qiang Xue <qiang.xue@gmail.com>
- * @version $Id$
- * @package System.Web.UI
- * @since 3.1
- */
-interface IPageStatePersister
-{
- /**
- * @param TPage the page that this persister works for
- */
- public function getPage();
- /**
- * @param TPage the page that this persister works for
- */
- public function setPage(TPage $page);
- /**
- * Saves state to persistent storage.
- * @param mixed state to be stored
- */
- public function save($state);
- /**
- * Loads page state from persistent storage
- * @return mixed the restored state
- */
- public function load();
-}
-
-
-/**
- * TPageStateFormatter class.
- *
- * TPageStateFormatter is a utility class to transform the page state
- * into and from a string that can be properly saved in persistent storage.
- *
- * Depending on the {@link TPage::getEnableStateValidation() EnableStateValidation}
- * and {@link TPage::getEnableStateEncryption() EnableStateEncryption},
- * TPageStateFormatter may do HMAC validation and encryption to prevent
- * the state data from being tampered or viewed.
- * The private keys and hashing/encryption methods are determined by
- * {@link TApplication::getSecurityManager() SecurityManager}.
- *
- * @author Qiang Xue <qiang.xue@gmail.com>
- * @version $Revision: $ $Date: $
- * @package System.Web.UI
- * @since 3.1
- */
-class TPageStateFormatter
-{
- /**
- * @param TPage
- * @param mixed state data
- * @return string serialized data
- */
- public static function serialize($page,$data)
- {
- $sm=$page->getApplication()->getSecurityManager();
- if($page->getEnableStateValidation())
- $str=$sm->hashData(Prado::serialize($data));
- else
- $str=Prado::serialize($data);
- if($page->getEnableStateCompression() && extension_loaded('zlib'))
- $str=gzcompress($str);
- if($page->getEnableStateEncryption())
- $str=$sm->encrypt($str);
- return base64_encode($str);
- }
-
- /**
- * @param TPage
- * @param string serialized data
- * @return mixed unserialized state data, null if data is corrupted
- */
- public static function unserialize($page,$data)
- {
- $str=base64_decode($data);
- if($str==='')
- return null;
- if($str!==false)
- {
- $sm=$page->getApplication()->getSecurityManager();
- if($page->getEnableStateEncryption())
- $str=$sm->decrypt($str);
- if($page->getEnableStateCompression() && extension_loaded('zlib'))
- $str=@gzuncompress($str);
- if($page->getEnableStateValidation())
- {
- if(($str=$sm->validateData($str))!==false)
- return Prado::unserialize($str);
- }
- else
- return Prado::unserialize($str);
- }
- return null;
- }
-}
+<?php
+/**
+ * TPage class file
+ *
+ * @author Qiang Xue <qiang.xue@gmail.com>
+ * @link http://www.pradosoft.com/
+ * @copyright Copyright &copy; 2005-2012 PradoSoft
+ * @license http://www.pradosoft.com/license/
+ * @version $Id$
+ * @package System.Web.UI
+ */
+
+Prado::using('System.Web.UI.WebControls.*');
+Prado::using('System.Web.UI.TControl');
+Prado::using('System.Web.UI.WebControls.TWebControl');
+Prado::using('System.Web.UI.TCompositeControl');
+Prado::using('System.Web.UI.TTemplateControl');
+Prado::using('System.Web.UI.TForm');
+Prado::using('System.Web.UI.TClientScriptManager');
+
+/**
+ * TPage class
+ *
+ * @author Qiang Xue <qiang.xue@gmail.com>
+ * @version $Id$
+ * @package System.Web.UI
+ * @since 3.0
+ */
+class TPage extends TTemplateControl
+{
+ /**
+ * system post fields
+ */
+ const FIELD_POSTBACK_TARGET='PRADO_POSTBACK_TARGET';
+ const FIELD_POSTBACK_PARAMETER='PRADO_POSTBACK_PARAMETER';
+ const FIELD_LASTFOCUS='PRADO_LASTFOCUS';
+ const FIELD_PAGESTATE='PRADO_PAGESTATE';
+ const FIELD_CALLBACK_TARGET='PRADO_CALLBACK_TARGET';
+ const FIELD_CALLBACK_PARAMETER='PRADO_CALLBACK_PARAMETER';
+
+ /**
+ * @var array system post fields
+ */
+ private static $_systemPostFields=array(
+ 'PRADO_POSTBACK_TARGET'=>true,
+ 'PRADO_POSTBACK_PARAMETER'=>true,
+ 'PRADO_LASTFOCUS'=>true,
+ 'PRADO_PAGESTATE'=>true,
+ 'PRADO_CALLBACK_TARGET'=>true,
+ 'PRADO_CALLBACK_PARAMETER'=>true
+ );
+ /**
+ * @var TForm form instance
+ */
+ private $_form;
+ /**
+ * @var THead head instance
+ */
+ private $_head;
+ /**
+ * @var array list of registered validators
+ */
+ private $_validators=array();
+ /**
+ * @var boolean if validation has been performed
+ */
+ private $_validated=false;
+ /**
+ * @var TTheme page theme
+ */
+ private $_theme;
+ /**
+ * @var string page title set when Head is not in page yet
+ */
+ private $_title;
+ /**
+ * @var TTheme page stylesheet theme
+ */
+ private $_styleSheet;
+ /**
+ * @var TClientScriptManager client script manager
+ */
+ private $_clientScript;
+ /**
+ * @var TMap data post back by user
+ */
+ protected $_postData;
+ /**
+ * @var TMap postback data that is not handled during first invocation of LoadPostData.
+ */
+ protected $_restPostData;
+ /**
+ * @var array list of controls whose data have been changed due to the postback
+ */
+ protected $_controlsPostDataChanged=array();
+ /**
+ * @var array list of controls that need to load post data in the current request
+ */
+ protected $_controlsRequiringPostData=array();
+ /**
+ * @var array list of controls that need to load post data in the next postback
+ */
+ protected $_controlsRegisteredForPostData=array();
+ /**
+ * @var TControl control that needs to raise postback event
+ */
+ private $_postBackEventTarget;
+ /**
+ * @var string postback event parameter
+ */
+ private $_postBackEventParameter;
+ /**
+ * @var boolean whether the form has been rendered
+ */
+ protected $_formRendered=false;
+ /**
+ * @var boolean whether the current rendering is within a form
+ */
+ protected $_inFormRender=false;
+ /**
+ * @var TControl|string the control or the ID of the element on the page to be focused when the page is sent back to user
+ */
+ private $_focus;
+ /**
+ * @var string page path to this page
+ */
+ private $_pagePath='';
+ /**
+ * @var boolean whether page state should be HMAC validated
+ */
+ private $_enableStateValidation=true;
+ /**
+ * @var boolean whether page state should be encrypted
+ */
+ private $_enableStateEncryption=false;
+ /**
+ * @var boolean whether page state should be compressed
+ * @since 3.1.6
+ */
+ private $_enableStateCompression=true;
+ /**
+ * @var string page state persister class name
+ */
+ private $_statePersisterClass='System.Web.UI.TPageStatePersister';
+ /**
+ * @var mixed page state persister
+ */
+ private $_statePersister;
+ /**
+ * @var TStack stack used to store currently active caching controls
+ */
+ private $_cachingStack;
+ /**
+ * @var string state string to be stored on the client side
+ */
+ private $_clientState='';
+ /**
+ * @var array post data loader IDs.
+ */
+ protected $_postDataLoaders=array();
+ /**
+ * @var boolean true if loading post data.
+ */
+ protected $_isLoadingPostData=false;
+ /**
+ * @var boolean whether client supports javascript
+ */
+ private $_enableJavaScript=true;
+ /**
+ * @var THtmlWriter current html render writer
+ */
+ private $_writer;
+
+ /**
+ * Constructor.
+ * Sets the page object to itself.
+ * Derived classes must call parent implementation.
+ */
+ public function __construct()
+ {
+ $this->setPage($this);
+ }
+
+ /**
+ * Runs through the page lifecycles.
+ * @param THtmlTextWriter the HTML writer
+ */
+ public function run($writer)
+ {
+ Prado::trace("Running page life cycles",'System.Web.UI.TPage');
+ $this->_writer = $writer;
+
+ $this->determinePostBackMode();
+
+ if($this->getIsPostBack())
+ {
+ if($this->getIsCallback())
+ $this->processCallbackRequest($writer);
+ else
+ $this->processPostBackRequest($writer);
+ }
+ else
+ $this->processNormalRequest($writer);
+
+ $this->_writer = null;
+ }
+
+ protected function processNormalRequest($writer)
+ {
+ Prado::trace("Page onPreInit()",'System.Web.UI.TPage');
+ $this->onPreInit(null);
+
+ Prado::trace("Page initRecursive()",'System.Web.UI.TPage');
+ $this->initRecursive();
+
+ Prado::trace("Page onInitComplete()",'System.Web.UI.TPage');
+ $this->onInitComplete(null);
+
+ Prado::trace("Page onPreLoad()",'System.Web.UI.TPage');
+ $this->onPreLoad(null);
+ Prado::trace("Page loadRecursive()",'System.Web.UI.TPage');
+ $this->loadRecursive();
+ Prado::trace("Page onLoadComplete()",'System.Web.UI.TPage');
+ $this->onLoadComplete(null);
+
+ Prado::trace("Page preRenderRecursive()",'System.Web.UI.TPage');
+ $this->preRenderRecursive();
+ Prado::trace("Page onPreRenderComplete()",'System.Web.UI.TPage');
+ $this->onPreRenderComplete(null);
+
+ Prado::trace("Page savePageState()",'System.Web.UI.TPage');
+ $this->savePageState();
+ Prado::trace("Page onSaveStateComplete()",'System.Web.UI.TPage');
+ $this->onSaveStateComplete(null);
+
+ Prado::trace("Page renderControl()",'System.Web.UI.TPage');
+ $this->renderControl($writer);
+ Prado::trace("Page unloadRecursive()",'System.Web.UI.TPage');
+ $this->unloadRecursive();
+ }
+
+ protected function processPostBackRequest($writer)
+ {
+ Prado::trace("Page onPreInit()",'System.Web.UI.TPage');
+ $this->onPreInit(null);
+
+ Prado::trace("Page initRecursive()",'System.Web.UI.TPage');
+ $this->initRecursive();
+
+ Prado::trace("Page onInitComplete()",'System.Web.UI.TPage');
+ $this->onInitComplete(null);
+
+ $this->_restPostData=new TMap;
+ Prado::trace("Page loadPageState()",'System.Web.UI.TPage');
+ $this->loadPageState();
+ Prado::trace("Page processPostData()",'System.Web.UI.TPage');
+ $this->processPostData($this->_postData,true);
+ Prado::trace("Page onPreLoad()",'System.Web.UI.TPage');
+ $this->onPreLoad(null);
+ Prado::trace("Page loadRecursive()",'System.Web.UI.TPage');
+ $this->loadRecursive();
+ Prado::trace("Page processPostData()",'System.Web.UI.TPage');
+ $this->processPostData($this->_restPostData,false);
+ Prado::trace("Page raiseChangedEvents()",'System.Web.UI.TPage');
+ $this->raiseChangedEvents();
+ Prado::trace("Page raisePostBackEvent()",'System.Web.UI.TPage');
+ $this->raisePostBackEvent();
+ Prado::trace("Page onLoadComplete()",'System.Web.UI.TPage');
+ $this->onLoadComplete(null);
+
+ Prado::trace("Page preRenderRecursive()",'System.Web.UI.TPage');
+ $this->preRenderRecursive();
+ Prado::trace("Page onPreRenderComplete()",'System.Web.UI.TPage');
+ $this->onPreRenderComplete(null);
+
+ Prado::trace("Page savePageState()",'System.Web.UI.TPage');
+ $this->savePageState();
+ Prado::trace("Page onSaveStateComplete()",'System.Web.UI.TPage');
+ $this->onSaveStateComplete(null);
+
+ Prado::trace("Page renderControl()",'System.Web.UI.TPage');
+ $this->renderControl($writer);
+ Prado::trace("Page unloadRecursive()",'System.Web.UI.TPage');
+ $this->unloadRecursive();
+ }
+
+ protected static function decodeUTF8($data, $enc)
+ {
+ if(is_array($data))
+ {
+ foreach($data as $k=>$v)
+ $data[$k]=self::decodeUTF8($v, $enc);
+ return $data;
+ } elseif(is_string($data)) {
+ return iconv('UTF-8',$enc.'//IGNORE',$data);
+ } else {
+ return $data;
+ }
+ }
+
+ /**
+ * Sets Adapter to TActivePageAdapter and calls apter to process the
+ * callback request.
+ */
+ protected function processCallbackRequest($writer)
+ {
+ Prado::using('System.Web.UI.ActiveControls.TActivePageAdapter');
+
+ $this->setAdapter(new TActivePageAdapter($this));
+
+ // Decode Callback postData from UTF-8 to current Charset
+ if (($g=$this->getApplication()->getGlobalization(false))!==null &&
+ strtoupper($enc=$g->getCharset())!='UTF-8')
+ foreach ($this->_postData as $k=>$v)
+ $this->_postData[$k]=self::decodeUTF8($v, $enc);
+
+ Prado::trace("Page onPreInit()",'System.Web.UI.TPage');
+ $this->onPreInit(null);
+
+ Prado::trace("Page initRecursive()",'System.Web.UI.TPage');
+ $this->initRecursive();
+
+ Prado::trace("Page onInitComplete()",'System.Web.UI.TPage');
+ $this->onInitComplete(null);
+
+ $this->_restPostData=new TMap;
+ Prado::trace("Page loadPageState()",'System.Web.UI.TPage');
+ $this->loadPageState();
+ Prado::trace("Page processPostData()",'System.Web.UI.TPage');
+ $this->processPostData($this->_postData,true);
+ Prado::trace("Page onPreLoad()",'System.Web.UI.TPage');
+ $this->onPreLoad(null);
+ Prado::trace("Page loadRecursive()",'System.Web.UI.TPage');
+ $this->loadRecursive();
+
+ Prado::trace("Page processPostData()",'System.Web.UI.TPage');
+ $this->processPostData($this->_restPostData,false);
+
+ Prado::trace("Page raiseChangedEvents()",'System.Web.UI.TPage');
+ $this->raiseChangedEvents();
+
+
+ $this->getAdapter()->processCallbackEvent($writer);
+
+/*
+ Prado::trace("Page raisePostBackEvent()",'System.Web.UI.TPage');
+ $this->raisePostBackEvent();
+*/
+ Prado::trace("Page onLoadComplete()",'System.Web.UI.TPage');
+ $this->onLoadComplete(null);
+
+ Prado::trace("Page preRenderRecursive()",'System.Web.UI.TPage');
+ $this->preRenderRecursive();
+ Prado::trace("Page onPreRenderComplete()",'System.Web.UI.TPage');
+ $this->onPreRenderComplete(null);
+
+ Prado::trace("Page savePageState()",'System.Web.UI.TPage');
+ $this->savePageState();
+ Prado::trace("Page onSaveStateComplete()",'System.Web.UI.TPage');
+ $this->onSaveStateComplete(null);
+
+/*
+ Prado::trace("Page renderControl()",'System.Web.UI.TPage');
+ $this->renderControl($writer);
+*/
+ $this->getAdapter()->renderCallbackResponse($writer);
+
+ Prado::trace("Page unloadRecursive()",'System.Web.UI.TPage');
+ $this->unloadRecursive();
+ }
+
+ /**
+ * Gets the callback client script handler that allows javascript functions
+ * to be executed during the callback response.
+ * @return TCallbackClientScript interface to client-side javascript code.
+ */
+ public function getCallbackClient()
+ {
+ if($this->getAdapter() !== null)
+ return $this->getAdapter()->getCallbackClientHandler();
+ else
+ return new TCallbackClientScript();
+ }
+
+ /**
+ * Set a new callback client handler.
+ * @param TCallbackClientScript new callback client script handler.
+ */
+ public function setCallbackClient($client)
+ {
+ $this->getAdapter()->setCallbackClientHandler($client);
+ }
+
+ /**
+ * @return TControl the control responsible for the current callback event,
+ * null if nonexistent
+ */
+ public function getCallbackEventTarget()
+ {
+ return $this->getAdapter()->getCallbackEventTarget();
+ }
+
+ /**
+ * Registers a control to raise callback event in the current request.
+ * @param TControl control registered to raise callback event.
+ */
+ public function setCallbackEventTarget(TControl $control)
+ {
+ $this->getAdapter()->setCallbackEventTarget($control);
+ }
+
+ /**
+ * Callback parameter is decoded assuming JSON encoding.
+ * @return string callback event parameter
+ */
+ public function getCallbackEventParameter()
+ {
+ return $this->getAdapter()->getCallbackEventParameter();
+ }
+
+ /**
+ * @param mixed callback event parameter
+ */
+ public function setCallbackEventParameter($value)
+ {
+ $this->getAdapter()->setCallbackEventParameter($value);
+ }
+
+ /**
+ * Register post data loaders for Callback to collect post data.
+ * This method should only be called by framework developers.
+ * @param TControl control that requires post data.
+ * @see TControl::preRenderRecursive();
+ */
+ public function registerPostDataLoader($control)
+ {
+ $id=is_string($control)?$control:$control->getUniqueID();
+ $this->_postDataLoaders[$id] = true;
+ }
+
+ /**
+ * Get a list of IDs of controls that are enabled and require post data.
+ * @return array list of IDs implementing IPostBackDataHandler
+ */
+ public function getPostDataLoaders()
+ {
+ return array_keys($this->_postDataLoaders);
+ }
+
+ /**
+ * @return TForm the form on the page
+ */
+ public function getForm()
+ {
+ return $this->_form;
+ }
+
+ /**
+ * Registers a TForm instance to the page.
+ * Note, a page can contain at most one TForm instance.
+ * @param TForm the form on the page
+ * @throws TInvalidOperationException if this method is invoked twice or more.
+ */
+ public function setForm(TForm $form)
+ {
+ if($this->_form===null)
+ $this->_form=$form;
+ else
+ throw new TInvalidOperationException('page_form_duplicated');
+ }
+
+ /**
+ * Returns a list of registered validators.
+ * If validation group is specified, only the validators in that group will be returned.
+ * @param string validation group
+ * @return TList registered validators in the requested group. If the group is null, all validators will be returned.
+ */
+ public function getValidators($validationGroup=null)
+ {
+ if(!$this->_validators)
+ $this->_validators=new TList;
+ if(empty($validationGroup) === true)
+ return $this->_validators;
+ else
+ {
+ $list=new TList;
+ foreach($this->_validators as $validator)
+ if($validator->getValidationGroup()===$validationGroup)
+ $list->add($validator);
+ return $list;
+ }
+ }
+
+ /**
+ * Performs input validation.
+ * This method will invoke the registered validators to perform the actual validation.
+ * If validation group is specified, only the validators in that group will be invoked.
+ * @param string validation group. If null, all validators will perform validation.
+ */
+ public function validate($validationGroup=null)
+ {
+ Prado::trace("Page validate()",'System.Web.UI.TPage');
+ $this->_validated=true;
+ if($this->_validators && $this->_validators->getCount())
+ {
+ if($validationGroup===null)
+ {
+ foreach($this->_validators as $validator)
+ $validator->validate();
+ }
+ else
+ {
+ foreach($this->_validators as $validator)
+ {
+ if($validator->getValidationGroup()===$validationGroup)
+ $validator->validate();
+ }
+ }
+ }
+ }
+
+ /**
+ * Returns whether user input is valid or not.
+ * This method must be invoked after {@link validate} is called.
+ * @return boolean whether the user input is valid or not.
+ * @throws TInvalidOperationException if {@link validate} is not invoked yet.
+ */
+ public function getIsValid()
+ {
+ if($this->_validated)
+ {
+ if($this->_validators && $this->_validators->getCount())
+ {
+ foreach($this->_validators as $validator)
+ if(!$validator->getIsValid())
+ return false;
+ }
+ return true;
+ }
+ else
+ throw new TInvalidOperationException('page_isvalid_unknown');
+ }
+
+ /**
+ * @return TTheme the theme used for the page. Defaults to null.
+ */
+ public function getTheme()
+ {
+ if(is_string($this->_theme))
+ $this->_theme=$this->getService()->getThemeManager()->getTheme($this->_theme);
+ return $this->_theme;
+ }
+
+ /**
+ * Sets the theme to be used for the page.
+ * @param string|TTheme the theme name or the theme object to be used for the page.
+ */
+ public function setTheme($value)
+ {
+ $this->_theme=empty($value)?null:$value;
+ }
+
+
+ /**
+ * @return TTheme the stylesheet theme used for the page. Defaults to null.
+ */
+ public function getStyleSheetTheme()
+ {
+ if(is_string($this->_styleSheet))
+ $this->_styleSheet=$this->getService()->getThemeManager()->getTheme($this->_styleSheet);
+ return $this->_styleSheet;
+ }
+
+ /**
+ * Sets the stylesheet theme to be used for the page.
+ * @param string|TTheme the stylesheet theme name or the stylesheet theme object to be used for the page.
+ */
+ public function setStyleSheetTheme($value)
+ {
+ $this->_styleSheet=empty($value)?null:$value;
+ }
+
+ /**
+ * Applies a skin in the current theme to a control.
+ * This method should only be used by framework developers.
+ * @param TControl a control to be applied skin with
+ */
+ public function applyControlSkin($control)
+ {
+ if(($theme=$this->getTheme())!==null)
+ $theme->applySkin($control);
+ }
+
+ /**
+ * Applies a stylesheet skin in the current theme to a control.
+ * This method should only be used by framework developers.
+ * @param TControl a control to be applied stylesheet skin with
+ */
+ public function applyControlStyleSheet($control)
+ {
+ if(($theme=$this->getStyleSheetTheme())!==null)
+ $theme->applySkin($control);
+ }
+
+ /**
+ * @return TClientScriptManager client script manager
+ */
+ public function getClientScript()
+ {
+ if(!$this->_clientScript) {
+ $className = $classPath = $this->getService()->getClientScriptManagerClass();
+ Prado::using($className);
+ if(($pos=strrpos($className,'.'))!==false)
+ $className=substr($className,$pos+1);
+
+ if(!class_exists($className,false) || ($className!=='TClientScriptManager' && !is_subclass_of($className,'TClientScriptManager')))
+ throw new THttpException(404,'page_csmanagerclass_invalid',$classPath);
+
+ $this->_clientScript=new $className($this);
+ }
+ return $this->_clientScript;
+ }
+
+ /**
+ * Raises OnPreInit event.
+ * This method is invoked right before {@link onInit OnInit} stage.
+ * You may override this method to provide additional initialization that
+ * should be done before {@link onInit OnInit} (e.g. setting {@link setTheme Theme} or
+ * {@link setStyleSheetTheme StyleSheetTheme}).
+ * Remember to call the parent implementation to ensure OnPreInit event is raised.
+ * @param mixed event parameter
+ */
+ public function onPreInit($param)
+ {
+ $this->raiseEvent('OnPreInit',$this,$param);
+ }
+
+ /**
+ * Raises OnInitComplete event.
+ * This method is invoked right after {@link onInit OnInit} stage and before {@link onLoad OnLoad} stage.
+ * You may override this method to provide additional initialization that
+ * should be done after {@link onInit OnInit}.
+ * Remember to call the parent implementation to ensure OnInitComplete event is raised.
+ * @param mixed event parameter
+ */
+ public function onInitComplete($param)
+ {
+ $this->raiseEvent('OnInitComplete',$this,$param);
+ }
+
+ /**
+ * Raises OnPreLoad event.
+ * This method is invoked right before {@link onLoad OnLoad} stage.
+ * You may override this method to provide additional page loading logic that
+ * should be done before {@link onLoad OnLoad}.
+ * Remember to call the parent implementation to ensure OnPreLoad event is raised.
+ * @param mixed event parameter
+ */
+ public function onPreLoad($param)
+ {
+ $this->raiseEvent('OnPreLoad',$this,$param);
+ }
+
+ /**
+ * Raises OnLoadComplete event.
+ * This method is invoked right after {@link onLoad OnLoad} stage.
+ * You may override this method to provide additional page loading logic that
+ * should be done after {@link onLoad OnLoad}.
+ * Remember to call the parent implementation to ensure OnLoadComplete event is raised.
+ * @param mixed event parameter
+ */
+ public function onLoadComplete($param)
+ {
+ $this->raiseEvent('OnLoadComplete',$this,$param);
+ }
+
+ /**
+ * Raises OnPreRenderComplete event.
+ * This method is invoked right after {@link onPreRender OnPreRender} stage.
+ * You may override this method to provide additional preparation for page rendering
+ * that should be done after {@link onPreRender OnPreRender}.
+ * Remember to call the parent implementation to ensure OnPreRenderComplete event is raised.
+ * @param mixed event parameter
+ */
+ public function onPreRenderComplete($param)
+ {
+ $this->raiseEvent('OnPreRenderComplete',$this,$param);
+ $cs=$this->getClientScript();
+ $theme=$this->getTheme();
+ if($theme instanceof ITheme)
+ {
+ foreach($theme->getStyleSheetFiles() as $url)
+ $cs->registerStyleSheetFile($url,$url,$this->getCssMediaType($url));
+ foreach($theme->getJavaScriptFiles() as $url)
+ $cs->registerHeadScriptFile($url,$url);
+ }
+ $styleSheet=$this->getStyleSheetTheme();
+ if($styleSheet instanceof ITheme)
+ {
+ foreach($styleSheet->getStyleSheetFiles() as $url)
+ $cs->registerStyleSheetFile($url,$url,$this->getCssMediaType($url));
+ foreach($styleSheet->getJavaScriptFiles() as $url)
+ $cs->registerHeadScriptFile($url,$url);
+ }
+
+ if($cs->getRequiresHead() && $this->getHead()===null)
+ throw new TConfigurationException('page_head_required');
+ }
+
+ /**
+ * Determines the media type of the CSS file.
+ * The media type is determined according to the following file name pattern:
+ * xxx.media-type.extension
+ * For example, 'mystyle.print.css' means its media type is 'print'.
+ * @param string CSS URL
+ * @return string media type of the CSS file
+ */
+ private function getCssMediaType($url)
+ {
+ $segs=explode('.',basename($url));
+ if(isset($segs[2]))
+ return $segs[count($segs)-2];
+ else
+ return '';
+ }
+
+ /**
+ * Raises OnSaveStateComplete event.
+ * This method is invoked right after {@link onSaveState OnSaveState} stage.
+ * You may override this method to provide additional logic after page state is saved.
+ * Remember to call the parent implementation to ensure OnSaveStateComplete event is raised.
+ * @param mixed event parameter
+ */
+ public function onSaveStateComplete($param)
+ {
+ $this->raiseEvent('OnSaveStateComplete',$this,$param);
+ }
+
+ /**
+ * Determines whether the current page request is a postback.
+ * Call {@link getIsPostBack} to get the result.
+ */
+ private function determinePostBackMode()
+ {
+ $postData=$this->getRequest();
+ if($postData->contains(self::FIELD_PAGESTATE) || $postData->contains(self::FIELD_POSTBACK_TARGET))
+ $this->_postData=$postData;
+ }
+
+ /**
+ * @return boolean whether the current page request is a postback
+ */
+ public function getIsPostBack()
+ {
+ return $this->_postData!==null;
+ }
+
+ /**
+ * @return boolean whether this is a callback request
+ */
+ public function getIsCallback()
+ {
+ return $this->getIsPostBack() && $this->getRequest()->contains(self::FIELD_CALLBACK_TARGET);
+ }
+
+ /**
+ * This method is invoked when control state is to be saved.
+ * You can override this method to do last step state saving.
+ * Parent implementation must be invoked.
+ */
+ public function saveState()
+ {
+ parent::saveState();
+ $this->setViewState('ControlsRequiringPostBack',$this->_controlsRegisteredForPostData,array());
+ }
+
+ /**
+ * This method is invoked right after the control has loaded its state.
+ * You can override this method to initialize data from the control state.
+ * Parent implementation must be invoked.
+ */
+ public function loadState()
+ {
+ parent::loadState();
+ $this->_controlsRequiringPostData=$this->getViewState('ControlsRequiringPostBack',array());
+ }
+
+ /**
+ * Loads page state from persistent storage.
+ */
+ protected function loadPageState()
+ {
+ Prado::trace("Loading state",'System.Web.UI.TPage');
+ $state=$this->getStatePersister()->load();
+ $this->loadStateRecursive($state,$this->getEnableViewState());
+ }
+
+ /**
+ * Saves page state from persistent storage.
+ */
+ protected function savePageState()
+ {
+ Prado::trace("Saving state",'System.Web.UI.TPage');
+ $state=&$this->saveStateRecursive($this->getEnableViewState());
+ $this->getStatePersister()->save($state);
+ }
+
+ /**
+ * @param string the field name
+ * @return boolean whether the specified field is a system field in postback data
+ */
+ protected function isSystemPostField($field)
+ {
+ return isset(self::$_systemPostFields[$field]);
+ }
+
+ /**
+ * Registers a control for loading post data in the next postback.
+ * This method needs to be invoked if the control to load post data
+ * may not have a post variable in some cases. For example, a checkbox,
+ * if not checked, will not have a post value.
+ * @param TControl control registered for loading post data
+ */
+ public function registerRequiresPostData($control)
+ {
+ $id=is_string($control)?$control:$control->getUniqueID();
+ $this->_controlsRegisteredForPostData[$id]=true;
+ $this->registerPostDataLoader($id);
+ $params=func_get_args();
+ foreach($this->getCachingStack() as $item)
+ $item->registerAction('Page','registerRequiresPostData',array($id));
+ }
+
+ /**
+ * @return TControl the control responsible for the current postback event, null if nonexistent
+ */
+ public function getPostBackEventTarget()
+ {
+ if($this->_postBackEventTarget===null && $this->_postData!==null)
+ {
+ $eventTarget=$this->_postData->itemAt(self::FIELD_POSTBACK_TARGET);
+ if(!empty($eventTarget))
+ $this->_postBackEventTarget=$this->findControl($eventTarget);
+ }
+ return $this->_postBackEventTarget;
+ }
+
+ /**
+ * Registers a control to raise postback event in the current request.
+ * @param TControl control registered to raise postback event.
+ */
+ public function setPostBackEventTarget(TControl $control)
+ {
+ $this->_postBackEventTarget=$control;
+ }
+
+ /**
+ * @return string postback event parameter
+ */
+ public function getPostBackEventParameter()
+ {
+ if($this->_postBackEventParameter===null && $this->_postData!==null)
+ {
+ if(($this->_postBackEventParameter=$this->_postData->itemAt(self::FIELD_POSTBACK_PARAMETER))===null)
+ $this->_postBackEventParameter='';
+ }
+ return $this->_postBackEventParameter;
+ }
+
+ /**
+ * @param string postback event parameter
+ */
+ public function setPostBackEventParameter($value)
+ {
+ $this->_postBackEventParameter=$value;
+ }
+
+ /**
+ * Processes post data.
+ * @param TMap post data to be processed
+ * @param boolean whether this method is invoked before {@link onLoad OnLoad}.
+ */
+ protected function processPostData($postData,$beforeLoad)
+ {
+ $this->_isLoadingPostData=true;
+ if($beforeLoad)
+ $this->_restPostData=new TMap;
+ foreach($postData as $key=>$value)
+ {
+ if($this->isSystemPostField($key))
+ continue;
+ else if($control=$this->findControl($key))
+ {
+ if($control instanceof IPostBackDataHandler)
+ {
+ if($control->loadPostData($key,$postData))
+ $this->_controlsPostDataChanged[]=$control;
+ }
+ else if($control instanceof IPostBackEventHandler &&
+ empty($this->_postData[self::FIELD_POSTBACK_TARGET]))
+ {
+ $this->_postData->add(self::FIELD_POSTBACK_TARGET,$key); // not calling setPostBackEventTarget() because the control may be removed later
+ }
+ unset($this->_controlsRequiringPostData[$key]);
+ }
+ else if($beforeLoad)
+ $this->_restPostData->add($key,$value);
+ }
+
+ foreach($this->_controlsRequiringPostData as $key=>$value)
+ {
+ if($control=$this->findControl($key))
+ {
+ if($control instanceof IPostBackDataHandler)
+ {
+ if($control->loadPostData($key,$this->_postData))
+ $this->_controlsPostDataChanged[]=$control;
+ }
+ else
+ throw new TInvalidDataValueException('page_postbackcontrol_invalid',$key);
+ unset($this->_controlsRequiringPostData[$key]);
+ }
+ }
+ $this->_isLoadingPostData=false;
+ }
+
+ /**
+ * @return boolean true if loading post data.
+ */
+ public function getIsLoadingPostData()
+ {
+ return $this->_isLoadingPostData;
+ }
+
+ /**
+ * Raises OnPostDataChangedEvent for controls whose data have been changed due to the postback.
+ */
+ protected function raiseChangedEvents()
+ {
+ foreach($this->_controlsPostDataChanged as $control)
+ $control->raisePostDataChangedEvent();
+ }
+
+ /**
+ * Raises PostBack event.
+ */
+ protected function raisePostBackEvent()
+ {
+ if(($postBackHandler=$this->getPostBackEventTarget())===null)
+ $this->validate();
+ else if($postBackHandler instanceof IPostBackEventHandler)
+ $postBackHandler->raisePostBackEvent($this->getPostBackEventParameter());
+ }
+
+ /**
+ * @return boolean Whether form rendering is in progress
+ */
+ public function getInFormRender()
+ {
+ return $this->_inFormRender;
+ }
+
+ /**
+ * Ensures the control is rendered within a form.
+ * @param TControl the control to be rendered
+ * @throws TConfigurationException if the control is outside of the form
+ */
+ public function ensureRenderInForm($control)
+ {
+ if(!$this->getIsCallback() && !$this->_inFormRender)
+ throw new TConfigurationException('page_control_outofform',get_class($control), $control ? $control->getUniqueID() : null);
+ }
+
+ /**
+ * @internal This method is invoked by TForm at the beginning of its rendering
+ */
+ public function beginFormRender($writer)
+ {
+ if($this->_formRendered)
+ throw new TConfigurationException('page_form_duplicated');
+ $this->_formRendered=true;
+ $this->getClientScript()->registerHiddenField(self::FIELD_PAGESTATE,$this->getClientState());
+ $this->_inFormRender=true;
+ }
+
+ /**
+ * @internal This method is invoked by TForm at the end of its rendering
+ */
+ public function endFormRender($writer)
+ {
+ if($this->_focus)
+ {
+ if(($this->_focus instanceof TControl) && $this->_focus->getVisible(true))
+ $focus=$this->_focus->getClientID();
+ else
+ $focus=$this->_focus;
+ $this->getClientScript()->registerFocusControl($focus);
+ }
+ else if($this->_postData && ($lastFocus=$this->_postData->itemAt(self::FIELD_LASTFOCUS))!==null)
+ $this->getClientScript()->registerFocusControl($lastFocus);
+ $this->_inFormRender=false;
+ }
+
+ /**
+ * Sets input focus on a control after the page is rendered to users.
+ * @param TControl|string control to receive focus, or the ID of the element on the page to receive focus
+ */
+ public function setFocus($value)
+ {
+ $this->_focus=$value;
+ }
+
+ /**
+ * @return boolean whether client supports javascript. Defaults to true.
+ */
+ public function getClientSupportsJavaScript()
+ {
+ return $this->_enableJavaScript;
+ }
+
+ /**
+ * @param boolean whether client supports javascript. If false, javascript will not be generated for controls.
+ */
+ public function setClientSupportsJavaScript($value)
+ {
+ $this->_enableJavaScript=TPropertyValue::ensureBoolean($value);
+ }
+
+ /**
+ * @return THead page head, null if not available
+ */
+ public function getHead()
+ {
+ return $this->_head;
+ }
+
+ /**
+ * @param THead page head
+ * @throws TInvalidOperationException if a head already exists
+ */
+ public function setHead(THead $value)
+ {
+ if($this->_head)
+ throw new TInvalidOperationException('page_head_duplicated');
+ $this->_head=$value;
+ if($this->_title!==null)
+ {
+ $this->_head->setTitle($this->_title);
+ $this->_title=null;
+ }
+ }
+
+ /**
+ * @return string page title.
+ */
+ public function getTitle()
+ {
+ if($this->_head)
+ return $this->_head->getTitle();
+ else
+ return $this->_title===null ? '' : $this->_title;
+ }
+
+ /**
+ * Sets the page title.
+ * Note, a {@link THead} control needs to place on the page
+ * in order that this title be rendered.
+ * @param string page title. This will override the title set in {@link getHead Head}.
+ */
+ public function setTitle($value)
+ {
+ if($this->_head)
+ $this->_head->setTitle($value);
+ else
+ $this->_title=$value;
+ }
+
+ /**
+ * Returns the state to be stored on the client side.
+ * This method should only be used by framework and control developers.
+ * @return string the state to be stored on the client side
+ */
+ public function getClientState()
+ {
+ return $this->_clientState;
+ }
+
+ /**
+ * Sets the state to be stored on the client side.
+ * This method should only be used by framework and control developers.
+ * @param string the state to be stored on the client side
+ */
+ public function setClientState($state)
+ {
+ $this->_clientState=$state;
+ }
+
+ /**
+ * @return string the state postback from client side
+ */
+ public function getRequestClientState()
+ {
+ return $this->getRequest()->itemAt(self::FIELD_PAGESTATE);
+ }
+
+ /**
+ * @return string class name of the page state persister. Defaults to TPageStatePersister.
+ */
+ public function getStatePersisterClass()
+ {
+ return $this->_statePersisterClass;
+ }
+
+ /**
+ * @param string class name of the page state persister.
+ */
+ public function setStatePersisterClass($value)
+ {
+ $this->_statePersisterClass=$value;
+ }
+
+ /**
+ * @return IPageStatePersister page state persister
+ */
+ public function getStatePersister()
+ {
+ if($this->_statePersister===null)
+ {
+ $this->_statePersister=Prado::createComponent($this->_statePersisterClass);
+ if(!($this->_statePersister instanceof IPageStatePersister))
+ throw new TInvalidDataTypeException('page_statepersister_invalid');
+ $this->_statePersister->setPage($this);
+ }
+ return $this->_statePersister;
+ }
+
+ /**
+ * @return boolean whether page state should be HMAC validated. Defaults to true.
+ */
+ public function getEnableStateValidation()
+ {
+ return $this->_enableStateValidation;
+ }
+
+ /**
+ * @param boolean whether page state should be HMAC validated.
+ */
+ public function setEnableStateValidation($value)
+ {
+ $this->_enableStateValidation=TPropertyValue::ensureBoolean($value);
+ }
+
+ /**
+ * @return boolean whether page state should be encrypted. Defaults to false.
+ */
+ public function getEnableStateEncryption()
+ {
+ return $this->_enableStateEncryption;
+ }
+
+ /**
+ * @param boolean whether page state should be encrypted.
+ */
+ public function setEnableStateEncryption($value)
+ {
+ $this->_enableStateEncryption=TPropertyValue::ensureBoolean($value);
+ }
+
+ /**
+ * @return boolean whether page state should be compressed. Defaults to true.
+ * @since 3.1.6
+ */
+ public function getEnableStateCompression()
+ {
+ return $this->_enableStateCompression;
+ }
+
+ /**
+ * @param boolean whether page state should be compressed.
+ * @since 3.1.6
+ */
+ public function setEnableStateCompression($value)
+ {
+ $this->_enableStateCompression=TPropertyValue::ensureBoolean($value);
+ }
+
+ /**
+ * @return string the requested page path for this page
+ */
+ public function getPagePath()
+ {
+ return $this->_pagePath;
+ }
+
+ /**
+ * @param string the requested page path for this page
+ */
+ public function setPagePath($value)
+ {
+ $this->_pagePath=$value;
+ }
+
+ /**
+ * Registers an action associated with the content being cached.
+ * The registered action will be replayed if the content stored
+ * in the cache is served to end-users.
+ * @param string context of the action method. This is a property-path
+ * referring to the context object (e.g. Page, Page.ClientScript).
+ * @param string method name of the context object
+ * @param array list of parameters to be passed to the action method
+ */
+ public function registerCachingAction($context,$funcName,$funcParams)
+ {
+ if($this->_cachingStack)
+ {
+ foreach($this->_cachingStack as $cache)
+ $cache->registerAction($context,$funcName,$funcParams);
+ }
+ }
+
+ /**
+ * @return TStack stack of {@link TOutputCache} objects
+ */
+ public function getCachingStack()
+ {
+ if(!$this->_cachingStack)
+ $this->_cachingStack=new TStack;
+ return $this->_cachingStack;
+ }
+
+ /**
+ * Flushes output
+ */
+ public function flushWriter()
+ {
+ if ($this->_writer)
+ $this->Response->write($this->_writer->flush());
+ }
+}
+
+/**
+ * IPageStatePersister interface.
+ *
+ * IPageStatePersister interface is required for all page state persister
+ * classes.
+ *
+ * @author Qiang Xue <qiang.xue@gmail.com>
+ * @version $Id$
+ * @package System.Web.UI
+ * @since 3.1
+ */
+interface IPageStatePersister
+{
+ /**
+ * @param TPage the page that this persister works for
+ */
+ public function getPage();
+ /**
+ * @param TPage the page that this persister works for
+ */
+ public function setPage(TPage $page);
+ /**
+ * Saves state to persistent storage.
+ * @param mixed state to be stored
+ */
+ public function save($state);
+ /**
+ * Loads page state from persistent storage
+ * @return mixed the restored state
+ */
+ public function load();
+}
+
+
+/**
+ * TPageStateFormatter class.
+ *
+ * TPageStateFormatter is a utility class to transform the page state
+ * into and from a string that can be properly saved in persistent storage.
+ *
+ * Depending on the {@link TPage::getEnableStateValidation() EnableStateValidation}
+ * and {@link TPage::getEnableStateEncryption() EnableStateEncryption},
+ * TPageStateFormatter may do HMAC validation and encryption to prevent
+ * the state data from being tampered or viewed.
+ * The private keys and hashing/encryption methods are determined by
+ * {@link TApplication::getSecurityManager() SecurityManager}.
+ *
+ * @author Qiang Xue <qiang.xue@gmail.com>
+ * @version $Revision: $ $Date: $
+ * @package System.Web.UI
+ * @since 3.1
+ */
+class TPageStateFormatter
+{
+ /**
+ * @param TPage
+ * @param mixed state data
+ * @return string serialized data
+ */
+ public static function serialize($page,$data)
+ {
+ $sm=$page->getApplication()->getSecurityManager();
+ if($page->getEnableStateValidation())
+ $str=$sm->hashData(Prado::serialize($data));
+ else
+ $str=Prado::serialize($data);
+ if($page->getEnableStateCompression() && extension_loaded('zlib'))
+ $str=gzcompress($str);
+ if($page->getEnableStateEncryption())
+ $str=$sm->encrypt($str);
+ return base64_encode($str);
+ }
+
+ /**
+ * @param TPage
+ * @param string serialized data
+ * @return mixed unserialized state data, null if data is corrupted
+ */
+ public static function unserialize($page,$data)
+ {
+ $str=base64_decode($data);
+ if($str==='')
+ return null;
+ if($str!==false)
+ {
+ $sm=$page->getApplication()->getSecurityManager();
+ if($page->getEnableStateEncryption())
+ $str=$sm->decrypt($str);
+ if($page->getEnableStateCompression() && extension_loaded('zlib'))
+ $str=@gzuncompress($str);
+ if($page->getEnableStateValidation())
+ {
+ if(($str=$sm->validateData($str))!==false)
+ return Prado::unserialize($str);
+ }
+ else
+ return Prado::unserialize($str);
+ }
+ return null;
+ }
+}
diff --git a/framework/Web/UI/TPageStatePersister.php b/framework/Web/UI/TPageStatePersister.php
index 18590a77..183cde13 100644
--- a/framework/Web/UI/TPageStatePersister.php
+++ b/framework/Web/UI/TPageStatePersister.php
@@ -1,71 +1,71 @@
-<?php
-/**
- * TPageStatePersister class file
- *
- * @author Qiang Xue <qiang.xue@gmail.com>
- * @link http://www.pradosoft.com/
+<?php
+/**
+ * TPageStatePersister class file
+ *
+ * @author Qiang Xue <qiang.xue@gmail.com>
+ * @link http://www.pradosoft.com/
* @copyright Copyright &copy; 2005-2012 PradoSoft
- * @license http://www.pradosoft.com/license/
- * @version $Id$
- * @package System.Web.UI
- */
-
-/**
- * TPageStatePersister class
- *
- * TPageStatePersister implements a page state persistent method based on
- * form hidden fields.
- *
- * Since page state can be very big for complex pages, consider using
- * alternative persisters, such as {@link TSessionPageStatePersister},
- * which store page state on the server side and thus reduce the network
- * traffic for transmitting bulky page state.
- *
- * @author Qiang Xue <qiang.xue@gmail.com>
- * @version $Id$
- * @package System.Web.UI
- * @since 3.0
- */
-class TPageStatePersister extends TComponent implements IPageStatePersister
-{
- private $_page;
-
- /**
- * @return TPage the page that this persister works for
- */
- public function getPage()
- {
- return $this->_page;
- }
-
- /**
- * @param TPage the page that this persister works for
- */
- public function setPage(TPage $page)
- {
- $this->_page=$page;
- }
-
- /**
- * Saves state in hidden fields.
- * @param mixed state to be stored
- */
- public function save($state)
- {
- $this->_page->setClientState(TPageStateFormatter::serialize($this->_page,$state));
- }
-
- /**
- * Loads page state from hidden fields.
- * @return mixed the restored state
- * @throws THttpException if page state is corrupted
- */
- public function load()
- {
- if(($data=TPageStateFormatter::unserialize($this->_page,$this->_page->getRequestClientState()))!==null)
- return $data;
- else
- throw new THttpException(400,'pagestatepersister_pagestate_corrupted');
- }
-}
-
+ * @license http://www.pradosoft.com/license/
+ * @version $Id$
+ * @package System.Web.UI
+ */
+
+/**
+ * TPageStatePersister class
+ *
+ * TPageStatePersister implements a page state persistent method based on
+ * form hidden fields.
+ *
+ * Since page state can be very big for complex pages, consider using
+ * alternative persisters, such as {@link TSessionPageStatePersister},
+ * which store page state on the server side and thus reduce the network
+ * traffic for transmitting bulky page state.
+ *
+ * @author Qiang Xue <qiang.xue@gmail.com>
+ * @version $Id$
+ * @package System.Web.UI
+ * @since 3.0
+ */
+class TPageStatePersister extends TComponent implements IPageStatePersister
+{
+ private $_page;
+
+ /**
+ * @return TPage the page that this persister works for
+ */
+ public function getPage()
+ {
+ return $this->_page;
+ }
+
+ /**
+ * @param TPage the page that this persister works for
+ */
+ public function setPage(TPage $page)
+ {
+ $this->_page=$page;
+ }
+
+ /**
+ * Saves state in hidden fields.
+ * @param mixed state to be stored
+ */
+ public function save($state)
+ {
+ $this->_page->setClientState(TPageStateFormatter::serialize($this->_page,$state));
+ }
+
+ /**
+ * Loads page state from hidden fields.
+ * @return mixed the restored state
+ * @throws THttpException if page state is corrupted
+ */
+ public function load()
+ {
+ if(($data=TPageStateFormatter::unserialize($this->_page,$this->_page->getRequestClientState()))!==null)
+ return $data;
+ else
+ throw new THttpException(400,'pagestatepersister_pagestate_corrupted');
+ }
+}
+
diff --git a/framework/Web/UI/TSessionPageStatePersister.php b/framework/Web/UI/TSessionPageStatePersister.php
index 4c2537df..a6d26f7a 100644
--- a/framework/Web/UI/TSessionPageStatePersister.php
+++ b/framework/Web/UI/TSessionPageStatePersister.php
@@ -1,131 +1,131 @@
-<?php
-/**
- * TSessionPageStatePersister class file
- *
- * @author Qiang Xue <qiang.xue@gmail.com>
- * @link http://www.pradosoft.com/
+<?php
+/**
+ * TSessionPageStatePersister class file
+ *
+ * @author Qiang Xue <qiang.xue@gmail.com>
+ * @link http://www.pradosoft.com/
* @copyright Copyright &copy; 2005-2012 PradoSoft
- * @license http://www.pradosoft.com/license/
- * @version $Id$
- * @package System.Web.UI
- */
-
-/**
- * TSessionPageStatePersister class
- *
- * TSessionPageStatePersister implements a page state persistent method based on
- * sessions. Page state are stored in user sessions and therefore, this persister
- * requires session to be started and available.
- *
- * TSessionPageStatePersister keeps limited number of history states in session,
- * mainly to preserve the precious server storage. The number is specified
- * by {@link setHistorySize HistorySize}, which defaults to 10.
- *
- * There are a couple of ways to use TSessionPageStatePersister.
- * One can override the page's {@link TPage::getStatePersister()} method and
- * create a TSessionPageStatePersister instance there.
- * Or one can configure the pages to use TSessionPageStatePersister in page configurations
- * as follows,
- * <code>
- * <pages StatePersisterClass="System.Web.UI.TSessionPageStatePersister" />
- * </code>
- * The above configuration will affect the pages under the directory containing
- * this configuration and all its subdirectories.
- * To configure individual pages to use TSessionPageStatePersister, use
- * <code>
- * <pages>
- * <page id="PageID" StatePersisterClass="System.Web.UI.TSessionPageStatePersister" />
- * </pages>
- * </code>
- *
- * @author Qiang Xue <qiang.xue@gmail.com>
- * @version $Id$
- * @package System.Web.UI
- * @since 3.1
- */
-class TSessionPageStatePersister extends TComponent implements IPageStatePersister
-{
- const STATE_SESSION_KEY='PRADO_SESSION_PAGESTATE';
- const QUEUE_SESSION_KEY='PRADO_SESSION_STATEQUEUE';
-
- private $_page;
- private $_historySize=10;
-
- /**
- * @param TPage the page that this persister works for
- */
- public function getPage()
- {
- return $this->_page;
- }
-
- /**
- * @param TPage the page that this persister works for.
- */
- public function setPage(TPage $page)
- {
- $this->_page=$page;
- }
-
- /**
- * @return integer maximum number of page states that should be kept in session. Defaults to 10.
- */
- public function getHistorySize()
- {
- return $this->_historySize;
- }
-
- /**
- * @param integer maximum number of page states that should be kept in session
- * @throws TInvalidDataValueException if the number is smaller than 1.
- */
- public function setHistorySize($value)
- {
- if(($value=TPropertyValue::ensureInteger($value))>0)
- $this->_historySize=$value;
- else
- throw new TInvalidDataValueException('sessionpagestatepersister_historysize_invalid');
- }
- /**
- * Saves state in session.
- * @param mixed state to be stored
- */
- public function save($state)
- {
- $session=$this->_page->getSession();
- $session->open();
- $data=serialize($state);
- $timestamp=(string)microtime(true);
- $key=self::STATE_SESSION_KEY.$timestamp;
- $session->add($key,$data);
- if(($queue=$session->itemAt(self::QUEUE_SESSION_KEY))===null)
- $queue=array();
- $queue[]=$key;
- if(count($queue)>$this->getHistorySize())
- {
- $expiredKey=array_shift($queue);
- $session->remove($expiredKey);
- }
- $session->add(self::QUEUE_SESSION_KEY,$queue);
- $this->_page->setClientState(TPageStateFormatter::serialize($this->_page,$timestamp));
- }
-
- /**
- * Loads page state from session.
- * @return mixed the restored state
- * @throws THttpException if page state is corrupted
- */
- public function load()
- {
- if(($timestamp=TPageStateFormatter::unserialize($this->_page,$this->_page->getRequestClientState()))!==null)
- {
- $session=$this->_page->getSession();
- $session->open();
- $key=self::STATE_SESSION_KEY.$timestamp;
- if(($data=$session->itemAt($key))!==null)
- return unserialize($data);
- }
- throw new THttpException(400,'sessionpagestatepersister_pagestate_corrupted');
- }
-}
-
+ * @license http://www.pradosoft.com/license/
+ * @version $Id$
+ * @package System.Web.UI
+ */
+
+/**
+ * TSessionPageStatePersister class
+ *
+ * TSessionPageStatePersister implements a page state persistent method based on
+ * sessions. Page state are stored in user sessions and therefore, this persister
+ * requires session to be started and available.
+ *
+ * TSessionPageStatePersister keeps limited number of history states in session,
+ * mainly to preserve the precious server storage. The number is specified
+ * by {@link setHistorySize HistorySize}, which defaults to 10.
+ *
+ * There are a couple of ways to use TSessionPageStatePersister.
+ * One can override the page's {@link TPage::getStatePersister()} method and
+ * create a TSessionPageStatePersister instance there.
+ * Or one can configure the pages to use TSessionPageStatePersister in page configurations
+ * as follows,
+ * <code>
+ * <pages StatePersisterClass="System.Web.UI.TSessionPageStatePersister" />
+ * </code>
+ * The above configuration will affect the pages under the directory containing
+ * this configuration and all its subdirectories.
+ * To configure individual pages to use TSessionPageStatePersister, use
+ * <code>
+ * <pages>
+ * <page id="PageID" StatePersisterClass="System.Web.UI.TSessionPageStatePersister" />
+ * </pages>
+ * </code>
+ *
+ * @author Qiang Xue <qiang.xue@gmail.com>
+ * @version $Id$
+ * @package System.Web.UI
+ * @since 3.1
+ */
+class TSessionPageStatePersister extends TComponent implements IPageStatePersister
+{
+ const STATE_SESSION_KEY='PRADO_SESSION_PAGESTATE';
+ const QUEUE_SESSION_KEY='PRADO_SESSION_STATEQUEUE';
+
+ private $_page;
+ private $_historySize=10;
+
+ /**
+ * @param TPage the page that this persister works for
+ */
+ public function getPage()
+ {
+ return $this->_page;
+ }
+
+ /**
+ * @param TPage the page that this persister works for.
+ */
+ public function setPage(TPage $page)
+ {
+ $this->_page=$page;
+ }
+
+ /**
+ * @return integer maximum number of page states that should be kept in session. Defaults to 10.
+ */
+ public function getHistorySize()
+ {
+ return $this->_historySize;
+ }
+
+ /**
+ * @param integer maximum number of page states that should be kept in session
+ * @throws TInvalidDataValueException if the number is smaller than 1.
+ */
+ public function setHistorySize($value)
+ {
+ if(($value=TPropertyValue::ensureInteger($value))>0)
+ $this->_historySize=$value;
+ else
+ throw new TInvalidDataValueException('sessionpagestatepersister_historysize_invalid');
+ }
+ /**
+ * Saves state in session.
+ * @param mixed state to be stored
+ */
+ public function save($state)
+ {
+ $session=$this->_page->getSession();
+ $session->open();
+ $data=serialize($state);
+ $timestamp=(string)microtime(true);
+ $key=self::STATE_SESSION_KEY.$timestamp;
+ $session->add($key,$data);
+ if(($queue=$session->itemAt(self::QUEUE_SESSION_KEY))===null)
+ $queue=array();
+ $queue[]=$key;
+ if(count($queue)>$this->getHistorySize())
+ {
+ $expiredKey=array_shift($queue);
+ $session->remove($expiredKey);
+ }
+ $session->add(self::QUEUE_SESSION_KEY,$queue);
+ $this->_page->setClientState(TPageStateFormatter::serialize($this->_page,$timestamp));
+ }
+
+ /**
+ * Loads page state from session.
+ * @return mixed the restored state
+ * @throws THttpException if page state is corrupted
+ */
+ public function load()
+ {
+ if(($timestamp=TPageStateFormatter::unserialize($this->_page,$this->_page->getRequestClientState()))!==null)
+ {
+ $session=$this->_page->getSession();
+ $session->open();
+ $key=self::STATE_SESSION_KEY.$timestamp;
+ if(($data=$session->itemAt($key))!==null)
+ return unserialize($data);
+ }
+ throw new THttpException(400,'sessionpagestatepersister_pagestate_corrupted');
+ }
+}
+
diff --git a/framework/Web/UI/TTemplateControl.php b/framework/Web/UI/TTemplateControl.php
index 400c1059..9b26728d 100644
--- a/framework/Web/UI/TTemplateControl.php
+++ b/framework/Web/UI/TTemplateControl.php
@@ -1,243 +1,243 @@
-<?php
-/**
- * TTemplateControl class file.
- *
- * @author Qiang Xue <qiang.xue@gmail.com>
- * @link http://www.pradosoft.com/
+<?php
+/**
+ * TTemplateControl class file.
+ *
+ * @author Qiang Xue <qiang.xue@gmail.com>
+ * @link http://www.pradosoft.com/
* @copyright Copyright &copy; 2005-2012 PradoSoft
- * @license http://www.pradosoft.com/license/
- * @version $Id$
- * @package System.Web.UI
- */
-
-/**
- * Includes TCompositeControl class
- */
-Prado::using('System.Web.UI.TCompositeControl');
-
-/**
- * TTemplateControl class.
- * TTemplateControl is the base class for all controls that use templates.
- * By default, a control template is assumed to be in a file under the same
- * directory with the control class file. They have the same file name and
- * different extension name. For template file, the extension name is ".tpl".
- *
- * @author Qiang Xue <qiang.xue@gmail.com>
- * @version $Id$
- * @package System.Web.UI
- * @since 3.0
- */
-class TTemplateControl extends TCompositeControl
-{
- /**
- * template file extension.
- */
- const EXT_TEMPLATE='.tpl';
-
- /**
- * @var ITemplate the parsed template structure shared by the same control class
- */
- private static $_template=array();
- /**
- * @var ITemplate the parsed template structure specific for this control instance
- */
- private $_localTemplate=null;
- /**
- * @var TTemplateControl the master control if any
- */
- private $_master=null;
- /**
- * @var string master control class name
- */
- private $_masterClass='';
- /**
- * @var array list of TContent controls
- */
- private $_contents=array();
- /**
- * @var array list of TContentPlaceHolder controls
- */
- private $_placeholders=array();
-
- /**
- * Returns the template object associated with this control object.
- * @return ITemplate|null the parsed template, null if none
- */
- public function getTemplate()
- {
- if($this->_localTemplate===null)
- {
- $class=get_class($this);
- if(!isset(self::$_template[$class]))
- self::$_template[$class]=$this->loadTemplate();
- return self::$_template[$class];
- }
- else
- return $this->_localTemplate;
- }
-
- /**
- * Sets the parsed template.
- * Note, the template will be applied to the whole control class.
- * This method should only be used by framework and control developers.
- * @param ITemplate the parsed template
- */
- public function setTemplate($value)
- {
- $this->_localTemplate=$value;
- }
-
- /**
- * @return boolean whether this control is a source template control.
- * A source template control loads its template from external storage,
- * such as file, db, rather than from within another template.
- */
- public function getIsSourceTemplateControl()
- {
- if(($template=$this->getTemplate())!==null)
- return $template->getIsSourceTemplate();
- else
- return false;
- }
-
- /**
- * @return string the directory containing the template. Empty if no template available.
- */
- public function getTemplateDirectory()
- {
- if(($template=$this->getTemplate())!==null)
- return $template->getContextPath();
- else
- return '';
- }
-
- /**
- * Loads the template associated with this control class.
- * @return ITemplate the parsed template structure
- */
- protected function loadTemplate()
- {
- Prado::trace("Loading template ".get_class($this),'System.Web.UI.TTemplateControl');
- $template=$this->getService()->getTemplateManager()->getTemplateByClassName(get_class($this));
- return $template;
- }
-
- /**
- * Creates child controls.
- * This method is overridden to load and instantiate control template.
- * This method should only be used by framework and control developers.
- */
- public function createChildControls()
- {
- if($tpl=$this->getTemplate())
- {
- foreach($tpl->getDirective() as $name=>$value)
- {
- if(is_string($value))
- $this->setSubProperty($name,$value);
- else
- throw new TConfigurationException('templatecontrol_directive_invalid',get_class($this),$name);
- }
- $tpl->instantiateIn($this);
- }
- }
-
- /**
- * Registers a content control.
- * @param string ID of the content
- * @param TContent
- */
- public function registerContent($id,TContent $object)
- {
- if(isset($this->_contents[$id]))
- throw new TConfigurationException('templatecontrol_contentid_duplicated',$id);
- else
- $this->_contents[$id]=$object;
- }
-
- /**
- * Registers a content placeholder to this template control.
- * This method should only be used by framework and control developers.
- * @param string placeholder ID
- * @param TContentPlaceHolder placeholder control
- */
- public function registerContentPlaceHolder($id,TContentPlaceHolder $object)
- {
- if(isset($this->_placeholders[$id]))
- throw new TConfigurationException('templatecontrol_placeholderid_duplicated',$id);
- else
- $this->_placeholders[$id]=$object;
- }
-
- /**
- * @return string master class name (in namespace form)
- */
- public function getMasterClass()
- {
- return $this->_masterClass;
- }
-
- /**
- * @param string master control class name (in namespace form)
- */
- public function setMasterClass($value)
- {
- $this->_masterClass=$value;
- }
-
- /**
- * @return TTemplateControl|null master control associated with this control, null if none
- */
- public function getMaster()
- {
- return $this->_master;
- }
-
- /**
- * Injects all content controls (and their children) to the corresponding content placeholders.
- * This method should only be used by framework and control developers.
- * @param string ID of the content control
- * @param TContent the content to be injected
- */
- public function injectContent($id,$content)
- {
- if(isset($this->_placeholders[$id]))
- {
- $placeholder=$this->_placeholders[$id];
- $controls=$placeholder->getParent()->getControls();
- $loc=$controls->remove($placeholder);
- $controls->insertAt($loc,$content);
- }
- else
- throw new TConfigurationException('templatecontrol_placeholder_inexistent',$id);
- }
-
- /**
- * Performs the OnInit step for the control and all its child controls.
- * This method overrides the parent implementation
- * by ensuring child controls are created first,
- * and if master class is set, master will be applied.
- * Only framework developers should use this method.
- * @param TControl the naming container control
- */
- protected function initRecursive($namingContainer=null)
- {
- $this->ensureChildControls();
- if($this->_masterClass!=='')
- {
- $master=Prado::createComponent($this->_masterClass);
- if(!($master instanceof TTemplateControl))
- throw new TInvalidDataValueException('templatecontrol_mastercontrol_invalid');
- $this->_master=$master;
- $this->getControls()->clear();
- $this->getControls()->add($master);
- $master->ensureChildControls();
- foreach($this->_contents as $id=>$content)
- $master->injectContent($id,$content);
- }
- else if(!empty($this->_contents))
- throw new TConfigurationException('templatecontrol_mastercontrol_required',get_class($this));
- parent::initRecursive($namingContainer);
- }
-}
-
+ * @license http://www.pradosoft.com/license/
+ * @version $Id$
+ * @package System.Web.UI
+ */
+
+/**
+ * Includes TCompositeControl class
+ */
+Prado::using('System.Web.UI.TCompositeControl');
+
+/**
+ * TTemplateControl class.
+ * TTemplateControl is the base class for all controls that use templates.
+ * By default, a control template is assumed to be in a file under the same
+ * directory with the control class file. They have the same file name and
+ * different extension name. For template file, the extension name is ".tpl".
+ *
+ * @author Qiang Xue <qiang.xue@gmail.com>
+ * @version $Id$
+ * @package System.Web.UI
+ * @since 3.0
+ */
+class TTemplateControl extends TCompositeControl
+{
+ /**
+ * template file extension.
+ */
+ const EXT_TEMPLATE='.tpl';
+
+ /**
+ * @var ITemplate the parsed template structure shared by the same control class
+ */
+ private static $_template=array();
+ /**
+ * @var ITemplate the parsed template structure specific for this control instance
+ */
+ private $_localTemplate=null;
+ /**
+ * @var TTemplateControl the master control if any
+ */
+ private $_master=null;
+ /**
+ * @var string master control class name
+ */
+ private $_masterClass='';
+ /**
+ * @var array list of TContent controls
+ */
+ private $_contents=array();
+ /**
+ * @var array list of TContentPlaceHolder controls
+ */
+ private $_placeholders=array();
+
+ /**
+ * Returns the template object associated with this control object.
+ * @return ITemplate|null the parsed template, null if none
+ */
+ public function getTemplate()
+ {
+ if($this->_localTemplate===null)
+ {
+ $class=get_class($this);
+ if(!isset(self::$_template[$class]))
+ self::$_template[$class]=$this->loadTemplate();
+ return self::$_template[$class];
+ }
+ else
+ return $this->_localTemplate;
+ }
+
+ /**
+ * Sets the parsed template.
+ * Note, the template will be applied to the whole control class.
+ * This method should only be used by framework and control developers.
+ * @param ITemplate the parsed template
+ */
+ public function setTemplate($value)
+ {
+ $this->_localTemplate=$value;
+ }
+
+ /**
+ * @return boolean whether this control is a source template control.
+ * A source template control loads its template from external storage,
+ * such as file, db, rather than from within another template.
+ */
+ public function getIsSourceTemplateControl()
+ {
+ if(($template=$this->getTemplate())!==null)
+ return $template->getIsSourceTemplate();
+ else
+ return false;
+ }
+
+ /**
+ * @return string the directory containing the template. Empty if no template available.
+ */
+ public function getTemplateDirectory()
+ {
+ if(($template=$this->getTemplate())!==null)
+ return $template->getContextPath();
+ else
+ return '';
+ }
+
+ /**
+ * Loads the template associated with this control class.
+ * @return ITemplate the parsed template structure
+ */
+ protected function loadTemplate()
+ {
+ Prado::trace("Loading template ".get_class($this),'System.Web.UI.TTemplateControl');
+ $template=$this->getService()->getTemplateManager()->getTemplateByClassName(get_class($this));
+ return $template;
+ }
+
+ /**
+ * Creates child controls.
+ * This method is overridden to load and instantiate control template.
+ * This method should only be used by framework and control developers.
+ */
+ public function createChildControls()
+ {
+ if($tpl=$this->getTemplate())
+ {
+ foreach($tpl->getDirective() as $name=>$value)
+ {
+ if(is_string($value))
+ $this->setSubProperty($name,$value);
+ else
+ throw new TConfigurationException('templatecontrol_directive_invalid',get_class($this),$name);
+ }
+ $tpl->instantiateIn($this);
+ }
+ }
+
+ /**
+ * Registers a content control.
+ * @param string ID of the content
+ * @param TContent
+ */
+ public function registerContent($id,TContent $object)
+ {
+ if(isset($this->_contents[$id]))
+ throw new TConfigurationException('templatecontrol_contentid_duplicated',$id);
+ else
+ $this->_contents[$id]=$object;
+ }
+
+ /**
+ * Registers a content placeholder to this template control.
+ * This method should only be used by framework and control developers.
+ * @param string placeholder ID
+ * @param TContentPlaceHolder placeholder control
+ */
+ public function registerContentPlaceHolder($id,TContentPlaceHolder $object)
+ {
+ if(isset($this->_placeholders[$id]))
+ throw new TConfigurationException('templatecontrol_placeholderid_duplicated',$id);
+ else
+ $this->_placeholders[$id]=$object;
+ }
+
+ /**
+ * @return string master class name (in namespace form)
+ */
+ public function getMasterClass()
+ {
+ return $this->_masterClass;
+ }
+
+ /**
+ * @param string master control class name (in namespace form)
+ */
+ public function setMasterClass($value)
+ {
+ $this->_masterClass=$value;
+ }
+
+ /**
+ * @return TTemplateControl|null master control associated with this control, null if none
+ */
+ public function getMaster()
+ {
+ return $this->_master;
+ }
+
+ /**
+ * Injects all content controls (and their children) to the corresponding content placeholders.
+ * This method should only be used by framework and control developers.
+ * @param string ID of the content control
+ * @param TContent the content to be injected
+ */
+ public function injectContent($id,$content)
+ {
+ if(isset($this->_placeholders[$id]))
+ {
+ $placeholder=$this->_placeholders[$id];
+ $controls=$placeholder->getParent()->getControls();
+ $loc=$controls->remove($placeholder);
+ $controls->insertAt($loc,$content);
+ }
+ else
+ throw new TConfigurationException('templatecontrol_placeholder_inexistent',$id);
+ }
+
+ /**
+ * Performs the OnInit step for the control and all its child controls.
+ * This method overrides the parent implementation
+ * by ensuring child controls are created first,
+ * and if master class is set, master will be applied.
+ * Only framework developers should use this method.
+ * @param TControl the naming container control
+ */
+ protected function initRecursive($namingContainer=null)
+ {
+ $this->ensureChildControls();
+ if($this->_masterClass!=='')
+ {
+ $master=Prado::createComponent($this->_masterClass);
+ if(!($master instanceof TTemplateControl))
+ throw new TInvalidDataValueException('templatecontrol_mastercontrol_invalid');
+ $this->_master=$master;
+ $this->getControls()->clear();
+ $this->getControls()->add($master);
+ $master->ensureChildControls();
+ foreach($this->_contents as $id=>$content)
+ $master->injectContent($id,$content);
+ }
+ else if(!empty($this->_contents))
+ throw new TConfigurationException('templatecontrol_mastercontrol_required',get_class($this));
+ parent::initRecursive($namingContainer);
+ }
+}
+
diff --git a/framework/Web/UI/TTemplateManager.php b/framework/Web/UI/TTemplateManager.php
index 4d17806b..f884cd65 100644
--- a/framework/Web/UI/TTemplateManager.php
+++ b/framework/Web/UI/TTemplateManager.php
@@ -1,1075 +1,1075 @@
-<?php
-/**
- * TTemplateManager and TTemplate class file
- *
- * @author Qiang Xue <qiang.xue@gmail.com>
- * @link http://www.pradosoft.com/
- * @copyright Copyright &copy; 2005-2012 PradoSoft
- * @license http://www.pradosoft.com/license/
- * @version $Id$
- * @package System.Web.UI
- */
-
-/**
- * Includes TOutputCache class file
- */
-Prado::using('System.Web.UI.WebControls.TOutputCache');
-
-/**
- * TTemplateManager class
- *
- * TTemplateManager manages the loading and parsing of control templates.
- *
- * There are two ways of loading a template, either by the associated template
- * control class name, or the template file name.
- * The former is via calling {@link getTemplateByClassName}, which tries to
- * locate the corresponding template file under the directory containing
- * the class file. The name of the template file is the class name with
- * the extension '.tpl'. To load a template from a template file path,
- * call {@link getTemplateByFileName}.
- *
- * By default, TTemplateManager is registered with {@link TPageService} as the
- * template manager module that can be accessed via {@link TPageService::getTemplateManager()}.
- *
- * @author Qiang Xue <qiang.xue@gmail.com>
- * @version $Id$
- * @package System.Web.UI
- * @since 3.0
- */
-class TTemplateManager extends TModule
-{
- /**
- * Template file extension
- */
- const TEMPLATE_FILE_EXT='.tpl';
- /**
- * Prefix of the cache variable name for storing parsed templates
- */
- const TEMPLATE_CACHE_PREFIX='prado:template:';
-
- /**
- * Initializes the module.
- * This method is required by IModule and is invoked by application.
- * It starts output buffer if it is enabled.
- * @param TXmlElement module configuration
- */
- public function init($config)
- {
- $this->getService()->setTemplateManager($this);
- }
-
- /**
- * Loads the template corresponding to the specified class name.
- * @return ITemplate template for the class name, null if template doesn't exist.
- */
- public function getTemplateByClassName($className)
- {
- $class=new ReflectionClass($className);
- $tplFile=dirname($class->getFileName()).DIRECTORY_SEPARATOR.$className.self::TEMPLATE_FILE_EXT;
- return $this->getTemplateByFileName($tplFile);
- }
-
- /**
- * Loads the template from the specified file.
- * @return ITemplate template parsed from the specified file, null if the file doesn't exist.
- */
- public function getTemplateByFileName($fileName)
- {
- if(($fileName=$this->getLocalizedTemplate($fileName))!==null)
- {
- Prado::trace("Loading template $fileName",'System.Web.UI.TTemplateManager');
- if(($cache=$this->getApplication()->getCache())===null)
- return new TTemplate(file_get_contents($fileName),dirname($fileName),$fileName);
- else
- {
- $array=$cache->get(self::TEMPLATE_CACHE_PREFIX.$fileName);
- if(is_array($array))
- {
- list($template,$timestamps)=$array;
- if($this->getApplication()->getMode()===TApplicationMode::Performance)
- return $template;
- $cacheValid=true;
- foreach($timestamps as $tplFile=>$timestamp)
- {
- if(!is_file($tplFile) || filemtime($tplFile)>$timestamp)
- {
- $cacheValid=false;
- break;
- }
- }
- if($cacheValid)
- return $template;
- }
- $template=new TTemplate(file_get_contents($fileName),dirname($fileName),$fileName);
- $includedFiles=$template->getIncludedFiles();
- $timestamps=array();
- $timestamps[$fileName]=filemtime($fileName);
- foreach($includedFiles as $includedFile)
- $timestamps[$includedFile]=filemtime($includedFile);
- $cache->set(self::TEMPLATE_CACHE_PREFIX.$fileName,array($template,$timestamps));
- return $template;
- }
- }
- else
- return null;
- }
-
- /**
- * Finds a localized template file.
- * @param string template file.
- * @return string|null a localized template file if found, null otherwise.
- */
- protected function getLocalizedTemplate($filename)
- {
- if(($app=$this->getApplication()->getGlobalization(false))===null)
- return is_file($filename)?$filename:null;
- foreach($app->getLocalizedResource($filename) as $file)
- {
- if(($file=realpath($file))!==false && is_file($file))
- return $file;
- }
- return null;
- }
-}
-
-/**
- * TTemplate implements PRADO template parsing logic.
- * A TTemplate object represents a parsed PRADO control template.
- * It can instantiate the template as child controls of a specified control.
- * The template format is like HTML, with the following special tags introduced,
- * - component tags: a component tag represents the configuration of a component.
- * The tag name is in the format of com:ComponentType, where ComponentType is the component
- * class name. Component tags must be well-formed. Attributes of the component tag
- * are treated as either property initial values, event handler attachment, or regular
- * tag attributes.
- * - property tags: property tags are used to set large block of attribute values.
- * The property tag name is in the format of <prop:AttributeName> where AttributeName
- * can be a property name, an event name or a regular tag attribute name.
- * - group subproperty tags: subproperties of a common property can be configured using
- * <prop:MainProperty SubProperty1="Value1" SubProperty2="Value2" .../>
- * - directive: directive specifies the property values for the template owner.
- * It is in the format of <%@ property name-value pairs %>;
- * - expressions: They are in the format of <%= PHP expression %> and <%% PHP statements %>
- * - comments: There are two kinds of comments, regular HTML comments and special template comments.
- * The former is in the format of <!-- comments -->, which will be treated as text strings.
- * The latter is in the format of <!-- comments --!>, which will be stripped out.
- *
- * Tags other than the above are not required to be well-formed.
- *
- * A TTemplate object represents a parsed PRADO template. To instantiate the template
- * for a particular control, call {@link instantiateIn($control)}, which
- * will create and intialize all components specified in the template and
- * set their parent as $control.
- *
- * @author Qiang Xue <qiang.xue@gmail.com>
- * @version $Id$
- * @package System.Web.UI
- * @since 3.0
- */
-class TTemplate extends TApplicationComponent implements ITemplate
-{
- /**
- * '<!--.*?--!>' - template comments
- * '<!--.*?-->' - HTML comments
- * '<\/?com:([\w\.]+)((?:\s*[\w\.]+\s*=\s*\'.*?\'|\s*[\w\.]+\s*=\s*".*?"|\s*[\w\.]+\s*=\s*<%.*?%>)*)\s*\/?>' - component tags
- * '<\/?prop:([\w\.]+)\s*>' - property tags
- * '<%@\s*((?:\s*[\w\.]+\s*=\s*\'.*?\'|\s*[\w\.]+\s*=\s*".*?")*)\s*%>' - directives
- * '<%[%#~\/\\$=\\[](.*?)%>' - expressions
- * '<prop:([\w\.]+)((?:\s*[\w\.]+=\'.*?\'|\s*[\w\.]+=".*?"|\s*[\w\.]+=<%.*?%>)*)\s*\/>' - group subproperty tags
- */
- const REGEX_RULES='/<!--.*?--!>|<!---.*?--->|<\/?com:([\w\.]+)((?:\s*[\w\.]+\s*=\s*\'.*?\'|\s*[\w\.]+\s*=\s*".*?"|\s*[\w\.]+\s*=\s*<%.*?%>)*)\s*\/?>|<\/?prop:([\w\.]+)\s*>|<%@\s*((?:\s*[\w\.]+\s*=\s*\'.*?\'|\s*[\w\.]+\s*=\s*".*?")*)\s*%>|<%[%#~\/\\$=\\[](.*?)%>|<prop:([\w\.]+)((?:\s*[\w\.]+\s*=\s*\'.*?\'|\s*[\w\.]+\s*=\s*".*?"|\s*[\w\.]+\s*=\s*<%.*?%>)*)\s*\/>/msS';
-
- /**
- * Different configurations of component property/event/attribute
- */
- const CONFIG_DATABIND=0;
- const CONFIG_EXPRESSION=1;
- const CONFIG_ASSET=2;
- const CONFIG_PARAMETER=3;
- const CONFIG_LOCALIZATION=4;
- const CONFIG_TEMPLATE=5;
-
- /**
- * @var array list of component tags and strings
- */
- private $_tpl=array();
- /**
- * @var array list of directive settings
- */
- private $_directive=array();
- /**
- * @var string context path
- */
- private $_contextPath;
- /**
- * @var string template file path (if available)
- */
- private $_tplFile=null;
- /**
- * @var integer the line number that parsing starts from (internal use)
- */
- private $_startingLine=0;
- /**
- * @var string template content to be parsed
- */
- private $_content;
- /**
- * @var boolean whether this template is a source template
- */
- private $_sourceTemplate=true;
- /**
- * @var string hash code of the template
- */
- private $_hashCode='';
- private $_tplControl=null;
- private $_includedFiles=array();
- private $_includeAtLine=array();
- private $_includeLines=array();
-
-
- /**
- * Constructor.
- * The template will be parsed after construction.
- * @param string the template string
- * @param string the template context directory
- * @param string the template file, null if no file
- * @param integer the line number that parsing starts from (internal use)
- * @param boolean whether this template is a source template, i.e., this template is loaded from
- * some external storage rather than from within another template.
- */
- public function __construct($template,$contextPath,$tplFile=null,$startingLine=0,$sourceTemplate=true)
- {
- $this->_sourceTemplate=$sourceTemplate;
- $this->_contextPath=$contextPath;
- $this->_tplFile=$tplFile;
- $this->_startingLine=$startingLine;
- $this->_content=$template;
- $this->_hashCode=md5($template);
- $this->parse($template);
- $this->_content=null; // reset to save memory
- }
-
- /**
- * @return string template file path if available, null otherwise.
- */
- public function getTemplateFile()
- {
- return $this->_tplFile;
- }
-
- /**
- * @return boolean whether this template is a source template, i.e., this template is loaded from
- * some external storage rather than from within another template.
- */
- public function getIsSourceTemplate()
- {
- return $this->_sourceTemplate;
- }
-
- /**
- * @return string context directory path
- */
- public function getContextPath()
- {
- return $this->_contextPath;
- }
-
- /**
- * @return array name-value pairs declared in the directive
- */
- public function getDirective()
- {
- return $this->_directive;
- }
-
- /**
- * @return string hash code that can be used to identify the template
- */
- public function getHashCode()
- {
- return $this->_hashCode;
- }
-
- /**
- * @return array the parsed template
- */
- public function &getItems()
- {
- return $this->_tpl;
- }
-
- /**
- * Instantiates the template.
- * Content in the template will be instantiated as components and text strings
- * and passed to the specified parent control.
- * @param TControl the control who owns the template
- * @param TControl the control who will become the root parent of the controls on the template. If null, it uses the template control.
- */
- public function instantiateIn($tplControl,$parentControl=null)
- {
- $this->_tplControl=$tplControl;
- if($parentControl===null)
- $parentControl=$tplControl;
- if(($page=$tplControl->getPage())===null)
- $page=$this->getService()->getRequestedPage();
- $controls=array();
- $directChildren=array();
- foreach($this->_tpl as $key=>$object)
- {
- if($object[0]===-1)
- $parent=$parentControl;
- else if(isset($controls[$object[0]]))
- $parent=$controls[$object[0]];
- else
- continue;
- if(isset($object[2])) // component
- {
- $component=Prado::createComponent($object[1]);
- $properties=&$object[2];
- if($component instanceof TControl)
- {
- if($component instanceof TOutputCache)
- $component->setCacheKeyPrefix($this->_hashCode.$key);
- $component->setTemplateControl($tplControl);
- if(isset($properties['id']))
- {
- if(is_array($properties['id']))
- $properties['id']=$component->evaluateExpression($properties['id'][1]);
- $tplControl->registerObject($properties['id'],$component);
- }
- if(isset($properties['skinid']))
- {
- if(is_array($properties['skinid']))
- $component->setSkinID($component->evaluateExpression($properties['skinid'][1]));
- else
- $component->setSkinID($properties['skinid']);
- unset($properties['skinid']);
- }
-
- $component->trackViewState(false);
-
- $component->applyStyleSheetSkin($page);
- foreach($properties as $name=>$value)
- $this->configureControl($component,$name,$value);
-
- $component->trackViewState(true);
-
- if($parent===$parentControl)
- $directChildren[]=$component;
- else
- $component->createdOnTemplate($parent);
- if($component->getAllowChildControls())
- $controls[$key]=$component;
- }
- else if($component instanceof TComponent)
- {
- $controls[$key]=$component;
- if(isset($properties['id']))
- {
- if(is_array($properties['id']))
- $properties['id']=$component->evaluateExpression($properties['id'][1]);
- $tplControl->registerObject($properties['id'],$component);
- if(!$component->hasProperty('id'))
- unset($properties['id']);
- }
- foreach($properties as $name=>$value)
- $this->configureComponent($component,$name,$value);
- if($parent===$parentControl)
- $directChildren[]=$component;
- else
- $component->createdOnTemplate($parent);
- }
- }
- else
- {
- if($object[1] instanceof TCompositeLiteral)
- {
- // need to clone a new object because the one in template is reused
- $o=clone $object[1];
- $o->setContainer($tplControl);
- if($parent===$parentControl)
- $directChildren[]=$o;
- else
- $parent->addParsedObject($o);
- }
- else
- {
- if($parent===$parentControl)
- $directChildren[]=$object[1];
- else
- $parent->addParsedObject($object[1]);
- }
- }
- }
- // delay setting parent till now because the parent may cause
- // the child to do lifecycle catchup which may cause problem
- // if the child needs its own child controls.
- foreach($directChildren as $control)
- {
- if($control instanceof TComponent)
- $control->createdOnTemplate($parentControl);
- else
- $parentControl->addParsedObject($control);
- }
- }
-
- /**
- * Configures a property/event of a control.
- * @param TControl control to be configured
- * @param string property name
- * @param mixed property initial value
- */
- protected function configureControl($control,$name,$value)
- {
- if(strncasecmp($name,'on',2)===0) // is an event
- $this->configureEvent($control,$name,$value,$control);
- else if(($pos=strrpos($name,'.'))===false) // is a simple property or custom attribute
- $this->configureProperty($control,$name,$value);
- else // is a subproperty
- $this->configureSubProperty($control,$name,$value);
- }
-
- /**
- * Configures a property of a non-control component.
- * @param TComponent component to be configured
- * @param string property name
- * @param mixed property initial value
- */
- protected function configureComponent($component,$name,$value)
- {
- if(strpos($name,'.')===false) // is a simple property or custom attribute
- $this->configureProperty($component,$name,$value);
- else // is a subproperty
- $this->configureSubProperty($component,$name,$value);
- }
-
- /**
- * Configures an event for a control.
- * @param TControl control to be configured
- * @param string event name
- * @param string event handler
- * @param TControl context control
- */
- protected function configureEvent($control,$name,$value,$contextControl)
- {
- if(strpos($value,'.')===false)
- $control->attachEventHandler($name,array($contextControl,'TemplateControl.'.$value));
- else
- $control->attachEventHandler($name,array($contextControl,$value));
- }
-
- /**
- * Configures a simple property for a component.
- * @param TComponent component to be configured
- * @param string property name
- * @param mixed property initial value
- */
- protected function configureProperty($component,$name,$value)
- {
- if(is_array($value))
- {
- switch($value[0])
- {
- case self::CONFIG_DATABIND:
- $component->bindProperty($name,$value[1]);
- break;
- case self::CONFIG_EXPRESSION:
- if($component instanceof TControl)
- $component->autoBindProperty($name,$value[1]);
- else
- {
- $setter='set'.$name;
- $component->$setter($this->_tplControl->evaluateExpression($value[1]));
- }
- break;
- case self::CONFIG_TEMPLATE:
- $setter='set'.$name;
- $component->$setter($value[1]);
- break;
- case self::CONFIG_ASSET: // asset URL
- $setter='set'.$name;
- $url=$this->publishFilePath($this->_contextPath.DIRECTORY_SEPARATOR.$value[1]);
- $component->$setter($url);
- break;
- case self::CONFIG_PARAMETER: // application parameter
- $setter='set'.$name;
- $component->$setter($this->getApplication()->getParameters()->itemAt($value[1]));
- break;
- case self::CONFIG_LOCALIZATION:
- $setter='set'.$name;
- $component->$setter(Prado::localize($value[1]));
- break;
- default: // an error if reaching here
- throw new TConfigurationException('template_tag_unexpected',$name,$value[1]);
- break;
- }
- }
- else
- {
- if (substr($name,0,2)=='js')
- if ($value and !($value instanceof TJavaScriptLiteral))
- $value = new TJavaScriptLiteral($value);
- $setter='set'.$name;
- $component->$setter($value);
- }
- }
-
- /**
- * Configures a subproperty for a component.
- * @param TComponent component to be configured
- * @param string subproperty name
- * @param mixed subproperty initial value
- */
- protected function configureSubProperty($component,$name,$value)
- {
- if(is_array($value))
- {
- switch($value[0])
- {
- case self::CONFIG_DATABIND: // databinding
- $component->bindProperty($name,$value[1]);
- break;
- case self::CONFIG_EXPRESSION: // expression
- if($component instanceof TControl)
- $component->autoBindProperty($name,$value[1]);
- else
- $component->setSubProperty($name,$this->_tplControl->evaluateExpression($value[1]));
- break;
- case self::CONFIG_TEMPLATE:
- $component->setSubProperty($name,$value[1]);
- break;
- case self::CONFIG_ASSET: // asset URL
- $url=$this->publishFilePath($this->_contextPath.DIRECTORY_SEPARATOR.$value[1]);
- $component->setSubProperty($name,$url);
- break;
- case self::CONFIG_PARAMETER: // application parameter
- $component->setSubProperty($name,$this->getApplication()->getParameters()->itemAt($value[1]));
- break;
- case self::CONFIG_LOCALIZATION:
- $component->setSubProperty($name,Prado::localize($value[1]));
- break;
- default: // an error if reaching here
- throw new TConfigurationException('template_tag_unexpected',$name,$value[1]);
- break;
- }
- }
- else
- $component->setSubProperty($name,$value);
- }
-
- /**
- * Parses a template string.
- *
- * This template parser recognizes five types of data:
- * regular string, well-formed component tags, well-formed property tags, directives, and expressions.
- *
- * The parsing result is returned as an array. Each array element can be of three types:
- * - a string, 0: container index; 1: string content;
- * - a component tag, 0: container index; 1: component type; 2: attributes (name=>value pairs)
- * If a directive is found in the template, it will be parsed and can be
- * retrieved via {@link getDirective}, which returns an array consisting of
- * name-value pairs in the directive.
- *
- * Note, attribute names are treated as case-insensitive and will be turned into lower cases.
- * Component and directive types are case-sensitive.
- * Container index is the index to the array element that stores the container object.
- * If an object has no container, its container index is -1.
- *
- * @param string the template string
- * @throws TConfigurationException if a parsing error is encountered
- */
- protected function parse($input)
- {
- $input=$this->preprocess($input);
- $tpl=&$this->_tpl;
- $n=preg_match_all(self::REGEX_RULES,$input,$matches,PREG_SET_ORDER|PREG_OFFSET_CAPTURE);
- $expectPropEnd=false;
- $textStart=0;
- $stack=array();
- $container=-1;
- $matchEnd=0;
- $c=0;
- $this->_directive=null;
- try
- {
- for($i=0;$i<$n;++$i)
- {
- $match=&$matches[$i];
- $str=$match[0][0];
- $matchStart=$match[0][1];
- $matchEnd=$matchStart+strlen($str)-1;
- if(strpos($str,'<com:')===0) // opening component tag
- {
- if($expectPropEnd)
- continue;
- if($matchStart>$textStart)
- $tpl[$c++]=array($container,substr($input,$textStart,$matchStart-$textStart));
- $textStart=$matchEnd+1;
- $type=$match[1][0];
- $attributes=$this->parseAttributes($match[2][0],$match[2][1]);
- $this->validateAttributes($type,$attributes);
- $tpl[$c++]=array($container,$type,$attributes);
- if($str[strlen($str)-2]!=='/') // open tag
- {
- $stack[] = $type;
- $container=$c-1;
- }
- }
- else if(strpos($str,'</com:')===0) // closing component tag
- {
- if($expectPropEnd)
- continue;
- if($matchStart>$textStart)
- $tpl[$c++]=array($container,substr($input,$textStart,$matchStart-$textStart));
- $textStart=$matchEnd+1;
- $type=$match[1][0];
-
- if(empty($stack))
- throw new TConfigurationException('template_closingtag_unexpected',"</com:$type>");
-
- $name=array_pop($stack);
- if($name!==$type)
- {
- $tag=$name[0]==='@' ? '</prop:'.substr($name,1).'>' : "</com:$name>";
- throw new TConfigurationException('template_closingtag_expected',$tag);
- }
- $container=$tpl[$container][0];
- }
- else if(strpos($str,'<%@')===0) // directive
- {
- if($expectPropEnd)
- continue;
- if($matchStart>$textStart)
- $tpl[$c++]=array($container,substr($input,$textStart,$matchStart-$textStart));
- $textStart=$matchEnd+1;
- if(isset($tpl[0]) || $this->_directive!==null)
- throw new TConfigurationException('template_directive_nonunique');
- $this->_directive=$this->parseAttributes($match[4][0],$match[4][1]);
- }
- else if(strpos($str,'<%')===0) // expression
- {
- if($expectPropEnd)
- continue;
- if($matchStart>$textStart)
- $tpl[$c++]=array($container,substr($input,$textStart,$matchStart-$textStart));
- $textStart=$matchEnd+1;
- $literal=trim($match[5][0]);
- if($str[2]==='=') // expression
- $tpl[$c++]=array($container,array(TCompositeLiteral::TYPE_EXPRESSION,$literal));
- else if($str[2]==='%') // statements
- $tpl[$c++]=array($container,array(TCompositeLiteral::TYPE_STATEMENTS,$literal));
- else if($str[2]==='#')
- $tpl[$c++]=array($container,array(TCompositeLiteral::TYPE_DATABINDING,$literal));
- else if($str[2]==='$')
- $tpl[$c++]=array($container,array(TCompositeLiteral::TYPE_EXPRESSION,"\$this->getApplication()->getParameters()->itemAt('$literal')"));
- else if($str[2]==='~')
- $tpl[$c++]=array($container,array(TCompositeLiteral::TYPE_EXPRESSION,"\$this->publishFilePath('$this->_contextPath/$literal')"));
- else if($str[2]==='/')
- $tpl[$c++]=array($container,array(TCompositeLiteral::TYPE_EXPRESSION,"dirname(\$this->getApplication()->getRequest()->getApplicationUrl()).'/$literal'"));
- else if($str[2]==='[')
- {
- $literal=strtr(trim(substr($literal,0,strlen($literal)-1)),array("'"=>"\'","\\"=>"\\\\"));
- $tpl[$c++]=array($container,array(TCompositeLiteral::TYPE_EXPRESSION,"Prado::localize('$literal')"));
- }
- }
- else if(strpos($str,'<prop:')===0) // opening property
- {
- if(strrpos($str,'/>')===strlen($str)-2) //subproperties
- {
- if($expectPropEnd)
- continue;
- if($matchStart>$textStart)
- $tpl[$c++]=array($container,substr($input,$textStart,$matchStart-$textStart));
- $textStart=$matchEnd+1;
- $prop=strtolower($match[6][0]);
- $attrs=$this->parseAttributes($match[7][0],$match[7][1]);
- $attributes=array();
- foreach($attrs as $name=>$value)
- $attributes[$prop.'.'.$name]=$value;
- $type=$tpl[$container][1];
- $this->validateAttributes($type,$attributes);
- foreach($attributes as $name=>$value)
- {
- if(isset($tpl[$container][2][$name]))
- throw new TConfigurationException('template_property_duplicated',$name);
- $tpl[$container][2][$name]=$value;
- }
- }
- else // regular property
- {
- $prop=strtolower($match[3][0]);
- $stack[] = '@'.$prop;
- if(!$expectPropEnd)
- {
- if($matchStart>$textStart)
- $tpl[$c++]=array($container,substr($input,$textStart,$matchStart-$textStart));
- $textStart=$matchEnd+1;
- $expectPropEnd=true;
- }
- }
- }
- else if(strpos($str,'</prop:')===0) // closing property
- {
- $prop=strtolower($match[3][0]);
- if(empty($stack))
- throw new TConfigurationException('template_closingtag_unexpected',"</prop:$prop>");
- $name=array_pop($stack);
- if($name!=='@'.$prop)
- {
- $tag=$name[0]==='@' ? '</prop:'.substr($name,1).'>' : "</com:$name>";
- throw new TConfigurationException('template_closingtag_expected',$tag);
- }
- if(($last=count($stack))<1 || $stack[$last-1][0]!=='@')
- {
- if($matchStart>$textStart)
- {
- $value=substr($input,$textStart,$matchStart-$textStart);
- if(substr($prop,-8,8)==='template')
- $value=$this->parseTemplateProperty($value,$textStart);
- else
- $value=$this->parseAttribute($value);
- if($container>=0)
- {
- $type=$tpl[$container][1];
- $this->validateAttributes($type,array($prop=>$value));
- if(isset($tpl[$container][2][$prop]))
- throw new TConfigurationException('template_property_duplicated',$prop);
- $tpl[$container][2][$prop]=$value;
- }
- else // a property for the template control
- $this->_directive[$prop]=$value;
- $textStart=$matchEnd+1;
- }
- $expectPropEnd=false;
- }
- }
- else if(strpos($str,'<!--')===0) // comments
- {
- if($expectPropEnd)
- throw new TConfigurationException('template_comments_forbidden');
- if($matchStart>$textStart)
- $tpl[$c++]=array($container,substr($input,$textStart,$matchStart-$textStart));
- $textStart=$matchEnd+1;
- }
- else
- throw new TConfigurationException('template_matching_unexpected',$match);
- }
- if(!empty($stack))
- {
- $name=array_pop($stack);
- $tag=$name[0]==='@' ? '</prop:'.substr($name,1).'>' : "</com:$name>";
- throw new TConfigurationException('template_closingtag_expected',$tag);
- }
- if($textStart<strlen($input))
- $tpl[$c++]=array($container,substr($input,$textStart));
- }
- catch(Exception $e)
- {
- if(($e instanceof TException) && ($e instanceof TTemplateException))
- throw $e;
- if($matchEnd===0)
- $line=$this->_startingLine+1;
- else
- $line=$this->_startingLine+count(explode("\n",substr($input,0,$matchEnd+1)));
- $this->handleException($e,$line,$input);
- }
-
- if($this->_directive===null)
- $this->_directive=array();
-
- // optimization by merging consecutive strings, expressions, statements and bindings
- $objects=array();
- $parent=null;
- $merged=array();
- foreach($tpl as $id=>$object)
- {
- if(isset($object[2]) || $object[0]!==$parent)
- {
- if($parent!==null)
- {
- if(count($merged[1])===1 && is_string($merged[1][0]))
- $objects[$id-1]=array($merged[0],$merged[1][0]);
- else
- $objects[$id-1]=array($merged[0],new TCompositeLiteral($merged[1]));
- }
- if(isset($object[2]))
- {
- $parent=null;
- $objects[$id]=$object;
- }
- else
- {
- $parent=$object[0];
- $merged=array($parent,array($object[1]));
- }
- }
- else
- $merged[1][]=$object[1];
- }
- if($parent!==null)
- {
- if(count($merged[1])===1 && is_string($merged[1][0]))
- $objects[$id]=array($merged[0],$merged[1][0]);
- else
- $objects[$id]=array($merged[0],new TCompositeLiteral($merged[1]));
- }
- $tpl=$objects;
- return $objects;
- }
-
- /**
- * Parses the attributes of a tag from a string.
- * @param string the string to be parsed.
- * @return array attribute values indexed by names.
- */
- protected function parseAttributes($str,$offset)
- {
- if($str==='')
- return array();
- $pattern='/([\w\.\-]+)\s*=\s*(\'.*?\'|".*?"|<%.*?%>)/msS';
- $attributes=array();
- $n=preg_match_all($pattern,$str,$matches,PREG_SET_ORDER|PREG_OFFSET_CAPTURE);
- for($i=0;$i<$n;++$i)
- {
- $match=&$matches[$i];
- $name=strtolower($match[1][0]);
- if(isset($attributes[$name]))
- throw new TConfigurationException('template_property_duplicated',$name);
- $value=$match[2][0];
- if(substr($name,-8,8)==='template')
- {
- if($value[0]==='\'' || $value[0]==='"')
- $attributes[$name]=$this->parseTemplateProperty(substr($value,1,strlen($value)-2),$match[2][1]+1);
- else
- $attributes[$name]=$this->parseTemplateProperty($value,$match[2][1]);
- }
- else
- {
- if($value[0]==='\'' || $value[0]==='"')
- $attributes[$name]=$this->parseAttribute(substr($value,1,strlen($value)-2));
- else
- $attributes[$name]=$this->parseAttribute($value);
- }
- }
- return $attributes;
- }
-
- protected function parseTemplateProperty($content,$offset)
- {
- $line=$this->_startingLine+count(explode("\n",substr($this->_content,0,$offset)))-1;
- return array(self::CONFIG_TEMPLATE,new TTemplate($content,$this->_contextPath,$this->_tplFile,$line,false));
- }
-
- /**
- * Parses a single attribute.
- * @param string the string to be parsed.
- * @return array attribute initialization
- */
- protected function parseAttribute($value)
- {
- if(($n=preg_match_all('/<%[#=].*?%>/msS',$value,$matches,PREG_OFFSET_CAPTURE))>0)
- {
- $isDataBind=false;
- $textStart=0;
- $expr='';
- for($i=0;$i<$n;++$i)
- {
- $match=$matches[0][$i];
- $token=$match[0];
- $offset=$match[1];
- $length=strlen($token);
- if($token[2]==='#')
- $isDataBind=true;
- if($offset>$textStart)
- $expr.=".'".strtr(substr($value,$textStart,$offset-$textStart),array("'"=>"\\'","\\"=>"\\\\"))."'";
- $expr.='.('.substr($token,3,$length-5).')';
- $textStart=$offset+$length;
- }
- $length=strlen($value);
- if($length>$textStart)
- $expr.=".'".strtr(substr($value,$textStart,$length-$textStart),array("'"=>"\\'","\\"=>"\\\\"))."'";
- if($isDataBind)
- return array(self::CONFIG_DATABIND,ltrim($expr,'.'));
- else
- return array(self::CONFIG_EXPRESSION,ltrim($expr,'.'));
- }
- else if(preg_match('/\\s*(<%~.*?%>|<%\\$.*?%>|<%\\[.*?\\]%>|<%\/.*?%>)\\s*/msS',$value,$matches) && $matches[0]===$value)
- {
- $value=$matches[1];
- if($value[2]==='~')
- return array(self::CONFIG_ASSET,trim(substr($value,3,strlen($value)-5)));
- elseif($value[2]==='[')
- return array(self::CONFIG_LOCALIZATION,trim(substr($value,3,strlen($value)-6)));
- elseif($value[2]==='$')
- return array(self::CONFIG_PARAMETER,trim(substr($value,3,strlen($value)-5)));
- elseif($value[2]==='/') {
- $literal = trim(substr($value,3,strlen($value)-5));
- return array(self::CONFIG_EXPRESSION,"dirname(\$this->getApplication()->getRequest()->getApplicationUrl()).'/$literal'");
- }
- }
- else
- return $value;
- }
-
- protected function validateAttributes($type,$attributes)
- {
- Prado::using($type);
- if(($pos=strrpos($type,'.'))!==false)
- $className=substr($type,$pos+1);
- else
- $className=$type;
- $class=new ReflectionClass($className);
- if(is_subclass_of($className,'TControl') || $className==='TControl')
- {
- foreach($attributes as $name=>$att)
- {
- if(($pos=strpos($name,'.'))!==false)
- {
- // a subproperty, so the first segment must be readable
- $subname=substr($name,0,$pos);
- if(!$class->hasMethod('get'.$subname))
- throw new TConfigurationException('template_property_unknown',$type,$subname);
- }
- else if(strncasecmp($name,'on',2)===0)
- {
- // an event
- if(!$class->hasMethod($name))
- throw new TConfigurationException('template_event_unknown',$type,$name);
- else if(!is_string($att))
- throw new TConfigurationException('template_eventhandler_invalid',$type,$name);
- }
- else
- {
- // a simple property
- if (! ($class->hasMethod('set'.$name) || $class->hasMethod('setjs'.$name)) )
- {
- if ($class->hasMethod('get'.$name) || $class->hasMethod('getjs'.$name))
- throw new TConfigurationException('template_property_readonly',$type,$name);
- else
- throw new TConfigurationException('template_property_unknown',$type,$name);
- }
- else if(is_array($att) && $att[0]!==self::CONFIG_EXPRESSION)
- {
- if(strcasecmp($name,'id')===0)
- throw new TConfigurationException('template_controlid_invalid',$type);
- else if(strcasecmp($name,'skinid')===0)
- throw new TConfigurationException('template_controlskinid_invalid',$type);
- }
- }
- }
- }
- else if(is_subclass_of($className,'TComponent') || $className==='TComponent')
- {
- foreach($attributes as $name=>$att)
- {
- if(is_array($att) && ($att[0]===self::CONFIG_DATABIND))
- throw new TConfigurationException('template_databind_forbidden',$type,$name);
- if(($pos=strpos($name,'.'))!==false)
- {
- // a subproperty, so the first segment must be readable
- $subname=substr($name,0,$pos);
- if(!$class->hasMethod('get'.$subname))
- throw new TConfigurationException('template_property_unknown',$type,$subname);
- }
- else if(strncasecmp($name,'on',2)===0)
- throw new TConfigurationException('template_event_forbidden',$type,$name);
- else
- {
- // id is still alowed for TComponent, even if id property doesn't exist
- if(strcasecmp($name,'id')!==0 && !$class->hasMethod('set'.$name))
- {
- if($class->hasMethod('get'.$name))
- throw new TConfigurationException('template_property_readonly',$type,$name);
- else
- throw new TConfigurationException('template_property_unknown',$type,$name);
- }
- }
- }
- }
- else
- throw new TConfigurationException('template_component_required',$type);
- }
-
- /**
- * @return array list of included external template files
- */
- public function getIncludedFiles()
- {
- return $this->_includedFiles;
- }
-
- /**
- * Handles template parsing exception.
- * This method rethrows the exception caught during template parsing.
- * It adjusts the error location by giving out correct error line number and source file.
- * @param Exception template exception
- * @param int line number
- * @param string template string if no source file is used
- */
- protected function handleException($e,$line,$input=null)
- {
- $srcFile=$this->_tplFile;
-
- if(($n=count($this->_includedFiles))>0) // need to adjust error row number and file name
- {
- for($i=$n-1;$i>=0;--$i)
- {
- if($this->_includeAtLine[$i]<=$line)
- {
- if($line<$this->_includeAtLine[$i]+$this->_includeLines[$i])
- {
- $line=$line-$this->_includeAtLine[$i]+1;
- $srcFile=$this->_includedFiles[$i];
- break;
- }
- else
- $line=$line-$this->_includeLines[$i]+1;
- }
- }
- }
- $exception=new TTemplateException('template_format_invalid',$e->getMessage());
- $exception->setLineNumber($line);
- if(!empty($srcFile))
- $exception->setTemplateFile($srcFile);
- else
- $exception->setTemplateSource($input);
- throw $exception;
- }
-
- /**
- * Preprocesses the template string by including external templates
- * @param string template string
- * @return string expanded template string
- */
- protected function preprocess($input)
- {
- if($n=preg_match_all('/<%include(.*?)%>/',$input,$matches,PREG_SET_ORDER|PREG_OFFSET_CAPTURE))
- {
- for($i=0;$i<$n;++$i)
- {
- $filePath=Prado::getPathOfNamespace(trim($matches[$i][1][0]),TTemplateManager::TEMPLATE_FILE_EXT);
- if($filePath!==null && is_file($filePath))
- $this->_includedFiles[]=$filePath;
- else
- {
- $errorLine=count(explode("\n",substr($input,0,$matches[$i][0][1]+1)));
- $this->handleException(new TConfigurationException('template_include_invalid',trim($matches[$i][1][0])),$errorLine,$input);
- }
- }
- $base=0;
- for($i=0;$i<$n;++$i)
- {
- $ext=file_get_contents($this->_includedFiles[$i]);
- $length=strlen($matches[$i][0][0]);
- $offset=$base+$matches[$i][0][1];
- $this->_includeAtLine[$i]=count(explode("\n",substr($input,0,$offset)));
- $this->_includeLines[$i]=count(explode("\n",$ext));
- $input=substr_replace($input,$ext,$offset,$length);
- $base+=strlen($ext)-$length;
- }
- }
-
- return $input;
- }
-}
-
+<?php
+/**
+ * TTemplateManager and TTemplate class file
+ *
+ * @author Qiang Xue <qiang.xue@gmail.com>
+ * @link http://www.pradosoft.com/
+ * @copyright Copyright &copy; 2005-2012 PradoSoft
+ * @license http://www.pradosoft.com/license/
+ * @version $Id$
+ * @package System.Web.UI
+ */
+
+/**
+ * Includes TOutputCache class file
+ */
+Prado::using('System.Web.UI.WebControls.TOutputCache');
+
+/**
+ * TTemplateManager class
+ *
+ * TTemplateManager manages the loading and parsing of control templates.
+ *
+ * There are two ways of loading a template, either by the associated template
+ * control class name, or the template file name.
+ * The former is via calling {@link getTemplateByClassName}, which tries to
+ * locate the corresponding template file under the directory containing
+ * the class file. The name of the template file is the class name with
+ * the extension '.tpl'. To load a template from a template file path,
+ * call {@link getTemplateByFileName}.
+ *
+ * By default, TTemplateManager is registered with {@link TPageService} as the
+ * template manager module that can be accessed via {@link TPageService::getTemplateManager()}.
+ *
+ * @author Qiang Xue <qiang.xue@gmail.com>
+ * @version $Id$
+ * @package System.Web.UI
+ * @since 3.0
+ */
+class TTemplateManager extends TModule
+{
+ /**
+ * Template file extension
+ */
+ const TEMPLATE_FILE_EXT='.tpl';
+ /**
+ * Prefix of the cache variable name for storing parsed templates
+ */
+ const TEMPLATE_CACHE_PREFIX='prado:template:';
+
+ /**
+ * Initializes the module.
+ * This method is required by IModule and is invoked by application.
+ * It starts output buffer if it is enabled.
+ * @param TXmlElement module configuration
+ */
+ public function init($config)
+ {
+ $this->getService()->setTemplateManager($this);
+ }
+
+ /**
+ * Loads the template corresponding to the specified class name.
+ * @return ITemplate template for the class name, null if template doesn't exist.
+ */
+ public function getTemplateByClassName($className)
+ {
+ $class=new ReflectionClass($className);
+ $tplFile=dirname($class->getFileName()).DIRECTORY_SEPARATOR.$className.self::TEMPLATE_FILE_EXT;
+ return $this->getTemplateByFileName($tplFile);
+ }
+
+ /**
+ * Loads the template from the specified file.
+ * @return ITemplate template parsed from the specified file, null if the file doesn't exist.
+ */
+ public function getTemplateByFileName($fileName)
+ {
+ if(($fileName=$this->getLocalizedTemplate($fileName))!==null)
+ {
+ Prado::trace("Loading template $fileName",'System.Web.UI.TTemplateManager');
+ if(($cache=$this->getApplication()->getCache())===null)
+ return new TTemplate(file_get_contents($fileName),dirname($fileName),$fileName);
+ else
+ {
+ $array=$cache->get(self::TEMPLATE_CACHE_PREFIX.$fileName);
+ if(is_array($array))
+ {
+ list($template,$timestamps)=$array;
+ if($this->getApplication()->getMode()===TApplicationMode::Performance)
+ return $template;
+ $cacheValid=true;
+ foreach($timestamps as $tplFile=>$timestamp)
+ {
+ if(!is_file($tplFile) || filemtime($tplFile)>$timestamp)
+ {
+ $cacheValid=false;
+ break;
+ }
+ }
+ if($cacheValid)
+ return $template;
+ }
+ $template=new TTemplate(file_get_contents($fileName),dirname($fileName),$fileName);
+ $includedFiles=$template->getIncludedFiles();
+ $timestamps=array();
+ $timestamps[$fileName]=filemtime($fileName);
+ foreach($includedFiles as $includedFile)
+ $timestamps[$includedFile]=filemtime($includedFile);
+ $cache->set(self::TEMPLATE_CACHE_PREFIX.$fileName,array($template,$timestamps));
+ return $template;
+ }
+ }
+ else
+ return null;
+ }
+
+ /**
+ * Finds a localized template file.
+ * @param string template file.
+ * @return string|null a localized template file if found, null otherwise.
+ */
+ protected function getLocalizedTemplate($filename)
+ {
+ if(($app=$this->getApplication()->getGlobalization(false))===null)
+ return is_file($filename)?$filename:null;
+ foreach($app->getLocalizedResource($filename) as $file)
+ {
+ if(($file=realpath($file))!==false && is_file($file))
+ return $file;
+ }
+ return null;
+ }
+}
+
+/**
+ * TTemplate implements PRADO template parsing logic.
+ * A TTemplate object represents a parsed PRADO control template.
+ * It can instantiate the template as child controls of a specified control.
+ * The template format is like HTML, with the following special tags introduced,
+ * - component tags: a component tag represents the configuration of a component.
+ * The tag name is in the format of com:ComponentType, where ComponentType is the component
+ * class name. Component tags must be well-formed. Attributes of the component tag
+ * are treated as either property initial values, event handler attachment, or regular
+ * tag attributes.
+ * - property tags: property tags are used to set large block of attribute values.
+ * The property tag name is in the format of <prop:AttributeName> where AttributeName
+ * can be a property name, an event name or a regular tag attribute name.
+ * - group subproperty tags: subproperties of a common property can be configured using
+ * <prop:MainProperty SubProperty1="Value1" SubProperty2="Value2" .../>
+ * - directive: directive specifies the property values for the template owner.
+ * It is in the format of <%@ property name-value pairs %>;
+ * - expressions: They are in the format of <%= PHP expression %> and <%% PHP statements %>
+ * - comments: There are two kinds of comments, regular HTML comments and special template comments.
+ * The former is in the format of <!-- comments -->, which will be treated as text strings.
+ * The latter is in the format of <!-- comments --!>, which will be stripped out.
+ *
+ * Tags other than the above are not required to be well-formed.
+ *
+ * A TTemplate object represents a parsed PRADO template. To instantiate the template
+ * for a particular control, call {@link instantiateIn($control)}, which
+ * will create and intialize all components specified in the template and
+ * set their parent as $control.
+ *
+ * @author Qiang Xue <qiang.xue@gmail.com>
+ * @version $Id$
+ * @package System.Web.UI
+ * @since 3.0
+ */
+class TTemplate extends TApplicationComponent implements ITemplate
+{
+ /**
+ * '<!--.*?--!>' - template comments
+ * '<!--.*?-->' - HTML comments
+ * '<\/?com:([\w\.]+)((?:\s*[\w\.]+\s*=\s*\'.*?\'|\s*[\w\.]+\s*=\s*".*?"|\s*[\w\.]+\s*=\s*<%.*?%>)*)\s*\/?>' - component tags
+ * '<\/?prop:([\w\.]+)\s*>' - property tags
+ * '<%@\s*((?:\s*[\w\.]+\s*=\s*\'.*?\'|\s*[\w\.]+\s*=\s*".*?")*)\s*%>' - directives
+ * '<%[%#~\/\\$=\\[](.*?)%>' - expressions
+ * '<prop:([\w\.]+)((?:\s*[\w\.]+=\'.*?\'|\s*[\w\.]+=".*?"|\s*[\w\.]+=<%.*?%>)*)\s*\/>' - group subproperty tags
+ */
+ const REGEX_RULES='/<!--.*?--!>|<!---.*?--->|<\/?com:([\w\.]+)((?:\s*[\w\.]+\s*=\s*\'.*?\'|\s*[\w\.]+\s*=\s*".*?"|\s*[\w\.]+\s*=\s*<%.*?%>)*)\s*\/?>|<\/?prop:([\w\.]+)\s*>|<%@\s*((?:\s*[\w\.]+\s*=\s*\'.*?\'|\s*[\w\.]+\s*=\s*".*?")*)\s*%>|<%[%#~\/\\$=\\[](.*?)%>|<prop:([\w\.]+)((?:\s*[\w\.]+\s*=\s*\'.*?\'|\s*[\w\.]+\s*=\s*".*?"|\s*[\w\.]+\s*=\s*<%.*?%>)*)\s*\/>/msS';
+
+ /**
+ * Different configurations of component property/event/attribute
+ */
+ const CONFIG_DATABIND=0;
+ const CONFIG_EXPRESSION=1;
+ const CONFIG_ASSET=2;
+ const CONFIG_PARAMETER=3;
+ const CONFIG_LOCALIZATION=4;
+ const CONFIG_TEMPLATE=5;
+
+ /**
+ * @var array list of component tags and strings
+ */
+ private $_tpl=array();
+ /**
+ * @var array list of directive settings
+ */
+ private $_directive=array();
+ /**
+ * @var string context path
+ */
+ private $_contextPath;
+ /**
+ * @var string template file path (if available)
+ */
+ private $_tplFile=null;
+ /**
+ * @var integer the line number that parsing starts from (internal use)
+ */
+ private $_startingLine=0;
+ /**
+ * @var string template content to be parsed
+ */
+ private $_content;
+ /**
+ * @var boolean whether this template is a source template
+ */
+ private $_sourceTemplate=true;
+ /**
+ * @var string hash code of the template
+ */
+ private $_hashCode='';
+ private $_tplControl=null;
+ private $_includedFiles=array();
+ private $_includeAtLine=array();
+ private $_includeLines=array();
+
+
+ /**
+ * Constructor.
+ * The template will be parsed after construction.
+ * @param string the template string
+ * @param string the template context directory
+ * @param string the template file, null if no file
+ * @param integer the line number that parsing starts from (internal use)
+ * @param boolean whether this template is a source template, i.e., this template is loaded from
+ * some external storage rather than from within another template.
+ */
+ public function __construct($template,$contextPath,$tplFile=null,$startingLine=0,$sourceTemplate=true)
+ {
+ $this->_sourceTemplate=$sourceTemplate;
+ $this->_contextPath=$contextPath;
+ $this->_tplFile=$tplFile;
+ $this->_startingLine=$startingLine;
+ $this->_content=$template;
+ $this->_hashCode=md5($template);
+ $this->parse($template);
+ $this->_content=null; // reset to save memory
+ }
+
+ /**
+ * @return string template file path if available, null otherwise.
+ */
+ public function getTemplateFile()
+ {
+ return $this->_tplFile;
+ }
+
+ /**
+ * @return boolean whether this template is a source template, i.e., this template is loaded from
+ * some external storage rather than from within another template.
+ */
+ public function getIsSourceTemplate()
+ {
+ return $this->_sourceTemplate;
+ }
+
+ /**
+ * @return string context directory path
+ */
+ public function getContextPath()
+ {
+ return $this->_contextPath;
+ }
+
+ /**
+ * @return array name-value pairs declared in the directive
+ */
+ public function getDirective()
+ {
+ return $this->_directive;
+ }
+
+ /**
+ * @return string hash code that can be used to identify the template
+ */
+ public function getHashCode()
+ {
+ return $this->_hashCode;
+ }
+
+ /**
+ * @return array the parsed template
+ */
+ public function &getItems()
+ {
+ return $this->_tpl;
+ }
+
+ /**
+ * Instantiates the template.
+ * Content in the template will be instantiated as components and text strings
+ * and passed to the specified parent control.
+ * @param TControl the control who owns the template
+ * @param TControl the control who will become the root parent of the controls on the template. If null, it uses the template control.
+ */
+ public function instantiateIn($tplControl,$parentControl=null)
+ {
+ $this->_tplControl=$tplControl;
+ if($parentControl===null)
+ $parentControl=$tplControl;
+ if(($page=$tplControl->getPage())===null)
+ $page=$this->getService()->getRequestedPage();
+ $controls=array();
+ $directChildren=array();
+ foreach($this->_tpl as $key=>$object)
+ {
+ if($object[0]===-1)
+ $parent=$parentControl;
+ else if(isset($controls[$object[0]]))
+ $parent=$controls[$object[0]];
+ else
+ continue;
+ if(isset($object[2])) // component
+ {
+ $component=Prado::createComponent($object[1]);
+ $properties=&$object[2];
+ if($component instanceof TControl)
+ {
+ if($component instanceof TOutputCache)
+ $component->setCacheKeyPrefix($this->_hashCode.$key);
+ $component->setTemplateControl($tplControl);
+ if(isset($properties['id']))
+ {
+ if(is_array($properties['id']))
+ $properties['id']=$component->evaluateExpression($properties['id'][1]);
+ $tplControl->registerObject($properties['id'],$component);
+ }
+ if(isset($properties['skinid']))
+ {
+ if(is_array($properties['skinid']))
+ $component->setSkinID($component->evaluateExpression($properties['skinid'][1]));
+ else
+ $component->setSkinID($properties['skinid']);
+ unset($properties['skinid']);
+ }
+
+ $component->trackViewState(false);
+
+ $component->applyStyleSheetSkin($page);
+ foreach($properties as $name=>$value)
+ $this->configureControl($component,$name,$value);
+
+ $component->trackViewState(true);
+
+ if($parent===$parentControl)
+ $directChildren[]=$component;
+ else
+ $component->createdOnTemplate($parent);
+ if($component->getAllowChildControls())
+ $controls[$key]=$component;
+ }
+ else if($component instanceof TComponent)
+ {
+ $controls[$key]=$component;
+ if(isset($properties['id']))
+ {
+ if(is_array($properties['id']))
+ $properties['id']=$component->evaluateExpression($properties['id'][1]);
+ $tplControl->registerObject($properties['id'],$component);
+ if(!$component->hasProperty('id'))
+ unset($properties['id']);
+ }
+ foreach($properties as $name=>$value)
+ $this->configureComponent($component,$name,$value);
+ if($parent===$parentControl)
+ $directChildren[]=$component;
+ else
+ $component->createdOnTemplate($parent);
+ }
+ }
+ else
+ {
+ if($object[1] instanceof TCompositeLiteral)
+ {
+ // need to clone a new object because the one in template is reused
+ $o=clone $object[1];
+ $o->setContainer($tplControl);
+ if($parent===$parentControl)
+ $directChildren[]=$o;
+ else
+ $parent->addParsedObject($o);
+ }
+ else
+ {
+ if($parent===$parentControl)
+ $directChildren[]=$object[1];
+ else
+ $parent->addParsedObject($object[1]);
+ }
+ }
+ }
+ // delay setting parent till now because the parent may cause
+ // the child to do lifecycle catchup which may cause problem
+ // if the child needs its own child controls.
+ foreach($directChildren as $control)
+ {
+ if($control instanceof TComponent)
+ $control->createdOnTemplate($parentControl);
+ else
+ $parentControl->addParsedObject($control);
+ }
+ }
+
+ /**
+ * Configures a property/event of a control.
+ * @param TControl control to be configured
+ * @param string property name
+ * @param mixed property initial value
+ */
+ protected function configureControl($control,$name,$value)
+ {
+ if(strncasecmp($name,'on',2)===0) // is an event
+ $this->configureEvent($control,$name,$value,$control);
+ else if(($pos=strrpos($name,'.'))===false) // is a simple property or custom attribute
+ $this->configureProperty($control,$name,$value);
+ else // is a subproperty
+ $this->configureSubProperty($control,$name,$value);
+ }
+
+ /**
+ * Configures a property of a non-control component.
+ * @param TComponent component to be configured
+ * @param string property name
+ * @param mixed property initial value
+ */
+ protected function configureComponent($component,$name,$value)
+ {
+ if(strpos($name,'.')===false) // is a simple property or custom attribute
+ $this->configureProperty($component,$name,$value);
+ else // is a subproperty
+ $this->configureSubProperty($component,$name,$value);
+ }
+
+ /**
+ * Configures an event for a control.
+ * @param TControl control to be configured
+ * @param string event name
+ * @param string event handler
+ * @param TControl context control
+ */
+ protected function configureEvent($control,$name,$value,$contextControl)
+ {
+ if(strpos($value,'.')===false)
+ $control->attachEventHandler($name,array($contextControl,'TemplateControl.'.$value));
+ else
+ $control->attachEventHandler($name,array($contextControl,$value));
+ }
+
+ /**
+ * Configures a simple property for a component.
+ * @param TComponent component to be configured
+ * @param string property name
+ * @param mixed property initial value
+ */
+ protected function configureProperty($component,$name,$value)
+ {
+ if(is_array($value))
+ {
+ switch($value[0])
+ {
+ case self::CONFIG_DATABIND:
+ $component->bindProperty($name,$value[1]);
+ break;
+ case self::CONFIG_EXPRESSION:
+ if($component instanceof TControl)
+ $component->autoBindProperty($name,$value[1]);
+ else
+ {
+ $setter='set'.$name;
+ $component->$setter($this->_tplControl->evaluateExpression($value[1]));
+ }
+ break;
+ case self::CONFIG_TEMPLATE:
+ $setter='set'.$name;
+ $component->$setter($value[1]);
+ break;
+ case self::CONFIG_ASSET: // asset URL
+ $setter='set'.$name;
+ $url=$this->publishFilePath($this->_contextPath.DIRECTORY_SEPARATOR.$value[1]);
+ $component->$setter($url);
+ break;
+ case self::CONFIG_PARAMETER: // application parameter
+ $setter='set'.$name;
+ $component->$setter($this->getApplication()->getParameters()->itemAt($value[1]));
+ break;
+ case self::CONFIG_LOCALIZATION:
+ $setter='set'.$name;
+ $component->$setter(Prado::localize($value[1]));
+ break;
+ default: // an error if reaching here
+ throw new TConfigurationException('template_tag_unexpected',$name,$value[1]);
+ break;
+ }
+ }
+ else
+ {
+ if (substr($name,0,2)=='js')
+ if ($value and !($value instanceof TJavaScriptLiteral))
+ $value = new TJavaScriptLiteral($value);
+ $setter='set'.$name;
+ $component->$setter($value);
+ }
+ }
+
+ /**
+ * Configures a subproperty for a component.
+ * @param TComponent component to be configured
+ * @param string subproperty name
+ * @param mixed subproperty initial value
+ */
+ protected function configureSubProperty($component,$name,$value)
+ {
+ if(is_array($value))
+ {
+ switch($value[0])
+ {
+ case self::CONFIG_DATABIND: // databinding
+ $component->bindProperty($name,$value[1]);
+ break;
+ case self::CONFIG_EXPRESSION: // expression
+ if($component instanceof TControl)
+ $component->autoBindProperty($name,$value[1]);
+ else
+ $component->setSubProperty($name,$this->_tplControl->evaluateExpression($value[1]));
+ break;
+ case self::CONFIG_TEMPLATE:
+ $component->setSubProperty($name,$value[1]);
+ break;
+ case self::CONFIG_ASSET: // asset URL
+ $url=$this->publishFilePath($this->_contextPath.DIRECTORY_SEPARATOR.$value[1]);
+ $component->setSubProperty($name,$url);
+ break;
+ case self::CONFIG_PARAMETER: // application parameter
+ $component->setSubProperty($name,$this->getApplication()->getParameters()->itemAt($value[1]));
+ break;
+ case self::CONFIG_LOCALIZATION:
+ $component->setSubProperty($name,Prado::localize($value[1]));
+ break;
+ default: // an error if reaching here
+ throw new TConfigurationException('template_tag_unexpected',$name,$value[1]);
+ break;
+ }
+ }
+ else
+ $component->setSubProperty($name,$value);
+ }
+
+ /**
+ * Parses a template string.
+ *
+ * This template parser recognizes five types of data:
+ * regular string, well-formed component tags, well-formed property tags, directives, and expressions.
+ *
+ * The parsing result is returned as an array. Each array element can be of three types:
+ * - a string, 0: container index; 1: string content;
+ * - a component tag, 0: container index; 1: component type; 2: attributes (name=>value pairs)
+ * If a directive is found in the template, it will be parsed and can be
+ * retrieved via {@link getDirective}, which returns an array consisting of
+ * name-value pairs in the directive.
+ *
+ * Note, attribute names are treated as case-insensitive and will be turned into lower cases.
+ * Component and directive types are case-sensitive.
+ * Container index is the index to the array element that stores the container object.
+ * If an object has no container, its container index is -1.
+ *
+ * @param string the template string
+ * @throws TConfigurationException if a parsing error is encountered
+ */
+ protected function parse($input)
+ {
+ $input=$this->preprocess($input);
+ $tpl=&$this->_tpl;
+ $n=preg_match_all(self::REGEX_RULES,$input,$matches,PREG_SET_ORDER|PREG_OFFSET_CAPTURE);
+ $expectPropEnd=false;
+ $textStart=0;
+ $stack=array();
+ $container=-1;
+ $matchEnd=0;
+ $c=0;
+ $this->_directive=null;
+ try
+ {
+ for($i=0;$i<$n;++$i)
+ {
+ $match=&$matches[$i];
+ $str=$match[0][0];
+ $matchStart=$match[0][1];
+ $matchEnd=$matchStart+strlen($str)-1;
+ if(strpos($str,'<com:')===0) // opening component tag
+ {
+ if($expectPropEnd)
+ continue;
+ if($matchStart>$textStart)
+ $tpl[$c++]=array($container,substr($input,$textStart,$matchStart-$textStart));
+ $textStart=$matchEnd+1;
+ $type=$match[1][0];
+ $attributes=$this->parseAttributes($match[2][0],$match[2][1]);
+ $this->validateAttributes($type,$attributes);
+ $tpl[$c++]=array($container,$type,$attributes);
+ if($str[strlen($str)-2]!=='/') // open tag
+ {
+ $stack[] = $type;
+ $container=$c-1;
+ }
+ }
+ else if(strpos($str,'</com:')===0) // closing component tag
+ {
+ if($expectPropEnd)
+ continue;
+ if($matchStart>$textStart)
+ $tpl[$c++]=array($container,substr($input,$textStart,$matchStart-$textStart));
+ $textStart=$matchEnd+1;
+ $type=$match[1][0];
+
+ if(empty($stack))
+ throw new TConfigurationException('template_closingtag_unexpected',"</com:$type>");
+
+ $name=array_pop($stack);
+ if($name!==$type)
+ {
+ $tag=$name[0]==='@' ? '</prop:'.substr($name,1).'>' : "</com:$name>";
+ throw new TConfigurationException('template_closingtag_expected',$tag);
+ }
+ $container=$tpl[$container][0];
+ }
+ else if(strpos($str,'<%@')===0) // directive
+ {
+ if($expectPropEnd)
+ continue;
+ if($matchStart>$textStart)
+ $tpl[$c++]=array($container,substr($input,$textStart,$matchStart-$textStart));
+ $textStart=$matchEnd+1;
+ if(isset($tpl[0]) || $this->_directive!==null)
+ throw new TConfigurationException('template_directive_nonunique');
+ $this->_directive=$this->parseAttributes($match[4][0],$match[4][1]);
+ }
+ else if(strpos($str,'<%')===0) // expression
+ {
+ if($expectPropEnd)
+ continue;
+ if($matchStart>$textStart)
+ $tpl[$c++]=array($container,substr($input,$textStart,$matchStart-$textStart));
+ $textStart=$matchEnd+1;
+ $literal=trim($match[5][0]);
+ if($str[2]==='=') // expression
+ $tpl[$c++]=array($container,array(TCompositeLiteral::TYPE_EXPRESSION,$literal));
+ else if($str[2]==='%') // statements
+ $tpl[$c++]=array($container,array(TCompositeLiteral::TYPE_STATEMENTS,$literal));
+ else if($str[2]==='#')
+ $tpl[$c++]=array($container,array(TCompositeLiteral::TYPE_DATABINDING,$literal));
+ else if($str[2]==='$')
+ $tpl[$c++]=array($container,array(TCompositeLiteral::TYPE_EXPRESSION,"\$this->getApplication()->getParameters()->itemAt('$literal')"));
+ else if($str[2]==='~')
+ $tpl[$c++]=array($container,array(TCompositeLiteral::TYPE_EXPRESSION,"\$this->publishFilePath('$this->_contextPath/$literal')"));
+ else if($str[2]==='/')
+ $tpl[$c++]=array($container,array(TCompositeLiteral::TYPE_EXPRESSION,"dirname(\$this->getApplication()->getRequest()->getApplicationUrl()).'/$literal'"));
+ else if($str[2]==='[')
+ {
+ $literal=strtr(trim(substr($literal,0,strlen($literal)-1)),array("'"=>"\'","\\"=>"\\\\"));
+ $tpl[$c++]=array($container,array(TCompositeLiteral::TYPE_EXPRESSION,"Prado::localize('$literal')"));
+ }
+ }
+ else if(strpos($str,'<prop:')===0) // opening property
+ {
+ if(strrpos($str,'/>')===strlen($str)-2) //subproperties
+ {
+ if($expectPropEnd)
+ continue;
+ if($matchStart>$textStart)
+ $tpl[$c++]=array($container,substr($input,$textStart,$matchStart-$textStart));
+ $textStart=$matchEnd+1;
+ $prop=strtolower($match[6][0]);
+ $attrs=$this->parseAttributes($match[7][0],$match[7][1]);
+ $attributes=array();
+ foreach($attrs as $name=>$value)
+ $attributes[$prop.'.'.$name]=$value;
+ $type=$tpl[$container][1];
+ $this->validateAttributes($type,$attributes);
+ foreach($attributes as $name=>$value)
+ {
+ if(isset($tpl[$container][2][$name]))
+ throw new TConfigurationException('template_property_duplicated',$name);
+ $tpl[$container][2][$name]=$value;
+ }
+ }
+ else // regular property
+ {
+ $prop=strtolower($match[3][0]);
+ $stack[] = '@'.$prop;
+ if(!$expectPropEnd)
+ {
+ if($matchStart>$textStart)
+ $tpl[$c++]=array($container,substr($input,$textStart,$matchStart-$textStart));
+ $textStart=$matchEnd+1;
+ $expectPropEnd=true;
+ }
+ }
+ }
+ else if(strpos($str,'</prop:')===0) // closing property
+ {
+ $prop=strtolower($match[3][0]);
+ if(empty($stack))
+ throw new TConfigurationException('template_closingtag_unexpected',"</prop:$prop>");
+ $name=array_pop($stack);
+ if($name!=='@'.$prop)
+ {
+ $tag=$name[0]==='@' ? '</prop:'.substr($name,1).'>' : "</com:$name>";
+ throw new TConfigurationException('template_closingtag_expected',$tag);
+ }
+ if(($last=count($stack))<1 || $stack[$last-1][0]!=='@')
+ {
+ if($matchStart>$textStart)
+ {
+ $value=substr($input,$textStart,$matchStart-$textStart);
+ if(substr($prop,-8,8)==='template')
+ $value=$this->parseTemplateProperty($value,$textStart);
+ else
+ $value=$this->parseAttribute($value);
+ if($container>=0)
+ {
+ $type=$tpl[$container][1];
+ $this->validateAttributes($type,array($prop=>$value));
+ if(isset($tpl[$container][2][$prop]))
+ throw new TConfigurationException('template_property_duplicated',$prop);
+ $tpl[$container][2][$prop]=$value;
+ }
+ else // a property for the template control
+ $this->_directive[$prop]=$value;
+ $textStart=$matchEnd+1;
+ }
+ $expectPropEnd=false;
+ }
+ }
+ else if(strpos($str,'<!--')===0) // comments
+ {
+ if($expectPropEnd)
+ throw new TConfigurationException('template_comments_forbidden');
+ if($matchStart>$textStart)
+ $tpl[$c++]=array($container,substr($input,$textStart,$matchStart-$textStart));
+ $textStart=$matchEnd+1;
+ }
+ else
+ throw new TConfigurationException('template_matching_unexpected',$match);
+ }
+ if(!empty($stack))
+ {
+ $name=array_pop($stack);
+ $tag=$name[0]==='@' ? '</prop:'.substr($name,1).'>' : "</com:$name>";
+ throw new TConfigurationException('template_closingtag_expected',$tag);
+ }
+ if($textStart<strlen($input))
+ $tpl[$c++]=array($container,substr($input,$textStart));
+ }
+ catch(Exception $e)
+ {
+ if(($e instanceof TException) && ($e instanceof TTemplateException))
+ throw $e;
+ if($matchEnd===0)
+ $line=$this->_startingLine+1;
+ else
+ $line=$this->_startingLine+count(explode("\n",substr($input,0,$matchEnd+1)));
+ $this->handleException($e,$line,$input);
+ }
+
+ if($this->_directive===null)
+ $this->_directive=array();
+
+ // optimization by merging consecutive strings, expressions, statements and bindings
+ $objects=array();
+ $parent=null;
+ $merged=array();
+ foreach($tpl as $id=>$object)
+ {
+ if(isset($object[2]) || $object[0]!==$parent)
+ {
+ if($parent!==null)
+ {
+ if(count($merged[1])===1 && is_string($merged[1][0]))
+ $objects[$id-1]=array($merged[0],$merged[1][0]);
+ else
+ $objects[$id-1]=array($merged[0],new TCompositeLiteral($merged[1]));
+ }
+ if(isset($object[2]))
+ {
+ $parent=null;
+ $objects[$id]=$object;
+ }
+ else
+ {
+ $parent=$object[0];
+ $merged=array($parent,array($object[1]));
+ }
+ }
+ else
+ $merged[1][]=$object[1];
+ }
+ if($parent!==null)
+ {
+ if(count($merged[1])===1 && is_string($merged[1][0]))
+ $objects[$id]=array($merged[0],$merged[1][0]);
+ else
+ $objects[$id]=array($merged[0],new TCompositeLiteral($merged[1]));
+ }
+ $tpl=$objects;
+ return $objects;
+ }
+
+ /**
+ * Parses the attributes of a tag from a string.
+ * @param string the string to be parsed.
+ * @return array attribute values indexed by names.
+ */
+ protected function parseAttributes($str,$offset)
+ {
+ if($str==='')
+ return array();
+ $pattern='/([\w\.\-]+)\s*=\s*(\'.*?\'|".*?"|<%.*?%>)/msS';
+ $attributes=array();
+ $n=preg_match_all($pattern,$str,$matches,PREG_SET_ORDER|PREG_OFFSET_CAPTURE);
+ for($i=0;$i<$n;++$i)
+ {
+ $match=&$matches[$i];
+ $name=strtolower($match[1][0]);
+ if(isset($attributes[$name]))
+ throw new TConfigurationException('template_property_duplicated',$name);
+ $value=$match[2][0];
+ if(substr($name,-8,8)==='template')
+ {
+ if($value[0]==='\'' || $value[0]==='"')
+ $attributes[$name]=$this->parseTemplateProperty(substr($value,1,strlen($value)-2),$match[2][1]+1);
+ else
+ $attributes[$name]=$this->parseTemplateProperty($value,$match[2][1]);
+ }
+ else
+ {
+ if($value[0]==='\'' || $value[0]==='"')
+ $attributes[$name]=$this->parseAttribute(substr($value,1,strlen($value)-2));
+ else
+ $attributes[$name]=$this->parseAttribute($value);
+ }
+ }
+ return $attributes;
+ }
+
+ protected function parseTemplateProperty($content,$offset)
+ {
+ $line=$this->_startingLine+count(explode("\n",substr($this->_content,0,$offset)))-1;
+ return array(self::CONFIG_TEMPLATE,new TTemplate($content,$this->_contextPath,$this->_tplFile,$line,false));
+ }
+
+ /**
+ * Parses a single attribute.
+ * @param string the string to be parsed.
+ * @return array attribute initialization
+ */
+ protected function parseAttribute($value)
+ {
+ if(($n=preg_match_all('/<%[#=].*?%>/msS',$value,$matches,PREG_OFFSET_CAPTURE))>0)
+ {
+ $isDataBind=false;
+ $textStart=0;
+ $expr='';
+ for($i=0;$i<$n;++$i)
+ {
+ $match=$matches[0][$i];
+ $token=$match[0];
+ $offset=$match[1];
+ $length=strlen($token);
+ if($token[2]==='#')
+ $isDataBind=true;
+ if($offset>$textStart)
+ $expr.=".'".strtr(substr($value,$textStart,$offset-$textStart),array("'"=>"\\'","\\"=>"\\\\"))."'";
+ $expr.='.('.substr($token,3,$length-5).')';
+ $textStart=$offset+$length;
+ }
+ $length=strlen($value);
+ if($length>$textStart)
+ $expr.=".'".strtr(substr($value,$textStart,$length-$textStart),array("'"=>"\\'","\\"=>"\\\\"))."'";
+ if($isDataBind)
+ return array(self::CONFIG_DATABIND,ltrim($expr,'.'));
+ else
+ return array(self::CONFIG_EXPRESSION,ltrim($expr,'.'));
+ }
+ else if(preg_match('/\\s*(<%~.*?%>|<%\\$.*?%>|<%\\[.*?\\]%>|<%\/.*?%>)\\s*/msS',$value,$matches) && $matches[0]===$value)
+ {
+ $value=$matches[1];
+ if($value[2]==='~')
+ return array(self::CONFIG_ASSET,trim(substr($value,3,strlen($value)-5)));
+ elseif($value[2]==='[')
+ return array(self::CONFIG_LOCALIZATION,trim(substr($value,3,strlen($value)-6)));
+ elseif($value[2]==='$')
+ return array(self::CONFIG_PARAMETER,trim(substr($value,3,strlen($value)-5)));
+ elseif($value[2]==='/') {
+ $literal = trim(substr($value,3,strlen($value)-5));
+ return array(self::CONFIG_EXPRESSION,"dirname(\$this->getApplication()->getRequest()->getApplicationUrl()).'/$literal'");
+ }
+ }
+ else
+ return $value;
+ }
+
+ protected function validateAttributes($type,$attributes)
+ {
+ Prado::using($type);
+ if(($pos=strrpos($type,'.'))!==false)
+ $className=substr($type,$pos+1);
+ else
+ $className=$type;
+ $class=new ReflectionClass($className);
+ if(is_subclass_of($className,'TControl') || $className==='TControl')
+ {
+ foreach($attributes as $name=>$att)
+ {
+ if(($pos=strpos($name,'.'))!==false)
+ {
+ // a subproperty, so the first segment must be readable
+ $subname=substr($name,0,$pos);
+ if(!$class->hasMethod('get'.$subname))
+ throw new TConfigurationException('template_property_unknown',$type,$subname);
+ }
+ else if(strncasecmp($name,'on',2)===0)
+ {
+ // an event
+ if(!$class->hasMethod($name))
+ throw new TConfigurationException('template_event_unknown',$type,$name);
+ else if(!is_string($att))
+ throw new TConfigurationException('template_eventhandler_invalid',$type,$name);
+ }
+ else
+ {
+ // a simple property
+ if (! ($class->hasMethod('set'.$name) || $class->hasMethod('setjs'.$name)) )
+ {
+ if ($class->hasMethod('get'.$name) || $class->hasMethod('getjs'.$name))
+ throw new TConfigurationException('template_property_readonly',$type,$name);
+ else
+ throw new TConfigurationException('template_property_unknown',$type,$name);
+ }
+ else if(is_array($att) && $att[0]!==self::CONFIG_EXPRESSION)
+ {
+ if(strcasecmp($name,'id')===0)
+ throw new TConfigurationException('template_controlid_invalid',$type);
+ else if(strcasecmp($name,'skinid')===0)
+ throw new TConfigurationException('template_controlskinid_invalid',$type);
+ }
+ }
+ }
+ }
+ else if(is_subclass_of($className,'TComponent') || $className==='TComponent')
+ {
+ foreach($attributes as $name=>$att)
+ {
+ if(is_array($att) && ($att[0]===self::CONFIG_DATABIND))
+ throw new TConfigurationException('template_databind_forbidden',$type,$name);
+ if(($pos=strpos($name,'.'))!==false)
+ {
+ // a subproperty, so the first segment must be readable
+ $subname=substr($name,0,$pos);
+ if(!$class->hasMethod('get'.$subname))
+ throw new TConfigurationException('template_property_unknown',$type,$subname);
+ }
+ else if(strncasecmp($name,'on',2)===0)
+ throw new TConfigurationException('template_event_forbidden',$type,$name);
+ else
+ {
+ // id is still alowed for TComponent, even if id property doesn't exist
+ if(strcasecmp($name,'id')!==0 && !$class->hasMethod('set'.$name))
+ {
+ if($class->hasMethod('get'.$name))
+ throw new TConfigurationException('template_property_readonly',$type,$name);
+ else
+ throw new TConfigurationException('template_property_unknown',$type,$name);
+ }
+ }
+ }
+ }
+ else
+ throw new TConfigurationException('template_component_required',$type);
+ }
+
+ /**
+ * @return array list of included external template files
+ */
+ public function getIncludedFiles()
+ {
+ return $this->_includedFiles;
+ }
+
+ /**
+ * Handles template parsing exception.
+ * This method rethrows the exception caught during template parsing.
+ * It adjusts the error location by giving out correct error line number and source file.
+ * @param Exception template exception
+ * @param int line number
+ * @param string template string if no source file is used
+ */
+ protected function handleException($e,$line,$input=null)
+ {
+ $srcFile=$this->_tplFile;
+
+ if(($n=count($this->_includedFiles))>0) // need to adjust error row number and file name
+ {
+ for($i=$n-1;$i>=0;--$i)
+ {
+ if($this->_includeAtLine[$i]<=$line)
+ {
+ if($line<$this->_includeAtLine[$i]+$this->_includeLines[$i])
+ {
+ $line=$line-$this->_includeAtLine[$i]+1;
+ $srcFile=$this->_includedFiles[$i];
+ break;
+ }
+ else
+ $line=$line-$this->_includeLines[$i]+1;
+ }
+ }
+ }
+ $exception=new TTemplateException('template_format_invalid',$e->getMessage());
+ $exception->setLineNumber($line);
+ if(!empty($srcFile))
+ $exception->setTemplateFile($srcFile);
+ else
+ $exception->setTemplateSource($input);
+ throw $exception;
+ }
+
+ /**
+ * Preprocesses the template string by including external templates
+ * @param string template string
+ * @return string expanded template string
+ */
+ protected function preprocess($input)
+ {
+ if($n=preg_match_all('/<%include(.*?)%>/',$input,$matches,PREG_SET_ORDER|PREG_OFFSET_CAPTURE))
+ {
+ for($i=0;$i<$n;++$i)
+ {
+ $filePath=Prado::getPathOfNamespace(trim($matches[$i][1][0]),TTemplateManager::TEMPLATE_FILE_EXT);
+ if($filePath!==null && is_file($filePath))
+ $this->_includedFiles[]=$filePath;
+ else
+ {
+ $errorLine=count(explode("\n",substr($input,0,$matches[$i][0][1]+1)));
+ $this->handleException(new TConfigurationException('template_include_invalid',trim($matches[$i][1][0])),$errorLine,$input);
+ }
+ }
+ $base=0;
+ for($i=0;$i<$n;++$i)
+ {
+ $ext=file_get_contents($this->_includedFiles[$i]);
+ $length=strlen($matches[$i][0][0]);
+ $offset=$base+$matches[$i][0][1];
+ $this->_includeAtLine[$i]=count(explode("\n",substr($input,0,$offset)));
+ $this->_includeLines[$i]=count(explode("\n",$ext));
+ $input=substr_replace($input,$ext,$offset,$length);
+ $base+=strlen($ext)-$length;
+ }
+ }
+
+ return $input;
+ }
+}
+
diff --git a/framework/Web/UI/TThemeManager.php b/framework/Web/UI/TThemeManager.php
index 57ab21ad..0d6befd4 100644
--- a/framework/Web/UI/TThemeManager.php
+++ b/framework/Web/UI/TThemeManager.php
@@ -1,517 +1,517 @@
-<?php
-/**
- * TThemeManager class
- *
- * @author Qiang Xue <qiang.xue@gmail.com>
- * @link http://www.pradosoft.com/
- * @copyright Copyright &copy; 2005-2012 PradoSoft
- * @license http://www.pradosoft.com/license/
- * @version $Id$
- * @package System.Web.UI
- */
-
-Prado::using('System.Web.Services.TPageService');
-
-/**
- * TThemeManager class
- *
- * TThemeManager manages the themes used in a Prado application.
- *
- * Themes are stored under the directory specified by the
- * {@link setBasePath BasePath} property. The themes can be accessed
- * via URL {@link setBaseUrl BaseUrl}. Each theme is represented by a subdirectory
- * and all the files under that directory. The name of a theme is the name
- * of the corresponding subdirectory.
- * By default, the base path of all themes is a directory named "themes"
- * under the directory containing the application entry script.
- * To get a theme (normally you do not need to), call {@link getTheme}.
- *
- * TThemeManager may be configured within page service tag in application
- * configuration file as follows,
- * <module id="themes" class="System.Web.UI.TThemeManager"
- * BasePath="Application.themes" BaseUrl="/themes" />
- * where {@link getCacheExpire CacheExpire}, {@link getCacheControl CacheControl}
- * and {@link getBufferOutput BufferOutput} are configurable properties of THttpResponse.
- *
- * @author Qiang Xue <qiang.xue@gmail.com>
- * @version $Id$
- * @package System.Web.UI
- * @since 3.0
- */
-class TThemeManager extends TModule
-{
- /**
- * default themes base path
- */
- const DEFAULT_BASEPATH='themes';
-
- /**
- * default theme class
- */
- const DEFAULT_THEMECLASS = 'TTheme';
-
- /**
- * @var string
- */
- private $_themeClass=self::DEFAULT_THEMECLASS;
-
- /**
- * @var boolean whether this module has been initialized
- */
- private $_initialized=false;
- /**
- * @var string the directory containing all themes
- */
- private $_basePath=null;
- /**
- * @var string the base URL for all themes
- */
- private $_baseUrl=null;
-
- /**
- * Initializes the module.
- * This method is required by IModule and is invoked by application.
- * @param TXmlElement module configuration
- */
- public function init($config)
- {
- $this->_initialized=true;
- $service=$this->getService();
- if($service instanceof TPageService)
- $service->setThemeManager($this);
- else
- throw new TConfigurationException('thememanager_service_unavailable');
- }
-
- /**
- * @param string name of the theme to be retrieved
- * @return TTheme the theme retrieved
- */
- public function getTheme($name)
- {
- $themePath=$this->getBasePath().DIRECTORY_SEPARATOR.$name;
- $themeUrl=rtrim($this->getBaseUrl(),'/').'/'.$name;
- return Prado::createComponent($this->getThemeClass(), $themePath, $themeUrl);
- }
-
- /**
- * @param string|null $class Theme class name in namespace format
- */
- public function setThemeClass($class) {
- $this->_themeClass = $class===null ? self::DEFAULT_THEMECLASS : (string)$class;
- }
-
- /**
- * @return string Theme class name in namespace format. Defaults to {@link TThemeManager::DEFAULT_THEMECLASS DEFAULT_THEMECLASS}.
- */
- public function getThemeClass() {
- return $this->_themeClass;
- }
-
- /**
- * @return array list of available theme names
- */
- public function getAvailableThemes()
- {
- $themes=array();
- $basePath=$this->getBasePath();
- $folder=@opendir($basePath);
- while($file=@readdir($folder))
- {
- if($file!=='.' && $file!=='..' && $file!=='.svn' && is_dir($basePath.DIRECTORY_SEPARATOR.$file))
- $themes[]=$file;
- }
- closedir($folder);
- return $themes;
- }
-
- /**
- * @return string the base path for all themes. It is returned as an absolute path.
- * @throws TConfigurationException if base path is not set and "themes" directory does not exist.
- */
- public function getBasePath()
- {
- if($this->_basePath===null)
- {
- $this->_basePath=dirname($this->getRequest()->getApplicationFilePath()).DIRECTORY_SEPARATOR.self::DEFAULT_BASEPATH;
- if(($basePath=realpath($this->_basePath))===false || !is_dir($basePath))
- throw new TConfigurationException('thememanager_basepath_invalid2',$this->_basePath);
- $this->_basePath=$basePath;
- }
- return $this->_basePath;
- }
-
- /**
- * @param string the base path for all themes. It must be in the format of a namespace.
- * @throws TInvalidDataValueException if the base path is not a proper namespace.
- */
- public function setBasePath($value)
- {
- if($this->_initialized)
- throw new TInvalidOperationException('thememanager_basepath_unchangeable');
- else
- {
- $this->_basePath=Prado::getPathOfNamespace($value);
- if($this->_basePath===null || !is_dir($this->_basePath))
- throw new TInvalidDataValueException('thememanager_basepath_invalid',$value);
- }
- }
-
- /**
- * @return string the base URL for all themes.
- * @throws TConfigurationException If base URL is not set and a correct one cannot be determined by Prado.
- */
- public function getBaseUrl()
- {
- if($this->_baseUrl===null)
- {
- $appPath=dirname($this->getRequest()->getApplicationFilePath());
- $basePath=$this->getBasePath();
- if(strpos($basePath,$appPath)===false)
- throw new TConfigurationException('thememanager_baseurl_required');
- $appUrl=rtrim(dirname($this->getRequest()->getApplicationUrl()),'/\\');
- $this->_baseUrl=$appUrl.strtr(substr($basePath,strlen($appPath)),'\\','/');
- }
- return $this->_baseUrl;
- }
-
- /**
- * @param string the base URL for all themes.
- */
- public function setBaseUrl($value)
- {
- $this->_baseUrl=rtrim($value,'/');
- }
-}
-
-/**
- * TTheme class
- *
- * TTheme represents a particular theme. It is merely a collection of skins
- * that are applicable to the corresponding controls.
- *
- * Each theme is stored as a directory and files under that directory.
- * The theme name is the directory name. When TTheme is created, the files
- * whose name has the extension ".skin" are parsed and saved as controls skins.
- *
- * A skin is essentially a list of initial property values that are to be applied
- * to a control when the skin is applied.
- * Each type of control can have multiple skins identified by the SkinID.
- * If a skin does not have SkinID, it is the default skin that will be applied
- * to controls that do not specify particular SkinID.
- *
- * Whenever possible, TTheme will try to make use of available cache to save
- * the parsing time.
- *
- * To apply a theme to a particular control, call {@link applySkin}.
- *
- * @author Qiang Xue <qiang.xue@gmail.com>
- * @version $Id$
- * @package System.Web.UI
- * @since 3.0
- */
-class TTheme extends TApplicationComponent implements ITheme
-{
- /**
- * prefix for cache variable name used to store parsed themes
- */
- const THEME_CACHE_PREFIX='prado:theme:';
- /**
- * Extension name of skin files
- */
- const SKIN_FILE_EXT='.skin';
- /**
- * @var string theme path
- */
- private $_themePath;
- /**
- * @var string theme url
- */
- private $_themeUrl;
- /**
- * @var array list of skins for the theme
- */
- private $_skins=null;
- /**
- * @var string theme name
- */
- private $_name='';
- /**
- * @var array list of css files
- */
- private $_cssFiles=array();
- /**
- * @var array list of js files
- */
- private $_jsFiles=array();
-
- /**
- * Constructor.
- * @param string theme path
- * @param string theme URL
- * @throws TConfigurationException if theme path does not exist or any parsing error of the skin files
- */
- public function __construct($themePath,$themeUrl)
- {
- $this->_themeUrl=$themeUrl;
- $this->_themePath=realpath($themePath);
- $this->_name=basename($themePath);
- $cacheValid=false;
- // TODO: the following needs to be cleaned up (Qiang)
- if(($cache=$this->getApplication()->getCache())!==null)
- {
- $array=$cache->get(self::THEME_CACHE_PREFIX.$themePath);
- if(is_array($array))
- {
- list($skins,$cssFiles,$jsFiles,$timestamp)=$array;
- if($this->getApplication()->getMode()!==TApplicationMode::Performance)
- {
- if(($dir=opendir($themePath))===false)
- throw new TIOException('theme_path_inexistent',$themePath);
- $cacheValid=true;
- while(($file=readdir($dir))!==false)
- {
- if($file==='.' || $file==='..')
- continue;
- else if(basename($file,'.css')!==$file)
- $this->_cssFiles[]=$themeUrl.'/'.$file;
- else if(basename($file,'.js')!==$file)
- $this->_jsFiles[]=$themeUrl.'/'.$file;
- else if(basename($file,self::SKIN_FILE_EXT)!==$file && filemtime($themePath.DIRECTORY_SEPARATOR.$file)>$timestamp)
- {
- $cacheValid=false;
- break;
- }
- }
- closedir($dir);
- if($cacheValid)
- $this->_skins=$skins;
- }
- else
- {
- $cacheValid=true;
- $this->_cssFiles=$cssFiles;
- $this->_jsFiles=$jsFiles;
- $this->_skins=$skins;
- }
- }
- }
- if(!$cacheValid)
- {
- $this->_cssFiles=array();
- $this->_jsFiles=array();
- $this->_skins=array();
- if(($dir=opendir($themePath))===false)
- throw new TIOException('theme_path_inexistent',$themePath);
- while(($file=readdir($dir))!==false)
- {
- if($file==='.' || $file==='..')
- continue;
- else if(basename($file,'.css')!==$file)
- $this->_cssFiles[]=$themeUrl.'/'.$file;
- else if(basename($file,'.js')!==$file)
- $this->_jsFiles[]=$themeUrl.'/'.$file;
- else if(basename($file,self::SKIN_FILE_EXT)!==$file)
- {
- $template=new TTemplate(file_get_contents($themePath.'/'.$file),$themePath,$themePath.'/'.$file);
- foreach($template->getItems() as $skin)
- {
- if(!isset($skin[2])) // a text string, ignored
- continue;
- else if($skin[0]!==-1)
- throw new TConfigurationException('theme_control_nested',$skin[1],dirname($themePath));
- $type=$skin[1];
- $id=isset($skin[2]['skinid'])?$skin[2]['skinid']:0;
- unset($skin[2]['skinid']);
- if(isset($this->_skins[$type][$id]))
- throw new TConfigurationException('theme_skinid_duplicated',$type,$id,dirname($themePath));
- /*
- foreach($skin[2] as $name=>$value)
- {
- if(is_array($value) && ($value[0]===TTemplate::CONFIG_DATABIND || $value[0]===TTemplate::CONFIG_PARAMETER))
- throw new TConfigurationException('theme_databind_forbidden',dirname($themePath),$type,$id);
- }
- */
- $this->_skins[$type][$id]=$skin[2];
- }
- }
- }
- closedir($dir);
- sort($this->_cssFiles);
- sort($this->_jsFiles);
- if($cache!==null)
- $cache->set(self::THEME_CACHE_PREFIX.$themePath,array($this->_skins,$this->_cssFiles,$this->_jsFiles,time()));
- }
- }
-
- /**
- * @return string theme name
- */
- public function getName()
- {
- return $this->_name;
- }
-
- /**
- * @param string theme name
- */
- protected function setName($value)
- {
- $this->_name = $value;
- }
-
- /**
- * @return string the URL to the theme folder (without ending slash)
- */
- public function getBaseUrl()
- {
- return $this->_themeUrl;
- }
-
- /**
- * @param string the URL to the theme folder
- */
- protected function setBaseUrl($value)
- {
- $this->_themeUrl=rtrim($value,'/');
- }
-
- /**
- * @return string the file path to the theme folder
- */
- public function getBasePath()
- {
- return $this->_themePath;
- }
-
- /**
- * @param string tthe file path to the theme folder
- */
- protected function setBasePath($value)
- {
- $this->_themePath=$value;
- }
-
- /**
- * @return array list of skins for the theme
- */
- public function getSkins()
- {
- return $this->_skins;
- }
-
- /**
- * @param array list of skins for the theme
- */
- protected function setSkins($value)
- {
- $this->_skins = $value;
- }
-
- /**
- * Applies the theme to a particular control.
- * The control's class name and SkinID value will be used to
- * identify which skin to be applied. If the control's SkinID is empty,
- * the default skin will be applied.
- * @param TControl the control to be applied with a skin
- * @return boolean if a skin is successfully applied
- * @throws TConfigurationException if any error happened during the skin application
- */
- public function applySkin($control)
- {
- $type=get_class($control);
- if(($id=$control->getSkinID())==='')
- $id=0;
- if(isset($this->_skins[$type][$id]))
- {
- foreach($this->_skins[$type][$id] as $name=>$value)
- {
- Prado::trace("Applying skin $name to $type",'System.Web.UI.TThemeManager');
- if(is_array($value))
- {
- switch($value[0])
- {
- case TTemplate::CONFIG_EXPRESSION:
- $value=$this->evaluateExpression($value[1]);
- break;
- case TTemplate::CONFIG_ASSET:
- $value=$this->_themeUrl.'/'.ltrim($value[1],'/');
- break;
- case TTemplate::CONFIG_DATABIND:
- $control->bindProperty($name,$value[1]);
- break;
- case TTemplate::CONFIG_PARAMETER:
- $control->setSubProperty($name,$this->getApplication()->getParameters()->itemAt($value[1]));
- break;
- case TTemplate::CONFIG_TEMPLATE:
- $control->setSubProperty($name,$value[1]);
- break;
- case TTemplate::CONFIG_LOCALIZATION:
- $control->setSubProperty($name,Prado::localize($value[1]));
- break;
- default:
- throw new TConfigurationException('theme_tag_unexpected',$name,$value[0]);
- break;
- }
- }
- if(!is_array($value))
- {
- if(strpos($name,'.')===false) // is simple property or custom attribute
- {
- if($control->hasProperty($name))
- {
- if($control->canSetProperty($name))
- {
- $setter='set'.$name;
- $control->$setter($value);
- }
- else
- throw new TConfigurationException('theme_property_readonly',$type,$name);
- }
- else
- throw new TConfigurationException('theme_property_undefined',$type,$name);
- }
- else // complex property
- $control->setSubProperty($name,$value);
- }
- }
- return true;
- }
- else
- return false;
- }
-
- /**
- * @return array list of CSS files (URL) in the theme
- */
- public function getStyleSheetFiles()
- {
- return $this->_cssFiles;
- }
-
- /**
- * @param array list of CSS files (URL) in the theme
- */
- protected function setStyleSheetFiles($value)
- {
- $this->_cssFiles=$value;
- }
-
- /**
- * @return array list of Javascript files (URL) in the theme
- */
- public function getJavaScriptFiles()
- {
- return $this->_jsFiles;
- }
-
- /**
- * @param array list of Javascript files (URL) in the theme
- */
- protected function setJavaScriptFiles($value)
- {
- $this->_jsFiles=$value;
- }
-}
-
-?>
+<?php
+/**
+ * TThemeManager class
+ *
+ * @author Qiang Xue <qiang.xue@gmail.com>
+ * @link http://www.pradosoft.com/
+ * @copyright Copyright &copy; 2005-2012 PradoSoft
+ * @license http://www.pradosoft.com/license/
+ * @version $Id$
+ * @package System.Web.UI
+ */
+
+Prado::using('System.Web.Services.TPageService');
+
+/**
+ * TThemeManager class
+ *
+ * TThemeManager manages the themes used in a Prado application.
+ *
+ * Themes are stored under the directory specified by the
+ * {@link setBasePath BasePath} property. The themes can be accessed
+ * via URL {@link setBaseUrl BaseUrl}. Each theme is represented by a subdirectory
+ * and all the files under that directory. The name of a theme is the name
+ * of the corresponding subdirectory.
+ * By default, the base path of all themes is a directory named "themes"
+ * under the directory containing the application entry script.
+ * To get a theme (normally you do not need to), call {@link getTheme}.
+ *
+ * TThemeManager may be configured within page service tag in application
+ * configuration file as follows,
+ * <module id="themes" class="System.Web.UI.TThemeManager"
+ * BasePath="Application.themes" BaseUrl="/themes" />
+ * where {@link getCacheExpire CacheExpire}, {@link getCacheControl CacheControl}
+ * and {@link getBufferOutput BufferOutput} are configurable properties of THttpResponse.
+ *
+ * @author Qiang Xue <qiang.xue@gmail.com>
+ * @version $Id$
+ * @package System.Web.UI
+ * @since 3.0
+ */
+class TThemeManager extends TModule
+{
+ /**
+ * default themes base path
+ */
+ const DEFAULT_BASEPATH='themes';
+
+ /**
+ * default theme class
+ */
+ const DEFAULT_THEMECLASS = 'TTheme';
+
+ /**
+ * @var string
+ */
+ private $_themeClass=self::DEFAULT_THEMECLASS;
+
+ /**
+ * @var boolean whether this module has been initialized
+ */
+ private $_initialized=false;
+ /**
+ * @var string the directory containing all themes
+ */
+ private $_basePath=null;
+ /**
+ * @var string the base URL for all themes
+ */
+ private $_baseUrl=null;
+
+ /**
+ * Initializes the module.
+ * This method is required by IModule and is invoked by application.
+ * @param TXmlElement module configuration
+ */
+ public function init($config)
+ {
+ $this->_initialized=true;
+ $service=$this->getService();
+ if($service instanceof TPageService)
+ $service->setThemeManager($this);
+ else
+ throw new TConfigurationException('thememanager_service_unavailable');
+ }
+
+ /**
+ * @param string name of the theme to be retrieved
+ * @return TTheme the theme retrieved
+ */
+ public function getTheme($name)
+ {
+ $themePath=$this->getBasePath().DIRECTORY_SEPARATOR.$name;
+ $themeUrl=rtrim($this->getBaseUrl(),'/').'/'.$name;
+ return Prado::createComponent($this->getThemeClass(), $themePath, $themeUrl);
+ }
+
+ /**
+ * @param string|null $class Theme class name in namespace format
+ */
+ public function setThemeClass($class) {
+ $this->_themeClass = $class===null ? self::DEFAULT_THEMECLASS : (string)$class;
+ }
+
+ /**
+ * @return string Theme class name in namespace format. Defaults to {@link TThemeManager::DEFAULT_THEMECLASS DEFAULT_THEMECLASS}.
+ */
+ public function getThemeClass() {
+ return $this->_themeClass;
+ }
+
+ /**
+ * @return array list of available theme names
+ */
+ public function getAvailableThemes()
+ {
+ $themes=array();
+ $basePath=$this->getBasePath();
+ $folder=@opendir($basePath);
+ while($file=@readdir($folder))
+ {
+ if($file!=='.' && $file!=='..' && $file!=='.svn' && is_dir($basePath.DIRECTORY_SEPARATOR.$file))
+ $themes[]=$file;
+ }
+ closedir($folder);
+ return $themes;
+ }
+
+ /**
+ * @return string the base path for all themes. It is returned as an absolute path.
+ * @throws TConfigurationException if base path is not set and "themes" directory does not exist.
+ */
+ public function getBasePath()
+ {
+ if($this->_basePath===null)
+ {
+ $this->_basePath=dirname($this->getRequest()->getApplicationFilePath()).DIRECTORY_SEPARATOR.self::DEFAULT_BASEPATH;
+ if(($basePath=realpath($this->_basePath))===false || !is_dir($basePath))
+ throw new TConfigurationException('thememanager_basepath_invalid2',$this->_basePath);
+ $this->_basePath=$basePath;
+ }
+ return $this->_basePath;
+ }
+
+ /**
+ * @param string the base path for all themes. It must be in the format of a namespace.
+ * @throws TInvalidDataValueException if the base path is not a proper namespace.
+ */
+ public function setBasePath($value)
+ {
+ if($this->_initialized)
+ throw new TInvalidOperationException('thememanager_basepath_unchangeable');
+ else
+ {
+ $this->_basePath=Prado::getPathOfNamespace($value);
+ if($this->_basePath===null || !is_dir($this->_basePath))
+ throw new TInvalidDataValueException('thememanager_basepath_invalid',$value);
+ }
+ }
+
+ /**
+ * @return string the base URL for all themes.
+ * @throws TConfigurationException If base URL is not set and a correct one cannot be determined by Prado.
+ */
+ public function getBaseUrl()
+ {
+ if($this->_baseUrl===null)
+ {
+ $appPath=dirname($this->getRequest()->getApplicationFilePath());
+ $basePath=$this->getBasePath();
+ if(strpos($basePath,$appPath)===false)
+ throw new TConfigurationException('thememanager_baseurl_required');
+ $appUrl=rtrim(dirname($this->getRequest()->getApplicationUrl()),'/\\');
+ $this->_baseUrl=$appUrl.strtr(substr($basePath,strlen($appPath)),'\\','/');
+ }
+ return $this->_baseUrl;
+ }
+
+ /**
+ * @param string the base URL for all themes.
+ */
+ public function setBaseUrl($value)
+ {
+ $this->_baseUrl=rtrim($value,'/');
+ }
+}
+
+/**
+ * TTheme class
+ *
+ * TTheme represents a particular theme. It is merely a collection of skins
+ * that are applicable to the corresponding controls.
+ *
+ * Each theme is stored as a directory and files under that directory.
+ * The theme name is the directory name. When TTheme is created, the files
+ * whose name has the extension ".skin" are parsed and saved as controls skins.
+ *
+ * A skin is essentially a list of initial property values that are to be applied
+ * to a control when the skin is applied.
+ * Each type of control can have multiple skins identified by the SkinID.
+ * If a skin does not have SkinID, it is the default skin that will be applied
+ * to controls that do not specify particular SkinID.
+ *
+ * Whenever possible, TTheme will try to make use of available cache to save
+ * the parsing time.
+ *
+ * To apply a theme to a particular control, call {@link applySkin}.
+ *
+ * @author Qiang Xue <qiang.xue@gmail.com>
+ * @version $Id$
+ * @package System.Web.UI
+ * @since 3.0
+ */
+class TTheme extends TApplicationComponent implements ITheme
+{
+ /**
+ * prefix for cache variable name used to store parsed themes
+ */
+ const THEME_CACHE_PREFIX='prado:theme:';
+ /**
+ * Extension name of skin files
+ */
+ const SKIN_FILE_EXT='.skin';
+ /**
+ * @var string theme path
+ */
+ private $_themePath;
+ /**
+ * @var string theme url
+ */
+ private $_themeUrl;
+ /**
+ * @var array list of skins for the theme
+ */
+ private $_skins=null;
+ /**
+ * @var string theme name
+ */
+ private $_name='';
+ /**
+ * @var array list of css files
+ */
+ private $_cssFiles=array();
+ /**
+ * @var array list of js files
+ */
+ private $_jsFiles=array();
+
+ /**
+ * Constructor.
+ * @param string theme path
+ * @param string theme URL
+ * @throws TConfigurationException if theme path does not exist or any parsing error of the skin files
+ */
+ public function __construct($themePath,$themeUrl)
+ {
+ $this->_themeUrl=$themeUrl;
+ $this->_themePath=realpath($themePath);
+ $this->_name=basename($themePath);
+ $cacheValid=false;
+ // TODO: the following needs to be cleaned up (Qiang)
+ if(($cache=$this->getApplication()->getCache())!==null)
+ {
+ $array=$cache->get(self::THEME_CACHE_PREFIX.$themePath);
+ if(is_array($array))
+ {
+ list($skins,$cssFiles,$jsFiles,$timestamp)=$array;
+ if($this->getApplication()->getMode()!==TApplicationMode::Performance)
+ {
+ if(($dir=opendir($themePath))===false)
+ throw new TIOException('theme_path_inexistent',$themePath);
+ $cacheValid=true;
+ while(($file=readdir($dir))!==false)
+ {
+ if($file==='.' || $file==='..')
+ continue;
+ else if(basename($file,'.css')!==$file)
+ $this->_cssFiles[]=$themeUrl.'/'.$file;
+ else if(basename($file,'.js')!==$file)
+ $this->_jsFiles[]=$themeUrl.'/'.$file;
+ else if(basename($file,self::SKIN_FILE_EXT)!==$file && filemtime($themePath.DIRECTORY_SEPARATOR.$file)>$timestamp)
+ {
+ $cacheValid=false;
+ break;
+ }
+ }
+ closedir($dir);
+ if($cacheValid)
+ $this->_skins=$skins;
+ }
+ else
+ {
+ $cacheValid=true;
+ $this->_cssFiles=$cssFiles;
+ $this->_jsFiles=$jsFiles;
+ $this->_skins=$skins;
+ }
+ }
+ }
+ if(!$cacheValid)
+ {
+ $this->_cssFiles=array();
+ $this->_jsFiles=array();
+ $this->_skins=array();
+ if(($dir=opendir($themePath))===false)
+ throw new TIOException('theme_path_inexistent',$themePath);
+ while(($file=readdir($dir))!==false)
+ {
+ if($file==='.' || $file==='..')
+ continue;
+ else if(basename($file,'.css')!==$file)
+ $this->_cssFiles[]=$themeUrl.'/'.$file;
+ else if(basename($file,'.js')!==$file)
+ $this->_jsFiles[]=$themeUrl.'/'.$file;
+ else if(basename($file,self::SKIN_FILE_EXT)!==$file)
+ {
+ $template=new TTemplate(file_get_contents($themePath.'/'.$file),$themePath,$themePath.'/'.$file);
+ foreach($template->getItems() as $skin)
+ {
+ if(!isset($skin[2])) // a text string, ignored
+ continue;
+ else if($skin[0]!==-1)
+ throw new TConfigurationException('theme_control_nested',$skin[1],dirname($themePath));
+ $type=$skin[1];
+ $id=isset($skin[2]['skinid'])?$skin[2]['skinid']:0;
+ unset($skin[2]['skinid']);
+ if(isset($this->_skins[$type][$id]))
+ throw new TConfigurationException('theme_skinid_duplicated',$type,$id,dirname($themePath));
+ /*
+ foreach($skin[2] as $name=>$value)
+ {
+ if(is_array($value) && ($value[0]===TTemplate::CONFIG_DATABIND || $value[0]===TTemplate::CONFIG_PARAMETER))
+ throw new TConfigurationException('theme_databind_forbidden',dirname($themePath),$type,$id);
+ }
+ */
+ $this->_skins[$type][$id]=$skin[2];
+ }
+ }
+ }
+ closedir($dir);
+ sort($this->_cssFiles);
+ sort($this->_jsFiles);
+ if($cache!==null)
+ $cache->set(self::THEME_CACHE_PREFIX.$themePath,array($this->_skins,$this->_cssFiles,$this->_jsFiles,time()));
+ }
+ }
+
+ /**
+ * @return string theme name
+ */
+ public function getName()
+ {
+ return $this->_name;
+ }
+
+ /**
+ * @param string theme name
+ */
+ protected function setName($value)
+ {
+ $this->_name = $value;
+ }
+
+ /**
+ * @return string the URL to the theme folder (without ending slash)
+ */
+ public function getBaseUrl()
+ {
+ return $this->_themeUrl;
+ }
+
+ /**
+ * @param string the URL to the theme folder
+ */
+ protected function setBaseUrl($value)
+ {
+ $this->_themeUrl=rtrim($value,'/');
+ }
+
+ /**
+ * @return string the file path to the theme folder
+ */
+ public function getBasePath()
+ {
+ return $this->_themePath;
+ }
+
+ /**
+ * @param string tthe file path to the theme folder
+ */
+ protected function setBasePath($value)
+ {
+ $this->_themePath=$value;
+ }
+
+ /**
+ * @return array list of skins for the theme
+ */
+ public function getSkins()
+ {
+ return $this->_skins;
+ }
+
+ /**
+ * @param array list of skins for the theme
+ */
+ protected function setSkins($value)
+ {
+ $this->_skins = $value;
+ }
+
+ /**
+ * Applies the theme to a particular control.
+ * The control's class name and SkinID value will be used to
+ * identify which skin to be applied. If the control's SkinID is empty,
+ * the default skin will be applied.
+ * @param TControl the control to be applied with a skin
+ * @return boolean if a skin is successfully applied
+ * @throws TConfigurationException if any error happened during the skin application
+ */
+ public function applySkin($control)
+ {
+ $type=get_class($control);
+ if(($id=$control->getSkinID())==='')
+ $id=0;
+ if(isset($this->_skins[$type][$id]))
+ {
+ foreach($this->_skins[$type][$id] as $name=>$value)
+ {
+ Prado::trace("Applying skin $name to $type",'System.Web.UI.TThemeManager');
+ if(is_array($value))
+ {
+ switch($value[0])
+ {
+ case TTemplate::CONFIG_EXPRESSION:
+ $value=$this->evaluateExpression($value[1]);
+ break;
+ case TTemplate::CONFIG_ASSET:
+ $value=$this->_themeUrl.'/'.ltrim($value[1],'/');
+ break;
+ case TTemplate::CONFIG_DATABIND:
+ $control->bindProperty($name,$value[1]);
+ break;
+ case TTemplate::CONFIG_PARAMETER:
+ $control->setSubProperty($name,$this->getApplication()->getParameters()->itemAt($value[1]));
+ break;
+ case TTemplate::CONFIG_TEMPLATE:
+ $control->setSubProperty($name,$value[1]);
+ break;
+ case TTemplate::CONFIG_LOCALIZATION:
+ $control->setSubProperty($name,Prado::localize($value[1]));
+ break;
+ default:
+ throw new TConfigurationException('theme_tag_unexpected',$name,$value[0]);
+ break;
+ }
+ }
+ if(!is_array($value))
+ {
+ if(strpos($name,'.')===false) // is simple property or custom attribute
+ {
+ if($control->hasProperty($name))
+ {
+ if($control->canSetProperty($name))
+ {
+ $setter='set'.$name;
+ $control->$setter($value);
+ }
+ else
+ throw new TConfigurationException('theme_property_readonly',$type,$name);
+ }
+ else
+ throw new TConfigurationException('theme_property_undefined',$type,$name);
+ }
+ else // complex property
+ $control->setSubProperty($name,$value);
+ }
+ }
+ return true;
+ }
+ else
+ return false;
+ }
+
+ /**
+ * @return array list of CSS files (URL) in the theme
+ */
+ public function getStyleSheetFiles()
+ {
+ return $this->_cssFiles;
+ }
+
+ /**
+ * @param array list of CSS files (URL) in the theme
+ */
+ protected function setStyleSheetFiles($value)
+ {
+ $this->_cssFiles=$value;
+ }
+
+ /**
+ * @return array list of Javascript files (URL) in the theme
+ */
+ public function getJavaScriptFiles()
+ {
+ return $this->_jsFiles;
+ }
+
+ /**
+ * @param array list of Javascript files (URL) in the theme
+ */
+ protected function setJavaScriptFiles($value)
+ {
+ $this->_jsFiles=$value;
+ }
+}
+
+?>
diff --git a/framework/Web/UI/WebControls/TAccordion.php b/framework/Web/UI/WebControls/TAccordion.php
index 22ff6b71..bfe3451d 100644
--- a/framework/Web/UI/WebControls/TAccordion.php
+++ b/framework/Web/UI/WebControls/TAccordion.php
@@ -1,744 +1,744 @@
-<?php
-/**
- * TAccordion class file.
- *
- * @author Gabor Berczi, DevWorx Hungary <gabor.berczi@devworx.hu>
- * @link http://www.pradosoft.com/
- * @copyright Copyright &copy; 2005-2012 PradoSoft
- * @license http://www.pradosoft.com/license/
- * @version $Id: TAccordion.php 2915 2011-05-15 16:26:11Z ctrlaltca@gmail.com $
- * @package System.Web.UI.WebControls
- * @since 3.2
- */
-
-/**
- * Class TAccordion.
- *
- * TAccordion displays an accordion control. Users can click on the view headers to switch among
- * different accordion views. Each accordion view is an independent panel that can contain arbitrary content.
- *
- * A TAccordion control consists of one or several {@link TAccordionView} controls representing the possible
- * accordion views. At any time, only one accordion view is visible (active), which is specified by any of
- * the following properties:
- * - {@link setActiveViewIndex ActiveViewIndex} - the zero-based integer index of the view in the view collection.
- * - {@link setActiveViewID ActiveViewID} - the text ID of the visible view.
- * - {@link setActiveView ActiveView} - the visible view instance.
- * If both {@link setActiveViewIndex ActiveViewIndex} and {@link setActiveViewID ActiveViewID}
- * are set, the latter takes precedence.
- *
- * TAccordion uses CSS to specify the appearance of the accordion headers and panel. By default,
- * an embedded CSS file will be published which contains the default CSS for TTabPanel.
- * You may also use your own CSS file by specifying the {@link setCssUrl CssUrl} property.
- * The following properties specify the CSS classes used for elements in a TAccordion:
- * - {@link setCssClass CssClass} - the CSS class name for the outer-most div element (defaults to 'accordion');
- * - {@link setHeaderCssClass HeaderCssClass} - the CSS class name for nonactive accordion div elements (defaults to 'accordion-header');
- * - {@link setActiveHeaderCssClass ActiveHeaderCssClass} - the CSS class name for the active accordion div element (defaults to 'accordion-header-active');
- * - {@link setViewCssClass ViewCssClass} - the CSS class for the div element enclosing view content (defaults to 'accordion-view');
- *
- * When the user clicks on a view header, the switch between the old visible view and the clicked one is animated.
- * You can use the {@link setAnimationDuration AnimationDuration} property to set the animation length in seconds;
- * it defaults to 1 second, and when set to 0 it will produce an immediate switch with no animation.
- *
- * The TAccordion auto-sizes itself to the largest of all views, so it can encompass all of them without scrolling.
- * If you want to specify a fixed height (in pixels), use the {@link setViewHeight ViewHeight} property.
- * When a TAccordion is nested inside another, it's adviced to manually specify a {@link setViewHeight ViewHeight} for the internal TAccordion
- *
- * To use TAccordion, write a template like following:
- * <code>
- * <com:TAccordion>
- * <com:TAccordionView Caption="View 1">
- * content for view 1
- * </com:TAccordionView>
- * <com:TAccordionView Caption="View 2">
- * content for view 2
- * </com:TAccordionView>
- * <com:TAccordionView Caption="View 3">
- * content for view 3
- * </com:TAccordionView>
- * </com:TAccordion>
- * </code>
- *
- * @author Gabor Berczi, DevWorx Hungary <gabor.berczi@devworx.hu>
- * @version $Id: TAccordion.php 2915 2011-05-15 16:26:11Z ctrlaltca@gmail.com $
- * @package System.Web.UI.WebControls
- * @since 3.2
- */
-
-class TAccordion extends TWebControl implements IPostBackDataHandler
-{
- private $_dataChanged=false;
-
- /**
- * @return string tag name for the control
- */
- protected function getTagName()
- {
- return 'div';
- }
-
- /**
- * Adds object parsed from template to the control.
- * This method adds only {@link TAccordionView} objects into the {@link getViews Views} collection.
- * All other objects are ignored.
- * @param mixed object parsed from template
- */
- public function addParsedObject($object)
- {
- if($object instanceof TAccordionView)
- $this->getControls()->add($object);
- }
-
- /**
- * Returns the index of the active accordion view.
- * Note, this property may not return the correct index.
- * To ensure the correctness, call {@link getActiveView()} first.
- * @return integer the zero-based index of the active accordion view. If -1, it means no active accordion view. Default is 0 (the first view is active).
- */
- public function getActiveViewIndex()
- {
- return $this->getViewState('ActiveViewIndex',0);
- }
-
- /**
- * @param integer the zero-based index of the current view in the view collection. -1 if no active view.
- * @throws TInvalidDataValueException if the view index is invalid
- */
- public function setActiveViewIndex($value)
- {
- $this->setViewState('ActiveViewIndex',TPropertyValue::ensureInteger($value),0);
- }
-
- /**
- * Returns the ID of the active accordion view.
- * Note, this property may not return the correct ID.
- * To ensure the correctness, call {@link getActiveView()} first.
- * @return string The ID of the active accordion view. Defaults to '', meaning not set.
- */
- public function getActiveViewID()
- {
- return $this->getViewState('ActiveViewID','');
- }
-
- /**
- * @param string The ID of the active accordion view.
- */
- public function setActiveViewID($value)
- {
- $this->setViewState('ActiveViewID',$value,'');
- }
-
- /**
- * Returns the currently active view.
- * This method will examin the ActiveViewID, ActiveViewIndex and Views collection to
- * determine which view is currently active. It will update ActiveViewID and ActiveViewIndex accordingly.
- * @return TAccordionView the currently active view, null if no active view
- * @throws TInvalidDataValueException if the active view ID or index set previously is invalid
- */
- public function getActiveView()
- {
- $activeView=null;
- $views=$this->getViews();
- if(($id=$this->getActiveViewID())!=='')
- {
- if(($index=$views->findIndexByID($id))>=0)
- $activeView=$views->itemAt($index);
- else
- throw new TInvalidDataValueException('tabpanel_activeviewid_invalid',$id);
- }
- else if(($index=$this->getActiveViewIndex())>=0)
- {
- if($index<$views->getCount())
- $activeView=$views->itemAt($index);
- else
- throw new TInvalidDataValueException('tabpanel_activeviewindex_invalid',$index);
- }
- else
- {
- foreach($views as $index=>$view)
- {
- if($view->getActive())
- {
- $activeView=$view;
- break;
- }
- }
- }
- if($activeView!==null)
- $this->activateView($activeView);
- return $activeView;
- }
-
- /**
- * @param TAccordionView the view to be activated
- * @throws TInvalidOperationException if the view is not in the view collection
- */
- public function setActiveView($view)
- {
- if($this->getViews()->indexOf($view)>=0)
- $this->activateView($view);
- else
- throw new TInvalidOperationException('tabpanel_view_inexistent');
- }
-
- /**
- * @return string URL for the CSS file including all relevant CSS class definitions. Defaults to ''.
- */
- public function getCssUrl()
- {
- return $this->getViewState('CssUrl','default');
- }
-
- /**
- * @param string URL for the CSS file including all relevant CSS class definitions.
- */
- public function setCssUrl($value)
- {
- $this->setViewState('CssUrl',TPropertyValue::ensureString($value),'');
- }
-
- /**
- * @return string CSS class for the whole accordion control div.
- */
- public function getCssClass()
- {
- $cssClass=parent::getCssClass();
- return $cssClass===''?'accordion':$cssClass;
- }
-
- /**
- * @return string CSS class for the currently displayed view div. Defaults to 'accordion-view'.
- */
- public function getViewCssClass()
- {
- return $this->getViewStyle()->getCssClass();
- }
-
- /**
- * @param string CSS class for the currently displayed view div.
- */
- public function setViewCssClass($value)
- {
- $this->getViewStyle()->setCssClass($value);
- }
-
- /**
- * @return string CSS class for the currently displayed view div. Defaults to 'accordion-view'.
- */
- public function getAnimationDuration()
- {
- return $this->getViewState('AnimationDuration','1');
- }
-
- /**
- * @param string CSS class for the currently displayed view div.
- */
- public function setAnimationDuration($value)
- {
- $this->setViewState('AnimationDuration',$value);
- }
-
- /**
- * @return TStyle the style for all the view div
- */
- public function getViewStyle()
- {
- if(($style=$this->getViewState('ViewStyle',null))===null)
- {
- $style=new TStyle;
- $style->setCssClass('accordion-view');
- $this->setViewState('ViewStyle',$style,null);
- }
- return $style;
- }
-
- /**
- * @return string CSS class for view headers. Defaults to 'accordion-header'.
- */
- public function getHeaderCssClass()
- {
- return $this->getHeaderStyle()->getCssClass();
- }
-
- /**
- * @param string CSS class for view headers.
- */
- public function setHeaderCssClass($value)
- {
- $this->getHeaderStyle()->setCssClass($value);
- }
-
- /**
- * @return TStyle the style for all the inactive header div
- */
- public function getHeaderStyle()
- {
- if(($style=$this->getViewState('HeaderStyle',null))===null)
- {
- $style=new TStyle;
- $style->setCssClass('accordion-header');
- $this->setViewState('HeaderStyle',$style,null);
- }
- return $style;
- }
-
- /**
- * @return string Extra CSS class for the active header. Defaults to 'accordion-header-active'.
- */
- public function getActiveHeaderCssClass()
- {
- return $this->getActiveHeaderStyle()->getCssClass();
- }
-
- /**
- * @param string Extra CSS class for the active header. Will be added to the normal header specified by HeaderCssClass.
- */
- public function setActiveHeaderCssClass($value)
- {
- $this->getActiveHeaderStyle()->setCssClass($value);
- }
-
- /**
- * @return TStyle the style for the active header div
- */
- public function getActiveHeaderStyle()
- {
- if(($style=$this->getViewState('ActiveHeaderStyle',null))===null)
- {
- $style=new TStyle;
- $style->setCssClass('accordion-header-active');
- $this->setViewState('ActiveHeaderStyle',$style,null);
- }
- return $style;
- }
-
- /**
- * @return integer Maximum height for the accordion views. If non specified, the accordion will auto-sized to the largest of all views, so it can encompass all of them without scrolling
- */
- public function getViewHeight()
- {
- return TPropertyValue::ensureInteger($this->getViewState('ViewHeight'));
- }
-
- /**
- * @param integer Maximum height for the accordion views. If any of the accordion's views' content is larger, those views will be made scrollable when activated
- */
- public function setViewHeight($value)
- {
- $this->setViewState('ViewHeight', TPropertyValue::ensureInteger($value));
- }
-
- /**
- * Activates the specified view.
- * If there is any other view currently active, it will be deactivated.
- * @param TAccordionView the view to be activated. If null, all views will be deactivated.
- */
- protected function activateView($view)
- {
- $this->setActiveViewIndex(-1);
- $this->setActiveViewID('');
- foreach($this->getViews() as $index=>$v)
- {
- if($view===$v)
- {
- $this->setActiveViewIndex($index);
- $this->setActiveViewID($view->getID(false));
- $view->setActive(true);
- }
- else
- $v->setActive(false);
- }
- }
-
- /**
- * Loads user input data.
- * This method is primarly used by framework developers.
- * @param string the key that can be used to retrieve data from the input data collection
- * @param array the input data collection
- * @return boolean whether the data of the control has been changed
- */
- public function loadPostData($key,$values)
- {
- if(($index=$values[$this->getClientID().'_1'])!==null)
- {
- $index=(int)$index;
- $currentIndex=$this->getActiveViewIndex();
- if($currentIndex!==$index)
- {
- $this->setActiveViewID(''); // clear up view ID
- $this->setActiveViewIndex($index);
- return $this->_dataChanged=true;
- }
- }
- return false;
- }
-
- /**
- * Raises postdata changed event.
- * This method is required by {@link IPostBackDataHandler} interface.
- * It is invoked by the framework when {@link getActiveViewIndex ActiveViewIndex} property
- * is changed on postback.
- * This method is primarly used by framework developers.
- */
- public function raisePostDataChangedEvent()
- {
- // do nothing
- }
-
- /**
- * Returns a value indicating whether postback has caused the control data change.
- * This method is required by the IPostBackDataHandler interface.
- * @return boolean whether postback has caused the control data change. False if the page is not in postback mode.
- */
- public function getDataChanged()
- {
- return $this->_dataChanged;
- }
-
- /**
- * Adds attributes to renderer.
- * @param THtmlWriter the renderer
- */
- protected function addAttributesToRender($writer)
- {
- $writer->addAttribute('id',$this->getClientID());
- $this->setCssClass($this->getCssClass());
- parent::addAttributesToRender($writer);
- }
-
- /**
- * Registers CSS and JS.
- * This method is invoked right before the control rendering, if the control is visible.
- * @param mixed event parameter
- */
- public function onPreRender($param)
- {
- parent::onPreRender($param);
- $this->getActiveView(); // determine the active view
- $this->registerStyleSheet();
- }
-
- /**
- * Registers the CSS relevant to the TAccordion.
- * It will register the CSS file specified by {@link getCssUrl CssUrl}.
- * If that is not set, it will use the default CSS.
- */
- protected function registerStyleSheet()
- {
- $url = $this->getCssUrl();
-
- if($url === '') {
- return;
- }
-
- if($url === 'default') {
- $url = $this->getApplication()->getAssetManager()->publishFilePath(dirname(__FILE__).DIRECTORY_SEPARATOR.'assets'.DIRECTORY_SEPARATOR.'accordion.css');
- }
-
- if($url !== '') {
- $this->getPage()->getClientScript()->registerStyleSheetFile($url, $url);
- }
- }
-
- /**
- * Registers the relevant JavaScript.
- */
- protected function registerClientScript()
- {
- $id=$this->getClientID();
- $options=TJavaScript::encode($this->getClientOptions());
- $className=$this->getClientClassName();
- $page=$this->getPage();
- $cs=$page->getClientScript();
- $cs->registerPradoScript('accordion');
- $code="new $className($options);";
- $cs->registerEndScript("prado:$id", $code);
- // ensure an item is always active and visible
- $index = $this->getActiveViewIndex();
- if(!$this->getViews()->itemAt($index)->Visible)
- $index=0;
- $cs->registerHiddenField($id.'_1', $index);
- $page->registerRequiresPostData($this);
- $page->registerRequiresPostData($id."_1");
- }
-
- /**
- * Gets the name of the javascript class responsible for performing postback for this control.
- * This method overrides the parent implementation.
- * @return string the javascript class name
- */
- protected function getClientClassName()
- {
- return 'Prado.WebUI.TAccordion';
- }
-
- /**
- * @return array the options for JavaScript
- */
- protected function getClientOptions()
- {
- $options['ID'] = $this->getClientID();
- $options['ActiveHeaderCssClass'] = $this->getActiveHeaderCssClass();
- $options['HeaderCssClass'] = $this->getHeaderCssClass();
- $options['Duration'] = $this->getAnimationDuration();
-
- if (($viewheight = $this->getViewHeight())>0)
- $options['maxHeight'] = $viewheight;
- $views = array();
- foreach($this->getViews() as $view)
- $views[$view->getClientID()] = $view->getVisible() ? '1': '0';
- $options['Views'] = $views;
-
- return $options;
- }
-
- /**
- * Creates a control collection object that is to be used to hold child controls
- * @return TAccordionViewCollection control collection
- */
- protected function createControlCollection()
- {
- return new TAccordionViewCollection($this);
- }
-
- /**
- * @return TAccordionViewCollection list of {@link TAccordionView} controls
- */
- public function getViews()
- {
- return $this->getControls();
- }
-
- public function render($writer)
- {
- $this->registerClientScript();
- parent::render($writer);
- }
-
- /**
- * Renders body contents of the accordion control.
- * @param THtmlWriter the writer used for the rendering purpose.
- */
- public function renderContents($writer)
- {
- $views=$this->getViews();
- if($views->getCount()>0)
- {
- $writer->writeLine();
- foreach($views as $view)
- {
- $view->renderHeader($writer);
- $view->renderControl($writer);
- $writer->writeLine();
- }
- }
- }
-
-}
-
-/**
- * Class TAccordionView.
- *
- * TAccordionView represents a single view in a {@link TAccordion}.
- *
- * TAccordionView is represented inside the {@link TAccordion} with an header label whose text is defined by
- * the {@link setCaption Caption} property; optionally the label can be an hyperlink: use the
- * {@link setNavigateUrl NavigateUrl} property to define the destination url.
- *
- * @author Gabor Berczi, DevWorx Hungary <gabor.berczi@devworx.hu>
- * @version $Id: TAccordion.php 2915 2011-05-15 16:26:11Z ctrlaltca@gmail.com $
- * @package System.Web.UI.WebControls
- * @since 3.2
- */
-class TAccordionView extends TWebControl
-{
- private $_active=false;
-
- /**
- * @return the tag name for the view element
- */
- protected function getTagName()
- {
- return 'div';
- }
-
- /**
- * Adds attributes to renderer.
- * @param THtmlWriter the renderer
- */
- protected function addAttributesToRender($writer)
- {
- if(!$this->getActive() && $this->getPage()->getClientSupportsJavaScript())
- $this->getStyle()->setStyleField('display','none');
-
- $this->getStyle()->mergeWith($this->getParent()->getViewStyle());
-
- parent::addAttributesToRender($writer);
-
- $writer->addAttribute('id',$this->getClientID());
- }
-
- /**
- * @return string the caption displayed on this header. Defaults to ''.
- */
- public function getCaption()
- {
- return $this->getViewState('Caption','');
- }
-
- /**
- * @param string the caption displayed on this header
- */
- public function setCaption($value)
- {
- $this->setViewState('Caption',TPropertyValue::ensureString($value),'');
- }
-
- /**
- * @return string the URL of the target page. Defaults to ''.
- */
- public function getNavigateUrl()
- {
- return $this->getViewState('NavigateUrl','');
- }
-
- /**
- * Sets the URL of the target page.
- * If not empty, clicking on this header will redirect the browser to the specified URL.
- * @param string the URL of the target page.
- */
- public function setNavigateUrl($value)
- {
- $this->setViewState('NavigateUrl',TPropertyValue::ensureString($value),'');
- }
-
- /**
- * @return string the text content displayed on this view. Defaults to ''.
- */
- public function getText()
- {
- return $this->getViewState('Text','');
- }
-
- /**
- * Sets the text content to be displayed on this view.
- * If this is not empty, the child content of the view will be ignored.
- * @param string the text content displayed on this view
- */
- public function setText($value)
- {
- $this->setViewState('Text',TPropertyValue::ensureString($value),'');
- }
-
- /**
- * @return boolean whether this accordion view is active. Defaults to false.
- */
- public function getActive()
- {
- return $this->_active;
- }
-
- /**
- * @param boolean whether this accordion view is active.
- */
- public function setActive($value)
- {
- $this->_active=TPropertyValue::ensureBoolean($value);
- }
-
- /**
- * Renders body contents of the accordion view.
- * @param THtmlWriter the writer used for the rendering purpose.
- */
- public function renderContents($writer)
- {
- if(($text=$this->getText())!=='')
- $writer->write($text);
- else if($this->getHasControls())
- parent::renderContents($writer);
- }
-
- /**
- * Renders the header associated with the accordion view.
- * @param THtmlWriter the writer for rendering purpose.
- */
- public function renderHeader($writer)
- {
- if($this->getVisible(false) && $this->getPage()->getClientSupportsJavaScript())
- {
- $writer->addAttribute('id',$this->getClientID().'_0');
-
- $style=$this->getActive()?$this->getParent()->getActiveHeaderStyle():$this->getParent()->getHeaderStyle();
-
- $style->addAttributesToRender($writer);
-
- $writer->renderBeginTag($this->getTagName());
-
- $this->renderHeaderContent($writer);
-
- $writer->renderEndTag();
- }
- }
-
- /**
- * Renders the content in the header.
- * By default, a hyperlink is displayed.
- * @param THtmlWriter the HTML writer
- */
- protected function renderHeaderContent($writer)
- {
- $url = $this->getNavigateUrl();
- if(($caption=$this->getCaption())==='')
- $caption='&nbsp;';
-
- if ($url!='')
- $writer->write("<a href=\"{$url}\">");
- $writer->write("{$caption}");
- if ($url!='')
- $writer->write("</a>");
- }
-}
-
-/**
- * Class TAccordionViewCollection.
- *
- * TAccordionViewCollection is a collection of {@link TAccordionView} to be used inside a {@link TAccordion}.
- *
- * @author Gabor Berczi, DevWorx Hungary <gabor.berczi@devworx.hu>
- * @version $Id: TAccordion.php 2915 2011-05-15 16:26:11Z ctrlaltca@gmail.com $
- * @package System.Web.UI.WebControls
- * @since 3.2
- */
-class TAccordionViewCollection extends TControlCollection
-{
- /**
- * Inserts an item at the specified position.
- * This overrides the parent implementation by performing sanity check on the type of new item.
- * @param integer the speicified position.
- * @param mixed new item
- * @throws TInvalidDataTypeException if the item to be inserted is not a {@link TAccordionView} object.
- */
- public function insertAt($index,$item)
- {
- if($item instanceof TAccordionView)
- parent::insertAt($index,$item);
- else
- throw new TInvalidDataTypeException('tabviewcollection_tabview_required');
- }
-
- /**
- * Finds the index of the accordion view whose ID is the same as the one being looked for.
- * @param string the explicit ID of the accordion view to be looked for
- * @return integer the index of the accordion view found, -1 if not found.
- */
- public function findIndexByID($id)
- {
- foreach($this as $index=>$view)
- {
- if($view->getID(false)===$id)
- return $index;
- }
- return -1;
- }
-}
-
-?>
+<?php
+/**
+ * TAccordion class file.
+ *
+ * @author Gabor Berczi, DevWorx Hungary <gabor.berczi@devworx.hu>
+ * @link http://www.pradosoft.com/
+ * @copyright Copyright &copy; 2005-2012 PradoSoft
+ * @license http://www.pradosoft.com/license/
+ * @version $Id: TAccordion.php 2915 2011-05-15 16:26:11Z ctrlaltca@gmail.com $
+ * @package System.Web.UI.WebControls
+ * @since 3.2
+ */
+
+/**
+ * Class TAccordion.
+ *
+ * TAccordion displays an accordion control. Users can click on the view headers to switch among
+ * different accordion views. Each accordion view is an independent panel that can contain arbitrary content.
+ *
+ * A TAccordion control consists of one or several {@link TAccordionView} controls representing the possible
+ * accordion views. At any time, only one accordion view is visible (active), which is specified by any of
+ * the following properties:
+ * - {@link setActiveViewIndex ActiveViewIndex} - the zero-based integer index of the view in the view collection.
+ * - {@link setActiveViewID ActiveViewID} - the text ID of the visible view.
+ * - {@link setActiveView ActiveView} - the visible view instance.
+ * If both {@link setActiveViewIndex ActiveViewIndex} and {@link setActiveViewID ActiveViewID}
+ * are set, the latter takes precedence.
+ *
+ * TAccordion uses CSS to specify the appearance of the accordion headers and panel. By default,
+ * an embedded CSS file will be published which contains the default CSS for TTabPanel.
+ * You may also use your own CSS file by specifying the {@link setCssUrl CssUrl} property.
+ * The following properties specify the CSS classes used for elements in a TAccordion:
+ * - {@link setCssClass CssClass} - the CSS class name for the outer-most div element (defaults to 'accordion');
+ * - {@link setHeaderCssClass HeaderCssClass} - the CSS class name for nonactive accordion div elements (defaults to 'accordion-header');
+ * - {@link setActiveHeaderCssClass ActiveHeaderCssClass} - the CSS class name for the active accordion div element (defaults to 'accordion-header-active');
+ * - {@link setViewCssClass ViewCssClass} - the CSS class for the div element enclosing view content (defaults to 'accordion-view');
+ *
+ * When the user clicks on a view header, the switch between the old visible view and the clicked one is animated.
+ * You can use the {@link setAnimationDuration AnimationDuration} property to set the animation length in seconds;
+ * it defaults to 1 second, and when set to 0 it will produce an immediate switch with no animation.
+ *
+ * The TAccordion auto-sizes itself to the largest of all views, so it can encompass all of them without scrolling.
+ * If you want to specify a fixed height (in pixels), use the {@link setViewHeight ViewHeight} property.
+ * When a TAccordion is nested inside another, it's adviced to manually specify a {@link setViewHeight ViewHeight} for the internal TAccordion
+ *
+ * To use TAccordion, write a template like following:
+ * <code>
+ * <com:TAccordion>
+ * <com:TAccordionView Caption="View 1">
+ * content for view 1
+ * </com:TAccordionView>
+ * <com:TAccordionView Caption="View 2">
+ * content for view 2
+ * </com:TAccordionView>
+ * <com:TAccordionView Caption="View 3">
+ * content for view 3
+ * </com:TAccordionView>
+ * </com:TAccordion>
+ * </code>
+ *
+ * @author Gabor Berczi, DevWorx Hungary <gabor.berczi@devworx.hu>
+ * @version $Id: TAccordion.php 2915 2011-05-15 16:26:11Z ctrlaltca@gmail.com $
+ * @package System.Web.UI.WebControls
+ * @since 3.2
+ */
+
+class TAccordion extends TWebControl implements IPostBackDataHandler
+{
+ private $_dataChanged=false;
+
+ /**
+ * @return string tag name for the control
+ */
+ protected function getTagName()
+ {
+ return 'div';
+ }
+
+ /**
+ * Adds object parsed from template to the control.
+ * This method adds only {@link TAccordionView} objects into the {@link getViews Views} collection.
+ * All other objects are ignored.
+ * @param mixed object parsed from template
+ */
+ public function addParsedObject($object)
+ {
+ if($object instanceof TAccordionView)
+ $this->getControls()->add($object);
+ }
+
+ /**
+ * Returns the index of the active accordion view.
+ * Note, this property may not return the correct index.
+ * To ensure the correctness, call {@link getActiveView()} first.
+ * @return integer the zero-based index of the active accordion view. If -1, it means no active accordion view. Default is 0 (the first view is active).
+ */
+ public function getActiveViewIndex()
+ {
+ return $this->getViewState('ActiveViewIndex',0);
+ }
+
+ /**
+ * @param integer the zero-based index of the current view in the view collection. -1 if no active view.
+ * @throws TInvalidDataValueException if the view index is invalid
+ */
+ public function setActiveViewIndex($value)
+ {
+ $this->setViewState('ActiveViewIndex',TPropertyValue::ensureInteger($value),0);
+ }
+
+ /**
+ * Returns the ID of the active accordion view.
+ * Note, this property may not return the correct ID.
+ * To ensure the correctness, call {@link getActiveView()} first.
+ * @return string The ID of the active accordion view. Defaults to '', meaning not set.
+ */
+ public function getActiveViewID()
+ {
+ return $this->getViewState('ActiveViewID','');
+ }
+
+ /**
+ * @param string The ID of the active accordion view.
+ */
+ public function setActiveViewID($value)
+ {
+ $this->setViewState('ActiveViewID',$value,'');
+ }
+
+ /**
+ * Returns the currently active view.
+ * This method will examin the ActiveViewID, ActiveViewIndex and Views collection to
+ * determine which view is currently active. It will update ActiveViewID and ActiveViewIndex accordingly.
+ * @return TAccordionView the currently active view, null if no active view
+ * @throws TInvalidDataValueException if the active view ID or index set previously is invalid
+ */
+ public function getActiveView()
+ {
+ $activeView=null;
+ $views=$this->getViews();
+ if(($id=$this->getActiveViewID())!=='')
+ {
+ if(($index=$views->findIndexByID($id))>=0)
+ $activeView=$views->itemAt($index);
+ else
+ throw new TInvalidDataValueException('tabpanel_activeviewid_invalid',$id);
+ }
+ else if(($index=$this->getActiveViewIndex())>=0)
+ {
+ if($index<$views->getCount())
+ $activeView=$views->itemAt($index);
+ else
+ throw new TInvalidDataValueException('tabpanel_activeviewindex_invalid',$index);
+ }
+ else
+ {
+ foreach($views as $index=>$view)
+ {
+ if($view->getActive())
+ {
+ $activeView=$view;
+ break;
+ }
+ }
+ }
+ if($activeView!==null)
+ $this->activateView($activeView);
+ return $activeView;
+ }
+
+ /**
+ * @param TAccordionView the view to be activated
+ * @throws TInvalidOperationException if the view is not in the view collection
+ */
+ public function setActiveView($view)
+ {
+ if($this->getViews()->indexOf($view)>=0)
+ $this->activateView($view);
+ else
+ throw new TInvalidOperationException('tabpanel_view_inexistent');
+ }
+
+ /**
+ * @return string URL for the CSS file including all relevant CSS class definitions. Defaults to ''.
+ */
+ public function getCssUrl()
+ {
+ return $this->getViewState('CssUrl','default');
+ }
+
+ /**
+ * @param string URL for the CSS file including all relevant CSS class definitions.
+ */
+ public function setCssUrl($value)
+ {
+ $this->setViewState('CssUrl',TPropertyValue::ensureString($value),'');
+ }
+
+ /**
+ * @return string CSS class for the whole accordion control div.
+ */
+ public function getCssClass()
+ {
+ $cssClass=parent::getCssClass();
+ return $cssClass===''?'accordion':$cssClass;
+ }
+
+ /**
+ * @return string CSS class for the currently displayed view div. Defaults to 'accordion-view'.
+ */
+ public function getViewCssClass()
+ {
+ return $this->getViewStyle()->getCssClass();
+ }
+
+ /**
+ * @param string CSS class for the currently displayed view div.
+ */
+ public function setViewCssClass($value)
+ {
+ $this->getViewStyle()->setCssClass($value);
+ }
+
+ /**
+ * @return string CSS class for the currently displayed view div. Defaults to 'accordion-view'.
+ */
+ public function getAnimationDuration()
+ {
+ return $this->getViewState('AnimationDuration','1');
+ }
+
+ /**
+ * @param string CSS class for the currently displayed view div.
+ */
+ public function setAnimationDuration($value)
+ {
+ $this->setViewState('AnimationDuration',$value);
+ }
+
+ /**
+ * @return TStyle the style for all the view div
+ */
+ public function getViewStyle()
+ {
+ if(($style=$this->getViewState('ViewStyle',null))===null)
+ {
+ $style=new TStyle;
+ $style->setCssClass('accordion-view');
+ $this->setViewState('ViewStyle',$style,null);
+ }
+ return $style;
+ }
+
+ /**
+ * @return string CSS class for view headers. Defaults to 'accordion-header'.
+ */
+ public function getHeaderCssClass()
+ {
+ return $this->getHeaderStyle()->getCssClass();
+ }
+
+ /**
+ * @param string CSS class for view headers.
+ */
+ public function setHeaderCssClass($value)
+ {
+ $this->getHeaderStyle()->setCssClass($value);
+ }
+
+ /**
+ * @return TStyle the style for all the inactive header div
+ */
+ public function getHeaderStyle()
+ {
+ if(($style=$this->getViewState('HeaderStyle',null))===null)
+ {
+ $style=new TStyle;
+ $style->setCssClass('accordion-header');
+ $this->setViewState('HeaderStyle',$style,null);
+ }
+ return $style;
+ }
+
+ /**
+ * @return string Extra CSS class for the active header. Defaults to 'accordion-header-active'.
+ */
+ public function getActiveHeaderCssClass()
+ {
+ return $this->getActiveHeaderStyle()->getCssClass();
+ }
+
+ /**
+ * @param string Extra CSS class for the active header. Will be added to the normal header specified by HeaderCssClass.
+ */
+ public function setActiveHeaderCssClass($value)
+ {
+ $this->getActiveHeaderStyle()->setCssClass($value);
+ }
+
+ /**
+ * @return TStyle the style for the active header div
+ */
+ public function getActiveHeaderStyle()
+ {
+ if(($style=$this->getViewState('ActiveHeaderStyle',null))===null)
+ {
+ $style=new TStyle;
+ $style->setCssClass('accordion-header-active');
+ $this->setViewState('ActiveHeaderStyle',$style,null);
+ }
+ return $style;
+ }
+
+ /**
+ * @return integer Maximum height for the accordion views. If non specified, the accordion will auto-sized to the largest of all views, so it can encompass all of them without scrolling
+ */
+ public function getViewHeight()
+ {
+ return TPropertyValue::ensureInteger($this->getViewState('ViewHeight'));
+ }
+
+ /**
+ * @param integer Maximum height for the accordion views. If any of the accordion's views' content is larger, those views will be made scrollable when activated
+ */
+ public function setViewHeight($value)
+ {
+ $this->setViewState('ViewHeight', TPropertyValue::ensureInteger($value));
+ }
+
+ /**
+ * Activates the specified view.
+ * If there is any other view currently active, it will be deactivated.
+ * @param TAccordionView the view to be activated. If null, all views will be deactivated.
+ */
+ protected function activateView($view)
+ {
+ $this->setActiveViewIndex(-1);
+ $this->setActiveViewID('');
+ foreach($this->getViews() as $index=>$v)
+ {
+ if($view===$v)
+ {
+ $this->setActiveViewIndex($index);
+ $this->setActiveViewID($view->getID(false));
+ $view->setActive(true);
+ }
+ else
+ $v->setActive(false);
+ }
+ }
+
+ /**
+ * Loads user input data.
+ * This method is primarly used by framework developers.
+ * @param string the key that can be used to retrieve data from the input data collection
+ * @param array the input data collection
+ * @return boolean whether the data of the control has been changed
+ */
+ public function loadPostData($key,$values)
+ {
+ if(($index=$values[$this->getClientID().'_1'])!==null)
+ {
+ $index=(int)$index;
+ $currentIndex=$this->getActiveViewIndex();
+ if($currentIndex!==$index)
+ {
+ $this->setActiveViewID(''); // clear up view ID
+ $this->setActiveViewIndex($index);
+ return $this->_dataChanged=true;
+ }
+ }
+ return false;
+ }
+
+ /**
+ * Raises postdata changed event.
+ * This method is required by {@link IPostBackDataHandler} interface.
+ * It is invoked by the framework when {@link getActiveViewIndex ActiveViewIndex} property
+ * is changed on postback.
+ * This method is primarly used by framework developers.
+ */
+ public function raisePostDataChangedEvent()
+ {
+ // do nothing
+ }
+
+ /**
+ * Returns a value indicating whether postback has caused the control data change.
+ * This method is required by the IPostBackDataHandler interface.
+ * @return boolean whether postback has caused the control data change. False if the page is not in postback mode.
+ */
+ public function getDataChanged()
+ {
+ return $this->_dataChanged;
+ }
+
+ /**
+ * Adds attributes to renderer.
+ * @param THtmlWriter the renderer
+ */
+ protected function addAttributesToRender($writer)
+ {
+ $writer->addAttribute('id',$this->getClientID());
+ $this->setCssClass($this->getCssClass());
+ parent::addAttributesToRender($writer);
+ }
+
+ /**
+ * Registers CSS and JS.
+ * This method is invoked right before the control rendering, if the control is visible.
+ * @param mixed event parameter
+ */
+ public function onPreRender($param)
+ {
+ parent::onPreRender($param);
+ $this->getActiveView(); // determine the active view
+ $this->registerStyleSheet();
+ }
+
+ /**
+ * Registers the CSS relevant to the TAccordion.
+ * It will register the CSS file specified by {@link getCssUrl CssUrl}.
+ * If that is not set, it will use the default CSS.
+ */
+ protected function registerStyleSheet()
+ {
+ $url = $this->getCssUrl();
+
+ if($url === '') {
+ return;
+ }
+
+ if($url === 'default') {
+ $url = $this->getApplication()->getAssetManager()->publishFilePath(dirname(__FILE__).DIRECTORY_SEPARATOR.'assets'.DIRECTORY_SEPARATOR.'accordion.css');
+ }
+
+ if($url !== '') {
+ $this->getPage()->getClientScript()->registerStyleSheetFile($url, $url);
+ }
+ }
+
+ /**
+ * Registers the relevant JavaScript.
+ */
+ protected function registerClientScript()
+ {
+ $id=$this->getClientID();
+ $options=TJavaScript::encode($this->getClientOptions());
+ $className=$this->getClientClassName();
+ $page=$this->getPage();
+ $cs=$page->getClientScript();
+ $cs->registerPradoScript('accordion');
+ $code="new $className($options);";
+ $cs->registerEndScript("prado:$id", $code);
+ // ensure an item is always active and visible
+ $index = $this->getActiveViewIndex();
+ if(!$this->getViews()->itemAt($index)->Visible)
+ $index=0;
+ $cs->registerHiddenField($id.'_1', $index);
+ $page->registerRequiresPostData($this);
+ $page->registerRequiresPostData($id."_1");
+ }
+
+ /**
+ * Gets the name of the javascript class responsible for performing postback for this control.
+ * This method overrides the parent implementation.
+ * @return string the javascript class name
+ */
+ protected function getClientClassName()
+ {
+ return 'Prado.WebUI.TAccordion';
+ }
+
+ /**
+ * @return array the options for JavaScript
+ */
+ protected function getClientOptions()
+ {
+ $options['ID'] = $this->getClientID();
+ $options['ActiveHeaderCssClass'] = $this->getActiveHeaderCssClass();
+ $options['HeaderCssClass'] = $this->getHeaderCssClass();
+ $options['Duration'] = $this->getAnimationDuration();
+
+ if (($viewheight = $this->getViewHeight())>0)
+ $options['maxHeight'] = $viewheight;
+ $views = array();
+ foreach($this->getViews() as $view)
+ $views[$view->getClientID()] = $view->getVisible() ? '1': '0';
+ $options['Views'] = $views;
+
+ return $options;
+ }
+
+ /**
+ * Creates a control collection object that is to be used to hold child controls
+ * @return TAccordionViewCollection control collection
+ */
+ protected function createControlCollection()
+ {
+ return new TAccordionViewCollection($this);
+ }
+
+ /**
+ * @return TAccordionViewCollection list of {@link TAccordionView} controls
+ */
+ public function getViews()
+ {
+ return $this->getControls();
+ }
+
+ public function render($writer)
+ {
+ $this->registerClientScript();
+ parent::render($writer);
+ }
+
+ /**
+ * Renders body contents of the accordion control.
+ * @param THtmlWriter the writer used for the rendering purpose.
+ */
+ public function renderContents($writer)
+ {
+ $views=$this->getViews();
+ if($views->getCount()>0)
+ {
+ $writer->writeLine();
+ foreach($views as $view)
+ {
+ $view->renderHeader($writer);
+ $view->renderControl($writer);
+ $writer->writeLine();
+ }
+ }
+ }
+
+}
+
+/**
+ * Class TAccordionView.
+ *
+ * TAccordionView represents a single view in a {@link TAccordion}.
+ *
+ * TAccordionView is represented inside the {@link TAccordion} with an header label whose text is defined by
+ * the {@link setCaption Caption} property; optionally the label can be an hyperlink: use the
+ * {@link setNavigateUrl NavigateUrl} property to define the destination url.
+ *
+ * @author Gabor Berczi, DevWorx Hungary <gabor.berczi@devworx.hu>
+ * @version $Id: TAccordion.php 2915 2011-05-15 16:26:11Z ctrlaltca@gmail.com $
+ * @package System.Web.UI.WebControls
+ * @since 3.2
+ */
+class TAccordionView extends TWebControl
+{
+ private $_active=false;
+
+ /**
+ * @return the tag name for the view element
+ */
+ protected function getTagName()
+ {
+ return 'div';
+ }
+
+ /**
+ * Adds attributes to renderer.
+ * @param THtmlWriter the renderer
+ */
+ protected function addAttributesToRender($writer)
+ {
+ if(!$this->getActive() && $this->getPage()->getClientSupportsJavaScript())
+ $this->getStyle()->setStyleField('display','none');
+
+ $this->getStyle()->mergeWith($this->getParent()->getViewStyle());
+
+ parent::addAttributesToRender($writer);
+
+ $writer->addAttribute('id',$this->getClientID());
+ }
+
+ /**
+ * @return string the caption displayed on this header. Defaults to ''.
+ */
+ public function getCaption()
+ {
+ return $this->getViewState('Caption','');
+ }
+
+ /**
+ * @param string the caption displayed on this header
+ */
+ public function setCaption($value)
+ {
+ $this->setViewState('Caption',TPropertyValue::ensureString($value),'');
+ }
+
+ /**
+ * @return string the URL of the target page. Defaults to ''.
+ */
+ public function getNavigateUrl()
+ {
+ return $this->getViewState('NavigateUrl','');
+ }
+
+ /**
+ * Sets the URL of the target page.
+ * If not empty, clicking on this header will redirect the browser to the specified URL.
+ * @param string the URL of the target page.
+ */
+ public function setNavigateUrl($value)
+ {
+ $this->setViewState('NavigateUrl',TPropertyValue::ensureString($value),'');
+ }
+
+ /**
+ * @return string the text content displayed on this view. Defaults to ''.
+ */
+ public function getText()
+ {
+ return $this->getViewState('Text','');
+ }
+
+ /**
+ * Sets the text content to be displayed on this view.
+ * If this is not empty, the child content of the view will be ignored.
+ * @param string the text content displayed on this view
+ */
+ public function setText($value)
+ {
+ $this->setViewState('Text',TPropertyValue::ensureString($value),'');
+ }
+
+ /**
+ * @return boolean whether this accordion view is active. Defaults to false.
+ */
+ public function getActive()
+ {
+ return $this->_active;
+ }
+
+ /**
+ * @param boolean whether this accordion view is active.
+ */
+ public function setActive($value)
+ {
+ $this->_active=TPropertyValue::ensureBoolean($value);
+ }
+
+ /**
+ * Renders body contents of the accordion view.
+ * @param THtmlWriter the writer used for the rendering purpose.
+ */
+ public function renderContents($writer)
+ {
+ if(($text=$this->getText())!=='')
+ $writer->write($text);
+ else if($this->getHasControls())
+ parent::renderContents($writer);
+ }
+
+ /**
+ * Renders the header associated with the accordion view.
+ * @param THtmlWriter the writer for rendering purpose.
+ */
+ public function renderHeader($writer)
+ {
+ if($this->getVisible(false) && $this->getPage()->getClientSupportsJavaScript())
+ {
+ $writer->addAttribute('id',$this->getClientID().'_0');
+
+ $style=$this->getActive()?$this->getParent()->getActiveHeaderStyle():$this->getParent()->getHeaderStyle();
+
+ $style->addAttributesToRender($writer);
+
+ $writer->renderBeginTag($this->getTagName());
+
+ $this->renderHeaderContent($writer);
+
+ $writer->renderEndTag();
+ }
+ }
+
+ /**
+ * Renders the content in the header.
+ * By default, a hyperlink is displayed.
+ * @param THtmlWriter the HTML writer
+ */
+ protected function renderHeaderContent($writer)
+ {
+ $url = $this->getNavigateUrl();
+ if(($caption=$this->getCaption())==='')
+ $caption='&nbsp;';
+
+ if ($url!='')
+ $writer->write("<a href=\"{$url}\">");
+ $writer->write("{$caption}");
+ if ($url!='')
+ $writer->write("</a>");
+ }
+}
+
+/**
+ * Class TAccordionViewCollection.
+ *
+ * TAccordionViewCollection is a collection of {@link TAccordionView} to be used inside a {@link TAccordion}.
+ *
+ * @author Gabor Berczi, DevWorx Hungary <gabor.berczi@devworx.hu>
+ * @version $Id: TAccordion.php 2915 2011-05-15 16:26:11Z ctrlaltca@gmail.com $
+ * @package System.Web.UI.WebControls
+ * @since 3.2
+ */
+class TAccordionViewCollection extends TControlCollection
+{
+ /**
+ * Inserts an item at the specified position.
+ * This overrides the parent implementation by performing sanity check on the type of new item.
+ * @param integer the speicified position.
+ * @param mixed new item
+ * @throws TInvalidDataTypeException if the item to be inserted is not a {@link TAccordionView} object.
+ */
+ public function insertAt($index,$item)
+ {
+ if($item instanceof TAccordionView)
+ parent::insertAt($index,$item);
+ else
+ throw new TInvalidDataTypeException('tabviewcollection_tabview_required');
+ }
+
+ /**
+ * Finds the index of the accordion view whose ID is the same as the one being looked for.
+ * @param string the explicit ID of the accordion view to be looked for
+ * @return integer the index of the accordion view found, -1 if not found.
+ */
+ public function findIndexByID($id)
+ {
+ foreach($this as $index=>$view)
+ {
+ if($view->getID(false)===$id)
+ return $index;
+ }
+ return -1;
+ }
+}
+
+?>
diff --git a/framework/Web/UI/WebControls/TBaseDataList.php b/framework/Web/UI/WebControls/TBaseDataList.php
index bc591174..01e7dbcf 100644
--- a/framework/Web/UI/WebControls/TBaseDataList.php
+++ b/framework/Web/UI/WebControls/TBaseDataList.php
@@ -1,190 +1,190 @@
-<?php
-/**
- * TBaseDataList class file
- *
- * @author Qiang Xue <qiang.xue@gmail.com>
- * @link http://www.pradosoft.com/
+<?php
+/**
+ * TBaseDataList class file
+ *
+ * @author Qiang Xue <qiang.xue@gmail.com>
+ * @link http://www.pradosoft.com/
* @copyright Copyright &copy; 2005-2012 PradoSoft
- * @license http://www.pradosoft.com/license/
- * @version $Id$
- * @package System.Web.UI.WebControls
- */
-
-/**
- * Includes TDataBoundControl and TDataFieldAccessor classes
- */
-Prado::using('System.Web.UI.WebControls.TDataBoundControl');
-Prado::using('System.Util.TDataFieldAccessor');
-
-/**
- * TBaseDataList class
- *
- * TBaseDataList is the base class for data listing controls, including
- * {@link TDataList} and {@link TDataGrid}.
- *
- * The key field in the data source is specified by {@link setKeyField KeyField},
- * while {@link getKeyValues KeyValues} stores the key values of each record in
- * a data listing control. You may use the list item index to obtain the corresponding
- * database key value.
- *
- * TBaseDataList also implements a few properties used for presentation based
- * on tabular layout. The {@link setCaption Caption}, whose alignment is
- * specified via {@link setCaptionAlign CaptionAlign}, is rendered as the table caption.
- * The table cellpadding and cellspacing are specified by
- * {@link setCellPadding CellPadding} and {@link setCellSpacing CellSpacing}
- * properties, respectively. The {@link setGridLines GridLines} specifies how
- * the table should display its borders, and the horizontal alignment of the table
- * content can be specified via {@link setHorizontalAlign HorizontalAlign}.
- *
- * @author Qiang Xue <qiang.xue@gmail.com>
- * @version $Id$
- * @package System.Web.UI.WebControls
- * @since 3.0
- */
-abstract class TBaseDataList extends TDataBoundControl
-{
- /**
- * Creates a style object for the control.
- * This method creates a {@link TTableStyle} to be used by the data list control.
- * @return TTableStyle control style to be used
- */
- protected function createStyle()
- {
- return new TTableStyle;
- }
-
- /**
- * @return integer the cellspacing for the table layout. Defaults to -1, meaning not set.
- */
- public function getCellSpacing()
- {
- if($this->getHasStyle())
- return $this->getStyle()->getCellSpacing();
- else
- return -1;
- }
-
- /**
- * @param integer the cellspacing for the table layout.
- */
- public function setCellSpacing($value)
- {
- $this->getStyle()->setCellSpacing($value);
- }
-
- /**
- * @return integer the cellpadding for the table layout. Defaults to -1, meaning not set.
- */
- public function getCellPadding()
- {
- if($this->getHasStyle())
- return $this->getStyle()->getCellPadding();
- else
- return -1;
- }
-
- /**
- * @param integer the cellpadding for the table layout
- */
- public function setCellPadding($value)
- {
- $this->getStyle()->setCellPadding($value);
- }
-
- /**
- * @return THorizontalAlign the horizontal alignment of the table content. Defaults to THorizontalAlign::NotSet.
- */
- public function getHorizontalAlign()
- {
- if($this->getHasStyle())
- return $this->getStyle()->getHorizontalAlign();
- else
- return THorizontalAlign::NotSet;
- }
-
- /**
- * @param THorizontalAlign the horizontal alignment of the table content.
- */
- public function setHorizontalAlign($value)
- {
- $this->getStyle()->setHorizontalAlign($value);
- }
-
- /**
- * @return TTableGridLines the grid line setting of the table layout. Defaults to TTableGridLines::None.
- */
- public function getGridLines()
- {
- if($this->getHasStyle())
- return $this->getStyle()->getGridLines();
- else
- return TTableGridLines::None;
- }
-
- /**
- * Sets the grid line style of the table layout.
- * @param TTableGridLines the grid line setting of the table
- */
- public function setGridLines($value)
- {
- $this->getStyle()->setGridLines($value);
- }
-
-
- /**
- * @return string the field of the data source that provides the keys of the list items.
- */
- public function getDataKeyField()
- {
- return $this->getViewState('DataKeyField','');
- }
-
- /**
- * @param string the field of the data source that provides the keys of the list items.
- */
- public function setDataKeyField($value)
- {
- $this->setViewState('DataKeyField',$value,'');
- }
-
- /**
- * @return TList the keys used in the data listing control.
- */
- public function getDataKeys()
- {
- if(($dataKeys=$this->getViewState('DataKeys',null))===null)
- {
- $dataKeys=new TList;
- $this->setViewState('DataKeys',$dataKeys,null);
- }
- return $dataKeys;
- }
-
- /**
- * Returns the value of the data at the specified field.
- * If data is an array, TMap or TList, the value will be returned at the index
- * of the specified field. If the data is a component with a property named
- * as the field name, the property value will be returned.
- * Otherwise, an exception will be raised.
- * @param mixed data item
- * @param mixed field name
- * @return mixed data value at the specified field
- * @throws TInvalidDataValueException if the data is invalid
- */
- protected function getDataFieldValue($data,$field)
- {
- return TDataFieldAccessor::getDataFieldValue($data,$field);
- }
-
- /**
- * Raises OnSelectedIndexChanged event.
- * This method is invoked when a different item is selected
- * in a data listing control between posts to the server.
- * @param mixed event parameter
- */
- public function onSelectedIndexChanged($param)
- {
- $this->raiseEvent('OnSelectedIndexChanged',$this,$param);
- }
-}
-
+ * @license http://www.pradosoft.com/license/
+ * @version $Id$
+ * @package System.Web.UI.WebControls
+ */
+
+/**
+ * Includes TDataBoundControl and TDataFieldAccessor classes
+ */
+Prado::using('System.Web.UI.WebControls.TDataBoundControl');
+Prado::using('System.Util.TDataFieldAccessor');
+
+/**
+ * TBaseDataList class
+ *
+ * TBaseDataList is the base class for data listing controls, including
+ * {@link TDataList} and {@link TDataGrid}.
+ *
+ * The key field in the data source is specified by {@link setKeyField KeyField},
+ * while {@link getKeyValues KeyValues} stores the key values of each record in
+ * a data listing control. You may use the list item index to obtain the corresponding
+ * database key value.
+ *
+ * TBaseDataList also implements a few properties used for presentation based
+ * on tabular layout. The {@link setCaption Caption}, whose alignment is
+ * specified via {@link setCaptionAlign CaptionAlign}, is rendered as the table caption.
+ * The table cellpadding and cellspacing are specified by
+ * {@link setCellPadding CellPadding} and {@link setCellSpacing CellSpacing}
+ * properties, respectively. The {@link setGridLines GridLines} specifies how
+ * the table should display its borders, and the horizontal alignment of the table
+ * content can be specified via {@link setHorizontalAlign HorizontalAlign}.
+ *
+ * @author Qiang Xue <qiang.xue@gmail.com>
+ * @version $Id$
+ * @package System.Web.UI.WebControls
+ * @since 3.0
+ */
+abstract class TBaseDataList extends TDataBoundControl
+{
+ /**
+ * Creates a style object for the control.
+ * This method creates a {@link TTableStyle} to be used by the data list control.
+ * @return TTableStyle control style to be used
+ */
+ protected function createStyle()
+ {
+ return new TTableStyle;
+ }
+
+ /**
+ * @return integer the cellspacing for the table layout. Defaults to -1, meaning not set.
+ */
+ public function getCellSpacing()
+ {
+ if($this->getHasStyle())
+ return $this->getStyle()->getCellSpacing();
+ else
+ return -1;
+ }
+
+ /**
+ * @param integer the cellspacing for the table layout.
+ */
+ public function setCellSpacing($value)
+ {
+ $this->getStyle()->setCellSpacing($value);
+ }
+
+ /**
+ * @return integer the cellpadding for the table layout. Defaults to -1, meaning not set.
+ */
+ public function getCellPadding()
+ {
+ if($this->getHasStyle())
+ return $this->getStyle()->getCellPadding();
+ else
+ return -1;
+ }
+
+ /**
+ * @param integer the cellpadding for the table layout
+ */
+ public function setCellPadding($value)
+ {
+ $this->getStyle()->setCellPadding($value);
+ }
+
+ /**
+ * @return THorizontalAlign the horizontal alignment of the table content. Defaults to THorizontalAlign::NotSet.
+ */
+ public function getHorizontalAlign()
+ {
+ if($this->getHasStyle())
+ return $this->getStyle()->getHorizontalAlign();
+ else
+ return THorizontalAlign::NotSet;
+ }
+
+ /**
+ * @param THorizontalAlign the horizontal alignment of the table content.
+ */
+ public function setHorizontalAlign($value)
+ {
+ $this->getStyle()->setHorizontalAlign($value);
+ }
+
+ /**
+ * @return TTableGridLines the grid line setting of the table layout. Defaults to TTableGridLines::None.
+ */
+ public function getGridLines()
+ {
+ if($this->getHasStyle())
+ return $this->getStyle()->getGridLines();
+ else
+ return TTableGridLines::None;
+ }
+
+ /**
+ * Sets the grid line style of the table layout.
+ * @param TTableGridLines the grid line setting of the table
+ */
+ public function setGridLines($value)
+ {
+ $this->getStyle()->setGridLines($value);
+ }
+
+
+ /**
+ * @return string the field of the data source that provides the keys of the list items.
+ */
+ public function getDataKeyField()
+ {
+ return $this->getViewState('DataKeyField','');
+ }
+
+ /**
+ * @param string the field of the data source that provides the keys of the list items.
+ */
+ public function setDataKeyField($value)
+ {
+ $this->setViewState('DataKeyField',$value,'');
+ }
+
+ /**
+ * @return TList the keys used in the data listing control.
+ */
+ public function getDataKeys()
+ {
+ if(($dataKeys=$this->getViewState('DataKeys',null))===null)
+ {
+ $dataKeys=new TList;
+ $this->setViewState('DataKeys',$dataKeys,null);
+ }
+ return $dataKeys;
+ }
+
+ /**
+ * Returns the value of the data at the specified field.
+ * If data is an array, TMap or TList, the value will be returned at the index
+ * of the specified field. If the data is a component with a property named
+ * as the field name, the property value will be returned.
+ * Otherwise, an exception will be raised.
+ * @param mixed data item
+ * @param mixed field name
+ * @return mixed data value at the specified field
+ * @throws TInvalidDataValueException if the data is invalid
+ */
+ protected function getDataFieldValue($data,$field)
+ {
+ return TDataFieldAccessor::getDataFieldValue($data,$field);
+ }
+
+ /**
+ * Raises OnSelectedIndexChanged event.
+ * This method is invoked when a different item is selected
+ * in a data listing control between posts to the server.
+ * @param mixed event parameter
+ */
+ public function onSelectedIndexChanged($param)
+ {
+ $this->raiseEvent('OnSelectedIndexChanged',$this,$param);
+ }
+}
+
diff --git a/framework/Web/UI/WebControls/TBoundColumn.php b/framework/Web/UI/WebControls/TBoundColumn.php
index 43ef28c2..b7bbc5da 100644
--- a/framework/Web/UI/WebControls/TBoundColumn.php
+++ b/framework/Web/UI/WebControls/TBoundColumn.php
@@ -1,249 +1,249 @@
-<?php
-/**
- * TBoundColumn class file
- *
- * @author Qiang Xue <qiang.xue@gmail.com>
- * @link http://www.pradosoft.com/
- * @copyright Copyright &copy; 2005-2012 PradoSoft
- * @license http://www.pradosoft.com/license/
- * @version $Id$
- * @package System.Web.UI.WebControls
- */
-
-/**
- * TDataGridColumn class file
- */
-Prado::using('System.Web.UI.WebControls.TDataGridColumn');
-
-/**
- * TBoundColumn class
- *
- * TBoundColumn represents a column that is bound to a field in a data source.
- * The cells in the column will be displayed using the data indexed by
- * {@link setDataField DataField}. You can customize the display by
- * setting {@link setDataFormatString DataFormatString}.
- *
- * If {@link setReadOnly ReadOnly} is false, TBoundColumn will display cells in edit mode
- * with textboxes. Otherwise, a static text is displayed.
- *
- * When a datagrid row is in edit mode, the textbox control in the TBoundColumn
- * can be accessed by one of the following two methods:
- * <code>
- * $datagridItem->BoundColumnID->TextBox
- * $datagridItem->BoundColumnID->Controls[0]
- * </code>
- * The second method is possible because the textbox control created within the
- * datagrid cell is the first child.
- *
- * Since v3.1.0, TBoundColumn has introduced two new properties {@link setItemRenderer ItemRenderer}
- * and {@link setEditItemRenderer EditItemRenderer} which can be used to specify
- * the layout of the datagrid cells in browsing and editing mode.
- * A renderer refers to a control class that is to be instantiated as a control.
- * For more details, see {@link TRepeater} and {@link TDataList}.
- *
- * @author Qiang Xue <qiang.xue@gmail.com>
- * @version $Id$
- * @package System.Web.UI.WebControls
- * @since 3.0
- */
-class TBoundColumn extends TDataGridColumn
-{
- /**
- * @return string the class name for the item cell renderer. Defaults to empty, meaning not set.
- * @since 3.1.0
- */
- public function getItemRenderer()
- {
- return $this->getViewState('ItemRenderer','');
- }
-
- /**
- * Sets the item cell renderer class.
- *
- * If not empty, the class will be used to instantiate as a child control in the item cells of the column.
- *
- * If the class implements {@link IDataRenderer}, the <b>Data</b> property
- * will be set as the data associated with the datagrid cell during databinding.
- * The data can be either the whole data row or a field of the row if
- * {@link getDataField DataField} is not empty. If {@link getDataFormatString DataFormatString}
- * is not empty, the data will be formatted first before passing to the renderer.
- *
- * @param string the renderer class name in namespace format.
- * @since 3.1.0
- */
- public function setItemRenderer($value)
- {
- $this->setViewState('ItemRenderer',$value,'');
- }
-
- /**
- * @return string the class name for the edit item cell renderer. Defaults to empty, meaning not set.
- * @since 3.1.0
- */
- public function getEditItemRenderer()
- {
- return $this->getViewState('EditItemRenderer','');
- }
-
- /**
- * Sets the edit item cell renderer class.
- *
- * If not empty, the class will be used to instantiate as a child control in the item cell that is in edit mode.
- *
- * If the class implements {@link IDataRenderer}, the <b>Data</b> property
- * will be set as the data associated with the datagrid cell during databinding.
- * The data can be either the whole data row or a field of the row if
- * {@link getDataField DataField} is not empty. If {@link getDataFormatString DataFormatString}
- * is not empty, the data will be formatted first before passing to the renderer.
- *
- * @param string the renderer class name in namespace format.
- * @since 3.1.0
- */
- public function setEditItemRenderer($value)
- {
- $this->setViewState('EditItemRenderer',$value,'');
- }
-
- /**
- * @return string the field name from the data source to bind to the column
- */
- public function getDataField()
- {
- return $this->getViewState('DataField','');
- }
-
- /**
- * @param string the field name from the data source to bind to the column
- */
- public function setDataField($value)
- {
- $this->setViewState('DataField',$value,'');
- }
-
- /**
- * @return string the formatting string used to control how the bound data will be displayed.
- */
- public function getDataFormatString()
- {
- return $this->getViewState('DataFormatString','');
- }
-
- /**
- * @param string the formatting string used to control how the bound data will be displayed.
- */
- public function setDataFormatString($value)
- {
- $this->setViewState('DataFormatString',$value,'');
- }
-
- /**
- * @return boolean whether the items in the column can be edited. Defaults to false.
- */
- public function getReadOnly()
- {
- return $this->getViewState('ReadOnly',false);
- }
-
- /**
- * @param boolean whether the items in the column can be edited
- */
- public function setReadOnly($value)
- {
- $this->setViewState('ReadOnly',TPropertyValue::ensureBoolean($value),false);
- }
-
- /**
- * Initializes the specified cell to its initial values.
- * This method overrides the parent implementation.
- * It creates a textbox for item in edit mode and the column is not read-only.
- * Otherwise it displays a static text.
- * The caption of the button and the static text are retrieved
- * from the datasource.
- * @param TTableCell the cell to be initialized.
- * @param integer the index to the Columns property that the cell resides in.
- * @param string the type of cell (Header,Footer,Item,AlternatingItem,EditItem,SelectedItem)
- */
- public function initializeCell($cell,$columnIndex,$itemType)
- {
- $item=$cell->getParent();
- switch($itemType)
- {
- case TListItemType::Item:
- case TListItemType::AlternatingItem:
- case TListItemType::SelectedItem:
- if(($classPath=$this->getItemRenderer())!=='')
- {
- $control=Prado::createComponent($classPath);
- if($control instanceof IItemDataRenderer)
- {
- $control->setItemIndex($item->getItemIndex());
- $control->setItemType($item->getItemType());
- }
- $cell->getControls()->add($control);
- }
- else
- $control=$cell;
- $control->attachEventHandler('OnDataBinding',array($this,'dataBindColumn'));
- break;
- case TListItemType::EditItem:
- if(!$this->getReadOnly())
- {
- if(($classPath=$this->getEditItemRenderer())!=='')
- {
- $control=Prado::createComponent($classPath);
- if($control instanceof IItemDataRenderer)
- {
- $control->setItemIndex($item->getItemIndex());
- $control->setItemType($item->getItemType());
- }
- $cell->getControls()->add($control);
- $cell->registerObject('EditControl',$control);
- }
- else
- {
- $control=Prado::createComponent('System.Web.UI.WebControls.TTextBox');
- $cell->getControls()->add($control);
- $cell->registerObject('TextBox',$control);
- }
- }
- else
- {
- if(($classPath=$this->getItemRenderer())!=='')
- {
- $control=Prado::createComponent($classPath);
- if($control instanceof IItemDataRenderer)
- {
- $control->setItemIndex($item->getItemIndex());
- $control->setItemType($item->getItemType());
- }
- $cell->getControls()->add($control);
- }
- else
- $control=$cell;
- }
- $control->attachEventHandler('OnDataBinding',array($this,'dataBindColumn'));
- break;
- default:
- parent::initializeCell($cell,$columnIndex,$itemType);
- break;
- }
- }
-
- /**
- * Databinds a cell in the column.
- * This method is invoked when datagrid performs databinding.
- * It populates the content of the cell with the relevant data from data source.
- */
- public function dataBindColumn($sender,$param)
- {
- $item=$sender->getNamingContainer();
- $data=$item->getData();
- $formatString=$this->getDataFormatString();
- if(($field=$this->getDataField())!=='')
- $value=$this->formatDataValue($formatString,$this->getDataFieldValue($data,$field));
- else
- $value=$this->formatDataValue($formatString,$data);
- $sender->setData($value);
- }
-}
-
+<?php
+/**
+ * TBoundColumn class file
+ *
+ * @author Qiang Xue <qiang.xue@gmail.com>
+ * @link http://www.pradosoft.com/
+ * @copyright Copyright &copy; 2005-2012 PradoSoft
+ * @license http://www.pradosoft.com/license/
+ * @version $Id$
+ * @package System.Web.UI.WebControls
+ */
+
+/**
+ * TDataGridColumn class file
+ */
+Prado::using('System.Web.UI.WebControls.TDataGridColumn');
+
+/**
+ * TBoundColumn class
+ *
+ * TBoundColumn represents a column that is bound to a field in a data source.
+ * The cells in the column will be displayed using the data indexed by
+ * {@link setDataField DataField}. You can customize the display by
+ * setting {@link setDataFormatString DataFormatString}.
+ *
+ * If {@link setReadOnly ReadOnly} is false, TBoundColumn will display cells in edit mode
+ * with textboxes. Otherwise, a static text is displayed.
+ *
+ * When a datagrid row is in edit mode, the textbox control in the TBoundColumn
+ * can be accessed by one of the following two methods:
+ * <code>
+ * $datagridItem->BoundColumnID->TextBox
+ * $datagridItem->BoundColumnID->Controls[0]
+ * </code>
+ * The second method is possible because the textbox control created within the
+ * datagrid cell is the first child.
+ *
+ * Since v3.1.0, TBoundColumn has introduced two new properties {@link setItemRenderer ItemRenderer}
+ * and {@link setEditItemRenderer EditItemRenderer} which can be used to specify
+ * the layout of the datagrid cells in browsing and editing mode.
+ * A renderer refers to a control class that is to be instantiated as a control.
+ * For more details, see {@link TRepeater} and {@link TDataList}.
+ *
+ * @author Qiang Xue <qiang.xue@gmail.com>
+ * @version $Id$
+ * @package System.Web.UI.WebControls
+ * @since 3.0
+ */
+class TBoundColumn extends TDataGridColumn
+{
+ /**
+ * @return string the class name for the item cell renderer. Defaults to empty, meaning not set.
+ * @since 3.1.0
+ */
+ public function getItemRenderer()
+ {
+ return $this->getViewState('ItemRenderer','');
+ }
+
+ /**
+ * Sets the item cell renderer class.
+ *
+ * If not empty, the class will be used to instantiate as a child control in the item cells of the column.
+ *
+ * If the class implements {@link IDataRenderer}, the <b>Data</b> property
+ * will be set as the data associated with the datagrid cell during databinding.
+ * The data can be either the whole data row or a field of the row if
+ * {@link getDataField DataField} is not empty. If {@link getDataFormatString DataFormatString}
+ * is not empty, the data will be formatted first before passing to the renderer.
+ *
+ * @param string the renderer class name in namespace format.
+ * @since 3.1.0
+ */
+ public function setItemRenderer($value)
+ {
+ $this->setViewState('ItemRenderer',$value,'');
+ }
+
+ /**
+ * @return string the class name for the edit item cell renderer. Defaults to empty, meaning not set.
+ * @since 3.1.0
+ */
+ public function getEditItemRenderer()
+ {
+ return $this->getViewState('EditItemRenderer','');
+ }
+
+ /**
+ * Sets the edit item cell renderer class.
+ *
+ * If not empty, the class will be used to instantiate as a child control in the item cell that is in edit mode.
+ *
+ * If the class implements {@link IDataRenderer}, the <b>Data</b> property
+ * will be set as the data associated with the datagrid cell during databinding.
+ * The data can be either the whole data row or a field of the row if
+ * {@link getDataField DataField} is not empty. If {@link getDataFormatString DataFormatString}
+ * is not empty, the data will be formatted first before passing to the renderer.
+ *
+ * @param string the renderer class name in namespace format.
+ * @since 3.1.0
+ */
+ public function setEditItemRenderer($value)
+ {
+ $this->setViewState('EditItemRenderer',$value,'');
+ }
+
+ /**
+ * @return string the field name from the data source to bind to the column
+ */
+ public function getDataField()
+ {
+ return $this->getViewState('DataField','');
+ }
+
+ /**
+ * @param string the field name from the data source to bind to the column
+ */
+ public function setDataField($value)
+ {
+ $this->setViewState('DataField',$value,'');
+ }
+
+ /**
+ * @return string the formatting string used to control how the bound data will be displayed.
+ */
+ public function getDataFormatString()
+ {
+ return $this->getViewState('DataFormatString','');
+ }
+
+ /**
+ * @param string the formatting string used to control how the bound data will be displayed.
+ */
+ public function setDataFormatString($value)
+ {
+ $this->setViewState('DataFormatString',$value,'');
+ }
+
+ /**
+ * @return boolean whether the items in the column can be edited. Defaults to false.
+ */
+ public function getReadOnly()
+ {
+ return $this->getViewState('ReadOnly',false);
+ }
+
+ /**
+ * @param boolean whether the items in the column can be edited
+ */
+ public function setReadOnly($value)
+ {
+ $this->setViewState('ReadOnly',TPropertyValue::ensureBoolean($value),false);
+ }
+
+ /**
+ * Initializes the specified cell to its initial values.
+ * This method overrides the parent implementation.
+ * It creates a textbox for item in edit mode and the column is not read-only.
+ * Otherwise it displays a static text.
+ * The caption of the button and the static text are retrieved
+ * from the datasource.
+ * @param TTableCell the cell to be initialized.
+ * @param integer the index to the Columns property that the cell resides in.
+ * @param string the type of cell (Header,Footer,Item,AlternatingItem,EditItem,SelectedItem)
+ */
+ public function initializeCell($cell,$columnIndex,$itemType)
+ {
+ $item=$cell->getParent();
+ switch($itemType)
+ {
+ case TListItemType::Item:
+ case TListItemType::AlternatingItem:
+ case TListItemType::SelectedItem:
+ if(($classPath=$this->getItemRenderer())!=='')
+ {
+ $control=Prado::createComponent($classPath);
+ if($control instanceof IItemDataRenderer)
+ {
+ $control->setItemIndex($item->getItemIndex());
+ $control->setItemType($item->getItemType());
+ }
+ $cell->getControls()->add($control);
+ }
+ else
+ $control=$cell;
+ $control->attachEventHandler('OnDataBinding',array($this,'dataBindColumn'));
+ break;
+ case TListItemType::EditItem:
+ if(!$this->getReadOnly())
+ {
+ if(($classPath=$this->getEditItemRenderer())!=='')
+ {
+ $control=Prado::createComponent($classPath);
+ if($control instanceof IItemDataRenderer)
+ {
+ $control->setItemIndex($item->getItemIndex());
+ $control->setItemType($item->getItemType());
+ }
+ $cell->getControls()->add($control);
+ $cell->registerObject('EditControl',$control);
+ }
+ else
+ {
+ $control=Prado::createComponent('System.Web.UI.WebControls.TTextBox');
+ $cell->getControls()->add($control);
+ $cell->registerObject('TextBox',$control);
+ }
+ }
+ else
+ {
+ if(($classPath=$this->getItemRenderer())!=='')
+ {
+ $control=Prado::createComponent($classPath);
+ if($control instanceof IItemDataRenderer)
+ {
+ $control->setItemIndex($item->getItemIndex());
+ $control->setItemType($item->getItemType());
+ }
+ $cell->getControls()->add($control);
+ }
+ else
+ $control=$cell;
+ }
+ $control->attachEventHandler('OnDataBinding',array($this,'dataBindColumn'));
+ break;
+ default:
+ parent::initializeCell($cell,$columnIndex,$itemType);
+ break;
+ }
+ }
+
+ /**
+ * Databinds a cell in the column.
+ * This method is invoked when datagrid performs databinding.
+ * It populates the content of the cell with the relevant data from data source.
+ */
+ public function dataBindColumn($sender,$param)
+ {
+ $item=$sender->getNamingContainer();
+ $data=$item->getData();
+ $formatString=$this->getDataFormatString();
+ if(($field=$this->getDataField())!=='')
+ $value=$this->formatDataValue($formatString,$this->getDataFieldValue($data,$field));
+ else
+ $value=$this->formatDataValue($formatString,$data);
+ $sender->setData($value);
+ }
+}
+
diff --git a/framework/Web/UI/WebControls/TBulletedList.php b/framework/Web/UI/WebControls/TBulletedList.php
index 1b32059f..51982c3e 100644
--- a/framework/Web/UI/WebControls/TBulletedList.php
+++ b/framework/Web/UI/WebControls/TBulletedList.php
@@ -1,492 +1,492 @@
-<?php
-/**
- * TBulletedList class file
- *
- * @author Qiang Xue <qiang.xue@gmail.com>
- * @link http://www.pradosoft.com/
+<?php
+/**
+ * TBulletedList class file
+ *
+ * @author Qiang Xue <qiang.xue@gmail.com>
+ * @link http://www.pradosoft.com/
* @copyright Copyright &copy; 2005-2012 PradoSoft
- * @license http://www.pradosoft.com/license/
- * @version $Id$
- * @package System.Web.UI.WebControls
- */
-
-/**
- * Includes TListControl class
- */
-Prado::using('System.Web.UI.WebControls.TListControl');
-
-/**
- * TBulletedList class
- *
- * TBulletedList displays items in a bullet format.
- * The bullet style is specified by {@link setBulletStyle BulletStyle}. When
- * the style is 'CustomImage', the {@link setBackImageUrl BulletImageUrl}
- * specifies the image used as bullets.
- *
- * TBulletedList displays the item texts in three different modes, specified
- * via {@link setDisplayMode DisplayMode}. When the mode is Text, the item texts
- * are displayed as static texts; When the mode is 'HyperLink', each item
- * is displayed as a hyperlink whose URL is given by the item value, and the
- * {@link setTarget Target} property can be used to specify the target browser window;
- * When the mode is 'LinkButton', each item is displayed as a link button which
- * posts back to the page if a user clicks on that and the event {@link onClick OnClick}
- * will be raised under such a circumstance.
- *
- * @author Qiang Xue <qiang.xue@gmail.com>
- * @version $Id$
- * @package System.Web.UI.WebControls
- * @since 3.0
- */
-class TBulletedList extends TListControl implements IPostBackEventHandler
-{
- /**
- * @var boolean cached property value of Enabled
- */
- private $_isEnabled;
- /**
- * @var TPostBackOptions postback options
- */
- private $_postBackOptions;
-
- private $_currentRenderItemIndex;
-
- /**
- * Raises the postback event.
- * This method is required by {@link IPostBackEventHandler} interface.
- * If {@link getCausesValidation CausesValidation} is true, it will
- * invoke the page's {@link TPage::validate validate} method first.
- * It will raise {@link onClick OnClick} events.
- * This method is mainly used by framework and control developers.
- * @param TEventParameter the event parameter
- */
- public function raisePostBackEvent($param)
- {
- if($this->getCausesValidation())
- $this->getPage()->validate($this->getValidationGroup());
- $this->onClick(new TBulletedListEventParameter((int)$param));
- }
-
- /**
- * @return string tag name of the bulleted list
- */
- protected function getTagName()
- {
- switch($this->getBulletStyle())
- {
- case TBulletStyle::Numbered:
- case TBulletStyle::LowerAlpha:
- case TBulletStyle::UpperAlpha:
- case TBulletStyle::LowerRoman:
- case TBulletStyle::UpperRoman:
- return 'ol';
- }
- return 'ul';
- }
-
- /**
- * Gets the name of the javascript class responsible for performing postback for this control.
- * This method overrides the parent implementation.
- * @return string the javascript class name
- */
- protected function getClientClassName()
- {
- return 'Prado.WebUI.TBulletedList';
- }
-
- /**
- * Adds attribute name-value pairs to renderer.
- * This overrides the parent implementation with additional bulleted list specific attributes.
- * @param THtmlWriter the writer used for the rendering purpose
- */
- protected function addAttributesToRender($writer)
- {
- $needStart=false;
- switch($this->getBulletStyle())
- {
- case TBulletStyle::None:
- $writer->addStyleAttribute('list-style-type','none');
- $needStart=true;
- break;
- case TBulletStyle::Numbered:
- $writer->addStyleAttribute('list-style-type','decimal');
- $needStart=true;
- break;
- case TBulletStyle::LowerAlpha:
- $writer->addStyleAttribute('list-style-type','lower-alpha');
- $needStart=true;
- break;
- case TBulletStyle::UpperAlpha:
- $writer->addStyleAttribute('list-style-type','upper-alpha');
- $needStart=true;
- break;
- case TBulletStyle::LowerRoman:
- $writer->addStyleAttribute('list-style-type','lower-roman');
- $needStart=true;
- break;
- case TBulletStyle::UpperRoman:
- $writer->addStyleAttribute('list-style-type','upper-roman');
- $needStart=true;
- break;
- case TBulletStyle::Disc:
- $writer->addStyleAttribute('list-style-type','disc');
- break;
- case TBulletStyle::Circle:
- $writer->addStyleAttribute('list-style-type','circle');
- break;
- case TBulletStyle::Square:
- $writer->addStyleAttribute('list-style-type','square');
- break;
- case TBulletStyle::CustomImage:
- $url=$this->getBulletImageUrl();
- $writer->addStyleAttribute('list-style-image',"url($url)");
- break;
- }
- if($needStart && ($start=$this->getFirstBulletNumber())!=1)
- $writer->addAttribute('start',"$start");
- parent::addAttributesToRender($writer);
- }
-
- /**
- * @return string image URL used for bullets when {@link getBulletStyle BulletStyle} is 'CustomImage'.
- */
- public function getBulletImageUrl()
- {
- return $this->getViewState('BulletImageUrl','');
- }
-
- /**
- * @param string image URL used for bullets when {@link getBulletStyle BulletStyle} is 'CustomImage'.
- */
- public function setBulletImageUrl($value)
- {
- $this->setViewState('BulletImageUrl',$value,'');
- }
-
- /**
- * @return TBulletStyle style of bullets. Defaults to TBulletStyle::NotSet.
- */
- public function getBulletStyle()
- {
- return $this->getViewState('BulletStyle',TBulletStyle::NotSet);
- }
-
- /**
- * @param TBulletStyle style of bullets.
- */
- public function setBulletStyle($value)
- {
- $this->setViewState('BulletStyle',TPropertyValue::ensureEnum($value,'TBulletStyle'),TBulletStyle::NotSet);
- }
-
- /**
- * @return TBulletedListDisplayMode display mode of the list. Defaults to TBulletedListDisplayMode::Text.
- */
- public function getDisplayMode()
- {
- return $this->getViewState('DisplayMode',TBulletedListDisplayMode::Text);
- }
-
- /**
- * @return TBulletedListDisplayMode display mode of the list.
- */
- public function setDisplayMode($value)
- {
- $this->setViewState('DisplayMode',TPropertyValue::ensureEnum($value,'TBulletedListDisplayMode'),TBulletedListDisplayMode::Text);
- }
-
- /**
- * @return integer starting index when {@link getBulletStyle BulletStyle} is one of
- * the following: 'Numbered', 'LowerAlpha', 'UpperAlpha', 'LowerRoman', 'UpperRoman'.
- * Defaults to 1.
- */
- public function getFirstBulletNumber()
- {
- return $this->getViewState('FirstBulletNumber',1);
- }
-
- /**
- * @param integer starting index when {@link getBulletStyle BulletStyle} is one of
- * the following: 'Numbered', 'LowerAlpha', 'UpperAlpha', 'LowerRoman', 'UpperRoman'.
- */
- public function setFirstBulletNumber($value)
- {
- $this->setViewState('FirstBulletNumber',TPropertyValue::ensureInteger($value),1);
- }
-
- /**
- * Raises 'OnClick' event.
- * This method is invoked when the {@link getDisplayMode DisplayMode} is 'LinkButton'
- * and end-users click on one of the buttons.
- * @param TBulletedListEventParameter event parameter.
- */
- public function onClick($param)
- {
- $this->raiseEvent('OnClick',$this,$param);
- }
-
- /**
- * @return string the target window or frame to display the Web page content
- * linked to when {@link getDisplayMode DisplayMode} is 'HyperLink' and one of
- * the hyperlinks is clicked.
- */
- public function getTarget()
- {
- return $this->getViewState('Target','');
- }
-
- /**
- * @param string the target window or frame to display the Web page content
- * linked to when {@link getDisplayMode DisplayMode} is 'HyperLink' and one of
- * the hyperlinks is clicked.
- */
- public function setTarget($value)
- {
- $this->setViewState('Target',$value,'');
- }
-
- /**
- * Renders the control.
- * @param THtmlWriter the writer for the rendering purpose.
- */
- public function render($writer)
- {
- if($this->getHasItems())
- parent::render($writer);
- }
-
- /**
- * Renders the body contents.
- * @param THtmlWriter the writer for the rendering purpose.
- */
- public function renderContents($writer)
- {
- $this->_isEnabled=$this->getEnabled(true);
- $this->_postBackOptions=$this->getPostBackOptions();
- $writer->writeLine();
- foreach($this->getItems() as $index=>$item)
- {
- if($item->getHasAttributes())
- $writer->addAttributes($item->getAttributes());
- $writer->renderBeginTag('li');
- $this->renderBulletText($writer,$item,$index);
- $writer->renderEndTag();
- $writer->writeLine();
- }
- }
-
- /**
- * Renders each item
- * @param THtmlWriter writer for the rendering purpose
- * @param TListItem item to be rendered
- * @param integer index of the item being rendered
- */
- protected function renderBulletText($writer,$item,$index)
- {
- switch($this->getDisplayMode())
- {
- case TBulletedListDisplayMode::Text:
- $this->renderTextItem($writer, $item, $index);
- break;
- case TBulletedListDisplayMode::HyperLink:
- $this->renderHyperLinkItem($writer, $item, $index);
- break;
- case TBulletedListDisplayMode::LinkButton:
- $this->renderLinkButtonItem($writer, $item, $index);
- break;
- }
- }
-
- protected function renderTextItem($writer, $item, $index)
- {
- if($item->getEnabled())
- $writer->write(THttpUtility::htmlEncode($item->getText()));
- else
- {
- $writer->addAttribute('disabled','disabled');
- $writer->renderBeginTag('span');
- $writer->write(THttpUtility::htmlEncode($item->getText()));
- $writer->renderEndTag();
- }
- }
-
- protected function renderHyperLinkItem($writer, $item, $index)
- {
- if(!$this->_isEnabled || !$item->getEnabled())
- $writer->addAttribute('disabled','disabled');
- else
- {
- $writer->addAttribute('href',$item->getValue());
- if(($target=$this->getTarget())!=='')
- $writer->addAttribute('target',$target);
- }
- if(($accesskey=$this->getAccessKey())!=='')
- $writer->addAttribute('accesskey',$accesskey);
- $writer->renderBeginTag('a');
- $writer->write(THttpUtility::htmlEncode($item->getText()));
- $writer->renderEndTag();
- }
-
- protected function renderLinkButtonItem($writer, $item, $index)
- {
- if(!$this->_isEnabled || !$item->getEnabled())
- $writer->addAttribute('disabled','disabled');
- else
- {
- $this->_currentRenderItemIndex = $index;
- $writer->addAttribute('id', $this->getClientID().$index);
- $writer->addAttribute('href', "javascript:;//".$this->getClientID().$index);
- $cs = $this->getPage()->getClientScript();
- $cs->registerPostBackControl($this->getClientClassName(),$this->getPostBackOptions());
- }
- if(($accesskey=$this->getAccessKey())!=='')
- $writer->addAttribute('accesskey',$accesskey);
- $writer->renderBeginTag('a');
- $writer->write(THttpUtility::htmlEncode($item->getText()));
- $writer->renderEndTag();
- }
-
- /**
- * @return array postback options used for linkbuttons.
- */
- protected function getPostBackOptions()
- {
- $options['ValidationGroup'] = $this->getValidationGroup();
- $options['CausesValidation'] = $this->getCausesValidation();
- $options['EventTarget'] = $this->getUniqueID();
- $options['EventParameter'] = $this->_currentRenderItemIndex;
- $options['ID'] = $this->getClientID().$this->_currentRenderItemIndex;
- $options['StopEvent'] = true;
- return $options;
- }
-
- protected function canCauseValidation()
- {
- $group = $this->getValidationGroup();
- $hasValidators = $this->getPage()->getValidators($group)->getCount()>0;
- return $this->getCausesValidation() && $hasValidators;
- }
-
- /**
- * @throws TNotSupportedException if this method is invoked
- */
- public function setAutoPostBack($value)
- {
- throw new TNotSupportedException('bulletedlist_autopostback_unsupported');
- }
-
- /**
- * @throws TNotSupportedException if this method is invoked
- */
- public function setSelectedIndex($index)
- {
- throw new TNotSupportedException('bulletedlist_selectedindex_unsupported');
- }
-
- /**
- * @throws TNotSupportedException if this method is invoked
- */
- public function setSelectedIndices($indices)
- {
- throw new TNotSupportedException('bulletedlist_selectedindices_unsupported');
- }
-
- /**
- * @throws TNotSupportedException if this method is invoked
- */
- public function setSelectedValue($value)
- {
- throw new TNotSupportedException('bulletedlist_selectedvalue_unsupported');
- }
-
- /**
- * @throws TNotSupportedException if this method is invoked
- */
- public function setSelectedValues($values)
- {
- throw new TNotSupportedException('bulletedlist_selectedvalue_unsupported');
- }
-}
-
-/**
- * TBulletedListEventParameter
- * Event parameter for {@link TBulletedList::onClick Click} event of the
- * bulleted list. The {@link getIndex Index} gives the zero-based index
- * of the item that is currently being clicked.
- *
- * @author Qiang Xue <qiang.xue@gmail.com>
- * @version $Id$
- * @package System.Web.UI.WebControls
- * @since 3.0
- */
-class TBulletedListEventParameter extends TEventParameter
-{
- /**
- * @var integer index of the item clicked
- */
- private $_index;
-
- /**
- * Constructor.
- * @param integer index of the item clicked
- */
- public function __construct($index)
- {
- $this->_index=$index;
- }
-
- /**
- * @return integer zero-based index of the item (rendered as a link button) that is clicked
- */
- public function getIndex()
- {
- return $this->_index;
- }
-}
-
-/**
- * TBulletStyle class.
- * TBulletStyle defines the enumerable type for the possible bullet styles that may be used
- * for a {@link TBulletedList} control.
- *
- * @author Qiang Xue <qiang.xue@gmail.com>
- * @version $Id$
- * @package System.Web.UI.WebControls
- * @since 3.0.4
- */
-class TBulletStyle extends TEnumerable
-{
- const NotSet='NotSet';
- const None='None';
- const Numbered='Numbered';
- const LowerAlpha='LowerAlpha';
- const UpperAlpha='UpperAlpha';
- const LowerRoman='LowerRoman';
- const UpperRoman='UpperRoman';
- const Disc='Disc';
- const Circle='Circle';
- const Square='Square';
- const CustomImage='CustomImage';
-}
-
-/**
- * TBulletedListDisplayMode class.
- * TBulletedListDisplayMode defines the enumerable type for the possible display mode
- * of a {@link TBulletedList} control.
- *
- * The following enumerable values are defined:
- * - Text: the bulleted list items are displayed as plain texts
- * - HyperLink: the bulleted list items are displayed as hyperlinks
- * - LinkButton: the bulleted list items are displayed as link buttons that can cause postbacks
- *
- * @author Qiang Xue <qiang.xue@gmail.com>
- * @version $Id$
- * @package System.Web.UI.WebControls
- * @since 3.0.4
- */
-class TBulletedListDisplayMode extends TEnumerable
-{
- const Text='Text';
- const HyperLink='HyperLink';
- const LinkButton='LinkButton';
-}
-
+ * @license http://www.pradosoft.com/license/
+ * @version $Id$
+ * @package System.Web.UI.WebControls
+ */
+
+/**
+ * Includes TListControl class
+ */
+Prado::using('System.Web.UI.WebControls.TListControl');
+
+/**
+ * TBulletedList class
+ *
+ * TBulletedList displays items in a bullet format.
+ * The bullet style is specified by {@link setBulletStyle BulletStyle}. When
+ * the style is 'CustomImage', the {@link setBackImageUrl BulletImageUrl}
+ * specifies the image used as bullets.
+ *
+ * TBulletedList displays the item texts in three different modes, specified
+ * via {@link setDisplayMode DisplayMode}. When the mode is Text, the item texts
+ * are displayed as static texts; When the mode is 'HyperLink', each item
+ * is displayed as a hyperlink whose URL is given by the item value, and the
+ * {@link setTarget Target} property can be used to specify the target browser window;
+ * When the mode is 'LinkButton', each item is displayed as a link button which
+ * posts back to the page if a user clicks on that and the event {@link onClick OnClick}
+ * will be raised under such a circumstance.
+ *
+ * @author Qiang Xue <qiang.xue@gmail.com>
+ * @version $Id$
+ * @package System.Web.UI.WebControls
+ * @since 3.0
+ */
+class TBulletedList extends TListControl implements IPostBackEventHandler
+{
+ /**
+ * @var boolean cached property value of Enabled
+ */
+ private $_isEnabled;
+ /**
+ * @var TPostBackOptions postback options
+ */
+ private $_postBackOptions;
+
+ private $_currentRenderItemIndex;
+
+ /**
+ * Raises the postback event.
+ * This method is required by {@link IPostBackEventHandler} interface.
+ * If {@link getCausesValidation CausesValidation} is true, it will
+ * invoke the page's {@link TPage::validate validate} method first.
+ * It will raise {@link onClick OnClick} events.
+ * This method is mainly used by framework and control developers.
+ * @param TEventParameter the event parameter
+ */
+ public function raisePostBackEvent($param)
+ {
+ if($this->getCausesValidation())
+ $this->getPage()->validate($this->getValidationGroup());
+ $this->onClick(new TBulletedListEventParameter((int)$param));
+ }
+
+ /**
+ * @return string tag name of the bulleted list
+ */
+ protected function getTagName()
+ {
+ switch($this->getBulletStyle())
+ {
+ case TBulletStyle::Numbered:
+ case TBulletStyle::LowerAlpha:
+ case TBulletStyle::UpperAlpha:
+ case TBulletStyle::LowerRoman:
+ case TBulletStyle::UpperRoman:
+ return 'ol';
+ }
+ return 'ul';
+ }
+
+ /**
+ * Gets the name of the javascript class responsible for performing postback for this control.
+ * This method overrides the parent implementation.
+ * @return string the javascript class name
+ */
+ protected function getClientClassName()
+ {
+ return 'Prado.WebUI.TBulletedList';
+ }
+
+ /**
+ * Adds attribute name-value pairs to renderer.
+ * This overrides the parent implementation with additional bulleted list specific attributes.
+ * @param THtmlWriter the writer used for the rendering purpose
+ */
+ protected function addAttributesToRender($writer)
+ {
+ $needStart=false;
+ switch($this->getBulletStyle())
+ {
+ case TBulletStyle::None:
+ $writer->addStyleAttribute('list-style-type','none');
+ $needStart=true;
+ break;
+ case TBulletStyle::Numbered:
+ $writer->addStyleAttribute('list-style-type','decimal');
+ $needStart=true;
+ break;
+ case TBulletStyle::LowerAlpha:
+ $writer->addStyleAttribute('list-style-type','lower-alpha');
+ $needStart=true;
+ break;
+ case TBulletStyle::UpperAlpha:
+ $writer->addStyleAttribute('list-style-type','upper-alpha');
+ $needStart=true;
+ break;
+ case TBulletStyle::LowerRoman:
+ $writer->addStyleAttribute('list-style-type','lower-roman');
+ $needStart=true;
+ break;
+ case TBulletStyle::UpperRoman:
+ $writer->addStyleAttribute('list-style-type','upper-roman');
+ $needStart=true;
+ break;
+ case TBulletStyle::Disc:
+ $writer->addStyleAttribute('list-style-type','disc');
+ break;
+ case TBulletStyle::Circle:
+ $writer->addStyleAttribute('list-style-type','circle');
+ break;
+ case TBulletStyle::Square:
+ $writer->addStyleAttribute('list-style-type','square');
+ break;
+ case TBulletStyle::CustomImage:
+ $url=$this->getBulletImageUrl();
+ $writer->addStyleAttribute('list-style-image',"url($url)");
+ break;
+ }
+ if($needStart && ($start=$this->getFirstBulletNumber())!=1)
+ $writer->addAttribute('start',"$start");
+ parent::addAttributesToRender($writer);
+ }
+
+ /**
+ * @return string image URL used for bullets when {@link getBulletStyle BulletStyle} is 'CustomImage'.
+ */
+ public function getBulletImageUrl()
+ {
+ return $this->getViewState('BulletImageUrl','');
+ }
+
+ /**
+ * @param string image URL used for bullets when {@link getBulletStyle BulletStyle} is 'CustomImage'.
+ */
+ public function setBulletImageUrl($value)
+ {
+ $this->setViewState('BulletImageUrl',$value,'');
+ }
+
+ /**
+ * @return TBulletStyle style of bullets. Defaults to TBulletStyle::NotSet.
+ */
+ public function getBulletStyle()
+ {
+ return $this->getViewState('BulletStyle',TBulletStyle::NotSet);
+ }
+
+ /**
+ * @param TBulletStyle style of bullets.
+ */
+ public function setBulletStyle($value)
+ {
+ $this->setViewState('BulletStyle',TPropertyValue::ensureEnum($value,'TBulletStyle'),TBulletStyle::NotSet);
+ }
+
+ /**
+ * @return TBulletedListDisplayMode display mode of the list. Defaults to TBulletedListDisplayMode::Text.
+ */
+ public function getDisplayMode()
+ {
+ return $this->getViewState('DisplayMode',TBulletedListDisplayMode::Text);
+ }
+
+ /**
+ * @return TBulletedListDisplayMode display mode of the list.
+ */
+ public function setDisplayMode($value)
+ {
+ $this->setViewState('DisplayMode',TPropertyValue::ensureEnum($value,'TBulletedListDisplayMode'),TBulletedListDisplayMode::Text);
+ }
+
+ /**
+ * @return integer starting index when {@link getBulletStyle BulletStyle} is one of
+ * the following: 'Numbered', 'LowerAlpha', 'UpperAlpha', 'LowerRoman', 'UpperRoman'.
+ * Defaults to 1.
+ */
+ public function getFirstBulletNumber()
+ {
+ return $this->getViewState('FirstBulletNumber',1);
+ }
+
+ /**
+ * @param integer starting index when {@link getBulletStyle BulletStyle} is one of
+ * the following: 'Numbered', 'LowerAlpha', 'UpperAlpha', 'LowerRoman', 'UpperRoman'.
+ */
+ public function setFirstBulletNumber($value)
+ {
+ $this->setViewState('FirstBulletNumber',TPropertyValue::ensureInteger($value),1);
+ }
+
+ /**
+ * Raises 'OnClick' event.
+ * This method is invoked when the {@link getDisplayMode DisplayMode} is 'LinkButton'
+ * and end-users click on one of the buttons.
+ * @param TBulletedListEventParameter event parameter.
+ */
+ public function onClick($param)
+ {
+ $this->raiseEvent('OnClick',$this,$param);
+ }
+
+ /**
+ * @return string the target window or frame to display the Web page content
+ * linked to when {@link getDisplayMode DisplayMode} is 'HyperLink' and one of
+ * the hyperlinks is clicked.
+ */
+ public function getTarget()
+ {
+ return $this->getViewState('Target','');
+ }
+
+ /**
+ * @param string the target window or frame to display the Web page content
+ * linked to when {@link getDisplayMode DisplayMode} is 'HyperLink' and one of
+ * the hyperlinks is clicked.
+ */
+ public function setTarget($value)
+ {
+ $this->setViewState('Target',$value,'');
+ }
+
+ /**
+ * Renders the control.
+ * @param THtmlWriter the writer for the rendering purpose.
+ */
+ public function render($writer)
+ {
+ if($this->getHasItems())
+ parent::render($writer);
+ }
+
+ /**
+ * Renders the body contents.
+ * @param THtmlWriter the writer for the rendering purpose.
+ */
+ public function renderContents($writer)
+ {
+ $this->_isEnabled=$this->getEnabled(true);
+ $this->_postBackOptions=$this->getPostBackOptions();
+ $writer->writeLine();
+ foreach($this->getItems() as $index=>$item)
+ {
+ if($item->getHasAttributes())
+ $writer->addAttributes($item->getAttributes());
+ $writer->renderBeginTag('li');
+ $this->renderBulletText($writer,$item,$index);
+ $writer->renderEndTag();
+ $writer->writeLine();
+ }
+ }
+
+ /**
+ * Renders each item
+ * @param THtmlWriter writer for the rendering purpose
+ * @param TListItem item to be rendered
+ * @param integer index of the item being rendered
+ */
+ protected function renderBulletText($writer,$item,$index)
+ {
+ switch($this->getDisplayMode())
+ {
+ case TBulletedListDisplayMode::Text:
+ $this->renderTextItem($writer, $item, $index);
+ break;
+ case TBulletedListDisplayMode::HyperLink:
+ $this->renderHyperLinkItem($writer, $item, $index);
+ break;
+ case TBulletedListDisplayMode::LinkButton:
+ $this->renderLinkButtonItem($writer, $item, $index);
+ break;
+ }
+ }
+
+ protected function renderTextItem($writer, $item, $index)
+ {
+ if($item->getEnabled())
+ $writer->write(THttpUtility::htmlEncode($item->getText()));
+ else
+ {
+ $writer->addAttribute('disabled','disabled');
+ $writer->renderBeginTag('span');
+ $writer->write(THttpUtility::htmlEncode($item->getText()));
+ $writer->renderEndTag();
+ }
+ }
+
+ protected function renderHyperLinkItem($writer, $item, $index)
+ {
+ if(!$this->_isEnabled || !$item->getEnabled())
+ $writer->addAttribute('disabled','disabled');
+ else
+ {
+ $writer->addAttribute('href',$item->getValue());
+ if(($target=$this->getTarget())!=='')
+ $writer->addAttribute('target',$target);
+ }
+ if(($accesskey=$this->getAccessKey())!=='')
+ $writer->addAttribute('accesskey',$accesskey);
+ $writer->renderBeginTag('a');
+ $writer->write(THttpUtility::htmlEncode($item->getText()));
+ $writer->renderEndTag();
+ }
+
+ protected function renderLinkButtonItem($writer, $item, $index)
+ {
+ if(!$this->_isEnabled || !$item->getEnabled())
+ $writer->addAttribute('disabled','disabled');
+ else
+ {
+ $this->_currentRenderItemIndex = $index;
+ $writer->addAttribute('id', $this->getClientID().$index);
+ $writer->addAttribute('href', "javascript:;//".$this->getClientID().$index);
+ $cs = $this->getPage()->getClientScript();
+ $cs->registerPostBackControl($this->getClientClassName(),$this->getPostBackOptions());
+ }
+ if(($accesskey=$this->getAccessKey())!=='')
+ $writer->addAttribute('accesskey',$accesskey);
+ $writer->renderBeginTag('a');
+ $writer->write(THttpUtility::htmlEncode($item->getText()));
+ $writer->renderEndTag();
+ }
+
+ /**
+ * @return array postback options used for linkbuttons.
+ */
+ protected function getPostBackOptions()
+ {
+ $options['ValidationGroup'] = $this->getValidationGroup();
+ $options['CausesValidation'] = $this->getCausesValidation();
+ $options['EventTarget'] = $this->getUniqueID();
+ $options['EventParameter'] = $this->_currentRenderItemIndex;
+ $options['ID'] = $this->getClientID().$this->_currentRenderItemIndex;
+ $options['StopEvent'] = true;
+ return $options;
+ }
+
+ protected function canCauseValidation()
+ {
+ $group = $this->getValidationGroup();
+ $hasValidators = $this->getPage()->getValidators($group)->getCount()>0;
+ return $this->getCausesValidation() && $hasValidators;
+ }
+
+ /**
+ * @throws TNotSupportedException if this method is invoked
+ */
+ public function setAutoPostBack($value)
+ {
+ throw new TNotSupportedException('bulletedlist_autopostback_unsupported');
+ }
+
+ /**
+ * @throws TNotSupportedException if this method is invoked
+ */
+ public function setSelectedIndex($index)
+ {
+ throw new TNotSupportedException('bulletedlist_selectedindex_unsupported');
+ }
+
+ /**
+ * @throws TNotSupportedException if this method is invoked
+ */
+ public function setSelectedIndices($indices)
+ {
+ throw new TNotSupportedException('bulletedlist_selectedindices_unsupported');
+ }
+
+ /**
+ * @throws TNotSupportedException if this method is invoked
+ */
+ public function setSelectedValue($value)
+ {
+ throw new TNotSupportedException('bulletedlist_selectedvalue_unsupported');
+ }
+
+ /**
+ * @throws TNotSupportedException if this method is invoked
+ */
+ public function setSelectedValues($values)
+ {
+ throw new TNotSupportedException('bulletedlist_selectedvalue_unsupported');
+ }
+}
+
+/**
+ * TBulletedListEventParameter
+ * Event parameter for {@link TBulletedList::onClick Click} event of the
+ * bulleted list. The {@link getIndex Index} gives the zero-based index
+ * of the item that is currently being clicked.
+ *
+ * @author Qiang Xue <qiang.xue@gmail.com>
+ * @version $Id$
+ * @package System.Web.UI.WebControls
+ * @since 3.0
+ */
+class TBulletedListEventParameter extends TEventParameter
+{
+ /**
+ * @var integer index of the item clicked
+ */
+ private $_index;
+
+ /**
+ * Constructor.
+ * @param integer index of the item clicked
+ */
+ public function __construct($index)
+ {
+ $this->_index=$index;
+ }
+
+ /**
+ * @return integer zero-based index of the item (rendered as a link button) that is clicked
+ */
+ public function getIndex()
+ {
+ return $this->_index;
+ }
+}
+
+/**
+ * TBulletStyle class.
+ * TBulletStyle defines the enumerable type for the possible bullet styles that may be used
+ * for a {@link TBulletedList} control.
+ *
+ * @author Qiang Xue <qiang.xue@gmail.com>
+ * @version $Id$
+ * @package System.Web.UI.WebControls
+ * @since 3.0.4
+ */
+class TBulletStyle extends TEnumerable
+{
+ const NotSet='NotSet';
+ const None='None';
+ const Numbered='Numbered';
+ const LowerAlpha='LowerAlpha';
+ const UpperAlpha='UpperAlpha';
+ const LowerRoman='LowerRoman';
+ const UpperRoman='UpperRoman';
+ const Disc='Disc';
+ const Circle='Circle';
+ const Square='Square';
+ const CustomImage='CustomImage';
+}
+
+/**
+ * TBulletedListDisplayMode class.
+ * TBulletedListDisplayMode defines the enumerable type for the possible display mode
+ * of a {@link TBulletedList} control.
+ *
+ * The following enumerable values are defined:
+ * - Text: the bulleted list items are displayed as plain texts
+ * - HyperLink: the bulleted list items are displayed as hyperlinks
+ * - LinkButton: the bulleted list items are displayed as link buttons that can cause postbacks
+ *
+ * @author Qiang Xue <qiang.xue@gmail.com>
+ * @version $Id$
+ * @package System.Web.UI.WebControls
+ * @since 3.0.4
+ */
+class TBulletedListDisplayMode extends TEnumerable
+{
+ const Text='Text';
+ const HyperLink='HyperLink';
+ const LinkButton='LinkButton';
+}
+
diff --git a/framework/Web/UI/WebControls/TButton.php b/framework/Web/UI/WebControls/TButton.php
index 71256a5b..caa0332c 100644
--- a/framework/Web/UI/WebControls/TButton.php
+++ b/framework/Web/UI/WebControls/TButton.php
@@ -1,368 +1,368 @@
-<?php
-/**
- * TButton class file.
- *
- * @author Qiang Xue <qiang.xue@gmail.com>
- * @link http://www.pradosoft.com/
+<?php
+/**
+ * TButton class file.
+ *
+ * @author Qiang Xue <qiang.xue@gmail.com>
+ * @link http://www.pradosoft.com/
* @copyright Copyright &copy; 2005-2012 PradoSoft
- * @license http://www.pradosoft.com/license/
- * @version $Id$
- * @package System.Web.UI.WebControls
- */
-
-/**
- * TButton class
- *
- * TButton creates a click button on the page. It is mainly used to submit data to a page.
- *
- * TButton raises two server-side events, {@link onClick OnClick} and {@link onCommand OnCommand},
- * when it is clicked on the client-side. The difference between these two events
- * is that the event {@link onCommand OnCommand} is bubbled up to the button's ancestor controls.
- * And within the event parameter for {@link onCommand OnCommand} contains the reference
- * to the {@link setCommandName CommandName} and {@link setCommandParameter CommandParameter}
- * property values that are set for the button object. This allows you to create multiple TButton
- * components on a Web page and programmatically determine which one is clicked
- * with what parameter.
- *
- * Clicking on button can also trigger form validation, if
- * {@link setCausesValidation CausesValidation} is true.
- * The validation may be restricted within a certain group of validator
- * controls by setting {@link setValidationGroup ValidationGroup} property.
- * If validation is successful, the data will be post back to the same page.
- *
- * TButton displays the {@link setText Text} property as the button caption.
- *
- * TButton can be one of three {@link setButtonType ButtonType}: Submit, Button and Reset.
- * By default, it is a Submit button and the form submission uses the browser's
- * default submission capability. If it is Button or Reset, postback may occur
- * if one of the following conditions is met:
- * - an event handler is attached to {@link onClick OnClick} event;
- * - an event handler is attached to {@link onCommand OnCommand} event;
- * - the button is in a non-empty validation group.
- * In addition, clicking on a Reset button will clear up all input fields
- * if the button does not cause a postback.
- *
- * @author Qiang Xue <qiang.xue@gmail.com>
- * @version $Id$
- * @package System.Web.UI.WebControls
- * @since 3.0
- */
-class TButton extends TWebControl implements IPostBackEventHandler, IButtonControl, IDataRenderer
-{
- /**
- * @return string tag name of the button
- */
- protected function getTagName()
- {
- return 'input';
- }
-
- /**
- * @return boolean whether to render javascript.
- */
- public function getEnableClientScript()
- {
- return $this->getViewState('EnableClientScript',true);
- }
-
- /**
- * @param boolean whether to render javascript.
- */
- public function setEnableClientScript($value)
- {
- $this->setViewState('EnableClientScript',TPropertyValue::ensureBoolean($value),true);
- }
-
- /**
- * Adds attribute name-value pairs to renderer.
- * This overrides the parent implementation with additional button specific attributes.
- * @param THtmlWriter the writer used for the rendering purpose
- */
- protected function addAttributesToRender($writer)
- {
- $page=$this->getPage();
- $page->ensureRenderInForm($this);
- $writer->addAttribute('type',strtolower($this->getButtonType()));
- if(($uniqueID=$this->getUniqueID())!=='')
- $writer->addAttribute('name',$uniqueID);
- $writer->addAttribute('value',$this->getText());
- if($this->getEnabled(true))
- {
- if($this->getEnableClientScript() && $this->needPostBackScript())
- $this->renderClientControlScript($writer);
- }
- else if($this->getEnabled()) // in this case, parent will not render 'disabled'
- $writer->addAttribute('disabled','disabled');
-
- parent::addAttributesToRender($writer);
- }
-
- /**
- * Renders the client-script code.
- */
- protected function renderClientControlScript($writer)
- {
- $writer->addAttribute('id',$this->getClientID());
- $this->getPage()->getClientScript()->registerPostBackControl($this->getClientClassName(),$this->getPostBackOptions());
- }
-
- /**
- * Gets the name of the javascript class responsible for performing postback for this control.
- * This method overrides the parent implementation.
- * @return string the javascript class name
- */
- protected function getClientClassName()
- {
- return 'Prado.WebUI.TButton';
- }
-
- /**
- * @return boolean whether to perform validation if the button is clicked
- */
- protected function canCauseValidation()
- {
- if($this->getCausesValidation())
- {
- $group=$this->getValidationGroup();
- return $this->getPage()->getValidators($group)->getCount()>0;
- }
- else
- return false;
- }
-
- /**
- * @param boolean set by a panel to register this button as the default button for the panel.
- */
- public function setIsDefaultButton($value)
- {
- $this->setViewState('IsDefaultButton', TPropertyValue::ensureBoolean($value),false);
- }
-
- /**
- * @return boolean true if this button is registered as a default button for a panel.
- */
- public function getIsDefaultButton()
- {
- return $this->getViewState('IsDefaultButton', false);
- }
-
- /**
- * @return boolean whether the button needs javascript to do postback
- */
- protected function needPostBackScript()
- {
- return $this->canCauseValidation() || ($this->getButtonType()!==TButtonType::Submit &&
- ($this->hasEventHandler('OnClick') || $this->hasEventHandler('OnCommand')))
- || $this->getIsDefaultButton();
- }
-
- /**
- * Returns postback specifications for the button.
- * This method is used by framework and control developers.
- * @return array parameters about how the button defines its postback behavior.
- */
- protected function getPostBackOptions()
- {
- $options['ID']=$this->getClientID();
- $options['CausesValidation']=$this->getCausesValidation();
- $options['EventTarget'] = $this->getUniqueID();
- $options['ValidationGroup']=$this->getValidationGroup();
-
- return $options;
- }
-
- /**
- * Renders the body content enclosed between the control tag.
- * This overrides the parent implementation with nothing to be rendered.
- * @param THtmlWriter the writer used for the rendering purpose
- */
- public function renderContents($writer)
- {
- }
-
- /**
- * This method is invoked when the button is clicked.
- * The method raises 'OnClick' event to fire up the event handlers.
- * If you override this method, be sure to call the parent implementation
- * so that the event handler can be invoked.
- * @param TEventParameter event parameter to be passed to the event handlers
- */
- public function onClick($param)
- {
- $this->raiseEvent('OnClick',$this,$param);
- }
-
- /**
- * This method is invoked when the button is clicked.
- * The method raises 'OnCommand' event to fire up the event handlers.
- * If you override this method, be sure to call the parent implementation
- * so that the event handlers can be invoked.
- * @param TCommandEventParameter event parameter to be passed to the event handlers
- */
- public function onCommand($param)
- {
- $this->raiseEvent('OnCommand',$this,$param);
- $this->raiseBubbleEvent($this,$param);
- }
-
- /**
- * Raises the postback event.
- * This method is required by {@link IPostBackEventHandler} interface.
- * If {@link getCausesValidation CausesValidation} is true, it will
- * invoke the page's {@link TPage::validate validate} method first.
- * It will raise {@link onClick OnClick} and {@link onCommand OnCommand} events.
- * This method is mainly used by framework and control developers.
- * @param TEventParameter the event parameter
- */
- public function raisePostBackEvent($param)
- {
- if($this->getCausesValidation())
- $this->getPage()->validate($this->getValidationGroup());
- $this->onClick(null);
- $this->onCommand(new TCommandEventParameter($this->getCommandName(),$this->getCommandParameter()));
- }
-
- /**
- * @return string caption of the button
- */
- public function getText()
- {
- return $this->getViewState('Text','');
- }
-
- /**
- * @param string caption of the button
- */
- public function setText($value)
- {
- $this->setViewState('Text',$value,'');
- }
-
- /**
- * Returns the caption of the button.
- * This method is required by {@link IDataRenderer}.
- * It is the same as {@link getText()}.
- * @return string caption of the button.
- * @see getText
- * @since 3.1.0
- */
- public function getData()
- {
- return $this->getText();
- }
-
- /**
- * Sets the caption of the button.
- * This method is required by {@link IDataRenderer}.
- * It is the same as {@link setText()}.
- * @param string caption of the button
- * @see setText
- * @since 3.1.0
- */
- public function setData($value)
- {
- $this->setText($value);
- }
-
- /**
- * @return boolean whether postback event trigger by this button will cause input validation, default is true
- */
- public function getCausesValidation()
- {
- return $this->getViewState('CausesValidation',true);
- }
-
- /**
- * @param boolean whether postback event trigger by this button will cause input validation
- */
- public function setCausesValidation($value)
- {
- $this->setViewState('CausesValidation',TPropertyValue::ensureBoolean($value),true);
- }
-
- /**
- * @return string the command name associated with the {@link onCommand OnCommand} event.
- */
- public function getCommandName()
- {
- return $this->getViewState('CommandName','');
- }
-
- /**
- * @param string the command name associated with the {@link onCommand OnCommand} event.
- */
- public function setCommandName($value)
- {
- $this->setViewState('CommandName',$value,'');
- }
-
- /**
- * @return string the parameter associated with the {@link onCommand OnCommand} event
- */
- public function getCommandParameter()
- {
- return $this->getViewState('CommandParameter','');
- }
-
- /**
- * @param string the parameter associated with the {@link onCommand OnCommand} event.
- */
- public function setCommandParameter($value)
- {
- $this->setViewState('CommandParameter',$value,'');
- }
-
- /**
- * @return string the group of validators which the button causes validation upon postback
- */
- public function getValidationGroup()
- {
- return $this->getViewState('ValidationGroup','');
- }
-
- /**
- * @param string the group of validators which the button causes validation upon postback
- */
- public function setValidationGroup($value)
- {
- $this->setViewState('ValidationGroup',$value,'');
- }
-
- /**
- * @return TButtonType the type of the button. Defaults to TButtonType::Submit.
- */
- public function getButtonType()
- {
- return $this->getViewState('ButtonType',TButtonType::Submit);
- }
-
- /**
- * @param TButtonType the type of the button.
- */
- public function setButtonType($value)
- {
- $this->setViewState('ButtonType',TPropertyValue::ensureEnum($value,'TButtonType'),TButtonType::Submit);
- }
-}
-
-/**
- * TButtonType class.
- * TButtonType defines the enumerable type for the possible types that a {@link TButton} can take.
- *
- * The following enumerable values are defined:
- * - Submit: a normal submit button
- * - Reset: a reset button
- * - Button: a client button (normally does not perform form submission)
- *
- * @author Qiang Xue <qiang.xue@gmail.com>
- * @version $Id$
- * @package System.Web.UI.WebControls
- * @since 3.0.4
- */
-class TButtonType extends TEnumerable
-{
- const Submit='Submit';
- const Reset='Reset';
- const Button='Button';
-}
-
+ * @license http://www.pradosoft.com/license/
+ * @version $Id$
+ * @package System.Web.UI.WebControls
+ */
+
+/**
+ * TButton class
+ *
+ * TButton creates a click button on the page. It is mainly used to submit data to a page.
+ *
+ * TButton raises two server-side events, {@link onClick OnClick} and {@link onCommand OnCommand},
+ * when it is clicked on the client-side. The difference between these two events
+ * is that the event {@link onCommand OnCommand} is bubbled up to the button's ancestor controls.
+ * And within the event parameter for {@link onCommand OnCommand} contains the reference
+ * to the {@link setCommandName CommandName} and {@link setCommandParameter CommandParameter}
+ * property values that are set for the button object. This allows you to create multiple TButton
+ * components on a Web page and programmatically determine which one is clicked
+ * with what parameter.
+ *
+ * Clicking on button can also trigger form validation, if
+ * {@link setCausesValidation CausesValidation} is true.
+ * The validation may be restricted within a certain group of validator
+ * controls by setting {@link setValidationGroup ValidationGroup} property.
+ * If validation is successful, the data will be post back to the same page.
+ *
+ * TButton displays the {@link setText Text} property as the button caption.
+ *
+ * TButton can be one of three {@link setButtonType ButtonType}: Submit, Button and Reset.
+ * By default, it is a Submit button and the form submission uses the browser's
+ * default submission capability. If it is Button or Reset, postback may occur
+ * if one of the following conditions is met:
+ * - an event handler is attached to {@link onClick OnClick} event;
+ * - an event handler is attached to {@link onCommand OnCommand} event;
+ * - the button is in a non-empty validation group.
+ * In addition, clicking on a Reset button will clear up all input fields
+ * if the button does not cause a postback.
+ *
+ * @author Qiang Xue <qiang.xue@gmail.com>
+ * @version $Id$
+ * @package System.Web.UI.WebControls
+ * @since 3.0
+ */
+class TButton extends TWebControl implements IPostBackEventHandler, IButtonControl, IDataRenderer
+{
+ /**
+ * @return string tag name of the button
+ */
+ protected function getTagName()
+ {
+ return 'input';
+ }
+
+ /**
+ * @return boolean whether to render javascript.
+ */
+ public function getEnableClientScript()
+ {
+ return $this->getViewState('EnableClientScript',true);
+ }
+
+ /**
+ * @param boolean whether to render javascript.
+ */
+ public function setEnableClientScript($value)
+ {
+ $this->setViewState('EnableClientScript',TPropertyValue::ensureBoolean($value),true);
+ }
+
+ /**
+ * Adds attribute name-value pairs to renderer.
+ * This overrides the parent implementation with additional button specific attributes.
+ * @param THtmlWriter the writer used for the rendering purpose
+ */
+ protected function addAttributesToRender($writer)
+ {
+ $page=$this->getPage();
+ $page->ensureRenderInForm($this);
+ $writer->addAttribute('type',strtolower($this->getButtonType()));
+ if(($uniqueID=$this->getUniqueID())!=='')
+ $writer->addAttribute('name',$uniqueID);
+ $writer->addAttribute('value',$this->getText());
+ if($this->getEnabled(true))
+ {
+ if($this->getEnableClientScript() && $this->needPostBackScript())
+ $this->renderClientControlScript($writer);
+ }
+ else if($this->getEnabled()) // in this case, parent will not render 'disabled'
+ $writer->addAttribute('disabled','disabled');
+
+ parent::addAttributesToRender($writer);
+ }
+
+ /**
+ * Renders the client-script code.
+ */
+ protected function renderClientControlScript($writer)
+ {
+ $writer->addAttribute('id',$this->getClientID());
+ $this->getPage()->getClientScript()->registerPostBackControl($this->getClientClassName(),$this->getPostBackOptions());
+ }
+
+ /**
+ * Gets the name of the javascript class responsible for performing postback for this control.
+ * This method overrides the parent implementation.
+ * @return string the javascript class name
+ */
+ protected function getClientClassName()
+ {
+ return 'Prado.WebUI.TButton';
+ }
+
+ /**
+ * @return boolean whether to perform validation if the button is clicked
+ */
+ protected function canCauseValidation()
+ {
+ if($this->getCausesValidation())
+ {
+ $group=$this->getValidationGroup();
+ return $this->getPage()->getValidators($group)->getCount()>0;
+ }
+ else
+ return false;
+ }
+
+ /**
+ * @param boolean set by a panel to register this button as the default button for the panel.
+ */
+ public function setIsDefaultButton($value)
+ {
+ $this->setViewState('IsDefaultButton', TPropertyValue::ensureBoolean($value),false);
+ }
+
+ /**
+ * @return boolean true if this button is registered as a default button for a panel.
+ */
+ public function getIsDefaultButton()
+ {
+ return $this->getViewState('IsDefaultButton', false);
+ }
+
+ /**
+ * @return boolean whether the button needs javascript to do postback
+ */
+ protected function needPostBackScript()
+ {
+ return $this->canCauseValidation() || ($this->getButtonType()!==TButtonType::Submit &&
+ ($this->hasEventHandler('OnClick') || $this->hasEventHandler('OnCommand')))
+ || $this->getIsDefaultButton();
+ }
+
+ /**
+ * Returns postback specifications for the button.
+ * This method is used by framework and control developers.
+ * @return array parameters about how the button defines its postback behavior.
+ */
+ protected function getPostBackOptions()
+ {
+ $options['ID']=$this->getClientID();
+ $options['CausesValidation']=$this->getCausesValidation();
+ $options['EventTarget'] = $this->getUniqueID();
+ $options['ValidationGroup']=$this->getValidationGroup();
+
+ return $options;
+ }
+
+ /**
+ * Renders the body content enclosed between the control tag.
+ * This overrides the parent implementation with nothing to be rendered.
+ * @param THtmlWriter the writer used for the rendering purpose
+ */
+ public function renderContents($writer)
+ {
+ }
+
+ /**
+ * This method is invoked when the button is clicked.
+ * The method raises 'OnClick' event to fire up the event handlers.
+ * If you override this method, be sure to call the parent implementation
+ * so that the event handler can be invoked.
+ * @param TEventParameter event parameter to be passed to the event handlers
+ */
+ public function onClick($param)
+ {
+ $this->raiseEvent('OnClick',$this,$param);
+ }
+
+ /**
+ * This method is invoked when the button is clicked.
+ * The method raises 'OnCommand' event to fire up the event handlers.
+ * If you override this method, be sure to call the parent implementation
+ * so that the event handlers can be invoked.
+ * @param TCommandEventParameter event parameter to be passed to the event handlers
+ */
+ public function onCommand($param)
+ {
+ $this->raiseEvent('OnCommand',$this,$param);
+ $this->raiseBubbleEvent($this,$param);
+ }
+
+ /**
+ * Raises the postback event.
+ * This method is required by {@link IPostBackEventHandler} interface.
+ * If {@link getCausesValidation CausesValidation} is true, it will
+ * invoke the page's {@link TPage::validate validate} method first.
+ * It will raise {@link onClick OnClick} and {@link onCommand OnCommand} events.
+ * This method is mainly used by framework and control developers.
+ * @param TEventParameter the event parameter
+ */
+ public function raisePostBackEvent($param)
+ {
+ if($this->getCausesValidation())
+ $this->getPage()->validate($this->getValidationGroup());
+ $this->onClick(null);
+ $this->onCommand(new TCommandEventParameter($this->getCommandName(),$this->getCommandParameter()));
+ }
+
+ /**
+ * @return string caption of the button
+ */
+ public function getText()
+ {
+ return $this->getViewState('Text','');
+ }
+
+ /**
+ * @param string caption of the button
+ */
+ public function setText($value)
+ {
+ $this->setViewState('Text',$value,'');
+ }
+
+ /**
+ * Returns the caption of the button.
+ * This method is required by {@link IDataRenderer}.
+ * It is the same as {@link getText()}.
+ * @return string caption of the button.
+ * @see getText
+ * @since 3.1.0
+ */
+ public function getData()
+ {
+ return $this->getText();
+ }
+
+ /**
+ * Sets the caption of the button.
+ * This method is required by {@link IDataRenderer}.
+ * It is the same as {@link setText()}.
+ * @param string caption of the button
+ * @see setText
+ * @since 3.1.0
+ */
+ public function setData($value)
+ {
+ $this->setText($value);
+ }
+
+ /**
+ * @return boolean whether postback event trigger by this button will cause input validation, default is true
+ */
+ public function getCausesValidation()
+ {
+ return $this->getViewState('CausesValidation',true);
+ }
+
+ /**
+ * @param boolean whether postback event trigger by this button will cause input validation
+ */
+ public function setCausesValidation($value)
+ {
+ $this->setViewState('CausesValidation',TPropertyValue::ensureBoolean($value),true);
+ }
+
+ /**
+ * @return string the command name associated with the {@link onCommand OnCommand} event.
+ */
+ public function getCommandName()
+ {
+ return $this->getViewState('CommandName','');
+ }
+
+ /**
+ * @param string the command name associated with the {@link onCommand OnCommand} event.
+ */
+ public function setCommandName($value)
+ {
+ $this->setViewState('CommandName',$value,'');
+ }
+
+ /**
+ * @return string the parameter associated with the {@link onCommand OnCommand} event
+ */
+ public function getCommandParameter()
+ {
+ return $this->getViewState('CommandParameter','');
+ }
+
+ /**
+ * @param string the parameter associated with the {@link onCommand OnCommand} event.
+ */
+ public function setCommandParameter($value)
+ {
+ $this->setViewState('CommandParameter',$value,'');
+ }
+
+ /**
+ * @return string the group of validators which the button causes validation upon postback
+ */
+ public function getValidationGroup()
+ {
+ return $this->getViewState('ValidationGroup','');
+ }
+
+ /**
+ * @param string the group of validators which the button causes validation upon postback
+ */
+ public function setValidationGroup($value)
+ {
+ $this->setViewState('ValidationGroup',$value,'');
+ }
+
+ /**
+ * @return TButtonType the type of the button. Defaults to TButtonType::Submit.
+ */
+ public function getButtonType()
+ {
+ return $this->getViewState('ButtonType',TButtonType::Submit);
+ }
+
+ /**
+ * @param TButtonType the type of the button.
+ */
+ public function setButtonType($value)
+ {
+ $this->setViewState('ButtonType',TPropertyValue::ensureEnum($value,'TButtonType'),TButtonType::Submit);
+ }
+}
+
+/**
+ * TButtonType class.
+ * TButtonType defines the enumerable type for the possible types that a {@link TButton} can take.
+ *
+ * The following enumerable values are defined:
+ * - Submit: a normal submit button
+ * - Reset: a reset button
+ * - Button: a client button (normally does not perform form submission)
+ *
+ * @author Qiang Xue <qiang.xue@gmail.com>
+ * @version $Id$
+ * @package System.Web.UI.WebControls
+ * @since 3.0.4
+ */
+class TButtonType extends TEnumerable
+{
+ const Submit='Submit';
+ const Reset='Reset';
+ const Button='Button';
+}
+
diff --git a/framework/Web/UI/WebControls/TButtonColumn.php b/framework/Web/UI/WebControls/TButtonColumn.php
index 9d754004..f0f387e7 100644
--- a/framework/Web/UI/WebControls/TButtonColumn.php
+++ b/framework/Web/UI/WebControls/TButtonColumn.php
@@ -1,278 +1,278 @@
-<?php
-/**
- * TButtonColumn class file
- *
- * @author Qiang Xue <qiang.xue@gmail.com>
- * @link http://www.pradosoft.com/
+<?php
+/**
+ * TButtonColumn class file
+ *
+ * @author Qiang Xue <qiang.xue@gmail.com>
+ * @link http://www.pradosoft.com/
* @copyright Copyright &copy; 2005-2012 PradoSoft
- * @license http://www.pradosoft.com/license/
- * @version $Id$
- * @package System.Web.UI.WebControls
- */
-
-/**
- * TDataGridColumn class file
- */
-Prado::using('System.Web.UI.WebControls.TDataGridColumn');
-Prado::using('System.Web.UI.WebControls.TButton');
-Prado::using('System.Web.UI.WebControls.TLinkButton');
-Prado::using('System.Web.UI.WebControls.TImageButton');
-
-/**
- * TButtonColumn class
- *
- * TButtonColumn contains a user-defined command button, such as Add or Remove,
- * that corresponds with each row in the column.
- *
- * The caption of the buttons in the column is determined by {@link setText Text}
- * and {@link setDataTextField DataTextField} properties. If both are present,
- * the latter takes precedence. The {@link setDataTextField DataTextField} property
- * refers to the name of the field in datasource whose value will be used as the button caption.
- * If {@link setDataTextFormatString DataTextFormatString} is not empty,
- * the value will be formatted before rendering.
- *
- * The buttons in the column can be set to display as hyperlinks or push buttons
- * by setting the {@link setButtonType ButtonType} property.
- * The {@link setCommandName CommandName} will assign its value to
- * all button's <b>CommandName</b> property. The datagrid will capture
- * the command event where you can write event handlers based on different command names.
- * The buttons' <b>CausesValidation</b> and <b>ValidationGroup</b> property values
- * are determined by the column's corresponding properties.
- *
- * The buttons in the column can be accessed by one of the following two methods:
- * <code>
- * $datagridItem->ButtonColumnID->Button
- * $datagridItem->ButtonColumnID->Controls[0]
- * </code>
- * The second method is possible because the button control created within the
- * datagrid cell is the first child.
- *
- * @author Qiang Xue <qiang.xue@gmail.com>
- * @version $Id$
- * @package System.Web.UI.WebControls
- * @since 3.0
- */
-class TButtonColumn extends TDataGridColumn
-{
- /**
- * @return string the text caption of the button
- */
- public function getText()
- {
- return $this->getViewState('Text','');
- }
-
- /**
- * Sets the text caption of the button.
- * @param string the text caption to be set
- */
- public function setText($value)
- {
- $this->setViewState('Text',$value,'');
- }
-
- /**
- * @return string the field name from the data source to bind to the button caption
- */
- public function getDataTextField()
- {
- return $this->getViewState('DataTextField','');
- }
-
- /**
- * @param string the field name from the data source to bind to the button caption
- */
- public function setDataTextField($value)
- {
- $this->setViewState('DataTextField',$value,'');
- }
-
- /**
- * @return string the formatting string used to control how the button caption will be displayed.
- */
- public function getDataTextFormatString()
- {
- return $this->getViewState('DataTextFormatString','');
- }
-
- /**
- * @param string the formatting string used to control how the button caption will be displayed.
- */
- public function setDataTextFormatString($value)
- {
- $this->setViewState('DataTextFormatString',$value,'');
- }
-
- /**
- * @return string the URL of the image file for image buttons
- */
- public function getImageUrl()
- {
- return $this->getViewState('ImageUrl','');
- }
-
- /**
- * @param string the URL of the image file for image buttons
- */
- public function setImageUrl($value)
- {
- $this->setViewState('ImageUrl',$value,'');
- }
-
- /**
- * @return string the field name from the data source to bind to the button image url
- */
- public function getDataImageUrlField()
- {
- return $this->getViewState('DataImageUrlField','');
- }
-
- /**
- * @param string the field name from the data source to bind to the button image url
- */
- public function setDataImageUrlField($value)
- {
- $this->setViewState('DataImageUrlField',$value,'');
- }
-
- /**
- * @return string the formatting string used to control how the button image url will be displayed.
- */
- public function getDataImageUrlFormatString()
- {
- return $this->getViewState('DataImageUrlFormatString','');
- }
-
- /**
- * @param string the formatting string used to control how the button image url will be displayed.
- */
- public function setDataImageUrlFormatString($value)
- {
- $this->setViewState('DataImageUrlFormatString',$value,'');
- }
-
- /**
- * @return TButtonColumnType the type of command button. Defaults to TButtonColumnType::LinkButton.
- */
- public function getButtonType()
- {
- return $this->getViewState('ButtonType',TButtonColumnType::LinkButton);
- }
-
- /**
- * @param TButtonColumnType the type of command button
- */
- public function setButtonType($value)
- {
- $this->setViewState('ButtonType',TPropertyValue::ensureEnum($value,'TButtonColumnType'),TButtonColumnType::LinkButton);
- }
-
- /**
- * @return string the command name associated with the <b>OnCommand</b> event.
- */
- public function getCommandName()
- {
- return $this->getViewState('CommandName','');
- }
-
- /**
- * Sets the command name associated with the <b>Command</b> event.
- * @param string the text caption to be set
- */
- public function setCommandName($value)
- {
- $this->setViewState('CommandName',$value,'');
- }
-
- /**
- * @return boolean whether postback event trigger by this button will cause input validation, default is true
- */
- public function getCausesValidation()
- {
- return $this->getViewState('CausesValidation',true);
- }
-
- /**
- * @param boolean whether postback event trigger by this button will cause input validation
- */
- public function setCausesValidation($value)
- {
- $this->setViewState('CausesValidation',TPropertyValue::ensureBoolean($value),true);
- }
-
- /**
- * @return string the group of validators which the button causes validation upon postback
- */
- public function getValidationGroup()
- {
- return $this->getViewState('ValidationGroup','');
- }
-
- /**
- * @param string the group of validators which the button causes validation upon postback
- */
- public function setValidationGroup($value)
- {
- $this->setViewState('ValidationGroup',$value,'');
- }
-
- /**
- * Initializes the specified cell to its initial values.
- * This method overrides the parent implementation.
- * It creates a command button within the cell.
- * @param TTableCell the cell to be initialized.
- * @param integer the index to the Columns property that the cell resides in.
- * @param string the type of cell (Header,Footer,Item,AlternatingItem,EditItem,SelectedItem)
- */
- public function initializeCell($cell,$columnIndex,$itemType)
- {
- if($itemType===TListItemType::Item || $itemType===TListItemType::AlternatingItem || $itemType===TListItemType::SelectedItem || $itemType===TListItemType::EditItem)
- {
- $buttonType=$this->getButtonType();
- if($buttonType===TButtonColumnType::LinkButton)
- $button=new TLinkButton;
- else if($buttonType===TButtonColumnType::PushButton)
- $button=new TButton;
- else // image button
- {
- $button=new TImageButton;
- $button->setImageUrl($this->getImageUrl());
- }
- $button->setText($this->getText());
- $button->setCommandName($this->getCommandName());
- $button->setCausesValidation($this->getCausesValidation());
- $button->setValidationGroup($this->getValidationGroup());
- if($this->getDataTextField()!=='' || ($buttonType===TButtonColumnType::ImageButton && $this->getDataImageUrlField()!==''))
- $button->attachEventHandler('OnDataBinding',array($this,'dataBindColumn'));
- $cell->getControls()->add($button);
- $cell->registerObject('Button',$button);
- }
- else
- parent::initializeCell($cell,$columnIndex,$itemType);
- }
-
- /**
- * Databinds a cell in the column.
- * This method is invoked when datagrid performs databinding.
- * It populates the content of the cell with the relevant data from data source.
- */
- public function dataBindColumn($sender,$param)
- {
- if($sender instanceof IButtonControl)
- {
- if(($field=$this->getDataTextField())!=='')
- {
- $value=$this->getDataFieldValue($sender->getNamingContainer()->getData(),$field);
- $text=$this->formatDataValue($this->getDataTextFormatString(),$value);
- $sender->setText($text);
- }
- if(($sender instanceof TImageButton) && ($field=$this->getDataImageUrlField())!=='')
- {
- $value=$this->getDataFieldValue($sender->getNamingContainer()->getData(),$field);
- $url=$this->formatDataValue($this->getDataImageUrlFormatString(),$value);
- $sender->setImageUrl($url);
- }
- }
- }
-}
-
+ * @license http://www.pradosoft.com/license/
+ * @version $Id$
+ * @package System.Web.UI.WebControls
+ */
+
+/**
+ * TDataGridColumn class file
+ */
+Prado::using('System.Web.UI.WebControls.TDataGridColumn');
+Prado::using('System.Web.UI.WebControls.TButton');
+Prado::using('System.Web.UI.WebControls.TLinkButton');
+Prado::using('System.Web.UI.WebControls.TImageButton');
+
+/**
+ * TButtonColumn class
+ *
+ * TButtonColumn contains a user-defined command button, such as Add or Remove,
+ * that corresponds with each row in the column.
+ *
+ * The caption of the buttons in the column is determined by {@link setText Text}
+ * and {@link setDataTextField DataTextField} properties. If both are present,
+ * the latter takes precedence. The {@link setDataTextField DataTextField} property
+ * refers to the name of the field in datasource whose value will be used as the button caption.
+ * If {@link setDataTextFormatString DataTextFormatString} is not empty,
+ * the value will be formatted before rendering.
+ *
+ * The buttons in the column can be set to display as hyperlinks or push buttons
+ * by setting the {@link setButtonType ButtonType} property.
+ * The {@link setCommandName CommandName} will assign its value to
+ * all button's <b>CommandName</b> property. The datagrid will capture
+ * the command event where you can write event handlers based on different command names.
+ * The buttons' <b>CausesValidation</b> and <b>ValidationGroup</b> property values
+ * are determined by the column's corresponding properties.
+ *
+ * The buttons in the column can be accessed by one of the following two methods:
+ * <code>
+ * $datagridItem->ButtonColumnID->Button
+ * $datagridItem->ButtonColumnID->Controls[0]
+ * </code>
+ * The second method is possible because the button control created within the
+ * datagrid cell is the first child.
+ *
+ * @author Qiang Xue <qiang.xue@gmail.com>
+ * @version $Id$
+ * @package System.Web.UI.WebControls
+ * @since 3.0
+ */
+class TButtonColumn extends TDataGridColumn
+{
+ /**
+ * @return string the text caption of the button
+ */
+ public function getText()
+ {
+ return $this->getViewState('Text','');
+ }
+
+ /**
+ * Sets the text caption of the button.
+ * @param string the text caption to be set
+ */
+ public function setText($value)
+ {
+ $this->setViewState('Text',$value,'');
+ }
+
+ /**
+ * @return string the field name from the data source to bind to the button caption
+ */
+ public function getDataTextField()
+ {
+ return $this->getViewState('DataTextField','');
+ }
+
+ /**
+ * @param string the field name from the data source to bind to the button caption
+ */
+ public function setDataTextField($value)
+ {
+ $this->setViewState('DataTextField',$value,'');
+ }
+
+ /**
+ * @return string the formatting string used to control how the button caption will be displayed.
+ */
+ public function getDataTextFormatString()
+ {
+ return $this->getViewState('DataTextFormatString','');
+ }
+
+ /**
+ * @param string the formatting string used to control how the button caption will be displayed.
+ */
+ public function setDataTextFormatString($value)
+ {
+ $this->setViewState('DataTextFormatString',$value,'');
+ }
+
+ /**
+ * @return string the URL of the image file for image buttons
+ */
+ public function getImageUrl()
+ {
+ return $this->getViewState('ImageUrl','');
+ }
+
+ /**
+ * @param string the URL of the image file for image buttons
+ */
+ public function setImageUrl($value)
+ {
+ $this->setViewState('ImageUrl',$value,'');
+ }
+
+ /**
+ * @return string the field name from the data source to bind to the button image url
+ */
+ public function getDataImageUrlField()
+ {
+ return $this->getViewState('DataImageUrlField','');
+ }
+
+ /**
+ * @param string the field name from the data source to bind to the button image url
+ */
+ public function setDataImageUrlField($value)
+ {
+ $this->setViewState('DataImageUrlField',$value,'');
+ }
+
+ /**
+ * @return string the formatting string used to control how the button image url will be displayed.
+ */
+ public function getDataImageUrlFormatString()
+ {
+ return $this->getViewState('DataImageUrlFormatString','');
+ }
+
+ /**
+ * @param string the formatting string used to control how the button image url will be displayed.
+ */
+ public function setDataImageUrlFormatString($value)
+ {
+ $this->setViewState('DataImageUrlFormatString',$value,'');
+ }
+
+ /**
+ * @return TButtonColumnType the type of command button. Defaults to TButtonColumnType::LinkButton.
+ */
+ public function getButtonType()
+ {
+ return $this->getViewState('ButtonType',TButtonColumnType::LinkButton);
+ }
+
+ /**
+ * @param TButtonColumnType the type of command button
+ */
+ public function setButtonType($value)
+ {
+ $this->setViewState('ButtonType',TPropertyValue::ensureEnum($value,'TButtonColumnType'),TButtonColumnType::LinkButton);
+ }
+
+ /**
+ * @return string the command name associated with the <b>OnCommand</b> event.
+ */
+ public function getCommandName()
+ {
+ return $this->getViewState('CommandName','');
+ }
+
+ /**
+ * Sets the command name associated with the <b>Command</b> event.
+ * @param string the text caption to be set
+ */
+ public function setCommandName($value)
+ {
+ $this->setViewState('CommandName',$value,'');
+ }
+
+ /**
+ * @return boolean whether postback event trigger by this button will cause input validation, default is true
+ */
+ public function getCausesValidation()
+ {
+ return $this->getViewState('CausesValidation',true);
+ }
+
+ /**
+ * @param boolean whether postback event trigger by this button will cause input validation
+ */
+ public function setCausesValidation($value)
+ {
+ $this->setViewState('CausesValidation',TPropertyValue::ensureBoolean($value),true);
+ }
+
+ /**
+ * @return string the group of validators which the button causes validation upon postback
+ */
+ public function getValidationGroup()
+ {
+ return $this->getViewState('ValidationGroup','');
+ }
+
+ /**
+ * @param string the group of validators which the button causes validation upon postback
+ */
+ public function setValidationGroup($value)
+ {
+ $this->setViewState('ValidationGroup',$value,'');
+ }
+
+ /**
+ * Initializes the specified cell to its initial values.
+ * This method overrides the parent implementation.
+ * It creates a command button within the cell.
+ * @param TTableCell the cell to be initialized.
+ * @param integer the index to the Columns property that the cell resides in.
+ * @param string the type of cell (Header,Footer,Item,AlternatingItem,EditItem,SelectedItem)
+ */
+ public function initializeCell($cell,$columnIndex,$itemType)
+ {
+ if($itemType===TListItemType::Item || $itemType===TListItemType::AlternatingItem || $itemType===TListItemType::SelectedItem || $itemType===TListItemType::EditItem)
+ {
+ $buttonType=$this->getButtonType();
+ if($buttonType===TButtonColumnType::LinkButton)
+ $button=new TLinkButton;
+ else if($buttonType===TButtonColumnType::PushButton)
+ $button=new TButton;
+ else // image button
+ {
+ $button=new TImageButton;
+ $button->setImageUrl($this->getImageUrl());
+ }
+ $button->setText($this->getText());
+ $button->setCommandName($this->getCommandName());
+ $button->setCausesValidation($this->getCausesValidation());
+ $button->setValidationGroup($this->getValidationGroup());
+ if($this->getDataTextField()!=='' || ($buttonType===TButtonColumnType::ImageButton && $this->getDataImageUrlField()!==''))
+ $button->attachEventHandler('OnDataBinding',array($this,'dataBindColumn'));
+ $cell->getControls()->add($button);
+ $cell->registerObject('Button',$button);
+ }
+ else
+ parent::initializeCell($cell,$columnIndex,$itemType);
+ }
+
+ /**
+ * Databinds a cell in the column.
+ * This method is invoked when datagrid performs databinding.
+ * It populates the content of the cell with the relevant data from data source.
+ */
+ public function dataBindColumn($sender,$param)
+ {
+ if($sender instanceof IButtonControl)
+ {
+ if(($field=$this->getDataTextField())!=='')
+ {
+ $value=$this->getDataFieldValue($sender->getNamingContainer()->getData(),$field);
+ $text=$this->formatDataValue($this->getDataTextFormatString(),$value);
+ $sender->setText($text);
+ }
+ if(($sender instanceof TImageButton) && ($field=$this->getDataImageUrlField())!=='')
+ {
+ $value=$this->getDataFieldValue($sender->getNamingContainer()->getData(),$field);
+ $url=$this->formatDataValue($this->getDataImageUrlFormatString(),$value);
+ $sender->setImageUrl($url);
+ }
+ }
+ }
+}
+
diff --git a/framework/Web/UI/WebControls/TCaptcha.php b/framework/Web/UI/WebControls/TCaptcha.php
index 7bcf5643..5ec870ce 100644
--- a/framework/Web/UI/WebControls/TCaptcha.php
+++ b/framework/Web/UI/WebControls/TCaptcha.php
@@ -1,495 +1,495 @@
-<?php
-/**
- * TCaptcha class file
- *
- * @author Qiang Xue <qiang.xue@gmail.com>
- * @link http://www.pradosoft.com/
- * @copyright Copyright &copy; 2005-2012 PradoSoft
- * @license http://www.pradosoft.com/license/
- * @version $Id$
- * @package System.Web.UI.WebControls
- */
-
-Prado::using('System.Web.UI.WebControls.TImage');
-
-/**
- * TCaptcha class.
- *
- * Notice: while this class is easy to use and implement, it does not provide full security.
- * In fact, it's easy to bypass the checks reusing old, already-validated tokens (reply attack).
- * A better alternative is provided by {@link TReCaptcha}.
- *
- * TCaptcha displays a CAPTCHA (a token displayed as an image) that can be used
- * to determine if the input is entered by a real user instead of some program.
- *
- * Unlike other CAPTCHA scripts, TCaptcha does not need session or cookie.
- *
- * The token (a string consisting of alphanumeric characters) displayed is automatically
- * generated and can be configured in several ways. To specify the length of characters
- * in the token, set {@link setMinTokenLength MinTokenLength} and {@link setMaxTokenLength MaxTokenLength}.
- * To use case-insensitive comparison and generate upper-case-only token, set {@link setCaseSensitive CaseSensitive}
- * to false. Advanced users can try to set {@link setTokenAlphabet TokenAlphabet}, which
- * specifies what characters can appear in tokens.
- *
- * The validation of the token is related with two properties: {@link setTestLimit TestLimit}
- * and {@link setTokenExpiry TokenExpiry}. The former specifies how many times a token can
- * be tested with on the server side, and the latter says when a generated token will expire.
- *
- * To specify the appearance of the generated token image, set {@link setTokenImageTheme TokenImageTheme}
- * to be an integer between 0 and 63. And to adjust the generated image size, set {@link setTokenFontSize TokenFontSize}
- * (you may also set {@link TWebControl::setWidth Width}, but the scaled image may not look good.)
- * By setting {@link setChangingTokenBackground ChangingTokenBackground} to true, the image background
- * of the token will be variating even though the token is the same during postbacks.
- *
- * Upon postback, user input can be validated by calling {@link validate()}.
- * The {@link TCaptchaValidator} control can also be used to do validation, which provides
- * client-side validation besides the server-side validation. By default, the token will
- * remain the same during multiple postbacks. A new one can be generated by calling
- * {@link regenerateToken()} manually.
- *
- * The following template shows a typical use of TCaptcha control:
- * <code>
- * <com:TCaptcha ID="Captcha" />
- * <com:TTextBox ID="Input" />
- * <com:TCaptchaValidator CaptchaControl="Captcha"
- * ControlToValidate="Input"
- * ErrorMessage="You are challenged!" />
- * </code>
- *
- * @author Qiang Xue <qiang.xue@gmail.com>
- * @version $Id$
- * @package System.Web.UI.WebControls
- * @since 3.1.1
- */
-class TCaptcha extends TImage
-{
- const MIN_TOKEN_LENGTH=2;
- const MAX_TOKEN_LENGTH=40;
- private $_privateKey;
- private $_validated=false;
-
- /**
- * @return integer the theme of the token image. Defaults to 0.
- */
- public function getTokenImageTheme()
- {
- return $this->getViewState('TokenImageTheme',0);
- }
-
- /**
- * Sets the theme of the token image.
- * You may test each theme to find out the one you like the most.
- * Below is the explanation of the theme value:
- * It is treated as a 5-bit integer. Each bit toggles a specific feature of the image.
- * Bit 0 (the least significant): whether the image is opaque (1) or transparent (0).
- * Bit 1: whether we should add white noise to the image (1) or not (0).
- * Bit 2: whether we should add a grid to the image (1) or not (0).
- * Bit 3: whether we should add some scribbles to the image (1) or not (0).
- * Bit 4: whether the image background should be morphed (1) or not (0).
- * Bit 5: whether the token text should cast a shadow (1) or not (0).
- * @param integer the theme of the token image. It must be an integer between 0 and 63.
- */
- public function setTokenImageTheme($value)
- {
- $value=TPropertyValue::ensureInteger($value);
- if($value>=0 && $value<=63)
- $this->setViewState('TokenImageTheme',$value,0);
- else
- throw new TConfigurationException('captcha_tokenimagetheme_invalid',0,63);
- }
-
- /**
- * @return integer the font size used for displaying the token in an image. Defaults to 30.
- */
- public function getTokenFontSize()
- {
- return $this->getViewState('TokenFontSize',30);
- }
-
- /**
- * Sets the font size used for displaying the token in an image.
- * This property affects the generated token image size.
- * The image width is proportional to this font size.
- * @param integer the font size used for displaying the token in an image. It must be an integer between 20 and 100.
- */
- public function setTokenFontSize($value)
- {
- $value=TPropertyValue::ensureInteger($value);
- if($value>=20 && $value<=100)
- $this->setViewState('TokenFontSize',$value,30);
- else
- throw new TConfigurationException('captcha_tokenfontsize_invalid',20,100);
- }
-
- /**
- * @return integer the minimum length of the token. Defaults to 4.
- */
- public function getMinTokenLength()
- {
- return $this->getViewState('MinTokenLength',4);
- }
-
- /**
- * @param integer the minimum length of the token. It must be between 2 and 40.
- */
- public function setMinTokenLength($value)
- {
- $length=TPropertyValue::ensureInteger($value);
- if($length>=self::MIN_TOKEN_LENGTH && $length<=self::MAX_TOKEN_LENGTH)
- $this->setViewState('MinTokenLength',$length,4);
- else
- throw new TConfigurationException('captcha_mintokenlength_invalid',self::MIN_TOKEN_LENGTH,self::MAX_TOKEN_LENGTH);
- }
-
- /**
- * @return integer the maximum length of the token. Defaults to 6.
- */
- public function getMaxTokenLength()
- {
- return $this->getViewState('MaxTokenLength',6);
- }
-
- /**
- * @param integer the maximum length of the token. It must be between 2 and 40.
- */
- public function setMaxTokenLength($value)
- {
- $length=TPropertyValue::ensureInteger($value);
- if($length>=self::MIN_TOKEN_LENGTH && $length<=self::MAX_TOKEN_LENGTH)
- $this->setViewState('MaxTokenLength',$length,6);
- else
- throw new TConfigurationException('captcha_maxtokenlength_invalid',self::MIN_TOKEN_LENGTH,self::MAX_TOKEN_LENGTH);
- }
-
- /**
- * @return boolean whether the token should be treated as case-sensitive. Defaults to true.
- */
- public function getCaseSensitive()
- {
- return $this->getViewState('CaseSensitive',true);
- }
-
- /**
- * @param boolean whether the token should be treated as case-sensitive. If false, only upper-case letters will appear in the token.
- */
- public function setCaseSensitive($value)
- {
- $this->setViewState('CaseSensitive',TPropertyValue::ensureBoolean($value),true);
- }
-
- /**
- * @return string the characters that may appear in the token. Defaults to '234578adefhijmnrtABDEFGHJLMNRT'.
- */
- public function getTokenAlphabet()
- {
- return $this->getViewState('TokenAlphabet','234578adefhijmnrtABDEFGHJLMNRT');
- }
-
- /**
- * @param string the characters that may appear in the token. At least 2 characters must be specified.
- */
- public function setTokenAlphabet($value)
- {
- if(strlen($value)<2)
- throw new TConfigurationException('captcha_tokenalphabet_invalid');
- $this->setViewState('TokenAlphabet',$value,'234578adefhijmnrtABDEFGHJLMNRT');
- }
-
- /**
- * @return integer the number of seconds that a generated token will remain valid. Defaults to 600 seconds (10 minutes).
- */
- public function getTokenExpiry()
- {
- return $this->getViewState('TokenExpiry',600);
- }
-
- /**
- * @param integer the number of seconds that a generated token will remain valid. A value smaller than 1 means the token will not expire.
- */
- public function setTokenExpiry($value)
- {
- $this->setViewState('TokenExpiry',TPropertyValue::ensureInteger($value),600);
- }
-
- /**
- * @return boolean whether the background of the token image should be variated during postbacks. Defaults to false.
- */
- public function getChangingTokenBackground()
- {
- return $this->getViewState('ChangingTokenBackground',false);
- }
-
- /**
- * @param boolean whether the background of the token image should be variated during postbacks.
- */
- public function setChangingTokenBackground($value)
- {
- $this->setViewState('ChangingTokenBackground',TPropertyValue::ensureBoolean($value),false);
- }
-
- /**
- * @return integer how many times a generated token can be tested. Defaults to 5.
- */
- public function getTestLimit()
- {
- return $this->getViewState('TestLimit',5);
- }
-
- /**
- * @param integer how many times a generated token can be tested. For unlimited tests, set it to 0.
- */
- public function setTestLimit($value)
- {
- $this->setViewState('TestLimit',TPropertyValue::ensureInteger($value),5);
- }
-
- /**
- * @return boolean whether the currently generated token has expired.
- */
- public function getIsTokenExpired()
- {
- if(($expiry=$this->getTokenExpiry())>0 && ($start=$this->getViewState('TokenGenerated',0))>0)
- return $expiry+$start<time();
- else
- return false;
- }
-
- /**
- * @return string the public key used for generating the token. A random one will be generated and returned if this is not set.
- */
- public function getPublicKey()
- {
- if(($publicKey=$this->getViewState('PublicKey',''))==='')
- {
- $publicKey=$this->generateRandomKey();
- $this->setPublicKey($publicKey);
- }
- return $publicKey;
- }
-
- /**
- * @param string the public key used for generating the token. A random one will be generated if this is not set.
- */
- public function setPublicKey($value)
- {
- $this->setViewState('PublicKey',$value,'');
- }
-
- /**
- * @return string the token that will be displayed
- */
- public function getToken()
- {
- return $this->generateToken($this->getPublicKey(),$this->getPrivateKey(),$this->getTokenAlphabet(),$this->getTokenLength(),$this->getCaseSensitive());
- }
-
- /**
- * @return integer the length of the token to be generated.
- */
- protected function getTokenLength()
- {
- if(($tokenLength=$this->getViewState('TokenLength'))===null)
- {
- $minLength=$this->getMinTokenLength();
- $maxLength=$this->getMaxTokenLength();
- if($minLength>$maxLength)
- $tokenLength=rand($maxLength,$minLength);
- else if($minLength<$maxLength)
- $tokenLength=rand($minLength,$maxLength);
- else
- $tokenLength=$minLength;
- $this->setViewState('TokenLength',$tokenLength);
- }
- return $tokenLength;
- }
-
- /**
- * @return string the private key used for generating the token. This is randomly generated and kept in a file for persistency.
- */
- public function getPrivateKey()
- {
- if($this->_privateKey===null)
- {
- $fileName=$this->generatePrivateKeyFile();
- $content=file_get_contents($fileName);
- $matches=array();
- if(preg_match("/privateKey='(.*?)'/ms",$content,$matches)>0)
- $this->_privateKey=$matches[1];
- else
- throw new TConfigurationException('captcha_privatekey_unknown');
- }
- return $this->_privateKey;
- }
-
- /**
- * Validates a user input with the token.
- * @param string user input
- * @return boolean if the user input is not the same as the token.
- */
- public function validate($input)
- {
- $number=$this->getViewState('TestNumber',0);
- if(!$this->_validated)
- {
- $this->setViewState('TestNumber',++$number);
- $this->_validated=true;
- }
- if($this->getIsTokenExpired() || (($limit=$this->getTestLimit())>0 && $number>$limit))
- {
- $this->regenerateToken();
- return false;
- }
- return ($this->getToken()===($this->getCaseSensitive()?$input:strtoupper($input)));
- }
-
- /**
- * Regenerates the token to be displayed.
- * By default, a token, once generated, will remain the same during the following page postbacks.
- * Calling this method will generate a new token.
- */
- public function regenerateToken()
- {
- $this->clearViewState('TokenLength');
- $this->setPublicKey('');
- $this->clearViewState('TokenGenerated');
- $this->clearViewState('RandomSeed');
- $this->clearViewState('TestNumber',0);
- }
-
- /**
- * Configures the image URL that shows the token.
- * @param mixed event parameter
- */
- public function onPreRender($param)
- {
- parent::onPreRender($param);
- if(!self::checkRequirements())
- throw new TConfigurationException('captcha_imagettftext_required');
- if(!$this->getViewState('TokenGenerated',0))
- {
- $manager=$this->getApplication()->getAssetManager();
- $manager->publishFilePath($this->getFontFile());
- $url=$manager->publishFilePath($this->getCaptchaScriptFile());
- $url.='?options='.urlencode($this->getTokenImageOptions());
- $this->setImageUrl($url);
-
- $this->setViewState('TokenGenerated',time());
- }
- }
-
- /**
- * @return string the options to be passed to the token image generator
- */
- protected function getTokenImageOptions()
- {
- $privateKey=$this->getPrivateKey(); // call this method to ensure private key is generated
- $token=$this->getToken();
- $options=array();
- $options['publicKey']=$this->getPublicKey();
- $options['tokenLength']=strlen($token);
- $options['caseSensitive']=$this->getCaseSensitive();
- $options['alphabet']=$this->getTokenAlphabet();
- $options['fontSize']=$this->getTokenFontSize();
- $options['theme']=$this->getTokenImageTheme();
- if(($randomSeed=$this->getViewState('RandomSeed',0))===0)
- {
- $randomSeed=(int)(microtime()*1000000);
- $this->setViewState('RandomSeed',$randomSeed);
- }
- $options['randomSeed']=$this->getChangingTokenBackground()?0:$randomSeed;
- $str=serialize($options);
- return base64_encode(md5($privateKey.$str).$str);
- }
-
- /**
- * @return string the file path of the PHP script generating the token image
- */
- protected function getCaptchaScriptFile()
- {
- return dirname(__FILE__).DIRECTORY_SEPARATOR.'assets'.DIRECTORY_SEPARATOR.'captcha.php';
- }
-
- protected function getFontFile()
- {
- return dirname(__FILE__).DIRECTORY_SEPARATOR.'assets'.DIRECTORY_SEPARATOR.'verase.ttf';
- }
-
- /**
- * Generates a file with a randomly generated private key.
- * @return string the path of the file keeping the private key
- */
- protected function generatePrivateKeyFile()
- {
- $captchaScript=$this->getCaptchaScriptFile();
- $path=dirname($this->getApplication()->getAssetManager()->getPublishedPath($captchaScript));
- $fileName=$path.DIRECTORY_SEPARATOR.'captcha_key.php';
- if(!is_file($fileName))
- {
- @mkdir($path);
- $key=$this->generateRandomKey();
- $content="<?php
-\$privateKey='$key';
-?>";
- file_put_contents($fileName,$content);
- }
- return $fileName;
- }
-
- /**
- * @return string a randomly generated key
- */
- protected function generateRandomKey()
- {
- return md5(rand().rand().rand().rand());
- }
-
- /**
- * Generates the token.
- * @param string public key
- * @param string private key
- * @param integer the length of the token
- * @param boolean whether the token is case sensitive
- * @return string the token generated.
- */
- protected function generateToken($publicKey,$privateKey,$alphabet,$tokenLength,$caseSensitive)
- {
- $token=substr($this->hash2string(md5($publicKey.$privateKey),$alphabet).$this->hash2string(md5($privateKey.$publicKey),$alphabet),0,$tokenLength);
- return $caseSensitive?$token:strtoupper($token);
- }
-
- /**
- * Converts a hash string into a string with characters consisting of alphanumeric characters.
- * @param string the hexadecimal representation of the hash string
- * @param string the alphabet used to represent the converted string. If empty, it means '234578adefhijmnrtwyABDEFGHIJLMNQRTWY', which excludes those confusing characters.
- * @return string the converted string
- */
- protected function hash2string($hex,$alphabet='')
- {
- if(strlen($alphabet)<2)
- $alphabet='234578adefhijmnrtABDEFGHJLMNQRT';
- $hexLength=strlen($hex);
- $base=strlen($alphabet);
- $result='';
- for($i=0;$i<$hexLength;$i+=6)
- {
- $number=hexdec(substr($hex,$i,6));
- while($number)
- {
- $result.=$alphabet[$number%$base];
- $number=floor($number/$base);
- }
- }
- return $result;
- }
-
- /**
- * Checks the requirements needed for generating CAPTCHA images.
- * TCaptach requires GD2 with TrueType font support and PNG image support.
- * @return boolean whether the requirements are satisfied.
- */
- public static function checkRequirements()
- {
- return extension_loaded('gd') && function_exists('imagettftext') && function_exists('imagepng');
- }
-}
-
+<?php
+/**
+ * TCaptcha class file
+ *
+ * @author Qiang Xue <qiang.xue@gmail.com>
+ * @link http://www.pradosoft.com/
+ * @copyright Copyright &copy; 2005-2012 PradoSoft
+ * @license http://www.pradosoft.com/license/
+ * @version $Id$
+ * @package System.Web.UI.WebControls
+ */
+
+Prado::using('System.Web.UI.WebControls.TImage');
+
+/**
+ * TCaptcha class.
+ *
+ * Notice: while this class is easy to use and implement, it does not provide full security.
+ * In fact, it's easy to bypass the checks reusing old, already-validated tokens (reply attack).
+ * A better alternative is provided by {@link TReCaptcha}.
+ *
+ * TCaptcha displays a CAPTCHA (a token displayed as an image) that can be used
+ * to determine if the input is entered by a real user instead of some program.
+ *
+ * Unlike other CAPTCHA scripts, TCaptcha does not need session or cookie.
+ *
+ * The token (a string consisting of alphanumeric characters) displayed is automatically
+ * generated and can be configured in several ways. To specify the length of characters
+ * in the token, set {@link setMinTokenLength MinTokenLength} and {@link setMaxTokenLength MaxTokenLength}.
+ * To use case-insensitive comparison and generate upper-case-only token, set {@link setCaseSensitive CaseSensitive}
+ * to false. Advanced users can try to set {@link setTokenAlphabet TokenAlphabet}, which
+ * specifies what characters can appear in tokens.
+ *
+ * The validation of the token is related with two properties: {@link setTestLimit TestLimit}
+ * and {@link setTokenExpiry TokenExpiry}. The former specifies how many times a token can
+ * be tested with on the server side, and the latter says when a generated token will expire.
+ *
+ * To specify the appearance of the generated token image, set {@link setTokenImageTheme TokenImageTheme}
+ * to be an integer between 0 and 63. And to adjust the generated image size, set {@link setTokenFontSize TokenFontSize}
+ * (you may also set {@link TWebControl::setWidth Width}, but the scaled image may not look good.)
+ * By setting {@link setChangingTokenBackground ChangingTokenBackground} to true, the image background
+ * of the token will be variating even though the token is the same during postbacks.
+ *
+ * Upon postback, user input can be validated by calling {@link validate()}.
+ * The {@link TCaptchaValidator} control can also be used to do validation, which provides
+ * client-side validation besides the server-side validation. By default, the token will
+ * remain the same during multiple postbacks. A new one can be generated by calling
+ * {@link regenerateToken()} manually.
+ *
+ * The following template shows a typical use of TCaptcha control:
+ * <code>
+ * <com:TCaptcha ID="Captcha" />
+ * <com:TTextBox ID="Input" />
+ * <com:TCaptchaValidator CaptchaControl="Captcha"
+ * ControlToValidate="Input"
+ * ErrorMessage="You are challenged!" />
+ * </code>
+ *
+ * @author Qiang Xue <qiang.xue@gmail.com>
+ * @version $Id$
+ * @package System.Web.UI.WebControls
+ * @since 3.1.1
+ */
+class TCaptcha extends TImage
+{
+ const MIN_TOKEN_LENGTH=2;
+ const MAX_TOKEN_LENGTH=40;
+ private $_privateKey;
+ private $_validated=false;
+
+ /**
+ * @return integer the theme of the token image. Defaults to 0.
+ */
+ public function getTokenImageTheme()
+ {
+ return $this->getViewState('TokenImageTheme',0);
+ }
+
+ /**
+ * Sets the theme of the token image.
+ * You may test each theme to find out the one you like the most.
+ * Below is the explanation of the theme value:
+ * It is treated as a 5-bit integer. Each bit toggles a specific feature of the image.
+ * Bit 0 (the least significant): whether the image is opaque (1) or transparent (0).
+ * Bit 1: whether we should add white noise to the image (1) or not (0).
+ * Bit 2: whether we should add a grid to the image (1) or not (0).
+ * Bit 3: whether we should add some scribbles to the image (1) or not (0).
+ * Bit 4: whether the image background should be morphed (1) or not (0).
+ * Bit 5: whether the token text should cast a shadow (1) or not (0).
+ * @param integer the theme of the token image. It must be an integer between 0 and 63.
+ */
+ public function setTokenImageTheme($value)
+ {
+ $value=TPropertyValue::ensureInteger($value);
+ if($value>=0 && $value<=63)
+ $this->setViewState('TokenImageTheme',$value,0);
+ else
+ throw new TConfigurationException('captcha_tokenimagetheme_invalid',0,63);
+ }
+
+ /**
+ * @return integer the font size used for displaying the token in an image. Defaults to 30.
+ */
+ public function getTokenFontSize()
+ {
+ return $this->getViewState('TokenFontSize',30);
+ }
+
+ /**
+ * Sets the font size used for displaying the token in an image.
+ * This property affects the generated token image size.
+ * The image width is proportional to this font size.
+ * @param integer the font size used for displaying the token in an image. It must be an integer between 20 and 100.
+ */
+ public function setTokenFontSize($value)
+ {
+ $value=TPropertyValue::ensureInteger($value);
+ if($value>=20 && $value<=100)
+ $this->setViewState('TokenFontSize',$value,30);
+ else
+ throw new TConfigurationException('captcha_tokenfontsize_invalid',20,100);
+ }
+
+ /**
+ * @return integer the minimum length of the token. Defaults to 4.
+ */
+ public function getMinTokenLength()
+ {
+ return $this->getViewState('MinTokenLength',4);
+ }
+
+ /**
+ * @param integer the minimum length of the token. It must be between 2 and 40.
+ */
+ public function setMinTokenLength($value)
+ {
+ $length=TPropertyValue::ensureInteger($value);
+ if($length>=self::MIN_TOKEN_LENGTH && $length<=self::MAX_TOKEN_LENGTH)
+ $this->setViewState('MinTokenLength',$length,4);
+ else
+ throw new TConfigurationException('captcha_mintokenlength_invalid',self::MIN_TOKEN_LENGTH,self::MAX_TOKEN_LENGTH);
+ }
+
+ /**
+ * @return integer the maximum length of the token. Defaults to 6.
+ */
+ public function getMaxTokenLength()
+ {
+ return $this->getViewState('MaxTokenLength',6);
+ }
+
+ /**
+ * @param integer the maximum length of the token. It must be between 2 and 40.
+ */
+ public function setMaxTokenLength($value)
+ {
+ $length=TPropertyValue::ensureInteger($value);
+ if($length>=self::MIN_TOKEN_LENGTH && $length<=self::MAX_TOKEN_LENGTH)
+ $this->setViewState('MaxTokenLength',$length,6);
+ else
+ throw new TConfigurationException('captcha_maxtokenlength_invalid',self::MIN_TOKEN_LENGTH,self::MAX_TOKEN_LENGTH);
+ }
+
+ /**
+ * @return boolean whether the token should be treated as case-sensitive. Defaults to true.
+ */
+ public function getCaseSensitive()
+ {
+ return $this->getViewState('CaseSensitive',true);
+ }
+
+ /**
+ * @param boolean whether the token should be treated as case-sensitive. If false, only upper-case letters will appear in the token.
+ */
+ public function setCaseSensitive($value)
+ {
+ $this->setViewState('CaseSensitive',TPropertyValue::ensureBoolean($value),true);
+ }
+
+ /**
+ * @return string the characters that may appear in the token. Defaults to '234578adefhijmnrtABDEFGHJLMNRT'.
+ */
+ public function getTokenAlphabet()
+ {
+ return $this->getViewState('TokenAlphabet','234578adefhijmnrtABDEFGHJLMNRT');
+ }
+
+ /**
+ * @param string the characters that may appear in the token. At least 2 characters must be specified.
+ */
+ public function setTokenAlphabet($value)
+ {
+ if(strlen($value)<2)
+ throw new TConfigurationException('captcha_tokenalphabet_invalid');
+ $this->setViewState('TokenAlphabet',$value,'234578adefhijmnrtABDEFGHJLMNRT');
+ }
+
+ /**
+ * @return integer the number of seconds that a generated token will remain valid. Defaults to 600 seconds (10 minutes).
+ */
+ public function getTokenExpiry()
+ {
+ return $this->getViewState('TokenExpiry',600);
+ }
+
+ /**
+ * @param integer the number of seconds that a generated token will remain valid. A value smaller than 1 means the token will not expire.
+ */
+ public function setTokenExpiry($value)
+ {
+ $this->setViewState('TokenExpiry',TPropertyValue::ensureInteger($value),600);
+ }
+
+ /**
+ * @return boolean whether the background of the token image should be variated during postbacks. Defaults to false.
+ */
+ public function getChangingTokenBackground()
+ {
+ return $this->getViewState('ChangingTokenBackground',false);
+ }
+
+ /**
+ * @param boolean whether the background of the token image should be variated during postbacks.
+ */
+ public function setChangingTokenBackground($value)
+ {
+ $this->setViewState('ChangingTokenBackground',TPropertyValue::ensureBoolean($value),false);
+ }
+
+ /**
+ * @return integer how many times a generated token can be tested. Defaults to 5.
+ */
+ public function getTestLimit()
+ {
+ return $this->getViewState('TestLimit',5);
+ }
+
+ /**
+ * @param integer how many times a generated token can be tested. For unlimited tests, set it to 0.
+ */
+ public function setTestLimit($value)
+ {
+ $this->setViewState('TestLimit',TPropertyValue::ensureInteger($value),5);
+ }
+
+ /**
+ * @return boolean whether the currently generated token has expired.
+ */
+ public function getIsTokenExpired()
+ {
+ if(($expiry=$this->getTokenExpiry())>0 && ($start=$this->getViewState('TokenGenerated',0))>0)
+ return $expiry+$start<time();
+ else
+ return false;
+ }
+
+ /**
+ * @return string the public key used for generating the token. A random one will be generated and returned if this is not set.
+ */
+ public function getPublicKey()
+ {
+ if(($publicKey=$this->getViewState('PublicKey',''))==='')
+ {
+ $publicKey=$this->generateRandomKey();
+ $this->setPublicKey($publicKey);
+ }
+ return $publicKey;
+ }
+
+ /**
+ * @param string the public key used for generating the token. A random one will be generated if this is not set.
+ */
+ public function setPublicKey($value)
+ {
+ $this->setViewState('PublicKey',$value,'');
+ }
+
+ /**
+ * @return string the token that will be displayed
+ */
+ public function getToken()
+ {
+ return $this->generateToken($this->getPublicKey(),$this->getPrivateKey(),$this->getTokenAlphabet(),$this->getTokenLength(),$this->getCaseSensitive());
+ }
+
+ /**
+ * @return integer the length of the token to be generated.
+ */
+ protected function getTokenLength()
+ {
+ if(($tokenLength=$this->getViewState('TokenLength'))===null)
+ {
+ $minLength=$this->getMinTokenLength();
+ $maxLength=$this->getMaxTokenLength();
+ if($minLength>$maxLength)
+ $tokenLength=rand($maxLength,$minLength);
+ else if($minLength<$maxLength)
+ $tokenLength=rand($minLength,$maxLength);
+ else
+ $tokenLength=$minLength;
+ $this->setViewState('TokenLength',$tokenLength);
+ }
+ return $tokenLength;
+ }
+
+ /**
+ * @return string the private key used for generating the token. This is randomly generated and kept in a file for persistency.
+ */
+ public function getPrivateKey()
+ {
+ if($this->_privateKey===null)
+ {
+ $fileName=$this->generatePrivateKeyFile();
+ $content=file_get_contents($fileName);
+ $matches=array();
+ if(preg_match("/privateKey='(.*?)'/ms",$content,$matches)>0)
+ $this->_privateKey=$matches[1];
+ else
+ throw new TConfigurationException('captcha_privatekey_unknown');
+ }
+ return $this->_privateKey;
+ }
+
+ /**
+ * Validates a user input with the token.
+ * @param string user input
+ * @return boolean if the user input is not the same as the token.
+ */
+ public function validate($input)
+ {
+ $number=$this->getViewState('TestNumber',0);
+ if(!$this->_validated)
+ {
+ $this->setViewState('TestNumber',++$number);
+ $this->_validated=true;
+ }
+ if($this->getIsTokenExpired() || (($limit=$this->getTestLimit())>0 && $number>$limit))
+ {
+ $this->regenerateToken();
+ return false;
+ }
+ return ($this->getToken()===($this->getCaseSensitive()?$input:strtoupper($input)));
+ }
+
+ /**
+ * Regenerates the token to be displayed.
+ * By default, a token, once generated, will remain the same during the following page postbacks.
+ * Calling this method will generate a new token.
+ */
+ public function regenerateToken()
+ {
+ $this->clearViewState('TokenLength');
+ $this->setPublicKey('');
+ $this->clearViewState('TokenGenerated');
+ $this->clearViewState('RandomSeed');
+ $this->clearViewState('TestNumber',0);
+ }
+
+ /**
+ * Configures the image URL that shows the token.
+ * @param mixed event parameter
+ */
+ public function onPreRender($param)
+ {
+ parent::onPreRender($param);
+ if(!self::checkRequirements())
+ throw new TConfigurationException('captcha_imagettftext_required');
+ if(!$this->getViewState('TokenGenerated',0))
+ {
+ $manager=$this->getApplication()->getAssetManager();
+ $manager->publishFilePath($this->getFontFile());
+ $url=$manager->publishFilePath($this->getCaptchaScriptFile());
+ $url.='?options='.urlencode($this->getTokenImageOptions());
+ $this->setImageUrl($url);
+
+ $this->setViewState('TokenGenerated',time());
+ }
+ }
+
+ /**
+ * @return string the options to be passed to the token image generator
+ */
+ protected function getTokenImageOptions()
+ {
+ $privateKey=$this->getPrivateKey(); // call this method to ensure private key is generated
+ $token=$this->getToken();
+ $options=array();
+ $options['publicKey']=$this->getPublicKey();
+ $options['tokenLength']=strlen($token);
+ $options['caseSensitive']=$this->getCaseSensitive();
+ $options['alphabet']=$this->getTokenAlphabet();
+ $options['fontSize']=$this->getTokenFontSize();
+ $options['theme']=$this->getTokenImageTheme();
+ if(($randomSeed=$this->getViewState('RandomSeed',0))===0)
+ {
+ $randomSeed=(int)(microtime()*1000000);
+ $this->setViewState('RandomSeed',$randomSeed);
+ }
+ $options['randomSeed']=$this->getChangingTokenBackground()?0:$randomSeed;
+ $str=serialize($options);
+ return base64_encode(md5($privateKey.$str).$str);
+ }
+
+ /**
+ * @return string the file path of the PHP script generating the token image
+ */
+ protected function getCaptchaScriptFile()
+ {
+ return dirname(__FILE__).DIRECTORY_SEPARATOR.'assets'.DIRECTORY_SEPARATOR.'captcha.php';
+ }
+
+ protected function getFontFile()
+ {
+ return dirname(__FILE__).DIRECTORY_SEPARATOR.'assets'.DIRECTORY_SEPARATOR.'verase.ttf';
+ }
+
+ /**
+ * Generates a file with a randomly generated private key.
+ * @return string the path of the file keeping the private key
+ */
+ protected function generatePrivateKeyFile()
+ {
+ $captchaScript=$this->getCaptchaScriptFile();
+ $path=dirname($this->getApplication()->getAssetManager()->getPublishedPath($captchaScript));
+ $fileName=$path.DIRECTORY_SEPARATOR.'captcha_key.php';
+ if(!is_file($fileName))
+ {
+ @mkdir($path);
+ $key=$this->generateRandomKey();
+ $content="<?php
+\$privateKey='$key';
+?>";
+ file_put_contents($fileName,$content);
+ }
+ return $fileName;
+ }
+
+ /**
+ * @return string a randomly generated key
+ */
+ protected function generateRandomKey()
+ {
+ return md5(rand().rand().rand().rand());
+ }
+
+ /**
+ * Generates the token.
+ * @param string public key
+ * @param string private key
+ * @param integer the length of the token
+ * @param boolean whether the token is case sensitive
+ * @return string the token generated.
+ */
+ protected function generateToken($publicKey,$privateKey,$alphabet,$tokenLength,$caseSensitive)
+ {
+ $token=substr($this->hash2string(md5($publicKey.$privateKey),$alphabet).$this->hash2string(md5($privateKey.$publicKey),$alphabet),0,$tokenLength);
+ return $caseSensitive?$token:strtoupper($token);
+ }
+
+ /**
+ * Converts a hash string into a string with characters consisting of alphanumeric characters.
+ * @param string the hexadecimal representation of the hash string
+ * @param string the alphabet used to represent the converted string. If empty, it means '234578adefhijmnrtwyABDEFGHIJLMNQRTWY', which excludes those confusing characters.
+ * @return string the converted string
+ */
+ protected function hash2string($hex,$alphabet='')
+ {
+ if(strlen($alphabet)<2)
+ $alphabet='234578adefhijmnrtABDEFGHJLMNQRT';
+ $hexLength=strlen($hex);
+ $base=strlen($alphabet);
+ $result='';
+ for($i=0;$i<$hexLength;$i+=6)
+ {
+ $number=hexdec(substr($hex,$i,6));
+ while($number)
+ {
+ $result.=$alphabet[$number%$base];
+ $number=floor($number/$base);
+ }
+ }
+ return $result;
+ }
+
+ /**
+ * Checks the requirements needed for generating CAPTCHA images.
+ * TCaptach requires GD2 with TrueType font support and PNG image support.
+ * @return boolean whether the requirements are satisfied.
+ */
+ public static function checkRequirements()
+ {
+ return extension_loaded('gd') && function_exists('imagettftext') && function_exists('imagepng');
+ }
+}
+
diff --git a/framework/Web/UI/WebControls/TCaptchaValidator.php b/framework/Web/UI/WebControls/TCaptchaValidator.php
index 9eca42fb..23943971 100644
--- a/framework/Web/UI/WebControls/TCaptchaValidator.php
+++ b/framework/Web/UI/WebControls/TCaptchaValidator.php
@@ -1,127 +1,127 @@
-<?php
-/**
- * TCaptchaValidator class file
- *
- * @author Qiang Xue <qiang.xue@gmail.com>
- * @link http://www.pradosoft.com/
- * @copyright Copyright &copy; 2005-2012 PradoSoft
- * @license http://www.pradosoft.com/license/
- * @version $Id$
- * @package System.Web.UI.WebControls
- */
-
-Prado::using('System.Web.UI.WebControls.TBaseValidator');
-Prado::using('System.Web.UI.WebControls.TCaptcha');
-
-/**
- * TCaptchaValidator class
- *
- * Notice: while this class is easy to use and implement, it does not provide full security.
- * In fact, it's easy to bypass the checks reusing old, already-validated tokens (reply attack).
- * A better alternative is provided by {@link TReCaptchaValidator}.
- *
- * TCaptchaValidator validates user input against a CAPTCHA represented by
- * a {@link TCaptcha} control. The input control fails validation if its value
- * is not the same as the token displayed in CAPTCHA. Note, if the user does
- * not enter any thing, it is still considered as failing the validation.
- *
- * To use TCaptchaValidator, specify the {@link setControlToValidate ControlToValidate}
- * to be the ID path of the input control (usually a {@link TTextBox} control}.
- * Also specify the {@link setCaptchaControl CaptchaControl} to be the ID path of
- * the CAPTCHA control that the user input should be compared with.
- *
- * @author Qiang Xue <qiang.xue@gmail.com>
- * @version $Id$
- * @package System.Web.UI.WebControls
- * @since 3.1.1
- */
-class TCaptchaValidator extends TBaseValidator
-{
- /**
- * Gets the name of the javascript class responsible for performing validation for this control.
- * This method overrides the parent implementation.
- * @return string the javascript class name
- */
- protected function getClientClassName()
- {
- return 'Prado.WebUI.TCaptchaValidator';
- }
-
- /**
- * @return string the ID path of the CAPTCHA control to validate
- */
- public function getCaptchaControl()
- {
- return $this->getViewState('CaptchaControl','');
- }
-
- /**
- * Sets the ID path of the CAPTCHA control to validate.
- * The ID path is the dot-connected IDs of the controls reaching from
- * the validator's naming container to the target control.
- * @param string the ID path
- */
- public function setCaptchaControl($value)
- {
- $this->setViewState('CaptchaControl',TPropertyValue::ensureString($value),'');
- }
-
- /**
- * This method overrides the parent's implementation.
- * The validation succeeds if the input control has the same value
- * as the one displayed in the corresponding CAPTCHA control.
- *
- * @return boolean whether the validation succeeds
- */
- protected function evaluateIsValid()
- {
- $value=$this->getValidationValue($this->getValidationTarget());
- $control=$this->findCaptchaControl();
- return $control->validate(trim($value));
- }
-
- /**
- * @return TCaptchaControl the CAPTCHA control to be validated against
- * @throws TConfigurationException if the CAPTCHA cannot be found according to {@link setCaptchaControl CaptchaControl}
- */
- protected function findCaptchaControl()
- {
- if(($id=$this->getCaptchaControl())==='')
- throw new TConfigurationException('captchavalidator_captchacontrol_required');
- else if(($control=$this->findControl($id))===null)
- throw new TConfigurationException('captchavalidator_captchacontrol_inexistent',$id);
- else if(!($control instanceof TCaptcha))
- throw new TConfigurationException('captchavalidator_captchacontrol_invalid',$id);
- else
- return $control;
- }
-
- /**
- * Returns an array of javascript validator options.
- * @return array javascript validator options.
- */
- protected function getClientScriptOptions()
- {
- $options=parent::getClientScriptOptions();
- $control=$this->findCaptchaControl();
- if($control->getCaseSensitive())
- {
- $options['TokenHash']=$this->generateTokenHash($control->getToken());
- $options['CaseSensitive']=true;
- }
- else
- {
- $options['TokenHash']=$this->generateTokenHash(strtoupper($control->getToken()));
- $options['CaseSensitive']=false;
- }
- return $options;
- }
-
- private function generateTokenHash($token)
- {
- for($h=0,$i=strlen($token)-1;$i>=0;--$i)
- $h+=ord($token[$i]);
- return $h;
- }
-}
-
+<?php
+/**
+ * TCaptchaValidator class file
+ *
+ * @author Qiang Xue <qiang.xue@gmail.com>
+ * @link http://www.pradosoft.com/
+ * @copyright Copyright &copy; 2005-2012 PradoSoft
+ * @license http://www.pradosoft.com/license/
+ * @version $Id$
+ * @package System.Web.UI.WebControls
+ */
+
+Prado::using('System.Web.UI.WebControls.TBaseValidator');
+Prado::using('System.Web.UI.WebControls.TCaptcha');
+
+/**
+ * TCaptchaValidator class
+ *
+ * Notice: while this class is easy to use and implement, it does not provide full security.
+ * In fact, it's easy to bypass the checks reusing old, already-validated tokens (reply attack).
+ * A better alternative is provided by {@link TReCaptchaValidator}.
+ *
+ * TCaptchaValidator validates user input against a CAPTCHA represented by
+ * a {@link TCaptcha} control. The input control fails validation if its value
+ * is not the same as the token displayed in CAPTCHA. Note, if the user does
+ * not enter any thing, it is still considered as failing the validation.
+ *
+ * To use TCaptchaValidator, specify the {@link setControlToValidate ControlToValidate}
+ * to be the ID path of the input control (usually a {@link TTextBox} control}.
+ * Also specify the {@link setCaptchaControl CaptchaControl} to be the ID path of
+ * the CAPTCHA control that the user input should be compared with.
+ *
+ * @author Qiang Xue <qiang.xue@gmail.com>
+ * @version $Id$
+ * @package System.Web.UI.WebControls
+ * @since 3.1.1
+ */
+class TCaptchaValidator extends TBaseValidator
+{
+ /**
+ * Gets the name of the javascript class responsible for performing validation for this control.
+ * This method overrides the parent implementation.
+ * @return string the javascript class name
+ */
+ protected function getClientClassName()
+ {
+ return 'Prado.WebUI.TCaptchaValidator';
+ }
+
+ /**
+ * @return string the ID path of the CAPTCHA control to validate
+ */
+ public function getCaptchaControl()
+ {
+ return $this->getViewState('CaptchaControl','');
+ }
+
+ /**
+ * Sets the ID path of the CAPTCHA control to validate.
+ * The ID path is the dot-connected IDs of the controls reaching from
+ * the validator's naming container to the target control.
+ * @param string the ID path
+ */
+ public function setCaptchaControl($value)
+ {
+ $this->setViewState('CaptchaControl',TPropertyValue::ensureString($value),'');
+ }
+
+ /**
+ * This method overrides the parent's implementation.
+ * The validation succeeds if the input control has the same value
+ * as the one displayed in the corresponding CAPTCHA control.
+ *
+ * @return boolean whether the validation succeeds
+ */
+ protected function evaluateIsValid()
+ {
+ $value=$this->getValidationValue($this->getValidationTarget());
+ $control=$this->findCaptchaControl();
+ return $control->validate(trim($value));
+ }
+
+ /**
+ * @return TCaptchaControl the CAPTCHA control to be validated against
+ * @throws TConfigurationException if the CAPTCHA cannot be found according to {@link setCaptchaControl CaptchaControl}
+ */
+ protected function findCaptchaControl()
+ {
+ if(($id=$this->getCaptchaControl())==='')
+ throw new TConfigurationException('captchavalidator_captchacontrol_required');
+ else if(($control=$this->findControl($id))===null)
+ throw new TConfigurationException('captchavalidator_captchacontrol_inexistent',$id);
+ else if(!($control instanceof TCaptcha))
+ throw new TConfigurationException('captchavalidator_captchacontrol_invalid',$id);
+ else
+ return $control;
+ }
+
+ /**
+ * Returns an array of javascript validator options.
+ * @return array javascript validator options.
+ */
+ protected function getClientScriptOptions()
+ {
+ $options=parent::getClientScriptOptions();
+ $control=$this->findCaptchaControl();
+ if($control->getCaseSensitive())
+ {
+ $options['TokenHash']=$this->generateTokenHash($control->getToken());
+ $options['CaseSensitive']=true;
+ }
+ else
+ {
+ $options['TokenHash']=$this->generateTokenHash(strtoupper($control->getToken()));
+ $options['CaseSensitive']=false;
+ }
+ return $options;
+ }
+
+ private function generateTokenHash($token)
+ {
+ for($h=0,$i=strlen($token)-1;$i>=0;--$i)
+ $h+=ord($token[$i]);
+ return $h;
+ }
+}
+
diff --git a/framework/Web/UI/WebControls/TCheckBox.php b/framework/Web/UI/WebControls/TCheckBox.php
index 641497ac..fe8bfbca 100644
--- a/framework/Web/UI/WebControls/TCheckBox.php
+++ b/framework/Web/UI/WebControls/TCheckBox.php
@@ -1,131 +1,131 @@
-<?php
-/**
- * TCheckBox class file
- *
- * @author Qiang Xue <qiang.xue@gmail.com>
- * @link http://www.pradosoft.com/
+<?php
+/**
+ * TCheckBox class file
+ *
+ * @author Qiang Xue <qiang.xue@gmail.com>
+ * @link http://www.pradosoft.com/
* @copyright Copyright &copy; 2005-2012 PradoSoft
- * @license http://www.pradosoft.com/license/
- * @version $Id$
- * @package System.Web.UI.WebControls
- */
-
-/**
- * TCheckBox class
- *
- * TCheckBox displays a check box on the page.
- * You can specify the caption to display beside the check box by setting
- * the {@link setText Text} property. The caption can appear either on the right
- * or left of the check box, which is determined by the {@link setTextAlign TextAlign}
- * property.
- *
- * To determine whether the TCheckBox component is checked, test the {@link getChecked Checked}
- * property. The {@link onCheckedChanged OnCheckedChanged} event is raised when
- * the {@link getChecked Checked} state of the TCheckBox component changes
- * between posts to the server. You can provide an event handler for
- * the {@link onCheckedChanged OnCheckedChanged} event to to programmatically
- * control the actions performed when the state of the TCheckBox component changes
- * between posts to the server.
- *
- * If {@link setAutoPostBack AutoPostBack} is set true, changing the check box state
- * will cause postback action. And if {@link setCausesValidation CausesValidation}
- * is true, validation will also be processed, which can be further restricted within
- * a {@link setValidationGroup ValidationGroup}.
- *
- * Note, {@link setText Text} is rendered as is. Make sure it does not contain unwanted characters
- * that may bring security vulnerabilities.
- *
- * @author Qiang Xue <qiang.xue@gmail.com>
- * @version $Id$
- * @package System.Web.UI.WebControls
- * @since 3.0
- */
-class TCheckBox extends TWebControl implements IPostBackDataHandler, IValidatable, IDataRenderer, ISurroundable
-{
- private $_dataChanged=false;
+ * @license http://www.pradosoft.com/license/
+ * @version $Id$
+ * @package System.Web.UI.WebControls
+ */
+
+/**
+ * TCheckBox class
+ *
+ * TCheckBox displays a check box on the page.
+ * You can specify the caption to display beside the check box by setting
+ * the {@link setText Text} property. The caption can appear either on the right
+ * or left of the check box, which is determined by the {@link setTextAlign TextAlign}
+ * property.
+ *
+ * To determine whether the TCheckBox component is checked, test the {@link getChecked Checked}
+ * property. The {@link onCheckedChanged OnCheckedChanged} event is raised when
+ * the {@link getChecked Checked} state of the TCheckBox component changes
+ * between posts to the server. You can provide an event handler for
+ * the {@link onCheckedChanged OnCheckedChanged} event to to programmatically
+ * control the actions performed when the state of the TCheckBox component changes
+ * between posts to the server.
+ *
+ * If {@link setAutoPostBack AutoPostBack} is set true, changing the check box state
+ * will cause postback action. And if {@link setCausesValidation CausesValidation}
+ * is true, validation will also be processed, which can be further restricted within
+ * a {@link setValidationGroup ValidationGroup}.
+ *
+ * Note, {@link setText Text} is rendered as is. Make sure it does not contain unwanted characters
+ * that may bring security vulnerabilities.
+ *
+ * @author Qiang Xue <qiang.xue@gmail.com>
+ * @version $Id$
+ * @package System.Web.UI.WebControls
+ * @since 3.0
+ */
+class TCheckBox extends TWebControl implements IPostBackDataHandler, IValidatable, IDataRenderer, ISurroundable
+{
+ private $_dataChanged=false;
private $_isValid=true;
-
- /**
- * @return string tag name of the button
- */
- protected function getTagName()
- {
- return 'input';
- }
-
- /**
- * Loads user input data.
- * This method is primarly used by framework developers.
- * @param string the key that can be used to retrieve data from the input data collection
- * @param array the input data collection
- * @return boolean whether the data of the control has been changed
- */
- public function loadPostData($key,$values)
- {
- $checked=$this->getChecked();
- if($newChecked=isset($values[$key]))
- $this->setValue($values[$key]);
- $this->setChecked($newChecked);
- return $this->_dataChanged=($newChecked!==$checked);
- }
-
- /**
- * Raises postdata changed event.
- * This method raises {@link onCheckedChanged OnCheckedChanged} event.
- * This method is primarly used by framework developers.
- */
- public function raisePostDataChangedEvent()
- {
- if($this->getAutoPostBack() && $this->getCausesValidation())
- $this->getPage()->validate($this->getValidationGroup());
- $this->onCheckedChanged(null);
- }
-
- /**
- * Raises <b>OnCheckedChanged</b> event when {@link getChecked Checked} changes value during postback.
- * If you override this method, be sure to call the parent implementation
- * so that the event delegates can be invoked.
- * @param TEventParameter event parameter to be passed to the event handlers
- */
- public function onCheckedChanged($param)
- {
- $this->raiseEvent('OnCheckedChanged',$this,$param);
- }
-
- /**
- * Registers the checkbox to receive postback data during postback.
- * This is necessary because a checkbox if unchecked, when postback,
- * does not have direct mapping between post data and the checkbox name.
- *
- * This method overrides the parent implementation and is invoked before render.
- * @param mixed event parameter
- */
- public function onPreRender($param)
- {
- parent::onPreRender($param);
- if($this->getEnabled(true))
- $this->getPage()->registerRequiresPostData($this);
- }
-
- /**
- * Returns a value indicating whether postback has caused the control data change.
- * This method is required by the IPostBackDataHandler interface.
- * @return boolean whether postback has caused the control data change. False if the page is not in postback mode.
- */
- public function getDataChanged()
- {
- return $this->_dataChanged;
- }
-
- /**
- * Returns the value of the property that needs validation.
- * @return mixed the property value to be validated
- */
- public function getValidationPropertyValue()
- {
- return $this->getChecked();
- }
-
+
+ /**
+ * @return string tag name of the button
+ */
+ protected function getTagName()
+ {
+ return 'input';
+ }
+
+ /**
+ * Loads user input data.
+ * This method is primarly used by framework developers.
+ * @param string the key that can be used to retrieve data from the input data collection
+ * @param array the input data collection
+ * @return boolean whether the data of the control has been changed
+ */
+ public function loadPostData($key,$values)
+ {
+ $checked=$this->getChecked();
+ if($newChecked=isset($values[$key]))
+ $this->setValue($values[$key]);
+ $this->setChecked($newChecked);
+ return $this->_dataChanged=($newChecked!==$checked);
+ }
+
+ /**
+ * Raises postdata changed event.
+ * This method raises {@link onCheckedChanged OnCheckedChanged} event.
+ * This method is primarly used by framework developers.
+ */
+ public function raisePostDataChangedEvent()
+ {
+ if($this->getAutoPostBack() && $this->getCausesValidation())
+ $this->getPage()->validate($this->getValidationGroup());
+ $this->onCheckedChanged(null);
+ }
+
+ /**
+ * Raises <b>OnCheckedChanged</b> event when {@link getChecked Checked} changes value during postback.
+ * If you override this method, be sure to call the parent implementation
+ * so that the event delegates can be invoked.
+ * @param TEventParameter event parameter to be passed to the event handlers
+ */
+ public function onCheckedChanged($param)
+ {
+ $this->raiseEvent('OnCheckedChanged',$this,$param);
+ }
+
+ /**
+ * Registers the checkbox to receive postback data during postback.
+ * This is necessary because a checkbox if unchecked, when postback,
+ * does not have direct mapping between post data and the checkbox name.
+ *
+ * This method overrides the parent implementation and is invoked before render.
+ * @param mixed event parameter
+ */
+ public function onPreRender($param)
+ {
+ parent::onPreRender($param);
+ if($this->getEnabled(true))
+ $this->getPage()->registerRequiresPostData($this);
+ }
+
+ /**
+ * Returns a value indicating whether postback has caused the control data change.
+ * This method is required by the IPostBackDataHandler interface.
+ * @return boolean whether postback has caused the control data change. False if the page is not in postback mode.
+ */
+ public function getDataChanged()
+ {
+ return $this->_dataChanged;
+ }
+
+ /**
+ * Returns the value of the property that needs validation.
+ * @return mixed the property value to be validated
+ */
+ public function getValidationPropertyValue()
+ {
+ return $this->getChecked();
+ }
+
/**
* Returns true if this control validated successfully.
* Defaults to true.
@@ -143,390 +143,390 @@ class TCheckBox extends TWebControl implements IPostBackDataHandler, IValidatabl
$this->_isValid=TPropertyValue::ensureBoolean($value);
}
- /**
- * @return string the text caption of the checkbox
- */
- public function getText()
- {
- return $this->getViewState('Text','');
- }
-
- /**
- * Sets the text caption of the checkbox.
- * @param string the text caption to be set
- */
- public function setText($value)
- {
- $this->setViewState('Text',$value,'');
- }
-
- /**
- * @return string the value of the checkbox. Defaults to empty.
- */
- public function getValue()
- {
- return $this->getViewState('Value','');
- }
-
- /**
- * @param string the value of the checkbox
- */
- public function setValue($value)
- {
- $this->setViewState('Value',TPropertyValue::ensureString($value),'');
- }
-
- /**
- * @return TTextAlign the alignment (Left or Right) of the text caption, defaults to TTextAlign::Right.
- */
- public function getTextAlign()
- {
- return $this->getViewState('TextAlign',TTextAlign::Right);
- }
-
- /**
- * @param TTextAlign the alignment of the text caption. Valid values include Left and Right.
- */
- public function setTextAlign($value)
- {
- $this->setViewState('TextAlign',TPropertyValue::ensureEnum($value,'TTextAlign'),TTextAlign::Right);
- }
-
- /**
- * @return boolean whether the checkbox is checked
- */
- public function getChecked()
- {
- return $this->getViewState('Checked',false);
- }
-
- /**
- * Sets a value indicating whether the checkbox is to be checked or not.
- * @param boolean whether the checkbox is to be checked or not.
- */
- public function setChecked($value)
- {
- $this->setViewState('Checked',TPropertyValue::ensureBoolean($value),false);
- }
-
- /**
- * Returns the value indicating whether the checkbox is checked.
- * This method is required by {@link IDataRenderer}.
- * It is the same as {@link getChecked()}.
- * @return boolean whether the checkbox is checked.
- * @see getChecked
- * @since 3.1.0
- */
- public function getData()
- {
- return $this->getChecked();
- }
-
- /**
- * Sets the value indicating whether the checkbox is to be checked or not.
- * This method is required by {@link IDataRenderer}.
- * It is the same as {@link setChecked()}.
- * @param boolean whether the checkbox is to be checked
- * @see setChecked
- * @since 3.1.0
- */
- public function setData($value)
- {
- $this->setChecked($value);
- }
-
- /**
- * @return boolean whether clicking on the checkbox will post the page.
- */
- public function getAutoPostBack()
- {
- return $this->getViewState('AutoPostBack',false);
- }
-
- /**
- * Sets a value indicating whether clicking on the checkbox will post the page.
- * @param boolean whether clicking on the checkbox will post the page.
- */
- public function setAutoPostBack($value)
- {
- $this->setViewState('AutoPostBack',TPropertyValue::ensureBoolean($value),false);
- }
-
- /**
- * @return boolean whether postback event triggered by this checkbox will cause input validation, default is true.
- */
- public function getCausesValidation()
- {
- return $this->getViewState('CausesValidation',true);
- }
-
- /**
- * Sets the value indicating whether postback event trigger by this checkbox will cause input validation.
- * @param boolean whether postback event trigger by this checkbox will cause input validation.
- */
- public function setCausesValidation($value)
- {
- $this->setViewState('CausesValidation',TPropertyValue::ensureBoolean($value),true);
- }
-
- /**
- * @return string the group of validators which the checkbox causes validation upon postback
- */
- public function getValidationGroup()
- {
- return $this->getViewState('ValidationGroup','');
- }
-
- /**
- * @param string the group of validators which the checkbox causes validation upon postback
- */
- public function setValidationGroup($value)
- {
- $this->setViewState('ValidationGroup',$value,'');
- }
-
- /**
- * @return string the id of the surrounding tag or this clientID if no such tag needed
- */
- public function getSurroundingTagID()
- {
- return $this->getSpanNeeded() ? $this->getClientID().'_parent' : $this->getClientID();
- }
-
- /**
- * Renders the checkbox control.
- * This method overrides the parent implementation by rendering a checkbox input element
- * and a span element if needed.
- * @param THtmlWriter the writer used for the rendering purpose
- */
- public function render($writer)
- {
- $this->getPage()->ensureRenderInForm($this);
- if($this->getHasStyle())
- $this->getStyle()->addAttributesToRender($writer);
- if(($tooltip=$this->getToolTip())!=='')
- $writer->addAttribute('title',$tooltip);
- if($this->getHasAttributes())
- {
- $attributes=$this->getAttributes();
- $value=$attributes->remove('value');
- // onclick js should only be added to input tag
- if(($onclick=$attributes->remove('onclick'))===null)
- $onclick='';
- if($attributes->getCount())
- $writer->addAttributes($attributes);
- if($value!==null)
- $attributes->add('value',$value);
- }
- else
- $onclick='';
- if($needspan=$this->getSpanNeeded())
- {
- $writer->addAttribute('id',$this->getSurroundingTagID());
- $writer->renderBeginTag('span');
- }
- $clientID=$this->getClientID();
- if(($text=$this->getText())!=='')
- {
- if($this->getTextAlign()===TTextAlign::Left)
- {
- $this->renderLabel($writer,$clientID,$text);
- $this->renderInputTag($writer,$clientID,$onclick);
- }
- else
- {
- $this->renderInputTag($writer,$clientID,$onclick);
- $this->renderLabel($writer,$clientID,$text);
- }
- }
- else
- $this->renderInputTag($writer,$clientID,$onclick);
- if($needspan)
- $writer->renderEndTag();
- }
-
- /**
- * @return TMap list of attributes to be rendered for label beside the checkbox
- */
- public function getLabelAttributes()
- {
- if($attributes=$this->getViewState('LabelAttributes',null))
- return $attributes;
- else
- {
- $attributes=new TAttributeCollection;
- $this->setViewState('LabelAttributes',$attributes,null);
- return $attributes;
- }
- }
-
- /**
- * @return TMap list of attributes to be rendered for the checkbox
- */
- public function getInputAttributes()
- {
- if($attributes=$this->getViewState('InputAttributes',null))
- return $attributes;
- else
- {
- $attributes=new TAttributeCollection;
- $this->setViewState('InputAttributes',$attributes,null);
- return $attributes;
- }
- }
-
- /**
- * @return string the value attribute to be rendered
- */
- protected function getValueAttribute()
- {
- if(($value=$this->getValue())!=='')
- return $value;
- else
- {
- $attributes=$this->getViewState('InputAttributes',null);
- if($attributes && $attributes->contains('value'))
- return $attributes->itemAt('value');
- else if($this->hasAttribute('value'))
- return $this->getAttribute('value');
- else
- return '';
- }
- }
-
- /**
- * @return boolean whether to render javascript.
- */
- public function getEnableClientScript()
- {
- return $this->getViewState('EnableClientScript',true);
- }
-
- /**
- * @param boolean whether to render javascript.
- */
- public function setEnableClientScript($value)
- {
- $this->setViewState('EnableClientScript',TPropertyValue::ensureBoolean($value),true);
- }
-
- /**
- * Check if we need a span tag to surround this control. The span tag will be created if
- * the Text property is set for this control.
- *
- * @return bool wether this control needs a surrounding span tag
- */
- protected function getSpanNeeded() {
- return $this->getText()!=='';
- }
-
- /**
- * Renders a label beside the checkbox.
- * @param THtmlWriter the writer for the rendering purpose
- * @param string checkbox id
- * @param string label text
- */
- protected function renderLabel($writer,$clientID,$text)
- {
- $writer->addAttribute('for',$clientID);
- if($attributes=$this->getViewState('LabelAttributes',null))
- $writer->addAttributes($attributes);
- $writer->renderBeginTag('label');
- $writer->write($text);
- $writer->renderEndTag();
- }
-
- /**
- * Renders a checkbox input element.
- * @param THtmlWriter the writer for the rendering purpose
- * @param string checkbox id
- * @param string onclick js
- */
- protected function renderInputTag($writer,$clientID,$onclick)
- {
- if($clientID!=='')
- $writer->addAttribute('id',$clientID);
- $writer->addAttribute('type','checkbox');
- if(($value=$this->getValueAttribute())!=='')
- $writer->addAttribute('value',$value);
- if(!empty($onclick))
- $writer->addAttribute('onclick',$onclick);
- if(($uniqueID=$this->getUniqueID())!=='')
- $writer->addAttribute('name',$uniqueID);
- if($this->getChecked())
- $writer->addAttribute('checked','checked');
- if(!$this->getEnabled(true))
- $writer->addAttribute('disabled','disabled');
-
- $page=$this->getPage();
- if($this->getEnabled(true)
- && $this->getEnableClientScript()
- && $this->getAutoPostBack()
- && $page->getClientSupportsJavaScript())
- {
- $this->renderClientControlScript($writer);
- }
-
- if(($accesskey=$this->getAccessKey())!=='')
- $writer->addAttribute('accesskey',$accesskey);
- if(($tabindex=$this->getTabIndex())>0)
- $writer->addAttribute('tabindex',"$tabindex");
- if($attributes=$this->getViewState('InputAttributes',null))
- $writer->addAttributes($attributes);
- $writer->renderBeginTag('input');
- $writer->renderEndTag();
- }
-
- /**
- * Renders the client-script code.
- */
- protected function renderClientControlScript($writer)
- {
- $cs = $this->getPage()->getClientScript();
- $cs->registerPostBackControl($this->getClientClassName(),$this->getPostBackOptions());
- }
-
- /**
- * Gets the name of the javascript class responsible for performing postback for this control.
- * This method overrides the parent implementation.
- * @return string the javascript class name
- */
- protected function getClientClassName()
- {
- return 'Prado.WebUI.TCheckBox';
- }
-
- /**
- * Gets the post back options for this checkbox.
- * @return array
- */
- protected function getPostBackOptions()
- {
- $options['ID'] = $this->getClientID();
- $options['ValidationGroup'] = $this->getValidationGroup();
- $options['CausesValidation'] = $this->getCausesValidation();
- $options['EventTarget'] = $this->getUniqueID();
- return $options;
- }
-}
-
-/**
- * TTextAlign class.
- * TTextAlign defines the enumerable type for the possible text alignments
- *
- * The following enumerable values are defined:
- * - Left: left aligned
- * - Right: right aligned
- *
- * @author Qiang Xue <qiang.xue@gmail.com>
- * @version $Id$
- * @package System.Web.UI.WebControls
- * @since 3.0.4
- */
-class TTextAlign extends TEnumerable
-{
- const Left='Left';
- const Right='Right';
-}
-
-?>
+ /**
+ * @return string the text caption of the checkbox
+ */
+ public function getText()
+ {
+ return $this->getViewState('Text','');
+ }
+
+ /**
+ * Sets the text caption of the checkbox.
+ * @param string the text caption to be set
+ */
+ public function setText($value)
+ {
+ $this->setViewState('Text',$value,'');
+ }
+
+ /**
+ * @return string the value of the checkbox. Defaults to empty.
+ */
+ public function getValue()
+ {
+ return $this->getViewState('Value','');
+ }
+
+ /**
+ * @param string the value of the checkbox
+ */
+ public function setValue($value)
+ {
+ $this->setViewState('Value',TPropertyValue::ensureString($value),'');
+ }
+
+ /**
+ * @return TTextAlign the alignment (Left or Right) of the text caption, defaults to TTextAlign::Right.
+ */
+ public function getTextAlign()
+ {
+ return $this->getViewState('TextAlign',TTextAlign::Right);
+ }
+
+ /**
+ * @param TTextAlign the alignment of the text caption. Valid values include Left and Right.
+ */
+ public function setTextAlign($value)
+ {
+ $this->setViewState('TextAlign',TPropertyValue::ensureEnum($value,'TTextAlign'),TTextAlign::Right);
+ }
+
+ /**
+ * @return boolean whether the checkbox is checked
+ */
+ public function getChecked()
+ {
+ return $this->getViewState('Checked',false);
+ }
+
+ /**
+ * Sets a value indicating whether the checkbox is to be checked or not.
+ * @param boolean whether the checkbox is to be checked or not.
+ */
+ public function setChecked($value)
+ {
+ $this->setViewState('Checked',TPropertyValue::ensureBoolean($value),false);
+ }
+
+ /**
+ * Returns the value indicating whether the checkbox is checked.
+ * This method is required by {@link IDataRenderer}.
+ * It is the same as {@link getChecked()}.
+ * @return boolean whether the checkbox is checked.
+ * @see getChecked
+ * @since 3.1.0
+ */
+ public function getData()
+ {
+ return $this->getChecked();
+ }
+
+ /**
+ * Sets the value indicating whether the checkbox is to be checked or not.
+ * This method is required by {@link IDataRenderer}.
+ * It is the same as {@link setChecked()}.
+ * @param boolean whether the checkbox is to be checked
+ * @see setChecked
+ * @since 3.1.0
+ */
+ public function setData($value)
+ {
+ $this->setChecked($value);
+ }
+
+ /**
+ * @return boolean whether clicking on the checkbox will post the page.
+ */
+ public function getAutoPostBack()
+ {
+ return $this->getViewState('AutoPostBack',false);
+ }
+
+ /**
+ * Sets a value indicating whether clicking on the checkbox will post the page.
+ * @param boolean whether clicking on the checkbox will post the page.
+ */
+ public function setAutoPostBack($value)
+ {
+ $this->setViewState('AutoPostBack',TPropertyValue::ensureBoolean($value),false);
+ }
+
+ /**
+ * @return boolean whether postback event triggered by this checkbox will cause input validation, default is true.
+ */
+ public function getCausesValidation()
+ {
+ return $this->getViewState('CausesValidation',true);
+ }
+
+ /**
+ * Sets the value indicating whether postback event trigger by this checkbox will cause input validation.
+ * @param boolean whether postback event trigger by this checkbox will cause input validation.
+ */
+ public function setCausesValidation($value)
+ {
+ $this->setViewState('CausesValidation',TPropertyValue::ensureBoolean($value),true);
+ }
+
+ /**
+ * @return string the group of validators which the checkbox causes validation upon postback
+ */
+ public function getValidationGroup()
+ {
+ return $this->getViewState('ValidationGroup','');
+ }
+
+ /**
+ * @param string the group of validators which the checkbox causes validation upon postback
+ */
+ public function setValidationGroup($value)
+ {
+ $this->setViewState('ValidationGroup',$value,'');
+ }
+
+ /**
+ * @return string the id of the surrounding tag or this clientID if no such tag needed
+ */
+ public function getSurroundingTagID()
+ {
+ return $this->getSpanNeeded() ? $this->getClientID().'_parent' : $this->getClientID();
+ }
+
+ /**
+ * Renders the checkbox control.
+ * This method overrides the parent implementation by rendering a checkbox input element
+ * and a span element if needed.
+ * @param THtmlWriter the writer used for the rendering purpose
+ */
+ public function render($writer)
+ {
+ $this->getPage()->ensureRenderInForm($this);
+ if($this->getHasStyle())
+ $this->getStyle()->addAttributesToRender($writer);
+ if(($tooltip=$this->getToolTip())!=='')
+ $writer->addAttribute('title',$tooltip);
+ if($this->getHasAttributes())
+ {
+ $attributes=$this->getAttributes();
+ $value=$attributes->remove('value');
+ // onclick js should only be added to input tag
+ if(($onclick=$attributes->remove('onclick'))===null)
+ $onclick='';
+ if($attributes->getCount())
+ $writer->addAttributes($attributes);
+ if($value!==null)
+ $attributes->add('value',$value);
+ }
+ else
+ $onclick='';
+ if($needspan=$this->getSpanNeeded())
+ {
+ $writer->addAttribute('id',$this->getSurroundingTagID());
+ $writer->renderBeginTag('span');
+ }
+ $clientID=$this->getClientID();
+ if(($text=$this->getText())!=='')
+ {
+ if($this->getTextAlign()===TTextAlign::Left)
+ {
+ $this->renderLabel($writer,$clientID,$text);
+ $this->renderInputTag($writer,$clientID,$onclick);
+ }
+ else
+ {
+ $this->renderInputTag($writer,$clientID,$onclick);
+ $this->renderLabel($writer,$clientID,$text);
+ }
+ }
+ else
+ $this->renderInputTag($writer,$clientID,$onclick);
+ if($needspan)
+ $writer->renderEndTag();
+ }
+
+ /**
+ * @return TMap list of attributes to be rendered for label beside the checkbox
+ */
+ public function getLabelAttributes()
+ {
+ if($attributes=$this->getViewState('LabelAttributes',null))
+ return $attributes;
+ else
+ {
+ $attributes=new TAttributeCollection;
+ $this->setViewState('LabelAttributes',$attributes,null);
+ return $attributes;
+ }
+ }
+
+ /**
+ * @return TMap list of attributes to be rendered for the checkbox
+ */
+ public function getInputAttributes()
+ {
+ if($attributes=$this->getViewState('InputAttributes',null))
+ return $attributes;
+ else
+ {
+ $attributes=new TAttributeCollection;
+ $this->setViewState('InputAttributes',$attributes,null);
+ return $attributes;
+ }
+ }
+
+ /**
+ * @return string the value attribute to be rendered
+ */
+ protected function getValueAttribute()
+ {
+ if(($value=$this->getValue())!=='')
+ return $value;
+ else
+ {
+ $attributes=$this->getViewState('InputAttributes',null);
+ if($attributes && $attributes->contains('value'))
+ return $attributes->itemAt('value');
+ else if($this->hasAttribute('value'))
+ return $this->getAttribute('value');
+ else
+ return '';
+ }
+ }
+
+ /**
+ * @return boolean whether to render javascript.
+ */
+ public function getEnableClientScript()
+ {
+ return $this->getViewState('EnableClientScript',true);
+ }
+
+ /**
+ * @param boolean whether to render javascript.
+ */
+ public function setEnableClientScript($value)
+ {
+ $this->setViewState('EnableClientScript',TPropertyValue::ensureBoolean($value),true);
+ }
+
+ /**
+ * Check if we need a span tag to surround this control. The span tag will be created if
+ * the Text property is set for this control.
+ *
+ * @return bool wether this control needs a surrounding span tag
+ */
+ protected function getSpanNeeded() {
+ return $this->getText()!=='';
+ }
+
+ /**
+ * Renders a label beside the checkbox.
+ * @param THtmlWriter the writer for the rendering purpose
+ * @param string checkbox id
+ * @param string label text
+ */
+ protected function renderLabel($writer,$clientID,$text)
+ {
+ $writer->addAttribute('for',$clientID);
+ if($attributes=$this->getViewState('LabelAttributes',null))
+ $writer->addAttributes($attributes);
+ $writer->renderBeginTag('label');
+ $writer->write($text);
+ $writer->renderEndTag();
+ }
+
+ /**
+ * Renders a checkbox input element.
+ * @param THtmlWriter the writer for the rendering purpose
+ * @param string checkbox id
+ * @param string onclick js
+ */
+ protected function renderInputTag($writer,$clientID,$onclick)
+ {
+ if($clientID!=='')
+ $writer->addAttribute('id',$clientID);
+ $writer->addAttribute('type','checkbox');
+ if(($value=$this->getValueAttribute())!=='')
+ $writer->addAttribute('value',$value);
+ if(!empty($onclick))
+ $writer->addAttribute('onclick',$onclick);
+ if(($uniqueID=$this->getUniqueID())!=='')
+ $writer->addAttribute('name',$uniqueID);
+ if($this->getChecked())
+ $writer->addAttribute('checked','checked');
+ if(!$this->getEnabled(true))
+ $writer->addAttribute('disabled','disabled');
+
+ $page=$this->getPage();
+ if($this->getEnabled(true)
+ && $this->getEnableClientScript()
+ && $this->getAutoPostBack()
+ && $page->getClientSupportsJavaScript())
+ {
+ $this->renderClientControlScript($writer);
+ }
+
+ if(($accesskey=$this->getAccessKey())!=='')
+ $writer->addAttribute('accesskey',$accesskey);
+ if(($tabindex=$this->getTabIndex())>0)
+ $writer->addAttribute('tabindex',"$tabindex");
+ if($attributes=$this->getViewState('InputAttributes',null))
+ $writer->addAttributes($attributes);
+ $writer->renderBeginTag('input');
+ $writer->renderEndTag();
+ }
+
+ /**
+ * Renders the client-script code.
+ */
+ protected function renderClientControlScript($writer)
+ {
+ $cs = $this->getPage()->getClientScript();
+ $cs->registerPostBackControl($this->getClientClassName(),$this->getPostBackOptions());
+ }
+
+ /**
+ * Gets the name of the javascript class responsible for performing postback for this control.
+ * This method overrides the parent implementation.
+ * @return string the javascript class name
+ */
+ protected function getClientClassName()
+ {
+ return 'Prado.WebUI.TCheckBox';
+ }
+
+ /**
+ * Gets the post back options for this checkbox.
+ * @return array
+ */
+ protected function getPostBackOptions()
+ {
+ $options['ID'] = $this->getClientID();
+ $options['ValidationGroup'] = $this->getValidationGroup();
+ $options['CausesValidation'] = $this->getCausesValidation();
+ $options['EventTarget'] = $this->getUniqueID();
+ return $options;
+ }
+}
+
+/**
+ * TTextAlign class.
+ * TTextAlign defines the enumerable type for the possible text alignments
+ *
+ * The following enumerable values are defined:
+ * - Left: left aligned
+ * - Right: right aligned
+ *
+ * @author Qiang Xue <qiang.xue@gmail.com>
+ * @version $Id$
+ * @package System.Web.UI.WebControls
+ * @since 3.0.4
+ */
+class TTextAlign extends TEnumerable
+{
+ const Left='Left';
+ const Right='Right';
+}
+
+?>
diff --git a/framework/Web/UI/WebControls/TCheckBoxColumn.php b/framework/Web/UI/WebControls/TCheckBoxColumn.php
index 9c1db114..e1a2e178 100644
--- a/framework/Web/UI/WebControls/TCheckBoxColumn.php
+++ b/framework/Web/UI/WebControls/TCheckBoxColumn.php
@@ -1,123 +1,123 @@
-<?php
-/**
- * TCheckBoxColumn class file
- *
- * @author Qiang Xue <qiang.xue@gmail.com>
- * @link http://www.pradosoft.com/
+<?php
+/**
+ * TCheckBoxColumn class file
+ *
+ * @author Qiang Xue <qiang.xue@gmail.com>
+ * @link http://www.pradosoft.com/
* @copyright Copyright &copy; 2005-2012 PradoSoft
- * @license http://www.pradosoft.com/license/
- * @version $Id$
- * @package System.Web.UI.WebControls
- */
-
-/**
- * TDataGridColumn class file
- */
-Prado::using('System.Web.UI.WebControls.TDataGridColumn');
-/**
- * TCheckBox class file
- */
-Prado::using('System.Web.UI.WebControls.TCheckBox');
-
-/**
- * TCheckBoxColumn class
- *
- * TCheckBoxColumn represents a checkbox column that is bound to a field in a data source.
- * The checked state of the checkboxes are determiend by the bound data at
- * {@link setDataField DataField}. If {@link setReadOnly ReadOnly} is false,
- * TCheckBoxColumn will display an enabled checkbox provided the cells are
- * in edit mode. Otherwise, the checkboxes will be disabled to prevent from editting.
- *
- * The checkbox control in the TCheckBoxColumn can be accessed by one of
- * the following two methods:
- * <code>
- * $datagridItem->CheckBoxColumnID->CheckBox
- * $datagridItem->CheckBoxColumnID->Controls[0]
- * </code>
- * The second method is possible because the checkbox control created within the
- * datagrid cell is the first child.
- *
- * @author Qiang Xue <qiang.xue@gmail.com>
- * @version $Id$
- * @package System.Web.UI.WebControls
- * @since 3.0
- */
-class TCheckBoxColumn extends TDataGridColumn
-{
- /**
- * @return string the field name from the data source to bind to the column
- */
- public function getDataField()
- {
- return $this->getViewState('DataField','');
- }
-
- /**
- * @param string the field name from the data source to bind to the column
- */
- public function setDataField($value)
- {
- $this->setViewState('DataField',$value,'');
- }
-
- /**
- * @return boolean whether the items in the column can be edited. Defaults to false.
- */
- public function getReadOnly()
- {
- return $this->getViewState('ReadOnly',false);
- }
-
- /**
- * @param boolean whether the items in the column can be edited
- */
- public function setReadOnly($value)
- {
- $this->setViewState('ReadOnly',TPropertyValue::ensureBoolean($value),false);
- }
-
- /**
- * Initializes the specified cell to its initial values.
- * This method overrides the parent implementation.
- * It creates a checkbox inside the cell.
- * If the column is read-only or if the item is not in edit mode,
- * the checkbox will be set disabled.
- * @param TTableCell the cell to be initialized.
- * @param integer the index to the Columns property that the cell resides in.
- * @param string the type of cell (Header,Footer,Item,AlternatingItem,EditItem,SelectedItem)
- */
- public function initializeCell($cell,$columnIndex,$itemType)
- {
- if($itemType===TListItemType::Item || $itemType===TListItemType::AlternatingItem || $itemType===TListItemType::SelectedItem || $itemType===TListItemType::EditItem)
- {
- $checkBox=new TCheckBox;
- if($this->getReadOnly() || $itemType!==TListItemType::EditItem)
- $checkBox->setEnabled(false);
- $cell->setHorizontalAlign('Center');
- $cell->getControls()->add($checkBox);
- $cell->registerObject('CheckBox',$checkBox);
- if($this->getDataField()!=='')
- $checkBox->attachEventHandler('OnDataBinding',array($this,'dataBindColumn'));
- }
- else
- parent::initializeCell($cell,$columnIndex,$itemType);
- }
-
- /**
- * Databinds a cell in the column.
- * This method is invoked when datagrid performs databinding.
- * It populates the content of the cell with the relevant data from data source.
- */
- public function dataBindColumn($sender,$param)
- {
- $item=$sender->getNamingContainer();
- $data=$item->getData();
- if(($field=$this->getDataField())!=='')
- $value=TPropertyValue::ensureBoolean($this->getDataFieldValue($data,$field));
- else
- $value=TPropertyValue::ensureBoolean($data);
- if($sender instanceof TCheckBox)
- $sender->setChecked($value);
- }
-}
-
+ * @license http://www.pradosoft.com/license/
+ * @version $Id$
+ * @package System.Web.UI.WebControls
+ */
+
+/**
+ * TDataGridColumn class file
+ */
+Prado::using('System.Web.UI.WebControls.TDataGridColumn');
+/**
+ * TCheckBox class file
+ */
+Prado::using('System.Web.UI.WebControls.TCheckBox');
+
+/**
+ * TCheckBoxColumn class
+ *
+ * TCheckBoxColumn represents a checkbox column that is bound to a field in a data source.
+ * The checked state of the checkboxes are determiend by the bound data at
+ * {@link setDataField DataField}. If {@link setReadOnly ReadOnly} is false,
+ * TCheckBoxColumn will display an enabled checkbox provided the cells are
+ * in edit mode. Otherwise, the checkboxes will be disabled to prevent from editting.
+ *
+ * The checkbox control in the TCheckBoxColumn can be accessed by one of
+ * the following two methods:
+ * <code>
+ * $datagridItem->CheckBoxColumnID->CheckBox
+ * $datagridItem->CheckBoxColumnID->Controls[0]
+ * </code>
+ * The second method is possible because the checkbox control created within the
+ * datagrid cell is the first child.
+ *
+ * @author Qiang Xue <qiang.xue@gmail.com>
+ * @version $Id$
+ * @package System.Web.UI.WebControls
+ * @since 3.0
+ */
+class TCheckBoxColumn extends TDataGridColumn
+{
+ /**
+ * @return string the field name from the data source to bind to the column
+ */
+ public function getDataField()
+ {
+ return $this->getViewState('DataField','');
+ }
+
+ /**
+ * @param string the field name from the data source to bind to the column
+ */
+ public function setDataField($value)
+ {
+ $this->setViewState('DataField',$value,'');
+ }
+
+ /**
+ * @return boolean whether the items in the column can be edited. Defaults to false.
+ */
+ public function getReadOnly()
+ {
+ return $this->getViewState('ReadOnly',false);
+ }
+
+ /**
+ * @param boolean whether the items in the column can be edited
+ */
+ public function setReadOnly($value)
+ {
+ $this->setViewState('ReadOnly',TPropertyValue::ensureBoolean($value),false);
+ }
+
+ /**
+ * Initializes the specified cell to its initial values.
+ * This method overrides the parent implementation.
+ * It creates a checkbox inside the cell.
+ * If the column is read-only or if the item is not in edit mode,
+ * the checkbox will be set disabled.
+ * @param TTableCell the cell to be initialized.
+ * @param integer the index to the Columns property that the cell resides in.
+ * @param string the type of cell (Header,Footer,Item,AlternatingItem,EditItem,SelectedItem)
+ */
+ public function initializeCell($cell,$columnIndex,$itemType)
+ {
+ if($itemType===TListItemType::Item || $itemType===TListItemType::AlternatingItem || $itemType===TListItemType::SelectedItem || $itemType===TListItemType::EditItem)
+ {
+ $checkBox=new TCheckBox;
+ if($this->getReadOnly() || $itemType!==TListItemType::EditItem)
+ $checkBox->setEnabled(false);
+ $cell->setHorizontalAlign('Center');
+ $cell->getControls()->add($checkBox);
+ $cell->registerObject('CheckBox',$checkBox);
+ if($this->getDataField()!=='')
+ $checkBox->attachEventHandler('OnDataBinding',array($this,'dataBindColumn'));
+ }
+ else
+ parent::initializeCell($cell,$columnIndex,$itemType);
+ }
+
+ /**
+ * Databinds a cell in the column.
+ * This method is invoked when datagrid performs databinding.
+ * It populates the content of the cell with the relevant data from data source.
+ */
+ public function dataBindColumn($sender,$param)
+ {
+ $item=$sender->getNamingContainer();
+ $data=$item->getData();
+ if(($field=$this->getDataField())!=='')
+ $value=TPropertyValue::ensureBoolean($this->getDataFieldValue($data,$field));
+ else
+ $value=TPropertyValue::ensureBoolean($data);
+ if($sender instanceof TCheckBox)
+ $sender->setChecked($value);
+ }
+}
+
diff --git a/framework/Web/UI/WebControls/TCheckBoxList.php b/framework/Web/UI/WebControls/TCheckBoxList.php
index 2f938174..3c298a02 100644
--- a/framework/Web/UI/WebControls/TCheckBoxList.php
+++ b/framework/Web/UI/WebControls/TCheckBoxList.php
@@ -1,499 +1,499 @@
-<?php
-/**
- * TCheckBoxList class file
- *
- * @author Qiang Xue <qiang.xue@gmail.com>
- * @link http://www.pradosoft.com/
- * @copyright Copyright &copy; 2005-2012 PradoSoft
- * @license http://www.pradosoft.com/license/
- * @version $Id$
- * @package System.Web.UI.WebControls
- */
-
-/**
- * Includes TListControl class
- */
-Prado::using('System.Web.UI.WebControls.TListControl');
-/**
- * Includes TRepeatInfo class
- */
-Prado::using('System.Web.UI.WebControls.TRepeatInfo');
-/**
- * Includes TCheckBox class
- */
-Prado::using('System.Web.UI.WebControls.TCheckBox');
-
-/**
- * TCheckBoxList class
- *
- * TCheckBoxList displays a list of checkboxes on a Web page.
- *
- * The layout of the checkbox list is specified via {@link setRepeatLayout RepeatLayout},
- * which can be either 'Table' (default) or 'Flow'.
- * A table layout uses HTML table cells to organize the checkboxes while
- * a flow layout uses line breaks to organize the checkboxes.
- * When the layout is using 'Table', {@link setCellPadding CellPadding} and
- * {@link setCellSpacing CellSpacing} can be used to adjust the cellpadding and
- * cellpadding of the table.
- *
- * The number of columns used to display the checkboxes is specified via
- * {@link setRepeatColumns RepeatColumns} property, while the {@link setRepeatDirection RepeatDirection}
- * governs the order of the items being rendered.
- *
- * The alignment of the text besides each checkbox can be specified via {@link setTextAlign TextAlign}.
- *
- * @author Qiang Xue <qiang.xue@gmail.com>
- * @version $Id$
- * @package System.Web.UI.WebControls
- * @since 3.0
- */
-class TCheckBoxList extends TListControl implements IRepeatInfoUser, INamingContainer, IPostBackDataHandler, IValidatable
-{
- private $_repeatedControl;
- private $_isEnabled;
- private $_changedEventRaised=false;
- private $_dataChanged=false;
- private $_isValid=true;
-
- /**
- * Constructor.
- * Remember to call parent implementation if you override this method
- */
- public function __construct()
- {
- parent::__construct();
- $this->_repeatedControl=$this->createRepeatedControl();
- $this->_repeatedControl->setEnableViewState(false);
- $this->_repeatedControl->setID('c0');
- $this->getControls()->add($this->_repeatedControl);
- }
-
- /**
- * Creates a control used for repetition (used as a template).
- * @return TControl the control to be repeated
- */
- protected function createRepeatedControl()
- {
- return new TCheckBox;
- }
-
- /**
- * Finds a control by ID.
- * This method overrides the parent implementation so that it always returns
- * the checkbox list itself (because the checkbox list does not have child controls.)
- * @param string control ID
- * @return TControl control being found
- */
- public function findControl($id)
- {
- return $this;
- }
-
- /**
- * @return boolean whether this control supports multiple selection. Always true for checkbox list.
- */
- protected function getIsMultiSelect()
- {
- return true;
- }
-
- /**
- * Creates a style object for the control.
- * This method creates a {@link TTableStyle} to be used by checkbox list.
- * @return TStyle control style to be used
- */
- protected function createStyle()
- {
- return new TTableStyle;
- }
-
- /**
- * @return TTextAlign the alignment of the text caption, defaults to TTextAlign::Right.
- */
- public function getTextAlign()
- {
- return $this->getViewState('TextAlign',TTextAlign::Right);
- }
-
- /**
- * @param TTextAlign the text alignment of the checkboxes
- */
- public function setTextAlign($value)
- {
- $this->setViewState('TextAlign',TPropertyValue::ensureEnum($value,'TTextAlign'),TTextAlign::Right);
- }
-
-
- /**
- * @return TRepeatInfo repeat information (primarily used by control developers)
- */
- protected function getRepeatInfo()
- {
- if(($repeatInfo=$this->getViewState('RepeatInfo',null))===null)
- {
- $repeatInfo=new TRepeatInfo;
- $this->setViewState('RepeatInfo',$repeatInfo,null);
- }
- return $repeatInfo;
- }
-
- /**
- * @return integer the number of columns that the list should be displayed with. Defaults to 0 meaning not set.
- */
- public function getRepeatColumns()
- {
- return $this->getRepeatInfo()->getRepeatColumns();
- }
-
- /**
- * @param integer the number of columns that the list should be displayed with.
- */
- public function setRepeatColumns($value)
- {
- $this->getRepeatInfo()->setRepeatColumns($value);
- }
-
- /**
- * @return string the direction of traversing the list, defaults to 'Vertical'
- */
- public function getRepeatDirection()
- {
- return $this->getRepeatInfo()->getRepeatDirection();
- }
-
- /**
- * @param string the direction (Vertical, Horizontal) of traversing the list
- */
- public function setRepeatDirection($value)
- {
- $this->getRepeatInfo()->setRepeatDirection($value);
- }
-
- /**
- * @return string how the list should be displayed, using table or using line breaks. Defaults to 'Table'.
- */
- public function getRepeatLayout()
- {
- return $this->getRepeatInfo()->getRepeatLayout();
- }
-
- /**
- * @param string how the list should be displayed, using table or using line breaks (Table, Flow)
- */
- public function setRepeatLayout($value)
- {
- $this->getRepeatInfo()->setRepeatLayout($value);
- }
-
- /**
- * @return integer the cellspacing for the table keeping the checkbox list. Defaults to -1, meaning not set.
- */
- public function getCellSpacing()
- {
- if($this->getHasStyle())
- return $this->getStyle()->getCellSpacing();
- else
- return -1;
- }
-
- /**
- * Sets the cellspacing for the table keeping the checkbox list.
- * @param integer the cellspacing for the table keeping the checkbox list.
- */
- public function setCellSpacing($value)
- {
- $this->getStyle()->setCellSpacing($value);
- }
-
- /**
- * @return integer the cellpadding for the table keeping the checkbox list. Defaults to -1, meaning not set.
- */
- public function getCellPadding()
- {
- if($this->getHasStyle())
- return $this->getStyle()->getCellPadding();
- else
- return -1;
- }
-
- /**
- * Sets the cellpadding for the table keeping the checkbox list.
- * @param integer the cellpadding for the table keeping the checkbox list.
- */
- public function setCellPadding($value)
- {
- $this->getStyle()->setCellPadding($value);
- }
-
- /**
- * Returns a value indicating whether this control contains header item.
- * This method is required by {@link IRepeatInfoUser} interface.
- * @return boolean always false.
- */
- public function getHasHeader()
- {
- return false;
- }
-
- /**
- * Returns a value indicating whether this control contains footer item.
- * This method is required by {@link IRepeatInfoUser} interface.
- * @return boolean always false.
- */
- public function getHasFooter()
- {
- return false;
- }
-
- /**
- * Returns a value indicating whether this control contains separator items.
- * This method is required by {@link IRepeatInfoUser} interface.
- * @return boolean always false.
- */
- public function getHasSeparators()
- {
- return false;
- }
-
- /**
- * @param boolean whether the control is to be enabled.
- */
- public function setEnabled($value)
- {
- parent::setEnabled($value);
- $value = !TPropertyValue::ensureBoolean($value);
- // if this is an active control,
- // and it's a callback,
- // and we can update clientside,
- // then update the 'disabled' attribute of the items.
- if(($this instanceof IActiveControl) &&
- $this->getPage()->getIsCallBack() &&
- $this->getActiveControl()->canUpdateClientSide())
- {
- $items = $this->getItems();
- $cs = $this->getPage()->getCallbackClient();
- $baseClientID = $this->getClientID().'_c';
- foreach($items as $index=>$item)
- {
- $cs->setAttribute($baseClientID.$index, 'disabled', $value);
- }
- }
- }
-
- /**
- * Returns a style used for rendering items.
- * This method is required by {@link IRepeatInfoUser} interface.
- * @param string item type (Header,Footer,Item,AlternatingItem,SelectedItem,EditItem,Separator,Pager)
- * @param integer index of the item being rendered
- * @return null
- */
- public function generateItemStyle($itemType,$index)
- {
- return null;
- }
-
- /**
- * Renders an item in the list.
- * This method is required by {@link IRepeatInfoUser} interface.
- * @param THtmlWriter writer for rendering purpose
- * @param TRepeatInfo repeat information
- * @param string item type (Header,Footer,Item,AlternatingItem,SelectedItem,EditItem,Separator,Pager)
- * @param integer zero-based index of the item in the item list
- */
- public function renderItem($writer,$repeatInfo,$itemType,$index)
- {
- $repeatedControl=$this->_repeatedControl;
- $item=$this->getItems()->itemAt($index);
- if($item->getHasAttributes())
- $repeatedControl->getAttributes()->copyFrom($item->getAttributes());
- else if($repeatedControl->getHasAttributes())
- $repeatedControl->getAttributes()->clear();
- $repeatedControl->setID("c$index");
- $repeatedControl->setText($item->getText());
- $repeatedControl->setChecked($item->getSelected());
- $repeatedControl->setAttribute('value',$item->getValue());
- $repeatedControl->setEnabled($this->_isEnabled && $item->getEnabled());
- $repeatedControl->setEnableClientScript(false);
- $repeatedControl->renderControl($writer);
- }
-
- /**
- * Loads user input data.
- * This method is primarly used by framework developers.
- * @param string the key that can be used to retrieve data from the input data collection
- * @param array the input data collection
- * @return boolean whether the data of the control has been changed
- */
- public function loadPostData($key,$values)
- {
- if($this->getEnabled(true))
- {
- $index=(int)substr($key,strlen($this->getUniqueID())+2);
- $this->ensureDataBound();
- if($index>=0 && $index<$this->getItemCount())
- {
- $item=$this->getItems()->itemAt($index);
- if($item->getEnabled())
- {
- $checked=isset($values[$key]);
- if($item->getSelected()!==$checked)
- {
- $item->setSelected($checked);
- if(!$this->_changedEventRaised)
- {
- $this->_changedEventRaised=true;
- return $this->_dataChanged=true;
- }
- }
- }
- }
- }
- return false;
- }
-
- /**
- * Raises postdata changed event.
- * This method is required by {@link IPostBackDataHandler} interface.
- * It is invoked by the framework when {@link getSelectedIndices SelectedIndices} property
- * is changed on postback.
- * This method is primarly used by framework developers.
- */
- public function raisePostDataChangedEvent()
- {
- if($this->getAutoPostBack() && $this->getCausesValidation())
- $this->getPage()->validate($this->getValidationGroup());
- $this->onSelectedIndexChanged(null);
- }
-
- /**
- * Registers for post data on postback.
- * This method overrides the parent implementation.
- * @param mixed event parameter
- */
- public function onPreRender($param)
- {
- parent::onPreRender($param);
- $this->_repeatedControl->setAutoPostBack($this->getAutoPostBack());
- $this->_repeatedControl->setCausesValidation($this->getCausesValidation());
- $this->_repeatedControl->setValidationGroup($this->getValidationGroup());
- $page=$this->getPage();
- $n=$this->getItemCount();
- for($i=0;$i<$n;++$i)
- {
- $this->_repeatedControl->setID("c$i");
- $page->registerRequiresPostData($this->_repeatedControl);
- }
- }
-
- /**
- * Wether the list should be rendered inside a span or not
- *
- *@return boolean true if we need a span
- */
- protected function getSpanNeeded ()
- {
- return $this->getRepeatLayout()===TRepeatLayout::Raw;
- }
-
- /**
- * Renders the checkbox list control.
- * This method overrides the parent implementation.
- * @param THtmlWriter writer for rendering purpose.
- */
- public function render($writer)
- {
- if($this->getItemCount()>0)
- {
- if ($needSpan=$this->getSpanNeeded())
- {
- $writer->addAttribute('id', $this->getClientId());
- $writer->renderBeginTag('span');
- }
- $this->_isEnabled=$this->getEnabled(true);
- $repeatInfo=$this->getRepeatInfo();
- $accessKey=$this->getAccessKey();
- $tabIndex=$this->getTabIndex();
- $this->_repeatedControl->setTextAlign($this->getTextAlign());
- $this->_repeatedControl->setAccessKey($accessKey);
- $this->_repeatedControl->setTabIndex($tabIndex);
- $this->setAccessKey('');
- $this->setTabIndex(0);
- $repeatInfo->renderRepeater($writer,$this);
- $this->setAccessKey($accessKey);
- $this->setTabIndex($tabIndex);
- if ($needSpan)
- $writer->renderEndTag();
- }
- //checkbox skipped the client control script in addAttributesToRender
- if($this->getEnabled(true)
- && $this->getEnableClientScript()
- && $this->getAutoPostBack()
- && $this->getPage()->getClientSupportsJavaScript())
- {
- $this->renderClientControlScript($writer);
- }
- }
-
- /**
- * Returns a value indicating whether postback has caused the control data change.
- * This method is required by the IPostBackDataHandler interface.
- * @return boolean whether postback has caused the control data change. False if the page is not in postback mode.
- */
- public function getDataChanged()
- {
- return $this->_dataChanged;
- }
-
- /**
- * Returns the value to be validated.
- * This methid is required by IValidatable interface.
- * @return mixed the value of the property to be validated.
- */
- public function getValidationPropertyValue()
- {
- return $this->getSelectedValue();
- }
-
- /**
- * Returns true if this control validated successfully.
- * Defaults to true.
- * @return bool wether this control validated successfully.
- */
- public function getIsValid()
- {
- return $this->_isValid;
- }
- /**
- * @param bool wether this control is valid.
- */
- public function setIsValid($value)
- {
- $this->_isValid=TPropertyValue::ensureBoolean($value);
- }
-
- /**
- * Gets the name of the javascript class responsible for performing postback for this control.
- * This method overrides the parent implementation.
- * @return string the javascript class name
- */
- protected function getClientClassName()
- {
- return 'Prado.WebUI.TCheckBoxList';
- }
-
- /**
- * Gets the post back options for this checkbox.
- * @return array
- */
- protected function getPostBackOptions()
- {
- $options['ListID'] = $this->getClientID();
- $options['ValidationGroup'] = $this->getValidationGroup();
- $options['CausesValidation'] = $this->getCausesValidation();
- $options['ListName'] = $this->getUniqueID();
- $options['ItemCount'] = $this->getItemCount();
- return $options;
- }
-
-}
-
+<?php
+/**
+ * TCheckBoxList class file
+ *
+ * @author Qiang Xue <qiang.xue@gmail.com>
+ * @link http://www.pradosoft.com/
+ * @copyright Copyright &copy; 2005-2012 PradoSoft
+ * @license http://www.pradosoft.com/license/
+ * @version $Id$
+ * @package System.Web.UI.WebControls
+ */
+
+/**
+ * Includes TListControl class
+ */
+Prado::using('System.Web.UI.WebControls.TListControl');
+/**
+ * Includes TRepeatInfo class
+ */
+Prado::using('System.Web.UI.WebControls.TRepeatInfo');
+/**
+ * Includes TCheckBox class
+ */
+Prado::using('System.Web.UI.WebControls.TCheckBox');
+
+/**
+ * TCheckBoxList class
+ *
+ * TCheckBoxList displays a list of checkboxes on a Web page.
+ *
+ * The layout of the checkbox list is specified via {@link setRepeatLayout RepeatLayout},
+ * which can be either 'Table' (default) or 'Flow'.
+ * A table layout uses HTML table cells to organize the checkboxes while
+ * a flow layout uses line breaks to organize the checkboxes.
+ * When the layout is using 'Table', {@link setCellPadding CellPadding} and
+ * {@link setCellSpacing CellSpacing} can be used to adjust the cellpadding and
+ * cellpadding of the table.
+ *
+ * The number of columns used to display the checkboxes is specified via
+ * {@link setRepeatColumns RepeatColumns} property, while the {@link setRepeatDirection RepeatDirection}
+ * governs the order of the items being rendered.
+ *
+ * The alignment of the text besides each checkbox can be specified via {@link setTextAlign TextAlign}.
+ *
+ * @author Qiang Xue <qiang.xue@gmail.com>
+ * @version $Id$
+ * @package System.Web.UI.WebControls
+ * @since 3.0
+ */
+class TCheckBoxList extends TListControl implements IRepeatInfoUser, INamingContainer, IPostBackDataHandler, IValidatable
+{
+ private $_repeatedControl;
+ private $_isEnabled;
+ private $_changedEventRaised=false;
+ private $_dataChanged=false;
+ private $_isValid=true;
+
+ /**
+ * Constructor.
+ * Remember to call parent implementation if you override this method
+ */
+ public function __construct()
+ {
+ parent::__construct();
+ $this->_repeatedControl=$this->createRepeatedControl();
+ $this->_repeatedControl->setEnableViewState(false);
+ $this->_repeatedControl->setID('c0');
+ $this->getControls()->add($this->_repeatedControl);
+ }
+
+ /**
+ * Creates a control used for repetition (used as a template).
+ * @return TControl the control to be repeated
+ */
+ protected function createRepeatedControl()
+ {
+ return new TCheckBox;
+ }
+
+ /**
+ * Finds a control by ID.
+ * This method overrides the parent implementation so that it always returns
+ * the checkbox list itself (because the checkbox list does not have child controls.)
+ * @param string control ID
+ * @return TControl control being found
+ */
+ public function findControl($id)
+ {
+ return $this;
+ }
+
+ /**
+ * @return boolean whether this control supports multiple selection. Always true for checkbox list.
+ */
+ protected function getIsMultiSelect()
+ {
+ return true;
+ }
+
+ /**
+ * Creates a style object for the control.
+ * This method creates a {@link TTableStyle} to be used by checkbox list.
+ * @return TStyle control style to be used
+ */
+ protected function createStyle()
+ {
+ return new TTableStyle;
+ }
+
+ /**
+ * @return TTextAlign the alignment of the text caption, defaults to TTextAlign::Right.
+ */
+ public function getTextAlign()
+ {
+ return $this->getViewState('TextAlign',TTextAlign::Right);
+ }
+
+ /**
+ * @param TTextAlign the text alignment of the checkboxes
+ */
+ public function setTextAlign($value)
+ {
+ $this->setViewState('TextAlign',TPropertyValue::ensureEnum($value,'TTextAlign'),TTextAlign::Right);
+ }
+
+
+ /**
+ * @return TRepeatInfo repeat information (primarily used by control developers)
+ */
+ protected function getRepeatInfo()
+ {
+ if(($repeatInfo=$this->getViewState('RepeatInfo',null))===null)
+ {
+ $repeatInfo=new TRepeatInfo;
+ $this->setViewState('RepeatInfo',$repeatInfo,null);
+ }
+ return $repeatInfo;
+ }
+
+ /**
+ * @return integer the number of columns that the list should be displayed with. Defaults to 0 meaning not set.
+ */
+ public function getRepeatColumns()
+ {
+ return $this->getRepeatInfo()->getRepeatColumns();
+ }
+
+ /**
+ * @param integer the number of columns that the list should be displayed with.
+ */
+ public function setRepeatColumns($value)
+ {
+ $this->getRepeatInfo()->setRepeatColumns($value);
+ }
+
+ /**
+ * @return string the direction of traversing the list, defaults to 'Vertical'
+ */
+ public function getRepeatDirection()
+ {
+ return $this->getRepeatInfo()->getRepeatDirection();
+ }
+
+ /**
+ * @param string the direction (Vertical, Horizontal) of traversing the list
+ */
+ public function setRepeatDirection($value)
+ {
+ $this->getRepeatInfo()->setRepeatDirection($value);
+ }
+
+ /**
+ * @return string how the list should be displayed, using table or using line breaks. Defaults to 'Table'.
+ */
+ public function getRepeatLayout()
+ {
+ return $this->getRepeatInfo()->getRepeatLayout();
+ }
+
+ /**
+ * @param string how the list should be displayed, using table or using line breaks (Table, Flow)
+ */
+ public function setRepeatLayout($value)
+ {
+ $this->getRepeatInfo()->setRepeatLayout($value);
+ }
+
+ /**
+ * @return integer the cellspacing for the table keeping the checkbox list. Defaults to -1, meaning not set.
+ */
+ public function getCellSpacing()
+ {
+ if($this->getHasStyle())
+ return $this->getStyle()->getCellSpacing();
+ else
+ return -1;
+ }
+
+ /**
+ * Sets the cellspacing for the table keeping the checkbox list.
+ * @param integer the cellspacing for the table keeping the checkbox list.
+ */
+ public function setCellSpacing($value)
+ {
+ $this->getStyle()->setCellSpacing($value);
+ }
+
+ /**
+ * @return integer the cellpadding for the table keeping the checkbox list. Defaults to -1, meaning not set.
+ */
+ public function getCellPadding()
+ {
+ if($this->getHasStyle())
+ return $this->getStyle()->getCellPadding();
+ else
+ return -1;
+ }
+
+ /**
+ * Sets the cellpadding for the table keeping the checkbox list.
+ * @param integer the cellpadding for the table keeping the checkbox list.
+ */
+ public function setCellPadding($value)
+ {
+ $this->getStyle()->setCellPadding($value);
+ }
+
+ /**
+ * Returns a value indicating whether this control contains header item.
+ * This method is required by {@link IRepeatInfoUser} interface.
+ * @return boolean always false.
+ */
+ public function getHasHeader()
+ {
+ return false;
+ }
+
+ /**
+ * Returns a value indicating whether this control contains footer item.
+ * This method is required by {@link IRepeatInfoUser} interface.
+ * @return boolean always false.
+ */
+ public function getHasFooter()
+ {
+ return false;
+ }
+
+ /**
+ * Returns a value indicating whether this control contains separator items.
+ * This method is required by {@link IRepeatInfoUser} interface.
+ * @return boolean always false.
+ */
+ public function getHasSeparators()
+ {
+ return false;
+ }
+
+ /**
+ * @param boolean whether the control is to be enabled.
+ */
+ public function setEnabled($value)
+ {
+ parent::setEnabled($value);
+ $value = !TPropertyValue::ensureBoolean($value);
+ // if this is an active control,
+ // and it's a callback,
+ // and we can update clientside,
+ // then update the 'disabled' attribute of the items.
+ if(($this instanceof IActiveControl) &&
+ $this->getPage()->getIsCallBack() &&
+ $this->getActiveControl()->canUpdateClientSide())
+ {
+ $items = $this->getItems();
+ $cs = $this->getPage()->getCallbackClient();
+ $baseClientID = $this->getClientID().'_c';
+ foreach($items as $index=>$item)
+ {
+ $cs->setAttribute($baseClientID.$index, 'disabled', $value);
+ }
+ }
+ }
+
+ /**
+ * Returns a style used for rendering items.
+ * This method is required by {@link IRepeatInfoUser} interface.
+ * @param string item type (Header,Footer,Item,AlternatingItem,SelectedItem,EditItem,Separator,Pager)
+ * @param integer index of the item being rendered
+ * @return null
+ */
+ public function generateItemStyle($itemType,$index)
+ {
+ return null;
+ }
+
+ /**
+ * Renders an item in the list.
+ * This method is required by {@link IRepeatInfoUser} interface.
+ * @param THtmlWriter writer for rendering purpose
+ * @param TRepeatInfo repeat information
+ * @param string item type (Header,Footer,Item,AlternatingItem,SelectedItem,EditItem,Separator,Pager)
+ * @param integer zero-based index of the item in the item list
+ */
+ public function renderItem($writer,$repeatInfo,$itemType,$index)
+ {
+ $repeatedControl=$this->_repeatedControl;
+ $item=$this->getItems()->itemAt($index);
+ if($item->getHasAttributes())
+ $repeatedControl->getAttributes()->copyFrom($item->getAttributes());
+ else if($repeatedControl->getHasAttributes())
+ $repeatedControl->getAttributes()->clear();
+ $repeatedControl->setID("c$index");
+ $repeatedControl->setText($item->getText());
+ $repeatedControl->setChecked($item->getSelected());
+ $repeatedControl->setAttribute('value',$item->getValue());
+ $repeatedControl->setEnabled($this->_isEnabled && $item->getEnabled());
+ $repeatedControl->setEnableClientScript(false);
+ $repeatedControl->renderControl($writer);
+ }
+
+ /**
+ * Loads user input data.
+ * This method is primarly used by framework developers.
+ * @param string the key that can be used to retrieve data from the input data collection
+ * @param array the input data collection
+ * @return boolean whether the data of the control has been changed
+ */
+ public function loadPostData($key,$values)
+ {
+ if($this->getEnabled(true))
+ {
+ $index=(int)substr($key,strlen($this->getUniqueID())+2);
+ $this->ensureDataBound();
+ if($index>=0 && $index<$this->getItemCount())
+ {
+ $item=$this->getItems()->itemAt($index);
+ if($item->getEnabled())
+ {
+ $checked=isset($values[$key]);
+ if($item->getSelected()!==$checked)
+ {
+ $item->setSelected($checked);
+ if(!$this->_changedEventRaised)
+ {
+ $this->_changedEventRaised=true;
+ return $this->_dataChanged=true;
+ }
+ }
+ }
+ }
+ }
+ return false;
+ }
+
+ /**
+ * Raises postdata changed event.
+ * This method is required by {@link IPostBackDataHandler} interface.
+ * It is invoked by the framework when {@link getSelectedIndices SelectedIndices} property
+ * is changed on postback.
+ * This method is primarly used by framework developers.
+ */
+ public function raisePostDataChangedEvent()
+ {
+ if($this->getAutoPostBack() && $this->getCausesValidation())
+ $this->getPage()->validate($this->getValidationGroup());
+ $this->onSelectedIndexChanged(null);
+ }
+
+ /**
+ * Registers for post data on postback.
+ * This method overrides the parent implementation.
+ * @param mixed event parameter
+ */
+ public function onPreRender($param)
+ {
+ parent::onPreRender($param);
+ $this->_repeatedControl->setAutoPostBack($this->getAutoPostBack());
+ $this->_repeatedControl->setCausesValidation($this->getCausesValidation());
+ $this->_repeatedControl->setValidationGroup($this->getValidationGroup());
+ $page=$this->getPage();
+ $n=$this->getItemCount();
+ for($i=0;$i<$n;++$i)
+ {
+ $this->_repeatedControl->setID("c$i");
+ $page->registerRequiresPostData($this->_repeatedControl);
+ }
+ }
+
+ /**
+ * Wether the list should be rendered inside a span or not
+ *
+ *@return boolean true if we need a span
+ */
+ protected function getSpanNeeded ()
+ {
+ return $this->getRepeatLayout()===TRepeatLayout::Raw;
+ }
+
+ /**
+ * Renders the checkbox list control.
+ * This method overrides the parent implementation.
+ * @param THtmlWriter writer for rendering purpose.
+ */
+ public function render($writer)
+ {
+ if($this->getItemCount()>0)
+ {
+ if ($needSpan=$this->getSpanNeeded())
+ {
+ $writer->addAttribute('id', $this->getClientId());
+ $writer->renderBeginTag('span');
+ }
+ $this->_isEnabled=$this->getEnabled(true);
+ $repeatInfo=$this->getRepeatInfo();
+ $accessKey=$this->getAccessKey();
+ $tabIndex=$this->getTabIndex();
+ $this->_repeatedControl->setTextAlign($this->getTextAlign());
+ $this->_repeatedControl->setAccessKey($accessKey);
+ $this->_repeatedControl->setTabIndex($tabIndex);
+ $this->setAccessKey('');
+ $this->setTabIndex(0);
+ $repeatInfo->renderRepeater($writer,$this);
+ $this->setAccessKey($accessKey);
+ $this->setTabIndex($tabIndex);
+ if ($needSpan)
+ $writer->renderEndTag();
+ }
+ //checkbox skipped the client control script in addAttributesToRender
+ if($this->getEnabled(true)
+ && $this->getEnableClientScript()
+ && $this->getAutoPostBack()
+ && $this->getPage()->getClientSupportsJavaScript())
+ {
+ $this->renderClientControlScript($writer);
+ }
+ }
+
+ /**
+ * Returns a value indicating whether postback has caused the control data change.
+ * This method is required by the IPostBackDataHandler interface.
+ * @return boolean whether postback has caused the control data change. False if the page is not in postback mode.
+ */
+ public function getDataChanged()
+ {
+ return $this->_dataChanged;
+ }
+
+ /**
+ * Returns the value to be validated.
+ * This methid is required by IValidatable interface.
+ * @return mixed the value of the property to be validated.
+ */
+ public function getValidationPropertyValue()
+ {
+ return $this->getSelectedValue();
+ }
+
+ /**
+ * Returns true if this control validated successfully.
+ * Defaults to true.
+ * @return bool wether this control validated successfully.
+ */
+ public function getIsValid()
+ {
+ return $this->_isValid;
+ }
+ /**
+ * @param bool wether this control is valid.
+ */
+ public function setIsValid($value)
+ {
+ $this->_isValid=TPropertyValue::ensureBoolean($value);
+ }
+
+ /**
+ * Gets the name of the javascript class responsible for performing postback for this control.
+ * This method overrides the parent implementation.
+ * @return string the javascript class name
+ */
+ protected function getClientClassName()
+ {
+ return 'Prado.WebUI.TCheckBoxList';
+ }
+
+ /**
+ * Gets the post back options for this checkbox.
+ * @return array
+ */
+ protected function getPostBackOptions()
+ {
+ $options['ListID'] = $this->getClientID();
+ $options['ValidationGroup'] = $this->getValidationGroup();
+ $options['CausesValidation'] = $this->getCausesValidation();
+ $options['ListName'] = $this->getUniqueID();
+ $options['ItemCount'] = $this->getItemCount();
+ return $options;
+ }
+
+}
+
diff --git a/framework/Web/UI/WebControls/TColorPicker.php b/framework/Web/UI/WebControls/TColorPicker.php
index e5b24bd0..365421a1 100644
--- a/framework/Web/UI/WebControls/TColorPicker.php
+++ b/framework/Web/UI/WebControls/TColorPicker.php
@@ -1,290 +1,290 @@
-<?php
-/**
- * TColorPicker class file
- *
- * @author Wei Zhuo <weizhuo[at]gmail[dot]com>
- * @link http://www.pradosoft.com/
- * @copyright Copyright &copy; 2005-2012 PradoSoft
- * @license http://www.pradosoft.com/license/
- * @version $Id$
- * @package System.Web.UI.WebControls
- */
-
-/**
- * TColorPicker class.
- *
- * TColorPicker displays a text box for color input purpose.
- * Next to the textbox there's a button filled with the current chosen color.
- * Users can write a color name directly in the text box as an hex triplet (also known as HTML notation, eg: #FF00FF).
- * Alternatively, if the <b>ShowColorPicker</b> property is enabled (it is by default), users can click the button
- * to have a color picker UI appear. A color chan be chosen directly by clicking on the color picker.
- *
- * TColorPicker has three different color picker UI <b>Mode</b>s:
- * # <b>Simple</b> - Grid with 12 simple colors.
- * # <b>Basic</b> - Grid with the most common 70 colors. This is the default mode.
- * # <b>Full</b> - Full-featured color picker.
- *
- * The <b>CssClass</b> property can be used to override the CSS class name
- * for the color picker panel. The <b>ColorStyle</b> property sets the packages
- * styles available. E.g. <b>default</b>.
- *
- * If the <b>Mode</b> property is set to <b>Full</b>, the color picker panel will
- * display an "Ok" and "Cancel" buttons. You can customize the button labels setting the <b>OKButtonText</b>
- * and <b>CancelButtonText</b> properties.
- *
- * @author Wei Zhuo <weizhuo[at]gmail[dot]com>
- * @version $Id$
- * @package System.Web.UI.WebControls
- * @since 3.0
- */
-class TColorPicker extends TTextBox
-{
- const SCRIPT_PATH = 'prado/colorpicker';
-
- private $_clientSide;
-
- /**
- * @return boolean whether the color picker should pop up when the button is clicked.
- */
- public function getShowColorPicker()
- {
- return $this->getViewState('ShowColorPicker',true);
- }
-
- /**
- * Sets whether to pop up the color picker when the button is clicked.
- * @param boolean whether to show the color picker popup
- */
- public function setShowColorPicker($value)
- {
- $this->setViewState('ShowColorPicker',TPropertyValue::ensureBoolean($value),true);
- }
-
- /**
- * @param TColorPickerMode color picker UI mode
- */
- public function setMode($value)
- {
- $this->setViewState('Mode', TPropertyValue::ensureEnum($value, 'TColorPickerMode'), TColorPickerMode::Basic);
- }
-
- /**
- * @return TColorPickerMode current color picker UI mode. Defaults to TColorPickerMode::Basic.
- */
- public function getMode()
- {
- return $this->getViewState('Mode', TColorPickerMode::Basic);
- }
-
- /**
- * @param string set the color picker style
- */
- public function setColorPickerStyle($value)
- {
- $this->setViewState('ColorStyle', $value, 'default');
- }
-
- /**
- * @return string current color picker style
- */
- public function getColorPickerStyle()
- {
- return $this->getViewState('ColorStyle', 'default');
- }
-
- /**
- * @return string text for the color picker OK button. Default is "OK".
- */
- public function getOKButtonText()
- {
- return $this->getViewState('OKButtonText', 'OK');
- }
-
- /**
- * @param string text for the color picker OK button
- */
- public function setOKButtonText($value)
- {
- $this->setViewState('OKButtonText', $value, 'OK');
- }
-
- /**
- * @return string text for the color picker Cancel button. Default is "Cancel".
- */
- public function getCancelButtonText()
- {
- return $this->getViewState('CancelButtonText', 'Cancel');
- }
-
- /**
- * @param string text for the color picker Cancel button
- */
- public function setCancelButtonText($value)
- {
- $this->setViewState('CancelButtonText', $value, 'Cancel');
- }
-
- /**
- * @return TColorPickerClientSide javascript event options.
- */
- public function getClientSide()
- {
- if($this->_clientSide===null)
- $this->_clientSide = $this->createClientSide();
- return $this->_clientSide;
- }
-
- /**
- * @return TColorPickerClientSide javascript validator event options.
- */
- protected function createClientSide()
- {
- return new TColorPickerClientSide;
- }
-
- /**
- * Get javascript color picker options.
- * @return array color picker client-side options
- */
- protected function getPostBackOptions()
- {
- $options = parent::getPostBackOptions();
- $options['ClassName'] = $this->getCssClass();
- $options['ShowColorPicker'] = $this->getShowColorPicker();
- if($options['ShowColorPicker'])
- {
- $mode = $this->getMode();
- if($mode == TColorPickerMode::Full) $options['Mode'] = $mode;
- else if($mode == TColorPickerMode::Simple) $options['Palette'] = 'Tiny';
- $options['OKButtonText'] = $this->getOKButtonText();
- $options['CancelButtonText'] = $this->getCancelButtonText();
- }
- $options = array_merge($options,$this->getClientSide()->getOptions()->toArray());
- return $options;
- }
-
- /**
- * @param string asset file in the self::SCRIPT_PATH directory.
- * @return string asset file url.
- */
- protected function getAssetUrl($file='')
- {
- $base = $this->getPage()->getClientScript()->getPradoScriptAssetUrl();
- return $base.'/'.self::SCRIPT_PATH.'/'.$file;
- }
-
- /**
- * Publish the color picker Css asset files.
- */
- public function onPreRender($param)
- {
- parent::onPreRender($param);
- $this->publishColorPickerAssets();
- }
-
- /**
- * Publish the color picker assets.
- */
- protected function publishColorPickerAssets()
- {
- $cs = $this->getPage()->getClientScript();
- $key = "prado:".get_class($this);
- $imgs['button.gif'] = $this->getAssetUrl('button.gif');
- $imgs['background.png'] = $this->getAssetUrl('background.png');
- $options = TJavaScript::encode($imgs);
- $code = "Prado.WebUI.TColorPicker.UIImages = {$options};";
- $cs->registerEndScript($key, $code);
- $cs->registerPradoScript("colorpicker");
- $url = $this->getAssetUrl($this->getColorPickerStyle().'.css');
- if(!$cs->isStyleSheetFileRegistered($url))
- $cs->registerStyleSheetFile($url, $url);
- }
-
- /**
- * Renders additional body content.
- * This method overrides parent implementation by adding
- * additional color picker button.
- * @param THtmlWriter writer
- */
- public function renderEndTag($writer)
- {
- parent::renderEndTag($writer);
-
- $color = $this->getText();
- $writer->addAttribute('class', 'TColorPicker_button');
- $writer->renderBeginTag('span');
-
- $writer->addAttribute('id', $this->getClientID().'_button');
- $writer->addAttribute('src', $this->getAssetUrl('button.gif'));
- if($color !== '')
- $writer->addAttribute('style', "background-color:{$color};");
- $writer->addAttribute('width', '20');
- $writer->addAttribute('height', '20');
- $writer->addAttribute('alt', '');
- $writer->renderBeginTag('img');
- $writer->renderEndTag();
- $writer->renderEndTag();
- }
-
- /**
- * Gets the name of the javascript class responsible for performing postback for this control.
- * This method overrides the parent implementation.
- * @return string the javascript class name
- */
- protected function getClientClassName()
- {
- return 'Prado.WebUI.TColorPicker';
- }
-}
-
-/**
- * TColorPickerMode class.
- * TColorPickerMode defines the enumerable type for the possible UI mode
- * that a {@link TColorPicker} control can take.
- *
- * The following enumerable values are defined:
- * # Simple - Grid with 12 simple colors.
- * # Basic - Grid with the most common 70 colors. This is the default mode.
- * # Full - Full-featured color picker.
- *
- * @author Qiang Xue <qiang.xue@gmail.com>
- * @version $Id$
- * @package System.Web.UI.WebControls
- * @since 3.0.4
- */
-class TColorPickerMode extends TEnumerable
-{
- const Simple='Simple';
- const Basic='Basic';
- const Full='Full';
-}
-
-/**
- * TColorPickerClientSide class.
- *
- * Client-side javascript code options.
- *
- * @author Wei Zhuo <weizhuo[at]gmail[dot]com>
- * @version $Id$
- * @package System.Web.UI.WebControls
- * @since 3.1
- */
-class TColorPickerClientSide extends TClientSideOptions
-{
- /**
- * @return string javascript code for when a color is selected.
- */
- public function getOnColorSelected()
- {
- return $this->getOption('OnColorSelected');
- }
-
- /**
- * @param string javascript code for when a color is selected.
- */
- public function setOnColorSelected($javascript)
- {
- $this->setFunction('OnColorSelected', $javascript);
- }
-}
-
+<?php
+/**
+ * TColorPicker class file
+ *
+ * @author Wei Zhuo <weizhuo[at]gmail[dot]com>
+ * @link http://www.pradosoft.com/
+ * @copyright Copyright &copy; 2005-2012 PradoSoft
+ * @license http://www.pradosoft.com/license/
+ * @version $Id$
+ * @package System.Web.UI.WebControls
+ */
+
+/**
+ * TColorPicker class.
+ *
+ * TColorPicker displays a text box for color input purpose.
+ * Next to the textbox there's a button filled with the current chosen color.
+ * Users can write a color name directly in the text box as an hex triplet (also known as HTML notation, eg: #FF00FF).
+ * Alternatively, if the <b>ShowColorPicker</b> property is enabled (it is by default), users can click the button
+ * to have a color picker UI appear. A color chan be chosen directly by clicking on the color picker.
+ *
+ * TColorPicker has three different color picker UI <b>Mode</b>s:
+ * # <b>Simple</b> - Grid with 12 simple colors.
+ * # <b>Basic</b> - Grid with the most common 70 colors. This is the default mode.
+ * # <b>Full</b> - Full-featured color picker.
+ *
+ * The <b>CssClass</b> property can be used to override the CSS class name
+ * for the color picker panel. The <b>ColorStyle</b> property sets the packages
+ * styles available. E.g. <b>default</b>.
+ *
+ * If the <b>Mode</b> property is set to <b>Full</b>, the color picker panel will
+ * display an "Ok" and "Cancel" buttons. You can customize the button labels setting the <b>OKButtonText</b>
+ * and <b>CancelButtonText</b> properties.
+ *
+ * @author Wei Zhuo <weizhuo[at]gmail[dot]com>
+ * @version $Id$
+ * @package System.Web.UI.WebControls
+ * @since 3.0
+ */
+class TColorPicker extends TTextBox
+{
+ const SCRIPT_PATH = 'prado/colorpicker';
+
+ private $_clientSide;
+
+ /**
+ * @return boolean whether the color picker should pop up when the button is clicked.
+ */
+ public function getShowColorPicker()
+ {
+ return $this->getViewState('ShowColorPicker',true);
+ }
+
+ /**
+ * Sets whether to pop up the color picker when the button is clicked.
+ * @param boolean whether to show the color picker popup
+ */
+ public function setShowColorPicker($value)
+ {
+ $this->setViewState('ShowColorPicker',TPropertyValue::ensureBoolean($value),true);
+ }
+
+ /**
+ * @param TColorPickerMode color picker UI mode
+ */
+ public function setMode($value)
+ {
+ $this->setViewState('Mode', TPropertyValue::ensureEnum($value, 'TColorPickerMode'), TColorPickerMode::Basic);
+ }
+
+ /**
+ * @return TColorPickerMode current color picker UI mode. Defaults to TColorPickerMode::Basic.
+ */
+ public function getMode()
+ {
+ return $this->getViewState('Mode', TColorPickerMode::Basic);
+ }
+
+ /**
+ * @param string set the color picker style
+ */
+ public function setColorPickerStyle($value)
+ {
+ $this->setViewState('ColorStyle', $value, 'default');
+ }
+
+ /**
+ * @return string current color picker style
+ */
+ public function getColorPickerStyle()
+ {
+ return $this->getViewState('ColorStyle', 'default');
+ }
+
+ /**
+ * @return string text for the color picker OK button. Default is "OK".
+ */
+ public function getOKButtonText()
+ {
+ return $this->getViewState('OKButtonText', 'OK');
+ }
+
+ /**
+ * @param string text for the color picker OK button
+ */
+ public function setOKButtonText($value)
+ {
+ $this->setViewState('OKButtonText', $value, 'OK');
+ }
+
+ /**
+ * @return string text for the color picker Cancel button. Default is "Cancel".
+ */
+ public function getCancelButtonText()
+ {
+ return $this->getViewState('CancelButtonText', 'Cancel');
+ }
+
+ /**
+ * @param string text for the color picker Cancel button
+ */
+ public function setCancelButtonText($value)
+ {
+ $this->setViewState('CancelButtonText', $value, 'Cancel');
+ }
+
+ /**
+ * @return TColorPickerClientSide javascript event options.
+ */
+ public function getClientSide()
+ {
+ if($this->_clientSide===null)
+ $this->_clientSide = $this->createClientSide();
+ return $this->_clientSide;
+ }
+
+ /**
+ * @return TColorPickerClientSide javascript validator event options.
+ */
+ protected function createClientSide()
+ {
+ return new TColorPickerClientSide;
+ }
+
+ /**
+ * Get javascript color picker options.
+ * @return array color picker client-side options
+ */
+ protected function getPostBackOptions()
+ {
+ $options = parent::getPostBackOptions();
+ $options['ClassName'] = $this->getCssClass();
+ $options['ShowColorPicker'] = $this->getShowColorPicker();
+ if($options['ShowColorPicker'])
+ {
+ $mode = $this->getMode();
+ if($mode == TColorPickerMode::Full) $options['Mode'] = $mode;
+ else if($mode == TColorPickerMode::Simple) $options['Palette'] = 'Tiny';
+ $options['OKButtonText'] = $this->getOKButtonText();
+ $options['CancelButtonText'] = $this->getCancelButtonText();
+ }
+ $options = array_merge($options,$this->getClientSide()->getOptions()->toArray());
+ return $options;
+ }
+
+ /**
+ * @param string asset file in the self::SCRIPT_PATH directory.
+ * @return string asset file url.
+ */
+ protected function getAssetUrl($file='')
+ {
+ $base = $this->getPage()->getClientScript()->getPradoScriptAssetUrl();
+ return $base.'/'.self::SCRIPT_PATH.'/'.$file;
+ }
+
+ /**
+ * Publish the color picker Css asset files.
+ */
+ public function onPreRender($param)
+ {
+ parent::onPreRender($param);
+ $this->publishColorPickerAssets();
+ }
+
+ /**
+ * Publish the color picker assets.
+ */
+ protected function publishColorPickerAssets()
+ {
+ $cs = $this->getPage()->getClientScript();
+ $key = "prado:".get_class($this);
+ $imgs['button.gif'] = $this->getAssetUrl('button.gif');
+ $imgs['background.png'] = $this->getAssetUrl('background.png');
+ $options = TJavaScript::encode($imgs);
+ $code = "Prado.WebUI.TColorPicker.UIImages = {$options};";
+ $cs->registerEndScript($key, $code);
+ $cs->registerPradoScript("colorpicker");
+ $url = $this->getAssetUrl($this->getColorPickerStyle().'.css');
+ if(!$cs->isStyleSheetFileRegistered($url))
+ $cs->registerStyleSheetFile($url, $url);
+ }
+
+ /**
+ * Renders additional body content.
+ * This method overrides parent implementation by adding
+ * additional color picker button.
+ * @param THtmlWriter writer
+ */
+ public function renderEndTag($writer)
+ {
+ parent::renderEndTag($writer);
+
+ $color = $this->getText();
+ $writer->addAttribute('class', 'TColorPicker_button');
+ $writer->renderBeginTag('span');
+
+ $writer->addAttribute('id', $this->getClientID().'_button');
+ $writer->addAttribute('src', $this->getAssetUrl('button.gif'));
+ if($color !== '')
+ $writer->addAttribute('style', "background-color:{$color};");
+ $writer->addAttribute('width', '20');
+ $writer->addAttribute('height', '20');
+ $writer->addAttribute('alt', '');
+ $writer->renderBeginTag('img');
+ $writer->renderEndTag();
+ $writer->renderEndTag();
+ }
+
+ /**
+ * Gets the name of the javascript class responsible for performing postback for this control.
+ * This method overrides the parent implementation.
+ * @return string the javascript class name
+ */
+ protected function getClientClassName()
+ {
+ return 'Prado.WebUI.TColorPicker';
+ }
+}
+
+/**
+ * TColorPickerMode class.
+ * TColorPickerMode defines the enumerable type for the possible UI mode
+ * that a {@link TColorPicker} control can take.
+ *
+ * The following enumerable values are defined:
+ * # Simple - Grid with 12 simple colors.
+ * # Basic - Grid with the most common 70 colors. This is the default mode.
+ * # Full - Full-featured color picker.
+ *
+ * @author Qiang Xue <qiang.xue@gmail.com>
+ * @version $Id$
+ * @package System.Web.UI.WebControls
+ * @since 3.0.4
+ */
+class TColorPickerMode extends TEnumerable
+{
+ const Simple='Simple';
+ const Basic='Basic';
+ const Full='Full';
+}
+
+/**
+ * TColorPickerClientSide class.
+ *
+ * Client-side javascript code options.
+ *
+ * @author Wei Zhuo <weizhuo[at]gmail[dot]com>
+ * @version $Id$
+ * @package System.Web.UI.WebControls
+ * @since 3.1
+ */
+class TColorPickerClientSide extends TClientSideOptions
+{
+ /**
+ * @return string javascript code for when a color is selected.
+ */
+ public function getOnColorSelected()
+ {
+ return $this->getOption('OnColorSelected');
+ }
+
+ /**
+ * @param string javascript code for when a color is selected.
+ */
+ public function setOnColorSelected($javascript)
+ {
+ $this->setFunction('OnColorSelected', $javascript);
+ }
+}
+
diff --git a/framework/Web/UI/WebControls/TCompareValidator.php b/framework/Web/UI/WebControls/TCompareValidator.php
index 57b42018..c936f140 100644
--- a/framework/Web/UI/WebControls/TCompareValidator.php
+++ b/framework/Web/UI/WebControls/TCompareValidator.php
@@ -1,265 +1,265 @@
-<?php
-/**
- * TCompareValidator class file
- *
- * @author Qiang Xue <qiang.xue@gmail.com>
- * @link http://www.pradosoft.com/
+<?php
+/**
+ * TCompareValidator class file
+ *
+ * @author Qiang Xue <qiang.xue@gmail.com>
+ * @link http://www.pradosoft.com/
* @copyright Copyright &copy; 2005-2012 PradoSoft
- * @license http://www.pradosoft.com/license/
- * @version $Id$
- * @package System.Web.UI.WebControls
- */
-
-/**
- * Using TBaseValidator class
- */
-Prado::using('System.Web.UI.WebControls.TBaseValidator');
-
-/**
- * TCompareValidator class
- *
- * TCompareValidator compares the value entered by the user into an input
- * control with the value entered into another input control or a constant value.
- * To compare the associated input control with another input control,
- * set the {@link setControlToCompare ControlToCompare} property to the ID path
- * of the control to compare with. To compare the associated input control with
- * a constant value, specify the constant value to compare with by setting the
- * {@link setValueToCompare ValueToCompare} property.
- *
- * The {@link setDataType DataType} property is used to specify the data type
- * of both comparison values. Both values are automatically converted to this data
- * type before the comparison operation is performed. The following value types are supported:
- * - <b>Integer</b> A 32-bit signed integer data type.
- * - <b>Float</b> A double-precision floating point number data type.
- * - <b>Date</b> A date data type. The format can be specified by the
- * {@link setDateFormat DateFormat} property
- * - <b>String</b> A string data type.
- *
- * Use the {@link setOperator Operator} property to specify the type of comparison
- * to perform. Valid operators include Equal, NotEqual, GreaterThan, GreaterThanEqual,
- * LessThan and LessThanEqual.
- *
- * @author Qiang Xue <qiang.xue@gmail.com>
- * @version $Id$
- * @package System.Web.UI.WebControls
- * @since 3.0
- */
-class TCompareValidator extends TBaseValidator
-{
- /**
- * Gets the name of the javascript class responsible for performing validation for this control.
- * This method overrides the parent implementation.
- * @return string the javascript class name
- */
- protected function getClientClassName()
- {
- return 'Prado.WebUI.TCompareValidator';
- }
-
- /**
- * @return TValidationDataType the data type that the values being compared are converted to before the comparison is made. Defaults to TValidationDataType::String.
- */
- public function getDataType()
- {
- return $this->getViewState('DataType',TValidationDataType::String);
- }
-
- /**
- * Sets the data type that the values being
- * compared are converted to before the comparison is made.
- * @param TValidationDataType the data type
- */
- public function setDataType($value)
- {
- $this->setViewState('DataType',TPropertyValue::ensureEnum($value,'TValidationDataType'),TValidationDataType::String);
- }
-
- /**
- * @return string the input component to compare with the input control being validated.
- */
- public function getControlToCompare()
- {
- return $this->getViewState('ControlToCompare','');
- }
-
- /**
- * Sets the input component to compare with the input control being validated.
- * @param string the ID path of the component to compare with
- */
- public function setControlToCompare($value)
- {
- $this->setViewState('ControlToCompare',$value,'');
- }
-
- /**
- * @return string the constant value to compare with the value entered by the user into the input component being validated.
- */
- public function getValueToCompare()
- {
- return $this->getViewState('ValueToCompare','');
- }
-
- /**
- * Sets the constant value to compare with the value entered by the user into the input component being validated.
- * @param string the constant value
- */
- public function setValueToCompare($value)
- {
- $this->setViewState('ValueToCompare',$value,'');
- }
-
- /**
- * @return TValidationCompareOperator the comparison operation to perform. Defaults to TValidationCompareOperator::Equal.
- */
- public function getOperator()
- {
- return $this->getViewState('Operator',TValidationCompareOperator::Equal);
- }
-
- /**
- * Sets the comparison operation to perform
- * @param TValidationCompareOperator the comparison operation
- */
- public function setOperator($value)
- {
- $this->setViewState('Operator',TPropertyValue::ensureEnum($value,'TValidationCompareOperator'),TValidationCompareOperator::Equal);
- }
-
- /**
- * Sets the date format for a date validation
- * @param string the date format value
- */
- public function setDateFormat($value)
- {
- $this->setViewState('DateFormat', $value, '');
- }
-
- /**
- * @return string the date validation date format if any
- */
- public function getDateFormat()
- {
- return $this->getViewState('DateFormat', '');
- }
-
- /**
- * This method overrides the parent's implementation.
- * The validation succeeds if the input data compares successfully.
- * The validation always succeeds if ControlToValidate is not specified
- * or the input data is empty.
- * @return boolean whether the validation succeeds
- */
- public function evaluateIsValid()
- {
- if(($value=$this->getValidationValue($this->getValidationTarget()))==='')
- return true;
-
- if(($controlToCompare=$this->getControlToCompare())!=='')
- {
- if(($control2=$this->findControl($controlToCompare))===null)
- throw new TInvalidDataValueException('comparevalidator_controltocompare_invalid');
- if(($value2=$this->getValidationValue($control2))==='')
- return false;
- }
- else
- $value2=$this->getValueToCompare();
-
- $values = $this->getComparisonValues($value, $value2);
- switch($this->getOperator())
- {
- case TValidationCompareOperator::Equal:
- return $values[0] == $values[1];
- case TValidationCompareOperator::NotEqual:
- return $values[0] != $values[1];
- case TValidationCompareOperator::GreaterThan:
- return $values[0] > $values[1];
- case TValidationCompareOperator::GreaterThanEqual:
- return $values[0] >= $values[1];
- case TValidationCompareOperator::LessThan:
- return $values[0] < $values[1];
- case TValidationCompareOperator::LessThanEqual:
- return $values[0] <= $values[1];
- }
-
- return false;
- }
-
- /**
- * Parse the pair of values into the appropriate value type.
- * @param string value one
- * @param string second value
- * @return array appropriate type of the value pair, array($value1, $value2);
- */
- protected function getComparisonValues($value1, $value2)
- {
- switch($this->getDataType())
- {
- case TValidationDataType::Integer:
- return array(intval($value1), intval($value2));
- case TValidationDataType::Float:
- return array(floatval($value1), floatval($value2));
- case TValidationDataType::Date:
- $dateFormat = $this->getDateFormat();
- if($dateFormat!=='')
- {
- $formatter = Prado::createComponent('System.Util.TSimpleDateFormatter', $dateFormat);
- return array($formatter->parse($value1), $formatter->parse($value2));
- }
- else
- return array(strtotime($value1), strtotime($value2));
- }
- return array($value1, $value2);
- }
-
- /**
- * Returns an array of javascript validator options.
- * @return array javascript validator options.
- */
- protected function getClientScriptOptions()
- {
- $options = parent::getClientScriptOptions();
- if(($name=$this->getControlToCompare())!=='')
- {
- if(($control=$this->findControl($name))!==null)
- $options['ControlToCompare']=$control->getClientID();
- }
- if(($value=$this->getValueToCompare())!=='')
- $options['ValueToCompare']=$value;
- if(($operator=$this->getOperator())!==TValidationCompareOperator::Equal)
- $options['Operator']=$operator;
- $options['DataType']=$this->getDataType();
- if(($dateFormat=$this->getDateFormat())!=='')
- $options['DateFormat']=$dateFormat;
- return $options;
- }
-}
-
-
-/**
- * TValidationCompareOperator class.
- * TValidationCompareOperator defines the enumerable type for the comparison operations
- * that {@link TCompareValidator} can perform validation with.
- *
- * The following enumerable values are defined:
- * - Equal
- * - NotEqual
- * - GreaterThan
- * - GreaterThanEqual
- * - LessThan
- * - LessThanEqual
- *
- * @author Qiang Xue <qiang.xue@gmail.com>
- * @version $Id$
- * @package System.Web.UI.WebControls
- * @since 3.0.4
- */
-class TValidationCompareOperator extends TEnumerable
-{
- const Equal='Equal';
- const NotEqual='NotEqual';
- const GreaterThan='GreaterThan';
- const GreaterThanEqual='GreaterThanEqual';
- const LessThan='LessThan';
- const LessThanEqual='LessThanEqual';
-}
-
+ * @license http://www.pradosoft.com/license/
+ * @version $Id$
+ * @package System.Web.UI.WebControls
+ */
+
+/**
+ * Using TBaseValidator class
+ */
+Prado::using('System.Web.UI.WebControls.TBaseValidator');
+
+/**
+ * TCompareValidator class
+ *
+ * TCompareValidator compares the value entered by the user into an input
+ * control with the value entered into another input control or a constant value.
+ * To compare the associated input control with another input control,
+ * set the {@link setControlToCompare ControlToCompare} property to the ID path
+ * of the control to compare with. To compare the associated input control with
+ * a constant value, specify the constant value to compare with by setting the
+ * {@link setValueToCompare ValueToCompare} property.
+ *
+ * The {@link setDataType DataType} property is used to specify the data type
+ * of both comparison values. Both values are automatically converted to this data
+ * type before the comparison operation is performed. The following value types are supported:
+ * - <b>Integer</b> A 32-bit signed integer data type.
+ * - <b>Float</b> A double-precision floating point number data type.
+ * - <b>Date</b> A date data type. The format can be specified by the
+ * {@link setDateFormat DateFormat} property
+ * - <b>String</b> A string data type.
+ *
+ * Use the {@link setOperator Operator} property to specify the type of comparison
+ * to perform. Valid operators include Equal, NotEqual, GreaterThan, GreaterThanEqual,
+ * LessThan and LessThanEqual.
+ *
+ * @author Qiang Xue <qiang.xue@gmail.com>
+ * @version $Id$
+ * @package System.Web.UI.WebControls
+ * @since 3.0
+ */
+class TCompareValidator extends TBaseValidator
+{
+ /**
+ * Gets the name of the javascript class responsible for performing validation for this control.
+ * This method overrides the parent implementation.
+ * @return string the javascript class name
+ */
+ protected function getClientClassName()
+ {
+ return 'Prado.WebUI.TCompareValidator';
+ }
+
+ /**
+ * @return TValidationDataType the data type that the values being compared are converted to before the comparison is made. Defaults to TValidationDataType::String.
+ */
+ public function getDataType()
+ {
+ return $this->getViewState('DataType',TValidationDataType::String);
+ }
+
+ /**
+ * Sets the data type that the values being
+ * compared are converted to before the comparison is made.
+ * @param TValidationDataType the data type
+ */
+ public function setDataType($value)
+ {
+ $this->setViewState('DataType',TPropertyValue::ensureEnum($value,'TValidationDataType'),TValidationDataType::String);
+ }
+
+ /**
+ * @return string the input component to compare with the input control being validated.
+ */
+ public function getControlToCompare()
+ {
+ return $this->getViewState('ControlToCompare','');
+ }
+
+ /**
+ * Sets the input component to compare with the input control being validated.
+ * @param string the ID path of the component to compare with
+ */
+ public function setControlToCompare($value)
+ {
+ $this->setViewState('ControlToCompare',$value,'');
+ }
+
+ /**
+ * @return string the constant value to compare with the value entered by the user into the input component being validated.
+ */
+ public function getValueToCompare()
+ {
+ return $this->getViewState('ValueToCompare','');
+ }
+
+ /**
+ * Sets the constant value to compare with the value entered by the user into the input component being validated.
+ * @param string the constant value
+ */
+ public function setValueToCompare($value)
+ {
+ $this->setViewState('ValueToCompare',$value,'');
+ }
+
+ /**
+ * @return TValidationCompareOperator the comparison operation to perform. Defaults to TValidationCompareOperator::Equal.
+ */
+ public function getOperator()
+ {
+ return $this->getViewState('Operator',TValidationCompareOperator::Equal);
+ }
+
+ /**
+ * Sets the comparison operation to perform
+ * @param TValidationCompareOperator the comparison operation
+ */
+ public function setOperator($value)
+ {
+ $this->setViewState('Operator',TPropertyValue::ensureEnum($value,'TValidationCompareOperator'),TValidationCompareOperator::Equal);
+ }
+
+ /**
+ * Sets the date format for a date validation
+ * @param string the date format value
+ */
+ public function setDateFormat($value)
+ {
+ $this->setViewState('DateFormat', $value, '');
+ }
+
+ /**
+ * @return string the date validation date format if any
+ */
+ public function getDateFormat()
+ {
+ return $this->getViewState('DateFormat', '');
+ }
+
+ /**
+ * This method overrides the parent's implementation.
+ * The validation succeeds if the input data compares successfully.
+ * The validation always succeeds if ControlToValidate is not specified
+ * or the input data is empty.
+ * @return boolean whether the validation succeeds
+ */
+ public function evaluateIsValid()
+ {
+ if(($value=$this->getValidationValue($this->getValidationTarget()))==='')
+ return true;
+
+ if(($controlToCompare=$this->getControlToCompare())!=='')
+ {
+ if(($control2=$this->findControl($controlToCompare))===null)
+ throw new TInvalidDataValueException('comparevalidator_controltocompare_invalid');
+ if(($value2=$this->getValidationValue($control2))==='')
+ return false;
+ }
+ else
+ $value2=$this->getValueToCompare();
+
+ $values = $this->getComparisonValues($value, $value2);
+ switch($this->getOperator())
+ {
+ case TValidationCompareOperator::Equal:
+ return $values[0] == $values[1];
+ case TValidationCompareOperator::NotEqual:
+ return $values[0] != $values[1];
+ case TValidationCompareOperator::GreaterThan:
+ return $values[0] > $values[1];
+ case TValidationCompareOperator::GreaterThanEqual:
+ return $values[0] >= $values[1];
+ case TValidationCompareOperator::LessThan:
+ return $values[0] < $values[1];
+ case TValidationCompareOperator::LessThanEqual:
+ return $values[0] <= $values[1];
+ }
+
+ return false;
+ }
+
+ /**
+ * Parse the pair of values into the appropriate value type.
+ * @param string value one
+ * @param string second value
+ * @return array appropriate type of the value pair, array($value1, $value2);
+ */
+ protected function getComparisonValues($value1, $value2)
+ {
+ switch($this->getDataType())
+ {
+ case TValidationDataType::Integer:
+ return array(intval($value1), intval($value2));
+ case TValidationDataType::Float:
+ return array(floatval($value1), floatval($value2));
+ case TValidationDataType::Date:
+ $dateFormat = $this->getDateFormat();
+ if($dateFormat!=='')
+ {
+ $formatter = Prado::createComponent('System.Util.TSimpleDateFormatter', $dateFormat);
+ return array($formatter->parse($value1), $formatter->parse($value2));
+ }
+ else
+ return array(strtotime($value1), strtotime($value2));
+ }
+ return array($value1, $value2);
+ }
+
+ /**
+ * Returns an array of javascript validator options.
+ * @return array javascript validator options.
+ */
+ protected function getClientScriptOptions()
+ {
+ $options = parent::getClientScriptOptions();
+ if(($name=$this->getControlToCompare())!=='')
+ {
+ if(($control=$this->findControl($name))!==null)
+ $options['ControlToCompare']=$control->getClientID();
+ }
+ if(($value=$this->getValueToCompare())!=='')
+ $options['ValueToCompare']=$value;
+ if(($operator=$this->getOperator())!==TValidationCompareOperator::Equal)
+ $options['Operator']=$operator;
+ $options['DataType']=$this->getDataType();
+ if(($dateFormat=$this->getDateFormat())!=='')
+ $options['DateFormat']=$dateFormat;
+ return $options;
+ }
+}
+
+
+/**
+ * TValidationCompareOperator class.
+ * TValidationCompareOperator defines the enumerable type for the comparison operations
+ * that {@link TCompareValidator} can perform validation with.
+ *
+ * The following enumerable values are defined:
+ * - Equal
+ * - NotEqual
+ * - GreaterThan
+ * - GreaterThanEqual
+ * - LessThan
+ * - LessThanEqual
+ *
+ * @author Qiang Xue <qiang.xue@gmail.com>
+ * @version $Id$
+ * @package System.Web.UI.WebControls
+ * @since 3.0.4
+ */
+class TValidationCompareOperator extends TEnumerable
+{
+ const Equal='Equal';
+ const NotEqual='NotEqual';
+ const GreaterThan='GreaterThan';
+ const GreaterThanEqual='GreaterThanEqual';
+ const LessThan='LessThan';
+ const LessThanEqual='LessThanEqual';
+}
+
diff --git a/framework/Web/UI/WebControls/TConditional.php b/framework/Web/UI/WebControls/TConditional.php
index d04324f0..28af2305 100644
--- a/framework/Web/UI/WebControls/TConditional.php
+++ b/framework/Web/UI/WebControls/TConditional.php
@@ -1,143 +1,143 @@
-<?php
-/**
- * TConditional class file.
- *
- * @author Qiang Xue <qiang.xue@gmail.com>
- * @link http://www.pradosoft.com/
+<?php
+/**
+ * TConditional class file.
+ *
+ * @author Qiang Xue <qiang.xue@gmail.com>
+ * @link http://www.pradosoft.com/
* @copyright Copyright &copy; 2005-2012 PradoSoft
- * @license http://www.pradosoft.com/license/
- * @version $Id$
- * @package System.Web.UI.WebControls
- */
-
-/**
- * TConditional class.
- *
- * TConditional displays appropriate content based on the evaluation result
- * of a PHP expression specified via {@link setCondition Condition}.
- * If the result is true, it instantiates the template {@link getTrueTemplate TrueTemplate};
- * otherwise, the template {@link getFalseTemplate FalseTemplate} is instantiated.
- * The PHP expression is evaluated right before {@link onInit} stage of the control lifecycle.
- *
- * Since {@link setCondition Condition} is evaluated at a very early stage, it is recommended
- * you set {@link setCondition Condition} in template and the expression should not refer to
- * objects that are available on or after {@link onInit} lifecycle.
- *
- * A typical usage of TConditional is shown as following:
- * <code>
- * <com:TConditional Condition="$this->User->IsGuest">
- * <prop:TrueTemplate>
- * <a href="path/to/login">Login</a>
- * </prop:TrueTemplate>
- * <prop:FalseTemplate>
- * <a href="path/to/logout">Logout</a>
- * </prop:FalseTemplate>
- * </com:TConditional>
- * </code>
- *
- * TConditional is very light. It instantiates either {@link getTrueTemplate TrueTemplate}
- * or {@link getFalseTemplate FalseTemplate}, but never both. And the condition is evaluated only once.
- *
- * @author Qiang Xue <qiang.xue@gmail.com>
- * @version $Id$
- * @package System.Web.UI.WebControls
- * @since 3.1.1
- */
-class TConditional extends TControl
-{
- private $_condition='true';
- private $_trueTemplate;
- private $_falseTemplate;
- private $_creatingChildren=false;
-
- /**
- * Processes an object that is created during parsing template.
- * This method overrides the parent implementation by removing
- * all contents enclosed in the template tag.
- * @param string|TComponent text string or component parsed and instantiated in template
- * @see createdOnTemplate
- */
- public function addParsedObject($object)
- {
- if($this->_creatingChildren)
- parent::addParsedObject($object);
- }
-
- /**
- * Creates child controls.
- * This method overrides the parent implementation. It evaluates {@link getCondition Condition}
- * and instantiate the corresponding template.
- */
- public function createChildControls()
- {
- $this->_creatingChildren=true;
- $result=true;
- try
- {
- $result=$this->getTemplateControl()->evaluateExpression($this->_condition);
- }
- catch(Exception $e)
- {
- throw new TInvalidDataValueException('conditional_condition_invalid',$this->_condition,$e->getMessage());
- }
- if($result)
- {
- if($this->_trueTemplate)
- $this->_trueTemplate->instantiateIn($this->getTemplateControl(),$this);
- }
- else if($this->_falseTemplate)
- $this->_falseTemplate->instantiateIn($this->getTemplateControl(),$this);
- $this->_creatingChildren=false;
- }
-
- /**
- * @return string the PHP expression used for determining which template to use. Defaults to 'true', meaning using TrueTemplate.
- */
- public function getCondition()
- {
- return $this->_condition;
- }
-
- /**
- * Sets the PHP expression to be evaluated for conditionally displaying content.
- * The context of the expression is the template control containing TConditional.
- * @param string the PHP expression used for determining which template to use.
- */
- public function setCondition($value)
- {
- $this->_condition=TPropertyValue::ensureString($value);
- }
-
- /**
- * @return ITemplate the template applied when {@link getCondition Condition} is true.
- */
- public function getTrueTemplate()
- {
- return $this->_trueTemplate;
- }
-
- /**
- * @param ITemplate the template applied when {@link getCondition Condition} is true.
- */
- public function setTrueTemplate(ITemplate $value)
- {
- $this->_trueTemplate=$value;
- }
-
- /**
- * @return ITemplate the template applied when {@link getCondition Condition} is false.
- */
- public function getFalseTemplate()
- {
- return $this->_falseTemplate;
- }
-
- /**
- * @param ITemplate the template applied when {@link getCondition Condition} is false.
- */
- public function setFalseTemplate(ITemplate $value)
- {
- $this->_falseTemplate=$value;
- }
-}
-
+ * @license http://www.pradosoft.com/license/
+ * @version $Id$
+ * @package System.Web.UI.WebControls
+ */
+
+/**
+ * TConditional class.
+ *
+ * TConditional displays appropriate content based on the evaluation result
+ * of a PHP expression specified via {@link setCondition Condition}.
+ * If the result is true, it instantiates the template {@link getTrueTemplate TrueTemplate};
+ * otherwise, the template {@link getFalseTemplate FalseTemplate} is instantiated.
+ * The PHP expression is evaluated right before {@link onInit} stage of the control lifecycle.
+ *
+ * Since {@link setCondition Condition} is evaluated at a very early stage, it is recommended
+ * you set {@link setCondition Condition} in template and the expression should not refer to
+ * objects that are available on or after {@link onInit} lifecycle.
+ *
+ * A typical usage of TConditional is shown as following:
+ * <code>
+ * <com:TConditional Condition="$this->User->IsGuest">
+ * <prop:TrueTemplate>
+ * <a href="path/to/login">Login</a>
+ * </prop:TrueTemplate>
+ * <prop:FalseTemplate>
+ * <a href="path/to/logout">Logout</a>
+ * </prop:FalseTemplate>
+ * </com:TConditional>
+ * </code>
+ *
+ * TConditional is very light. It instantiates either {@link getTrueTemplate TrueTemplate}
+ * or {@link getFalseTemplate FalseTemplate}, but never both. And the condition is evaluated only once.
+ *
+ * @author Qiang Xue <qiang.xue@gmail.com>
+ * @version $Id$
+ * @package System.Web.UI.WebControls
+ * @since 3.1.1
+ */
+class TConditional extends TControl
+{
+ private $_condition='true';
+ private $_trueTemplate;
+ private $_falseTemplate;
+ private $_creatingChildren=false;
+
+ /**
+ * Processes an object that is created during parsing template.
+ * This method overrides the parent implementation by removing
+ * all contents enclosed in the template tag.
+ * @param string|TComponent text string or component parsed and instantiated in template
+ * @see createdOnTemplate
+ */
+ public function addParsedObject($object)
+ {
+ if($this->_creatingChildren)
+ parent::addParsedObject($object);
+ }
+
+ /**
+ * Creates child controls.
+ * This method overrides the parent implementation. It evaluates {@link getCondition Condition}
+ * and instantiate the corresponding template.
+ */
+ public function createChildControls()
+ {
+ $this->_creatingChildren=true;
+ $result=true;
+ try
+ {
+ $result=$this->getTemplateControl()->evaluateExpression($this->_condition);
+ }
+ catch(Exception $e)
+ {
+ throw new TInvalidDataValueException('conditional_condition_invalid',$this->_condition,$e->getMessage());
+ }
+ if($result)
+ {
+ if($this->_trueTemplate)
+ $this->_trueTemplate->instantiateIn($this->getTemplateControl(),$this);
+ }
+ else if($this->_falseTemplate)
+ $this->_falseTemplate->instantiateIn($this->getTemplateControl(),$this);
+ $this->_creatingChildren=false;
+ }
+
+ /**
+ * @return string the PHP expression used for determining which template to use. Defaults to 'true', meaning using TrueTemplate.
+ */
+ public function getCondition()
+ {
+ return $this->_condition;
+ }
+
+ /**
+ * Sets the PHP expression to be evaluated for conditionally displaying content.
+ * The context of the expression is the template control containing TConditional.
+ * @param string the PHP expression used for determining which template to use.
+ */
+ public function setCondition($value)
+ {
+ $this->_condition=TPropertyValue::ensureString($value);
+ }
+
+ /**
+ * @return ITemplate the template applied when {@link getCondition Condition} is true.
+ */
+ public function getTrueTemplate()
+ {
+ return $this->_trueTemplate;
+ }
+
+ /**
+ * @param ITemplate the template applied when {@link getCondition Condition} is true.
+ */
+ public function setTrueTemplate(ITemplate $value)
+ {
+ $this->_trueTemplate=$value;
+ }
+
+ /**
+ * @return ITemplate the template applied when {@link getCondition Condition} is false.
+ */
+ public function getFalseTemplate()
+ {
+ return $this->_falseTemplate;
+ }
+
+ /**
+ * @param ITemplate the template applied when {@link getCondition Condition} is false.
+ */
+ public function setFalseTemplate(ITemplate $value)
+ {
+ $this->_falseTemplate=$value;
+ }
+}
+
diff --git a/framework/Web/UI/WebControls/TContent.php b/framework/Web/UI/WebControls/TContent.php
index 3b17c2cc..60a8e0b6 100644
--- a/framework/Web/UI/WebControls/TContent.php
+++ b/framework/Web/UI/WebControls/TContent.php
@@ -1,47 +1,47 @@
-<?php
-/**
- * TContent class file.
- *
- * @author Qiang Xue <qiang.xue@gmail.com>
- * @link http://www.pradosoft.com/
+<?php
+/**
+ * TContent class file.
+ *
+ * @author Qiang Xue <qiang.xue@gmail.com>
+ * @link http://www.pradosoft.com/
* @copyright Copyright &copy; 2005-2012 PradoSoft
- * @license http://www.pradosoft.com/license/
- * @version $Id$
- * @package System.Web.UI.WebControls
- */
-
-/**
- * TContent class
- *
- * TContent specifies a block of content on a control's template
- * that will be injected at somewhere of the master control's template.
- * TContentPlaceHolder and {@link TContent} together implement a decoration
- * pattern for prado templated controls. A template control
- * (called content control) can specify a master control
- * whose template contains some TContentPlaceHolder controls.
- * {@link TContent} controls on the content control's template will replace the corresponding
- * {@link TContentPlaceHolder} controls on the master control's template.
- * This is called content injection. It is done by matching the IDs of
- * {@link TContent} and {@link TContentPlaceHolder} controls.
- *
- * @author Qiang Xue <qiang.xue@gmail.com>
- * @version $Id$
- * @package System.Web.UI.WebControls
- * @since 3.0
- */
-class TContent extends TControl implements INamingContainer
-{
- /**
- * This method is invoked after the control is instantiated on a template.
- * This overrides the parent implementation by registering the content control
- * to the template owner control.
- * @param TControl potential parent of this control
- */
- public function createdOnTemplate($parent)
- {
- if(($id=$this->getID())==='')
- throw new TConfigurationException('content_id_required');
- $this->getTemplateControl()->registerContent($id,$this);
- }
-}
-
+ * @license http://www.pradosoft.com/license/
+ * @version $Id$
+ * @package System.Web.UI.WebControls
+ */
+
+/**
+ * TContent class
+ *
+ * TContent specifies a block of content on a control's template
+ * that will be injected at somewhere of the master control's template.
+ * TContentPlaceHolder and {@link TContent} together implement a decoration
+ * pattern for prado templated controls. A template control
+ * (called content control) can specify a master control
+ * whose template contains some TContentPlaceHolder controls.
+ * {@link TContent} controls on the content control's template will replace the corresponding
+ * {@link TContentPlaceHolder} controls on the master control's template.
+ * This is called content injection. It is done by matching the IDs of
+ * {@link TContent} and {@link TContentPlaceHolder} controls.
+ *
+ * @author Qiang Xue <qiang.xue@gmail.com>
+ * @version $Id$
+ * @package System.Web.UI.WebControls
+ * @since 3.0
+ */
+class TContent extends TControl implements INamingContainer
+{
+ /**
+ * This method is invoked after the control is instantiated on a template.
+ * This overrides the parent implementation by registering the content control
+ * to the template owner control.
+ * @param TControl potential parent of this control
+ */
+ public function createdOnTemplate($parent)
+ {
+ if(($id=$this->getID())==='')
+ throw new TConfigurationException('content_id_required');
+ $this->getTemplateControl()->registerContent($id,$this);
+ }
+}
+
diff --git a/framework/Web/UI/WebControls/TContentPlaceHolder.php b/framework/Web/UI/WebControls/TContentPlaceHolder.php
index ddd2b610..55ed461d 100644
--- a/framework/Web/UI/WebControls/TContentPlaceHolder.php
+++ b/framework/Web/UI/WebControls/TContentPlaceHolder.php
@@ -1,48 +1,48 @@
-<?php
-/**
- * TContentPlaceHolder class file.
- *
- * @author Qiang Xue <qiang.xue@gmail.com>
- * @link http://www.pradosoft.com/
+<?php
+/**
+ * TContentPlaceHolder class file.
+ *
+ * @author Qiang Xue <qiang.xue@gmail.com>
+ * @link http://www.pradosoft.com/
* @copyright Copyright &copy; 2005-2012 PradoSoft
- * @license http://www.pradosoft.com/license/
- * @version $Id$
- * @package System.Web.UI.WebControls
- */
-
-/**
- * TContentPlaceHolder class
- *
- * TContentPlaceHolder reserves a place on a template where a {@link TContent}
- * control can inject itself and its children in. TContentPlaceHolder and {@link TContent}
- * together implement a decoration pattern for prado templated controls.
- * A template control (called content control) can specify a master control
- * whose template contains some TContentPlaceHolder controls.
- * {@link TContent} controls on the content control's template will replace the corresponding
- * {@link TContentPlaceHolder} controls on the master control's template.
- * This is called content injection. It is done by matching the IDs of
- * {@link TContent} and {@link TContentPlaceHolder} controls.
- *
- * @author Qiang Xue <qiang.xue@gmail.com>
- * @version $Id$
- * @package System.Web.UI.WebControls
- * @since 3.0
- */
-class TContentPlaceHolder extends TControl
-{
- /**
- * This method is invoked after the control is instantiated on a template.
- * This overrides the parent implementation by registering the content placeholder
- * control to the template owner control. The placeholder control will NOT
- * be added to the potential parent control!
- * @param TControl potential parent of this control
- */
- public function createdOnTemplate($parent)
- {
- if(($id=$this->getID())==='')
- throw new TConfigurationException('contentplaceholder_id_required');
- $this->getTemplateControl()->registerContentPlaceHolder($id,$this);
- $parent->getControls()->add($this);
- }
-}
-
+ * @license http://www.pradosoft.com/license/
+ * @version $Id$
+ * @package System.Web.UI.WebControls
+ */
+
+/**
+ * TContentPlaceHolder class
+ *
+ * TContentPlaceHolder reserves a place on a template where a {@link TContent}
+ * control can inject itself and its children in. TContentPlaceHolder and {@link TContent}
+ * together implement a decoration pattern for prado templated controls.
+ * A template control (called content control) can specify a master control
+ * whose template contains some TContentPlaceHolder controls.
+ * {@link TContent} controls on the content control's template will replace the corresponding
+ * {@link TContentPlaceHolder} controls on the master control's template.
+ * This is called content injection. It is done by matching the IDs of
+ * {@link TContent} and {@link TContentPlaceHolder} controls.
+ *
+ * @author Qiang Xue <qiang.xue@gmail.com>
+ * @version $Id$
+ * @package System.Web.UI.WebControls
+ * @since 3.0
+ */
+class TContentPlaceHolder extends TControl
+{
+ /**
+ * This method is invoked after the control is instantiated on a template.
+ * This overrides the parent implementation by registering the content placeholder
+ * control to the template owner control. The placeholder control will NOT
+ * be added to the potential parent control!
+ * @param TControl potential parent of this control
+ */
+ public function createdOnTemplate($parent)
+ {
+ if(($id=$this->getID())==='')
+ throw new TConfigurationException('contentplaceholder_id_required');
+ $this->getTemplateControl()->registerContentPlaceHolder($id,$this);
+ $parent->getControls()->add($this);
+ }
+}
+
diff --git a/framework/Web/UI/WebControls/TCustomValidator.php b/framework/Web/UI/WebControls/TCustomValidator.php
index 9ab75258..dcfadacd 100644
--- a/framework/Web/UI/WebControls/TCustomValidator.php
+++ b/framework/Web/UI/WebControls/TCustomValidator.php
@@ -1,207 +1,207 @@
-<?php
-/**
- * TCustomValidator class file
- *
- * @author Qiang Xue <qiang.xue@gmail.com>
- * @link http://www.pradosoft.com/
- * @copyright Copyright &copy; 2005-2012 PradoSoft
- * @license http://www.pradosoft.com/license/
- * @version $Id$
- * @package System.Web.UI.WebControls
- */
-
-/**
- * Using TBaseValidator class
- */
-Prado::using('System.Web.UI.WebControls.TBaseValidator');
-
-/**
- * TCustomValidator class
- *
- * TCustomValidator performs user-defined validation (either
- * server-side or client-side or both) on an input component.
- *
- * To create a server-side validation function, provide a handler for
- * the {@link onServerValidate OnServerValidate} event that performs the validation.
- * The data string of the input control to validate can be accessed
- * by {@link TServerValidateEventParameter::getValue Value} of the event parameter.
- * The result of the validation should be stored in the
- * {@link TServerValidateEventParameter::getIsValid IsValid} property of the event
- * parameter.
- *
- * To create a client-side validation function, add the client-side
- * validation javascript function to the page template.
- * The function should have the following signature:
- * <code>
- * <script type="text/javascript"><!--
- * function ValidationFunctionName(sender, parameter)
- * {
- * // if(parameter == ...)
- * // return true;
- * // else
- * // return false;
- * }
- * --></script>
- * </code>
- * Use the {@link setClientValidationFunction ClientValidationFunction} property
- * to specify the name of the client-side validation script function associated
- * with the TCustomValidator.
- *
- * @author Qiang Xue <qiang.xue@gmail.com>
- * @version $Id$
- * @package System.Web.UI.WebControls
- * @since 3.0
- */
-class TCustomValidator extends TBaseValidator
-{
- /**
- * Gets the name of the javascript class responsible for performing validation for this control.
- * This method overrides the parent implementation.
- * @return string the javascript class name
- */
- protected function getClientClassName()
- {
- return 'Prado.WebUI.TCustomValidator';
- }
-
- /**
- * @return string the name of the custom client-side script function used for validation.
- */
- public function getClientValidationFunction()
- {
- return $this->getViewState('ClientValidationFunction','');
- }
-
- /**
- * Sets the name of the custom client-side script function used for validation.
- * @param string the script function name
- */
- public function setClientValidationFunction($value)
- {
- $this->setViewState('ClientValidationFunction',$value,'');
- }
-
- /**
- * This method overrides the parent's implementation.
- * The validation succeeds if {@link onServerValidate} returns true.
- * @return boolean whether the validation succeeds
- */
- public function evaluateIsValid()
- {
- $value = '';
- if($this->getValidationTarget()!==null)
- $value=$this->getValidationValue($this->getValidationTarget());
- return $this->onServerValidate($value);
- }
-
- /**
- * This method is invoked when the server side validation happens.
- * It will raise the <b>OnServerValidate</b> event.
- * The method also allows derived classes to handle the event without attaching a delegate.
- * <b>Note</b> The derived classes should call parent implementation
- * to ensure the <b>OnServerValidate</b> event is raised.
- * @param string the value to be validated
- * @return boolean whether the value is valid
- */
- public function onServerValidate($value)
- {
- $param=new TServerValidateEventParameter($value,true);
- $this->raiseEvent('OnServerValidate',$this,$param);
- return $param->getIsValid();
- }
-
- /**
- * @return TControl control to be validated. Null if no control is found.
- */
- public function getValidationTarget()
- {
- if(($id=$this->getControlToValidate())!=='' && ($control=$this->findControl($id))!==null)
- return $control;
- else if(($id=$this->getControlToValidate())!=='')
- throw new TInvalidDataTypeException('basevalidator_validatable_required',get_class($this));
- else
- return null;
- }
-
- /**
- * Returns an array of javascript validator options.
- * @return array javascript validator options.
- */
- protected function getClientScriptOptions()
- {
- $options=parent::getClientScriptOptions();
- if(($clientJs=$this->getClientValidationFunction())!=='')
- $options['ClientValidationFunction']=$clientJs;
- return $options;
- }
-
- /**
- * Only register the client-side validator if
- * {@link setClientValidationFunction ClientValidationFunction} is set.
- */
- protected function registerClientScriptValidator()
- {
- if($this->getClientValidationFunction()!=='')
- parent::registerClientScriptValidator();
- }
-}
-
-/**
- * TServerValidateEventParameter class
- *
- * TServerValidateEventParameter encapsulates the parameter data for
- * <b>OnServerValidate</b> event of TCustomValidator components.
- *
- * @author Qiang Xue <qiang.xue@gmail.com>
- * @version $Id$
- * @package System.Web.UI.WebControls
- * @since 3.0
- */
-class TServerValidateEventParameter extends TEventParameter
-{
- /**
- * the value to be validated
- * @var string
- */
- private $_value='';
- /**
- * whether the value is valid
- * @var boolean
- */
- private $_isValid=true;
-
- /**
- * Constructor.
- * @param string property value to be validated
- * @param boolean whether the value is valid
- */
- public function __construct($value,$isValid)
- {
- $this->_value=$value;
- $this->setIsValid($isValid);
- }
-
- /**
- * @return string value to be validated
- */
- public function getValue()
- {
- return $this->_value;
- }
-
- /**
- * @return boolean whether the value is valid
- */
- public function getIsValid()
- {
- return $this->_isValid;
- }
-
- /**
- * @param boolean whether the value is valid
- */
- public function setIsValid($value)
- {
- $this->_isValid=TPropertyValue::ensureBoolean($value);
- }
-}
+<?php
+/**
+ * TCustomValidator class file
+ *
+ * @author Qiang Xue <qiang.xue@gmail.com>
+ * @link http://www.pradosoft.com/
+ * @copyright Copyright &copy; 2005-2012 PradoSoft
+ * @license http://www.pradosoft.com/license/
+ * @version $Id$
+ * @package System.Web.UI.WebControls
+ */
+
+/**
+ * Using TBaseValidator class
+ */
+Prado::using('System.Web.UI.WebControls.TBaseValidator');
+
+/**
+ * TCustomValidator class
+ *
+ * TCustomValidator performs user-defined validation (either
+ * server-side or client-side or both) on an input component.
+ *
+ * To create a server-side validation function, provide a handler for
+ * the {@link onServerValidate OnServerValidate} event that performs the validation.
+ * The data string of the input control to validate can be accessed
+ * by {@link TServerValidateEventParameter::getValue Value} of the event parameter.
+ * The result of the validation should be stored in the
+ * {@link TServerValidateEventParameter::getIsValid IsValid} property of the event
+ * parameter.
+ *
+ * To create a client-side validation function, add the client-side
+ * validation javascript function to the page template.
+ * The function should have the following signature:
+ * <code>
+ * <script type="text/javascript"><!--
+ * function ValidationFunctionName(sender, parameter)
+ * {
+ * // if(parameter == ...)
+ * // return true;
+ * // else
+ * // return false;
+ * }
+ * --></script>
+ * </code>
+ * Use the {@link setClientValidationFunction ClientValidationFunction} property
+ * to specify the name of the client-side validation script function associated
+ * with the TCustomValidator.
+ *
+ * @author Qiang Xue <qiang.xue@gmail.com>
+ * @version $Id$
+ * @package System.Web.UI.WebControls
+ * @since 3.0
+ */
+class TCustomValidator extends TBaseValidator
+{
+ /**
+ * Gets the name of the javascript class responsible for performing validation for this control.
+ * This method overrides the parent implementation.
+ * @return string the javascript class name
+ */
+ protected function getClientClassName()
+ {
+ return 'Prado.WebUI.TCustomValidator';
+ }
+
+ /**
+ * @return string the name of the custom client-side script function used for validation.
+ */
+ public function getClientValidationFunction()
+ {
+ return $this->getViewState('ClientValidationFunction','');
+ }
+
+ /**
+ * Sets the name of the custom client-side script function used for validation.
+ * @param string the script function name
+ */
+ public function setClientValidationFunction($value)
+ {
+ $this->setViewState('ClientValidationFunction',$value,'');
+ }
+
+ /**
+ * This method overrides the parent's implementation.
+ * The validation succeeds if {@link onServerValidate} returns true.
+ * @return boolean whether the validation succeeds
+ */
+ public function evaluateIsValid()
+ {
+ $value = '';
+ if($this->getValidationTarget()!==null)
+ $value=$this->getValidationValue($this->getValidationTarget());
+ return $this->onServerValidate($value);
+ }
+
+ /**
+ * This method is invoked when the server side validation happens.
+ * It will raise the <b>OnServerValidate</b> event.
+ * The method also allows derived classes to handle the event without attaching a delegate.
+ * <b>Note</b> The derived classes should call parent implementation
+ * to ensure the <b>OnServerValidate</b> event is raised.
+ * @param string the value to be validated
+ * @return boolean whether the value is valid
+ */
+ public function onServerValidate($value)
+ {
+ $param=new TServerValidateEventParameter($value,true);
+ $this->raiseEvent('OnServerValidate',$this,$param);
+ return $param->getIsValid();
+ }
+
+ /**
+ * @return TControl control to be validated. Null if no control is found.
+ */
+ public function getValidationTarget()
+ {
+ if(($id=$this->getControlToValidate())!=='' && ($control=$this->findControl($id))!==null)
+ return $control;
+ else if(($id=$this->getControlToValidate())!=='')
+ throw new TInvalidDataTypeException('basevalidator_validatable_required',get_class($this));
+ else
+ return null;
+ }
+
+ /**
+ * Returns an array of javascript validator options.
+ * @return array javascript validator options.
+ */
+ protected function getClientScriptOptions()
+ {
+ $options=parent::getClientScriptOptions();
+ if(($clientJs=$this->getClientValidationFunction())!=='')
+ $options['ClientValidationFunction']=$clientJs;
+ return $options;
+ }
+
+ /**
+ * Only register the client-side validator if
+ * {@link setClientValidationFunction ClientValidationFunction} is set.
+ */
+ protected function registerClientScriptValidator()
+ {
+ if($this->getClientValidationFunction()!=='')
+ parent::registerClientScriptValidator();
+ }
+}
+
+/**
+ * TServerValidateEventParameter class
+ *
+ * TServerValidateEventParameter encapsulates the parameter data for
+ * <b>OnServerValidate</b> event of TCustomValidator components.
+ *
+ * @author Qiang Xue <qiang.xue@gmail.com>
+ * @version $Id$
+ * @package System.Web.UI.WebControls
+ * @since 3.0
+ */
+class TServerValidateEventParameter extends TEventParameter
+{
+ /**
+ * the value to be validated
+ * @var string
+ */
+ private $_value='';
+ /**
+ * whether the value is valid
+ * @var boolean
+ */
+ private $_isValid=true;
+
+ /**
+ * Constructor.
+ * @param string property value to be validated
+ * @param boolean whether the value is valid
+ */
+ public function __construct($value,$isValid)
+ {
+ $this->_value=$value;
+ $this->setIsValid($isValid);
+ }
+
+ /**
+ * @return string value to be validated
+ */
+ public function getValue()
+ {
+ return $this->_value;
+ }
+
+ /**
+ * @return boolean whether the value is valid
+ */
+ public function getIsValid()
+ {
+ return $this->_isValid;
+ }
+
+ /**
+ * @param boolean whether the value is valid
+ */
+ public function setIsValid($value)
+ {
+ $this->_isValid=TPropertyValue::ensureBoolean($value);
+ }
+}
diff --git a/framework/Web/UI/WebControls/TDataBoundControl.php b/framework/Web/UI/WebControls/TDataBoundControl.php
index 294dd416..076179fb 100644
--- a/framework/Web/UI/WebControls/TDataBoundControl.php
+++ b/framework/Web/UI/WebControls/TDataBoundControl.php
@@ -1,587 +1,587 @@
-<?php
-/**
- * TDataBoundControl class file
- *
- * @author Qiang Xue <qiang.xue@gmail.com>
- * @link http://www.pradosoft.com/
- * @copyright Copyright &copy; 2005-2012 PradoSoft
- * @license http://www.pradosoft.com/license/
- * @version $Id$
- * @package System.Web.UI.WebControls
- */
-
-Prado::using('System.Web.UI.WebControls.TDataSourceControl');
-Prado::using('System.Web.UI.WebControls.TDataSourceView');
-Prado::using('System.Collections.TPagedDataSource');
-
-/**
- * TDataBoundControl class.
- *
- * TDataBoundControl is the based class for controls that need to populate
- * data from data sources. It provides basic properties and methods that allow
- * the derived controls to associate with data sources and retrieve data from them.
- *
- * TBC....
- *
- * TDataBoundControl is equipped with paging capabilities. By setting
- * {@link setAllowPaging AllowPaging} to true, the input data will be paged
- * and only one page of data is actually populated into the data-bound control.
- * This saves a lot of memory when dealing with larget datasets.
- *
- * To specify the number of data items displayed on each page, set
- * the {@link setPageSize PageSize} property, and to specify which
- * page of data to be displayed, set {@link setCurrentPageIndex CurrentPageIndex}.
- *
- * When the size of the original data is too big to be loaded all in the memory,
- * one can enable custom paging. In custom paging, the total number of data items
- * is specified manually via {@link setVirtualItemCount VirtualItemCount},
- * and the data source only needs to contain the current page of data. To enable
- * custom paging, set {@link setAllowCustomPaging AllowCustomPaging} to true.
- *
- * @author Qiang Xue <qiang.xue@gmail.com>
- * @version $Id$
- * @package System.Web.UI.WebControls
- * @since 3.0
- */
-abstract class TDataBoundControl extends TWebControl
-{
- private $_initialized=false;
- private $_dataSource=null;
- private $_requiresBindToNull=false;
- private $_requiresDataBinding=false;
- private $_prerendered=false;
- private $_currentView=null;
- private $_currentDataSource=null;
- private $_currentViewValid=false;
- private $_currentDataSourceValid=false;
- private $_currentViewIsFromDataSourceID=false;
- private $_parameters=null;
- private $_isDataBound=false;
-
- /**
- * @return Traversable data source object, defaults to null.
- */
- public function getDataSource()
- {
- return $this->_dataSource;
- }
-
- /**
- * Sets the data source object associated with the databound control.
- * The data source must implement Traversable interface.
- * If an array is given, it will be converted to xxx.
- * If a string is given, it will be converted to xxx.
- * @param Traversable|array|string data source object
- */
- public function setDataSource($value)
- {
- $this->_dataSource=$this->validateDataSource($value);
- $this->onDataSourceChanged();
- }
-
- /**
- * @return string ID path to the data source control. Defaults to empty.
- */
- public function getDataSourceID()
- {
- return $this->getViewState('DataSourceID','');
- }
-
- /**
- * @param string ID path to the data source control. The data source
- * control must be locatable via {@link TControl::findControl} call.
- */
- public function setDataSourceID($value)
- {
- $dsid=$this->getViewState('DataSourceID','');
- if($dsid!=='' && $value==='')
- $this->_requiresBindToNull=true;
- $this->setViewState('DataSourceID',$value,'');
- $this->onDataSourceChanged();
- }
-
- /**
- * @return boolean if the databound control uses the data source specified
- * by {@link setDataSourceID}, or it uses the data source object specified
- * by {@link setDataSource}.
- */
- protected function getUsingDataSourceID()
- {
- return $this->getDataSourceID()!=='';
- }
-
- /**
- * Sets {@link setRequiresDataBinding RequiresDataBinding} as true if the control is initialized.
- * This method is invoked when either {@link setDataSource} or {@link setDataSourceID} is changed.
- */
- public function onDataSourceChanged()
- {
- $this->_currentViewValid=false;
- $this->_currentDataSourceValid=false;
- if($this->getInitialized())
- $this->setRequiresDataBinding(true);
- }
-
- /**
- * @return boolean whether the databound control has been initialized.
- * By default, the control is initialized after its viewstate has been restored.
- */
- protected function getInitialized()
- {
- return $this->_initialized;
- }
-
- /**
- * Sets a value indicating whether the databound control is initialized.
- * If initialized, any modification to {@link setDataSource DataSource} or
- * {@link setDataSourceID DataSourceID} will set {@link setRequiresDataBinding RequiresDataBinding}
- * as true.
- * @param boolean a value indicating whether the databound control is initialized.
- */
- protected function setInitialized($value)
- {
- $this->_initialized=TPropertyValue::ensureBoolean($value);
- }
-
- /**
- * @return boolean whether databind has been invoked in the previous page request
- */
- protected function getIsDataBound()
- {
- return $this->_isDataBound;
- }
-
- /**
- * @param boolean if databind has been invoked in this page request
- */
- protected function setIsDataBound($value)
- {
- $this->_isDataBound=$value;
- }
-
- /**
- * @return boolean whether a databind call is required (by the data bound control)
- */
- protected function getRequiresDataBinding()
- {
- return $this->_requiresDataBinding;
- }
-
- /**
- * @return boolean whether paging is enabled. Defaults to false.
- */
- public function getAllowPaging()
- {
- return $this->getViewState('AllowPaging',false);
- }
-
- /**
- * @param boolean whether paging is enabled
- */
- public function setAllowPaging($value)
- {
- $this->setViewState('AllowPaging',TPropertyValue::ensureBoolean($value),false);
- }
-
- /**
- * @return boolean whether the custom paging is enabled. Defaults to false.
- */
- public function getAllowCustomPaging()
- {
- return $this->getViewState('AllowCustomPaging',false);
- }
-
- /**
- * Sets a value indicating whether the custom paging should be enabled.
- * When the pager is in custom paging mode, the {@link setVirtualItemCount VirtualItemCount}
- * property is used to determine the paging, and the data items in the
- * {@link setDataSource DataSource} are considered to be in the current page.
- * @param boolean whether the custom paging is enabled
- */
- public function setAllowCustomPaging($value)
- {
- $this->setViewState('AllowCustomPaging',TPropertyValue::ensureBoolean($value),false);
- }
-
- /**
- * @return integer the zero-based index of the current page. Defaults to 0.
- */
- public function getCurrentPageIndex()
- {
- return $this->getViewState('CurrentPageIndex',0);
- }
-
- /**
- * @param integer the zero-based index of the current page
- * @throws TInvalidDataValueException if the value is less than 0
- */
- public function setCurrentPageIndex($value)
- {
- if(($value=TPropertyValue::ensureInteger($value))<0)
- $value=0;
- $this->setViewState('CurrentPageIndex',$value,0);
- }
-
- /**
- * @return integer the number of data items on each page. Defaults to 10.
- */
- public function getPageSize()
- {
- return $this->getViewState('PageSize',10);
- }
-
- /**
- * @param integer the number of data items on each page.
- * @throws TInvalidDataValueException if the value is less than 1
- */
- public function setPageSize($value)
- {
- if(($value=TPropertyValue::ensureInteger($value))<1)
- throw new TInvalidDataValueException('databoundcontrol_pagesize_invalid',get_class($this));
- $this->setViewState('PageSize',TPropertyValue::ensureInteger($value),10);
- }
-
- /**
- * @return integer number of pages of data items available
- */
- public function getPageCount()
- {
- return $this->getViewState('PageCount',1);
- }
-
- /**
- * @return integer virtual number of data items in the data source. Defaults to 0.
- * @see setAllowCustomPaging
- */
- public function getVirtualItemCount()
- {
- return $this->getViewState('VirtualItemCount',0);
- }
-
- /**
- * @param integer virtual number of data items in the data source.
- * @throws TInvalidDataValueException if the value is less than 0
- * @see setAllowCustomPaging
- */
- public function setVirtualItemCount($value)
- {
- if(($value=TPropertyValue::ensureInteger($value))<0)
- throw new TInvalidDataValueException('databoundcontrol_virtualitemcount_invalid',get_class($this));
- $this->setViewState('VirtualItemCount',$value,0);
- }
-
- /**
- * Sets a value indicating whether a databind call is required by the data bound control.
- * If true and the control has been prerendered while it uses the data source
- * specified by {@link setDataSourceID}, a databind call will be called by this method.
- * @param boolean whether a databind call is required.
- */
- protected function setRequiresDataBinding($value)
- {
- $value=TPropertyValue::ensureBoolean($value);
- if($value && $this->_prerendered)
- {
- $this->_requiresDataBinding=true;
- $this->ensureDataBound();
- }
- else
- $this->_requiresDataBinding=$value;
- }
-
- /**
- * Ensures any pending {@link dataBind} is called.
- * This method calls {@link dataBind} if the data source is specified
- * by {@link setDataSourceID} or if {@link getRequiresDataBinding RequiresDataBinding}
- * is true.
- */
- protected function ensureDataBound()
- {
- if($this->_requiresDataBinding && ($this->getUsingDataSourceID() || $this->_requiresBindToNull))
- {
- $this->dataBind();
- $this->_requiresBindToNull=false;
- }
- }
-
- /**
- * @return TPagedDataSource creates a paged data source
- */
- protected function createPagedDataSource()
- {
- $ds=new TPagedDataSource;
- $ds->setCurrentPageIndex($this->getCurrentPageIndex());
- $ds->setPageSize($this->getPageSize());
- $ds->setAllowPaging($this->getAllowPaging());
- $ds->setAllowCustomPaging($this->getAllowCustomPaging());
- $ds->setVirtualItemCount($this->getVirtualItemCount());
- return $ds;
- }
-
- /**
- * Performs databinding.
- * This method overrides the parent implementation by calling
- * {@link performSelect} which fetches data from data source and does
- * the actual binding work.
- */
- public function dataBind()
- {
- $this->setRequiresDataBinding(false);
- $this->dataBindProperties();
- $this->onDataBinding(null);
-
- if(($view=$this->getDataSourceView())!==null)
- $data=$view->select($this->getSelectParameters());
- else
- $data=null;
-
- if($data instanceof Traversable)
- {
- if($this->getAllowPaging())
- {
- $ds=$this->createPagedDataSource();
- $ds->setDataSource($data);
- $this->setViewState('PageCount',$ds->getPageCount());
- if($ds->getCurrentPageIndex()>=$ds->getPageCount())
- {
- $ds->setCurrentPageIndex($ds->getPageCount()-1);
- $this->setCurrentPageIndex($ds->getCurrentPageIndex());
- }
- $this->performDataBinding($ds);
- }
- else
- {
- $this->clearViewState('PageCount');
- $this->performDataBinding($data);
- }
- }
- $this->setIsDataBound(true);
- $this->onDataBound(null);
- }
-
- public function dataSourceViewChanged($sender,$param)
- {
- if(!$this->_ignoreDataSourceViewChanged)
- $this->setRequiresDataBinding(true);
- }
-
- protected function getDataSourceView()
- {
- if(!$this->_currentViewValid)
- {
- if($this->_currentView && $this->_currentViewIsFromDataSourceID)
- $this->_currentView->detachEventHandler('DataSourceViewChanged',array($this,'dataSourceViewChanged'));
- if(($dataSource=$this->determineDataSource())!==null)
- {
- if(($view=$dataSource->getView($this->getDataMember()))===null)
- throw new TInvalidDataValueException('databoundcontrol_datamember_invalid',$this->getDataMember());
- if($this->_currentViewIsFromDataSourceID=$this->getUsingDataSourceID())
- $view->attachEventHandler('OnDataSourceViewChanged',array($this,'dataSourceViewChanged'));
- $this->_currentView=$view;
- }
- else
- $this->_currentView=null;
- $this->_currentViewValid=true;
- }
- return $this->_currentView;
- }
-
- protected function determineDataSource()
- {
- if(!$this->_currentDataSourceValid)
- {
- if(($dsid=$this->getDataSourceID())!=='')
- {
- if(($dataSource=$this->getNamingContainer()->findControl($dsid))===null)
- throw new TInvalidDataValueException('databoundcontrol_datasourceid_inexistent',$dsid);
- else if(!($dataSource instanceof IDataSource))
- throw new TInvalidDataValueException('databoundcontrol_datasourceid_invalid',$dsid);
- else
- $this->_currentDataSource=$dataSource;
- }
- else if(($dataSource=$this->getDataSource())!==null)
- $this->_currentDataSource=new TReadOnlyDataSource($dataSource,$this->getDataMember());
- else
- $this->_currentDataSource=null;
- $this->_currentDataSourceValid=true;
- }
- return $this->_currentDataSource;
- }
-
- abstract protected function performDataBinding($data);
-
- /**
- * Raises <b>OnDataBound</b> event.
- * This method should be invoked after a databind is performed.
- * It is mainly used by framework and component developers.
- */
- public function onDataBound($param)
- {
- $this->raiseEvent('OnDataBound',$this,$param);
- }
-
- /**
- * Sets page's <b>OnPreLoad</b> event handler as {@link pagePreLoad}.
- * If viewstate is disabled and the current request is a postback,
- * {@link setRequiresDataBinding RequiresDataBinding} will be set true.
- * This method overrides the parent implementation.
- * @param TEventParameter event parameter
- */
- public function onInit($param)
- {
- parent::onInit($param);
- $page=$this->getPage();
- $page->attachEventHandler('OnPreLoad',array($this,'pagePreLoad'));
- }
-
- /**
- * Sets {@link getInitialized} as true.
- * This method is invoked when page raises <b>PreLoad</b> event.
- * @param mixed event sender
- * @param TEventParameter event parameter
- */
- public function pagePreLoad($sender,$param)
- {
- $this->_initialized=true;
- $isPostBack=$this->getPage()->getIsPostBack();
- if(!$isPostBack || ($isPostBack && (!$this->getEnableViewState(true) || !$this->getIsDataBound())))
- $this->setRequiresDataBinding(true);
- }
-
- /**
- * Ensures any pending databind is performed.
- * This method overrides the parent implementation.
- * @param TEventParameter event parameter
- */
- public function onPreRender($param)
- {
- $this->_prerendered=true;
- $this->ensureDataBound();
- parent::onPreRender($param);
- }
-
- /**
- * Validates if the parameter is a valid data source.
- * If it is a string or an array, it will be converted as a TList object.
- * @param Traversable|array|string data source to be validated
- * @return Traversable the data that is traversable
- * @throws TInvalidDataTypeException if the data is neither null nor Traversable
- */
- protected function validateDataSource($value)
- {
- if(is_string($value))
- {
- $list=new TList;
- foreach(TPropertyValue::ensureArray($value) as $key=>$value)
- {
- if(is_array($value))
- $list->add($value);
- else
- $list->add(array($value,is_string($key)?$key:$value));
- }
- return $list;
- }
- else if(is_array($value))
- return new TMap($value);
- else if($value instanceof TDbDataReader) {
- // read array from TDbDataReader since it's forward-only stream and can only be traversed once
- return $value->readAll();
- }
- else if(($value instanceof Traversable) || $value===null)
- return $value;
- else
- throw new TInvalidDataTypeException('databoundcontrol_datasource_invalid',get_class($this));
- }
-
- public function getDataMember()
- {
- return $this->getViewState('DataMember','');
- }
-
- public function setDataMember($value)
- {
- $this->setViewState('DataMember',$value,'');
- }
-
- public function getSelectParameters()
- {
- if(!$this->_parameters)
- $this->_parameters=new TDataSourceSelectParameters;
- return $this->_parameters;
- }
-}
-
-
-/**
- * TListItemType class.
- * TListItemType defines the enumerable type for the possible types
- * that databound list items could take.
- *
- * The following enumerable values are defined:
- * - Header: header item
- * - Footer: footer item
- * - Item: content item (neither header nor footer)
- * - Separator: separator between items
- * - AlternatingItem: alternating content item
- * - EditItem: content item in edit mode
- * - SelectedItem: selected content item
- * - Pager: pager
- *
- * @author Qiang Xue <qiang.xue@gmail.com>
- * @version $Id$
- * @package System.Web.UI.WebControls
- * @since 3.0.4
- */
-class TListItemType extends TEnumerable
-{
- const Header='Header';
- const Footer='Footer';
- const Item='Item';
- const Separator='Separator';
- const AlternatingItem='AlternatingItem';
- const EditItem='EditItem';
- const SelectedItem='SelectedItem';
- const Pager='Pager';
-}
-
-
-/**
- * IItemDataRenderer interface.
- *
- * IItemDataRenderer defines the interface that an item renderer
- * needs to implement. Besides the {@link getData Data} property, a list item
- * renderer also needs to provide {@link getItemIndex ItemIndex} and
- * {@link getItemType ItemType} property.
- *
- * @author Qiang Xue <qiang.xue@gmail.com>
- * @version $Id$
- * @package System.Web.UI.WebControls
- * @since 3.1.0
- */
-interface IItemDataRenderer extends IDataRenderer
-{
- /**
- * Returns a value indicating the zero-based index of the item in the corresponding data control's item collection.
- * If the item is not in the collection (e.g. it is a header item), it returns -1.
- * @return integer zero-based index of the item.
- */
- public function getItemIndex();
-
- /**
- * Sets the zero-based index for the item.
- * If the item is not in the item collection (e.g. it is a header item), -1 should be used.
- * @param integer zero-based index of the item.
- */
- public function setItemIndex($value);
-
- /**
- * @return TListItemType the item type.
- */
- public function getItemType();
-
- /**
- * @param TListItemType the item type.
- */
- public function setItemType($value);
-}
-
-?>
+<?php
+/**
+ * TDataBoundControl class file
+ *
+ * @author Qiang Xue <qiang.xue@gmail.com>
+ * @link http://www.pradosoft.com/
+ * @copyright Copyright &copy; 2005-2012 PradoSoft
+ * @license http://www.pradosoft.com/license/
+ * @version $Id$
+ * @package System.Web.UI.WebControls
+ */
+
+Prado::using('System.Web.UI.WebControls.TDataSourceControl');
+Prado::using('System.Web.UI.WebControls.TDataSourceView');
+Prado::using('System.Collections.TPagedDataSource');
+
+/**
+ * TDataBoundControl class.
+ *
+ * TDataBoundControl is the based class for controls that need to populate
+ * data from data sources. It provides basic properties and methods that allow
+ * the derived controls to associate with data sources and retrieve data from them.
+ *
+ * TBC....
+ *
+ * TDataBoundControl is equipped with paging capabilities. By setting
+ * {@link setAllowPaging AllowPaging} to true, the input data will be paged
+ * and only one page of data is actually populated into the data-bound control.
+ * This saves a lot of memory when dealing with larget datasets.
+ *
+ * To specify the number of data items displayed on each page, set
+ * the {@link setPageSize PageSize} property, and to specify which
+ * page of data to be displayed, set {@link setCurrentPageIndex CurrentPageIndex}.
+ *
+ * When the size of the original data is too big to be loaded all in the memory,
+ * one can enable custom paging. In custom paging, the total number of data items
+ * is specified manually via {@link setVirtualItemCount VirtualItemCount},
+ * and the data source only needs to contain the current page of data. To enable
+ * custom paging, set {@link setAllowCustomPaging AllowCustomPaging} to true.
+ *
+ * @author Qiang Xue <qiang.xue@gmail.com>
+ * @version $Id$
+ * @package System.Web.UI.WebControls
+ * @since 3.0
+ */
+abstract class TDataBoundControl extends TWebControl
+{
+ private $_initialized=false;
+ private $_dataSource=null;
+ private $_requiresBindToNull=false;
+ private $_requiresDataBinding=false;
+ private $_prerendered=false;
+ private $_currentView=null;
+ private $_currentDataSource=null;
+ private $_currentViewValid=false;
+ private $_currentDataSourceValid=false;
+ private $_currentViewIsFromDataSourceID=false;
+ private $_parameters=null;
+ private $_isDataBound=false;
+
+ /**
+ * @return Traversable data source object, defaults to null.
+ */
+ public function getDataSource()
+ {
+ return $this->_dataSource;
+ }
+
+ /**
+ * Sets the data source object associated with the databound control.
+ * The data source must implement Traversable interface.
+ * If an array is given, it will be converted to xxx.
+ * If a string is given, it will be converted to xxx.
+ * @param Traversable|array|string data source object
+ */
+ public function setDataSource($value)
+ {
+ $this->_dataSource=$this->validateDataSource($value);
+ $this->onDataSourceChanged();
+ }
+
+ /**
+ * @return string ID path to the data source control. Defaults to empty.
+ */
+ public function getDataSourceID()
+ {
+ return $this->getViewState('DataSourceID','');
+ }
+
+ /**
+ * @param string ID path to the data source control. The data source
+ * control must be locatable via {@link TControl::findControl} call.
+ */
+ public function setDataSourceID($value)
+ {
+ $dsid=$this->getViewState('DataSourceID','');
+ if($dsid!=='' && $value==='')
+ $this->_requiresBindToNull=true;
+ $this->setViewState('DataSourceID',$value,'');
+ $this->onDataSourceChanged();
+ }
+
+ /**
+ * @return boolean if the databound control uses the data source specified
+ * by {@link setDataSourceID}, or it uses the data source object specified
+ * by {@link setDataSource}.
+ */
+ protected function getUsingDataSourceID()
+ {
+ return $this->getDataSourceID()!=='';
+ }
+
+ /**
+ * Sets {@link setRequiresDataBinding RequiresDataBinding} as true if the control is initialized.
+ * This method is invoked when either {@link setDataSource} or {@link setDataSourceID} is changed.
+ */
+ public function onDataSourceChanged()
+ {
+ $this->_currentViewValid=false;
+ $this->_currentDataSourceValid=false;
+ if($this->getInitialized())
+ $this->setRequiresDataBinding(true);
+ }
+
+ /**
+ * @return boolean whether the databound control has been initialized.
+ * By default, the control is initialized after its viewstate has been restored.
+ */
+ protected function getInitialized()
+ {
+ return $this->_initialized;
+ }
+
+ /**
+ * Sets a value indicating whether the databound control is initialized.
+ * If initialized, any modification to {@link setDataSource DataSource} or
+ * {@link setDataSourceID DataSourceID} will set {@link setRequiresDataBinding RequiresDataBinding}
+ * as true.
+ * @param boolean a value indicating whether the databound control is initialized.
+ */
+ protected function setInitialized($value)
+ {
+ $this->_initialized=TPropertyValue::ensureBoolean($value);
+ }
+
+ /**
+ * @return boolean whether databind has been invoked in the previous page request
+ */
+ protected function getIsDataBound()
+ {
+ return $this->_isDataBound;
+ }
+
+ /**
+ * @param boolean if databind has been invoked in this page request
+ */
+ protected function setIsDataBound($value)
+ {
+ $this->_isDataBound=$value;
+ }
+
+ /**
+ * @return boolean whether a databind call is required (by the data bound control)
+ */
+ protected function getRequiresDataBinding()
+ {
+ return $this->_requiresDataBinding;
+ }
+
+ /**
+ * @return boolean whether paging is enabled. Defaults to false.
+ */
+ public function getAllowPaging()
+ {
+ return $this->getViewState('AllowPaging',false);
+ }
+
+ /**
+ * @param boolean whether paging is enabled
+ */
+ public function setAllowPaging($value)
+ {
+ $this->setViewState('AllowPaging',TPropertyValue::ensureBoolean($value),false);
+ }
+
+ /**
+ * @return boolean whether the custom paging is enabled. Defaults to false.
+ */
+ public function getAllowCustomPaging()
+ {
+ return $this->getViewState('AllowCustomPaging',false);
+ }
+
+ /**
+ * Sets a value indicating whether the custom paging should be enabled.
+ * When the pager is in custom paging mode, the {@link setVirtualItemCount VirtualItemCount}
+ * property is used to determine the paging, and the data items in the
+ * {@link setDataSource DataSource} are considered to be in the current page.
+ * @param boolean whether the custom paging is enabled
+ */
+ public function setAllowCustomPaging($value)
+ {
+ $this->setViewState('AllowCustomPaging',TPropertyValue::ensureBoolean($value),false);
+ }
+
+ /**
+ * @return integer the zero-based index of the current page. Defaults to 0.
+ */
+ public function getCurrentPageIndex()
+ {
+ return $this->getViewState('CurrentPageIndex',0);
+ }
+
+ /**
+ * @param integer the zero-based index of the current page
+ * @throws TInvalidDataValueException if the value is less than 0
+ */
+ public function setCurrentPageIndex($value)
+ {
+ if(($value=TPropertyValue::ensureInteger($value))<0)
+ $value=0;
+ $this->setViewState('CurrentPageIndex',$value,0);
+ }
+
+ /**
+ * @return integer the number of data items on each page. Defaults to 10.
+ */
+ public function getPageSize()
+ {
+ return $this->getViewState('PageSize',10);
+ }
+
+ /**
+ * @param integer the number of data items on each page.
+ * @throws TInvalidDataValueException if the value is less than 1
+ */
+ public function setPageSize($value)
+ {
+ if(($value=TPropertyValue::ensureInteger($value))<1)
+ throw new TInvalidDataValueException('databoundcontrol_pagesize_invalid',get_class($this));
+ $this->setViewState('PageSize',TPropertyValue::ensureInteger($value),10);
+ }
+
+ /**
+ * @return integer number of pages of data items available
+ */
+ public function getPageCount()
+ {
+ return $this->getViewState('PageCount',1);
+ }
+
+ /**
+ * @return integer virtual number of data items in the data source. Defaults to 0.
+ * @see setAllowCustomPaging
+ */
+ public function getVirtualItemCount()
+ {
+ return $this->getViewState('VirtualItemCount',0);
+ }
+
+ /**
+ * @param integer virtual number of data items in the data source.
+ * @throws TInvalidDataValueException if the value is less than 0
+ * @see setAllowCustomPaging
+ */
+ public function setVirtualItemCount($value)
+ {
+ if(($value=TPropertyValue::ensureInteger($value))<0)
+ throw new TInvalidDataValueException('databoundcontrol_virtualitemcount_invalid',get_class($this));
+ $this->setViewState('VirtualItemCount',$value,0);
+ }
+
+ /**
+ * Sets a value indicating whether a databind call is required by the data bound control.
+ * If true and the control has been prerendered while it uses the data source
+ * specified by {@link setDataSourceID}, a databind call will be called by this method.
+ * @param boolean whether a databind call is required.
+ */
+ protected function setRequiresDataBinding($value)
+ {
+ $value=TPropertyValue::ensureBoolean($value);
+ if($value && $this->_prerendered)
+ {
+ $this->_requiresDataBinding=true;
+ $this->ensureDataBound();
+ }
+ else
+ $this->_requiresDataBinding=$value;
+ }
+
+ /**
+ * Ensures any pending {@link dataBind} is called.
+ * This method calls {@link dataBind} if the data source is specified
+ * by {@link setDataSourceID} or if {@link getRequiresDataBinding RequiresDataBinding}
+ * is true.
+ */
+ protected function ensureDataBound()
+ {
+ if($this->_requiresDataBinding && ($this->getUsingDataSourceID() || $this->_requiresBindToNull))
+ {
+ $this->dataBind();
+ $this->_requiresBindToNull=false;
+ }
+ }
+
+ /**
+ * @return TPagedDataSource creates a paged data source
+ */
+ protected function createPagedDataSource()
+ {
+ $ds=new TPagedDataSource;
+ $ds->setCurrentPageIndex($this->getCurrentPageIndex());
+ $ds->setPageSize($this->getPageSize());
+ $ds->setAllowPaging($this->getAllowPaging());
+ $ds->setAllowCustomPaging($this->getAllowCustomPaging());
+ $ds->setVirtualItemCount($this->getVirtualItemCount());
+ return $ds;
+ }
+
+ /**
+ * Performs databinding.
+ * This method overrides the parent implementation by calling
+ * {@link performSelect} which fetches data from data source and does
+ * the actual binding work.
+ */
+ public function dataBind()
+ {
+ $this->setRequiresDataBinding(false);
+ $this->dataBindProperties();
+ $this->onDataBinding(null);
+
+ if(($view=$this->getDataSourceView())!==null)
+ $data=$view->select($this->getSelectParameters());
+ else
+ $data=null;
+
+ if($data instanceof Traversable)
+ {
+ if($this->getAllowPaging())
+ {
+ $ds=$this->createPagedDataSource();
+ $ds->setDataSource($data);
+ $this->setViewState('PageCount',$ds->getPageCount());
+ if($ds->getCurrentPageIndex()>=$ds->getPageCount())
+ {
+ $ds->setCurrentPageIndex($ds->getPageCount()-1);
+ $this->setCurrentPageIndex($ds->getCurrentPageIndex());
+ }
+ $this->performDataBinding($ds);
+ }
+ else
+ {
+ $this->clearViewState('PageCount');
+ $this->performDataBinding($data);
+ }
+ }
+ $this->setIsDataBound(true);
+ $this->onDataBound(null);
+ }
+
+ public function dataSourceViewChanged($sender,$param)
+ {
+ if(!$this->_ignoreDataSourceViewChanged)
+ $this->setRequiresDataBinding(true);
+ }
+
+ protected function getDataSourceView()
+ {
+ if(!$this->_currentViewValid)
+ {
+ if($this->_currentView && $this->_currentViewIsFromDataSourceID)
+ $this->_currentView->detachEventHandler('DataSourceViewChanged',array($this,'dataSourceViewChanged'));
+ if(($dataSource=$this->determineDataSource())!==null)
+ {
+ if(($view=$dataSource->getView($this->getDataMember()))===null)
+ throw new TInvalidDataValueException('databoundcontrol_datamember_invalid',$this->getDataMember());
+ if($this->_currentViewIsFromDataSourceID=$this->getUsingDataSourceID())
+ $view->attachEventHandler('OnDataSourceViewChanged',array($this,'dataSourceViewChanged'));
+ $this->_currentView=$view;
+ }
+ else
+ $this->_currentView=null;
+ $this->_currentViewValid=true;
+ }
+ return $this->_currentView;
+ }
+
+ protected function determineDataSource()
+ {
+ if(!$this->_currentDataSourceValid)
+ {
+ if(($dsid=$this->getDataSourceID())!=='')
+ {
+ if(($dataSource=$this->getNamingContainer()->findControl($dsid))===null)
+ throw new TInvalidDataValueException('databoundcontrol_datasourceid_inexistent',$dsid);
+ else if(!($dataSource instanceof IDataSource))
+ throw new TInvalidDataValueException('databoundcontrol_datasourceid_invalid',$dsid);
+ else
+ $this->_currentDataSource=$dataSource;
+ }
+ else if(($dataSource=$this->getDataSource())!==null)
+ $this->_currentDataSource=new TReadOnlyDataSource($dataSource,$this->getDataMember());
+ else
+ $this->_currentDataSource=null;
+ $this->_currentDataSourceValid=true;
+ }
+ return $this->_currentDataSource;
+ }
+
+ abstract protected function performDataBinding($data);
+
+ /**
+ * Raises <b>OnDataBound</b> event.
+ * This method should be invoked after a databind is performed.
+ * It is mainly used by framework and component developers.
+ */
+ public function onDataBound($param)
+ {
+ $this->raiseEvent('OnDataBound',$this,$param);
+ }
+
+ /**
+ * Sets page's <b>OnPreLoad</b> event handler as {@link pagePreLoad}.
+ * If viewstate is disabled and the current request is a postback,
+ * {@link setRequiresDataBinding RequiresDataBinding} will be set true.
+ * This method overrides the parent implementation.
+ * @param TEventParameter event parameter
+ */
+ public function onInit($param)
+ {
+ parent::onInit($param);
+ $page=$this->getPage();
+ $page->attachEventHandler('OnPreLoad',array($this,'pagePreLoad'));
+ }
+
+ /**
+ * Sets {@link getInitialized} as true.
+ * This method is invoked when page raises <b>PreLoad</b> event.
+ * @param mixed event sender
+ * @param TEventParameter event parameter
+ */
+ public function pagePreLoad($sender,$param)
+ {
+ $this->_initialized=true;
+ $isPostBack=$this->getPage()->getIsPostBack();
+ if(!$isPostBack || ($isPostBack && (!$this->getEnableViewState(true) || !$this->getIsDataBound())))
+ $this->setRequiresDataBinding(true);
+ }
+
+ /**
+ * Ensures any pending databind is performed.
+ * This method overrides the parent implementation.
+ * @param TEventParameter event parameter
+ */
+ public function onPreRender($param)
+ {
+ $this->_prerendered=true;
+ $this->ensureDataBound();
+ parent::onPreRender($param);
+ }
+
+ /**
+ * Validates if the parameter is a valid data source.
+ * If it is a string or an array, it will be converted as a TList object.
+ * @param Traversable|array|string data source to be validated
+ * @return Traversable the data that is traversable
+ * @throws TInvalidDataTypeException if the data is neither null nor Traversable
+ */
+ protected function validateDataSource($value)
+ {
+ if(is_string($value))
+ {
+ $list=new TList;
+ foreach(TPropertyValue::ensureArray($value) as $key=>$value)
+ {
+ if(is_array($value))
+ $list->add($value);
+ else
+ $list->add(array($value,is_string($key)?$key:$value));
+ }
+ return $list;
+ }
+ else if(is_array($value))
+ return new TMap($value);
+ else if($value instanceof TDbDataReader) {
+ // read array from TDbDataReader since it's forward-only stream and can only be traversed once
+ return $value->readAll();
+ }
+ else if(($value instanceof Traversable) || $value===null)
+ return $value;
+ else
+ throw new TInvalidDataTypeException('databoundcontrol_datasource_invalid',get_class($this));
+ }
+
+ public function getDataMember()
+ {
+ return $this->getViewState('DataMember','');
+ }
+
+ public function setDataMember($value)
+ {
+ $this->setViewState('DataMember',$value,'');
+ }
+
+ public function getSelectParameters()
+ {
+ if(!$this->_parameters)
+ $this->_parameters=new TDataSourceSelectParameters;
+ return $this->_parameters;
+ }
+}
+
+
+/**
+ * TListItemType class.
+ * TListItemType defines the enumerable type for the possible types
+ * that databound list items could take.
+ *
+ * The following enumerable values are defined:
+ * - Header: header item
+ * - Footer: footer item
+ * - Item: content item (neither header nor footer)
+ * - Separator: separator between items
+ * - AlternatingItem: alternating content item
+ * - EditItem: content item in edit mode
+ * - SelectedItem: selected content item
+ * - Pager: pager
+ *
+ * @author Qiang Xue <qiang.xue@gmail.com>
+ * @version $Id$
+ * @package System.Web.UI.WebControls
+ * @since 3.0.4
+ */
+class TListItemType extends TEnumerable
+{
+ const Header='Header';
+ const Footer='Footer';
+ const Item='Item';
+ const Separator='Separator';
+ const AlternatingItem='AlternatingItem';
+ const EditItem='EditItem';
+ const SelectedItem='SelectedItem';
+ const Pager='Pager';
+}
+
+
+/**
+ * IItemDataRenderer interface.
+ *
+ * IItemDataRenderer defines the interface that an item renderer
+ * needs to implement. Besides the {@link getData Data} property, a list item
+ * renderer also needs to provide {@link getItemIndex ItemIndex} and
+ * {@link getItemType ItemType} property.
+ *
+ * @author Qiang Xue <qiang.xue@gmail.com>
+ * @version $Id$
+ * @package System.Web.UI.WebControls
+ * @since 3.1.0
+ */
+interface IItemDataRenderer extends IDataRenderer
+{
+ /**
+ * Returns a value indicating the zero-based index of the item in the corresponding data control's item collection.
+ * If the item is not in the collection (e.g. it is a header item), it returns -1.
+ * @return integer zero-based index of the item.
+ */
+ public function getItemIndex();
+
+ /**
+ * Sets the zero-based index for the item.
+ * If the item is not in the item collection (e.g. it is a header item), -1 should be used.
+ * @param integer zero-based index of the item.
+ */
+ public function setItemIndex($value);
+
+ /**
+ * @return TListItemType the item type.
+ */
+ public function getItemType();
+
+ /**
+ * @param TListItemType the item type.
+ */
+ public function setItemType($value);
+}
+
+?>
diff --git a/framework/Web/UI/WebControls/TDataGrid.php b/framework/Web/UI/WebControls/TDataGrid.php
index 2af66b33..2e2c5252 100644
--- a/framework/Web/UI/WebControls/TDataGrid.php
+++ b/framework/Web/UI/WebControls/TDataGrid.php
@@ -1,2258 +1,2258 @@
-<?php
-/**
- * TDataGrid related class files.
- * This file contains the definition of the following classes:
- * TDataGrid, TDataGridItem, TDataGridItemCollection, TDataGridColumnCollection,
- * TDataGridPagerStyle, TDataGridItemEventParameter,
- * TDataGridCommandEventParameter, TDataGridSortCommandEventParameter,
- * TDataGridPageChangedEventParameter
- *
- * @author Qiang Xue <qiang.xue@gmail.com>
- * @link http://www.pradosoft.com/
- * @copyright Copyright &copy; 2005-2012 PradoSoft
- * @license http://www.pradosoft.com/license/
- * @version $Id$
- * @package System.Web.UI.WebControls
- */
-
-/**
- * Includes TBaseList, TPagedDataSource, TDummyDataSource and TTable classes
- */
-Prado::using('System.Web.UI.WebControls.TBaseDataList');
-Prado::using('System.Collections.TPagedDataSource');
-Prado::using('System.Collections.TDummyDataSource');
-Prado::using('System.Web.UI.WebControls.TTable');
-Prado::using('System.Web.UI.WebControls.TPanel');
-Prado::using('System.Web.UI.WebControls.TDataGridPagerStyle');
-
-/**
- * TDataGrid class
- *
- * TDataGrid represents a data bound and updatable grid control.
- *
- * To populate data into the datagrid, sets its {@link setDataSource DataSource}
- * to a tabular data source and call {@link dataBind()}.
- * Each row of data will be represented by an item in the {@link getItems Items}
- * collection of the datagrid.
- *
- * An item can be at one of three states: browsing, selected and edit.
- * The state determines how the item will be displayed. For example, if an item
- * is in edit state, it may be displayed as a table row with input text boxes
- * if the columns are of type {@link TBoundColumn}; and if in browsing state,
- * they are displayed as static text.
- *
- * To change the state of an item, set {@link setEditItemIndex EditItemIndex}
- * or {@link setSelectedItemIndex SelectedItemIndex} property.
- *
- * Each datagrid item has a {@link TDataGridItem::getItemType type}
- * which tells the position and state of the item in the datalist. An item in the header
- * of the repeater is of type Header. A body item may be of either
- * Item, AlternatingItem, SelectedItem or EditItem, depending whether the item
- * index is odd or even, whether it is being selected or edited.
- *
- * A datagrid is specified with a list of columns. Each column specifies how the corresponding
- * table column will be displayed. For example, the header/footer text of that column,
- * the cells in that column, and so on. The following column types are currently
- * provided by the framework,
- * - {@link TBoundColumn}, associated with a specific field in datasource and displays the corresponding data.
- * - {@link TEditCommandColumn}, displaying edit/update/cancel command buttons
- * - {@link TButtonColumn}, displaying generic command buttons that may be bound to specific field in datasource.
- * - {@link TDropDownListColumn}, displaying a dropdown list when the item is in edit state
- * - {@link THyperLinkColumn}, displaying a hyperlink that may be bound to specific field in datasource.
- * - {@link TCheckBoxColumn}, displaying a checkbox that may be bound to specific field in datasource.
- * - {@link TTemplateColumn}, displaying content based on templates.
- *
- * There are three ways to specify columns for a datagrid.
- * <ul>
- * <li>Automatically generated based on data source.
- * By setting {@link setAutoGenerateColumns AutoGenerateColumns} to true,
- * a list of columns will be automatically generated based on the schema of the data source.
- * Each column corresponds to a column of the data.</li>
- * <li>Specified in template. For example,
- * <code>
- * <com:TDataGrid ...>
- * <com:TBoundColumn .../>
- * <com:TEditCommandColumn .../>
- * </com:TDataGrid>
- * </code>
- * </li>
- * <li>Manually created in code. Columns can be manipulated via
- * the {@link setColumns Columns} property of the datagrid. For example,
- * <code>
- * $column=new TBoundColumn;
- * $datagrid->Columns[]=$column;
- * </code>
- * </li>
- * </ul>
- * Note, automatically generated columns cannot be accessed via
- * the {@link getColumns Columns} property.
- *
- * TDataGrid supports sorting. If the {@link setAllowSorting AllowSorting}
- * is set to true, a column with nonempty {@link setSortExpression SortExpression}
- * will have its header text displayed as a clickable link button.
- * Clicking on the link button will raise {@link onSortCommand OnSortCommand}
- * event. You can respond to this event, sort the data source according
- * to the event parameter, and then invoke {@link databind()} on the datagrid
- * to show to end users the sorted data.
- *
- * TDataGrid supports paging. If the {@link setAllowPaging AllowPaging}
- * is set to true, a pager will be displayed on top and/or bottom of the table.
- * How the pager will be displayed is determined by the {@link getPagerStyle PagerStyle}
- * property. Clicking on a pager button will raise an {@link onPageIndexChanged OnPageIndexChanged}
- * event. You can respond to this event, specify the page to be displayed by
- * setting {@link setCurrentPageIndex CurrentPageIndex}</b> property,
- * and then invoke {@link databind()} on the datagrid to show to end users
- * a new page of data.
- *
- * TDataGrid supports two kinds of paging. The first one is based on the number of data items in
- * datasource. The number of pages {@link getPageCount PageCount} is calculated based
- * the item number and the {@link setPageSize PageSize} property.
- * The datagrid will manage which section of the data source to be displayed
- * based on the {@link setCurrentPageIndex CurrentPageIndex} property.
- * The second approach calculates the page number based on the
- * {@link setVirtualItemCount VirtualItemCount} property and
- * the {@link setPageSize PageSize} property. The datagrid will always
- * display from the beginning of the datasource up to the number of
- * {@link setPageSize PageSize} data items. This approach is especially
- * useful when the datasource may contain too many data items to be managed by
- * the datagrid efficiently.
- *
- * When the datagrid contains a button control that raises an {@link onCommand OnCommand}
- * event, the event will be bubbled up to the datagrid control.
- * If the event's command name is recognizable by the datagrid control,
- * a corresponding item event will be raised. The following item events will be
- * raised upon a specific command:
- * - OnEditCommand, if CommandName=edit
- * - OnCancelCommand, if CommandName=cancel
- * - OnSelectCommand, if CommandName=select
- * - OnDeleteCommand, if CommandName=delete
- * - OnUpdateCommand, if CommandName=update
- * - onPageIndexChanged, if CommandName=page
- * - OnSortCommand, if CommandName=sort
- * Note, an {@link onItemCommand OnItemCommand} event is raised in addition to
- * the above specific command events.
- *
- * TDataGrid also raises an {@link onItemCreated OnItemCreated} event for
- * every newly created datagrid item. You can respond to this event to customize
- * the content or style of the newly created item.
- *
- * Note, the data bound to the datagrid are reset to null after databinding.
- * There are several ways to access the data associated with a datagrid row:
- * - Access the data in {@link onItemDataBound OnItemDataBound} event
- * - Use {@link getDataKeys DataKeys} to obtain the data key associated with
- * the specified datagrid row and use the key to fetch the corresponding data
- * from some persistent storage such as DB.
- * - Save the data in viewstate and get it back during postbacks.
- *
- * @author Qiang Xue <qiang.xue@gmail.com>
- * @version $Id$
- * @package System.Web.UI.WebControls
- * @since 3.0
- */
-class TDataGrid extends TBaseDataList implements INamingContainer
-{
- /**
- * datagrid item types
- * @deprecated deprecated since version 3.0.4. Use TListItemType constants instead.
- */
- const IT_HEADER='Header';
- const IT_FOOTER='Footer';
- const IT_ITEM='Item';
- const IT_SEPARATOR='Separator';
- const IT_ALTERNATINGITEM='AlternatingItem';
- const IT_EDITITEM='EditItem';
- const IT_SELECTEDITEM='SelectedItem';
- const IT_PAGER='Pager';
-
- /**
- * Command name that TDataGrid understands.
- */
- const CMD_SELECT='Select';
- const CMD_EDIT='Edit';
- const CMD_UPDATE='Update';
- const CMD_DELETE='Delete';
- const CMD_CANCEL='Cancel';
- const CMD_SORT='Sort';
- const CMD_PAGE='Page';
- const CMD_PAGE_NEXT='Next';
- const CMD_PAGE_PREV='Previous';
- const CMD_PAGE_FIRST='First';
- const CMD_PAGE_LAST='Last';
-
- /**
- * @var TDataGridColumnCollection manually created column collection
- */
- private $_columns=null;
- /**
- * @var TDataGridColumnCollection automatically created column collection
- */
- private $_autoColumns=null;
- /**
- * @var TList all columns including both manually and automatically created columns
- */
- private $_allColumns=null;
- /**
- * @var TDataGridItemCollection datagrid item collection
- */
- private $_items=null;
- /**
- * @var TDataGridItem header item
- */
- private $_header=null;
- /**
- * @var TDataGridItem footer item
- */
- private $_footer=null;
- /**
- * @var TPagedDataSource paged data source object
- */
- private $_pagedDataSource=null;
- private $_topPager=null;
- private $_bottomPager=null;
- /**
- * @var ITemplate template used when empty data is bounded
- */
- private $_emptyTemplate=null;
- /**
- * @var boolean whether empty template is effective
- */
- private $_useEmptyTemplate=false;
-
- /**
- * @return string tag name (table) of the datagrid
- */
- protected function getTagName()
- {
- return 'table';
- }
-
- /**
- * @return string Name of the class used in AutoGenerateColumns mode
- */
- protected function getAutoGenerateColumnName()
- {
- return 'TBoundColumn';
- }
-
- /**
- * Adds objects parsed in template to datagrid.
- * Datagrid columns are added into {@link getColumns Columns} collection.
- * @param mixed object parsed in template
- */
- public function addParsedObject($object)
- {
- if($object instanceof TDataGridColumn)
- $this->getColumns()->add($object);
- else
- parent::addParsedObject($object); // this is needed by EmptyTemplate
- }
-
- /**
- * @return TDataGridColumnCollection manually specified datagrid columns
- */
- public function getColumns()
- {
- if(!$this->_columns)
- $this->_columns=new TDataGridColumnCollection($this);
- return $this->_columns;
- }
-
- /**
- * @return TDataGridColumnCollection automatically generated datagrid columns
- */
- public function getAutoColumns()
- {
- if(!$this->_autoColumns)
- $this->_autoColumns=new TDataGridColumnCollection($this);
- return $this->_autoColumns;
- }
-
- /**
- * @return TDataGridItemCollection datagrid item collection
- */
- public function getItems()
- {
- if(!$this->_items)
- $this->_items=new TDataGridItemCollection;
- return $this->_items;
- }
-
- /**
- * @return integer number of items
- */
- public function getItemCount()
- {
- return $this->_items?$this->_items->getCount():0;
- }
-
- /**
- * Creates a style object for the control.
- * This method creates a {@link TTableStyle} to be used by datagrid.
- * @return TTableStyle control style to be used
- */
- protected function createStyle()
- {
- return new TTableStyle;
- }
-
- /**
- * @return string the URL of the background image for the datagrid
- */
- public function getBackImageUrl()
- {
- return $this->getStyle()->getBackImageUrl();
- }
-
- /**
- * @param string the URL of the background image for the datagrid
- */
- public function setBackImageUrl($value)
- {
- $this->getStyle()->setBackImageUrl($value);
- }
-
- /**
- * @return TTableItemStyle the style for every item
- */
- public function getItemStyle()
- {
- if(($style=$this->getViewState('ItemStyle',null))===null)
- {
- $style=new TTableItemStyle;
- $this->setViewState('ItemStyle',$style,null);
- }
- return $style;
- }
-
- /**
- * @return TTableItemStyle the style for each alternating item
- */
- public function getAlternatingItemStyle()
- {
- if(($style=$this->getViewState('AlternatingItemStyle',null))===null)
- {
- $style=new TTableItemStyle;
- $this->setViewState('AlternatingItemStyle',$style,null);
- }
- return $style;
- }
-
- /**
- * @return TTableItemStyle the style for selected item
- */
- public function getSelectedItemStyle()
- {
- if(($style=$this->getViewState('SelectedItemStyle',null))===null)
- {
- $style=new TTableItemStyle;
- $this->setViewState('SelectedItemStyle',$style,null);
- }
- return $style;
- }
-
- /**
- * @return TTableItemStyle the style for edit item
- */
- public function getEditItemStyle()
- {
- if(($style=$this->getViewState('EditItemStyle',null))===null)
- {
- $style=new TTableItemStyle;
- $this->setViewState('EditItemStyle',$style,null);
- }
- return $style;
- }
-
- /**
- * @return TTableItemStyle the style for header
- */
- public function getHeaderStyle()
- {
- if(($style=$this->getViewState('HeaderStyle',null))===null)
- {
- $style=new TTableItemStyle;
- $this->setViewState('HeaderStyle',$style,null);
- }
- return $style;
- }
-
- /**
- * @return TTableItemStyle the style for footer
- */
- public function getFooterStyle()
- {
- if(($style=$this->getViewState('FooterStyle',null))===null)
- {
- $style=new TTableItemStyle;
- $this->setViewState('FooterStyle',$style,null);
- }
- return $style;
- }
-
- /**
- * @return TDataGridPagerStyle the style for pager
- */
- public function getPagerStyle()
- {
- if(($style=$this->getViewState('PagerStyle',null))===null)
- {
- $style=new TDataGridPagerStyle;
- $this->setViewState('PagerStyle',$style,null);
- }
- return $style;
- }
-
- /**
- * @return TStyle the style for thead element, if any
- * @since 3.1.1
- */
- public function getTableHeadStyle()
- {
- if(($style=$this->getViewState('TableHeadStyle',null))===null)
- {
- $style=new TStyle;
- $this->setViewState('TableHeadStyle',$style,null);
- }
- return $style;
- }
-
- /**
- * @return TStyle the style for tbody element, if any
- * @since 3.1.1
- */
- public function getTableBodyStyle()
- {
- if(($style=$this->getViewState('TableBodyStyle',null))===null)
- {
- $style=new TStyle;
- $this->setViewState('TableBodyStyle',$style,null);
- }
- return $style;
- }
-
- /**
- * @return TStyle the style for tfoot element, if any
- * @since 3.1.1
- */
- public function getTableFootStyle()
- {
- if(($style=$this->getViewState('TableFootStyle',null))===null)
- {
- $style=new TStyle;
- $this->setViewState('TableFootStyle',$style,null);
- }
- return $style;
- }
-
- /**
- * @return string caption for the datagrid
- */
- public function getCaption()
- {
- return $this->getViewState('Caption','');
- }
-
- /**
- * @param string caption for the datagrid
- */
- public function setCaption($value)
- {
- $this->setViewState('Caption',$value,'');
- }
-
- /**
- * @return TTableCaptionAlign datagrid caption alignment. Defaults to TTableCaptionAlign::NotSet.
- */
- public function getCaptionAlign()
- {
- return $this->getViewState('CaptionAlign',TTableCaptionAlign::NotSet);
- }
-
- /**
- * @param TTableCaptionAlign datagrid caption alignment. Valid values include
- */
- public function setCaptionAlign($value)
- {
- $this->setViewState('CaptionAlign',TPropertyValue::ensureEnum($value,'TTableCaptionAlign'),TTableCaptionAlign::NotSet);
- }
-
- /**
- * @return TDataGridItem the header item
- */
- public function getHeader()
- {
- return $this->_header;
- }
-
- /**
- * @return TDataGridItem the footer item
- */
- public function getFooter()
- {
- return $this->_footer;
- }
-
- /**
- * @return TDataGridPager the pager displayed at the top of datagrid. It could be null if paging is disabled.
- */
- public function getTopPager()
- {
- return $this->_topPager;
- }
-
- /**
- * @return TDataGridPager the pager displayed at the bottom of datagrid. It could be null if paging is disabled.
- */
- public function getBottomPager()
- {
- return $this->_bottomPager;
- }
-
- /**
- * @return TDataGridItem the selected item, null if no item is selected.
- */
- public function getSelectedItem()
- {
- $index=$this->getSelectedItemIndex();
- $items=$this->getItems();
- if($index>=0 && $index<$items->getCount())
- return $items->itemAt($index);
- else
- return null;
- }
-
- /**
- * @return integer the zero-based index of the selected item in {@link getItems Items}.
- * A value -1 means no item selected.
- */
- public function getSelectedItemIndex()
- {
- return $this->getViewState('SelectedItemIndex',-1);
- }
-
- /**
- * Selects an item by its index in {@link getItems Items}.
- * Previously selected item will be un-selected.
- * If the item to be selected is already in edit mode, it will remain in edit mode.
- * If the index is less than 0, any existing selection will be cleared up.
- * @param integer the selected item index
- */
- public function setSelectedItemIndex($value)
- {
- if(($value=TPropertyValue::ensureInteger($value))<0)
- $value=-1;
- if(($current=$this->getSelectedItemIndex())!==$value)
- {
- $this->setViewState('SelectedItemIndex',$value,-1);
- $items=$this->getItems();
- $itemCount=$items->getCount();
- if($current>=0 && $current<$itemCount)
- {
- $item=$items->itemAt($current);
- if($item->getItemType()!==TListItemType::EditItem)
- $item->setItemType($current%2?TListItemType::AlternatingItem:TListItemType::Item);
- }
- if($value>=0 && $value<$itemCount)
- {
- $item=$items->itemAt($value);
- if($item->getItemType()!==TListItemType::EditItem)
- $item->setItemType(TListItemType::SelectedItem);
- }
- }
- }
-
- /**
- * @return TDataGridItem the edit item
- */
- public function getEditItem()
- {
- $index=$this->getEditItemIndex();
- $items=$this->getItems();
- if($index>=0 && $index<$items->getCount())
- return $items->itemAt($index);
- else
- return null;
- }
-
- /**
- * @return integer the zero-based index of the edit item in {@link getItems Items}.
- * A value -1 means no item is in edit mode.
- */
- public function getEditItemIndex()
- {
- return $this->getViewState('EditItemIndex',-1);
- }
-
- /**
- * Edits an item by its index in {@link getItems Items}.
- * Previously editting item will change to normal item state.
- * If the index is less than 0, any existing edit item will be cleared up.
- * @param integer the edit item index
- */
- public function setEditItemIndex($value)
- {
- if(($value=TPropertyValue::ensureInteger($value))<0)
- $value=-1;
- if(($current=$this->getEditItemIndex())!==$value)
- {
- $this->setViewState('EditItemIndex',$value,-1);
- $items=$this->getItems();
- $itemCount=$items->getCount();
- if($current>=0 && $current<$itemCount)
- $items->itemAt($current)->setItemType($current%2?TListItemType::AlternatingItem:TListItemType::Item);
- if($value>=0 && $value<$itemCount)
- $items->itemAt($value)->setItemType(TListItemType::EditItem);
- }
- }
-
- /**
- * @return boolean whether sorting is enabled. Defaults to false.
- */
- public function getAllowSorting()
- {
- return $this->getViewState('AllowSorting',false);
- }
-
- /**
- * @param boolean whether sorting is enabled
- */
- public function setAllowSorting($value)
- {
- $this->setViewState('AllowSorting',TPropertyValue::ensureBoolean($value),false);
- }
-
- /**
- * @return boolean whether datagrid columns should be automatically generated. Defaults to true.
- */
- public function getAutoGenerateColumns()
- {
- return $this->getViewState('AutoGenerateColumns',true);
- }
-
- /**
- * @param boolean whether datagrid columns should be automatically generated
- */
- public function setAutoGenerateColumns($value)
- {
- $this->setViewState('AutoGenerateColumns',TPropertyValue::ensureBoolean($value),true);
- }
-
- /**
- * @return boolean whether the header should be displayed. Defaults to true.
- */
- public function getShowHeader()
- {
- return $this->getViewState('ShowHeader',true);
- }
-
- /**
- * @param boolean whether the header should be displayed
- */
- public function setShowHeader($value)
- {
- $this->setViewState('ShowHeader',TPropertyValue::ensureBoolean($value),true);
- }
-
- /**
- * @return boolean whether the footer should be displayed. Defaults to false.
- */
- public function getShowFooter()
- {
- return $this->getViewState('ShowFooter',false);
- }
-
- /**
- * @param boolean whether the footer should be displayed
- */
- public function setShowFooter($value)
- {
- $this->setViewState('ShowFooter',TPropertyValue::ensureBoolean($value),false);
- }
-
- /**
- * @return ITemplate the template applied when no data is bound to the datagrid
- */
- public function getEmptyTemplate()
- {
- return $this->_emptyTemplate;
- }
-
- /**
- * @param ITemplate the template applied when no data is bound to the datagrid
- * @throws TInvalidDataTypeException if the input is not an {@link ITemplate} or not null.
- */
- public function setEmptyTemplate($value)
- {
- if($value instanceof ITemplate || $value===null)
- $this->_emptyTemplate=$value;
- else
- throw new TInvalidDataTypeException('datagrid_template_required','EmptyTemplate');
- }
-
- /**
- * This method overrides parent's implementation to handle
- * {@link onItemCommand OnItemCommand} event which is bubbled from
- * {@link TDataGridItem} child controls.
- * If the event parameter is {@link TDataGridCommandEventParameter} and
- * the command name is a recognized one, which includes 'select', 'edit',
- * 'delete', 'update', and 'cancel' (case-insensitive), then a
- * corresponding command event is also raised (such as {@link onEditCommand OnEditCommand}).
- * This method should only be used by control developers.
- * @param TControl the sender of the event
- * @param TEventParameter event parameter
- * @return boolean whether the event bubbling should stop here.
- */
- public function bubbleEvent($sender,$param)
- {
- if($param instanceof TDataGridCommandEventParameter)
- {
- $this->onItemCommand($param);
- $command=$param->getCommandName();
- if(strcasecmp($command,self::CMD_SELECT)===0)
- {
- $this->setSelectedItemIndex($param->getItem()->getItemIndex());
- $this->onSelectedIndexChanged($param);
- return true;
- }
- else if(strcasecmp($command,self::CMD_EDIT)===0)
- {
- $this->onEditCommand($param);
- return true;
- }
- else if(strcasecmp($command,self::CMD_DELETE)===0)
- {
- $this->onDeleteCommand($param);
- return true;
- }
- else if(strcasecmp($command,self::CMD_UPDATE)===0)
- {
- $this->onUpdateCommand($param);
- return true;
- }
- else if(strcasecmp($command,self::CMD_CANCEL)===0)
- {
- $this->onCancelCommand($param);
- return true;
- }
- else if(strcasecmp($command,self::CMD_SORT)===0)
- {
- $this->onSortCommand(new TDataGridSortCommandEventParameter($sender,$param));
- return true;
- }
- else if(strcasecmp($command,self::CMD_PAGE)===0)
- {
- $p=$param->getCommandParameter();
- if(strcasecmp($p,self::CMD_PAGE_NEXT)===0)
- $pageIndex=$this->getCurrentPageIndex()+1;
- else if(strcasecmp($p,self::CMD_PAGE_PREV)===0)
- $pageIndex=$this->getCurrentPageIndex()-1;
- else if(strcasecmp($p,self::CMD_PAGE_FIRST)===0)
- $pageIndex=0;
- else if(strcasecmp($p,self::CMD_PAGE_LAST)===0)
- $pageIndex=$this->getPageCount()-1;
- else
- $pageIndex=TPropertyValue::ensureInteger($p)-1;
- $this->onPageIndexChanged(new TDataGridPageChangedEventParameter($sender,$pageIndex));
- return true;
- }
- }
- return false;
- }
-
- /**
- * Raises <b>OnCancelCommand</b> event.
- * This method is invoked when a button control raises <b>OnCommand</b> event
- * with <b>cancel</b> command name.
- * @param TDataGridCommandEventParameter event parameter
- */
- public function onCancelCommand($param)
- {
- $this->raiseEvent('OnCancelCommand',$this,$param);
- }
-
- /**
- * Raises <b>OnDeleteCommand</b> event.
- * This method is invoked when a button control raises <b>OnCommand</b> event
- * with <b>delete</b> command name.
- * @param TDataGridCommandEventParameter event parameter
- */
- public function onDeleteCommand($param)
- {
- $this->raiseEvent('OnDeleteCommand',$this,$param);
- }
-
- /**
- * Raises <b>OnEditCommand</b> event.
- * This method is invoked when a button control raises <b>OnCommand</b> event
- * with <b>edit</b> command name.
- * @param TDataGridCommandEventParameter event parameter
- */
- public function onEditCommand($param)
- {
- $this->raiseEvent('OnEditCommand',$this,$param);
- }
-
- /**
- * Raises <b>OnItemCommand</b> event.
- * This method is invoked when a button control raises <b>OnCommand</b> event.
- * @param TDataGridCommandEventParameter event parameter
- */
- public function onItemCommand($param)
- {
- $this->raiseEvent('OnItemCommand',$this,$param);
- }
-
- /**
- * Raises <b>OnSortCommand</b> event.
- * This method is invoked when a button control raises <b>OnCommand</b> event
- * with <b>sort</b> command name.
- * @param TDataGridSortCommandEventParameter event parameter
- */
- public function onSortCommand($param)
- {
- $this->raiseEvent('OnSortCommand',$this,$param);
- }
-
- /**
- * Raises <b>OnUpdateCommand</b> event.
- * This method is invoked when a button control raises <b>OnCommand</b> event
- * with <b>update</b> command name.
- * @param TDataGridCommandEventParameter event parameter
- */
- public function onUpdateCommand($param)
- {
- $this->raiseEvent('OnUpdateCommand',$this,$param);
- }
-
- /**
- * Raises <b>OnItemCreated</b> event.
- * This method is invoked right after a datagrid item is created and before
- * added to page hierarchy.
- * @param TDataGridItemEventParameter event parameter
- */
- public function onItemCreated($param)
- {
- $this->raiseEvent('OnItemCreated',$this,$param);
- }
-
- /**
- * Raises <b>OnPagerCreated</b> event.
- * This method is invoked right after a datagrid pager is created and before
- * added to page hierarchy.
- * @param TDataGridPagerEventParameter event parameter
- */
- public function onPagerCreated($param)
- {
- $this->raiseEvent('OnPagerCreated',$this,$param);
- }
-
- /**
- * Raises <b>OnItemDataBound</b> event.
- * This method is invoked for each datagrid item after it performs
- * databinding.
- * @param TDataGridItemEventParameter event parameter
- */
- public function onItemDataBound($param)
- {
- $this->raiseEvent('OnItemDataBound',$this,$param);
- }
-
- /**
- * Raises <b>OnPageIndexChanged</b> event.
- * This method is invoked when current page is changed.
- * @param TDataGridPageChangedEventParameter event parameter
- */
- public function onPageIndexChanged($param)
- {
- $this->raiseEvent('OnPageIndexChanged',$this,$param);
- }
-
- /**
- * Saves item count in viewstate.
- * This method is invoked right before control state is to be saved.
- */
- public function saveState()
- {
- parent::saveState();
- if(!$this->getEnableViewState(true))
- return;
- if($this->_items)
- $this->setViewState('ItemCount',$this->_items->getCount(),0);
- else
- $this->clearViewState('ItemCount');
- if($this->_autoColumns)
- {
- $state=array();
- foreach($this->_autoColumns as $column)
- $state[]=$column->saveState();
- $this->setViewState('AutoColumns',$state,array());
- }
- else
- $this->clearViewState('AutoColumns');
- if($this->_columns)
- {
- $state=array();
- foreach($this->_columns as $column)
- $state[]=$column->saveState();
- $this->setViewState('Columns',$state,array());
- }
- else
- $this->clearViewState('Columns');
- }
-
- /**
- * Loads item count information from viewstate.
- * This method is invoked right after control state is loaded.
- */
- public function loadState()
- {
- parent::loadState();
- if(!$this->getEnableViewState(true))
- return;
- if(!$this->getIsDataBound())
- {
- $state=$this->getViewState('AutoColumns',array());
- if(!empty($state))
- {
- $this->_autoColumns=new TDataGridColumnCollection($this);
- foreach($state as $st)
- {
- $column=new $this->AutoGenerateColumnName;
- $column->loadState($st);
- $this->_autoColumns->add($column);
- }
- }
- else
- $this->_autoColumns=null;
- $state=$this->getViewState('Columns',array());
- if($this->_columns && $this->_columns->getCount()===count($state))
- {
- $i=0;
- foreach($this->_columns as $column)
- {
- $column->loadState($state[$i]);
- $i++;
- }
- }
- $this->restoreGridFromViewState();
- }
- }
-
- /**
- * Clears up all items in the datagrid.
- */
- public function reset()
- {
- $this->getControls()->clear();
- $this->getItems()->clear();
- $this->_header=null;
- $this->_footer=null;
- $this->_topPager=null;
- $this->_bottomPager=null;
- $this->_useEmptyTemplate=false;
- }
-
- /**
- * Restores datagrid content from viewstate.
- */
- protected function restoreGridFromViewState()
- {
- $this->reset();
-
- $allowPaging=$this->getAllowPaging();
-
- $itemCount=$this->getViewState('ItemCount',0);
- $dsIndex=$this->getViewState('DataSourceIndex',0);
-
- $columns=new TList($this->getColumns());
- $columns->mergeWith($this->_autoColumns);
- $this->_allColumns=$columns;
-
- $items=$this->getItems();
-
- if($columns->getCount())
- {
- foreach($columns as $column)
- $column->initialize();
- $selectedIndex=$this->getSelectedItemIndex();
- $editIndex=$this->getEditItemIndex();
- for($index=0;$index<$itemCount;++$index)
- {
- if($index===0)
- {
- if($allowPaging)
- $this->_topPager=$this->createPager();
- $this->_header=$this->createItemInternal(-1,-1,TListItemType::Header,false,null,$columns);
- }
- if($index===$editIndex)
- $itemType=TListItemType::EditItem;
- else if($index===$selectedIndex)
- $itemType=TListItemType::SelectedItem;
- else if($index % 2)
- $itemType=TListItemType::AlternatingItem;
- else
- $itemType=TListItemType::Item;
- $items->add($this->createItemInternal($index,$dsIndex,$itemType,false,null,$columns));
- $dsIndex++;
- }
- if($index>0)
- {
- $this->_footer=$this->createItemInternal(-1,-1,TListItemType::Footer,false,null,$columns);
- if($allowPaging)
- $this->_bottomPager=$this->createPager();
- }
- }
- if(!$dsIndex && $this->_emptyTemplate!==null)
- {
- $this->_useEmptyTemplate=true;
- $this->_emptyTemplate->instantiateIn($this);
- }
- }
-
- /**
- * Performs databinding to populate datagrid items from data source.
- * This method is invoked by {@link dataBind()}.
- * You may override this function to provide your own way of data population.
- * @param Traversable the bound data
- */
- protected function performDataBinding($data)
- {
- $this->reset();
- $keys=$this->getDataKeys();
- $keys->clear();
- $keyField=$this->getDataKeyField();
-
- // get all columns
- if($this->getAutoGenerateColumns())
- {
- $columns=new TList($this->getColumns());
- $autoColumns=$this->createAutoColumns($data);
- $columns->mergeWith($autoColumns);
- }
- else
- $columns=$this->getColumns();
- $this->_allColumns=$columns;
-
- $items=$this->getItems();
-
- $index=0;
- $allowPaging=$this->getAllowPaging() && ($data instanceof TPagedDataSource);
- $dsIndex=$allowPaging?$data->getFirstIndexInPage():0;
- $this->setViewState('DataSourceIndex',$dsIndex,0);
- if($columns->getCount())
- {
- foreach($columns as $column)
- $column->initialize();
-
- $selectedIndex=$this->getSelectedItemIndex();
- $editIndex=$this->getEditItemIndex();
- foreach($data as $key=>$row)
- {
- if($keyField!=='')
- $keys->add($this->getDataFieldValue($row,$keyField));
- else
- $keys->add($key);
- if($index===0)
- {
- if($allowPaging)
- $this->_topPager=$this->createPager();
- $this->_header=$this->createItemInternal(-1,-1,TListItemType::Header,true,null,$columns);
- }
- if($index===$editIndex)
- $itemType=TListItemType::EditItem;
- else if($index===$selectedIndex)
- $itemType=TListItemType::SelectedItem;
- else if($index % 2)
- $itemType=TListItemType::AlternatingItem;
- else
- $itemType=TListItemType::Item;
- $items->add($this->createItemInternal($index,$dsIndex,$itemType,true,$row,$columns));
- $index++;
- $dsIndex++;
- }
- if($index>0)
- {
- $this->_footer=$this->createItemInternal(-1,-1,TListItemType::Footer,true,null,$columns);
- if($allowPaging)
- $this->_bottomPager=$this->createPager();
- }
- }
- $this->setViewState('ItemCount',$index,0);
- if(!$dsIndex && $this->_emptyTemplate!==null)
- {
- $this->_useEmptyTemplate=true;
- $this->_emptyTemplate->instantiateIn($this);
- $this->dataBindChildren();
- }
- }
-
- /**
- * Merges consecutive cells who have the same text.
- * @since 3.1.1
- */
- private function groupCells()
- {
- if(($columns=$this->_allColumns)===null)
- return;
- $items=$this->getItems();
- foreach($columns as $id=>$column)
- {
- if(!$column->getEnableCellGrouping())
- continue;
- $prevCell=null;
- $prevCellText=null;
- foreach($items as $item)
- {
- $itemType=$item->getItemType();
- $cell=$item->getCells()->itemAt($id);
- if(!$cell->getVisible())
- continue;
- if($itemType===TListItemType::Item || $itemType===TListItemType::AlternatingItem || $itemType===TListItemType::SelectedItem)
- {
- if(($cellText=$this->getCellText($cell))==='')
- {
- $prevCell=null;
- $prevCellText=null;
- continue;
- }
- if($prevCell===null || $prevCellText!==$cellText)
- {
- $prevCell=$cell;
- $prevCellText=$cellText;
- }
- else
- {
- if(($rowSpan=$prevCell->getRowSpan())===0)
- $rowSpan=1;
- $prevCell->setRowSpan($rowSpan+1);
- $cell->setVisible(false);
- }
- }
- }
- }
- }
-
- private function getCellText($cell)
- {
- if(($data=$cell->getText())==='' && $cell->getHasControls())
- {
- $controls=$cell->getControls();
- foreach($controls as $control)
- {
- if($control instanceof IDataRenderer)
- return $control->getData();
- }
- }
- return $data;
- }
-
- /**
- * Creates a datagrid item instance based on the item type and index.
- * @param integer zero-based item index
- * @param TListItemType item type
- * @return TDataGridItem created data list item
- */
- protected function createItem($itemIndex,$dataSourceIndex,$itemType)
- {
- return new TDataGridItem($itemIndex,$dataSourceIndex,$itemType);
- }
-
- private function createItemInternal($itemIndex,$dataSourceIndex,$itemType,$dataBind,$dataItem,$columns)
- {
- $item=$this->createItem($itemIndex,$dataSourceIndex,$itemType);
- $this->initializeItem($item,$columns);
- $param=new TDataGridItemEventParameter($item);
- if($dataBind)
- {
- $item->setDataItem($dataItem);
- $this->onItemCreated($param);
- $this->getControls()->add($item);
- $item->dataBind();
- $this->onItemDataBound($param);
- }
- else
- {
- $this->onItemCreated($param);
- $this->getControls()->add($item);
- }
- return $item;
- }
-
- /**
- * Initializes a datagrid item and cells inside it
- * @param TDataGrid datagrid item to be initialized
- * @param TDataGridColumnCollection datagrid columns to be used to initialize the cells in the item
- */
- protected function initializeItem($item,$columns)
- {
- $cells=$item->getCells();
- $itemType=$item->getItemType();
- $index=0;
- foreach($columns as $column)
- {
- if($itemType===TListItemType::Header)
- $cell=new TTableHeaderCell;
- else
- $cell=new TTableCell;
- if(($id=$column->getID())!=='')
- $item->registerObject($id,$cell);
- $cells->add($cell);
- $column->initializeCell($cell,$index,$itemType);
- $index++;
- }
- }
-
- protected function createPager()
- {
- $pager=new TDataGridPager($this);
- $this->buildPager($pager);
- $this->onPagerCreated(new TDataGridPagerEventParameter($pager));
- $this->getControls()->add($pager);
- return $pager;
- }
-
- /**
- * Builds the pager content based on pager style.
- * @param TDataGridPager the container for the pager
- */
- protected function buildPager($pager)
- {
- switch($this->getPagerStyle()->getMode())
- {
- case TDataGridPagerMode::NextPrev:
- $this->buildNextPrevPager($pager);
- break;
- case TDataGridPagerMode::Numeric:
- $this->buildNumericPager($pager);
- break;
- }
- }
-
- /**
- * Creates a pager button.
- * Depending on the button type, a TLinkButton or a TButton may be created.
- * If it is enabled (clickable), its command name and parameter will also be set.
- * Derived classes may override this method to create additional types of buttons, such as TImageButton.
- * @param mixed the container pager instance of TActiveDatagridPager
- * @param string button type, either LinkButton or PushButton
- * @param boolean whether the button should be enabled
- * @param string caption of the button
- * @param string CommandName corresponding to the OnCommand event of the button
- * @param string CommandParameter corresponding to the OnCommand event of the button
- * @return mixed the button instance
- */
- protected function createPagerButton($pager,$buttonType,$enabled,$text,$commandName,$commandParameter)
- {
- if($buttonType===TDataGridPagerButtonType::LinkButton)
- {
- if($enabled)
- $button=new TLinkButton;
- else
- {
- $button=new TLabel;
- $button->setText($text);
- return $button;
- }
- }
- else
- {
- $button=new TButton;
- if(!$enabled)
- $button->setEnabled(false);
- }
- $button->setText($text);
- $button->setCommandName($commandName);
- $button->setCommandParameter($commandParameter);
- $button->setCausesValidation(false);
- return $button;
- }
-
- /**
- * Builds a next-prev pager
- * @param TDataGridPager the container for the pager
- */
- protected function buildNextPrevPager($pager)
- {
- $style=$this->getPagerStyle();
- $buttonType=$style->getButtonType();
- $controls=$pager->getControls();
- $currentPageIndex=$this->getCurrentPageIndex();
- if($currentPageIndex===0)
- {
- if(($text=$style->getFirstPageText())!=='')
- {
- $label=$this->createPagerButton($pager,$buttonType,false,$text,'','');
- $controls->add($label);
- $controls->add("\n");
- }
-
- $label=$this->createPagerButton($pager,$buttonType,false,$style->getPrevPageText(),'','');
- $controls->add($label);
- }
- else
- {
- if(($text=$style->getFirstPageText())!=='')
- {
- $button=$this->createPagerButton($pager,$buttonType,true,$text,self::CMD_PAGE,self::CMD_PAGE_FIRST);
- $controls->add($button);
- $controls->add("\n");
- }
-
- $button=$this->createPagerButton($pager,$buttonType,true,$style->getPrevPageText(),self::CMD_PAGE,self::CMD_PAGE_PREV);
- $controls->add($button);
- }
- $controls->add("\n");
- if($currentPageIndex===$this->getPageCount()-1)
- {
- $label=$this->createPagerButton($pager,$buttonType,false,$style->getNextPageText(),'','');
- $controls->add($label);
- if(($text=$style->getLastPageText())!=='')
- {
- $controls->add("\n");
- $label=$this->createPagerButton($pager,$buttonType,false,$text,'','');
- $controls->add($label);
- }
- }
- else
- {
- $button=$this->createPagerButton($pager,$buttonType,true,$style->getNextPageText(),self::CMD_PAGE,self::CMD_PAGE_NEXT);
- $controls->add($button);
- if(($text=$style->getLastPageText())!=='')
- {
- $controls->add("\n");
- $button=$this->createPagerButton($pager,$buttonType,true,$text,self::CMD_PAGE,self::CMD_PAGE_LAST);
- $controls->add($button);
- }
- }
- }
-
- /**
- * Builds a numeric pager
- * @param TDataGridPager the container for the pager
- */
- protected function buildNumericPager($pager)
- {
- $style=$this->getPagerStyle();
- $buttonType=$style->getButtonType();
- $controls=$pager->getControls();
- $pageCount=$this->getPageCount();
- $pageIndex=$this->getCurrentPageIndex()+1;
- $maxButtonCount=$style->getPageButtonCount();
- $buttonCount=$maxButtonCount>$pageCount?$pageCount:$maxButtonCount;
- $startPageIndex=1;
- $endPageIndex=$buttonCount;
- if($pageIndex>$endPageIndex)
- {
- $startPageIndex=((int)(($pageIndex-1)/$maxButtonCount))*$maxButtonCount+1;
- if(($endPageIndex=$startPageIndex+$maxButtonCount-1)>$pageCount)
- $endPageIndex=$pageCount;
- if($endPageIndex-$startPageIndex+1<$maxButtonCount)
- {
- if(($startPageIndex=$endPageIndex-$maxButtonCount+1)<1)
- $startPageIndex=1;
- }
- }
-
- if($startPageIndex>1)
- {
- if(($text=$style->getFirstPageText())!=='')
- {
- $button=$this->createPagerButton($pager,$buttonType,true,$text,self::CMD_PAGE,self::CMD_PAGE_FIRST);
- $controls->add($button);
- $controls->add("\n");
- }
- $prevPageIndex=$startPageIndex-1;
- $button=$this->createPagerButton($pager,$buttonType,true,$style->getPrevPageText(),self::CMD_PAGE,"$prevPageIndex");
- $controls->add($button);
- $controls->add("\n");
- }
-
- for($i=$startPageIndex;$i<=$endPageIndex;++$i)
- {
- if($i===$pageIndex)
- {
- $label=$this->createPagerButton($pager,$buttonType,false,"$i",'','');
- $controls->add($label);
- }
- else
- {
- $button=$this->createPagerButton($pager,$buttonType,true,"$i",self::CMD_PAGE,"$i");
- $controls->add($button);
- }
- if($i<$endPageIndex)
- $controls->add("\n");
- }
-
- if($pageCount>$endPageIndex)
- {
- $controls->add("\n");
- $nextPageIndex=$endPageIndex+1;
- $button=$this->createPagerButton($pager,$buttonType,true,$style->getNextPageText(),self::CMD_PAGE,"$nextPageIndex");
- $controls->add($button);
- if(($text=$style->getLastPageText())!=='')
- {
- $controls->add("\n");
- $button=$this->createPagerButton($pager,$buttonType,true,$text,self::CMD_PAGE,self::CMD_PAGE_LAST);
- $controls->add($button);
- }
- }
- }
-
- /**
- * Automatically generates datagrid columns based on datasource schema
- * @param Traversable data source bound to the datagrid
- * @return TDataGridColumnCollection
- */
- protected function createAutoColumns($dataSource)
- {
- if(!$dataSource)
- return null;
- $autoColumns=$this->getAutoColumns();
- $autoColumns->clear();
- foreach($dataSource as $row)
- {
- foreach($row as $key=>$value)
- {
- $column=new $this->AutoGenerateColumnName;
- if(is_string($key))
- {
- $column->setHeaderText($key);
- $column->setDataField($key);
- $column->setSortExpression($key);
- $autoColumns->add($column);
- }
- else
- {
- $column->setHeaderText(TListItemType::Item);
- $column->setDataField($key);
- $column->setSortExpression(TListItemType::Item);
- $autoColumns->add($column);
- }
- }
- break;
- }
- return $autoColumns;
- }
-
- /**
- * Applies styles to items, header, footer and separators.
- * Item styles are applied in a hierarchical way. Style in higher hierarchy
- * will inherit from styles in lower hierarchy.
- * Starting from the lowest hierarchy, the item styles include
- * item's own style, {@link getItemStyle ItemStyle}, {@link getAlternatingItemStyle AlternatingItemStyle},
- * {@link getSelectedItemStyle SelectedItemStyle}, and {@link getEditItemStyle EditItemStyle}.
- * Therefore, if background color is set as red in {@link getItemStyle ItemStyle},
- * {@link getEditItemStyle EditItemStyle} will also have red background color
- * unless it is set to a different value explicitly.
- */
- protected function applyItemStyles()
- {
- $itemStyle=$this->getViewState('ItemStyle',null);
-
- $alternatingItemStyle=$this->getViewState('AlternatingItemStyle',null);
- if($itemStyle!==null)
- {
- if($alternatingItemStyle===null)
- $alternatingItemStyle=$itemStyle;
- else
- $alternatingItemStyle->mergeWith($itemStyle);
- }
-
- $selectedItemStyle=$this->getViewState('SelectedItemStyle',null);
-
- $editItemStyle=$this->getViewState('EditItemStyle',null);
- if($selectedItemStyle!==null)
- {
- if($editItemStyle===null)
- $editItemStyle=$selectedItemStyle;
- else
- $editItemStyle->mergeWith($selectedItemStyle);
- }
-
- $headerStyle=$this->getViewState('HeaderStyle',null);
- $footerStyle=$this->getViewState('FooterStyle',null);
- $pagerStyle=$this->getViewState('PagerStyle',null);
- $separatorStyle=$this->getViewState('SeparatorStyle',null);
-
- foreach($this->getControls() as $index=>$item)
- {
- if(!($item instanceof TDataGridItem) && !($item instanceof TDataGridPager))
- continue;
- $itemType=$item->getItemType();
- switch($itemType)
- {
- case TListItemType::Header:
- if($headerStyle)
- $item->getStyle()->mergeWith($headerStyle);
- if(!$this->getShowHeader())
- $item->setVisible(false);
- break;
- case TListItemType::Footer:
- if($footerStyle)
- $item->getStyle()->mergeWith($footerStyle);
- if(!$this->getShowFooter())
- $item->setVisible(false);
- break;
- case TListItemType::Separator:
- if($separatorStyle)
- $item->getStyle()->mergeWith($separatorStyle);
- break;
- case TListItemType::Item:
- if($itemStyle)
- $item->getStyle()->mergeWith($itemStyle);
- break;
- case TListItemType::AlternatingItem:
- if($alternatingItemStyle)
- $item->getStyle()->mergeWith($alternatingItemStyle);
- break;
- case TListItemType::SelectedItem:
- if($selectedItemStyle)
- $item->getStyle()->mergeWith($selectedItemStyle);
- if($index % 2==1)
- {
- if($itemStyle)
- $item->getStyle()->mergeWith($itemStyle);
- }
- else
- {
- if($alternatingItemStyle)
- $item->getStyle()->mergeWith($alternatingItemStyle);
- }
- break;
- case TListItemType::EditItem:
- if($editItemStyle)
- $item->getStyle()->mergeWith($editItemStyle);
- if($index % 2==1)
- {
- if($itemStyle)
- $item->getStyle()->mergeWith($itemStyle);
- }
- else
- {
- if($alternatingItemStyle)
- $item->getStyle()->mergeWith($alternatingItemStyle);
- }
- break;
- case TListItemType::Pager:
- if($pagerStyle)
- {
- $item->getStyle()->mergeWith($pagerStyle);
- if($index===0)
- {
- if($pagerStyle->getPosition()===TDataGridPagerPosition::Bottom || !$pagerStyle->getVisible())
- $item->setVisible(false);
- }
- else
- {
- if($pagerStyle->getPosition()===TDataGridPagerPosition::Top || !$pagerStyle->getVisible())
- $item->setVisible(false);
- }
- }
- break;
- default:
- break;
- }
- if($this->_columns && $itemType!==TListItemType::Pager)
- {
- $n=$this->_columns->getCount();
- $cells=$item->getCells();
- for($i=0;$i<$n;++$i)
- {
- $cell=$cells->itemAt($i);
- $column=$this->_columns->itemAt($i);
- if(!$column->getVisible())
- $cell->setVisible(false);
- else
- {
- if($itemType===TListItemType::Header)
- $style=$column->getHeaderStyle(false);
- else if($itemType===TListItemType::Footer)
- $style=$column->getFooterStyle(false);
- else
- $style=$column->getItemStyle(false);
- if($style!==null)
- $cell->getStyle()->mergeWith($style);
- }
- }
- }
- }
- }
-
- /**
- * Renders the openning tag for the datagrid control which will render table caption if present.
- * @param THtmlWriter the writer used for the rendering purpose
- */
- public function renderBeginTag($writer)
- {
- parent::renderBeginTag($writer);
- if(($caption=$this->getCaption())!=='')
- {
- if(($align=$this->getCaptionAlign())!==TTableCaptionAlign::NotSet)
- $writer->addAttribute('align',strtolower($align));
- $writer->renderBeginTag('caption');
- $writer->write($caption);
- $writer->renderEndTag();
- }
- }
-
- /**
- * Renders the datagrid.
- * @param THtmlWriter writer for the rendering purpose
- */
- public function render($writer)
- {
- if($this->getHasControls())
- {
- $this->groupCells();
- if($this->_useEmptyTemplate)
- {
- $control=new TWebControl;
- $control->setID($this->getClientID());
- $control->copyBaseAttributes($this);
- if($this->getHasStyle())
- $control->getStyle()->copyFrom($this->getStyle());
- $control->renderBeginTag($writer);
- $this->renderContents($writer);
- $control->renderEndTag($writer);
- }
- else if($this->getViewState('ItemCount',0)>0)
- {
- $this->applyItemStyles();
- if($this->_topPager)
- {
- $this->_topPager->renderControl($writer);
- $writer->writeLine();
- }
- $this->renderTable($writer);
- if($this->_bottomPager)
- {
- $writer->writeLine();
- $this->_bottomPager->renderControl($writer);
- }
- }
- }
- }
-
- /**
- * Renders the tabular data.
- * @param THtmlWriter writer
- */
- protected function renderTable($writer)
- {
- $this->renderBeginTag($writer);
- if($this->_header && $this->_header->getVisible())
- {
- $writer->writeLine();
- if($style=$this->getViewState('TableHeadStyle',null))
- $style->addAttributesToRender($writer);
- $writer->renderBeginTag('thead');
- $this->_header->render($writer);
- $writer->renderEndTag();
- }
- $writer->writeLine();
- if($style=$this->getViewState('TableBodyStyle',null))
- $style->addAttributesToRender($writer);
- $writer->renderBeginTag('tbody');
- foreach($this->getItems() as $item)
- $item->renderControl($writer);
- $writer->renderEndTag();
-
- if($this->_footer && $this->_footer->getVisible())
- {
- $writer->writeLine();
- if($style=$this->getViewState('TableFootStyle',null))
- $style->addAttributesToRender($writer);
- $writer->renderBeginTag('tfoot');
- $this->_footer->render($writer);
- $writer->renderEndTag();
- }
-
- $writer->writeLine();
- $this->renderEndTag($writer);
- }
-}
-
-/**
- * TDataGridItemEventParameter class
- *
- * TDataGridItemEventParameter encapsulates the parameter data for
- * {@link TDataGrid::onItemCreated OnItemCreated} event of {@link TDataGrid} controls.
- * The {@link getItem Item} property indicates the datagrid item related with the event.
- *
- * @author Qiang Xue <qiang.xue@gmail.com>
- * @version $Id$
- * @package System.Web.UI.WebControls
- * @since 3.0
- */
-class TDataGridItemEventParameter extends TEventParameter
-{
- /**
- * The TDataGridItem control responsible for the event.
- * @var TDataGridItem
- */
- private $_item=null;
-
- /**
- * Constructor.
- * @param TDataGridItem datagrid item related with the corresponding event
- */
- public function __construct(TDataGridItem $item)
- {
- $this->_item=$item;
- }
-
- /**
- * @return TDataGridItem datagrid item related with the corresponding event
- */
- public function getItem()
- {
- return $this->_item;
- }
-}
-
-/**
- * TDataGridPagerEventParameter class
- *
- * TDataGridPagerEventParameter encapsulates the parameter data for
- * {@link TDataGrid::onPagerCreated OnPagerCreated} event of {@link TDataGrid} controls.
- * The {@link getPager Pager} property indicates the datagrid pager related with the event.
- *
- * @author Qiang Xue <qiang.xue@gmail.com>
- * @version $Id$
- * @package System.Web.UI.WebControls
- * @since 3.0
- */
-class TDataGridPagerEventParameter extends TEventParameter
-{
- /**
- * The TDataGridPager control responsible for the event.
- * @var TDataGridPager
- */
- protected $_pager=null;
-
- /**
- * Constructor.
- * @param TDataGridPager datagrid pager related with the corresponding event
- */
- public function __construct(TDataGridPager $pager)
- {
- $this->_pager=$pager;
- }
-
- /**
- * @return TDataGridPager datagrid pager related with the corresponding event
- */
- public function getPager()
- {
- return $this->_pager;
- }
-}
-
-/**
- * TDataGridCommandEventParameter class
- *
- * TDataGridCommandEventParameter encapsulates the parameter data for
- * {@link TDataGrid::onItemCommand ItemCommand} event of {@link TDataGrid} controls.
- *
- * The {@link getItem Item} property indicates the datagrid item related with the event.
- * The {@link getCommandSource CommandSource} refers to the control that originally
- * raises the Command event.
- *
- * @author Qiang Xue <qiang.xue@gmail.com>
- * @version $Id$
- * @package System.Web.UI.WebControls
- * @since 3.0
- */
-class TDataGridCommandEventParameter extends TCommandEventParameter
-{
- /**
- * @var TDataGridItem the TDataGridItem control responsible for the event.
- */
- private $_item=null;
- /**
- * @var TControl the control originally raises the <b>Command</b> event.
- */
- private $_source=null;
-
- /**
- * Constructor.
- * @param TDataGridItem datagrid item responsible for the event
- * @param TControl original event sender
- * @param TCommandEventParameter original event parameter
- */
- public function __construct($item,$source,TCommandEventParameter $param)
- {
- $this->_item=$item;
- $this->_source=$source;
- parent::__construct($param->getCommandName(),$param->getCommandParameter());
- }
-
- /**
- * @return TDataGridItem the TDataGridItem control responsible for the event.
- */
- public function getItem()
- {
- return $this->_item;
- }
-
- /**
- * @return TControl the control originally raises the <b>Command</b> event.
- */
- public function getCommandSource()
- {
- return $this->_source;
- }
-}
-
-/**
- * TDataGridSortCommandEventParameter class
- *
- * TDataGridSortCommandEventParameter encapsulates the parameter data for
- * {@link TDataGrid::onSortCommand SortCommand} event of {@link TDataGrid} controls.
- *
- * The {@link getCommandSource CommandSource} property refers to the control
- * that originally raises the OnCommand event, while {@link getSortExpression SortExpression}
- * gives the sort expression carried with the sort command.
- *
- * @author Qiang Xue <qiang.xue@gmail.com>
- * @version $Id$
- * @package System.Web.UI.WebControls
- * @since 3.0
- */
-class TDataGridSortCommandEventParameter extends TEventParameter
-{
- /**
- * @var string sort expression
- */
- private $_sortExpression='';
- /**
- * @var TControl original event sender
- */
- private $_source=null;
-
- /**
- * Constructor.
- * @param TControl the control originally raises the <b>OnCommand</b> event.
- * @param TDataGridCommandEventParameter command event parameter
- */
- public function __construct($source,TDataGridCommandEventParameter $param)
- {
- $this->_source=$source;
- $this->_sortExpression=$param->getCommandParameter();
- }
-
- /**
- * @return TControl the control originally raises the <b>OnCommand</b> event.
- */
- public function getCommandSource()
- {
- return $this->_source;
- }
-
- /**
- * @return string sort expression
- */
- public function getSortExpression()
- {
- return $this->_sortExpression;
- }
-}
-
-/**
- * TDataGridPageChangedEventParameter class
- *
- * TDataGridPageChangedEventParameter encapsulates the parameter data for
- * {@link TDataGrid::onPageIndexChanged PageIndexChanged} event of {@link TDataGrid} controls.
- *
- * The {@link getCommandSource CommandSource} property refers to the control
- * that originally raises the OnCommand event, while {@link getNewPageIndex NewPageIndex}
- * returns the new page index carried with the page command.
- *
- * @author Qiang Xue <qiang.xue@gmail.com>
- * @version $Id$
- * @package System.Web.UI.WebControls
- * @since 3.0
- */
-class TDataGridPageChangedEventParameter extends TEventParameter
-{
- /**
- * @var integer new page index
- */
- private $_newIndex;
- /**
- * @var TControl original event sender
- */
- private $_source=null;
-
- /**
- * Constructor.
- * @param TControl the control originally raises the <b>OnCommand</b> event.
- * @param integer new page index
- */
- public function __construct($source,$newPageIndex)
- {
- $this->_source=$source;
- $this->_newIndex=$newPageIndex;
- }
-
- /**
- * @return TControl the control originally raises the <b>OnCommand</b> event.
- */
- public function getCommandSource()
- {
- return $this->_source;
- }
-
- /**
- * @return integer new page index
- */
- public function getNewPageIndex()
- {
- return $this->_newIndex;
- }
-}
-
-/**
- * TDataGridItem class
- *
- * A TDataGridItem control represents an item in the {@link TDataGrid} control,
- * such as heading section, footer section, or a data item.
- * The index and data value of the item can be accessed via {@link getItemIndex ItemIndex}>
- * and {@link getDataItem DataItem} properties, respectively. The type of the item
- * is given by {@link getItemType ItemType} property. Property {@link getDataSourceIndex DataSourceIndex}
- * gives the index of the item from the bound data source.
- *
- * @author Qiang Xue <qiang.xue@gmail.com>
- * @version $Id$
- * @package System.Web.UI.WebControls
- * @since 3.0
- */
-class TDataGridItem extends TTableRow implements INamingContainer
-{
- /**
- * @var integer index of the data item in the Items collection of datagrid
- */
- private $_itemIndex='';
- /**
- * @var integer index of the item from the bound data source
- */
- private $_dataSourceIndex=0;
- /**
- * type of the TDataGridItem
- * @var string
- */
- private $_itemType='';
- /**
- * value of the data item
- * @var mixed
- */
- private $_data=null;
-
- /**
- * Constructor.
- * @param integer zero-based index of the item in the item collection of datagrid
- * @param TListItemType item type
- */
- public function __construct($itemIndex,$dataSourceIndex,$itemType)
- {
- $this->_itemIndex=$itemIndex;
- $this->_dataSourceIndex=$dataSourceIndex;
- $this->setItemType($itemType);
- if($itemType===TListItemType::Header)
- $this->setTableSection(TTableRowSection::Header);
- else if($itemType===TListItemType::Footer)
- $this->setTableSection(TTableRowSection::Footer);
- }
-
- /**
- * @return TListItemType item type.
- */
- public function getItemType()
- {
- return $this->_itemType;
- }
-
- /**
- * @param TListItemType item type
- */
- public function setItemType($value)
- {
- $this->_itemType=TPropertyValue::ensureEnum($value,'TListItemType');
- }
-
- /**
- * @return integer zero-based index of the item in the item collection of datagrid
- */
- public function getItemIndex()
- {
- return $this->_itemIndex;
- }
-
- /**
- * @return integer the index of the datagrid item from the bound data source
- */
- public function getDataSourceIndex()
- {
- return $this->_dataSourceIndex;
- }
-
- /**
- * @return mixed data associated with the item
- * @since 3.1.0
- */
- public function getData()
- {
- return $this->_data;
- }
-
- /**
- * @param mixed data to be associated with the item
- * @since 3.1.0
- */
- public function setData($value)
- {
- $this->_data=$value;
- }
-
- /**
- * This property is deprecated since v3.1.0.
- * @return mixed data associated with the item
- * @deprecated deprecated since v3.1.0. Use {@link getData} instead.
- */
- public function getDataItem()
- {
- return $this->getData();
- }
-
- /**
- * This property is deprecated since v3.1.0.
- * @param mixed data to be associated with the item
- * @deprecated deprecated since version 3.1.0. Use {@link setData} instead.
- */
- public function setDataItem($value)
- {
- return $this->setData($value);
- }
-
- /**
- * This method overrides parent's implementation by wrapping event parameter
- * for <b>OnCommand</b> event with item information.
- * @param TControl the sender of the event
- * @param TEventParameter event parameter
- * @return boolean whether the event bubbling should stop here.
- */
- public function bubbleEvent($sender,$param)
- {
- if($param instanceof TCommandEventParameter)
- {
- $this->raiseBubbleEvent($this,new TDataGridCommandEventParameter($this,$sender,$param));
- return true;
- }
- else
- return false;
- }
-}
-
-
-/**
- * TDataGridPager class.
- *
- * TDataGridPager represents a datagrid pager.
- *
- * @author Qiang Xue <qiang.xue@gmail.com>
- * @version $Id$
- * @package System.Web.UI.WebControls
- * @since 3.0
- */
-class TDataGridPager extends TPanel implements INamingContainer
-{
- private $_dataGrid;
-
- /**
- * Constructor.
- * @param TDataGrid datagrid object
- */
- public function __construct($dataGrid)
- {
- $this->_dataGrid=$dataGrid;
- }
-
- /**
- * This method overrides parent's implementation by wrapping event parameter
- * for <b>OnCommand</b> event with item information.
- * @param TControl the sender of the event
- * @param TEventParameter event parameter
- * @return boolean whether the event bubbling should stop here.
- */
- public function bubbleEvent($sender,$param)
- {
- if($param instanceof TCommandEventParameter)
- {
- $this->raiseBubbleEvent($this,new TDataGridCommandEventParameter($this,$sender,$param));
- return true;
- }
- else
- return false;
- }
-
- /**
- * @return TDataGrid the datagrid owning this pager
- */
- public function getDataGrid()
- {
- return $this->_dataGrid;
- }
-
- /**
- * @return string item type.
- */
- public function getItemType()
- {
- return TListItemType::Pager;
- }
-}
-
-
-/**
- * TDataGridItemCollection class.
- *
- * TDataGridItemCollection represents a collection of data grid items.
- *
- * @author Qiang Xue <qiang.xue@gmail.com>
- * @version $Id$
- * @package System.Web.UI.WebControls
- * @since 3.0
- */
-class TDataGridItemCollection extends TList
-{
- /**
- * Inserts an item at the specified position.
- * This overrides the parent implementation by inserting only TDataGridItem.
- * @param integer the speicified position.
- * @param mixed new item
- * @throws TInvalidDataTypeException if the item to be inserted is not a TDataGridItem.
- */
- public function insertAt($index,$item)
- {
- if($item instanceof TDataGridItem)
- parent::insertAt($index,$item);
- else
- throw new TInvalidDataTypeException('datagriditemcollection_datagriditem_required');
- }
-}
-
-/**
- * TDataGridColumnCollection class.
- *
- * TDataGridColumnCollection represents a collection of data grid columns.
- *
- * @author Qiang Xue <qiang.xue@gmail.com>
- * @version $Id$
- * @package System.Web.UI.WebControls
- * @since 3.0
- */
-class TDataGridColumnCollection extends TList
-{
- /**
- * the control that owns this collection.
- * @var TControl
- */
- private $_o;
-
- /**
- * Constructor.
- * @param TDataGrid the control that owns this collection.
- */
- public function __construct(TDataGrid $owner)
- {
- $this->_o=$owner;
- }
-
- /**
- * @return TDataGrid the control that owns this collection.
- */
- protected function getOwner()
- {
- return $this->_o;
- }
-
- /**
- * Inserts an item at the specified position.
- * This overrides the parent implementation by inserting only TDataGridColumn.
- * @param integer the speicified position.
- * @param mixed new item
- * @throws TInvalidDataTypeException if the item to be inserted is not a TDataGridColumn.
- */
- public function insertAt($index,$item)
- {
- if($item instanceof TDataGridColumn)
- {
- $item->setOwner($this->_o);
- parent::insertAt($index,$item);
- }
- else
- throw new TInvalidDataTypeException('datagridcolumncollection_datagridcolumn_required');
- }
-}
-
-/**
- * TDataGridPagerMode class.
- * TDataGridPagerMode defines the enumerable type for the possible modes that a datagrid pager can take.
- *
- * The following enumerable values are defined:
- * - NextPrev: pager buttons are displayed as next and previous pages
- * - Numeric: pager buttons are displayed as numeric page numbers
- *
- * @author Qiang Xue <qiang.xue@gmail.com>
- * @version $Id$
- * @package System.Web.UI.WebControls
- * @since 3.0.4
- */
-class TDataGridPagerMode extends TEnumerable
-{
- const NextPrev='NextPrev';
- const Numeric='Numeric';
-}
-
-
-/**
- * TDataGridPagerButtonType class.
- * TDataGridPagerButtonType defines the enumerable type for the possible types of datagrid pager buttons.
- *
- * The following enumerable values are defined:
- * - LinkButton: link buttons
- * - PushButton: form submit buttons
- *
- * @author Qiang Xue <qiang.xue@gmail.com>
- * @version $Id$
- * @package System.Web.UI.WebControls
- * @since 3.0.4
- */
-class TDataGridPagerButtonType extends TEnumerable
-{
- const LinkButton='LinkButton';
- const PushButton='PushButton';
-}
-
-
-/**
- * TDataGridPagerPosition class.
- * TDataGridPagerPosition defines the enumerable type for the possible positions that a datagrid pager can be located at.
- *
- * The following enumerable values are defined:
- * - Bottom: pager appears only at the bottom of the data grid.
- * - Top: pager appears only at the top of the data grid.
- * - TopAndBottom: pager appears on both top and bottom of the data grid.
- *
- * @author Qiang Xue <qiang.xue@gmail.com>
- * @version $Id$
- * @package System.Web.UI.WebControls
- * @since 3.0.4
- */
-class TDataGridPagerPosition extends TEnumerable
-{
- const Bottom='Bottom';
- const Top='Top';
- const TopAndBottom='TopAndBottom';
-}
-
+<?php
+/**
+ * TDataGrid related class files.
+ * This file contains the definition of the following classes:
+ * TDataGrid, TDataGridItem, TDataGridItemCollection, TDataGridColumnCollection,
+ * TDataGridPagerStyle, TDataGridItemEventParameter,
+ * TDataGridCommandEventParameter, TDataGridSortCommandEventParameter,
+ * TDataGridPageChangedEventParameter
+ *
+ * @author Qiang Xue <qiang.xue@gmail.com>
+ * @link http://www.pradosoft.com/
+ * @copyright Copyright &copy; 2005-2012 PradoSoft
+ * @license http://www.pradosoft.com/license/
+ * @version $Id$
+ * @package System.Web.UI.WebControls
+ */
+
+/**
+ * Includes TBaseList, TPagedDataSource, TDummyDataSource and TTable classes
+ */
+Prado::using('System.Web.UI.WebControls.TBaseDataList');
+Prado::using('System.Collections.TPagedDataSource');
+Prado::using('System.Collections.TDummyDataSource');
+Prado::using('System.Web.UI.WebControls.TTable');
+Prado::using('System.Web.UI.WebControls.TPanel');
+Prado::using('System.Web.UI.WebControls.TDataGridPagerStyle');
+
+/**
+ * TDataGrid class
+ *
+ * TDataGrid represents a data bound and updatable grid control.
+ *
+ * To populate data into the datagrid, sets its {@link setDataSource DataSource}
+ * to a tabular data source and call {@link dataBind()}.
+ * Each row of data will be represented by an item in the {@link getItems Items}
+ * collection of the datagrid.
+ *
+ * An item can be at one of three states: browsing, selected and edit.
+ * The state determines how the item will be displayed. For example, if an item
+ * is in edit state, it may be displayed as a table row with input text boxes
+ * if the columns are of type {@link TBoundColumn}; and if in browsing state,
+ * they are displayed as static text.
+ *
+ * To change the state of an item, set {@link setEditItemIndex EditItemIndex}
+ * or {@link setSelectedItemIndex SelectedItemIndex} property.
+ *
+ * Each datagrid item has a {@link TDataGridItem::getItemType type}
+ * which tells the position and state of the item in the datalist. An item in the header
+ * of the repeater is of type Header. A body item may be of either
+ * Item, AlternatingItem, SelectedItem or EditItem, depending whether the item
+ * index is odd or even, whether it is being selected or edited.
+ *
+ * A datagrid is specified with a list of columns. Each column specifies how the corresponding
+ * table column will be displayed. For example, the header/footer text of that column,
+ * the cells in that column, and so on. The following column types are currently
+ * provided by the framework,
+ * - {@link TBoundColumn}, associated with a specific field in datasource and displays the corresponding data.
+ * - {@link TEditCommandColumn}, displaying edit/update/cancel command buttons
+ * - {@link TButtonColumn}, displaying generic command buttons that may be bound to specific field in datasource.
+ * - {@link TDropDownListColumn}, displaying a dropdown list when the item is in edit state
+ * - {@link THyperLinkColumn}, displaying a hyperlink that may be bound to specific field in datasource.
+ * - {@link TCheckBoxColumn}, displaying a checkbox that may be bound to specific field in datasource.
+ * - {@link TTemplateColumn}, displaying content based on templates.
+ *
+ * There are three ways to specify columns for a datagrid.
+ * <ul>
+ * <li>Automatically generated based on data source.
+ * By setting {@link setAutoGenerateColumns AutoGenerateColumns} to true,
+ * a list of columns will be automatically generated based on the schema of the data source.
+ * Each column corresponds to a column of the data.</li>
+ * <li>Specified in template. For example,
+ * <code>
+ * <com:TDataGrid ...>
+ * <com:TBoundColumn .../>
+ * <com:TEditCommandColumn .../>
+ * </com:TDataGrid>
+ * </code>
+ * </li>
+ * <li>Manually created in code. Columns can be manipulated via
+ * the {@link setColumns Columns} property of the datagrid. For example,
+ * <code>
+ * $column=new TBoundColumn;
+ * $datagrid->Columns[]=$column;
+ * </code>
+ * </li>
+ * </ul>
+ * Note, automatically generated columns cannot be accessed via
+ * the {@link getColumns Columns} property.
+ *
+ * TDataGrid supports sorting. If the {@link setAllowSorting AllowSorting}
+ * is set to true, a column with nonempty {@link setSortExpression SortExpression}
+ * will have its header text displayed as a clickable link button.
+ * Clicking on the link button will raise {@link onSortCommand OnSortCommand}
+ * event. You can respond to this event, sort the data source according
+ * to the event parameter, and then invoke {@link databind()} on the datagrid
+ * to show to end users the sorted data.
+ *
+ * TDataGrid supports paging. If the {@link setAllowPaging AllowPaging}
+ * is set to true, a pager will be displayed on top and/or bottom of the table.
+ * How the pager will be displayed is determined by the {@link getPagerStyle PagerStyle}
+ * property. Clicking on a pager button will raise an {@link onPageIndexChanged OnPageIndexChanged}
+ * event. You can respond to this event, specify the page to be displayed by
+ * setting {@link setCurrentPageIndex CurrentPageIndex}</b> property,
+ * and then invoke {@link databind()} on the datagrid to show to end users
+ * a new page of data.
+ *
+ * TDataGrid supports two kinds of paging. The first one is based on the number of data items in
+ * datasource. The number of pages {@link getPageCount PageCount} is calculated based
+ * the item number and the {@link setPageSize PageSize} property.
+ * The datagrid will manage which section of the data source to be displayed
+ * based on the {@link setCurrentPageIndex CurrentPageIndex} property.
+ * The second approach calculates the page number based on the
+ * {@link setVirtualItemCount VirtualItemCount} property and
+ * the {@link setPageSize PageSize} property. The datagrid will always
+ * display from the beginning of the datasource up to the number of
+ * {@link setPageSize PageSize} data items. This approach is especially
+ * useful when the datasource may contain too many data items to be managed by
+ * the datagrid efficiently.
+ *
+ * When the datagrid contains a button control that raises an {@link onCommand OnCommand}
+ * event, the event will be bubbled up to the datagrid control.
+ * If the event's command name is recognizable by the datagrid control,
+ * a corresponding item event will be raised. The following item events will be
+ * raised upon a specific command:
+ * - OnEditCommand, if CommandName=edit
+ * - OnCancelCommand, if CommandName=cancel
+ * - OnSelectCommand, if CommandName=select
+ * - OnDeleteCommand, if CommandName=delete
+ * - OnUpdateCommand, if CommandName=update
+ * - onPageIndexChanged, if CommandName=page
+ * - OnSortCommand, if CommandName=sort
+ * Note, an {@link onItemCommand OnItemCommand} event is raised in addition to
+ * the above specific command events.
+ *
+ * TDataGrid also raises an {@link onItemCreated OnItemCreated} event for
+ * every newly created datagrid item. You can respond to this event to customize
+ * the content or style of the newly created item.
+ *
+ * Note, the data bound to the datagrid are reset to null after databinding.
+ * There are several ways to access the data associated with a datagrid row:
+ * - Access the data in {@link onItemDataBound OnItemDataBound} event
+ * - Use {@link getDataKeys DataKeys} to obtain the data key associated with
+ * the specified datagrid row and use the key to fetch the corresponding data
+ * from some persistent storage such as DB.
+ * - Save the data in viewstate and get it back during postbacks.
+ *
+ * @author Qiang Xue <qiang.xue@gmail.com>
+ * @version $Id$
+ * @package System.Web.UI.WebControls
+ * @since 3.0
+ */
+class TDataGrid extends TBaseDataList implements INamingContainer
+{
+ /**
+ * datagrid item types
+ * @deprecated deprecated since version 3.0.4. Use TListItemType constants instead.
+ */
+ const IT_HEADER='Header';
+ const IT_FOOTER='Footer';
+ const IT_ITEM='Item';
+ const IT_SEPARATOR='Separator';
+ const IT_ALTERNATINGITEM='AlternatingItem';
+ const IT_EDITITEM='EditItem';
+ const IT_SELECTEDITEM='SelectedItem';
+ const IT_PAGER='Pager';
+
+ /**
+ * Command name that TDataGrid understands.
+ */
+ const CMD_SELECT='Select';
+ const CMD_EDIT='Edit';
+ const CMD_UPDATE='Update';
+ const CMD_DELETE='Delete';
+ const CMD_CANCEL='Cancel';
+ const CMD_SORT='Sort';
+ const CMD_PAGE='Page';
+ const CMD_PAGE_NEXT='Next';
+ const CMD_PAGE_PREV='Previous';
+ const CMD_PAGE_FIRST='First';
+ const CMD_PAGE_LAST='Last';
+
+ /**
+ * @var TDataGridColumnCollection manually created column collection
+ */
+ private $_columns=null;
+ /**
+ * @var TDataGridColumnCollection automatically created column collection
+ */
+ private $_autoColumns=null;
+ /**
+ * @var TList all columns including both manually and automatically created columns
+ */
+ private $_allColumns=null;
+ /**
+ * @var TDataGridItemCollection datagrid item collection
+ */
+ private $_items=null;
+ /**
+ * @var TDataGridItem header item
+ */
+ private $_header=null;
+ /**
+ * @var TDataGridItem footer item
+ */
+ private $_footer=null;
+ /**
+ * @var TPagedDataSource paged data source object
+ */
+ private $_pagedDataSource=null;
+ private $_topPager=null;
+ private $_bottomPager=null;
+ /**
+ * @var ITemplate template used when empty data is bounded
+ */
+ private $_emptyTemplate=null;
+ /**
+ * @var boolean whether empty template is effective
+ */
+ private $_useEmptyTemplate=false;
+
+ /**
+ * @return string tag name (table) of the datagrid
+ */
+ protected function getTagName()
+ {
+ return 'table';
+ }
+
+ /**
+ * @return string Name of the class used in AutoGenerateColumns mode
+ */
+ protected function getAutoGenerateColumnName()
+ {
+ return 'TBoundColumn';
+ }
+
+ /**
+ * Adds objects parsed in template to datagrid.
+ * Datagrid columns are added into {@link getColumns Columns} collection.
+ * @param mixed object parsed in template
+ */
+ public function addParsedObject($object)
+ {
+ if($object instanceof TDataGridColumn)
+ $this->getColumns()->add($object);
+ else
+ parent::addParsedObject($object); // this is needed by EmptyTemplate
+ }
+
+ /**
+ * @return TDataGridColumnCollection manually specified datagrid columns
+ */
+ public function getColumns()
+ {
+ if(!$this->_columns)
+ $this->_columns=new TDataGridColumnCollection($this);
+ return $this->_columns;
+ }
+
+ /**
+ * @return TDataGridColumnCollection automatically generated datagrid columns
+ */
+ public function getAutoColumns()
+ {
+ if(!$this->_autoColumns)
+ $this->_autoColumns=new TDataGridColumnCollection($this);
+ return $this->_autoColumns;
+ }
+
+ /**
+ * @return TDataGridItemCollection datagrid item collection
+ */
+ public function getItems()
+ {
+ if(!$this->_items)
+ $this->_items=new TDataGridItemCollection;
+ return $this->_items;
+ }
+
+ /**
+ * @return integer number of items
+ */
+ public function getItemCount()
+ {
+ return $this->_items?$this->_items->getCount():0;
+ }
+
+ /**
+ * Creates a style object for the control.
+ * This method creates a {@link TTableStyle} to be used by datagrid.
+ * @return TTableStyle control style to be used
+ */
+ protected function createStyle()
+ {
+ return new TTableStyle;
+ }
+
+ /**
+ * @return string the URL of the background image for the datagrid
+ */
+ public function getBackImageUrl()
+ {
+ return $this->getStyle()->getBackImageUrl();
+ }
+
+ /**
+ * @param string the URL of the background image for the datagrid
+ */
+ public function setBackImageUrl($value)
+ {
+ $this->getStyle()->setBackImageUrl($value);
+ }
+
+ /**
+ * @return TTableItemStyle the style for every item
+ */
+ public function getItemStyle()
+ {
+ if(($style=$this->getViewState('ItemStyle',null))===null)
+ {
+ $style=new TTableItemStyle;
+ $this->setViewState('ItemStyle',$style,null);
+ }
+ return $style;
+ }
+
+ /**
+ * @return TTableItemStyle the style for each alternating item
+ */
+ public function getAlternatingItemStyle()
+ {
+ if(($style=$this->getViewState('AlternatingItemStyle',null))===null)
+ {
+ $style=new TTableItemStyle;
+ $this->setViewState('AlternatingItemStyle',$style,null);
+ }
+ return $style;
+ }
+
+ /**
+ * @return TTableItemStyle the style for selected item
+ */
+ public function getSelectedItemStyle()
+ {
+ if(($style=$this->getViewState('SelectedItemStyle',null))===null)
+ {
+ $style=new TTableItemStyle;
+ $this->setViewState('SelectedItemStyle',$style,null);
+ }
+ return $style;
+ }
+
+ /**
+ * @return TTableItemStyle the style for edit item
+ */
+ public function getEditItemStyle()
+ {
+ if(($style=$this->getViewState('EditItemStyle',null))===null)
+ {
+ $style=new TTableItemStyle;
+ $this->setViewState('EditItemStyle',$style,null);
+ }
+ return $style;
+ }
+
+ /**
+ * @return TTableItemStyle the style for header
+ */
+ public function getHeaderStyle()
+ {
+ if(($style=$this->getViewState('HeaderStyle',null))===null)
+ {
+ $style=new TTableItemStyle;
+ $this->setViewState('HeaderStyle',$style,null);
+ }
+ return $style;
+ }
+
+ /**
+ * @return TTableItemStyle the style for footer
+ */
+ public function getFooterStyle()
+ {
+ if(($style=$this->getViewState('FooterStyle',null))===null)
+ {
+ $style=new TTableItemStyle;
+ $this->setViewState('FooterStyle',$style,null);
+ }
+ return $style;
+ }
+
+ /**
+ * @return TDataGridPagerStyle the style for pager
+ */
+ public function getPagerStyle()
+ {
+ if(($style=$this->getViewState('PagerStyle',null))===null)
+ {
+ $style=new TDataGridPagerStyle;
+ $this->setViewState('PagerStyle',$style,null);
+ }
+ return $style;
+ }
+
+ /**
+ * @return TStyle the style for thead element, if any
+ * @since 3.1.1
+ */
+ public function getTableHeadStyle()
+ {
+ if(($style=$this->getViewState('TableHeadStyle',null))===null)
+ {
+ $style=new TStyle;
+ $this->setViewState('TableHeadStyle',$style,null);
+ }
+ return $style;
+ }
+
+ /**
+ * @return TStyle the style for tbody element, if any
+ * @since 3.1.1
+ */
+ public function getTableBodyStyle()
+ {
+ if(($style=$this->getViewState('TableBodyStyle',null))===null)
+ {
+ $style=new TStyle;
+ $this->setViewState('TableBodyStyle',$style,null);
+ }
+ return $style;
+ }
+
+ /**
+ * @return TStyle the style for tfoot element, if any
+ * @since 3.1.1
+ */
+ public function getTableFootStyle()
+ {
+ if(($style=$this->getViewState('TableFootStyle',null))===null)
+ {
+ $style=new TStyle;
+ $this->setViewState('TableFootStyle',$style,null);
+ }
+ return $style;
+ }
+
+ /**
+ * @return string caption for the datagrid
+ */
+ public function getCaption()
+ {
+ return $this->getViewState('Caption','');
+ }
+
+ /**
+ * @param string caption for the datagrid
+ */
+ public function setCaption($value)
+ {
+ $this->setViewState('Caption',$value,'');
+ }
+
+ /**
+ * @return TTableCaptionAlign datagrid caption alignment. Defaults to TTableCaptionAlign::NotSet.
+ */
+ public function getCaptionAlign()
+ {
+ return $this->getViewState('CaptionAlign',TTableCaptionAlign::NotSet);
+ }
+
+ /**
+ * @param TTableCaptionAlign datagrid caption alignment. Valid values include
+ */
+ public function setCaptionAlign($value)
+ {
+ $this->setViewState('CaptionAlign',TPropertyValue::ensureEnum($value,'TTableCaptionAlign'),TTableCaptionAlign::NotSet);
+ }
+
+ /**
+ * @return TDataGridItem the header item
+ */
+ public function getHeader()
+ {
+ return $this->_header;
+ }
+
+ /**
+ * @return TDataGridItem the footer item
+ */
+ public function getFooter()
+ {
+ return $this->_footer;
+ }
+
+ /**
+ * @return TDataGridPager the pager displayed at the top of datagrid. It could be null if paging is disabled.
+ */
+ public function getTopPager()
+ {
+ return $this->_topPager;
+ }
+
+ /**
+ * @return TDataGridPager the pager displayed at the bottom of datagrid. It could be null if paging is disabled.
+ */
+ public function getBottomPager()
+ {
+ return $this->_bottomPager;
+ }
+
+ /**
+ * @return TDataGridItem the selected item, null if no item is selected.
+ */
+ public function getSelectedItem()
+ {
+ $index=$this->getSelectedItemIndex();
+ $items=$this->getItems();
+ if($index>=0 && $index<$items->getCount())
+ return $items->itemAt($index);
+ else
+ return null;
+ }
+
+ /**
+ * @return integer the zero-based index of the selected item in {@link getItems Items}.
+ * A value -1 means no item selected.
+ */
+ public function getSelectedItemIndex()
+ {
+ return $this->getViewState('SelectedItemIndex',-1);
+ }
+
+ /**
+ * Selects an item by its index in {@link getItems Items}.
+ * Previously selected item will be un-selected.
+ * If the item to be selected is already in edit mode, it will remain in edit mode.
+ * If the index is less than 0, any existing selection will be cleared up.
+ * @param integer the selected item index
+ */
+ public function setSelectedItemIndex($value)
+ {
+ if(($value=TPropertyValue::ensureInteger($value))<0)
+ $value=-1;
+ if(($current=$this->getSelectedItemIndex())!==$value)
+ {
+ $this->setViewState('SelectedItemIndex',$value,-1);
+ $items=$this->getItems();
+ $itemCount=$items->getCount();
+ if($current>=0 && $current<$itemCount)
+ {
+ $item=$items->itemAt($current);
+ if($item->getItemType()!==TListItemType::EditItem)
+ $item->setItemType($current%2?TListItemType::AlternatingItem:TListItemType::Item);
+ }
+ if($value>=0 && $value<$itemCount)
+ {
+ $item=$items->itemAt($value);
+ if($item->getItemType()!==TListItemType::EditItem)
+ $item->setItemType(TListItemType::SelectedItem);
+ }
+ }
+ }
+
+ /**
+ * @return TDataGridItem the edit item
+ */
+ public function getEditItem()
+ {
+ $index=$this->getEditItemIndex();
+ $items=$this->getItems();
+ if($index>=0 && $index<$items->getCount())
+ return $items->itemAt($index);
+ else
+ return null;
+ }
+
+ /**
+ * @return integer the zero-based index of the edit item in {@link getItems Items}.
+ * A value -1 means no item is in edit mode.
+ */
+ public function getEditItemIndex()
+ {
+ return $this->getViewState('EditItemIndex',-1);
+ }
+
+ /**
+ * Edits an item by its index in {@link getItems Items}.
+ * Previously editting item will change to normal item state.
+ * If the index is less than 0, any existing edit item will be cleared up.
+ * @param integer the edit item index
+ */
+ public function setEditItemIndex($value)
+ {
+ if(($value=TPropertyValue::ensureInteger($value))<0)
+ $value=-1;
+ if(($current=$this->getEditItemIndex())!==$value)
+ {
+ $this->setViewState('EditItemIndex',$value,-1);
+ $items=$this->getItems();
+ $itemCount=$items->getCount();
+ if($current>=0 && $current<$itemCount)
+ $items->itemAt($current)->setItemType($current%2?TListItemType::AlternatingItem:TListItemType::Item);
+ if($value>=0 && $value<$itemCount)
+ $items->itemAt($value)->setItemType(TListItemType::EditItem);
+ }
+ }
+
+ /**
+ * @return boolean whether sorting is enabled. Defaults to false.
+ */
+ public function getAllowSorting()
+ {
+ return $this->getViewState('AllowSorting',false);
+ }
+
+ /**
+ * @param boolean whether sorting is enabled
+ */
+ public function setAllowSorting($value)
+ {
+ $this->setViewState('AllowSorting',TPropertyValue::ensureBoolean($value),false);
+ }
+
+ /**
+ * @return boolean whether datagrid columns should be automatically generated. Defaults to true.
+ */
+ public function getAutoGenerateColumns()
+ {
+ return $this->getViewState('AutoGenerateColumns',true);
+ }
+
+ /**
+ * @param boolean whether datagrid columns should be automatically generated
+ */
+ public function setAutoGenerateColumns($value)
+ {
+ $this->setViewState('AutoGenerateColumns',TPropertyValue::ensureBoolean($value),true);
+ }
+
+ /**
+ * @return boolean whether the header should be displayed. Defaults to true.
+ */
+ public function getShowHeader()
+ {
+ return $this->getViewState('ShowHeader',true);
+ }
+
+ /**
+ * @param boolean whether the header should be displayed
+ */
+ public function setShowHeader($value)
+ {
+ $this->setViewState('ShowHeader',TPropertyValue::ensureBoolean($value),true);
+ }
+
+ /**
+ * @return boolean whether the footer should be displayed. Defaults to false.
+ */
+ public function getShowFooter()
+ {
+ return $this->getViewState('ShowFooter',false);
+ }
+
+ /**
+ * @param boolean whether the footer should be displayed
+ */
+ public function setShowFooter($value)
+ {
+ $this->setViewState('ShowFooter',TPropertyValue::ensureBoolean($value),false);
+ }
+
+ /**
+ * @return ITemplate the template applied when no data is bound to the datagrid
+ */
+ public function getEmptyTemplate()
+ {
+ return $this->_emptyTemplate;
+ }
+
+ /**
+ * @param ITemplate the template applied when no data is bound to the datagrid
+ * @throws TInvalidDataTypeException if the input is not an {@link ITemplate} or not null.
+ */
+ public function setEmptyTemplate($value)
+ {
+ if($value instanceof ITemplate || $value===null)
+ $this->_emptyTemplate=$value;
+ else
+ throw new TInvalidDataTypeException('datagrid_template_required','EmptyTemplate');
+ }
+
+ /**
+ * This method overrides parent's implementation to handle
+ * {@link onItemCommand OnItemCommand} event which is bubbled from
+ * {@link TDataGridItem} child controls.
+ * If the event parameter is {@link TDataGridCommandEventParameter} and
+ * the command name is a recognized one, which includes 'select', 'edit',
+ * 'delete', 'update', and 'cancel' (case-insensitive), then a
+ * corresponding command event is also raised (such as {@link onEditCommand OnEditCommand}).
+ * This method should only be used by control developers.
+ * @param TControl the sender of the event
+ * @param TEventParameter event parameter
+ * @return boolean whether the event bubbling should stop here.
+ */
+ public function bubbleEvent($sender,$param)
+ {
+ if($param instanceof TDataGridCommandEventParameter)
+ {
+ $this->onItemCommand($param);
+ $command=$param->getCommandName();
+ if(strcasecmp($command,self::CMD_SELECT)===0)
+ {
+ $this->setSelectedItemIndex($param->getItem()->getItemIndex());
+ $this->onSelectedIndexChanged($param);
+ return true;
+ }
+ else if(strcasecmp($command,self::CMD_EDIT)===0)
+ {
+ $this->onEditCommand($param);
+ return true;
+ }
+ else if(strcasecmp($command,self::CMD_DELETE)===0)
+ {
+ $this->onDeleteCommand($param);
+ return true;
+ }
+ else if(strcasecmp($command,self::CMD_UPDATE)===0)
+ {
+ $this->onUpdateCommand($param);
+ return true;
+ }
+ else if(strcasecmp($command,self::CMD_CANCEL)===0)
+ {
+ $this->onCancelCommand($param);
+ return true;
+ }
+ else if(strcasecmp($command,self::CMD_SORT)===0)
+ {
+ $this->onSortCommand(new TDataGridSortCommandEventParameter($sender,$param));
+ return true;
+ }
+ else if(strcasecmp($command,self::CMD_PAGE)===0)
+ {
+ $p=$param->getCommandParameter();
+ if(strcasecmp($p,self::CMD_PAGE_NEXT)===0)
+ $pageIndex=$this->getCurrentPageIndex()+1;
+ else if(strcasecmp($p,self::CMD_PAGE_PREV)===0)
+ $pageIndex=$this->getCurrentPageIndex()-1;
+ else if(strcasecmp($p,self::CMD_PAGE_FIRST)===0)
+ $pageIndex=0;
+ else if(strcasecmp($p,self::CMD_PAGE_LAST)===0)
+ $pageIndex=$this->getPageCount()-1;
+ else
+ $pageIndex=TPropertyValue::ensureInteger($p)-1;
+ $this->onPageIndexChanged(new TDataGridPageChangedEventParameter($sender,$pageIndex));
+ return true;
+ }
+ }
+ return false;
+ }
+
+ /**
+ * Raises <b>OnCancelCommand</b> event.
+ * This method is invoked when a button control raises <b>OnCommand</b> event
+ * with <b>cancel</b> command name.
+ * @param TDataGridCommandEventParameter event parameter
+ */
+ public function onCancelCommand($param)
+ {
+ $this->raiseEvent('OnCancelCommand',$this,$param);
+ }
+
+ /**
+ * Raises <b>OnDeleteCommand</b> event.
+ * This method is invoked when a button control raises <b>OnCommand</b> event
+ * with <b>delete</b> command name.
+ * @param TDataGridCommandEventParameter event parameter
+ */
+ public function onDeleteCommand($param)
+ {
+ $this->raiseEvent('OnDeleteCommand',$this,$param);
+ }
+
+ /**
+ * Raises <b>OnEditCommand</b> event.
+ * This method is invoked when a button control raises <b>OnCommand</b> event
+ * with <b>edit</b> command name.
+ * @param TDataGridCommandEventParameter event parameter
+ */
+ public function onEditCommand($param)
+ {
+ $this->raiseEvent('OnEditCommand',$this,$param);
+ }
+
+ /**
+ * Raises <b>OnItemCommand</b> event.
+ * This method is invoked when a button control raises <b>OnCommand</b> event.
+ * @param TDataGridCommandEventParameter event parameter
+ */
+ public function onItemCommand($param)
+ {
+ $this->raiseEvent('OnItemCommand',$this,$param);
+ }
+
+ /**
+ * Raises <b>OnSortCommand</b> event.
+ * This method is invoked when a button control raises <b>OnCommand</b> event
+ * with <b>sort</b> command name.
+ * @param TDataGridSortCommandEventParameter event parameter
+ */
+ public function onSortCommand($param)
+ {
+ $this->raiseEvent('OnSortCommand',$this,$param);
+ }
+
+ /**
+ * Raises <b>OnUpdateCommand</b> event.
+ * This method is invoked when a button control raises <b>OnCommand</b> event
+ * with <b>update</b> command name.
+ * @param TDataGridCommandEventParameter event parameter
+ */
+ public function onUpdateCommand($param)
+ {
+ $this->raiseEvent('OnUpdateCommand',$this,$param);
+ }
+
+ /**
+ * Raises <b>OnItemCreated</b> event.
+ * This method is invoked right after a datagrid item is created and before
+ * added to page hierarchy.
+ * @param TDataGridItemEventParameter event parameter
+ */
+ public function onItemCreated($param)
+ {
+ $this->raiseEvent('OnItemCreated',$this,$param);
+ }
+
+ /**
+ * Raises <b>OnPagerCreated</b> event.
+ * This method is invoked right after a datagrid pager is created and before
+ * added to page hierarchy.
+ * @param TDataGridPagerEventParameter event parameter
+ */
+ public function onPagerCreated($param)
+ {
+ $this->raiseEvent('OnPagerCreated',$this,$param);
+ }
+
+ /**
+ * Raises <b>OnItemDataBound</b> event.
+ * This method is invoked for each datagrid item after it performs
+ * databinding.
+ * @param TDataGridItemEventParameter event parameter
+ */
+ public function onItemDataBound($param)
+ {
+ $this->raiseEvent('OnItemDataBound',$this,$param);
+ }
+
+ /**
+ * Raises <b>OnPageIndexChanged</b> event.
+ * This method is invoked when current page is changed.
+ * @param TDataGridPageChangedEventParameter event parameter
+ */
+ public function onPageIndexChanged($param)
+ {
+ $this->raiseEvent('OnPageIndexChanged',$this,$param);
+ }
+
+ /**
+ * Saves item count in viewstate.
+ * This method is invoked right before control state is to be saved.
+ */
+ public function saveState()
+ {
+ parent::saveState();
+ if(!$this->getEnableViewState(true))
+ return;
+ if($this->_items)
+ $this->setViewState('ItemCount',$this->_items->getCount(),0);
+ else
+ $this->clearViewState('ItemCount');
+ if($this->_autoColumns)
+ {
+ $state=array();
+ foreach($this->_autoColumns as $column)
+ $state[]=$column->saveState();
+ $this->setViewState('AutoColumns',$state,array());
+ }
+ else
+ $this->clearViewState('AutoColumns');
+ if($this->_columns)
+ {
+ $state=array();
+ foreach($this->_columns as $column)
+ $state[]=$column->saveState();
+ $this->setViewState('Columns',$state,array());
+ }
+ else
+ $this->clearViewState('Columns');
+ }
+
+ /**
+ * Loads item count information from viewstate.
+ * This method is invoked right after control state is loaded.
+ */
+ public function loadState()
+ {
+ parent::loadState();
+ if(!$this->getEnableViewState(true))
+ return;
+ if(!$this->getIsDataBound())
+ {
+ $state=$this->getViewState('AutoColumns',array());
+ if(!empty($state))
+ {
+ $this->_autoColumns=new TDataGridColumnCollection($this);
+ foreach($state as $st)
+ {
+ $column=new $this->AutoGenerateColumnName;
+ $column->loadState($st);
+ $this->_autoColumns->add($column);
+ }
+ }
+ else
+ $this->_autoColumns=null;
+ $state=$this->getViewState('Columns',array());
+ if($this->_columns && $this->_columns->getCount()===count($state))
+ {
+ $i=0;
+ foreach($this->_columns as $column)
+ {
+ $column->loadState($state[$i]);
+ $i++;
+ }
+ }
+ $this->restoreGridFromViewState();
+ }
+ }
+
+ /**
+ * Clears up all items in the datagrid.
+ */
+ public function reset()
+ {
+ $this->getControls()->clear();
+ $this->getItems()->clear();
+ $this->_header=null;
+ $this->_footer=null;
+ $this->_topPager=null;
+ $this->_bottomPager=null;
+ $this->_useEmptyTemplate=false;
+ }
+
+ /**
+ * Restores datagrid content from viewstate.
+ */
+ protected function restoreGridFromViewState()
+ {
+ $this->reset();
+
+ $allowPaging=$this->getAllowPaging();
+
+ $itemCount=$this->getViewState('ItemCount',0);
+ $dsIndex=$this->getViewState('DataSourceIndex',0);
+
+ $columns=new TList($this->getColumns());
+ $columns->mergeWith($this->_autoColumns);
+ $this->_allColumns=$columns;
+
+ $items=$this->getItems();
+
+ if($columns->getCount())
+ {
+ foreach($columns as $column)
+ $column->initialize();
+ $selectedIndex=$this->getSelectedItemIndex();
+ $editIndex=$this->getEditItemIndex();
+ for($index=0;$index<$itemCount;++$index)
+ {
+ if($index===0)
+ {
+ if($allowPaging)
+ $this->_topPager=$this->createPager();
+ $this->_header=$this->createItemInternal(-1,-1,TListItemType::Header,false,null,$columns);
+ }
+ if($index===$editIndex)
+ $itemType=TListItemType::EditItem;
+ else if($index===$selectedIndex)
+ $itemType=TListItemType::SelectedItem;
+ else if($index % 2)
+ $itemType=TListItemType::AlternatingItem;
+ else
+ $itemType=TListItemType::Item;
+ $items->add($this->createItemInternal($index,$dsIndex,$itemType,false,null,$columns));
+ $dsIndex++;
+ }
+ if($index>0)
+ {
+ $this->_footer=$this->createItemInternal(-1,-1,TListItemType::Footer,false,null,$columns);
+ if($allowPaging)
+ $this->_bottomPager=$this->createPager();
+ }
+ }
+ if(!$dsIndex && $this->_emptyTemplate!==null)
+ {
+ $this->_useEmptyTemplate=true;
+ $this->_emptyTemplate->instantiateIn($this);
+ }
+ }
+
+ /**
+ * Performs databinding to populate datagrid items from data source.
+ * This method is invoked by {@link dataBind()}.
+ * You may override this function to provide your own way of data population.
+ * @param Traversable the bound data
+ */
+ protected function performDataBinding($data)
+ {
+ $this->reset();
+ $keys=$this->getDataKeys();
+ $keys->clear();
+ $keyField=$this->getDataKeyField();
+
+ // get all columns
+ if($this->getAutoGenerateColumns())
+ {
+ $columns=new TList($this->getColumns());
+ $autoColumns=$this->createAutoColumns($data);
+ $columns->mergeWith($autoColumns);
+ }
+ else
+ $columns=$this->getColumns();
+ $this->_allColumns=$columns;
+
+ $items=$this->getItems();
+
+ $index=0;
+ $allowPaging=$this->getAllowPaging() && ($data instanceof TPagedDataSource);
+ $dsIndex=$allowPaging?$data->getFirstIndexInPage():0;
+ $this->setViewState('DataSourceIndex',$dsIndex,0);
+ if($columns->getCount())
+ {
+ foreach($columns as $column)
+ $column->initialize();
+
+ $selectedIndex=$this->getSelectedItemIndex();
+ $editIndex=$this->getEditItemIndex();
+ foreach($data as $key=>$row)
+ {
+ if($keyField!=='')
+ $keys->add($this->getDataFieldValue($row,$keyField));
+ else
+ $keys->add($key);
+ if($index===0)
+ {
+ if($allowPaging)
+ $this->_topPager=$this->createPager();
+ $this->_header=$this->createItemInternal(-1,-1,TListItemType::Header,true,null,$columns);
+ }
+ if($index===$editIndex)
+ $itemType=TListItemType::EditItem;
+ else if($index===$selectedIndex)
+ $itemType=TListItemType::SelectedItem;
+ else if($index % 2)
+ $itemType=TListItemType::AlternatingItem;
+ else
+ $itemType=TListItemType::Item;
+ $items->add($this->createItemInternal($index,$dsIndex,$itemType,true,$row,$columns));
+ $index++;
+ $dsIndex++;
+ }
+ if($index>0)
+ {
+ $this->_footer=$this->createItemInternal(-1,-1,TListItemType::Footer,true,null,$columns);
+ if($allowPaging)
+ $this->_bottomPager=$this->createPager();
+ }
+ }
+ $this->setViewState('ItemCount',$index,0);
+ if(!$dsIndex && $this->_emptyTemplate!==null)
+ {
+ $this->_useEmptyTemplate=true;
+ $this->_emptyTemplate->instantiateIn($this);
+ $this->dataBindChildren();
+ }
+ }
+
+ /**
+ * Merges consecutive cells who have the same text.
+ * @since 3.1.1
+ */
+ private function groupCells()
+ {
+ if(($columns=$this->_allColumns)===null)
+ return;
+ $items=$this->getItems();
+ foreach($columns as $id=>$column)
+ {
+ if(!$column->getEnableCellGrouping())
+ continue;
+ $prevCell=null;
+ $prevCellText=null;
+ foreach($items as $item)
+ {
+ $itemType=$item->getItemType();
+ $cell=$item->getCells()->itemAt($id);
+ if(!$cell->getVisible())
+ continue;
+ if($itemType===TListItemType::Item || $itemType===TListItemType::AlternatingItem || $itemType===TListItemType::SelectedItem)
+ {
+ if(($cellText=$this->getCellText($cell))==='')
+ {
+ $prevCell=null;
+ $prevCellText=null;
+ continue;
+ }
+ if($prevCell===null || $prevCellText!==$cellText)
+ {
+ $prevCell=$cell;
+ $prevCellText=$cellText;
+ }
+ else
+ {
+ if(($rowSpan=$prevCell->getRowSpan())===0)
+ $rowSpan=1;
+ $prevCell->setRowSpan($rowSpan+1);
+ $cell->setVisible(false);
+ }
+ }
+ }
+ }
+ }
+
+ private function getCellText($cell)
+ {
+ if(($data=$cell->getText())==='' && $cell->getHasControls())
+ {
+ $controls=$cell->getControls();
+ foreach($controls as $control)
+ {
+ if($control instanceof IDataRenderer)
+ return $control->getData();
+ }
+ }
+ return $data;
+ }
+
+ /**
+ * Creates a datagrid item instance based on the item type and index.
+ * @param integer zero-based item index
+ * @param TListItemType item type
+ * @return TDataGridItem created data list item
+ */
+ protected function createItem($itemIndex,$dataSourceIndex,$itemType)
+ {
+ return new TDataGridItem($itemIndex,$dataSourceIndex,$itemType);
+ }
+
+ private function createItemInternal($itemIndex,$dataSourceIndex,$itemType,$dataBind,$dataItem,$columns)
+ {
+ $item=$this->createItem($itemIndex,$dataSourceIndex,$itemType);
+ $this->initializeItem($item,$columns);
+ $param=new TDataGridItemEventParameter($item);
+ if($dataBind)
+ {
+ $item->setDataItem($dataItem);
+ $this->onItemCreated($param);
+ $this->getControls()->add($item);
+ $item->dataBind();
+ $this->onItemDataBound($param);
+ }
+ else
+ {
+ $this->onItemCreated($param);
+ $this->getControls()->add($item);
+ }
+ return $item;
+ }
+
+ /**
+ * Initializes a datagrid item and cells inside it
+ * @param TDataGrid datagrid item to be initialized
+ * @param TDataGridColumnCollection datagrid columns to be used to initialize the cells in the item
+ */
+ protected function initializeItem($item,$columns)
+ {
+ $cells=$item->getCells();
+ $itemType=$item->getItemType();
+ $index=0;
+ foreach($columns as $column)
+ {
+ if($itemType===TListItemType::Header)
+ $cell=new TTableHeaderCell;
+ else
+ $cell=new TTableCell;
+ if(($id=$column->getID())!=='')
+ $item->registerObject($id,$cell);
+ $cells->add($cell);
+ $column->initializeCell($cell,$index,$itemType);
+ $index++;
+ }
+ }
+
+ protected function createPager()
+ {
+ $pager=new TDataGridPager($this);
+ $this->buildPager($pager);
+ $this->onPagerCreated(new TDataGridPagerEventParameter($pager));
+ $this->getControls()->add($pager);
+ return $pager;
+ }
+
+ /**
+ * Builds the pager content based on pager style.
+ * @param TDataGridPager the container for the pager
+ */
+ protected function buildPager($pager)
+ {
+ switch($this->getPagerStyle()->getMode())
+ {
+ case TDataGridPagerMode::NextPrev:
+ $this->buildNextPrevPager($pager);
+ break;
+ case TDataGridPagerMode::Numeric:
+ $this->buildNumericPager($pager);
+ break;
+ }
+ }
+
+ /**
+ * Creates a pager button.
+ * Depending on the button type, a TLinkButton or a TButton may be created.
+ * If it is enabled (clickable), its command name and parameter will also be set.
+ * Derived classes may override this method to create additional types of buttons, such as TImageButton.
+ * @param mixed the container pager instance of TActiveDatagridPager
+ * @param string button type, either LinkButton or PushButton
+ * @param boolean whether the button should be enabled
+ * @param string caption of the button
+ * @param string CommandName corresponding to the OnCommand event of the button
+ * @param string CommandParameter corresponding to the OnCommand event of the button
+ * @return mixed the button instance
+ */
+ protected function createPagerButton($pager,$buttonType,$enabled,$text,$commandName,$commandParameter)
+ {
+ if($buttonType===TDataGridPagerButtonType::LinkButton)
+ {
+ if($enabled)
+ $button=new TLinkButton;
+ else
+ {
+ $button=new TLabel;
+ $button->setText($text);
+ return $button;
+ }
+ }
+ else
+ {
+ $button=new TButton;
+ if(!$enabled)
+ $button->setEnabled(false);
+ }
+ $button->setText($text);
+ $button->setCommandName($commandName);
+ $button->setCommandParameter($commandParameter);
+ $button->setCausesValidation(false);
+ return $button;
+ }
+
+ /**
+ * Builds a next-prev pager
+ * @param TDataGridPager the container for the pager
+ */
+ protected function buildNextPrevPager($pager)
+ {
+ $style=$this->getPagerStyle();
+ $buttonType=$style->getButtonType();
+ $controls=$pager->getControls();
+ $currentPageIndex=$this->getCurrentPageIndex();
+ if($currentPageIndex===0)
+ {
+ if(($text=$style->getFirstPageText())!=='')
+ {
+ $label=$this->createPagerButton($pager,$buttonType,false,$text,'','');
+ $controls->add($label);
+ $controls->add("\n");
+ }
+
+ $label=$this->createPagerButton($pager,$buttonType,false,$style->getPrevPageText(),'','');
+ $controls->add($label);
+ }
+ else
+ {
+ if(($text=$style->getFirstPageText())!=='')
+ {
+ $button=$this->createPagerButton($pager,$buttonType,true,$text,self::CMD_PAGE,self::CMD_PAGE_FIRST);
+ $controls->add($button);
+ $controls->add("\n");
+ }
+
+ $button=$this->createPagerButton($pager,$buttonType,true,$style->getPrevPageText(),self::CMD_PAGE,self::CMD_PAGE_PREV);
+ $controls->add($button);
+ }
+ $controls->add("\n");
+ if($currentPageIndex===$this->getPageCount()-1)
+ {
+ $label=$this->createPagerButton($pager,$buttonType,false,$style->getNextPageText(),'','');
+ $controls->add($label);
+ if(($text=$style->getLastPageText())!=='')
+ {
+ $controls->add("\n");
+ $label=$this->createPagerButton($pager,$buttonType,false,$text,'','');
+ $controls->add($label);
+ }
+ }
+ else
+ {
+ $button=$this->createPagerButton($pager,$buttonType,true,$style->getNextPageText(),self::CMD_PAGE,self::CMD_PAGE_NEXT);
+ $controls->add($button);
+ if(($text=$style->getLastPageText())!=='')
+ {
+ $controls->add("\n");
+ $button=$this->createPagerButton($pager,$buttonType,true,$text,self::CMD_PAGE,self::CMD_PAGE_LAST);
+ $controls->add($button);
+ }
+ }
+ }
+
+ /**
+ * Builds a numeric pager
+ * @param TDataGridPager the container for the pager
+ */
+ protected function buildNumericPager($pager)
+ {
+ $style=$this->getPagerStyle();
+ $buttonType=$style->getButtonType();
+ $controls=$pager->getControls();
+ $pageCount=$this->getPageCount();
+ $pageIndex=$this->getCurrentPageIndex()+1;
+ $maxButtonCount=$style->getPageButtonCount();
+ $buttonCount=$maxButtonCount>$pageCount?$pageCount:$maxButtonCount;
+ $startPageIndex=1;
+ $endPageIndex=$buttonCount;
+ if($pageIndex>$endPageIndex)
+ {
+ $startPageIndex=((int)(($pageIndex-1)/$maxButtonCount))*$maxButtonCount+1;
+ if(($endPageIndex=$startPageIndex+$maxButtonCount-1)>$pageCount)
+ $endPageIndex=$pageCount;
+ if($endPageIndex-$startPageIndex+1<$maxButtonCount)
+ {
+ if(($startPageIndex=$endPageIndex-$maxButtonCount+1)<1)
+ $startPageIndex=1;
+ }
+ }
+
+ if($startPageIndex>1)
+ {
+ if(($text=$style->getFirstPageText())!=='')
+ {
+ $button=$this->createPagerButton($pager,$buttonType,true,$text,self::CMD_PAGE,self::CMD_PAGE_FIRST);
+ $controls->add($button);
+ $controls->add("\n");
+ }
+ $prevPageIndex=$startPageIndex-1;
+ $button=$this->createPagerButton($pager,$buttonType,true,$style->getPrevPageText(),self::CMD_PAGE,"$prevPageIndex");
+ $controls->add($button);
+ $controls->add("\n");
+ }
+
+ for($i=$startPageIndex;$i<=$endPageIndex;++$i)
+ {
+ if($i===$pageIndex)
+ {
+ $label=$this->createPagerButton($pager,$buttonType,false,"$i",'','');
+ $controls->add($label);
+ }
+ else
+ {
+ $button=$this->createPagerButton($pager,$buttonType,true,"$i",self::CMD_PAGE,"$i");
+ $controls->add($button);
+ }
+ if($i<$endPageIndex)
+ $controls->add("\n");
+ }
+
+ if($pageCount>$endPageIndex)
+ {
+ $controls->add("\n");
+ $nextPageIndex=$endPageIndex+1;
+ $button=$this->createPagerButton($pager,$buttonType,true,$style->getNextPageText(),self::CMD_PAGE,"$nextPageIndex");
+ $controls->add($button);
+ if(($text=$style->getLastPageText())!=='')
+ {
+ $controls->add("\n");
+ $button=$this->createPagerButton($pager,$buttonType,true,$text,self::CMD_PAGE,self::CMD_PAGE_LAST);
+ $controls->add($button);
+ }
+ }
+ }
+
+ /**
+ * Automatically generates datagrid columns based on datasource schema
+ * @param Traversable data source bound to the datagrid
+ * @return TDataGridColumnCollection
+ */
+ protected function createAutoColumns($dataSource)
+ {
+ if(!$dataSource)
+ return null;
+ $autoColumns=$this->getAutoColumns();
+ $autoColumns->clear();
+ foreach($dataSource as $row)
+ {
+ foreach($row as $key=>$value)
+ {
+ $column=new $this->AutoGenerateColumnName;
+ if(is_string($key))
+ {
+ $column->setHeaderText($key);
+ $column->setDataField($key);
+ $column->setSortExpression($key);
+ $autoColumns->add($column);
+ }
+ else
+ {
+ $column->setHeaderText(TListItemType::Item);
+ $column->setDataField($key);
+ $column->setSortExpression(TListItemType::Item);
+ $autoColumns->add($column);
+ }
+ }
+ break;
+ }
+ return $autoColumns;
+ }
+
+ /**
+ * Applies styles to items, header, footer and separators.
+ * Item styles are applied in a hierarchical way. Style in higher hierarchy
+ * will inherit from styles in lower hierarchy.
+ * Starting from the lowest hierarchy, the item styles include
+ * item's own style, {@link getItemStyle ItemStyle}, {@link getAlternatingItemStyle AlternatingItemStyle},
+ * {@link getSelectedItemStyle SelectedItemStyle}, and {@link getEditItemStyle EditItemStyle}.
+ * Therefore, if background color is set as red in {@link getItemStyle ItemStyle},
+ * {@link getEditItemStyle EditItemStyle} will also have red background color
+ * unless it is set to a different value explicitly.
+ */
+ protected function applyItemStyles()
+ {
+ $itemStyle=$this->getViewState('ItemStyle',null);
+
+ $alternatingItemStyle=$this->getViewState('AlternatingItemStyle',null);
+ if($itemStyle!==null)
+ {
+ if($alternatingItemStyle===null)
+ $alternatingItemStyle=$itemStyle;
+ else
+ $alternatingItemStyle->mergeWith($itemStyle);
+ }
+
+ $selectedItemStyle=$this->getViewState('SelectedItemStyle',null);
+
+ $editItemStyle=$this->getViewState('EditItemStyle',null);
+ if($selectedItemStyle!==null)
+ {
+ if($editItemStyle===null)
+ $editItemStyle=$selectedItemStyle;
+ else
+ $editItemStyle->mergeWith($selectedItemStyle);
+ }
+
+ $headerStyle=$this->getViewState('HeaderStyle',null);
+ $footerStyle=$this->getViewState('FooterStyle',null);
+ $pagerStyle=$this->getViewState('PagerStyle',null);
+ $separatorStyle=$this->getViewState('SeparatorStyle',null);
+
+ foreach($this->getControls() as $index=>$item)
+ {
+ if(!($item instanceof TDataGridItem) && !($item instanceof TDataGridPager))
+ continue;
+ $itemType=$item->getItemType();
+ switch($itemType)
+ {
+ case TListItemType::Header:
+ if($headerStyle)
+ $item->getStyle()->mergeWith($headerStyle);
+ if(!$this->getShowHeader())
+ $item->setVisible(false);
+ break;
+ case TListItemType::Footer:
+ if($footerStyle)
+ $item->getStyle()->mergeWith($footerStyle);
+ if(!$this->getShowFooter())
+ $item->setVisible(false);
+ break;
+ case TListItemType::Separator:
+ if($separatorStyle)
+ $item->getStyle()->mergeWith($separatorStyle);
+ break;
+ case TListItemType::Item:
+ if($itemStyle)
+ $item->getStyle()->mergeWith($itemStyle);
+ break;
+ case TListItemType::AlternatingItem:
+ if($alternatingItemStyle)
+ $item->getStyle()->mergeWith($alternatingItemStyle);
+ break;
+ case TListItemType::SelectedItem:
+ if($selectedItemStyle)
+ $item->getStyle()->mergeWith($selectedItemStyle);
+ if($index % 2==1)
+ {
+ if($itemStyle)
+ $item->getStyle()->mergeWith($itemStyle);
+ }
+ else
+ {
+ if($alternatingItemStyle)
+ $item->getStyle()->mergeWith($alternatingItemStyle);
+ }
+ break;
+ case TListItemType::EditItem:
+ if($editItemStyle)
+ $item->getStyle()->mergeWith($editItemStyle);
+ if($index % 2==1)
+ {
+ if($itemStyle)
+ $item->getStyle()->mergeWith($itemStyle);
+ }
+ else
+ {
+ if($alternatingItemStyle)
+ $item->getStyle()->mergeWith($alternatingItemStyle);
+ }
+ break;
+ case TListItemType::Pager:
+ if($pagerStyle)
+ {
+ $item->getStyle()->mergeWith($pagerStyle);
+ if($index===0)
+ {
+ if($pagerStyle->getPosition()===TDataGridPagerPosition::Bottom || !$pagerStyle->getVisible())
+ $item->setVisible(false);
+ }
+ else
+ {
+ if($pagerStyle->getPosition()===TDataGridPagerPosition::Top || !$pagerStyle->getVisible())
+ $item->setVisible(false);
+ }
+ }
+ break;
+ default:
+ break;
+ }
+ if($this->_columns && $itemType!==TListItemType::Pager)
+ {
+ $n=$this->_columns->getCount();
+ $cells=$item->getCells();
+ for($i=0;$i<$n;++$i)
+ {
+ $cell=$cells->itemAt($i);
+ $column=$this->_columns->itemAt($i);
+ if(!$column->getVisible())
+ $cell->setVisible(false);
+ else
+ {
+ if($itemType===TListItemType::Header)
+ $style=$column->getHeaderStyle(false);
+ else if($itemType===TListItemType::Footer)
+ $style=$column->getFooterStyle(false);
+ else
+ $style=$column->getItemStyle(false);
+ if($style!==null)
+ $cell->getStyle()->mergeWith($style);
+ }
+ }
+ }
+ }
+ }
+
+ /**
+ * Renders the openning tag for the datagrid control which will render table caption if present.
+ * @param THtmlWriter the writer used for the rendering purpose
+ */
+ public function renderBeginTag($writer)
+ {
+ parent::renderBeginTag($writer);
+ if(($caption=$this->getCaption())!=='')
+ {
+ if(($align=$this->getCaptionAlign())!==TTableCaptionAlign::NotSet)
+ $writer->addAttribute('align',strtolower($align));
+ $writer->renderBeginTag('caption');
+ $writer->write($caption);
+ $writer->renderEndTag();
+ }
+ }
+
+ /**
+ * Renders the datagrid.
+ * @param THtmlWriter writer for the rendering purpose
+ */
+ public function render($writer)
+ {
+ if($this->getHasControls())
+ {
+ $this->groupCells();
+ if($this->_useEmptyTemplate)
+ {
+ $control=new TWebControl;
+ $control->setID($this->getClientID());
+ $control->copyBaseAttributes($this);
+ if($this->getHasStyle())
+ $control->getStyle()->copyFrom($this->getStyle());
+ $control->renderBeginTag($writer);
+ $this->renderContents($writer);
+ $control->renderEndTag($writer);
+ }
+ else if($this->getViewState('ItemCount',0)>0)
+ {
+ $this->applyItemStyles();
+ if($this->_topPager)
+ {
+ $this->_topPager->renderControl($writer);
+ $writer->writeLine();
+ }
+ $this->renderTable($writer);
+ if($this->_bottomPager)
+ {
+ $writer->writeLine();
+ $this->_bottomPager->renderControl($writer);
+ }
+ }
+ }
+ }
+
+ /**
+ * Renders the tabular data.
+ * @param THtmlWriter writer
+ */
+ protected function renderTable($writer)
+ {
+ $this->renderBeginTag($writer);
+ if($this->_header && $this->_header->getVisible())
+ {
+ $writer->writeLine();
+ if($style=$this->getViewState('TableHeadStyle',null))
+ $style->addAttributesToRender($writer);
+ $writer->renderBeginTag('thead');
+ $this->_header->render($writer);
+ $writer->renderEndTag();
+ }
+ $writer->writeLine();
+ if($style=$this->getViewState('TableBodyStyle',null))
+ $style->addAttributesToRender($writer);
+ $writer->renderBeginTag('tbody');
+ foreach($this->getItems() as $item)
+ $item->renderControl($writer);
+ $writer->renderEndTag();
+
+ if($this->_footer && $this->_footer->getVisible())
+ {
+ $writer->writeLine();
+ if($style=$this->getViewState('TableFootStyle',null))
+ $style->addAttributesToRender($writer);
+ $writer->renderBeginTag('tfoot');
+ $this->_footer->render($writer);
+ $writer->renderEndTag();
+ }
+
+ $writer->writeLine();
+ $this->renderEndTag($writer);
+ }
+}
+
+/**
+ * TDataGridItemEventParameter class
+ *
+ * TDataGridItemEventParameter encapsulates the parameter data for
+ * {@link TDataGrid::onItemCreated OnItemCreated} event of {@link TDataGrid} controls.
+ * The {@link getItem Item} property indicates the datagrid item related with the event.
+ *
+ * @author Qiang Xue <qiang.xue@gmail.com>
+ * @version $Id$
+ * @package System.Web.UI.WebControls
+ * @since 3.0
+ */
+class TDataGridItemEventParameter extends TEventParameter
+{
+ /**
+ * The TDataGridItem control responsible for the event.
+ * @var TDataGridItem
+ */
+ private $_item=null;
+
+ /**
+ * Constructor.
+ * @param TDataGridItem datagrid item related with the corresponding event
+ */
+ public function __construct(TDataGridItem $item)
+ {
+ $this->_item=$item;
+ }
+
+ /**
+ * @return TDataGridItem datagrid item related with the corresponding event
+ */
+ public function getItem()
+ {
+ return $this->_item;
+ }
+}
+
+/**
+ * TDataGridPagerEventParameter class
+ *
+ * TDataGridPagerEventParameter encapsulates the parameter data for
+ * {@link TDataGrid::onPagerCreated OnPagerCreated} event of {@link TDataGrid} controls.
+ * The {@link getPager Pager} property indicates the datagrid pager related with the event.
+ *
+ * @author Qiang Xue <qiang.xue@gmail.com>
+ * @version $Id$
+ * @package System.Web.UI.WebControls
+ * @since 3.0
+ */
+class TDataGridPagerEventParameter extends TEventParameter
+{
+ /**
+ * The TDataGridPager control responsible for the event.
+ * @var TDataGridPager
+ */
+ protected $_pager=null;
+
+ /**
+ * Constructor.
+ * @param TDataGridPager datagrid pager related with the corresponding event
+ */
+ public function __construct(TDataGridPager $pager)
+ {
+ $this->_pager=$pager;
+ }
+
+ /**
+ * @return TDataGridPager datagrid pager related with the corresponding event
+ */
+ public function getPager()
+ {
+ return $this->_pager;
+ }
+}
+
+/**
+ * TDataGridCommandEventParameter class
+ *
+ * TDataGridCommandEventParameter encapsulates the parameter data for
+ * {@link TDataGrid::onItemCommand ItemCommand} event of {@link TDataGrid} controls.
+ *
+ * The {@link getItem Item} property indicates the datagrid item related with the event.
+ * The {@link getCommandSource CommandSource} refers to the control that originally
+ * raises the Command event.
+ *
+ * @author Qiang Xue <qiang.xue@gmail.com>
+ * @version $Id$
+ * @package System.Web.UI.WebControls
+ * @since 3.0
+ */
+class TDataGridCommandEventParameter extends TCommandEventParameter
+{
+ /**
+ * @var TDataGridItem the TDataGridItem control responsible for the event.
+ */
+ private $_item=null;
+ /**
+ * @var TControl the control originally raises the <b>Command</b> event.
+ */
+ private $_source=null;
+
+ /**
+ * Constructor.
+ * @param TDataGridItem datagrid item responsible for the event
+ * @param TControl original event sender
+ * @param TCommandEventParameter original event parameter
+ */
+ public function __construct($item,$source,TCommandEventParameter $param)
+ {
+ $this->_item=$item;
+ $this->_source=$source;
+ parent::__construct($param->getCommandName(),$param->getCommandParameter());
+ }
+
+ /**
+ * @return TDataGridItem the TDataGridItem control responsible for the event.
+ */
+ public function getItem()
+ {
+ return $this->_item;
+ }
+
+ /**
+ * @return TControl the control originally raises the <b>Command</b> event.
+ */
+ public function getCommandSource()
+ {
+ return $this->_source;
+ }
+}
+
+/**
+ * TDataGridSortCommandEventParameter class
+ *
+ * TDataGridSortCommandEventParameter encapsulates the parameter data for
+ * {@link TDataGrid::onSortCommand SortCommand} event of {@link TDataGrid} controls.
+ *
+ * The {@link getCommandSource CommandSource} property refers to the control
+ * that originally raises the OnCommand event, while {@link getSortExpression SortExpression}
+ * gives the sort expression carried with the sort command.
+ *
+ * @author Qiang Xue <qiang.xue@gmail.com>
+ * @version $Id$
+ * @package System.Web.UI.WebControls
+ * @since 3.0
+ */
+class TDataGridSortCommandEventParameter extends TEventParameter
+{
+ /**
+ * @var string sort expression
+ */
+ private $_sortExpression='';
+ /**
+ * @var TControl original event sender
+ */
+ private $_source=null;
+
+ /**
+ * Constructor.
+ * @param TControl the control originally raises the <b>OnCommand</b> event.
+ * @param TDataGridCommandEventParameter command event parameter
+ */
+ public function __construct($source,TDataGridCommandEventParameter $param)
+ {
+ $this->_source=$source;
+ $this->_sortExpression=$param->getCommandParameter();
+ }
+
+ /**
+ * @return TControl the control originally raises the <b>OnCommand</b> event.
+ */
+ public function getCommandSource()
+ {
+ return $this->_source;
+ }
+
+ /**
+ * @return string sort expression
+ */
+ public function getSortExpression()
+ {
+ return $this->_sortExpression;
+ }
+}
+
+/**
+ * TDataGridPageChangedEventParameter class
+ *
+ * TDataGridPageChangedEventParameter encapsulates the parameter data for
+ * {@link TDataGrid::onPageIndexChanged PageIndexChanged} event of {@link TDataGrid} controls.
+ *
+ * The {@link getCommandSource CommandSource} property refers to the control
+ * that originally raises the OnCommand event, while {@link getNewPageIndex NewPageIndex}
+ * returns the new page index carried with the page command.
+ *
+ * @author Qiang Xue <qiang.xue@gmail.com>
+ * @version $Id$
+ * @package System.Web.UI.WebControls
+ * @since 3.0
+ */
+class TDataGridPageChangedEventParameter extends TEventParameter
+{
+ /**
+ * @var integer new page index
+ */
+ private $_newIndex;
+ /**
+ * @var TControl original event sender
+ */
+ private $_source=null;
+
+ /**
+ * Constructor.
+ * @param TControl the control originally raises the <b>OnCommand</b> event.
+ * @param integer new page index
+ */
+ public function __construct($source,$newPageIndex)
+ {
+ $this->_source=$source;
+ $this->_newIndex=$newPageIndex;
+ }
+
+ /**
+ * @return TControl the control originally raises the <b>OnCommand</b> event.
+ */
+ public function getCommandSource()
+ {
+ return $this->_source;
+ }
+
+ /**
+ * @return integer new page index
+ */
+ public function getNewPageIndex()
+ {
+ return $this->_newIndex;
+ }
+}
+
+/**
+ * TDataGridItem class
+ *
+ * A TDataGridItem control represents an item in the {@link TDataGrid} control,
+ * such as heading section, footer section, or a data item.
+ * The index and data value of the item can be accessed via {@link getItemIndex ItemIndex}>
+ * and {@link getDataItem DataItem} properties, respectively. The type of the item
+ * is given by {@link getItemType ItemType} property. Property {@link getDataSourceIndex DataSourceIndex}
+ * gives the index of the item from the bound data source.
+ *
+ * @author Qiang Xue <qiang.xue@gmail.com>
+ * @version $Id$
+ * @package System.Web.UI.WebControls
+ * @since 3.0
+ */
+class TDataGridItem extends TTableRow implements INamingContainer
+{
+ /**
+ * @var integer index of the data item in the Items collection of datagrid
+ */
+ private $_itemIndex='';
+ /**
+ * @var integer index of the item from the bound data source
+ */
+ private $_dataSourceIndex=0;
+ /**
+ * type of the TDataGridItem
+ * @var string
+ */
+ private $_itemType='';
+ /**
+ * value of the data item
+ * @var mixed
+ */
+ private $_data=null;
+
+ /**
+ * Constructor.
+ * @param integer zero-based index of the item in the item collection of datagrid
+ * @param TListItemType item type
+ */
+ public function __construct($itemIndex,$dataSourceIndex,$itemType)
+ {
+ $this->_itemIndex=$itemIndex;
+ $this->_dataSourceIndex=$dataSourceIndex;
+ $this->setItemType($itemType);
+ if($itemType===TListItemType::Header)
+ $this->setTableSection(TTableRowSection::Header);
+ else if($itemType===TListItemType::Footer)
+ $this->setTableSection(TTableRowSection::Footer);
+ }
+
+ /**
+ * @return TListItemType item type.
+ */
+ public function getItemType()
+ {
+ return $this->_itemType;
+ }
+
+ /**
+ * @param TListItemType item type
+ */
+ public function setItemType($value)
+ {
+ $this->_itemType=TPropertyValue::ensureEnum($value,'TListItemType');
+ }
+
+ /**
+ * @return integer zero-based index of the item in the item collection of datagrid
+ */
+ public function getItemIndex()
+ {
+ return $this->_itemIndex;
+ }
+
+ /**
+ * @return integer the index of the datagrid item from the bound data source
+ */
+ public function getDataSourceIndex()
+ {
+ return $this->_dataSourceIndex;
+ }
+
+ /**
+ * @return mixed data associated with the item
+ * @since 3.1.0
+ */
+ public function getData()
+ {
+ return $this->_data;
+ }
+
+ /**
+ * @param mixed data to be associated with the item
+ * @since 3.1.0
+ */
+ public function setData($value)
+ {
+ $this->_data=$value;
+ }
+
+ /**
+ * This property is deprecated since v3.1.0.
+ * @return mixed data associated with the item
+ * @deprecated deprecated since v3.1.0. Use {@link getData} instead.
+ */
+ public function getDataItem()
+ {
+ return $this->getData();
+ }
+
+ /**
+ * This property is deprecated since v3.1.0.
+ * @param mixed data to be associated with the item
+ * @deprecated deprecated since version 3.1.0. Use {@link setData} instead.
+ */
+ public function setDataItem($value)
+ {
+ return $this->setData($value);
+ }
+
+ /**
+ * This method overrides parent's implementation by wrapping event parameter
+ * for <b>OnCommand</b> event with item information.
+ * @param TControl the sender of the event
+ * @param TEventParameter event parameter
+ * @return boolean whether the event bubbling should stop here.
+ */
+ public function bubbleEvent($sender,$param)
+ {
+ if($param instanceof TCommandEventParameter)
+ {
+ $this->raiseBubbleEvent($this,new TDataGridCommandEventParameter($this,$sender,$param));
+ return true;
+ }
+ else
+ return false;
+ }
+}
+
+
+/**
+ * TDataGridPager class.
+ *
+ * TDataGridPager represents a datagrid pager.
+ *
+ * @author Qiang Xue <qiang.xue@gmail.com>
+ * @version $Id$
+ * @package System.Web.UI.WebControls
+ * @since 3.0
+ */
+class TDataGridPager extends TPanel implements INamingContainer
+{
+ private $_dataGrid;
+
+ /**
+ * Constructor.
+ * @param TDataGrid datagrid object
+ */
+ public function __construct($dataGrid)
+ {
+ $this->_dataGrid=$dataGrid;
+ }
+
+ /**
+ * This method overrides parent's implementation by wrapping event parameter
+ * for <b>OnCommand</b> event with item information.
+ * @param TControl the sender of the event
+ * @param TEventParameter event parameter
+ * @return boolean whether the event bubbling should stop here.
+ */
+ public function bubbleEvent($sender,$param)
+ {
+ if($param instanceof TCommandEventParameter)
+ {
+ $this->raiseBubbleEvent($this,new TDataGridCommandEventParameter($this,$sender,$param));
+ return true;
+ }
+ else
+ return false;
+ }
+
+ /**
+ * @return TDataGrid the datagrid owning this pager
+ */
+ public function getDataGrid()
+ {
+ return $this->_dataGrid;
+ }
+
+ /**
+ * @return string item type.
+ */
+ public function getItemType()
+ {
+ return TListItemType::Pager;
+ }
+}
+
+
+/**
+ * TDataGridItemCollection class.
+ *
+ * TDataGridItemCollection represents a collection of data grid items.
+ *
+ * @author Qiang Xue <qiang.xue@gmail.com>
+ * @version $Id$
+ * @package System.Web.UI.WebControls
+ * @since 3.0
+ */
+class TDataGridItemCollection extends TList
+{
+ /**
+ * Inserts an item at the specified position.
+ * This overrides the parent implementation by inserting only TDataGridItem.
+ * @param integer the speicified position.
+ * @param mixed new item
+ * @throws TInvalidDataTypeException if the item to be inserted is not a TDataGridItem.
+ */
+ public function insertAt($index,$item)
+ {
+ if($item instanceof TDataGridItem)
+ parent::insertAt($index,$item);
+ else
+ throw new TInvalidDataTypeException('datagriditemcollection_datagriditem_required');
+ }
+}
+
+/**
+ * TDataGridColumnCollection class.
+ *
+ * TDataGridColumnCollection represents a collection of data grid columns.
+ *
+ * @author Qiang Xue <qiang.xue@gmail.com>
+ * @version $Id$
+ * @package System.Web.UI.WebControls
+ * @since 3.0
+ */
+class TDataGridColumnCollection extends TList
+{
+ /**
+ * the control that owns this collection.
+ * @var TControl
+ */
+ private $_o;
+
+ /**
+ * Constructor.
+ * @param TDataGrid the control that owns this collection.
+ */
+ public function __construct(TDataGrid $owner)
+ {
+ $this->_o=$owner;
+ }
+
+ /**
+ * @return TDataGrid the control that owns this collection.
+ */
+ protected function getOwner()
+ {
+ return $this->_o;
+ }
+
+ /**
+ * Inserts an item at the specified position.
+ * This overrides the parent implementation by inserting only TDataGridColumn.
+ * @param integer the speicified position.
+ * @param mixed new item
+ * @throws TInvalidDataTypeException if the item to be inserted is not a TDataGridColumn.
+ */
+ public function insertAt($index,$item)
+ {
+ if($item instanceof TDataGridColumn)
+ {
+ $item->setOwner($this->_o);
+ parent::insertAt($index,$item);
+ }
+ else
+ throw new TInvalidDataTypeException('datagridcolumncollection_datagridcolumn_required');
+ }
+}
+
+/**
+ * TDataGridPagerMode class.
+ * TDataGridPagerMode defines the enumerable type for the possible modes that a datagrid pager can take.
+ *
+ * The following enumerable values are defined:
+ * - NextPrev: pager buttons are displayed as next and previous pages
+ * - Numeric: pager buttons are displayed as numeric page numbers
+ *
+ * @author Qiang Xue <qiang.xue@gmail.com>
+ * @version $Id$
+ * @package System.Web.UI.WebControls
+ * @since 3.0.4
+ */
+class TDataGridPagerMode extends TEnumerable
+{
+ const NextPrev='NextPrev';
+ const Numeric='Numeric';
+}
+
+
+/**
+ * TDataGridPagerButtonType class.
+ * TDataGridPagerButtonType defines the enumerable type for the possible types of datagrid pager buttons.
+ *
+ * The following enumerable values are defined:
+ * - LinkButton: link buttons
+ * - PushButton: form submit buttons
+ *
+ * @author Qiang Xue <qiang.xue@gmail.com>
+ * @version $Id$
+ * @package System.Web.UI.WebControls
+ * @since 3.0.4
+ */
+class TDataGridPagerButtonType extends TEnumerable
+{
+ const LinkButton='LinkButton';
+ const PushButton='PushButton';
+}
+
+
+/**
+ * TDataGridPagerPosition class.
+ * TDataGridPagerPosition defines the enumerable type for the possible positions that a datagrid pager can be located at.
+ *
+ * The following enumerable values are defined:
+ * - Bottom: pager appears only at the bottom of the data grid.
+ * - Top: pager appears only at the top of the data grid.
+ * - TopAndBottom: pager appears on both top and bottom of the data grid.
+ *
+ * @author Qiang Xue <qiang.xue@gmail.com>
+ * @version $Id$
+ * @package System.Web.UI.WebControls
+ * @since 3.0.4
+ */
+class TDataGridPagerPosition extends TEnumerable
+{
+ const Bottom='Bottom';
+ const Top='Top';
+ const TopAndBottom='TopAndBottom';
+}
+
diff --git a/framework/Web/UI/WebControls/TDataGridColumn.php b/framework/Web/UI/WebControls/TDataGridColumn.php
index d37fbc40..4794fbf8 100644
--- a/framework/Web/UI/WebControls/TDataGridColumn.php
+++ b/framework/Web/UI/WebControls/TDataGridColumn.php
@@ -1,567 +1,567 @@
-<?php
-/**
- * TDataGridColumn class file
- *
- * @author Qiang Xue <qiang.xue@gmail.com>
- * @link http://www.pradosoft.com/
- * @copyright Copyright &copy; 2005-2012 PradoSoft
- * @license http://www.pradosoft.com/license/
- * @version $Id$
- * @package System.Web.UI.WebControls
- */
-
-Prado::using('System.Util.TDataFieldAccessor');
-Prado::using('System.Web.UI.WebControls.TDataGrid');
-
-/**
- * TDataGridColumn class
- *
- * TDataGridColumn serves as the base class for the different column types of
- * the {@link TDataGrid} control.
- * TDataGridColumn defines the properties and methods that are common among
- * all datagrid column types. In particular, it initializes header and footer
- * cells according to {@link setHeaderText HeaderText} and {@link getHeaderStyle HeaderStyle}
- * {@link setFooterText FooterText} and {@link getFooterStyle FooterStyle} properties.
- * If {@link setHeaderImageUrl HeaderImageUrl} is specified, the image
- * will be displayed instead in the header cell.
- * The {@link getItemStyle ItemStyle} is applied to cells that belong to
- * non-header and -footer datagrid items.
- *
- * When the datagrid enables sorting, if the {@link setSortExpression SortExpression}
- * is not empty, the header cell will display a button (linkbutton or imagebutton)
- * that will bubble the sort command event to the datagrid.
- *
- * Since v3.1.0, TDataGridColumn has introduced two new properties {@link setHeaderRenderer HeaderRenderer}
- * and {@link setFooterRenderer FooterRenderer} which can be used to specify
- * the layout of header and footer column cells.
- * A renderer refers to a control class that is to be instantiated as a control.
- * For more details, see {@link TRepeater} and {@link TDataList}.
- *
- * Since v3.1.1, TDataGridColumn has introduced {@link setEnableCellGrouping EnableCellGrouping}.
- * If a column has this property set true, consecutive cells having the same content in this
- * column will be grouped into one cell.
- * Note, there are some limitations to cell grouping. We determine the cell content according to
- * the cell's {@link TTableCell::getText Text} property. If the text is empty and the cell has
- * some child controls, we will pick up the first control who implements {@link IDataRenderer}
- * and obtain its {@link IDataRenderer::getData Data} property.
- *
- * The following datagrid column types are provided by the framework currently,
- * - {@link TBoundColumn}, associated with a specific field in datasource and displays the corresponding data.
- * - {@link TEditCommandColumn}, displaying edit/update/cancel command buttons
- * - {@link TDropDownListColumn}, displaying a dropdown list when the item is in edit state
- * - {@link TButtonColumn}, displaying generic command buttons that may be bound to specific field in datasource.
- * - {@link THyperLinkColumn}, displaying a hyperlink that may be bound to specific field in datasource.
- * - {@link TCheckBoxColumn}, displaying a checkbox that may be bound to specific field in datasource.
- * - {@link TTemplateColumn}, displaying content based on templates.
- *
- * To create your own column class, simply override {@link initializeCell()} method,
- * which is the major logic for managing the data and presentation of cells in the column.
- *
- * @author Qiang Xue <qiang.xue@gmail.com>
- * @version $Id$
- * @package System.Web.UI.WebControls
- * @since 3.0
- */
-abstract class TDataGridColumn extends TApplicationComponent
-{
- private $_id='';
- private $_owner=null;
- private $_viewState=array();
-
- /**
- * @return string the ID of the column.
- */
- public function getID()
- {
- return $this->_id;
- }
-
- /**
- * Sets the ID of the column.
- * By explicitly specifying the column ID, one can access the column
- * by $templateControl->ColumnID.
- * @param string the ID of the column.
- * @throws TInvalidDataValueException if the ID is of bad format
- */
- public function setID($value)
- {
- if(!preg_match(TControl::ID_FORMAT,$value))
- throw new TInvalidDataValueException('datagridcolumn_id_invalid',get_class($this),$value);
- $this->_id=$value;
- }
-
- /**
- * @return string the text to be displayed in the header of this column
- */
- public function getHeaderText()
- {
- return $this->getViewState('HeaderText','');
- }
-
- /**
- * @param string text to be displayed in the header of this column
- */
- public function setHeaderText($value)
- {
- $this->setViewState('HeaderText',$value,'');
- }
-
- /**
- * @return string the url of the image to be displayed in header
- */
- public function getHeaderImageUrl()
- {
- return $this->getViewState('HeaderImageUrl','');
- }
-
- /**
- * @param string the url of the image to be displayed in header
- */
- public function setHeaderImageUrl($value)
- {
- $this->setViewState('HeaderImageUrl',$value,'');
- }
-
- /**
- * @return string the class name for the column header cell renderer. Defaults to empty, meaning not set.
- * @since 3.1.0
- */
- public function getHeaderRenderer()
- {
- return $this->getViewState('HeaderRenderer','');
- }
-
- /**
- * Sets the column header cell renderer class.
- *
- * If not empty, the class will be used to instantiate as a child control in the column header cell.
- * If the class implements {@link IDataRenderer}, the <b>Data</b> property
- * will be set as the {@link getFooterText FooterText}.
- *
- * @param string the renderer class name in namespace format.
- * @since 3.1.0
- */
- public function setHeaderRenderer($value)
- {
- $this->setViewState('HeaderRenderer',$value,'');
- }
-
- /**
- * @param boolean whether to create a style if previously not existing
- * @return TTableItemStyle the style for header
- */
- public function getHeaderStyle($createStyle=true)
- {
- if(($style=$this->getViewState('HeaderStyle',null))===null && $createStyle)
- {
- $style=new TTableItemStyle;
- $this->setViewState('HeaderStyle',$style,null);
- }
- return $style;
- }
-
- /**
- * @return string the text to be displayed in the footer of this column
- */
- public function getFooterText()
- {
- return $this->getViewState('FooterText','');
- }
-
- /**
- * @param string text to be displayed in the footer of this column
- */
- public function setFooterText($value)
- {
- $this->setViewState('FooterText',$value,'');
- }
-
- /**
- * @return string the class name for the column footer cell renderer. Defaults to empty, meaning not set.
- * @since 3.1.0
- */
- public function getFooterRenderer()
- {
- return $this->getViewState('FooterRenderer','');
- }
-
- /**
- * Sets the column footer cell renderer class.
- *
- * If not empty, the class will be used to instantiate as a child control in the column footer cell.
- * If the class implements {@link IDataRenderer}, the <b>Data</b> property
- * will be set as the {@link getFooterText FooterText}.
- *
- * @param string the renderer class name in namespace format.
- * @since 3.1.0
- */
- public function setFooterRenderer($value)
- {
- $this->setViewState('FooterRenderer',$value,'');
- }
-
- /**
- * @param boolean whether to create a style if previously not existing
- * @return TTableItemStyle the style for footer
- */
- public function getFooterStyle($createStyle=true)
- {
- if(($style=$this->getViewState('FooterStyle',null))===null && $createStyle)
- {
- $style=new TTableItemStyle;
- $this->setViewState('FooterStyle',$style,null);
- }
- return $style;
- }
-
- /**
- * @param boolean whether to create a style if previously not existing
- * @return TTableItemStyle the style for item
- */
- public function getItemStyle($createStyle=true)
- {
- if(($style=$this->getViewState('ItemStyle',null))===null && $createStyle)
- {
- $style=new TTableItemStyle;
- $this->setViewState('ItemStyle',$style,null);
- }
- return $style;
- }
-
- /**
- * @return string the name of the field or expression for sorting
- */
- public function getSortExpression()
- {
- return $this->getViewState('SortExpression','');
- }
-
- /**
- * @param string the name of the field or expression for sorting
- */
- public function setSortExpression($value)
- {
- $this->setViewState('SortExpression',$value,'');
- }
-
- /**
- * @return boolean whether cells having the same content should be grouped together. Defaults to false.
- * @since 3.1.1
- */
- public function getEnableCellGrouping()
- {
- return $this->getViewState('EnableCellGrouping',false);
- }
-
- /**
- * @param boolean whether cells having the same content should be grouped together.
- * @since 3.1.1
- */
- public function setEnableCellGrouping($value)
- {
- $this->setViewState('EnableCellGrouping',TPropertyValue::ensureBoolean($value),false);
- }
-
- /**
- * @return boolean whether the column is visible. Defaults to true.
- */
- public function getVisible($checkParents=true)
- {
- return $this->getViewState('Visible',true);
- }
-
- /**
- * @param boolean whether the column is visible
- */
- public function setVisible($value)
- {
- $this->setViewState('Visible',TPropertyValue::ensureBoolean($value),true);
- }
-
- /**
- * Returns a viewstate value.
- *
- * @param string the name of the viewstate value to be returned
- * @param mixed the default value. If $key is not found in viewstate, $defaultValue will be returned
- * @return mixed the viewstate value corresponding to $key
- */
- protected function getViewState($key,$defaultValue=null)
- {
- return isset($this->_viewState[$key])?$this->_viewState[$key]:$defaultValue;
- }
-
- /**
- * Sets a viewstate value.
- *
- * Make sure that the viewstate value must be serializable and unserializable.
- * @param string the name of the viewstate value
- * @param mixed the viewstate value to be set
- * @param mixed default value. If $value===$defaultValue, the item will be cleared from the viewstate.
- */
- protected function setViewState($key,$value,$defaultValue=null)
- {
- if($value===$defaultValue)
- unset($this->_viewState[$key]);
- else
- $this->_viewState[$key]=$value;
- }
-
- /**
- * Loads persistent state values.
- * @param mixed state values
- */
- public function loadState($state)
- {
- $this->_viewState=$state;
- }
-
- /**
- * Saves persistent state values.
- * @return mixed values to be saved
- */
- public function saveState()
- {
- return $this->_viewState;
- }
-
- /**
- * @return TDataGrid datagrid that owns this column
- */
- public function getOwner()
- {
- return $this->_owner;
- }
-
- /**
- * @param TDataGrid datagrid object that owns this column
- */
- public function setOwner(TDataGrid $value)
- {
- $this->_owner=$value;
- }
-
- /**
- * Initializes the column.
- * This method is invoked by {@link TDataGrid} when the column
- * is about to be used to initialize datagrid items.
- * Derived classes may override this method to do additional initialization.
- */
- public function initialize()
- {
- }
-
- /**
- * Fetches the value of the data at the specified field.
- * If the data is an array, the field is used as an array key.
- * If the data is an of {@link TMap}, {@link TList} or their derived class,
- * the field is used as a key value.
- * If the data is a component, the field is used as the name of a property.
- * @param mixed data containing the field of value
- * @param string the data field
- * @return mixed data value at the specified field
- * @throws TInvalidDataValueException if the data or the field is invalid.
- */
- protected function getDataFieldValue($data,$field)
- {
- return TDataFieldAccessor::getDataFieldValue($data,$field);
- }
-
-
- /**
- * Initializes the specified cell to its initial values.
- * The default implementation sets the content of header and footer cells.
- * If sorting is enabled by the grid and sort expression is specified in the column,
- * the header cell will show a link/image button. Otherwise, the header/footer cell
- * will only show static text/image.
- * This method can be overriden to provide customized intialization to column cells.
- * @param TTableCell the cell to be initialized.
- * @param integer the index to the Columns property that the cell resides in.
- * @param string the type of cell (Header,Footer,Item,AlternatingItem,EditItem,SelectedItem)
- */
- public function initializeCell($cell,$columnIndex,$itemType)
- {
- if($itemType===TListItemType::Header)
- $this->initializeHeaderCell($cell,$columnIndex);
- else if($itemType===TListItemType::Footer)
- $this->initializeFooterCell($cell,$columnIndex);
- }
-
- /**
- * Returns a value indicating whether this column allows sorting.
- * The column allows sorting only when {@link getSortExpression SortExpression}
- * is not empty and the datagrid allows sorting.
- * @return boolean whether this column allows sorting
- */
- public function getAllowSorting()
- {
- return $this->getSortExpression()!=='' && (!$this->_owner || $this->_owner->getAllowSorting());
- }
-
- /**
- * Initializes the header cell.
- *
- * This method attempts to use {@link getHeaderRenderer HeaderRenderer} to
- * instantiate the header cell. If that is not available, it will populate
- * the cell with an image or a text string, depending on {@link getHeaderImageUrl HeaderImageUrl}
- * and {@link getHeaderText HeaderText} property values.
- *
- * If the column allows sorting, image or text will be created as
- * a button which issues <b>Sort</b> command upon user click.
- *
- * @param TTableCell the cell to be initialized
- * @param integer the index to the Columns property that the cell resides in.
- */
- protected function initializeHeaderCell($cell,$columnIndex)
- {
- $text=$this->getHeaderText();
-
- if(($classPath=$this->getHeaderRenderer())!=='')
- {
- $control=Prado::createComponent($classPath);
- $cell->getControls()->add($control);
- if($control instanceof IDataRenderer)
- {
- if($control instanceof IItemDataRenderer)
- {
- $item=$cell->getParent();
- $control->setItemIndex($item->getItemIndex());
- $control->setItemType($item->getItemType());
- }
- $control->setData($text);
- }
- }
- else if($this->getAllowSorting())
- {
- $sortExpression=$this->getSortExpression();
- if(($url=$this->getHeaderImageUrl())!=='')
- {
- $button=Prado::createComponent('System.Web.UI.WebControls.TImageButton');
- $button->setImageUrl($url);
- $button->setCommandName(TDataGrid::CMD_SORT);
- $button->setCommandParameter($sortExpression);
- if($text!=='')
- $button->setAlternateText($text);
- $button->setCausesValidation(false);
- $cell->getControls()->add($button);
- }
- else if($text!=='')
- {
- $button=Prado::createComponent('System.Web.UI.WebControls.TLinkButton');
- $button->setText($text);
- $button->setCommandName(TDataGrid::CMD_SORT);
- $button->setCommandParameter($sortExpression);
- $button->setCausesValidation(false);
- $cell->getControls()->add($button);
- }
- else
- $cell->setText('&nbsp;');
- }
- else
- {
- if(($url=$this->getHeaderImageUrl())!=='')
- {
- $image=Prado::createComponent('System.Web.UI.WebControls.TImage');
- $image->setImageUrl($url);
- if($text!=='')
- $image->setAlternateText($text);
- $cell->getControls()->add($image);
- }
- else if($text!=='')
- $cell->setText($text);
- else
- $cell->setText('&nbsp;');
- }
- }
-
- /**
- * Initializes the footer cell.
- *
- * This method attempts to use {@link getFooterRenderer FooterRenderer} to
- * instantiate the footer cell. If that is not available, it will populate
- * the cell with a text string specified by {@link getFooterImageUrl FooterImageUrl}
- *
- * @param TTableCell the cell to be initialized
- * @param integer the index to the Columns property that the cell resides in.
- */
- protected function initializeFooterCell($cell,$columnIndex)
- {
- $text=$this->getFooterText();
- if(($classPath=$this->getFooterRenderer())!=='')
- {
- $control=Prado::createComponent($classPath);
- $cell->getControls()->add($control);
- if($control instanceof IDataRenderer)
- {
- if($control instanceof IItemDataRenderer)
- {
- $item=$cell->getParent();
- $control->setItemIndex($item->getItemIndex());
- $control->setItemType($item->getItemType());
- }
- $control->setData($text);
- }
- }
- else if($text!=='')
- $cell->setText($text);
- else
- $cell->setText('&nbsp;');
- }
-
- /**
- * Formats the text value according to a format string.
- * If the format string is empty, the original value is converted into
- * a string and returned.
- * If the format string starts with '#', the string is treated as a PHP expression
- * within which the token '{0}' is translated with the data value to be formated.
- * Otherwise, the format string and the data value are passed
- * as the first and second parameters in {@link sprintf}.
- * @param string format string
- * @param mixed the data to be formatted
- * @return string the formatted result
- */
- protected function formatDataValue($formatString,$value)
- {
- if($formatString==='')
- return TPropertyValue::ensureString($value);
- else if($formatString[0]==='#')
- {
- $expression=strtr(substr($formatString,1),array('{0}'=>'$value'));
- try
- {
- if(eval("\$result=$expression;")===false)
- throw new Exception('');
- return $result;
- }
- catch(Exception $e)
- {
- throw new TInvalidDataValueException('datagridcolumn_expression_invalid',get_class($this),$expression,$e->getMessage());
- }
- }
- else
- return sprintf($formatString,$value);
- }
-}
-
-
-/**
- * TButtonColumnType class.
- * TButtonColumnType defines the enumerable type for the possible types of buttons
- * that can be used in a {@link TButtonColumn}.
- *
- * The following enumerable values are defined:
- * - LinkButton: link buttons
- * - PushButton: form buttons
- * - ImageButton: image buttons
- *
- * @author Qiang Xue <qiang.xue@gmail.com>
- * @version $Id$
- * @package System.Web.UI.WebControls
- * @since 3.0.4
- */
-class TButtonColumnType extends TEnumerable
-{
- const LinkButton='LinkButton';
- const PushButton='PushButton';
- const ImageButton='ImageButton';
-}
-
+<?php
+/**
+ * TDataGridColumn class file
+ *
+ * @author Qiang Xue <qiang.xue@gmail.com>
+ * @link http://www.pradosoft.com/
+ * @copyright Copyright &copy; 2005-2012 PradoSoft
+ * @license http://www.pradosoft.com/license/
+ * @version $Id$
+ * @package System.Web.UI.WebControls
+ */
+
+Prado::using('System.Util.TDataFieldAccessor');
+Prado::using('System.Web.UI.WebControls.TDataGrid');
+
+/**
+ * TDataGridColumn class
+ *
+ * TDataGridColumn serves as the base class for the different column types of
+ * the {@link TDataGrid} control.
+ * TDataGridColumn defines the properties and methods that are common among
+ * all datagrid column types. In particular, it initializes header and footer
+ * cells according to {@link setHeaderText HeaderText} and {@link getHeaderStyle HeaderStyle}
+ * {@link setFooterText FooterText} and {@link getFooterStyle FooterStyle} properties.
+ * If {@link setHeaderImageUrl HeaderImageUrl} is specified, the image
+ * will be displayed instead in the header cell.
+ * The {@link getItemStyle ItemStyle} is applied to cells that belong to
+ * non-header and -footer datagrid items.
+ *
+ * When the datagrid enables sorting, if the {@link setSortExpression SortExpression}
+ * is not empty, the header cell will display a button (linkbutton or imagebutton)
+ * that will bubble the sort command event to the datagrid.
+ *
+ * Since v3.1.0, TDataGridColumn has introduced two new properties {@link setHeaderRenderer HeaderRenderer}
+ * and {@link setFooterRenderer FooterRenderer} which can be used to specify
+ * the layout of header and footer column cells.
+ * A renderer refers to a control class that is to be instantiated as a control.
+ * For more details, see {@link TRepeater} and {@link TDataList}.
+ *
+ * Since v3.1.1, TDataGridColumn has introduced {@link setEnableCellGrouping EnableCellGrouping}.
+ * If a column has this property set true, consecutive cells having the same content in this
+ * column will be grouped into one cell.
+ * Note, there are some limitations to cell grouping. We determine the cell content according to
+ * the cell's {@link TTableCell::getText Text} property. If the text is empty and the cell has
+ * some child controls, we will pick up the first control who implements {@link IDataRenderer}
+ * and obtain its {@link IDataRenderer::getData Data} property.
+ *
+ * The following datagrid column types are provided by the framework currently,
+ * - {@link TBoundColumn}, associated with a specific field in datasource and displays the corresponding data.
+ * - {@link TEditCommandColumn}, displaying edit/update/cancel command buttons
+ * - {@link TDropDownListColumn}, displaying a dropdown list when the item is in edit state
+ * - {@link TButtonColumn}, displaying generic command buttons that may be bound to specific field in datasource.
+ * - {@link THyperLinkColumn}, displaying a hyperlink that may be bound to specific field in datasource.
+ * - {@link TCheckBoxColumn}, displaying a checkbox that may be bound to specific field in datasource.
+ * - {@link TTemplateColumn}, displaying content based on templates.
+ *
+ * To create your own column class, simply override {@link initializeCell()} method,
+ * which is the major logic for managing the data and presentation of cells in the column.
+ *
+ * @author Qiang Xue <qiang.xue@gmail.com>
+ * @version $Id$
+ * @package System.Web.UI.WebControls
+ * @since 3.0
+ */
+abstract class TDataGridColumn extends TApplicationComponent
+{
+ private $_id='';
+ private $_owner=null;
+ private $_viewState=array();
+
+ /**
+ * @return string the ID of the column.
+ */
+ public function getID()
+ {
+ return $this->_id;
+ }
+
+ /**
+ * Sets the ID of the column.
+ * By explicitly specifying the column ID, one can access the column
+ * by $templateControl->ColumnID.
+ * @param string the ID of the column.
+ * @throws TInvalidDataValueException if the ID is of bad format
+ */
+ public function setID($value)
+ {
+ if(!preg_match(TControl::ID_FORMAT,$value))
+ throw new TInvalidDataValueException('datagridcolumn_id_invalid',get_class($this),$value);
+ $this->_id=$value;
+ }
+
+ /**
+ * @return string the text to be displayed in the header of this column
+ */
+ public function getHeaderText()
+ {
+ return $this->getViewState('HeaderText','');
+ }
+
+ /**
+ * @param string text to be displayed in the header of this column
+ */
+ public function setHeaderText($value)
+ {
+ $this->setViewState('HeaderText',$value,'');
+ }
+
+ /**
+ * @return string the url of the image to be displayed in header
+ */
+ public function getHeaderImageUrl()
+ {
+ return $this->getViewState('HeaderImageUrl','');
+ }
+
+ /**
+ * @param string the url of the image to be displayed in header
+ */
+ public function setHeaderImageUrl($value)
+ {
+ $this->setViewState('HeaderImageUrl',$value,'');
+ }
+
+ /**
+ * @return string the class name for the column header cell renderer. Defaults to empty, meaning not set.
+ * @since 3.1.0
+ */
+ public function getHeaderRenderer()
+ {
+ return $this->getViewState('HeaderRenderer','');
+ }
+
+ /**
+ * Sets the column header cell renderer class.
+ *
+ * If not empty, the class will be used to instantiate as a child control in the column header cell.
+ * If the class implements {@link IDataRenderer}, the <b>Data</b> property
+ * will be set as the {@link getFooterText FooterText}.
+ *
+ * @param string the renderer class name in namespace format.
+ * @since 3.1.0
+ */
+ public function setHeaderRenderer($value)
+ {
+ $this->setViewState('HeaderRenderer',$value,'');
+ }
+
+ /**
+ * @param boolean whether to create a style if previously not existing
+ * @return TTableItemStyle the style for header
+ */
+ public function getHeaderStyle($createStyle=true)
+ {
+ if(($style=$this->getViewState('HeaderStyle',null))===null && $createStyle)
+ {
+ $style=new TTableItemStyle;
+ $this->setViewState('HeaderStyle',$style,null);
+ }
+ return $style;
+ }
+
+ /**
+ * @return string the text to be displayed in the footer of this column
+ */
+ public function getFooterText()
+ {
+ return $this->getViewState('FooterText','');
+ }
+
+ /**
+ * @param string text to be displayed in the footer of this column
+ */
+ public function setFooterText($value)
+ {
+ $this->setViewState('FooterText',$value,'');
+ }
+
+ /**
+ * @return string the class name for the column footer cell renderer. Defaults to empty, meaning not set.
+ * @since 3.1.0
+ */
+ public function getFooterRenderer()
+ {
+ return $this->getViewState('FooterRenderer','');
+ }
+
+ /**
+ * Sets the column footer cell renderer class.
+ *
+ * If not empty, the class will be used to instantiate as a child control in the column footer cell.
+ * If the class implements {@link IDataRenderer}, the <b>Data</b> property
+ * will be set as the {@link getFooterText FooterText}.
+ *
+ * @param string the renderer class name in namespace format.
+ * @since 3.1.0
+ */
+ public function setFooterRenderer($value)
+ {
+ $this->setViewState('FooterRenderer',$value,'');
+ }
+
+ /**
+ * @param boolean whether to create a style if previously not existing
+ * @return TTableItemStyle the style for footer
+ */
+ public function getFooterStyle($createStyle=true)
+ {
+ if(($style=$this->getViewState('FooterStyle',null))===null && $createStyle)
+ {
+ $style=new TTableItemStyle;
+ $this->setViewState('FooterStyle',$style,null);
+ }
+ return $style;
+ }
+
+ /**
+ * @param boolean whether to create a style if previously not existing
+ * @return TTableItemStyle the style for item
+ */
+ public function getItemStyle($createStyle=true)
+ {
+ if(($style=$this->getViewState('ItemStyle',null))===null && $createStyle)
+ {
+ $style=new TTableItemStyle;
+ $this->setViewState('ItemStyle',$style,null);
+ }
+ return $style;
+ }
+
+ /**
+ * @return string the name of the field or expression for sorting
+ */
+ public function getSortExpression()
+ {
+ return $this->getViewState('SortExpression','');
+ }
+
+ /**
+ * @param string the name of the field or expression for sorting
+ */
+ public function setSortExpression($value)
+ {
+ $this->setViewState('SortExpression',$value,'');
+ }
+
+ /**
+ * @return boolean whether cells having the same content should be grouped together. Defaults to false.
+ * @since 3.1.1
+ */
+ public function getEnableCellGrouping()
+ {
+ return $this->getViewState('EnableCellGrouping',false);
+ }
+
+ /**
+ * @param boolean whether cells having the same content should be grouped together.
+ * @since 3.1.1
+ */
+ public function setEnableCellGrouping($value)
+ {
+ $this->setViewState('EnableCellGrouping',TPropertyValue::ensureBoolean($value),false);
+ }
+
+ /**
+ * @return boolean whether the column is visible. Defaults to true.
+ */
+ public function getVisible($checkParents=true)
+ {
+ return $this->getViewState('Visible',true);
+ }
+
+ /**
+ * @param boolean whether the column is visible
+ */
+ public function setVisible($value)
+ {
+ $this->setViewState('Visible',TPropertyValue::ensureBoolean($value),true);
+ }
+
+ /**
+ * Returns a viewstate value.
+ *
+ * @param string the name of the viewstate value to be returned
+ * @param mixed the default value. If $key is not found in viewstate, $defaultValue will be returned
+ * @return mixed the viewstate value corresponding to $key
+ */
+ protected function getViewState($key,$defaultValue=null)
+ {
+ return isset($this->_viewState[$key])?$this->_viewState[$key]:$defaultValue;
+ }
+
+ /**
+ * Sets a viewstate value.
+ *
+ * Make sure that the viewstate value must be serializable and unserializable.
+ * @param string the name of the viewstate value
+ * @param mixed the viewstate value to be set
+ * @param mixed default value. If $value===$defaultValue, the item will be cleared from the viewstate.
+ */
+ protected function setViewState($key,$value,$defaultValue=null)
+ {
+ if($value===$defaultValue)
+ unset($this->_viewState[$key]);
+ else
+ $this->_viewState[$key]=$value;
+ }
+
+ /**
+ * Loads persistent state values.
+ * @param mixed state values
+ */
+ public function loadState($state)
+ {
+ $this->_viewState=$state;
+ }
+
+ /**
+ * Saves persistent state values.
+ * @return mixed values to be saved
+ */
+ public function saveState()
+ {
+ return $this->_viewState;
+ }
+
+ /**
+ * @return TDataGrid datagrid that owns this column
+ */
+ public function getOwner()
+ {
+ return $this->_owner;
+ }
+
+ /**
+ * @param TDataGrid datagrid object that owns this column
+ */
+ public function setOwner(TDataGrid $value)
+ {
+ $this->_owner=$value;
+ }
+
+ /**
+ * Initializes the column.
+ * This method is invoked by {@link TDataGrid} when the column
+ * is about to be used to initialize datagrid items.
+ * Derived classes may override this method to do additional initialization.
+ */
+ public function initialize()
+ {
+ }
+
+ /**
+ * Fetches the value of the data at the specified field.
+ * If the data is an array, the field is used as an array key.
+ * If the data is an of {@link TMap}, {@link TList} or their derived class,
+ * the field is used as a key value.
+ * If the data is a component, the field is used as the name of a property.
+ * @param mixed data containing the field of value
+ * @param string the data field
+ * @return mixed data value at the specified field
+ * @throws TInvalidDataValueException if the data or the field is invalid.
+ */
+ protected function getDataFieldValue($data,$field)
+ {
+ return TDataFieldAccessor::getDataFieldValue($data,$field);
+ }
+
+
+ /**
+ * Initializes the specified cell to its initial values.
+ * The default implementation sets the content of header and footer cells.
+ * If sorting is enabled by the grid and sort expression is specified in the column,
+ * the header cell will show a link/image button. Otherwise, the header/footer cell
+ * will only show static text/image.
+ * This method can be overriden to provide customized intialization to column cells.
+ * @param TTableCell the cell to be initialized.
+ * @param integer the index to the Columns property that the cell resides in.
+ * @param string the type of cell (Header,Footer,Item,AlternatingItem,EditItem,SelectedItem)
+ */
+ public function initializeCell($cell,$columnIndex,$itemType)
+ {
+ if($itemType===TListItemType::Header)
+ $this->initializeHeaderCell($cell,$columnIndex);
+ else if($itemType===TListItemType::Footer)
+ $this->initializeFooterCell($cell,$columnIndex);
+ }
+
+ /**
+ * Returns a value indicating whether this column allows sorting.
+ * The column allows sorting only when {@link getSortExpression SortExpression}
+ * is not empty and the datagrid allows sorting.
+ * @return boolean whether this column allows sorting
+ */
+ public function getAllowSorting()
+ {
+ return $this->getSortExpression()!=='' && (!$this->_owner || $this->_owner->getAllowSorting());
+ }
+
+ /**
+ * Initializes the header cell.
+ *
+ * This method attempts to use {@link getHeaderRenderer HeaderRenderer} to
+ * instantiate the header cell. If that is not available, it will populate
+ * the cell with an image or a text string, depending on {@link getHeaderImageUrl HeaderImageUrl}
+ * and {@link getHeaderText HeaderText} property values.
+ *
+ * If the column allows sorting, image or text will be created as
+ * a button which issues <b>Sort</b> command upon user click.
+ *
+ * @param TTableCell the cell to be initialized
+ * @param integer the index to the Columns property that the cell resides in.
+ */
+ protected function initializeHeaderCell($cell,$columnIndex)
+ {
+ $text=$this->getHeaderText();
+
+ if(($classPath=$this->getHeaderRenderer())!=='')
+ {
+ $control=Prado::createComponent($classPath);
+ $cell->getControls()->add($control);
+ if($control instanceof IDataRenderer)
+ {
+ if($control instanceof IItemDataRenderer)
+ {
+ $item=$cell->getParent();
+ $control->setItemIndex($item->getItemIndex());
+ $control->setItemType($item->getItemType());
+ }
+ $control->setData($text);
+ }
+ }
+ else if($this->getAllowSorting())
+ {
+ $sortExpression=$this->getSortExpression();
+ if(($url=$this->getHeaderImageUrl())!=='')
+ {
+ $button=Prado::createComponent('System.Web.UI.WebControls.TImageButton');
+ $button->setImageUrl($url);
+ $button->setCommandName(TDataGrid::CMD_SORT);
+ $button->setCommandParameter($sortExpression);
+ if($text!=='')
+ $button->setAlternateText($text);
+ $button->setCausesValidation(false);
+ $cell->getControls()->add($button);
+ }
+ else if($text!=='')
+ {
+ $button=Prado::createComponent('System.Web.UI.WebControls.TLinkButton');
+ $button->setText($text);
+ $button->setCommandName(TDataGrid::CMD_SORT);
+ $button->setCommandParameter($sortExpression);
+ $button->setCausesValidation(false);
+ $cell->getControls()->add($button);
+ }
+ else
+ $cell->setText('&nbsp;');
+ }
+ else
+ {
+ if(($url=$this->getHeaderImageUrl())!=='')
+ {
+ $image=Prado::createComponent('System.Web.UI.WebControls.TImage');
+ $image->setImageUrl($url);
+ if($text!=='')
+ $image->setAlternateText($text);
+ $cell->getControls()->add($image);
+ }
+ else if($text!=='')
+ $cell->setText($text);
+ else
+ $cell->setText('&nbsp;');
+ }
+ }
+
+ /**
+ * Initializes the footer cell.
+ *
+ * This method attempts to use {@link getFooterRenderer FooterRenderer} to
+ * instantiate the footer cell. If that is not available, it will populate
+ * the cell with a text string specified by {@link getFooterImageUrl FooterImageUrl}
+ *
+ * @param TTableCell the cell to be initialized
+ * @param integer the index to the Columns property that the cell resides in.
+ */
+ protected function initializeFooterCell($cell,$columnIndex)
+ {
+ $text=$this->getFooterText();
+ if(($classPath=$this->getFooterRenderer())!=='')
+ {
+ $control=Prado::createComponent($classPath);
+ $cell->getControls()->add($control);
+ if($control instanceof IDataRenderer)
+ {
+ if($control instanceof IItemDataRenderer)
+ {
+ $item=$cell->getParent();
+ $control->setItemIndex($item->getItemIndex());
+ $control->setItemType($item->getItemType());
+ }
+ $control->setData($text);
+ }
+ }
+ else if($text!=='')
+ $cell->setText($text);
+ else
+ $cell->setText('&nbsp;');
+ }
+
+ /**
+ * Formats the text value according to a format string.
+ * If the format string is empty, the original value is converted into
+ * a string and returned.
+ * If the format string starts with '#', the string is treated as a PHP expression
+ * within which the token '{0}' is translated with the data value to be formated.
+ * Otherwise, the format string and the data value are passed
+ * as the first and second parameters in {@link sprintf}.
+ * @param string format string
+ * @param mixed the data to be formatted
+ * @return string the formatted result
+ */
+ protected function formatDataValue($formatString,$value)
+ {
+ if($formatString==='')
+ return TPropertyValue::ensureString($value);
+ else if($formatString[0]==='#')
+ {
+ $expression=strtr(substr($formatString,1),array('{0}'=>'$value'));
+ try
+ {
+ if(eval("\$result=$expression;")===false)
+ throw new Exception('');
+ return $result;
+ }
+ catch(Exception $e)
+ {
+ throw new TInvalidDataValueException('datagridcolumn_expression_invalid',get_class($this),$expression,$e->getMessage());
+ }
+ }
+ else
+ return sprintf($formatString,$value);
+ }
+}
+
+
+/**
+ * TButtonColumnType class.
+ * TButtonColumnType defines the enumerable type for the possible types of buttons
+ * that can be used in a {@link TButtonColumn}.
+ *
+ * The following enumerable values are defined:
+ * - LinkButton: link buttons
+ * - PushButton: form buttons
+ * - ImageButton: image buttons
+ *
+ * @author Qiang Xue <qiang.xue@gmail.com>
+ * @version $Id$
+ * @package System.Web.UI.WebControls
+ * @since 3.0.4
+ */
+class TButtonColumnType extends TEnumerable
+{
+ const LinkButton='LinkButton';
+ const PushButton='PushButton';
+ const ImageButton='ImageButton';
+}
+
diff --git a/framework/Web/UI/WebControls/TDataGridItemRenderer.php b/framework/Web/UI/WebControls/TDataGridItemRenderer.php
index 0e30a062..dbbbec11 100644
--- a/framework/Web/UI/WebControls/TDataGridItemRenderer.php
+++ b/framework/Web/UI/WebControls/TDataGridItemRenderer.php
@@ -1,30 +1,30 @@
-<?php
-/**
- * TDataGridItemRenderer class file
- *
- * @author Qiang Xue <qiang.xue@gmail.com>
- * @link http://www.pradosoft.com/
+<?php
+/**
+ * TDataGridItemRenderer class file
+ *
+ * @author Qiang Xue <qiang.xue@gmail.com>
+ * @link http://www.pradosoft.com/
* @copyright Copyright &copy; 2005-2012 PradoSoft
- * @license http://www.pradosoft.com/license/
- * @version $Id$
- * @package System.Web.UI.WebControls
- */
-
-Prado::using('System.Web.UI.WebControls.TDataGrid');
-Prado::using('System.Web.UI.WebControls.TItemDataRenderer');
-
-/**
- * TDataGridItemRenderer class
- *
- * TDataGridItemRenderer can be used as a convenient base class to
- * define an item renderer class specific for {@link TDataGrid}.
- *
- * @author Qiang Xue <qiang.xue@gmail.com>
- * @version $Id$
- * @package System.Web.UI.WebControls
- * @since 3.1.0
- */
-class TDataGridItemRenderer extends TItemDataRenderer
-{
-}
-
+ * @license http://www.pradosoft.com/license/
+ * @version $Id$
+ * @package System.Web.UI.WebControls
+ */
+
+Prado::using('System.Web.UI.WebControls.TDataGrid');
+Prado::using('System.Web.UI.WebControls.TItemDataRenderer');
+
+/**
+ * TDataGridItemRenderer class
+ *
+ * TDataGridItemRenderer can be used as a convenient base class to
+ * define an item renderer class specific for {@link TDataGrid}.
+ *
+ * @author Qiang Xue <qiang.xue@gmail.com>
+ * @version $Id$
+ * @package System.Web.UI.WebControls
+ * @since 3.1.0
+ */
+class TDataGridItemRenderer extends TItemDataRenderer
+{
+}
+
diff --git a/framework/Web/UI/WebControls/TDataGridPagerStyle.php b/framework/Web/UI/WebControls/TDataGridPagerStyle.php
index 12346c06..2464291a 100644
--- a/framework/Web/UI/WebControls/TDataGridPagerStyle.php
+++ b/framework/Web/UI/WebControls/TDataGridPagerStyle.php
@@ -1,255 +1,255 @@
-<?php
-/**
- * TDataGridPagerStyle class file.
- *
- * @author Qiang Xue <qiang.xue@gmail.com>
- * @link http://www.pradosoft.com/
- * @copyright Copyright &copy; 2005-2012 PradoSoft
- * @license http://www.pradosoft.com/license/
- * @version $Id$
- * @package System.Web.UI.WebControls
- */
-
-Prado::using('System.Web.UI.WebControls.TDataGrid');
-
-/**
- * TDataGridPagerStyle class.
- *
- * TDataGridPagerStyle specifies the styles available for a datagrid pager.
- *
- * @author Qiang Xue <qiang.xue@gmail.com>
- * @version $Id$
- * @package System.Web.UI.WebControls
- * @since 3.0
- */
-class TDataGridPagerStyle extends TPanelStyle
-{
- private $_mode=null;
- private $_nextText=null;
- private $_prevText=null;
- private $_firstText=null;
- private $_lastText=null;
- private $_buttonCount=null;
- private $_position=null;
- private $_visible=null;
- private $_buttonType=null;
-
- /**
- * @return TDataGridPagerMode pager mode. Defaults to TDataGridPagerMode::NextPrev.
- */
- public function getMode()
- {
- return $this->_mode===null?TDataGridPagerMode::NextPrev : $this->_mode;
- }
-
- /**
- * @param TDataGridPagerMode pager mode.
- */
- public function setMode($value)
- {
- $this->_mode=TPropertyValue::ensureEnum($value,'TDataGridPagerMode');
- }
-
- /**
- * @return TDataGridPagerButtonType the type of command button. Defaults to TDataGridPagerButtonType::LinkButton.
- */
- public function getButtonType()
- {
- return $this->_buttonType===null?TDataGridPagerButtonType::LinkButton:$this->_buttonType;
- }
-
- /**
- * @param TDataGridPagerButtonType the type of command button
- */
- public function setButtonType($value)
- {
- $this->_buttonType=TPropertyValue::ensureEnum($value,'TDataGridPagerButtonType');
- }
-
- /**
- * @return string text for the next page button. Defaults to '>'.
- */
- public function getNextPageText()
- {
- return $this->_nextText===null?'>':$this->_nextText;
- }
-
- /**
- * @param string text for the next page button.
- */
- public function setNextPageText($value)
- {
- $this->_nextText=$value;
- }
-
- /**
- * @return string text for the previous page button. Defaults to '<'.
- */
- public function getPrevPageText()
- {
- return $this->_prevText===null?'<':$this->_prevText;
- }
-
- /**
- * @param string text for the previous page button.
- */
- public function setPrevPageText($value)
- {
- $this->_prevText=$value;
- }
-
- /**
- * @return string text for the first page button. Defaults to '<<'.
- */
- public function getFirstPageText()
- {
- return $this->_firstText===null?'<<':$this->_firstText;
- }
-
- /**
- * @param string text for the first page button.
- */
- public function setFirstPageText($value)
- {
- $this->_firstText=$value;
- }
-
- /**
- * @return string text for the last page button. Defaults to '>>'.
- */
- public function getLastPageText()
- {
- return $this->_lastText===null?'>>':$this->_lastText;
- }
-
- /**
- * @param string text for the last page button.
- */
- public function setLastPageText($value)
- {
- $this->_lastText=$value;
- }
-
- /**
- * @return integer maximum number of pager buttons to be displayed. Defaults to 10.
- */
- public function getPageButtonCount()
- {
- return $this->_buttonCount===null?10:$this->_buttonCount;
- }
-
- /**
- * @param integer maximum number of pager buttons to be displayed
- * @throws TInvalidDataValueException if the value is less than 1.
- */
- public function setPageButtonCount($value)
- {
- if(($value=TPropertyValue::ensureInteger($value))<1)
- throw new TInvalidDataValueException('datagridpagerstyle_pagebuttoncount_invalid');
- $this->_buttonCount=$value;
- }
-
- /**
- * @return TDataGridPagerPosition where the pager is to be displayed. Defaults to TDataGridPagerPosition::Bottom.
- */
- public function getPosition()
- {
- return $this->_position===null?TDataGridPagerPosition::Bottom:$this->_position;
- }
-
- /**
- * @param TDataGridPagerPosition where the pager is to be displayed.
- */
- public function setPosition($value)
- {
- $this->_position=TPropertyValue::ensureEnum($value,'TDataGridPagerPosition');
- }
-
- /**
- * @return boolean whether the pager is visible. Defaults to true.
- */
- public function getVisible()
- {
- return $this->_visible===null?true:$this->_visible;
- }
-
- /**
- * @param boolean whether the pager is visible.
- */
- public function setVisible($value)
- {
- $this->_visible=TPropertyValue::ensureBoolean($value);
- }
-
- /**
- * Resets the style to the original empty state.
- */
- public function reset()
- {
- parent::reset();
- $this->_visible=null;
- $this->_position=null;
- $this->_buttonCount=null;
- $this->_prevText=null;
- $this->_nextText=null;
- $this->_mode=null;
- $this->_buttonType=null;
- }
-
- /**
- * Copies the fields in a new style to this style.
- * If a style field is set in the new style, the corresponding field
- * in this style will be overwritten.
- * @param TStyle the new style
- */
- public function copyFrom($style)
- {
- parent::copyFrom($style);
- if($style instanceof TDataGridPagerStyle)
- {
- if($style->_visible!==null)
- $this->_visible=$style->_visible;
- if($style->_position!==null)
- $this->_position=$style->_position;
- if($style->_buttonCount!==null)
- $this->_buttonCount=$style->_buttonCount;
- if($style->_prevText!==null)
- $this->_prevText=$style->_prevText;
- if($style->_nextText!==null)
- $this->_nextText=$style->_nextText;
- if($style->_mode!==null)
- $this->_mode=$style->_mode;
- if($style->_buttonType!==null)
- $this->_buttonType=$style->_buttonType;
- }
- }
-
- /**
- * Merges the style with a new one.
- * If a style field is not set in this style, it will be overwritten by
- * the new one.
- * @param TStyle the new style
- */
- public function mergeWith($style)
- {
- parent::mergeWith($style);
- if($style instanceof TDataGridPagerStyle)
- {
- if($this->_visible===null)
- $this->_visible=$style->_visible;
- if($this->_position===null)
- $this->_position=$style->_position;
- if($this->_buttonCount===null)
- $this->_buttonCount=$style->_buttonCount;
- if($this->_prevText===null)
- $this->_prevText=$style->_prevText;
- if($this->_nextText===null)
- $this->_nextText=$style->_nextText;
- if($this->_mode===null)
- $this->_mode=$style->_mode;
- if($this->_buttonType===null)
- $this->_buttonType=$style->_buttonType;
- }
- }
-}
-
+<?php
+/**
+ * TDataGridPagerStyle class file.
+ *
+ * @author Qiang Xue <qiang.xue@gmail.com>
+ * @link http://www.pradosoft.com/
+ * @copyright Copyright &copy; 2005-2012 PradoSoft
+ * @license http://www.pradosoft.com/license/
+ * @version $Id$
+ * @package System.Web.UI.WebControls
+ */
+
+Prado::using('System.Web.UI.WebControls.TDataGrid');
+
+/**
+ * TDataGridPagerStyle class.
+ *
+ * TDataGridPagerStyle specifies the styles available for a datagrid pager.
+ *
+ * @author Qiang Xue <qiang.xue@gmail.com>
+ * @version $Id$
+ * @package System.Web.UI.WebControls
+ * @since 3.0
+ */
+class TDataGridPagerStyle extends TPanelStyle
+{
+ private $_mode=null;
+ private $_nextText=null;
+ private $_prevText=null;
+ private $_firstText=null;
+ private $_lastText=null;
+ private $_buttonCount=null;
+ private $_position=null;
+ private $_visible=null;
+ private $_buttonType=null;
+
+ /**
+ * @return TDataGridPagerMode pager mode. Defaults to TDataGridPagerMode::NextPrev.
+ */
+ public function getMode()
+ {
+ return $this->_mode===null?TDataGridPagerMode::NextPrev : $this->_mode;
+ }
+
+ /**
+ * @param TDataGridPagerMode pager mode.
+ */
+ public function setMode($value)
+ {
+ $this->_mode=TPropertyValue::ensureEnum($value,'TDataGridPagerMode');
+ }
+
+ /**
+ * @return TDataGridPagerButtonType the type of command button. Defaults to TDataGridPagerButtonType::LinkButton.
+ */
+ public function getButtonType()
+ {
+ return $this->_buttonType===null?TDataGridPagerButtonType::LinkButton:$this->_buttonType;
+ }
+
+ /**
+ * @param TDataGridPagerButtonType the type of command button
+ */
+ public function setButtonType($value)
+ {
+ $this->_buttonType=TPropertyValue::ensureEnum($value,'TDataGridPagerButtonType');
+ }
+
+ /**
+ * @return string text for the next page button. Defaults to '>'.
+ */
+ public function getNextPageText()
+ {
+ return $this->_nextText===null?'>':$this->_nextText;
+ }
+
+ /**
+ * @param string text for the next page button.
+ */
+ public function setNextPageText($value)
+ {
+ $this->_nextText=$value;
+ }
+
+ /**
+ * @return string text for the previous page button. Defaults to '<'.
+ */
+ public function getPrevPageText()
+ {
+ return $this->_prevText===null?'<':$this->_prevText;
+ }
+
+ /**
+ * @param string text for the previous page button.
+ */
+ public function setPrevPageText($value)
+ {
+ $this->_prevText=$value;
+ }
+
+ /**
+ * @return string text for the first page button. Defaults to '<<'.
+ */
+ public function getFirstPageText()
+ {
+ return $this->_firstText===null?'<<':$this->_firstText;
+ }
+
+ /**
+ * @param string text for the first page button.
+ */
+ public function setFirstPageText($value)
+ {
+ $this->_firstText=$value;
+ }
+
+ /**
+ * @return string text for the last page button. Defaults to '>>'.
+ */
+ public function getLastPageText()
+ {
+ return $this->_lastText===null?'>>':$this->_lastText;
+ }
+
+ /**
+ * @param string text for the last page button.
+ */
+ public function setLastPageText($value)
+ {
+ $this->_lastText=$value;
+ }
+
+ /**
+ * @return integer maximum number of pager buttons to be displayed. Defaults to 10.
+ */
+ public function getPageButtonCount()
+ {
+ return $this->_buttonCount===null?10:$this->_buttonCount;
+ }
+
+ /**
+ * @param integer maximum number of pager buttons to be displayed
+ * @throws TInvalidDataValueException if the value is less than 1.
+ */
+ public function setPageButtonCount($value)
+ {
+ if(($value=TPropertyValue::ensureInteger($value))<1)
+ throw new TInvalidDataValueException('datagridpagerstyle_pagebuttoncount_invalid');
+ $this->_buttonCount=$value;
+ }
+
+ /**
+ * @return TDataGridPagerPosition where the pager is to be displayed. Defaults to TDataGridPagerPosition::Bottom.
+ */
+ public function getPosition()
+ {
+ return $this->_position===null?TDataGridPagerPosition::Bottom:$this->_position;
+ }
+
+ /**
+ * @param TDataGridPagerPosition where the pager is to be displayed.
+ */
+ public function setPosition($value)
+ {
+ $this->_position=TPropertyValue::ensureEnum($value,'TDataGridPagerPosition');
+ }
+
+ /**
+ * @return boolean whether the pager is visible. Defaults to true.
+ */
+ public function getVisible()
+ {
+ return $this->_visible===null?true:$this->_visible;
+ }
+
+ /**
+ * @param boolean whether the pager is visible.
+ */
+ public function setVisible($value)
+ {
+ $this->_visible=TPropertyValue::ensureBoolean($value);
+ }
+
+ /**
+ * Resets the style to the original empty state.
+ */
+ public function reset()
+ {
+ parent::reset();
+ $this->_visible=null;
+ $this->_position=null;
+ $this->_buttonCount=null;
+ $this->_prevText=null;
+ $this->_nextText=null;
+ $this->_mode=null;
+ $this->_buttonType=null;
+ }
+
+ /**
+ * Copies the fields in a new style to this style.
+ * If a style field is set in the new style, the corresponding field
+ * in this style will be overwritten.
+ * @param TStyle the new style
+ */
+ public function copyFrom($style)
+ {
+ parent::copyFrom($style);
+ if($style instanceof TDataGridPagerStyle)
+ {
+ if($style->_visible!==null)
+ $this->_visible=$style->_visible;
+ if($style->_position!==null)
+ $this->_position=$style->_position;
+ if($style->_buttonCount!==null)
+ $this->_buttonCount=$style->_buttonCount;
+ if($style->_prevText!==null)
+ $this->_prevText=$style->_prevText;
+ if($style->_nextText!==null)
+ $this->_nextText=$style->_nextText;
+ if($style->_mode!==null)
+ $this->_mode=$style->_mode;
+ if($style->_buttonType!==null)
+ $this->_buttonType=$style->_buttonType;
+ }
+ }
+
+ /**
+ * Merges the style with a new one.
+ * If a style field is not set in this style, it will be overwritten by
+ * the new one.
+ * @param TStyle the new style
+ */
+ public function mergeWith($style)
+ {
+ parent::mergeWith($style);
+ if($style instanceof TDataGridPagerStyle)
+ {
+ if($this->_visible===null)
+ $this->_visible=$style->_visible;
+ if($this->_position===null)
+ $this->_position=$style->_position;
+ if($this->_buttonCount===null)
+ $this->_buttonCount=$style->_buttonCount;
+ if($this->_prevText===null)
+ $this->_prevText=$style->_prevText;
+ if($this->_nextText===null)
+ $this->_nextText=$style->_nextText;
+ if($this->_mode===null)
+ $this->_mode=$style->_mode;
+ if($this->_buttonType===null)
+ $this->_buttonType=$style->_buttonType;
+ }
+ }
+}
+
diff --git a/framework/Web/UI/WebControls/TDataList.php b/framework/Web/UI/WebControls/TDataList.php
index 43980c0c..49e9c749 100644
--- a/framework/Web/UI/WebControls/TDataList.php
+++ b/framework/Web/UI/WebControls/TDataList.php
@@ -1,1766 +1,1766 @@
-<?php
-/**
- * TDataList class file
- *
- * @author Qiang Xue <qiang.xue@gmail.com>
- * @link http://www.pradosoft.com/
+<?php
+/**
+ * TDataList class file
+ *
+ * @author Qiang Xue <qiang.xue@gmail.com>
+ * @link http://www.pradosoft.com/
* @copyright Copyright &copy; 2005-2012 PradoSoft
- * @license http://www.pradosoft.com/license/
- * @version $Id$
- * @package System.Web.UI.WebControls
- */
-
-/**
- * Includes TBaseDataList class
- */
-Prado::using('System.Web.UI.WebControls.TBaseDataList');
-/**
- * Includes TRepeatInfo class
- */
-Prado::using('System.Web.UI.WebControls.TRepeatInfo');
-
-/**
- * TDataList class
- *
- * TDataList represents a data bound and updatable list control.
- *
- * Like {@link TRepeater}, TDataList displays its content repeatedly based on
- * the data fetched from {@link setDataSource DataSource}.
- * The repeated contents in TDataList are called items, which are controls and
- * can be accessed through {@link getItems Items}. When {@link dataBind()} is
- * invoked, TDataList creates an item for each row of data and binds the data
- * row to the item. Optionally, a TDataList can have a header, a footer and/or
- * separators between items.
- *
- * TDataList differs from {@link TRepeater} in that it supports tiling the items
- * in different manners and it maintains status of items to handle data update.
- *
- * The layout of the repeated contents are specified by inline templates.
- * TDataList items, header, footer, etc. are being instantiated with the corresponding
- * templates when data is being bound to the repeater.
- *
- * Since v3.1.0, the layout can also be by renderers. A renderer is a control class
- * that can be instantiated as datalist items, header, etc. A renderer can thus be viewed
- * as an external template (in fact, it can also be non-templated controls).
- *
- * A renderer can be any control class.
- * - If the class implements {@link IDataRenderer}, the <b>Data</b>
- * property will be set as the data row during databinding. Many PRADO controls
- * implement this interface, such as {@link TLabel}, {@link TTextBox}, etc.
- * - If the class implements {@link IItemDataRenderer}, the <b>ItemIndex</b> property will be set
- * as the zero-based index of the item in the datalist item collection, and
- * the <b>ItemType</b> property as the item's type (such as TListItemType::Item).
- * {@link TDataListItemRenderer} may be used as the convenient base class which
- * already implements {@link IDataItemRenderer}.
- *
- * The following properties are used to specify different types of template and renderer
- * for a datalist:
- * - {@link setItemTemplate ItemTemplate}, {@link setItemRenderer ItemRenderer}:
- * for each repeated row of data
- * - {@link setAlternatingItemTemplate AlternatingItemTemplate}, {@link setAlternatingItemRenderer AlternatingItemRenderer}:
- * for each alternating row of data. If not set, {@link setItemTemplate ItemTemplate} or {@link setItemRenderer ItemRenderer}
- * will be used instead.
- * - {@link setHeaderTemplate HeaderTemplate}, {@link setHeaderRenderer HeaderRenderer}:
- * for the datalist header.
- * - {@link setFooterTemplate FooterTemplate}, {@link setFooterRenderer FooterRenderer}:
- * for the datalist footer.
- * - {@link setSeparatorTemplate SeparatorTemplate}, {@link setSeparatorRenderer SeparatorRenderer}:
- * for content to be displayed between items.
- * - {@link setEmptyTemplate EmptyTemplate}, {@link setEmptyRenderer EmptyRenderer}:
- * used when data bound to the datalist is empty.
- * - {@link setEditItemTemplate EditItemTemplate}, {@link setEditItemRenderer EditItemRenderer}:
- * for the row being editted.
- * - {@link setSelectedItemTemplate SelectedItemTemplate}, {@link setSelectedItemRenderer SelectedItemRenderer}:
- * for the row being selected.
- *
- * If a content type is defined with both a template and a renderer, the latter takes precedence.
- *
- * When {@link dataBind()} is being called, TDataList undergoes the following lifecycles for each row of data:
- * - create item based on templates or renderers
- * - set the row of data to the item
- * - raise {@link onItemCreated OnItemCreated}:
- * - add the item as a child control
- * - call dataBind() of the item
- * - raise {@link onItemDataBound OnItemDataBound}:
- *
- * TDataList raises an {@link onItemCommand OnItemCommand} whenever a button control
- * within some datalist item raises a <b>OnCommand</b> event. Therefore,
- * you can handle all sorts of <b>OnCommand</b> event in a central place by
- * writing an event handler for {@link onItemCommand OnItemCommand}.
- *
- * An additional event is raised if the <b>OnCommand</b> event has one of the following
- * command names:
- * - edit: user wants to edit an item. <b>OnEditCommand</b> event will be raised.
- * - update: user wants to save the change to an item. <b>OnUpdateCommand</b> event will be raised.
- * - select: user selects an item. <b>OnSelectedIndexChanged</b> event will be raised.
- * - delete: user deletes an item. <b>OnDeleteCommand</b> event will be raised.
- * - cancel: user cancels previously editting action. <b>OnCancelCommand</b> event will be raised.
- *
- * TDataList provides a few properties to support tiling the items.
- * The number of columns used to display the data items is specified via
- * {@link setRepeatColumns RepeatColumns} property, while the {@link setRepeatDirection RepeatDirection}
- * governs the order of the items being rendered.
- * The layout of the data items in the list is specified via {@link setRepeatLayout RepeatLayout},
- * which can take one of the following values:
- * - Table (default): items are organized using HTML table and cells.
- * When using this layout, one can set {@link setCellPadding CellPadding} and
- * {@link setCellSpacing CellSpacing} to adjust the cellpadding and cellpadding
- * of the table, and {@link setCaption Caption} and {@link setCaptionAlign CaptionAlign}
- * to add a table caption with the specified alignment.
- * - Flow: items are organized using HTML spans and breaks.
- * - Raw: TDataList does not generate any HTML tags to do the tiling.
- *
- * Items in TDataList can be in one of the three status: normal browsing,
- * being editted and being selected. To change the status of a particular
- * item, set {@link setSelectedItemIndex SelectedItemIndex} or
- * {@link setEditItemIndex EditItemIndex}. The former will change
- * the indicated item to selected mode, which will cause the item to
- * use {@link setSelectedItemTemplate SelectedItemTemplate} or
- * {@link setSelectedItemRenderer SelectedItemRenderer} for presentation.
- * The latter will change the indicated item to edit mode and to use corresponding
- * template or renderer.
- * Note, if an item is in edit mode, then selecting this item will have no effect.
- *
- * Different styles may be applied to items in different status. The style
- * application is performed in a hierarchical way: Style in higher hierarchy
- * will inherit from styles in lower hierarchy.
- * Starting from the lowest hierarchy, the item styles include
- * - item's own style
- * - {@link getItemStyle ItemStyle}
- * - {@link getAlternatingItemStyle AlternatingItemStyle}
- * - {@link getSelectedItemStyle SelectedItemStyle}
- * - {@link getEditItemStyle EditItemStyle}.
- * Therefore, if background color is set as red in {@link getItemStyle ItemStyle},
- * {@link getEditItemStyle EditItemStyle} will also have red background color
- * unless it is set to a different value explicitly.
- *
- * When a page containing a datalist is post back, the datalist will restore automatically
- * all its contents, including items, header, footer and separators.
- * However, the data row associated with each item will not be recovered and become null.
- * To access the data, use one of the following ways:
- * - Use {@link getDataKeys DataKeys} to obtain the data key associated with
- * the specified datalist item and use the key to fetch the corresponding data
- * from some persistent storage such as DB.
- * - Save the whole dataset in viewstate, which will restore the dataset automatically upon postback.
- * Be aware though, if the size of your dataset is big, your page size will become big. Some
- * complex data may also have serializing problem if saved in viewstate.
- *
- * @author Qiang Xue <qiang.xue@gmail.com>
- * @version $Id$
- * @package System.Web.UI.WebControls
- * @since 3.0
- */
-class TDataList extends TBaseDataList implements INamingContainer, IRepeatInfoUser
-{
- /**
- * Command name that TDataList understands. They are case-insensitive.
- */
- const CMD_SELECT='Select';
- const CMD_EDIT='Edit';
- const CMD_UPDATE='Update';
- const CMD_DELETE='Delete';
- const CMD_CANCEL='Cancel';
-
- /**
- * @var TDataListItemCollection item list
- */
- private $_items=null;
- /**
- * @var Itemplate various item templates
- */
- private $_itemTemplate=null;
- private $_emptyTemplate=null;
- private $_alternatingItemTemplate=null;
- private $_selectedItemTemplate=null;
- private $_editItemTemplate=null;
- private $_headerTemplate=null;
- private $_footerTemplate=null;
- private $_separatorTemplate=null;
- /**
- * @var TControl header item
- */
- private $_header=null;
- /**
- * @var TControl footer item
- */
- private $_footer=null;
-
- /**
- * @return TDataListItemCollection item list
- */
- public function getItems()
- {
- if(!$this->_items)
- $this->_items=new TDataListItemCollection;
- return $this->_items;
- }
-
- /**
- * @return integer number of items
- */
- public function getItemCount()
- {
- return $this->_items?$this->_items->getCount():0;
- }
-
- /**
- * @return string the class name for datalist items. Defaults to empty, meaning not set.
- * @since 3.1.0
- */
- public function getItemRenderer()
- {
- return $this->getViewState('ItemRenderer','');
- }
-
- /**
- * Sets the item renderer class.
- *
- * If not empty, the class will be used to instantiate as datalist items.
- * This property takes precedence over {@link getItemTemplate ItemTemplate}.
- *
- * @param string the renderer class name in namespace format.
- * @see setItemTemplate
- * @since 3.1.0
- */
- public function setItemRenderer($value)
- {
- $this->setViewState('ItemRenderer',$value,'');
- }
-
- /**
- * @return string the class name for alternative datalist items. Defaults to empty, meaning not set.
- * @since 3.1.0
- */
- public function getAlternatingItemRenderer()
- {
- return $this->getViewState('AlternatingItemRenderer','');
- }
-
- /**
- * Sets the alternative item renderer class.
- *
- * If not empty, the class will be used to instantiate as alternative datalist items.
- * This property takes precedence over {@link getAlternatingItemTemplate AlternatingItemTemplate}.
- *
- * @param string the renderer class name in namespace format.
- * @see setAlternatingItemTemplate
- * @since 3.1.0
- */
- public function setAlternatingItemRenderer($value)
- {
- $this->setViewState('AlternatingItemRenderer',$value,'');
- }
-
- /**
- * @return string the class name for the datalist item being editted. Defaults to empty, meaning not set.
- * @since 3.1.0
- */
- public function getEditItemRenderer()
- {
- return $this->getViewState('EditItemRenderer','');
- }
-
- /**
- * Sets the renderer class for the datalist item being editted.
- *
- * If not empty, the class will be used to instantiate as the datalist item.
- * This property takes precedence over {@link getEditItemTemplate EditItemTemplate}.
- *
- * @param string the renderer class name in namespace format.
- * @see setEditItemTemplate
- * @since 3.1.0
- */
- public function setEditItemRenderer($value)
- {
- $this->setViewState('EditItemRenderer',$value,'');
- }
-
- /**
- * @return string the class name for the datalist item being selected. Defaults to empty, meaning not set.
- * @since 3.1.0
- */
- public function getSelectedItemRenderer()
- {
- return $this->getViewState('SelectedItemRenderer','');
- }
-
- /**
- * Sets the renderer class for the datalist item being selected.
- *
- * If not empty, the class will be used to instantiate as the datalist item.
- * This property takes precedence over {@link getSelectedItemTemplate SelectedItemTemplate}.
- *
- * @param string the renderer class name in namespace format.
- * @see setSelectedItemTemplate
- * @since 3.1.0
- */
- public function setSelectedItemRenderer($value)
- {
- $this->setViewState('SelectedItemRenderer',$value,'');
- }
-
- /**
- * @return string the class name for datalist item separators. Defaults to empty, meaning not set.
- * @since 3.1.0
- */
- public function getSeparatorRenderer()
- {
- return $this->getViewState('SeparatorRenderer','');
- }
-
- /**
- * Sets the datalist item separator renderer class.
- *
- * If not empty, the class will be used to instantiate as datalist item separators.
- * This property takes precedence over {@link getSeparatorTemplate SeparatorTemplate}.
- *
- * @param string the renderer class name in namespace format.
- * @see setSeparatorTemplate
- * @since 3.1.0
- */
- public function setSeparatorRenderer($value)
- {
- $this->setViewState('SeparatorRenderer',$value,'');
- }
-
- /**
- * @return string the class name for datalist header item. Defaults to empty, meaning not set.
- * @since 3.1.0
- */
- public function getHeaderRenderer()
- {
- return $this->getViewState('HeaderRenderer','');
- }
-
- /**
- * Sets the datalist header renderer class.
- *
- * If not empty, the class will be used to instantiate as datalist header item.
- * This property takes precedence over {@link getHeaderTemplate HeaderTemplate}.
- *
- * @param string the renderer class name in namespace format.
- * @see setHeaderTemplate
- * @since 3.1.0
- */
- public function setHeaderRenderer($value)
- {
- $this->setViewState('HeaderRenderer',$value,'');
- }
-
- /**
- * @return string the class name for datalist footer item. Defaults to empty, meaning not set.
- * @since 3.1.0
- */
- public function getFooterRenderer()
- {
- return $this->getViewState('FooterRenderer','');
- }
-
- /**
- * Sets the datalist footer renderer class.
- *
- * If not empty, the class will be used to instantiate as datalist footer item.
- * This property takes precedence over {@link getFooterTemplate FooterTemplate}.
- *
- * @param string the renderer class name in namespace format.
- * @see setFooterTemplate
- * @since 3.1.0
- */
- public function setFooterRenderer($value)
- {
- $this->setViewState('FooterRenderer',$value,'');
- }
-
- /**
- * @return string the class name for empty datalist item. Defaults to empty, meaning not set.
- * @since 3.1.0
- */
- public function getEmptyRenderer()
- {
- return $this->getViewState('EmptyRenderer','');
- }
-
- /**
- * Sets the datalist empty renderer class.
- *
- * The empty renderer is created as the child of the datalist
- * if data bound to the datalist is empty.
- * This property takes precedence over {@link getEmptyTemplate EmptyTemplate}.
- *
- * @param string the renderer class name in namespace format.
- * @see setEmptyTemplate
- * @since 3.1.0
- */
- public function setEmptyRenderer($value)
- {
- $this->setViewState('EmptyRenderer',$value,'');
- }
-
- /**
- * @return ITemplate the template for item
- */
- public function getItemTemplate()
- {
- return $this->_itemTemplate;
- }
-
- /**
- * @param ITemplate the template for item
- * @throws TInvalidDataTypeException if the input is not an {@link ITemplate} or not null.
- */
- public function setItemTemplate($value)
- {
- if($value instanceof ITemplate || $value===null)
- $this->_itemTemplate=$value;
- else
- throw new TInvalidDataTypeException('datalist_template_required','ItemTemplate');
- }
-
- /**
- * @return TTableItemStyle the style for item
- */
- public function getItemStyle()
- {
- if(($style=$this->getViewState('ItemStyle',null))===null)
- {
- $style=new TTableItemStyle;
- $this->setViewState('ItemStyle',$style,null);
- }
- return $style;
- }
-
- /**
- * @return ITemplate the template for each alternating item
- */
- public function getAlternatingItemTemplate()
- {
- return $this->_alternatingItemTemplate;
- }
-
- /**
- * @param ITemplate the template for each alternating item
- * @throws TInvalidDataTypeException if the input is not an {@link ITemplate} or not null.
- */
- public function setAlternatingItemTemplate($value)
- {
- if($value instanceof ITemplate || $value===null)
- $this->_alternatingItemTemplate=$value;
- else
- throw new TInvalidDataTypeException('datalist_template_required','AlternatingItemType');
- }
-
- /**
- * @return TTableItemStyle the style for each alternating item
- */
- public function getAlternatingItemStyle()
- {
- if(($style=$this->getViewState('AlternatingItemStyle',null))===null)
- {
- $style=new TTableItemStyle;
- $this->setViewState('AlternatingItemStyle',$style,null);
- }
- return $style;
- }
-
- /**
- * @return ITemplate the selected item template
- */
- public function getSelectedItemTemplate()
- {
- return $this->_selectedItemTemplate;
- }
-
- /**
- * @param ITemplate the selected item template
- * @throws TInvalidDataTypeException if the input is not an {@link ITemplate} or not null.
- */
- public function setSelectedItemTemplate($value)
- {
- if($value instanceof ITemplate || $value===null)
- $this->_selectedItemTemplate=$value;
- else
- throw new TInvalidDataTypeException('datalist_template_required','SelectedItemTemplate');
- }
-
- /**
- * @return TTableItemStyle the style for selected item
- */
- public function getSelectedItemStyle()
- {
- if(($style=$this->getViewState('SelectedItemStyle',null))===null)
- {
- $style=new TTableItemStyle;
- $this->setViewState('SelectedItemStyle',$style,null);
- }
- return $style;
- }
-
- /**
- * @return ITemplate the edit item template
- */
- public function getEditItemTemplate()
- {
- return $this->_editItemTemplate;
- }
-
- /**
- * @param ITemplate the edit item template
- * @throws TInvalidDataTypeException if the input is not an {@link ITemplate} or not null.
- */
- public function setEditItemTemplate($value)
- {
- if($value instanceof ITemplate || $value===null)
- $this->_editItemTemplate=$value;
- else
- throw new TInvalidDataTypeException('datalist_template_required','EditItemTemplate');
- }
-
- /**
- * @return TTableItemStyle the style for edit item
- */
- public function getEditItemStyle()
- {
- if(($style=$this->getViewState('EditItemStyle',null))===null)
- {
- $style=new TTableItemStyle;
- $this->setViewState('EditItemStyle',$style,null);
- }
- return $style;
- }
-
- /**
- * @return ITemplate the header template
- */
- public function getHeaderTemplate()
- {
- return $this->_headerTemplate;
- }
-
- /**
- * @param ITemplate the header template
- * @throws TInvalidDataTypeException if the input is not an {@link ITemplate} or not null.
- */
- public function setHeaderTemplate($value)
- {
- if($value instanceof ITemplate || $value===null)
- $this->_headerTemplate=$value;
- else
- throw new TInvalidDataTypeException('datalist_template_required','HeaderTemplate');
- }
-
- /**
- * @return TTableItemStyle the style for header
- */
- public function getHeaderStyle()
- {
- if(($style=$this->getViewState('HeaderStyle',null))===null)
- {
- $style=new TTableItemStyle;
- $this->setViewState('HeaderStyle',$style,null);
- }
- return $style;
- }
-
- /**
- * @return TControl the header item
- */
- public function getHeader()
- {
- return $this->_header;
- }
-
- /**
- * @return ITemplate the footer template
- */
- public function getFooterTemplate()
- {
- return $this->_footerTemplate;
- }
-
- /**
- * @param ITemplate the footer template
- * @throws TInvalidDataTypeException if the input is not an {@link ITemplate} or not null.
- */
- public function setFooterTemplate($value)
- {
- if($value instanceof ITemplate || $value===null)
- $this->_footerTemplate=$value;
- else
- throw new TInvalidDataTypeException('datalist_template_required','FooterTemplate');
- }
-
- /**
- * @return TTableItemStyle the style for footer
- */
- public function getFooterStyle()
- {
- if(($style=$this->getViewState('FooterStyle',null))===null)
- {
- $style=new TTableItemStyle;
- $this->setViewState('FooterStyle',$style,null);
- }
- return $style;
- }
-
- /**
- * @return TControl the footer item
- */
- public function getFooter()
- {
- return $this->_footer;
- }
-
- /**
- * @return ITemplate the template applied when no data is bound to the datalist
- */
- public function getEmptyTemplate()
- {
- return $this->_emptyTemplate;
- }
-
- /**
- * @param ITemplate the template applied when no data is bound to the datalist
- * @throws TInvalidDataTypeException if the input is not an {@link ITemplate} or not null.
- */
- public function setEmptyTemplate($value)
- {
- if($value instanceof ITemplate || $value===null)
- $this->_emptyTemplate=$value;
- else
- throw new TInvalidDataTypeException('datalist_template_required','EmptyTemplate');
- }
-
- /**
- * @return ITemplate the separator template
- */
- public function getSeparatorTemplate()
- {
- return $this->_separatorTemplate;
- }
-
- /**
- * @param ITemplate the separator template
- * @throws TInvalidDataTypeException if the input is not an {@link ITemplate} or not null.
- */
- public function setSeparatorTemplate($value)
- {
- if($value instanceof ITemplate || $value===null)
- $this->_separatorTemplate=$value;
- else
- throw new TInvalidDataTypeException('datalist_template_required','SeparatorTemplate');
- }
-
- /**
- * @return TTableItemStyle the style for separator
- */
- public function getSeparatorStyle()
- {
- if(($style=$this->getViewState('SeparatorStyle',null))===null)
- {
- $style=new TTableItemStyle;
- $this->setViewState('SeparatorStyle',$style,null);
- }
- return $style;
- }
-
- /**
- * @return integer the zero-based index of the selected item in {@link getItems Items}.
- * A value -1 means no item selected.
- */
- public function getSelectedItemIndex()
- {
- return $this->getViewState('SelectedItemIndex',-1);
- }
-
- /**
- * Selects an item by its index in {@link getItems Items}.
- * Previously selected item will be un-selected.
- * If the item to be selected is already in edit mode, it will remain in edit mode.
- * If the index is less than 0, any existing selection will be cleared up.
- * @param integer the selected item index
- */
- public function setSelectedItemIndex($value)
- {
- if(($value=TPropertyValue::ensureInteger($value))<0)
- $value=-1;
- if(($current=$this->getSelectedItemIndex())!==$value)
- {
- $this->setViewState('SelectedItemIndex',$value,-1);
- $items=$this->getItems();
- $itemCount=$items->getCount();
- if($current>=0 && $current<$itemCount)
- {
- $item=$items->itemAt($current);
- if(($item instanceof IItemDataRenderer) && $item->getItemType()!==TListItemType::EditItem)
- $item->setItemType($current%2?TListItemType::AlternatingItem : TListItemType::Item);
- }
- if($value>=0 && $value<$itemCount)
- {
- $item=$items->itemAt($value);
- if(($item instanceof IItemDataRenderer) && $item->getItemType()!==TListItemType::EditItem)
- $item->setItemType(TListItemType::SelectedItem);
- }
- }
- }
-
- /**
- * @return TControl the selected item, null if no item is selected.
- */
- public function getSelectedItem()
- {
- $index=$this->getSelectedItemIndex();
- $items=$this->getItems();
- if($index>=0 && $index<$items->getCount())
- return $items->itemAt($index);
- else
- return null;
- }
-
- /**
- * @return mixed the key value of the currently selected item
- * @throws TInvalidOperationException if {@link getDataKeyField DataKeyField} is empty.
- */
- public function getSelectedDataKey()
- {
- if($this->getDataKeyField()==='')
- throw new TInvalidOperationException('datalist_datakeyfield_required');
- $index=$this->getSelectedItemIndex();
- $dataKeys=$this->getDataKeys();
- if($index>=0 && $index<$dataKeys->getCount())
- return $dataKeys->itemAt($index);
- else
- return null;
- }
-
- /**
- * @return integer the zero-based index of the edit item in {@link getItems Items}.
- * A value -1 means no item is in edit mode.
- */
- public function getEditItemIndex()
- {
- return $this->getViewState('EditItemIndex',-1);
- }
-
- /**
- * Edits an item by its index in {@link getItems Items}.
- * Previously editting item will change to normal item state.
- * If the index is less than 0, any existing edit item will be cleared up.
- * @param integer the edit item index
- */
- public function setEditItemIndex($value)
- {
- if(($value=TPropertyValue::ensureInteger($value))<0)
- $value=-1;
- if(($current=$this->getEditItemIndex())!==$value)
- {
- $this->setViewState('EditItemIndex',$value,-1);
- $items=$this->getItems();
- $itemCount=$items->getCount();
- if($current>=0 && $current<$itemCount)
- $items->itemAt($current)->setItemType($current%2?TListItemType::AlternatingItem : TListItemType::Item);
- if($value>=0 && $value<$itemCount)
- $items->itemAt($value)->setItemType(TListItemType::EditItem);
- }
- }
-
- /**
- * @return TControl the edit item
- */
- public function getEditItem()
- {
- $index=$this->getEditItemIndex();
- $items=$this->getItems();
- if($index>=0 && $index<$items->getCount())
- return $items->itemAt($index);
- else
- return null;
- }
-
- /**
- * @return boolean whether the header should be shown. Defaults to true.
- */
- public function getShowHeader()
- {
- return $this->getViewState('ShowHeader',true);
- }
-
- /**
- * @param boolean whether to show header
- */
- public function setShowHeader($value)
- {
- $this->setViewState('ShowHeader',TPropertyValue::ensureBoolean($value),true);
- }
-
- /**
- * @return boolean whether the footer should be shown. Defaults to true.
- */
- public function getShowFooter()
- {
- return $this->getViewState('ShowFooter',true);
- }
-
- /**
- * @param boolean whether to show footer
- */
- public function setShowFooter($value)
- {
- $this->setViewState('ShowFooter',TPropertyValue::ensureBoolean($value),true);
- }
-
- /**
- * @return TRepeatInfo repeat information (primarily used by control developers)
- */
- protected function getRepeatInfo()
- {
- if(($repeatInfo=$this->getViewState('RepeatInfo',null))===null)
- {
- $repeatInfo=new TRepeatInfo;
- $this->setViewState('RepeatInfo',$repeatInfo,null);
- }
- return $repeatInfo;
- }
-
- /**
- * @return string caption of the table layout
- */
- public function getCaption()
- {
- return $this->getRepeatInfo()->getCaption();
- }
-
- /**
- * @param string caption of the table layout
- */
- public function setCaption($value)
- {
- $this->getRepeatInfo()->setCaption($value);
- }
-
- /**
- * @return TTableCaptionAlign alignment of the caption of the table layout. Defaults to TTableCaptionAlign::NotSet.
- */
- public function getCaptionAlign()
- {
- return $this->getRepeatInfo()->getCaptionAlign();
- }
-
- /**
- * @return TTableCaptionAlign alignment of the caption of the table layout.
- */
- public function setCaptionAlign($value)
- {
- $this->getRepeatInfo()->setCaptionAlign($value);
- }
-
- /**
- * @return integer the number of columns that the list should be displayed with. Defaults to 0 meaning not set.
- */
- public function getRepeatColumns()
- {
- return $this->getRepeatInfo()->getRepeatColumns();
- }
-
- /**
- * @param integer the number of columns that the list should be displayed with.
- */
- public function setRepeatColumns($value)
- {
- $this->getRepeatInfo()->setRepeatColumns($value);
- }
-
- /**
- * @return TRepeatDirection the direction of traversing the list, defaults to TRepeatDirection::Vertical
- */
- public function getRepeatDirection()
- {
- return $this->getRepeatInfo()->getRepeatDirection();
- }
-
- /**
- * @param TRepeatDirection the direction of traversing the list
- */
- public function setRepeatDirection($value)
- {
- $this->getRepeatInfo()->setRepeatDirection($value);
- }
-
- /**
- * @return TRepeatLayout how the list should be displayed, using table or using line breaks. Defaults to TRepeatLayout::Table.
- */
- public function getRepeatLayout()
- {
- return $this->getRepeatInfo()->getRepeatLayout();
- }
-
- /**
- * @param TRepeatLayout how the list should be displayed, using table or using line breaks
- */
- public function setRepeatLayout($value)
- {
- $this->getRepeatInfo()->setRepeatLayout($value);
- }
-
- /**
- * This method overrides parent's implementation to handle
- * {@link onItemCommand OnItemCommand} event which is bubbled from
- * datalist items and their child controls.
- * If the event parameter is {@link TDataListCommandEventParameter} and
- * the command name is a recognized one, which includes 'select', 'edit',
- * 'delete', 'update', and 'cancel' (case-insensitive), then a
- * corresponding command event is also raised (such as {@link onEditCommand OnEditCommand}).
- * This method should only be used by control developers.
- * @param TControl the sender of the event
- * @param TEventParameter event parameter
- * @return boolean whether the event bubbling should stop here.
- */
- public function bubbleEvent($sender,$param)
- {
- if($param instanceof TDataListCommandEventParameter)
- {
- $this->onItemCommand($param);
- $command=$param->getCommandName();
- if(strcasecmp($command,self::CMD_SELECT)===0)
- {
- if(($item=$param->getItem()) instanceof IItemDataRenderer)
- $this->setSelectedItemIndex($item->getItemIndex());
- $this->onSelectedIndexChanged($param);
- return true;
- }
- else if(strcasecmp($command,self::CMD_EDIT)===0)
- {
- $this->onEditCommand($param);
- return true;
- }
- else if(strcasecmp($command,self::CMD_DELETE)===0)
- {
- $this->onDeleteCommand($param);
- return true;
- }
- else if(strcasecmp($command,self::CMD_UPDATE)===0)
- {
- $this->onUpdateCommand($param);
- return true;
- }
- else if(strcasecmp($command,self::CMD_CANCEL)===0)
- {
- $this->onCancelCommand($param);
- return true;
- }
- }
- return false;
- }
-
-
- /**
- * Raises <b>OnItemCreated</b> event.
- * This method is invoked after a data list item is created and instantiated with
- * template, but before added to the page hierarchy.
- * The datalist item control responsible for the event
- * can be determined from the event parameter.
- * If you override this method, be sure to call parent's implementation
- * so that event handlers have chance to respond to the event.
- * @param TDataListItemEventParameter event parameter
- */
- public function onItemCreated($param)
- {
- $this->raiseEvent('OnItemCreated',$this,$param);
- }
-
- /**
- * Raises <b>OnItemDataBound</b> event.
- * This method is invoked right after an item is data bound.
- * The datalist item control responsible for the event
- * can be determined from the event parameter.
- * If you override this method, be sure to call parent's implementation
- * so that event handlers have chance to respond to the event.
- * @param TDataListItemEventParameter event parameter
- */
- public function onItemDataBound($param)
- {
- $this->raiseEvent('OnItemDataBound',$this,$param);
- }
-
- /**
- * Raises <b>OnItemCommand</b> event.
- * This method is invoked when a child control of the data list
- * raises an <b>OnCommand</b> event.
- * @param TDataListCommandEventParameter event parameter
- */
- public function onItemCommand($param)
- {
- $this->raiseEvent('OnItemCommand',$this,$param);
- }
-
- /**
- * Raises <b>OnEditCommand</b> event.
- * This method is invoked when a child control of the data list
- * raises an <b>OnCommand</b> event and the command name is 'edit' (case-insensitive).
- * @param TDataListCommandEventParameter event parameter
- */
- public function onEditCommand($param)
- {
- $this->raiseEvent('OnEditCommand',$this,$param);
- }
-
- /**
- * Raises <b>OnDeleteCommand</b> event.
- * This method is invoked when a child control of the data list
- * raises an <b>OnCommand</b> event and the command name is 'delete' (case-insensitive).
- * @param TDataListCommandEventParameter event parameter
- */
- public function onDeleteCommand($param)
- {
- $this->raiseEvent('OnDeleteCommand',$this,$param);
- }
-
- /**
- * Raises <b>OnUpdateCommand</b> event.
- * This method is invoked when a child control of the data list
- * raises an <b>OnCommand</b> event and the command name is 'update' (case-insensitive).
- * @param TDataListCommandEventParameter event parameter
- */
- public function onUpdateCommand($param)
- {
- $this->raiseEvent('OnUpdateCommand',$this,$param);
- }
-
- /**
- * Raises <b>OnCancelCommand</b> event.
- * This method is invoked when a child control of the data list
- * raises an <b>OnCommand</b> event and the command name is 'cancel' (case-insensitive).
- * @param TDataListCommandEventParameter event parameter
- */
- public function onCancelCommand($param)
- {
- $this->raiseEvent('OnCancelCommand',$this,$param);
- }
-
- /**
- * Returns a value indicating whether this control contains header item.
- * This method is required by {@link IRepeatInfoUser} interface.
- * @return boolean whether the datalist has header
- */
- public function getHasHeader()
- {
- return ($this->getShowHeader() && ($this->_headerTemplate!==null || $this->getHeaderRenderer()!==''));
- }
-
- /**
- * Returns a value indicating whether this control contains footer item.
- * This method is required by {@link IRepeatInfoUser} interface.
- * @return boolean whether the datalist has footer
- */
- public function getHasFooter()
- {
- return ($this->getShowFooter() && ($this->_footerTemplate!==null || $this->getFooterRenderer()!==''));
- }
-
- /**
- * Returns a value indicating whether this control contains separator items.
- * This method is required by {@link IRepeatInfoUser} interface.
- * @return boolean always false.
- */
- public function getHasSeparators()
- {
- return $this->_separatorTemplate!==null || $this->getSeparatorRenderer()!=='';
- }
-
- /**
- * Returns a style used for rendering items.
- * This method is required by {@link IRepeatInfoUser} interface.
- * @param string item type (Header,Footer,Item,AlternatingItem,SelectedItem,EditItem,Separator,Pager)
- * @param integer index of the item being rendered
- * @return TStyle item style
- */
- public function generateItemStyle($itemType,$index)
- {
- if(($item=$this->getItem($itemType,$index))!==null && ($item instanceof IStyleable) && $item->getHasStyle())
- {
- $style=$item->getStyle();
- $item->clearStyle();
- return $style;
- }
- else
- return null;
- }
-
- /**
- * Renders an item in the list.
- * This method is required by {@link IRepeatInfoUser} interface.
- * @param THtmlWriter writer for rendering purpose
- * @param TRepeatInfo repeat information
- * @param string item type (Header,Footer,Item,AlternatingItem,SelectedItem,EditItem,Separator,Pager)
- * @param integer zero-based index of the item in the item list
- */
- public function renderItem($writer,$repeatInfo,$itemType,$index)
- {
- $item=$this->getItem($itemType,$index);
- if($repeatInfo->getRepeatLayout()===TRepeatLayout::Raw && get_class($item)==='TDataListItem')
- $item->setTagName('div');
- $item->renderControl($writer);
- }
-
- /**
- * @param TListItemType item type
- * @param integer item index
- * @return TControl data list item with the specified item type and index
- */
- private function getItem($itemType,$index)
- {
- switch($itemType)
- {
- case TListItemType::Item:
- case TListItemType::AlternatingItem:
- case TListItemType::SelectedItem:
- case TListItemType::EditItem:
- return $this->getItems()->itemAt($index);
- case TListItemType::Header:
- return $this->getControls()->itemAt(0);
- case TListItemType::Footer:
- return $this->getControls()->itemAt($this->getControls()->getCount()-1);
- case TListItemType::Separator:
- $i=$index+$index+1;
- if($this->_headerTemplate!==null || $this->getHeaderRenderer()!=='')
- $i++;
- return $this->getControls()->itemAt($i);
- }
- return null;
- }
-
- /**
- * Creates a datalist item.
- * This method invokes {@link createItem} to create a new datalist item.
- * @param integer zero-based item index.
- * @param TListItemType item type
- * @return TControl the created item, null if item is not created
- */
- private function createItemInternal($itemIndex,$itemType)
- {
- if(($item=$this->createItem($itemIndex,$itemType))!==null)
- {
- $param=new TDataListItemEventParameter($item);
- $this->onItemCreated($param);
- $this->getControls()->add($item);
- return $item;
- }
- else
- return null;
- }
-
- /**
- * Creates a datalist item and performs databinding.
- * This method invokes {@link createItem} to create a new datalist item.
- * @param integer zero-based item index.
- * @param TListItemType item type
- * @param mixed data to be associated with the item
- * @return TControl the created item, null if item is not created
- */
- private function createItemWithDataInternal($itemIndex,$itemType,$dataItem)
- {
- if(($item=$this->createItem($itemIndex,$itemType))!==null)
- {
- $param=new TDataListItemEventParameter($item);
- if($item instanceof IDataRenderer)
- $item->setData($dataItem);
- $this->onItemCreated($param);
- $this->getControls()->add($item);
- $item->dataBind();
- $this->onItemDataBound($param);
- return $item;
- }
- else
- return null;
- }
-
- private function getAlternatingItemDisplay()
- {
- if(($classPath=$this->getAlternatingItemRenderer())==='' && $this->_alternatingItemTemplate===null)
- return array($this->getItemRenderer(),$this->_itemTemplate);
- else
- return array($classPath,$this->_alternatingItemTemplate);
- }
-
- private function getSelectedItemDisplay($itemIndex)
- {
- if(($classPath=$this->getSelectedItemRenderer())==='' && $this->_selectedItemTemplate===null)
- {
- if($itemIndex%2===0)
- return array($this->getItemRenderer(),$this->_itemTemplate);
- else
- return $this->getAlternatingItemDisplay();
- }
- else
- return array($classPath,$this->_selectedItemTemplate);
- }
-
- private function getEditItemDisplay($itemIndex)
- {
- if(($classPath=$this->getEditItemRenderer())==='' && $this->_editItemTemplate===null)
- return $this->getSelectedItemDisplay($itemIndex);
- else
- return array($classPath,$this->_editItemTemplate);
- }
-
- /**
- * Creates a datalist item instance based on the item type and index.
- * @param integer zero-based item index
- * @param TListItemType item type
- * @return TControl created datalist item
- */
- protected function createItem($itemIndex,$itemType)
- {
- $template=null;
- $classPath=null;
- switch($itemType)
- {
- case TListItemType::Item :
- $classPath=$this->getItemRenderer();
- $template=$this->_itemTemplate;
- break;
- case TListItemType::AlternatingItem :
- list($classPath,$template)=$this->getAlternatingItemDisplay();
- break;
- case TListItemType::SelectedItem:
- list($classPath,$template)=$this->getSelectedItemDisplay($itemIndex);
- break;
- case TListItemType::EditItem:
- list($classPath,$template)=$this->getEditItemDisplay($itemIndex);
- break;
- case TListItemType::Header :
- $classPath=$this->getHeaderRenderer();
- $template=$this->_headerTemplate;
- break;
- case TListItemType::Footer :
- $classPath=$this->getFooterRenderer();
- $template=$this->_footerTemplate;
- break;
- case TListItemType::Separator :
- $classPath=$this->getSeparatorRenderer();
- $template=$this->_separatorTemplate;
- break;
- default:
- throw new TInvalidDataValueException('datalist_itemtype_unknown',$itemType);
- }
- if($classPath!=='')
- {
- $item=Prado::createComponent($classPath);
- if($item instanceof IItemDataRenderer)
- {
- $item->setItemIndex($itemIndex);
- $item->setItemType($itemType);
- }
- }
- else if($template!==null)
- {
- $item=new TDataListItem;
- $item->setItemIndex($itemIndex);
- $item->setItemType($itemType);
- $template->instantiateIn($item);
- }
- else
- $item=null;
-
- return $item;
- }
-
- /**
- * Creates empty datalist content.
- */
- protected function createEmptyContent()
- {
- if(($classPath=$this->getEmptyRenderer())!=='')
- $this->getControls()->add(Prado::createComponent($classPath));
- else if($this->_emptyTemplate!==null)
- $this->_emptyTemplate->instantiateIn($this);
- }
-
- /**
- * Applies styles to items, header, footer and separators.
- * Item styles are applied in a hierarchical way. Style in higher hierarchy
- * will inherit from styles in lower hierarchy.
- * Starting from the lowest hierarchy, the item styles include
- * item's own style, {@link getItemStyle ItemStyle}, {@link getAlternatingItemStyle AlternatingItemStyle},
- * {@link getSelectedItemStyle SelectedItemStyle}, and {@link getEditItemStyle EditItemStyle}.
- * Therefore, if background color is set as red in {@link getItemStyle ItemStyle},
- * {@link getEditItemStyle EditItemStyle} will also have red background color
- * unless it is set to a different value explicitly.
- */
- protected function applyItemStyles()
- {
- $itemStyle=$this->getViewState('ItemStyle',null);
-
- $alternatingItemStyle=$this->getViewState('AlternatingItemStyle',null);
- if($itemStyle!==null)
- {
- if($alternatingItemStyle===null)
- $alternatingItemStyle=$itemStyle;
- else
- $alternatingItemStyle->mergeWith($itemStyle);
- }
-
- $selectedItemStyle=$this->getViewState('SelectedItemStyle',null);
-
- $editItemStyle=$this->getViewState('EditItemStyle',null);
- if($selectedItemStyle!==null)
- {
- if($editItemStyle===null)
- $editItemStyle=$selectedItemStyle;
- else
- $editItemStyle->mergeWith($selectedItemStyle);
- }
-
- // apply header style if any
- if($this->_header!==null && $this->_header instanceof IStyleable)
- {
- if($headerStyle=$this->getViewState('HeaderStyle',null))
- $this->_header->getStyle()->mergeWith($headerStyle);
- }
-
- // apply footer style if any
- if($this->_footer!==null && $this->_footer instanceof IStyleable)
- {
- if($footerStyle=$this->getViewState('FooterStyle',null))
- $this->_footer->getStyle()->mergeWith($footerStyle);
- }
-
- $selectedIndex=$this->getSelectedItemIndex();
- $editIndex=$this->getEditItemIndex();
-
- // apply item styles if any
- foreach($this->getItems() as $index=>$item)
- {
- if($index===$editIndex)
- $style=$editItemStyle;
- else if($index===$selectedIndex)
- $style=$selectedItemStyle;
- else if($index%2===0)
- $style=$itemStyle;
- else
- $style=$alternatingItemStyle;
- if($style && $item instanceof IStyleable)
- $item->getStyle()->mergeWith($style);
- }
-
- // apply separator style if any
- if(($separatorStyle=$this->getViewState('SeparatorStyle',null))!==null && $this->getHasSeparators())
- {
- $controls=$this->getControls();
- $count=$controls->getCount();
- for($i=$this->_header?2:1;$i<$count;$i+=2)
- {
- if(($separator=$controls->itemAt($i)) instanceof IStyleable)
- $separator->getStyle()->mergeWith($separatorStyle);
- }
- }
- }
-
- /**
- * Saves item count in viewstate.
- * This method is invoked right before control state is to be saved.
- */
- public function saveState()
- {
- parent::saveState();
- if($this->_items)
- $this->setViewState('ItemCount',$this->_items->getCount(),0);
- else
- $this->clearViewState('ItemCount');
- }
-
- /**
- * Loads item count information from viewstate.
- * This method is invoked right after control state is loaded.
- */
- public function loadState()
- {
- parent::loadState();
- if(!$this->getIsDataBound())
- $this->restoreItemsFromViewState();
- $this->clearViewState('ItemCount');
- }
-
- /**
- * Clears up all items in the data list.
- */
- public function reset()
- {
- $this->getControls()->clear();
- $this->getItems()->clear();
- $this->_header=null;
- $this->_footer=null;
- }
-
- /**
- * Creates data list items based on viewstate information.
- */
- protected function restoreItemsFromViewState()
- {
- $this->reset();
- if(($itemCount=$this->getViewState('ItemCount',0))>0)
- {
- $items=$this->getItems();
- $selectedIndex=$this->getSelectedItemIndex();
- $editIndex=$this->getEditItemIndex();
- $hasSeparator=$this->_separatorTemplate!==null || $this->getSeparatorRenderer()!=='';
- $this->_header=$this->createItemInternal(-1,TListItemType::Header);
- for($i=0;$i<$itemCount;++$i)
- {
- if($hasSeparator && $i>0)
- $this->createItemInternal($i-1,TListItemType::Separator);
- if($i===$editIndex)
- $itemType=TListItemType::EditItem;
- else if($i===$selectedIndex)
- $itemType=TListItemType::SelectedItem;
- else
- $itemType=$i%2?TListItemType::AlternatingItem : TListItemType::Item;
- $items->add($this->createItemInternal($i,$itemType));
- }
- $this->_footer=$this->createItemInternal(-1,TListItemType::Footer);
- }
- else
- $this->createEmptyContent();
- $this->clearChildState();
- }
-
- /**
- * Performs databinding to populate data list items from data source.
- * This method is invoked by dataBind().
- * You may override this function to provide your own way of data population.
- * @param Traversable the data
- */
- protected function performDataBinding($data)
- {
- $this->reset();
- $keys=$this->getDataKeys();
- $keys->clear();
- $keyField=$this->getDataKeyField();
- $itemIndex=0;
- $items=$this->getItems();
- $hasSeparator=$this->_separatorTemplate!==null || $this->getSeparatorRenderer()!=='';
- $selectedIndex=$this->getSelectedItemIndex();
- $editIndex=$this->getEditItemIndex();
- foreach($data as $key=>$dataItem)
- {
- if($keyField!=='')
- $keys->add($this->getDataFieldValue($dataItem,$keyField));
- else
- $keys->add($key);
- if($itemIndex===0)
- $this->_header=$this->createItemWithDataInternal(-1,TListItemType::Header,null);
- if($hasSeparator && $itemIndex>0)
- $this->createItemWithDataInternal($itemIndex-1,TListItemType::Separator,null);
- if($itemIndex===$editIndex)
- $itemType=TListItemType::EditItem;
- else if($itemIndex===$selectedIndex)
- $itemType=TListItemType::SelectedItem;
- else
- $itemType=$itemIndex%2?TListItemType::AlternatingItem : TListItemType::Item;
- $items->add($this->createItemWithDataInternal($itemIndex,$itemType,$dataItem));
- $itemIndex++;
- }
- if($itemIndex>0)
- $this->_footer=$this->createItemWithDataInternal(-1,TListItemType::Footer,null);
- else
- {
- $this->createEmptyContent();
- $this->dataBindChildren();
- }
- $this->setViewState('ItemCount',$itemIndex,0);
- }
-
- /**
- * Renders the data list control.
- * This method overrides the parent implementation.
- * @param THtmlWriter writer for rendering purpose.
- */
- public function render($writer)
- {
- if($this->getHasControls())
- {
- if($this->getItemCount()>0)
- {
- $this->applyItemStyles();
- $repeatInfo=$this->getRepeatInfo();
- $repeatInfo->renderRepeater($writer,$this);
- }
- else if($this->_emptyTemplate!==null || $this->getEmptyRenderer()!=='')
- parent::render($writer);
- }
- }
-}
-
-
-/**
- * TDataListItemEventParameter class
- *
- * TDataListItemEventParameter encapsulates the parameter data for
- * {@link TDataList::onItemCreated ItemCreated} event of {@link TDataList} controls.
- * The {@link getItem Item} property indicates the DataList item related with the event.
- *
- * @author Qiang Xue <qiang.xue@gmail.com>
- * @version $Id$
- * @package System.Web.UI.WebControls
- * @since 3.0
- */
-class TDataListItemEventParameter extends TEventParameter
-{
- /**
- * The datalist item control responsible for the event.
- * @var TControl
- */
- private $_item=null;
-
- /**
- * Constructor.
- * @param TControl DataList item related with the corresponding event
- */
- public function __construct($item)
- {
- $this->_item=$item;
- }
-
- /**
- * @return TControl datalist item related with the corresponding event
- */
- public function getItem()
- {
- return $this->_item;
- }
-}
-
-/**
- * TDataListCommandEventParameter class
- *
- * TDataListCommandEventParameter encapsulates the parameter data for
- * {@link TDataList::onItemCommand ItemCommand} event of {@link TDataList} controls.
- *
- * The {@link getItem Item} property indicates the DataList item related with the event.
- * The {@link getCommandSource CommandSource} refers to the control that originally
- * raises the Command event.
- *
- * @author Qiang Xue <qiang.xue@gmail.com>
- * @version $Id$
- * @package System.Web.UI.WebControls
- * @since 3.0
- */
-class TDataListCommandEventParameter extends TCommandEventParameter
-{
- /**
- * @var TControl the datalist item control responsible for the event.
- */
- private $_item=null;
- /**
- * @var TControl the control originally raises the <b>OnCommand</b> event.
- */
- private $_source=null;
-
- /**
- * Constructor.
- * @param TControl datalist item responsible for the event
- * @param TControl original event sender
- * @param TCommandEventParameter original event parameter
- */
- public function __construct($item,$source,TCommandEventParameter $param)
- {
- $this->_item=$item;
- $this->_source=$source;
- parent::__construct($param->getCommandName(),$param->getCommandParameter());
- }
-
- /**
- * @return TControl the datalist item control responsible for the event.
- */
- public function getItem()
- {
- return $this->_item;
- }
-
- /**
- * @return TControl the control originally raises the <b>OnCommand</b> event.
- */
- public function getCommandSource()
- {
- return $this->_source;
- }
-}
-
-/**
- * TDataListItem class
- *
- * A TDataListItem control represents an item in the {@link TDataList} control,
- * such as heading section, footer section, or a data item.
- * The index and data value of the item can be accessed via {@link getItemIndex ItemIndex}>
- * and {@link getDataItem DataItem} properties, respectively. The type of the item
- * is given by {@link getItemType ItemType} property.
- *
- * @author Qiang Xue <qiang.xue@gmail.com>
- * @version $Id$
- * @package System.Web.UI.WebControls
- * @since 3.0
- */
-class TDataListItem extends TWebControl implements INamingContainer, IItemDataRenderer
-{
- /**
- * index of the data item in the Items collection of DataList
- */
- private $_itemIndex;
- /**
- * type of the TDataListItem
- * @var TListItemType
- */
- private $_itemType;
- /**
- * value of the data associated with this item
- * @var mixed
- */
- private $_data;
-
- private $_tagName='span';
-
- /**
- * Returns the tag name used for this control.
- * @return string tag name of the control to be rendered
- */
- protected function getTagName()
- {
- return $this->_tagName;
- }
-
- /**
- * @param string tag name of the control to be rendered
- */
- public function setTagName($value)
- {
- $this->_tagName=$value;
- }
-
- /**
- * Creates a style object for the control.
- * This method creates a {@link TTableItemStyle} to be used by a datalist item.
- * @return TStyle control style to be used
- */
- protected function createStyle()
- {
- return new TTableItemStyle;
- }
-
- /**
- * @return TListItemType item type
- */
- public function getItemType()
- {
- return $this->_itemType;
- }
-
- /**
- * @param TListItemType item type.
- */
- public function setItemType($value)
- {
- $this->_itemType=TPropertyValue::ensureEnum($value,'TListItemType');
- }
-
- /**
- * @return integer zero-based index of the item in the item collection of datalist
- */
- public function getItemIndex()
- {
- return $this->_itemIndex;
- }
-
- /**
- * Sets the zero-based index for the item.
- * If the item is not in the item collection (e.g. it is a header item), -1 should be used.
- * @param integer zero-based index of the item.
- */
- public function setItemIndex($value)
- {
- $this->_itemIndex=TPropertyValue::ensureInteger($value);
- }
-
- /**
- * @return mixed data associated with the item
- * @since 3.1.0
- */
- public function getData()
- {
- return $this->_data;
- }
-
- /**
- * @param mixed data to be associated with the item
- * @since 3.1.0
- */
- public function setData($value)
- {
- $this->_data=$value;
- }
-
- /**
- * This property is deprecated since v3.1.0.
- * @return mixed data associated with the item
- * @deprecated deprecated since v3.1.0. Use {@link getData} instead.
- */
- public function getDataItem()
- {
- return $this->getData();
- }
-
- /**
- * This property is deprecated since v3.1.0.
- * @param mixed data to be associated with the item
- * @deprecated deprecated since version 3.1.0. Use {@link setData} instead.
- */
- public function setDataItem($value)
- {
- return $this->setData($value);
- }
-
- /**
- * This method overrides parent's implementation by wrapping event parameter
- * for <b>OnCommand</b> event with item information.
- * @param TControl the sender of the event
- * @param TEventParameter event parameter
- * @return boolean whether the event bubbling should stop here.
- */
- public function bubbleEvent($sender,$param)
- {
- if($param instanceof TCommandEventParameter)
- {
- $this->raiseBubbleEvent($this,new TDataListCommandEventParameter($this,$sender,$param));
- return true;
- }
- else
- return false;
- }
-}
-
-/**
- * TDataListItemCollection class.
- *
- * TDataListItemCollection represents a collection of data list items.
- *
- * @author Qiang Xue <qiang.xue@gmail.com>
- * @version $Id$
- * @package System.Web.UI.WebControls
- * @since 3.0
- */
-class TDataListItemCollection extends TList
-{
- /**
- * Inserts an item at the specified position.
- * This overrides the parent implementation by inserting only TControl descendants.
- * @param integer the speicified position.
- * @param mixed new item
- * @throws TInvalidDataTypeException if the item to be inserted is not a TControl descendant.
- */
- public function insertAt($index,$item)
- {
- if($item instanceof TControl)
- parent::insertAt($index,$item);
- else
- throw new TInvalidDataTypeException('datalistitemcollection_datalistitem_required');
- }
-}
-
+ * @license http://www.pradosoft.com/license/
+ * @version $Id$
+ * @package System.Web.UI.WebControls
+ */
+
+/**
+ * Includes TBaseDataList class
+ */
+Prado::using('System.Web.UI.WebControls.TBaseDataList');
+/**
+ * Includes TRepeatInfo class
+ */
+Prado::using('System.Web.UI.WebControls.TRepeatInfo');
+
+/**
+ * TDataList class
+ *
+ * TDataList represents a data bound and updatable list control.
+ *
+ * Like {@link TRepeater}, TDataList displays its content repeatedly based on
+ * the data fetched from {@link setDataSource DataSource}.
+ * The repeated contents in TDataList are called items, which are controls and
+ * can be accessed through {@link getItems Items}. When {@link dataBind()} is
+ * invoked, TDataList creates an item for each row of data and binds the data
+ * row to the item. Optionally, a TDataList can have a header, a footer and/or
+ * separators between items.
+ *
+ * TDataList differs from {@link TRepeater} in that it supports tiling the items
+ * in different manners and it maintains status of items to handle data update.
+ *
+ * The layout of the repeated contents are specified by inline templates.
+ * TDataList items, header, footer, etc. are being instantiated with the corresponding
+ * templates when data is being bound to the repeater.
+ *
+ * Since v3.1.0, the layout can also be by renderers. A renderer is a control class
+ * that can be instantiated as datalist items, header, etc. A renderer can thus be viewed
+ * as an external template (in fact, it can also be non-templated controls).
+ *
+ * A renderer can be any control class.
+ * - If the class implements {@link IDataRenderer}, the <b>Data</b>
+ * property will be set as the data row during databinding. Many PRADO controls
+ * implement this interface, such as {@link TLabel}, {@link TTextBox}, etc.
+ * - If the class implements {@link IItemDataRenderer}, the <b>ItemIndex</b> property will be set
+ * as the zero-based index of the item in the datalist item collection, and
+ * the <b>ItemType</b> property as the item's type (such as TListItemType::Item).
+ * {@link TDataListItemRenderer} may be used as the convenient base class which
+ * already implements {@link IDataItemRenderer}.
+ *
+ * The following properties are used to specify different types of template and renderer
+ * for a datalist:
+ * - {@link setItemTemplate ItemTemplate}, {@link setItemRenderer ItemRenderer}:
+ * for each repeated row of data
+ * - {@link setAlternatingItemTemplate AlternatingItemTemplate}, {@link setAlternatingItemRenderer AlternatingItemRenderer}:
+ * for each alternating row of data. If not set, {@link setItemTemplate ItemTemplate} or {@link setItemRenderer ItemRenderer}
+ * will be used instead.
+ * - {@link setHeaderTemplate HeaderTemplate}, {@link setHeaderRenderer HeaderRenderer}:
+ * for the datalist header.
+ * - {@link setFooterTemplate FooterTemplate}, {@link setFooterRenderer FooterRenderer}:
+ * for the datalist footer.
+ * - {@link setSeparatorTemplate SeparatorTemplate}, {@link setSeparatorRenderer SeparatorRenderer}:
+ * for content to be displayed between items.
+ * - {@link setEmptyTemplate EmptyTemplate}, {@link setEmptyRenderer EmptyRenderer}:
+ * used when data bound to the datalist is empty.
+ * - {@link setEditItemTemplate EditItemTemplate}, {@link setEditItemRenderer EditItemRenderer}:
+ * for the row being editted.
+ * - {@link setSelectedItemTemplate SelectedItemTemplate}, {@link setSelectedItemRenderer SelectedItemRenderer}:
+ * for the row being selected.
+ *
+ * If a content type is defined with both a template and a renderer, the latter takes precedence.
+ *
+ * When {@link dataBind()} is being called, TDataList undergoes the following lifecycles for each row of data:
+ * - create item based on templates or renderers
+ * - set the row of data to the item
+ * - raise {@link onItemCreated OnItemCreated}:
+ * - add the item as a child control
+ * - call dataBind() of the item
+ * - raise {@link onItemDataBound OnItemDataBound}:
+ *
+ * TDataList raises an {@link onItemCommand OnItemCommand} whenever a button control
+ * within some datalist item raises a <b>OnCommand</b> event. Therefore,
+ * you can handle all sorts of <b>OnCommand</b> event in a central place by
+ * writing an event handler for {@link onItemCommand OnItemCommand}.
+ *
+ * An additional event is raised if the <b>OnCommand</b> event has one of the following
+ * command names:
+ * - edit: user wants to edit an item. <b>OnEditCommand</b> event will be raised.
+ * - update: user wants to save the change to an item. <b>OnUpdateCommand</b> event will be raised.
+ * - select: user selects an item. <b>OnSelectedIndexChanged</b> event will be raised.
+ * - delete: user deletes an item. <b>OnDeleteCommand</b> event will be raised.
+ * - cancel: user cancels previously editting action. <b>OnCancelCommand</b> event will be raised.
+ *
+ * TDataList provides a few properties to support tiling the items.
+ * The number of columns used to display the data items is specified via
+ * {@link setRepeatColumns RepeatColumns} property, while the {@link setRepeatDirection RepeatDirection}
+ * governs the order of the items being rendered.
+ * The layout of the data items in the list is specified via {@link setRepeatLayout RepeatLayout},
+ * which can take one of the following values:
+ * - Table (default): items are organized using HTML table and cells.
+ * When using this layout, one can set {@link setCellPadding CellPadding} and
+ * {@link setCellSpacing CellSpacing} to adjust the cellpadding and cellpadding
+ * of the table, and {@link setCaption Caption} and {@link setCaptionAlign CaptionAlign}
+ * to add a table caption with the specified alignment.
+ * - Flow: items are organized using HTML spans and breaks.
+ * - Raw: TDataList does not generate any HTML tags to do the tiling.
+ *
+ * Items in TDataList can be in one of the three status: normal browsing,
+ * being editted and being selected. To change the status of a particular
+ * item, set {@link setSelectedItemIndex SelectedItemIndex} or
+ * {@link setEditItemIndex EditItemIndex}. The former will change
+ * the indicated item to selected mode, which will cause the item to
+ * use {@link setSelectedItemTemplate SelectedItemTemplate} or
+ * {@link setSelectedItemRenderer SelectedItemRenderer} for presentation.
+ * The latter will change the indicated item to edit mode and to use corresponding
+ * template or renderer.
+ * Note, if an item is in edit mode, then selecting this item will have no effect.
+ *
+ * Different styles may be applied to items in different status. The style
+ * application is performed in a hierarchical way: Style in higher hierarchy
+ * will inherit from styles in lower hierarchy.
+ * Starting from the lowest hierarchy, the item styles include
+ * - item's own style
+ * - {@link getItemStyle ItemStyle}
+ * - {@link getAlternatingItemStyle AlternatingItemStyle}
+ * - {@link getSelectedItemStyle SelectedItemStyle}
+ * - {@link getEditItemStyle EditItemStyle}.
+ * Therefore, if background color is set as red in {@link getItemStyle ItemStyle},
+ * {@link getEditItemStyle EditItemStyle} will also have red background color
+ * unless it is set to a different value explicitly.
+ *
+ * When a page containing a datalist is post back, the datalist will restore automatically
+ * all its contents, including items, header, footer and separators.
+ * However, the data row associated with each item will not be recovered and become null.
+ * To access the data, use one of the following ways:
+ * - Use {@link getDataKeys DataKeys} to obtain the data key associated with
+ * the specified datalist item and use the key to fetch the corresponding data
+ * from some persistent storage such as DB.
+ * - Save the whole dataset in viewstate, which will restore the dataset automatically upon postback.
+ * Be aware though, if the size of your dataset is big, your page size will become big. Some
+ * complex data may also have serializing problem if saved in viewstate.
+ *
+ * @author Qiang Xue <qiang.xue@gmail.com>
+ * @version $Id$
+ * @package System.Web.UI.WebControls
+ * @since 3.0
+ */
+class TDataList extends TBaseDataList implements INamingContainer, IRepeatInfoUser
+{
+ /**
+ * Command name that TDataList understands. They are case-insensitive.
+ */
+ const CMD_SELECT='Select';
+ const CMD_EDIT='Edit';
+ const CMD_UPDATE='Update';
+ const CMD_DELETE='Delete';
+ const CMD_CANCEL='Cancel';
+
+ /**
+ * @var TDataListItemCollection item list
+ */
+ private $_items=null;
+ /**
+ * @var Itemplate various item templates
+ */
+ private $_itemTemplate=null;
+ private $_emptyTemplate=null;
+ private $_alternatingItemTemplate=null;
+ private $_selectedItemTemplate=null;
+ private $_editItemTemplate=null;
+ private $_headerTemplate=null;
+ private $_footerTemplate=null;
+ private $_separatorTemplate=null;
+ /**
+ * @var TControl header item
+ */
+ private $_header=null;
+ /**
+ * @var TControl footer item
+ */
+ private $_footer=null;
+
+ /**
+ * @return TDataListItemCollection item list
+ */
+ public function getItems()
+ {
+ if(!$this->_items)
+ $this->_items=new TDataListItemCollection;
+ return $this->_items;
+ }
+
+ /**
+ * @return integer number of items
+ */
+ public function getItemCount()
+ {
+ return $this->_items?$this->_items->getCount():0;
+ }
+
+ /**
+ * @return string the class name for datalist items. Defaults to empty, meaning not set.
+ * @since 3.1.0
+ */
+ public function getItemRenderer()
+ {
+ return $this->getViewState('ItemRenderer','');
+ }
+
+ /**
+ * Sets the item renderer class.
+ *
+ * If not empty, the class will be used to instantiate as datalist items.
+ * This property takes precedence over {@link getItemTemplate ItemTemplate}.
+ *
+ * @param string the renderer class name in namespace format.
+ * @see setItemTemplate
+ * @since 3.1.0
+ */
+ public function setItemRenderer($value)
+ {
+ $this->setViewState('ItemRenderer',$value,'');
+ }
+
+ /**
+ * @return string the class name for alternative datalist items. Defaults to empty, meaning not set.
+ * @since 3.1.0
+ */
+ public function getAlternatingItemRenderer()
+ {
+ return $this->getViewState('AlternatingItemRenderer','');
+ }
+
+ /**
+ * Sets the alternative item renderer class.
+ *
+ * If not empty, the class will be used to instantiate as alternative datalist items.
+ * This property takes precedence over {@link getAlternatingItemTemplate AlternatingItemTemplate}.
+ *
+ * @param string the renderer class name in namespace format.
+ * @see setAlternatingItemTemplate
+ * @since 3.1.0
+ */
+ public function setAlternatingItemRenderer($value)
+ {
+ $this->setViewState('AlternatingItemRenderer',$value,'');
+ }
+
+ /**
+ * @return string the class name for the datalist item being editted. Defaults to empty, meaning not set.
+ * @since 3.1.0
+ */
+ public function getEditItemRenderer()
+ {
+ return $this->getViewState('EditItemRenderer','');
+ }
+
+ /**
+ * Sets the renderer class for the datalist item being editted.
+ *
+ * If not empty, the class will be used to instantiate as the datalist item.
+ * This property takes precedence over {@link getEditItemTemplate EditItemTemplate}.
+ *
+ * @param string the renderer class name in namespace format.
+ * @see setEditItemTemplate
+ * @since 3.1.0
+ */
+ public function setEditItemRenderer($value)
+ {
+ $this->setViewState('EditItemRenderer',$value,'');
+ }
+
+ /**
+ * @return string the class name for the datalist item being selected. Defaults to empty, meaning not set.
+ * @since 3.1.0
+ */
+ public function getSelectedItemRenderer()
+ {
+ return $this->getViewState('SelectedItemRenderer','');
+ }
+
+ /**
+ * Sets the renderer class for the datalist item being selected.
+ *
+ * If not empty, the class will be used to instantiate as the datalist item.
+ * This property takes precedence over {@link getSelectedItemTemplate SelectedItemTemplate}.
+ *
+ * @param string the renderer class name in namespace format.
+ * @see setSelectedItemTemplate
+ * @since 3.1.0
+ */
+ public function setSelectedItemRenderer($value)
+ {
+ $this->setViewState('SelectedItemRenderer',$value,'');
+ }
+
+ /**
+ * @return string the class name for datalist item separators. Defaults to empty, meaning not set.
+ * @since 3.1.0
+ */
+ public function getSeparatorRenderer()
+ {
+ return $this->getViewState('SeparatorRenderer','');
+ }
+
+ /**
+ * Sets the datalist item separator renderer class.
+ *
+ * If not empty, the class will be used to instantiate as datalist item separators.
+ * This property takes precedence over {@link getSeparatorTemplate SeparatorTemplate}.
+ *
+ * @param string the renderer class name in namespace format.
+ * @see setSeparatorTemplate
+ * @since 3.1.0
+ */
+ public function setSeparatorRenderer($value)
+ {
+ $this->setViewState('SeparatorRenderer',$value,'');
+ }
+
+ /**
+ * @return string the class name for datalist header item. Defaults to empty, meaning not set.
+ * @since 3.1.0
+ */
+ public function getHeaderRenderer()
+ {
+ return $this->getViewState('HeaderRenderer','');
+ }
+
+ /**
+ * Sets the datalist header renderer class.
+ *
+ * If not empty, the class will be used to instantiate as datalist header item.
+ * This property takes precedence over {@link getHeaderTemplate HeaderTemplate}.
+ *
+ * @param string the renderer class name in namespace format.
+ * @see setHeaderTemplate
+ * @since 3.1.0
+ */
+ public function setHeaderRenderer($value)
+ {
+ $this->setViewState('HeaderRenderer',$value,'');
+ }
+
+ /**
+ * @return string the class name for datalist footer item. Defaults to empty, meaning not set.
+ * @since 3.1.0
+ */
+ public function getFooterRenderer()
+ {
+ return $this->getViewState('FooterRenderer','');
+ }
+
+ /**
+ * Sets the datalist footer renderer class.
+ *
+ * If not empty, the class will be used to instantiate as datalist footer item.
+ * This property takes precedence over {@link getFooterTemplate FooterTemplate}.
+ *
+ * @param string the renderer class name in namespace format.
+ * @see setFooterTemplate
+ * @since 3.1.0
+ */
+ public function setFooterRenderer($value)
+ {
+ $this->setViewState('FooterRenderer',$value,'');
+ }
+
+ /**
+ * @return string the class name for empty datalist item. Defaults to empty, meaning not set.
+ * @since 3.1.0
+ */
+ public function getEmptyRenderer()
+ {
+ return $this->getViewState('EmptyRenderer','');
+ }
+
+ /**
+ * Sets the datalist empty renderer class.
+ *
+ * The empty renderer is created as the child of the datalist
+ * if data bound to the datalist is empty.
+ * This property takes precedence over {@link getEmptyTemplate EmptyTemplate}.
+ *
+ * @param string the renderer class name in namespace format.
+ * @see setEmptyTemplate
+ * @since 3.1.0
+ */
+ public function setEmptyRenderer($value)
+ {
+ $this->setViewState('EmptyRenderer',$value,'');
+ }
+
+ /**
+ * @return ITemplate the template for item
+ */
+ public function getItemTemplate()
+ {
+ return $this->_itemTemplate;
+ }
+
+ /**
+ * @param ITemplate the template for item
+ * @throws TInvalidDataTypeException if the input is not an {@link ITemplate} or not null.
+ */
+ public function setItemTemplate($value)
+ {
+ if($value instanceof ITemplate || $value===null)
+ $this->_itemTemplate=$value;
+ else
+ throw new TInvalidDataTypeException('datalist_template_required','ItemTemplate');
+ }
+
+ /**
+ * @return TTableItemStyle the style for item
+ */
+ public function getItemStyle()
+ {
+ if(($style=$this->getViewState('ItemStyle',null))===null)
+ {
+ $style=new TTableItemStyle;
+ $this->setViewState('ItemStyle',$style,null);
+ }
+ return $style;
+ }
+
+ /**
+ * @return ITemplate the template for each alternating item
+ */
+ public function getAlternatingItemTemplate()
+ {
+ return $this->_alternatingItemTemplate;
+ }
+
+ /**
+ * @param ITemplate the template for each alternating item
+ * @throws TInvalidDataTypeException if the input is not an {@link ITemplate} or not null.
+ */
+ public function setAlternatingItemTemplate($value)
+ {
+ if($value instanceof ITemplate || $value===null)
+ $this->_alternatingItemTemplate=$value;
+ else
+ throw new TInvalidDataTypeException('datalist_template_required','AlternatingItemType');
+ }
+
+ /**
+ * @return TTableItemStyle the style for each alternating item
+ */
+ public function getAlternatingItemStyle()
+ {
+ if(($style=$this->getViewState('AlternatingItemStyle',null))===null)
+ {
+ $style=new TTableItemStyle;
+ $this->setViewState('AlternatingItemStyle',$style,null);
+ }
+ return $style;
+ }
+
+ /**
+ * @return ITemplate the selected item template
+ */
+ public function getSelectedItemTemplate()
+ {
+ return $this->_selectedItemTemplate;
+ }
+
+ /**
+ * @param ITemplate the selected item template
+ * @throws TInvalidDataTypeException if the input is not an {@link ITemplate} or not null.
+ */
+ public function setSelectedItemTemplate($value)
+ {
+ if($value instanceof ITemplate || $value===null)
+ $this->_selectedItemTemplate=$value;
+ else
+ throw new TInvalidDataTypeException('datalist_template_required','SelectedItemTemplate');
+ }
+
+ /**
+ * @return TTableItemStyle the style for selected item
+ */
+ public function getSelectedItemStyle()
+ {
+ if(($style=$this->getViewState('SelectedItemStyle',null))===null)
+ {
+ $style=new TTableItemStyle;
+ $this->setViewState('SelectedItemStyle',$style,null);
+ }
+ return $style;
+ }
+
+ /**
+ * @return ITemplate the edit item template
+ */
+ public function getEditItemTemplate()
+ {
+ return $this->_editItemTemplate;
+ }
+
+ /**
+ * @param ITemplate the edit item template
+ * @throws TInvalidDataTypeException if the input is not an {@link ITemplate} or not null.
+ */
+ public function setEditItemTemplate($value)
+ {
+ if($value instanceof ITemplate || $value===null)
+ $this->_editItemTemplate=$value;
+ else
+ throw new TInvalidDataTypeException('datalist_template_required','EditItemTemplate');
+ }
+
+ /**
+ * @return TTableItemStyle the style for edit item
+ */
+ public function getEditItemStyle()
+ {
+ if(($style=$this->getViewState('EditItemStyle',null))===null)
+ {
+ $style=new TTableItemStyle;
+ $this->setViewState('EditItemStyle',$style,null);
+ }
+ return $style;
+ }
+
+ /**
+ * @return ITemplate the header template
+ */
+ public function getHeaderTemplate()
+ {
+ return $this->_headerTemplate;
+ }
+
+ /**
+ * @param ITemplate the header template
+ * @throws TInvalidDataTypeException if the input is not an {@link ITemplate} or not null.
+ */
+ public function setHeaderTemplate($value)
+ {
+ if($value instanceof ITemplate || $value===null)
+ $this->_headerTemplate=$value;
+ else
+ throw new TInvalidDataTypeException('datalist_template_required','HeaderTemplate');
+ }
+
+ /**
+ * @return TTableItemStyle the style for header
+ */
+ public function getHeaderStyle()
+ {
+ if(($style=$this->getViewState('HeaderStyle',null))===null)
+ {
+ $style=new TTableItemStyle;
+ $this->setViewState('HeaderStyle',$style,null);
+ }
+ return $style;
+ }
+
+ /**
+ * @return TControl the header item
+ */
+ public function getHeader()
+ {
+ return $this->_header;
+ }
+
+ /**
+ * @return ITemplate the footer template
+ */
+ public function getFooterTemplate()
+ {
+ return $this->_footerTemplate;
+ }
+
+ /**
+ * @param ITemplate the footer template
+ * @throws TInvalidDataTypeException if the input is not an {@link ITemplate} or not null.
+ */
+ public function setFooterTemplate($value)
+ {
+ if($value instanceof ITemplate || $value===null)
+ $this->_footerTemplate=$value;
+ else
+ throw new TInvalidDataTypeException('datalist_template_required','FooterTemplate');
+ }
+
+ /**
+ * @return TTableItemStyle the style for footer
+ */
+ public function getFooterStyle()
+ {
+ if(($style=$this->getViewState('FooterStyle',null))===null)
+ {
+ $style=new TTableItemStyle;
+ $this->setViewState('FooterStyle',$style,null);
+ }
+ return $style;
+ }
+
+ /**
+ * @return TControl the footer item
+ */
+ public function getFooter()
+ {
+ return $this->_footer;
+ }
+
+ /**
+ * @return ITemplate the template applied when no data is bound to the datalist
+ */
+ public function getEmptyTemplate()
+ {
+ return $this->_emptyTemplate;
+ }
+
+ /**
+ * @param ITemplate the template applied when no data is bound to the datalist
+ * @throws TInvalidDataTypeException if the input is not an {@link ITemplate} or not null.
+ */
+ public function setEmptyTemplate($value)
+ {
+ if($value instanceof ITemplate || $value===null)
+ $this->_emptyTemplate=$value;
+ else
+ throw new TInvalidDataTypeException('datalist_template_required','EmptyTemplate');
+ }
+
+ /**
+ * @return ITemplate the separator template
+ */
+ public function getSeparatorTemplate()
+ {
+ return $this->_separatorTemplate;
+ }
+
+ /**
+ * @param ITemplate the separator template
+ * @throws TInvalidDataTypeException if the input is not an {@link ITemplate} or not null.
+ */
+ public function setSeparatorTemplate($value)
+ {
+ if($value instanceof ITemplate || $value===null)
+ $this->_separatorTemplate=$value;
+ else
+ throw new TInvalidDataTypeException('datalist_template_required','SeparatorTemplate');
+ }
+
+ /**
+ * @return TTableItemStyle the style for separator
+ */
+ public function getSeparatorStyle()
+ {
+ if(($style=$this->getViewState('SeparatorStyle',null))===null)
+ {
+ $style=new TTableItemStyle;
+ $this->setViewState('SeparatorStyle',$style,null);
+ }
+ return $style;
+ }
+
+ /**
+ * @return integer the zero-based index of the selected item in {@link getItems Items}.
+ * A value -1 means no item selected.
+ */
+ public function getSelectedItemIndex()
+ {
+ return $this->getViewState('SelectedItemIndex',-1);
+ }
+
+ /**
+ * Selects an item by its index in {@link getItems Items}.
+ * Previously selected item will be un-selected.
+ * If the item to be selected is already in edit mode, it will remain in edit mode.
+ * If the index is less than 0, any existing selection will be cleared up.
+ * @param integer the selected item index
+ */
+ public function setSelectedItemIndex($value)
+ {
+ if(($value=TPropertyValue::ensureInteger($value))<0)
+ $value=-1;
+ if(($current=$this->getSelectedItemIndex())!==$value)
+ {
+ $this->setViewState('SelectedItemIndex',$value,-1);
+ $items=$this->getItems();
+ $itemCount=$items->getCount();
+ if($current>=0 && $current<$itemCount)
+ {
+ $item=$items->itemAt($current);
+ if(($item instanceof IItemDataRenderer) && $item->getItemType()!==TListItemType::EditItem)
+ $item->setItemType($current%2?TListItemType::AlternatingItem : TListItemType::Item);
+ }
+ if($value>=0 && $value<$itemCount)
+ {
+ $item=$items->itemAt($value);
+ if(($item instanceof IItemDataRenderer) && $item->getItemType()!==TListItemType::EditItem)
+ $item->setItemType(TListItemType::SelectedItem);
+ }
+ }
+ }
+
+ /**
+ * @return TControl the selected item, null if no item is selected.
+ */
+ public function getSelectedItem()
+ {
+ $index=$this->getSelectedItemIndex();
+ $items=$this->getItems();
+ if($index>=0 && $index<$items->getCount())
+ return $items->itemAt($index);
+ else
+ return null;
+ }
+
+ /**
+ * @return mixed the key value of the currently selected item
+ * @throws TInvalidOperationException if {@link getDataKeyField DataKeyField} is empty.
+ */
+ public function getSelectedDataKey()
+ {
+ if($this->getDataKeyField()==='')
+ throw new TInvalidOperationException('datalist_datakeyfield_required');
+ $index=$this->getSelectedItemIndex();
+ $dataKeys=$this->getDataKeys();
+ if($index>=0 && $index<$dataKeys->getCount())
+ return $dataKeys->itemAt($index);
+ else
+ return null;
+ }
+
+ /**
+ * @return integer the zero-based index of the edit item in {@link getItems Items}.
+ * A value -1 means no item is in edit mode.
+ */
+ public function getEditItemIndex()
+ {
+ return $this->getViewState('EditItemIndex',-1);
+ }
+
+ /**
+ * Edits an item by its index in {@link getItems Items}.
+ * Previously editting item will change to normal item state.
+ * If the index is less than 0, any existing edit item will be cleared up.
+ * @param integer the edit item index
+ */
+ public function setEditItemIndex($value)
+ {
+ if(($value=TPropertyValue::ensureInteger($value))<0)
+ $value=-1;
+ if(($current=$this->getEditItemIndex())!==$value)
+ {
+ $this->setViewState('EditItemIndex',$value,-1);
+ $items=$this->getItems();
+ $itemCount=$items->getCount();
+ if($current>=0 && $current<$itemCount)
+ $items->itemAt($current)->setItemType($current%2?TListItemType::AlternatingItem : TListItemType::Item);
+ if($value>=0 && $value<$itemCount)
+ $items->itemAt($value)->setItemType(TListItemType::EditItem);
+ }
+ }
+
+ /**
+ * @return TControl the edit item
+ */
+ public function getEditItem()
+ {
+ $index=$this->getEditItemIndex();
+ $items=$this->getItems();
+ if($index>=0 && $index<$items->getCount())
+ return $items->itemAt($index);
+ else
+ return null;
+ }
+
+ /**
+ * @return boolean whether the header should be shown. Defaults to true.
+ */
+ public function getShowHeader()
+ {
+ return $this->getViewState('ShowHeader',true);
+ }
+
+ /**
+ * @param boolean whether to show header
+ */
+ public function setShowHeader($value)
+ {
+ $this->setViewState('ShowHeader',TPropertyValue::ensureBoolean($value),true);
+ }
+
+ /**
+ * @return boolean whether the footer should be shown. Defaults to true.
+ */
+ public function getShowFooter()
+ {
+ return $this->getViewState('ShowFooter',true);
+ }
+
+ /**
+ * @param boolean whether to show footer
+ */
+ public function setShowFooter($value)
+ {
+ $this->setViewState('ShowFooter',TPropertyValue::ensureBoolean($value),true);
+ }
+
+ /**
+ * @return TRepeatInfo repeat information (primarily used by control developers)
+ */
+ protected function getRepeatInfo()
+ {
+ if(($repeatInfo=$this->getViewState('RepeatInfo',null))===null)
+ {
+ $repeatInfo=new TRepeatInfo;
+ $this->setViewState('RepeatInfo',$repeatInfo,null);
+ }
+ return $repeatInfo;
+ }
+
+ /**
+ * @return string caption of the table layout
+ */
+ public function getCaption()
+ {
+ return $this->getRepeatInfo()->getCaption();
+ }
+
+ /**
+ * @param string caption of the table layout
+ */
+ public function setCaption($value)
+ {
+ $this->getRepeatInfo()->setCaption($value);
+ }
+
+ /**
+ * @return TTableCaptionAlign alignment of the caption of the table layout. Defaults to TTableCaptionAlign::NotSet.
+ */
+ public function getCaptionAlign()
+ {
+ return $this->getRepeatInfo()->getCaptionAlign();
+ }
+
+ /**
+ * @return TTableCaptionAlign alignment of the caption of the table layout.
+ */
+ public function setCaptionAlign($value)
+ {
+ $this->getRepeatInfo()->setCaptionAlign($value);
+ }
+
+ /**
+ * @return integer the number of columns that the list should be displayed with. Defaults to 0 meaning not set.
+ */
+ public function getRepeatColumns()
+ {
+ return $this->getRepeatInfo()->getRepeatColumns();
+ }
+
+ /**
+ * @param integer the number of columns that the list should be displayed with.
+ */
+ public function setRepeatColumns($value)
+ {
+ $this->getRepeatInfo()->setRepeatColumns($value);
+ }
+
+ /**
+ * @return TRepeatDirection the direction of traversing the list, defaults to TRepeatDirection::Vertical
+ */
+ public function getRepeatDirection()
+ {
+ return $this->getRepeatInfo()->getRepeatDirection();
+ }
+
+ /**
+ * @param TRepeatDirection the direction of traversing the list
+ */
+ public function setRepeatDirection($value)
+ {
+ $this->getRepeatInfo()->setRepeatDirection($value);
+ }
+
+ /**
+ * @return TRepeatLayout how the list should be displayed, using table or using line breaks. Defaults to TRepeatLayout::Table.
+ */
+ public function getRepeatLayout()
+ {
+ return $this->getRepeatInfo()->getRepeatLayout();
+ }
+
+ /**
+ * @param TRepeatLayout how the list should be displayed, using table or using line breaks
+ */
+ public function setRepeatLayout($value)
+ {
+ $this->getRepeatInfo()->setRepeatLayout($value);
+ }
+
+ /**
+ * This method overrides parent's implementation to handle
+ * {@link onItemCommand OnItemCommand} event which is bubbled from
+ * datalist items and their child controls.
+ * If the event parameter is {@link TDataListCommandEventParameter} and
+ * the command name is a recognized one, which includes 'select', 'edit',
+ * 'delete', 'update', and 'cancel' (case-insensitive), then a
+ * corresponding command event is also raised (such as {@link onEditCommand OnEditCommand}).
+ * This method should only be used by control developers.
+ * @param TControl the sender of the event
+ * @param TEventParameter event parameter
+ * @return boolean whether the event bubbling should stop here.
+ */
+ public function bubbleEvent($sender,$param)
+ {
+ if($param instanceof TDataListCommandEventParameter)
+ {
+ $this->onItemCommand($param);
+ $command=$param->getCommandName();
+ if(strcasecmp($command,self::CMD_SELECT)===0)
+ {
+ if(($item=$param->getItem()) instanceof IItemDataRenderer)
+ $this->setSelectedItemIndex($item->getItemIndex());
+ $this->onSelectedIndexChanged($param);
+ return true;
+ }
+ else if(strcasecmp($command,self::CMD_EDIT)===0)
+ {
+ $this->onEditCommand($param);
+ return true;
+ }
+ else if(strcasecmp($command,self::CMD_DELETE)===0)
+ {
+ $this->onDeleteCommand($param);
+ return true;
+ }
+ else if(strcasecmp($command,self::CMD_UPDATE)===0)
+ {
+ $this->onUpdateCommand($param);
+ return true;
+ }
+ else if(strcasecmp($command,self::CMD_CANCEL)===0)
+ {
+ $this->onCancelCommand($param);
+ return true;
+ }
+ }
+ return false;
+ }
+
+
+ /**
+ * Raises <b>OnItemCreated</b> event.
+ * This method is invoked after a data list item is created and instantiated with
+ * template, but before added to the page hierarchy.
+ * The datalist item control responsible for the event
+ * can be determined from the event parameter.
+ * If you override this method, be sure to call parent's implementation
+ * so that event handlers have chance to respond to the event.
+ * @param TDataListItemEventParameter event parameter
+ */
+ public function onItemCreated($param)
+ {
+ $this->raiseEvent('OnItemCreated',$this,$param);
+ }
+
+ /**
+ * Raises <b>OnItemDataBound</b> event.
+ * This method is invoked right after an item is data bound.
+ * The datalist item control responsible for the event
+ * can be determined from the event parameter.
+ * If you override this method, be sure to call parent's implementation
+ * so that event handlers have chance to respond to the event.
+ * @param TDataListItemEventParameter event parameter
+ */
+ public function onItemDataBound($param)
+ {
+ $this->raiseEvent('OnItemDataBound',$this,$param);
+ }
+
+ /**
+ * Raises <b>OnItemCommand</b> event.
+ * This method is invoked when a child control of the data list
+ * raises an <b>OnCommand</b> event.
+ * @param TDataListCommandEventParameter event parameter
+ */
+ public function onItemCommand($param)
+ {
+ $this->raiseEvent('OnItemCommand',$this,$param);
+ }
+
+ /**
+ * Raises <b>OnEditCommand</b> event.
+ * This method is invoked when a child control of the data list
+ * raises an <b>OnCommand</b> event and the command name is 'edit' (case-insensitive).
+ * @param TDataListCommandEventParameter event parameter
+ */
+ public function onEditCommand($param)
+ {
+ $this->raiseEvent('OnEditCommand',$this,$param);
+ }
+
+ /**
+ * Raises <b>OnDeleteCommand</b> event.
+ * This method is invoked when a child control of the data list
+ * raises an <b>OnCommand</b> event and the command name is 'delete' (case-insensitive).
+ * @param TDataListCommandEventParameter event parameter
+ */
+ public function onDeleteCommand($param)
+ {
+ $this->raiseEvent('OnDeleteCommand',$this,$param);
+ }
+
+ /**
+ * Raises <b>OnUpdateCommand</b> event.
+ * This method is invoked when a child control of the data list
+ * raises an <b>OnCommand</b> event and the command name is 'update' (case-insensitive).
+ * @param TDataListCommandEventParameter event parameter
+ */
+ public function onUpdateCommand($param)
+ {
+ $this->raiseEvent('OnUpdateCommand',$this,$param);
+ }
+
+ /**
+ * Raises <b>OnCancelCommand</b> event.
+ * This method is invoked when a child control of the data list
+ * raises an <b>OnCommand</b> event and the command name is 'cancel' (case-insensitive).
+ * @param TDataListCommandEventParameter event parameter
+ */
+ public function onCancelCommand($param)
+ {
+ $this->raiseEvent('OnCancelCommand',$this,$param);
+ }
+
+ /**
+ * Returns a value indicating whether this control contains header item.
+ * This method is required by {@link IRepeatInfoUser} interface.
+ * @return boolean whether the datalist has header
+ */
+ public function getHasHeader()
+ {
+ return ($this->getShowHeader() && ($this->_headerTemplate!==null || $this->getHeaderRenderer()!==''));
+ }
+
+ /**
+ * Returns a value indicating whether this control contains footer item.
+ * This method is required by {@link IRepeatInfoUser} interface.
+ * @return boolean whether the datalist has footer
+ */
+ public function getHasFooter()
+ {
+ return ($this->getShowFooter() && ($this->_footerTemplate!==null || $this->getFooterRenderer()!==''));
+ }
+
+ /**
+ * Returns a value indicating whether this control contains separator items.
+ * This method is required by {@link IRepeatInfoUser} interface.
+ * @return boolean always false.
+ */
+ public function getHasSeparators()
+ {
+ return $this->_separatorTemplate!==null || $this->getSeparatorRenderer()!=='';
+ }
+
+ /**
+ * Returns a style used for rendering items.
+ * This method is required by {@link IRepeatInfoUser} interface.
+ * @param string item type (Header,Footer,Item,AlternatingItem,SelectedItem,EditItem,Separator,Pager)
+ * @param integer index of the item being rendered
+ * @return TStyle item style
+ */
+ public function generateItemStyle($itemType,$index)
+ {
+ if(($item=$this->getItem($itemType,$index))!==null && ($item instanceof IStyleable) && $item->getHasStyle())
+ {
+ $style=$item->getStyle();
+ $item->clearStyle();
+ return $style;
+ }
+ else
+ return null;
+ }
+
+ /**
+ * Renders an item in the list.
+ * This method is required by {@link IRepeatInfoUser} interface.
+ * @param THtmlWriter writer for rendering purpose
+ * @param TRepeatInfo repeat information
+ * @param string item type (Header,Footer,Item,AlternatingItem,SelectedItem,EditItem,Separator,Pager)
+ * @param integer zero-based index of the item in the item list
+ */
+ public function renderItem($writer,$repeatInfo,$itemType,$index)
+ {
+ $item=$this->getItem($itemType,$index);
+ if($repeatInfo->getRepeatLayout()===TRepeatLayout::Raw && get_class($item)==='TDataListItem')
+ $item->setTagName('div');
+ $item->renderControl($writer);
+ }
+
+ /**
+ * @param TListItemType item type
+ * @param integer item index
+ * @return TControl data list item with the specified item type and index
+ */
+ private function getItem($itemType,$index)
+ {
+ switch($itemType)
+ {
+ case TListItemType::Item:
+ case TListItemType::AlternatingItem:
+ case TListItemType::SelectedItem:
+ case TListItemType::EditItem:
+ return $this->getItems()->itemAt($index);
+ case TListItemType::Header:
+ return $this->getControls()->itemAt(0);
+ case TListItemType::Footer:
+ return $this->getControls()->itemAt($this->getControls()->getCount()-1);
+ case TListItemType::Separator:
+ $i=$index+$index+1;
+ if($this->_headerTemplate!==null || $this->getHeaderRenderer()!=='')
+ $i++;
+ return $this->getControls()->itemAt($i);
+ }
+ return null;
+ }
+
+ /**
+ * Creates a datalist item.
+ * This method invokes {@link createItem} to create a new datalist item.
+ * @param integer zero-based item index.
+ * @param TListItemType item type
+ * @return TControl the created item, null if item is not created
+ */
+ private function createItemInternal($itemIndex,$itemType)
+ {
+ if(($item=$this->createItem($itemIndex,$itemType))!==null)
+ {
+ $param=new TDataListItemEventParameter($item);
+ $this->onItemCreated($param);
+ $this->getControls()->add($item);
+ return $item;
+ }
+ else
+ return null;
+ }
+
+ /**
+ * Creates a datalist item and performs databinding.
+ * This method invokes {@link createItem} to create a new datalist item.
+ * @param integer zero-based item index.
+ * @param TListItemType item type
+ * @param mixed data to be associated with the item
+ * @return TControl the created item, null if item is not created
+ */
+ private function createItemWithDataInternal($itemIndex,$itemType,$dataItem)
+ {
+ if(($item=$this->createItem($itemIndex,$itemType))!==null)
+ {
+ $param=new TDataListItemEventParameter($item);
+ if($item instanceof IDataRenderer)
+ $item->setData($dataItem);
+ $this->onItemCreated($param);
+ $this->getControls()->add($item);
+ $item->dataBind();
+ $this->onItemDataBound($param);
+ return $item;
+ }
+ else
+ return null;
+ }
+
+ private function getAlternatingItemDisplay()
+ {
+ if(($classPath=$this->getAlternatingItemRenderer())==='' && $this->_alternatingItemTemplate===null)
+ return array($this->getItemRenderer(),$this->_itemTemplate);
+ else
+ return array($classPath,$this->_alternatingItemTemplate);
+ }
+
+ private function getSelectedItemDisplay($itemIndex)
+ {
+ if(($classPath=$this->getSelectedItemRenderer())==='' && $this->_selectedItemTemplate===null)
+ {
+ if($itemIndex%2===0)
+ return array($this->getItemRenderer(),$this->_itemTemplate);
+ else
+ return $this->getAlternatingItemDisplay();
+ }
+ else
+ return array($classPath,$this->_selectedItemTemplate);
+ }
+
+ private function getEditItemDisplay($itemIndex)
+ {
+ if(($classPath=$this->getEditItemRenderer())==='' && $this->_editItemTemplate===null)
+ return $this->getSelectedItemDisplay($itemIndex);
+ else
+ return array($classPath,$this->_editItemTemplate);
+ }
+
+ /**
+ * Creates a datalist item instance based on the item type and index.
+ * @param integer zero-based item index
+ * @param TListItemType item type
+ * @return TControl created datalist item
+ */
+ protected function createItem($itemIndex,$itemType)
+ {
+ $template=null;
+ $classPath=null;
+ switch($itemType)
+ {
+ case TListItemType::Item :
+ $classPath=$this->getItemRenderer();
+ $template=$this->_itemTemplate;
+ break;
+ case TListItemType::AlternatingItem :
+ list($classPath,$template)=$this->getAlternatingItemDisplay();
+ break;
+ case TListItemType::SelectedItem:
+ list($classPath,$template)=$this->getSelectedItemDisplay($itemIndex);
+ break;
+ case TListItemType::EditItem:
+ list($classPath,$template)=$this->getEditItemDisplay($itemIndex);
+ break;
+ case TListItemType::Header :
+ $classPath=$this->getHeaderRenderer();
+ $template=$this->_headerTemplate;
+ break;
+ case TListItemType::Footer :
+ $classPath=$this->getFooterRenderer();
+ $template=$this->_footerTemplate;
+ break;
+ case TListItemType::Separator :
+ $classPath=$this->getSeparatorRenderer();
+ $template=$this->_separatorTemplate;
+ break;
+ default:
+ throw new TInvalidDataValueException('datalist_itemtype_unknown',$itemType);
+ }
+ if($classPath!=='')
+ {
+ $item=Prado::createComponent($classPath);
+ if($item instanceof IItemDataRenderer)
+ {
+ $item->setItemIndex($itemIndex);
+ $item->setItemType($itemType);
+ }
+ }
+ else if($template!==null)
+ {
+ $item=new TDataListItem;
+ $item->setItemIndex($itemIndex);
+ $item->setItemType($itemType);
+ $template->instantiateIn($item);
+ }
+ else
+ $item=null;
+
+ return $item;
+ }
+
+ /**
+ * Creates empty datalist content.
+ */
+ protected function createEmptyContent()
+ {
+ if(($classPath=$this->getEmptyRenderer())!=='')
+ $this->getControls()->add(Prado::createComponent($classPath));
+ else if($this->_emptyTemplate!==null)
+ $this->_emptyTemplate->instantiateIn($this);
+ }
+
+ /**
+ * Applies styles to items, header, footer and separators.
+ * Item styles are applied in a hierarchical way. Style in higher hierarchy
+ * will inherit from styles in lower hierarchy.
+ * Starting from the lowest hierarchy, the item styles include
+ * item's own style, {@link getItemStyle ItemStyle}, {@link getAlternatingItemStyle AlternatingItemStyle},
+ * {@link getSelectedItemStyle SelectedItemStyle}, and {@link getEditItemStyle EditItemStyle}.
+ * Therefore, if background color is set as red in {@link getItemStyle ItemStyle},
+ * {@link getEditItemStyle EditItemStyle} will also have red background color
+ * unless it is set to a different value explicitly.
+ */
+ protected function applyItemStyles()
+ {
+ $itemStyle=$this->getViewState('ItemStyle',null);
+
+ $alternatingItemStyle=$this->getViewState('AlternatingItemStyle',null);
+ if($itemStyle!==null)
+ {
+ if($alternatingItemStyle===null)
+ $alternatingItemStyle=$itemStyle;
+ else
+ $alternatingItemStyle->mergeWith($itemStyle);
+ }
+
+ $selectedItemStyle=$this->getViewState('SelectedItemStyle',null);
+
+ $editItemStyle=$this->getViewState('EditItemStyle',null);
+ if($selectedItemStyle!==null)
+ {
+ if($editItemStyle===null)
+ $editItemStyle=$selectedItemStyle;
+ else
+ $editItemStyle->mergeWith($selectedItemStyle);
+ }
+
+ // apply header style if any
+ if($this->_header!==null && $this->_header instanceof IStyleable)
+ {
+ if($headerStyle=$this->getViewState('HeaderStyle',null))
+ $this->_header->getStyle()->mergeWith($headerStyle);
+ }
+
+ // apply footer style if any
+ if($this->_footer!==null && $this->_footer instanceof IStyleable)
+ {
+ if($footerStyle=$this->getViewState('FooterStyle',null))
+ $this->_footer->getStyle()->mergeWith($footerStyle);
+ }
+
+ $selectedIndex=$this->getSelectedItemIndex();
+ $editIndex=$this->getEditItemIndex();
+
+ // apply item styles if any
+ foreach($this->getItems() as $index=>$item)
+ {
+ if($index===$editIndex)
+ $style=$editItemStyle;
+ else if($index===$selectedIndex)
+ $style=$selectedItemStyle;
+ else if($index%2===0)
+ $style=$itemStyle;
+ else
+ $style=$alternatingItemStyle;
+ if($style && $item instanceof IStyleable)
+ $item->getStyle()->mergeWith($style);
+ }
+
+ // apply separator style if any
+ if(($separatorStyle=$this->getViewState('SeparatorStyle',null))!==null && $this->getHasSeparators())
+ {
+ $controls=$this->getControls();
+ $count=$controls->getCount();
+ for($i=$this->_header?2:1;$i<$count;$i+=2)
+ {
+ if(($separator=$controls->itemAt($i)) instanceof IStyleable)
+ $separator->getStyle()->mergeWith($separatorStyle);
+ }
+ }
+ }
+
+ /**
+ * Saves item count in viewstate.
+ * This method is invoked right before control state is to be saved.
+ */
+ public function saveState()
+ {
+ parent::saveState();
+ if($this->_items)
+ $this->setViewState('ItemCount',$this->_items->getCount(),0);
+ else
+ $this->clearViewState('ItemCount');
+ }
+
+ /**
+ * Loads item count information from viewstate.
+ * This method is invoked right after control state is loaded.
+ */
+ public function loadState()
+ {
+ parent::loadState();
+ if(!$this->getIsDataBound())
+ $this->restoreItemsFromViewState();
+ $this->clearViewState('ItemCount');
+ }
+
+ /**
+ * Clears up all items in the data list.
+ */
+ public function reset()
+ {
+ $this->getControls()->clear();
+ $this->getItems()->clear();
+ $this->_header=null;
+ $this->_footer=null;
+ }
+
+ /**
+ * Creates data list items based on viewstate information.
+ */
+ protected function restoreItemsFromViewState()
+ {
+ $this->reset();
+ if(($itemCount=$this->getViewState('ItemCount',0))>0)
+ {
+ $items=$this->getItems();
+ $selectedIndex=$this->getSelectedItemIndex();
+ $editIndex=$this->getEditItemIndex();
+ $hasSeparator=$this->_separatorTemplate!==null || $this->getSeparatorRenderer()!=='';
+ $this->_header=$this->createItemInternal(-1,TListItemType::Header);
+ for($i=0;$i<$itemCount;++$i)
+ {
+ if($hasSeparator && $i>0)
+ $this->createItemInternal($i-1,TListItemType::Separator);
+ if($i===$editIndex)
+ $itemType=TListItemType::EditItem;
+ else if($i===$selectedIndex)
+ $itemType=TListItemType::SelectedItem;
+ else
+ $itemType=$i%2?TListItemType::AlternatingItem : TListItemType::Item;
+ $items->add($this->createItemInternal($i,$itemType));
+ }
+ $this->_footer=$this->createItemInternal(-1,TListItemType::Footer);
+ }
+ else
+ $this->createEmptyContent();
+ $this->clearChildState();
+ }
+
+ /**
+ * Performs databinding to populate data list items from data source.
+ * This method is invoked by dataBind().
+ * You may override this function to provide your own way of data population.
+ * @param Traversable the data
+ */
+ protected function performDataBinding($data)
+ {
+ $this->reset();
+ $keys=$this->getDataKeys();
+ $keys->clear();
+ $keyField=$this->getDataKeyField();
+ $itemIndex=0;
+ $items=$this->getItems();
+ $hasSeparator=$this->_separatorTemplate!==null || $this->getSeparatorRenderer()!=='';
+ $selectedIndex=$this->getSelectedItemIndex();
+ $editIndex=$this->getEditItemIndex();
+ foreach($data as $key=>$dataItem)
+ {
+ if($keyField!=='')
+ $keys->add($this->getDataFieldValue($dataItem,$keyField));
+ else
+ $keys->add($key);
+ if($itemIndex===0)
+ $this->_header=$this->createItemWithDataInternal(-1,TListItemType::Header,null);
+ if($hasSeparator && $itemIndex>0)
+ $this->createItemWithDataInternal($itemIndex-1,TListItemType::Separator,null);
+ if($itemIndex===$editIndex)
+ $itemType=TListItemType::EditItem;
+ else if($itemIndex===$selectedIndex)
+ $itemType=TListItemType::SelectedItem;
+ else
+ $itemType=$itemIndex%2?TListItemType::AlternatingItem : TListItemType::Item;
+ $items->add($this->createItemWithDataInternal($itemIndex,$itemType,$dataItem));
+ $itemIndex++;
+ }
+ if($itemIndex>0)
+ $this->_footer=$this->createItemWithDataInternal(-1,TListItemType::Footer,null);
+ else
+ {
+ $this->createEmptyContent();
+ $this->dataBindChildren();
+ }
+ $this->setViewState('ItemCount',$itemIndex,0);
+ }
+
+ /**
+ * Renders the data list control.
+ * This method overrides the parent implementation.
+ * @param THtmlWriter writer for rendering purpose.
+ */
+ public function render($writer)
+ {
+ if($this->getHasControls())
+ {
+ if($this->getItemCount()>0)
+ {
+ $this->applyItemStyles();
+ $repeatInfo=$this->getRepeatInfo();
+ $repeatInfo->renderRepeater($writer,$this);
+ }
+ else if($this->_emptyTemplate!==null || $this->getEmptyRenderer()!=='')
+ parent::render($writer);
+ }
+ }
+}
+
+
+/**
+ * TDataListItemEventParameter class
+ *
+ * TDataListItemEventParameter encapsulates the parameter data for
+ * {@link TDataList::onItemCreated ItemCreated} event of {@link TDataList} controls.
+ * The {@link getItem Item} property indicates the DataList item related with the event.
+ *
+ * @author Qiang Xue <qiang.xue@gmail.com>
+ * @version $Id$
+ * @package System.Web.UI.WebControls
+ * @since 3.0
+ */
+class TDataListItemEventParameter extends TEventParameter
+{
+ /**
+ * The datalist item control responsible for the event.
+ * @var TControl
+ */
+ private $_item=null;
+
+ /**
+ * Constructor.
+ * @param TControl DataList item related with the corresponding event
+ */
+ public function __construct($item)
+ {
+ $this->_item=$item;
+ }
+
+ /**
+ * @return TControl datalist item related with the corresponding event
+ */
+ public function getItem()
+ {
+ return $this->_item;
+ }
+}
+
+/**
+ * TDataListCommandEventParameter class
+ *
+ * TDataListCommandEventParameter encapsulates the parameter data for
+ * {@link TDataList::onItemCommand ItemCommand} event of {@link TDataList} controls.
+ *
+ * The {@link getItem Item} property indicates the DataList item related with the event.
+ * The {@link getCommandSource CommandSource} refers to the control that originally
+ * raises the Command event.
+ *
+ * @author Qiang Xue <qiang.xue@gmail.com>
+ * @version $Id$
+ * @package System.Web.UI.WebControls
+ * @since 3.0
+ */
+class TDataListCommandEventParameter extends TCommandEventParameter
+{
+ /**
+ * @var TControl the datalist item control responsible for the event.
+ */
+ private $_item=null;
+ /**
+ * @var TControl the control originally raises the <b>OnCommand</b> event.
+ */
+ private $_source=null;
+
+ /**
+ * Constructor.
+ * @param TControl datalist item responsible for the event
+ * @param TControl original event sender
+ * @param TCommandEventParameter original event parameter
+ */
+ public function __construct($item,$source,TCommandEventParameter $param)
+ {
+ $this->_item=$item;
+ $this->_source=$source;
+ parent::__construct($param->getCommandName(),$param->getCommandParameter());
+ }
+
+ /**
+ * @return TControl the datalist item control responsible for the event.
+ */
+ public function getItem()
+ {
+ return $this->_item;
+ }
+
+ /**
+ * @return TControl the control originally raises the <b>OnCommand</b> event.
+ */
+ public function getCommandSource()
+ {
+ return $this->_source;
+ }
+}
+
+/**
+ * TDataListItem class
+ *
+ * A TDataListItem control represents an item in the {@link TDataList} control,
+ * such as heading section, footer section, or a data item.
+ * The index and data value of the item can be accessed via {@link getItemIndex ItemIndex}>
+ * and {@link getDataItem DataItem} properties, respectively. The type of the item
+ * is given by {@link getItemType ItemType} property.
+ *
+ * @author Qiang Xue <qiang.xue@gmail.com>
+ * @version $Id$
+ * @package System.Web.UI.WebControls
+ * @since 3.0
+ */
+class TDataListItem extends TWebControl implements INamingContainer, IItemDataRenderer
+{
+ /**
+ * index of the data item in the Items collection of DataList
+ */
+ private $_itemIndex;
+ /**
+ * type of the TDataListItem
+ * @var TListItemType
+ */
+ private $_itemType;
+ /**
+ * value of the data associated with this item
+ * @var mixed
+ */
+ private $_data;
+
+ private $_tagName='span';
+
+ /**
+ * Returns the tag name used for this control.
+ * @return string tag name of the control to be rendered
+ */
+ protected function getTagName()
+ {
+ return $this->_tagName;
+ }
+
+ /**
+ * @param string tag name of the control to be rendered
+ */
+ public function setTagName($value)
+ {
+ $this->_tagName=$value;
+ }
+
+ /**
+ * Creates a style object for the control.
+ * This method creates a {@link TTableItemStyle} to be used by a datalist item.
+ * @return TStyle control style to be used
+ */
+ protected function createStyle()
+ {
+ return new TTableItemStyle;
+ }
+
+ /**
+ * @return TListItemType item type
+ */
+ public function getItemType()
+ {
+ return $this->_itemType;
+ }
+
+ /**
+ * @param TListItemType item type.
+ */
+ public function setItemType($value)
+ {
+ $this->_itemType=TPropertyValue::ensureEnum($value,'TListItemType');
+ }
+
+ /**
+ * @return integer zero-based index of the item in the item collection of datalist
+ */
+ public function getItemIndex()
+ {
+ return $this->_itemIndex;
+ }
+
+ /**
+ * Sets the zero-based index for the item.
+ * If the item is not in the item collection (e.g. it is a header item), -1 should be used.
+ * @param integer zero-based index of the item.
+ */
+ public function setItemIndex($value)
+ {
+ $this->_itemIndex=TPropertyValue::ensureInteger($value);
+ }
+
+ /**
+ * @return mixed data associated with the item
+ * @since 3.1.0
+ */
+ public function getData()
+ {
+ return $this->_data;
+ }
+
+ /**
+ * @param mixed data to be associated with the item
+ * @since 3.1.0
+ */
+ public function setData($value)
+ {
+ $this->_data=$value;
+ }
+
+ /**
+ * This property is deprecated since v3.1.0.
+ * @return mixed data associated with the item
+ * @deprecated deprecated since v3.1.0. Use {@link getData} instead.
+ */
+ public function getDataItem()
+ {
+ return $this->getData();
+ }
+
+ /**
+ * This property is deprecated since v3.1.0.
+ * @param mixed data to be associated with the item
+ * @deprecated deprecated since version 3.1.0. Use {@link setData} instead.
+ */
+ public function setDataItem($value)
+ {
+ return $this->setData($value);
+ }
+
+ /**
+ * This method overrides parent's implementation by wrapping event parameter
+ * for <b>OnCommand</b> event with item information.
+ * @param TControl the sender of the event
+ * @param TEventParameter event parameter
+ * @return boolean whether the event bubbling should stop here.
+ */
+ public function bubbleEvent($sender,$param)
+ {
+ if($param instanceof TCommandEventParameter)
+ {
+ $this->raiseBubbleEvent($this,new TDataListCommandEventParameter($this,$sender,$param));
+ return true;
+ }
+ else
+ return false;
+ }
+}
+
+/**
+ * TDataListItemCollection class.
+ *
+ * TDataListItemCollection represents a collection of data list items.
+ *
+ * @author Qiang Xue <qiang.xue@gmail.com>
+ * @version $Id$
+ * @package System.Web.UI.WebControls
+ * @since 3.0
+ */
+class TDataListItemCollection extends TList
+{
+ /**
+ * Inserts an item at the specified position.
+ * This overrides the parent implementation by inserting only TControl descendants.
+ * @param integer the speicified position.
+ * @param mixed new item
+ * @throws TInvalidDataTypeException if the item to be inserted is not a TControl descendant.
+ */
+ public function insertAt($index,$item)
+ {
+ if($item instanceof TControl)
+ parent::insertAt($index,$item);
+ else
+ throw new TInvalidDataTypeException('datalistitemcollection_datalistitem_required');
+ }
+}
+
diff --git a/framework/Web/UI/WebControls/TDataListItemRenderer.php b/framework/Web/UI/WebControls/TDataListItemRenderer.php
index 7065dc09..53c48b6e 100644
--- a/framework/Web/UI/WebControls/TDataListItemRenderer.php
+++ b/framework/Web/UI/WebControls/TDataListItemRenderer.php
@@ -1,172 +1,172 @@
-<?php
-/**
- * TDataListItemRenderer class file
- *
- * @author Qiang Xue <qiang.xue@gmail.com>
- * @link http://www.pradosoft.com/
+<?php
+/**
+ * TDataListItemRenderer class file
+ *
+ * @author Qiang Xue <qiang.xue@gmail.com>
+ * @link http://www.pradosoft.com/
* @copyright Copyright &copy; 2005-2012 PradoSoft
- * @license http://www.pradosoft.com/license/
- * @version $Id$
- * @package System.Web.UI.WebControls
- */
-
-Prado::using('System.Web.UI.WebControls.TDataList');
-Prado::using('System.Web.UI.WebControls.TItemDataRenderer');
-
-/**
- * TDataListItemRenderer class
- *
- * TDataListItemRenderer can be used as a convenient base class to
- * define an item renderer class specific for {@link TDataList}.
- *
- * TDataListItemRenderer extends {@link TItemDataRenderer} and implements
- * the bubbling scheme for the OnCommand event of data list items.
- *
- * TDataListItemRenderer also implements the {@link IStyleable} interface,
- * which allows TDataList to apply CSS styles to the renders.
- *
- * @author Qiang Xue <qiang.xue@gmail.com>
- * @version $Id$
- * @package System.Web.UI.WebControls
- * @since 3.1.0
- */
-class TDataListItemRenderer extends TItemDataRenderer implements IStyleable
-{
- /**
- * Creates a style object to be used by the control.
- * This method may be overriden by controls to provide customized style.
- * @return TStyle
- */
- protected function createStyle()
- {
- return new TTableItemStyle;
- }
-
- /**
- * @return boolean whether the control has defined any style information
- */
- public function getHasStyle()
- {
- return $this->getViewState('Style',null)!==null;
- }
-
- /**
- * @return TStyle the object representing the css style of the control
- */
- public function getStyle()
- {
- if($style=$this->getViewState('Style',null))
- return $style;
- else
- {
- $style=$this->createStyle();
- $this->setViewState('Style',$style,null);
- return $style;
- }
- }
-
- /**
- * Removes all style data.
- */
- public function clearStyle()
- {
- $this->clearViewState('Style');
- }
-
- /**
- * This method overrides parent's implementation by wrapping event parameter
- * for <b>OnCommand</b> event with item information.
- * @param TControl the sender of the event
- * @param TEventParameter event parameter
- * @return boolean whether the event bubbling should stop here.
- */
- public function bubbleEvent($sender,$param)
- {
- if($param instanceof TCommandEventParameter)
- {
- $this->raiseBubbleEvent($this,new TDataListCommandEventParameter($this,$sender,$param));
- return true;
- }
- else
- return false;
- }
-
- /**
- * Returns the tag name used for this control.
- * By default, the tag name is 'span'.
- * You can override this method to provide customized tag names.
- * If the tag name is empty, the opening and closing tag will NOT be rendered.
- * @return string tag name of the control to be rendered
- */
- protected function getTagName()
- {
- return 'span';
- }
-
- /**
- * Adds attribute name-value pairs to renderer.
- * By default, this method renders the style string.
- * The method can be overriden to provide customized attribute rendering.
- * @param THtmlWriter the writer used for the rendering purpose
- */
- protected function addAttributesToRender($writer)
- {
- if($style=$this->getViewState('Style',null))
- $style->addAttributesToRender($writer);
- }
-
- /**
- * Renders the control.
- * This method overrides the parent implementation by replacing it with
- * the following sequence:
- * - {@link renderBeginTag}
- * - {@link renderContents}
- * - {@link renderEndTag}
- * If the {@link getTagName TagName} is empty, only {@link renderContents} is invoked.
- * @param THtmlWriter the writer used for the rendering purpose
- */
- public function render($writer)
- {
- if($this->getTagName()!=='')
- {
- $this->renderBeginTag($writer);
- $this->renderContents($writer);
- $this->renderEndTag($writer);
- }
- else
- $this->renderContents($writer);
- }
-
- /**
- * Renders the openning tag for the control (including attributes)
- * This method is invoked when {@link getTagName TagName} is not empty.
- * @param THtmlWriter the writer used for the rendering purpose
- */
- public function renderBeginTag($writer)
- {
- $this->addAttributesToRender($writer);
- $writer->renderBeginTag($this->getTagName());
- }
-
- /**
- * Renders the body content enclosed between the control tag.
- * By default, child controls and text strings will be rendered.
- * You can override this method to provide customized content rendering.
- * @param THtmlWriter the writer used for the rendering purpose
- */
- public function renderContents($writer)
- {
- parent::renderChildren($writer);
- }
-
- /**
- * Renders the closing tag for the control
- * This method is invoked when {@link getTagName TagName} is not empty.
- * @param THtmlWriter the writer used for the rendering purpose
- */
- public function renderEndTag($writer)
- {
- $writer->renderEndTag();
- }
-}
-
+ * @license http://www.pradosoft.com/license/
+ * @version $Id$
+ * @package System.Web.UI.WebControls
+ */
+
+Prado::using('System.Web.UI.WebControls.TDataList');
+Prado::using('System.Web.UI.WebControls.TItemDataRenderer');
+
+/**
+ * TDataListItemRenderer class
+ *
+ * TDataListItemRenderer can be used as a convenient base class to
+ * define an item renderer class specific for {@link TDataList}.
+ *
+ * TDataListItemRenderer extends {@link TItemDataRenderer} and implements
+ * the bubbling scheme for the OnCommand event of data list items.
+ *
+ * TDataListItemRenderer also implements the {@link IStyleable} interface,
+ * which allows TDataList to apply CSS styles to the renders.
+ *
+ * @author Qiang Xue <qiang.xue@gmail.com>
+ * @version $Id$
+ * @package System.Web.UI.WebControls
+ * @since 3.1.0
+ */
+class TDataListItemRenderer extends TItemDataRenderer implements IStyleable
+{
+ /**
+ * Creates a style object to be used by the control.
+ * This method may be overriden by controls to provide customized style.
+ * @return TStyle
+ */
+ protected function createStyle()
+ {
+ return new TTableItemStyle;
+ }
+
+ /**
+ * @return boolean whether the control has defined any style information
+ */
+ public function getHasStyle()
+ {
+ return $this->getViewState('Style',null)!==null;
+ }
+
+ /**
+ * @return TStyle the object representing the css style of the control
+ */
+ public function getStyle()
+ {
+ if($style=$this->getViewState('Style',null))
+ return $style;
+ else
+ {
+ $style=$this->createStyle();
+ $this->setViewState('Style',$style,null);
+ return $style;
+ }
+ }
+
+ /**
+ * Removes all style data.
+ */
+ public function clearStyle()
+ {
+ $this->clearViewState('Style');
+ }
+
+ /**
+ * This method overrides parent's implementation by wrapping event parameter
+ * for <b>OnCommand</b> event with item information.
+ * @param TControl the sender of the event
+ * @param TEventParameter event parameter
+ * @return boolean whether the event bubbling should stop here.
+ */
+ public function bubbleEvent($sender,$param)
+ {
+ if($param instanceof TCommandEventParameter)
+ {
+ $this->raiseBubbleEvent($this,new TDataListCommandEventParameter($this,$sender,$param));
+ return true;
+ }
+ else
+ return false;
+ }
+
+ /**
+ * Returns the tag name used for this control.
+ * By default, the tag name is 'span'.
+ * You can override this method to provide customized tag names.
+ * If the tag name is empty, the opening and closing tag will NOT be rendered.
+ * @return string tag name of the control to be rendered
+ */
+ protected function getTagName()
+ {
+ return 'span';
+ }
+
+ /**
+ * Adds attribute name-value pairs to renderer.
+ * By default, this method renders the style string.
+ * The method can be overriden to provide customized attribute rendering.
+ * @param THtmlWriter the writer used for the rendering purpose
+ */
+ protected function addAttributesToRender($writer)
+ {
+ if($style=$this->getViewState('Style',null))
+ $style->addAttributesToRender($writer);
+ }
+
+ /**
+ * Renders the control.
+ * This method overrides the parent implementation by replacing it with
+ * the following sequence:
+ * - {@link renderBeginTag}
+ * - {@link renderContents}
+ * - {@link renderEndTag}
+ * If the {@link getTagName TagName} is empty, only {@link renderContents} is invoked.
+ * @param THtmlWriter the writer used for the rendering purpose
+ */
+ public function render($writer)
+ {
+ if($this->getTagName()!=='')
+ {
+ $this->renderBeginTag($writer);
+ $this->renderContents($writer);
+ $this->renderEndTag($writer);
+ }
+ else
+ $this->renderContents($writer);
+ }
+
+ /**
+ * Renders the openning tag for the control (including attributes)
+ * This method is invoked when {@link getTagName TagName} is not empty.
+ * @param THtmlWriter the writer used for the rendering purpose
+ */
+ public function renderBeginTag($writer)
+ {
+ $this->addAttributesToRender($writer);
+ $writer->renderBeginTag($this->getTagName());
+ }
+
+ /**
+ * Renders the body content enclosed between the control tag.
+ * By default, child controls and text strings will be rendered.
+ * You can override this method to provide customized content rendering.
+ * @param THtmlWriter the writer used for the rendering purpose
+ */
+ public function renderContents($writer)
+ {
+ parent::renderChildren($writer);
+ }
+
+ /**
+ * Renders the closing tag for the control
+ * This method is invoked when {@link getTagName TagName} is not empty.
+ * @param THtmlWriter the writer used for the rendering purpose
+ */
+ public function renderEndTag($writer)
+ {
+ $writer->renderEndTag();
+ }
+}
+
diff --git a/framework/Web/UI/WebControls/TDataRenderer.php b/framework/Web/UI/WebControls/TDataRenderer.php
index ece9d974..44ab0b1d 100644
--- a/framework/Web/UI/WebControls/TDataRenderer.php
+++ b/framework/Web/UI/WebControls/TDataRenderer.php
@@ -1,52 +1,52 @@
-<?php
-/**
- * TDataRenderer class file
- *
- * @author Qiang Xue <qiang.xue@gmail.com>
- * @link http://www.pradosoft.com/
+<?php
+/**
+ * TDataRenderer class file
+ *
+ * @author Qiang Xue <qiang.xue@gmail.com>
+ * @link http://www.pradosoft.com/
* @copyright Copyright &copy; 2005-2012 PradoSoft
- * @license http://www.pradosoft.com/license/
- * @version $Id$
- * @package System.Web.UI.WebControls
- * @since 3.1.2
- */
-
-/**
- * TDataRenderer class
- *
- * TDataRenderer is the convenient base class for template-based renderer controls.
- * It extends {@link TTemplateControl} and implements the methods required
- * by the {@link IDataRenderer} interface.
- *
- * The following property is provided by TDataRenderer:
- * - {@link getData Data}: data associated with this renderer.
-
- * @author Qiang Xue <qiang.xue@gmail.com>
- * @version $Id$
- * @package System.Web.UI.WebControls
- * @since 3.1.2
- */
-abstract class TDataRenderer extends TTemplateControl implements IDataRenderer
-{
- /**
- * @var mixed data associated with this renderer
- */
- private $_data;
-
- /**
- * @return mixed data associated with the item
- */
- public function getData()
- {
- return $this->_data;
- }
-
- /**
- * @param mixed data to be associated with the item
- */
- public function setData($value)
- {
- $this->_data=$value;
- }
-}
-
+ * @license http://www.pradosoft.com/license/
+ * @version $Id$
+ * @package System.Web.UI.WebControls
+ * @since 3.1.2
+ */
+
+/**
+ * TDataRenderer class
+ *
+ * TDataRenderer is the convenient base class for template-based renderer controls.
+ * It extends {@link TTemplateControl} and implements the methods required
+ * by the {@link IDataRenderer} interface.
+ *
+ * The following property is provided by TDataRenderer:
+ * - {@link getData Data}: data associated with this renderer.
+
+ * @author Qiang Xue <qiang.xue@gmail.com>
+ * @version $Id$
+ * @package System.Web.UI.WebControls
+ * @since 3.1.2
+ */
+abstract class TDataRenderer extends TTemplateControl implements IDataRenderer
+{
+ /**
+ * @var mixed data associated with this renderer
+ */
+ private $_data;
+
+ /**
+ * @return mixed data associated with the item
+ */
+ public function getData()
+ {
+ return $this->_data;
+ }
+
+ /**
+ * @param mixed data to be associated with the item
+ */
+ public function setData($value)
+ {
+ $this->_data=$value;
+ }
+}
+
diff --git a/framework/Web/UI/WebControls/TDataSourceControl.php b/framework/Web/UI/WebControls/TDataSourceControl.php
index 0b07810a..f7a224af 100644
--- a/framework/Web/UI/WebControls/TDataSourceControl.php
+++ b/framework/Web/UI/WebControls/TDataSourceControl.php
@@ -1,118 +1,118 @@
-<?php
-/**
- * IDataSource, TDataSourceControl, TReadOnlyDataSource class file
- *
- * @author Qiang Xue <qiang.xue@gmail.com>
- * @link http://www.pradosoft.com/
+<?php
+/**
+ * IDataSource, TDataSourceControl, TReadOnlyDataSource class file
+ *
+ * @author Qiang Xue <qiang.xue@gmail.com>
+ * @link http://www.pradosoft.com/
* @copyright Copyright &copy; 2005-2012 PradoSoft
- * @license http://www.pradosoft.com/license/
- * @version $Id$
- * @package System.Web.UI.WebControls
- */
-
-/**
- * IDataSource class
- *
- * @author Qiang Xue <qiang.xue@gmail.com>
- * @version $Id$
- * @package System.Web.UI.WebControls
- * @since 3.0
- */
-interface IDataSource
-{
- public function getView($viewName);
- public function getViewNames();
- public function onDataSourceChanged($param);
-}
-
-/**
- * TDataSourceControl class
- *
- * @author Qiang Xue <qiang.xue@gmail.com>
- * @version $Id$
- * @package System.Web.UI.WebControls
- * @since 3.0
- */
-abstract class TDataSourceControl extends TControl implements IDataSource
-{
- public function getView($viewName)
- {
- return null;
- }
-
- public function getViewNames()
- {
- return array();
- }
-
- public function onDataSourceChanged($param)
- {
- $this->raiseEvent('OnDataSourceChanged',$this,$param);
- }
-
- public function focus()
- {
- throw new TNotSupportedException('datasourcecontrol_focus_unsupported');
- }
-
- public function getEnableTheming()
- {
- return false;
- }
-
- public function setEnableTheming($value)
- {
- throw new TNotSupportedException('datasourcecontrol_enabletheming_unsupported');
- }
-
- public function getSkinID()
- {
- return '';
- }
-
- public function setSkinID($value)
- {
- throw new TNotSupportedException('datasourcecontrol_skinid_unsupported');
- }
-
- public function getVisible($checkParents=true)
- {
- return false;
- }
-
- public function setVisible($value)
- {
- throw new TNotSupportedException('datasourcecontrol_visible_unsupported');
- }
-}
-
-/**
- * TDataSourceControl class
- *
- * @author Qiang Xue <qiang.xue@gmail.com>
- * @version $Id$
- * @package System.Web.UI.WebControls
- * @since 3.0
- */
-class TReadOnlyDataSource extends TDataSourceControl
-{
- private $_dataSource;
- private $_dataMember;
-
- public function __construct($dataSource,$dataMember)
- {
- if(!is_array($dataSource) && !($dataSource instanceof IDataSource) && !($dataSource instanceof Traversable))
- throw new TInvalidDataTypeException('readonlydatasource_datasource_invalid');
- $this->_dataSource=$dataSource;
- $this->_dataMember=$dataMember;
- }
-
- public function getView($viewName)
- {
- if($this->_dataSource instanceof IDataSource)
- return $this->_dataSource->getView($viewName);
- else
- return new TReadOnlyDataSourceView($this,$this->_dataMember,$this->_dataSource);
- }
-}
-
+ * @license http://www.pradosoft.com/license/
+ * @version $Id$
+ * @package System.Web.UI.WebControls
+ */
+
+/**
+ * IDataSource class
+ *
+ * @author Qiang Xue <qiang.xue@gmail.com>
+ * @version $Id$
+ * @package System.Web.UI.WebControls
+ * @since 3.0
+ */
+interface IDataSource
+{
+ public function getView($viewName);
+ public function getViewNames();
+ public function onDataSourceChanged($param);
+}
+
+/**
+ * TDataSourceControl class
+ *
+ * @author Qiang Xue <qiang.xue@gmail.com>
+ * @version $Id$
+ * @package System.Web.UI.WebControls
+ * @since 3.0
+ */
+abstract class TDataSourceControl extends TControl implements IDataSource
+{
+ public function getView($viewName)
+ {
+ return null;
+ }
+
+ public function getViewNames()
+ {
+ return array();
+ }
+
+ public function onDataSourceChanged($param)
+ {
+ $this->raiseEvent('OnDataSourceChanged',$this,$param);
+ }
+
+ public function focus()
+ {
+ throw new TNotSupportedException('datasourcecontrol_focus_unsupported');
+ }
+
+ public function getEnableTheming()
+ {
+ return false;
+ }
+
+ public function setEnableTheming($value)
+ {
+ throw new TNotSupportedException('datasourcecontrol_enabletheming_unsupported');
+ }
+
+ public function getSkinID()
+ {
+ return '';
+ }
+
+ public function setSkinID($value)
+ {
+ throw new TNotSupportedException('datasourcecontrol_skinid_unsupported');
+ }
+
+ public function getVisible($checkParents=true)
+ {
+ return false;
+ }
+
+ public function setVisible($value)
+ {
+ throw new TNotSupportedException('datasourcecontrol_visible_unsupported');
+ }
+}
+
+/**
+ * TDataSourceControl class
+ *
+ * @author Qiang Xue <qiang.xue@gmail.com>
+ * @version $Id$
+ * @package System.Web.UI.WebControls
+ * @since 3.0
+ */
+class TReadOnlyDataSource extends TDataSourceControl
+{
+ private $_dataSource;
+ private $_dataMember;
+
+ public function __construct($dataSource,$dataMember)
+ {
+ if(!is_array($dataSource) && !($dataSource instanceof IDataSource) && !($dataSource instanceof Traversable))
+ throw new TInvalidDataTypeException('readonlydatasource_datasource_invalid');
+ $this->_dataSource=$dataSource;
+ $this->_dataMember=$dataMember;
+ }
+
+ public function getView($viewName)
+ {
+ if($this->_dataSource instanceof IDataSource)
+ return $this->_dataSource->getView($viewName);
+ else
+ return new TReadOnlyDataSourceView($this,$this->_dataMember,$this->_dataSource);
+ }
+}
+
diff --git a/framework/Web/UI/WebControls/TDataSourceView.php b/framework/Web/UI/WebControls/TDataSourceView.php
index 9e7c0128..af817a32 100644
--- a/framework/Web/UI/WebControls/TDataSourceView.php
+++ b/framework/Web/UI/WebControls/TDataSourceView.php
@@ -1,206 +1,206 @@
-<?php
-/**
- * TDataSourceSelectParameters, TDataSourceView, TReadOnlyDataSourceView class file
- *
- * @author Qiang Xue <qiang.xue@gmail.com>
- * @link http://www.pradosoft.com/
+<?php
+/**
+ * TDataSourceSelectParameters, TDataSourceView, TReadOnlyDataSourceView class file
+ *
+ * @author Qiang Xue <qiang.xue@gmail.com>
+ * @link http://www.pradosoft.com/
* @copyright Copyright &copy; 2005-2012 PradoSoft
- * @license http://www.pradosoft.com/license/
- * @version $Id$
- * @package System.Web.UI.WebControls
- */
-
-/**
- * TDataSourceSelectParameters class
- *
- * @author Qiang Xue <qiang.xue@gmail.com>
- * @version $Id$
- * @package System.Web.UI.WebControls
- * @since 3.0
- */
-class TDataSourceSelectParameters extends TComponent
-{
- private $_retrieveTotalRowCount=false;
- private $_startRowIndex=0;
- private $_totalRowCount=0;
- private $_maximumRows=0;
-
- public function getStartRowIndex()
- {
- return $this->_startRowIndex;
- }
-
- public function setStartRowIndex($value)
- {
- if(($value=TPropertyValue::ensureInteger($value))<0)
- $value=0;
- $this->_startRowIndex=$value;
- }
-
- public function getMaximumRows()
- {
- return $this->_maximumRows;
- }
-
- public function setMaximumRows($value)
- {
- if(($value=TPropertyValue::ensureInteger($value))<0)
- $value=0;
- $this->_maximumRows=$value;
- }
-
- public function getRetrieveTotalRowCount()
- {
- return $this->_retrieveTotalRowCount;
- }
-
- public function setRetrieveTotalRowCount($value)
- {
- $this->_retrieveTotalRowCount=TPropertyValue::ensureBoolean($value);
- }
-
- public function getTotalRowCount()
- {
- return $this->_totalRowCount;
- }
-
- public function setTotalRowCount($value)
- {
- if(($value=TPropertyValue::ensureInteger($value))<0)
- $value=0;
- $this->_totalRowCount=$value;
- }
-}
-
-/**
- * TDataSourceView class
- *
- * @author Qiang Xue <qiang.xue@gmail.com>
- * @version $Id$
- * @package System.Web.UI.WebControls
- * @since 3.0
- */
-abstract class TDataSourceView extends TComponent
-{
- private $_owner;
- private $_name;
-
- public function __construct(IDataSource $owner,$viewName)
- {
- $this->_owner=$owner;
- $this->_name=$viewName;
- }
-
- /**
- * Performs DB selection based on specified parameters.
- * @param ???
- * @return Traversable
- */
- abstract public function select($parameters);
-
- /**
- * Inserts a DB record.
- * @param array|TMap
- * @return integer affected rows
- */
- public function insertAt($values)
- {
- throw new TNotSupportedException('datasourceview_insert_unsupported');
- }
-
- /**
- * Updates DB record(s) with the specified keys and new values
- * @param array|TMap keys for specifying the records to be updated
- * @param array|TMap new values
- * @return integer affected rows
- */
- public function update($keys,$values)
- {
- throw new TNotSupportedException('datasourceview_update_unsupported');
- }
-
- /**
- * Deletes DB row(s) with the specified keys.
- * @param array|TMap keys for specifying the rows to be deleted
- * @return integer affected rows
- */
- public function delete($keys)
- {
- throw new TNotSupportedException('datasourceview_delete_unsupported');
- }
-
- public function getCanDelete()
- {
- return false;
- }
-
- public function getCanInsert()
- {
- return false;
- }
-
- public function getCanPage()
- {
- return false;
- }
-
- public function getCanGetRowCount()
- {
- return false;
- }
-
- public function getCanSort()
- {
- return false;
- }
-
- public function getCanUpdate()
- {
- return false;
- }
-
- public function getName()
- {
- return $this->_name;
- }
-
- public function getDataSource()
- {
- return $this->_owner;
- }
-
- public function onDataSourceViewChanged($param)
- {
- $this->raiseEvent('OnDataSourceViewChanged',$this,$param);
- }
-}
-
-/**
- * TReadOnlyDataSourceView class
- *
- * @author Qiang Xue <qiang.xue@gmail.com>
- * @version $Id$
- * @package System.Web.UI.WebControls
- * @since 3.0
- */
-class TReadOnlyDataSourceView extends TDataSourceView
-{
- private $_dataSource=null;
-
- public function __construct(IDataSource $owner,$viewName,$dataSource)
- {
- parent::__construct($owner,$viewName);
- if($dataSource===null || is_array($dataSource))
- $this->_dataSource=new TMap($dataSource);
- else if($dataSource instanceof Traversable)
- $this->_dataSource=$dataSource;
- else
- throw new TInvalidDataTypeException('readonlydatasourceview_datasource_invalid');
- }
-
- public function select($parameters)
- {
- return $this->_dataSource;
- }
-}
-
+ * @license http://www.pradosoft.com/license/
+ * @version $Id$
+ * @package System.Web.UI.WebControls
+ */
+
+/**
+ * TDataSourceSelectParameters class
+ *
+ * @author Qiang Xue <qiang.xue@gmail.com>
+ * @version $Id$
+ * @package System.Web.UI.WebControls
+ * @since 3.0
+ */
+class TDataSourceSelectParameters extends TComponent
+{
+ private $_retrieveTotalRowCount=false;
+ private $_startRowIndex=0;
+ private $_totalRowCount=0;
+ private $_maximumRows=0;
+
+ public function getStartRowIndex()
+ {
+ return $this->_startRowIndex;
+ }
+
+ public function setStartRowIndex($value)
+ {
+ if(($value=TPropertyValue::ensureInteger($value))<0)
+ $value=0;
+ $this->_startRowIndex=$value;
+ }
+
+ public function getMaximumRows()
+ {
+ return $this->_maximumRows;
+ }
+
+ public function setMaximumRows($value)
+ {
+ if(($value=TPropertyValue::ensureInteger($value))<0)
+ $value=0;
+ $this->_maximumRows=$value;
+ }
+
+ public function getRetrieveTotalRowCount()
+ {
+ return $this->_retrieveTotalRowCount;
+ }
+
+ public function setRetrieveTotalRowCount($value)
+ {
+ $this->_retrieveTotalRowCount=TPropertyValue::ensureBoolean($value);
+ }
+
+ public function getTotalRowCount()
+ {
+ return $this->_totalRowCount;
+ }
+
+ public function setTotalRowCount($value)
+ {
+ if(($value=TPropertyValue::ensureInteger($value))<0)
+ $value=0;
+ $this->_totalRowCount=$value;
+ }
+}
+
+/**
+ * TDataSourceView class
+ *
+ * @author Qiang Xue <qiang.xue@gmail.com>
+ * @version $Id$
+ * @package System.Web.UI.WebControls
+ * @since 3.0
+ */
+abstract class TDataSourceView extends TComponent
+{
+ private $_owner;
+ private $_name;
+
+ public function __construct(IDataSource $owner,$viewName)
+ {
+ $this->_owner=$owner;
+ $this->_name=$viewName;
+ }
+
+ /**
+ * Performs DB selection based on specified parameters.
+ * @param ???
+ * @return Traversable
+ */
+ abstract public function select($parameters);
+
+ /**
+ * Inserts a DB record.
+ * @param array|TMap
+ * @return integer affected rows
+ */
+ public function insertAt($values)
+ {
+ throw new TNotSupportedException('datasourceview_insert_unsupported');
+ }
+
+ /**
+ * Updates DB record(s) with the specified keys and new values
+ * @param array|TMap keys for specifying the records to be updated
+ * @param array|TMap new values
+ * @return integer affected rows
+ */
+ public function update($keys,$values)
+ {
+ throw new TNotSupportedException('datasourceview_update_unsupported');
+ }
+
+ /**
+ * Deletes DB row(s) with the specified keys.
+ * @param array|TMap keys for specifying the rows to be deleted
+ * @return integer affected rows
+ */
+ public function delete($keys)
+ {
+ throw new TNotSupportedException('datasourceview_delete_unsupported');
+ }
+
+ public function getCanDelete()
+ {
+ return false;
+ }
+
+ public function getCanInsert()
+ {
+ return false;
+ }
+
+ public function getCanPage()
+ {
+ return false;
+ }
+
+ public function getCanGetRowCount()
+ {
+ return false;
+ }
+
+ public function getCanSort()
+ {
+ return false;
+ }
+
+ public function getCanUpdate()
+ {
+ return false;
+ }
+
+ public function getName()
+ {
+ return $this->_name;
+ }
+
+ public function getDataSource()
+ {
+ return $this->_owner;
+ }
+
+ public function onDataSourceViewChanged($param)
+ {
+ $this->raiseEvent('OnDataSourceViewChanged',$this,$param);
+ }
+}
+
+/**
+ * TReadOnlyDataSourceView class
+ *
+ * @author Qiang Xue <qiang.xue@gmail.com>
+ * @version $Id$
+ * @package System.Web.UI.WebControls
+ * @since 3.0
+ */
+class TReadOnlyDataSourceView extends TDataSourceView
+{
+ private $_dataSource=null;
+
+ public function __construct(IDataSource $owner,$viewName,$dataSource)
+ {
+ parent::__construct($owner,$viewName);
+ if($dataSource===null || is_array($dataSource))
+ $this->_dataSource=new TMap($dataSource);
+ else if($dataSource instanceof Traversable)
+ $this->_dataSource=$dataSource;
+ else
+ throw new TInvalidDataTypeException('readonlydatasourceview_datasource_invalid');
+ }
+
+ public function select($parameters)
+ {
+ return $this->_dataSource;
+ }
+}
+
diff --git a/framework/Web/UI/WebControls/TDataTypeValidator.php b/framework/Web/UI/WebControls/TDataTypeValidator.php
index 24372565..0e412e24 100644
--- a/framework/Web/UI/WebControls/TDataTypeValidator.php
+++ b/framework/Web/UI/WebControls/TDataTypeValidator.php
@@ -1,141 +1,141 @@
-<?php
-/**
- * TDataTypeValidator class.
- *
- * @author Wei Zhuo <weizhuo[at]gmail[dot]com>
- * @link http://www.pradosoft.com/
+<?php
+/**
+ * TDataTypeValidator class.
+ *
+ * @author Wei Zhuo <weizhuo[at]gmail[dot]com>
+ * @link http://www.pradosoft.com/
* @copyright Copyright &copy; 2005-2012 PradoSoft
- * @license http://www.pradosoft.com/license/
- * @version $Id$
- * @package System.Web.UI.WebControls
- */
-
-/**
- * Using TBaseValidator class
- */
-Prado::using('System.Web.UI.WebControls.TBaseValidator');
-
-/**
- * TDataTypeValidator class
- *
- * TDataTypeValidator verifies if the input data is of the type specified
- * by {@link setDataType DataType}.
- * The following data types are supported:
- * - <b>Integer</b> A 32-bit signed integer data type.
- * - <b>Float</b> A double-precision floating point number data type.
- * - <b>Date</b> A date data type.
- * - <b>String</b> A string data type.
- * For <b>Date</b> type, the property {@link setDateFormat DateFormat}
- * will be used to determine how to parse the date string. If it is not
- * provided, the string will be assumed to be in GNU datetime format.
- *
- * @author Wei Zhuo <weizhuo[at]gmail[dot]com>
- * @version $Id$
- * @package System.Web.UI.WebControls
- * @since 3.0
- */
-class TDataTypeValidator extends TBaseValidator
-{
- /**
- * Gets the name of the javascript class responsible for performing validation for this control.
- * This method overrides the parent implementation.
- * @return string the javascript class name
- */
- protected function getClientClassName()
- {
- return 'Prado.WebUI.TDataTypeValidator';
- }
-
- /**
- * @return TValidationDataType the data type that the values being compared are converted to before the comparison is made. Defaults to TValidationDataType::String.
- */
- public function getDataType()
- {
- return $this->getViewState('DataType','String');
- }
-
- /**
- * Sets the data type that the values being compared are converted to before the comparison is made.
- * @param TValidationDataType the data type
- */
- public function setDataType($value)
- {
- $this->setViewState('DataType',TPropertyValue::ensureEnum($value,'TValidationDataType'),TValidationDataType::String);
- }
-
- /**
- * Sets the date format for a date validation
- * @param string the date format value
- */
- public function setDateFormat($value)
- {
- $this->setViewState('DateFormat', $value, '');
- }
-
- /**
- * @return string the date validation date format if any
- */
- public function getDateFormat()
- {
- return $this->getViewState('DateFormat', '');
- }
-
-
- /**
- * Determine if the given value is of a particular type using RegExp.
- * @param string value to check
- * @return boolean true if value fits the type expression.
- */
- protected function evaluateDataTypeCheck($value)
- {
- if($value=='')
- return true;
-
- switch($this->getDataType())
- {
- case TValidationDataType::Integer:
- return preg_match('/^[-+]?[0-9]+$/',trim($value));
- case TValidationDataType::Float:
- return preg_match('/^[-+]?([0-9]*\.)?[0-9]+([eE][-+]?[0-9]+)?$/',trim($value));
- case TValidationDataType::Date:
- $dateFormat = $this->getDateFormat();
- if(strlen($dateFormat))
- {
- $formatter = Prado::createComponent('System.Util.TSimpleDateFormatter',$dateFormat);
- return $formatter->isValidDate($value);
- }
- else
- return strtotime($value) > 0;
- }
- return true;
- }
-
- /**
- * Returns an array of javascript validator options.
- * @return array javascript validator options.
- */
- protected function getClientScriptOptions()
- {
- $options = parent::getClientScriptOptions();
- $options['DataType']=$this->getDataType();
- if(($dateFormat=$this->getDateFormat())!=='')
- $options['DateFormat']=$dateFormat;
- return $options;
- }
-
- /**
- * This method overrides the parent's implementation.
- * The validation succeeds if the input data is of valid type.
- * The validation always succeeds if ControlToValidate is not specified
- * or the input data is empty.
- * @return boolean whether the validation succeeds
- */
- public function evaluateIsValid()
- {
- if(($value=$this->getValidationValue($this->getValidationTarget()))==='')
- return true;
-
- return $this->evaluateDataTypeCheck($value);
- }
-}
-
+ * @license http://www.pradosoft.com/license/
+ * @version $Id$
+ * @package System.Web.UI.WebControls
+ */
+
+/**
+ * Using TBaseValidator class
+ */
+Prado::using('System.Web.UI.WebControls.TBaseValidator');
+
+/**
+ * TDataTypeValidator class
+ *
+ * TDataTypeValidator verifies if the input data is of the type specified
+ * by {@link setDataType DataType}.
+ * The following data types are supported:
+ * - <b>Integer</b> A 32-bit signed integer data type.
+ * - <b>Float</b> A double-precision floating point number data type.
+ * - <b>Date</b> A date data type.
+ * - <b>String</b> A string data type.
+ * For <b>Date</b> type, the property {@link setDateFormat DateFormat}
+ * will be used to determine how to parse the date string. If it is not
+ * provided, the string will be assumed to be in GNU datetime format.
+ *
+ * @author Wei Zhuo <weizhuo[at]gmail[dot]com>
+ * @version $Id$
+ * @package System.Web.UI.WebControls
+ * @since 3.0
+ */
+class TDataTypeValidator extends TBaseValidator
+{
+ /**
+ * Gets the name of the javascript class responsible for performing validation for this control.
+ * This method overrides the parent implementation.
+ * @return string the javascript class name
+ */
+ protected function getClientClassName()
+ {
+ return 'Prado.WebUI.TDataTypeValidator';
+ }
+
+ /**
+ * @return TValidationDataType the data type that the values being compared are converted to before the comparison is made. Defaults to TValidationDataType::String.
+ */
+ public function getDataType()
+ {
+ return $this->getViewState('DataType','String');
+ }
+
+ /**
+ * Sets the data type that the values being compared are converted to before the comparison is made.
+ * @param TValidationDataType the data type
+ */
+ public function setDataType($value)
+ {
+ $this->setViewState('DataType',TPropertyValue::ensureEnum($value,'TValidationDataType'),TValidationDataType::String);
+ }
+
+ /**
+ * Sets the date format for a date validation
+ * @param string the date format value
+ */
+ public function setDateFormat($value)
+ {
+ $this->setViewState('DateFormat', $value, '');
+ }
+
+ /**
+ * @return string the date validation date format if any
+ */
+ public function getDateFormat()
+ {
+ return $this->getViewState('DateFormat', '');
+ }
+
+
+ /**
+ * Determine if the given value is of a particular type using RegExp.
+ * @param string value to check
+ * @return boolean true if value fits the type expression.
+ */
+ protected function evaluateDataTypeCheck($value)
+ {
+ if($value=='')
+ return true;
+
+ switch($this->getDataType())
+ {
+ case TValidationDataType::Integer:
+ return preg_match('/^[-+]?[0-9]+$/',trim($value));
+ case TValidationDataType::Float:
+ return preg_match('/^[-+]?([0-9]*\.)?[0-9]+([eE][-+]?[0-9]+)?$/',trim($value));
+ case TValidationDataType::Date:
+ $dateFormat = $this->getDateFormat();
+ if(strlen($dateFormat))
+ {
+ $formatter = Prado::createComponent('System.Util.TSimpleDateFormatter',$dateFormat);
+ return $formatter->isValidDate($value);
+ }
+ else
+ return strtotime($value) > 0;
+ }
+ return true;
+ }
+
+ /**
+ * Returns an array of javascript validator options.
+ * @return array javascript validator options.
+ */
+ protected function getClientScriptOptions()
+ {
+ $options = parent::getClientScriptOptions();
+ $options['DataType']=$this->getDataType();
+ if(($dateFormat=$this->getDateFormat())!=='')
+ $options['DateFormat']=$dateFormat;
+ return $options;
+ }
+
+ /**
+ * This method overrides the parent's implementation.
+ * The validation succeeds if the input data is of valid type.
+ * The validation always succeeds if ControlToValidate is not specified
+ * or the input data is empty.
+ * @return boolean whether the validation succeeds
+ */
+ public function evaluateIsValid()
+ {
+ if(($value=$this->getValidationValue($this->getValidationTarget()))==='')
+ return true;
+
+ return $this->evaluateDataTypeCheck($value);
+ }
+}
+
diff --git a/framework/Web/UI/WebControls/TDatePicker.php b/framework/Web/UI/WebControls/TDatePicker.php
index 8d1a811c..866bc585 100644
--- a/framework/Web/UI/WebControls/TDatePicker.php
+++ b/framework/Web/UI/WebControls/TDatePicker.php
@@ -1,993 +1,993 @@
-<?php
-/**
- * TDatePicker class file.
- *
- * @author Wei Zhuo <weizhuo[at]gmail[dot]com>
- * @link http://www.pradosoft.com/
- * @copyright Copyright &copy; 2005-2012 PradoSoft
- * @license http://www.pradosoft.com/license/
- * @version $Id$
- * @package System.Web.UI.WebControls
- */
-
-/**
- * Includes TTextBox class
- */
-Prado::using('System.Web.UI.WebControls.TTextBox');
-
-/**
- *
- * TDatePicker class.
- *
- * TDatePicker displays a text box for date input purpose.
- * When the text box receives focus, a calendar will pop up and users can
- * pick up from it a date that will be automatically entered into the text box.
- * The format of the date string displayed in the text box is determined by
- * the <b>DateFormat</b> property. Valid formats are the combination of the
- * following tokens,
- *
- * <code>
- * Character Format Pattern (en-US)
- * -----------------------------------------
- * d day digit
- * dd padded day digit e.g. 01, 02
- * M month digit
- * MM padded month digit
- * MMMM localized month name, e.g. March, April
- * yy 2 digit year
- * yyyy 4 digit year
- * -----------------------------------------
- * </code>
- *
- * TDatePicker has four <b>Mode</b> to show the date picker popup.
- *
- * # <b>Basic</b> -- Only shows a text input, focusing on the input shows the
- * date picker. This way you can access the popup using only
- * the keyboard. Note that because of this, TAB-bing through
- * this control will automatically select the current date if
- * no previous date was selected. If you close the popup (eg.
- * pressing the ESC key) you'll need to un-focus and re-focus
- * the control again for the popup to reappear.
- * # <b>Clickable</b> -- Only shows a text input, clicking on the input shows the
- * date picker. This mode solves the two small problems of the
- * Basic mode. It was first introduced in Prado 3.2.
- * # <b>Button</b> -- Shows a button next to the text input, clicking on the
- * button shows the date, button text can be by the
- * <b>ButtonText</b> property
- * # <b>ImageButton</b> -- Shows an image next to the text input, clicking on
- * the image shows the date picker, image source can be
- * change through the <b>ButtonImageUrl</b> property.
- *
- * The <b>CssClass</b> property can be used to override the css class name
- * for the date picker panel. <b>CalendarStyle</b> property sets the packages
- * styles available. E.g. <b>default</b>.
- *
- * The <b>InputMode</b> property can be set to "TextBox" or "DropDownList" with
- * default as "TextBox".
- * In <b>DropDownList</b> mode, in addition to the popup date picker, three
- * drop down list (day, month and year) are presented to select the date .
- *
- * The <b>PositionMode</b> property can be set to "Top" or "Bottom" with default
- * as "Bottom". It specifies the position of the calendar popup, relative to the
- * input field.
- *
- * @author Wei Zhuo <weizhuo[at]gmail[dot]com>
- * @author Carl G. Mathisen <carlgmathisen@gmail.com>
- * @version $Id$
- * @package System.Web.UI.WebControls
- * @since 3.0
- */
-class TDatePicker extends TTextBox
-{
- /**
- * Script path relative to the TClientScriptManager::SCRIPT_PATH
- */
- const SCRIPT_PATH = 'prado/datepicker';
-
- /**
- * @var TDatePickerClientScript validator client-script options.
- */
- private $_clientScript;
- /**
- * AutoPostBack is not supported.
- */
- public function setAutoPostBack($value)
- {
- throw new TNotSupportedException('tdatepicker_autopostback_unsupported',
- get_class($this));
- }
-
- /**
- * @return string the format of the date string
- */
- public function getDateFormat()
- {
- return $this->getViewState('DateFormat','dd-MM-yyyy');
- }
-
- /**
- * Sets the format of the date string.
- * @param string the format of the date string
- */
- public function setDateFormat($value)
- {
- $this->setViewState('DateFormat',$value,'dd-MM-yyyy');
- }
-
- /**
- * @return boolean whether the calendar window should pop up when the control receives focus
- */
- public function getShowCalendar()
- {
- return $this->getViewState('ShowCalendar',true);
- }
-
- /**
- * Sets whether to pop up the calendar window when the control receives focus
- * @param boolean whether to show the calendar window
- */
- public function setShowCalendar($value)
- {
- $this->setViewState('ShowCalendar',TPropertyValue::ensureBoolean($value),true);
- }
-
- /**
- * Gets the current culture.
- * @return string current culture, e.g. en_AU.
- */
- public function getCulture()
- {
- return $this->getViewState('Culture', '');
- }
-
- /**
- * Sets the culture/language for the date picker.
- * @param string a culture string, e.g. en_AU.
- */
- public function setCulture($value)
- {
- $this->setViewState('Culture', $value, '');
- }
-
- /**
- * @param TDatePickerInputMode input method of date values
- */
- public function setInputMode($value)
- {
- $this->setViewState('InputMode', TPropertyValue::ensureEnum($value, 'TDatePickerInputMode'), TDatePickerInputMode::TextBox);
- }
-
- /**
- * @return TDatePickerInputMode input method of date values. Defaults to TDatePickerInputMode::TextBox.
- */
- public function getInputMode()
- {
- return $this->getViewState('InputMode', TDatePickerInputMode::TextBox);
- }
-
- /**
- * @param TDatePickerMode calendar UI mode
- */
- public function setMode($value)
- {
- $this->setViewState('Mode', TPropertyValue::ensureEnum($value, 'TDatePickerMode'), TDatePickerMode::Basic);
- }
-
- /**
- * @return TDatePickerMode current calendar UI mode.
- */
- public function getMode()
- {
- return $this->getViewState('Mode', TDatePickerMode::Basic);
- }
- /**
- * @param string the image url for "Image" UI mode.
- */
- public function setButtonImageUrl($value)
- {
- $this->setViewState('ImageUrl', $value, '');
- }
-
- /**
- * @return string the image url for "Image" UI mode.
- */
- public function getButtonImageUrl()
- {
- return $this->getViewState('ImageUrl', '');
- }
-
- /**
- * @param string set the calendar style
- */
- public function setCalendarStyle($value)
- {
- $this->setViewState('CalendarStyle', $value, 'default');
- }
-
- /**
- * @return string current calendar style
- */
- public function getCalendarStyle()
- {
- return $this->getViewState('CalendarStyle', 'default');
- }
-
- /**
- * Set the first day of week, with 0 as Sunday, 1 as Monday, etc.
- * @param integer 0 for Sunday, 1 for Monday, 2 for Tuesday, etc.
- */
- public function setFirstDayOfWeek($value)
- {
- $this->setViewState('FirstDayOfWeek', TPropertyValue::ensureInteger($value), 1);
- }
-
- /**
- * @return integer first day of the week
- */
- public function getFirstDayOfWeek()
- {
- return $this->getViewState('FirstDayOfWeek', 1);
- }
-
- /**
- * @return string text for the date picker button. Default is "...".
- */
- public function getButtonText()
- {
- return $this->getViewState('ButtonText', '...');
- }
-
- /**
- * @param string text for the date picker button
- */
- public function setButtonText($value)
- {
- $this->setViewState('ButtonText', $value, '...');
- }
-
- /**
- * @param integer date picker starting year, default is 2000.
- */
- public function setFromYear($value)
- {
- $this->setViewState('FromYear', TPropertyValue::ensureInteger($value), intval(@date('Y'))-5);
- }
-
- /**
- * @return integer date picker starting year, default is -5 years
- */
- public function getFromYear()
- {
- return $this->getViewState('FromYear', intval(@date('Y'))-5);
- }
-
- /**
- * @param integer date picker ending year, default +10 years
- */
- public function setUpToYear($value)
- {
- $this->setViewState('UpToYear', TPropertyValue::ensureInteger($value), intval(@date('Y'))+10);
- }
-
- /**
- * @return integer date picker ending year, default +10 years
- */
- public function getUpToYear()
- {
- return $this->getViewState('UpToYear', intval(@date('Y'))+10);
- }
-
- /**
- * @param TDatePickerPositionMode calendar UI position
- */
- public function setPositionMode($value)
- {
- $this->setViewState('PositionMode', TPropertyValue::ensureEnum($value, 'TDatePickerPositionMode'), TDatePickerPositionMode::Bottom);
- }
-
- /**
- * @return TDatePickerPositionMode current calendar UI position.
- */
- public function getPositionMode()
- {
- return $this->getViewState('PositionMode', TDatePickerPositionMode::Bottom);
- }
-
- /**
- * @return integer current selected date from the date picker as timestamp, NULL if timestamp is not set previously.
- */
- public function getTimeStamp()
- {
- if(trim($this->getText())==='')
- return null;
- else
- return $this->getTimeStampFromText();
- }
-
- /**
- * Sets the date for the date picker using timestamp.
- * @param float time stamp for the date picker
- */
- public function setTimeStamp($value)
- {
- if($value===null || (is_string($value) && trim($value)===''))
- $this->setText('');
- else
- {
- $date = TPropertyValue::ensureFloat($value);
- $formatter = Prado::createComponent('System.Util.TSimpleDateFormatter',$this->getDateFormat());
- $this->setText($formatter->format($date));
- }
- }
-
- /**
- * Returns the timestamp selected by the user.
- * This method is required by {@link IDataRenderer}.
- * It is the same as {@link getTimeStamp()}.
- * @return integer the timestamp of the TDatePicker control.
- * @see getTimeStamp
- * @since 3.1.2
- */
- public function getData()
- {
- return $this->getTimeStamp();
- }
-
- /**
- * Sets the timestamp represented by this control.
- * This method is required by {@link IDataRenderer}.
- * It is the same as {@link setTimeStamp()}.
- * @param integer the timestamp of the TDatePicker control.
- * @see setTimeStamp
- * @since 3.1.2
- */
- public function setData($value)
- {
- $this->setTimeStamp($value);
- }
-
- /**
- * @return string the date string.
- */
- public function getDate()
- {
- return $this->getText();
- }
-
- /**
- * @param string date string
- */
- public function setDate($value)
- {
- $this->setText($value);
- }
-
- /**
- * Gets the TDatePickerClientScript to set the TDatePicker event handlers.
- *
- * The date picker on the client-side supports the following events.
- * # <tt>OnDateChanged</tt> -- raised when the date is changed.
- *
- * You can attach custom javascript code to each of these events
- *
- * @return TDatePickerClientScript javascript validator event options.
- */
- public function getClientSide()
- {
- if($this->_clientScript===null)
- $this->_clientScript = $this->createClientScript();
- return $this->_clientScript;
- }
-
- /**
- * @return TDatePickerClientScript javascript validator event options.
- */
- protected function createClientScript()
- {
- return new TDatePickerClientScript;
- }
-
- /**
- * Returns the value to be validated.
- * This methid is required by IValidatable interface.
- * @return integer the interger timestamp if valid, otherwise the original text.
- */
- public function getValidationPropertyValue()
- {
- if(($text = $this->getText()) === '')
- return '';
- $date = $this->getTimeStamp();
- return $date == null ? $text : $date;
- }
-
- /**
- * Publish the date picker Css asset files.
- */
- public function onPreRender($param)
- {
- parent::onPreRender($param);
- if($this->getInputMode() === TDatePickerInputMode::DropDownList)
- {
- $page = $this->getPage();
- $uniqueID = $this->getUniqueID();
- $page->registerPostDataLoader($uniqueID.TControl::ID_SEPARATOR.'day');
- $page->registerPostDataLoader($uniqueID.TControl::ID_SEPARATOR.'month');
- $page->registerPostDataLoader($uniqueID.TControl::ID_SEPARATOR.'year');
- }
- $this->publishCalendarStyle();
- $this->registerCalendarClientScriptPre();
- }
-
- /**
- * Renders body content.
- * This method overrides parent implementation by adding
- * additional date picker button if Mode is Button or ImageButton.
- * @param THtmlWriter writer
- */
- public function render($writer)
- {
- if($this->getInputMode() == TDatePickerInputMode::TextBox)
- {
- parent::render($writer);
- $this->renderDatePickerButtons($writer);
- }
- else
- {
- $this->renderDropDownListCalendar($writer);
- if($this->hasDayPattern())
- {
- $this->registerCalendarClientScriptPost();
- $this->renderDatePickerButtons($writer);
- }
- }
- }
-
- /**
- * Renders the date picker popup buttons.
- */
- protected function renderDatePickerButtons($writer)
- {
- if($this->getShowCalendar())
- {
- switch ($this->getMode())
- {
- case TDatePickerMode::Button:
- $this->renderButtonDatePicker($writer);
- break;
- case TDatePickerMode::ImageButton :
- $this->renderImageButtonDatePicker($writer);
- break;
- }
- }
- }
-
- /**
- * Loads user input data. Override parent implementation, when InputMode
- * is DropDownList call getDateFromPostData to get date data.
- * This method is primarly used by framework developers.
- * @param string the key that can be used to retrieve data from the input data collection
- * @param array the input data collection
- * @return boolean whether the data of the component has been changed
- */
- public function loadPostData($key,$values)
- {
- if($this->getInputMode() == TDatePickerInputMode::TextBox)
- return parent::loadPostData($key, $values);
- $value = $this->getDateFromPostData($key, $values);
- if(!$this->getReadOnly() && $this->getText()!==$value)
- {
- $this->setText($value);
- return true;
- }
- else
- return false;
- }
-
- /**
- * Loads date from drop down list data.
- * @param string the key that can be used to retrieve data from the input data collection
- * @param array the input data collection
- * @return array the date selected
- */
- protected function getDateFromPostData($key, $values)
- {
- $date = @getdate();
-
- if(isset($values[$key.'$day']))
- $day = intval($values[$key.'$day']);
- else
- $day = $date['mday'];
-
- if(isset($values[$key.'$month']))
- $month = intval($values[$key.'$month']) + 1;
- else
- $month = $date['mon'];
-
- if(isset($values[$key.'$year']))
- $year = intval($values[$key.'$year']);
- else
- $year = $date['year'];
-
- $s = Prado::createComponent('System.Util.TDateTimeStamp');
- $date = $s->getTimeStamp(0, 0, 0, $month, $day, $year);
- //$date = @mktime(0, 0, 0, $month, $day, $year);
-
- $pattern = $this->getDateFormat();
- $pattern = str_replace(array('MMMM', 'MMM'), array('MM','MM'), $pattern);
- $formatter = Prado::createComponent('System.Util.TSimpleDateFormatter', $pattern);
- return $formatter->format($date);
- }
-
- /**
- * Get javascript date picker options.
- * @return array date picker client-side options
- */
- protected function getDatePickerOptions()
- {
- $options['ID'] = $this->getClientID();
- $options['InputMode'] = $this->getInputMode();
- $options['Format'] = $this->getDateFormat();
- $options['FirstDayOfWeek'] = $this->getFirstDayOfWeek();
- if(($cssClass=$this->getCssClass())!=='')
- $options['ClassName'] = $cssClass;
- $options['CalendarStyle'] = $this->getCalendarStyle();
- $options['FromYear'] = $this->getFromYear();
- $options['UpToYear'] = $this->getUpToYear();
- switch($this->getMode())
- {
- case TDatePickerMode::Basic:
- break;
- case TDatePickerMode::Clickable:
- $options['TriggerEvent'] = "click";
- break;
- default:
- $options['Trigger'] = $this->getDatePickerButtonID();
- break;
- }
- $options['PositionMode'] = $this->getPositionMode();
-
- $options = array_merge($options, $this->getCulturalOptions());
- if($this->_clientScript!==null)
- $options = array_merge($options,
- $this->_clientScript->getOptions()->toArray());
- return $options;
- }
-
- /**
- * Get javascript localization options, e.g. month and weekday names.
- * @return array localization options.
- */
- protected function getCulturalOptions()
- {
- if($this->getCurrentCulture() == 'en')
- return array();
-
- $date = $this->getLocalizedCalendarInfo();
- $options['MonthNames'] = $date->getMonthNames();
- $options['AbbreviatedMonthNames'] = $date->getAbbreviatedMonthNames();
- $options['ShortWeekDayNames'] = $date->getAbbreviatedDayNames();
-
- return $options;
- }
-
- /**
- * @return string the current culture, falls back to application if culture is not set.
- */
- protected function getCurrentCulture()
- {
- $app = $this->getApplication()->getGlobalization(false);
- return $this->getCulture() == '' ?
- ($app ? $app->getCulture() : 'en') : $this->getCulture();
- }
-
- /**
- * @return DateTimeFormatInfo date time format information for the current culture.
- */
- protected function getLocalizedCalendarInfo()
- {
- //expensive operations
- $culture = $this->getCurrentCulture();
- Prado::using('System.I18N.core.DateTimeFormatInfo');
- $info = Prado::createComponent('System.I18N.core.CultureInfo', $culture);
- return $info->getDateTimeFormat();
- }
-
- /**
- * Renders the drop down list date picker.
- */
- protected function renderDropDownListCalendar($writer)
- {
- if($this->getMode() == TDatePickerMode::Basic)
- $this->setMode(TDatePickerMode::ImageButton);
- parent::addAttributesToRender($writer);
- $writer->removeAttribute('name');
- $writer->removeAttribute('type');
- $writer->addAttribute('id', $this->getClientID());
-
- if(strlen($class = $this->getCssClass()) > 0)
- $writer->addAttribute('class', $class);
- $writer->renderBeginTag('span');
-
- $s = Prado::createComponent('System.Util.TDateTimeStamp');
- $date = $s->getDate($this->getTimeStampFromText());
- //$date = @getdate($this->getTimeStampFromText());
-
- $this->renderCalendarSelections($writer, $date);
-
- //render a hidden input field
- $writer->addAttribute('name', $this->getUniqueID());
- $writer->addAttribute('type', 'hidden');
- $writer->addAttribute('value', $this->getText());
- $writer->renderBeginTag('input');
-
- $writer->renderEndTag();
- $writer->renderEndTag();
- }
-
- protected function hasDayPattern()
- {
- $formatter = Prado::createComponent('System.Util.TSimpleDateFormatter',
- $this->getDateFormat());
- return ($formatter->getDayPattern()!==null);
- }
-
- /**
- * Renders the calendar drop down list depending on the DateFormat pattern.
- * @param THtmlWriter the Html writer to render the drop down lists.
- * @param array the current selected date
- */
- protected function renderCalendarSelections($writer, $date)
- {
- $formatter = Prado::createComponent('System.Util.TSimpleDateFormatter',
- $this->getDateFormat());
-
- foreach($formatter->getDayMonthYearOrdering() as $type)
- {
- if($type == 'day')
- $this->renderCalendarDayOptions($writer,$date['mday']);
- elseif($type == 'month')
- $this->renderCalendarMonthOptions($writer,$date['mon']);
- elseif($type == 'year')
- $this->renderCalendarYearOptions($writer,$date['year']);
- }
- }
-
- /**
- * Gets the date from the text input using TSimpleDateFormatter
- * @return integer current selected date timestamp
- */
- protected function getTimeStampFromText()
- {
- $pattern = $this->getDateFormat();
- $pattern = str_replace(array('MMMM', 'MMM'), array('MM','MM'), $pattern);
- $formatter = Prado::createComponent('System.Util.TSimpleDateFormatter',$pattern);
- return $formatter->parse($this->getText());
- }
-
- /**
- * Renders a drop down lists.
- * @param THtmlWriter the writer used for the rendering purpose
- * @param array list of selection options
- * @param mixed selected key.
- */
- private function renderDropDownListOptions($writer,$options,$selected=null)
- {
- foreach($options as $k => $v)
- {
- $writer->addAttribute('value', $k);
- if($k == $selected)
- $writer->addAttribute('selected', 'selected');
- $writer->renderBeginTag('option');
- $writer->write($v);
- $writer->renderEndTag();
- }
- }
-
- /**
- * Renders the day drop down list options.
- * @param THtmlWriter the writer used for the rendering purpose
- * @param mixed selected day.
- */
- protected function renderCalendarDayOptions($writer, $selected=null)
- {
- $days = $this->getDropDownDayOptions();
- $writer->addAttribute('id', $this->getClientID().TControl::CLIENT_ID_SEPARATOR.'day');
- $writer->addAttribute('name', $this->getUniqueID().TControl::ID_SEPARATOR.'day');
- $writer->addAttribute('class', 'datepicker_day_options');
- if($this->getReadOnly() || !$this->getEnabled(true))
- $writer->addAttribute('disabled', 'disabled');
- $writer->renderBeginTag('select');
- $this->renderDropDownListOptions($writer, $days, $selected);
- $writer->renderEndTag();
- }
-
- /**
- * @return array list of day options for a drop down list.
- */
- protected function getDropDownDayOptions()
- {
- $formatter = Prado::createComponent('System.Util.TSimpleDateFormatter',
- $this->getDateFormat());
- $days = array();
- $requiresPadding = $formatter->getDayPattern() === 'dd';
- for($i=1;$i<=31;$i++)
- {
- $days[$i] = $requiresPadding ? str_pad($i, 2, '0', STR_PAD_LEFT) : $i;
- }
- return $days;
- }
-
- /**
- * Renders the month drop down list options.
- * @param THtmlWriter the writer used for the rendering purpose
- * @param mixed selected month.
- */
- protected function renderCalendarMonthOptions($writer, $selected=null)
- {
- $info = $this->getLocalizedCalendarInfo();
- $writer->addAttribute('id', $this->getClientID().TControl::CLIENT_ID_SEPARATOR.'month');
- $writer->addAttribute('name', $this->getUniqueID().TControl::ID_SEPARATOR.'month');
- $writer->addAttribute('class', 'datepicker_month_options');
- if($this->getReadOnly() || !$this->getEnabled(true))
- $writer->addAttribute('disabled', 'disabled');
- $writer->renderBeginTag('select');
- $this->renderDropDownListOptions($writer,
- $this->getLocalizedMonthNames($info), $selected-1);
- $writer->renderEndTag();
- }
-
- /**
- * Returns the localized month names that depends on the month format pattern.
- * "MMMM" will return the month names, "MM" or "MMM" return abbr. month names
- * and "M" return month digits.
- * @param DateTimeFormatInfo localized date format information.
- * @return array localized month names.
- */
- protected function getLocalizedMonthNames($info)
- {
- $formatter = Prado::createComponent('System.Util.TSimpleDateFormatter',
- $this->getDateFormat());
- switch($formatter->getMonthPattern())
- {
- case 'MMM': return $info->getAbbreviatedMonthNames();
- case 'MM':
- $array = array();
- for($i=1;$i<=12;$i++)
- $array[$i-1] = $i < 10 ? '0'.$i : $i;
- return $array;
- case 'M':
- $array = array(); for($i=1;$i<=12;$i++) $array[$i-1] = $i;
- return $array;
- default : return $info->getMonthNames();
- }
- }
-
- /**
- * Renders the year drop down list options.
- * @param THtmlWriter the writer used for the rendering purpose
- * @param mixed selected year.
- */
- protected function renderCalendarYearOptions($writer, $selected=null)
- {
- $years = array();
- for($i = $this->getFromYear(); $i <= $this->getUpToYear(); $i++)
- $years[$i] = $i;
- $writer->addAttribute('id', $this->getClientID().TControl::CLIENT_ID_SEPARATOR.'year');
- $writer->addAttribute('name', $this->getUniqueID().TControl::ID_SEPARATOR.'year');
- if($this->getReadOnly() || !$this->getEnabled(true))
- $writer->addAttribute('disabled', 'disabled');
- $writer->renderBeginTag('select');
- $writer->addAttribute('class', 'datepicker_year_options');
- $this->renderDropDownListOptions($writer, $years, $selected);
- $writer->renderEndTag();
- }
-
- /**
- * Gets the ID for the date picker trigger button.
- * @return string unique button ID
- */
- protected function getDatePickerButtonID()
- {
- return $this->getClientID().'button';
- }
-
- /**
- * Adds an additional button such that when clicked it shows the date picker.
- * @return THtmlWriter writer
- */
- protected function renderButtonDatePicker($writer)
- {
- $writer->addAttribute('id', $this->getDatePickerButtonID());
- $writer->addAttribute('type', 'button');
- $writer->addAttribute('class', $this->getCssClass().' TDatePickerButton');
- $writer->addAttribute('value',$this->getButtonText());
- if(!$this->getEnabled(true))
- $writer->addAttribute('disabled', 'disabled');
- $writer->renderBeginTag("input");
- $writer->renderEndTag();
- }
-
- /**
- * Adds an additional image button such that when clicked it shows the date picker.
- * @return THtmlWriter writer
- */
- protected function renderImageButtonDatePicker($writer)
- {
- $url = $this->getButtonImageUrl();
- $url = empty($url) ? $this->getAssetUrl('calendar.png') : $url;
- $writer->addAttribute('id', $this->getDatePickerButtonID());
- $writer->addAttribute('src', $url);
- $writer->addAttribute('alt', ' ');
- $writer->addAttribute('class', $this->getCssClass().' TDatePickerImageButton');
- if(!$this->getEnabled(true))
- $writer->addAttribute('disabled', 'disabled');
- $writer->addAttribute('type', 'image');
- $writer->addAttribute('onclick', 'return false;');
- $writer->renderBeginTag('input');
- $writer->renderEndTag();
- }
-
- /**
- * @param string date picker asset file in the self::SCRIPT_PATH directory.
- * @return string date picker asset url.
- */
- protected function getAssetUrl($file='')
- {
- $base = $this->getPage()->getClientScript()->getPradoScriptAssetUrl();
- return $base.'/'.self::SCRIPT_PATH.'/'.$file;
- }
-
- /**
- * Publish the calendar style Css asset file.
- * @return string Css file url.
- */
- protected function publishCalendarStyle()
- {
- $url = $this->getAssetUrl($this->getCalendarStyle().'.css');
- $cs = $this->getPage()->getClientScript();
- if(!$cs->isStyleSheetFileRegistered($url))
- $cs->registerStyleSheetFile($url, $url);
- return $url;
- }
-
- /**
- * Add the client id to the input textbox, and register the client scripts.
- * @param THtmlWriter writer
- */
- protected function addAttributesToRender($writer)
- {
- parent::addAttributesToRender($writer);
- $writer->addAttribute('id',$this->getClientID());
- $this->registerCalendarClientScriptPost();
- }
-
-
- /**
- * Registers the javascript code to initialize the date picker.
- */
- protected function registerCalendarClientScriptPre()
- {
- if($this->getShowCalendar())
- {
- $cs = $this->getPage()->getClientScript();
- $cs->registerPradoScript("datepicker");
- }
- }
-
- protected function registerCalendarClientScriptPost()
- {
- if($this->getShowCalendar())
- {
- $cs = $this->getPage()->getClientScript();
- if(!$cs->isEndScriptRegistered('TDatePicker.spacer'))
- {
- $spacer = $this->getAssetUrl('spacer.gif');
- $code = "Prado.WebUI.TDatePicker.spacer = '$spacer';";
- $cs->registerEndScript('TDatePicker.spacer', $code);
- }
-
- $options = TJavaScript::encode($this->getDatePickerOptions());
- $code = "new Prado.WebUI.TDatePicker($options);";
- $cs->registerEndScript("prado:".$this->getClientID(), $code);
- }
- }
-}
-
-/**
- * TDatePickerClientScript class.
- *
- * Client-side date picker event {@link setOnDateChanged OnDateChanged}
- * can be modified through the {@link TDatePicker::getClientSide ClientSide}
- * property of a date picker.
- *
- * The <tt>OnDateChanged</tt> event is raise when the date picker's date
- * is changed.
- * The formatted date according to {@link TDatePicker::getDateFormat DateFormat} is sent
- * as parameter to this event
- *
- * @author Wei Zhuo <weizhuo[at]gmail[dot]com>
- * @version $Id$
- * @package System.Web.UI.WebControls
- * @since 3.0.4
- */
-class TDatePickerClientScript extends TClientSideOptions
-{
- /**
- * Javascript code to execute when the date picker's date is changed.
- * @param string javascript code
- */
- public function setOnDateChanged($javascript)
- {
- $this->setFunction('OnDateChanged', $javascript);
- }
-
- /**
- * @return string javascript code to execute when the date picker's date is changed.
- */
- public function getOnDateChanged()
- {
- return $this->getOption('OnDateChanged');
- }
-}
-
-
-/**
- * TDatePickerInputMode class.
- * TDatePickerInputMode defines the enumerable type for the possible datepicker input methods.
- *
- * The following enumerable values are defined:
- * - TextBox: text boxes are used to input date values
- * - DropDownList: dropdown lists are used to pick up date values
- *
- * @author Qiang Xue <qiang.xue@gmail.com>
- * @version $Id$
- * @package System.Web.UI.WebControls
- * @since 3.0.4
- */
-class TDatePickerInputMode extends TEnumerable
-{
- const TextBox='TextBox';
- const DropDownList='DropDownList';
-}
-
-/**
- * TDatePickerMode class.
- * TDatePickerMode defines the enumerable type for the possible UI mode
- * that a {@link TDatePicker} control can take.
- *
- * The following enumerable values are defined:
- * - Basic: Only shows a text input, focusing on the input shows the date picker
- * - Clickable: Only shows a text input, clicking on the input shows the date picker (since 3.2)
- * - Button: Shows a button next to the text input, clicking on the button shows the date, button text can be by the
- * - ImageButton: Shows an image next to the text input, clicking on the image shows the date picker,
- *
- * @author Qiang Xue <qiang.xue@gmail.com>
- * @version $Id$
- * @package System.Web.UI.WebControls
- * @since 3.0.4
- */
-class TDatePickerMode extends TEnumerable
-{
- const Basic='Basic';
- const Clickable='Clickable';
- const Button='Button';
- const ImageButton='ImageButton';
-}
-
-/**
- * TDatePickerPositionMode class.
- * TDatePickerPositionMode defines the positions available for the calendar popup, relative to the corresponding input.
- *
- * The following enumerable values are defined:
- * - Top: the date picker is placed above the input field
- * - Bottom: the date picker is placed below the input field
- *
- * @author Carl G. Mathisen <carlgmathisen@gmail.com>
- * @package System.Web.UI.WebControls
- * @since 3.1.4
- */
-class TDatePickerPositionMode extends TEnumerable
-{
- const Top='Top';
- const Bottom='Bottom';
-}
+<?php
+/**
+ * TDatePicker class file.
+ *
+ * @author Wei Zhuo <weizhuo[at]gmail[dot]com>
+ * @link http://www.pradosoft.com/
+ * @copyright Copyright &copy; 2005-2012 PradoSoft
+ * @license http://www.pradosoft.com/license/
+ * @version $Id$
+ * @package System.Web.UI.WebControls
+ */
+
+/**
+ * Includes TTextBox class
+ */
+Prado::using('System.Web.UI.WebControls.TTextBox');
+
+/**
+ *
+ * TDatePicker class.
+ *
+ * TDatePicker displays a text box for date input purpose.
+ * When the text box receives focus, a calendar will pop up and users can
+ * pick up from it a date that will be automatically entered into the text box.
+ * The format of the date string displayed in the text box is determined by
+ * the <b>DateFormat</b> property. Valid formats are the combination of the
+ * following tokens,
+ *
+ * <code>
+ * Character Format Pattern (en-US)
+ * -----------------------------------------
+ * d day digit
+ * dd padded day digit e.g. 01, 02
+ * M month digit
+ * MM padded month digit
+ * MMMM localized month name, e.g. March, April
+ * yy 2 digit year
+ * yyyy 4 digit year
+ * -----------------------------------------
+ * </code>
+ *
+ * TDatePicker has four <b>Mode</b> to show the date picker popup.
+ *
+ * # <b>Basic</b> -- Only shows a text input, focusing on the input shows the
+ * date picker. This way you can access the popup using only
+ * the keyboard. Note that because of this, TAB-bing through
+ * this control will automatically select the current date if
+ * no previous date was selected. If you close the popup (eg.
+ * pressing the ESC key) you'll need to un-focus and re-focus
+ * the control again for the popup to reappear.
+ * # <b>Clickable</b> -- Only shows a text input, clicking on the input shows the
+ * date picker. This mode solves the two small problems of the
+ * Basic mode. It was first introduced in Prado 3.2.
+ * # <b>Button</b> -- Shows a button next to the text input, clicking on the
+ * button shows the date, button text can be by the
+ * <b>ButtonText</b> property
+ * # <b>ImageButton</b> -- Shows an image next to the text input, clicking on
+ * the image shows the date picker, image source can be
+ * change through the <b>ButtonImageUrl</b> property.
+ *
+ * The <b>CssClass</b> property can be used to override the css class name
+ * for the date picker panel. <b>CalendarStyle</b> property sets the packages
+ * styles available. E.g. <b>default</b>.
+ *
+ * The <b>InputMode</b> property can be set to "TextBox" or "DropDownList" with
+ * default as "TextBox".
+ * In <b>DropDownList</b> mode, in addition to the popup date picker, three
+ * drop down list (day, month and year) are presented to select the date .
+ *
+ * The <b>PositionMode</b> property can be set to "Top" or "Bottom" with default
+ * as "Bottom". It specifies the position of the calendar popup, relative to the
+ * input field.
+ *
+ * @author Wei Zhuo <weizhuo[at]gmail[dot]com>
+ * @author Carl G. Mathisen <carlgmathisen@gmail.com>
+ * @version $Id$
+ * @package System.Web.UI.WebControls
+ * @since 3.0
+ */
+class TDatePicker extends TTextBox
+{
+ /**
+ * Script path relative to the TClientScriptManager::SCRIPT_PATH
+ */
+ const SCRIPT_PATH = 'prado/datepicker';
+
+ /**
+ * @var TDatePickerClientScript validator client-script options.
+ */
+ private $_clientScript;
+ /**
+ * AutoPostBack is not supported.
+ */
+ public function setAutoPostBack($value)
+ {
+ throw new TNotSupportedException('tdatepicker_autopostback_unsupported',
+ get_class($this));
+ }
+
+ /**
+ * @return string the format of the date string
+ */
+ public function getDateFormat()
+ {
+ return $this->getViewState('DateFormat','dd-MM-yyyy');
+ }
+
+ /**
+ * Sets the format of the date string.
+ * @param string the format of the date string
+ */
+ public function setDateFormat($value)
+ {
+ $this->setViewState('DateFormat',$value,'dd-MM-yyyy');
+ }
+
+ /**
+ * @return boolean whether the calendar window should pop up when the control receives focus
+ */
+ public function getShowCalendar()
+ {
+ return $this->getViewState('ShowCalendar',true);
+ }
+
+ /**
+ * Sets whether to pop up the calendar window when the control receives focus
+ * @param boolean whether to show the calendar window
+ */
+ public function setShowCalendar($value)
+ {
+ $this->setViewState('ShowCalendar',TPropertyValue::ensureBoolean($value),true);
+ }
+
+ /**
+ * Gets the current culture.
+ * @return string current culture, e.g. en_AU.
+ */
+ public function getCulture()
+ {
+ return $this->getViewState('Culture', '');
+ }
+
+ /**
+ * Sets the culture/language for the date picker.
+ * @param string a culture string, e.g. en_AU.
+ */
+ public function setCulture($value)
+ {
+ $this->setViewState('Culture', $value, '');
+ }
+
+ /**
+ * @param TDatePickerInputMode input method of date values
+ */
+ public function setInputMode($value)
+ {
+ $this->setViewState('InputMode', TPropertyValue::ensureEnum($value, 'TDatePickerInputMode'), TDatePickerInputMode::TextBox);
+ }
+
+ /**
+ * @return TDatePickerInputMode input method of date values. Defaults to TDatePickerInputMode::TextBox.
+ */
+ public function getInputMode()
+ {
+ return $this->getViewState('InputMode', TDatePickerInputMode::TextBox);
+ }
+
+ /**
+ * @param TDatePickerMode calendar UI mode
+ */
+ public function setMode($value)
+ {
+ $this->setViewState('Mode', TPropertyValue::ensureEnum($value, 'TDatePickerMode'), TDatePickerMode::Basic);
+ }
+
+ /**
+ * @return TDatePickerMode current calendar UI mode.
+ */
+ public function getMode()
+ {
+ return $this->getViewState('Mode', TDatePickerMode::Basic);
+ }
+ /**
+ * @param string the image url for "Image" UI mode.
+ */
+ public function setButtonImageUrl($value)
+ {
+ $this->setViewState('ImageUrl', $value, '');
+ }
+
+ /**
+ * @return string the image url for "Image" UI mode.
+ */
+ public function getButtonImageUrl()
+ {
+ return $this->getViewState('ImageUrl', '');
+ }
+
+ /**
+ * @param string set the calendar style
+ */
+ public function setCalendarStyle($value)
+ {
+ $this->setViewState('CalendarStyle', $value, 'default');
+ }
+
+ /**
+ * @return string current calendar style
+ */
+ public function getCalendarStyle()
+ {
+ return $this->getViewState('CalendarStyle', 'default');
+ }
+
+ /**
+ * Set the first day of week, with 0 as Sunday, 1 as Monday, etc.
+ * @param integer 0 for Sunday, 1 for Monday, 2 for Tuesday, etc.
+ */
+ public function setFirstDayOfWeek($value)
+ {
+ $this->setViewState('FirstDayOfWeek', TPropertyValue::ensureInteger($value), 1);
+ }
+
+ /**
+ * @return integer first day of the week
+ */
+ public function getFirstDayOfWeek()
+ {
+ return $this->getViewState('FirstDayOfWeek', 1);
+ }
+
+ /**
+ * @return string text for the date picker button. Default is "...".
+ */
+ public function getButtonText()
+ {
+ return $this->getViewState('ButtonText', '...');
+ }
+
+ /**
+ * @param string text for the date picker button
+ */
+ public function setButtonText($value)
+ {
+ $this->setViewState('ButtonText', $value, '...');
+ }
+
+ /**
+ * @param integer date picker starting year, default is 2000.
+ */
+ public function setFromYear($value)
+ {
+ $this->setViewState('FromYear', TPropertyValue::ensureInteger($value), intval(@date('Y'))-5);
+ }
+
+ /**
+ * @return integer date picker starting year, default is -5 years
+ */
+ public function getFromYear()
+ {
+ return $this->getViewState('FromYear', intval(@date('Y'))-5);
+ }
+
+ /**
+ * @param integer date picker ending year, default +10 years
+ */
+ public function setUpToYear($value)
+ {
+ $this->setViewState('UpToYear', TPropertyValue::ensureInteger($value), intval(@date('Y'))+10);
+ }
+
+ /**
+ * @return integer date picker ending year, default +10 years
+ */
+ public function getUpToYear()
+ {
+ return $this->getViewState('UpToYear', intval(@date('Y'))+10);
+ }
+
+ /**
+ * @param TDatePickerPositionMode calendar UI position
+ */
+ public function setPositionMode($value)
+ {
+ $this->setViewState('PositionMode', TPropertyValue::ensureEnum($value, 'TDatePickerPositionMode'), TDatePickerPositionMode::Bottom);
+ }
+
+ /**
+ * @return TDatePickerPositionMode current calendar UI position.
+ */
+ public function getPositionMode()
+ {
+ return $this->getViewState('PositionMode', TDatePickerPositionMode::Bottom);
+ }
+
+ /**
+ * @return integer current selected date from the date picker as timestamp, NULL if timestamp is not set previously.
+ */
+ public function getTimeStamp()
+ {
+ if(trim($this->getText())==='')
+ return null;
+ else
+ return $this->getTimeStampFromText();
+ }
+
+ /**
+ * Sets the date for the date picker using timestamp.
+ * @param float time stamp for the date picker
+ */
+ public function setTimeStamp($value)
+ {
+ if($value===null || (is_string($value) && trim($value)===''))
+ $this->setText('');
+ else
+ {
+ $date = TPropertyValue::ensureFloat($value);
+ $formatter = Prado::createComponent('System.Util.TSimpleDateFormatter',$this->getDateFormat());
+ $this->setText($formatter->format($date));
+ }
+ }
+
+ /**
+ * Returns the timestamp selected by the user.
+ * This method is required by {@link IDataRenderer}.
+ * It is the same as {@link getTimeStamp()}.
+ * @return integer the timestamp of the TDatePicker control.
+ * @see getTimeStamp
+ * @since 3.1.2
+ */
+ public function getData()
+ {
+ return $this->getTimeStamp();
+ }
+
+ /**
+ * Sets the timestamp represented by this control.
+ * This method is required by {@link IDataRenderer}.
+ * It is the same as {@link setTimeStamp()}.
+ * @param integer the timestamp of the TDatePicker control.
+ * @see setTimeStamp
+ * @since 3.1.2
+ */
+ public function setData($value)
+ {
+ $this->setTimeStamp($value);
+ }
+
+ /**
+ * @return string the date string.
+ */
+ public function getDate()
+ {
+ return $this->getText();
+ }
+
+ /**
+ * @param string date string
+ */
+ public function setDate($value)
+ {
+ $this->setText($value);
+ }
+
+ /**
+ * Gets the TDatePickerClientScript to set the TDatePicker event handlers.
+ *
+ * The date picker on the client-side supports the following events.
+ * # <tt>OnDateChanged</tt> -- raised when the date is changed.
+ *
+ * You can attach custom javascript code to each of these events
+ *
+ * @return TDatePickerClientScript javascript validator event options.
+ */
+ public function getClientSide()
+ {
+ if($this->_clientScript===null)
+ $this->_clientScript = $this->createClientScript();
+ return $this->_clientScript;
+ }
+
+ /**
+ * @return TDatePickerClientScript javascript validator event options.
+ */
+ protected function createClientScript()
+ {
+ return new TDatePickerClientScript;
+ }
+
+ /**
+ * Returns the value to be validated.
+ * This methid is required by IValidatable interface.
+ * @return integer the interger timestamp if valid, otherwise the original text.
+ */
+ public function getValidationPropertyValue()
+ {
+ if(($text = $this->getText()) === '')
+ return '';
+ $date = $this->getTimeStamp();
+ return $date == null ? $text : $date;
+ }
+
+ /**
+ * Publish the date picker Css asset files.
+ */
+ public function onPreRender($param)
+ {
+ parent::onPreRender($param);
+ if($this->getInputMode() === TDatePickerInputMode::DropDownList)
+ {
+ $page = $this->getPage();
+ $uniqueID = $this->getUniqueID();
+ $page->registerPostDataLoader($uniqueID.TControl::ID_SEPARATOR.'day');
+ $page->registerPostDataLoader($uniqueID.TControl::ID_SEPARATOR.'month');
+ $page->registerPostDataLoader($uniqueID.TControl::ID_SEPARATOR.'year');
+ }
+ $this->publishCalendarStyle();
+ $this->registerCalendarClientScriptPre();
+ }
+
+ /**
+ * Renders body content.
+ * This method overrides parent implementation by adding
+ * additional date picker button if Mode is Button or ImageButton.
+ * @param THtmlWriter writer
+ */
+ public function render($writer)
+ {
+ if($this->getInputMode() == TDatePickerInputMode::TextBox)
+ {
+ parent::render($writer);
+ $this->renderDatePickerButtons($writer);
+ }
+ else
+ {
+ $this->renderDropDownListCalendar($writer);
+ if($this->hasDayPattern())
+ {
+ $this->registerCalendarClientScriptPost();
+ $this->renderDatePickerButtons($writer);
+ }
+ }
+ }
+
+ /**
+ * Renders the date picker popup buttons.
+ */
+ protected function renderDatePickerButtons($writer)
+ {
+ if($this->getShowCalendar())
+ {
+ switch ($this->getMode())
+ {
+ case TDatePickerMode::Button:
+ $this->renderButtonDatePicker($writer);
+ break;
+ case TDatePickerMode::ImageButton :
+ $this->renderImageButtonDatePicker($writer);
+ break;
+ }
+ }
+ }
+
+ /**
+ * Loads user input data. Override parent implementation, when InputMode
+ * is DropDownList call getDateFromPostData to get date data.
+ * This method is primarly used by framework developers.
+ * @param string the key that can be used to retrieve data from the input data collection
+ * @param array the input data collection
+ * @return boolean whether the data of the component has been changed
+ */
+ public function loadPostData($key,$values)
+ {
+ if($this->getInputMode() == TDatePickerInputMode::TextBox)
+ return parent::loadPostData($key, $values);
+ $value = $this->getDateFromPostData($key, $values);
+ if(!$this->getReadOnly() && $this->getText()!==$value)
+ {
+ $this->setText($value);
+ return true;
+ }
+ else
+ return false;
+ }
+
+ /**
+ * Loads date from drop down list data.
+ * @param string the key that can be used to retrieve data from the input data collection
+ * @param array the input data collection
+ * @return array the date selected
+ */
+ protected function getDateFromPostData($key, $values)
+ {
+ $date = @getdate();
+
+ if(isset($values[$key.'$day']))
+ $day = intval($values[$key.'$day']);
+ else
+ $day = $date['mday'];
+
+ if(isset($values[$key.'$month']))
+ $month = intval($values[$key.'$month']) + 1;
+ else
+ $month = $date['mon'];
+
+ if(isset($values[$key.'$year']))
+ $year = intval($values[$key.'$year']);
+ else
+ $year = $date['year'];
+
+ $s = Prado::createComponent('System.Util.TDateTimeStamp');
+ $date = $s->getTimeStamp(0, 0, 0, $month, $day, $year);
+ //$date = @mktime(0, 0, 0, $month, $day, $year);
+
+ $pattern = $this->getDateFormat();
+ $pattern = str_replace(array('MMMM', 'MMM'), array('MM','MM'), $pattern);
+ $formatter = Prado::createComponent('System.Util.TSimpleDateFormatter', $pattern);
+ return $formatter->format($date);
+ }
+
+ /**
+ * Get javascript date picker options.
+ * @return array date picker client-side options
+ */
+ protected function getDatePickerOptions()
+ {
+ $options['ID'] = $this->getClientID();
+ $options['InputMode'] = $this->getInputMode();
+ $options['Format'] = $this->getDateFormat();
+ $options['FirstDayOfWeek'] = $this->getFirstDayOfWeek();
+ if(($cssClass=$this->getCssClass())!=='')
+ $options['ClassName'] = $cssClass;
+ $options['CalendarStyle'] = $this->getCalendarStyle();
+ $options['FromYear'] = $this->getFromYear();
+ $options['UpToYear'] = $this->getUpToYear();
+ switch($this->getMode())
+ {
+ case TDatePickerMode::Basic:
+ break;
+ case TDatePickerMode::Clickable:
+ $options['TriggerEvent'] = "click";
+ break;
+ default:
+ $options['Trigger'] = $this->getDatePickerButtonID();
+ break;
+ }
+ $options['PositionMode'] = $this->getPositionMode();
+
+ $options = array_merge($options, $this->getCulturalOptions());
+ if($this->_clientScript!==null)
+ $options = array_merge($options,
+ $this->_clientScript->getOptions()->toArray());
+ return $options;
+ }
+
+ /**
+ * Get javascript localization options, e.g. month and weekday names.
+ * @return array localization options.
+ */
+ protected function getCulturalOptions()
+ {
+ if($this->getCurrentCulture() == 'en')
+ return array();
+
+ $date = $this->getLocalizedCalendarInfo();
+ $options['MonthNames'] = $date->getMonthNames();
+ $options['AbbreviatedMonthNames'] = $date->getAbbreviatedMonthNames();
+ $options['ShortWeekDayNames'] = $date->getAbbreviatedDayNames();
+
+ return $options;
+ }
+
+ /**
+ * @return string the current culture, falls back to application if culture is not set.
+ */
+ protected function getCurrentCulture()
+ {
+ $app = $this->getApplication()->getGlobalization(false);
+ return $this->getCulture() == '' ?
+ ($app ? $app->getCulture() : 'en') : $this->getCulture();
+ }
+
+ /**
+ * @return DateTimeFormatInfo date time format information for the current culture.
+ */
+ protected function getLocalizedCalendarInfo()
+ {
+ //expensive operations
+ $culture = $this->getCurrentCulture();
+ Prado::using('System.I18N.core.DateTimeFormatInfo');
+ $info = Prado::createComponent('System.I18N.core.CultureInfo', $culture);
+ return $info->getDateTimeFormat();
+ }
+
+ /**
+ * Renders the drop down list date picker.
+ */
+ protected function renderDropDownListCalendar($writer)
+ {
+ if($this->getMode() == TDatePickerMode::Basic)
+ $this->setMode(TDatePickerMode::ImageButton);
+ parent::addAttributesToRender($writer);
+ $writer->removeAttribute('name');
+ $writer->removeAttribute('type');
+ $writer->addAttribute('id', $this->getClientID());
+
+ if(strlen($class = $this->getCssClass()) > 0)
+ $writer->addAttribute('class', $class);
+ $writer->renderBeginTag('span');
+
+ $s = Prado::createComponent('System.Util.TDateTimeStamp');
+ $date = $s->getDate($this->getTimeStampFromText());
+ //$date = @getdate($this->getTimeStampFromText());
+
+ $this->renderCalendarSelections($writer, $date);
+
+ //render a hidden input field
+ $writer->addAttribute('name', $this->getUniqueID());
+ $writer->addAttribute('type', 'hidden');
+ $writer->addAttribute('value', $this->getText());
+ $writer->renderBeginTag('input');
+
+ $writer->renderEndTag();
+ $writer->renderEndTag();
+ }
+
+ protected function hasDayPattern()
+ {
+ $formatter = Prado::createComponent('System.Util.TSimpleDateFormatter',
+ $this->getDateFormat());
+ return ($formatter->getDayPattern()!==null);
+ }
+
+ /**
+ * Renders the calendar drop down list depending on the DateFormat pattern.
+ * @param THtmlWriter the Html writer to render the drop down lists.
+ * @param array the current selected date
+ */
+ protected function renderCalendarSelections($writer, $date)
+ {
+ $formatter = Prado::createComponent('System.Util.TSimpleDateFormatter',
+ $this->getDateFormat());
+
+ foreach($formatter->getDayMonthYearOrdering() as $type)
+ {
+ if($type == 'day')
+ $this->renderCalendarDayOptions($writer,$date['mday']);
+ elseif($type == 'month')
+ $this->renderCalendarMonthOptions($writer,$date['mon']);
+ elseif($type == 'year')
+ $this->renderCalendarYearOptions($writer,$date['year']);
+ }
+ }
+
+ /**
+ * Gets the date from the text input using TSimpleDateFormatter
+ * @return integer current selected date timestamp
+ */
+ protected function getTimeStampFromText()
+ {
+ $pattern = $this->getDateFormat();
+ $pattern = str_replace(array('MMMM', 'MMM'), array('MM','MM'), $pattern);
+ $formatter = Prado::createComponent('System.Util.TSimpleDateFormatter',$pattern);
+ return $formatter->parse($this->getText());
+ }
+
+ /**
+ * Renders a drop down lists.
+ * @param THtmlWriter the writer used for the rendering purpose
+ * @param array list of selection options
+ * @param mixed selected key.
+ */
+ private function renderDropDownListOptions($writer,$options,$selected=null)
+ {
+ foreach($options as $k => $v)
+ {
+ $writer->addAttribute('value', $k);
+ if($k == $selected)
+ $writer->addAttribute('selected', 'selected');
+ $writer->renderBeginTag('option');
+ $writer->write($v);
+ $writer->renderEndTag();
+ }
+ }
+
+ /**
+ * Renders the day drop down list options.
+ * @param THtmlWriter the writer used for the rendering purpose
+ * @param mixed selected day.
+ */
+ protected function renderCalendarDayOptions($writer, $selected=null)
+ {
+ $days = $this->getDropDownDayOptions();
+ $writer->addAttribute('id', $this->getClientID().TControl::CLIENT_ID_SEPARATOR.'day');
+ $writer->addAttribute('name', $this->getUniqueID().TControl::ID_SEPARATOR.'day');
+ $writer->addAttribute('class', 'datepicker_day_options');
+ if($this->getReadOnly() || !$this->getEnabled(true))
+ $writer->addAttribute('disabled', 'disabled');
+ $writer->renderBeginTag('select');
+ $this->renderDropDownListOptions($writer, $days, $selected);
+ $writer->renderEndTag();
+ }
+
+ /**
+ * @return array list of day options for a drop down list.
+ */
+ protected function getDropDownDayOptions()
+ {
+ $formatter = Prado::createComponent('System.Util.TSimpleDateFormatter',
+ $this->getDateFormat());
+ $days = array();
+ $requiresPadding = $formatter->getDayPattern() === 'dd';
+ for($i=1;$i<=31;$i++)
+ {
+ $days[$i] = $requiresPadding ? str_pad($i, 2, '0', STR_PAD_LEFT) : $i;
+ }
+ return $days;
+ }
+
+ /**
+ * Renders the month drop down list options.
+ * @param THtmlWriter the writer used for the rendering purpose
+ * @param mixed selected month.
+ */
+ protected function renderCalendarMonthOptions($writer, $selected=null)
+ {
+ $info = $this->getLocalizedCalendarInfo();
+ $writer->addAttribute('id', $this->getClientID().TControl::CLIENT_ID_SEPARATOR.'month');
+ $writer->addAttribute('name', $this->getUniqueID().TControl::ID_SEPARATOR.'month');
+ $writer->addAttribute('class', 'datepicker_month_options');
+ if($this->getReadOnly() || !$this->getEnabled(true))
+ $writer->addAttribute('disabled', 'disabled');
+ $writer->renderBeginTag('select');
+ $this->renderDropDownListOptions($writer,
+ $this->getLocalizedMonthNames($info), $selected-1);
+ $writer->renderEndTag();
+ }
+
+ /**
+ * Returns the localized month names that depends on the month format pattern.
+ * "MMMM" will return the month names, "MM" or "MMM" return abbr. month names
+ * and "M" return month digits.
+ * @param DateTimeFormatInfo localized date format information.
+ * @return array localized month names.
+ */
+ protected function getLocalizedMonthNames($info)
+ {
+ $formatter = Prado::createComponent('System.Util.TSimpleDateFormatter',
+ $this->getDateFormat());
+ switch($formatter->getMonthPattern())
+ {
+ case 'MMM': return $info->getAbbreviatedMonthNames();
+ case 'MM':
+ $array = array();
+ for($i=1;$i<=12;$i++)
+ $array[$i-1] = $i < 10 ? '0'.$i : $i;
+ return $array;
+ case 'M':
+ $array = array(); for($i=1;$i<=12;$i++) $array[$i-1] = $i;
+ return $array;
+ default : return $info->getMonthNames();
+ }
+ }
+
+ /**
+ * Renders the year drop down list options.
+ * @param THtmlWriter the writer used for the rendering purpose
+ * @param mixed selected year.
+ */
+ protected function renderCalendarYearOptions($writer, $selected=null)
+ {
+ $years = array();
+ for($i = $this->getFromYear(); $i <= $this->getUpToYear(); $i++)
+ $years[$i] = $i;
+ $writer->addAttribute('id', $this->getClientID().TControl::CLIENT_ID_SEPARATOR.'year');
+ $writer->addAttribute('name', $this->getUniqueID().TControl::ID_SEPARATOR.'year');
+ if($this->getReadOnly() || !$this->getEnabled(true))
+ $writer->addAttribute('disabled', 'disabled');
+ $writer->renderBeginTag('select');
+ $writer->addAttribute('class', 'datepicker_year_options');
+ $this->renderDropDownListOptions($writer, $years, $selected);
+ $writer->renderEndTag();
+ }
+
+ /**
+ * Gets the ID for the date picker trigger button.
+ * @return string unique button ID
+ */
+ protected function getDatePickerButtonID()
+ {
+ return $this->getClientID().'button';
+ }
+
+ /**
+ * Adds an additional button such that when clicked it shows the date picker.
+ * @return THtmlWriter writer
+ */
+ protected function renderButtonDatePicker($writer)
+ {
+ $writer->addAttribute('id', $this->getDatePickerButtonID());
+ $writer->addAttribute('type', 'button');
+ $writer->addAttribute('class', $this->getCssClass().' TDatePickerButton');
+ $writer->addAttribute('value',$this->getButtonText());
+ if(!$this->getEnabled(true))
+ $writer->addAttribute('disabled', 'disabled');
+ $writer->renderBeginTag("input");
+ $writer->renderEndTag();
+ }
+
+ /**
+ * Adds an additional image button such that when clicked it shows the date picker.
+ * @return THtmlWriter writer
+ */
+ protected function renderImageButtonDatePicker($writer)
+ {
+ $url = $this->getButtonImageUrl();
+ $url = empty($url) ? $this->getAssetUrl('calendar.png') : $url;
+ $writer->addAttribute('id', $this->getDatePickerButtonID());
+ $writer->addAttribute('src', $url);
+ $writer->addAttribute('alt', ' ');
+ $writer->addAttribute('class', $this->getCssClass().' TDatePickerImageButton');
+ if(!$this->getEnabled(true))
+ $writer->addAttribute('disabled', 'disabled');
+ $writer->addAttribute('type', 'image');
+ $writer->addAttribute('onclick', 'return false;');
+ $writer->renderBeginTag('input');
+ $writer->renderEndTag();
+ }
+
+ /**
+ * @param string date picker asset file in the self::SCRIPT_PATH directory.
+ * @return string date picker asset url.
+ */
+ protected function getAssetUrl($file='')
+ {
+ $base = $this->getPage()->getClientScript()->getPradoScriptAssetUrl();
+ return $base.'/'.self::SCRIPT_PATH.'/'.$file;
+ }
+
+ /**
+ * Publish the calendar style Css asset file.
+ * @return string Css file url.
+ */
+ protected function publishCalendarStyle()
+ {
+ $url = $this->getAssetUrl($this->getCalendarStyle().'.css');
+ $cs = $this->getPage()->getClientScript();
+ if(!$cs->isStyleSheetFileRegistered($url))
+ $cs->registerStyleSheetFile($url, $url);
+ return $url;
+ }
+
+ /**
+ * Add the client id to the input textbox, and register the client scripts.
+ * @param THtmlWriter writer
+ */
+ protected function addAttributesToRender($writer)
+ {
+ parent::addAttributesToRender($writer);
+ $writer->addAttribute('id',$this->getClientID());
+ $this->registerCalendarClientScriptPost();
+ }
+
+
+ /**
+ * Registers the javascript code to initialize the date picker.
+ */
+ protected function registerCalendarClientScriptPre()
+ {
+ if($this->getShowCalendar())
+ {
+ $cs = $this->getPage()->getClientScript();
+ $cs->registerPradoScript("datepicker");
+ }
+ }
+
+ protected function registerCalendarClientScriptPost()
+ {
+ if($this->getShowCalendar())
+ {
+ $cs = $this->getPage()->getClientScript();
+ if(!$cs->isEndScriptRegistered('TDatePicker.spacer'))
+ {
+ $spacer = $this->getAssetUrl('spacer.gif');
+ $code = "Prado.WebUI.TDatePicker.spacer = '$spacer';";
+ $cs->registerEndScript('TDatePicker.spacer', $code);
+ }
+
+ $options = TJavaScript::encode($this->getDatePickerOptions());
+ $code = "new Prado.WebUI.TDatePicker($options);";
+ $cs->registerEndScript("prado:".$this->getClientID(), $code);
+ }
+ }
+}
+
+/**
+ * TDatePickerClientScript class.
+ *
+ * Client-side date picker event {@link setOnDateChanged OnDateChanged}
+ * can be modified through the {@link TDatePicker::getClientSide ClientSide}
+ * property of a date picker.
+ *
+ * The <tt>OnDateChanged</tt> event is raise when the date picker's date
+ * is changed.
+ * The formatted date according to {@link TDatePicker::getDateFormat DateFormat} is sent
+ * as parameter to this event
+ *
+ * @author Wei Zhuo <weizhuo[at]gmail[dot]com>
+ * @version $Id$
+ * @package System.Web.UI.WebControls
+ * @since 3.0.4
+ */
+class TDatePickerClientScript extends TClientSideOptions
+{
+ /**
+ * Javascript code to execute when the date picker's date is changed.
+ * @param string javascript code
+ */
+ public function setOnDateChanged($javascript)
+ {
+ $this->setFunction('OnDateChanged', $javascript);
+ }
+
+ /**
+ * @return string javascript code to execute when the date picker's date is changed.
+ */
+ public function getOnDateChanged()
+ {
+ return $this->getOption('OnDateChanged');
+ }
+}
+
+
+/**
+ * TDatePickerInputMode class.
+ * TDatePickerInputMode defines the enumerable type for the possible datepicker input methods.
+ *
+ * The following enumerable values are defined:
+ * - TextBox: text boxes are used to input date values
+ * - DropDownList: dropdown lists are used to pick up date values
+ *
+ * @author Qiang Xue <qiang.xue@gmail.com>
+ * @version $Id$
+ * @package System.Web.UI.WebControls
+ * @since 3.0.4
+ */
+class TDatePickerInputMode extends TEnumerable
+{
+ const TextBox='TextBox';
+ const DropDownList='DropDownList';
+}
+
+/**
+ * TDatePickerMode class.
+ * TDatePickerMode defines the enumerable type for the possible UI mode
+ * that a {@link TDatePicker} control can take.
+ *
+ * The following enumerable values are defined:
+ * - Basic: Only shows a text input, focusing on the input shows the date picker
+ * - Clickable: Only shows a text input, clicking on the input shows the date picker (since 3.2)
+ * - Button: Shows a button next to the text input, clicking on the button shows the date, button text can be by the
+ * - ImageButton: Shows an image next to the text input, clicking on the image shows the date picker,
+ *
+ * @author Qiang Xue <qiang.xue@gmail.com>
+ * @version $Id$
+ * @package System.Web.UI.WebControls
+ * @since 3.0.4
+ */
+class TDatePickerMode extends TEnumerable
+{
+ const Basic='Basic';
+ const Clickable='Clickable';
+ const Button='Button';
+ const ImageButton='ImageButton';
+}
+
+/**
+ * TDatePickerPositionMode class.
+ * TDatePickerPositionMode defines the positions available for the calendar popup, relative to the corresponding input.
+ *
+ * The following enumerable values are defined:
+ * - Top: the date picker is placed above the input field
+ * - Bottom: the date picker is placed below the input field
+ *
+ * @author Carl G. Mathisen <carlgmathisen@gmail.com>
+ * @package System.Web.UI.WebControls
+ * @since 3.1.4
+ */
+class TDatePickerPositionMode extends TEnumerable
+{
+ const Top='Top';
+ const Bottom='Bottom';
+}
diff --git a/framework/Web/UI/WebControls/TDropDownList.php b/framework/Web/UI/WebControls/TDropDownList.php
index 0eba6285..57f1f165 100644
--- a/framework/Web/UI/WebControls/TDropDownList.php
+++ b/framework/Web/UI/WebControls/TDropDownList.php
@@ -1,154 +1,154 @@
-<?php
-/**
- * TDropDownList class file
- *
- * @author Qiang Xue <qiang.xue@gmail.com>
- * @link http://www.pradosoft.com/
- * @copyright Copyright &copy; 2005-2012 PradoSoft
- * @license http://www.pradosoft.com/license/
- * @version $Id$
- * @package System.Web.UI.WebControls
- */
-
-/**
- * Includes TListControl class
- */
-Prado::using('System.Web.UI.WebControls.TListControl');
-
-/**
- * TDropDownList class
- *
- * TDropDownList displays a dropdown list on a Web page.
- * It inherits all properties and events from {@link TListControl}.
- *
- * Since v3.0.3, TDropDownList starts to support optgroup. To specify an option group for
- * a list item, set a Group attribute with it,
- * <code>
- * $listitem->Attributes->Group="Group Name";
- * // or <com:TListItem Attributes.Group="Group Name" .../> in template
- * </code>
- *
- * Since v3.1.1, TDropDownList starts to support prompt text. That is, a prompt item can be
- * displayed as the first list item by specifying either {@link setPromptText PromptText} or
- * {@link setPromptValue PromptValue}, or both. Choosing the prompt item will unselect the TDropDownList.
- *
- * When a prompt item is set, its index in the list is set to -1. So, the {@link getSelectedIndex SelectedIndex}
- * property is not affected by a prompt item: the items list will still be zero-based.
- *
- * The {@link clearSelection clearSelection} method will select the prompt item if existing, otherway the first
- * available item in the dropdown list will be selected.
- *
- * @author Qiang Xue <qiang.xue@gmail.com>
- * @version $Id$
- * @package System.Web.UI.WebControls
- * @since 3.0
- */
-class TDropDownList extends TListControl implements IPostBackDataHandler, IValidatable
-{
- private $_dataChanged=false;
- private $_isValid=true;
-
- /**
- * Adds attributes to renderer.
- * @param THtmlWriter the renderer
- */
- protected function addAttributesToRender($writer)
- {
- $writer->addAttribute('name',$this->getUniqueID());
- parent::addAttributesToRender($writer);
- }
-
- /**
- * Gets the name of the javascript class responsible for performing postback for this control.
- * This method overrides the parent implementation.
- * @return string the javascript class name
- */
- protected function getClientClassName()
- {
- return 'Prado.WebUI.TDropDownList';
- }
-
- /**
- * Loads user input data.
- * This method is primarly used by framework developers.
- * @param string the key that can be used to retrieve data from the input data collection
- * @param array the input data collection
- * @return boolean whether the data of the component has been changed
- */
- public function loadPostData($key,$values)
- {
- if(!$this->getEnabled(true))
- return false;
- $this->ensureDataBound();
- $selection=isset($values[$key])?$values[$key]:null;
- if($selection!==null)
- {
- $index=$this->getItems()->findIndexByValue($selection,false);
- if($this->getSelectedIndex()!==$index)
- {
- $this->setSelectedIndex($index);
- return $this->_dataChanged=true;
- }
- }
- return false;
- }
-
- /**
- * Raises postdata changed event.
- * This method is required by {@link IPostBackDataHandler} interface.
- * It is invoked by the framework when {@link getSelectedIndex SelectedIndex} property
- * is changed on postback.
- * This method is primarly used by framework developers.
- */
- public function raisePostDataChangedEvent()
- {
- if($this->getAutoPostBack() && $this->getCausesValidation())
- $this->getPage()->validate($this->getValidationGroup());
- $this->onSelectedIndexChanged(null);
- }
-
- /**
- * Returns a value indicating whether postback has caused the control data change.
- * This method is required by the IPostBackDataHandler interface.
- * @return boolean whether postback has caused the control data change. False if the page is not in postback mode.
- */
- public function getDataChanged()
- {
- return $this->_dataChanged;
- }
-
- /**
- * @throws TNotSupportedException if this method is invoked
- */
- public function setSelectedIndices($indices)
- {
- throw new TNotSupportedException('dropdownlist_selectedindices_unsupported');
- }
-
- /**
- * Returns the value to be validated.
- * This methid is required by IValidatable interface.
- * @return mixed the value of the property to be validated.
- */
- public function getValidationPropertyValue()
- {
- return $this->getSelectedValue();
- }
-
- /**
- * Returns true if this control validated successfully.
- * Defaults to true.
- * @return bool wether this control validated successfully.
- */
- public function getIsValid()
- {
- return $this->_isValid;
- }
- /**
- * @param bool wether this control is valid.
- */
- public function setIsValid($value)
- {
- $this->_isValid=TPropertyValue::ensureBoolean($value);
- }
-}
+<?php
+/**
+ * TDropDownList class file
+ *
+ * @author Qiang Xue <qiang.xue@gmail.com>
+ * @link http://www.pradosoft.com/
+ * @copyright Copyright &copy; 2005-2012 PradoSoft
+ * @license http://www.pradosoft.com/license/
+ * @version $Id$
+ * @package System.Web.UI.WebControls
+ */
+
+/**
+ * Includes TListControl class
+ */
+Prado::using('System.Web.UI.WebControls.TListControl');
+
+/**
+ * TDropDownList class
+ *
+ * TDropDownList displays a dropdown list on a Web page.
+ * It inherits all properties and events from {@link TListControl}.
+ *
+ * Since v3.0.3, TDropDownList starts to support optgroup. To specify an option group for
+ * a list item, set a Group attribute with it,
+ * <code>
+ * $listitem->Attributes->Group="Group Name";
+ * // or <com:TListItem Attributes.Group="Group Name" .../> in template
+ * </code>
+ *
+ * Since v3.1.1, TDropDownList starts to support prompt text. That is, a prompt item can be
+ * displayed as the first list item by specifying either {@link setPromptText PromptText} or
+ * {@link setPromptValue PromptValue}, or both. Choosing the prompt item will unselect the TDropDownList.
+ *
+ * When a prompt item is set, its index in the list is set to -1. So, the {@link getSelectedIndex SelectedIndex}
+ * property is not affected by a prompt item: the items list will still be zero-based.
+ *
+ * The {@link clearSelection clearSelection} method will select the prompt item if existing, otherway the first
+ * available item in the dropdown list will be selected.
+ *
+ * @author Qiang Xue <qiang.xue@gmail.com>
+ * @version $Id$
+ * @package System.Web.UI.WebControls
+ * @since 3.0
+ */
+class TDropDownList extends TListControl implements IPostBackDataHandler, IValidatable
+{
+ private $_dataChanged=false;
+ private $_isValid=true;
+
+ /**
+ * Adds attributes to renderer.
+ * @param THtmlWriter the renderer
+ */
+ protected function addAttributesToRender($writer)
+ {
+ $writer->addAttribute('name',$this->getUniqueID());
+ parent::addAttributesToRender($writer);
+ }
+
+ /**
+ * Gets the name of the javascript class responsible for performing postback for this control.
+ * This method overrides the parent implementation.
+ * @return string the javascript class name
+ */
+ protected function getClientClassName()
+ {
+ return 'Prado.WebUI.TDropDownList';
+ }
+
+ /**
+ * Loads user input data.
+ * This method is primarly used by framework developers.
+ * @param string the key that can be used to retrieve data from the input data collection
+ * @param array the input data collection
+ * @return boolean whether the data of the component has been changed
+ */
+ public function loadPostData($key,$values)
+ {
+ if(!$this->getEnabled(true))
+ return false;
+ $this->ensureDataBound();
+ $selection=isset($values[$key])?$values[$key]:null;
+ if($selection!==null)
+ {
+ $index=$this->getItems()->findIndexByValue($selection,false);
+ if($this->getSelectedIndex()!==$index)
+ {
+ $this->setSelectedIndex($index);
+ return $this->_dataChanged=true;
+ }
+ }
+ return false;
+ }
+
+ /**
+ * Raises postdata changed event.
+ * This method is required by {@link IPostBackDataHandler} interface.
+ * It is invoked by the framework when {@link getSelectedIndex SelectedIndex} property
+ * is changed on postback.
+ * This method is primarly used by framework developers.
+ */
+ public function raisePostDataChangedEvent()
+ {
+ if($this->getAutoPostBack() && $this->getCausesValidation())
+ $this->getPage()->validate($this->getValidationGroup());
+ $this->onSelectedIndexChanged(null);
+ }
+
+ /**
+ * Returns a value indicating whether postback has caused the control data change.
+ * This method is required by the IPostBackDataHandler interface.
+ * @return boolean whether postback has caused the control data change. False if the page is not in postback mode.
+ */
+ public function getDataChanged()
+ {
+ return $this->_dataChanged;
+ }
+
+ /**
+ * @throws TNotSupportedException if this method is invoked
+ */
+ public function setSelectedIndices($indices)
+ {
+ throw new TNotSupportedException('dropdownlist_selectedindices_unsupported');
+ }
+
+ /**
+ * Returns the value to be validated.
+ * This methid is required by IValidatable interface.
+ * @return mixed the value of the property to be validated.
+ */
+ public function getValidationPropertyValue()
+ {
+ return $this->getSelectedValue();
+ }
+
+ /**
+ * Returns true if this control validated successfully.
+ * Defaults to true.
+ * @return bool wether this control validated successfully.
+ */
+ public function getIsValid()
+ {
+ return $this->_isValid;
+ }
+ /**
+ * @param bool wether this control is valid.
+ */
+ public function setIsValid($value)
+ {
+ $this->_isValid=TPropertyValue::ensureBoolean($value);
+ }
+}
diff --git a/framework/Web/UI/WebControls/TDropDownListColumn.php b/framework/Web/UI/WebControls/TDropDownListColumn.php
index ffbe8f70..941a9be1 100644
--- a/framework/Web/UI/WebControls/TDropDownListColumn.php
+++ b/framework/Web/UI/WebControls/TDropDownListColumn.php
@@ -1,321 +1,321 @@
-<?php
-/**
- * TDropDownListColumn class file
- *
- * @author Qiang Xue <qiang.xue@gmail.com>
- * @link http://www.pradosoft.com/
+<?php
+/**
+ * TDropDownListColumn class file
+ *
+ * @author Qiang Xue <qiang.xue@gmail.com>
+ * @link http://www.pradosoft.com/
* @copyright Copyright &copy; 2005-2012 PradoSoft
- * @license http://www.pradosoft.com/license/
- * @version $Id$
- * @package System.Web.UI.WebControls
- */
-
-Prado::using('System.Web.UI.WebControls.TDataGridColumn');
-Prado::using('System.Web.UI.WebControls.TDropDownList');
-
-/**
- * TDropDownListColumn class
- *
- * TDropDownListColumn represents a column that is bound to a field in a data source.
- * The cells in the column will be displayed using the data indexed by
- * {@link setDataTextField DataTextField}. You can customize the display by
- * setting {@link setDataTextFormatString DataTextFormatString}.
- *
- * If {@link setReadOnly ReadOnly} is false, TDropDownListColumn will display cells in edit mode
- * with dropdown lists. Otherwise, a static text is displayed.
- * The currently selected dropndown list item is specified by the data indexed with
- * {@link setDataValueField DataValueField}.
- *
- * There are two approaches to specify the list items available for selection.
- * The first approach uses template syntax as follows,
- * <code>
- * <com:TDropDownListColumn ....>
- * <com:TListItem Value="1" Text="first item" />
- * <com:TListItem Value="2" Text="second item" />
- * <com:TListItem Value="3" Text="third item" />
- * </com:TDropDownListColumn>
- * </code>
- * The second approach specifies a data source to be bound to the dropdown lists
- * by setting {@link setListDataSource ListDataSource}. Like generic list controls,
- * you may also want to specify which data fields are used for item values and texts
- * by setting {@link setListValueField ListValueField} and
- * {@link setListTextField ListTextField}, respectively.
- * Furthermore, the item texts may be formatted by using {@link setListTextFormatString ListTextFormatString}.
- * Note, if you specify {@link setListDataSource ListDataSource}, do it before
- * calling the datagrid's dataBind().
- *
- * The dropdown list control in the TDropDownListColumn can be accessed by one of
- * the following two methods:
- * <code>
- * $datagridItem->DropDownListColumnID->DropDownList
- * $datagridItem->DropDownListColumnID->Controls[0]
- * </code>
- * The second method is possible because the dropdown list control created within the
- * datagrid cell is the first child.
- *
- * @author Qiang Xue <qiang.xue@gmail.com>
- * @version $Id$
- * @package System.Web.UI.WebControls
- * @since 3.0.4
- */
-class TDropDownListColumn extends TDataGridColumn
-{
- private $_stateLoaded=false;
- private $_dataBound=false;
- private $_listControl=null;
-
- public function __construct()
- {
- $this->_listControl=new TDropDownList;
- }
-
- /**
- * Loads items from viewstate.
- * This method overrides the parent implementation by loading list items
- * @param mixed state values
- */
- public function loadState($state)
- {
- parent::loadState($state);
- $this->_stateLoaded=true;
- if(!$this->_dataBound)
- $this->_listControl->getItems()->loadState($this->getViewState('Items',null));
- }
-
- /**
- * Saves items into viewstate.
- * This method overrides the parent implementation by saving list items
- */
- public function saveState()
- {
- $this->setViewState('Items',$this->_listControl->getItems()->saveState(),null);
- return parent::saveState();
- }
-
- /**
- * Adds object parsed from template to the control.
- * This method adds only {@link TListItem} objects into the {@link getItems Items} collection.
- * All other objects are ignored.
- * @param mixed object parsed from template
- */
- public function addParsedObject($object)
- {
- // Do not add items from template if items are loaded from viewstate
- if(!$this->_stateLoaded && ($object instanceof TListItem))
- {
- $object->setSelected(false);
- $index=$this->_listControl->getItems()->add($object);
- }
- }
-
- /**
- * @return string the field of the data source that provides the text content of the column.
- */
- public function getDataTextField()
- {
- return $this->getViewState('DataTextField','');
- }
-
- /**
- * Sets the field of the data source that provides the text content of the column.
- * If this is not set, the data specified via {@link getDataValueField DataValueField}
- * will be displayed in the column.
- * @param string the field of the data source that provides the text content of the column.
- */
- public function setDataTextField($value)
- {
- $this->setViewState('DataTextField',$value,'');
- }
-
- /**
- * @return string the formatting string used to control how the bound data will be displayed.
- */
- public function getDataTextFormatString()
- {
- return $this->getViewState('DataTextFormatString','');
- }
-
- /**
- * @param string the formatting string used to control how the bound data will be displayed.
- */
- public function setDataTextFormatString($value)
- {
- $this->setViewState('DataTextFormatString',$value,'');
- }
-
- /**
- * @return string the field of the data source that provides the key selecting an item in dropdown list.
- */
- public function getDataValueField()
- {
- return $this->getViewState('DataValueField','');
- }
-
- /**
- * Sets the field of the data source that provides the key selecting an item in dropdown list.
- * If this is not present, the data specified via {@link getDataTextField DataTextField} (without
- * applying the formatting string) will be used for selection, instead.
- * @param string the field of the data source that provides the key selecting an item in dropdown list.
- */
- public function setDataValueField($value)
- {
- $this->setViewState('DataValueField',$value,'');
- }
-
- /**
- * @return boolean whether the items in the column can be edited. Defaults to false.
- */
- public function getReadOnly()
- {
- return $this->getViewState('ReadOnly',false);
- }
-
- /**
- * @param boolean whether the items in the column can be edited
- */
- public function setReadOnly($value)
- {
- $this->setViewState('ReadOnly',TPropertyValue::ensureBoolean($value),false);
- }
-
- /**
- * @return Traversable data source to be bound to the dropdown list boxes.
- */
- public function getListDataSource()
- {
- return $this->_listControl->getDataSource();
- }
-
- /**
- * @param Traversable|array|string data source to be bound to the dropdown list boxes.
- */
- public function setListDataSource($value)
- {
- $this->_listControl->setDataSource($value);
- }
-
- /**
- * @return string the data field used to populate the values of the dropdown list items. Defaults to empty.
- */
- public function getListValueField()
- {
- return $this->getViewState('ListValueField','');
- }
-
- /**
- * @param string the data field used to populate the values of the dropdown list items
- */
- public function setListValueField($value)
- {
- $this->setViewState('ListValueField',$value,'');
- }
-
- /**
- * @return string the data field used to populate the texts of the dropdown list items. Defaults to empty.
- */
- public function getListTextField()
- {
- return $this->getViewState('ListTextField','');
- }
-
- /**
- * @param string the data field used to populate the texts of the dropdown list items
- */
- public function setListTextField($value)
- {
- $this->setViewState('ListTextField',$value,'');
- }
-
- /**
- * @return string the formatting string used to control how the list item texts will be displayed.
- */
- public function getListTextFormatString()
- {
- return $this->getViewState('ListTextFormatString','');
- }
-
- /**
- * @param string the formatting string used to control how the list item texts will be displayed.
- */
- public function setListTextFormatString($value)
- {
- $this->setViewState('ListTextFormatString',$value,'');
- }
-
- /**
- * Initializes the specified cell to its initial values.
- * This method overrides the parent implementation.
- * It creates a textbox for item in edit mode and the column is not read-only.
- * Otherwise it displays a static text.
- * The caption of the button and the static text are retrieved
- * from the datasource.
- * @param TTableCell the cell to be initialized.
- * @param integer the index to the Columns property that the cell resides in.
- * @param string the type of cell (Header,Footer,Item,AlternatingItem,EditItem,SelectedItem)
- */
- public function initializeCell($cell,$columnIndex,$itemType)
- {
- if(!$this->_dataBound && $this->_listControl->getDataSource()!==null)
- {
- $this->_listControl->setDataTextField($this->getListTextField());
- $this->_listControl->setDataValueField($this->getListValueField());
- $this->_listControl->setDataTextFormatString($this->getListTextFormatString());
- $this->_listControl->dataBind();
- $this->_dataBound=true;
- }
- switch($itemType)
- {
- case TListItemType::EditItem:
- if(!$this->getReadOnly())
- {
- $listControl=clone $this->_listControl;
- $cell->getControls()->add($listControl);
- $cell->registerObject('DropDownList',$listControl);
- $control=$listControl;
- }
- else
- $control=$cell;
- $control->attachEventHandler('OnDataBinding',array($this,'dataBindColumn'));
- break;
- case TListItemType::Item:
- case TListItemType::AlternatingItem:
- case TListItemType::SelectedItem:
- if($this->getDataTextField()!=='' || $this->getDataValueField()!=='')
- $cell->attachEventHandler('OnDataBinding',array($this,'dataBindColumn'));
- break;
- default:
- parent::initializeCell($cell,$columnIndex,$itemType);
- break;
- }
- }
-
- /**
- * Databinds a cell in the column.
- * This method is invoked when datagrid performs databinding.
- * It populates the content of the cell with the relevant data from data source.
- */
- public function dataBindColumn($sender,$param)
- {
- $item=$sender->getNamingContainer();
- $data=$item->getData();
- if(($valueField=$this->getDataValueField())!=='')
- $value=$this->getDataFieldValue($data,$valueField);
- else
- $value='';
- if(($textField=$this->getDataTextField())!=='')
- {
- $text=$this->getDataFieldValue($data,$textField);
- if($valueField==='')
- $value=$text;
- $formatString=$this->getDataTextFormatString();
- $text=$this->formatDataValue($formatString,$text);
- }
- else
- $text=$value;
- if($sender instanceof TTableCell)
- $sender->setText($text);
- else if($sender instanceof TDropDownList)
- $sender->setSelectedValue($value);
- }
-}
-
+ * @license http://www.pradosoft.com/license/
+ * @version $Id$
+ * @package System.Web.UI.WebControls
+ */
+
+Prado::using('System.Web.UI.WebControls.TDataGridColumn');
+Prado::using('System.Web.UI.WebControls.TDropDownList');
+
+/**
+ * TDropDownListColumn class
+ *
+ * TDropDownListColumn represents a column that is bound to a field in a data source.
+ * The cells in the column will be displayed using the data indexed by
+ * {@link setDataTextField DataTextField}. You can customize the display by
+ * setting {@link setDataTextFormatString DataTextFormatString}.
+ *
+ * If {@link setReadOnly ReadOnly} is false, TDropDownListColumn will display cells in edit mode
+ * with dropdown lists. Otherwise, a static text is displayed.
+ * The currently selected dropndown list item is specified by the data indexed with
+ * {@link setDataValueField DataValueField}.
+ *
+ * There are two approaches to specify the list items available for selection.
+ * The first approach uses template syntax as follows,
+ * <code>
+ * <com:TDropDownListColumn ....>
+ * <com:TListItem Value="1" Text="first item" />
+ * <com:TListItem Value="2" Text="second item" />
+ * <com:TListItem Value="3" Text="third item" />
+ * </com:TDropDownListColumn>
+ * </code>
+ * The second approach specifies a data source to be bound to the dropdown lists
+ * by setting {@link setListDataSource ListDataSource}. Like generic list controls,
+ * you may also want to specify which data fields are used for item values and texts
+ * by setting {@link setListValueField ListValueField} and
+ * {@link setListTextField ListTextField}, respectively.
+ * Furthermore, the item texts may be formatted by using {@link setListTextFormatString ListTextFormatString}.
+ * Note, if you specify {@link setListDataSource ListDataSource}, do it before
+ * calling the datagrid's dataBind().
+ *
+ * The dropdown list control in the TDropDownListColumn can be accessed by one of
+ * the following two methods:
+ * <code>
+ * $datagridItem->DropDownListColumnID->DropDownList
+ * $datagridItem->DropDownListColumnID->Controls[0]
+ * </code>
+ * The second method is possible because the dropdown list control created within the
+ * datagrid cell is the first child.
+ *
+ * @author Qiang Xue <qiang.xue@gmail.com>
+ * @version $Id$
+ * @package System.Web.UI.WebControls
+ * @since 3.0.4
+ */
+class TDropDownListColumn extends TDataGridColumn
+{
+ private $_stateLoaded=false;
+ private $_dataBound=false;
+ private $_listControl=null;
+
+ public function __construct()
+ {
+ $this->_listControl=new TDropDownList;
+ }
+
+ /**
+ * Loads items from viewstate.
+ * This method overrides the parent implementation by loading list items
+ * @param mixed state values
+ */
+ public function loadState($state)
+ {
+ parent::loadState($state);
+ $this->_stateLoaded=true;
+ if(!$this->_dataBound)
+ $this->_listControl->getItems()->loadState($this->getViewState('Items',null));
+ }
+
+ /**
+ * Saves items into viewstate.
+ * This method overrides the parent implementation by saving list items
+ */
+ public function saveState()
+ {
+ $this->setViewState('Items',$this->_listControl->getItems()->saveState(),null);
+ return parent::saveState();
+ }
+
+ /**
+ * Adds object parsed from template to the control.
+ * This method adds only {@link TListItem} objects into the {@link getItems Items} collection.
+ * All other objects are ignored.
+ * @param mixed object parsed from template
+ */
+ public function addParsedObject($object)
+ {
+ // Do not add items from template if items are loaded from viewstate
+ if(!$this->_stateLoaded && ($object instanceof TListItem))
+ {
+ $object->setSelected(false);
+ $index=$this->_listControl->getItems()->add($object);
+ }
+ }
+
+ /**
+ * @return string the field of the data source that provides the text content of the column.
+ */
+ public function getDataTextField()
+ {
+ return $this->getViewState('DataTextField','');
+ }
+
+ /**
+ * Sets the field of the data source that provides the text content of the column.
+ * If this is not set, the data specified via {@link getDataValueField DataValueField}
+ * will be displayed in the column.
+ * @param string the field of the data source that provides the text content of the column.
+ */
+ public function setDataTextField($value)
+ {
+ $this->setViewState('DataTextField',$value,'');
+ }
+
+ /**
+ * @return string the formatting string used to control how the bound data will be displayed.
+ */
+ public function getDataTextFormatString()
+ {
+ return $this->getViewState('DataTextFormatString','');
+ }
+
+ /**
+ * @param string the formatting string used to control how the bound data will be displayed.
+ */
+ public function setDataTextFormatString($value)
+ {
+ $this->setViewState('DataTextFormatString',$value,'');
+ }
+
+ /**
+ * @return string the field of the data source that provides the key selecting an item in dropdown list.
+ */
+ public function getDataValueField()
+ {
+ return $this->getViewState('DataValueField','');
+ }
+
+ /**
+ * Sets the field of the data source that provides the key selecting an item in dropdown list.
+ * If this is not present, the data specified via {@link getDataTextField DataTextField} (without
+ * applying the formatting string) will be used for selection, instead.
+ * @param string the field of the data source that provides the key selecting an item in dropdown list.
+ */
+ public function setDataValueField($value)
+ {
+ $this->setViewState('DataValueField',$value,'');
+ }
+
+ /**
+ * @return boolean whether the items in the column can be edited. Defaults to false.
+ */
+ public function getReadOnly()
+ {
+ return $this->getViewState('ReadOnly',false);
+ }
+
+ /**
+ * @param boolean whether the items in the column can be edited
+ */
+ public function setReadOnly($value)
+ {
+ $this->setViewState('ReadOnly',TPropertyValue::ensureBoolean($value),false);
+ }
+
+ /**
+ * @return Traversable data source to be bound to the dropdown list boxes.
+ */
+ public function getListDataSource()
+ {
+ return $this->_listControl->getDataSource();
+ }
+
+ /**
+ * @param Traversable|array|string data source to be bound to the dropdown list boxes.
+ */
+ public function setListDataSource($value)
+ {
+ $this->_listControl->setDataSource($value);
+ }
+
+ /**
+ * @return string the data field used to populate the values of the dropdown list items. Defaults to empty.
+ */
+ public function getListValueField()
+ {
+ return $this->getViewState('ListValueField','');
+ }
+
+ /**
+ * @param string the data field used to populate the values of the dropdown list items
+ */
+ public function setListValueField($value)
+ {
+ $this->setViewState('ListValueField',$value,'');
+ }
+
+ /**
+ * @return string the data field used to populate the texts of the dropdown list items. Defaults to empty.
+ */
+ public function getListTextField()
+ {
+ return $this->getViewState('ListTextField','');
+ }
+
+ /**
+ * @param string the data field used to populate the texts of the dropdown list items
+ */
+ public function setListTextField($value)
+ {
+ $this->setViewState('ListTextField',$value,'');
+ }
+
+ /**
+ * @return string the formatting string used to control how the list item texts will be displayed.
+ */
+ public function getListTextFormatString()
+ {
+ return $this->getViewState('ListTextFormatString','');
+ }
+
+ /**
+ * @param string the formatting string used to control how the list item texts will be displayed.
+ */
+ public function setListTextFormatString($value)
+ {
+ $this->setViewState('ListTextFormatString',$value,'');
+ }
+
+ /**
+ * Initializes the specified cell to its initial values.
+ * This method overrides the parent implementation.
+ * It creates a textbox for item in edit mode and the column is not read-only.
+ * Otherwise it displays a static text.
+ * The caption of the button and the static text are retrieved
+ * from the datasource.
+ * @param TTableCell the cell to be initialized.
+ * @param integer the index to the Columns property that the cell resides in.
+ * @param string the type of cell (Header,Footer,Item,AlternatingItem,EditItem,SelectedItem)
+ */
+ public function initializeCell($cell,$columnIndex,$itemType)
+ {
+ if(!$this->_dataBound && $this->_listControl->getDataSource()!==null)
+ {
+ $this->_listControl->setDataTextField($this->getListTextField());
+ $this->_listControl->setDataValueField($this->getListValueField());
+ $this->_listControl->setDataTextFormatString($this->getListTextFormatString());
+ $this->_listControl->dataBind();
+ $this->_dataBound=true;
+ }
+ switch($itemType)
+ {
+ case TListItemType::EditItem:
+ if(!$this->getReadOnly())
+ {
+ $listControl=clone $this->_listControl;
+ $cell->getControls()->add($listControl);
+ $cell->registerObject('DropDownList',$listControl);
+ $control=$listControl;
+ }
+ else
+ $control=$cell;
+ $control->attachEventHandler('OnDataBinding',array($this,'dataBindColumn'));
+ break;
+ case TListItemType::Item:
+ case TListItemType::AlternatingItem:
+ case TListItemType::SelectedItem:
+ if($this->getDataTextField()!=='' || $this->getDataValueField()!=='')
+ $cell->attachEventHandler('OnDataBinding',array($this,'dataBindColumn'));
+ break;
+ default:
+ parent::initializeCell($cell,$columnIndex,$itemType);
+ break;
+ }
+ }
+
+ /**
+ * Databinds a cell in the column.
+ * This method is invoked when datagrid performs databinding.
+ * It populates the content of the cell with the relevant data from data source.
+ */
+ public function dataBindColumn($sender,$param)
+ {
+ $item=$sender->getNamingContainer();
+ $data=$item->getData();
+ if(($valueField=$this->getDataValueField())!=='')
+ $value=$this->getDataFieldValue($data,$valueField);
+ else
+ $value='';
+ if(($textField=$this->getDataTextField())!=='')
+ {
+ $text=$this->getDataFieldValue($data,$textField);
+ if($valueField==='')
+ $value=$text;
+ $formatString=$this->getDataTextFormatString();
+ $text=$this->formatDataValue($formatString,$text);
+ }
+ else
+ $text=$value;
+ if($sender instanceof TTableCell)
+ $sender->setText($text);
+ else if($sender instanceof TDropDownList)
+ $sender->setSelectedValue($value);
+ }
+}
+
diff --git a/framework/Web/UI/WebControls/TEditCommandColumn.php b/framework/Web/UI/WebControls/TEditCommandColumn.php
index 44004807..b10c6880 100644
--- a/framework/Web/UI/WebControls/TEditCommandColumn.php
+++ b/framework/Web/UI/WebControls/TEditCommandColumn.php
@@ -1,265 +1,265 @@
-<?php
-/**
- * TEditCommandColumn class file
- *
- * @author Qiang Xue <qiang.xue@gmail.com>
- * @link http://www.pradosoft.com/
+<?php
+/**
+ * TEditCommandColumn class file
+ *
+ * @author Qiang Xue <qiang.xue@gmail.com>
+ * @link http://www.pradosoft.com/
* @copyright Copyright &copy; 2005-2012 PradoSoft
- * @license http://www.pradosoft.com/license/
- * @version $Id$
- * @package System.Web.UI.WebControls
- */
-
-/**
- * TDataGridColumn class file
- */
-Prado::using('System.Web.UI.WebControls.TDataGridColumn');
-
-/**
- * TEditCommandColumn class
- *
- * TEditCommandColumn contains the Edit command buttons for editing data items in each row.
- *
- * TEditCommandColumn will create an edit button if a cell is not in edit mode.
- * Otherwise an update button and a cancel button will be created within the cell.
- * The button captions are specified using {@link setEditText EditText},
- * {@link setUpdateText UpdateText}, and {@link setCancelText CancelText}.
- *
- * The buttons in the column can be set to display as hyperlinks, push or image buttons
- * by setting the {@link setButtonType ButtonType} property.
- *
- * When an edit button is clicked, the datagrid will generate an
- * {@link onEditCommand OnEditCommand} event. When an update/cancel button
- * is clicked, the datagrid will generate an
- * {@link onUpdateCommand OnUpdateCommand} or an {@link onCancelCommand OnCancelCommand}
- * You can write these event handlers to change the state of specific datagrid item.
- *
- * The {@link setCausesValidation CausesValidation} and {@link setValidationGroup ValidationGroup}
- * properties affect the corresponding properties of the edit and update buttons.
- * The cancel button does not cause validation by default.
- *
- * The command buttons in the column can be accessed by one of the following methods:
- * <code>
- * $datagridItem->ButtonColumnID->EditButton (or UpdateButton, CancelButton)
- * $datagridItem->ButtonColumnID->Controls[0]
- * </code>
- * The second method is possible because the button control created within the
- * datagrid cell is the first child.
- *
- * @author Qiang Xue <qiang.xue@gmail.com>
- * @version $Id$
- * @package System.Web.UI.WebControls
- * @since 3.0
- */
-class TEditCommandColumn extends TDataGridColumn
-{
- /**
- * @return TButtonColumnType the type of command button. Defaults to TButtonColumnType::LinkButton.
- */
- public function getButtonType()
- {
- return $this->getViewState('ButtonType',TButtonColumnType::LinkButton);
- }
-
- /**
- * @param TButtonColumnType the type of command button.
- */
- public function setButtonType($value)
- {
- $this->setViewState('ButtonType',TPropertyValue::ensureEnum($value,'TButtonColumnType'),TButtonColumnType::LinkButton);
- }
-
- /**
- * @return string the caption of the edit button. Defaults to 'Edit'.
- */
- public function getEditText()
- {
- return $this->getViewState('EditText','Edit');
- }
-
- /**
- * @param string the caption of the edit button
- */
- public function setEditText($value)
- {
- $this->setViewState('EditText',$value,'Edit');
- }
-
- /**
- * @return string the URL of the image file for edit image buttons
- */
- public function getEditImageUrl()
- {
- return $this->getViewState('EditImageUrl','');
- }
-
- /**
- * @param string the URL of the image file for edit image buttons
- */
- public function setEditImageUrl($value)
- {
- $this->setViewState('EditImageUrl',$value,'');
- }
-
- /**
- * @return string the caption of the update button. Defaults to 'Update'.
- */
- public function getUpdateText()
- {
- return $this->getViewState('UpdateText','Update');
- }
-
- /**
- * @param string the caption of the update button
- */
- public function setUpdateText($value)
- {
- $this->setViewState('UpdateText',$value,'Update');
- }
-
- /**
- * @return string the URL of the image file for update image buttons
- */
- public function getUpdateImageUrl()
- {
- return $this->getViewState('UpdateImageUrl','');
- }
-
- /**
- * @param string the URL of the image file for update image buttons
- */
- public function setUpdateImageUrl($value)
- {
- $this->setViewState('UpdateImageUrl',$value,'');
- }
-
- /**
- * @return string the caption of the cancel button. Defaults to 'Cancel'.
- */
- public function getCancelText()
- {
- return $this->getViewState('CancelText','Cancel');
- }
-
- /**
- * @param string the caption of the cancel button
- */
- public function setCancelText($value)
- {
- $this->setViewState('CancelText',$value,'Cancel');
- }
-
- /**
- * @return string the URL of the image file for cancel image buttons
- */
- public function getCancelImageUrl()
- {
- return $this->getViewState('CancelImageUrl','');
- }
-
- /**
- * @param string the URL of the image file for cancel image buttons
- */
- public function setCancelImageUrl($value)
- {
- $this->setViewState('CancelImageUrl',$value,'');
- }
-
- /**
- * @return boolean whether postback event trigger by edit or update button will cause input validation, default is true
- */
- public function getCausesValidation()
- {
- return $this->getViewState('CausesValidation',true);
- }
-
- /**
- * @param boolean whether postback event trigger by edit or update button will cause input validation
- */
- public function setCausesValidation($value)
- {
- $this->setViewState('CausesValidation',TPropertyValue::ensureBoolean($value),true);
- }
-
- /**
- * @return string the group of validators which the edit or update button causes validation upon postback
- */
- public function getValidationGroup()
- {
- return $this->getViewState('ValidationGroup','');
- }
-
- /**
- * @param string the group of validators which the edit or update button causes validation upon postback
- */
- public function setValidationGroup($value)
- {
- $this->setViewState('ValidationGroup',$value,'');
- }
-
- /**
- * Initializes the specified cell to its initial values.
- * This method overrides the parent implementation.
- * It creates an update and a cancel button for cell in edit mode.
- * Otherwise it creates an edit button.
- * @param TTableCell the cell to be initialized.
- * @param integer the index to the Columns property that the cell resides in.
- * @param string the type of cell (Header,Footer,Item,AlternatingItem,EditItem,SelectedItem)
- */
- public function initializeCell($cell,$columnIndex,$itemType)
- {
- if($itemType===TListItemType::Item || $itemType===TListItemType::AlternatingItem || $itemType===TListItemType::SelectedItem)
- {
- $button=$this->createButton('Edit',$this->getEditText(),false,'');
- $cell->getControls()->add($button);
- $cell->registerObject('EditButton',$button);
- }
- else if($itemType===TListItemType::EditItem)
- {
- $controls=$cell->getControls();
- $button=$this->createButton('Update',$this->getUpdateText(),$this->getCausesValidation(),$this->getValidationGroup());
- $controls->add($button);
- $cell->registerObject('UpdateButton',$button);
- $controls->add('&nbsp;');
- $button=$this->createButton('Cancel',$this->getCancelText(),false,'');
- $controls->add($button);
- $cell->registerObject('CancelButton',$button);
- }
- else
- parent::initializeCell($cell,$columnIndex,$itemType);
- }
-
- /**
- * Creates a button and initializes its properties.
- * The button type is determined by {@link getButtonType ButtonType}.
- * @param string command name associated with the button
- * @param string button caption
- * @param boolean whether the button should cause validation
- * @param string the validation group that the button belongs to
- * @return mixed the newly created button.
- */
- protected function createButton($commandName,$text,$causesValidation,$validationGroup)
- {
- if($this->getButtonType()===TButtonColumnType::LinkButton)
- $button=Prado::createComponent('System.Web.UI.WebControls.TLinkButton');
- else if($this->getButtonType()===TButtonColumnType::PushButton)
- $button=Prado::createComponent('System.Web.UI.WebControls.TButton');
- else // image buttons
- {
- $button=Prado::createComponent('System.Web.UI.WebControls.TImageButton');
- if(strcasecmp($commandName,'Update')===0)
- $url=$this->getUpdateImageUrl();
- else if(strcasecmp($commandName,'Cancel')===0)
- $url=$this->getCancelImageUrl();
- else
- $url=$this->getEditImageUrl();
- $button->setImageUrl($url);
- }
- $button->setText($text);
- $button->setCommandName($commandName);
- $button->setCausesValidation($causesValidation);
- $button->setValidationGroup($validationGroup);
- return $button;
- }
-}
-
+ * @license http://www.pradosoft.com/license/
+ * @version $Id$
+ * @package System.Web.UI.WebControls
+ */
+
+/**
+ * TDataGridColumn class file
+ */
+Prado::using('System.Web.UI.WebControls.TDataGridColumn');
+
+/**
+ * TEditCommandColumn class
+ *
+ * TEditCommandColumn contains the Edit command buttons for editing data items in each row.
+ *
+ * TEditCommandColumn will create an edit button if a cell is not in edit mode.
+ * Otherwise an update button and a cancel button will be created within the cell.
+ * The button captions are specified using {@link setEditText EditText},
+ * {@link setUpdateText UpdateText}, and {@link setCancelText CancelText}.
+ *
+ * The buttons in the column can be set to display as hyperlinks, push or image buttons
+ * by setting the {@link setButtonType ButtonType} property.
+ *
+ * When an edit button is clicked, the datagrid will generate an
+ * {@link onEditCommand OnEditCommand} event. When an update/cancel button
+ * is clicked, the datagrid will generate an
+ * {@link onUpdateCommand OnUpdateCommand} or an {@link onCancelCommand OnCancelCommand}
+ * You can write these event handlers to change the state of specific datagrid item.
+ *
+ * The {@link setCausesValidation CausesValidation} and {@link setValidationGroup ValidationGroup}
+ * properties affect the corresponding properties of the edit and update buttons.
+ * The cancel button does not cause validation by default.
+ *
+ * The command buttons in the column can be accessed by one of the following methods:
+ * <code>
+ * $datagridItem->ButtonColumnID->EditButton (or UpdateButton, CancelButton)
+ * $datagridItem->ButtonColumnID->Controls[0]
+ * </code>
+ * The second method is possible because the button control created within the
+ * datagrid cell is the first child.
+ *
+ * @author Qiang Xue <qiang.xue@gmail.com>
+ * @version $Id$
+ * @package System.Web.UI.WebControls
+ * @since 3.0
+ */
+class TEditCommandColumn extends TDataGridColumn
+{
+ /**
+ * @return TButtonColumnType the type of command button. Defaults to TButtonColumnType::LinkButton.
+ */
+ public function getButtonType()
+ {
+ return $this->getViewState('ButtonType',TButtonColumnType::LinkButton);
+ }
+
+ /**
+ * @param TButtonColumnType the type of command button.
+ */
+ public function setButtonType($value)
+ {
+ $this->setViewState('ButtonType',TPropertyValue::ensureEnum($value,'TButtonColumnType'),TButtonColumnType::LinkButton);
+ }
+
+ /**
+ * @return string the caption of the edit button. Defaults to 'Edit'.
+ */
+ public function getEditText()
+ {
+ return $this->getViewState('EditText','Edit');
+ }
+
+ /**
+ * @param string the caption of the edit button
+ */
+ public function setEditText($value)
+ {
+ $this->setViewState('EditText',$value,'Edit');
+ }
+
+ /**
+ * @return string the URL of the image file for edit image buttons
+ */
+ public function getEditImageUrl()
+ {
+ return $this->getViewState('EditImageUrl','');
+ }
+
+ /**
+ * @param string the URL of the image file for edit image buttons
+ */
+ public function setEditImageUrl($value)
+ {
+ $this->setViewState('EditImageUrl',$value,'');
+ }
+
+ /**
+ * @return string the caption of the update button. Defaults to 'Update'.
+ */
+ public function getUpdateText()
+ {
+ return $this->getViewState('UpdateText','Update');
+ }
+
+ /**
+ * @param string the caption of the update button
+ */
+ public function setUpdateText($value)
+ {
+ $this->setViewState('UpdateText',$value,'Update');
+ }
+
+ /**
+ * @return string the URL of the image file for update image buttons
+ */
+ public function getUpdateImageUrl()
+ {
+ return $this->getViewState('UpdateImageUrl','');
+ }
+
+ /**
+ * @param string the URL of the image file for update image buttons
+ */
+ public function setUpdateImageUrl($value)
+ {
+ $this->setViewState('UpdateImageUrl',$value,'');
+ }
+
+ /**
+ * @return string the caption of the cancel button. Defaults to 'Cancel'.
+ */
+ public function getCancelText()
+ {
+ return $this->getViewState('CancelText','Cancel');
+ }
+
+ /**
+ * @param string the caption of the cancel button
+ */
+ public function setCancelText($value)
+ {
+ $this->setViewState('CancelText',$value,'Cancel');
+ }
+
+ /**
+ * @return string the URL of the image file for cancel image buttons
+ */
+ public function getCancelImageUrl()
+ {
+ return $this->getViewState('CancelImageUrl','');
+ }
+
+ /**
+ * @param string the URL of the image file for cancel image buttons
+ */
+ public function setCancelImageUrl($value)
+ {
+ $this->setViewState('CancelImageUrl',$value,'');
+ }
+
+ /**
+ * @return boolean whether postback event trigger by edit or update button will cause input validation, default is true
+ */
+ public function getCausesValidation()
+ {
+ return $this->getViewState('CausesValidation',true);
+ }
+
+ /**
+ * @param boolean whether postback event trigger by edit or update button will cause input validation
+ */
+ public function setCausesValidation($value)
+ {
+ $this->setViewState('CausesValidation',TPropertyValue::ensureBoolean($value),true);
+ }
+
+ /**
+ * @return string the group of validators which the edit or update button causes validation upon postback
+ */
+ public function getValidationGroup()
+ {
+ return $this->getViewState('ValidationGroup','');
+ }
+
+ /**
+ * @param string the group of validators which the edit or update button causes validation upon postback
+ */
+ public function setValidationGroup($value)
+ {
+ $this->setViewState('ValidationGroup',$value,'');
+ }
+
+ /**
+ * Initializes the specified cell to its initial values.
+ * This method overrides the parent implementation.
+ * It creates an update and a cancel button for cell in edit mode.
+ * Otherwise it creates an edit button.
+ * @param TTableCell the cell to be initialized.
+ * @param integer the index to the Columns property that the cell resides in.
+ * @param string the type of cell (Header,Footer,Item,AlternatingItem,EditItem,SelectedItem)
+ */
+ public function initializeCell($cell,$columnIndex,$itemType)
+ {
+ if($itemType===TListItemType::Item || $itemType===TListItemType::AlternatingItem || $itemType===TListItemType::SelectedItem)
+ {
+ $button=$this->createButton('Edit',$this->getEditText(),false,'');
+ $cell->getControls()->add($button);
+ $cell->registerObject('EditButton',$button);
+ }
+ else if($itemType===TListItemType::EditItem)
+ {
+ $controls=$cell->getControls();
+ $button=$this->createButton('Update',$this->getUpdateText(),$this->getCausesValidation(),$this->getValidationGroup());
+ $controls->add($button);
+ $cell->registerObject('UpdateButton',$button);
+ $controls->add('&nbsp;');
+ $button=$this->createButton('Cancel',$this->getCancelText(),false,'');
+ $controls->add($button);
+ $cell->registerObject('CancelButton',$button);
+ }
+ else
+ parent::initializeCell($cell,$columnIndex,$itemType);
+ }
+
+ /**
+ * Creates a button and initializes its properties.
+ * The button type is determined by {@link getButtonType ButtonType}.
+ * @param string command name associated with the button
+ * @param string button caption
+ * @param boolean whether the button should cause validation
+ * @param string the validation group that the button belongs to
+ * @return mixed the newly created button.
+ */
+ protected function createButton($commandName,$text,$causesValidation,$validationGroup)
+ {
+ if($this->getButtonType()===TButtonColumnType::LinkButton)
+ $button=Prado::createComponent('System.Web.UI.WebControls.TLinkButton');
+ else if($this->getButtonType()===TButtonColumnType::PushButton)
+ $button=Prado::createComponent('System.Web.UI.WebControls.TButton');
+ else // image buttons
+ {
+ $button=Prado::createComponent('System.Web.UI.WebControls.TImageButton');
+ if(strcasecmp($commandName,'Update')===0)
+ $url=$this->getUpdateImageUrl();
+ else if(strcasecmp($commandName,'Cancel')===0)
+ $url=$this->getCancelImageUrl();
+ else
+ $url=$this->getEditImageUrl();
+ $button->setImageUrl($url);
+ }
+ $button->setText($text);
+ $button->setCommandName($commandName);
+ $button->setCausesValidation($causesValidation);
+ $button->setValidationGroup($validationGroup);
+ return $button;
+ }
+}
+
diff --git a/framework/Web/UI/WebControls/TEmailAddressValidator.php b/framework/Web/UI/WebControls/TEmailAddressValidator.php
index a198ffc4..b0b51208 100644
--- a/framework/Web/UI/WebControls/TEmailAddressValidator.php
+++ b/framework/Web/UI/WebControls/TEmailAddressValidator.php
@@ -1,97 +1,97 @@
-<?php
-/**
- * TEmailAddressValidator class file
- *
- * @author Qiang Xue <qiang.xue@gmail.com>
- * @link http://www.pradosoft.com/
+<?php
+/**
+ * TEmailAddressValidator class file
+ *
+ * @author Qiang Xue <qiang.xue@gmail.com>
+ * @link http://www.pradosoft.com/
* @copyright Copyright &copy; 2005-2012 PradoSoft
- * @license http://www.pradosoft.com/license/
- * @version $Id$
- * @package System.Web.UI.WebControls
- */
-
-/**
- * Using TRegularExpressionValidator class
- */
-Prado::using('System.Web.UI.WebControls.TRegularExpressionValidator');
-
-/**
- * TEmailAddressValidator class
- *
- * TEmailAddressValidator validates whether the value of an associated
- * input component is a valid email address. If {@link getCheckMXRecord CheckMXRecord}
- * is true, it will check MX record for the email adress, provided
- * checkdnsrr() is available in the installed PHP.
- *
- * @author Qiang Xue <qiang.xue@gmail.com>
- * @version $Id$
- * @package System.Web.UI.WebControls
- * @since 3.0
- */
-class TEmailAddressValidator extends TRegularExpressionValidator
-{
- /**
- * Regular expression used to validate the email address
- */
- const EMAIL_REGEXP="\\w+([-+.]\\w+)*@\\w+([-.]\\w+)*\\.\\w+([-.]\\w+)*";
-
- /**
- * Gets the name of the javascript class responsible for performing validation for this control.
- * This method overrides the parent implementation.
- * @return string the javascript class name
- */
- protected function getClientClassName()
- {
- return 'Prado.WebUI.TEmailAddressValidator';
- }
-
- /**
- * @return string the regular expression that determines the pattern used to validate a field.
- */
- public function getRegularExpression()
- {
- $regex=parent::getRegularExpression();
- return $regex===''?self::EMAIL_REGEXP:$regex;
- }
-
- /**
- * Returns an array of javascript validator options.
- * @return array javascript validator options.
- */
- public function evaluateIsValid()
- {
- $valid=parent::evaluateIsValid();
- if($valid && $this->getCheckMXRecord() && function_exists('checkdnsrr'))
- {
- if(($value=$this->getValidationValue($this->getValidationTarget()))!=='')
- {
- if(($pos=strpos($value,'@'))!==false)
- {
- $domain=substr($value,$pos+1);
- return $domain===''?false:checkdnsrr($domain,'MX');
- }
- else
- return false;
- }
- }
- return $valid;
- }
-
- /**
- * @return boolean whether to check MX record for the email address being validated. Defaults to true.
- */
- public function getCheckMXRecord()
- {
- return $this->getViewState('CheckMXRecord',true);
- }
-
- /**
- * @param boolean whether to check MX record for the email address being validated.
- * Note, if {@link checkdnsrr} is not available, this check will not be performed.
- */
- public function setCheckMXRecord($value)
- {
- $this->setViewState('CheckMXRecord',TPropertyValue::ensureBoolean($value),true);
- }
-}
-
+ * @license http://www.pradosoft.com/license/
+ * @version $Id$
+ * @package System.Web.UI.WebControls
+ */
+
+/**
+ * Using TRegularExpressionValidator class
+ */
+Prado::using('System.Web.UI.WebControls.TRegularExpressionValidator');
+
+/**
+ * TEmailAddressValidator class
+ *
+ * TEmailAddressValidator validates whether the value of an associated
+ * input component is a valid email address. If {@link getCheckMXRecord CheckMXRecord}
+ * is true, it will check MX record for the email adress, provided
+ * checkdnsrr() is available in the installed PHP.
+ *
+ * @author Qiang Xue <qiang.xue@gmail.com>
+ * @version $Id$
+ * @package System.Web.UI.WebControls
+ * @since 3.0
+ */
+class TEmailAddressValidator extends TRegularExpressionValidator
+{
+ /**
+ * Regular expression used to validate the email address
+ */
+ const EMAIL_REGEXP="\\w+([-+.]\\w+)*@\\w+([-.]\\w+)*\\.\\w+([-.]\\w+)*";
+
+ /**
+ * Gets the name of the javascript class responsible for performing validation for this control.
+ * This method overrides the parent implementation.
+ * @return string the javascript class name
+ */
+ protected function getClientClassName()
+ {
+ return 'Prado.WebUI.TEmailAddressValidator';
+ }
+
+ /**
+ * @return string the regular expression that determines the pattern used to validate a field.
+ */
+ public function getRegularExpression()
+ {
+ $regex=parent::getRegularExpression();
+ return $regex===''?self::EMAIL_REGEXP:$regex;
+ }
+
+ /**
+ * Returns an array of javascript validator options.
+ * @return array javascript validator options.
+ */
+ public function evaluateIsValid()
+ {
+ $valid=parent::evaluateIsValid();
+ if($valid && $this->getCheckMXRecord() && function_exists('checkdnsrr'))
+ {
+ if(($value=$this->getValidationValue($this->getValidationTarget()))!=='')
+ {
+ if(($pos=strpos($value,'@'))!==false)
+ {
+ $domain=substr($value,$pos+1);
+ return $domain===''?false:checkdnsrr($domain,'MX');
+ }
+ else
+ return false;
+ }
+ }
+ return $valid;
+ }
+
+ /**
+ * @return boolean whether to check MX record for the email address being validated. Defaults to true.
+ */
+ public function getCheckMXRecord()
+ {
+ return $this->getViewState('CheckMXRecord',true);
+ }
+
+ /**
+ * @param boolean whether to check MX record for the email address being validated.
+ * Note, if {@link checkdnsrr} is not available, this check will not be performed.
+ */
+ public function setCheckMXRecord($value)
+ {
+ $this->setViewState('CheckMXRecord',TPropertyValue::ensureBoolean($value),true);
+ }
+}
+
diff --git a/framework/Web/UI/WebControls/TExpression.php b/framework/Web/UI/WebControls/TExpression.php
index 9b8eb7e7..cf38df70 100644
--- a/framework/Web/UI/WebControls/TExpression.php
+++ b/framework/Web/UI/WebControls/TExpression.php
@@ -1,62 +1,62 @@
-<?php
-/**
- * TExpression class file
- *
- * @author Qiang Xue <qiang.xue@gmail.com>
- * @link http://www.pradosoft.com/
+<?php
+/**
+ * TExpression class file
+ *
+ * @author Qiang Xue <qiang.xue@gmail.com>
+ * @link http://www.pradosoft.com/
* @copyright Copyright &copy; 2005-2012 PradoSoft
- * @license http://www.pradosoft.com/license/
- * @version $Id$
- * @package System.Web.UI.WebControls
- */
-
-/**
- * TExpression class
- *
- * TExpression evaluates a PHP expression and renders the result.
- * The expression is evaluated during the rendering stage. The expression being
- * evaluated can be set via the property {@link setExpression Expression}.
- * The context of the expression evaluated is the TExpression object itself.
- *
- * Note, since TExpression allows evaluation of arbitrary PHP expression,
- * make sure {@link setExpression Expression} does not come directly from user input.
- *
- * @author Qiang Xue <qiang.xue@gmail.com>
- * @version $Id$
- * @package System.Web.UI.WebControls
- * @since 3.0
- */
-class TExpression extends TControl
-{
- /**
- * @var string PHP expression to be evaluated
- */
- private $_e='';
-
- /**
- * @return string the expression to be evaluated
- */
- public function getExpression()
- {
- return $this->_e;
- }
-
- /**
- * @param string the expression to be evaluated
- */
- public function setExpression($value)
- {
- $this->_e=$value;
- }
-
- /**
- * Renders the evaluation result of the expression.
- * @param THtmlWriter the writer used for the rendering purpose
- */
- public function render($writer)
- {
- if($this->_e!=='')
- $writer->write($this->evaluateExpression($this->_e));
- }
-}
-
+ * @license http://www.pradosoft.com/license/
+ * @version $Id$
+ * @package System.Web.UI.WebControls
+ */
+
+/**
+ * TExpression class
+ *
+ * TExpression evaluates a PHP expression and renders the result.
+ * The expression is evaluated during the rendering stage. The expression being
+ * evaluated can be set via the property {@link setExpression Expression}.
+ * The context of the expression evaluated is the TExpression object itself.
+ *
+ * Note, since TExpression allows evaluation of arbitrary PHP expression,
+ * make sure {@link setExpression Expression} does not come directly from user input.
+ *
+ * @author Qiang Xue <qiang.xue@gmail.com>
+ * @version $Id$
+ * @package System.Web.UI.WebControls
+ * @since 3.0
+ */
+class TExpression extends TControl
+{
+ /**
+ * @var string PHP expression to be evaluated
+ */
+ private $_e='';
+
+ /**
+ * @return string the expression to be evaluated
+ */
+ public function getExpression()
+ {
+ return $this->_e;
+ }
+
+ /**
+ * @param string the expression to be evaluated
+ */
+ public function setExpression($value)
+ {
+ $this->_e=$value;
+ }
+
+ /**
+ * Renders the evaluation result of the expression.
+ * @param THtmlWriter the writer used for the rendering purpose
+ */
+ public function render($writer)
+ {
+ if($this->_e!=='')
+ $writer->write($this->evaluateExpression($this->_e));
+ }
+}
+
diff --git a/framework/Web/UI/WebControls/TFileUpload.php b/framework/Web/UI/WebControls/TFileUpload.php
index 0f7d226d..051e3e0b 100644
--- a/framework/Web/UI/WebControls/TFileUpload.php
+++ b/framework/Web/UI/WebControls/TFileUpload.php
@@ -1,281 +1,281 @@
-<?php
-/**
- * TFileUpload class file
- *
- * @author Marcus Nyeholt <tanus@users.sourceforge.net>, Qiang Xue <qiang.xue@gmail.com>
- * @link http://www.pradosoft.com/
- * @copyright Copyright &copy; 2005-2012 PradoSoft
- * @license http://www.pradosoft.com/license/
- * @version $Id$
- * @package System.Web.UI.WebControls
- */
-
-/**
- * TFileUpload class
- *
- * TFileUpload displays a file upload field on a page. Upon postback,
- * the text entered into the field will be treated as the name of the file
- * that will be uploaded to the server. The property {@link getHasFile HasFile}
- * indicates whether the file upload is successful. If successful, the file
- * may be obtained by calling {@link saveAs} to save it at a specified place.
- * You can use {@link getFileName FileName}, {@link getFileType FileType},
- * {@link getFileSize FileSize} to get the original client-side file name,
- * the file mime type, and the file size information. If the upload is not
- * successful, {@link getErrorCode ErrorCode} contains the error code
- * describing the cause of failure.
- *
- * TFileUpload raises {@link onFileUpload OnFileUpload} event if a file is uploaded
- * (whether it succeeds or not).
- *
- * @author Marcus Nyeholt <tanus@users.sourceforge.net>, Qiang Xue <qiang.xue@gmail.com>
- * @version $Id$
- * @package System.Web.UI.WebControls
- * @since 3.0
- */
-class TFileUpload extends TWebControl implements IPostBackDataHandler, IValidatable
-{
- /**
- * Maximum file size (in bytes) allowed to be uploaded, defaults to 1MB.
- */
- const MAX_FILE_SIZE=1048576;
- /**
- * @var integer the size of the uploaded file (in bytes)
- */
- private $_fileSize=0;
- /**
- * @var string The original name of the file on the client machine
- */
- private $_fileName='';
- /**
- * @var string the name of the temporary file storing the uploaded file
- */
- private $_localName='';
- /**
- * @var string the uploaded file mime type
- */
- private $_fileType='';
- /**
- * @var integer error code of the current file upload
- */
- protected $_errorCode=UPLOAD_ERR_NO_FILE;
- private $_dataChanged=false;
- private $_isValid=true;
-
- /**
- * @return string tag name of the file upload control
- */
- protected function getTagName()
- {
- return 'input';
- }
-
- /**
- * Sets name attribute to the unique ID of the control.
- * This method overrides the parent implementation with additional file update control specific attributes.
- * @param THtmlWriter the writer used for the rendering purpose
- */
- protected function addAttributesToRender($writer)
- {
- $this->getPage()->ensureRenderInForm($this);
- parent::addAttributesToRender($writer);
- $writer->addAttribute('type','file');
- $writer->addAttribute('name',$this->getUniqueID());
- $isEnabled=$this->getEnabled(true);
- if(!$isEnabled && $this->getEnabled()) // in this case parent will not render 'disabled'
- $writer->addAttribute('disabled','disabled');
- }
-
- /**
- * Sets Enctype of the form on the page.
- * This method overrides the parent implementation and is invoked before render.
- * @param mixed event parameter
- */
- public function onPreRender($param)
- {
- parent::onPreRender($param);
- if(($form=$this->getPage()->getForm())!==null)
- $form->setEnctype('multipart/form-data');
- $this->getPage()->getClientScript()->registerHiddenField('MAX_FILE_SIZE',$this->getMaxFileSize());
- if($this->getEnabled(true))
- $this->getPage()->registerRequiresPostData($this);
- }
-
- /**
- * @return integer the maximum file size, defaults to 1MB (1048576 bytes).
- * @see setMaxFileSize
- */
- public function getMaxFileSize()
- {
- return $this->getViewState('MaxFileSize',self::MAX_FILE_SIZE);
- }
-
- /**
- * Sets the maximum size that a file can be uploaded.
- * Note, this is an advisory value to the browser. Sets this property with
- * a reasonably large size to save users the trouble of waiting
- * for a big file being transferred only to find that it was too big
- * and the transfer failed.
- * @param int the maximum upload size allowed for a file.
- */
- public function setMaxFileSize($size)
- {
- $this->setViewState('MaxFileSize',TPropertyValue::ensureInteger($size),self::MAX_FILE_SIZE);
- }
-
- /**
- * @return string the original full path name of the file on the client machine
- */
- public function getFileName()
- {
- return $this->_fileName;
- }
-
- /**
- * @return integer the actual size of the uploaded file in bytes
- */
- public function getFileSize()
- {
- return $this->_fileSize;
- }
-
- /**
- * @return string the MIME-type of the uploaded file (such as "image/gif").
- * This mime type is not checked on the server side and do not take its value for granted.
- */
- public function getFileType()
- {
- return $this->_fileType;
- }
-
- /**
- * @return string the local name of the file (where it is after being uploaded).
- * Note, PHP will delete this file automatically after finishing this round of request.
- */
- public function getLocalName()
- {
- return $this->_localName;
- }
-
- /**
- * Returns an error code describing the status of this file uploading.
- * @return integer the error code
- * @see http://www.php.net/manual/en/features.file-upload.errors.php
- */
- public function getErrorCode()
- {
- return $this->_errorCode;
- }
-
- /**
- * @return boolean whether the file is uploaded successfully
- */
- public function getHasFile()
- {
- return $this->_errorCode===UPLOAD_ERR_OK;
- }
-
- /**
- * Saves the uploaded file.
- * @param string the file name used to save the uploaded file
- * @param boolean whether to delete the temporary file after saving.
- * If true, you will not be able to save the uploaded file again.
- * @return boolean true if the file saving is successful
- */
- public function saveAs($fileName,$deleteTempFile=true)
- {
- if($this->_errorCode===UPLOAD_ERR_OK)
- {
- if($deleteTempFile)
- return move_uploaded_file($this->_localName,$fileName);
- else if(is_uploaded_file($this->_localName))
- return file_put_contents($fileName,file_get_contents($this->_localName))!==false;
- else
- return false;
- }
- else
- return false;
- }
-
- /**
- * Loads user input data.
- * This method is primarly used by framework developers.
- * @param string the key that can be used to retrieve data from the input data collection
- * @param array the input data collection
- * @return boolean whether the data of the control has been changed
- */
- public function loadPostData($key,$values)
- {
- if(isset($_FILES[$key]))
- {
- $this->_fileName=$_FILES[$key]['name'];
- $this->_fileSize=$_FILES[$key]['size'];
- $this->_fileType=$_FILES[$key]['type'];
- $this->_errorCode=$_FILES[$key]['error'];
- $this->_localName=$_FILES[$key]['tmp_name'];
- return $this->_dataChanged=true;
- }
- else
- return false;
- }
-
- /**
- * Raises postdata changed event.
- * This method calls {@link onFileUpload} method.
- * This method is primarly used by framework developers.
- */
- public function raisePostDataChangedEvent()
- {
- $this->onFileUpload(null);
- }
-
- /**
- * This method is invoked when a file is uploaded during a postback.
- * The method raises <b>OnFileUpload</b> event to fire up the event handler.
- * If you override this method, be sure to call the parent implementation
- * so that the event delegates can be invoked.
- * @param TEventParameter event parameter to be passed to the event handlers
- */
- public function onFileUpload($param)
- {
- $this->raiseEvent('OnFileUpload',$this,$param);
- }
-
- /**
- * Returns a value indicating whether postback has caused the control data change.
- * This method is required by the IPostBackDataHandler interface.
- * @return boolean whether postback has caused the control data change. False if the page is not in postback mode.
- */
- public function getDataChanged()
- {
- return $this->_dataChanged;
- }
-
- /**
- * Returns the original file name as the property value to be validated.
- * This method is required by IValidatable property.
- * @return mixed the property value to be validated
- */
- public function getValidationPropertyValue()
- {
- return $this->getFileName();
- }
-
- /**
- * Returns true if this control validated successfully.
- * Defaults to true.
- * @return bool wether this control validated successfully.
- */
- public function getIsValid()
- {
- return $this->_isValid;
- }
- /**
- * @param bool wether this control is valid.
- */
- public function setIsValid($value)
- {
- $this->_isValid=TPropertyValue::ensureBoolean($value);
- }
-
-}
-
+<?php
+/**
+ * TFileUpload class file
+ *
+ * @author Marcus Nyeholt <tanus@users.sourceforge.net>, Qiang Xue <qiang.xue@gmail.com>
+ * @link http://www.pradosoft.com/
+ * @copyright Copyright &copy; 2005-2012 PradoSoft
+ * @license http://www.pradosoft.com/license/
+ * @version $Id$
+ * @package System.Web.UI.WebControls
+ */
+
+/**
+ * TFileUpload class
+ *
+ * TFileUpload displays a file upload field on a page. Upon postback,
+ * the text entered into the field will be treated as the name of the file
+ * that will be uploaded to the server. The property {@link getHasFile HasFile}
+ * indicates whether the file upload is successful. If successful, the file
+ * may be obtained by calling {@link saveAs} to save it at a specified place.
+ * You can use {@link getFileName FileName}, {@link getFileType FileType},
+ * {@link getFileSize FileSize} to get the original client-side file name,
+ * the file mime type, and the file size information. If the upload is not
+ * successful, {@link getErrorCode ErrorCode} contains the error code
+ * describing the cause of failure.
+ *
+ * TFileUpload raises {@link onFileUpload OnFileUpload} event if a file is uploaded
+ * (whether it succeeds or not).
+ *
+ * @author Marcus Nyeholt <tanus@users.sourceforge.net>, Qiang Xue <qiang.xue@gmail.com>
+ * @version $Id$
+ * @package System.Web.UI.WebControls
+ * @since 3.0
+ */
+class TFileUpload extends TWebControl implements IPostBackDataHandler, IValidatable
+{
+ /**
+ * Maximum file size (in bytes) allowed to be uploaded, defaults to 1MB.
+ */
+ const MAX_FILE_SIZE=1048576;
+ /**
+ * @var integer the size of the uploaded file (in bytes)
+ */
+ private $_fileSize=0;
+ /**
+ * @var string The original name of the file on the client machine
+ */
+ private $_fileName='';
+ /**
+ * @var string the name of the temporary file storing the uploaded file
+ */
+ private $_localName='';
+ /**
+ * @var string the uploaded file mime type
+ */
+ private $_fileType='';
+ /**
+ * @var integer error code of the current file upload
+ */
+ protected $_errorCode=UPLOAD_ERR_NO_FILE;
+ private $_dataChanged=false;
+ private $_isValid=true;
+
+ /**
+ * @return string tag name of the file upload control
+ */
+ protected function getTagName()
+ {
+ return 'input';
+ }
+
+ /**
+ * Sets name attribute to the unique ID of the control.
+ * This method overrides the parent implementation with additional file update control specific attributes.
+ * @param THtmlWriter the writer used for the rendering purpose
+ */
+ protected function addAttributesToRender($writer)
+ {
+ $this->getPage()->ensureRenderInForm($this);
+ parent::addAttributesToRender($writer);
+ $writer->addAttribute('type','file');
+ $writer->addAttribute('name',$this->getUniqueID());
+ $isEnabled=$this->getEnabled(true);
+ if(!$isEnabled && $this->getEnabled()) // in this case parent will not render 'disabled'
+ $writer->addAttribute('disabled','disabled');
+ }
+
+ /**
+ * Sets Enctype of the form on the page.
+ * This method overrides the parent implementation and is invoked before render.
+ * @param mixed event parameter
+ */
+ public function onPreRender($param)
+ {
+ parent::onPreRender($param);
+ if(($form=$this->getPage()->getForm())!==null)
+ $form->setEnctype('multipart/form-data');
+ $this->getPage()->getClientScript()->registerHiddenField('MAX_FILE_SIZE',$this->getMaxFileSize());
+ if($this->getEnabled(true))
+ $this->getPage()->registerRequiresPostData($this);
+ }
+
+ /**
+ * @return integer the maximum file size, defaults to 1MB (1048576 bytes).
+ * @see setMaxFileSize
+ */
+ public function getMaxFileSize()
+ {
+ return $this->getViewState('MaxFileSize',self::MAX_FILE_SIZE);
+ }
+
+ /**
+ * Sets the maximum size that a file can be uploaded.
+ * Note, this is an advisory value to the browser. Sets this property with
+ * a reasonably large size to save users the trouble of waiting
+ * for a big file being transferred only to find that it was too big
+ * and the transfer failed.
+ * @param int the maximum upload size allowed for a file.
+ */
+ public function setMaxFileSize($size)
+ {
+ $this->setViewState('MaxFileSize',TPropertyValue::ensureInteger($size),self::MAX_FILE_SIZE);
+ }
+
+ /**
+ * @return string the original full path name of the file on the client machine
+ */
+ public function getFileName()
+ {
+ return $this->_fileName;
+ }
+
+ /**
+ * @return integer the actual size of the uploaded file in bytes
+ */
+ public function getFileSize()
+ {
+ return $this->_fileSize;
+ }
+
+ /**
+ * @return string the MIME-type of the uploaded file (such as "image/gif").
+ * This mime type is not checked on the server side and do not take its value for granted.
+ */
+ public function getFileType()
+ {
+ return $this->_fileType;
+ }
+
+ /**
+ * @return string the local name of the file (where it is after being uploaded).
+ * Note, PHP will delete this file automatically after finishing this round of request.
+ */
+ public function getLocalName()
+ {
+ return $this->_localName;
+ }
+
+ /**
+ * Returns an error code describing the status of this file uploading.
+ * @return integer the error code
+ * @see http://www.php.net/manual/en/features.file-upload.errors.php
+ */
+ public function getErrorCode()
+ {
+ return $this->_errorCode;
+ }
+
+ /**
+ * @return boolean whether the file is uploaded successfully
+ */
+ public function getHasFile()
+ {
+ return $this->_errorCode===UPLOAD_ERR_OK;
+ }
+
+ /**
+ * Saves the uploaded file.
+ * @param string the file name used to save the uploaded file
+ * @param boolean whether to delete the temporary file after saving.
+ * If true, you will not be able to save the uploaded file again.
+ * @return boolean true if the file saving is successful
+ */
+ public function saveAs($fileName,$deleteTempFile=true)
+ {
+ if($this->_errorCode===UPLOAD_ERR_OK)
+ {
+ if($deleteTempFile)
+ return move_uploaded_file($this->_localName,$fileName);
+ else if(is_uploaded_file($this->_localName))
+ return file_put_contents($fileName,file_get_contents($this->_localName))!==false;
+ else
+ return false;
+ }
+ else
+ return false;
+ }
+
+ /**
+ * Loads user input data.
+ * This method is primarly used by framework developers.
+ * @param string the key that can be used to retrieve data from the input data collection
+ * @param array the input data collection
+ * @return boolean whether the data of the control has been changed
+ */
+ public function loadPostData($key,$values)
+ {
+ if(isset($_FILES[$key]))
+ {
+ $this->_fileName=$_FILES[$key]['name'];
+ $this->_fileSize=$_FILES[$key]['size'];
+ $this->_fileType=$_FILES[$key]['type'];
+ $this->_errorCode=$_FILES[$key]['error'];
+ $this->_localName=$_FILES[$key]['tmp_name'];
+ return $this->_dataChanged=true;
+ }
+ else
+ return false;
+ }
+
+ /**
+ * Raises postdata changed event.
+ * This method calls {@link onFileUpload} method.
+ * This method is primarly used by framework developers.
+ */
+ public function raisePostDataChangedEvent()
+ {
+ $this->onFileUpload(null);
+ }
+
+ /**
+ * This method is invoked when a file is uploaded during a postback.
+ * The method raises <b>OnFileUpload</b> event to fire up the event handler.
+ * If you override this method, be sure to call the parent implementation
+ * so that the event delegates can be invoked.
+ * @param TEventParameter event parameter to be passed to the event handlers
+ */
+ public function onFileUpload($param)
+ {
+ $this->raiseEvent('OnFileUpload',$this,$param);
+ }
+
+ /**
+ * Returns a value indicating whether postback has caused the control data change.
+ * This method is required by the IPostBackDataHandler interface.
+ * @return boolean whether postback has caused the control data change. False if the page is not in postback mode.
+ */
+ public function getDataChanged()
+ {
+ return $this->_dataChanged;
+ }
+
+ /**
+ * Returns the original file name as the property value to be validated.
+ * This method is required by IValidatable property.
+ * @return mixed the property value to be validated
+ */
+ public function getValidationPropertyValue()
+ {
+ return $this->getFileName();
+ }
+
+ /**
+ * Returns true if this control validated successfully.
+ * Defaults to true.
+ * @return bool wether this control validated successfully.
+ */
+ public function getIsValid()
+ {
+ return $this->_isValid;
+ }
+ /**
+ * @param bool wether this control is valid.
+ */
+ public function setIsValid($value)
+ {
+ $this->_isValid=TPropertyValue::ensureBoolean($value);
+ }
+
+}
+
diff --git a/framework/Web/UI/WebControls/TFlushOutput.php b/framework/Web/UI/WebControls/TFlushOutput.php
index cc55646d..0ea9b389 100644
--- a/framework/Web/UI/WebControls/TFlushOutput.php
+++ b/framework/Web/UI/WebControls/TFlushOutput.php
@@ -1,86 +1,86 @@
-<?php
-/**
- * TFlushOutput class file
- *
- * @author Berczi Gabor <gabor.berczi@devworx.hu>
- * @link http://www.pradosoft.com/
- * @license http://www.pradosoft.com/license/
- * @version $Id: TFlushOutput.php $
- * @package System.Web.UI.WebControls
- */
-
-/**
- * TFlushOutput class.
- *
- * TFlushOutput enables forced flushing of the current output buffer
- * at (a) certain point(s) in the page, after rendering of all previous
- * controls has been completed.
- *
- * To use TFlushOutput, simply place it in a template where you want
- * the have the output buffered between the start of the page or the
- * last TFlushOutput to be sent to the client immediately
- * <code>
- * <com:TFlushOutput />
- * </code>
- *
- * You can specify whether you want to keep buffering of the output
- * (if it was enabled) till the next occourence of a <com: TFlushOutput />
- * or the end of the page rendering, or stop buffering, by using the
- * {@link setContinueBuffering ContinueBuffering}.
- *
- * @author Berczi Gabor <gabor.berczi@devworx.hu>
- * @version $Id: TFlushOutput.php $
- * @package System.Web.UI.WebControls
- * @since 3.1
- */
-class TFlushOutput extends TControl
-{
- /**
- * @var boolean whether to continue buffering of output
- */
- private $_continueBuffering=true;
-
-
- /**
- * Constructor.
- */
- public function __construct()
- {
- parent::__construct();
- $this->EnableViewState = false;
- }
-
- /**
- * @return Tells whether buffering of output can continue after this point
- */
- public function getContinueBuffering()
- {
- return $this->_continueBuffering;
- }
-
- /**
- * @param boolean sets whether buffering of output can continue after this point
- */
- public function setContinueBuffering($value)
- {
- $this->_continueBuffering = TPropertyValue::ensureBoolean($value);
- }
-
- /**
- * Flushes the output of all completely rendered controls to the client.
- * @param THtmlWriter writer for the rendering purpose
- */
- public function render($writer)
- {
-//$writer->write('<!-- flush -->');
- // ajax responses can't be parsed by the client side before loaded and returned completely,
- // so don't bother with flushing output somewhere mid-page if refreshing in a callback
- if (!$this->Page->IsCallback)
- {
- $this->Page->flushWriter();
-// $this->Application->flushOutput($this->ContinueBuffering);
- }
- }
-}
-
+<?php
+/**
+ * TFlushOutput class file
+ *
+ * @author Berczi Gabor <gabor.berczi@devworx.hu>
+ * @link http://www.pradosoft.com/
+ * @license http://www.pradosoft.com/license/
+ * @version $Id: TFlushOutput.php $
+ * @package System.Web.UI.WebControls
+ */
+
+/**
+ * TFlushOutput class.
+ *
+ * TFlushOutput enables forced flushing of the current output buffer
+ * at (a) certain point(s) in the page, after rendering of all previous
+ * controls has been completed.
+ *
+ * To use TFlushOutput, simply place it in a template where you want
+ * the have the output buffered between the start of the page or the
+ * last TFlushOutput to be sent to the client immediately
+ * <code>
+ * <com:TFlushOutput />
+ * </code>
+ *
+ * You can specify whether you want to keep buffering of the output
+ * (if it was enabled) till the next occourence of a <com: TFlushOutput />
+ * or the end of the page rendering, or stop buffering, by using the
+ * {@link setContinueBuffering ContinueBuffering}.
+ *
+ * @author Berczi Gabor <gabor.berczi@devworx.hu>
+ * @version $Id: TFlushOutput.php $
+ * @package System.Web.UI.WebControls
+ * @since 3.1
+ */
+class TFlushOutput extends TControl
+{
+ /**
+ * @var boolean whether to continue buffering of output
+ */
+ private $_continueBuffering=true;
+
+
+ /**
+ * Constructor.
+ */
+ public function __construct()
+ {
+ parent::__construct();
+ $this->EnableViewState = false;
+ }
+
+ /**
+ * @return Tells whether buffering of output can continue after this point
+ */
+ public function getContinueBuffering()
+ {
+ return $this->_continueBuffering;
+ }
+
+ /**
+ * @param boolean sets whether buffering of output can continue after this point
+ */
+ public function setContinueBuffering($value)
+ {
+ $this->_continueBuffering = TPropertyValue::ensureBoolean($value);
+ }
+
+ /**
+ * Flushes the output of all completely rendered controls to the client.
+ * @param THtmlWriter writer for the rendering purpose
+ */
+ public function render($writer)
+ {
+//$writer->write('<!-- flush -->');
+ // ajax responses can't be parsed by the client side before loaded and returned completely,
+ // so don't bother with flushing output somewhere mid-page if refreshing in a callback
+ if (!$this->Page->IsCallback)
+ {
+ $this->Page->flushWriter();
+// $this->Application->flushOutput($this->ContinueBuffering);
+ }
+ }
+}
+
?> \ No newline at end of file
diff --git a/framework/Web/UI/WebControls/TFont.php b/framework/Web/UI/WebControls/TFont.php
index 4da42508..771b6a4e 100644
--- a/framework/Web/UI/WebControls/TFont.php
+++ b/framework/Web/UI/WebControls/TFont.php
@@ -1,318 +1,318 @@
-<?php
-/**
- * TFont class file.
- *
- * @author Qiang Xue <qiang.xue@gmail.com>
- * @link http://www.pradosoft.com/
+<?php
+/**
+ * TFont class file.
+ *
+ * @author Qiang Xue <qiang.xue@gmail.com>
+ * @link http://www.pradosoft.com/
* @copyright Copyright &copy; 2005-2012 PradoSoft
- * @license http://www.pradosoft.com/license/
- * @version $Id$
- * @package System.Web.UI.WebControls
- */
-
-/**
- * TFont class
- *
- * TFont encapsulates the CSS style fields related with font settings.
- *
- * @author Qiang Xue <qiang.xue@gmail.com>
- * @version $Id$
- * @package System.Web.UI.WebControls
- * @since 3.0
- */
-class TFont extends TComponent
-{
- /**
- * Bits indicating the font states.
- */
- const IS_BOLD=0x01;
- const IS_ITALIC=0x02;
- const IS_OVERLINE=0x04;
- const IS_STRIKEOUT=0x08;
- const IS_UNDERLINE=0x10;
-
- /**
- * Bits indicating whether particular font states are changed.
- */
- const IS_SET_BOLD=0x01000;
- const IS_SET_ITALIC=0x02000;
- const IS_SET_OVERLINE=0x04000;
- const IS_SET_STRIKEOUT=0x08000;
- const IS_SET_UNDERLINE=0x10000;
- const IS_SET_SIZE=0x20000;
- const IS_SET_NAME=0x40000;
-
- /**
- * @var integer bits representing various states
- */
- private $_flags=0;
- /**
- * @var string font name
- */
- private $_name='';
- /**
- * @var string font size
- */
- private $_size='';
-
- /**
- * @return boolean whether the font is in bold face. Defaults to false.
- */
- public function getBold()
- {
- return ($this->_flags & self::IS_BOLD)!==0;
- }
-
- /**
- * @param boolean whether the font is in bold face
- */
- public function setBold($value)
- {
- $this->_flags |= self::IS_SET_BOLD;
- if(TPropertyValue::ensureBoolean($value))
- $this->_flags |= self::IS_BOLD;
- else
- $this->_flags &= ~self::IS_BOLD;
- }
-
- /**
- * @return boolean whether the font is in italic face. Defaults to false.
- */
- public function getItalic()
- {
- return ($this->_flags & self::IS_ITALIC)!==0;
- }
-
- /**
- * @param boolean whether the font is italic
- */
- public function setItalic($value)
- {
- $this->_flags |= self::IS_SET_ITALIC;
- if(TPropertyValue::ensureBoolean($value))
- $this->_flags |= self::IS_ITALIC;
- else
- $this->_flags &= ~self::IS_ITALIC;
- }
-
- /**
- * @return boolean whether the font is overlined. Defaults to false.
- */
- public function getOverline()
- {
- return ($this->_flags & self::IS_OVERLINE)!==0;
- }
-
- /**
- * @param boolean whether the font is overlined
- */
- public function setOverline($value)
- {
- $this->_flags |= self::IS_SET_OVERLINE;
- if(TPropertyValue::ensureBoolean($value))
- $this->_flags |= self::IS_OVERLINE;
- else
- $this->_flags &= ~self::IS_OVERLINE;
- }
-
- /**
- * @return string the font size
- */
- public function getSize()
- {
- return $this->_size;
- }
-
- /**
- * @param string the font size
- */
- public function setSize($value)
- {
- $this->_flags |= self::IS_SET_SIZE;
- $this->_size=$value;
- }
-
- /**
- * @return boolean whether the font is strikeout. Defaults to false.
- */
- public function getStrikeout()
- {
- return ($this->_flags & self::IS_STRIKEOUT)!==0;
- }
-
- /**
- * @param boolean whether the font is strikeout
- */
- public function setStrikeout($value)
- {
- $this->_flags |= self::IS_SET_STRIKEOUT;
- if(TPropertyValue::ensureBoolean($value))
- $this->_flags |= self::IS_STRIKEOUT;
- else
- $this->_flags &= ~self::IS_STRIKEOUT;
- }
-
- /**
- * @return boolean whether the font is underlined. Defaults to false.
- */
- public function getUnderline()
- {
- return ($this->_flags & self::IS_UNDERLINE)!==0;
- }
-
- /**
- * @param boolean whether the font is underlined
- */
- public function setUnderline($value)
- {
- $this->_flags |= self::IS_SET_UNDERLINE;
- if(TPropertyValue::ensureBoolean($value))
- $this->_flags |= self::IS_UNDERLINE;
- else
- $this->_flags &= ~self::IS_UNDERLINE;
- }
-
- /**
- * @return string the font name (family)
- */
- public function getName()
- {
- return $this->_name;
- }
-
- /**
- * @param string the font name (family)
- */
- public function setName($value)
- {
- $this->_flags |= self::IS_SET_NAME;
- $this->_name=$value;
- }
-
- /**
- * @return boolean whether the font is empty
- */
- public function getIsEmpty()
- {
- return !$this->_flags;
- }
-
- /**
- * Clears up the font.
- */
- public function reset()
- {
- $this->_flags=0;
- $this->_name='';
- $this->_size='';
- }
-
- /**
- * Merges the font with a new one.
- * If a font field is not set in the font, it will be overwritten with
- * the new one.
- * @param TFont the new font
- */
- public function mergeWith($font)
- {
- if($font===null || $font->_flags===0)
- return;
- if(!($this->_flags & self::IS_SET_BOLD) && ($font->_flags & self::IS_SET_BOLD))
- $this->setBold($font->getBold());
- if(!($this->_flags & self::IS_SET_ITALIC) && ($font->_flags & self::IS_SET_ITALIC))
- $this->setItalic($font->getItalic());
- if(!($this->_flags & self::IS_SET_OVERLINE) && ($font->_flags & self::IS_SET_OVERLINE))
- $this->setOverline($font->getOverline());
- if(!($this->_flags & self::IS_SET_STRIKEOUT) && ($font->_flags & self::IS_SET_STRIKEOUT))
- $this->setStrikeout($font->getStrikeout());
- if(!($this->_flags & self::IS_SET_UNDERLINE) && ($font->_flags & self::IS_SET_UNDERLINE))
- $this->setUnderline($font->getUnderline());
- if(!($this->_flags & self::IS_SET_SIZE) && ($font->_flags & self::IS_SET_SIZE))
- $this->setSize($font->getSize());
- if(!($this->_flags & self::IS_SET_NAME) && ($font->_flags & self::IS_SET_NAME))
- $this->setName($font->getName());
- }
-
- /**
- * Copies the fields in a new font to this font.
- * If a font field is set in the new font, the corresponding field
- * in this font will be overwritten.
- * @param TFont the new font
- */
- public function copyFrom($font)
- {
- if($font===null || $font->_flags===0)
- return;
- if($font->_flags & self::IS_SET_BOLD)
- $this->setBold($font->getBold());
- if($font->_flags & self::IS_SET_ITALIC)
- $this->setItalic($font->getItalic());
- if($font->_flags & self::IS_SET_OVERLINE)
- $this->setOverline($font->getOverline());
- if($font->_flags & self::IS_SET_STRIKEOUT)
- $this->setStrikeout($font->getStrikeout());
- if($font->_flags & self::IS_SET_UNDERLINE)
- $this->setUnderline($font->getUnderline());
- if($font->_flags & self::IS_SET_SIZE)
- $this->setSize($font->getSize());
- if($font->_flags & self::IS_SET_NAME)
- $this->setName($font->getName());
- }
-
- /**
- * @return string the font in a css style string representation.
- */
- public function toString()
- {
- if($this->_flags===0)
- return '';
- $str='';
- if($this->_flags & self::IS_SET_BOLD)
- $str.='font-weight:'.(($this->_flags & self::IS_BOLD)?'bold;':'normal;');
- if($this->_flags & self::IS_SET_ITALIC)
- $str.='font-style:'.(($this->_flags & self::IS_ITALIC)?'italic;':'normal;');
- $textDec='';
- if($this->_flags & self::IS_UNDERLINE)
- $textDec.='underline';
- if($this->_flags & self::IS_OVERLINE)
- $textDec.=' overline';
- if($this->_flags & self::IS_STRIKEOUT)
- $textDec.=' line-through';
- $textDec=ltrim($textDec);
- if($textDec!=='')
- $str.='text-decoration:'.$textDec.';';
- if($this->_size!=='')
- $str.='font-size:'.$this->_size.';';
- if($this->_name!=='')
- $str.='font-family:'.$this->_name.';';
- return $str;
- }
-
- /**
- * Adds attributes related to CSS styles to renderer.
- * @param THtmlWriter the writer used for the rendering purpose
- */
- public function addAttributesToRender($writer)
- {
- if($this->_flags===0)
- return;
- if($this->_flags & self::IS_SET_BOLD)
- $writer->addStyleAttribute('font-weight',(($this->_flags & self::IS_BOLD)?'bold':'normal'));
- if($this->_flags & self::IS_SET_ITALIC)
- $writer->addStyleAttribute('font-style',(($this->_flags & self::IS_ITALIC)?'italic':'normal'));
- $textDec='';
- if($this->_flags & self::IS_UNDERLINE)
- $textDec.='underline';
- if($this->_flags & self::IS_OVERLINE)
- $textDec.=' overline';
- if($this->_flags & self::IS_STRIKEOUT)
- $textDec.=' line-through';
- $textDec=ltrim($textDec);
- if($textDec!=='')
- $writer->addStyleAttribute('text-decoration',$textDec);
- if($this->_size!=='')
- $writer->addStyleAttribute('font-size',$this->_size);
- if($this->_name!=='')
- $writer->addStyleAttribute('font-family',$this->_name);
- }
-}
+ * @license http://www.pradosoft.com/license/
+ * @version $Id$
+ * @package System.Web.UI.WebControls
+ */
+
+/**
+ * TFont class
+ *
+ * TFont encapsulates the CSS style fields related with font settings.
+ *
+ * @author Qiang Xue <qiang.xue@gmail.com>
+ * @version $Id$
+ * @package System.Web.UI.WebControls
+ * @since 3.0
+ */
+class TFont extends TComponent
+{
+ /**
+ * Bits indicating the font states.
+ */
+ const IS_BOLD=0x01;
+ const IS_ITALIC=0x02;
+ const IS_OVERLINE=0x04;
+ const IS_STRIKEOUT=0x08;
+ const IS_UNDERLINE=0x10;
+
+ /**
+ * Bits indicating whether particular font states are changed.
+ */
+ const IS_SET_BOLD=0x01000;
+ const IS_SET_ITALIC=0x02000;
+ const IS_SET_OVERLINE=0x04000;
+ const IS_SET_STRIKEOUT=0x08000;
+ const IS_SET_UNDERLINE=0x10000;
+ const IS_SET_SIZE=0x20000;
+ const IS_SET_NAME=0x40000;
+
+ /**
+ * @var integer bits representing various states
+ */
+ private $_flags=0;
+ /**
+ * @var string font name
+ */
+ private $_name='';
+ /**
+ * @var string font size
+ */
+ private $_size='';
+
+ /**
+ * @return boolean whether the font is in bold face. Defaults to false.
+ */
+ public function getBold()
+ {
+ return ($this->_flags & self::IS_BOLD)!==0;
+ }
+
+ /**
+ * @param boolean whether the font is in bold face
+ */
+ public function setBold($value)
+ {
+ $this->_flags |= self::IS_SET_BOLD;
+ if(TPropertyValue::ensureBoolean($value))
+ $this->_flags |= self::IS_BOLD;
+ else
+ $this->_flags &= ~self::IS_BOLD;
+ }
+
+ /**
+ * @return boolean whether the font is in italic face. Defaults to false.
+ */
+ public function getItalic()
+ {
+ return ($this->_flags & self::IS_ITALIC)!==0;
+ }
+
+ /**
+ * @param boolean whether the font is italic
+ */
+ public function setItalic($value)
+ {
+ $this->_flags |= self::IS_SET_ITALIC;
+ if(TPropertyValue::ensureBoolean($value))
+ $this->_flags |= self::IS_ITALIC;
+ else
+ $this->_flags &= ~self::IS_ITALIC;
+ }
+
+ /**
+ * @return boolean whether the font is overlined. Defaults to false.
+ */
+ public function getOverline()
+ {
+ return ($this->_flags & self::IS_OVERLINE)!==0;
+ }
+
+ /**
+ * @param boolean whether the font is overlined
+ */
+ public function setOverline($value)
+ {
+ $this->_flags |= self::IS_SET_OVERLINE;
+ if(TPropertyValue::ensureBoolean($value))
+ $this->_flags |= self::IS_OVERLINE;
+ else
+ $this->_flags &= ~self::IS_OVERLINE;
+ }
+
+ /**
+ * @return string the font size
+ */
+ public function getSize()
+ {
+ return $this->_size;
+ }
+
+ /**
+ * @param string the font size
+ */
+ public function setSize($value)
+ {
+ $this->_flags |= self::IS_SET_SIZE;
+ $this->_size=$value;
+ }
+
+ /**
+ * @return boolean whether the font is strikeout. Defaults to false.
+ */
+ public function getStrikeout()
+ {
+ return ($this->_flags & self::IS_STRIKEOUT)!==0;
+ }
+
+ /**
+ * @param boolean whether the font is strikeout
+ */
+ public function setStrikeout($value)
+ {
+ $this->_flags |= self::IS_SET_STRIKEOUT;
+ if(TPropertyValue::ensureBoolean($value))
+ $this->_flags |= self::IS_STRIKEOUT;
+ else
+ $this->_flags &= ~self::IS_STRIKEOUT;
+ }
+
+ /**
+ * @return boolean whether the font is underlined. Defaults to false.
+ */
+ public function getUnderline()
+ {
+ return ($this->_flags & self::IS_UNDERLINE)!==0;
+ }
+
+ /**
+ * @param boolean whether the font is underlined
+ */
+ public function setUnderline($value)
+ {
+ $this->_flags |= self::IS_SET_UNDERLINE;
+ if(TPropertyValue::ensureBoolean($value))
+ $this->_flags |= self::IS_UNDERLINE;
+ else
+ $this->_flags &= ~self::IS_UNDERLINE;
+ }
+
+ /**
+ * @return string the font name (family)
+ */
+ public function getName()
+ {
+ return $this->_name;
+ }
+
+ /**
+ * @param string the font name (family)
+ */
+ public function setName($value)
+ {
+ $this->_flags |= self::IS_SET_NAME;
+ $this->_name=$value;
+ }
+
+ /**
+ * @return boolean whether the font is empty
+ */
+ public function getIsEmpty()
+ {
+ return !$this->_flags;
+ }
+
+ /**
+ * Clears up the font.
+ */
+ public function reset()
+ {
+ $this->_flags=0;
+ $this->_name='';
+ $this->_size='';
+ }
+
+ /**
+ * Merges the font with a new one.
+ * If a font field is not set in the font, it will be overwritten with
+ * the new one.
+ * @param TFont the new font
+ */
+ public function mergeWith($font)
+ {
+ if($font===null || $font->_flags===0)
+ return;
+ if(!($this->_flags & self::IS_SET_BOLD) && ($font->_flags & self::IS_SET_BOLD))
+ $this->setBold($font->getBold());
+ if(!($this->_flags & self::IS_SET_ITALIC) && ($font->_flags & self::IS_SET_ITALIC))
+ $this->setItalic($font->getItalic());
+ if(!($this->_flags & self::IS_SET_OVERLINE) && ($font->_flags & self::IS_SET_OVERLINE))
+ $this->setOverline($font->getOverline());
+ if(!($this->_flags & self::IS_SET_STRIKEOUT) && ($font->_flags & self::IS_SET_STRIKEOUT))
+ $this->setStrikeout($font->getStrikeout());
+ if(!($this->_flags & self::IS_SET_UNDERLINE) && ($font->_flags & self::IS_SET_UNDERLINE))
+ $this->setUnderline($font->getUnderline());
+ if(!($this->_flags & self::IS_SET_SIZE) && ($font->_flags & self::IS_SET_SIZE))
+ $this->setSize($font->getSize());
+ if(!($this->_flags & self::IS_SET_NAME) && ($font->_flags & self::IS_SET_NAME))
+ $this->setName($font->getName());
+ }
+
+ /**
+ * Copies the fields in a new font to this font.
+ * If a font field is set in the new font, the corresponding field
+ * in this font will be overwritten.
+ * @param TFont the new font
+ */
+ public function copyFrom($font)
+ {
+ if($font===null || $font->_flags===0)
+ return;
+ if($font->_flags & self::IS_SET_BOLD)
+ $this->setBold($font->getBold());
+ if($font->_flags & self::IS_SET_ITALIC)
+ $this->setItalic($font->getItalic());
+ if($font->_flags & self::IS_SET_OVERLINE)
+ $this->setOverline($font->getOverline());
+ if($font->_flags & self::IS_SET_STRIKEOUT)
+ $this->setStrikeout($font->getStrikeout());
+ if($font->_flags & self::IS_SET_UNDERLINE)
+ $this->setUnderline($font->getUnderline());
+ if($font->_flags & self::IS_SET_SIZE)
+ $this->setSize($font->getSize());
+ if($font->_flags & self::IS_SET_NAME)
+ $this->setName($font->getName());
+ }
+
+ /**
+ * @return string the font in a css style string representation.
+ */
+ public function toString()
+ {
+ if($this->_flags===0)
+ return '';
+ $str='';
+ if($this->_flags & self::IS_SET_BOLD)
+ $str.='font-weight:'.(($this->_flags & self::IS_BOLD)?'bold;':'normal;');
+ if($this->_flags & self::IS_SET_ITALIC)
+ $str.='font-style:'.(($this->_flags & self::IS_ITALIC)?'italic;':'normal;');
+ $textDec='';
+ if($this->_flags & self::IS_UNDERLINE)
+ $textDec.='underline';
+ if($this->_flags & self::IS_OVERLINE)
+ $textDec.=' overline';
+ if($this->_flags & self::IS_STRIKEOUT)
+ $textDec.=' line-through';
+ $textDec=ltrim($textDec);
+ if($textDec!=='')
+ $str.='text-decoration:'.$textDec.';';
+ if($this->_size!=='')
+ $str.='font-size:'.$this->_size.';';
+ if($this->_name!=='')
+ $str.='font-family:'.$this->_name.';';
+ return $str;
+ }
+
+ /**
+ * Adds attributes related to CSS styles to renderer.
+ * @param THtmlWriter the writer used for the rendering purpose
+ */
+ public function addAttributesToRender($writer)
+ {
+ if($this->_flags===0)
+ return;
+ if($this->_flags & self::IS_SET_BOLD)
+ $writer->addStyleAttribute('font-weight',(($this->_flags & self::IS_BOLD)?'bold':'normal'));
+ if($this->_flags & self::IS_SET_ITALIC)
+ $writer->addStyleAttribute('font-style',(($this->_flags & self::IS_ITALIC)?'italic':'normal'));
+ $textDec='';
+ if($this->_flags & self::IS_UNDERLINE)
+ $textDec.='underline';
+ if($this->_flags & self::IS_OVERLINE)
+ $textDec.=' overline';
+ if($this->_flags & self::IS_STRIKEOUT)
+ $textDec.=' line-through';
+ $textDec=ltrim($textDec);
+ if($textDec!=='')
+ $writer->addStyleAttribute('text-decoration',$textDec);
+ if($this->_size!=='')
+ $writer->addStyleAttribute('font-size',$this->_size);
+ if($this->_name!=='')
+ $writer->addStyleAttribute('font-family',$this->_name);
+ }
+}
diff --git a/framework/Web/UI/WebControls/THead.php b/framework/Web/UI/WebControls/THead.php
index c0042c22..7966f2d3 100644
--- a/framework/Web/UI/WebControls/THead.php
+++ b/framework/Web/UI/WebControls/THead.php
@@ -1,377 +1,377 @@
-<?php
-/**
- * THead class file
- *
- * @author Marcus Nyeholt <tanus@users.sourceforge.net> and Qiang Xue <qiang.xue@gmail.com>
- * @link http://www.pradosoft.com/
- * @copyright Copyright &copy; 2005-2012 PradoSoft
- * @license http://www.pradosoft.com/license/
- * @version $Id$
- * @package System.Web.UI
- */
-
-/**
- * THead class
- *
- * THead displays a head element on a page. It displays the content
- * enclosed in its body and the page title set by the
- * {@link setTitle Title} property. In addition, stylesheets and JavaScripts registered via
- * {@link TClientScriptManager::registerStyleSheet}, {@link TClientScriptManager::registerStyleSheetFile}
- * {@link TClientScriptManager::registerHeadJavaScript}, and
- * {@link TClientScriptManager::registerHeadJavaScriptFile} will also be displayed
- * in the head.
- * THead also manages and displays meta tags through its {@link getMetaTags MetaTags}
- * property. You can add a meta object to the collection in code dynamically,
- * or add it in template using the following syntax,
- * <code>
- * <com:THead>
- * <com:TMetaTag HttpEquiv="Pragma" Content="no-cache" />
- * <com:TMetaTag Name="keywords" Content="Prado" />
- * </com:THead>
- * </code>
- *
- * Note, {@link TPage} has a property {@link TPage::getHead Head} that refers to
- * the THead control currently on the page. A page can have at most one THead
- * control. Although not required, it is recommended to place a THead on your page.
- * Without a THead on the page, stylesheets and javascripts in the current page
- * theme will not be rendered.
- *
- * @author Marcus Nyeholt <tanus@users.sourceforge.net> and Qiang Xue <qiang.xue@gmail.com>
- * @version $Id$
- * @package System.Web.UI
- * @since 3.0
- */
-class THead extends TControl
-{
- /**
- * @var TList list of meta name tags to be loaded by {@link THead}
- */
- private $_metaTags=null;
-
- /**
- * Registers the head control with the current page.
- * This method is invoked when the control enters 'Init' stage.
- * The method raises 'Init' event.
- * If you override this method, be sure to call the parent implementation
- * so that the event handlers can be invoked.
- * @param TEventParameter event parameter to be passed to the event handlers
- */
- public function onInit($param)
- {
- parent::onInit($param);
- $this->getPage()->setHead($this);
- }
-
- /**
- * Processes an object that is created during parsing template.
- * This method adds TMetaTag components into the {@link getMetaTags MetaTags}
- * collection of the head control.
- * @param string|TComponent text string or component parsed and instantiated in template
- * @see createdOnTemplate
- */
- public function addParsedObject($object)
- {
- if($object instanceof TMetaTag)
- $this->getMetaTags()->add($object);
- else
- parent::addParsedObject($object);
- }
-
- /**
- * @return string the page title.
- */
- public function getTitle()
- {
- return $this->getViewState('Title','');
- }
-
- /**
- * Sets the page title.
- * This title will be rendered only if the {@link TPage::getTitle Title} property
- * of the page is empty.
- * @param string the page title.
- */
- public function setTitle($value)
- {
- $this->setViewState('Title',$value,'');
- }
-
- /**
- * @return string base URL of the page. This URL is rendered as the 'href' attribute of <base> tag. Defaults to ''.
- */
- public function getBaseUrl()
- {
- return $this->getViewState('BaseUrl','');
- }
-
- /**
- * @param string base URL of the page. This URL is rendered as the 'href' attribute of <base> tag.
- */
- public function setBaseUrl($url)
- {
- $this->setViewState('BaseUrl',$url,'');
- }
-
- /**
- * @return string the URL for the shortcut icon of the page. Defaults to ''.
- */
- public function getShortcutIcon()
- {
- return $this->getViewState('ShortcutIcon','');
- }
-
- /**
- * @param string the URL for the shortcut icon of the page.
- */
- public function setShortcutIcon($url)
- {
- $this->setViewState('ShortcutIcon',$url,'');
- }
-
- /**
- * @return TMetaTagCollection meta tag collection
- */
- public function getMetaTags()
- {
- if(($metaTags=$this->getViewState('MetaTags',null))===null)
- {
- $metaTags=new TMetaTagCollection;
- $this->setViewState('MetaTags',$metaTags,null);
- }
- return $metaTags;
- }
-
- /**
- * Renders the head control.
- * @param THtmlWriter the writer for rendering purpose.
- */
- public function render($writer)
- {
- $page=$this->getPage();
- $title=$this->getTitle();
- $writer->write("<head>\n<title>".THttpUtility::htmlEncode($title)."</title>\n");
- if(($baseUrl=$this->getBaseUrl())!=='')
- $writer->write('<base href="'.$baseUrl."\" />\n");
- if(($icon=$this->getShortcutIcon())!=='')
- $writer->write('<link rel="shortcut icon" href="'.$icon."\" />\n");
-
- if(($metaTags=$this->getMetaTags())!==null)
- {
- foreach($metaTags as $metaTag)
- {
- $metaTag->render($writer);
- $writer->writeLine();
- }
- }
- $cs=$page->getClientScript();
- $cs->renderStyleSheetFiles($writer);
- $cs->renderStyleSheets($writer);
- if($page->getClientSupportsJavaScript())
- {
- $cs->renderHeadScriptFiles($writer);
- $cs->renderHeadScripts($writer);
- }
- parent::render($writer);
- $writer->write("</head>\n");
- }
-}
-
-/**
- * TMetaTag class.
- *
- * TMetaTag represents a meta tag appearing in a page head section.
- * You can set its {@link setID ID}, {@link setHttpEquiv HttpEquiv},
- * {@link setName Name}, {@link setContent Content}, {@link setScheme Scheme}
- * properties, which correspond to id, http-equiv, name, content, and scheme
- * attributes for a meta tag, respectively.
- *
- * @author Qiang Xue <qiang.xue@gmail.com>
- * @version $Id$
- * @package System.Web.UI.WebControls
- * @since 3.0
- */
-class TMetaTag extends TComponent
-{
- /**
- * @var string id of the meta tag
- */
- private $_id='';
- /**
- * @var string http-equiv attribute of the meta tag
- */
- private $_httpEquiv='';
- /**
- * @var string name attribute of the meta tag
- */
- private $_name='';
- /**
- * @var string content attribute of the meta tag
- */
- private $_content='';
- /**
- * @var string scheme attribute of the meta tag
- */
- private $_scheme='';
-
- /**
- * @return string id of the meta tag
- */
- public function getID()
- {
- return $this->_id;
- }
-
- /**
- * @param string id of the meta tag
- */
- public function setID($value)
- {
- $this->_id=$value;
- }
-
- /**
- * @return string http-equiv attribute of the meta tag
- */
- public function getHttpEquiv()
- {
- return $this->_httpEquiv;
- }
-
- /**
- * @param string http-equiv attribute of the meta tag
- */
- public function setHttpEquiv($value)
- {
- $this->_httpEquiv=$value;
- }
-
- /**
- * @return string name attribute of the meta tag
- */
- public function getName()
- {
- return $this->_name;
- }
-
- /**
- * @param string name attribute of the meta tag
- */
- public function setName($value)
- {
- $this->_name=$value;
- }
-
- /**
- * @return string content attribute of the meta tag
- */
- public function getContent()
- {
- return $this->_content;
- }
-
- /**
- * @param string content attribute of the meta tag
- */
- public function setContent($value)
- {
- $this->_content=$value;
- }
-
- /**
- * @return string scheme attribute of the meta tag
- */
- public function getScheme()
- {
- return $this->_scheme;
- }
-
- /**
- * @param string scheme attribute of the meta tag
- */
- public function setScheme($value)
- {
- $this->_scheme=$value;
- }
-
- /**
- * Renders the meta tag.
- * @param THtmlWriter writer for the rendering purpose
- */
- public function render($writer)
- {
- if($this->_id!=='')
- $writer->addAttribute('id',$this->_id);
- if($this->_name!=='')
- $writer->addAttribute('name',$this->_name);
- if($this->_httpEquiv!=='')
- $writer->addAttribute('http-equiv',$this->_httpEquiv);
- if($this->_scheme!=='')
- $writer->addAttribute('scheme',$this->_scheme);
- $writer->addAttribute('content',$this->_content);
- $writer->renderBeginTag('meta');
- $writer->renderEndTag();
- }
-}
-
-
-/**
- * TMetaTagCollection class
- *
- * TMetaTagCollection represents a collection of meta tags
- * contained in a {@link THead} control.
- *
- * @author Qiang Xue <qiang.xue@gmail.com>
- * @version $Id$
- * @package System.Web.UI.WebControls
- * @since 3.0
- */
-class TMetaTagCollection extends TList
-{
- /**
- * Inserts an item at the specified position.
- * This overrides the parent implementation by performing type
- * check on the item being added.
- * @param integer the speicified position.
- * @param mixed new item
- * @throws TInvalidDataTypeException if the item to be inserted is not a {@link TMetaTag}
- */
- public function insertAt($index,$item)
- {
- if($item instanceof TMetaTag)
- parent::insertAt($index,$item);
- else
- throw new TInvalidDataTypeException('metatagcollection_metatag_invalid');
- }
-
- /**
- * Finds the lowest cardinal index of the meta tag whose id is the one being looked for.
- * @param string the ID of the meta tag to be looked for
- * @return integer the index of the meta tag found, -1 if not found.
- */
- public function findIndexByID($id)
- {
- $index=0;
- foreach($this as $item)
- {
- if($item->getID()===$id)
- return $index;
- $index++;
- }
- return -1;
- }
-
- /**
- * Finds the item whose value is the one being looked for.
- * @param string the id of the meta tag to be looked for
- * @return TMetaTag the meta tag found, null if not found.
- */
- public function findMetaTagByID($id)
- {
- if(($index=$this->findIndexByID($id))>=0)
- return $this->itemAt($index);
- else
- return null;
- }
-}
-
-?>
+<?php
+/**
+ * THead class file
+ *
+ * @author Marcus Nyeholt <tanus@users.sourceforge.net> and Qiang Xue <qiang.xue@gmail.com>
+ * @link http://www.pradosoft.com/
+ * @copyright Copyright &copy; 2005-2012 PradoSoft
+ * @license http://www.pradosoft.com/license/
+ * @version $Id$
+ * @package System.Web.UI
+ */
+
+/**
+ * THead class
+ *
+ * THead displays a head element on a page. It displays the content
+ * enclosed in its body and the page title set by the
+ * {@link setTitle Title} property. In addition, stylesheets and JavaScripts registered via
+ * {@link TClientScriptManager::registerStyleSheet}, {@link TClientScriptManager::registerStyleSheetFile}
+ * {@link TClientScriptManager::registerHeadJavaScript}, and
+ * {@link TClientScriptManager::registerHeadJavaScriptFile} will also be displayed
+ * in the head.
+ * THead also manages and displays meta tags through its {@link getMetaTags MetaTags}
+ * property. You can add a meta object to the collection in code dynamically,
+ * or add it in template using the following syntax,
+ * <code>
+ * <com:THead>
+ * <com:TMetaTag HttpEquiv="Pragma" Content="no-cache" />
+ * <com:TMetaTag Name="keywords" Content="Prado" />
+ * </com:THead>
+ * </code>
+ *
+ * Note, {@link TPage} has a property {@link TPage::getHead Head} that refers to
+ * the THead control currently on the page. A page can have at most one THead
+ * control. Although not required, it is recommended to place a THead on your page.
+ * Without a THead on the page, stylesheets and javascripts in the current page
+ * theme will not be rendered.
+ *
+ * @author Marcus Nyeholt <tanus@users.sourceforge.net> and Qiang Xue <qiang.xue@gmail.com>
+ * @version $Id$
+ * @package System.Web.UI
+ * @since 3.0
+ */
+class THead extends TControl
+{
+ /**
+ * @var TList list of meta name tags to be loaded by {@link THead}
+ */
+ private $_metaTags=null;
+
+ /**
+ * Registers the head control with the current page.
+ * This method is invoked when the control enters 'Init' stage.
+ * The method raises 'Init' event.
+ * If you override this method, be sure to call the parent implementation
+ * so that the event handlers can be invoked.
+ * @param TEventParameter event parameter to be passed to the event handlers
+ */
+ public function onInit($param)
+ {
+ parent::onInit($param);
+ $this->getPage()->setHead($this);
+ }
+
+ /**
+ * Processes an object that is created during parsing template.
+ * This method adds TMetaTag components into the {@link getMetaTags MetaTags}
+ * collection of the head control.
+ * @param string|TComponent text string or component parsed and instantiated in template
+ * @see createdOnTemplate
+ */
+ public function addParsedObject($object)
+ {
+ if($object instanceof TMetaTag)
+ $this->getMetaTags()->add($object);
+ else
+ parent::addParsedObject($object);
+ }
+
+ /**
+ * @return string the page title.
+ */
+ public function getTitle()
+ {
+ return $this->getViewState('Title','');
+ }
+
+ /**
+ * Sets the page title.
+ * This title will be rendered only if the {@link TPage::getTitle Title} property
+ * of the page is empty.
+ * @param string the page title.
+ */
+ public function setTitle($value)
+ {
+ $this->setViewState('Title',$value,'');
+ }
+
+ /**
+ * @return string base URL of the page. This URL is rendered as the 'href' attribute of <base> tag. Defaults to ''.
+ */
+ public function getBaseUrl()
+ {
+ return $this->getViewState('BaseUrl','');
+ }
+
+ /**
+ * @param string base URL of the page. This URL is rendered as the 'href' attribute of <base> tag.
+ */
+ public function setBaseUrl($url)
+ {
+ $this->setViewState('BaseUrl',$url,'');
+ }
+
+ /**
+ * @return string the URL for the shortcut icon of the page. Defaults to ''.
+ */
+ public function getShortcutIcon()
+ {
+ return $this->getViewState('ShortcutIcon','');
+ }
+
+ /**
+ * @param string the URL for the shortcut icon of the page.
+ */
+ public function setShortcutIcon($url)
+ {
+ $this->setViewState('ShortcutIcon',$url,'');
+ }
+
+ /**
+ * @return TMetaTagCollection meta tag collection
+ */
+ public function getMetaTags()
+ {
+ if(($metaTags=$this->getViewState('MetaTags',null))===null)
+ {
+ $metaTags=new TMetaTagCollection;
+ $this->setViewState('MetaTags',$metaTags,null);
+ }
+ return $metaTags;
+ }
+
+ /**
+ * Renders the head control.
+ * @param THtmlWriter the writer for rendering purpose.
+ */
+ public function render($writer)
+ {
+ $page=$this->getPage();
+ $title=$this->getTitle();
+ $writer->write("<head>\n<title>".THttpUtility::htmlEncode($title)."</title>\n");
+ if(($baseUrl=$this->getBaseUrl())!=='')
+ $writer->write('<base href="'.$baseUrl."\" />\n");
+ if(($icon=$this->getShortcutIcon())!=='')
+ $writer->write('<link rel="shortcut icon" href="'.$icon."\" />\n");
+
+ if(($metaTags=$this->getMetaTags())!==null)
+ {
+ foreach($metaTags as $metaTag)
+ {
+ $metaTag->render($writer);
+ $writer->writeLine();
+ }
+ }
+ $cs=$page->getClientScript();
+ $cs->renderStyleSheetFiles($writer);
+ $cs->renderStyleSheets($writer);
+ if($page->getClientSupportsJavaScript())
+ {
+ $cs->renderHeadScriptFiles($writer);
+ $cs->renderHeadScripts($writer);
+ }
+ parent::render($writer);
+ $writer->write("</head>\n");
+ }
+}
+
+/**
+ * TMetaTag class.
+ *
+ * TMetaTag represents a meta tag appearing in a page head section.
+ * You can set its {@link setID ID}, {@link setHttpEquiv HttpEquiv},
+ * {@link setName Name}, {@link setContent Content}, {@link setScheme Scheme}
+ * properties, which correspond to id, http-equiv, name, content, and scheme
+ * attributes for a meta tag, respectively.
+ *
+ * @author Qiang Xue <qiang.xue@gmail.com>
+ * @version $Id$
+ * @package System.Web.UI.WebControls
+ * @since 3.0
+ */
+class TMetaTag extends TComponent
+{
+ /**
+ * @var string id of the meta tag
+ */
+ private $_id='';
+ /**
+ * @var string http-equiv attribute of the meta tag
+ */
+ private $_httpEquiv='';
+ /**
+ * @var string name attribute of the meta tag
+ */
+ private $_name='';
+ /**
+ * @var string content attribute of the meta tag
+ */
+ private $_content='';
+ /**
+ * @var string scheme attribute of the meta tag
+ */
+ private $_scheme='';
+
+ /**
+ * @return string id of the meta tag
+ */
+ public function getID()
+ {
+ return $this->_id;
+ }
+
+ /**
+ * @param string id of the meta tag
+ */
+ public function setID($value)
+ {
+ $this->_id=$value;
+ }
+
+ /**
+ * @return string http-equiv attribute of the meta tag
+ */
+ public function getHttpEquiv()
+ {
+ return $this->_httpEquiv;
+ }
+
+ /**
+ * @param string http-equiv attribute of the meta tag
+ */
+ public function setHttpEquiv($value)
+ {
+ $this->_httpEquiv=$value;
+ }
+
+ /**
+ * @return string name attribute of the meta tag
+ */
+ public function getName()
+ {
+ return $this->_name;
+ }
+
+ /**
+ * @param string name attribute of the meta tag
+ */
+ public function setName($value)
+ {
+ $this->_name=$value;
+ }
+
+ /**
+ * @return string content attribute of the meta tag
+ */
+ public function getContent()
+ {
+ return $this->_content;
+ }
+
+ /**
+ * @param string content attribute of the meta tag
+ */
+ public function setContent($value)
+ {
+ $this->_content=$value;
+ }
+
+ /**
+ * @return string scheme attribute of the meta tag
+ */
+ public function getScheme()
+ {
+ return $this->_scheme;
+ }
+
+ /**
+ * @param string scheme attribute of the meta tag
+ */
+ public function setScheme($value)
+ {
+ $this->_scheme=$value;
+ }
+
+ /**
+ * Renders the meta tag.
+ * @param THtmlWriter writer for the rendering purpose
+ */
+ public function render($writer)
+ {
+ if($this->_id!=='')
+ $writer->addAttribute('id',$this->_id);
+ if($this->_name!=='')
+ $writer->addAttribute('name',$this->_name);
+ if($this->_httpEquiv!=='')
+ $writer->addAttribute('http-equiv',$this->_httpEquiv);
+ if($this->_scheme!=='')
+ $writer->addAttribute('scheme',$this->_scheme);
+ $writer->addAttribute('content',$this->_content);
+ $writer->renderBeginTag('meta');
+ $writer->renderEndTag();
+ }
+}
+
+
+/**
+ * TMetaTagCollection class
+ *
+ * TMetaTagCollection represents a collection of meta tags
+ * contained in a {@link THead} control.
+ *
+ * @author Qiang Xue <qiang.xue@gmail.com>
+ * @version $Id$
+ * @package System.Web.UI.WebControls
+ * @since 3.0
+ */
+class TMetaTagCollection extends TList
+{
+ /**
+ * Inserts an item at the specified position.
+ * This overrides the parent implementation by performing type
+ * check on the item being added.
+ * @param integer the speicified position.
+ * @param mixed new item
+ * @throws TInvalidDataTypeException if the item to be inserted is not a {@link TMetaTag}
+ */
+ public function insertAt($index,$item)
+ {
+ if($item instanceof TMetaTag)
+ parent::insertAt($index,$item);
+ else
+ throw new TInvalidDataTypeException('metatagcollection_metatag_invalid');
+ }
+
+ /**
+ * Finds the lowest cardinal index of the meta tag whose id is the one being looked for.
+ * @param string the ID of the meta tag to be looked for
+ * @return integer the index of the meta tag found, -1 if not found.
+ */
+ public function findIndexByID($id)
+ {
+ $index=0;
+ foreach($this as $item)
+ {
+ if($item->getID()===$id)
+ return $index;
+ $index++;
+ }
+ return -1;
+ }
+
+ /**
+ * Finds the item whose value is the one being looked for.
+ * @param string the id of the meta tag to be looked for
+ * @return TMetaTag the meta tag found, null if not found.
+ */
+ public function findMetaTagByID($id)
+ {
+ if(($index=$this->findIndexByID($id))>=0)
+ return $this->itemAt($index);
+ else
+ return null;
+ }
+}
+
+?>
diff --git a/framework/Web/UI/WebControls/THiddenField.php b/framework/Web/UI/WebControls/THiddenField.php
index ac8ddfff..ec330d54 100644
--- a/framework/Web/UI/WebControls/THiddenField.php
+++ b/framework/Web/UI/WebControls/THiddenField.php
@@ -1,117 +1,117 @@
-<?php
-/**
- * THiddenField class file.
- *
- * @author Qiang Xue <qiang.xue@gmail.com>
- * @link http://www.xisc.com/
+<?php
+/**
+ * THiddenField class file.
+ *
+ * @author Qiang Xue <qiang.xue@gmail.com>
+ * @link http://www.xisc.com/
* @copyright Copyright &copy; 2005-2012 PradoSoft
- * @license http://www.opensource.org/licenses/bsd-license.php BSD License
- * @version $Id$
- * @package System.Web.UI.WebControls
- */
-
-/**
- * THiddenField class
- *
- * THiddenField displays a hidden input field on a Web page.
- * The value of the input field can be accessed via {@link getValue Value} property.
- * If upon postback the value is changed, a {@link onValueChanged OnValueChanged}
- * event will be raised.
- *
- * @author Qiang Xue <qiang.xue@gmail.com>
- * @version $Id$
- * @package System.Web.UI.WebControls
- * @since 3.0
- */
-class THiddenField extends TControl implements IPostBackDataHandler, IValidatable, IDataRenderer
-{
- private $_dataChanged=false;
+ * @license http://www.opensource.org/licenses/bsd-license.php BSD License
+ * @version $Id$
+ * @package System.Web.UI.WebControls
+ */
+
+/**
+ * THiddenField class
+ *
+ * THiddenField displays a hidden input field on a Web page.
+ * The value of the input field can be accessed via {@link getValue Value} property.
+ * If upon postback the value is changed, a {@link onValueChanged OnValueChanged}
+ * event will be raised.
+ *
+ * @author Qiang Xue <qiang.xue@gmail.com>
+ * @version $Id$
+ * @package System.Web.UI.WebControls
+ * @since 3.0
+ */
+class THiddenField extends TControl implements IPostBackDataHandler, IValidatable, IDataRenderer
+{
+ private $_dataChanged=false;
private $_isValid=true;
-
- /**
- * @return string tag name of the hidden field.
- */
- protected function getTagName()
- {
- return 'input';
- }
-
- /**
- * Sets focus to this control.
- * This method overrides the parent implementation by forbidding setting focus to this control.
- */
- public function focus()
- {
- throw new TNotSupportedException('hiddenfield_focus_unsupported');
- }
-
- /**
- * Renders the control.
- * This method overrides the parent implementation by rendering
- * the hidden field input element.
- * @param THtmlWriter the writer used for the rendering purpose
- */
- public function render($writer)
- {
- $uniqueID=$this->getUniqueID();
- $this->getPage()->ensureRenderInForm($this);
- $writer->addAttribute('type','hidden');
- if($uniqueID!=='')
- $writer->addAttribute('name',$uniqueID);
- if($this->getID()!=='')
- $writer->addAttribute('id',$this->getClientID());
- if(($value=$this->getValue())!=='')
- $writer->addAttribute('value',$value);
-
- if($this->getHasAttributes())
- {
- foreach($this->getAttributes() as $name=>$value)
- $writer->addAttribute($name,$value);
- }
-
- $writer->renderBeginTag('input');
- $writer->renderEndTag();
- }
-
- /**
- * Loads hidden field data.
- * This method is primarly used by framework developers.
- * @param string the key that can be used to retrieve data from the input data collection
- * @param array the input data collection
- * @return boolean whether the data of the component has been changed
- */
- public function loadPostData($key,$values)
- {
- $value=$values[$key];
- if($value===$this->getValue())
- return false;
- else
- {
- $this->setValue($value);
- return $this->_dataChanged=true;
- }
- }
-
- /**
- * Returns a value indicating whether postback has caused the control data change.
- * This method is required by the IPostBackDataHandler interface.
- * @return boolean whether postback has caused the control data change. False if the page is not in postback mode.
- */
- public function getDataChanged()
- {
- return $this->_dataChanged;
- }
-
- /**
- * Returns the value to be validated.
- * This methid is required by IValidatable interface.
- * @return mixed the value of the property to be validated.
- */
- public function getValidationPropertyValue()
- {
- return $this->getValue();
- }
-
+
+ /**
+ * @return string tag name of the hidden field.
+ */
+ protected function getTagName()
+ {
+ return 'input';
+ }
+
+ /**
+ * Sets focus to this control.
+ * This method overrides the parent implementation by forbidding setting focus to this control.
+ */
+ public function focus()
+ {
+ throw new TNotSupportedException('hiddenfield_focus_unsupported');
+ }
+
+ /**
+ * Renders the control.
+ * This method overrides the parent implementation by rendering
+ * the hidden field input element.
+ * @param THtmlWriter the writer used for the rendering purpose
+ */
+ public function render($writer)
+ {
+ $uniqueID=$this->getUniqueID();
+ $this->getPage()->ensureRenderInForm($this);
+ $writer->addAttribute('type','hidden');
+ if($uniqueID!=='')
+ $writer->addAttribute('name',$uniqueID);
+ if($this->getID()!=='')
+ $writer->addAttribute('id',$this->getClientID());
+ if(($value=$this->getValue())!=='')
+ $writer->addAttribute('value',$value);
+
+ if($this->getHasAttributes())
+ {
+ foreach($this->getAttributes() as $name=>$value)
+ $writer->addAttribute($name,$value);
+ }
+
+ $writer->renderBeginTag('input');
+ $writer->renderEndTag();
+ }
+
+ /**
+ * Loads hidden field data.
+ * This method is primarly used by framework developers.
+ * @param string the key that can be used to retrieve data from the input data collection
+ * @param array the input data collection
+ * @return boolean whether the data of the component has been changed
+ */
+ public function loadPostData($key,$values)
+ {
+ $value=$values[$key];
+ if($value===$this->getValue())
+ return false;
+ else
+ {
+ $this->setValue($value);
+ return $this->_dataChanged=true;
+ }
+ }
+
+ /**
+ * Returns a value indicating whether postback has caused the control data change.
+ * This method is required by the IPostBackDataHandler interface.
+ * @return boolean whether postback has caused the control data change. False if the page is not in postback mode.
+ */
+ public function getDataChanged()
+ {
+ return $this->_dataChanged;
+ }
+
+ /**
+ * Returns the value to be validated.
+ * This methid is required by IValidatable interface.
+ * @return mixed the value of the property to be validated.
+ */
+ public function getValidationPropertyValue()
+ {
+ return $this->getValue();
+ }
+
/**
* Returns true if this control validated successfully.
* Defaults to true.
@@ -129,96 +129,96 @@ class THiddenField extends TControl implements IPostBackDataHandler, IValidatabl
$this->_isValid=TPropertyValue::ensureBoolean($value);
}
- /**
- * Raises postdata changed event.
- * This method calls {@link onValueChanged} method.
- * This method is primarly used by framework developers.
- */
- public function raisePostDataChangedEvent()
- {
- $this->onValueChanged(null);
- }
-
- /**
- * This method is invoked when the value of the {@link getValue Value} property changes between posts to the server.
- * The method raises 'OnValueChanged' event to fire up the event delegates.
- * If you override this method, be sure to call the parent implementation
- * so that the attached event handlers can be invoked.
- * @param TEventParameter event parameter to be passed to the event handlers
- */
- public function onValueChanged($param)
- {
- $this->raiseEvent('OnValueChanged',$this,$param);
- }
-
- /**
- * @return string the value of the THiddenField
- */
- public function getValue()
- {
- return $this->getViewState('Value','');
- }
-
- /**
- * Sets the value of the THiddenField
- * @param string the value to be set
- */
- public function setValue($value)
- {
- $this->setViewState('Value',$value,'');
- }
-
- /**
- * Returns the value of the hidden field.
- * This method is required by {@link IDataRenderer}.
- * It is the same as {@link getValue()}.
- * @return string value of the hidden field
- * @see getValue
- * @since 3.1.0
- */
- public function getData()
- {
- return $this->getValue();
- }
-
- /**
- * Sets the value of the hidden field.
- * This method is required by {@link IDataRenderer}.
- * It is the same as {@link setValue()}.
- * @param string value of the hidden field
- * @see setValue
- * @since 3.1.0
- */
- public function setData($value)
- {
- $this->setValue($value);
- }
-
-
- /**
- * @return boolean whether theming is enabled for this control. Defaults to false.
- */
- public function getEnableTheming()
- {
- return false;
- }
-
- /**
- * @param boolean whether theming is enabled for this control.
- * @throws TNotSupportedException This method is always thrown when calling this method.
- */
- public function setEnableTheming($value)
- {
- throw new TNotSupportedException('hiddenfield_theming_unsupported');
- }
-
- /**
- * @param string Skin ID
- * @throws TNotSupportedException This method is always thrown when calling this method.
- */
- public function setSkinID($value)
- {
- throw new TNotSupportedException('hiddenfield_skinid_unsupported');
- }
-}
-
+ /**
+ * Raises postdata changed event.
+ * This method calls {@link onValueChanged} method.
+ * This method is primarly used by framework developers.
+ */
+ public function raisePostDataChangedEvent()
+ {
+ $this->onValueChanged(null);
+ }
+
+ /**
+ * This method is invoked when the value of the {@link getValue Value} property changes between posts to the server.
+ * The method raises 'OnValueChanged' event to fire up the event delegates.
+ * If you override this method, be sure to call the parent implementation
+ * so that the attached event handlers can be invoked.
+ * @param TEventParameter event parameter to be passed to the event handlers
+ */
+ public function onValueChanged($param)
+ {
+ $this->raiseEvent('OnValueChanged',$this,$param);
+ }
+
+ /**
+ * @return string the value of the THiddenField
+ */
+ public function getValue()
+ {
+ return $this->getViewState('Value','');
+ }
+
+ /**
+ * Sets the value of the THiddenField
+ * @param string the value to be set
+ */
+ public function setValue($value)
+ {
+ $this->setViewState('Value',$value,'');
+ }
+
+ /**
+ * Returns the value of the hidden field.
+ * This method is required by {@link IDataRenderer}.
+ * It is the same as {@link getValue()}.
+ * @return string value of the hidden field
+ * @see getValue
+ * @since 3.1.0
+ */
+ public function getData()
+ {
+ return $this->getValue();
+ }
+
+ /**
+ * Sets the value of the hidden field.
+ * This method is required by {@link IDataRenderer}.
+ * It is the same as {@link setValue()}.
+ * @param string value of the hidden field
+ * @see setValue
+ * @since 3.1.0
+ */
+ public function setData($value)
+ {
+ $this->setValue($value);
+ }
+
+
+ /**
+ * @return boolean whether theming is enabled for this control. Defaults to false.
+ */
+ public function getEnableTheming()
+ {
+ return false;
+ }
+
+ /**
+ * @param boolean whether theming is enabled for this control.
+ * @throws TNotSupportedException This method is always thrown when calling this method.
+ */
+ public function setEnableTheming($value)
+ {
+ throw new TNotSupportedException('hiddenfield_theming_unsupported');
+ }
+
+ /**
+ * @param string Skin ID
+ * @throws TNotSupportedException This method is always thrown when calling this method.
+ */
+ public function setSkinID($value)
+ {
+ throw new TNotSupportedException('hiddenfield_skinid_unsupported');
+ }
+}
+
diff --git a/framework/Web/UI/WebControls/THtmlElement.php b/framework/Web/UI/WebControls/THtmlElement.php
index 3889ee50..29cd0057 100644
--- a/framework/Web/UI/WebControls/THtmlElement.php
+++ b/framework/Web/UI/WebControls/THtmlElement.php
@@ -1,68 +1,68 @@
-<?php
-/**
- * THtmlElement class file.
- *
- * @author Qiang Xue <qiang.xue@gmail.com>
- * @link http://www.pradosoft.com/
- * @copyright Copyright &copy; 2005-2012 PradoSoft
- * @license http://www.pradosoft.com/license/
- * @version $Id$
- * @package System.Web.UI.WebControls
- */
-
-Prado::using('System.Web.UI.WebControls.TWebControl');
-
-/**
- * THtmlElement class.
- *
- * THtmlElement represents a generic HTML element whose tag name is specified
- * via {@link setTagName TagName} property. Because THtmlElement extends from
- * {@link TWebControl}, it enjoys all its functionalities.
- *
- * To change the default tag your subclass should override {@link getDefaultTagName}
- *
- * @author Qiang Xue <qiang.xue@gmail.com>
- * @author Brad Anderson <javalizard@gmail.com>
- * @version $Id$
- * @package System.Web.UI.WebControls
- * @since 3.1.2
- */
-class THtmlElement extends TWebControl
-{
- /**
- * @var the tag of this element
- */
- private $_tagName=null;
-
- /**
- * @return string the tag name of this control. Defaults to 'span'.
- */
- public function getTagName()
- {
- return ($this->_tagName !== null) ? $this->_tagName : ($this->_tagName = $this->getDefaultTagName());
- }
-
- /**
- * @param string the tag name of this control.
- */
- public function setTagName($value)
- {
- $this->_tagName=TPropertyValue::ensureString($value);
- }
-
- /**
- * This is the default tag when no other is specified
- * @return string the default tag
- */
- public function getDefaultTagName() {
- return 'span';
- }
-
- /**
- * This tells you if this TagName has deviated from the original
- * @return boolean true if TagName has deviated from the default.
- */
- public function getIsMutated() {
- return $this->_tagName !== null && $this->_tagName != $this->getDefaultTagName();
- }
-}
+<?php
+/**
+ * THtmlElement class file.
+ *
+ * @author Qiang Xue <qiang.xue@gmail.com>
+ * @link http://www.pradosoft.com/
+ * @copyright Copyright &copy; 2005-2012 PradoSoft
+ * @license http://www.pradosoft.com/license/
+ * @version $Id$
+ * @package System.Web.UI.WebControls
+ */
+
+Prado::using('System.Web.UI.WebControls.TWebControl');
+
+/**
+ * THtmlElement class.
+ *
+ * THtmlElement represents a generic HTML element whose tag name is specified
+ * via {@link setTagName TagName} property. Because THtmlElement extends from
+ * {@link TWebControl}, it enjoys all its functionalities.
+ *
+ * To change the default tag your subclass should override {@link getDefaultTagName}
+ *
+ * @author Qiang Xue <qiang.xue@gmail.com>
+ * @author Brad Anderson <javalizard@gmail.com>
+ * @version $Id$
+ * @package System.Web.UI.WebControls
+ * @since 3.1.2
+ */
+class THtmlElement extends TWebControl
+{
+ /**
+ * @var the tag of this element
+ */
+ private $_tagName=null;
+
+ /**
+ * @return string the tag name of this control. Defaults to 'span'.
+ */
+ public function getTagName()
+ {
+ return ($this->_tagName !== null) ? $this->_tagName : ($this->_tagName = $this->getDefaultTagName());
+ }
+
+ /**
+ * @param string the tag name of this control.
+ */
+ public function setTagName($value)
+ {
+ $this->_tagName=TPropertyValue::ensureString($value);
+ }
+
+ /**
+ * This is the default tag when no other is specified
+ * @return string the default tag
+ */
+ public function getDefaultTagName() {
+ return 'span';
+ }
+
+ /**
+ * This tells you if this TagName has deviated from the original
+ * @return boolean true if TagName has deviated from the default.
+ */
+ public function getIsMutated() {
+ return $this->_tagName !== null && $this->_tagName != $this->getDefaultTagName();
+ }
+}
diff --git a/framework/Web/UI/WebControls/THyperLink.php b/framework/Web/UI/WebControls/THyperLink.php
index 1e32d6c9..b745f7b0 100644
--- a/framework/Web/UI/WebControls/THyperLink.php
+++ b/framework/Web/UI/WebControls/THyperLink.php
@@ -1,227 +1,227 @@
-<?php
-/**
- * THyperLink class file.
- *
- * @author Qiang Xue <qiang.xue@gmail.com>
- * @link http://www.xisc.com/
- * @copyright Copyright &copy; 2005-2012 PradoSoft
- * @license http://www.opensource.org/licenses/bsd-license.php BSD License
- * @version $Id$
- * @package System.Web.UI.WebControls
- */
-
-/**
- * THyperLink class
- *
- * THyperLink displays a hyperlink on a page. The hyperlink URL is specified
- * via the {@link setNavigateUrl NavigateUrl} property, and link text is via
- * the {@link setText Text} property. It is also possible to display an image
- * by setting the {@link setImageUrl ImageUrl} property. In this case,
- * {@link getText Text} is displayed as the alternate text of the image.
- * The link target is specified via the {@link setTarget Target} property.
- * If both {@link getImageUrl ImageUrl} and {@link getText Text} are empty,
- * the content enclosed within the control tag will be rendered.
- *
- * @author Qiang Xue <qiang.xue@gmail.com>
- * @version $Id$
- * @package System.Web.UI.WebControls
- * @since 3.0
- */
-class THyperLink extends TWebControl implements IDataRenderer
-{
- /**
- * @return string tag name of the hyperlink
- */
- protected function getTagName()
- {
- return 'a';
- }
-
- /**
- * Adds attributes related to a hyperlink element to renderer.
- * @param THtmlWriter the writer used for the rendering purpose
- */
- protected function addAttributesToRender($writer)
- {
- $isEnabled=$this->getEnabled(true);
- if($this->getEnabled() && !$isEnabled)
- $writer->addAttribute('disabled','disabled');
- parent::addAttributesToRender($writer);
- if(($url=$this->getNavigateUrl())!=='' && $isEnabled)
- $writer->addAttribute('href',$url);
- if(($target=$this->getTarget())!=='')
- $writer->addAttribute('target',$target);
- }
-
- /**
- * Renders the body content of the hyperlink.
- * @param THtmlWriter the writer for rendering
- */
- public function renderContents($writer)
- {
- if(($imageUrl=$this->getImageUrl())==='')
- {
- if(($text=$this->getText())!=='')
- $writer->write(THttpUtility::htmlEncode($text));
- else if($this->getHasControls())
- parent::renderContents($writer);
- else
- $writer->write(THttpUtility::htmlEncode($this->getNavigateUrl()));
- }
- else
- {
- $this->createImage($imageUrl)->renderControl($writer);
- }
- }
-
- /**
- * Gets the TImage for rendering the ImageUrl property. This is not for
- * creating dynamic images.
- * @param string image url.
- * @return TImage image control for rendering.
- */
- protected function createImage($imageUrl)
- {
- $image=Prado::createComponent('System.Web.UI.WebControls.TImage');
- $image->setImageUrl($imageUrl);
- if(($width=$this->getImageWidth())!=='')
- $image->setWidth($width);
- if(($height=$this->getImageHeight())!=='')
- $image->setHeight($height);
- if(($toolTip=$this->getToolTip())!=='')
- $image->setToolTip($toolTip);
- if(($text=$this->getText())!=='')
- $image->setAlternateText($text);
- $image->setBorderWidth('0');
- return $image;
- }
-
- /**
- * @return string the text caption of the THyperLink
- */
- public function getText()
- {
- return $this->getViewState('Text','');
- }
-
- /**
- * Sets the text caption of the THyperLink.
- * @param string the text caption to be set
- */
- public function setText($value)
- {
- $this->setViewState('Text',$value,'');
- }
-
- /**
- * @return string height of the image in the THyperLink
- */
- public function getImageHeight()
- {
- return $this->getViewState('ImageHeight','');
- }
-
- /**
- * Sets the height of the image in the THyperLink
- * @param string height of the image in the THyperLink
- */
- public function setImageHeight($value)
- {
- $this->setViewSTate('ImageHeight',$value,'');
- }
-
- /**
- * @return string the location of the image file for the THyperLink
- */
- public function getImageUrl()
- {
- return $this->getViewState('ImageUrl','');
- }
-
- /**
- * Sets the location of image file of the THyperLink.
- * @param string the image file location
- */
- public function setImageUrl($value)
- {
- $this->setViewState('ImageUrl',$value,'');
- }
-
- /**
- * @return string width of the image in the THyperLink
- */
- public function getImageWidth()
- {
- return $this->getViewState('ImageWidth','');
- }
-
- /**
- * Sets the width of the image in the THyperLink
- * @param string width of the image
- */
- public function setImageWidth($value)
- {
- $this->setViewState('ImageWidth',$value,'');
- }
-
- /**
- * @return string the URL to link to when the THyperLink component is clicked.
- */
- public function getNavigateUrl()
- {
- return $this->getViewState('NavigateUrl','');
- }
-
- /**
- * Sets the URL to link to when the THyperLink component is clicked.
- * @param string the URL
- */
- public function setNavigateUrl($value)
- {
- $this->setViewState('NavigateUrl',$value,'');
- }
-
- /**
- * Returns the URL to link to when the THyperLink component is clicked.
- * This method is required by {@link IDataRenderer}.
- * It is the same as {@link getText()}.
- * @return string the text caption
- * @see getText
- * @since 3.1.0
- */
- public function getData()
- {
- return $this->getText();
- }
-
- /**
- * Sets the URL to link to when the THyperLink component is clicked.
- * This method is required by {@link IDataRenderer}.
- * It is the same as {@link setText()}.
- * @param string the text caption to be set
- * @see setText
- * @since 3.1.0
- */
- public function setData($value)
- {
- $this->setText($value);
- }
-
- /**
- * @return string the target window or frame to display the Web page content linked to when the THyperLink component is clicked.
- */
- public function getTarget()
- {
- return $this->getViewState('Target','');
- }
-
- /**
- * Sets the target window or frame to display the Web page content linked to when the THyperLink component is clicked.
- * @param string the target window, valid values include '_blank', '_parent', '_self', '_top' and empty string.
- */
- public function setTarget($value)
- {
- $this->setViewState('Target',$value,'');
- }
-}
-
+<?php
+/**
+ * THyperLink class file.
+ *
+ * @author Qiang Xue <qiang.xue@gmail.com>
+ * @link http://www.xisc.com/
+ * @copyright Copyright &copy; 2005-2012 PradoSoft
+ * @license http://www.opensource.org/licenses/bsd-license.php BSD License
+ * @version $Id$
+ * @package System.Web.UI.WebControls
+ */
+
+/**
+ * THyperLink class
+ *
+ * THyperLink displays a hyperlink on a page. The hyperlink URL is specified
+ * via the {@link setNavigateUrl NavigateUrl} property, and link text is via
+ * the {@link setText Text} property. It is also possible to display an image
+ * by setting the {@link setImageUrl ImageUrl} property. In this case,
+ * {@link getText Text} is displayed as the alternate text of the image.
+ * The link target is specified via the {@link setTarget Target} property.
+ * If both {@link getImageUrl ImageUrl} and {@link getText Text} are empty,
+ * the content enclosed within the control tag will be rendered.
+ *
+ * @author Qiang Xue <qiang.xue@gmail.com>
+ * @version $Id$
+ * @package System.Web.UI.WebControls
+ * @since 3.0
+ */
+class THyperLink extends TWebControl implements IDataRenderer
+{
+ /**
+ * @return string tag name of the hyperlink
+ */
+ protected function getTagName()
+ {
+ return 'a';
+ }
+
+ /**
+ * Adds attributes related to a hyperlink element to renderer.
+ * @param THtmlWriter the writer used for the rendering purpose
+ */
+ protected function addAttributesToRender($writer)
+ {
+ $isEnabled=$this->getEnabled(true);
+ if($this->getEnabled() && !$isEnabled)
+ $writer->addAttribute('disabled','disabled');
+ parent::addAttributesToRender($writer);
+ if(($url=$this->getNavigateUrl())!=='' && $isEnabled)
+ $writer->addAttribute('href',$url);
+ if(($target=$this->getTarget())!=='')
+ $writer->addAttribute('target',$target);
+ }
+
+ /**
+ * Renders the body content of the hyperlink.
+ * @param THtmlWriter the writer for rendering
+ */
+ public function renderContents($writer)
+ {
+ if(($imageUrl=$this->getImageUrl())==='')
+ {
+ if(($text=$this->getText())!=='')
+ $writer->write(THttpUtility::htmlEncode($text));
+ else if($this->getHasControls())
+ parent::renderContents($writer);
+ else
+ $writer->write(THttpUtility::htmlEncode($this->getNavigateUrl()));
+ }
+ else
+ {
+ $this->createImage($imageUrl)->renderControl($writer);
+ }
+ }
+
+ /**
+ * Gets the TImage for rendering the ImageUrl property. This is not for
+ * creating dynamic images.
+ * @param string image url.
+ * @return TImage image control for rendering.
+ */
+ protected function createImage($imageUrl)
+ {
+ $image=Prado::createComponent('System.Web.UI.WebControls.TImage');
+ $image->setImageUrl($imageUrl);
+ if(($width=$this->getImageWidth())!=='')
+ $image->setWidth($width);
+ if(($height=$this->getImageHeight())!=='')
+ $image->setHeight($height);
+ if(($toolTip=$this->getToolTip())!=='')
+ $image->setToolTip($toolTip);
+ if(($text=$this->getText())!=='')
+ $image->setAlternateText($text);
+ $image->setBorderWidth('0');
+ return $image;
+ }
+
+ /**
+ * @return string the text caption of the THyperLink
+ */
+ public function getText()
+ {
+ return $this->getViewState('Text','');
+ }
+
+ /**
+ * Sets the text caption of the THyperLink.
+ * @param string the text caption to be set
+ */
+ public function setText($value)
+ {
+ $this->setViewState('Text',$value,'');
+ }
+
+ /**
+ * @return string height of the image in the THyperLink
+ */
+ public function getImageHeight()
+ {
+ return $this->getViewState('ImageHeight','');
+ }
+
+ /**
+ * Sets the height of the image in the THyperLink
+ * @param string height of the image in the THyperLink
+ */
+ public function setImageHeight($value)
+ {
+ $this->setViewSTate('ImageHeight',$value,'');
+ }
+
+ /**
+ * @return string the location of the image file for the THyperLink
+ */
+ public function getImageUrl()
+ {
+ return $this->getViewState('ImageUrl','');
+ }
+
+ /**
+ * Sets the location of image file of the THyperLink.
+ * @param string the image file location
+ */
+ public function setImageUrl($value)
+ {
+ $this->setViewState('ImageUrl',$value,'');
+ }
+
+ /**
+ * @return string width of the image in the THyperLink
+ */
+ public function getImageWidth()
+ {
+ return $this->getViewState('ImageWidth','');
+ }
+
+ /**
+ * Sets the width of the image in the THyperLink
+ * @param string width of the image
+ */
+ public function setImageWidth($value)
+ {
+ $this->setViewState('ImageWidth',$value,'');
+ }
+
+ /**
+ * @return string the URL to link to when the THyperLink component is clicked.
+ */
+ public function getNavigateUrl()
+ {
+ return $this->getViewState('NavigateUrl','');
+ }
+
+ /**
+ * Sets the URL to link to when the THyperLink component is clicked.
+ * @param string the URL
+ */
+ public function setNavigateUrl($value)
+ {
+ $this->setViewState('NavigateUrl',$value,'');
+ }
+
+ /**
+ * Returns the URL to link to when the THyperLink component is clicked.
+ * This method is required by {@link IDataRenderer}.
+ * It is the same as {@link getText()}.
+ * @return string the text caption
+ * @see getText
+ * @since 3.1.0
+ */
+ public function getData()
+ {
+ return $this->getText();
+ }
+
+ /**
+ * Sets the URL to link to when the THyperLink component is clicked.
+ * This method is required by {@link IDataRenderer}.
+ * It is the same as {@link setText()}.
+ * @param string the text caption to be set
+ * @see setText
+ * @since 3.1.0
+ */
+ public function setData($value)
+ {
+ $this->setText($value);
+ }
+
+ /**
+ * @return string the target window or frame to display the Web page content linked to when the THyperLink component is clicked.
+ */
+ public function getTarget()
+ {
+ return $this->getViewState('Target','');
+ }
+
+ /**
+ * Sets the target window or frame to display the Web page content linked to when the THyperLink component is clicked.
+ * @param string the target window, valid values include '_blank', '_parent', '_self', '_top' and empty string.
+ */
+ public function setTarget($value)
+ {
+ $this->setViewState('Target',$value,'');
+ }
+}
+
diff --git a/framework/Web/UI/WebControls/THyperLinkColumn.php b/framework/Web/UI/WebControls/THyperLinkColumn.php
index a73880f1..faa4ce42 100644
--- a/framework/Web/UI/WebControls/THyperLinkColumn.php
+++ b/framework/Web/UI/WebControls/THyperLinkColumn.php
@@ -1,273 +1,273 @@
-<?php
-/**
- * THyperLinkColumn class file
- *
- * @author Qiang Xue <qiang.xue@gmail.com>
- * @link http://www.pradosoft.com/
- * @copyright Copyright &copy; 2005-2012 PradoSoft
- * @license http://www.pradosoft.com/license/
- * @version $Id$
- * @package System.Web.UI.WebControls
- */
-
-/**
- * TDataGridColumn class file
- */
-Prado::using('System.Web.UI.WebControls.TDataGridColumn');
-/**
- * THyperLink class file
- */
-Prado::using('System.Web.UI.WebControls.THyperLink');
-
-/**
- * THyperLinkColumn class
- *
- * THyperLinkColumn contains a hyperlink for each item in the column.
- * You can set the text and the url of the hyperlink by {@link setText Text}
- * and {@link setNavigateUrl NavigateUrl} properties, respectively.
- * You can also bind the text and url to specific data field in datasource
- * by setting {@link setDataTextField DataTextField} and
- * {@link setDataNavigateUrlField DataNavigateUrlField}.
- * Both can be formatted before rendering according to the
- * {@link setDataTextFormatString DataTextFormatString} and
- * and {@link setDataNavigateUrlFormatString DataNavigateUrlFormatString}
- * properties, respectively. If both {@link setText Text} and {@link setDataTextField DataTextField}
- * are present, the latter takes precedence.
- * The same rule applies to {@link setNavigateUrl NavigateUrl} and
- * {@link setDataNavigateUrlField DataNavigateUrlField} properties.
- *
- * The hyperlinks in the column can be accessed by one of the following two methods:
- * <code>
- * $datagridItem->HyperLinkColumnID->HyperLink
- * $datagridItem->HyperLinkColumnID->Controls[0]
- * </code>
- * The second method is possible because the hyperlink control created within the
- * datagrid cell is the first child.
- *
- * @author Qiang Xue <qiang.xue@gmail.com>
- * @version $Id$
- * @package System.Web.UI.WebControls
- * @since 3.0
- */
-class THyperLinkColumn extends TDataGridColumn
-{
- /**
- * @return string the text caption of the hyperlink
- */
- public function getText()
- {
- return $this->getViewState('Text','');
- }
-
- /**
- * Sets the text caption of the hyperlink.
- * @param string the text caption to be set
- */
- public function setText($value)
- {
- $this->setViewState('Text',$value,'');
- }
-
- /**
- * @return string the field name from the data source to bind to the hyperlink caption
- */
- public function getDataTextField()
- {
- return $this->getViewState('DataTextField','');
- }
-
- /**
- * @param string the field name from the data source to bind to the hyperlink caption
- */
- public function setDataTextField($value)
- {
- $this->setViewState('DataTextField',$value,'');
- }
-
- /**
- * @return string the formatting string used to control how the hyperlink caption will be displayed.
- */
- public function getDataTextFormatString()
- {
- return $this->getViewState('DataTextFormatString','');
- }
-
- /**
- * @param string the formatting string used to control how the hyperlink caption will be displayed.
- */
- public function setDataTextFormatString($value)
- {
- $this->setViewState('DataTextFormatString',$value,'');
- }
-
- /**
- * @return string height of the image in the THyperLink
- */
- public function getImageHeight()
- {
- return $this->getViewState('ImageHeight','');
- }
-
- /**
- * @param string height of the image in the THyperLink
- */
- public function setImageHeight($value)
- {
- $this->setViewState('ImageHeight',$value,'');
- }
-
- /**
- * @return string url of the image in the THyperLink
- */
- public function getImageUrl()
- {
- return $this->getViewState('ImageUrl','');
- }
-
- /**
- * @param string url of the image in the THyperLink
- */
- public function setImageUrl($value)
- {
- $this->setViewState('ImageUrl',$value,'');
- }
-
- /**
- * @return string width of the image in the THyperLink
- */
- public function getImageWidth()
- {
- return $this->getViewState('ImageWidth','');
- }
-
- /**
- * @param string width of the image in the THyperLink
- */
- public function setImageWidth($value)
- {
- $this->setViewState('ImageWidth',$value,'');
- }
-
- /**
- * @return string the URL to link to when the hyperlink is clicked.
- */
- public function getNavigateUrl()
- {
- return $this->getViewState('NavigateUrl','');
- }
-
- /**
- * Sets the URL to link to when the hyperlink is clicked.
- * @param string the URL
- */
- public function setNavigateUrl($value)
- {
- $this->setViewState('NavigateUrl',$value,'');
- }
-
- /**
- * @return string the field name from the data source to bind to the navigate url of hyperlink
- */
- public function getDataNavigateUrlField()
- {
- return $this->getViewState('DataNavigateUrlField','');
- }
-
- /**
- * @param string the field name from the data source to bind to the navigate url of hyperlink
- */
- public function setDataNavigateUrlField($value)
- {
- $this->setViewState('DataNavigateUrlField',$value,'');
- }
-
- /**
- * @return string the formatting string used to control how the navigate url of hyperlink will be displayed.
- */
- public function getDataNavigateUrlFormatString()
- {
- return $this->getViewState('DataNavigateUrlFormatString','');
- }
-
- /**
- * @param string the formatting string used to control how the navigate url of hyperlink will be displayed.
- */
- public function setDataNavigateUrlFormatString($value)
- {
- $this->setViewState('DataNavigateUrlFormatString',$value,'');
- }
-
- /**
- * @return string the target window or frame to display the Web page content linked to when the hyperlink is clicked.
- */
- public function getTarget()
- {
- return $this->getViewState('Target','');
- }
-
- /**
- * Sets the target window or frame to display the Web page content linked to when the hyperlink is clicked.
- * @param string the target window, valid values include '_blank', '_parent', '_self', '_top' and empty string.
- */
- public function setTarget($value)
- {
- $this->setViewState('Target',$value,'');
- }
-
- /**
- * Initializes the specified cell to its initial values.
- * This method overrides the parent implementation.
- * It creates a hyperlink within the cell.
- * @param TTableCell the cell to be initialized.
- * @param integer the index to the Columns property that the cell resides in.
- * @param string the type of cell (Header,Footer,Item,AlternatingItem,EditItem,SelectedItem)
- */
- public function initializeCell($cell,$columnIndex,$itemType)
- {
- if($itemType===TListItemType::Item || $itemType===TListItemType::AlternatingItem || $itemType===TListItemType::SelectedItem || $itemType===TListItemType::EditItem)
- {
- $link=new THyperLink;
- if(($url = $this->getImageUrl())!=='')
- {
- $link->setImageUrl($url);
- if(($width=$this->getImageWidth())!=='')
- $link->setImageWidth($width);
- if(($height=$this->getImageHeight())!=='')
- $link->setImageHeight($height);
- }
- $link->setText($this->getText());
- $link->setNavigateUrl($this->getNavigateUrl());
- $link->setTarget($this->getTarget());
- if($this->getDataTextField()!=='' || $this->getDataNavigateUrlField()!=='')
- $link->attachEventHandler('OnDataBinding',array($this,'dataBindColumn'));
- $cell->getControls()->add($link);
- $cell->registerObject('HyperLink',$link);
- }
- else
- parent::initializeCell($cell,$columnIndex,$itemType);
- }
-
- /**
- * Databinds a cell in the column.
- * This method is invoked when datagrid performs databinding.
- * It populates the content of the cell with the relevant data from data source.
- */
- public function dataBindColumn($sender,$param)
- {
- $item=$sender->getNamingContainer();
- $data=$item->getData();
- if(($field=$this->getDataTextField())!=='')
- {
- $value=$this->getDataFieldValue($data,$field);
- $text=$this->formatDataValue($this->getDataTextFormatString(),$value);
- $sender->setText($text);
- }
- if(($field=$this->getDataNavigateUrlField())!=='')
- {
- $value=$this->getDataFieldValue($data,$field);
- $url=$this->formatDataValue($this->getDataNavigateUrlFormatString(),$value);
- $sender->setNavigateUrl($url);
- }
- }
-}
-
+<?php
+/**
+ * THyperLinkColumn class file
+ *
+ * @author Qiang Xue <qiang.xue@gmail.com>
+ * @link http://www.pradosoft.com/
+ * @copyright Copyright &copy; 2005-2012 PradoSoft
+ * @license http://www.pradosoft.com/license/
+ * @version $Id$
+ * @package System.Web.UI.WebControls
+ */
+
+/**
+ * TDataGridColumn class file
+ */
+Prado::using('System.Web.UI.WebControls.TDataGridColumn');
+/**
+ * THyperLink class file
+ */
+Prado::using('System.Web.UI.WebControls.THyperLink');
+
+/**
+ * THyperLinkColumn class
+ *
+ * THyperLinkColumn contains a hyperlink for each item in the column.
+ * You can set the text and the url of the hyperlink by {@link setText Text}
+ * and {@link setNavigateUrl NavigateUrl} properties, respectively.
+ * You can also bind the text and url to specific data field in datasource
+ * by setting {@link setDataTextField DataTextField} and
+ * {@link setDataNavigateUrlField DataNavigateUrlField}.
+ * Both can be formatted before rendering according to the
+ * {@link setDataTextFormatString DataTextFormatString} and
+ * and {@link setDataNavigateUrlFormatString DataNavigateUrlFormatString}
+ * properties, respectively. If both {@link setText Text} and {@link setDataTextField DataTextField}
+ * are present, the latter takes precedence.
+ * The same rule applies to {@link setNavigateUrl NavigateUrl} and
+ * {@link setDataNavigateUrlField DataNavigateUrlField} properties.
+ *
+ * The hyperlinks in the column can be accessed by one of the following two methods:
+ * <code>
+ * $datagridItem->HyperLinkColumnID->HyperLink
+ * $datagridItem->HyperLinkColumnID->Controls[0]
+ * </code>
+ * The second method is possible because the hyperlink control created within the
+ * datagrid cell is the first child.
+ *
+ * @author Qiang Xue <qiang.xue@gmail.com>
+ * @version $Id$
+ * @package System.Web.UI.WebControls
+ * @since 3.0
+ */
+class THyperLinkColumn extends TDataGridColumn
+{
+ /**
+ * @return string the text caption of the hyperlink
+ */
+ public function getText()
+ {
+ return $this->getViewState('Text','');
+ }
+
+ /**
+ * Sets the text caption of the hyperlink.
+ * @param string the text caption to be set
+ */
+ public function setText($value)
+ {
+ $this->setViewState('Text',$value,'');
+ }
+
+ /**
+ * @return string the field name from the data source to bind to the hyperlink caption
+ */
+ public function getDataTextField()
+ {
+ return $this->getViewState('DataTextField','');
+ }
+
+ /**
+ * @param string the field name from the data source to bind to the hyperlink caption
+ */
+ public function setDataTextField($value)
+ {
+ $this->setViewState('DataTextField',$value,'');
+ }
+
+ /**
+ * @return string the formatting string used to control how the hyperlink caption will be displayed.
+ */
+ public function getDataTextFormatString()
+ {
+ return $this->getViewState('DataTextFormatString','');
+ }
+
+ /**
+ * @param string the formatting string used to control how the hyperlink caption will be displayed.
+ */
+ public function setDataTextFormatString($value)
+ {
+ $this->setViewState('DataTextFormatString',$value,'');
+ }
+
+ /**
+ * @return string height of the image in the THyperLink
+ */
+ public function getImageHeight()
+ {
+ return $this->getViewState('ImageHeight','');
+ }
+
+ /**
+ * @param string height of the image in the THyperLink
+ */
+ public function setImageHeight($value)
+ {
+ $this->setViewState('ImageHeight',$value,'');
+ }
+
+ /**
+ * @return string url of the image in the THyperLink
+ */
+ public function getImageUrl()
+ {
+ return $this->getViewState('ImageUrl','');
+ }
+
+ /**
+ * @param string url of the image in the THyperLink
+ */
+ public function setImageUrl($value)
+ {
+ $this->setViewState('ImageUrl',$value,'');
+ }
+
+ /**
+ * @return string width of the image in the THyperLink
+ */
+ public function getImageWidth()
+ {
+ return $this->getViewState('ImageWidth','');
+ }
+
+ /**
+ * @param string width of the image in the THyperLink
+ */
+ public function setImageWidth($value)
+ {
+ $this->setViewState('ImageWidth',$value,'');
+ }
+
+ /**
+ * @return string the URL to link to when the hyperlink is clicked.
+ */
+ public function getNavigateUrl()
+ {
+ return $this->getViewState('NavigateUrl','');
+ }
+
+ /**
+ * Sets the URL to link to when the hyperlink is clicked.
+ * @param string the URL
+ */
+ public function setNavigateUrl($value)
+ {
+ $this->setViewState('NavigateUrl',$value,'');
+ }
+
+ /**
+ * @return string the field name from the data source to bind to the navigate url of hyperlink
+ */
+ public function getDataNavigateUrlField()
+ {
+ return $this->getViewState('DataNavigateUrlField','');
+ }
+
+ /**
+ * @param string the field name from the data source to bind to the navigate url of hyperlink
+ */
+ public function setDataNavigateUrlField($value)
+ {
+ $this->setViewState('DataNavigateUrlField',$value,'');
+ }
+
+ /**
+ * @return string the formatting string used to control how the navigate url of hyperlink will be displayed.
+ */
+ public function getDataNavigateUrlFormatString()
+ {
+ return $this->getViewState('DataNavigateUrlFormatString','');
+ }
+
+ /**
+ * @param string the formatting string used to control how the navigate url of hyperlink will be displayed.
+ */
+ public function setDataNavigateUrlFormatString($value)
+ {
+ $this->setViewState('DataNavigateUrlFormatString',$value,'');
+ }
+
+ /**
+ * @return string the target window or frame to display the Web page content linked to when the hyperlink is clicked.
+ */
+ public function getTarget()
+ {
+ return $this->getViewState('Target','');
+ }
+
+ /**
+ * Sets the target window or frame to display the Web page content linked to when the hyperlink is clicked.
+ * @param string the target window, valid values include '_blank', '_parent', '_self', '_top' and empty string.
+ */
+ public function setTarget($value)
+ {
+ $this->setViewState('Target',$value,'');
+ }
+
+ /**
+ * Initializes the specified cell to its initial values.
+ * This method overrides the parent implementation.
+ * It creates a hyperlink within the cell.
+ * @param TTableCell the cell to be initialized.
+ * @param integer the index to the Columns property that the cell resides in.
+ * @param string the type of cell (Header,Footer,Item,AlternatingItem,EditItem,SelectedItem)
+ */
+ public function initializeCell($cell,$columnIndex,$itemType)
+ {
+ if($itemType===TListItemType::Item || $itemType===TListItemType::AlternatingItem || $itemType===TListItemType::SelectedItem || $itemType===TListItemType::EditItem)
+ {
+ $link=new THyperLink;
+ if(($url = $this->getImageUrl())!=='')
+ {
+ $link->setImageUrl($url);
+ if(($width=$this->getImageWidth())!=='')
+ $link->setImageWidth($width);
+ if(($height=$this->getImageHeight())!=='')
+ $link->setImageHeight($height);
+ }
+ $link->setText($this->getText());
+ $link->setNavigateUrl($this->getNavigateUrl());
+ $link->setTarget($this->getTarget());
+ if($this->getDataTextField()!=='' || $this->getDataNavigateUrlField()!=='')
+ $link->attachEventHandler('OnDataBinding',array($this,'dataBindColumn'));
+ $cell->getControls()->add($link);
+ $cell->registerObject('HyperLink',$link);
+ }
+ else
+ parent::initializeCell($cell,$columnIndex,$itemType);
+ }
+
+ /**
+ * Databinds a cell in the column.
+ * This method is invoked when datagrid performs databinding.
+ * It populates the content of the cell with the relevant data from data source.
+ */
+ public function dataBindColumn($sender,$param)
+ {
+ $item=$sender->getNamingContainer();
+ $data=$item->getData();
+ if(($field=$this->getDataTextField())!=='')
+ {
+ $value=$this->getDataFieldValue($data,$field);
+ $text=$this->formatDataValue($this->getDataTextFormatString(),$value);
+ $sender->setText($text);
+ }
+ if(($field=$this->getDataNavigateUrlField())!=='')
+ {
+ $value=$this->getDataFieldValue($data,$field);
+ $url=$this->formatDataValue($this->getDataNavigateUrlFormatString(),$value);
+ $sender->setNavigateUrl($url);
+ }
+ }
+}
+
diff --git a/framework/Web/UI/WebControls/TImage.php b/framework/Web/UI/WebControls/TImage.php
index 37f9a050..c8dde281 100644
--- a/framework/Web/UI/WebControls/TImage.php
+++ b/framework/Web/UI/WebControls/TImage.php
@@ -1,157 +1,157 @@
-<?php
-/**
- * TImage class file.
- *
- * @author Qiang Xue <qiang.xue@gmail.com>
- * @link http://www.pradosoft.com/
+<?php
+/**
+ * TImage class file.
+ *
+ * @author Qiang Xue <qiang.xue@gmail.com>
+ * @link http://www.pradosoft.com/
* @copyright Copyright &copy; 2005-2012 PradoSoft
- * @license http://www.pradosoft.com/license/
- * @version $Id$
- * @package System.Web.UI.WebControls
- */
-
-/**
- * TImage class
- *
- * TImage displays an image on a page. The image is specified via the
- * {@link setImageUrl ImageUrl} property which takes a relative or absolute
- * URL to the image file. The alignment of the image displayed is set by
- * the {@link setImageAlign ImageAlign} property. To set alternative texts
- * or long description of the image, use {@link setAlternateText AlternateText}
- * or {@link setDescriptionUrl DescriptionUrl} property, respectively.
- *
- * @author Qiang Xue <qiang.xue@gmail.com>
- * @version $Id$
- * @package System.Web.UI.WebControls
- * @since 3.0
- */
-class TImage extends TWebControl implements IDataRenderer
-{
- /**
- * @return string tag name of image control
- */
- protected function getTagName()
- {
- return 'img';
- }
-
- /**
- * Adds attributes related to an HTML image element to renderer.
- * @param THtmlWriter the writer used for the rendering purpose
- */
- protected function addAttributesToRender($writer)
- {
- $writer->addAttribute('src',$this->getImageUrl());
- $writer->addAttribute('alt',$this->getAlternateText());
- if(($desc=$this->getDescriptionUrl())!=='')
- $writer->addAttribute('longdesc',$desc);
- if(($align=$this->getImageAlign())!=='')
- $writer->addAttribute('align',$align);
- parent::addAttributesToRender($writer);
- }
-
- /**
- * Renders the body content of the image.
- * Nothing to be rendered within image tags.
- * @param THtmlWriter the writer for rendering
- */
- public function renderContents($writer)
- {
- }
-
- /**
- * @return string the alternative text displayed in the TImage component when the image is unavailable.
- */
- public function getAlternateText()
- {
- return $this->getViewState('AlternateText','');
- }
-
- /**
- * Sets the alternative text to be displayed in the TImage when the image is unavailable.
- * @param string the alternative text
- */
- public function setAlternateText($value)
- {
- $this->setViewState('AlternateText',$value,'');
- }
-
- /**
- * @return string the alignment of the image with respective to other elements on the page, defaults to empty.
- */
- public function getImageAlign()
- {
- return $this->getViewState('ImageAlign','');
- }
-
- /**
- * Sets the alignment of the image with respective to other elements on the page.
- * Possible values include: absbottom, absmiddle, baseline, bottom, left,
- * middle, right, texttop, and top. If an empty string is passed in,
- * imagealign attribute will not be rendered.
- * @param string the alignment of the image
- */
- public function setImageAlign($value)
- {
- $this->setViewState('ImageAlign',$value,'');
- }
-
- /**
- * @return string the URL of the image file
- */
- public function getImageUrl()
- {
- return $this->getViewState('ImageUrl','');
- }
-
- /**
- * @param string the URL of the image file
- */
- public function setImageUrl($value)
- {
- $this->setViewState('ImageUrl',$value,'');
- }
-
- /**
- * Returns the URL of the image file.
- * This method is required by {@link IDataRenderer}.
- * It is the same as {@link getImageUrl()}.
- * @return string the URL of the image file.
- * @see getImageUrl
- * @since 3.1.0
- */
- public function getData()
- {
- return $this->getImageUrl();
- }
-
- /**
- * Sets the URL of the image.
- * This method is required by {@link IDataRenderer}.
- * It is the same as {@link setImageUrl()}.
- * @param string the URL of the image file.
- * @see setImageUrl
- * @since 3.1.0
- */
- public function setData($value)
- {
- $this->setImageUrl($value);
- }
-
- /**
- * @return string the URL to long description
- */
- public function getDescriptionUrl()
- {
- return $this->getViewState('DescriptionUrl','');
- }
-
- /**
- * @param string the URL to the long description of the image.
- */
- public function setDescriptionUrl($value)
- {
- $this->setViewState('DescriptionUrl',$value,'');
- }
-}
-
+ * @license http://www.pradosoft.com/license/
+ * @version $Id$
+ * @package System.Web.UI.WebControls
+ */
+
+/**
+ * TImage class
+ *
+ * TImage displays an image on a page. The image is specified via the
+ * {@link setImageUrl ImageUrl} property which takes a relative or absolute
+ * URL to the image file. The alignment of the image displayed is set by
+ * the {@link setImageAlign ImageAlign} property. To set alternative texts
+ * or long description of the image, use {@link setAlternateText AlternateText}
+ * or {@link setDescriptionUrl DescriptionUrl} property, respectively.
+ *
+ * @author Qiang Xue <qiang.xue@gmail.com>
+ * @version $Id$
+ * @package System.Web.UI.WebControls
+ * @since 3.0
+ */
+class TImage extends TWebControl implements IDataRenderer
+{
+ /**
+ * @return string tag name of image control
+ */
+ protected function getTagName()
+ {
+ return 'img';
+ }
+
+ /**
+ * Adds attributes related to an HTML image element to renderer.
+ * @param THtmlWriter the writer used for the rendering purpose
+ */
+ protected function addAttributesToRender($writer)
+ {
+ $writer->addAttribute('src',$this->getImageUrl());
+ $writer->addAttribute('alt',$this->getAlternateText());
+ if(($desc=$this->getDescriptionUrl())!=='')
+ $writer->addAttribute('longdesc',$desc);
+ if(($align=$this->getImageAlign())!=='')
+ $writer->addAttribute('align',$align);
+ parent::addAttributesToRender($writer);
+ }
+
+ /**
+ * Renders the body content of the image.
+ * Nothing to be rendered within image tags.
+ * @param THtmlWriter the writer for rendering
+ */
+ public function renderContents($writer)
+ {
+ }
+
+ /**
+ * @return string the alternative text displayed in the TImage component when the image is unavailable.
+ */
+ public function getAlternateText()
+ {
+ return $this->getViewState('AlternateText','');
+ }
+
+ /**
+ * Sets the alternative text to be displayed in the TImage when the image is unavailable.
+ * @param string the alternative text
+ */
+ public function setAlternateText($value)
+ {
+ $this->setViewState('AlternateText',$value,'');
+ }
+
+ /**
+ * @return string the alignment of the image with respective to other elements on the page, defaults to empty.
+ */
+ public function getImageAlign()
+ {
+ return $this->getViewState('ImageAlign','');
+ }
+
+ /**
+ * Sets the alignment of the image with respective to other elements on the page.
+ * Possible values include: absbottom, absmiddle, baseline, bottom, left,
+ * middle, right, texttop, and top. If an empty string is passed in,
+ * imagealign attribute will not be rendered.
+ * @param string the alignment of the image
+ */
+ public function setImageAlign($value)
+ {
+ $this->setViewState('ImageAlign',$value,'');
+ }
+
+ /**
+ * @return string the URL of the image file
+ */
+ public function getImageUrl()
+ {
+ return $this->getViewState('ImageUrl','');
+ }
+
+ /**
+ * @param string the URL of the image file
+ */
+ public function setImageUrl($value)
+ {
+ $this->setViewState('ImageUrl',$value,'');
+ }
+
+ /**
+ * Returns the URL of the image file.
+ * This method is required by {@link IDataRenderer}.
+ * It is the same as {@link getImageUrl()}.
+ * @return string the URL of the image file.
+ * @see getImageUrl
+ * @since 3.1.0
+ */
+ public function getData()
+ {
+ return $this->getImageUrl();
+ }
+
+ /**
+ * Sets the URL of the image.
+ * This method is required by {@link IDataRenderer}.
+ * It is the same as {@link setImageUrl()}.
+ * @param string the URL of the image file.
+ * @see setImageUrl
+ * @since 3.1.0
+ */
+ public function setData($value)
+ {
+ $this->setImageUrl($value);
+ }
+
+ /**
+ * @return string the URL to long description
+ */
+ public function getDescriptionUrl()
+ {
+ return $this->getViewState('DescriptionUrl','');
+ }
+
+ /**
+ * @param string the URL to the long description of the image.
+ */
+ public function setDescriptionUrl($value)
+ {
+ $this->setViewState('DescriptionUrl',$value,'');
+ }
+}
+
diff --git a/framework/Web/UI/WebControls/TImageButton.php b/framework/Web/UI/WebControls/TImageButton.php
index 350c84d4..a92a9df8 100644
--- a/framework/Web/UI/WebControls/TImageButton.php
+++ b/framework/Web/UI/WebControls/TImageButton.php
@@ -1,442 +1,442 @@
-<?php
-/**
- * TImageButton class file
- *
- * @author Qiang Xue <qiang.xue@gmail.com>
- * @link http://www.pradosoft.com/
+<?php
+/**
+ * TImageButton class file
+ *
+ * @author Qiang Xue <qiang.xue@gmail.com>
+ * @link http://www.pradosoft.com/
* @copyright Copyright &copy; 2005-2012 PradoSoft
- * @license http://www.pradosoft.com/license/
- * @version $Id$
- * @package System.Web.UI.WebControls
- */
-
-/**
- * Includes TImage class file
- */
-Prado::using('System.Web.UI.WebControls.TImage');
-
-/**
- * TImageButton class
- *
- * TImageButton creates an image button on the page. It is used to submit data to a page.
- * You can create either a <b>submit</b> button or a <b>command</b> button.
- *
- * A <b>command</b> button has a command name (specified by
- * the {@link setCommandName CommandName} property) and and a command parameter
- * (specified by {@link setCommandParameter CommandParameter} property)
- * associated with the button. This allows you to create multiple TLinkButton
- * components on a Web page and programmatically determine which one is clicked
- * with what parameter. You can provide an event handler for
- * {@link onCommand OnCommand} event to programmatically control the actions performed
- * when the command button is clicked. In the event handler, you can determine
- * the {@link setCommandName CommandName} property value and
- * the {@link setCommandParameter CommandParameter} property value
- * through the {@link TCommandParameter::getName Name} and
- * {@link TCommandParameter::getParameter Parameter} properties of the event
- * parameter which is of type {@link TCommandEventParameter}.
- *
- * A <b>submit</b> button does not have a command name associated with the button
- * and clicking on it simply posts the Web page back to the server.
- * By default, a TImageButton control is a submit button.
- * You can provide an event handler for the {@link onClick OnClick} event
- * to programmatically control the actions performed when the submit button is clicked.
- * The coordinates of the clicking point can be obtained from the {@link onClick OnClick}
- * event parameter, which is of type {@link TImageClickEventParameter}.
- *
- * Clicking on button can trigger form validation, if
- * {@link setCausesValidation CausesValidation} is true.
- * And the validation may be restricted within a certain group of validator
- * controls by setting {@link setValidationGroup ValidationGroup} property.
- * If validation is successful, the data will be post back to the same page.
- *
- * TImageButton displays the {@link setText Text} property as the hint text to the displayed image.
- *
- * @author Qiang Xue <qiang.xue@gmail.com>
- * @version $Id$
- * @package System.Web.UI.WebControls
- * @since 3.0
- */
-class TImageButton extends TImage implements IPostBackDataHandler, IPostBackEventHandler, IButtonControl
-{
- /**
- * @var integer x coordinate that the image is being clicked at
- */
- private $_x=0;
- /**
- * @var integer y coordinate that the image is being clicked at
- */
- private $_y=0;
- private $_dataChanged=false;
-
- /**
- * @return string tag name of the button
- */
- protected function getTagName()
- {
- return 'input';
- }
-
- /**
- * @return boolean whether to render javascript.
- */
- public function getEnableClientScript()
- {
- return $this->getViewState('EnableClientScript',true);
- }
-
- /**
- * @param boolean whether to render javascript.
- */
- public function setEnableClientScript($value)
- {
- $this->setViewState('EnableClientScript',TPropertyValue::ensureBoolean($value),true);
- }
-
- /**
- * Adds attribute name-value pairs to renderer.
- * This overrides the parent implementation with additional button specific attributes.
- * @param THtmlWriter the writer used for the rendering purpose
- */
- protected function addAttributesToRender($writer)
- {
- $page=$this->getPage();
- $page->ensureRenderInForm($this);
- $writer->addAttribute('type','image');
- if(($uniqueID=$this->getUniqueID())!=='')
- $writer->addAttribute('name',$uniqueID);
- if($this->getEnabled(true))
- {
- if($this->getEnableClientScript() && $this->needPostBackScript())
- $this->renderClientControlScript($writer);
- }
- else if($this->getEnabled()) // in this case, parent will not render 'disabled'
- $writer->addAttribute('disabled','disabled');
- parent::addAttributesToRender($writer);
- }
-
- /**
- * Renders the client-script code.
- */
- protected function renderClientControlScript($writer)
- {
- $writer->addAttribute('id',$this->getClientID());
- $cs = $this->getPage()->getClientScript();
- $cs->registerPostBackControl($this->getClientClassName(),$this->getPostBackOptions());
- }
-
- /**
- * Gets the name of the javascript class responsible for performing postback for this control.
- * This method overrides the parent implementation.
- * @return string the javascript class name
- */
- protected function getClientClassName()
- {
- return 'Prado.WebUI.TImageButton';
- }
-
- /**
- * @return boolean whether to perform validation if the button is clicked
- */
- protected function canCauseValidation()
- {
- if($this->getCausesValidation())
- {
- $group=$this->getValidationGroup();
- return $this->getPage()->getValidators($group)->getCount()>0;
- }
- else
- return false;
- }
-
- /**
- * @param boolean set by a panel to register this button as the default button for the panel.
- */
- public function setIsDefaultButton($value)
- {
- $this->setViewState('IsDefaultButton', TPropertyValue::ensureBoolean($value),false);
- }
-
- /**
- * @return boolean true if this button is registered as a default button for a panel.
- */
- public function getIsDefaultButton()
- {
- return $this->getViewState('IsDefaultButton', false);
- }
-
- /**
- * @return boolean whether the button needs javascript to do postback
- */
- protected function needPostBackScript()
- {
- return $this->canCauseValidation() || $this->getIsDefaultButton();
- }
-
- /**
- * Returns postback specifications for the button.
- * This method is used by framework and control developers.
- * @return array parameters about how the button defines its postback behavior.
- */
- protected function getPostBackOptions()
- {
- $options['ID'] = $this->getClientID();
- $options['CausesValidation'] = $this->getCausesValidation();
- $options['ValidationGroup'] = $this->getValidationGroup();
- $options['EventTarget'] = $this->getUniqueID();
-
- return $options;
- }
-
- /**
- * This method checks if the TImageButton is clicked and loads the coordinates of the clicking position.
- * This method is primarly used by framework developers.
- * @param string the key that can be used to retrieve data from the input data collection
- * @param array the input data collection
- * @return boolean whether the data of the component has been changed
- */
- public function loadPostData($key,$values)
- {
- $uid=$this->getUniqueID();
- if(isset($values["{$uid}_x"]) && isset($values["{$uid}_y"]))
- {
- $this->_x=intval($values["{$uid}_x"]);
- $this->_y=intval($values["{$uid}_y"]);
- if($this->getPage()->getPostBackEventTarget()===null)
- $this->getPage()->setPostBackEventTarget($this);
- $this->_dataChanged=true;
- }
- return false;
- }
-
- /**
- * A dummy implementation for the IPostBackDataHandler interface.
- */
- public function raisePostDataChangedEvent()
- {
- // no post data to handle
- }
-
- /**
- * This method is invoked when the button is clicked.
- * The method raises 'OnClick' event to fire up the event handlers.
- * If you override this method, be sure to call the parent implementation
- * so that the event handler can be invoked.
- * @param TImageClickEventParameter event parameter to be passed to the event handlers
- */
- public function onClick($param)
- {
- $this->raiseEvent('OnClick',$this,$param);
- }
-
- /**
- * This method is invoked when the button is clicked.
- * The method raises 'OnCommand' event to fire up the event handlers.
- * If you override this method, be sure to call the parent implementation
- * so that the event handlers can be invoked.
- * @param TCommandEventParameter event parameter to be passed to the event handlers
- */
- public function onCommand($param)
- {
- $this->raiseEvent('OnCommand',$this,$param);
- $this->raiseBubbleEvent($this,$param);
- }
-
- /**
- * Raises the postback event.
- * This method is required by {@link IPostBackEventHandler} interface.
- * If {@link getCausesValidation CausesValidation} is true, it will
- * invoke the page's {@link TPage::validate validate} method first.
- * It will raise {@link onClick OnClick} and {@link onCommand OnCommand} events.
- * This method is mainly used by framework and control developers.
- * @param TEventParameter the event parameter
- */
- public function raisePostBackEvent($param)
- {
- if($this->getCausesValidation())
- $this->getPage()->validate($this->getValidationGroup());
- $this->onClick(new TImageClickEventParameter($this->_x,$this->_y));
- $this->onCommand(new TCommandEventParameter($this->getCommandName(),$this->getCommandParameter()));
- }
-
- /**
- * Returns a value indicating whether postback has caused the control data change.
- * This method is required by the IPostBackDataHandler interface.
- * @return boolean whether postback has caused the control data change. False if the page is not in postback mode.
- */
- public function getDataChanged()
- {
- return $this->_dataChanged;
- }
-
- /**
- * @return boolean whether postback event trigger by this button will cause input validation, default is true
- */
- public function getCausesValidation()
- {
- return $this->getViewState('CausesValidation',true);
- }
-
- /**
- * @param boolean whether postback event trigger by this button will cause input validation
- */
- public function setCausesValidation($value)
- {
- $this->setViewState('CausesValidation',TPropertyValue::ensureBoolean($value),true);
- }
-
- /**
- * @return string the command name associated with the {@link onCommand OnCommand} event.
- */
- public function getCommandName()
- {
- return $this->getViewState('CommandName','');
- }
-
- /**
- * @param string the command name associated with the {@link onCommand OnCommand} event.
- */
- public function setCommandName($value)
- {
- $this->setViewState('CommandName',$value,'');
- }
-
- /**
- * @return string the parameter associated with the {@link onCommand OnCommand} event
- */
- public function getCommandParameter()
- {
- return $this->getViewState('CommandParameter','');
- }
-
- /**
- * @param string the parameter associated with the {@link onCommand OnCommand} event.
- */
- public function setCommandParameter($value)
- {
- $this->setViewState('CommandParameter',$value,'');
- }
-
- /**
- * @return string the group of validators which the button causes validation upon postback
- */
- public function getValidationGroup()
- {
- return $this->getViewState('ValidationGroup','');
- }
-
- /**
- * @param string the group of validators which the button causes validation upon postback
- */
- public function setValidationGroup($value)
- {
- $this->setViewState('ValidationGroup',$value,'');
- }
-
- /**
- * @return string caption of the button
- */
- public function getText()
- {
- return $this->getAlternateText();
- }
-
- /**
- * @param string caption of the button
- */
- public function setText($value)
- {
- $this->setAlternateText($value);
- }
-
- /**
- * Registers the image button to receive postback data during postback.
- * This is necessary because an image button, when postback, does not have
- * direct mapping between post data and the image button name.
- * This method overrides the parent implementation and is invoked before render.
- * @param mixed event parameter
- */
- public function onPreRender($param)
- {
- parent::onPreRender($param);
- $this->getPage()->registerRequiresPostData($this);
- }
-
- /**
- * Renders the body content enclosed between the control tag.
- * This overrides the parent implementation with nothing to be rendered.
- * @param THtmlWriter the writer used for the rendering purpose
- */
- public function renderContents($writer)
- {
- }
-}
-
-/**
- * TImageClickEventParameter class
- *
- * TImageClickEventParameter encapsulates the parameter data for
- * {@link TImageButton::onClick Click} event of {@link TImageButton} controls.
- *
- * @author Qiang Xue <qiang.xue@gmail.com>
- * @version $Id$
- * @package System.Web.UI.WebControls
- * @since 3.0
- */
-class TImageClickEventParameter extends TEventParameter
-{
- /**
- * the X coordinate of the clicking point
- * @var integer
- */
- private $_x=0;
- /**
- * the Y coordinate of the clicking point
- * @var integer
- */
- private $_y=0;
-
- /**
- * Constructor.
- * @param integer X coordinate of the clicking point
- * @param integer Y coordinate of the clicking point
- */
- public function __construct($x,$y)
- {
- $this->_x=$x;
- $this->_y=$y;
- }
-
- /**
- * @return integer X coordinate of the clicking point, defaults to 0
- */
- public function getX()
- {
- return $this->_x;
- }
-
- /**
- * @param integer X coordinate of the clicking point
- */
- public function setX($value)
- {
- $this->_x=TPropertyValue::ensureInteger($value);
- }
-
- /**
- * @return integer Y coordinate of the clicking point, defaults to 0
- */
- public function getY()
- {
- return $this->_y;
- }
-
- /**
- * @param integer Y coordinate of the clicking point
- */
- public function setY($value)
- {
- $this->_y=TPropertyValue::ensureInteger($value);
- }
-}
-
-?>
+ * @license http://www.pradosoft.com/license/
+ * @version $Id$
+ * @package System.Web.UI.WebControls
+ */
+
+/**
+ * Includes TImage class file
+ */
+Prado::using('System.Web.UI.WebControls.TImage');
+
+/**
+ * TImageButton class
+ *
+ * TImageButton creates an image button on the page. It is used to submit data to a page.
+ * You can create either a <b>submit</b> button or a <b>command</b> button.
+ *
+ * A <b>command</b> button has a command name (specified by
+ * the {@link setCommandName CommandName} property) and and a command parameter
+ * (specified by {@link setCommandParameter CommandParameter} property)
+ * associated with the button. This allows you to create multiple TLinkButton
+ * components on a Web page and programmatically determine which one is clicked
+ * with what parameter. You can provide an event handler for
+ * {@link onCommand OnCommand} event to programmatically control the actions performed
+ * when the command button is clicked. In the event handler, you can determine
+ * the {@link setCommandName CommandName} property value and
+ * the {@link setCommandParameter CommandParameter} property value
+ * through the {@link TCommandParameter::getName Name} and
+ * {@link TCommandParameter::getParameter Parameter} properties of the event
+ * parameter which is of type {@link TCommandEventParameter}.
+ *
+ * A <b>submit</b> button does not have a command name associated with the button
+ * and clicking on it simply posts the Web page back to the server.
+ * By default, a TImageButton control is a submit button.
+ * You can provide an event handler for the {@link onClick OnClick} event
+ * to programmatically control the actions performed when the submit button is clicked.
+ * The coordinates of the clicking point can be obtained from the {@link onClick OnClick}
+ * event parameter, which is of type {@link TImageClickEventParameter}.
+ *
+ * Clicking on button can trigger form validation, if
+ * {@link setCausesValidation CausesValidation} is true.
+ * And the validation may be restricted within a certain group of validator
+ * controls by setting {@link setValidationGroup ValidationGroup} property.
+ * If validation is successful, the data will be post back to the same page.
+ *
+ * TImageButton displays the {@link setText Text} property as the hint text to the displayed image.
+ *
+ * @author Qiang Xue <qiang.xue@gmail.com>
+ * @version $Id$
+ * @package System.Web.UI.WebControls
+ * @since 3.0
+ */
+class TImageButton extends TImage implements IPostBackDataHandler, IPostBackEventHandler, IButtonControl
+{
+ /**
+ * @var integer x coordinate that the image is being clicked at
+ */
+ private $_x=0;
+ /**
+ * @var integer y coordinate that the image is being clicked at
+ */
+ private $_y=0;
+ private $_dataChanged=false;
+
+ /**
+ * @return string tag name of the button
+ */
+ protected function getTagName()
+ {
+ return 'input';
+ }
+
+ /**
+ * @return boolean whether to render javascript.
+ */
+ public function getEnableClientScript()
+ {
+ return $this->getViewState('EnableClientScript',true);
+ }
+
+ /**
+ * @param boolean whether to render javascript.
+ */
+ public function setEnableClientScript($value)
+ {
+ $this->setViewState('EnableClientScript',TPropertyValue::ensureBoolean($value),true);
+ }
+
+ /**
+ * Adds attribute name-value pairs to renderer.
+ * This overrides the parent implementation with additional button specific attributes.
+ * @param THtmlWriter the writer used for the rendering purpose
+ */
+ protected function addAttributesToRender($writer)
+ {
+ $page=$this->getPage();
+ $page->ensureRenderInForm($this);
+ $writer->addAttribute('type','image');
+ if(($uniqueID=$this->getUniqueID())!=='')
+ $writer->addAttribute('name',$uniqueID);
+ if($this->getEnabled(true))
+ {
+ if($this->getEnableClientScript() && $this->needPostBackScript())
+ $this->renderClientControlScript($writer);
+ }
+ else if($this->getEnabled()) // in this case, parent will not render 'disabled'
+ $writer->addAttribute('disabled','disabled');
+ parent::addAttributesToRender($writer);
+ }
+
+ /**
+ * Renders the client-script code.
+ */
+ protected function renderClientControlScript($writer)
+ {
+ $writer->addAttribute('id',$this->getClientID());
+ $cs = $this->getPage()->getClientScript();
+ $cs->registerPostBackControl($this->getClientClassName(),$this->getPostBackOptions());
+ }
+
+ /**
+ * Gets the name of the javascript class responsible for performing postback for this control.
+ * This method overrides the parent implementation.
+ * @return string the javascript class name
+ */
+ protected function getClientClassName()
+ {
+ return 'Prado.WebUI.TImageButton';
+ }
+
+ /**
+ * @return boolean whether to perform validation if the button is clicked
+ */
+ protected function canCauseValidation()
+ {
+ if($this->getCausesValidation())
+ {
+ $group=$this->getValidationGroup();
+ return $this->getPage()->getValidators($group)->getCount()>0;
+ }
+ else
+ return false;
+ }
+
+ /**
+ * @param boolean set by a panel to register this button as the default button for the panel.
+ */
+ public function setIsDefaultButton($value)
+ {
+ $this->setViewState('IsDefaultButton', TPropertyValue::ensureBoolean($value),false);
+ }
+
+ /**
+ * @return boolean true if this button is registered as a default button for a panel.
+ */
+ public function getIsDefaultButton()
+ {
+ return $this->getViewState('IsDefaultButton', false);
+ }
+
+ /**
+ * @return boolean whether the button needs javascript to do postback
+ */
+ protected function needPostBackScript()
+ {
+ return $this->canCauseValidation() || $this->getIsDefaultButton();
+ }
+
+ /**
+ * Returns postback specifications for the button.
+ * This method is used by framework and control developers.
+ * @return array parameters about how the button defines its postback behavior.
+ */
+ protected function getPostBackOptions()
+ {
+ $options['ID'] = $this->getClientID();
+ $options['CausesValidation'] = $this->getCausesValidation();
+ $options['ValidationGroup'] = $this->getValidationGroup();
+ $options['EventTarget'] = $this->getUniqueID();
+
+ return $options;
+ }
+
+ /**
+ * This method checks if the TImageButton is clicked and loads the coordinates of the clicking position.
+ * This method is primarly used by framework developers.
+ * @param string the key that can be used to retrieve data from the input data collection
+ * @param array the input data collection
+ * @return boolean whether the data of the component has been changed
+ */
+ public function loadPostData($key,$values)
+ {
+ $uid=$this->getUniqueID();
+ if(isset($values["{$uid}_x"]) && isset($values["{$uid}_y"]))
+ {
+ $this->_x=intval($values["{$uid}_x"]);
+ $this->_y=intval($values["{$uid}_y"]);
+ if($this->getPage()->getPostBackEventTarget()===null)
+ $this->getPage()->setPostBackEventTarget($this);
+ $this->_dataChanged=true;
+ }
+ return false;
+ }
+
+ /**
+ * A dummy implementation for the IPostBackDataHandler interface.
+ */
+ public function raisePostDataChangedEvent()
+ {
+ // no post data to handle
+ }
+
+ /**
+ * This method is invoked when the button is clicked.
+ * The method raises 'OnClick' event to fire up the event handlers.
+ * If you override this method, be sure to call the parent implementation
+ * so that the event handler can be invoked.
+ * @param TImageClickEventParameter event parameter to be passed to the event handlers
+ */
+ public function onClick($param)
+ {
+ $this->raiseEvent('OnClick',$this,$param);
+ }
+
+ /**
+ * This method is invoked when the button is clicked.
+ * The method raises 'OnCommand' event to fire up the event handlers.
+ * If you override this method, be sure to call the parent implementation
+ * so that the event handlers can be invoked.
+ * @param TCommandEventParameter event parameter to be passed to the event handlers
+ */
+ public function onCommand($param)
+ {
+ $this->raiseEvent('OnCommand',$this,$param);
+ $this->raiseBubbleEvent($this,$param);
+ }
+
+ /**
+ * Raises the postback event.
+ * This method is required by {@link IPostBackEventHandler} interface.
+ * If {@link getCausesValidation CausesValidation} is true, it will
+ * invoke the page's {@link TPage::validate validate} method first.
+ * It will raise {@link onClick OnClick} and {@link onCommand OnCommand} events.
+ * This method is mainly used by framework and control developers.
+ * @param TEventParameter the event parameter
+ */
+ public function raisePostBackEvent($param)
+ {
+ if($this->getCausesValidation())
+ $this->getPage()->validate($this->getValidationGroup());
+ $this->onClick(new TImageClickEventParameter($this->_x,$this->_y));
+ $this->onCommand(new TCommandEventParameter($this->getCommandName(),$this->getCommandParameter()));
+ }
+
+ /**
+ * Returns a value indicating whether postback has caused the control data change.
+ * This method is required by the IPostBackDataHandler interface.
+ * @return boolean whether postback has caused the control data change. False if the page is not in postback mode.
+ */
+ public function getDataChanged()
+ {
+ return $this->_dataChanged;
+ }
+
+ /**
+ * @return boolean whether postback event trigger by this button will cause input validation, default is true
+ */
+ public function getCausesValidation()
+ {
+ return $this->getViewState('CausesValidation',true);
+ }
+
+ /**
+ * @param boolean whether postback event trigger by this button will cause input validation
+ */
+ public function setCausesValidation($value)
+ {
+ $this->setViewState('CausesValidation',TPropertyValue::ensureBoolean($value),true);
+ }
+
+ /**
+ * @return string the command name associated with the {@link onCommand OnCommand} event.
+ */
+ public function getCommandName()
+ {
+ return $this->getViewState('CommandName','');
+ }
+
+ /**
+ * @param string the command name associated with the {@link onCommand OnCommand} event.
+ */
+ public function setCommandName($value)
+ {
+ $this->setViewState('CommandName',$value,'');
+ }
+
+ /**
+ * @return string the parameter associated with the {@link onCommand OnCommand} event
+ */
+ public function getCommandParameter()
+ {
+ return $this->getViewState('CommandParameter','');
+ }
+
+ /**
+ * @param string the parameter associated with the {@link onCommand OnCommand} event.
+ */
+ public function setCommandParameter($value)
+ {
+ $this->setViewState('CommandParameter',$value,'');
+ }
+
+ /**
+ * @return string the group of validators which the button causes validation upon postback
+ */
+ public function getValidationGroup()
+ {
+ return $this->getViewState('ValidationGroup','');
+ }
+
+ /**
+ * @param string the group of validators which the button causes validation upon postback
+ */
+ public function setValidationGroup($value)
+ {
+ $this->setViewState('ValidationGroup',$value,'');
+ }
+
+ /**
+ * @return string caption of the button
+ */
+ public function getText()
+ {
+ return $this->getAlternateText();
+ }
+
+ /**
+ * @param string caption of the button
+ */
+ public function setText($value)
+ {
+ $this->setAlternateText($value);
+ }
+
+ /**
+ * Registers the image button to receive postback data during postback.
+ * This is necessary because an image button, when postback, does not have
+ * direct mapping between post data and the image button name.
+ * This method overrides the parent implementation and is invoked before render.
+ * @param mixed event parameter
+ */
+ public function onPreRender($param)
+ {
+ parent::onPreRender($param);
+ $this->getPage()->registerRequiresPostData($this);
+ }
+
+ /**
+ * Renders the body content enclosed between the control tag.
+ * This overrides the parent implementation with nothing to be rendered.
+ * @param THtmlWriter the writer used for the rendering purpose
+ */
+ public function renderContents($writer)
+ {
+ }
+}
+
+/**
+ * TImageClickEventParameter class
+ *
+ * TImageClickEventParameter encapsulates the parameter data for
+ * {@link TImageButton::onClick Click} event of {@link TImageButton} controls.
+ *
+ * @author Qiang Xue <qiang.xue@gmail.com>
+ * @version $Id$
+ * @package System.Web.UI.WebControls
+ * @since 3.0
+ */
+class TImageClickEventParameter extends TEventParameter
+{
+ /**
+ * the X coordinate of the clicking point
+ * @var integer
+ */
+ private $_x=0;
+ /**
+ * the Y coordinate of the clicking point
+ * @var integer
+ */
+ private $_y=0;
+
+ /**
+ * Constructor.
+ * @param integer X coordinate of the clicking point
+ * @param integer Y coordinate of the clicking point
+ */
+ public function __construct($x,$y)
+ {
+ $this->_x=$x;
+ $this->_y=$y;
+ }
+
+ /**
+ * @return integer X coordinate of the clicking point, defaults to 0
+ */
+ public function getX()
+ {
+ return $this->_x;
+ }
+
+ /**
+ * @param integer X coordinate of the clicking point
+ */
+ public function setX($value)
+ {
+ $this->_x=TPropertyValue::ensureInteger($value);
+ }
+
+ /**
+ * @return integer Y coordinate of the clicking point, defaults to 0
+ */
+ public function getY()
+ {
+ return $this->_y;
+ }
+
+ /**
+ * @param integer Y coordinate of the clicking point
+ */
+ public function setY($value)
+ {
+ $this->_y=TPropertyValue::ensureInteger($value);
+ }
+}
+
+?>
diff --git a/framework/Web/UI/WebControls/TImageMap.php b/framework/Web/UI/WebControls/TImageMap.php
index 5907d03d..718a3414 100644
--- a/framework/Web/UI/WebControls/TImageMap.php
+++ b/framework/Web/UI/WebControls/TImageMap.php
@@ -1,837 +1,837 @@
-<?php
-/**
- * TImageMap and related class file.
- *
- * @author Qiang Xue <qiang.xue@gmail.com>
- * @link http://www.pradosoft.com/
+<?php
+/**
+ * TImageMap and related class file.
+ *
+ * @author Qiang Xue <qiang.xue@gmail.com>
+ * @link http://www.pradosoft.com/
* @copyright Copyright &copy; 2005-2012 PradoSoft
- * @license http://www.pradosoft.com/license/
- * @version $Id$
- * @package System.Web.UI.WebControls
- */
-
-/**
- * Includes TImage class file
- */
-Prado::using('System.Web.UI.WebControls.TImage');
-
-/**
- * TImageMap class
- *
- * TImageMap represents an image on a page. Hotspot regions can be defined
- * within the image. Depending on the {@link setHotSpotMode HotSpotMode},
- * clicking on the hotspots may trigger a postback or navigate to a specified
- * URL. The hotspots defined may be accessed via {@link getHotSpots HotSpots}.
- * Each hotspot is described as a {@link THotSpot}, which can be a circle,
- * rectangle, polygon, etc. To add hotspot in a template, use the following,
- * <code>
- * <com:TImageMap>
- * <com:TCircleHotSpot ... />
- * <com:TRectangleHotSpot ... />
- * <com:TPolygonHotSpot ... />
- * </com:TImageMap>
- * </code>
- *
- * @author Qiang Xue <qiang.xue@gmail.com>
- * @version $Id$
- * @package System.Web.UI.WebControls
- * @since 3.0
- */
-class TImageMap extends TImage implements IPostBackEventHandler
-{
- const MAP_NAME_PREFIX='ImageMap';
-
- /**
- * Processes an object that is created during parsing template.
- * This method adds {@link THotSpot} objects into the hotspot collection
- * of the imagemap.
- * @param string|TComponent text string or component parsed and instantiated in template
- */
- public function addParsedObject($object)
- {
- if($object instanceof THotSpot)
- $this->getHotSpots()->add($object);
- }
-
- /**
- * Adds attribute name-value pairs to renderer.
- * This overrides the parent implementation with additional imagemap specific attributes.
- * @param THtmlWriter the writer used for the rendering purpose
- */
- protected function addAttributesToRender($writer)
- {
- parent::addAttributesToRender($writer);
- if($this->getHotSpots()->getCount()>0)
- {
- $writer->addAttribute('usemap','#'.self::MAP_NAME_PREFIX.$this->getClientID());
- $writer->addAttribute('id',$this->getUniqueID());
- }
- if($this->getEnabled() && !$this->getEnabled(true))
- $writer->addAttribute('disabled','disabled');
- }
-
- /**
- * Renders this imagemap.
- * @param THtmlWriter
- */
- public function render($writer)
- {
- parent::render($writer);
-
- $hotspots=$this->getHotSpots();
-
- if($hotspots->getCount()>0)
- {
- $clientID=$this->getClientID();
- $cs=$this->getPage()->getClientScript();
- $writer->writeLine();
- $writer->addAttribute('name',self::MAP_NAME_PREFIX.$clientID);
- $writer->renderBeginTag('map');
- $writer->writeLine();
- if(($mode=$this->getHotSpotMode())===THotSpotMode::NotSet)
- $mode=THotSpotMode::Navigate;
- $target=$this->getTarget();
- $i=0;
- $options['EventTarget'] = $this->getUniqueID();
- $options['StopEvent'] = true;
- $cs=$this->getPage()->getClientScript();
- foreach($hotspots as $hotspot)
- {
- if($hotspot->getHotSpotMode()===THotSpotMode::NotSet)
- $hotspot->setHotSpotMode($mode);
- if($target!=='' && $hotspot->getTarget()==='')
- $hotspot->setTarget($target);
- if($hotspot->getHotSpotMode()===THotSpotMode::PostBack)
- {
- $id=$clientID.'_'.$i;
- $writer->addAttribute('id',$id);
- $writer->addAttribute('href','#'.$id); //create unique no-op url references
- $options['ID']=$id;
- $options['EventParameter']="$i";
- $options['CausesValidation']=$hotspot->getCausesValidation();
- $options['ValidationGroup']=$hotspot->getValidationGroup();
- $cs->registerPostBackControl($this->getClientClassName(),$options);
- }
- $hotspot->render($writer);
- $writer->writeLine();
- $i++;
- }
- $writer->renderEndTag();
- }
- }
-
- /**
- * Gets the name of the javascript class responsible for performing postback for this control.
- * This method overrides the parent implementation.
- * @return string the javascript class name
- */
- protected function getClientClassName()
- {
- return 'Prado.WebUI.TImageMap';
- }
-
- /**
- * Raises the postback event.
- * This method is required by {@link IPostBackEventHandler} interface.
- * This method is mainly used by framework and control developers.
- * @param TEventParameter the event parameter
- */
- public function raisePostBackEvent($param)
- {
- $postBackValue=null;
- if($param!=='')
- {
- $index=TPropertyValue::ensureInteger($param);
- $hotspots=$this->getHotSpots();
- if($index>=0 && $index<$hotspots->getCount())
- {
- $hotspot=$hotspots->itemAt($index);
- if(($mode=$hotspot->getHotSpotMode())===THotSpotMode::NotSet)
- $mode=$this->getHotSpotMode();
- if($mode===THotSpotMode::PostBack)
- {
- $postBackValue=$hotspot->getPostBackValue();
- if($hotspot->getCausesValidation())
- $this->getPage()->validate($hotspot->getValidationGroup());
- }
- }
- }
- if($postBackValue!==null)
- $this->onClick(new TImageMapEventParameter($postBackValue));
- }
-
- /**
- * @return THotSpotMode the behavior of hotspot regions in this imagemap when they are clicked. Defaults to THotSpotMode::NotSet.
- */
- public function getHotSpotMode()
- {
- return $this->getViewState('HotSpotMode',THotSpotMode::NotSet);
- }
-
- /**
- * Sets the behavior of hotspot regions in this imagemap when they are clicked.
- * If an individual hotspot has a mode other than 'NotSet', the mode set in this
- * imagemap will be ignored. By default, 'NotSet' is equivalent to 'Navigate'.
- * @param THotSpotMode the behavior of hotspot regions in this imagemap when they are clicked.
- */
- public function setHotSpotMode($value)
- {
- $this->setViewState('HotSpotMode',TPropertyValue::ensureEnum($value,'THotSpotMode'),THotSpotMode::NotSet);
- }
-
- /**
- * @return THotSpotCollection collection of hotspots defined in this imagemap.
- */
- public function getHotSpots()
- {
- if(($hotspots=$this->getViewState('HotSpots',null))===null)
- {
- $hotspots=new THotSpotCollection;
- $this->setViewState('HotSpots',$hotspots);
- }
- return $hotspots;
- }
-
- /**
- * @return string the target window or frame to display the new page when a hotspot region is clicked within the imagemap. Defaults to ''.
- */
- public function getTarget()
- {
- return $this->getViewState('Target','');
- }
-
- /**
- * @param string the target window or frame to display the new page when a hotspot region is clicked within the imagemap.
- */
- public function setTarget($value)
- {
- $this->setViewState('Target',TPropertyValue::ensureString($value),'');
- }
-
- /**
- * Raises <b>OnClick</b> event.
- * This method is invoked when a hotspot region is clicked within the imagemap.
- * If you override this method, be sure to call the parent implementation
- * so that the event handler can be invoked.
- * @param TImageMapEventParameter event parameter to be passed to the event handlers
- */
- public function onClick($param)
- {
- $this->raiseEvent('OnClick',$this,$param);
- }
-}
-
-/**
- * TImageMapEventParameter class.
- *
- * TImageMapEventParameter represents a postback event parameter
- * when a hotspot is clicked and posts back in a {@link TImageMap}.
- * To retrieve the post back value associated with the hotspot being clicked,
- * access {@link getPostBackValue PostBackValue}.
- *
- * @author Qiang Xue <qiang.xue@gmail.com>
- * @version $Id$
- * @package System.Web.UI.WebControls
- * @since 3.0
- */
-class TImageMapEventParameter extends TEventParameter
-{
- private $_postBackValue;
-
- /**
- * Constructor.
- * @param string post back value associated with the hotspot clicked
- */
- public function __construct($postBackValue)
- {
- $this->_postBackValue=$postBackValue;
- }
-
- /**
- * @return string post back value associated with the hotspot clicked
- */
- public function getPostBackValue()
- {
- return $this->_postBackValue;
- }
-}
-
-/**
- * THotSpotCollection class.
- *
- * THotSpotCollection represents a collection of hotspots in an imagemap.
- *
- * @author Qiang Xue <qiang.xue@gmail.com>
- * @version $Id$
- * @package System.Web.UI.WebControls
- * @since 3.0
- */
-class THotSpotCollection extends TList
-{
- /**
- * Inserts an item at the specified position.
- * This overrides the parent implementation by inserting only {@link THotSpot}.
- * @param integer the speicified position.
- * @param mixed new item
- * @throws TInvalidDataTypeException if the item to be inserted is not a THotSpot.
- */
- public function insertAt($index,$item)
- {
- if($item instanceof THotSpot)
- parent::insertAt($index,$item);
- else
- throw new TInvalidDataTypeException('hotspotcollection_hotspot_required');
- }
-}
-
-
-/**
- * THotSpot class.
- *
- * THotSpot implements the basic functionality common to all hot spot shapes.
- * Derived classes include {@link TCircleHotSpot}, {@link TPolygonHotSpot}
- * and {@link TRectangleHotSpot}.
- *
- * @author Qiang Xue <qiang.xue@gmail.com>
- * @version $Id$
- * @package System.Web.UI.WebControls
- * @since 3.0
- */
-abstract class THotSpot extends TComponent
-{
- private $_viewState=array();
-
- /**
- * Returns a viewstate value.
- *
- * This function is very useful in defining getter functions for component properties
- * that must be kept in viewstate.
- * @param string the name of the viewstate value to be returned
- * @param mixed the default value. If $key is not found in viewstate, $defaultValue will be returned
- * @return mixed the viewstate value corresponding to $key
- */
- protected function getViewState($key,$defaultValue=null)
- {
- return isset($this->_viewState[$key])?$this->_viewState[$key]:$defaultValue;
- }
-
- /**
- * Sets a viewstate value.
- *
- * This function is very useful in defining setter functions for control properties
- * that must be kept in viewstate.
- * Make sure that the viewstate value must be serializable and unserializable.
- * @param string the name of the viewstate value
- * @param mixed the viewstate value to be set
- * @param mixed default value. If $value===$defaultValue, the item will be cleared from the viewstate.
- */
- protected function setViewState($key,$value,$defaultValue=null)
- {
- if($value===$defaultValue)
- unset($this->_viewState[$key]);
- else
- $this->_viewState[$key]=$value;
- }
-
- /**
- * @return string shape of the hotspot, can be 'circle', 'rect', 'poly', etc.
- */
- abstract public function getShape();
- /**
- * @return string coordinates defining the hotspot shape.
- */
- abstract public function getCoordinates();
-
- /**
- * @return string the access key that allows you to quickly navigate to the HotSpot region. Defaults to ''.
- */
- public function getAccessKey()
- {
- return $this->getViewState('AccessKey','');
- }
-
- /**
- * @param string the access key that allows you to quickly navigate to the HotSpot region.
- */
- public function setAccessKey($value)
- {
- $this->setViewState('AccessKey',TPropertyValue::ensureString($value),'');
- }
-
- /**
- * @return string the alternate text to display for a HotSpot object. Defaults to ''.
- */
- public function getAlternateText()
- {
- return $this->getViewState('AlternateText','');
- }
-
- /**
- * @param string the alternate text to display for a HotSpot object.
- */
- public function setAlternateText($value)
- {
- $this->setViewState('AlternateText',TPropertyValue::ensureString($value),'');
- }
-
- /**
- * @return THotSpotMode the behavior of a HotSpot object when it is clicked. Defaults to THotSpotMode::NotSet.
- */
- public function getHotSpotMode()
- {
- return $this->getViewState('HotSpotMode',THotSpotMode::NotSet);
- }
-
- /**
- * @param THotSpotMode the behavior of a HotSpot object when it is clicked.
- */
- public function setHotSpotMode($value)
- {
- $this->setViewState('HotSpotMode',TPropertyValue::ensureEnum($value,'THotSpotMode'),THotSpotMode::NotSet);
- }
-
- /**
- * @return string the URL to navigate to when a HotSpot object is clicked. Defaults to ''.
- */
- public function getNavigateUrl()
- {
- return $this->getViewState('NavigateUrl','');
- }
-
- /**
- * @param string the URL to navigate to when a HotSpot object is clicked.
- */
- public function setNavigateUrl($value)
- {
- $this->setViewState('NavigateUrl',TPropertyValue::ensureString($value),'');
- }
-
- /**
- * @return string a value that is post back when the HotSpot is clicked. Defaults to ''.
- */
- public function getPostBackValue()
- {
- return $this->getViewState('PostBackValue','');
- }
-
- /**
- * @param string a value that is post back when the HotSpot is clicked.
- */
- public function setPostBackValue($value)
- {
- $this->setViewState('PostBackValue',TPropertyValue::ensureString($value),'');
- }
-
- /**
- * @return integer the tab index of the HotSpot region. Defaults to 0.
- */
- public function getTabIndex()
- {
- return $this->getViewState('TabIndex',0);
- }
-
- /**
- * @param integer the tab index of the HotSpot region.
- */
- public function setTabIndex($value)
- {
- $this->setViewState('TabIndex',TPropertyValue::ensureInteger($value),0);
- }
-
- /**
- * @return boolean whether postback event trigger by this hotspot will cause input validation, default is true
- */
- public function getCausesValidation()
- {
- return $this->getViewState('CausesValidation',true);
- }
-
- /**
- * @param boolean whether postback event trigger by this hotspot will cause input validation
- */
- public function setCausesValidation($value)
- {
- $this->setViewState('CausesValidation',TPropertyValue::ensureBoolean($value),true);
- }
-
- /**
- * @return string the group of validators which the hotspot causes validation upon postback
- */
- public function getValidationGroup()
- {
- return $this->getViewState('ValidationGroup','');
- }
-
- /**
- * @param string the group of validators which the hotspot causes validation upon postback
- */
- public function setValidationGroup($value)
- {
- $this->setViewState('ValidationGroup',$value,'');
- }
-
- /**
- * @return string the target window or frame to display the new page when the HotSpot region
- * is clicked. Defaults to ''.
- */
- public function getTarget()
- {
- return $this->getViewState('Target','');
- }
-
- /**
- * @param string the target window or frame to display the new page when the HotSpot region
- * is clicked.
- */
- public function setTarget($value)
- {
- $this->setViewState('Target',TPropertyValue::ensureString($value),'');
- }
-
- /**
- * @return boolean whether the hotspot has custom attributes
- */
- public function getHasAttributes()
- {
- if($attributes=$this->getViewState('Attributes',null))
- return $attributes->getCount()>0;
- else
- return false;
- }
-
- /**
- * Returns the list of custom attributes.
- * Custom attributes are name-value pairs that may be rendered
- * as HTML tags' attributes.
- * @return TAttributeCollection the list of custom attributes
- */
- public function getAttributes()
- {
- if($attributes=$this->getViewState('Attributes',null))
- return $attributes;
- else
- {
- $attributes=new TAttributeCollection;
- $this->setViewState('Attributes',$attributes,null);
- return $attributes;
- }
- }
-
- /**
- * @return boolean whether the named attribute exists
- */
- public function hasAttribute($name)
- {
- if($attributes=$this->getViewState('Attributes',null))
- return $attributes->contains($name);
- else
- return false;
- }
-
- /**
- * @return string attribute value, null if attribute does not exist
- */
- public function getAttribute($name)
- {
- if($attributes=$this->getViewState('Attributes',null))
- return $attributes->itemAt($name);
- else
- return null;
- }
-
- /**
- * Sets a custom hotspot attribute.
- * @param string attribute name
- * @param string value of the attribute
- */
- public function setAttribute($name,$value)
- {
- $this->getAttributes()->add($name,$value);
- }
-
- /**
- * Removes the named attribute.
- * @param string the name of the attribute to be removed.
- * @return string attribute value removed, null if attribute does not exist.
- */
- public function removeAttribute($name)
- {
- if($attributes=$this->getViewState('Attributes',null))
- return $attributes->remove($name);
- else
- return null;
- }
-
- /**
- * Renders this hotspot.
- * @param THtmlWriter
- */
- public function render($writer)
- {
- $writer->addAttribute('shape',$this->getShape());
- $writer->addAttribute('coords',$this->getCoordinates());
- if(($mode=$this->getHotSpotMode())===THotSpotMode::NotSet)
- $mode=THotSpotMode::Navigate;
- if($mode===THotSpotMode::Navigate)
- {
- $writer->addAttribute('href',$this->getNavigateUrl());
- if(($target=$this->getTarget())!=='')
- $writer->addAttribute('target',$target);
- }
- else if($mode===THotSpotMode::Inactive)
- $writer->addAttribute('nohref','true');
- $text=$this->getAlternateText();
- $writer->addAttribute('title',$text);
- $writer->addAttribute('alt',$text);
- if(($accessKey=$this->getAccessKey())!=='')
- $writer->addAttribute('accesskey',$accessKey);
- if(($tabIndex=$this->getTabIndex())!==0)
- $writer->addAttribute('tabindex',"$tabIndex");
- if($this->getHasAttributes())
- {
- foreach($this->getAttributes() as $name=>$value)
- $writer->addAttribute($name,$value);
- }
- $writer->renderBeginTag('area');
- $writer->renderEndTag();
- }
-}
-
-/**
- * Class TCircleHotSpot.
- *
- * TCircleHotSpot defines a circular hot spot region in a {@link TImageMap}
- * control.
- *
- * @author Qiang Xue <qiang.xue@gmail.com>
- * @version $Id$
- * @package System.Web.UI.WebControls
- * @since 3.0
- */
-class TCircleHotSpot extends THotSpot
-{
- /**
- * @return string shape of this hotspot.
- */
- public function getShape()
- {
- return 'circle';
- }
-
- /**
- * @return string coordinates defining this hotspot shape
- */
- public function getCoordinates()
- {
- return $this->getX().','.$this->getY().','.$this->getRadius();
- }
-
- /**
- * @return integer radius of the circular HotSpot region. Defaults to 0.
- */
- public function getRadius()
- {
- return $this->getViewState('Radius',0);
- }
-
- /**
- * @param integer radius of the circular HotSpot region.
- */
- public function setRadius($value)
- {
- $this->setViewState('Radius',TPropertyValue::ensureInteger($value),0);
- }
-
- /**
- * @return integer the X coordinate of the center of the circular HotSpot region. Defaults to 0.
- */
- public function getX()
- {
- return $this->getViewState('X',0);
- }
-
- /**
- * @param integer the X coordinate of the center of the circular HotSpot region.
- */
- public function setX($value)
- {
- $this->setViewState('X',TPropertyValue::ensureInteger($value),0);
- }
-
- /**
- * @return integer the Y coordinate of the center of the circular HotSpot region. Defaults to 0.
- */
- public function getY()
- {
- return $this->getViewState('Y',0);
- }
-
- /**
- * @param integer the Y coordinate of the center of the circular HotSpot region.
- */
- public function setY($value)
- {
- $this->setViewState('Y',TPropertyValue::ensureInteger($value),0);
- }
-}
-
-/**
- * Class TRectangleHotSpot.
- *
- * TRectangleHotSpot defines a rectangle hot spot region in a {@link
- * TImageMap} control.
- *
- * @author Qiang Xue <qiang.xue@gmail.com>
- * @version $Id$
- * @package System.Web.UI.WebControls
- * @since 3.0
- */
-class TRectangleHotSpot extends THotSpot
-{
- /**
- * @return string shape of this hotspot.
- */
- public function getShape()
- {
- return 'rect';
- }
-
- /**
- * @return string coordinates defining this hotspot shape
- */
- public function getCoordinates()
- {
- return $this->getLeft().','.$this->getTop().','.$this->getRight().','.$this->getBottom();
- }
-
- /**
- * @return integer the Y coordinate of the bottom side of the rectangle HotSpot region. Defaults to 0.
- */
- public function getBottom()
- {
- return $this->getViewState('Bottom',0);
- }
-
- /**
- * @param integer the Y coordinate of the bottom side of the rectangle HotSpot region.
- */
- public function setBottom($value)
- {
- $this->setViewState('Bottom',TPropertyValue::ensureInteger($value),0);
- }
-
- /**
- * @return integer the X coordinate of the right side of the rectangle HotSpot region. Defaults to 0.
- */
- public function getLeft()
- {
- return $this->getViewState('Left',0);
- }
-
- /**
- * @param integer the X coordinate of the right side of the rectangle HotSpot region.
- */
- public function setLeft($value)
- {
- $this->setViewState('Left',TPropertyValue::ensureInteger($value),0);
- }
-
- /**
- * @return integer the X coordinate of the right side of the rectangle HotSpot region. Defaults to 0.
- */
- public function getRight()
- {
- return $this->getViewState('Right',0);
- }
-
- /**
- * @param integer the X coordinate of the right side of the rectangle HotSpot region.
- */
- public function setRight($value)
- {
- $this->setViewState('Right',TPropertyValue::ensureInteger($value),0);
- }
-
- /**
- * @return integer the Y coordinate of the top side of the rectangle HotSpot region. Defaults to 0.
- */
- public function getTop()
- {
- return $this->getViewState('Top',0);
- }
-
- /**
- * @param integer the Y coordinate of the top side of the rectangle HotSpot region.
- */
- public function setTop($value)
- {
- $this->setViewState('Top',TPropertyValue::ensureInteger($value),0);
- }
-}
-
-/**
- * Class TPolygonHotSpot.
- *
- * TPolygonHotSpot defines a polygon hot spot region in a {@link
- * TImageMap} control.
- *
- * @author Qiang Xue <qiang.xue@gmail.com>
- * @version $Id$
- * @package System.Web.UI.WebControls
- * @since 3.0
- */
-class TPolygonHotSpot extends THotSpot
-{
- /**
- * @return string shape of this hotspot.
- */
- public function getShape()
- {
- return 'poly';
- }
-
- /**
- * @return string coordinates of the vertices defining the polygon.
- * Coordinates are concatenated together with comma ','. Each pair
- * represents (x,y) of a vertex.
- */
- public function getCoordinates()
- {
- return $this->getViewState('Coordinates','');
- }
-
- /**
- * @param string coordinates of the vertices defining the polygon.
- * Coordinates are concatenated together with comma ','. Each pair
- * represents (x,y) of a vertex.
- */
- public function setCoordinates($value)
- {
- $this->setViewState('Coordinates',$value,'');
- }
-}
-
-
-/**
- * THotSpotMode class.
- * THotSpotMode defines the enumerable type for the possible hot spot modes.
- *
- * The following enumerable values are defined:
- * - NotSet: the mode is not specified
- * - Navigate: clicking on the hotspot will redirect the browser to a different page
- * - PostBack: clicking on the hotspot will cause a postback
- * - Inactive: the hotspot is inactive (not clickable)
- *
- * @author Qiang Xue <qiang.xue@gmail.com>
- * @version $Id$
- * @package System.Web.UI.WebControls
- * @since 3.0.4
- */
-class THotSpotMode extends TEnumerable
-{
- const NotSet='NotSet';
- const Navigate='Navigate';
- const PostBack='PostBack';
- const Inactive='Inactive';
-}
-
+ * @license http://www.pradosoft.com/license/
+ * @version $Id$
+ * @package System.Web.UI.WebControls
+ */
+
+/**
+ * Includes TImage class file
+ */
+Prado::using('System.Web.UI.WebControls.TImage');
+
+/**
+ * TImageMap class
+ *
+ * TImageMap represents an image on a page. Hotspot regions can be defined
+ * within the image. Depending on the {@link setHotSpotMode HotSpotMode},
+ * clicking on the hotspots may trigger a postback or navigate to a specified
+ * URL. The hotspots defined may be accessed via {@link getHotSpots HotSpots}.
+ * Each hotspot is described as a {@link THotSpot}, which can be a circle,
+ * rectangle, polygon, etc. To add hotspot in a template, use the following,
+ * <code>
+ * <com:TImageMap>
+ * <com:TCircleHotSpot ... />
+ * <com:TRectangleHotSpot ... />
+ * <com:TPolygonHotSpot ... />
+ * </com:TImageMap>
+ * </code>
+ *
+ * @author Qiang Xue <qiang.xue@gmail.com>
+ * @version $Id$
+ * @package System.Web.UI.WebControls
+ * @since 3.0
+ */
+class TImageMap extends TImage implements IPostBackEventHandler
+{
+ const MAP_NAME_PREFIX='ImageMap';
+
+ /**
+ * Processes an object that is created during parsing template.
+ * This method adds {@link THotSpot} objects into the hotspot collection
+ * of the imagemap.
+ * @param string|TComponent text string or component parsed and instantiated in template
+ */
+ public function addParsedObject($object)
+ {
+ if($object instanceof THotSpot)
+ $this->getHotSpots()->add($object);
+ }
+
+ /**
+ * Adds attribute name-value pairs to renderer.
+ * This overrides the parent implementation with additional imagemap specific attributes.
+ * @param THtmlWriter the writer used for the rendering purpose
+ */
+ protected function addAttributesToRender($writer)
+ {
+ parent::addAttributesToRender($writer);
+ if($this->getHotSpots()->getCount()>0)
+ {
+ $writer->addAttribute('usemap','#'.self::MAP_NAME_PREFIX.$this->getClientID());
+ $writer->addAttribute('id',$this->getUniqueID());
+ }
+ if($this->getEnabled() && !$this->getEnabled(true))
+ $writer->addAttribute('disabled','disabled');
+ }
+
+ /**
+ * Renders this imagemap.
+ * @param THtmlWriter
+ */
+ public function render($writer)
+ {
+ parent::render($writer);
+
+ $hotspots=$this->getHotSpots();
+
+ if($hotspots->getCount()>0)
+ {
+ $clientID=$this->getClientID();
+ $cs=$this->getPage()->getClientScript();
+ $writer->writeLine();
+ $writer->addAttribute('name',self::MAP_NAME_PREFIX.$clientID);
+ $writer->renderBeginTag('map');
+ $writer->writeLine();
+ if(($mode=$this->getHotSpotMode())===THotSpotMode::NotSet)
+ $mode=THotSpotMode::Navigate;
+ $target=$this->getTarget();
+ $i=0;
+ $options['EventTarget'] = $this->getUniqueID();
+ $options['StopEvent'] = true;
+ $cs=$this->getPage()->getClientScript();
+ foreach($hotspots as $hotspot)
+ {
+ if($hotspot->getHotSpotMode()===THotSpotMode::NotSet)
+ $hotspot->setHotSpotMode($mode);
+ if($target!=='' && $hotspot->getTarget()==='')
+ $hotspot->setTarget($target);
+ if($hotspot->getHotSpotMode()===THotSpotMode::PostBack)
+ {
+ $id=$clientID.'_'.$i;
+ $writer->addAttribute('id',$id);
+ $writer->addAttribute('href','#'.$id); //create unique no-op url references
+ $options['ID']=$id;
+ $options['EventParameter']="$i";
+ $options['CausesValidation']=$hotspot->getCausesValidation();
+ $options['ValidationGroup']=$hotspot->getValidationGroup();
+ $cs->registerPostBackControl($this->getClientClassName(),$options);
+ }
+ $hotspot->render($writer);
+ $writer->writeLine();
+ $i++;
+ }
+ $writer->renderEndTag();
+ }
+ }
+
+ /**
+ * Gets the name of the javascript class responsible for performing postback for this control.
+ * This method overrides the parent implementation.
+ * @return string the javascript class name
+ */
+ protected function getClientClassName()
+ {
+ return 'Prado.WebUI.TImageMap';
+ }
+
+ /**
+ * Raises the postback event.
+ * This method is required by {@link IPostBackEventHandler} interface.
+ * This method is mainly used by framework and control developers.
+ * @param TEventParameter the event parameter
+ */
+ public function raisePostBackEvent($param)
+ {
+ $postBackValue=null;
+ if($param!=='')
+ {
+ $index=TPropertyValue::ensureInteger($param);
+ $hotspots=$this->getHotSpots();
+ if($index>=0 && $index<$hotspots->getCount())
+ {
+ $hotspot=$hotspots->itemAt($index);
+ if(($mode=$hotspot->getHotSpotMode())===THotSpotMode::NotSet)
+ $mode=$this->getHotSpotMode();
+ if($mode===THotSpotMode::PostBack)
+ {
+ $postBackValue=$hotspot->getPostBackValue();
+ if($hotspot->getCausesValidation())
+ $this->getPage()->validate($hotspot->getValidationGroup());
+ }
+ }
+ }
+ if($postBackValue!==null)
+ $this->onClick(new TImageMapEventParameter($postBackValue));
+ }
+
+ /**
+ * @return THotSpotMode the behavior of hotspot regions in this imagemap when they are clicked. Defaults to THotSpotMode::NotSet.
+ */
+ public function getHotSpotMode()
+ {
+ return $this->getViewState('HotSpotMode',THotSpotMode::NotSet);
+ }
+
+ /**
+ * Sets the behavior of hotspot regions in this imagemap when they are clicked.
+ * If an individual hotspot has a mode other than 'NotSet', the mode set in this
+ * imagemap will be ignored. By default, 'NotSet' is equivalent to 'Navigate'.
+ * @param THotSpotMode the behavior of hotspot regions in this imagemap when they are clicked.
+ */
+ public function setHotSpotMode($value)
+ {
+ $this->setViewState('HotSpotMode',TPropertyValue::ensureEnum($value,'THotSpotMode'),THotSpotMode::NotSet);
+ }
+
+ /**
+ * @return THotSpotCollection collection of hotspots defined in this imagemap.
+ */
+ public function getHotSpots()
+ {
+ if(($hotspots=$this->getViewState('HotSpots',null))===null)
+ {
+ $hotspots=new THotSpotCollection;
+ $this->setViewState('HotSpots',$hotspots);
+ }
+ return $hotspots;
+ }
+
+ /**
+ * @return string the target window or frame to display the new page when a hotspot region is clicked within the imagemap. Defaults to ''.
+ */
+ public function getTarget()
+ {
+ return $this->getViewState('Target','');
+ }
+
+ /**
+ * @param string the target window or frame to display the new page when a hotspot region is clicked within the imagemap.
+ */
+ public function setTarget($value)
+ {
+ $this->setViewState('Target',TPropertyValue::ensureString($value),'');
+ }
+
+ /**
+ * Raises <b>OnClick</b> event.
+ * This method is invoked when a hotspot region is clicked within the imagemap.
+ * If you override this method, be sure to call the parent implementation
+ * so that the event handler can be invoked.
+ * @param TImageMapEventParameter event parameter to be passed to the event handlers
+ */
+ public function onClick($param)
+ {
+ $this->raiseEvent('OnClick',$this,$param);
+ }
+}
+
+/**
+ * TImageMapEventParameter class.
+ *
+ * TImageMapEventParameter represents a postback event parameter
+ * when a hotspot is clicked and posts back in a {@link TImageMap}.
+ * To retrieve the post back value associated with the hotspot being clicked,
+ * access {@link getPostBackValue PostBackValue}.
+ *
+ * @author Qiang Xue <qiang.xue@gmail.com>
+ * @version $Id$
+ * @package System.Web.UI.WebControls
+ * @since 3.0
+ */
+class TImageMapEventParameter extends TEventParameter
+{
+ private $_postBackValue;
+
+ /**
+ * Constructor.
+ * @param string post back value associated with the hotspot clicked
+ */
+ public function __construct($postBackValue)
+ {
+ $this->_postBackValue=$postBackValue;
+ }
+
+ /**
+ * @return string post back value associated with the hotspot clicked
+ */
+ public function getPostBackValue()
+ {
+ return $this->_postBackValue;
+ }
+}
+
+/**
+ * THotSpotCollection class.
+ *
+ * THotSpotCollection represents a collection of hotspots in an imagemap.
+ *
+ * @author Qiang Xue <qiang.xue@gmail.com>
+ * @version $Id$
+ * @package System.Web.UI.WebControls
+ * @since 3.0
+ */
+class THotSpotCollection extends TList
+{
+ /**
+ * Inserts an item at the specified position.
+ * This overrides the parent implementation by inserting only {@link THotSpot}.
+ * @param integer the speicified position.
+ * @param mixed new item
+ * @throws TInvalidDataTypeException if the item to be inserted is not a THotSpot.
+ */
+ public function insertAt($index,$item)
+ {
+ if($item instanceof THotSpot)
+ parent::insertAt($index,$item);
+ else
+ throw new TInvalidDataTypeException('hotspotcollection_hotspot_required');
+ }
+}
+
+
+/**
+ * THotSpot class.
+ *
+ * THotSpot implements the basic functionality common to all hot spot shapes.
+ * Derived classes include {@link TCircleHotSpot}, {@link TPolygonHotSpot}
+ * and {@link TRectangleHotSpot}.
+ *
+ * @author Qiang Xue <qiang.xue@gmail.com>
+ * @version $Id$
+ * @package System.Web.UI.WebControls
+ * @since 3.0
+ */
+abstract class THotSpot extends TComponent
+{
+ private $_viewState=array();
+
+ /**
+ * Returns a viewstate value.
+ *
+ * This function is very useful in defining getter functions for component properties
+ * that must be kept in viewstate.
+ * @param string the name of the viewstate value to be returned
+ * @param mixed the default value. If $key is not found in viewstate, $defaultValue will be returned
+ * @return mixed the viewstate value corresponding to $key
+ */
+ protected function getViewState($key,$defaultValue=null)
+ {
+ return isset($this->_viewState[$key])?$this->_viewState[$key]:$defaultValue;
+ }
+
+ /**
+ * Sets a viewstate value.
+ *
+ * This function is very useful in defining setter functions for control properties
+ * that must be kept in viewstate.
+ * Make sure that the viewstate value must be serializable and unserializable.
+ * @param string the name of the viewstate value
+ * @param mixed the viewstate value to be set
+ * @param mixed default value. If $value===$defaultValue, the item will be cleared from the viewstate.
+ */
+ protected function setViewState($key,$value,$defaultValue=null)
+ {
+ if($value===$defaultValue)
+ unset($this->_viewState[$key]);
+ else
+ $this->_viewState[$key]=$value;
+ }
+
+ /**
+ * @return string shape of the hotspot, can be 'circle', 'rect', 'poly', etc.
+ */
+ abstract public function getShape();
+ /**
+ * @return string coordinates defining the hotspot shape.
+ */
+ abstract public function getCoordinates();
+
+ /**
+ * @return string the access key that allows you to quickly navigate to the HotSpot region. Defaults to ''.
+ */
+ public function getAccessKey()
+ {
+ return $this->getViewState('AccessKey','');
+ }
+
+ /**
+ * @param string the access key that allows you to quickly navigate to the HotSpot region.
+ */
+ public function setAccessKey($value)
+ {
+ $this->setViewState('AccessKey',TPropertyValue::ensureString($value),'');
+ }
+
+ /**
+ * @return string the alternate text to display for a HotSpot object. Defaults to ''.
+ */
+ public function getAlternateText()
+ {
+ return $this->getViewState('AlternateText','');
+ }
+
+ /**
+ * @param string the alternate text to display for a HotSpot object.
+ */
+ public function setAlternateText($value)
+ {
+ $this->setViewState('AlternateText',TPropertyValue::ensureString($value),'');
+ }
+
+ /**
+ * @return THotSpotMode the behavior of a HotSpot object when it is clicked. Defaults to THotSpotMode::NotSet.
+ */
+ public function getHotSpotMode()
+ {
+ return $this->getViewState('HotSpotMode',THotSpotMode::NotSet);
+ }
+
+ /**
+ * @param THotSpotMode the behavior of a HotSpot object when it is clicked.
+ */
+ public function setHotSpotMode($value)
+ {
+ $this->setViewState('HotSpotMode',TPropertyValue::ensureEnum($value,'THotSpotMode'),THotSpotMode::NotSet);
+ }
+
+ /**
+ * @return string the URL to navigate to when a HotSpot object is clicked. Defaults to ''.
+ */
+ public function getNavigateUrl()
+ {
+ return $this->getViewState('NavigateUrl','');
+ }
+
+ /**
+ * @param string the URL to navigate to when a HotSpot object is clicked.
+ */
+ public function setNavigateUrl($value)
+ {
+ $this->setViewState('NavigateUrl',TPropertyValue::ensureString($value),'');
+ }
+
+ /**
+ * @return string a value that is post back when the HotSpot is clicked. Defaults to ''.
+ */
+ public function getPostBackValue()
+ {
+ return $this->getViewState('PostBackValue','');
+ }
+
+ /**
+ * @param string a value that is post back when the HotSpot is clicked.
+ */
+ public function setPostBackValue($value)
+ {
+ $this->setViewState('PostBackValue',TPropertyValue::ensureString($value),'');
+ }
+
+ /**
+ * @return integer the tab index of the HotSpot region. Defaults to 0.
+ */
+ public function getTabIndex()
+ {
+ return $this->getViewState('TabIndex',0);
+ }
+
+ /**
+ * @param integer the tab index of the HotSpot region.
+ */
+ public function setTabIndex($value)
+ {
+ $this->setViewState('TabIndex',TPropertyValue::ensureInteger($value),0);
+ }
+
+ /**
+ * @return boolean whether postback event trigger by this hotspot will cause input validation, default is true
+ */
+ public function getCausesValidation()
+ {
+ return $this->getViewState('CausesValidation',true);
+ }
+
+ /**
+ * @param boolean whether postback event trigger by this hotspot will cause input validation
+ */
+ public function setCausesValidation($value)
+ {
+ $this->setViewState('CausesValidation',TPropertyValue::ensureBoolean($value),true);
+ }
+
+ /**
+ * @return string the group of validators which the hotspot causes validation upon postback
+ */
+ public function getValidationGroup()
+ {
+ return $this->getViewState('ValidationGroup','');
+ }
+
+ /**
+ * @param string the group of validators which the hotspot causes validation upon postback
+ */
+ public function setValidationGroup($value)
+ {
+ $this->setViewState('ValidationGroup',$value,'');
+ }
+
+ /**
+ * @return string the target window or frame to display the new page when the HotSpot region
+ * is clicked. Defaults to ''.
+ */
+ public function getTarget()
+ {
+ return $this->getViewState('Target','');
+ }
+
+ /**
+ * @param string the target window or frame to display the new page when the HotSpot region
+ * is clicked.
+ */
+ public function setTarget($value)
+ {
+ $this->setViewState('Target',TPropertyValue::ensureString($value),'');
+ }
+
+ /**
+ * @return boolean whether the hotspot has custom attributes
+ */
+ public function getHasAttributes()
+ {
+ if($attributes=$this->getViewState('Attributes',null))
+ return $attributes->getCount()>0;
+ else
+ return false;
+ }
+
+ /**
+ * Returns the list of custom attributes.
+ * Custom attributes are name-value pairs that may be rendered
+ * as HTML tags' attributes.
+ * @return TAttributeCollection the list of custom attributes
+ */
+ public function getAttributes()
+ {
+ if($attributes=$this->getViewState('Attributes',null))
+ return $attributes;
+ else
+ {
+ $attributes=new TAttributeCollection;
+ $this->setViewState('Attributes',$attributes,null);
+ return $attributes;
+ }
+ }
+
+ /**
+ * @return boolean whether the named attribute exists
+ */
+ public function hasAttribute($name)
+ {
+ if($attributes=$this->getViewState('Attributes',null))
+ return $attributes->contains($name);
+ else
+ return false;
+ }
+
+ /**
+ * @return string attribute value, null if attribute does not exist
+ */
+ public function getAttribute($name)
+ {
+ if($attributes=$this->getViewState('Attributes',null))
+ return $attributes->itemAt($name);
+ else
+ return null;
+ }
+
+ /**
+ * Sets a custom hotspot attribute.
+ * @param string attribute name
+ * @param string value of the attribute
+ */
+ public function setAttribute($name,$value)
+ {
+ $this->getAttributes()->add($name,$value);
+ }
+
+ /**
+ * Removes the named attribute.
+ * @param string the name of the attribute to be removed.
+ * @return string attribute value removed, null if attribute does not exist.
+ */
+ public function removeAttribute($name)
+ {
+ if($attributes=$this->getViewState('Attributes',null))
+ return $attributes->remove($name);
+ else
+ return null;
+ }
+
+ /**
+ * Renders this hotspot.
+ * @param THtmlWriter
+ */
+ public function render($writer)
+ {
+ $writer->addAttribute('shape',$this->getShape());
+ $writer->addAttribute('coords',$this->getCoordinates());
+ if(($mode=$this->getHotSpotMode())===THotSpotMode::NotSet)
+ $mode=THotSpotMode::Navigate;
+ if($mode===THotSpotMode::Navigate)
+ {
+ $writer->addAttribute('href',$this->getNavigateUrl());
+ if(($target=$this->getTarget())!=='')
+ $writer->addAttribute('target',$target);
+ }
+ else if($mode===THotSpotMode::Inactive)
+ $writer->addAttribute('nohref','true');
+ $text=$this->getAlternateText();
+ $writer->addAttribute('title',$text);
+ $writer->addAttribute('alt',$text);
+ if(($accessKey=$this->getAccessKey())!=='')
+ $writer->addAttribute('accesskey',$accessKey);
+ if(($tabIndex=$this->getTabIndex())!==0)
+ $writer->addAttribute('tabindex',"$tabIndex");
+ if($this->getHasAttributes())
+ {
+ foreach($this->getAttributes() as $name=>$value)
+ $writer->addAttribute($name,$value);
+ }
+ $writer->renderBeginTag('area');
+ $writer->renderEndTag();
+ }
+}
+
+/**
+ * Class TCircleHotSpot.
+ *
+ * TCircleHotSpot defines a circular hot spot region in a {@link TImageMap}
+ * control.
+ *
+ * @author Qiang Xue <qiang.xue@gmail.com>
+ * @version $Id$
+ * @package System.Web.UI.WebControls
+ * @since 3.0
+ */
+class TCircleHotSpot extends THotSpot
+{
+ /**
+ * @return string shape of this hotspot.
+ */
+ public function getShape()
+ {
+ return 'circle';
+ }
+
+ /**
+ * @return string coordinates defining this hotspot shape
+ */
+ public function getCoordinates()
+ {
+ return $this->getX().','.$this->getY().','.$this->getRadius();
+ }
+
+ /**
+ * @return integer radius of the circular HotSpot region. Defaults to 0.
+ */
+ public function getRadius()
+ {
+ return $this->getViewState('Radius',0);
+ }
+
+ /**
+ * @param integer radius of the circular HotSpot region.
+ */
+ public function setRadius($value)
+ {
+ $this->setViewState('Radius',TPropertyValue::ensureInteger($value),0);
+ }
+
+ /**
+ * @return integer the X coordinate of the center of the circular HotSpot region. Defaults to 0.
+ */
+ public function getX()
+ {
+ return $this->getViewState('X',0);
+ }
+
+ /**
+ * @param integer the X coordinate of the center of the circular HotSpot region.
+ */
+ public function setX($value)
+ {
+ $this->setViewState('X',TPropertyValue::ensureInteger($value),0);
+ }
+
+ /**
+ * @return integer the Y coordinate of the center of the circular HotSpot region. Defaults to 0.
+ */
+ public function getY()
+ {
+ return $this->getViewState('Y',0);
+ }
+
+ /**
+ * @param integer the Y coordinate of the center of the circular HotSpot region.
+ */
+ public function setY($value)
+ {
+ $this->setViewState('Y',TPropertyValue::ensureInteger($value),0);
+ }
+}
+
+/**
+ * Class TRectangleHotSpot.
+ *
+ * TRectangleHotSpot defines a rectangle hot spot region in a {@link
+ * TImageMap} control.
+ *
+ * @author Qiang Xue <qiang.xue@gmail.com>
+ * @version $Id$
+ * @package System.Web.UI.WebControls
+ * @since 3.0
+ */
+class TRectangleHotSpot extends THotSpot
+{
+ /**
+ * @return string shape of this hotspot.
+ */
+ public function getShape()
+ {
+ return 'rect';
+ }
+
+ /**
+ * @return string coordinates defining this hotspot shape
+ */
+ public function getCoordinates()
+ {
+ return $this->getLeft().','.$this->getTop().','.$this->getRight().','.$this->getBottom();
+ }
+
+ /**
+ * @return integer the Y coordinate of the bottom side of the rectangle HotSpot region. Defaults to 0.
+ */
+ public function getBottom()
+ {
+ return $this->getViewState('Bottom',0);
+ }
+
+ /**
+ * @param integer the Y coordinate of the bottom side of the rectangle HotSpot region.
+ */
+ public function setBottom($value)
+ {
+ $this->setViewState('Bottom',TPropertyValue::ensureInteger($value),0);
+ }
+
+ /**
+ * @return integer the X coordinate of the right side of the rectangle HotSpot region. Defaults to 0.
+ */
+ public function getLeft()
+ {
+ return $this->getViewState('Left',0);
+ }
+
+ /**
+ * @param integer the X coordinate of the right side of the rectangle HotSpot region.
+ */
+ public function setLeft($value)
+ {
+ $this->setViewState('Left',TPropertyValue::ensureInteger($value),0);
+ }
+
+ /**
+ * @return integer the X coordinate of the right side of the rectangle HotSpot region. Defaults to 0.
+ */
+ public function getRight()
+ {
+ return $this->getViewState('Right',0);
+ }
+
+ /**
+ * @param integer the X coordinate of the right side of the rectangle HotSpot region.
+ */
+ public function setRight($value)
+ {
+ $this->setViewState('Right',TPropertyValue::ensureInteger($value),0);
+ }
+
+ /**
+ * @return integer the Y coordinate of the top side of the rectangle HotSpot region. Defaults to 0.
+ */
+ public function getTop()
+ {
+ return $this->getViewState('Top',0);
+ }
+
+ /**
+ * @param integer the Y coordinate of the top side of the rectangle HotSpot region.
+ */
+ public function setTop($value)
+ {
+ $this->setViewState('Top',TPropertyValue::ensureInteger($value),0);
+ }
+}
+
+/**
+ * Class TPolygonHotSpot.
+ *
+ * TPolygonHotSpot defines a polygon hot spot region in a {@link
+ * TImageMap} control.
+ *
+ * @author Qiang Xue <qiang.xue@gmail.com>
+ * @version $Id$
+ * @package System.Web.UI.WebControls
+ * @since 3.0
+ */
+class TPolygonHotSpot extends THotSpot
+{
+ /**
+ * @return string shape of this hotspot.
+ */
+ public function getShape()
+ {
+ return 'poly';
+ }
+
+ /**
+ * @return string coordinates of the vertices defining the polygon.
+ * Coordinates are concatenated together with comma ','. Each pair
+ * represents (x,y) of a vertex.
+ */
+ public function getCoordinates()
+ {
+ return $this->getViewState('Coordinates','');
+ }
+
+ /**
+ * @param string coordinates of the vertices defining the polygon.
+ * Coordinates are concatenated together with comma ','. Each pair
+ * represents (x,y) of a vertex.
+ */
+ public function setCoordinates($value)
+ {
+ $this->setViewState('Coordinates',$value,'');
+ }
+}
+
+
+/**
+ * THotSpotMode class.
+ * THotSpotMode defines the enumerable type for the possible hot spot modes.
+ *
+ * The following enumerable values are defined:
+ * - NotSet: the mode is not specified
+ * - Navigate: clicking on the hotspot will redirect the browser to a different page
+ * - PostBack: clicking on the hotspot will cause a postback
+ * - Inactive: the hotspot is inactive (not clickable)
+ *
+ * @author Qiang Xue <qiang.xue@gmail.com>
+ * @version $Id$
+ * @package System.Web.UI.WebControls
+ * @since 3.0.4
+ */
+class THotSpotMode extends TEnumerable
+{
+ const NotSet='NotSet';
+ const Navigate='Navigate';
+ const PostBack='PostBack';
+ const Inactive='Inactive';
+}
+
diff --git a/framework/Web/UI/WebControls/TItemDataRenderer.php b/framework/Web/UI/WebControls/TItemDataRenderer.php
index 60b34873..80d7f418 100644
--- a/framework/Web/UI/WebControls/TItemDataRenderer.php
+++ b/framework/Web/UI/WebControls/TItemDataRenderer.php
@@ -1,83 +1,83 @@
-<?php
-/**
- * TItemDataRenderer class file
- *
- * @author Qiang Xue <qiang.xue@gmail.com>
- * @link http://www.pradosoft.com/
+<?php
+/**
+ * TItemDataRenderer class file
+ *
+ * @author Qiang Xue <qiang.xue@gmail.com>
+ * @link http://www.pradosoft.com/
* @copyright Copyright &copy; 2005-2012 PradoSoft
- * @license http://www.pradosoft.com/license/
- * @version $Id$
- * @package System.Web.UI.WebControls
- * @since 3.1.2
- */
-
-Prado::using('System.Web.UI.WebControls.TDataBoundControl');
-Prado::using('System.Web.UI.WebControls.TDataRenderer');
-
-/**
- * TItemDataRenderer class
- *
- * TItemDataRenderer is the convient base class for template-based item data renderers.
- * It implements the {@link IItemDataRenderer} interface, and because
- * TItemDataRenderer extends from {@link TTemplateControl}, derived child
- * classes can have templates to define their presentational layout.
- *
- * The following properties are provided by TItemDataRenderer:
- * - {@link getItemIndex ItemIndex}: zero-based index of this renderer in the item list collection.
- * - {@link getItemType ItemType}: item type of this renderer, such as TListItemType::AlternatingItem
- * - {@link getData Data}: data associated with this renderer
-
- * @author Qiang Xue <qiang.xue@gmail.com>
- * @version $Id$
- * @package System.Web.UI.WebControls
- * @since 3.1.2
- */
-abstract class TItemDataRenderer extends TDataRenderer implements IItemDataRenderer
-{
- /**
- * index of the data item in the Items collection of repeater
- */
- private $_itemIndex;
- /**
- * type of the TRepeaterItem
- * @var TListItemType
- */
- private $_itemType;
-
- /**
- * @return TListItemType item type
- */
- public function getItemType()
- {
- return $this->_itemType;
- }
-
- /**
- * @param TListItemType item type.
- */
- public function setItemType($value)
- {
- $this->_itemType=TPropertyValue::ensureEnum($value,'TListItemType');
- }
-
- /**
- * Returns a value indicating the zero-based index of the item in the corresponding data control's item collection.
- * If the item is not in the collection (e.g. it is a header item), it returns -1.
- * @return integer zero-based index of the item.
- */
- public function getItemIndex()
- {
- return $this->_itemIndex;
- }
-
- /**
- * Sets the zero-based index for the item.
- * If the item is not in the item collection (e.g. it is a header item), -1 should be used.
- * @param integer zero-based index of the item.
- */
- public function setItemIndex($value)
- {
- $this->_itemIndex=TPropertyValue::ensureInteger($value);
- }
-}
-
+ * @license http://www.pradosoft.com/license/
+ * @version $Id$
+ * @package System.Web.UI.WebControls
+ * @since 3.1.2
+ */
+
+Prado::using('System.Web.UI.WebControls.TDataBoundControl');
+Prado::using('System.Web.UI.WebControls.TDataRenderer');
+
+/**
+ * TItemDataRenderer class
+ *
+ * TItemDataRenderer is the convient base class for template-based item data renderers.
+ * It implements the {@link IItemDataRenderer} interface, and because
+ * TItemDataRenderer extends from {@link TTemplateControl}, derived child
+ * classes can have templates to define their presentational layout.
+ *
+ * The following properties are provided by TItemDataRenderer:
+ * - {@link getItemIndex ItemIndex}: zero-based index of this renderer in the item list collection.
+ * - {@link getItemType ItemType}: item type of this renderer, such as TListItemType::AlternatingItem
+ * - {@link getData Data}: data associated with this renderer
+
+ * @author Qiang Xue <qiang.xue@gmail.com>
+ * @version $Id$
+ * @package System.Web.UI.WebControls
+ * @since 3.1.2
+ */
+abstract class TItemDataRenderer extends TDataRenderer implements IItemDataRenderer
+{
+ /**
+ * index of the data item in the Items collection of repeater
+ */
+ private $_itemIndex;
+ /**
+ * type of the TRepeaterItem
+ * @var TListItemType
+ */
+ private $_itemType;
+
+ /**
+ * @return TListItemType item type
+ */
+ public function getItemType()
+ {
+ return $this->_itemType;
+ }
+
+ /**
+ * @param TListItemType item type.
+ */
+ public function setItemType($value)
+ {
+ $this->_itemType=TPropertyValue::ensureEnum($value,'TListItemType');
+ }
+
+ /**
+ * Returns a value indicating the zero-based index of the item in the corresponding data control's item collection.
+ * If the item is not in the collection (e.g. it is a header item), it returns -1.
+ * @return integer zero-based index of the item.
+ */
+ public function getItemIndex()
+ {
+ return $this->_itemIndex;
+ }
+
+ /**
+ * Sets the zero-based index for the item.
+ * If the item is not in the item collection (e.g. it is a header item), -1 should be used.
+ * @param integer zero-based index of the item.
+ */
+ public function setItemIndex($value)
+ {
+ $this->_itemIndex=TPropertyValue::ensureInteger($value);
+ }
+}
+
diff --git a/framework/Web/UI/WebControls/TJavascriptLogger.php b/framework/Web/UI/WebControls/TJavascriptLogger.php
index e0d695f4..3b430357 100644
--- a/framework/Web/UI/WebControls/TJavascriptLogger.php
+++ b/framework/Web/UI/WebControls/TJavascriptLogger.php
@@ -1,93 +1,93 @@
-<?php
-/**
- * TJavascriptLogger class file.
- *
- * @author Wei Zhuo <weizhuo[at]gmail[dot]com>
- * @link http://www.pradosoft.com/
- * @copyright Copyright &copy; 2005-2012 PradoSoft
- * @license http://www.pradosoft.com/license/
- * @version $Id$
- * @package System.Web.UI.WebControls
- */
-
-/**
- * TJavascriptLogger class.
- *
- * Provides logging for client-side javascript. Example: template code
- * <code><com:TJavascriptLogger /></code>
- *
- * Client-side javascript code to log info, error, warn, debug
- * <code>Logger.warn('A warning');
- * Logger.info('something happend');
- * </code>
- *
- * To see the logger and console, press ALT-D (or CTRL-D on OS X).
- * More information on the logger can be found at
- * http://web.archive.org/web/20060512041505/gleepglop.com/javascripts/logger/
- *
- * @author Wei Zhuo<weizhuo[at]gmail[dot]com>
- * @version $Id$
- * @package System.Web.UI.WebControls
- * @since 3.0
- */
-class TJavascriptLogger extends TWebControl
-{
- private static $_keyCodes = array(
- '0'=>48, '1'=>49, '2'=>50, '3'=>51, '4'=>52, '5'=>53, '6'=>54, '7'=>55, '8'=>56, '9'=>57,
- 'a'=>65, 'b'=>66, 'c'=>67, 'd'=>68, 'e'=>69, 'f'=>70, 'g'=>71, 'h'=>72,
- 'i'=>73, 'j'=>74, 'k'=>75, 'l'=>76, 'm'=>77, 'n'=>78, 'o'=>79, 'p'=>80,
- 'q'=>81, 'r'=>82, 's'=>83, 't'=>84, 'u'=>85, 'v'=>86, 'w'=>87, 'x'=>88, 'y'=>89, 'z'=>90);
-
- /**
- * @return string tag name of the panel
- */
- protected function getTagName()
- {
- return 'div';
- }
-
- /**
- * @param string keyboard key for toggling the console, default is J.
- */
- public function setToggleKey($value)
- {
- $this->setViewState('ToggleKey', $value, 'j');
- }
-
- /**
- * @return string keyboard key for toggling the console.
- */
- public function getToggleKey()
- {
- return $this->getViewState('ToggleKey', 'j');
- }
-
- /**
- * Registers the required logger javascript.
- * @param TEventParameter event parameter
- */
- public function onPreRender($param)
- {
- $key = strtolower($this->getToggleKey());
- $code = isset(self::$_keyCodes[$key]) ? self::$_keyCodes[$key] : 74;
- $js = "var logConsole; Event.OnLoad(function() { logConsole = new LogConsole($code)}); ";
- $cs = $this->getPage()->getClientScript();
- $cs->registerBeginScript($this->getClientID(),$js);
- $cs->registerPradoScript('logger');
- }
-
- /**
- * Register the required javascript libraries and
- * display some general usage information.
- * @param THtmlWriter the writer used for the rendering purpose
- */
- public function renderContents($writer)
- {
- $code = strtoupper($this->getToggleKey());
- $info = '(<a href="http://web.archive.org/web/20060512041505/gleepglop.com/javascripts/logger/" target="_blank">more info</a>).';
- $link = '<a href="javascript:if(logConsole)logConsole.toggle()">toggle the javascript log console.</a>';
- $usage = 'Press ALT-'.$code.' (Or CTRL-'.$code.' on OS X) to';
- $writer->write("{$usage} {$link} {$info}");
- }
-}
-
+<?php
+/**
+ * TJavascriptLogger class file.
+ *
+ * @author Wei Zhuo <weizhuo[at]gmail[dot]com>
+ * @link http://www.pradosoft.com/
+ * @copyright Copyright &copy; 2005-2012 PradoSoft
+ * @license http://www.pradosoft.com/license/
+ * @version $Id$
+ * @package System.Web.UI.WebControls
+ */
+
+/**
+ * TJavascriptLogger class.
+ *
+ * Provides logging for client-side javascript. Example: template code
+ * <code><com:TJavascriptLogger /></code>
+ *
+ * Client-side javascript code to log info, error, warn, debug
+ * <code>Logger.warn('A warning');
+ * Logger.info('something happend');
+ * </code>
+ *
+ * To see the logger and console, press ALT-D (or CTRL-D on OS X).
+ * More information on the logger can be found at
+ * http://web.archive.org/web/20060512041505/gleepglop.com/javascripts/logger/
+ *
+ * @author Wei Zhuo<weizhuo[at]gmail[dot]com>
+ * @version $Id$
+ * @package System.Web.UI.WebControls
+ * @since 3.0
+ */
+class TJavascriptLogger extends TWebControl
+{
+ private static $_keyCodes = array(
+ '0'=>48, '1'=>49, '2'=>50, '3'=>51, '4'=>52, '5'=>53, '6'=>54, '7'=>55, '8'=>56, '9'=>57,
+ 'a'=>65, 'b'=>66, 'c'=>67, 'd'=>68, 'e'=>69, 'f'=>70, 'g'=>71, 'h'=>72,
+ 'i'=>73, 'j'=>74, 'k'=>75, 'l'=>76, 'm'=>77, 'n'=>78, 'o'=>79, 'p'=>80,
+ 'q'=>81, 'r'=>82, 's'=>83, 't'=>84, 'u'=>85, 'v'=>86, 'w'=>87, 'x'=>88, 'y'=>89, 'z'=>90);
+
+ /**
+ * @return string tag name of the panel
+ */
+ protected function getTagName()
+ {
+ return 'div';
+ }
+
+ /**
+ * @param string keyboard key for toggling the console, default is J.
+ */
+ public function setToggleKey($value)
+ {
+ $this->setViewState('ToggleKey', $value, 'j');
+ }
+
+ /**
+ * @return string keyboard key for toggling the console.
+ */
+ public function getToggleKey()
+ {
+ return $this->getViewState('ToggleKey', 'j');
+ }
+
+ /**
+ * Registers the required logger javascript.
+ * @param TEventParameter event parameter
+ */
+ public function onPreRender($param)
+ {
+ $key = strtolower($this->getToggleKey());
+ $code = isset(self::$_keyCodes[$key]) ? self::$_keyCodes[$key] : 74;
+ $js = "var logConsole; Event.OnLoad(function() { logConsole = new LogConsole($code)}); ";
+ $cs = $this->getPage()->getClientScript();
+ $cs->registerBeginScript($this->getClientID(),$js);
+ $cs->registerPradoScript('logger');
+ }
+
+ /**
+ * Register the required javascript libraries and
+ * display some general usage information.
+ * @param THtmlWriter the writer used for the rendering purpose
+ */
+ public function renderContents($writer)
+ {
+ $code = strtoupper($this->getToggleKey());
+ $info = '(<a href="http://web.archive.org/web/20060512041505/gleepglop.com/javascripts/logger/" target="_blank">more info</a>).';
+ $link = '<a href="javascript:if(logConsole)logConsole.toggle()">toggle the javascript log console.</a>';
+ $usage = 'Press ALT-'.$code.' (Or CTRL-'.$code.' on OS X) to';
+ $writer->write("{$usage} {$link} {$info}");
+ }
+}
+
diff --git a/framework/Web/UI/WebControls/TKeyboard.php b/framework/Web/UI/WebControls/TKeyboard.php
index 27cb55c5..58c80e26 100644
--- a/framework/Web/UI/WebControls/TKeyboard.php
+++ b/framework/Web/UI/WebControls/TKeyboard.php
@@ -1,189 +1,189 @@
-<?php
-/**
- * TKeyboard class file.
- *
- * @author Sergey Morkovkin <sergeymorkovkin@mail.ru> and Qiang Xue <qiang.xue@gmail.com>
- * @link http://www.pradosoft.com/
- * @copyright Copyright &copy; 2005-2012 PradoSoft
- * @license http://www.pradosoft.com/license/
- * @version $Id$
- * @package System.Web.UI.WebControls
- * @since 3.1.1
- */
-
-/**
- * Class TKeyboard.
- *
- * TKeyboard displays a virtual keyboard that users can click on to enter input in
- * an associated text box. It helps to reduce the keyboard recording hacking.
- *
- * To use TKeyboard, write a template like following:
- * <code>
- * <com:TTextBox ID="PasswordInput" />
- * <com:TKeyboard ForControl="PasswordInput" />
- * </code>
- *
- * A TKeyboard control is associated with a {@link TTextBox} control by specifying {@link setForControl ForControl}
- * to be the ID of that control. When the textbox is in focus, a virtual keyboard will pop up; and when
- * the text box is losing focus, the keyboard will hide automatically. Set {@link setAutoHide AutoHide} to
- * false to keep the keyboard showing all the time.
- *
- * The appearance of the keyboard can also be changed by specifying a customized CSS file via
- * {@link setCssUrl CssUrl}. By default, the CSS class name for the keyboard is 'Keyboard'. This may
- * also be changed by specifying {@link setKeyboardCssClass KeyboardCssClass}.
- *
- * @author Sergey Morkovkin <sergeymorkovkin@mail.ru> and Qiang Xue <qiang.xue@gmail.com>
- * @version $Id$
- * @package System.Web.UI.WebControls
- * @since 3.1.1
- */
-class TKeyboard extends TWebControl
-{
- /**
- * @return string the ID path of the {@link TTextBox} control
- */
- public function getForControl()
- {
- return $this->getViewState('ForControl','');
- }
-
- /**
- * Sets the ID path of the {@link TTextBox} control.
- * The ID path is the dot-connected IDs of the controls reaching from
- * the keyboard's naming container to the target control.
- * @param string the ID path
- */
- public function setForControl($value)
- {
- $this->setViewState('ForControl', TPropertyValue::ensureString($value));
- }
-
- /**
- * @return boolean whether the keyboard should be hidden when the textbox is not in focus. Defaults to true.
- */
- public function getAutoHide()
- {
- return $this->getViewState('AutoHide', true);
- }
-
- /**
- * @param boolean whether the keyboard should be hidden when the textbox is not in focus.
- */
- public function setAutoHide($value)
- {
- $this->setViewState('AutoHide', TPropertyValue::ensureBoolean($value), true);
- }
-
- /**
- * @return string the CSS class name for the keyboard <div> element. Defaults to 'Keyboard'.
- */
- public function getKeyboardCssClass()
- {
- return $this->getViewState('KeyboardCssClass', 'Keyboard');
- }
-
- /**
- * Sets a value indicating the CSS class name for the keyboard <div> element.
- * Note, if you change this property, make sure you also supply a customized CSS file
- * by specifying {@link setCssUrl CssUrl} which uses the new CSS class name for styling.
- * @param string the CSS class name for the keyboard <div> element.
- */
- public function setKeyboardCssClass($value)
- {
- $this->setViewState('KeyboardCssClass', $value, 'Keyboard');
- }
-
- /**
- * @return string the URL for the CSS file to customize the appearance of the keyboard.
- */
- public function getCssUrl()
- {
- return $this->getViewState('CssUrl', '');
- }
-
- /**
- * @param string the URL for the CSS file to customize the appearance of the keyboard.
- */
- public function setCssUrl($value)
- {
- $this->setViewState('CssUrl', $value, '');
- }
-
- /**
- * Registers CSS and JS.
- * This method is invoked right before the control rendering, if the control is visible.
- * @param mixed event parameter
- */
- public function onPreRender($param)
- {
- parent::onPreRender($param);
- if($this->getPage()->getClientSupportsJavaScript())
- {
- $this->registerStyleSheet();
- $this->registerClientScript();
- }
- }
-
- /**
- * Adds attribute name-value pairs to renderer.
- * This method overrides the parent implementation with additional TKeyboard specific attributes.
- * @param THtmlWriter the writer used for the rendering purpose
- */
- protected function addAttributesToRender($writer)
- {
- parent::addAttributesToRender($writer);
- if($this->getPage()->getClientSupportsJavaScript())
- $writer->addAttribute('id',$this->getClientID());
- }
-
- /**
- * Registers the CSS relevant to the TKeyboard.
- * It will register the CSS file specified by {@link getCssUrl CssUrl}.
- * If that is not set, it will use the default CSS.
- */
- protected function registerStyleSheet()
- {
- if(($url=$this->getCssUrl())==='')
- $url=$this->getApplication()->getAssetManager()->publishFilePath(dirname(__FILE__).DIRECTORY_SEPARATOR.'assets'.DIRECTORY_SEPARATOR.'keyboard.css');
- $this->getPage()->getClientScript()->registerStyleSheetFile($url,$url);
- }
-
- /**
- * Registers the relevant JavaScript.
- */
- protected function registerClientScript()
- {
- $options=TJavaScript::encode($this->getClientOptions());
- $className=$this->getClientClassName();
- $cs=$this->getPage()->getClientScript();
- $cs->registerPradoScript('keyboard');
- $cs->registerEndScript('prado:'.$this->getClientID(), "new $className($options);");
- }
-
- /**
- * @return string the Javascript class name for this control
- */
- protected function getClientClassName()
- {
- return 'Prado.WebUI.TKeyboard';
- }
-
- /**
- * @return array the JavaScript options for this control
- */
- protected function getClientOptions()
- {
- if(($forControl=$this->getForControl())==='')
- throw new TConfigurationException('keyboard_forcontrol_required');
- if(($target=$this->findControl($forControl))===null)
- throw new TConfigurationException('keyboard_forcontrol_invalid',$forControl);
-
- $options['ID'] = $this->getClientID();
- $options['ForControl'] = $target->getClientID();
- $options['AutoHide'] = $this->getAutoHide();
- $options['CssClass'] = $this->getKeyboardCssClass();
-
- return $options;
- }
-}
-
+<?php
+/**
+ * TKeyboard class file.
+ *
+ * @author Sergey Morkovkin <sergeymorkovkin@mail.ru> and Qiang Xue <qiang.xue@gmail.com>
+ * @link http://www.pradosoft.com/
+ * @copyright Copyright &copy; 2005-2012 PradoSoft
+ * @license http://www.pradosoft.com/license/
+ * @version $Id$
+ * @package System.Web.UI.WebControls
+ * @since 3.1.1
+ */
+
+/**
+ * Class TKeyboard.
+ *
+ * TKeyboard displays a virtual keyboard that users can click on to enter input in
+ * an associated text box. It helps to reduce the keyboard recording hacking.
+ *
+ * To use TKeyboard, write a template like following:
+ * <code>
+ * <com:TTextBox ID="PasswordInput" />
+ * <com:TKeyboard ForControl="PasswordInput" />
+ * </code>
+ *
+ * A TKeyboard control is associated with a {@link TTextBox} control by specifying {@link setForControl ForControl}
+ * to be the ID of that control. When the textbox is in focus, a virtual keyboard will pop up; and when
+ * the text box is losing focus, the keyboard will hide automatically. Set {@link setAutoHide AutoHide} to
+ * false to keep the keyboard showing all the time.
+ *
+ * The appearance of the keyboard can also be changed by specifying a customized CSS file via
+ * {@link setCssUrl CssUrl}. By default, the CSS class name for the keyboard is 'Keyboard'. This may
+ * also be changed by specifying {@link setKeyboardCssClass KeyboardCssClass}.
+ *
+ * @author Sergey Morkovkin <sergeymorkovkin@mail.ru> and Qiang Xue <qiang.xue@gmail.com>
+ * @version $Id$
+ * @package System.Web.UI.WebControls
+ * @since 3.1.1
+ */
+class TKeyboard extends TWebControl
+{
+ /**
+ * @return string the ID path of the {@link TTextBox} control
+ */
+ public function getForControl()
+ {
+ return $this->getViewState('ForControl','');
+ }
+
+ /**
+ * Sets the ID path of the {@link TTextBox} control.
+ * The ID path is the dot-connected IDs of the controls reaching from
+ * the keyboard's naming container to the target control.
+ * @param string the ID path
+ */
+ public function setForControl($value)
+ {
+ $this->setViewState('ForControl', TPropertyValue::ensureString($value));
+ }
+
+ /**
+ * @return boolean whether the keyboard should be hidden when the textbox is not in focus. Defaults to true.
+ */
+ public function getAutoHide()
+ {
+ return $this->getViewState('AutoHide', true);
+ }
+
+ /**
+ * @param boolean whether the keyboard should be hidden when the textbox is not in focus.
+ */
+ public function setAutoHide($value)
+ {
+ $this->setViewState('AutoHide', TPropertyValue::ensureBoolean($value), true);
+ }
+
+ /**
+ * @return string the CSS class name for the keyboard <div> element. Defaults to 'Keyboard'.
+ */
+ public function getKeyboardCssClass()
+ {
+ return $this->getViewState('KeyboardCssClass', 'Keyboard');
+ }
+
+ /**
+ * Sets a value indicating the CSS class name for the keyboard <div> element.
+ * Note, if you change this property, make sure you also supply a customized CSS file
+ * by specifying {@link setCssUrl CssUrl} which uses the new CSS class name for styling.
+ * @param string the CSS class name for the keyboard <div> element.
+ */
+ public function setKeyboardCssClass($value)
+ {
+ $this->setViewState('KeyboardCssClass', $value, 'Keyboard');
+ }
+
+ /**
+ * @return string the URL for the CSS file to customize the appearance of the keyboard.
+ */
+ public function getCssUrl()
+ {
+ return $this->getViewState('CssUrl', '');
+ }
+
+ /**
+ * @param string the URL for the CSS file to customize the appearance of the keyboard.
+ */
+ public function setCssUrl($value)
+ {
+ $this->setViewState('CssUrl', $value, '');
+ }
+
+ /**
+ * Registers CSS and JS.
+ * This method is invoked right before the control rendering, if the control is visible.
+ * @param mixed event parameter
+ */
+ public function onPreRender($param)
+ {
+ parent::onPreRender($param);
+ if($this->getPage()->getClientSupportsJavaScript())
+ {
+ $this->registerStyleSheet();
+ $this->registerClientScript();
+ }
+ }
+
+ /**
+ * Adds attribute name-value pairs to renderer.
+ * This method overrides the parent implementation with additional TKeyboard specific attributes.
+ * @param THtmlWriter the writer used for the rendering purpose
+ */
+ protected function addAttributesToRender($writer)
+ {
+ parent::addAttributesToRender($writer);
+ if($this->getPage()->getClientSupportsJavaScript())
+ $writer->addAttribute('id',$this->getClientID());
+ }
+
+ /**
+ * Registers the CSS relevant to the TKeyboard.
+ * It will register the CSS file specified by {@link getCssUrl CssUrl}.
+ * If that is not set, it will use the default CSS.
+ */
+ protected function registerStyleSheet()
+ {
+ if(($url=$this->getCssUrl())==='')
+ $url=$this->getApplication()->getAssetManager()->publishFilePath(dirname(__FILE__).DIRECTORY_SEPARATOR.'assets'.DIRECTORY_SEPARATOR.'keyboard.css');
+ $this->getPage()->getClientScript()->registerStyleSheetFile($url,$url);
+ }
+
+ /**
+ * Registers the relevant JavaScript.
+ */
+ protected function registerClientScript()
+ {
+ $options=TJavaScript::encode($this->getClientOptions());
+ $className=$this->getClientClassName();
+ $cs=$this->getPage()->getClientScript();
+ $cs->registerPradoScript('keyboard');
+ $cs->registerEndScript('prado:'.$this->getClientID(), "new $className($options);");
+ }
+
+ /**
+ * @return string the Javascript class name for this control
+ */
+ protected function getClientClassName()
+ {
+ return 'Prado.WebUI.TKeyboard';
+ }
+
+ /**
+ * @return array the JavaScript options for this control
+ */
+ protected function getClientOptions()
+ {
+ if(($forControl=$this->getForControl())==='')
+ throw new TConfigurationException('keyboard_forcontrol_required');
+ if(($target=$this->findControl($forControl))===null)
+ throw new TConfigurationException('keyboard_forcontrol_invalid',$forControl);
+
+ $options['ID'] = $this->getClientID();
+ $options['ForControl'] = $target->getClientID();
+ $options['AutoHide'] = $this->getAutoHide();
+ $options['CssClass'] = $this->getKeyboardCssClass();
+
+ return $options;
+ }
+}
+
diff --git a/framework/Web/UI/WebControls/TLabel.php b/framework/Web/UI/WebControls/TLabel.php
index 31e424e5..7228d588 100644
--- a/framework/Web/UI/WebControls/TLabel.php
+++ b/framework/Web/UI/WebControls/TLabel.php
@@ -1,154 +1,154 @@
-<?php
-/**
- * TLabel class file.
- *
- * @author Qiang Xue <qiang.xue@gmail.com>
- * @link http://www.pradosoft.com/
+<?php
+/**
+ * TLabel class file.
+ *
+ * @author Qiang Xue <qiang.xue@gmail.com>
+ * @link http://www.pradosoft.com/
* @copyright Copyright &copy; 2005-2012 PradoSoft
- * @license http://www.pradosoft.com/license/
- * @version $Id$
- * @package System.Web.UI.WebControls
- */
-
-/**
- * TLabel class
- *
- * TLabel displays a piece of text on a Web page.
- * Use {@link setText Text} property to set the text to be displayed.
- * TLabel will render the contents enclosed within its component tag
- * if {@link setText Text} is empty.
- * To use TLabel as a form label, associate it with a control by setting the
- * {@link setForControl ForControl} property.
- * The associated control must be locatable within the label's naming container.
- * If the associated control is not visible, the label will not be rendered, either.
- *
- * Note, {@link setText Text} will NOT be encoded for rendering.
- * Make sure it does not contain dangerous characters that you want to avoid.
- *
- * @author Qiang Xue <qiang.xue@gmail.com>
- * @version $Id$
- * @package System.Web.UI.WebControls
- * @since 3.0
- */
-class TLabel extends TWebControl implements IDataRenderer
-{
- private $_forControl='';
-
- /**
- * @return string tag name of the label, returns 'label' if there is an associated control, 'span' otherwise.
- */
- protected function getTagName()
- {
- return ($this->getForControl()==='')?'span':'label';
- }
-
- /**
- * Adds attributes to renderer.
- * @param THtmlWriter the renderer
- * @throws TInvalidDataValueException if associated control cannot be found using the ID
- */
- protected function addAttributesToRender($writer)
- {
- if($this->_forControl!=='')
- $writer->addAttribute('for',$this->_forControl);
- parent::addAttributesToRender($writer);
- }
-
- /**
- * Renders the label.
- * It overrides the parent implementation by checking if an associated
- * control is visible or not. If not, the label will not be rendered.
- * @param THtmlWriter writer
- */
- public function render($writer)
- {
- if(($aid=$this->getForControl())!=='')
- {
- if($control=$this->findControl($aid))
- {
- if($control->getVisible(true))
- {
- $this->_forControl=$control->getClientID();
- parent::render($writer);
- }
- }
- else
- throw new TInvalidDataValueException('label_associatedcontrol_invalid',$aid);
- }
- else
- parent::render($writer);
- }
-
- /**
- * Renders the body content of the label.
- * @param THtmlWriter the renderer
- */
- public function renderContents($writer)
- {
- if(($text=$this->getText())==='')
- parent::renderContents($writer);
- else
- $writer->write($text);
- }
-
- /**
- * @return string the text value of the label
- */
- public function getText()
- {
- return $this->getViewState('Text','');
- }
-
- /**
- * @param string the text value of the label
- */
- public function setText($value)
- {
- $this->setViewState('Text',$value,'');
- }
-
- /**
- * Returns the text value of the label.
- * This method is required by {@link IDataRenderer}.
- * It is the same as {@link getText()}.
- * @return string the text value of the label
- * @see getText
- * @since 3.1.0
- */
- public function getData()
- {
- return $this->getText();
- }
-
- /**
- * Sets the text value of the label.
- * This method is required by {@link IDataRenderer}.
- * It is the same as {@link setText()}.
- * @param string the text value of the label
- * @see setText
- * @since 3.1.0
- */
- public function setData($value)
- {
- $this->setText($value);
- }
-
- /**
- * @return string the associated control ID
- */
- public function getForControl()
- {
- return $this->getViewState('ForControl','');
- }
-
- /**
- * Sets the ID of the control that the label is associated with.
- * The control must be locatable via {@link TControl::findControl} using the ID.
- * @param string the associated control ID
- */
- public function setForControl($value)
- {
- $this->setViewState('ForControl',$value,'');
- }
-}
-
+ * @license http://www.pradosoft.com/license/
+ * @version $Id$
+ * @package System.Web.UI.WebControls
+ */
+
+/**
+ * TLabel class
+ *
+ * TLabel displays a piece of text on a Web page.
+ * Use {@link setText Text} property to set the text to be displayed.
+ * TLabel will render the contents enclosed within its component tag
+ * if {@link setText Text} is empty.
+ * To use TLabel as a form label, associate it with a control by setting the
+ * {@link setForControl ForControl} property.
+ * The associated control must be locatable within the label's naming container.
+ * If the associated control is not visible, the label will not be rendered, either.
+ *
+ * Note, {@link setText Text} will NOT be encoded for rendering.
+ * Make sure it does not contain dangerous characters that you want to avoid.
+ *
+ * @author Qiang Xue <qiang.xue@gmail.com>
+ * @version $Id$
+ * @package System.Web.UI.WebControls
+ * @since 3.0
+ */
+class TLabel extends TWebControl implements IDataRenderer
+{
+ private $_forControl='';
+
+ /**
+ * @return string tag name of the label, returns 'label' if there is an associated control, 'span' otherwise.
+ */
+ protected function getTagName()
+ {
+ return ($this->getForControl()==='')?'span':'label';
+ }
+
+ /**
+ * Adds attributes to renderer.
+ * @param THtmlWriter the renderer
+ * @throws TInvalidDataValueException if associated control cannot be found using the ID
+ */
+ protected function addAttributesToRender($writer)
+ {
+ if($this->_forControl!=='')
+ $writer->addAttribute('for',$this->_forControl);
+ parent::addAttributesToRender($writer);
+ }
+
+ /**
+ * Renders the label.
+ * It overrides the parent implementation by checking if an associated
+ * control is visible or not. If not, the label will not be rendered.
+ * @param THtmlWriter writer
+ */
+ public function render($writer)
+ {
+ if(($aid=$this->getForControl())!=='')
+ {
+ if($control=$this->findControl($aid))
+ {
+ if($control->getVisible(true))
+ {
+ $this->_forControl=$control->getClientID();
+ parent::render($writer);
+ }
+ }
+ else
+ throw new TInvalidDataValueException('label_associatedcontrol_invalid',$aid);
+ }
+ else
+ parent::render($writer);
+ }
+
+ /**
+ * Renders the body content of the label.
+ * @param THtmlWriter the renderer
+ */
+ public function renderContents($writer)
+ {
+ if(($text=$this->getText())==='')
+ parent::renderContents($writer);
+ else
+ $writer->write($text);
+ }
+
+ /**
+ * @return string the text value of the label
+ */
+ public function getText()
+ {
+ return $this->getViewState('Text','');
+ }
+
+ /**
+ * @param string the text value of the label
+ */
+ public function setText($value)
+ {
+ $this->setViewState('Text',$value,'');
+ }
+
+ /**
+ * Returns the text value of the label.
+ * This method is required by {@link IDataRenderer}.
+ * It is the same as {@link getText()}.
+ * @return string the text value of the label
+ * @see getText
+ * @since 3.1.0
+ */
+ public function getData()
+ {
+ return $this->getText();
+ }
+
+ /**
+ * Sets the text value of the label.
+ * This method is required by {@link IDataRenderer}.
+ * It is the same as {@link setText()}.
+ * @param string the text value of the label
+ * @see setText
+ * @since 3.1.0
+ */
+ public function setData($value)
+ {
+ $this->setText($value);
+ }
+
+ /**
+ * @return string the associated control ID
+ */
+ public function getForControl()
+ {
+ return $this->getViewState('ForControl','');
+ }
+
+ /**
+ * Sets the ID of the control that the label is associated with.
+ * The control must be locatable via {@link TControl::findControl} using the ID.
+ * @param string the associated control ID
+ */
+ public function setForControl($value)
+ {
+ $this->setViewState('ForControl',$value,'');
+ }
+}
+
diff --git a/framework/Web/UI/WebControls/TLinkButton.php b/framework/Web/UI/WebControls/TLinkButton.php
index 9da5ec59..f03f9098 100644
--- a/framework/Web/UI/WebControls/TLinkButton.php
+++ b/framework/Web/UI/WebControls/TLinkButton.php
@@ -1,334 +1,334 @@
-<?php
-/**
- * TLinkButton class file
- *
- * @author Qiang Xue <qiang.xue@gmail.com>
- * @link http://www.pradosoft.com/
+<?php
+/**
+ * TLinkButton class file
+ *
+ * @author Qiang Xue <qiang.xue@gmail.com>
+ * @link http://www.pradosoft.com/
* @copyright Copyright &copy; 2005-2012 PradoSoft
- * @license http://www.pradosoft.com/license/
- * @version $Id$
- * @package System.Web.UI.WebControls
- */
-
-/**
- * TLinkButton class
- *
- * TLinkButton creates a hyperlink style button on the page.
- * TLinkButton has the same appearance as a hyperlink. However, it is mainly
- * used to submit data to a page. Like {@link TButton}, you can create either
- * a <b>submit</b> button or a <b>command</b> button.
- *
- * A <b>command</b> button has a command name (specified by
- * the {@link setCommandName CommandName} property) and and a command parameter
- * (specified by {@link setCommandParameter CommandParameter} property)
- * associated with the button. This allows you to create multiple TLinkButton
- * components on a Web page and programmatically determine which one is clicked
- * with what parameter. You can provide an event handler for
- * {@link onCommand OnCommand} event to programmatically control the actions performed
- * when the command button is clicked. In the event handler, you can determine
- * the {@link setCommandName CommandName} property value and
- * the {@link setCommandParameter CommandParameter} property value
- * through the {@link TCommandParameter::getName Name} and
- * {@link TCommandParameter::getParameter Parameter} properties of the event
- * parameter which is of type {@link TCommandEventParameter}.
- *
- * A <b>submit</b> button does not have a command name associated with the button
- * and clicking on it simply posts the Web page back to the server.
- * By default, a TLinkButton component is a submit button.
- * You can provide an event handler for the {@link onClick OnClick} event
- * to programmatically control the actions performed when the submit button is clicked.
- *
- * Clicking on button can trigger form validation, if
- * {@link setCausesValidation CausesValidation} is true.
- * And the validation may be restricted within a certain group of validator
- * controls by setting {@link setValidationGroup ValidationGroup} property.
- * If validation is successful, the data will be post back to the same page.
- *
- * TLinkButton will display the {@link setText Text} property value
- * as the hyperlink text. If {@link setText Text} is empty, the body content
- * of TLinkButton will be displayed. Therefore, you can use TLinkButton
- * as an image button by enclosing an &lt;img&gt; tag as the body of TLinkButton.
- *
- * @author Qiang Xue <qiang.xue@gmail.com>
- * @version $Id$
- * @package System.Web.UI.WebControls
- * @since 3.0
- */
-class TLinkButton extends TWebControl implements IPostBackEventHandler, IButtonControl, IDataRenderer
-{
- /**
- * @return string tag name of the button
- */
- protected function getTagName()
- {
- return 'a';
- }
-
- /**
- * @return boolean whether to render javascript.
- */
- public function getEnableClientScript()
- {
- return $this->getViewState('EnableClientScript',true);
- }
-
- /**
- * @param boolean whether to render javascript.
- */
- public function setEnableClientScript($value)
- {
- $this->setViewState('EnableClientScript',TPropertyValue::ensureBoolean($value),true);
- }
-
- /**
- * Adds attribute name-value pairs to renderer.
- * This overrides the parent implementation with additional button specific attributes.
- * @param THtmlWriter the writer used for the rendering purpose
- */
- protected function addAttributesToRender($writer)
- {
- $page=$this->getPage();
- $page->ensureRenderInForm($this);
-
- $writer->addAttribute('id',$this->getClientID());
-
- // We call parent implementation here because some attributes
- // may be overwritten in the following
- parent::addAttributesToRender($writer);
-
- if($this->getEnabled(true) && $this->getEnableClientScript())
- {
- $this->renderLinkButtonHref($writer);
- $this->renderClientControlScript($writer);
- }
- else if($this->getEnabled()) // in this case, parent will not render 'disabled'
- $writer->addAttribute('disabled','disabled');
- }
-
- /**
- * Renders the client-script code.
- * @param THtmlWriter renderer
- */
- protected function renderClientControlScript($writer)
- {
- $cs = $this->getPage()->getClientScript();
- $cs->registerPostBackControl($this->getClientClassName(),$this->getPostBackOptions());
- }
-
- /**
- * @param boolean set by a panel to register this button as the default button for the panel.
- */
- public function setIsDefaultButton($value)
- {
- $this->setViewState('IsDefaultButton', TPropertyValue::ensureBoolean($value),false);
- }
-
- /**
- * @return boolean true if this button is registered as a default button for a panel.
- */
- public function getIsDefaultButton()
- {
- return $this->getViewState('IsDefaultButton', false);
- }
-
- /**
- * Renders the Href for link button.
- * @param THtmlWriter renderer
- */
- protected function renderLinkButtonHref($writer)
- {
- //create unique no-op url references
- $nop = "javascript:;//".$this->getClientID();
- $writer->addAttribute('href', $nop);
- }
-
- /**
- * Gets the name of the javascript class responsible for performing postback for this control.
- * This method overrides the parent implementation.
- * @return string the javascript class name
- */
- protected function getClientClassName()
- {
- return 'Prado.WebUI.TLinkButton';
- }
-
- /**
- * Returns postback specifications for the button.
- * This method is used by framework and control developers.
- * @return array parameters about how the button defines its postback behavior.
- */
- protected function getPostBackOptions()
- {
- $options['ID'] = $this->getClientID();
- $options['EventTarget'] = $this->getUniqueID();
- $options['CausesValidation'] = $this->getCausesValidation();
- $options['ValidationGroup'] = $this->getValidationGroup();
- $options['StopEvent'] = true;
-
- return $options;
- }
-
- /**
- * Renders the body content enclosed between the control tag.
- * If {@link getText Text} is not empty, it will be rendered. Otherwise,
- * the body content enclosed in the control tag will be rendered.
- * @param THtmlWriter the writer used for the rendering purpose
- */
- public function renderContents($writer)
- {
- if(($text=$this->getText())==='')
- parent::renderContents($writer);
- else
- $writer->write($text);
- }
-
- /**
- * @return string the text caption of the button
- */
- public function getText()
- {
- return $this->getViewState('Text','');
- }
-
- /**
- * @param string the text caption to be set
- */
- public function setText($value)
- {
- $this->setViewState('Text',$value,'');
- }
-
- /**
- * Returns the caption of the button.
- * This method is required by {@link IDataRenderer}.
- * It is the same as {@link getText()}.
- * @return string caption of the button.
- * @see getText
- * @since 3.1.0
- */
- public function getData()
- {
- return $this->getText();
- }
-
- /**
- * Sets the caption of the button.
- * This method is required by {@link IDataRenderer}.
- * It is the same as {@link setText()}.
- * @param string caption of the button
- * @see setText
- * @since 3.1.0
- */
- public function setData($value)
- {
- $this->setText($value);
- }
-
- /**
- * @return string the command name associated with the {@link onCommand OnCommand} event.
- */
- public function getCommandName()
- {
- return $this->getViewState('CommandName','');
- }
-
- /**
- * @param string the command name associated with the {@link onCommand OnCommand} event.
- */
- public function setCommandName($value)
- {
- $this->setViewState('CommandName',$value,'');
- }
-
- /**
- * @return string the parameter associated with the {@link onCommand OnCommand} event
- */
- public function getCommandParameter()
- {
- return $this->getViewState('CommandParameter','');
- }
-
- /**
- * @param string the parameter associated with the {@link onCommand OnCommand} event.
- */
- public function setCommandParameter($value)
- {
- $this->setViewState('CommandParameter',$value,'');
- }
-
- /**
- * @return boolean whether postback event trigger by this button will cause input validation
- */
- public function getCausesValidation()
- {
- return $this->getViewState('CausesValidation',true);
- }
-
- /**
- * Sets the value indicating whether postback event trigger by this button will cause input validation.
- * @param string the text caption to be set
- */
- public function setCausesValidation($value)
- {
- $this->setViewState('CausesValidation',TPropertyValue::ensureBoolean($value),true);
- }
-
- /**
- * @return string the group of validators which the button causes validation upon postback
- */
- public function getValidationGroup()
- {
- return $this->getViewState('ValidationGroup','');
- }
-
- /**
- * @param string the group of validators which the button causes validation upon postback
- */
- public function setValidationGroup($value)
- {
- $this->setViewState('ValidationGroup',$value,'');
- }
-
- /**
- * Raises the postback event.
- * This method is required by {@link IPostBackEventHandler} interface.
- * If {@link getCausesValidation CausesValidation} is true, it will
- * invoke the page's {@link TPage::validate validate} method first.
- * It will raise {@link onClick OnClick} and {@link onCommand OnCommand} events.
- * This method is mainly used by framework and control developers.
- * @param TEventParameter the event parameter
- */
- public function raisePostBackEvent($param)
- {
- if($this->getCausesValidation())
- $this->getPage()->validate($this->getValidationGroup());
- $this->onClick(null);
- $this->onCommand(new TCommandEventParameter($this->getCommandName(),$this->getCommandParameter()));
- }
-
- /**
- * This method is invoked when the button is clicked.
- * The method raises 'OnClick' event to fire up the event handlers.
- * If you override this method, be sure to call the parent implementation
- * so that the event handler can be invoked.
- * @param TEventParameter event parameter to be passed to the event handlers
- */
- public function onClick($param)
- {
- $this->raiseEvent('OnClick',$this,$param);
- }
-
- /**
- * This method is invoked when the button is clicked.
- * The method raises 'OnCommand' event to fire up the event handlers.
- * If you override this method, be sure to call the parent implementation
- * so that the event handlers can be invoked.
- * @param TCommandEventParameter event parameter to be passed to the event handlers
- */
- public function onCommand($param)
- {
- $this->raiseEvent('OnCommand',$this,$param);
- $this->raiseBubbleEvent($this,$param);
- }
-}
-
+ * @license http://www.pradosoft.com/license/
+ * @version $Id$
+ * @package System.Web.UI.WebControls
+ */
+
+/**
+ * TLinkButton class
+ *
+ * TLinkButton creates a hyperlink style button on the page.
+ * TLinkButton has the same appearance as a hyperlink. However, it is mainly
+ * used to submit data to a page. Like {@link TButton}, you can create either
+ * a <b>submit</b> button or a <b>command</b> button.
+ *
+ * A <b>command</b> button has a command name (specified by
+ * the {@link setCommandName CommandName} property) and and a command parameter
+ * (specified by {@link setCommandParameter CommandParameter} property)
+ * associated with the button. This allows you to create multiple TLinkButton
+ * components on a Web page and programmatically determine which one is clicked
+ * with what parameter. You can provide an event handler for
+ * {@link onCommand OnCommand} event to programmatically control the actions performed
+ * when the command button is clicked. In the event handler, you can determine
+ * the {@link setCommandName CommandName} property value and
+ * the {@link setCommandParameter CommandParameter} property value
+ * through the {@link TCommandParameter::getName Name} and
+ * {@link TCommandParameter::getParameter Parameter} properties of the event
+ * parameter which is of type {@link TCommandEventParameter}.
+ *
+ * A <b>submit</b> button does not have a command name associated with the button
+ * and clicking on it simply posts the Web page back to the server.
+ * By default, a TLinkButton component is a submit button.
+ * You can provide an event handler for the {@link onClick OnClick} event
+ * to programmatically control the actions performed when the submit button is clicked.
+ *
+ * Clicking on button can trigger form validation, if
+ * {@link setCausesValidation CausesValidation} is true.
+ * And the validation may be restricted within a certain group of validator
+ * controls by setting {@link setValidationGroup ValidationGroup} property.
+ * If validation is successful, the data will be post back to the same page.
+ *
+ * TLinkButton will display the {@link setText Text} property value
+ * as the hyperlink text. If {@link setText Text} is empty, the body content
+ * of TLinkButton will be displayed. Therefore, you can use TLinkButton
+ * as an image button by enclosing an &lt;img&gt; tag as the body of TLinkButton.
+ *
+ * @author Qiang Xue <qiang.xue@gmail.com>
+ * @version $Id$
+ * @package System.Web.UI.WebControls
+ * @since 3.0
+ */
+class TLinkButton extends TWebControl implements IPostBackEventHandler, IButtonControl, IDataRenderer
+{
+ /**
+ * @return string tag name of the button
+ */
+ protected function getTagName()
+ {
+ return 'a';
+ }
+
+ /**
+ * @return boolean whether to render javascript.
+ */
+ public function getEnableClientScript()
+ {
+ return $this->getViewState('EnableClientScript',true);
+ }
+
+ /**
+ * @param boolean whether to render javascript.
+ */
+ public function setEnableClientScript($value)
+ {
+ $this->setViewState('EnableClientScript',TPropertyValue::ensureBoolean($value),true);
+ }
+
+ /**
+ * Adds attribute name-value pairs to renderer.
+ * This overrides the parent implementation with additional button specific attributes.
+ * @param THtmlWriter the writer used for the rendering purpose
+ */
+ protected function addAttributesToRender($writer)
+ {
+ $page=$this->getPage();
+ $page->ensureRenderInForm($this);
+
+ $writer->addAttribute('id',$this->getClientID());
+
+ // We call parent implementation here because some attributes
+ // may be overwritten in the following
+ parent::addAttributesToRender($writer);
+
+ if($this->getEnabled(true) && $this->getEnableClientScript())
+ {
+ $this->renderLinkButtonHref($writer);
+ $this->renderClientControlScript($writer);
+ }
+ else if($this->getEnabled()) // in this case, parent will not render 'disabled'
+ $writer->addAttribute('disabled','disabled');
+ }
+
+ /**
+ * Renders the client-script code.
+ * @param THtmlWriter renderer
+ */
+ protected function renderClientControlScript($writer)
+ {
+ $cs = $this->getPage()->getClientScript();
+ $cs->registerPostBackControl($this->getClientClassName(),$this->getPostBackOptions());
+ }
+
+ /**
+ * @param boolean set by a panel to register this button as the default button for the panel.
+ */
+ public function setIsDefaultButton($value)
+ {
+ $this->setViewState('IsDefaultButton', TPropertyValue::ensureBoolean($value),false);
+ }
+
+ /**
+ * @return boolean true if this button is registered as a default button for a panel.
+ */
+ public function getIsDefaultButton()
+ {
+ return $this->getViewState('IsDefaultButton', false);
+ }
+
+ /**
+ * Renders the Href for link button.
+ * @param THtmlWriter renderer
+ */
+ protected function renderLinkButtonHref($writer)
+ {
+ //create unique no-op url references
+ $nop = "javascript:;//".$this->getClientID();
+ $writer->addAttribute('href', $nop);
+ }
+
+ /**
+ * Gets the name of the javascript class responsible for performing postback for this control.
+ * This method overrides the parent implementation.
+ * @return string the javascript class name
+ */
+ protected function getClientClassName()
+ {
+ return 'Prado.WebUI.TLinkButton';
+ }
+
+ /**
+ * Returns postback specifications for the button.
+ * This method is used by framework and control developers.
+ * @return array parameters about how the button defines its postback behavior.
+ */
+ protected function getPostBackOptions()
+ {
+ $options['ID'] = $this->getClientID();
+ $options['EventTarget'] = $this->getUniqueID();
+ $options['CausesValidation'] = $this->getCausesValidation();
+ $options['ValidationGroup'] = $this->getValidationGroup();
+ $options['StopEvent'] = true;
+
+ return $options;
+ }
+
+ /**
+ * Renders the body content enclosed between the control tag.
+ * If {@link getText Text} is not empty, it will be rendered. Otherwise,
+ * the body content enclosed in the control tag will be rendered.
+ * @param THtmlWriter the writer used for the rendering purpose
+ */
+ public function renderContents($writer)
+ {
+ if(($text=$this->getText())==='')
+ parent::renderContents($writer);
+ else
+ $writer->write($text);
+ }
+
+ /**
+ * @return string the text caption of the button
+ */
+ public function getText()
+ {
+ return $this->getViewState('Text','');
+ }
+
+ /**
+ * @param string the text caption to be set
+ */
+ public function setText($value)
+ {
+ $this->setViewState('Text',$value,'');
+ }
+
+ /**
+ * Returns the caption of the button.
+ * This method is required by {@link IDataRenderer}.
+ * It is the same as {@link getText()}.
+ * @return string caption of the button.
+ * @see getText
+ * @since 3.1.0
+ */
+ public function getData()
+ {
+ return $this->getText();
+ }
+
+ /**
+ * Sets the caption of the button.
+ * This method is required by {@link IDataRenderer}.
+ * It is the same as {@link setText()}.
+ * @param string caption of the button
+ * @see setText
+ * @since 3.1.0
+ */
+ public function setData($value)
+ {
+ $this->setText($value);
+ }
+
+ /**
+ * @return string the command name associated with the {@link onCommand OnCommand} event.
+ */
+ public function getCommandName()
+ {
+ return $this->getViewState('CommandName','');
+ }
+
+ /**
+ * @param string the command name associated with the {@link onCommand OnCommand} event.
+ */
+ public function setCommandName($value)
+ {
+ $this->setViewState('CommandName',$value,'');
+ }
+
+ /**
+ * @return string the parameter associated with the {@link onCommand OnCommand} event
+ */
+ public function getCommandParameter()
+ {
+ return $this->getViewState('CommandParameter','');
+ }
+
+ /**
+ * @param string the parameter associated with the {@link onCommand OnCommand} event.
+ */
+ public function setCommandParameter($value)
+ {
+ $this->setViewState('CommandParameter',$value,'');
+ }
+
+ /**
+ * @return boolean whether postback event trigger by this button will cause input validation
+ */
+ public function getCausesValidation()
+ {
+ return $this->getViewState('CausesValidation',true);
+ }
+
+ /**
+ * Sets the value indicating whether postback event trigger by this button will cause input validation.
+ * @param string the text caption to be set
+ */
+ public function setCausesValidation($value)
+ {
+ $this->setViewState('CausesValidation',TPropertyValue::ensureBoolean($value),true);
+ }
+
+ /**
+ * @return string the group of validators which the button causes validation upon postback
+ */
+ public function getValidationGroup()
+ {
+ return $this->getViewState('ValidationGroup','');
+ }
+
+ /**
+ * @param string the group of validators which the button causes validation upon postback
+ */
+ public function setValidationGroup($value)
+ {
+ $this->setViewState('ValidationGroup',$value,'');
+ }
+
+ /**
+ * Raises the postback event.
+ * This method is required by {@link IPostBackEventHandler} interface.
+ * If {@link getCausesValidation CausesValidation} is true, it will
+ * invoke the page's {@link TPage::validate validate} method first.
+ * It will raise {@link onClick OnClick} and {@link onCommand OnCommand} events.
+ * This method is mainly used by framework and control developers.
+ * @param TEventParameter the event parameter
+ */
+ public function raisePostBackEvent($param)
+ {
+ if($this->getCausesValidation())
+ $this->getPage()->validate($this->getValidationGroup());
+ $this->onClick(null);
+ $this->onCommand(new TCommandEventParameter($this->getCommandName(),$this->getCommandParameter()));
+ }
+
+ /**
+ * This method is invoked when the button is clicked.
+ * The method raises 'OnClick' event to fire up the event handlers.
+ * If you override this method, be sure to call the parent implementation
+ * so that the event handler can be invoked.
+ * @param TEventParameter event parameter to be passed to the event handlers
+ */
+ public function onClick($param)
+ {
+ $this->raiseEvent('OnClick',$this,$param);
+ }
+
+ /**
+ * This method is invoked when the button is clicked.
+ * The method raises 'OnCommand' event to fire up the event handlers.
+ * If you override this method, be sure to call the parent implementation
+ * so that the event handlers can be invoked.
+ * @param TCommandEventParameter event parameter to be passed to the event handlers
+ */
+ public function onCommand($param)
+ {
+ $this->raiseEvent('OnCommand',$this,$param);
+ $this->raiseBubbleEvent($this,$param);
+ }
+}
+
diff --git a/framework/Web/UI/WebControls/TListBox.php b/framework/Web/UI/WebControls/TListBox.php
index 8e996b6e..f7ab4791 100644
--- a/framework/Web/UI/WebControls/TListBox.php
+++ b/framework/Web/UI/WebControls/TListBox.php
@@ -1,226 +1,226 @@
-<?php
-/**
- * TListBox class file
- *
- * @author Qiang Xue <qiang.xue@gmail.com>
- * @link http://www.pradosoft.com/
+<?php
+/**
+ * TListBox class file
+ *
+ * @author Qiang Xue <qiang.xue@gmail.com>
+ * @link http://www.pradosoft.com/
* @copyright Copyright &copy; 2005-2012 PradoSoft
- * @license http://www.pradosoft.com/license/
- * @version $Id$
- * @package System.Web.UI.WebControls
- */
-
-/**
- * Includes TListControl class
- */
-Prado::using('System.Web.UI.WebControls.TListControl');
-
-/**
- * TListBox class
- *
- * TListBox displays a list box on a Web page that allows single or multiple selection.
- * The list box allows multiple selections if {@link setSelectionMode SelectionMode}
- * is TListSelectionMode::Multiple. It takes single selection only if Single.
- * The property {@link setRows Rows} specifies how many rows of options are visible
- * at a time. See {@link TListControl} for inherited properties.
- *
- * Since v3.0.3, TListBox starts to support optgroup. To specify an option group for
- * a list item, set a Group attribute with it,
- * <code>
- * $listitem->Attributes->Group="Group Name";
- * // or <com:TListItem Attributes.Group="Group Name" .../> in template
- * </code>
- *
- * @author Qiang Xue <qiang.xue@gmail.com>
- * @version $Id$
- * @package System.Web.UI.WebControls
- * @since 3.0
- */
-class TListBox extends TListControl implements IPostBackDataHandler, IValidatable
-{
- private $_dataChanged=false;
+ * @license http://www.pradosoft.com/license/
+ * @version $Id$
+ * @package System.Web.UI.WebControls
+ */
+
+/**
+ * Includes TListControl class
+ */
+Prado::using('System.Web.UI.WebControls.TListControl');
+
+/**
+ * TListBox class
+ *
+ * TListBox displays a list box on a Web page that allows single or multiple selection.
+ * The list box allows multiple selections if {@link setSelectionMode SelectionMode}
+ * is TListSelectionMode::Multiple. It takes single selection only if Single.
+ * The property {@link setRows Rows} specifies how many rows of options are visible
+ * at a time. See {@link TListControl} for inherited properties.
+ *
+ * Since v3.0.3, TListBox starts to support optgroup. To specify an option group for
+ * a list item, set a Group attribute with it,
+ * <code>
+ * $listitem->Attributes->Group="Group Name";
+ * // or <com:TListItem Attributes.Group="Group Name" .../> in template
+ * </code>
+ *
+ * @author Qiang Xue <qiang.xue@gmail.com>
+ * @version $Id$
+ * @package System.Web.UI.WebControls
+ * @since 3.0
+ */
+class TListBox extends TListControl implements IPostBackDataHandler, IValidatable
+{
+ private $_dataChanged=false;
private $_isValid=true;
-
- /**
- * Adds attribute name-value pairs to renderer.
- * This method overrides the parent implementation with additional list box specific attributes.
- * @param THtmlWriter the writer used for the rendering purpose
- */
- protected function addAttributesToRender($writer)
- {
- $rows=$this->getRows();
- $writer->addAttribute('size',"$rows");
- if($this->getSelectionMode()===TListSelectionMode::Multiple)
- $writer->addAttribute('name',$this->getUniqueID().'[]');
- else
- $writer->addAttribute('name',$this->getUniqueID());
- parent::addAttributesToRender($writer);
- }
-
- /**
- * Gets the name of the javascript class responsible for performing postback for this control.
- * This method overrides the parent implementation.
- * @return string the javascript class name
- */
- protected function getClientClassName()
- {
- return 'Prado.WebUI.TListBox';
- }
-
- /**
- * Registers the list control to load post data on postback.
- * This method overrides the parent implementation.
- * @param mixed event parameter
- */
- public function onPreRender($param)
- {
- parent::onPreRender($param);
- if($this->getEnabled(true))
- $this->getPage()->registerRequiresPostData($this);
- }
-
- /**
- * Loads user input data.
- * This method is primarly used by framework developers.
- * @param string the key that can be used to retrieve data from the input data collection
- * @param array the input data collection
- * @return boolean whether the data of the component has been changed
- */
- public function loadPostData($key,$values)
- {
- if(!$this->getEnabled(true))
- return false;
- $this->ensureDataBound();
- $selections=isset($values[$key])?$values[$key]:null;
- if($selections!==null)
- {
- $items=$this->getItems();
- if($this->getSelectionMode()===TListSelectionMode::Single)
- {
- $selection=is_array($selections)?$selections[0]:$selections;
- $index=$items->findIndexByValue($selection,false);
- if($this->getSelectedIndex()!==$index)
- {
- $this->setSelectedIndex($index);
- return $this->_dataChanged=true;
- }
- else
- return false;
- }
- if(!is_array($selections))
- $selections=array($selections);
- $list=array();
- foreach($selections as $selection)
- $list[]=$items->findIndexByValue($selection,false);
- $list2=$this->getSelectedIndices();
- $n=count($list);
- $flag=false;
- if($n===count($list2))
- {
- sort($list,SORT_NUMERIC);
- for($i=0;$i<$n;++$i)
- {
- if($list[$i]!==$list2[$i])
- {
- $flag=true;
- break;
- }
- }
- }
- else
- $flag=true;
- if($flag)
- {
- $this->setSelectedIndices($list);
- $this->_dataChanged=true;
- }
- return $flag;
- }
- else if($this->getSelectedIndex()!==-1)
- {
- $this->clearSelection();
- return $this->_dataChanged=true;
- }
- else
- return false;
- }
-
- /**
- * Raises postdata changed event.
- * This method is required by {@link IPostBackDataHandler} interface.
- * It is invoked by the framework when {@link getSelectedIndices SelectedIndices} property
- * is changed on postback.
- * This method is primarly used by framework developers.
- */
- public function raisePostDataChangedEvent()
- {
- if($this->getAutoPostBack() && $this->getCausesValidation())
- $this->getPage()->validate($this->getValidationGroup());
- $this->onSelectedIndexChanged(null);
- }
-
- /**
- * Returns a value indicating whether postback has caused the control data change.
- * This method is required by the IPostBackDataHandler interface.
- * @return boolean whether postback has caused the control data change. False if the page is not in postback mode.
- */
- public function getDataChanged()
- {
- return $this->_dataChanged;
- }
-
- /**
- * @return boolean whether this control allows multiple selection
- */
- protected function getIsMultiSelect()
- {
- return $this->getSelectionMode()===TListSelectionMode::Multiple;
- }
-
- /**
- * @return integer the number of rows to be displayed in the list control
- */
- public function getRows()
- {
- return $this->getViewState('Rows', 4);
- }
-
- /**
- * @param integer the number of rows to be displayed in the list control
- */
- public function setRows($value)
- {
- $value=TPropertyValue::ensureInteger($value);
- if($value<=0)
- $value=4;
- $this->setViewState('Rows', $value, 4);
- }
-
- /**
- * @return TListSelectionMode the selection mode (Single, Multiple). Defaults to TListSelectionMode::Single.
- */
- public function getSelectionMode()
- {
- return $this->getViewState('SelectionMode', TListSelectionMode::Single);
- }
-
- /**
- * @param TListSelectionMode the selection mode
- */
- public function setSelectionMode($value)
- {
- $this->setViewState('SelectionMode',TPropertyValue::ensureEnum($value,'TListSelectionMode'),TListSelectionMode::Single);
- }
-
- /**
- * Returns the value to be validated.
- * This methid is required by IValidatable interface.
- * @return mixed the value of the property to be validated.
- */
- public function getValidationPropertyValue()
- {
- return $this->getSelectedValue();
- }
+
+ /**
+ * Adds attribute name-value pairs to renderer.
+ * This method overrides the parent implementation with additional list box specific attributes.
+ * @param THtmlWriter the writer used for the rendering purpose
+ */
+ protected function addAttributesToRender($writer)
+ {
+ $rows=$this->getRows();
+ $writer->addAttribute('size',"$rows");
+ if($this->getSelectionMode()===TListSelectionMode::Multiple)
+ $writer->addAttribute('name',$this->getUniqueID().'[]');
+ else
+ $writer->addAttribute('name',$this->getUniqueID());
+ parent::addAttributesToRender($writer);
+ }
+
+ /**
+ * Gets the name of the javascript class responsible for performing postback for this control.
+ * This method overrides the parent implementation.
+ * @return string the javascript class name
+ */
+ protected function getClientClassName()
+ {
+ return 'Prado.WebUI.TListBox';
+ }
+
+ /**
+ * Registers the list control to load post data on postback.
+ * This method overrides the parent implementation.
+ * @param mixed event parameter
+ */
+ public function onPreRender($param)
+ {
+ parent::onPreRender($param);
+ if($this->getEnabled(true))
+ $this->getPage()->registerRequiresPostData($this);
+ }
+
+ /**
+ * Loads user input data.
+ * This method is primarly used by framework developers.
+ * @param string the key that can be used to retrieve data from the input data collection
+ * @param array the input data collection
+ * @return boolean whether the data of the component has been changed
+ */
+ public function loadPostData($key,$values)
+ {
+ if(!$this->getEnabled(true))
+ return false;
+ $this->ensureDataBound();
+ $selections=isset($values[$key])?$values[$key]:null;
+ if($selections!==null)
+ {
+ $items=$this->getItems();
+ if($this->getSelectionMode()===TListSelectionMode::Single)
+ {
+ $selection=is_array($selections)?$selections[0]:$selections;
+ $index=$items->findIndexByValue($selection,false);
+ if($this->getSelectedIndex()!==$index)
+ {
+ $this->setSelectedIndex($index);
+ return $this->_dataChanged=true;
+ }
+ else
+ return false;
+ }
+ if(!is_array($selections))
+ $selections=array($selections);
+ $list=array();
+ foreach($selections as $selection)
+ $list[]=$items->findIndexByValue($selection,false);
+ $list2=$this->getSelectedIndices();
+ $n=count($list);
+ $flag=false;
+ if($n===count($list2))
+ {
+ sort($list,SORT_NUMERIC);
+ for($i=0;$i<$n;++$i)
+ {
+ if($list[$i]!==$list2[$i])
+ {
+ $flag=true;
+ break;
+ }
+ }
+ }
+ else
+ $flag=true;
+ if($flag)
+ {
+ $this->setSelectedIndices($list);
+ $this->_dataChanged=true;
+ }
+ return $flag;
+ }
+ else if($this->getSelectedIndex()!==-1)
+ {
+ $this->clearSelection();
+ return $this->_dataChanged=true;
+ }
+ else
+ return false;
+ }
+
+ /**
+ * Raises postdata changed event.
+ * This method is required by {@link IPostBackDataHandler} interface.
+ * It is invoked by the framework when {@link getSelectedIndices SelectedIndices} property
+ * is changed on postback.
+ * This method is primarly used by framework developers.
+ */
+ public function raisePostDataChangedEvent()
+ {
+ if($this->getAutoPostBack() && $this->getCausesValidation())
+ $this->getPage()->validate($this->getValidationGroup());
+ $this->onSelectedIndexChanged(null);
+ }
+
+ /**
+ * Returns a value indicating whether postback has caused the control data change.
+ * This method is required by the IPostBackDataHandler interface.
+ * @return boolean whether postback has caused the control data change. False if the page is not in postback mode.
+ */
+ public function getDataChanged()
+ {
+ return $this->_dataChanged;
+ }
+
+ /**
+ * @return boolean whether this control allows multiple selection
+ */
+ protected function getIsMultiSelect()
+ {
+ return $this->getSelectionMode()===TListSelectionMode::Multiple;
+ }
+
+ /**
+ * @return integer the number of rows to be displayed in the list control
+ */
+ public function getRows()
+ {
+ return $this->getViewState('Rows', 4);
+ }
+
+ /**
+ * @param integer the number of rows to be displayed in the list control
+ */
+ public function setRows($value)
+ {
+ $value=TPropertyValue::ensureInteger($value);
+ if($value<=0)
+ $value=4;
+ $this->setViewState('Rows', $value, 4);
+ }
+
+ /**
+ * @return TListSelectionMode the selection mode (Single, Multiple). Defaults to TListSelectionMode::Single.
+ */
+ public function getSelectionMode()
+ {
+ return $this->getViewState('SelectionMode', TListSelectionMode::Single);
+ }
+
+ /**
+ * @param TListSelectionMode the selection mode
+ */
+ public function setSelectionMode($value)
+ {
+ $this->setViewState('SelectionMode',TPropertyValue::ensureEnum($value,'TListSelectionMode'),TListSelectionMode::Single);
+ }
+
+ /**
+ * Returns the value to be validated.
+ * This methid is required by IValidatable interface.
+ * @return mixed the value of the property to be validated.
+ */
+ public function getValidationPropertyValue()
+ {
+ return $this->getSelectedValue();
+ }
/**
* Returns true if this control validated successfully.
@@ -238,25 +238,25 @@ class TListBox extends TListControl implements IPostBackDataHandler, IValidatabl
{
$this->_isValid=TPropertyValue::ensureBoolean($value);
}
-}
-
-
-/**
- * TListSelectionMode class.
- * TListSelectionMode defines the enumerable type for the possible selection modes of a {@link TListBox}.
- *
- * The following enumerable values are defined:
- * - Single: single selection
- * - Multiple: allow multiple selection
- *
- * @author Qiang Xue <qiang.xue@gmail.com>
- * @version $Id$
- * @package System.Web.UI.WebControls
- * @since 3.0.4
- */
-class TListSelectionMode extends TEnumerable
-{
- const Single='Single';
- const Multiple='Multiple';
-}
-
+}
+
+
+/**
+ * TListSelectionMode class.
+ * TListSelectionMode defines the enumerable type for the possible selection modes of a {@link TListBox}.
+ *
+ * The following enumerable values are defined:
+ * - Single: single selection
+ * - Multiple: allow multiple selection
+ *
+ * @author Qiang Xue <qiang.xue@gmail.com>
+ * @version $Id$
+ * @package System.Web.UI.WebControls
+ * @since 3.0.4
+ */
+class TListSelectionMode extends TEnumerable
+{
+ const Single='Single';
+ const Multiple='Multiple';
+}
+
diff --git a/framework/Web/UI/WebControls/TListControl.php b/framework/Web/UI/WebControls/TListControl.php
index 1a07a292..4d388d45 100644
--- a/framework/Web/UI/WebControls/TListControl.php
+++ b/framework/Web/UI/WebControls/TListControl.php
@@ -1,923 +1,923 @@
-<?php
-
-/**
- * TListControl class file
- *
- * @author Robin J. Rogge <rojaro@gmail.com>
- * @author Qiang Xue <qiang.xue@gmail.com>
- * @link http://www.pradosoft.com/
- * @copyright Copyright &copy; 2005-2012 PradoSoft
- * @license http://www.pradosoft.com/license/
- * @version $Id$
- * @package System.Web.UI.WebControls
- */
-
-/**
- * Includes the supporting classes
- */
-Prado::using('System.Web.UI.WebControls.TDataBoundControl');
-Prado::using('System.Web.UI.WebControls.TListItem');
-Prado::using('System.Collections.TListItemCollection');
-Prado::using('System.Collections.TAttributeCollection');
-Prado::using('System.Util.TDataFieldAccessor');
-
-/**
- * TListControl class
- *
- * TListControl is a base class for list controls, such as {@link TListBox},
- * {@link TDropDownList}, {@link TCheckBoxList}, etc.
- * It manages the items and their status in a list control.
- * It also implements how the items can be populated from template and
- * data source.
- *
- * The property {@link getItems} returns a list of the items in the control.
- * To specify or determine which item is selected, use the
- * {@link getSelectedIndex SelectedIndex} property that indicates the zero-based
- * index of the selected item in the item list. You may also use
- * {@link getSelectedItem SelectedItem} and {@link getSelectedValue SelectedValue}
- * to get the selected item and its value. For multiple selection lists
- * (such as {@link TCheckBoxList} and {@link TListBox}), property
- * {@link getSelectedIndices SelectedIndices} is useful.
- *
- * TListControl implements {@link setAutoPostBack AutoPostBack} which allows
- * a list control to postback the page if the selections of the list items are changed.
- * The {@link setCausesValidation CausesValidation} and {@link setValidationGroup ValidationGroup}
- * properties may be used to specify that validation be performed when auto postback occurs.
- *
- * There are three ways to populate the items in a list control: from template,
- * using {@link setDataSource DataSource} and using {@link setDataSourceID DataSourceID}.
- * The latter two are covered in {@link TDataBoundControl}. To specify items via
- * template, using the following template syntax:
- * <code>
- * <com:TListControl>
- * <com:TListItem Value="xxx" Text="yyy" >
- * <com:TListItem Value="xxx" Text="yyy" Selected="true" >
- * <com:TListItem Value="xxx" Text="yyy" >
- * </com:TListControl>
- * </code>
- *
- * When {@link setDataSource DataSource} or {@link setDataSourceID DataSourceID}
- * is used to populate list items, the {@link setDataTextField DataTextField} and
- * {@link setDataValueField DataValueField} properties are used to specify which
- * columns of the data will be used to populate the text and value of the items.
- * For example, if a data source is as follows,
- * <code>
- * $dataSource=array(
- * array('name'=>'John', 'age'=>31),
- * array('name'=>'Cary', 'age'=>28),
- * array('name'=>'Rose', 'age'=>35),
- * );
- * </code>
- * setting {@link setDataTextField DataTextField} and {@link setDataValueField DataValueField}
- * to 'name' and 'age' will make the first item's text be 'John', value be 31,
- * the second item's text be 'Cary', value be 28, and so on.
- * The {@link setDataTextFormatString DataTextFormatString} property may be further
- * used to format how the item should be displayed. See {@link formatDataValue()}
- * for an explanation of the format string.
- *
- * @author Qiang Xue <qiang.xue@gmail.com>
- * @version $Id$
- * @package System.Web.UI.WebControls
- * @since 3.0
- */
-abstract class TListControl extends TDataBoundControl implements IDataRenderer
-{
- /**
- * @var TListItemCollection item list
- */
- private $_items=null;
- /**
- * @var boolean whether items are restored from viewstate
- */
- private $_stateLoaded=false;
- /**
- * @var mixed the following selection variables are used
- * to keep selections when Items are not available
- */
- private $_cachedSelectedIndex=-1;
- private $_cachedSelectedValue=null;
- private $_cachedSelectedIndices=null;
- private $_cachedSelectedValues=null;
-
- /**
- * @return string tag name of the list control
- */
- protected function getTagName()
- {
- return 'select';
- }
-
- /**
- * @return boolean whether to render javascript.
- */
- public function getEnableClientScript()
- {
- return $this->getViewState('EnableClientScript',true);
- }
-
- /**
- * @param boolean whether to render javascript.
- */
- public function setEnableClientScript($value)
- {
- $this->setViewState('EnableClientScript',TPropertyValue::ensureBoolean($value),true);
- }
-
- /**
- * Adds attributes to renderer.
- * @param THtmlWriter the renderer
- */
- protected function addAttributesToRender($writer)
- {
- $page=$this->getPage();
- $page->ensureRenderInForm($this);
- if($this->getIsMultiSelect())
- $writer->addAttribute('multiple','multiple');
- if($this->getEnabled(true))
- {
- if($this->getAutoPostBack()
- && $this->getEnableClientScript()
- && $page->getClientSupportsJavaScript())
- {
- $this->renderClientControlScript($writer);
- }
- }
- else if($this->getEnabled())
- $writer->addAttribute('disabled','disabled');
- parent::addAttributesToRender($writer);
- }
-
- /**
- * Renders the javascript for list control.
- */
- protected function renderClientControlScript($writer)
- {
- $writer->addAttribute('id',$this->getClientID());
- $this->getPage()->getClientScript()->registerPostBackControl($this->getClientClassName(),$this->getPostBackOptions());
- }
-
- /**
- * Gets the name of the javascript class responsible for performing postback for this control.
- * Derived classes may override this method and return customized js class names.
- * @return string the javascript class name
- */
- protected function getClientClassName()
- {
- return 'Prado.WebUI.TListControl';
- }
-
- /**
- * @return array postback options for JS postback code
- */
- protected function getPostBackOptions()
- {
- $options['ID'] = $this->getClientID();
- $options['CausesValidation'] = $this->getCausesValidation();
- $options['ValidationGroup'] = $this->getValidationGroup();
- $options['EventTarget'] = $this->getUniqueID();
- return $options;
- }
-
- /**
- * Adds object parsed from template to the control.
- * This method adds only {@link TListItem} objects into the {@link getItems Items} collection.
- * All other objects are ignored.
- * @param mixed object parsed from template
- */
- public function addParsedObject($object)
- {
- // Do not add items from template if items are loaded from viewstate
- if(!$this->_stateLoaded && ($object instanceof TListItem))
- {
- $index=$this->getItems()->add($object);
- if(($this->_cachedSelectedValue!==null && $this->_cachedSelectedValue===$object->getValue()) || ($this->_cachedSelectedIndex===$index))
- {
- $object->setSelected(true);
- $this->_cachedSelectedValue=null;
- $this->_cachedSelectedIndex=-1;
- }
- }
- }
-
- /**
- * Performs databinding to populate list items from data source.
- * This method is invoked by dataBind().
- * You may override this function to provide your own way of data population.
- * @param Traversable the data
- */
- protected function performDataBinding($data)
- {
- $items=$this->getItems();
- if(!$this->getAppendDataBoundItems())
- $items->clear();
- $textField=$this->getDataTextField();
- if($textField==='')
- $textField=0;
- $valueField=$this->getDataValueField();
- if($valueField==='')
- $valueField=1;
- $textFormat=$this->getDataTextFormatString();
- $groupField=$this->getDataGroupField();
- foreach($data as $key=>$object)
- {
- $item=$items->createListItem();
- if(is_array($object) || is_object($object))
- {
- $text=TDataFieldAccessor::getDataFieldValue($object,$textField);
- $value=TDataFieldAccessor::getDataFieldValue($object,$valueField);
- $item->setValue($value);
- if($groupField!=='')
- $item->setAttribute('Group',TDataFieldAccessor::getDataFieldValue($object,$groupField));
- }
- else
- {
- $text=$object;
- $item->setValue("$key");
- }
- $item->setText($this->formatDataValue($textFormat,$text));
- }
- // SelectedValue or SelectedIndex may be set before databinding
- // so we make them be effective now
- if($this->_cachedSelectedValue!==null)
- {
- $this->setSelectedValue($this->_cachedSelectedValue);
- $this->resetCachedSelections();
- }
- else if($this->_cachedSelectedIndex!==-1)
- {
- $this->setSelectedIndex($this->_cachedSelectedIndex);
- $this->resetCachedSelections();
- }
- else if($this->_cachedSelectedValues!==null)
- {
- $this->setSelectedValues($this->_cachedSelectedValues);
- $this->resetCachedSelections();
- }
- else if($this->_cachedSelectedIndices!==null)
- {
- $this->setSelectedIndices($this->_cachedSelectedIndices);
- $this->resetCachedSelections();
- }
- }
-
- private function resetCachedSelections()
- {
- $this->_cachedSelectedValue=null;
- $this->_cachedSelectedIndex=-1;
- $this->_cachedSelectedValues=null;
- $this->_cachedSelectedIndices=null;
- }
-
- /**
- * Creates a collection object to hold list items.
- * This method may be overriden to create a customized collection.
- * @return TListItemCollection the collection object
- */
- protected function createListItemCollection()
- {
- return new TListItemCollection;
- }
-
- /**
- * Saves items into viewstate.
- * This method is invoked right before control state is to be saved.
- */
- public function saveState()
- {
- parent::saveState();
- if($this->_items)
- $this->setViewState('Items',$this->_items->saveState(),null);
- else
- $this->clearViewState('Items');
- }
-
- /**
- * Loads items from viewstate.
- * This method is invoked right after control state is loaded.
- */
- public function loadState()
- {
- parent::loadState();
- $this->_stateLoaded=true;
- if(!$this->getIsDataBound())
- {
- $this->_items=$this->createListItemCollection();
- $this->_items->loadState($this->getViewState('Items',null));
- }
- $this->clearViewState('Items');
- }
-
- /**
- * @return boolean whether this is a multiselect control. Defaults to false.
- */
- protected function getIsMultiSelect()
- {
- return false;
- }
-
- /**
- * @return boolean whether performing databind should append items or clear the existing ones. Defaults to false.
- */
- public function getAppendDataBoundItems()
- {
- return $this->getViewState('AppendDataBoundItems',false);
- }
-
- /**
- * @param boolean whether performing databind should append items or clear the existing ones.
- */
- public function setAppendDataBoundItems($value)
- {
- $this->setViewState('AppendDataBoundItems',TPropertyValue::ensureBoolean($value),false);
- }
-
- /**
- * @return boolean a value indicating whether an automatic postback to the server
- * will occur whenever the user makes change to the list control and then tabs out of it.
- * Defaults to false.
- */
- public function getAutoPostBack()
- {
- return $this->getViewState('AutoPostBack',false);
- }
-
- /**
- * Sets the value indicating if postback automatically.
- * An automatic postback to the server will occur whenever the user
- * makes change to the list control and then tabs out of it.
- * @param boolean the value indicating if postback automatically
- */
- public function setAutoPostBack($value)
- {
- $this->setViewState('AutoPostBack',TPropertyValue::ensureBoolean($value),false);
- }
-
- /**
- * @return boolean whether postback event trigger by this list control will cause input validation, default is true.
- */
- public function getCausesValidation()
- {
- return $this->getViewState('CausesValidation',true);
- }
-
- /**
- * @param boolean whether postback event trigger by this list control will cause input validation.
- */
- public function setCausesValidation($value)
- {
- $this->setViewState('CausesValidation',TPropertyValue::ensureBoolean($value),true);
- }
-
- /**
- * @return string the field of the data source that provides the text content of the list items.
- */
- public function getDataTextField()
- {
- return $this->getViewState('DataTextField','');
- }
-
- /**
- * @param string the field of the data source that provides the text content of the list items.
- */
- public function setDataTextField($value)
- {
- $this->setViewState('DataTextField',$value,'');
- }
-
- /**
- * @return string the formatting string used to control how data bound to the list control is displayed.
- */
- public function getDataTextFormatString()
- {
- return $this->getViewState('DataTextFormatString','');
- }
-
- /**
- * Sets data text format string.
- * The format string is used in {@link TDataValueFormatter::format()} to format the Text property value
- * of each item in the list control.
- * @param string the formatting string used to control how data bound to the list control is displayed.
- * @see TDataValueFormatter::format()
- */
- public function setDataTextFormatString($value)
- {
- $this->setViewState('DataTextFormatString',$value,'');
- }
-
- /**
- * @return string the field of the data source that provides the value of each list item.
- */
- public function getDataValueField()
- {
- return $this->getViewState('DataValueField','');
- }
-
- /**
- * @param string the field of the data source that provides the value of each list item.
- */
- public function setDataValueField($value)
- {
- $this->setViewState('DataValueField',$value,'');
- }
-
- /**
- * @return string the field of the data source that provides the label of the list item groups
- */
- public function getDataGroupField()
- {
- return $this->getViewState('DataGroupField','');
- }
-
- /**
- * @param string the field of the data source that provides the label of the list item groups
- */
- public function setDataGroupField($value)
- {
- $this->setViewState('DataGroupField',$value,'');
- }
-
- /**
- * @return integer the number of items in the list control
- */
- public function getItemCount()
- {
- return $this->_items?$this->_items->getCount():0;
- }
-
- /**
- * @return boolean whether the list control contains any items.
- */
- public function getHasItems()
- {
- return ($this->_items && $this->_items->getCount()>0);
- }
-
- /**
- * @return TListItemCollection the item collection
- */
- public function getItems()
- {
- if(!$this->_items)
- $this->_items=$this->createListItemCollection();
- return $this->_items;
- }
-
- /**
- * @return integer the index (zero-based) of the item being selected, -1 if no item is selected.
- */
- public function getSelectedIndex()
- {
- if($this->_items)
- {
- $n=$this->_items->getCount();
- for($i=0;$i<$n;++$i)
- if($this->_items->itemAt($i)->getSelected())
- return $i;
- }
- return -1;
- }
-
- /**
- * @param integer the index (zero-based) of the item to be selected
- */
- public function setSelectedIndex($index)
- {
- if(($index=TPropertyValue::ensureInteger($index))<0)
- $index=-1;
- if($this->_items)
- {
- $this->clearSelection();
- if($index>=0 && $index<$this->_items->getCount())
- $this->_items->itemAt($index)->setSelected(true);
- }
- $this->_cachedSelectedIndex=$index;
- if($this->getAdapter() instanceof IListControlAdapter)
- $this->getAdapter()->setSelectedIndex($index);
- }
-
- /**
- * @return array list of index of items that are selected
- */
- public function getSelectedIndices()
- {
- $selections=array();
- if($this->_items)
- {
- $n=$this->_items->getCount();
- for($i=0;$i<$n;++$i)
- if($this->_items->itemAt($i)->getSelected())
- $selections[]=$i;
- }
- return $selections;
- }
-
- /**
- * @param array list of index of items to be selected
- */
- public function setSelectedIndices($indices)
- {
- if($this->getIsMultiSelect())
- {
- if($this->_items)
- {
- $this->clearSelection();
- $n=$this->_items->getCount();
- foreach($indices as $index)
- {
- if($index>=0 && $index<$n)
- $this->_items->itemAt($index)->setSelected(true);
- }
- }
- $this->_cachedSelectedIndices=$indices;
- }
- else
- throw new TNotSupportedException('listcontrol_multiselect_unsupported',get_class($this));
-
- if($this->getAdapter() instanceof IListControlAdapter)
- $this->getAdapter()->setSelectedIndices($indices);
- }
-
- /**
- * @return TListItem|null the selected item with the lowest cardinal index, null if no item is selected.
- */
- public function getSelectedItem()
- {
- if(($index=$this->getSelectedIndex())>=0)
- return $this->_items->itemAt($index);
- else
- return null;
- }
-
- /**
- * Returns the value of the selected item with the lowest cardinal index.
- * This method is required by {@link IDataRenderer}.
- * It is the same as {@link getSelectedValue()}.
- * @return string the value of the selected item with the lowest cardinal index, empty if no selection.
- * @see getSelectedValue
- * @since 3.1.0
- */
- public function getData()
- {
- return $this->getSelectedValue();
- }
-
- /**
- * Selects an item by the specified value.
- * This method is required by {@link IDataRenderer}.
- * It is the same as {@link setSelectedValue()}.
- * @param string the value of the item to be selected.
- * @see setSelectedValue
- * @since 3.1.0
- */
- public function setData($value)
- {
- $this->setSelectedValue($value);
- }
-
- /**
- * @return string the value of the selected item with the lowest cardinal index, empty if no selection
- */
- public function getSelectedValue()
- {
- $index=$this->getSelectedIndex();
- return $index>=0?$this->getItems()->itemAt($index)->getValue():'';
- }
-
- /**
- * Sets selection by item value.
- * Existing selections will be cleared if the item value is found in the item collection.
- * Note, if the value is null, existing selections will also be cleared.
- * @param string the value of the item to be selected.
- */
- public function setSelectedValue($value)
- {
- if($this->_items)
- {
- if($value===null)
- $this->clearSelection();
- else if(($item=$this->_items->findItemByValue($value))!==null)
- {
- $this->clearSelection();
- $item->setSelected(true);
- }
- else
- $this->clearSelection();
- }
- $this->_cachedSelectedValue=$value;
- if($this->getAdapter() instanceof IListControlAdapter)
- $this->getAdapter()->setSelectedValue($value);
- }
-
-
- /**
- * @return array list of the selected item values (strings)
- */
- public function getSelectedValues()
- {
- $values=array();
- if($this->_items)
- {
- foreach($this->_items as $item)
- {
- if($item->getSelected())
- $values[]=$item->getValue();
- }
- }
- return $values;
- }
-
- /**
- * @param array list of the selected item values
- */
- public function setSelectedValues($values)
- {
- if($this->getIsMultiSelect())
- {
- if($this->_items)
- {
- $this->clearSelection();
- $lookup=array();
- foreach($this->_items as $item)
- $lookup[$item->getValue()]=$item;
- foreach($values as $value)
- {
- if(isset($lookup["$value"]))
- $lookup["$value"]->setSelected(true);
- }
- }
- $this->_cachedSelectedValues=$values;
- }
- else
- throw new TNotSupportedException('listcontrol_multiselect_unsupported',get_class($this));
-
- if($this->getAdapter() instanceof IListControlAdapter)
- $this->getAdapter()->setSelectedValues($values);
- }
-
- /**
- * @return string selected value
- */
- public function getText()
- {
- return $this->getSelectedValue();
- }
-
- /**
- * @param string value to be selected
- */
- public function setText($value)
- {
- $this->setSelectedValue($value);
- }
-
- /**
- * Clears all existing selections.
- */
- public function clearSelection()
- {
- if($this->_items)
- {
- foreach($this->_items as $item)
- $item->setSelected(false);
- }
-
- if($this->getAdapter() instanceof IListControlAdapter)
- $this->getAdapter()->clearSelection();
- }
-
- /**
- * @return string the group of validators which the list control causes validation upon postback
- */
- public function getValidationGroup()
- {
- return $this->getViewState('ValidationGroup','');
- }
-
- /**
- * @param string the group of validators which the list control causes validation upon postback
- */
- public function setValidationGroup($value)
- {
- $this->setViewState('ValidationGroup',$value,'');
- }
-
- /**
- * @return string the prompt text which is to be displayed as the first list item.
- * @since 3.1.1
- */
- public function getPromptText()
- {
- return $this->getViewState('PromptText','');
- }
-
- /**
- * @param string the prompt text which is to be displayed as the first list item.
- * @since 3.1.1
- */
- public function setPromptText($value)
- {
- $this->setViewState('PromptText',$value,'');
- }
-
- /**
- * @return string the prompt selection value.
- * @see getPromptText
- * @since 3.1.1
- */
- public function getPromptValue()
- {
- return $this->getViewState('PromptValue','');
- }
-
- /**
- * @param string the prompt selection value. If empty, {@link getPromptText PromptText} will be used as the value.
- * @see setPromptText
- * @since 3.1.1
- */
- public function setPromptValue($value)
- {
- $this->setViewState('PromptValue',(string)$value,'');
- }
-
- /**
- * Raises OnSelectedIndexChanged event when selection is changed.
- * This method is invoked when the list control has its selection changed
- * by end-users.
- * @param TEventParameter event parameter
- */
- public function onSelectedIndexChanged($param)
- {
- $this->raiseEvent('OnSelectedIndexChanged',$this,$param);
- $this->onTextChanged($param);
- }
-
- /**
- * Raises OnTextChanged event when selection is changed.
- * This method is invoked when the list control has its selection changed
- * by end-users.
- * @param TEventParameter event parameter
- */
- public function onTextChanged($param)
- {
- $this->raiseEvent('OnTextChanged',$this,$param);
- }
-
- /**
- * Renders the prompt text, if any.
- * @param THtmlWriter writer
- * @since 3.1.1
- */
- protected function renderPrompt($writer)
- {
- $text=$this->getPromptText();
- $value=$this->getPromptValue();
- if($value==='')
- $value=$text;
- if($value!=='')
- {
- $writer->addAttribute('value',$value);
- $writer->renderBeginTag('option');
- $writer->write(THttpUtility::htmlEncode($text));
- $writer->renderEndTag();
- $writer->writeLine();
- }
- }
-
- /**
- * Renders body content of the list control.
- * This method renders items contained in the list control as the body content.
- * @param THtmlWriter writer
- */
- public function renderContents($writer)
- {
- $this->renderPrompt($writer);
-
- if($this->_items)
- {
- $writer->writeLine();
- $previousGroup=null;
- foreach($this->_items as $item)
- {
- if($item->getEnabled())
- {
- if($item->getHasAttributes())
- {
- $group=$item->getAttributes()->remove('Group');
- if($group!==$previousGroup)
- {
- if($previousGroup!==null)
- {
- $writer->renderEndTag();
- $writer->writeLine();
- $previousGroup=null;
- }
- if($group!==null)
- {
- $writer->addAttribute('label',$group);
- $writer->renderBeginTag('optgroup');
- $writer->writeLine();
- $previousGroup=$group;
- }
- }
- foreach($item->getAttributes() as $name=>$value)
- $writer->addAttribute($name,$value);
- }
- else if($previousGroup!==null)
- {
- $writer->renderEndTag();
- $writer->writeLine();
- $previousGroup=null;
- }
- if($item->getSelected())
- $writer->addAttribute('selected','selected');
- $writer->addAttribute('value',$item->getValue());
- $writer->renderBeginTag('option');
- $writer->write(THttpUtility::htmlEncode($item->getText()));
- $writer->renderEndTag();
- $writer->writeLine();
- }
- }
- if($previousGroup!==null)
- {
- $writer->renderEndTag();
- $writer->writeLine();
- }
- }
- }
-
- /**
- * Formats the text value according to a format string.
- * If the format string is empty, the original value is converted into
- * a string and returned.
- * If the format string starts with '#', the string is treated as a PHP expression
- * within which the token '{0}' is translated with the data value to be formated.
- * Otherwise, the format string and the data value are passed
- * as the first and second parameters in {@link sprintf}.
- * @param string format string
- * @param mixed the data to be formatted
- * @return string the formatted result
- */
- protected function formatDataValue($formatString,$value)
- {
- if($formatString==='')
- return TPropertyValue::ensureString($value);
- else if($formatString[0]==='#')
- {
- $expression=strtr(substr($formatString,1),array('{0}'=>'$value'));
- try
- {
- if(eval("\$result=$expression;")===false)
- throw new Exception('');
- return $result;
- }
- catch(Exception $e)
- {
- throw new TInvalidDataValueException('listcontrol_expression_invalid',get_class($this),$expression,$e->getMessage());
- }
- }
- else
- return sprintf($formatString,$value);
- }
-}
-
-/**
- * IListControlAdapter interface
- *
- * @author Wei Zhuo <weizhuo[at]gmail[dot]com>
- * @version $Revision: $ Sun Jun 25 04:53:43 EST 2006 $
- * @package System.Web.UI.ActiveControls
- * @since 3.0
- */
-interface IListControlAdapter
-{
- /**
- * Selects an item based on zero-base index on the client side.
- * @param integer the index (zero-based) of the item to be selected
- */
- public function setSelectedIndex($index);
- /**
- * Selects a list of item based on zero-base indices on the client side.
- * @param array list of index of items to be selected
- */
- public function setSelectedIndices($indices);
-
- /**
- * Sets selection by item value on the client side.
- * @param string the value of the item to be selected.
- */
- public function setSelectedValue($value);
-
- /**
- * Sets selection by a list of item values on the client side.
- * @param array list of the selected item values
- */
- public function setSelectedValues($values);
-
- /**
- * Clears all existing selections on the client side.
- */
- public function clearSelection();
-}
-
-
-?>
+<?php
+
+/**
+ * TListControl class file
+ *
+ * @author Robin J. Rogge <rojaro@gmail.com>
+ * @author Qiang Xue <qiang.xue@gmail.com>
+ * @link http://www.pradosoft.com/
+ * @copyright Copyright &copy; 2005-2012 PradoSoft
+ * @license http://www.pradosoft.com/license/
+ * @version $Id$
+ * @package System.Web.UI.WebControls
+ */
+
+/**
+ * Includes the supporting classes
+ */
+Prado::using('System.Web.UI.WebControls.TDataBoundControl');
+Prado::using('System.Web.UI.WebControls.TListItem');
+Prado::using('System.Collections.TListItemCollection');
+Prado::using('System.Collections.TAttributeCollection');
+Prado::using('System.Util.TDataFieldAccessor');
+
+/**
+ * TListControl class
+ *
+ * TListControl is a base class for list controls, such as {@link TListBox},
+ * {@link TDropDownList}, {@link TCheckBoxList}, etc.
+ * It manages the items and their status in a list control.
+ * It also implements how the items can be populated from template and
+ * data source.
+ *
+ * The property {@link getItems} returns a list of the items in the control.
+ * To specify or determine which item is selected, use the
+ * {@link getSelectedIndex SelectedIndex} property that indicates the zero-based
+ * index of the selected item in the item list. You may also use
+ * {@link getSelectedItem SelectedItem} and {@link getSelectedValue SelectedValue}
+ * to get the selected item and its value. For multiple selection lists
+ * (such as {@link TCheckBoxList} and {@link TListBox}), property
+ * {@link getSelectedIndices SelectedIndices} is useful.
+ *
+ * TListControl implements {@link setAutoPostBack AutoPostBack} which allows
+ * a list control to postback the page if the selections of the list items are changed.
+ * The {@link setCausesValidation CausesValidation} and {@link setValidationGroup ValidationGroup}
+ * properties may be used to specify that validation be performed when auto postback occurs.
+ *
+ * There are three ways to populate the items in a list control: from template,
+ * using {@link setDataSource DataSource} and using {@link setDataSourceID DataSourceID}.
+ * The latter two are covered in {@link TDataBoundControl}. To specify items via
+ * template, using the following template syntax:
+ * <code>
+ * <com:TListControl>
+ * <com:TListItem Value="xxx" Text="yyy" >
+ * <com:TListItem Value="xxx" Text="yyy" Selected="true" >
+ * <com:TListItem Value="xxx" Text="yyy" >
+ * </com:TListControl>
+ * </code>
+ *
+ * When {@link setDataSource DataSource} or {@link setDataSourceID DataSourceID}
+ * is used to populate list items, the {@link setDataTextField DataTextField} and
+ * {@link setDataValueField DataValueField} properties are used to specify which
+ * columns of the data will be used to populate the text and value of the items.
+ * For example, if a data source is as follows,
+ * <code>
+ * $dataSource=array(
+ * array('name'=>'John', 'age'=>31),
+ * array('name'=>'Cary', 'age'=>28),
+ * array('name'=>'Rose', 'age'=>35),
+ * );
+ * </code>
+ * setting {@link setDataTextField DataTextField} and {@link setDataValueField DataValueField}
+ * to 'name' and 'age' will make the first item's text be 'John', value be 31,
+ * the second item's text be 'Cary', value be 28, and so on.
+ * The {@link setDataTextFormatString DataTextFormatString} property may be further
+ * used to format how the item should be displayed. See {@link formatDataValue()}
+ * for an explanation of the format string.
+ *
+ * @author Qiang Xue <qiang.xue@gmail.com>
+ * @version $Id$
+ * @package System.Web.UI.WebControls
+ * @since 3.0
+ */
+abstract class TListControl extends TDataBoundControl implements IDataRenderer
+{
+ /**
+ * @var TListItemCollection item list
+ */
+ private $_items=null;
+ /**
+ * @var boolean whether items are restored from viewstate
+ */
+ private $_stateLoaded=false;
+ /**
+ * @var mixed the following selection variables are used
+ * to keep selections when Items are not available
+ */
+ private $_cachedSelectedIndex=-1;
+ private $_cachedSelectedValue=null;
+ private $_cachedSelectedIndices=null;
+ private $_cachedSelectedValues=null;
+
+ /**
+ * @return string tag name of the list control
+ */
+ protected function getTagName()
+ {
+ return 'select';
+ }
+
+ /**
+ * @return boolean whether to render javascript.
+ */
+ public function getEnableClientScript()
+ {
+ return $this->getViewState('EnableClientScript',true);
+ }
+
+ /**
+ * @param boolean whether to render javascript.
+ */
+ public function setEnableClientScript($value)
+ {
+ $this->setViewState('EnableClientScript',TPropertyValue::ensureBoolean($value),true);
+ }
+
+ /**
+ * Adds attributes to renderer.
+ * @param THtmlWriter the renderer
+ */
+ protected function addAttributesToRender($writer)
+ {
+ $page=$this->getPage();
+ $page->ensureRenderInForm($this);
+ if($this->getIsMultiSelect())
+ $writer->addAttribute('multiple','multiple');
+ if($this->getEnabled(true))
+ {
+ if($this->getAutoPostBack()
+ && $this->getEnableClientScript()
+ && $page->getClientSupportsJavaScript())
+ {
+ $this->renderClientControlScript($writer);
+ }
+ }
+ else if($this->getEnabled())
+ $writer->addAttribute('disabled','disabled');
+ parent::addAttributesToRender($writer);
+ }
+
+ /**
+ * Renders the javascript for list control.
+ */
+ protected function renderClientControlScript($writer)
+ {
+ $writer->addAttribute('id',$this->getClientID());
+ $this->getPage()->getClientScript()->registerPostBackControl($this->getClientClassName(),$this->getPostBackOptions());
+ }
+
+ /**
+ * Gets the name of the javascript class responsible for performing postback for this control.
+ * Derived classes may override this method and return customized js class names.
+ * @return string the javascript class name
+ */
+ protected function getClientClassName()
+ {
+ return 'Prado.WebUI.TListControl';
+ }
+
+ /**
+ * @return array postback options for JS postback code
+ */
+ protected function getPostBackOptions()
+ {
+ $options['ID'] = $this->getClientID();
+ $options['CausesValidation'] = $this->getCausesValidation();
+ $options['ValidationGroup'] = $this->getValidationGroup();
+ $options['EventTarget'] = $this->getUniqueID();
+ return $options;
+ }
+
+ /**
+ * Adds object parsed from template to the control.
+ * This method adds only {@link TListItem} objects into the {@link getItems Items} collection.
+ * All other objects are ignored.
+ * @param mixed object parsed from template
+ */
+ public function addParsedObject($object)
+ {
+ // Do not add items from template if items are loaded from viewstate
+ if(!$this->_stateLoaded && ($object instanceof TListItem))
+ {
+ $index=$this->getItems()->add($object);
+ if(($this->_cachedSelectedValue!==null && $this->_cachedSelectedValue===$object->getValue()) || ($this->_cachedSelectedIndex===$index))
+ {
+ $object->setSelected(true);
+ $this->_cachedSelectedValue=null;
+ $this->_cachedSelectedIndex=-1;
+ }
+ }
+ }
+
+ /**
+ * Performs databinding to populate list items from data source.
+ * This method is invoked by dataBind().
+ * You may override this function to provide your own way of data population.
+ * @param Traversable the data
+ */
+ protected function performDataBinding($data)
+ {
+ $items=$this->getItems();
+ if(!$this->getAppendDataBoundItems())
+ $items->clear();
+ $textField=$this->getDataTextField();
+ if($textField==='')
+ $textField=0;
+ $valueField=$this->getDataValueField();
+ if($valueField==='')
+ $valueField=1;
+ $textFormat=$this->getDataTextFormatString();
+ $groupField=$this->getDataGroupField();
+ foreach($data as $key=>$object)
+ {
+ $item=$items->createListItem();
+ if(is_array($object) || is_object($object))
+ {
+ $text=TDataFieldAccessor::getDataFieldValue($object,$textField);
+ $value=TDataFieldAccessor::getDataFieldValue($object,$valueField);
+ $item->setValue($value);
+ if($groupField!=='')
+ $item->setAttribute('Group',TDataFieldAccessor::getDataFieldValue($object,$groupField));
+ }
+ else
+ {
+ $text=$object;
+ $item->setValue("$key");
+ }
+ $item->setText($this->formatDataValue($textFormat,$text));
+ }
+ // SelectedValue or SelectedIndex may be set before databinding
+ // so we make them be effective now
+ if($this->_cachedSelectedValue!==null)
+ {
+ $this->setSelectedValue($this->_cachedSelectedValue);
+ $this->resetCachedSelections();
+ }
+ else if($this->_cachedSelectedIndex!==-1)
+ {
+ $this->setSelectedIndex($this->_cachedSelectedIndex);
+ $this->resetCachedSelections();
+ }
+ else if($this->_cachedSelectedValues!==null)
+ {
+ $this->setSelectedValues($this->_cachedSelectedValues);
+ $this->resetCachedSelections();
+ }
+ else if($this->_cachedSelectedIndices!==null)
+ {
+ $this->setSelectedIndices($this->_cachedSelectedIndices);
+ $this->resetCachedSelections();
+ }
+ }
+
+ private function resetCachedSelections()
+ {
+ $this->_cachedSelectedValue=null;
+ $this->_cachedSelectedIndex=-1;
+ $this->_cachedSelectedValues=null;
+ $this->_cachedSelectedIndices=null;
+ }
+
+ /**
+ * Creates a collection object to hold list items.
+ * This method may be overriden to create a customized collection.
+ * @return TListItemCollection the collection object
+ */
+ protected function createListItemCollection()
+ {
+ return new TListItemCollection;
+ }
+
+ /**
+ * Saves items into viewstate.
+ * This method is invoked right before control state is to be saved.
+ */
+ public function saveState()
+ {
+ parent::saveState();
+ if($this->_items)
+ $this->setViewState('Items',$this->_items->saveState(),null);
+ else
+ $this->clearViewState('Items');
+ }
+
+ /**
+ * Loads items from viewstate.
+ * This method is invoked right after control state is loaded.
+ */
+ public function loadState()
+ {
+ parent::loadState();
+ $this->_stateLoaded=true;
+ if(!$this->getIsDataBound())
+ {
+ $this->_items=$this->createListItemCollection();
+ $this->_items->loadState($this->getViewState('Items',null));
+ }
+ $this->clearViewState('Items');
+ }
+
+ /**
+ * @return boolean whether this is a multiselect control. Defaults to false.
+ */
+ protected function getIsMultiSelect()
+ {
+ return false;
+ }
+
+ /**
+ * @return boolean whether performing databind should append items or clear the existing ones. Defaults to false.
+ */
+ public function getAppendDataBoundItems()
+ {
+ return $this->getViewState('AppendDataBoundItems',false);
+ }
+
+ /**
+ * @param boolean whether performing databind should append items or clear the existing ones.
+ */
+ public function setAppendDataBoundItems($value)
+ {
+ $this->setViewState('AppendDataBoundItems',TPropertyValue::ensureBoolean($value),false);
+ }
+
+ /**
+ * @return boolean a value indicating whether an automatic postback to the server
+ * will occur whenever the user makes change to the list control and then tabs out of it.
+ * Defaults to false.
+ */
+ public function getAutoPostBack()
+ {
+ return $this->getViewState('AutoPostBack',false);
+ }
+
+ /**
+ * Sets the value indicating if postback automatically.
+ * An automatic postback to the server will occur whenever the user
+ * makes change to the list control and then tabs out of it.
+ * @param boolean the value indicating if postback automatically
+ */
+ public function setAutoPostBack($value)
+ {
+ $this->setViewState('AutoPostBack',TPropertyValue::ensureBoolean($value),false);
+ }
+
+ /**
+ * @return boolean whether postback event trigger by this list control will cause input validation, default is true.
+ */
+ public function getCausesValidation()
+ {
+ return $this->getViewState('CausesValidation',true);
+ }
+
+ /**
+ * @param boolean whether postback event trigger by this list control will cause input validation.
+ */
+ public function setCausesValidation($value)
+ {
+ $this->setViewState('CausesValidation',TPropertyValue::ensureBoolean($value),true);
+ }
+
+ /**
+ * @return string the field of the data source that provides the text content of the list items.
+ */
+ public function getDataTextField()
+ {
+ return $this->getViewState('DataTextField','');
+ }
+
+ /**
+ * @param string the field of the data source that provides the text content of the list items.
+ */
+ public function setDataTextField($value)
+ {
+ $this->setViewState('DataTextField',$value,'');
+ }
+
+ /**
+ * @return string the formatting string used to control how data bound to the list control is displayed.
+ */
+ public function getDataTextFormatString()
+ {
+ return $this->getViewState('DataTextFormatString','');
+ }
+
+ /**
+ * Sets data text format string.
+ * The format string is used in {@link TDataValueFormatter::format()} to format the Text property value
+ * of each item in the list control.
+ * @param string the formatting string used to control how data bound to the list control is displayed.
+ * @see TDataValueFormatter::format()
+ */
+ public function setDataTextFormatString($value)
+ {
+ $this->setViewState('DataTextFormatString',$value,'');
+ }
+
+ /**
+ * @return string the field of the data source that provides the value of each list item.
+ */
+ public function getDataValueField()
+ {
+ return $this->getViewState('DataValueField','');
+ }
+
+ /**
+ * @param string the field of the data source that provides the value of each list item.
+ */
+ public function setDataValueField($value)
+ {
+ $this->setViewState('DataValueField',$value,'');
+ }
+
+ /**
+ * @return string the field of the data source that provides the label of the list item groups
+ */
+ public function getDataGroupField()
+ {
+ return $this->getViewState('DataGroupField','');
+ }
+
+ /**
+ * @param string the field of the data source that provides the label of the list item groups
+ */
+ public function setDataGroupField($value)
+ {
+ $this->setViewState('DataGroupField',$value,'');
+ }
+
+ /**
+ * @return integer the number of items in the list control
+ */
+ public function getItemCount()
+ {
+ return $this->_items?$this->_items->getCount():0;
+ }
+
+ /**
+ * @return boolean whether the list control contains any items.
+ */
+ public function getHasItems()
+ {
+ return ($this->_items && $this->_items->getCount()>0);
+ }
+
+ /**
+ * @return TListItemCollection the item collection
+ */
+ public function getItems()
+ {
+ if(!$this->_items)
+ $this->_items=$this->createListItemCollection();
+ return $this->_items;
+ }
+
+ /**
+ * @return integer the index (zero-based) of the item being selected, -1 if no item is selected.
+ */
+ public function getSelectedIndex()
+ {
+ if($this->_items)
+ {
+ $n=$this->_items->getCount();
+ for($i=0;$i<$n;++$i)
+ if($this->_items->itemAt($i)->getSelected())
+ return $i;
+ }
+ return -1;
+ }
+
+ /**
+ * @param integer the index (zero-based) of the item to be selected
+ */
+ public function setSelectedIndex($index)
+ {
+ if(($index=TPropertyValue::ensureInteger($index))<0)
+ $index=-1;
+ if($this->_items)
+ {
+ $this->clearSelection();
+ if($index>=0 && $index<$this->_items->getCount())
+ $this->_items->itemAt($index)->setSelected(true);
+ }
+ $this->_cachedSelectedIndex=$index;
+ if($this->getAdapter() instanceof IListControlAdapter)
+ $this->getAdapter()->setSelectedIndex($index);
+ }
+
+ /**
+ * @return array list of index of items that are selected
+ */
+ public function getSelectedIndices()
+ {
+ $selections=array();
+ if($this->_items)
+ {
+ $n=$this->_items->getCount();
+ for($i=0;$i<$n;++$i)
+ if($this->_items->itemAt($i)->getSelected())
+ $selections[]=$i;
+ }
+ return $selections;
+ }
+
+ /**
+ * @param array list of index of items to be selected
+ */
+ public function setSelectedIndices($indices)
+ {
+ if($this->getIsMultiSelect())
+ {
+ if($this->_items)
+ {
+ $this->clearSelection();
+ $n=$this->_items->getCount();
+ foreach($indices as $index)
+ {
+ if($index>=0 && $index<$n)
+ $this->_items->itemAt($index)->setSelected(true);
+ }
+ }
+ $this->_cachedSelectedIndices=$indices;
+ }
+ else
+ throw new TNotSupportedException('listcontrol_multiselect_unsupported',get_class($this));
+
+ if($this->getAdapter() instanceof IListControlAdapter)
+ $this->getAdapter()->setSelectedIndices($indices);
+ }
+
+ /**
+ * @return TListItem|null the selected item with the lowest cardinal index, null if no item is selected.
+ */
+ public function getSelectedItem()
+ {
+ if(($index=$this->getSelectedIndex())>=0)
+ return $this->_items->itemAt($index);
+ else
+ return null;
+ }
+
+ /**
+ * Returns the value of the selected item with the lowest cardinal index.
+ * This method is required by {@link IDataRenderer}.
+ * It is the same as {@link getSelectedValue()}.
+ * @return string the value of the selected item with the lowest cardinal index, empty if no selection.
+ * @see getSelectedValue
+ * @since 3.1.0
+ */
+ public function getData()
+ {
+ return $this->getSelectedValue();
+ }
+
+ /**
+ * Selects an item by the specified value.
+ * This method is required by {@link IDataRenderer}.
+ * It is the same as {@link setSelectedValue()}.
+ * @param string the value of the item to be selected.
+ * @see setSelectedValue
+ * @since 3.1.0
+ */
+ public function setData($value)
+ {
+ $this->setSelectedValue($value);
+ }
+
+ /**
+ * @return string the value of the selected item with the lowest cardinal index, empty if no selection
+ */
+ public function getSelectedValue()
+ {
+ $index=$this->getSelectedIndex();
+ return $index>=0?$this->getItems()->itemAt($index)->getValue():'';
+ }
+
+ /**
+ * Sets selection by item value.
+ * Existing selections will be cleared if the item value is found in the item collection.
+ * Note, if the value is null, existing selections will also be cleared.
+ * @param string the value of the item to be selected.
+ */
+ public function setSelectedValue($value)
+ {
+ if($this->_items)
+ {
+ if($value===null)
+ $this->clearSelection();
+ else if(($item=$this->_items->findItemByValue($value))!==null)
+ {
+ $this->clearSelection();
+ $item->setSelected(true);
+ }
+ else
+ $this->clearSelection();
+ }
+ $this->_cachedSelectedValue=$value;
+ if($this->getAdapter() instanceof IListControlAdapter)
+ $this->getAdapter()->setSelectedValue($value);
+ }
+
+
+ /**
+ * @return array list of the selected item values (strings)
+ */
+ public function getSelectedValues()
+ {
+ $values=array();
+ if($this->_items)
+ {
+ foreach($this->_items as $item)
+ {
+ if($item->getSelected())
+ $values[]=$item->getValue();
+ }
+ }
+ return $values;
+ }
+
+ /**
+ * @param array list of the selected item values
+ */
+ public function setSelectedValues($values)
+ {
+ if($this->getIsMultiSelect())
+ {
+ if($this->_items)
+ {
+ $this->clearSelection();
+ $lookup=array();
+ foreach($this->_items as $item)
+ $lookup[$item->getValue()]=$item;
+ foreach($values as $value)
+ {
+ if(isset($lookup["$value"]))
+ $lookup["$value"]->setSelected(true);
+ }
+ }
+ $this->_cachedSelectedValues=$values;
+ }
+ else
+ throw new TNotSupportedException('listcontrol_multiselect_unsupported',get_class($this));
+
+ if($this->getAdapter() instanceof IListControlAdapter)
+ $this->getAdapter()->setSelectedValues($values);
+ }
+
+ /**
+ * @return string selected value
+ */
+ public function getText()
+ {
+ return $this->getSelectedValue();
+ }
+
+ /**
+ * @param string value to be selected
+ */
+ public function setText($value)
+ {
+ $this->setSelectedValue($value);
+ }
+
+ /**
+ * Clears all existing selections.
+ */
+ public function clearSelection()
+ {
+ if($this->_items)
+ {
+ foreach($this->_items as $item)
+ $item->setSelected(false);
+ }
+
+ if($this->getAdapter() instanceof IListControlAdapter)
+ $this->getAdapter()->clearSelection();
+ }
+
+ /**
+ * @return string the group of validators which the list control causes validation upon postback
+ */
+ public function getValidationGroup()
+ {
+ return $this->getViewState('ValidationGroup','');
+ }
+
+ /**
+ * @param string the group of validators which the list control causes validation upon postback
+ */
+ public function setValidationGroup($value)
+ {
+ $this->setViewState('ValidationGroup',$value,'');
+ }
+
+ /**
+ * @return string the prompt text which is to be displayed as the first list item.
+ * @since 3.1.1
+ */
+ public function getPromptText()
+ {
+ return $this->getViewState('PromptText','');
+ }
+
+ /**
+ * @param string the prompt text which is to be displayed as the first list item.
+ * @since 3.1.1
+ */
+ public function setPromptText($value)
+ {
+ $this->setViewState('PromptText',$value,'');
+ }
+
+ /**
+ * @return string the prompt selection value.
+ * @see getPromptText
+ * @since 3.1.1
+ */
+ public function getPromptValue()
+ {
+ return $this->getViewState('PromptValue','');
+ }
+
+ /**
+ * @param string the prompt selection value. If empty, {@link getPromptText PromptText} will be used as the value.
+ * @see setPromptText
+ * @since 3.1.1
+ */
+ public function setPromptValue($value)
+ {
+ $this->setViewState('PromptValue',(string)$value,'');
+ }
+
+ /**
+ * Raises OnSelectedIndexChanged event when selection is changed.
+ * This method is invoked when the list control has its selection changed
+ * by end-users.
+ * @param TEventParameter event parameter
+ */
+ public function onSelectedIndexChanged($param)
+ {
+ $this->raiseEvent('OnSelectedIndexChanged',$this,$param);
+ $this->onTextChanged($param);
+ }
+
+ /**
+ * Raises OnTextChanged event when selection is changed.
+ * This method is invoked when the list control has its selection changed
+ * by end-users.
+ * @param TEventParameter event parameter
+ */
+ public function onTextChanged($param)
+ {
+ $this->raiseEvent('OnTextChanged',$this,$param);
+ }
+
+ /**
+ * Renders the prompt text, if any.
+ * @param THtmlWriter writer
+ * @since 3.1.1
+ */
+ protected function renderPrompt($writer)
+ {
+ $text=$this->getPromptText();
+ $value=$this->getPromptValue();
+ if($value==='')
+ $value=$text;
+ if($value!=='')
+ {
+ $writer->addAttribute('value',$value);
+ $writer->renderBeginTag('option');
+ $writer->write(THttpUtility::htmlEncode($text));
+ $writer->renderEndTag();
+ $writer->writeLine();
+ }
+ }
+
+ /**
+ * Renders body content of the list control.
+ * This method renders items contained in the list control as the body content.
+ * @param THtmlWriter writer
+ */
+ public function renderContents($writer)
+ {
+ $this->renderPrompt($writer);
+
+ if($this->_items)
+ {
+ $writer->writeLine();
+ $previousGroup=null;
+ foreach($this->_items as $item)
+ {
+ if($item->getEnabled())
+ {
+ if($item->getHasAttributes())
+ {
+ $group=$item->getAttributes()->remove('Group');
+ if($group!==$previousGroup)
+ {
+ if($previousGroup!==null)
+ {
+ $writer->renderEndTag();
+ $writer->writeLine();
+ $previousGroup=null;
+ }
+ if($group!==null)
+ {
+ $writer->addAttribute('label',$group);
+ $writer->renderBeginTag('optgroup');
+ $writer->writeLine();
+ $previousGroup=$group;
+ }
+ }
+ foreach($item->getAttributes() as $name=>$value)
+ $writer->addAttribute($name,$value);
+ }
+ else if($previousGroup!==null)
+ {
+ $writer->renderEndTag();
+ $writer->writeLine();
+ $previousGroup=null;
+ }
+ if($item->getSelected())
+ $writer->addAttribute('selected','selected');
+ $writer->addAttribute('value',$item->getValue());
+ $writer->renderBeginTag('option');
+ $writer->write(THttpUtility::htmlEncode($item->getText()));
+ $writer->renderEndTag();
+ $writer->writeLine();
+ }
+ }
+ if($previousGroup!==null)
+ {
+ $writer->renderEndTag();
+ $writer->writeLine();
+ }
+ }
+ }
+
+ /**
+ * Formats the text value according to a format string.
+ * If the format string is empty, the original value is converted into
+ * a string and returned.
+ * If the format string starts with '#', the string is treated as a PHP expression
+ * within which the token '{0}' is translated with the data value to be formated.
+ * Otherwise, the format string and the data value are passed
+ * as the first and second parameters in {@link sprintf}.
+ * @param string format string
+ * @param mixed the data to be formatted
+ * @return string the formatted result
+ */
+ protected function formatDataValue($formatString,$value)
+ {
+ if($formatString==='')
+ return TPropertyValue::ensureString($value);
+ else if($formatString[0]==='#')
+ {
+ $expression=strtr(substr($formatString,1),array('{0}'=>'$value'));
+ try
+ {
+ if(eval("\$result=$expression;")===false)
+ throw new Exception('');
+ return $result;
+ }
+ catch(Exception $e)
+ {
+ throw new TInvalidDataValueException('listcontrol_expression_invalid',get_class($this),$expression,$e->getMessage());
+ }
+ }
+ else
+ return sprintf($formatString,$value);
+ }
+}
+
+/**
+ * IListControlAdapter interface
+ *
+ * @author Wei Zhuo <weizhuo[at]gmail[dot]com>
+ * @version $Revision: $ Sun Jun 25 04:53:43 EST 2006 $
+ * @package System.Web.UI.ActiveControls
+ * @since 3.0
+ */
+interface IListControlAdapter
+{
+ /**
+ * Selects an item based on zero-base index on the client side.
+ * @param integer the index (zero-based) of the item to be selected
+ */
+ public function setSelectedIndex($index);
+ /**
+ * Selects a list of item based on zero-base indices on the client side.
+ * @param array list of index of items to be selected
+ */
+ public function setSelectedIndices($indices);
+
+ /**
+ * Sets selection by item value on the client side.
+ * @param string the value of the item to be selected.
+ */
+ public function setSelectedValue($value);
+
+ /**
+ * Sets selection by a list of item values on the client side.
+ * @param array list of the selected item values
+ */
+ public function setSelectedValues($values);
+
+ /**
+ * Clears all existing selections on the client side.
+ */
+ public function clearSelection();
+}
+
+
+?>
diff --git a/framework/Web/UI/WebControls/TListControlValidator.php b/framework/Web/UI/WebControls/TListControlValidator.php
index a5be67b3..75a0510c 100644
--- a/framework/Web/UI/WebControls/TListControlValidator.php
+++ b/framework/Web/UI/WebControls/TListControlValidator.php
@@ -1,225 +1,225 @@
-<?php
-/**
- * TListControlValidator class file
- *
- * @author Wei Zhuo <weizhuo[at]gmail[dot]com>
- * @link http://www.pradosoft.com/
+<?php
+/**
+ * TListControlValidator class file
+ *
+ * @author Wei Zhuo <weizhuo[at]gmail[dot]com>
+ * @link http://www.pradosoft.com/
* @copyright Copyright &copy; 2005-2012 PradoSoft
- * @license http://www.pradosoft.com/license/
- * @version $Id$
- * @package System.Web.UI.WebControls
- */
-
-/**
- * Using TBaseValidator class
- */
-Prado::using('System.Web.UI.WebControls.TBaseValidator');
-
-/**
- * TListControlValidator class.
- *
- * TListControlValidator checks the number of selection and their values
- * for a <b>TListControl that allows multiple selection</b>.
- *
- * You can specify the minimum or maximum (or both) number of selections
- * required using the {@link setMinSelection MinSelection} and
- * {@link setMaxSelection MaxSelection} properties, respectively. In addition,
- * you can specify a comma separated list of required selected values via the
- * {@link setRequiredSelections RequiredSelections} property.
- *
- * Examples
- * - At least two selections
- * <code>
- * <com:TListBox ID="listbox" SelectionMode="Multiple">
- * <com:TListItem Text="item1" Value="value1" />
- * <com:TListItem Text="item2" Value="value2" />
- * <com:TListItem Text="item3" Value="value3" />
- * </com:TListBox>
- *
- * <com:TListControlValidator
- * ControlToValidate="listbox"
- * MinSelection="2"
- * ErrorMessage="Please select at least 2" />
- * </code>
- * - "value1" must be selected <b>and</b> at least 1 other
- * <code>
- * <com:TCheckBoxList ID="checkboxes">
- * <com:TListItem Text="item1" Value="value1" />
- * <com:TListItem Text="item2" Value="value2" />
- * <com:TListItem Text="item3" Value="value3" />
- * </com:TCheckBoxList>
- *
- * <com:TListControlValidator
- * ControlToValidate="checkboxes"
- * RequiredSelections="value1"
- * MinSelection="2"
- * ErrorMessage="Please select 'item1' and at least 1 other" />
- * </code>
- *
- * @author Xiang Wei Zhuo <weizhuo[at]gmail.com>
- * @version $Id$
- * @package System.Web.UI.WebControls
- * @since 3.0
- */
-class TListControlValidator extends TBaseValidator
-{
- /**
- * Gets the name of the javascript class responsible for performing validation for this control.
- * This method overrides the parent implementation.
- * @return string the javascript class name
- */
- protected function getClientClassName()
- {
- return 'Prado.WebUI.TListControlValidator';
- }
-
- /**
- * @return integer min number of selections. Defaults to -1, meaning not set.
- */
- public function getMinSelection()
- {
- return $this->getViewState('MinSelection',-1);
- }
-
- /**
- * @param integer minimum number of selections.
- */
- public function setMinSelection($value)
- {
- if(($value=TPropertyValue::ensureInteger($value))<0)
- $value=-1;
- $this->setViewState('MinSelection',$value,-1);
- }
-
- /**
- * @return integer max number of selections. Defaults to -1, meaning not set.
- */
- public function getMaxSelection()
- {
- return $this->getViewState('MaxSelection',-1);
- }
-
- /**
- * @param integer max number of selections.
- */
- public function setMaxSelection($value)
- {
- if(($value=TPropertyValue::ensureInteger($value))<0)
- $value=-1;
- $this->setViewState('MaxSelection',$value,-1);
- }
-
- /**
- * Get a comma separated list of required selected values.
- * @return string comma separated list of required values.
- */
- public function getRequiredSelections()
- {
- return $this->getViewState('RequiredSelections','');
- }
-
- /**
- * Set the list of required values, using aa comma separated list.
- * @param string comma separated list of required values.
- */
- public function setRequiredSelections($value)
- {
- $this->setViewState('RequiredSelections',$value,'');
- }
-
- /**
- * This method overrides the parent's implementation.
- * The validation succeeds if the input component changes its data
- * from the InitialValue or the input component is not given.
- * @return boolean whether the validation succeeds
- */
- protected function evaluateIsValid()
- {
- $control=$this->getValidationTarget();
-
- $exists = true;
- $values = $this->getSelection($control);
- $count = count($values);
- $required = $this->getRequiredValues();
-
- //if required, check the values
- if(!empty($required))
- {
- if($count < count($required) )
- return false;
- foreach($required as $require)
- $exists = $exists && in_array($require, $values);
- }
-
- $min = $this->getMinSelection();
- $max = $this->getMaxSelection();
-
- if($min !== -1 && $max !== -1)
- return $exists && $count >= $min && $count <= $max;
- else if($min === -1 && $max !== -1)
- return $exists && $count <= $max;
- else if($min !== -1 && $max === -1)
- return $exists && $count >= $min;
- else
- return $exists;
- }
-
- /**
- * @param TListControl control to validate
- * @return array number of selected values and its values.
- */
- protected function getSelection($control)
- {
- $values = array();
-
- //get the data
- foreach($control->getItems() as $item)
- {
- if($item->getSelected())
- $values[] = $item->getValue();
- }
- return $values;
- }
-
- /**
- * @return array list of required values.
- */
- protected function getRequiredValues()
- {
- $required = array();
- $string = $this->getRequiredSelections();
- if(!empty($string))
- $required = preg_split('/,\s*/', $string);
- return $required;
- }
-
- /**
- * Returns an array of javascript validator options.
- * @return array javascript validator options.
- */
- protected function getClientScriptOptions()
- {
- $options = parent::getClientScriptOptions();
- $control = $this->getValidationTarget();
-
- if(!$control instanceof TListControl)
- {
- throw new TConfigurationException(
- 'listcontrolvalidator_invalid_control',
- $this->getID(),$this->getControlToValidate(), get_class($control));
- }
-
- $min = $this->getMinSelection();
- $max = $this->getMaxSelection();
- if($min !== -1)
- $options['Min']= $min;
- if($max !== -1)
- $options['Max']= $max;
- $required = $this->getRequiredSelections();
- if(strlen($required) > 0)
- $options['Required']= $required;
- $options['TotalItems'] = $control->getItemCount();
-
- return $options;
- }
-}
+ * @license http://www.pradosoft.com/license/
+ * @version $Id$
+ * @package System.Web.UI.WebControls
+ */
+
+/**
+ * Using TBaseValidator class
+ */
+Prado::using('System.Web.UI.WebControls.TBaseValidator');
+
+/**
+ * TListControlValidator class.
+ *
+ * TListControlValidator checks the number of selection and their values
+ * for a <b>TListControl that allows multiple selection</b>.
+ *
+ * You can specify the minimum or maximum (or both) number of selections
+ * required using the {@link setMinSelection MinSelection} and
+ * {@link setMaxSelection MaxSelection} properties, respectively. In addition,
+ * you can specify a comma separated list of required selected values via the
+ * {@link setRequiredSelections RequiredSelections} property.
+ *
+ * Examples
+ * - At least two selections
+ * <code>
+ * <com:TListBox ID="listbox" SelectionMode="Multiple">
+ * <com:TListItem Text="item1" Value="value1" />
+ * <com:TListItem Text="item2" Value="value2" />
+ * <com:TListItem Text="item3" Value="value3" />
+ * </com:TListBox>
+ *
+ * <com:TListControlValidator
+ * ControlToValidate="listbox"
+ * MinSelection="2"
+ * ErrorMessage="Please select at least 2" />
+ * </code>
+ * - "value1" must be selected <b>and</b> at least 1 other
+ * <code>
+ * <com:TCheckBoxList ID="checkboxes">
+ * <com:TListItem Text="item1" Value="value1" />
+ * <com:TListItem Text="item2" Value="value2" />
+ * <com:TListItem Text="item3" Value="value3" />
+ * </com:TCheckBoxList>
+ *
+ * <com:TListControlValidator
+ * ControlToValidate="checkboxes"
+ * RequiredSelections="value1"
+ * MinSelection="2"
+ * ErrorMessage="Please select 'item1' and at least 1 other" />
+ * </code>
+ *
+ * @author Xiang Wei Zhuo <weizhuo[at]gmail.com>
+ * @version $Id$
+ * @package System.Web.UI.WebControls
+ * @since 3.0
+ */
+class TListControlValidator extends TBaseValidator
+{
+ /**
+ * Gets the name of the javascript class responsible for performing validation for this control.
+ * This method overrides the parent implementation.
+ * @return string the javascript class name
+ */
+ protected function getClientClassName()
+ {
+ return 'Prado.WebUI.TListControlValidator';
+ }
+
+ /**
+ * @return integer min number of selections. Defaults to -1, meaning not set.
+ */
+ public function getMinSelection()
+ {
+ return $this->getViewState('MinSelection',-1);
+ }
+
+ /**
+ * @param integer minimum number of selections.
+ */
+ public function setMinSelection($value)
+ {
+ if(($value=TPropertyValue::ensureInteger($value))<0)
+ $value=-1;
+ $this->setViewState('MinSelection',$value,-1);
+ }
+
+ /**
+ * @return integer max number of selections. Defaults to -1, meaning not set.
+ */
+ public function getMaxSelection()
+ {
+ return $this->getViewState('MaxSelection',-1);
+ }
+
+ /**
+ * @param integer max number of selections.
+ */
+ public function setMaxSelection($value)
+ {
+ if(($value=TPropertyValue::ensureInteger($value))<0)
+ $value=-1;
+ $this->setViewState('MaxSelection',$value,-1);
+ }
+
+ /**
+ * Get a comma separated list of required selected values.
+ * @return string comma separated list of required values.
+ */
+ public function getRequiredSelections()
+ {
+ return $this->getViewState('RequiredSelections','');
+ }
+
+ /**
+ * Set the list of required values, using aa comma separated list.
+ * @param string comma separated list of required values.
+ */
+ public function setRequiredSelections($value)
+ {
+ $this->setViewState('RequiredSelections',$value,'');
+ }
+
+ /**
+ * This method overrides the parent's implementation.
+ * The validation succeeds if the input component changes its data
+ * from the InitialValue or the input component is not given.
+ * @return boolean whether the validation succeeds
+ */
+ protected function evaluateIsValid()
+ {
+ $control=$this->getValidationTarget();
+
+ $exists = true;
+ $values = $this->getSelection($control);
+ $count = count($values);
+ $required = $this->getRequiredValues();
+
+ //if required, check the values
+ if(!empty($required))
+ {
+ if($count < count($required) )
+ return false;
+ foreach($required as $require)
+ $exists = $exists && in_array($require, $values);
+ }
+
+ $min = $this->getMinSelection();
+ $max = $this->getMaxSelection();
+
+ if($min !== -1 && $max !== -1)
+ return $exists && $count >= $min && $count <= $max;
+ else if($min === -1 && $max !== -1)
+ return $exists && $count <= $max;
+ else if($min !== -1 && $max === -1)
+ return $exists && $count >= $min;
+ else
+ return $exists;
+ }
+
+ /**
+ * @param TListControl control to validate
+ * @return array number of selected values and its values.
+ */
+ protected function getSelection($control)
+ {
+ $values = array();
+
+ //get the data
+ foreach($control->getItems() as $item)
+ {
+ if($item->getSelected())
+ $values[] = $item->getValue();
+ }
+ return $values;
+ }
+
+ /**
+ * @return array list of required values.
+ */
+ protected function getRequiredValues()
+ {
+ $required = array();
+ $string = $this->getRequiredSelections();
+ if(!empty($string))
+ $required = preg_split('/,\s*/', $string);
+ return $required;
+ }
+
+ /**
+ * Returns an array of javascript validator options.
+ * @return array javascript validator options.
+ */
+ protected function getClientScriptOptions()
+ {
+ $options = parent::getClientScriptOptions();
+ $control = $this->getValidationTarget();
+
+ if(!$control instanceof TListControl)
+ {
+ throw new TConfigurationException(
+ 'listcontrolvalidator_invalid_control',
+ $this->getID(),$this->getControlToValidate(), get_class($control));
+ }
+
+ $min = $this->getMinSelection();
+ $max = $this->getMaxSelection();
+ if($min !== -1)
+ $options['Min']= $min;
+ if($max !== -1)
+ $options['Max']= $max;
+ $required = $this->getRequiredSelections();
+ if(strlen($required) > 0)
+ $options['Required']= $required;
+ $options['TotalItems'] = $control->getItemCount();
+
+ return $options;
+ }
+}
diff --git a/framework/Web/UI/WebControls/TListItem.php b/framework/Web/UI/WebControls/TListItem.php
index 354aa62a..e80bcafd 100644
--- a/framework/Web/UI/WebControls/TListItem.php
+++ b/framework/Web/UI/WebControls/TListItem.php
@@ -1,184 +1,184 @@
-<?php
-/**
- * TListItem class file
- *
- * @author Qiang Xue <qiang.xue@gmail.com>
- * @link http://www.pradosoft.com/
+<?php
+/**
+ * TListItem class file
+ *
+ * @author Qiang Xue <qiang.xue@gmail.com>
+ * @link http://www.pradosoft.com/
* @copyright Copyright &copy; 2005-2012 PradoSoft
- * @license http://www.pradosoft.com/license/
- * @version $Id$
- * @package System.Web.UI.WebControls
- */
-
-/**
- * TListItem class.
- *
- * TListItem represents an item in a list control. Each item has a {@link setText Text}
- * property and a {@link setValue Value} property. If either one of them is not set,
- * it will take the value of the other property.
- * An item can be {@link setSelected Selected} or {@link setEnabled Enabled},
- * and it can have additional {@link getAttributes Attributes} which may be rendered
- * if the list control supports so.
- *
- * @author Qiang Xue <qiang.xue@gmail.com>
- * @version $Id$
- * @package System.Web.UI.WebControls
- * @since 3.0
- */
-class TListItem extends TComponent
-{
- /**
- * @var TMap list of custom attributes
- */
- private $_attributes=null;
- /**
- * @var string text of the item
- */
- private $_text;
- /**
- * @var string value of the item
- */
- private $_value;
- /**
- * @var boolean whether the item is enabled
- */
- private $_enabled;
- /**
- * @var boolean whether the item is selected
- */
- private $_selected;
-
- /**
- * Constructor.
- * @param string text of the item
- * @param string value of the item
- * @param boolean whether the item is enabled
- * @param boolean whether the item is selected
- */
- public function __construct($text='',$value='',$enabled=true,$selected=false)
- {
- $this->setText($text);
- $this->setValue($value);
- $this->setEnabled($enabled);
- $this->setSelected($selected);
- }
-
- /**
- * @return boolean whether the item is enabled
- */
- public function getEnabled()
- {
- return $this->_enabled;
- }
-
- /**
- * @param boolean whether the item is enabled
- */
- public function setEnabled($value)
- {
- $this->_enabled=TPropertyValue::ensureBoolean($value);
- }
-
- /**
- * @return boolean whether the item is selected
- */
- public function getSelected()
- {
- return $this->_selected;
- }
-
- /**
- * @param boolean whether the item is selected
- */
- public function setSelected($value)
- {
- $this->_selected=TPropertyValue::ensureBoolean($value);
- }
-
- /**
- * @return string text of the item
- */
- public function getText()
- {
- return $this->_text===''?$this->_value:$this->_text;
- }
-
- /**
- * @param string text of the item
- */
- public function setText($value)
- {
- $this->_text=TPropertyValue::ensureString($value);
- }
-
- /**
- * @return string value of the item
- */
- public function getValue()
- {
- return $this->_value===''?$this->_text:$this->_value;
- }
-
- /**
- * @param string value of the item
- */
- public function setValue($value)
- {
- $this->_value=TPropertyValue::ensureString($value);
- }
-
- /**
- * @return TAttributeCollection custom attributes
- */
- public function getAttributes()
- {
- if(!$this->_attributes)
- $this->_attributes=new TAttributeCollection;
- return $this->_attributes;
- }
-
- /**
- * @return boolean whether the item has any custom attribute
- */
- public function getHasAttributes()
- {
- return $this->_attributes && $this->_attributes->getCount()>0;
- }
-
- /**
- * @param string name of the attribute
- * @return boolean whether the named attribute exists
- */
- public function hasAttribute($name)
- {
- return $this->_attributes?$this->_attributes->contains($name):false;
- }
-
- /**
- * @return string the named attribute value, null if attribute does not exist
- */
- public function getAttribute($name)
- {
- return $this->_attributes?$this->_attributes->itemAt($name):null;
- }
-
- /**
- * @param string attribute name
- * @param string value of the attribute
- */
- public function setAttribute($name,$value)
- {
- $this->getAttributes()->add($name,$value);
- }
-
- /**
- * Removes the named attribute.
- * @param string the name of the attribute to be removed.
- * @return string attribute value removed, empty string if attribute does not exist.
- */
- public function removeAttribute($name)
- {
- return $this->_attributes?$this->_attributes->remove($name):null;
- }
-}
-
+ * @license http://www.pradosoft.com/license/
+ * @version $Id$
+ * @package System.Web.UI.WebControls
+ */
+
+/**
+ * TListItem class.
+ *
+ * TListItem represents an item in a list control. Each item has a {@link setText Text}
+ * property and a {@link setValue Value} property. If either one of them is not set,
+ * it will take the value of the other property.
+ * An item can be {@link setSelected Selected} or {@link setEnabled Enabled},
+ * and it can have additional {@link getAttributes Attributes} which may be rendered
+ * if the list control supports so.
+ *
+ * @author Qiang Xue <qiang.xue@gmail.com>
+ * @version $Id$
+ * @package System.Web.UI.WebControls
+ * @since 3.0
+ */
+class TListItem extends TComponent
+{
+ /**
+ * @var TMap list of custom attributes
+ */
+ private $_attributes=null;
+ /**
+ * @var string text of the item
+ */
+ private $_text;
+ /**
+ * @var string value of the item
+ */
+ private $_value;
+ /**
+ * @var boolean whether the item is enabled
+ */
+ private $_enabled;
+ /**
+ * @var boolean whether the item is selected
+ */
+ private $_selected;
+
+ /**
+ * Constructor.
+ * @param string text of the item
+ * @param string value of the item
+ * @param boolean whether the item is enabled
+ * @param boolean whether the item is selected
+ */
+ public function __construct($text='',$value='',$enabled=true,$selected=false)
+ {
+ $this->setText($text);
+ $this->setValue($value);
+ $this->setEnabled($enabled);
+ $this->setSelected($selected);
+ }
+
+ /**
+ * @return boolean whether the item is enabled
+ */
+ public function getEnabled()
+ {
+ return $this->_enabled;
+ }
+
+ /**
+ * @param boolean whether the item is enabled
+ */
+ public function setEnabled($value)
+ {
+ $this->_enabled=TPropertyValue::ensureBoolean($value);
+ }
+
+ /**
+ * @return boolean whether the item is selected
+ */
+ public function getSelected()
+ {
+ return $this->_selected;
+ }
+
+ /**
+ * @param boolean whether the item is selected
+ */
+ public function setSelected($value)
+ {
+ $this->_selected=TPropertyValue::ensureBoolean($value);
+ }
+
+ /**
+ * @return string text of the item
+ */
+ public function getText()
+ {
+ return $this->_text===''?$this->_value:$this->_text;
+ }
+
+ /**
+ * @param string text of the item
+ */
+ public function setText($value)
+ {
+ $this->_text=TPropertyValue::ensureString($value);
+ }
+
+ /**
+ * @return string value of the item
+ */
+ public function getValue()
+ {
+ return $this->_value===''?$this->_text:$this->_value;
+ }
+
+ /**
+ * @param string value of the item
+ */
+ public function setValue($value)
+ {
+ $this->_value=TPropertyValue::ensureString($value);
+ }
+
+ /**
+ * @return TAttributeCollection custom attributes
+ */
+ public function getAttributes()
+ {
+ if(!$this->_attributes)
+ $this->_attributes=new TAttributeCollection;
+ return $this->_attributes;
+ }
+
+ /**
+ * @return boolean whether the item has any custom attribute
+ */
+ public function getHasAttributes()
+ {
+ return $this->_attributes && $this->_attributes->getCount()>0;
+ }
+
+ /**
+ * @param string name of the attribute
+ * @return boolean whether the named attribute exists
+ */
+ public function hasAttribute($name)
+ {
+ return $this->_attributes?$this->_attributes->contains($name):false;
+ }
+
+ /**
+ * @return string the named attribute value, null if attribute does not exist
+ */
+ public function getAttribute($name)
+ {
+ return $this->_attributes?$this->_attributes->itemAt($name):null;
+ }
+
+ /**
+ * @param string attribute name
+ * @param string value of the attribute
+ */
+ public function setAttribute($name,$value)
+ {
+ $this->getAttributes()->add($name,$value);
+ }
+
+ /**
+ * Removes the named attribute.
+ * @param string the name of the attribute to be removed.
+ * @return string attribute value removed, empty string if attribute does not exist.
+ */
+ public function removeAttribute($name)
+ {
+ return $this->_attributes?$this->_attributes->remove($name):null;
+ }
+}
+
diff --git a/framework/Web/UI/WebControls/TLiteral.php b/framework/Web/UI/WebControls/TLiteral.php
index 423e2d8e..e98d56bb 100644
--- a/framework/Web/UI/WebControls/TLiteral.php
+++ b/framework/Web/UI/WebControls/TLiteral.php
@@ -1,112 +1,112 @@
-<?php
-/**
- * TLiteral class file
- *
- * @author Qiang Xue <qiang.xue@gmail.com>
- * @link http://www.pradosoft.com/
+<?php
+/**
+ * TLiteral class file
+ *
+ * @author Qiang Xue <qiang.xue@gmail.com>
+ * @link http://www.pradosoft.com/
* @copyright Copyright &copy; 2005-2012 PradoSoft
- * @license http://www.pradosoft.com/license/
- * @version $Id$
- * @package System.Web.UI.WebControls
- */
-
-/**
- * TLiteral class
- *
- * TLiteral displays a static text on the Web page.
- * TLiteral is similar to the TLabel control, except that the TLiteral
- * control does not have style properties (e.g. BackColor, Font, etc.)
- * You can programmatically control the text displayed in the control by setting
- * the {@link setText Text} property. The text displayed may be HTML-encoded
- * if the {@link setEncode Encode} property is set true (defaults to false).
- *
- * TLiteral will render the contents enclosed within its component tag
- * if {@link setText Text} is empty.
- *
- * Note, if {@link setEncode Encode} is false, make sure {@link setText Text}
- * does not contain unwanted characters that may bring security vulnerabilities.
- *
- * @author Qiang Xue <qiang.xue@gmail.com>
- * @version $Id$
- * @package System.Web.UI.WebControls
- * @since 3.0
- */
-class TLiteral extends TControl implements IDataRenderer
-{
- /**
- * @return string the static text of the TLiteral
- */
- public function getText()
- {
- return $this->getViewState('Text','');
- }
-
- /**
- * Sets the static text of the TLiteral
- * @param string the text to be set
- */
- public function setText($value)
- {
- $this->setViewState('Text',$value,'');
- }
-
- /**
- * Returns the static text of the TLiteral.
- * This method is required by {@link IDataRenderer}.
- * It is the same as {@link getText()}.
- * @return string the static text of the TLiteral
- * @see getText
- * @since 3.1.0
- */
- public function getData()
- {
- return $this->getText();
- }
-
- /**
- * Sets the static text of the TLiteral.
- * This method is required by {@link IDataRenderer}.
- * It is the same as {@link setText()}.
- * @param string the static text of the TLiteral
- * @see setText
- * @since 3.1.0
- */
- public function setData($value)
- {
- $this->setText($value);
- }
-
- /**
- * @return boolean whether the rendered text should be HTML-encoded. Defaults to false.
- */
- public function getEncode()
- {
- return $this->getViewState('Encode',false);
- }
-
- /**
- * @param boolean whether the rendered text should be HTML-encoded.
- */
- public function setEncode($value)
- {
- $this->setViewState('Encode',TPropertyValue::ensureBoolean($value),false);
- }
-
- /**
- * Renders the literal control.
- * @param THtmlWriter the writer used for the rendering purpose
- */
- public function render($writer)
- {
- if(($text=$this->getText())!=='')
- {
- if($this->getEncode())
- $writer->write(THttpUtility::htmlEncode($text));
- else
- $writer->write($text);
- }
- else
- parent::render($writer);
- }
-}
-
+ * @license http://www.pradosoft.com/license/
+ * @version $Id$
+ * @package System.Web.UI.WebControls
+ */
+
+/**
+ * TLiteral class
+ *
+ * TLiteral displays a static text on the Web page.
+ * TLiteral is similar to the TLabel control, except that the TLiteral
+ * control does not have style properties (e.g. BackColor, Font, etc.)
+ * You can programmatically control the text displayed in the control by setting
+ * the {@link setText Text} property. The text displayed may be HTML-encoded
+ * if the {@link setEncode Encode} property is set true (defaults to false).
+ *
+ * TLiteral will render the contents enclosed within its component tag
+ * if {@link setText Text} is empty.
+ *
+ * Note, if {@link setEncode Encode} is false, make sure {@link setText Text}
+ * does not contain unwanted characters that may bring security vulnerabilities.
+ *
+ * @author Qiang Xue <qiang.xue@gmail.com>
+ * @version $Id$
+ * @package System.Web.UI.WebControls
+ * @since 3.0
+ */
+class TLiteral extends TControl implements IDataRenderer
+{
+ /**
+ * @return string the static text of the TLiteral
+ */
+ public function getText()
+ {
+ return $this->getViewState('Text','');
+ }
+
+ /**
+ * Sets the static text of the TLiteral
+ * @param string the text to be set
+ */
+ public function setText($value)
+ {
+ $this->setViewState('Text',$value,'');
+ }
+
+ /**
+ * Returns the static text of the TLiteral.
+ * This method is required by {@link IDataRenderer}.
+ * It is the same as {@link getText()}.
+ * @return string the static text of the TLiteral
+ * @see getText
+ * @since 3.1.0
+ */
+ public function getData()
+ {
+ return $this->getText();
+ }
+
+ /**
+ * Sets the static text of the TLiteral.
+ * This method is required by {@link IDataRenderer}.
+ * It is the same as {@link setText()}.
+ * @param string the static text of the TLiteral
+ * @see setText
+ * @since 3.1.0
+ */
+ public function setData($value)
+ {
+ $this->setText($value);
+ }
+
+ /**
+ * @return boolean whether the rendered text should be HTML-encoded. Defaults to false.
+ */
+ public function getEncode()
+ {
+ return $this->getViewState('Encode',false);
+ }
+
+ /**
+ * @param boolean whether the rendered text should be HTML-encoded.
+ */
+ public function setEncode($value)
+ {
+ $this->setViewState('Encode',TPropertyValue::ensureBoolean($value),false);
+ }
+
+ /**
+ * Renders the literal control.
+ * @param THtmlWriter the writer used for the rendering purpose
+ */
+ public function render($writer)
+ {
+ if(($text=$this->getText())!=='')
+ {
+ if($this->getEncode())
+ $writer->write(THttpUtility::htmlEncode($text));
+ else
+ $writer->write($text);
+ }
+ else
+ parent::render($writer);
+ }
+}
+
diff --git a/framework/Web/UI/WebControls/TLiteralColumn.php b/framework/Web/UI/WebControls/TLiteralColumn.php
index 5b1353fc..48cbe013 100644
--- a/framework/Web/UI/WebControls/TLiteralColumn.php
+++ b/framework/Web/UI/WebControls/TLiteralColumn.php
@@ -1,154 +1,154 @@
-<?php
-/**
- * TLiteralColumn class file
- *
- * @author Qiang Xue <qiang.xue@gmail.com>
- * @link http://www.pradosoft.com/
+<?php
+/**
+ * TLiteralColumn class file
+ *
+ * @author Qiang Xue <qiang.xue@gmail.com>
+ * @link http://www.pradosoft.com/
* @copyright Copyright &copy; 2005-2012 PradoSoft
- * @license http://www.pradosoft.com/license/
- * @version $Id: TLiteralColumn.php 1397 2006-09-07 07:55:53Z wei $
- * @package System.Web.UI.WebControls
- */
-
-/**
- * TDataGridColumn class file
- */
-Prado::using('System.Web.UI.WebControls.TDataGridColumn');
-
-/**
- * TLiteralColumn class
- *
- * TLiteralColumn represents a static text column that is bound to a field in a data source.
- * The cells in the column will be displayed with static texts using the data indexed by
- * {@link setDataField DataField}. You can customize the display by
- * setting {@link setDataFormatString DataFormatString}.
- *
- * If {@link setDataField DataField} is not specified, the cells will be filled
- * with {@link setText Text}.
- *
- * If {@link setEncode Encode} is true, the static texts will be HTML-encoded.
- *
- * @author Qiang Xue <qiang.xue@gmail.com>
- * @version $Id: TLiteralColumn.php 1397 2006-09-07 07:55:53Z wei $
- * @package System.Web.UI.WebControls
- * @since 3.0.5
- */
-class TLiteralColumn extends TDataGridColumn
-{
- /**
- * @return string the field name from the data source to bind to the column
- */
- public function getDataField()
- {
- return $this->getViewState('DataField','');
- }
-
- /**
- * @param string the field name from the data source to bind to the column
- */
- public function setDataField($value)
- {
- $this->setViewState('DataField',$value,'');
- }
-
- /**
- * @return string the formatting string used to control how the bound data will be displayed.
- */
- public function getDataFormatString()
- {
- return $this->getViewState('DataFormatString','');
- }
-
- /**
- * @param string the formatting string used to control how the bound data will be displayed.
- */
- public function setDataFormatString($value)
- {
- $this->setViewState('DataFormatString',$value,'');
- }
-
- /**
- * @return string static text to be displayed in the column. Defaults to empty.
- */
- public function getText()
- {
- return $this->getViewState('Text','');
- }
-
- /**
- * @param string static text to be displayed in the column.
- */
- public function setText($value)
- {
- $this->setViewState('Text',$value,'');
- }
-
- /**
- * @return boolean whether the rendered text should be HTML-encoded. Defaults to false.
- */
- public function getEncode()
- {
- return $this->getViewState('Encode',false);
- }
-
- /**
- * @param boolean whether the rendered text should be HTML-encoded.
- */
- public function setEncode($value)
- {
- $this->setViewState('Encode',TPropertyValue::ensureBoolean($value),false);
- }
-
- /**
- * Initializes the specified cell to its initial values.
- * This method overrides the parent implementation.
- * @param TTableCell the cell to be initialized.
- * @param integer the index to the Columns property that the cell resides in.
- * @param string the type of cell (Header,Footer,Item,AlternatingItem,EditItem,SelectedItem)
- */
- public function initializeCell($cell,$columnIndex,$itemType)
- {
- if($itemType===TListItemType::Item || $itemType===TListItemType::AlternatingItem || $itemType===TListItemType::EditItem || $itemType===TListItemType::SelectedItem)
- {
- if($this->getDataField()!=='')
- $cell->attachEventHandler('OnDataBinding',array($this,'dataBindColumn'));
- else
- {
- if(($dataField=$this->getDataField())!=='')
- $control->attachEventHandler('OnDataBinding',array($this,'dataBindColumn'));
- else
- {
- $text=$this->getText();
- if($this->getEncode())
- $text=THttpUtility::htmlEncode($text);
- $cell->setText($text);
- }
- }
- }
- else
- parent::initializeCell($cell,$columnIndex,$itemType);
- }
-
- /**
- * Databinds a cell in the column.
- * This method is invoked when datagrid performs databinding.
- * It populates the content of the cell with the relevant data from data source.
- */
- public function dataBindColumn($sender,$param)
- {
- $item=$sender->getNamingContainer();
- $data=$item->getData();
- $formatString=$this->getDataFormatString();
- if(($field=$this->getDataField())!=='')
- $value=$this->formatDataValue($formatString,$this->getDataFieldValue($data,$field));
- else
- $value=$this->formatDataValue($formatString,$data);
- if($sender instanceof TTableCell)
- {
- if($this->getEncode())
- $value=THttpUtility::htmlEncode($value);
- $sender->setText($value);
- }
- }
-}
-
+ * @license http://www.pradosoft.com/license/
+ * @version $Id: TLiteralColumn.php 1397 2006-09-07 07:55:53Z wei $
+ * @package System.Web.UI.WebControls
+ */
+
+/**
+ * TDataGridColumn class file
+ */
+Prado::using('System.Web.UI.WebControls.TDataGridColumn');
+
+/**
+ * TLiteralColumn class
+ *
+ * TLiteralColumn represents a static text column that is bound to a field in a data source.
+ * The cells in the column will be displayed with static texts using the data indexed by
+ * {@link setDataField DataField}. You can customize the display by
+ * setting {@link setDataFormatString DataFormatString}.
+ *
+ * If {@link setDataField DataField} is not specified, the cells will be filled
+ * with {@link setText Text}.
+ *
+ * If {@link setEncode Encode} is true, the static texts will be HTML-encoded.
+ *
+ * @author Qiang Xue <qiang.xue@gmail.com>
+ * @version $Id: TLiteralColumn.php 1397 2006-09-07 07:55:53Z wei $
+ * @package System.Web.UI.WebControls
+ * @since 3.0.5
+ */
+class TLiteralColumn extends TDataGridColumn
+{
+ /**
+ * @return string the field name from the data source to bind to the column
+ */
+ public function getDataField()
+ {
+ return $this->getViewState('DataField','');
+ }
+
+ /**
+ * @param string the field name from the data source to bind to the column
+ */
+ public function setDataField($value)
+ {
+ $this->setViewState('DataField',$value,'');
+ }
+
+ /**
+ * @return string the formatting string used to control how the bound data will be displayed.
+ */
+ public function getDataFormatString()
+ {
+ return $this->getViewState('DataFormatString','');
+ }
+
+ /**
+ * @param string the formatting string used to control how the bound data will be displayed.
+ */
+ public function setDataFormatString($value)
+ {
+ $this->setViewState('DataFormatString',$value,'');
+ }
+
+ /**
+ * @return string static text to be displayed in the column. Defaults to empty.
+ */
+ public function getText()
+ {
+ return $this->getViewState('Text','');
+ }
+
+ /**
+ * @param string static text to be displayed in the column.
+ */
+ public function setText($value)
+ {
+ $this->setViewState('Text',$value,'');
+ }
+
+ /**
+ * @return boolean whether the rendered text should be HTML-encoded. Defaults to false.
+ */
+ public function getEncode()
+ {
+ return $this->getViewState('Encode',false);
+ }
+
+ /**
+ * @param boolean whether the rendered text should be HTML-encoded.
+ */
+ public function setEncode($value)
+ {
+ $this->setViewState('Encode',TPropertyValue::ensureBoolean($value),false);
+ }
+
+ /**
+ * Initializes the specified cell to its initial values.
+ * This method overrides the parent implementation.
+ * @param TTableCell the cell to be initialized.
+ * @param integer the index to the Columns property that the cell resides in.
+ * @param string the type of cell (Header,Footer,Item,AlternatingItem,EditItem,SelectedItem)
+ */
+ public function initializeCell($cell,$columnIndex,$itemType)
+ {
+ if($itemType===TListItemType::Item || $itemType===TListItemType::AlternatingItem || $itemType===TListItemType::EditItem || $itemType===TListItemType::SelectedItem)
+ {
+ if($this->getDataField()!=='')
+ $cell->attachEventHandler('OnDataBinding',array($this,'dataBindColumn'));
+ else
+ {
+ if(($dataField=$this->getDataField())!=='')
+ $control->attachEventHandler('OnDataBinding',array($this,'dataBindColumn'));
+ else
+ {
+ $text=$this->getText();
+ if($this->getEncode())
+ $text=THttpUtility::htmlEncode($text);
+ $cell->setText($text);
+ }
+ }
+ }
+ else
+ parent::initializeCell($cell,$columnIndex,$itemType);
+ }
+
+ /**
+ * Databinds a cell in the column.
+ * This method is invoked when datagrid performs databinding.
+ * It populates the content of the cell with the relevant data from data source.
+ */
+ public function dataBindColumn($sender,$param)
+ {
+ $item=$sender->getNamingContainer();
+ $data=$item->getData();
+ $formatString=$this->getDataFormatString();
+ if(($field=$this->getDataField())!=='')
+ $value=$this->formatDataValue($formatString,$this->getDataFieldValue($data,$field));
+ else
+ $value=$this->formatDataValue($formatString,$data);
+ if($sender instanceof TTableCell)
+ {
+ if($this->getEncode())
+ $value=THttpUtility::htmlEncode($value);
+ $sender->setText($value);
+ }
+ }
+}
+
diff --git a/framework/Web/UI/WebControls/TMarkdown.php b/framework/Web/UI/WebControls/TMarkdown.php
index 3aa1c9be..726a1ebe 100644
--- a/framework/Web/UI/WebControls/TMarkdown.php
+++ b/framework/Web/UI/WebControls/TMarkdown.php
@@ -1,75 +1,75 @@
-<?php
-/**
- * TMarkdown class file
- *
- * @author Wei Zhuo <weizhuo[at]gmail[dot]com>
- * @link http://www.pradosoft.com/
+<?php
+/**
+ * TMarkdown class file
+ *
+ * @author Wei Zhuo <weizhuo[at]gmail[dot]com>
+ * @link http://www.pradosoft.com/
* @copyright Copyright &copy; 2005-2012 PradoSoft
- * @license http://www.pradosoft.com/license/
- * @version $Id$
- * @package System.Web.UI.WebControls
- */
-
-/**
- * Using TTextHighlighter and MarkdownParser classes
- */
-Prado::using('System.Web.UI.WebControls.TTextHighlighter');
-Prado::using('System.3rdParty.Markdown.MarkdownParser');
-
-/**
- * TMarkdown class
- *
- * TMarkdown is a control that produces HTML from code with markdown syntax.
- *
- * Markdown is a text-to-HTML conversion tool for web writers. Markdown allows
- * you to write using an easy-to-read, easy-to-write plain text format, then
- * convert it to structurally valid XHTML (or HTML).
- * Further documentation regarding Markdown can be found at
- * http://daringfireball.net/projects/markdown/
- *
- * To use TMarkdown, simply enclose the content to be rendered within
- * the body of TMarkdown in a template.
- *
- * See http://www.pradosoft.com/demos/quickstart/?page=Markdown for
- * details on the Markdown syntax usage.
- *
- * TMarkdown also performs syntax highlighting for code blocks whose language
- * is recognized by {@link TTextHighlighter}.
- * The language of a code block must be specified in the first line of the block
- * and enclosed within a pair of square brackets (e.g. [php]).
- *
- * @author Wei Zhuo <weizhuo[at]gmail[dot]com>
- * @version $Id$
- * @package System.Web.UI.WebControls
- * @since 3.0.1
- */
-class TMarkdown extends TTextHighlighter
-{
- /**
- * Processes a text string.
- * This method is required by the parent class.
- * @param string text string to be processed
- * @return string the processed text result
- */
- public function processText($text)
- {
- $renderer = new MarkdownParser;
- $result = $renderer->parse($text);
- return preg_replace_callback(
- '/<pre><code>\[\s*(\w+)\s*\]\n+((.|\n)*?)\s*<\\/code><\\/pre>/im',
- array($this, 'highlightCode'), $result);
- }
-
- /**
- * Highlights source code using TTextHighlighter
- * @param array matches of code blocks
- * @return string highlighted code.
- */
- protected function highlightCode($matches)
- {
- $text = html_entity_decode($matches[2],ENT_QUOTES,'UTF-8');
- $this->setLanguage($matches[1]);
- return parent::processText($text);
- }
-}
-
+ * @license http://www.pradosoft.com/license/
+ * @version $Id$
+ * @package System.Web.UI.WebControls
+ */
+
+/**
+ * Using TTextHighlighter and MarkdownParser classes
+ */
+Prado::using('System.Web.UI.WebControls.TTextHighlighter');
+Prado::using('System.3rdParty.Markdown.MarkdownParser');
+
+/**
+ * TMarkdown class
+ *
+ * TMarkdown is a control that produces HTML from code with markdown syntax.
+ *
+ * Markdown is a text-to-HTML conversion tool for web writers. Markdown allows
+ * you to write using an easy-to-read, easy-to-write plain text format, then
+ * convert it to structurally valid XHTML (or HTML).
+ * Further documentation regarding Markdown can be found at
+ * http://daringfireball.net/projects/markdown/
+ *
+ * To use TMarkdown, simply enclose the content to be rendered within
+ * the body of TMarkdown in a template.
+ *
+ * See http://www.pradosoft.com/demos/quickstart/?page=Markdown for
+ * details on the Markdown syntax usage.
+ *
+ * TMarkdown also performs syntax highlighting for code blocks whose language
+ * is recognized by {@link TTextHighlighter}.
+ * The language of a code block must be specified in the first line of the block
+ * and enclosed within a pair of square brackets (e.g. [php]).
+ *
+ * @author Wei Zhuo <weizhuo[at]gmail[dot]com>
+ * @version $Id$
+ * @package System.Web.UI.WebControls
+ * @since 3.0.1
+ */
+class TMarkdown extends TTextHighlighter
+{
+ /**
+ * Processes a text string.
+ * This method is required by the parent class.
+ * @param string text string to be processed
+ * @return string the processed text result
+ */
+ public function processText($text)
+ {
+ $renderer = new MarkdownParser;
+ $result = $renderer->parse($text);
+ return preg_replace_callback(
+ '/<pre><code>\[\s*(\w+)\s*\]\n+((.|\n)*?)\s*<\\/code><\\/pre>/im',
+ array($this, 'highlightCode'), $result);
+ }
+
+ /**
+ * Highlights source code using TTextHighlighter
+ * @param array matches of code blocks
+ * @return string highlighted code.
+ */
+ protected function highlightCode($matches)
+ {
+ $text = html_entity_decode($matches[2],ENT_QUOTES,'UTF-8');
+ $this->setLanguage($matches[1]);
+ return parent::processText($text);
+ }
+}
+
diff --git a/framework/Web/UI/WebControls/TMultiView.php b/framework/Web/UI/WebControls/TMultiView.php
index 81d404b2..0c40cd06 100644
--- a/framework/Web/UI/WebControls/TMultiView.php
+++ b/framework/Web/UI/WebControls/TMultiView.php
@@ -1,378 +1,378 @@
-<?php
-/**
- * TMultiView and TView class file.
- *
- * @author Qiang Xue <qiang.xue@gmail.com>
- * @link http://www.pradosoft.com/
- * @copyright Copyright &copy; 2005-2012 PradoSoft
- * @license http://www.pradosoft.com/license/
- * @version $Id$
- * @package System.Web.UI.WebControls
- */
-
-/**
- * TMultiView class
- *
- * TMultiView serves as a container for a group of {@link TView} controls.
- * The view collection can be retrieved by {@link getViews Views}.
- * Each view contains child controls. TMultiView determines which view and its
- * child controls are visible. At any time, at most one view is visible (called
- * active). To make a view active, set {@link setActiveView ActiveView} or
- * {@link setActiveViewIndex ActiveViewIndex}.
- *
- * TMultiView also responds to specific command events raised from button controls
- * contained in current active view. A command event with name 'NextView'
- * will cause TMultiView to make the next available view active.
- * Other command names recognized by TMultiView include
- * - PreviousView : switch to previous view
- * - SwitchViewID : switch to a view by its ID path
- * - SwitchViewIndex : switch to a view by its index in the {@link getViews Views} collection.
- *
- * TMultiView raises {@link OnActiveViewChanged OnActiveViewChanged} event
- * when its active view is changed during a postback.
- *
- * @author Qiang Xue <qiang.xue@gmail.com>
- * @version $Id$
- * @package System.Web.UI.WebControls
- * @since 3.0
- */
-class TMultiView extends TControl
-{
- const CMD_NEXTVIEW='NextView';
- const CMD_PREVIOUSVIEW='PreviousView';
- const CMD_SWITCHVIEWID='SwitchViewID';
- const CMD_SWITCHVIEWINDEX='SwitchViewIndex';
- private $_cachedActiveViewIndex=-1;
- private $_ignoreBubbleEvents=false;
-
- /**
- * Processes an object that is created during parsing template.
- * This method overrides the parent implementation by adding only {@link TView}
- * controls as children.
- * @param string|TComponent text string or component parsed and instantiated in template
- * @see createdOnTemplate
- * @throws TConfigurationException if controls other than {@link TView} is being added
- */
- public function addParsedObject($object)
- {
- if($object instanceof TView)
- $this->getControls()->add($object);
- else if(!is_string($object))
- throw new TConfigurationException('multiview_view_required');
- }
-
- /**
- * Creates a control collection object that is to be used to hold child controls
- * @return TViewCollection control collection
- */
- protected function createControlCollection()
- {
- return new TViewCollection($this);
- }
-
- /**
- * @return integer the zero-based index of the current view in the view collection. -1 if no active view. Default is -1.
- */
- public function getActiveViewIndex()
- {
- if($this->_cachedActiveViewIndex>-1)
- return $this->_cachedActiveViewIndex;
- else
- return $this->getControlState('ActiveViewIndex',-1);
- }
-
- /**
- * @param integer the zero-based index of the current view in the view collection. -1 if no active view.
- * @throws TInvalidDataValueException if the view index is invalid
- */
- public function setActiveViewIndex($value)
- {
- if(($index=TPropertyValue::ensureInteger($value))<0)
- $index=-1;
- $views=$this->getViews();
- $count=$views->getCount();
- if($count===0 && $this->getControlStage()<TControl::CS_CHILD_INITIALIZED)
- $this->_cachedActiveViewIndex=$index;
- else if($index<$count)
- {
- $this->setControlState('ActiveViewIndex',$index,-1);
- $this->_cachedActiveViewIndex=-1;
- if($index>=0)
- $this->activateView($views->itemAt($index),true);
- }
- else
- throw new TInvalidDataValueException('multiview_activeviewindex_invalid',$index);
- }
-
- /**
- * @return TView the currently active view, null if no active view
- * @throws TInvalidDataValueException if the current active view index is invalid
- */
- public function getActiveView()
- {
- $index=$this->getActiveViewIndex();
- $views=$this->getViews();
- if($index>=$views->getCount())
- throw new TInvalidDataValueException('multiview_activeviewindex_invalid',$index);
- if($index<0)
- return null;
- $view=$views->itemAt($index);
- if(!$view->getActive())
- $this->activateView($view,false);
- return $view;
- }
-
- /**
- * @param TView the view to be activated
- * @throws TInvalidOperationException if the view is not in the view collection
- */
- public function setActiveView($view)
- {
- if(($index=$this->getViews()->indexOf($view))>=0)
- $this->setActiveViewIndex($index);
- else
- throw new TInvalidOperationException('multiview_view_inexistent');
- }
-
- /**
- * Activates the specified view.
- * If there is any view currently active, it will be deactivated.
- * @param TView the view to be activated
- * @param boolean whether to trigger OnActiveViewChanged event.
- */
- protected function activateView($view,$triggerViewChangedEvent=true)
- {
- if($view->getActive())
- return;
- $triggerEvent=$triggerViewChangedEvent && ($this->getControlStage()>=TControl::CS_STATE_LOADED || ($this->getPage() && !$this->getPage()->getIsPostBack()));
- foreach($this->getViews() as $v)
- {
- if($v===$view)
- {
- $view->setActive(true);
- if($triggerEvent)
- {
- $view->onActivate(null);
- $this->onActiveViewChanged(null);
- }
- }
- else if($v->getActive())
- {
- $v->setActive(false);
- if($triggerEvent)
- $v->onDeactivate(null);
- }
- }
- }
-
- /**
- * @return TViewCollection the view collection
- */
- public function getViews()
- {
- return $this->getControls();
- }
-
- /**
- * Makes the multiview ignore all bubbled events.
- * This is method is used internally by framework and control
- * developers.
- */
- public function ignoreBubbleEvents()
- {
- $this->_ignoreBubbleEvents=true;
- }
-
- /**
- * Initializes the active view if any.
- * This method overrides the parent implementation.
- * @param TEventParameter event parameter
- */
- public function onInit($param)
- {
- parent::onInit($param);
- if($this->_cachedActiveViewIndex>=0)
- $this->setActiveViewIndex($this->_cachedActiveViewIndex);
- }
-
- /**
- * Raises <b>OnActiveViewChanged</b> event.
- * The event is raised when the currently active view is changed to a new one
- * @param TEventParameter event parameter
- */
- public function onActiveViewChanged($param)
- {
- $this->raiseEvent('OnActiveViewChanged',$this,$param);
- }
-
- /**
- * Processes the events bubbled from child controls.
- * The method handles view-related command events.
- * @param TControl sender of the event
- * @param mixed event parameter
- * @return boolean whether this event is handled
- */
- public function bubbleEvent($sender,$param)
- {
- if(!$this->_ignoreBubbleEvents && ($param instanceof TCommandEventParameter))
- {
- switch($param->getCommandName())
- {
- case self::CMD_NEXTVIEW:
- if(($index=$this->getActiveViewIndex())<$this->getViews()->getCount()-1)
- $this->setActiveViewIndex($index+1);
- else
- $this->setActiveViewIndex(-1);
- return true;
- case self::CMD_PREVIOUSVIEW:
- if(($index=$this->getActiveViewIndex())>=0)
- $this->setActiveViewIndex($index-1);
- return true;
- case self::CMD_SWITCHVIEWID:
- $view=$this->findControl($viewID=$param->getCommandParameter());
- if($view!==null && $view->getParent()===$this)
- {
- $this->setActiveView($view);
- return true;
- }
- else
- throw new TInvalidDataValueException('multiview_viewid_invalid', $viewID);
- case self::CMD_SWITCHVIEWINDEX:
- $index=TPropertyValue::ensureInteger($param->getCommandParameter());
- $this->setActiveViewIndex($index);
- return true;
- }
- }
- return false;
- }
-
- /**
- * Loads state into the wizard.
- * This method is invoked by the framework when the control state is being saved.
- */
- public function loadState()
- {
- // a dummy call to ensure the view is activated
- $this->getActiveView();
- }
-
- /**
- * Renders the currently active view.
- * @param THtmlWriter the writer for the rendering purpose.
- */
- public function render($writer)
- {
- if(($view=$this->getActiveView())!==null)
- $view->renderControl($writer);
- }
-}
-
-/**
- * TViewCollection class.
- * TViewCollection represents a collection that only takes {@link TView} instances
- * as collection elements.
- * @author Qiang Xue <qiang.xue@gmail.com>
- * @version $Id$
- * @package System.Web.UI.WebControls
- * @since 3.0
- */
-class TViewCollection extends TControlCollection
-{
- /**
- * Inserts an item at the specified position.
- * This overrides the parent implementation by ensuring only {@link TView}
- * controls be added into the collection.
- * @param integer the speicified position.
- * @param mixed new item
- * @throws TInvalidDataTypeException if the item to be inserted is neither a string nor a TControl.
- */
- public function insertAt($index,$item)
- {
- if($item instanceof TView)
- parent::insertAt($index,$item);
- else
- throw new TInvalidDataTypeException('viewcollection_view_required');
- }
-}
-
-/**
- * TView class
- *
- * TView is a container for a group of controls. TView must be contained
- * within a {@link TMultiView} control in which only one view can be active
- * at one time.
- *
- * To activate a view, set {@link setActive Active} to true.
- * When a view is activated, it raises {@link onActivate OnActivate} event;
- * and when a view is deactivated, it raises {@link onDeactivate OnDeactivate}.
- *
- * @author Qiang Xue <qiang.xue@gmail.com>
- * @version $Id$
- * @package System.Web.UI.WebControls
- * @since 3.0
- */
-class TView extends TControl
-{
- private $_active=false;
-
- /**
- * Raises <b>OnActivate</b> event.
- * @param TEventParameter event parameter
- */
- public function onActivate($param)
- {
- $this->raiseEvent('OnActivate',$this,$param);
- }
-
- /**
- * Raises <b>OnDeactivate</b> event.
- * @param TEventParameter event parameter
- */
- public function onDeactivate($param)
- {
- $this->raiseEvent('OnDeactivate',$this,$param);
- }
-
- /**
- * @return boolean whether this view is active. Defaults to false.
- */
- public function getActive()
- {
- return $this->_active;
- }
-
- /**
- * @param boolean whether this view is active.
- */
- public function setActive($value)
- {
- $value=TPropertyValue::ensureBoolean($value);
- $this->_active=$value;
- parent::setVisible($value);
- }
-
- /**
- * @param boolean whether the parents should also be checked if visible
- * @return boolean whether this view is visible.
- * The view is visible if it is active and its parent is visible.
- */
- public function getVisible($checkParents=true)
- {
- if(($parent=$this->getParent())===null)
- return $this->getActive();
- else if($this->getActive())
- return $parent->getVisible($checkParents);
- else
- return false;
- }
-
- /**
- * @param boolean
- * @throws TInvalidOperationException whenever this method is invoked.
- */
- public function setVisible($value)
- {
- throw new TInvalidOperationException('view_visible_readonly');
- }
-}
-
+<?php
+/**
+ * TMultiView and TView class file.
+ *
+ * @author Qiang Xue <qiang.xue@gmail.com>
+ * @link http://www.pradosoft.com/
+ * @copyright Copyright &copy; 2005-2012 PradoSoft
+ * @license http://www.pradosoft.com/license/
+ * @version $Id$
+ * @package System.Web.UI.WebControls
+ */
+
+/**
+ * TMultiView class
+ *
+ * TMultiView serves as a container for a group of {@link TView} controls.
+ * The view collection can be retrieved by {@link getViews Views}.
+ * Each view contains child controls. TMultiView determines which view and its
+ * child controls are visible. At any time, at most one view is visible (called
+ * active). To make a view active, set {@link setActiveView ActiveView} or
+ * {@link setActiveViewIndex ActiveViewIndex}.
+ *
+ * TMultiView also responds to specific command events raised from button controls
+ * contained in current active view. A command event with name 'NextView'
+ * will cause TMultiView to make the next available view active.
+ * Other command names recognized by TMultiView include
+ * - PreviousView : switch to previous view
+ * - SwitchViewID : switch to a view by its ID path
+ * - SwitchViewIndex : switch to a view by its index in the {@link getViews Views} collection.
+ *
+ * TMultiView raises {@link OnActiveViewChanged OnActiveViewChanged} event
+ * when its active view is changed during a postback.
+ *
+ * @author Qiang Xue <qiang.xue@gmail.com>
+ * @version $Id$
+ * @package System.Web.UI.WebControls
+ * @since 3.0
+ */
+class TMultiView extends TControl
+{
+ const CMD_NEXTVIEW='NextView';
+ const CMD_PREVIOUSVIEW='PreviousView';
+ const CMD_SWITCHVIEWID='SwitchViewID';
+ const CMD_SWITCHVIEWINDEX='SwitchViewIndex';
+ private $_cachedActiveViewIndex=-1;
+ private $_ignoreBubbleEvents=false;
+
+ /**
+ * Processes an object that is created during parsing template.
+ * This method overrides the parent implementation by adding only {@link TView}
+ * controls as children.
+ * @param string|TComponent text string or component parsed and instantiated in template
+ * @see createdOnTemplate
+ * @throws TConfigurationException if controls other than {@link TView} is being added
+ */
+ public function addParsedObject($object)
+ {
+ if($object instanceof TView)
+ $this->getControls()->add($object);
+ else if(!is_string($object))
+ throw new TConfigurationException('multiview_view_required');
+ }
+
+ /**
+ * Creates a control collection object that is to be used to hold child controls
+ * @return TViewCollection control collection
+ */
+ protected function createControlCollection()
+ {
+ return new TViewCollection($this);
+ }
+
+ /**
+ * @return integer the zero-based index of the current view in the view collection. -1 if no active view. Default is -1.
+ */
+ public function getActiveViewIndex()
+ {
+ if($this->_cachedActiveViewIndex>-1)
+ return $this->_cachedActiveViewIndex;
+ else
+ return $this->getControlState('ActiveViewIndex',-1);
+ }
+
+ /**
+ * @param integer the zero-based index of the current view in the view collection. -1 if no active view.
+ * @throws TInvalidDataValueException if the view index is invalid
+ */
+ public function setActiveViewIndex($value)
+ {
+ if(($index=TPropertyValue::ensureInteger($value))<0)
+ $index=-1;
+ $views=$this->getViews();
+ $count=$views->getCount();
+ if($count===0 && $this->getControlStage()<TControl::CS_CHILD_INITIALIZED)
+ $this->_cachedActiveViewIndex=$index;
+ else if($index<$count)
+ {
+ $this->setControlState('ActiveViewIndex',$index,-1);
+ $this->_cachedActiveViewIndex=-1;
+ if($index>=0)
+ $this->activateView($views->itemAt($index),true);
+ }
+ else
+ throw new TInvalidDataValueException('multiview_activeviewindex_invalid',$index);
+ }
+
+ /**
+ * @return TView the currently active view, null if no active view
+ * @throws TInvalidDataValueException if the current active view index is invalid
+ */
+ public function getActiveView()
+ {
+ $index=$this->getActiveViewIndex();
+ $views=$this->getViews();
+ if($index>=$views->getCount())
+ throw new TInvalidDataValueException('multiview_activeviewindex_invalid',$index);
+ if($index<0)
+ return null;
+ $view=$views->itemAt($index);
+ if(!$view->getActive())
+ $this->activateView($view,false);
+ return $view;
+ }
+
+ /**
+ * @param TView the view to be activated
+ * @throws TInvalidOperationException if the view is not in the view collection
+ */
+ public function setActiveView($view)
+ {
+ if(($index=$this->getViews()->indexOf($view))>=0)
+ $this->setActiveViewIndex($index);
+ else
+ throw new TInvalidOperationException('multiview_view_inexistent');
+ }
+
+ /**
+ * Activates the specified view.
+ * If there is any view currently active, it will be deactivated.
+ * @param TView the view to be activated
+ * @param boolean whether to trigger OnActiveViewChanged event.
+ */
+ protected function activateView($view,$triggerViewChangedEvent=true)
+ {
+ if($view->getActive())
+ return;
+ $triggerEvent=$triggerViewChangedEvent && ($this->getControlStage()>=TControl::CS_STATE_LOADED || ($this->getPage() && !$this->getPage()->getIsPostBack()));
+ foreach($this->getViews() as $v)
+ {
+ if($v===$view)
+ {
+ $view->setActive(true);
+ if($triggerEvent)
+ {
+ $view->onActivate(null);
+ $this->onActiveViewChanged(null);
+ }
+ }
+ else if($v->getActive())
+ {
+ $v->setActive(false);
+ if($triggerEvent)
+ $v->onDeactivate(null);
+ }
+ }
+ }
+
+ /**
+ * @return TViewCollection the view collection
+ */
+ public function getViews()
+ {
+ return $this->getControls();
+ }
+
+ /**
+ * Makes the multiview ignore all bubbled events.
+ * This is method is used internally by framework and control
+ * developers.
+ */
+ public function ignoreBubbleEvents()
+ {
+ $this->_ignoreBubbleEvents=true;
+ }
+
+ /**
+ * Initializes the active view if any.
+ * This method overrides the parent implementation.
+ * @param TEventParameter event parameter
+ */
+ public function onInit($param)
+ {
+ parent::onInit($param);
+ if($this->_cachedActiveViewIndex>=0)
+ $this->setActiveViewIndex($this->_cachedActiveViewIndex);
+ }
+
+ /**
+ * Raises <b>OnActiveViewChanged</b> event.
+ * The event is raised when the currently active view is changed to a new one
+ * @param TEventParameter event parameter
+ */
+ public function onActiveViewChanged($param)
+ {
+ $this->raiseEvent('OnActiveViewChanged',$this,$param);
+ }
+
+ /**
+ * Processes the events bubbled from child controls.
+ * The method handles view-related command events.
+ * @param TControl sender of the event
+ * @param mixed event parameter
+ * @return boolean whether this event is handled
+ */
+ public function bubbleEvent($sender,$param)
+ {
+ if(!$this->_ignoreBubbleEvents && ($param instanceof TCommandEventParameter))
+ {
+ switch($param->getCommandName())
+ {
+ case self::CMD_NEXTVIEW:
+ if(($index=$this->getActiveViewIndex())<$this->getViews()->getCount()-1)
+ $this->setActiveViewIndex($index+1);
+ else
+ $this->setActiveViewIndex(-1);
+ return true;
+ case self::CMD_PREVIOUSVIEW:
+ if(($index=$this->getActiveViewIndex())>=0)
+ $this->setActiveViewIndex($index-1);
+ return true;
+ case self::CMD_SWITCHVIEWID:
+ $view=$this->findControl($viewID=$param->getCommandParameter());
+ if($view!==null && $view->getParent()===$this)
+ {
+ $this->setActiveView($view);
+ return true;
+ }
+ else
+ throw new TInvalidDataValueException('multiview_viewid_invalid', $viewID);
+ case self::CMD_SWITCHVIEWINDEX:
+ $index=TPropertyValue::ensureInteger($param->getCommandParameter());
+ $this->setActiveViewIndex($index);
+ return true;
+ }
+ }
+ return false;
+ }
+
+ /**
+ * Loads state into the wizard.
+ * This method is invoked by the framework when the control state is being saved.
+ */
+ public function loadState()
+ {
+ // a dummy call to ensure the view is activated
+ $this->getActiveView();
+ }
+
+ /**
+ * Renders the currently active view.
+ * @param THtmlWriter the writer for the rendering purpose.
+ */
+ public function render($writer)
+ {
+ if(($view=$this->getActiveView())!==null)
+ $view->renderControl($writer);
+ }
+}
+
+/**
+ * TViewCollection class.
+ * TViewCollection represents a collection that only takes {@link TView} instances
+ * as collection elements.
+ * @author Qiang Xue <qiang.xue@gmail.com>
+ * @version $Id$
+ * @package System.Web.UI.WebControls
+ * @since 3.0
+ */
+class TViewCollection extends TControlCollection
+{
+ /**
+ * Inserts an item at the specified position.
+ * This overrides the parent implementation by ensuring only {@link TView}
+ * controls be added into the collection.
+ * @param integer the speicified position.
+ * @param mixed new item
+ * @throws TInvalidDataTypeException if the item to be inserted is neither a string nor a TControl.
+ */
+ public function insertAt($index,$item)
+ {
+ if($item instanceof TView)
+ parent::insertAt($index,$item);
+ else
+ throw new TInvalidDataTypeException('viewcollection_view_required');
+ }
+}
+
+/**
+ * TView class
+ *
+ * TView is a container for a group of controls. TView must be contained
+ * within a {@link TMultiView} control in which only one view can be active
+ * at one time.
+ *
+ * To activate a view, set {@link setActive Active} to true.
+ * When a view is activated, it raises {@link onActivate OnActivate} event;
+ * and when a view is deactivated, it raises {@link onDeactivate OnDeactivate}.
+ *
+ * @author Qiang Xue <qiang.xue@gmail.com>
+ * @version $Id$
+ * @package System.Web.UI.WebControls
+ * @since 3.0
+ */
+class TView extends TControl
+{
+ private $_active=false;
+
+ /**
+ * Raises <b>OnActivate</b> event.
+ * @param TEventParameter event parameter
+ */
+ public function onActivate($param)
+ {
+ $this->raiseEvent('OnActivate',$this,$param);
+ }
+
+ /**
+ * Raises <b>OnDeactivate</b> event.
+ * @param TEventParameter event parameter
+ */
+ public function onDeactivate($param)
+ {
+ $this->raiseEvent('OnDeactivate',$this,$param);
+ }
+
+ /**
+ * @return boolean whether this view is active. Defaults to false.
+ */
+ public function getActive()
+ {
+ return $this->_active;
+ }
+
+ /**
+ * @param boolean whether this view is active.
+ */
+ public function setActive($value)
+ {
+ $value=TPropertyValue::ensureBoolean($value);
+ $this->_active=$value;
+ parent::setVisible($value);
+ }
+
+ /**
+ * @param boolean whether the parents should also be checked if visible
+ * @return boolean whether this view is visible.
+ * The view is visible if it is active and its parent is visible.
+ */
+ public function getVisible($checkParents=true)
+ {
+ if(($parent=$this->getParent())===null)
+ return $this->getActive();
+ else if($this->getActive())
+ return $parent->getVisible($checkParents);
+ else
+ return false;
+ }
+
+ /**
+ * @param boolean
+ * @throws TInvalidOperationException whenever this method is invoked.
+ */
+ public function setVisible($value)
+ {
+ throw new TInvalidOperationException('view_visible_readonly');
+ }
+}
+
diff --git a/framework/Web/UI/WebControls/TOutputCache.php b/framework/Web/UI/WebControls/TOutputCache.php
index 64e4ff42..cc79e76f 100644
--- a/framework/Web/UI/WebControls/TOutputCache.php
+++ b/framework/Web/UI/WebControls/TOutputCache.php
@@ -1,621 +1,621 @@
-<?php
-/**
- * TOutputCache class file
- *
- * @author Qiang Xue <qiang.xue@gmail.com>
- * @link http://www.pradosoft.com/
+<?php
+/**
+ * TOutputCache class file
+ *
+ * @author Qiang Xue <qiang.xue@gmail.com>
+ * @link http://www.pradosoft.com/
* @copyright Copyright &copy; 2005-2012 PradoSoft
- * @license http://www.pradosoft.com/license/
- * @version $Id$
- * @package System.Web.UI.WebControls
- */
-
-/**
- * TOutputCache class.
- *
- * TOutputCache enables caching a portion of a Web page, also known as
- * partial caching. The content being cached can be either static or
- * dynamic.
- *
- * To use TOutputCache, simply enclose the content to be cached
- * within the TOutputCache component tag on a template, e.g.,
- * <code>
- * <com:TOutputCache>
- * content to be cached
- * </com:TOutputCache>
- * </code>
- * where content to be cached can be static text and/or component tags.
- *
- * The validity of the cached content is determined based on two factors:
- * the {@link setDuration Duration} and the cache dependency.
- * The former specifies the number of seconds that the data can remain
- * valid in cache (defaults to 60s), while the latter specifies conditions
- * that the cached data depends on. If a dependency changes,
- * (e.g. relevant data in DB are updated), the cached data will be invalidated.
- *
- * There are two ways to specify cache dependency. One may write event handlers
- * to respond to the {@link onCheckDependency OnCheckDependency} event and set
- * the event parameter's {@link TOutputCacheCheckDependencyEventParameter::getIsValid IsValid}
- * property to indicate whether the cached data remains valid or not.
- * One can also extend TOutputCache and override its {@link getCacheDependency}
- * function. While the former is easier to use, the latter offers more extensibility.
- *
- * The content fetched from cache may be variated with respect to
- * some parameters. It supports variation with respect to request parameters,
- * which is specified by {@link setVaryByParam VaryByParam} property.
- * If a specified request parameter is different, a different version of
- * cached content is used. This is extremely useful if a page's content
- * may be variated according to some GET parameters.
- * The content being cached may also be variated with user sessions if
- * {@link setVaryBySession VaryBySession} is set true.
- * To variate the cached content by other factors, override {@link calculateCacheKey()} method.
- *
- * Output caches can be nested. An outer cache takes precedence over an
- * inner cache. This means, if the content cached by the inner cache expires
- * or is invalidated, while that by the outer cache not, the outer cached
- * content will be used.
- *
- * Note, TOutputCache is effective only for non-postback page requests
- * and when cache module is enabled.
- *
- * Do not attempt to address child controls of TOutputCache when the cached
- * content is to be used. Use {@link getContentCached ContentCached} property
- * to determine whether the content is cached or not.
- *
- * @author Qiang Xue <qiang.xue@gmail.com>
- * @version $Id$
- * @package System.Web.UI.WebControls
- * @since 3.1
- */
-class TOutputCache extends TControl implements INamingContainer
-{
- const CACHE_ID_PREFIX='prado:outputcache';
- private $_cacheModuleID='';
- private $_dataCached=false;
- private $_cacheAvailable=false;
- private $_cacheChecked=false;
- private $_cacheKey=null;
- private $_duration=60;
- private $_cache=null;
- private $_contents;
- private $_state;
- private $_actions=array();
- private $_varyByParam='';
- private $_keyPrefix='';
- private $_varyBySession=false;
- private $_cachePostBack=false;
- private $_cacheTime=0;
-
- /**
- * Returns a value indicating whether body contents are allowed for this control.
- * This method overrides the parent implementation by checking if cached
- * content is available or not. If yes, it returns false, otherwise true.
- * @param boolean whether body contents are allowed for this control.
- */
- public function getAllowChildControls()
- {
- $this->determineCacheability();
- return !$this->_dataCached;
- }
-
- private function determineCacheability()
- {
- if(!$this->_cacheChecked)
- {
- $this->_cacheChecked=true;
- if($this->_duration>0 && ($this->_cachePostBack || !$this->getPage()->getIsPostBack()))
- {
- if($this->_cacheModuleID!=='')
- {
- $this->_cache=$this->getApplication()->getModule($this->_cacheModuleID);
- if(!($this->_cache instanceof ICache))
- throw new TConfigurationException('outputcache_cachemoduleid_invalid',$this->_cacheModuleID);
- }
- else
- $this->_cache=$this->getApplication()->getCache();
- if($this->_cache!==null)
- {
- $this->_cacheAvailable=true;
- $data=$this->_cache->get($this->getCacheKey());
- if(is_array($data))
- {
- $param=new TOutputCacheCheckDependencyEventParameter;
- $param->setCacheTime(isset($data[3])?$data[3]:0);
- $this->onCheckDependency($param);
- $this->_dataCached=$param->getIsValid();
- }
- else
- $this->_dataCached=false;
- if($this->_dataCached)
- list($this->_contents,$this->_state,$this->_actions,$this->_cacheTime)=$data;
- }
- }
- }
- }
-
- /**
- * Performs the Init step for the control and all its child controls.
- * This method overrides the parent implementation by setting up
- * the stack of the output cache in the page.
- * Only framework developers should use this method.
- * @param TControl the naming container control
- */
- protected function initRecursive($namingContainer=null)
- {
- if($this->_cacheAvailable && !$this->_dataCached)
- {
- $stack=$this->getPage()->getCachingStack();
- $stack->push($this);
- parent::initRecursive($namingContainer);
- $stack->pop();
- }
- else
- parent::initRecursive($namingContainer);
- }
-
- /**
- * Performs the Load step for the control and all its child controls.
- * This method overrides the parent implementation by setting up
- * the stack of the output cache in the page. If the data is restored
- * from cache, it also recovers the actions associated with the cached data.
- * Only framework developers should use this method.
- * @param TControl the naming container control
- */
- protected function loadRecursive()
- {
- if($this->_cacheAvailable && !$this->_dataCached)
- {
- $stack=$this->getPage()->getCachingStack();
- $stack->push($this);
- parent::loadRecursive();
- $stack->pop();
- }
- else
- {
- if($this->_dataCached)
- $this->performActions();
- parent::loadRecursive();
- }
- }
-
- private function performActions()
- {
- $page=$this->getPage();
- $cs=$page->getClientScript();
- foreach($this->_actions as $action)
- {
- if($action[0]==='Page.ClientScript')
- call_user_func_array(array($cs,$action[1]),$action[2]);
- else if($action[0]==='Page')
- call_user_func_array(array($page,$action[1]),$action[2]);
- else
- call_user_func_array(array($this->getSubProperty($action[0]),$action[1]),$action[2]);
- }
- }
-
- /**
- * Performs the PreRender step for the control and all its child controls.
- * This method overrides the parent implementation by setting up
- * the stack of the output cache in the page.
- * Only framework developers should use this method.
- * @param TControl the naming container control
- */
- protected function preRenderRecursive()
- {
- if($this->_cacheAvailable && !$this->_dataCached)
- {
- $stack=$this->getPage()->getCachingStack();
- $stack->push($this);
- parent::preRenderRecursive();
- $stack->pop();
- }
- else
- parent::preRenderRecursive();
- }
-
- /**
- * Loads state (viewstate and controlstate) into a control and its children.
- * This method overrides the parent implementation by loading
- * cached state if available.
- * This method should only be used by framework developers.
- * @param array the collection of the state
- * @param boolean whether the viewstate should be loaded
- */
- protected function loadStateRecursive(&$state,$needViewState=true)
- {
- $st=unserialize($state);
- parent::loadStateRecursive($st,$needViewState);
- }
-
- /**
- * Saves all control state (viewstate and controlstate) as a collection.
- * This method overrides the parent implementation by saving state
- * into cache if needed.
- * This method should only be used by framework developers.
- * @param boolean whether the viewstate should be saved
- * @return array the collection of the control state (including its children's state).
- */
- protected function &saveStateRecursive($needViewState=true)
- {
- if($this->_dataCached)
- return $this->_state;
- else
- {
- $st=parent::saveStateRecursive($needViewState);
- // serialization is needed to avoid undefined classes when loading state
- $this->_state=serialize($st);
- return $this->_state;
- }
- }
-
- /**
- * Registers an action associated with the content being cached.
- * The registered action will be replayed if the content stored
- * in the cache is served to end-users.
- * @param string context of the action method. This is a property-path
- * referring to the context object (e.g. Page, Page.ClientScript)
- * @param string method name of the context object
- * @param array list of parameters to be passed to the action method
- */
- public function registerAction($context,$funcName,$funcParams)
- {
- $this->_actions[]=array($context,$funcName,$funcParams);
- }
-
- public function getCacheKey()
- {
- if($this->_cacheKey===null)
- $this->_cacheKey=$this->calculateCacheKey();
- return $this->_cacheKey;
- }
-
- /**
- * Calculates the cache key.
- * The key is calculated based on the unique ID of this control
- * and the request parameters specified via {@link setVaryByParam VaryByParam}.
- * If {@link getVaryBySession VaryBySession} is true, the session ID
- * will also participate in the key calculation.
- * This method may be overriden to support other variations in
- * the calculated cache key.
- * @return string cache key
- */
- protected function calculateCacheKey()
- {
- $key=$this->getBaseCacheKey();
- if($this->_varyBySession)
- $key.=$this->getSession()->getSessionID();
- if($this->_varyByParam!=='')
- {
- $params=array();
- $request=$this->getRequest();
- foreach(explode(',',$this->_varyByParam) as $name)
- {
- $name=trim($name);
- $params[$name]=$request->itemAt($name);
- }
- $key.=serialize($params);
- }
- $param=new TOutputCacheCalculateKeyEventParameter;
- $this->onCalculateKey($param);
- $key.=$param->getCacheKey();
- return $key;
- }
-
- /**
- * @return string basic cache key without variations
- */
- protected function getBaseCacheKey()
- {
- return self::CACHE_ID_PREFIX.$this->_keyPrefix.$this->getPage()->getPagePath().$this->getUniqueID();
- }
-
- /**
- * @return string the ID of the cache module. Defaults to '', meaning the primary cache module is used.
- */
- public function getCacheModuleID()
- {
- return $this->_cacheModuleID;
- }
-
- /**
- * @param string the ID of the cache module. If empty, the primary cache module will be used.
- */
- public function setCacheModuleID($value)
- {
- $this->_cacheModuleID=$value;
- }
-
- /**
- * Sets the prefix of the cache key.
- * This method is used internally by {@link TTemplate}.
- * @param string key prefix
- */
- public function setCacheKeyPrefix($value)
- {
- $this->_keyPrefix=$value;
- }
-
- /**
- * @return integer the timestamp of the cached content. This is only valid if the content is being cached.
- * @since 3.1.1
- */
- public function getCacheTime()
- {
- return $this->_cacheTime;
- }
-
- /**
- * Returns the dependency of the data to be cached.
- * The default implementation simply returns null, meaning no specific dependency.
- * This method may be overriden to associate the data to be cached
- * with additional dependencies.
- * @return ICacheDependency
- */
- protected function getCacheDependency()
- {
- return null;
- }
-
- /**
- * @return boolean whether content enclosed is cached or not
- */
- public function getContentCached()
- {
- return $this->_dataCached;
- }
-
- /**
- * @return integer number of seconds that the data can remain in cache. Defaults to 60 seconds.
- * Note, if cache dependency changes or cache space is limited,
- * the data may be purged out of cache earlier.
- */
- public function getDuration()
- {
- return $this->_duration;
- }
-
- /**
- * @param integer number of seconds that the data can remain in cache. If 0, it means data is not cached.
- * @throws TInvalidDataValueException if the value is smaller than 0.
- */
- public function setDuration($value)
- {
- if(($value=TPropertyValue::ensureInteger($value))<0)
- throw new TInvalidDataValueException('outputcache_duration_invalid',get_class($this));
- $this->_duration=$value;
- }
-
- /**
- * @return string a semicolon-separated list of strings used to vary the output cache. Defaults to ''.
- */
- public function getVaryByParam()
- {
- return $this->_varyByParam;
- }
-
- /**
- * Sets the names of the request parameters that should be used in calculating the cache key.
- * The names should be concatenated by semicolons.
- * By setting this value, the output cache will use different cached data
- * for each different set of request parameter values.
- * @return string a semicolon-separated list of strings used to vary the output cache.
- */
- public function setVaryByParam($value)
- {
- $this->_varyByParam=trim($value);
- }
-
- /**
- * @return boolean whether the content being cached should be differentiated according to user sessions. Defaults to false.
- */
- public function getVaryBySession()
- {
- return $this->_varyBySession;
- }
-
- /**
- * @param boolean whether the content being cached should be differentiated according to user sessions.
- */
- public function setVaryBySession($value)
- {
- $this->_varyBySession=TPropertyValue::ensureBoolean($value);
- }
-
- /**
- * @return boolean whether cached output will be used on postback requests. Defaults to false.
- */
- public function getCachingPostBack()
- {
- return $this->_cachePostBack;
- }
-
- /**
- * Sets a value indicating whether cached output will be used on postback requests.
- * By default, this is disabled. Be very cautious when enabling it.
- * If the cached content including interactive user controls such as
- * TTextBox, TDropDownList, your page may fail to render on postbacks.
- * @param boolean whether cached output will be used on postback requests.
- */
- public function setCachingPostBack($value)
- {
- $this->_cachePostBack=TPropertyValue::ensureBoolean($value);
- }
-
- /**
- * This event is raised when the output cache is checking cache dependency.
- * An event handler may be written to check customized dependency conditions.
- * The checking result should be saved by setting {@link TOutputCacheCheckDependencyEventParameter::setIsValid IsValid}
- * property of the event parameter (which defaults to true).
- * @param TOutputCacheCheckDependencyEventParameter event parameter
- */
- public function onCheckDependency($param)
- {
- $this->raiseEvent('OnCheckDependency',$this,$param);
- }
-
- /**
- * This event is raised when the output cache is calculating cache key.
- * By varying cache keys, one can obtain different versions of cached content.
- * An event handler may be written to add variety of the key calculation.
- * The value set in {@link TOutputCacheCalculateKeyEventParameter::setCacheKey CacheKey} of
- * this event parameter will be appended to the default key calculation scheme.
- * @param TOutputCacheCalculateKeyEventParameter event parameter
- */
- public function onCalculateKey($param)
- {
- $this->raiseEvent('OnCalculateKey',$this,$param);
- }
-
- /**
- * Renders the output cache control.
- * This method overrides the parent implementation by capturing the output
- * from its child controls and saving it into cache, if output cache is needed.
- * @param THtmlWriter
- */
- public function render($writer)
- {
- if($this->_dataCached)
- $writer->write($this->_contents);
- else if($this->_cacheAvailable)
- {
- $textwriter = new TTextWriter();
- $multiwriter = new TOutputCacheTextWriterMulti(array($writer->getWriter(),$textwriter));
- $htmlWriter = Prado::createComponent($this->GetResponse()->getHtmlWriterType(), $multiwriter);
-
- $stack=$this->getPage()->getCachingStack();
- $stack->push($this);
- parent::render($htmlWriter);
- $stack->pop();
-
- $content=$textwriter->flush();
- $data=array($content,$this->_state,$this->_actions,time());
- $this->_cache->set($this->getCacheKey(),$data,$this->getDuration(),$this->getCacheDependency());
- }
- else
- parent::render($writer);
- }
-}
-
-/**
- * TOutputCacheCheckDependencyEventParameter class
- *
- * TOutputCacheCheckDependencyEventParameter encapsulates the parameter data for
- * <b>OnCheckDependency</b> event of {@link TOutputCache} control.
- *
- * @author Qiang Xue <qiang.xue@gmail.com>
- * @version $Id$
- * @package System.Web.UI.WebControls
- * @since 3.0
- */
-class TOutputCacheCheckDependencyEventParameter extends TEventParameter
-{
- private $_isValid=true;
- private $_cacheTime=0;
-
- /**
- * @return boolean whether the dependency remains valid. Defaults to true.
- */
- public function getIsValid()
- {
- return $this->_isValid;
- }
-
- /**
- * @param boolean whether the dependency remains valid
- */
- public function setIsValid($value)
- {
- $this->_isValid=TPropertyValue::ensureBoolean($value);
- }
-
- /**
- * @return integer the timestamp of the cached result. You may use this to help determine any dependency is changed.
- * @since 3.1.1
- */
- public function getCacheTime()
- {
- return $this->_cacheTime;
- }
-
- /**
- * @param integer the timestamp of the cached result. This is used internally.
- * @since 3.1.1
- */
- public function setCacheTime($value)
- {
- $this->_cacheTime=TPropertyValue::ensureInteger($value);
- }
-}
-
-
-/**
- * TOutputCacheCalculateKeyEventParameter class
- *
- * TOutputCacheCalculateKeyEventParameter encapsulates the parameter data for
- * <b>OnCalculateKey</b> event of {@link TOutputCache} control.
- *
- * @author Qiang Xue <qiang.xue@gmail.com>
- * @version $Id$
- * @package System.Web.UI.WebControls
- * @since 3.0
- */
-class TOutputCacheCalculateKeyEventParameter extends TEventParameter
-{
- /**
- * @var string cache key to be appended to the default calculation scheme.
- */
- private $_cacheKey='';
-
- /**
- * @return string cache key to be appended to the default calculation scheme.
- */
- public function getCacheKey()
- {
- return $this->_cacheKey;
- }
-
- /**
- * @param string cache key to be appended to the default calculation scheme
- */
- public function setCacheKey($value)
- {
- $this->_cacheKey=TPropertyValue::ensureString($value);
- }
-}
-
-/**
- * TOutputCacheTextWriterMulti class
- *
- * TOutputCacheTextWriterMulti is an internal class used by
- * TOutputCache to write simultaneously to multiple writers.
- *
- * @author Gabor Berczi, DevWorx Hungary <gabor.berczi@devworx.hu>
- * @author Qiang Xue <qiang.xue@gmail.com>
- * @version $Id$
- * @package System.Web.UI.WebControls
- * @since 3.2
- */
-class TOutputCacheTextWriterMulti extends TTextWriter
-{
- protected $_writers;
-
- public function __construct(Array $writers)
- {
- //parent::__construct();
- $this->_writers = $writers;
- }
-
- public function write($s)
- {
- foreach($this->_writers as $writer)
- $writer->write($s);
- }
-
- public function flush()
- {
- foreach($this->_writers as $writer)
- $s = $writer->flush();
- return $s;
- }
-}
-
+ * @license http://www.pradosoft.com/license/
+ * @version $Id$
+ * @package System.Web.UI.WebControls
+ */
+
+/**
+ * TOutputCache class.
+ *
+ * TOutputCache enables caching a portion of a Web page, also known as
+ * partial caching. The content being cached can be either static or
+ * dynamic.
+ *
+ * To use TOutputCache, simply enclose the content to be cached
+ * within the TOutputCache component tag on a template, e.g.,
+ * <code>
+ * <com:TOutputCache>
+ * content to be cached
+ * </com:TOutputCache>
+ * </code>
+ * where content to be cached can be static text and/or component tags.
+ *
+ * The validity of the cached content is determined based on two factors:
+ * the {@link setDuration Duration} and the cache dependency.
+ * The former specifies the number of seconds that the data can remain
+ * valid in cache (defaults to 60s), while the latter specifies conditions
+ * that the cached data depends on. If a dependency changes,
+ * (e.g. relevant data in DB are updated), the cached data will be invalidated.
+ *
+ * There are two ways to specify cache dependency. One may write event handlers
+ * to respond to the {@link onCheckDependency OnCheckDependency} event and set
+ * the event parameter's {@link TOutputCacheCheckDependencyEventParameter::getIsValid IsValid}
+ * property to indicate whether the cached data remains valid or not.
+ * One can also extend TOutputCache and override its {@link getCacheDependency}
+ * function. While the former is easier to use, the latter offers more extensibility.
+ *
+ * The content fetched from cache may be variated with respect to
+ * some parameters. It supports variation with respect to request parameters,
+ * which is specified by {@link setVaryByParam VaryByParam} property.
+ * If a specified request parameter is different, a different version of
+ * cached content is used. This is extremely useful if a page's content
+ * may be variated according to some GET parameters.
+ * The content being cached may also be variated with user sessions if
+ * {@link setVaryBySession VaryBySession} is set true.
+ * To variate the cached content by other factors, override {@link calculateCacheKey()} method.
+ *
+ * Output caches can be nested. An outer cache takes precedence over an
+ * inner cache. This means, if the content cached by the inner cache expires
+ * or is invalidated, while that by the outer cache not, the outer cached
+ * content will be used.
+ *
+ * Note, TOutputCache is effective only for non-postback page requests
+ * and when cache module is enabled.
+ *
+ * Do not attempt to address child controls of TOutputCache when the cached
+ * content is to be used. Use {@link getContentCached ContentCached} property
+ * to determine whether the content is cached or not.
+ *
+ * @author Qiang Xue <qiang.xue@gmail.com>
+ * @version $Id$
+ * @package System.Web.UI.WebControls
+ * @since 3.1
+ */
+class TOutputCache extends TControl implements INamingContainer
+{
+ const CACHE_ID_PREFIX='prado:outputcache';
+ private $_cacheModuleID='';
+ private $_dataCached=false;
+ private $_cacheAvailable=false;
+ private $_cacheChecked=false;
+ private $_cacheKey=null;
+ private $_duration=60;
+ private $_cache=null;
+ private $_contents;
+ private $_state;
+ private $_actions=array();
+ private $_varyByParam='';
+ private $_keyPrefix='';
+ private $_varyBySession=false;
+ private $_cachePostBack=false;
+ private $_cacheTime=0;
+
+ /**
+ * Returns a value indicating whether body contents are allowed for this control.
+ * This method overrides the parent implementation by checking if cached
+ * content is available or not. If yes, it returns false, otherwise true.
+ * @param boolean whether body contents are allowed for this control.
+ */
+ public function getAllowChildControls()
+ {
+ $this->determineCacheability();
+ return !$this->_dataCached;
+ }
+
+ private function determineCacheability()
+ {
+ if(!$this->_cacheChecked)
+ {
+ $this->_cacheChecked=true;
+ if($this->_duration>0 && ($this->_cachePostBack || !$this->getPage()->getIsPostBack()))
+ {
+ if($this->_cacheModuleID!=='')
+ {
+ $this->_cache=$this->getApplication()->getModule($this->_cacheModuleID);
+ if(!($this->_cache instanceof ICache))
+ throw new TConfigurationException('outputcache_cachemoduleid_invalid',$this->_cacheModuleID);
+ }
+ else
+ $this->_cache=$this->getApplication()->getCache();
+ if($this->_cache!==null)
+ {
+ $this->_cacheAvailable=true;
+ $data=$this->_cache->get($this->getCacheKey());
+ if(is_array($data))
+ {
+ $param=new TOutputCacheCheckDependencyEventParameter;
+ $param->setCacheTime(isset($data[3])?$data[3]:0);
+ $this->onCheckDependency($param);
+ $this->_dataCached=$param->getIsValid();
+ }
+ else
+ $this->_dataCached=false;
+ if($this->_dataCached)
+ list($this->_contents,$this->_state,$this->_actions,$this->_cacheTime)=$data;
+ }
+ }
+ }
+ }
+
+ /**
+ * Performs the Init step for the control and all its child controls.
+ * This method overrides the parent implementation by setting up
+ * the stack of the output cache in the page.
+ * Only framework developers should use this method.
+ * @param TControl the naming container control
+ */
+ protected function initRecursive($namingContainer=null)
+ {
+ if($this->_cacheAvailable && !$this->_dataCached)
+ {
+ $stack=$this->getPage()->getCachingStack();
+ $stack->push($this);
+ parent::initRecursive($namingContainer);
+ $stack->pop();
+ }
+ else
+ parent::initRecursive($namingContainer);
+ }
+
+ /**
+ * Performs the Load step for the control and all its child controls.
+ * This method overrides the parent implementation by setting up
+ * the stack of the output cache in the page. If the data is restored
+ * from cache, it also recovers the actions associated with the cached data.
+ * Only framework developers should use this method.
+ * @param TControl the naming container control
+ */
+ protected function loadRecursive()
+ {
+ if($this->_cacheAvailable && !$this->_dataCached)
+ {
+ $stack=$this->getPage()->getCachingStack();
+ $stack->push($this);
+ parent::loadRecursive();
+ $stack->pop();
+ }
+ else
+ {
+ if($this->_dataCached)
+ $this->performActions();
+ parent::loadRecursive();
+ }
+ }
+
+ private function performActions()
+ {
+ $page=$this->getPage();
+ $cs=$page->getClientScript();
+ foreach($this->_actions as $action)
+ {
+ if($action[0]==='Page.ClientScript')
+ call_user_func_array(array($cs,$action[1]),$action[2]);
+ else if($action[0]==='Page')
+ call_user_func_array(array($page,$action[1]),$action[2]);
+ else
+ call_user_func_array(array($this->getSubProperty($action[0]),$action[1]),$action[2]);
+ }
+ }
+
+ /**
+ * Performs the PreRender step for the control and all its child controls.
+ * This method overrides the parent implementation by setting up
+ * the stack of the output cache in the page.
+ * Only framework developers should use this method.
+ * @param TControl the naming container control
+ */
+ protected function preRenderRecursive()
+ {
+ if($this->_cacheAvailable && !$this->_dataCached)
+ {
+ $stack=$this->getPage()->getCachingStack();
+ $stack->push($this);
+ parent::preRenderRecursive();
+ $stack->pop();
+ }
+ else
+ parent::preRenderRecursive();
+ }
+
+ /**
+ * Loads state (viewstate and controlstate) into a control and its children.
+ * This method overrides the parent implementation by loading
+ * cached state if available.
+ * This method should only be used by framework developers.
+ * @param array the collection of the state
+ * @param boolean whether the viewstate should be loaded
+ */
+ protected function loadStateRecursive(&$state,$needViewState=true)
+ {
+ $st=unserialize($state);
+ parent::loadStateRecursive($st,$needViewState);
+ }
+
+ /**
+ * Saves all control state (viewstate and controlstate) as a collection.
+ * This method overrides the parent implementation by saving state
+ * into cache if needed.
+ * This method should only be used by framework developers.
+ * @param boolean whether the viewstate should be saved
+ * @return array the collection of the control state (including its children's state).
+ */
+ protected function &saveStateRecursive($needViewState=true)
+ {
+ if($this->_dataCached)
+ return $this->_state;
+ else
+ {
+ $st=parent::saveStateRecursive($needViewState);
+ // serialization is needed to avoid undefined classes when loading state
+ $this->_state=serialize($st);
+ return $this->_state;
+ }
+ }
+
+ /**
+ * Registers an action associated with the content being cached.
+ * The registered action will be replayed if the content stored
+ * in the cache is served to end-users.
+ * @param string context of the action method. This is a property-path
+ * referring to the context object (e.g. Page, Page.ClientScript)
+ * @param string method name of the context object
+ * @param array list of parameters to be passed to the action method
+ */
+ public function registerAction($context,$funcName,$funcParams)
+ {
+ $this->_actions[]=array($context,$funcName,$funcParams);
+ }
+
+ public function getCacheKey()
+ {
+ if($this->_cacheKey===null)
+ $this->_cacheKey=$this->calculateCacheKey();
+ return $this->_cacheKey;
+ }
+
+ /**
+ * Calculates the cache key.
+ * The key is calculated based on the unique ID of this control
+ * and the request parameters specified via {@link setVaryByParam VaryByParam}.
+ * If {@link getVaryBySession VaryBySession} is true, the session ID
+ * will also participate in the key calculation.
+ * This method may be overriden to support other variations in
+ * the calculated cache key.
+ * @return string cache key
+ */
+ protected function calculateCacheKey()
+ {
+ $key=$this->getBaseCacheKey();
+ if($this->_varyBySession)
+ $key.=$this->getSession()->getSessionID();
+ if($this->_varyByParam!=='')
+ {
+ $params=array();
+ $request=$this->getRequest();
+ foreach(explode(',',$this->_varyByParam) as $name)
+ {
+ $name=trim($name);
+ $params[$name]=$request->itemAt($name);
+ }
+ $key.=serialize($params);
+ }
+ $param=new TOutputCacheCalculateKeyEventParameter;
+ $this->onCalculateKey($param);
+ $key.=$param->getCacheKey();
+ return $key;
+ }
+
+ /**
+ * @return string basic cache key without variations
+ */
+ protected function getBaseCacheKey()
+ {
+ return self::CACHE_ID_PREFIX.$this->_keyPrefix.$this->getPage()->getPagePath().$this->getUniqueID();
+ }
+
+ /**
+ * @return string the ID of the cache module. Defaults to '', meaning the primary cache module is used.
+ */
+ public function getCacheModuleID()
+ {
+ return $this->_cacheModuleID;
+ }
+
+ /**
+ * @param string the ID of the cache module. If empty, the primary cache module will be used.
+ */
+ public function setCacheModuleID($value)
+ {
+ $this->_cacheModuleID=$value;
+ }
+
+ /**
+ * Sets the prefix of the cache key.
+ * This method is used internally by {@link TTemplate}.
+ * @param string key prefix
+ */
+ public function setCacheKeyPrefix($value)
+ {
+ $this->_keyPrefix=$value;
+ }
+
+ /**
+ * @return integer the timestamp of the cached content. This is only valid if the content is being cached.
+ * @since 3.1.1
+ */
+ public function getCacheTime()
+ {
+ return $this->_cacheTime;
+ }
+
+ /**
+ * Returns the dependency of the data to be cached.
+ * The default implementation simply returns null, meaning no specific dependency.
+ * This method may be overriden to associate the data to be cached
+ * with additional dependencies.
+ * @return ICacheDependency
+ */
+ protected function getCacheDependency()
+ {
+ return null;
+ }
+
+ /**
+ * @return boolean whether content enclosed is cached or not
+ */
+ public function getContentCached()
+ {
+ return $this->_dataCached;
+ }
+
+ /**
+ * @return integer number of seconds that the data can remain in cache. Defaults to 60 seconds.
+ * Note, if cache dependency changes or cache space is limited,
+ * the data may be purged out of cache earlier.
+ */
+ public function getDuration()
+ {
+ return $this->_duration;
+ }
+
+ /**
+ * @param integer number of seconds that the data can remain in cache. If 0, it means data is not cached.
+ * @throws TInvalidDataValueException if the value is smaller than 0.
+ */
+ public function setDuration($value)
+ {
+ if(($value=TPropertyValue::ensureInteger($value))<0)
+ throw new TInvalidDataValueException('outputcache_duration_invalid',get_class($this));
+ $this->_duration=$value;
+ }
+
+ /**
+ * @return string a semicolon-separated list of strings used to vary the output cache. Defaults to ''.
+ */
+ public function getVaryByParam()
+ {
+ return $this->_varyByParam;
+ }
+
+ /**
+ * Sets the names of the request parameters that should be used in calculating the cache key.
+ * The names should be concatenated by semicolons.
+ * By setting this value, the output cache will use different cached data
+ * for each different set of request parameter values.
+ * @return string a semicolon-separated list of strings used to vary the output cache.
+ */
+ public function setVaryByParam($value)
+ {
+ $this->_varyByParam=trim($value);
+ }
+
+ /**
+ * @return boolean whether the content being cached should be differentiated according to user sessions. Defaults to false.
+ */
+ public function getVaryBySession()
+ {
+ return $this->_varyBySession;
+ }
+
+ /**
+ * @param boolean whether the content being cached should be differentiated according to user sessions.
+ */
+ public function setVaryBySession($value)
+ {
+ $this->_varyBySession=TPropertyValue::ensureBoolean($value);
+ }
+
+ /**
+ * @return boolean whether cached output will be used on postback requests. Defaults to false.
+ */
+ public function getCachingPostBack()
+ {
+ return $this->_cachePostBack;
+ }
+
+ /**
+ * Sets a value indicating whether cached output will be used on postback requests.
+ * By default, this is disabled. Be very cautious when enabling it.
+ * If the cached content including interactive user controls such as
+ * TTextBox, TDropDownList, your page may fail to render on postbacks.
+ * @param boolean whether cached output will be used on postback requests.
+ */
+ public function setCachingPostBack($value)
+ {
+ $this->_cachePostBack=TPropertyValue::ensureBoolean($value);
+ }
+
+ /**
+ * This event is raised when the output cache is checking cache dependency.
+ * An event handler may be written to check customized dependency conditions.
+ * The checking result should be saved by setting {@link TOutputCacheCheckDependencyEventParameter::setIsValid IsValid}
+ * property of the event parameter (which defaults to true).
+ * @param TOutputCacheCheckDependencyEventParameter event parameter
+ */
+ public function onCheckDependency($param)
+ {
+ $this->raiseEvent('OnCheckDependency',$this,$param);
+ }
+
+ /**
+ * This event is raised when the output cache is calculating cache key.
+ * By varying cache keys, one can obtain different versions of cached content.
+ * An event handler may be written to add variety of the key calculation.
+ * The value set in {@link TOutputCacheCalculateKeyEventParameter::setCacheKey CacheKey} of
+ * this event parameter will be appended to the default key calculation scheme.
+ * @param TOutputCacheCalculateKeyEventParameter event parameter
+ */
+ public function onCalculateKey($param)
+ {
+ $this->raiseEvent('OnCalculateKey',$this,$param);
+ }
+
+ /**
+ * Renders the output cache control.
+ * This method overrides the parent implementation by capturing the output
+ * from its child controls and saving it into cache, if output cache is needed.
+ * @param THtmlWriter
+ */
+ public function render($writer)
+ {
+ if($this->_dataCached)
+ $writer->write($this->_contents);
+ else if($this->_cacheAvailable)
+ {
+ $textwriter = new TTextWriter();
+ $multiwriter = new TOutputCacheTextWriterMulti(array($writer->getWriter(),$textwriter));
+ $htmlWriter = Prado::createComponent($this->GetResponse()->getHtmlWriterType(), $multiwriter);
+
+ $stack=$this->getPage()->getCachingStack();
+ $stack->push($this);
+ parent::render($htmlWriter);
+ $stack->pop();
+
+ $content=$textwriter->flush();
+ $data=array($content,$this->_state,$this->_actions,time());
+ $this->_cache->set($this->getCacheKey(),$data,$this->getDuration(),$this->getCacheDependency());
+ }
+ else
+ parent::render($writer);
+ }
+}
+
+/**
+ * TOutputCacheCheckDependencyEventParameter class
+ *
+ * TOutputCacheCheckDependencyEventParameter encapsulates the parameter data for
+ * <b>OnCheckDependency</b> event of {@link TOutputCache} control.
+ *
+ * @author Qiang Xue <qiang.xue@gmail.com>
+ * @version $Id$
+ * @package System.Web.UI.WebControls
+ * @since 3.0
+ */
+class TOutputCacheCheckDependencyEventParameter extends TEventParameter
+{
+ private $_isValid=true;
+ private $_cacheTime=0;
+
+ /**
+ * @return boolean whether the dependency remains valid. Defaults to true.
+ */
+ public function getIsValid()
+ {
+ return $this->_isValid;
+ }
+
+ /**
+ * @param boolean whether the dependency remains valid
+ */
+ public function setIsValid($value)
+ {
+ $this->_isValid=TPropertyValue::ensureBoolean($value);
+ }
+
+ /**
+ * @return integer the timestamp of the cached result. You may use this to help determine any dependency is changed.
+ * @since 3.1.1
+ */
+ public function getCacheTime()
+ {
+ return $this->_cacheTime;
+ }
+
+ /**
+ * @param integer the timestamp of the cached result. This is used internally.
+ * @since 3.1.1
+ */
+ public function setCacheTime($value)
+ {
+ $this->_cacheTime=TPropertyValue::ensureInteger($value);
+ }
+}
+
+
+/**
+ * TOutputCacheCalculateKeyEventParameter class
+ *
+ * TOutputCacheCalculateKeyEventParameter encapsulates the parameter data for
+ * <b>OnCalculateKey</b> event of {@link TOutputCache} control.
+ *
+ * @author Qiang Xue <qiang.xue@gmail.com>
+ * @version $Id$
+ * @package System.Web.UI.WebControls
+ * @since 3.0
+ */
+class TOutputCacheCalculateKeyEventParameter extends TEventParameter
+{
+ /**
+ * @var string cache key to be appended to the default calculation scheme.
+ */
+ private $_cacheKey='';
+
+ /**
+ * @return string cache key to be appended to the default calculation scheme.
+ */
+ public function getCacheKey()
+ {
+ return $this->_cacheKey;
+ }
+
+ /**
+ * @param string cache key to be appended to the default calculation scheme
+ */
+ public function setCacheKey($value)
+ {
+ $this->_cacheKey=TPropertyValue::ensureString($value);
+ }
+}
+
+/**
+ * TOutputCacheTextWriterMulti class
+ *
+ * TOutputCacheTextWriterMulti is an internal class used by
+ * TOutputCache to write simultaneously to multiple writers.
+ *
+ * @author Gabor Berczi, DevWorx Hungary <gabor.berczi@devworx.hu>
+ * @author Qiang Xue <qiang.xue@gmail.com>
+ * @version $Id$
+ * @package System.Web.UI.WebControls
+ * @since 3.2
+ */
+class TOutputCacheTextWriterMulti extends TTextWriter
+{
+ protected $_writers;
+
+ public function __construct(Array $writers)
+ {
+ //parent::__construct();
+ $this->_writers = $writers;
+ }
+
+ public function write($s)
+ {
+ foreach($this->_writers as $writer)
+ $writer->write($s);
+ }
+
+ public function flush()
+ {
+ foreach($this->_writers as $writer)
+ $s = $writer->flush();
+ return $s;
+ }
+}
+
diff --git a/framework/Web/UI/WebControls/TPager.php b/framework/Web/UI/WebControls/TPager.php
index 8e4bf2b0..11de5233 100644
--- a/framework/Web/UI/WebControls/TPager.php
+++ b/framework/Web/UI/WebControls/TPager.php
@@ -1,792 +1,792 @@
-<?php
-/**
- * TPager class file.
- *
- * @author Qiang Xue <qiang.xue@gmail.com>
- * @link http://www.pradosoft.com/
+<?php
+/**
+ * TPager class file.
+ *
+ * @author Qiang Xue <qiang.xue@gmail.com>
+ * @link http://www.pradosoft.com/
* @copyright Copyright &copy; 2005-2012 PradoSoft
- * @license http://www.pradosoft.com/license/
- * @version $Id$
- * @package System.Web.UI.WebControls
- */
-
-/**
- * TPager class.
- *
- * TPager creates a pager that provides UI for end-users to interactively
- * specify which page of data to be rendered in a {@link TDataBoundControl}-derived control,
- * such as {@link TDataList}, {@link TRepeater}, {@link TCheckBoxList}, etc.
- * The target data-bound control is specified by {@link setControlToPaginate ControlToPaginate},
- * which must be the ID path of the target control reaching from the pager's
- * naming container. Note, the target control must have its {@link TDataBoundControl::setAllowPaging AllowPaging}
- * set to true.
- *
- * TPager can display three different UIs, specified via {@link setMode Mode}:
- * - NextPrev: a next page and a previous page button are rendered.
- * - Numeric: a list of page index buttons are rendered.
- * - List: a dropdown list of page indices are rendered.
- *
- * When the pager mode is either NextPrev or Numeric, the paging buttons may be displayed
- * in three types by setting {@link setButtonType ButtonType}:
- * - LinkButton: a hyperlink button
- * - PushButton: a normal button
- * - ImageButton: an image button (please set XXXPageImageUrl properties accordingly to specify the button images.)
- *
- * TPager raises an {@link onPageIndexChanged OnPageIndexChanged} event when
- * the end-user interacts with it and specifies a new page (e.g. clicking
- * on a page button that leads to a new page.) The new page index may be obtained
- * from the event parameter's property {@link TPagerPageChangedEventParameter::getNewPageIndex NewPageIndex}.
- * Normally, in the event handler, one can set the {@link TDataBoundControl::getCurrentPageIndex CurrentPageIndex}
- * to this new page index so that the new page of data is rendered.
- *
- * Multiple pagers can be associated with the same data-bound control.
- *
- * @author Qiang Xue <qiang.xue@gmail.com>
- * @version $Id$
- * @package System.Web.UI.WebControls
- * @since 3.0.2
- */
-class TPager extends TWebControl implements INamingContainer
-{
- /**
- * Command name that TPager understands.
- */
- const CMD_PAGE='Page';
- const CMD_PAGE_NEXT='Next';
- const CMD_PAGE_PREV='Previous';
- const CMD_PAGE_FIRST='First';
- const CMD_PAGE_LAST='Last';
-
- private $_pageCount=0;
-
- /**
- * Restores the pager state.
- * This method overrides the parent implementation and is invoked when
- * the control is loading persistent state.
- */
- public function loadState()
- {
- parent::loadState();
- if($this->getEnableViewState(true))
- {
- $this->getControls()->clear();
- $this->buildPager();
- }
- }
-
- /**
- * @return string the ID path of the control whose content would be paginated.
- */
- public function getControlToPaginate()
- {
- return $this->getViewState('ControlToPaginate','');
- }
-
- /**
- * Sets the ID path of the control whose content would be paginated.
- * The ID path is the dot-connected IDs of the controls reaching from
- * the pager's naming container to the target control.
- * @param string the ID path
- */
- public function setControlToPaginate($value)
- {
- $this->setViewState('ControlToPaginate',$value,'');
- }
-
- /**
- * @return TPagerMode pager mode. Defaults to TPagerMode::NextPrev.
- */
- public function getMode()
- {
- return $this->getViewState('Mode',TPagerMode::NextPrev);
- }
-
- /**
- * @param TPagerMode pager mode.
- */
- public function setMode($value)
- {
- $this->setViewState('Mode',TPropertyValue::ensureEnum($value,'TPagerMode'),TPagerMode::NextPrev);
- }
-
- /**
- * @return TPagerButtonType the type of command button for paging. Defaults to TPagerButtonType::LinkButton.
- */
- public function getButtonType()
- {
- return $this->getViewState('ButtonType',TPagerButtonType::LinkButton);
- }
-
- /**
- * @param TPagerButtonType the type of command button for paging.
- */
- public function setButtonType($value)
- {
- $this->setViewState('ButtonType',TPropertyValue::ensureEnum($value,'TPagerButtonType'),TPagerButtonType::LinkButton);
- }
-
- /**
- * @return string text for the next page button. Defaults to '>'.
- */
- public function getNextPageText()
- {
- return $this->getViewState('NextPageText','>');
- }
-
- /**
- * @param string text for the next page button.
- */
- public function setNextPageText($value)
- {
- $this->setViewState('NextPageText',$value,'>');
- }
-
- /**
- * @return string text for the previous page button. Defaults to '<'.
- */
- public function getPrevPageText()
- {
- return $this->getViewState('PrevPageText','<');
- }
-
- /**
- * @param string text for the next page button.
- */
- public function setPrevPageText($value)
- {
- $this->setViewState('PrevPageText',$value,'<');
- }
-
- /**
- * @return string text for the first page button. Defaults to '<<'.
- */
- public function getFirstPageText()
- {
- return $this->getViewState('FirstPageText','<<');
- }
-
- /**
- * @param string text for the first page button. If empty, the first page button will not be rendered.
- */
- public function setFirstPageText($value)
- {
- $this->setViewState('FirstPageText',$value,'<<');
- }
-
- /**
- * @return string text for the last page button. Defaults to '>>'.
- */
- public function getLastPageText()
- {
- return $this->getViewState('LastPageText','>>');
- }
-
- /**
- * @param string text for the last page button. If empty, the last page button will not be rendered.
- */
- public function setLastPageText($value)
- {
- $this->setViewState('LastPageText',$value,'>>');
- }
-
- /**
- * @return string the image URL for the first page button. This is only used when {@link getButtonType ButtonType} is 'ImageButton'.
- * @since 3.1.1
- */
- public function getFirstPageImageUrl()
- {
- return $this->getViewState('FirstPageImageUrl','');
- }
-
- /**
- * @param string the image URL for the first page button. This is only used when {@link getButtonType ButtonType} is 'ImageButton'.
- * @since 3.1.1
- */
- public function setFirstPageImageUrl($value)
- {
- $this->setViewState('FirstPageImageUrl',$value);
- }
-
- /**
- * @return string the image URL for the last page button. This is only used when {@link getButtonType ButtonType} is 'ImageButton'.
- * @since 3.1.1
- */
- public function getLastPageImageUrl()
- {
- return $this->getViewState('LastPageImageUrl','');
- }
-
- /**
- * @param string the image URL for the last page button. This is only used when {@link getButtonType ButtonType} is 'ImageButton'.
- * @since 3.1.1
- */
- public function setLastPageImageUrl($value)
- {
- $this->setViewState('LastPageImageUrl',$value);
- }
-
- /**
- * @return string the image URL for the next page button. This is only used when {@link getButtonType ButtonType} is 'ImageButton'.
- * @since 3.1.1
- */
- public function getNextPageImageUrl()
- {
- return $this->getViewState('NextPageImageUrl','');
- }
-
- /**
- * @param string the image URL for the next page button. This is only used when {@link getButtonType ButtonType} is 'ImageButton'.
- * @since 3.1.1
- */
- public function setNextPageImageUrl($value)
- {
- $this->setViewState('NextPageImageUrl',$value);
- }
-
- /**
- * @return string the image URL for the previous page button. This is only used when {@link getButtonType ButtonType} is 'ImageButton'.
- * @since 3.1.1
- */
- public function getPrevPageImageUrl()
- {
- return $this->getViewState('PrevPageImageUrl','');
- }
-
- /**
- * @param string the image URL for the previous page button. This is only used when {@link getButtonType ButtonType} is 'ImageButton'.
- * @since 3.1.1
- */
- public function setPrevPageImageUrl($value)
- {
- $this->setViewState('PrevPageImageUrl',$value);
- }
-
- /**
- * @return string the image URL for the numeric page buttons. This is only used when {@link getButtonType ButtonType} is 'ImageButton' and {@link getMode Mode} is 'Numeric'.
- * @see setNumericPageImageUrl
- * @since 3.1.1
- */
- public function getNumericPageImageUrl()
- {
- return $this->getViewState('NumericPageImageUrl','');
- }
-
- /**
- * Sets the image URL for the numeric page buttons.
- * This is actually a template for generating a set of URLs corresponding to numeric button 1, 2, 3, .., etc.
- * Use {0} as the placeholder for the numbers.
- * For example, the image URL http://example.com/images/button{0}.gif
- * will be replaced as http://example.com/images/button1.gif, http://example.com/images/button2.gif, etc.
- * @param string the image URL for the numeric page buttons. This is only used when {@link getButtonType ButtonType} is 'ImageButton' and {@link getMode Mode} is 'Numeric'.
- * @since 3.1.1
- */
- public function setNumericPageImageUrl($value)
- {
- $this->setViewState('NumericPageImageUrl',$value);
- }
-
- /**
- * @return integer maximum number of pager buttons to be displayed. Defaults to 10.
- */
- public function getPageButtonCount()
- {
- return $this->getViewState('PageButtonCount',10);
- }
-
- /**
- * @param integer maximum number of pager buttons to be displayed
- * @throws TInvalidDataValueException if the value is less than 1.
- */
- public function setPageButtonCount($value)
- {
- if(($value=TPropertyValue::ensureInteger($value))<1)
- throw new TInvalidDataValueException('pager_pagebuttoncount_invalid');
- $this->setViewState('PageButtonCount',$value,10);
- }
-
- /**
- * @return integer the zero-based index of the current page. Defaults to 0.
- */
- public function getCurrentPageIndex()
- {
- return $this->getViewState('CurrentPageIndex',0);
- }
-
- /**
- * @param integer the zero-based index of the current page
- * @throws TInvalidDataValueException if the value is less than 0
- */
- protected function setCurrentPageIndex($value)
- {
- if(($value=TPropertyValue::ensureInteger($value))<0)
- throw new TInvalidDataValueException('pager_currentpageindex_invalid');
- $this->setViewState('CurrentPageIndex',$value,0);
- }
-
- /**
- * @return integer number of pages of data items available
- */
- public function getPageCount()
- {
- return $this->getViewState('PageCount',0);
- }
-
- /**
- * @param integer number of pages of data items available
- * @throws TInvalidDataValueException if the value is less than 0
- */
- protected function setPageCount($value)
- {
- if(($value=TPropertyValue::ensureInteger($value))<0)
- throw new TInvalidDataValueException('pager_pagecount_invalid');
- $this->setViewState('PageCount',$value,0);
- }
-
- /**
- * @return boolean whether the current page is the first page Defaults to false.
- */
- public function getIsFirstPage()
- {
- return $this->getCurrentPageIndex()===0;
- }
-
- /**
- * @return boolean whether the current page is the last page
- */
- public function getIsLastPage()
- {
- return $this->getCurrentPageIndex()===$this->getPageCount()-1;
- }
-
- /**
- * Performs databinding to populate data items from data source.
- * This method is invoked by {@link dataBind()}.
- * You may override this function to provide your own way of data population.
- * @param Traversable the bound data
- */
- public function onPreRender($param)
- {
- parent::onPreRender($param);
-
- $controlID=$this->getControlToPaginate();
- if(($targetControl=$this->getNamingContainer()->findControl($controlID))===null || !($targetControl instanceof TDataBoundControl))
- throw new TConfigurationException('pager_controltopaginate_invalid',$controlID);
-
- if($targetControl->getAllowPaging())
- {
- $this->_pageCount=$targetControl->getPageCount();
- $this->getControls()->clear();
- $this->setPageCount($targetControl->getPageCount());
- $this->setCurrentPageIndex($targetControl->getCurrentPageIndex());
- $this->buildPager();
- }
- else
- $this->_pageCount=0;
- }
-
- /**
- * Renders the control.
- * The method overrides the parent implementation by rendering
- * the pager only when there are two or more pages.
- * @param THtmlWriter the writer
- */
- public function render($writer)
- {
- if($this->_pageCount>1)
- parent::render($writer);
- }
-
- /**
- * Builds the pager content based on the pager mode.
- * Current implementation includes building 'NextPrev', 'Numeric' and 'DropDownList' pagers.
- * Derived classes may override this method to provide additional pagers.
- */
- protected function buildPager()
- {
- switch($this->getMode())
- {
- case TPagerMode::NextPrev:
- $this->buildNextPrevPager();
- break;
- case TPagerMode::Numeric:
- $this->buildNumericPager();
- break;
- case TPagerMode::DropDownList:
- $this->buildListPager();
- break;
- }
- }
-
- /**
- * Creates a pager button.
- * Depending on the button type, a TLinkButton or a TButton may be created.
- * If it is enabled (clickable), its command name and parameter will also be set.
- * Derived classes may override this method to create additional types of buttons, such as TImageButton.
- * @param string button type, either LinkButton or PushButton
- * @param boolean whether the button should be enabled
- * @param string caption of the button.
- * @param string CommandName corresponding to the OnCommand event of the button.
- * @param string CommandParameter corresponding to the OnCommand event of the button
- * @return mixed the button instance
- */
- protected function createPagerButton($buttonType,$enabled,$text,$commandName,$commandParameter)
- {
- if($buttonType===TPagerButtonType::LinkButton)
- {
- if($enabled)
- $button=new TLinkButton;
- else
- {
- $button=new TLabel;
- $button->setText($text);
- return $button;
- }
- }
- else
- {
- if($buttonType===TPagerButtonType::ImageButton)
- {
- $button=new TImageButton;
- $button->setImageUrl($this->getPageImageUrl($text,$commandName));
- }
- else
- $button=new TButton;
- if(!$enabled)
- $button->setEnabled(false);
- }
- $button->setText($text);
- $button->setCommandName($commandName);
- $button->setCommandParameter($commandParameter);
- $button->setCausesValidation(false);
- return $button;
- }
-
- /**
- * @param string the caption of the image button
- * @param string the command name associated with the image button
- * @since 3.1.1
- */
- protected function getPageImageUrl($text,$commandName)
- {
- switch($commandName)
- {
- case self::CMD_PAGE:
- $url=$this->getNumericPageImageUrl();
- return str_replace('{0}',$text,$url);
- case self::CMD_PAGE_NEXT:
- return $this->getNextPageImageUrl();
- case self::CMD_PAGE_PREV:
- return $this->getPrevPageImageUrl();
- case self::CMD_PAGE_FIRST:
- return $this->getFirstPageImageUrl();
- case self::CMD_PAGE_LAST:
- return $this->getLastPageImageUrl();
- default:
- return '';
- }
- }
-
- /**
- * Builds a next-prev pager
- */
- protected function buildNextPrevPager()
- {
- $buttonType=$this->getButtonType();
- $controls=$this->getControls();
- if($this->getIsFirstPage())
- {
- if(($text=$this->getFirstPageText())!=='')
- {
- $label=$this->createPagerButton($buttonType,false,$text,self::CMD_PAGE_FIRST,'');
- $controls->add($label);
- $controls->add("\n");
- }
- $label=$this->createPagerButton($buttonType,false,$this->getPrevPageText(),self::CMD_PAGE_PREV,'');
- $controls->add($label);
- }
- else
- {
- if(($text=$this->getFirstPageText())!=='')
- {
- $button=$this->createPagerButton($buttonType,true,$text,self::CMD_PAGE_FIRST,'');
- $controls->add($button);
- $controls->add("\n");
- }
- $button=$this->createPagerButton($buttonType,true,$this->getPrevPageText(),self::CMD_PAGE_PREV,'');
- $controls->add($button);
- }
- $controls->add("\n");
- if($this->getIsLastPage())
- {
- $label=$this->createPagerButton($buttonType,false,$this->getNextPageText(),self::CMD_PAGE_NEXT,'');
- $controls->add($label);
- if(($text=$this->getLastPageText())!=='')
- {
- $controls->add("\n");
- $label=$this->createPagerButton($buttonType,false,$text,self::CMD_PAGE_LAST,'');
- $controls->add($label);
- }
- }
- else
- {
- $button=$this->createPagerButton($buttonType,true,$this->getNextPageText(),self::CMD_PAGE_NEXT,'');
- $controls->add($button);
- if(($text=$this->getLastPageText())!=='')
- {
- $controls->add("\n");
- $button=$this->createPagerButton($buttonType,true,$text,self::CMD_PAGE_LAST,'');
- $controls->add($button);
- }
- }
- }
-
- /**
- * Builds a numeric pager
- */
- protected function buildNumericPager()
- {
- $buttonType=$this->getButtonType();
- $controls=$this->getControls();
- $pageCount=$this->getPageCount();
- $pageIndex=$this->getCurrentPageIndex()+1;
- $maxButtonCount=$this->getPageButtonCount();
- $buttonCount=$maxButtonCount>$pageCount?$pageCount:$maxButtonCount;
- $startPageIndex=1;
- $endPageIndex=$buttonCount;
- if($pageIndex>$endPageIndex)
- {
- $startPageIndex=((int)(($pageIndex-1)/$maxButtonCount))*$maxButtonCount+1;
- if(($endPageIndex=$startPageIndex+$maxButtonCount-1)>$pageCount)
- $endPageIndex=$pageCount;
- if($endPageIndex-$startPageIndex+1<$maxButtonCount)
- {
- if(($startPageIndex=$endPageIndex-$maxButtonCount+1)<1)
- $startPageIndex=1;
- }
- }
-
- if($startPageIndex>1)
- {
- if(($text=$this->getFirstPageText())!=='')
- {
- $button=$this->createPagerButton($buttonType,true,$text,self::CMD_PAGE_FIRST,'');
- $controls->add($button);
- $controls->add("\n");
- }
- $prevPageIndex=$startPageIndex-1;
- $button=$this->createPagerButton($buttonType,true,$this->getPrevPageText(),self::CMD_PAGE,"$prevPageIndex");
- $controls->add($button);
- $controls->add("\n");
- }
-
- for($i=$startPageIndex;$i<=$endPageIndex;++$i)
- {
- if($i===$pageIndex)
- {
- $label=$this->createPagerButton($buttonType,false,"$i",self::CMD_PAGE,'');
- $controls->add($label);
- }
- else
- {
- $button=$this->createPagerButton($buttonType,true,"$i",self::CMD_PAGE,"$i");
- $controls->add($button);
- }
- if($i<$endPageIndex)
- $controls->add("\n");
- }
-
- if($pageCount>$endPageIndex)
- {
- $controls->add("\n");
- $nextPageIndex=$endPageIndex+1;
- $button=$this->createPagerButton($buttonType,true,$this->getNextPageText(),self::CMD_PAGE,"$nextPageIndex");
- $controls->add($button);
- if(($text=$this->getLastPageText())!=='')
- {
- $controls->add("\n");
- $button=$this->createPagerButton($buttonType,true,$text,self::CMD_PAGE_LAST,'');
- $controls->add($button);
- }
- }
- }
-
- /**
- * Builds a dropdown list pager
- */
- protected function buildListPager()
- {
- $list=new TDropDownList;
- $this->getControls()->add($list);
- $list->setDataSource(range(1,$this->getPageCount()));
- $list->dataBind();
- $list->setSelectedIndex($this->getCurrentPageIndex());
- $list->setAutoPostBack(true);
- $list->attachEventHandler('OnSelectedIndexChanged',array($this,'listIndexChanged'));
- }
-
- /**
- * Event handler to the OnSelectedIndexChanged event of the dropdown list.
- * This handler will raise {@link onPageIndexChanged OnPageIndexChanged} event.
- * @param TDropDownList the dropdown list control raising the event
- * @param TEventParameter event parameter
- */
- public function listIndexChanged($sender,$param)
- {
- $pageIndex=$sender->getSelectedIndex();
- $this->onPageIndexChanged(new TPagerPageChangedEventParameter($sender,$pageIndex));
- }
-
- /**
- * This event is raised when page index is changed due to a page button click.
- * @param TPagerPageChangedEventParameter event parameter
- */
- public function onPageIndexChanged($param)
- {
- $this->raiseEvent('OnPageIndexChanged',$this,$param);
- }
-
- /**
- * Processes a bubbled event.
- * This method overrides parent's implementation by wrapping event parameter
- * for <b>OnCommand</b> event with item information.
- * @param TControl the sender of the event
- * @param TEventParameter event parameter
- * @return boolean whether the event bubbling should stop here.
- */
- public function bubbleEvent($sender,$param)
- {
- if($param instanceof TCommandEventParameter)
- {
- $command=$param->getCommandName();
- if(strcasecmp($command,self::CMD_PAGE)===0)
- {
- $pageIndex=TPropertyValue::ensureInteger($param->getCommandParameter())-1;
- $this->onPageIndexChanged(new TPagerPageChangedEventParameter($sender,$pageIndex));
- return true;
- }
- else if(strcasecmp($command,self::CMD_PAGE_NEXT)===0)
- {
- $pageIndex=$this->getCurrentPageIndex()+1;
- $this->onPageIndexChanged(new TPagerPageChangedEventParameter($sender,$pageIndex));
- return true;
- }
- else if(strcasecmp($command,self::CMD_PAGE_PREV)===0)
- {
- $pageIndex=$this->getCurrentPageIndex()-1;
- $this->onPageIndexChanged(new TPagerPageChangedEventParameter($sender,$pageIndex));
- return true;
- }
- else if(strcasecmp($command,self::CMD_PAGE_FIRST)===0)
- {
- $this->onPageIndexChanged(new TPagerPageChangedEventParameter($sender,0));
- return true;
- }
- else if(strcasecmp($command,self::CMD_PAGE_LAST)===0)
- {
- $this->onPageIndexChanged(new TPagerPageChangedEventParameter($sender,$this->getPageCount()-1));
- return true;
- }
- return false;
- }
- else
- return false;
- }
-}
-
-/**
- * TPagerPageChangedEventParameter class
- *
- * TPagerPageChangedEventParameter encapsulates the parameter data for
- * {@link TPager::onPageIndexChanged PageIndexChanged} event of {@link TPager} controls.
- *
- * The {@link getCommandSource CommandSource} property refers to the control
- * that originally raises the OnCommand event, while {@link getNewPageIndex NewPageIndex}
- * returns the new page index carried with the page command.
- *
- * @author Qiang Xue <qiang.xue@gmail.com>
- * @version $Id$
- * @package System.Web.UI.WebControls
- * @since 3.0.2
- */
-class TPagerPageChangedEventParameter extends TEventParameter
-{
- /**
- * @var integer new page index
- */
- private $_newIndex;
- /**
- * @var TControl original event sender
- */
- private $_source=null;
-
- /**
- * Constructor.
- * @param TControl the control originally raises the <b>OnCommand</b> event.
- * @param integer new page index
- */
- public function __construct($source,$newPageIndex)
- {
- $this->_source=$source;
- $this->_newIndex=$newPageIndex;
- }
-
- /**
- * @return TControl the control originally raises the <b>OnCommand</b> event.
- */
- public function getCommandSource()
- {
- return $this->_source;
- }
-
- /**
- * @return integer new page index
- */
- public function getNewPageIndex()
- {
- return $this->_newIndex;
- }
-}
-
-
-/**
- * TPagerMode class.
- * TPagerMode defines the enumerable type for the possible modes that a {@link TPager} control can take.
- *
- * The following enumerable values are defined:
- * - NextPrev: pager buttons are displayed as next and previous pages
- * - Numeric: pager buttons are displayed as numeric page numbers
- * - DropDownList: a dropdown list is used to select pages
- *
- * @author Qiang Xue <qiang.xue@gmail.com>
- * @version $Id$
- * @package System.Web.UI.WebControls
- * @since 3.0.4
- */
-class TPagerMode extends TEnumerable
-{
- const NextPrev='NextPrev';
- const Numeric='Numeric';
- const DropDownList='DropDownList';
-}
-
-
-/**
- * TPagerButtonType class.
- * TPagerButtonType defines the enumerable type for the possible types of pager buttons.
- *
- * The following enumerable values are defined:
- * - LinkButton: link buttons
- * - PushButton: form submit buttons
- *
- * @author Qiang Xue <qiang.xue@gmail.com>
- * @version $Id$
- * @package System.Web.UI.WebControls
- * @since 3.0.4
- */
-class TPagerButtonType extends TEnumerable
-{
- const LinkButton='LinkButton';
- const PushButton='PushButton';
- const ImageButton='ImageButton';
-}
-
+ * @license http://www.pradosoft.com/license/
+ * @version $Id$
+ * @package System.Web.UI.WebControls
+ */
+
+/**
+ * TPager class.
+ *
+ * TPager creates a pager that provides UI for end-users to interactively
+ * specify which page of data to be rendered in a {@link TDataBoundControl}-derived control,
+ * such as {@link TDataList}, {@link TRepeater}, {@link TCheckBoxList}, etc.
+ * The target data-bound control is specified by {@link setControlToPaginate ControlToPaginate},
+ * which must be the ID path of the target control reaching from the pager's
+ * naming container. Note, the target control must have its {@link TDataBoundControl::setAllowPaging AllowPaging}
+ * set to true.
+ *
+ * TPager can display three different UIs, specified via {@link setMode Mode}:
+ * - NextPrev: a next page and a previous page button are rendered.
+ * - Numeric: a list of page index buttons are rendered.
+ * - List: a dropdown list of page indices are rendered.
+ *
+ * When the pager mode is either NextPrev or Numeric, the paging buttons may be displayed
+ * in three types by setting {@link setButtonType ButtonType}:
+ * - LinkButton: a hyperlink button
+ * - PushButton: a normal button
+ * - ImageButton: an image button (please set XXXPageImageUrl properties accordingly to specify the button images.)
+ *
+ * TPager raises an {@link onPageIndexChanged OnPageIndexChanged} event when
+ * the end-user interacts with it and specifies a new page (e.g. clicking
+ * on a page button that leads to a new page.) The new page index may be obtained
+ * from the event parameter's property {@link TPagerPageChangedEventParameter::getNewPageIndex NewPageIndex}.
+ * Normally, in the event handler, one can set the {@link TDataBoundControl::getCurrentPageIndex CurrentPageIndex}
+ * to this new page index so that the new page of data is rendered.
+ *
+ * Multiple pagers can be associated with the same data-bound control.
+ *
+ * @author Qiang Xue <qiang.xue@gmail.com>
+ * @version $Id$
+ * @package System.Web.UI.WebControls
+ * @since 3.0.2
+ */
+class TPager extends TWebControl implements INamingContainer
+{
+ /**
+ * Command name that TPager understands.
+ */
+ const CMD_PAGE='Page';
+ const CMD_PAGE_NEXT='Next';
+ const CMD_PAGE_PREV='Previous';
+ const CMD_PAGE_FIRST='First';
+ const CMD_PAGE_LAST='Last';
+
+ private $_pageCount=0;
+
+ /**
+ * Restores the pager state.
+ * This method overrides the parent implementation and is invoked when
+ * the control is loading persistent state.
+ */
+ public function loadState()
+ {
+ parent::loadState();
+ if($this->getEnableViewState(true))
+ {
+ $this->getControls()->clear();
+ $this->buildPager();
+ }
+ }
+
+ /**
+ * @return string the ID path of the control whose content would be paginated.
+ */
+ public function getControlToPaginate()
+ {
+ return $this->getViewState('ControlToPaginate','');
+ }
+
+ /**
+ * Sets the ID path of the control whose content would be paginated.
+ * The ID path is the dot-connected IDs of the controls reaching from
+ * the pager's naming container to the target control.
+ * @param string the ID path
+ */
+ public function setControlToPaginate($value)
+ {
+ $this->setViewState('ControlToPaginate',$value,'');
+ }
+
+ /**
+ * @return TPagerMode pager mode. Defaults to TPagerMode::NextPrev.
+ */
+ public function getMode()
+ {
+ return $this->getViewState('Mode',TPagerMode::NextPrev);
+ }
+
+ /**
+ * @param TPagerMode pager mode.
+ */
+ public function setMode($value)
+ {
+ $this->setViewState('Mode',TPropertyValue::ensureEnum($value,'TPagerMode'),TPagerMode::NextPrev);
+ }
+
+ /**
+ * @return TPagerButtonType the type of command button for paging. Defaults to TPagerButtonType::LinkButton.
+ */
+ public function getButtonType()
+ {
+ return $this->getViewState('ButtonType',TPagerButtonType::LinkButton);
+ }
+
+ /**
+ * @param TPagerButtonType the type of command button for paging.
+ */
+ public function setButtonType($value)
+ {
+ $this->setViewState('ButtonType',TPropertyValue::ensureEnum($value,'TPagerButtonType'),TPagerButtonType::LinkButton);
+ }
+
+ /**
+ * @return string text for the next page button. Defaults to '>'.
+ */
+ public function getNextPageText()
+ {
+ return $this->getViewState('NextPageText','>');
+ }
+
+ /**
+ * @param string text for the next page button.
+ */
+ public function setNextPageText($value)
+ {
+ $this->setViewState('NextPageText',$value,'>');
+ }
+
+ /**
+ * @return string text for the previous page button. Defaults to '<'.
+ */
+ public function getPrevPageText()
+ {
+ return $this->getViewState('PrevPageText','<');
+ }
+
+ /**
+ * @param string text for the next page button.
+ */
+ public function setPrevPageText($value)
+ {
+ $this->setViewState('PrevPageText',$value,'<');
+ }
+
+ /**
+ * @return string text for the first page button. Defaults to '<<'.
+ */
+ public function getFirstPageText()
+ {
+ return $this->getViewState('FirstPageText','<<');
+ }
+
+ /**
+ * @param string text for the first page button. If empty, the first page button will not be rendered.
+ */
+ public function setFirstPageText($value)
+ {
+ $this->setViewState('FirstPageText',$value,'<<');
+ }
+
+ /**
+ * @return string text for the last page button. Defaults to '>>'.
+ */
+ public function getLastPageText()
+ {
+ return $this->getViewState('LastPageText','>>');
+ }
+
+ /**
+ * @param string text for the last page button. If empty, the last page button will not be rendered.
+ */
+ public function setLastPageText($value)
+ {
+ $this->setViewState('LastPageText',$value,'>>');
+ }
+
+ /**
+ * @return string the image URL for the first page button. This is only used when {@link getButtonType ButtonType} is 'ImageButton'.
+ * @since 3.1.1
+ */
+ public function getFirstPageImageUrl()
+ {
+ return $this->getViewState('FirstPageImageUrl','');
+ }
+
+ /**
+ * @param string the image URL for the first page button. This is only used when {@link getButtonType ButtonType} is 'ImageButton'.
+ * @since 3.1.1
+ */
+ public function setFirstPageImageUrl($value)
+ {
+ $this->setViewState('FirstPageImageUrl',$value);
+ }
+
+ /**
+ * @return string the image URL for the last page button. This is only used when {@link getButtonType ButtonType} is 'ImageButton'.
+ * @since 3.1.1
+ */
+ public function getLastPageImageUrl()
+ {
+ return $this->getViewState('LastPageImageUrl','');
+ }
+
+ /**
+ * @param string the image URL for the last page button. This is only used when {@link getButtonType ButtonType} is 'ImageButton'.
+ * @since 3.1.1
+ */
+ public function setLastPageImageUrl($value)
+ {
+ $this->setViewState('LastPageImageUrl',$value);
+ }
+
+ /**
+ * @return string the image URL for the next page button. This is only used when {@link getButtonType ButtonType} is 'ImageButton'.
+ * @since 3.1.1
+ */
+ public function getNextPageImageUrl()
+ {
+ return $this->getViewState('NextPageImageUrl','');
+ }
+
+ /**
+ * @param string the image URL for the next page button. This is only used when {@link getButtonType ButtonType} is 'ImageButton'.
+ * @since 3.1.1
+ */
+ public function setNextPageImageUrl($value)
+ {
+ $this->setViewState('NextPageImageUrl',$value);
+ }
+
+ /**
+ * @return string the image URL for the previous page button. This is only used when {@link getButtonType ButtonType} is 'ImageButton'.
+ * @since 3.1.1
+ */
+ public function getPrevPageImageUrl()
+ {
+ return $this->getViewState('PrevPageImageUrl','');
+ }
+
+ /**
+ * @param string the image URL for the previous page button. This is only used when {@link getButtonType ButtonType} is 'ImageButton'.
+ * @since 3.1.1
+ */
+ public function setPrevPageImageUrl($value)
+ {
+ $this->setViewState('PrevPageImageUrl',$value);
+ }
+
+ /**
+ * @return string the image URL for the numeric page buttons. This is only used when {@link getButtonType ButtonType} is 'ImageButton' and {@link getMode Mode} is 'Numeric'.
+ * @see setNumericPageImageUrl
+ * @since 3.1.1
+ */
+ public function getNumericPageImageUrl()
+ {
+ return $this->getViewState('NumericPageImageUrl','');
+ }
+
+ /**
+ * Sets the image URL for the numeric page buttons.
+ * This is actually a template for generating a set of URLs corresponding to numeric button 1, 2, 3, .., etc.
+ * Use {0} as the placeholder for the numbers.
+ * For example, the image URL http://example.com/images/button{0}.gif
+ * will be replaced as http://example.com/images/button1.gif, http://example.com/images/button2.gif, etc.
+ * @param string the image URL for the numeric page buttons. This is only used when {@link getButtonType ButtonType} is 'ImageButton' and {@link getMode Mode} is 'Numeric'.
+ * @since 3.1.1
+ */
+ public function setNumericPageImageUrl($value)
+ {
+ $this->setViewState('NumericPageImageUrl',$value);
+ }
+
+ /**
+ * @return integer maximum number of pager buttons to be displayed. Defaults to 10.
+ */
+ public function getPageButtonCount()
+ {
+ return $this->getViewState('PageButtonCount',10);
+ }
+
+ /**
+ * @param integer maximum number of pager buttons to be displayed
+ * @throws TInvalidDataValueException if the value is less than 1.
+ */
+ public function setPageButtonCount($value)
+ {
+ if(($value=TPropertyValue::ensureInteger($value))<1)
+ throw new TInvalidDataValueException('pager_pagebuttoncount_invalid');
+ $this->setViewState('PageButtonCount',$value,10);
+ }
+
+ /**
+ * @return integer the zero-based index of the current page. Defaults to 0.
+ */
+ public function getCurrentPageIndex()
+ {
+ return $this->getViewState('CurrentPageIndex',0);
+ }
+
+ /**
+ * @param integer the zero-based index of the current page
+ * @throws TInvalidDataValueException if the value is less than 0
+ */
+ protected function setCurrentPageIndex($value)
+ {
+ if(($value=TPropertyValue::ensureInteger($value))<0)
+ throw new TInvalidDataValueException('pager_currentpageindex_invalid');
+ $this->setViewState('CurrentPageIndex',$value,0);
+ }
+
+ /**
+ * @return integer number of pages of data items available
+ */
+ public function getPageCount()
+ {
+ return $this->getViewState('PageCount',0);
+ }
+
+ /**
+ * @param integer number of pages of data items available
+ * @throws TInvalidDataValueException if the value is less than 0
+ */
+ protected function setPageCount($value)
+ {
+ if(($value=TPropertyValue::ensureInteger($value))<0)
+ throw new TInvalidDataValueException('pager_pagecount_invalid');
+ $this->setViewState('PageCount',$value,0);
+ }
+
+ /**
+ * @return boolean whether the current page is the first page Defaults to false.
+ */
+ public function getIsFirstPage()
+ {
+ return $this->getCurrentPageIndex()===0;
+ }
+
+ /**
+ * @return boolean whether the current page is the last page
+ */
+ public function getIsLastPage()
+ {
+ return $this->getCurrentPageIndex()===$this->getPageCount()-1;
+ }
+
+ /**
+ * Performs databinding to populate data items from data source.
+ * This method is invoked by {@link dataBind()}.
+ * You may override this function to provide your own way of data population.
+ * @param Traversable the bound data
+ */
+ public function onPreRender($param)
+ {
+ parent::onPreRender($param);
+
+ $controlID=$this->getControlToPaginate();
+ if(($targetControl=$this->getNamingContainer()->findControl($controlID))===null || !($targetControl instanceof TDataBoundControl))
+ throw new TConfigurationException('pager_controltopaginate_invalid',$controlID);
+
+ if($targetControl->getAllowPaging())
+ {
+ $this->_pageCount=$targetControl->getPageCount();
+ $this->getControls()->clear();
+ $this->setPageCount($targetControl->getPageCount());
+ $this->setCurrentPageIndex($targetControl->getCurrentPageIndex());
+ $this->buildPager();
+ }
+ else
+ $this->_pageCount=0;
+ }
+
+ /**
+ * Renders the control.
+ * The method overrides the parent implementation by rendering
+ * the pager only when there are two or more pages.
+ * @param THtmlWriter the writer
+ */
+ public function render($writer)
+ {
+ if($this->_pageCount>1)
+ parent::render($writer);
+ }
+
+ /**
+ * Builds the pager content based on the pager mode.
+ * Current implementation includes building 'NextPrev', 'Numeric' and 'DropDownList' pagers.
+ * Derived classes may override this method to provide additional pagers.
+ */
+ protected function buildPager()
+ {
+ switch($this->getMode())
+ {
+ case TPagerMode::NextPrev:
+ $this->buildNextPrevPager();
+ break;
+ case TPagerMode::Numeric:
+ $this->buildNumericPager();
+ break;
+ case TPagerMode::DropDownList:
+ $this->buildListPager();
+ break;
+ }
+ }
+
+ /**
+ * Creates a pager button.
+ * Depending on the button type, a TLinkButton or a TButton may be created.
+ * If it is enabled (clickable), its command name and parameter will also be set.
+ * Derived classes may override this method to create additional types of buttons, such as TImageButton.
+ * @param string button type, either LinkButton or PushButton
+ * @param boolean whether the button should be enabled
+ * @param string caption of the button.
+ * @param string CommandName corresponding to the OnCommand event of the button.
+ * @param string CommandParameter corresponding to the OnCommand event of the button
+ * @return mixed the button instance
+ */
+ protected function createPagerButton($buttonType,$enabled,$text,$commandName,$commandParameter)
+ {
+ if($buttonType===TPagerButtonType::LinkButton)
+ {
+ if($enabled)
+ $button=new TLinkButton;
+ else
+ {
+ $button=new TLabel;
+ $button->setText($text);
+ return $button;
+ }
+ }
+ else
+ {
+ if($buttonType===TPagerButtonType::ImageButton)
+ {
+ $button=new TImageButton;
+ $button->setImageUrl($this->getPageImageUrl($text,$commandName));
+ }
+ else
+ $button=new TButton;
+ if(!$enabled)
+ $button->setEnabled(false);
+ }
+ $button->setText($text);
+ $button->setCommandName($commandName);
+ $button->setCommandParameter($commandParameter);
+ $button->setCausesValidation(false);
+ return $button;
+ }
+
+ /**
+ * @param string the caption of the image button
+ * @param string the command name associated with the image button
+ * @since 3.1.1
+ */
+ protected function getPageImageUrl($text,$commandName)
+ {
+ switch($commandName)
+ {
+ case self::CMD_PAGE:
+ $url=$this->getNumericPageImageUrl();
+ return str_replace('{0}',$text,$url);
+ case self::CMD_PAGE_NEXT:
+ return $this->getNextPageImageUrl();
+ case self::CMD_PAGE_PREV:
+ return $this->getPrevPageImageUrl();
+ case self::CMD_PAGE_FIRST:
+ return $this->getFirstPageImageUrl();
+ case self::CMD_PAGE_LAST:
+ return $this->getLastPageImageUrl();
+ default:
+ return '';
+ }
+ }
+
+ /**
+ * Builds a next-prev pager
+ */
+ protected function buildNextPrevPager()
+ {
+ $buttonType=$this->getButtonType();
+ $controls=$this->getControls();
+ if($this->getIsFirstPage())
+ {
+ if(($text=$this->getFirstPageText())!=='')
+ {
+ $label=$this->createPagerButton($buttonType,false,$text,self::CMD_PAGE_FIRST,'');
+ $controls->add($label);
+ $controls->add("\n");
+ }
+ $label=$this->createPagerButton($buttonType,false,$this->getPrevPageText(),self::CMD_PAGE_PREV,'');
+ $controls->add($label);
+ }
+ else
+ {
+ if(($text=$this->getFirstPageText())!=='')
+ {
+ $button=$this->createPagerButton($buttonType,true,$text,self::CMD_PAGE_FIRST,'');
+ $controls->add($button);
+ $controls->add("\n");
+ }
+ $button=$this->createPagerButton($buttonType,true,$this->getPrevPageText(),self::CMD_PAGE_PREV,'');
+ $controls->add($button);
+ }
+ $controls->add("\n");
+ if($this->getIsLastPage())
+ {
+ $label=$this->createPagerButton($buttonType,false,$this->getNextPageText(),self::CMD_PAGE_NEXT,'');
+ $controls->add($label);
+ if(($text=$this->getLastPageText())!=='')
+ {
+ $controls->add("\n");
+ $label=$this->createPagerButton($buttonType,false,$text,self::CMD_PAGE_LAST,'');
+ $controls->add($label);
+ }
+ }
+ else
+ {
+ $button=$this->createPagerButton($buttonType,true,$this->getNextPageText(),self::CMD_PAGE_NEXT,'');
+ $controls->add($button);
+ if(($text=$this->getLastPageText())!=='')
+ {
+ $controls->add("\n");
+ $button=$this->createPagerButton($buttonType,true,$text,self::CMD_PAGE_LAST,'');
+ $controls->add($button);
+ }
+ }
+ }
+
+ /**
+ * Builds a numeric pager
+ */
+ protected function buildNumericPager()
+ {
+ $buttonType=$this->getButtonType();
+ $controls=$this->getControls();
+ $pageCount=$this->getPageCount();
+ $pageIndex=$this->getCurrentPageIndex()+1;
+ $maxButtonCount=$this->getPageButtonCount();
+ $buttonCount=$maxButtonCount>$pageCount?$pageCount:$maxButtonCount;
+ $startPageIndex=1;
+ $endPageIndex=$buttonCount;
+ if($pageIndex>$endPageIndex)
+ {
+ $startPageIndex=((int)(($pageIndex-1)/$maxButtonCount))*$maxButtonCount+1;
+ if(($endPageIndex=$startPageIndex+$maxButtonCount-1)>$pageCount)
+ $endPageIndex=$pageCount;
+ if($endPageIndex-$startPageIndex+1<$maxButtonCount)
+ {
+ if(($startPageIndex=$endPageIndex-$maxButtonCount+1)<1)
+ $startPageIndex=1;
+ }
+ }
+
+ if($startPageIndex>1)
+ {
+ if(($text=$this->getFirstPageText())!=='')
+ {
+ $button=$this->createPagerButton($buttonType,true,$text,self::CMD_PAGE_FIRST,'');
+ $controls->add($button);
+ $controls->add("\n");
+ }
+ $prevPageIndex=$startPageIndex-1;
+ $button=$this->createPagerButton($buttonType,true,$this->getPrevPageText(),self::CMD_PAGE,"$prevPageIndex");
+ $controls->add($button);
+ $controls->add("\n");
+ }
+
+ for($i=$startPageIndex;$i<=$endPageIndex;++$i)
+ {
+ if($i===$pageIndex)
+ {
+ $label=$this->createPagerButton($buttonType,false,"$i",self::CMD_PAGE,'');
+ $controls->add($label);
+ }
+ else
+ {
+ $button=$this->createPagerButton($buttonType,true,"$i",self::CMD_PAGE,"$i");
+ $controls->add($button);
+ }
+ if($i<$endPageIndex)
+ $controls->add("\n");
+ }
+
+ if($pageCount>$endPageIndex)
+ {
+ $controls->add("\n");
+ $nextPageIndex=$endPageIndex+1;
+ $button=$this->createPagerButton($buttonType,true,$this->getNextPageText(),self::CMD_PAGE,"$nextPageIndex");
+ $controls->add($button);
+ if(($text=$this->getLastPageText())!=='')
+ {
+ $controls->add("\n");
+ $button=$this->createPagerButton($buttonType,true,$text,self::CMD_PAGE_LAST,'');
+ $controls->add($button);
+ }
+ }
+ }
+
+ /**
+ * Builds a dropdown list pager
+ */
+ protected function buildListPager()
+ {
+ $list=new TDropDownList;
+ $this->getControls()->add($list);
+ $list->setDataSource(range(1,$this->getPageCount()));
+ $list->dataBind();
+ $list->setSelectedIndex($this->getCurrentPageIndex());
+ $list->setAutoPostBack(true);
+ $list->attachEventHandler('OnSelectedIndexChanged',array($this,'listIndexChanged'));
+ }
+
+ /**
+ * Event handler to the OnSelectedIndexChanged event of the dropdown list.
+ * This handler will raise {@link onPageIndexChanged OnPageIndexChanged} event.
+ * @param TDropDownList the dropdown list control raising the event
+ * @param TEventParameter event parameter
+ */
+ public function listIndexChanged($sender,$param)
+ {
+ $pageIndex=$sender->getSelectedIndex();
+ $this->onPageIndexChanged(new TPagerPageChangedEventParameter($sender,$pageIndex));
+ }
+
+ /**
+ * This event is raised when page index is changed due to a page button click.
+ * @param TPagerPageChangedEventParameter event parameter
+ */
+ public function onPageIndexChanged($param)
+ {
+ $this->raiseEvent('OnPageIndexChanged',$this,$param);
+ }
+
+ /**
+ * Processes a bubbled event.
+ * This method overrides parent's implementation by wrapping event parameter
+ * for <b>OnCommand</b> event with item information.
+ * @param TControl the sender of the event
+ * @param TEventParameter event parameter
+ * @return boolean whether the event bubbling should stop here.
+ */
+ public function bubbleEvent($sender,$param)
+ {
+ if($param instanceof TCommandEventParameter)
+ {
+ $command=$param->getCommandName();
+ if(strcasecmp($command,self::CMD_PAGE)===0)
+ {
+ $pageIndex=TPropertyValue::ensureInteger($param->getCommandParameter())-1;
+ $this->onPageIndexChanged(new TPagerPageChangedEventParameter($sender,$pageIndex));
+ return true;
+ }
+ else if(strcasecmp($command,self::CMD_PAGE_NEXT)===0)
+ {
+ $pageIndex=$this->getCurrentPageIndex()+1;
+ $this->onPageIndexChanged(new TPagerPageChangedEventParameter($sender,$pageIndex));
+ return true;
+ }
+ else if(strcasecmp($command,self::CMD_PAGE_PREV)===0)
+ {
+ $pageIndex=$this->getCurrentPageIndex()-1;
+ $this->onPageIndexChanged(new TPagerPageChangedEventParameter($sender,$pageIndex));
+ return true;
+ }
+ else if(strcasecmp($command,self::CMD_PAGE_FIRST)===0)
+ {
+ $this->onPageIndexChanged(new TPagerPageChangedEventParameter($sender,0));
+ return true;
+ }
+ else if(strcasecmp($command,self::CMD_PAGE_LAST)===0)
+ {
+ $this->onPageIndexChanged(new TPagerPageChangedEventParameter($sender,$this->getPageCount()-1));
+ return true;
+ }
+ return false;
+ }
+ else
+ return false;
+ }
+}
+
+/**
+ * TPagerPageChangedEventParameter class
+ *
+ * TPagerPageChangedEventParameter encapsulates the parameter data for
+ * {@link TPager::onPageIndexChanged PageIndexChanged} event of {@link TPager} controls.
+ *
+ * The {@link getCommandSource CommandSource} property refers to the control
+ * that originally raises the OnCommand event, while {@link getNewPageIndex NewPageIndex}
+ * returns the new page index carried with the page command.
+ *
+ * @author Qiang Xue <qiang.xue@gmail.com>
+ * @version $Id$
+ * @package System.Web.UI.WebControls
+ * @since 3.0.2
+ */
+class TPagerPageChangedEventParameter extends TEventParameter
+{
+ /**
+ * @var integer new page index
+ */
+ private $_newIndex;
+ /**
+ * @var TControl original event sender
+ */
+ private $_source=null;
+
+ /**
+ * Constructor.
+ * @param TControl the control originally raises the <b>OnCommand</b> event.
+ * @param integer new page index
+ */
+ public function __construct($source,$newPageIndex)
+ {
+ $this->_source=$source;
+ $this->_newIndex=$newPageIndex;
+ }
+
+ /**
+ * @return TControl the control originally raises the <b>OnCommand</b> event.
+ */
+ public function getCommandSource()
+ {
+ return $this->_source;
+ }
+
+ /**
+ * @return integer new page index
+ */
+ public function getNewPageIndex()
+ {
+ return $this->_newIndex;
+ }
+}
+
+
+/**
+ * TPagerMode class.
+ * TPagerMode defines the enumerable type for the possible modes that a {@link TPager} control can take.
+ *
+ * The following enumerable values are defined:
+ * - NextPrev: pager buttons are displayed as next and previous pages
+ * - Numeric: pager buttons are displayed as numeric page numbers
+ * - DropDownList: a dropdown list is used to select pages
+ *
+ * @author Qiang Xue <qiang.xue@gmail.com>
+ * @version $Id$
+ * @package System.Web.UI.WebControls
+ * @since 3.0.4
+ */
+class TPagerMode extends TEnumerable
+{
+ const NextPrev='NextPrev';
+ const Numeric='Numeric';
+ const DropDownList='DropDownList';
+}
+
+
+/**
+ * TPagerButtonType class.
+ * TPagerButtonType defines the enumerable type for the possible types of pager buttons.
+ *
+ * The following enumerable values are defined:
+ * - LinkButton: link buttons
+ * - PushButton: form submit buttons
+ *
+ * @author Qiang Xue <qiang.xue@gmail.com>
+ * @version $Id$
+ * @package System.Web.UI.WebControls
+ * @since 3.0.4
+ */
+class TPagerButtonType extends TEnumerable
+{
+ const LinkButton='LinkButton';
+ const PushButton='PushButton';
+ const ImageButton='ImageButton';
+}
+
diff --git a/framework/Web/UI/WebControls/TPanel.php b/framework/Web/UI/WebControls/TPanel.php
index 5d651679..d4e05136 100644
--- a/framework/Web/UI/WebControls/TPanel.php
+++ b/framework/Web/UI/WebControls/TPanel.php
@@ -1,246 +1,246 @@
-<?php
-/**
- * TPanel class file
- *
- * @author Qiang Xue <qiang.xue@gmail.com>
- * @link http://www.pradosoft.com/
- * @copyright Copyright &copy; 2005-2012 PradoSoft
- * @license http://www.pradosoft.com/license/
- * @version $Id$
- * @package System.Web.UI.WebControls
- */
-
-/**
- * Includes TPanelStyle class file
- */
-Prado::using('System.Web.UI.WebControls.TPanelStyle');
-
-/**
- * TPanel class
- *
- * TPanel represents a component that acts as a container for other component.
- * It is especially useful when you want to generate components programmatically
- * or hide/show a group of components.
- *
- * By default, TPanel displays a &lt;div&gt; element on a page.
- * Children of TPanel are displayed as the body content of the element.
- * The property {@link setWrap Wrap} can be used to set whether the body content
- * should wrap or not. {@link setHorizontalAlign HorizontalAlign} governs how
- * the content is aligned horizontally, and {@link getDirection Direction} indicates
- * the content direction (left to right or right to left). You can set
- * {@link setBackImageUrl BackImageUrl} to give a background image to the panel,
- * and you can ste {@link setGroupingText GroupingText} so that the panel is
- * displayed as a field set with a legend text. Finally, you can specify
- * a default button to be fired when users press 'return' key within the panel
- * by setting the {@link setDefaultButton DefaultButton} property.
- *
- * @author Qiang Xue <qiang.xue@gmail.com>
- * @version $Id$
- * @package System.Web.UI.WebControls
- * @since 3.0
- */
-class TPanel extends TWebControl
-{
- /**
- * @var string ID path to the default button
- */
- private $_defaultButton='';
-
- /**
- * @return string tag name of the panel
- */
- protected function getTagName()
- {
- return 'div';
- }
-
- /**
- * Creates a style object to be used by the control.
- * This method overrides the parent impementation by creating a TPanelStyle object.
- * @return TPanelStyle the style used by TPanel.
- */
- protected function createStyle()
- {
- return new TPanelStyle;
- }
-
- /**
- * Adds attributes to renderer.
- * @param THtmlWriter the renderer
- * @throws TInvalidDataValueException if default button is not right.
- */
- protected function addAttributesToRender($writer)
- {
- parent::addAttributesToRender($writer);
- if(($butt=$this->getDefaultButton())!=='')
- $writer->addAttribute('id',$this->getClientID());
- }
-
- /**
- * @return boolean whether the content wraps within the panel. Defaults to true.
- */
- public function getWrap()
- {
- return $this->getStyle()->getWrap();
- }
-
- /**
- * Sets the value indicating whether the content wraps within the panel.
- * @param boolean whether the content wraps within the panel.
- */
- public function setWrap($value)
- {
- $this->getStyle()->setWrap($value);
- }
-
- /**
- * @return string the horizontal alignment of the contents within the panel, defaults to 'NotSet'.
- */
- public function getHorizontalAlign()
- {
- return $this->getStyle()->getHorizontalAlign();
- }
-
- /**
- * Sets the horizontal alignment of the contents within the panel.
- * Valid values include 'NotSet', 'Justify', 'Left', 'Right', 'Center'
- * @param string the horizontal alignment
- */
- public function setHorizontalAlign($value)
- {
- $this->getStyle()->setHorizontalAlign($value);
- }
-
- /**
- * @return string the URL of the background image for the panel component.
- */
- public function getBackImageUrl()
- {
- return $this->getStyle()->getBackImageUrl();
- }
-
- /**
- * Sets the URL of the background image for the panel component.
- * @param string the URL
- */
- public function setBackImageUrl($value)
- {
- $this->getStyle()->setBackImageUrl($value);
- }
-
- /**
- * @return string alignment of the content in the panel. Defaults to 'NotSet'.
- */
- public function getDirection()
- {
- return $this->getStyle()->getDirection();
- }
-
- /**
- * @param string alignment of the content in the panel.
- * Valid values include 'NotSet', 'LeftToRight', 'RightToLeft'.
- */
- public function setDirection($value)
- {
- $this->getStyle()->setDirection($value);
- }
-
- /**
- * @return string the ID path to the default button. Defaults to empty.
- */
- public function getDefaultButton()
- {
- return $this->_defaultButton;
- }
-
- /**
- * Specifies the default button for the panel.
- * The default button will be fired (clicked) whenever a user enters 'return'
- * key within the panel.
- * The button must be locatable via the function call {@link TControl::findControl findControl}.
- * @param string the ID path to the default button.
- */
- public function setDefaultButton($value)
- {
- $this->_defaultButton=$value;
- }
-
- /**
- * @return string the legend text when the panel is used as a fieldset. Defaults to empty.
- */
- public function getGroupingText()
- {
- return $this->getViewState('GroupingText','');
- }
-
- /**
- * @param string the legend text. If this value is not empty, the panel will be rendered as a fieldset.
- */
- public function setGroupingText($value)
- {
- $this->setViewState('GroupingText',$value,'');
- }
-
- /**
- * @return string the visibility and position of scroll bars in a panel control, defaults to None.
- */
- public function getScrollBars()
- {
- return $this->getStyle()->getScrollBars();
- }
-
- /**
- * @param string the visibility and position of scroll bars in a panel control.
- * Valid values include None, Auto, Both, Horizontal and Vertical.
- */
- public function setScrollBars($value)
- {
- $this->getStyle()->setScrollBars($value);
- }
-
- /**
- * Renders the openning tag for the control (including attributes)
- * @param THtmlWriter the writer used for the rendering purpose
- */
- public function renderBeginTag($writer)
- {
- parent::renderBeginTag($writer);
- if(($text=$this->getGroupingText())!=='')
- {
- $writer->renderBeginTag('fieldset');
- $writer->renderBeginTag('legend');
- $writer->write($text);
- $writer->renderEndTag();
- }
- }
-
- /**
- * Renders the closing tag for the control
- * @param THtmlWriter the writer used for the rendering purpose
- */
- public function renderEndTag($writer)
- {
- if($this->getGroupingText()!=='')
- $writer->renderEndTag();
- parent::renderEndTag($writer);
- }
-
- public function render($writer)
- {
- parent::render($writer);
-
- if(($butt=$this->getDefaultButton())!=='')
- {
- $buttons = $this->findControlsByID($butt);
- if (count($buttons)>0)
- $button = reset($buttons);
- else
- $button = null;
- if($button===null)
- throw new TInvalidDataValueException('panel_defaultbutton_invalid',$butt);
- else
- $this->getPage()->getClientScript()->registerDefaultButton($this, $button);
- }
- }
-}
-
+<?php
+/**
+ * TPanel class file
+ *
+ * @author Qiang Xue <qiang.xue@gmail.com>
+ * @link http://www.pradosoft.com/
+ * @copyright Copyright &copy; 2005-2012 PradoSoft
+ * @license http://www.pradosoft.com/license/
+ * @version $Id$
+ * @package System.Web.UI.WebControls
+ */
+
+/**
+ * Includes TPanelStyle class file
+ */
+Prado::using('System.Web.UI.WebControls.TPanelStyle');
+
+/**
+ * TPanel class
+ *
+ * TPanel represents a component that acts as a container for other component.
+ * It is especially useful when you want to generate components programmatically
+ * or hide/show a group of components.
+ *
+ * By default, TPanel displays a &lt;div&gt; element on a page.
+ * Children of TPanel are displayed as the body content of the element.
+ * The property {@link setWrap Wrap} can be used to set whether the body content
+ * should wrap or not. {@link setHorizontalAlign HorizontalAlign} governs how
+ * the content is aligned horizontally, and {@link getDirection Direction} indicates
+ * the content direction (left to right or right to left). You can set
+ * {@link setBackImageUrl BackImageUrl} to give a background image to the panel,
+ * and you can ste {@link setGroupingText GroupingText} so that the panel is
+ * displayed as a field set with a legend text. Finally, you can specify
+ * a default button to be fired when users press 'return' key within the panel
+ * by setting the {@link setDefaultButton DefaultButton} property.
+ *
+ * @author Qiang Xue <qiang.xue@gmail.com>
+ * @version $Id$
+ * @package System.Web.UI.WebControls
+ * @since 3.0
+ */
+class TPanel extends TWebControl
+{
+ /**
+ * @var string ID path to the default button
+ */
+ private $_defaultButton='';
+
+ /**
+ * @return string tag name of the panel
+ */
+ protected function getTagName()
+ {
+ return 'div';
+ }
+
+ /**
+ * Creates a style object to be used by the control.
+ * This method overrides the parent impementation by creating a TPanelStyle object.
+ * @return TPanelStyle the style used by TPanel.
+ */
+ protected function createStyle()
+ {
+ return new TPanelStyle;
+ }
+
+ /**
+ * Adds attributes to renderer.
+ * @param THtmlWriter the renderer
+ * @throws TInvalidDataValueException if default button is not right.
+ */
+ protected function addAttributesToRender($writer)
+ {
+ parent::addAttributesToRender($writer);
+ if(($butt=$this->getDefaultButton())!=='')
+ $writer->addAttribute('id',$this->getClientID());
+ }
+
+ /**
+ * @return boolean whether the content wraps within the panel. Defaults to true.
+ */
+ public function getWrap()
+ {
+ return $this->getStyle()->getWrap();
+ }
+
+ /**
+ * Sets the value indicating whether the content wraps within the panel.
+ * @param boolean whether the content wraps within the panel.
+ */
+ public function setWrap($value)
+ {
+ $this->getStyle()->setWrap($value);
+ }
+
+ /**
+ * @return string the horizontal alignment of the contents within the panel, defaults to 'NotSet'.
+ */
+ public function getHorizontalAlign()
+ {
+ return $this->getStyle()->getHorizontalAlign();
+ }
+
+ /**
+ * Sets the horizontal alignment of the contents within the panel.
+ * Valid values include 'NotSet', 'Justify', 'Left', 'Right', 'Center'
+ * @param string the horizontal alignment
+ */
+ public function setHorizontalAlign($value)
+ {
+ $this->getStyle()->setHorizontalAlign($value);
+ }
+
+ /**
+ * @return string the URL of the background image for the panel component.
+ */
+ public function getBackImageUrl()
+ {
+ return $this->getStyle()->getBackImageUrl();
+ }
+
+ /**
+ * Sets the URL of the background image for the panel component.
+ * @param string the URL
+ */
+ public function setBackImageUrl($value)
+ {
+ $this->getStyle()->setBackImageUrl($value);
+ }
+
+ /**
+ * @return string alignment of the content in the panel. Defaults to 'NotSet'.
+ */
+ public function getDirection()
+ {
+ return $this->getStyle()->getDirection();
+ }
+
+ /**
+ * @param string alignment of the content in the panel.
+ * Valid values include 'NotSet', 'LeftToRight', 'RightToLeft'.
+ */
+ public function setDirection($value)
+ {
+ $this->getStyle()->setDirection($value);
+ }
+
+ /**
+ * @return string the ID path to the default button. Defaults to empty.
+ */
+ public function getDefaultButton()
+ {
+ return $this->_defaultButton;
+ }
+
+ /**
+ * Specifies the default button for the panel.
+ * The default button will be fired (clicked) whenever a user enters 'return'
+ * key within the panel.
+ * The button must be locatable via the function call {@link TControl::findControl findControl}.
+ * @param string the ID path to the default button.
+ */
+ public function setDefaultButton($value)
+ {
+ $this->_defaultButton=$value;
+ }
+
+ /**
+ * @return string the legend text when the panel is used as a fieldset. Defaults to empty.
+ */
+ public function getGroupingText()
+ {
+ return $this->getViewState('GroupingText','');
+ }
+
+ /**
+ * @param string the legend text. If this value is not empty, the panel will be rendered as a fieldset.
+ */
+ public function setGroupingText($value)
+ {
+ $this->setViewState('GroupingText',$value,'');
+ }
+
+ /**
+ * @return string the visibility and position of scroll bars in a panel control, defaults to None.
+ */
+ public function getScrollBars()
+ {
+ return $this->getStyle()->getScrollBars();
+ }
+
+ /**
+ * @param string the visibility and position of scroll bars in a panel control.
+ * Valid values include None, Auto, Both, Horizontal and Vertical.
+ */
+ public function setScrollBars($value)
+ {
+ $this->getStyle()->setScrollBars($value);
+ }
+
+ /**
+ * Renders the openning tag for the control (including attributes)
+ * @param THtmlWriter the writer used for the rendering purpose
+ */
+ public function renderBeginTag($writer)
+ {
+ parent::renderBeginTag($writer);
+ if(($text=$this->getGroupingText())!=='')
+ {
+ $writer->renderBeginTag('fieldset');
+ $writer->renderBeginTag('legend');
+ $writer->write($text);
+ $writer->renderEndTag();
+ }
+ }
+
+ /**
+ * Renders the closing tag for the control
+ * @param THtmlWriter the writer used for the rendering purpose
+ */
+ public function renderEndTag($writer)
+ {
+ if($this->getGroupingText()!=='')
+ $writer->renderEndTag();
+ parent::renderEndTag($writer);
+ }
+
+ public function render($writer)
+ {
+ parent::render($writer);
+
+ if(($butt=$this->getDefaultButton())!=='')
+ {
+ $buttons = $this->findControlsByID($butt);
+ if (count($buttons)>0)
+ $button = reset($buttons);
+ else
+ $button = null;
+ if($button===null)
+ throw new TInvalidDataValueException('panel_defaultbutton_invalid',$butt);
+ else
+ $this->getPage()->getClientScript()->registerDefaultButton($this, $button);
+ }
+ }
+}
+
diff --git a/framework/Web/UI/WebControls/TPanelStyle.php b/framework/Web/UI/WebControls/TPanelStyle.php
index 16169749..5e5db6e4 100644
--- a/framework/Web/UI/WebControls/TPanelStyle.php
+++ b/framework/Web/UI/WebControls/TPanelStyle.php
@@ -1,278 +1,278 @@
-<?php
-/**
- * TPanelStyle class file
- *
- * @author Qiang Xue <qiang.xue@gmail.com>
- * @link http://www.pradosoft.com/
+<?php
+/**
+ * TPanelStyle class file
+ *
+ * @author Qiang Xue <qiang.xue@gmail.com>
+ * @link http://www.pradosoft.com/
* @copyright Copyright &copy; 2005-2012 PradoSoft
- * @license http://www.pradosoft.com/license/
- * @version $Id$
- * @package System.Web.UI.WebControls
- */
-
-/**
- * Includes TStyle class file
- */
-Prado::using('System.Web.UI.WebControls.TStyle');
-
-/**
- * TPanelStyle class.
- * TPanelStyle represents the CSS style specific for panel HTML tag.
- *
- * @author Qiang Xue <qiang.xue@gmail.com>
- * @version $Id$
- * @package System.Web.UI.WebControls
- * @since 3.0
- */
-class TPanelStyle extends TStyle
-{
- /**
- * @var string the URL of the background image for the panel component
- */
- private $_backImageUrl=null;
- /**
- * @var string alignment of the content in the panel.
- */
- private $_direction=null;
- /**
- * @var string horizontal alignment of the contents within the panel
- */
- private $_horizontalAlign=null;
- /**
- * @var string visibility and position of scroll bars
- */
- private $_scrollBars=null;
- /**
- * @var boolean whether the content wraps within the panel
- */
- private $_wrap=null;
-
- /**
- * Adds attributes related to CSS styles to renderer.
- * This method overrides the parent implementation.
- * @param THtmlWriter the writer used for the rendering purpose
- */
- public function addAttributesToRender($writer)
- {
- if(($url=trim($this->getBackImageUrl()))!=='')
- $this->setStyleField('background-image','url('.$url.')');
-
- switch($this->getScrollBars())
- {
- case TScrollBars::Horizontal: $this->setStyleField('overflow-x','scroll'); break;
- case TScrollBars::Vertical: $this->setStyleField('overflow-y','scroll'); break;
- case TScrollBars::Both: $this->setStyleField('overflow','scroll'); break;
- case TScrollBars::Auto: $this->setStyleField('overflow','auto'); break;
- }
-
- if(($align=$this->getHorizontalAlign())!==THorizontalAlign::NotSet)
- $this->setStyleField('text-align',strtolower($align));
-
- if(!$this->getWrap())
- $this->setStyleField('white-space','nowrap');
-
- if(($direction=$this->getDirection())!==TContentDirection::NotSet)
- {
- if($direction===TContentDirection::LeftToRight)
- $this->setStyleField('direction','ltr');
- else
- $this->setStyleField('direction','rtl');
- }
-
- parent::addAttributesToRender($writer);
- }
-
- /**
- * @return string the URL of the background image for the panel component.
- */
- public function getBackImageUrl()
- {
- return $this->_backImageUrl===null?'':$this->_backImageUrl;
- }
-
- /**
- * Sets the URL of the background image for the panel component.
- * @param string the URL
- */
- public function setBackImageUrl($value)
- {
- $this->_backImageUrl=$value;
- }
-
- /**
- * @return TContentDirection alignment of the content in the panel. Defaults to TContentDirection::NotSet.
- */
- public function getDirection()
- {
- return $this->_direction===null?TContentDirection::NotSet:$this->_direction;
- }
-
- /**
- * @param TContentDirection alignment of the content in the panel.
- */
- public function setDirection($value)
- {
- $this->_direction=TPropertyValue::ensureEnum($value,'TContentDirection');
- }
-
- /**
- * @return boolean whether the content wraps within the panel. Defaults to true.
- */
- public function getWrap()
- {
- return $this->_wrap===null?true:$this->_wrap;
- }
-
- /**
- * Sets the value indicating whether the content wraps within the panel.
- * @param boolean whether the content wraps within the panel.
- */
- public function setWrap($value)
- {
- $this->_wrap=TPropertyValue::ensureBoolean($value);
- }
-
- /**
- * @return THorizontalAlign the horizontal alignment of the contents within the panel, defaults to THorizontalAlign::NotSet.
- */
- public function getHorizontalAlign()
- {
- return $this->_horizontalAlign===null?THorizontalAlign::NotSet:$this->_horizontalAlign;
- }
-
- /**
- * Sets the horizontal alignment of the contents within the panel.
- * @param THorizontalAlign the horizontal alignment
- */
- public function setHorizontalAlign($value)
- {
- $this->_horizontalAlign=TPropertyValue::ensureEnum($value,'THorizontalAlign');
- }
-
- /**
- * @return TScrollBars the visibility and position of scroll bars in a panel control, defaults to TScrollBars::None.
- */
- public function getScrollBars()
- {
- return $this->_scrollBars===null?TScrollBars::None:$this->_scrollBars;
- }
-
- /**
- * @param TScrollBars the visibility and position of scroll bars in a panel control.
- */
- public function setScrollBars($value)
- {
- $this->_scrollBars=TPropertyValue::ensureEnum($value,'TScrollBars');
- }
-
- /**
- * Sets the style attributes to default values.
- * This method overrides the parent implementation by
- * resetting additional TPanelStyle specific attributes.
- */
- public function reset()
- {
- parent::reset();
- $this->_backImageUrl=null;
- $this->_direction=null;
- $this->_horizontalAlign=null;
- $this->_scrollBars=null;
- $this->_wrap=null;
- }
-
- /**
- * Copies the fields in a new style to this style.
- * If a style field is set in the new style, the corresponding field
- * in this style will be overwritten.
- * @param TStyle the new style
- */
- public function copyFrom($style)
- {
- parent::copyFrom($style);
- if($style instanceof TPanelStyle)
- {
- if($style->_backImageUrl!==null)
- $this->_backImageUrl=$style->_backImageUrl;
- if($style->_direction!==null)
- $this->_direction=$style->_direction;
- if($style->_horizontalAlign!==null)
- $this->_horizontalAlign=$style->_horizontalAlign;
- if($style->_scrollBars!==null)
- $this->_scrollBars=$style->_scrollBars;
- if($style->_wrap!==null)
- $this->_wrap=$style->_wrap;
- }
- }
-
- /**
- * Merges the style with a new one.
- * If a style field is not set in this style, it will be overwritten by
- * the new one.
- * @param TStyle the new style
- */
- public function mergeWith($style)
- {
- parent::mergeWith($style);
- if($style instanceof TPanelStyle)
- {
- if($this->_backImageUrl===null && $style->_backImageUrl!==null)
- $this->_backImageUrl=$style->_backImageUrl;
- if($this->_direction===null && $style->_direction!==null)
- $this->_direction=$style->_direction;
- if($this->_horizontalAlign===null && $style->_horizontalAlign!==null)
- $this->_horizontalAlign=$style->_horizontalAlign;
- if($this->_scrollBars===null && $style->_scrollBars!==null)
- $this->_scrollBars=$style->_scrollBars;
- if($this->_wrap===null && $style->_wrap!==null)
- $this->_wrap=$style->_wrap;
- }
- }
-}
-
-/**
- * TContentDirection class.
- * TContentDirection defines the enumerable type for the possible directions that a panel can be at.
- *
- * The following enumerable values are defined:
- * - NotSet: the direction is not specified
- * - LeftToRight: content in a panel is left to right
- * - RightToLeft: content in a panel is right to left
- *
- * @author Qiang Xue <qiang.xue@gmail.com>
- * @version $Id$
- * @package System.Web.UI.WebControls
- * @since 3.0.4
- */
-class TContentDirection extends TEnumerable
-{
- const NotSet='NotSet';
- const LeftToRight='LeftToRight';
- const RightToLeft='RightToLeft';
-}
-
-/**
- * TScrollBars class.
- * TScrollBars defines the enumerable type for the possible scroll bar mode
- * that a {@link TPanel} control could use.
- *
- * The following enumerable values are defined:
- * - None: no scroll bars.
- * - Auto: scroll bars automatically appeared when needed.
- * - Both: show both horizontal and vertical scroll bars all the time.
- * - Horizontal: horizontal scroll bar only
- * - Vertical: vertical scroll bar only
- *
- * @author Qiang Xue <qiang.xue@gmail.com>
- * @version $Id$
- * @package System.Web.UI.WebControls
- * @since 3.0.4
- */
-class TScrollBars extends TEnumerable
-{
- const None='None';
- const Auto='Auto';
- const Both='Both';
- const Horizontal='Horizontal';
- const Vertical='Vertical';
-}
-
+ * @license http://www.pradosoft.com/license/
+ * @version $Id$
+ * @package System.Web.UI.WebControls
+ */
+
+/**
+ * Includes TStyle class file
+ */
+Prado::using('System.Web.UI.WebControls.TStyle');
+
+/**
+ * TPanelStyle class.
+ * TPanelStyle represents the CSS style specific for panel HTML tag.
+ *
+ * @author Qiang Xue <qiang.xue@gmail.com>
+ * @version $Id$
+ * @package System.Web.UI.WebControls
+ * @since 3.0
+ */
+class TPanelStyle extends TStyle
+{
+ /**
+ * @var string the URL of the background image for the panel component
+ */
+ private $_backImageUrl=null;
+ /**
+ * @var string alignment of the content in the panel.
+ */
+ private $_direction=null;
+ /**
+ * @var string horizontal alignment of the contents within the panel
+ */
+ private $_horizontalAlign=null;
+ /**
+ * @var string visibility and position of scroll bars
+ */
+ private $_scrollBars=null;
+ /**
+ * @var boolean whether the content wraps within the panel
+ */
+ private $_wrap=null;
+
+ /**
+ * Adds attributes related to CSS styles to renderer.
+ * This method overrides the parent implementation.
+ * @param THtmlWriter the writer used for the rendering purpose
+ */
+ public function addAttributesToRender($writer)
+ {
+ if(($url=trim($this->getBackImageUrl()))!=='')
+ $this->setStyleField('background-image','url('.$url.')');
+
+ switch($this->getScrollBars())
+ {
+ case TScrollBars::Horizontal: $this->setStyleField('overflow-x','scroll'); break;
+ case TScrollBars::Vertical: $this->setStyleField('overflow-y','scroll'); break;
+ case TScrollBars::Both: $this->setStyleField('overflow','scroll'); break;
+ case TScrollBars::Auto: $this->setStyleField('overflow','auto'); break;
+ }
+
+ if(($align=$this->getHorizontalAlign())!==THorizontalAlign::NotSet)
+ $this->setStyleField('text-align',strtolower($align));
+
+ if(!$this->getWrap())
+ $this->setStyleField('white-space','nowrap');
+
+ if(($direction=$this->getDirection())!==TContentDirection::NotSet)
+ {
+ if($direction===TContentDirection::LeftToRight)
+ $this->setStyleField('direction','ltr');
+ else
+ $this->setStyleField('direction','rtl');
+ }
+
+ parent::addAttributesToRender($writer);
+ }
+
+ /**
+ * @return string the URL of the background image for the panel component.
+ */
+ public function getBackImageUrl()
+ {
+ return $this->_backImageUrl===null?'':$this->_backImageUrl;
+ }
+
+ /**
+ * Sets the URL of the background image for the panel component.
+ * @param string the URL
+ */
+ public function setBackImageUrl($value)
+ {
+ $this->_backImageUrl=$value;
+ }
+
+ /**
+ * @return TContentDirection alignment of the content in the panel. Defaults to TContentDirection::NotSet.
+ */
+ public function getDirection()
+ {
+ return $this->_direction===null?TContentDirection::NotSet:$this->_direction;
+ }
+
+ /**
+ * @param TContentDirection alignment of the content in the panel.
+ */
+ public function setDirection($value)
+ {
+ $this->_direction=TPropertyValue::ensureEnum($value,'TContentDirection');
+ }
+
+ /**
+ * @return boolean whether the content wraps within the panel. Defaults to true.
+ */
+ public function getWrap()
+ {
+ return $this->_wrap===null?true:$this->_wrap;
+ }
+
+ /**
+ * Sets the value indicating whether the content wraps within the panel.
+ * @param boolean whether the content wraps within the panel.
+ */
+ public function setWrap($value)
+ {
+ $this->_wrap=TPropertyValue::ensureBoolean($value);
+ }
+
+ /**
+ * @return THorizontalAlign the horizontal alignment of the contents within the panel, defaults to THorizontalAlign::NotSet.
+ */
+ public function getHorizontalAlign()
+ {
+ return $this->_horizontalAlign===null?THorizontalAlign::NotSet:$this->_horizontalAlign;
+ }
+
+ /**
+ * Sets the horizontal alignment of the contents within the panel.
+ * @param THorizontalAlign the horizontal alignment
+ */
+ public function setHorizontalAlign($value)
+ {
+ $this->_horizontalAlign=TPropertyValue::ensureEnum($value,'THorizontalAlign');
+ }
+
+ /**
+ * @return TScrollBars the visibility and position of scroll bars in a panel control, defaults to TScrollBars::None.
+ */
+ public function getScrollBars()
+ {
+ return $this->_scrollBars===null?TScrollBars::None:$this->_scrollBars;
+ }
+
+ /**
+ * @param TScrollBars the visibility and position of scroll bars in a panel control.
+ */
+ public function setScrollBars($value)
+ {
+ $this->_scrollBars=TPropertyValue::ensureEnum($value,'TScrollBars');
+ }
+
+ /**
+ * Sets the style attributes to default values.
+ * This method overrides the parent implementation by
+ * resetting additional TPanelStyle specific attributes.
+ */
+ public function reset()
+ {
+ parent::reset();
+ $this->_backImageUrl=null;
+ $this->_direction=null;
+ $this->_horizontalAlign=null;
+ $this->_scrollBars=null;
+ $this->_wrap=null;
+ }
+
+ /**
+ * Copies the fields in a new style to this style.
+ * If a style field is set in the new style, the corresponding field
+ * in this style will be overwritten.
+ * @param TStyle the new style
+ */
+ public function copyFrom($style)
+ {
+ parent::copyFrom($style);
+ if($style instanceof TPanelStyle)
+ {
+ if($style->_backImageUrl!==null)
+ $this->_backImageUrl=$style->_backImageUrl;
+ if($style->_direction!==null)
+ $this->_direction=$style->_direction;
+ if($style->_horizontalAlign!==null)
+ $this->_horizontalAlign=$style->_horizontalAlign;
+ if($style->_scrollBars!==null)
+ $this->_scrollBars=$style->_scrollBars;
+ if($style->_wrap!==null)
+ $this->_wrap=$style->_wrap;
+ }
+ }
+
+ /**
+ * Merges the style with a new one.
+ * If a style field is not set in this style, it will be overwritten by
+ * the new one.
+ * @param TStyle the new style
+ */
+ public function mergeWith($style)
+ {
+ parent::mergeWith($style);
+ if($style instanceof TPanelStyle)
+ {
+ if($this->_backImageUrl===null && $style->_backImageUrl!==null)
+ $this->_backImageUrl=$style->_backImageUrl;
+ if($this->_direction===null && $style->_direction!==null)
+ $this->_direction=$style->_direction;
+ if($this->_horizontalAlign===null && $style->_horizontalAlign!==null)
+ $this->_horizontalAlign=$style->_horizontalAlign;
+ if($this->_scrollBars===null && $style->_scrollBars!==null)
+ $this->_scrollBars=$style->_scrollBars;
+ if($this->_wrap===null && $style->_wrap!==null)
+ $this->_wrap=$style->_wrap;
+ }
+ }
+}
+
+/**
+ * TContentDirection class.
+ * TContentDirection defines the enumerable type for the possible directions that a panel can be at.
+ *
+ * The following enumerable values are defined:
+ * - NotSet: the direction is not specified
+ * - LeftToRight: content in a panel is left to right
+ * - RightToLeft: content in a panel is right to left
+ *
+ * @author Qiang Xue <qiang.xue@gmail.com>
+ * @version $Id$
+ * @package System.Web.UI.WebControls
+ * @since 3.0.4
+ */
+class TContentDirection extends TEnumerable
+{
+ const NotSet='NotSet';
+ const LeftToRight='LeftToRight';
+ const RightToLeft='RightToLeft';
+}
+
+/**
+ * TScrollBars class.
+ * TScrollBars defines the enumerable type for the possible scroll bar mode
+ * that a {@link TPanel} control could use.
+ *
+ * The following enumerable values are defined:
+ * - None: no scroll bars.
+ * - Auto: scroll bars automatically appeared when needed.
+ * - Both: show both horizontal and vertical scroll bars all the time.
+ * - Horizontal: horizontal scroll bar only
+ * - Vertical: vertical scroll bar only
+ *
+ * @author Qiang Xue <qiang.xue@gmail.com>
+ * @version $Id$
+ * @package System.Web.UI.WebControls
+ * @since 3.0.4
+ */
+class TScrollBars extends TEnumerable
+{
+ const None='None';
+ const Auto='Auto';
+ const Both='Both';
+ const Horizontal='Horizontal';
+ const Vertical='Vertical';
+}
+
diff --git a/framework/Web/UI/WebControls/TPlaceHolder.php b/framework/Web/UI/WebControls/TPlaceHolder.php
index ac67cef7..585e9e99 100644
--- a/framework/Web/UI/WebControls/TPlaceHolder.php
+++ b/framework/Web/UI/WebControls/TPlaceHolder.php
@@ -1,28 +1,28 @@
-<?php
-/**
- * TPlaceHolder class file
- *
- * @author Qiang Xue <qiang.xue@gmail.com>
- * @link http://www.pradosoft.com/
+<?php
+/**
+ * TPlaceHolder class file
+ *
+ * @author Qiang Xue <qiang.xue@gmail.com>
+ * @link http://www.pradosoft.com/
* @copyright Copyright &copy; 2005-2012 PradoSoft
- * @license http://www.pradosoft.com/license/
- * @version $Id$
- * @package System.Web.UI.WebControls
- */
-
-/**
- * TPlaceHolder class
- *
- * TPlaceHolder reserves a place on a template, where static texts or controls
- * may be inserted. You may add or remove texts or child controls of TPlaceHolder
- * by manipulating the {@link TControl::getControls Controls} property.
- *
- * @author Qiang Xue <qiang.xue@gmail.com>
- * @version $Id$
- * @package System.Web.UI.WebControls
- * @since 3.0
- */
-class TPlaceHolder extends TControl
-{
-}
-
+ * @license http://www.pradosoft.com/license/
+ * @version $Id$
+ * @package System.Web.UI.WebControls
+ */
+
+/**
+ * TPlaceHolder class
+ *
+ * TPlaceHolder reserves a place on a template, where static texts or controls
+ * may be inserted. You may add or remove texts or child controls of TPlaceHolder
+ * by manipulating the {@link TControl::getControls Controls} property.
+ *
+ * @author Qiang Xue <qiang.xue@gmail.com>
+ * @version $Id$
+ * @package System.Web.UI.WebControls
+ * @since 3.0
+ */
+class TPlaceHolder extends TControl
+{
+}
+
diff --git a/framework/Web/UI/WebControls/TRadioButton.php b/framework/Web/UI/WebControls/TRadioButton.php
index b90cfcf5..6a2347f4 100644
--- a/framework/Web/UI/WebControls/TRadioButton.php
+++ b/framework/Web/UI/WebControls/TRadioButton.php
@@ -1,320 +1,320 @@
-<?php
-/**
- * TRadioButton class file
- *
- * @author Qiang Xue <qiang.xue@gmail.com>
- * @link http://www.pradosoft.com/
+<?php
+/**
+ * TRadioButton class file
+ *
+ * @author Qiang Xue <qiang.xue@gmail.com>
+ * @link http://www.pradosoft.com/
* @copyright Copyright &copy; 2005-2012 PradoSoft
- * @license http://www.pradosoft.com/license/
- * @version $Id$
- * @package System.Web.UI.WebControls
- */
-
-/**
- * Using TCheckBox parent class
- */
-Prado::using('System.Web.UI.WebControls.TCheckBox');
-/**
- * Using TRadioButtonList class
- */
-Prado::using('System.Web.UI.WebControls.TRadioButtonList');
-
-/**
- * TRadioButton class
- *
- * TRadioButton displays a radio button on the page.
- * You can specify the caption to display beside the radio buttonby setting
- * the {@link setText Text} property. The caption can appear either on the right
- * or left of the radio button, which is determined by the {@link setTextAlign TextAlign}
- * property.
- *
- * To determine whether the TRadioButton component is checked, test the {@link getChecked Checked}
- * property. The {@link onCheckedChanged OnCheckedChanged} event is raised when
- * the {@link getChecked Checked} state of the TRadioButton component changes
- * between posts to the server. You can provide an event handler for
- * the {@link onCheckedChanged OnCheckedChanged} event to to programmatically
- * control the actions performed when the state of the TRadioButton component changes
- * between posts to the server.
- *
- * TRadioButton uses {@link setGroupName GroupName} to group together a set of radio buttons.
- * Once the {@link setGroupName GroupName} is set, you can use the {@link getRadioButtonsInGroup}
- * method to get an array of TRadioButtons having the same group name.
- *
- * If {@link setAutoPostBack AutoPostBack} is set true, changing the radio button state
- * will cause postback action. And if {@link setCausesValidation CausesValidation}
- * is true, validation will also be processed, which can be further restricted within
- * a {@link setValidationGroup ValidationGroup}.
- *
- * Note, {@link setText Text} is rendered as is. Make sure it does not contain unwanted characters
- * that may bring security vulnerabilities.
- *
- * @author Qiang Xue <qiang.xue@gmail.com>
- * @version $Id$
- * @package System.Web.UI.WebControls
- * @since 3.0
- */
-class TRadioButton extends TCheckBox
-{
- /**
- * @param array list of radio buttons that are on the current page hierarchy
- */
- private static $_activeButtons=array();
- /**
- * @var integer number of radio buttons created
- */
- private static $_buttonCount=0;
- /**
- * @var integer global ID of this radiobutton
- */
- private $_globalID;
- /**
- * @var string previous UniqueID (used to calculate UniqueGroup)
- */
- private $_previousUniqueID=null;
- /**
- * @var string the name used to fetch radiobutton post data
- */
- private $_uniqueGroupName=null;
-
- /**
- * Constructor.
- * Registers the radiobutton in a global radiobutton collection.
- * If overridden, the parent implementation must be invoked first.
- */
- public function __construct()
- {
- parent::__construct();
- $this->_globalID = self::$_buttonCount++;
- }
-
- /**
- * Registers the radio button groupings. If overriding onInit method,
- * ensure to call parent implemenation.
- * @param TEventParameter event parameter to be passed to the event handlers
- */
- public function onInit($param)
- {
- parent::onInit($param);
- self::$_activeButtons[$this->_globalID]=$this;
- }
-
- /**
- * Unregisters the radio button groupings. If overriding onInit method,
- * ensure to call parent implemenation.
- * @param TEventParameter event parameter to be passed to the event handlers
- */
- public function onUnLoad($param)
- {
- unset(self::$_activeButtons[$this->_globalID]);
- parent::onUnLoad($param);
- }
-
- /**
- * Loads user input data.
- * This method is primarly used by framework developers.
- * @param string the key that can be used to retrieve data from the input data collection
- * @param array the input data collection
- * @return boolean whether the data of the control has been changed
- */
- public function loadPostData($key,$values)
- {
- $uniqueGroupName=$this->getUniqueGroupName();
- $value=isset($values[$uniqueGroupName])?$values[$uniqueGroupName]:null;
- if($value!==null && $value===$this->getValueAttribute())
- {
- if(!$this->getChecked())
- {
- $this->setChecked(true);
- return true;
- }
- else
- return false;
- }
- else if($this->getChecked())
- $this->setChecked(false);
- return false;
- }
-
- /**
- * @return string the name of the group that the radio button belongs to. Defaults to empty.
- */
- public function getGroupName()
- {
- return $this->getViewState('GroupName','');
- }
-
- /**
- * Sets the name of the group that the radio button belongs to.
- * The group is unique among the control's naming container.
- * @param string the group name
- * @see setUniqueGroupName
- */
- public function setGroupName($value)
- {
- $this->setViewState('GroupName',$value,'');
- $this->_uniqueGroupName=null;
- }
-
- /**
- * Add the group name as post data loader if group name is set.
- */
- protected function addToPostDataLoader()
- {
- parent::addToPostDataLoader();
- $group = $this->getGroupName();
- if(!empty($group) || $this->getViewState('UniqueGroupName','') !== '')
- $this->getPage()->registerPostDataLoader($this->getUniqueGroupName());
- }
- /**
- * @return string the name used to fetch radiobutton post data
- */
- public function getUniqueGroupName()
- {
- if(($groupName=$this->getViewState('UniqueGroupName',''))!=='')
- return $groupName;
- else if(($uniqueID=$this->getUniqueID())!==$this->_previousUniqueID || $this->_uniqueGroupName===null)
- {
- $groupName=$this->getGroupName();
- $this->_previousUniqueID=$uniqueID;
- if($uniqueID!=='')
- {
- if(($pos=strrpos($uniqueID,TControl::ID_SEPARATOR))!==false)
- {
- if($groupName!=='')
- $groupName=substr($uniqueID,0,$pos+1).$groupName;
- else if($this->getNamingContainer() instanceof TRadioButtonList)
- $groupName=substr($uniqueID,0,$pos);
- }
- if($groupName==='')
- $groupName=$uniqueID;
- }
- $this->_uniqueGroupName=$groupName;
- }
- return $this->_uniqueGroupName;
- }
-
- /**
- * Sets the unique group name that the radio button belongs to.
- * A unique group is a radiobutton group unique among the whole page hierarchy,
- * while the {@link setGroupName GroupName} specifies a group that is unique
- * among the control's naming container only.
- * For example, each cell of a {@link TDataGrid} is a naming container.
- * If you specify {@link setGroupName GroupName} for a radiobutton in a cell,
- * it groups together radiobutton within a cell, but not the other, even though
- * they have the same {@link setGroupName GroupName}.
- * On the contratry, if {@link setUniqueGroupName UniqueGroupName} is used instead,
- * it will group all appropriate radio buttons on the whole page hierarchy.
- * Note, when both {@link setUniqueGroupName UniqueGroupName} and
- * {@link setGroupName GroupName}, the former takes precedence.
- * @param string the group name
- * @see setGroupName
- */
- public function setUniqueGroupName($value)
- {
- $this->setViewState('UniqueGroupName',$value,'');
- }
-
- /**
- * Gets an array of radiobuttons whose group name is the same as this radiobutton's.
- * Note, only those radiobuttons that are on the current page hierarchy may be
- * returned in the result.
- * @return array list of TRadioButton with the same group
- */
- public function getRadioButtonsInGroup()
- {
- $group = $this->getUniqueGroupName();
- $buttons = array();
- foreach(self::$_activeButtons as $control)
- {
- if($control->getUniqueGroupName() === $group)
- $buttons[] = $control;
- }
- return $buttons;
- }
-
- /**
- * @return string the value attribute to be rendered
- */
- protected function getValueAttribute()
- {
- if(($value=parent::getValueAttribute())==='')
- return $this->getUniqueID();
- else
- return $value;
- }
-
- /**
- * @return boolean whether to render javascript.
- */
- public function getEnableClientScript()
- {
- return $this->getViewState('EnableClientScript',true);
- }
-
- /**
- * @param boolean whether to render javascript.
- */
- public function setEnableClientScript($value)
- {
- $this->setViewState('EnableClientScript',TPropertyValue::ensureBoolean($value),true);
- }
-
- /**
- * Renders a radiobutton input element.
- * @param THtmlWriter the writer for the rendering purpose
- * @param string checkbox id
- * @param string onclick js
- */
- protected function renderInputTag($writer,$clientID,$onclick)
- {
- if($clientID!=='')
- $writer->addAttribute('id',$clientID);
- $writer->addAttribute('type','radio');
- $writer->addAttribute('name',$this->getUniqueGroupName());
- $writer->addAttribute('value',$this->getValueAttribute());
- if(!empty($onclick))
- $writer->addAttribute('onclick',$onclick);
- if($this->getChecked())
- $writer->addAttribute('checked','checked');
- if(!$this->getEnabled(true))
- $writer->addAttribute('disabled','disabled');
-
- $page=$this->getPage();
- if($this->getEnabled(true)
- && $this->getEnableClientScript()
- && $this->getAutoPostBack()
- && $page->getClientSupportsJavaScript())
- {
- $this->renderClientControlScript($writer);
- }
-
- if(($accesskey=$this->getAccessKey())!=='')
- $writer->addAttribute('accesskey',$accesskey);
- if(($tabindex=$this->getTabIndex())>0)
- $writer->addAttribute('tabindex',"$tabindex");
- if($attributes=$this->getViewState('InputAttributes',null))
- $writer->addAttributes($attributes);
- $writer->renderBeginTag('input');
- $writer->renderEndTag();
- }
-
- /**
- * Renders the client-script code.
- */
- protected function renderClientControlScript($writer)
- {
- $cs = $this->getPage()->getClientScript();
- $cs->registerPostBackControl($this->getClientClassName(),$this->getPostBackOptions());
- }
-
- /**
- * Gets the name of the javascript class responsible for performing postback for this control.
- * This method overrides the parent implementation.
- * @return string the javascript class name
- */
- protected function getClientClassName()
- {
- return 'Prado.WebUI.TRadioButton';
- }
-}
-
+ * @license http://www.pradosoft.com/license/
+ * @version $Id$
+ * @package System.Web.UI.WebControls
+ */
+
+/**
+ * Using TCheckBox parent class
+ */
+Prado::using('System.Web.UI.WebControls.TCheckBox');
+/**
+ * Using TRadioButtonList class
+ */
+Prado::using('System.Web.UI.WebControls.TRadioButtonList');
+
+/**
+ * TRadioButton class
+ *
+ * TRadioButton displays a radio button on the page.
+ * You can specify the caption to display beside the radio buttonby setting
+ * the {@link setText Text} property. The caption can appear either on the right
+ * or left of the radio button, which is determined by the {@link setTextAlign TextAlign}
+ * property.
+ *
+ * To determine whether the TRadioButton component is checked, test the {@link getChecked Checked}
+ * property. The {@link onCheckedChanged OnCheckedChanged} event is raised when
+ * the {@link getChecked Checked} state of the TRadioButton component changes
+ * between posts to the server. You can provide an event handler for
+ * the {@link onCheckedChanged OnCheckedChanged} event to to programmatically
+ * control the actions performed when the state of the TRadioButton component changes
+ * between posts to the server.
+ *
+ * TRadioButton uses {@link setGroupName GroupName} to group together a set of radio buttons.
+ * Once the {@link setGroupName GroupName} is set, you can use the {@link getRadioButtonsInGroup}
+ * method to get an array of TRadioButtons having the same group name.
+ *
+ * If {@link setAutoPostBack AutoPostBack} is set true, changing the radio button state
+ * will cause postback action. And if {@link setCausesValidation CausesValidation}
+ * is true, validation will also be processed, which can be further restricted within
+ * a {@link setValidationGroup ValidationGroup}.
+ *
+ * Note, {@link setText Text} is rendered as is. Make sure it does not contain unwanted characters
+ * that may bring security vulnerabilities.
+ *
+ * @author Qiang Xue <qiang.xue@gmail.com>
+ * @version $Id$
+ * @package System.Web.UI.WebControls
+ * @since 3.0
+ */
+class TRadioButton extends TCheckBox
+{
+ /**
+ * @param array list of radio buttons that are on the current page hierarchy
+ */
+ private static $_activeButtons=array();
+ /**
+ * @var integer number of radio buttons created
+ */
+ private static $_buttonCount=0;
+ /**
+ * @var integer global ID of this radiobutton
+ */
+ private $_globalID;
+ /**
+ * @var string previous UniqueID (used to calculate UniqueGroup)
+ */
+ private $_previousUniqueID=null;
+ /**
+ * @var string the name used to fetch radiobutton post data
+ */
+ private $_uniqueGroupName=null;
+
+ /**
+ * Constructor.
+ * Registers the radiobutton in a global radiobutton collection.
+ * If overridden, the parent implementation must be invoked first.
+ */
+ public function __construct()
+ {
+ parent::__construct();
+ $this->_globalID = self::$_buttonCount++;
+ }
+
+ /**
+ * Registers the radio button groupings. If overriding onInit method,
+ * ensure to call parent implemenation.
+ * @param TEventParameter event parameter to be passed to the event handlers
+ */
+ public function onInit($param)
+ {
+ parent::onInit($param);
+ self::$_activeButtons[$this->_globalID]=$this;
+ }
+
+ /**
+ * Unregisters the radio button groupings. If overriding onInit method,
+ * ensure to call parent implemenation.
+ * @param TEventParameter event parameter to be passed to the event handlers
+ */
+ public function onUnLoad($param)
+ {
+ unset(self::$_activeButtons[$this->_globalID]);
+ parent::onUnLoad($param);
+ }
+
+ /**
+ * Loads user input data.
+ * This method is primarly used by framework developers.
+ * @param string the key that can be used to retrieve data from the input data collection
+ * @param array the input data collection
+ * @return boolean whether the data of the control has been changed
+ */
+ public function loadPostData($key,$values)
+ {
+ $uniqueGroupName=$this->getUniqueGroupName();
+ $value=isset($values[$uniqueGroupName])?$values[$uniqueGroupName]:null;
+ if($value!==null && $value===$this->getValueAttribute())
+ {
+ if(!$this->getChecked())
+ {
+ $this->setChecked(true);
+ return true;
+ }
+ else
+ return false;
+ }
+ else if($this->getChecked())
+ $this->setChecked(false);
+ return false;
+ }
+
+ /**
+ * @return string the name of the group that the radio button belongs to. Defaults to empty.
+ */
+ public function getGroupName()
+ {
+ return $this->getViewState('GroupName','');
+ }
+
+ /**
+ * Sets the name of the group that the radio button belongs to.
+ * The group is unique among the control's naming container.
+ * @param string the group name
+ * @see setUniqueGroupName
+ */
+ public function setGroupName($value)
+ {
+ $this->setViewState('GroupName',$value,'');
+ $this->_uniqueGroupName=null;
+ }
+
+ /**
+ * Add the group name as post data loader if group name is set.
+ */
+ protected function addToPostDataLoader()
+ {
+ parent::addToPostDataLoader();
+ $group = $this->getGroupName();
+ if(!empty($group) || $this->getViewState('UniqueGroupName','') !== '')
+ $this->getPage()->registerPostDataLoader($this->getUniqueGroupName());
+ }
+ /**
+ * @return string the name used to fetch radiobutton post data
+ */
+ public function getUniqueGroupName()
+ {
+ if(($groupName=$this->getViewState('UniqueGroupName',''))!=='')
+ return $groupName;
+ else if(($uniqueID=$this->getUniqueID())!==$this->_previousUniqueID || $this->_uniqueGroupName===null)
+ {
+ $groupName=$this->getGroupName();
+ $this->_previousUniqueID=$uniqueID;
+ if($uniqueID!=='')
+ {
+ if(($pos=strrpos($uniqueID,TControl::ID_SEPARATOR))!==false)
+ {
+ if($groupName!=='')
+ $groupName=substr($uniqueID,0,$pos+1).$groupName;
+ else if($this->getNamingContainer() instanceof TRadioButtonList)
+ $groupName=substr($uniqueID,0,$pos);
+ }
+ if($groupName==='')
+ $groupName=$uniqueID;
+ }
+ $this->_uniqueGroupName=$groupName;
+ }
+ return $this->_uniqueGroupName;
+ }
+
+ /**
+ * Sets the unique group name that the radio button belongs to.
+ * A unique group is a radiobutton group unique among the whole page hierarchy,
+ * while the {@link setGroupName GroupName} specifies a group that is unique
+ * among the control's naming container only.
+ * For example, each cell of a {@link TDataGrid} is a naming container.
+ * If you specify {@link setGroupName GroupName} for a radiobutton in a cell,
+ * it groups together radiobutton within a cell, but not the other, even though
+ * they have the same {@link setGroupName GroupName}.
+ * On the contratry, if {@link setUniqueGroupName UniqueGroupName} is used instead,
+ * it will group all appropriate radio buttons on the whole page hierarchy.
+ * Note, when both {@link setUniqueGroupName UniqueGroupName} and
+ * {@link setGroupName GroupName}, the former takes precedence.
+ * @param string the group name
+ * @see setGroupName
+ */
+ public function setUniqueGroupName($value)
+ {
+ $this->setViewState('UniqueGroupName',$value,'');
+ }
+
+ /**
+ * Gets an array of radiobuttons whose group name is the same as this radiobutton's.
+ * Note, only those radiobuttons that are on the current page hierarchy may be
+ * returned in the result.
+ * @return array list of TRadioButton with the same group
+ */
+ public function getRadioButtonsInGroup()
+ {
+ $group = $this->getUniqueGroupName();
+ $buttons = array();
+ foreach(self::$_activeButtons as $control)
+ {
+ if($control->getUniqueGroupName() === $group)
+ $buttons[] = $control;
+ }
+ return $buttons;
+ }
+
+ /**
+ * @return string the value attribute to be rendered
+ */
+ protected function getValueAttribute()
+ {
+ if(($value=parent::getValueAttribute())==='')
+ return $this->getUniqueID();
+ else
+ return $value;
+ }
+
+ /**
+ * @return boolean whether to render javascript.
+ */
+ public function getEnableClientScript()
+ {
+ return $this->getViewState('EnableClientScript',true);
+ }
+
+ /**
+ * @param boolean whether to render javascript.
+ */
+ public function setEnableClientScript($value)
+ {
+ $this->setViewState('EnableClientScript',TPropertyValue::ensureBoolean($value),true);
+ }
+
+ /**
+ * Renders a radiobutton input element.
+ * @param THtmlWriter the writer for the rendering purpose
+ * @param string checkbox id
+ * @param string onclick js
+ */
+ protected function renderInputTag($writer,$clientID,$onclick)
+ {
+ if($clientID!=='')
+ $writer->addAttribute('id',$clientID);
+ $writer->addAttribute('type','radio');
+ $writer->addAttribute('name',$this->getUniqueGroupName());
+ $writer->addAttribute('value',$this->getValueAttribute());
+ if(!empty($onclick))
+ $writer->addAttribute('onclick',$onclick);
+ if($this->getChecked())
+ $writer->addAttribute('checked','checked');
+ if(!$this->getEnabled(true))
+ $writer->addAttribute('disabled','disabled');
+
+ $page=$this->getPage();
+ if($this->getEnabled(true)
+ && $this->getEnableClientScript()
+ && $this->getAutoPostBack()
+ && $page->getClientSupportsJavaScript())
+ {
+ $this->renderClientControlScript($writer);
+ }
+
+ if(($accesskey=$this->getAccessKey())!=='')
+ $writer->addAttribute('accesskey',$accesskey);
+ if(($tabindex=$this->getTabIndex())>0)
+ $writer->addAttribute('tabindex',"$tabindex");
+ if($attributes=$this->getViewState('InputAttributes',null))
+ $writer->addAttributes($attributes);
+ $writer->renderBeginTag('input');
+ $writer->renderEndTag();
+ }
+
+ /**
+ * Renders the client-script code.
+ */
+ protected function renderClientControlScript($writer)
+ {
+ $cs = $this->getPage()->getClientScript();
+ $cs->registerPostBackControl($this->getClientClassName(),$this->getPostBackOptions());
+ }
+
+ /**
+ * Gets the name of the javascript class responsible for performing postback for this control.
+ * This method overrides the parent implementation.
+ * @return string the javascript class name
+ */
+ protected function getClientClassName()
+ {
+ return 'Prado.WebUI.TRadioButton';
+ }
+}
+
diff --git a/framework/Web/UI/WebControls/TRangeValidator.php b/framework/Web/UI/WebControls/TRangeValidator.php
index d8d2d20d..57538e88 100644
--- a/framework/Web/UI/WebControls/TRangeValidator.php
+++ b/framework/Web/UI/WebControls/TRangeValidator.php
@@ -1,360 +1,360 @@
-<?php
-/**
- * TRangeValidator class file
- *
- * @author Qiang Xue <qiang.xue@gmail.com>
- * @link http://www.pradosoft.com/
+<?php
+/**
+ * TRangeValidator class file
+ *
+ * @author Qiang Xue <qiang.xue@gmail.com>
+ * @link http://www.pradosoft.com/
* @copyright Copyright &copy; 2005-2012 PradoSoft
- * @license http://www.pradosoft.com/license/
- * @version $Id$
- * @package System.Web.UI.WebControls
- */
-
-/**
- * Using TBaseValidator class
- */
-Prado::using('System.Web.UI.WebControls.TBaseValidator');
-
-/**
- * TRangeValidator class
- *
- * TRangeValidator tests whether an input value is within a specified range.
- *
- * TRangeValidator uses three key properties to perform its validation.
- * The {@link setMinValue MinValue} and {@link setMaxValue MaxValue}
- * properties specify the minimum and maximum values of the valid range.
- * The {@link setDataType DataType} property is used to specify the
- * data type of the value and the minimum and maximum range values.
- * These values are converted to this data type before the validation
- * operation is performed. The following value types are supported:
- * - <b>Integer</b> A 32-bit signed integer data type.
- * - <b>Float</b> A double-precision floating point number data type.
- * - <b>Date</b> A date data type. The date format can be specified by
- * setting {@link setDateFormat DateFormat} property, which must be recognizable
- * by {@link TSimpleDateFormatter}. If the property is not set,
- * the GNU date syntax is assumed.
- * - <b>String</b> A string data type.
- * - <b>StringLength</b> check for string length.
- *
- * If {@link setStrictComparison StrictComparison} is true, then the ranges
- * are compared as strictly less than the max value and/or strictly greater than the min value.
- *
- * The TRangeValidator allows a special DataType "StringLength" that
- * can be used to verify minimum and maximum string length. The
- * {@link setCharset Charset} property can be used to force a particular
- * charset for comparison. Otherwise, the application charset is used and is
- * defaulted as UTF-8.
- *
- * @author Qiang Xue <qiang.xue@gmail.com>
- * @version $Id$
- * @package System.Web.UI.WebControls
- * @since 3.0
- */
-class TRangeValidator extends TBaseValidator
-{
- /**
- * Gets the name of the javascript class responsible for performing validation for this control.
- * This method overrides the parent implementation.
- * @return string the javascript class name
- */
- protected function getClientClassName()
- {
- return 'Prado.WebUI.TRangeValidator';
- }
-
- /**
- * @return string the minimum value of the validation range.
- */
- public function getMinValue()
- {
- return $this->getViewState('MinValue','');
- }
-
- /**
- * Sets the minimum value of the validation range.
- * @param string the minimum value
- */
- public function setMinValue($value)
- {
- $this->setViewState('MinValue',TPropertyValue::ensureString($value),'');
- }
-
- /**
- * @return string the maximum value of the validation range.
- */
- public function getMaxValue()
- {
- return $this->getViewState('MaxValue','');
- }
-
- /**
- * Sets the maximum value of the validation range.
- * @param string the maximum value
- */
- public function setMaxValue($value)
- {
- $this->setViewState('MaxValue',TPropertyValue::ensureString($value),'');
- }
-
- /**
- * @param boolean true to perform strict comparison (i.e. strictly less than max and/or strictly greater than min).
- */
- public function setStrictComparison($value)
- {
- $this->setViewState('StrictComparison', TPropertyValue::ensureBoolean($value),false);
- }
-
- /**
- * @return boolean true to perform strict comparison.
- */
- public function getStrictComparison()
- {
- return $this->getViewState('StrictComparison', false);
- }
-
- /**
- * @return TRangeValidationDataType the data type that the values being compared are
- * converted to before the comparison is made. Defaults to TRangeValidationDataType::String.
- */
- public function getDataType()
- {
- return $this->getViewState('DataType',TRangeValidationDataType::String);
- }
-
- /**
- * Sets the data type that the values being compared are converted to before the comparison is made.
- * @param TRangeValidationDataType the data type
- */
- public function setDataType($value)
- {
- $this->setViewState('DataType',TPropertyValue::ensureEnum($value,'TRangeValidationDataType'),TRangeValidationDataType::String);
- }
-
- /**
- * Sets the date format for a date validation
- * @param string the date format value
- */
- public function setDateFormat($value)
- {
- $this->setViewState('DateFormat', $value, '');
- }
-
- /**
- * @return string the date validation date format if any
- */
- public function getDateFormat()
- {
- return $this->getViewState('DateFormat', '');
- }
-
- /**
- * @param string charset for string length comparison.
- */
- public function setCharset($value)
- {
- $this->setViewState('Charset', $value, '');
- }
-
- /**
- * @return string charset for string length comparison.
- */
- public function getCharset()
- {
- return $this->getViewState('Charset', '');
- }
-
- /**
- * This method overrides the parent's implementation.
- * The validation succeeds if the input data is within the range.
- * The validation always succeeds if the input data is empty.
- * @return boolean whether the validation succeeds
- */
- protected function evaluateIsValid()
- {
- $value=$this->getValidationValue($this->getValidationTarget());
- if($value==='')
- return true;
-
- switch($this->getDataType())
- {
- case TRangeValidationDataType::Integer:
- return $this->isValidInteger($value);
- case TRangeValidationDataType::Float:
- return $this->isValidFloat($value);
- case TRangeValidationDataType::Date:
- return $this->isValidDate($value);
- case TRangeValidationDataType::StringLength:
- return $this->isValidStringLength($value);
- default:
- return $this->isValidString($value);
- }
- }
-
- /**
- * Determine if the value is within the integer range.
- * @param string value to validate true
- * @return boolean true if within integer range.
- */
- protected function isValidInteger($value)
- {
- $minValue=$this->getMinValue();
- $maxValue=$this->getMaxValue();
-
+ * @license http://www.pradosoft.com/license/
+ * @version $Id$
+ * @package System.Web.UI.WebControls
+ */
+
+/**
+ * Using TBaseValidator class
+ */
+Prado::using('System.Web.UI.WebControls.TBaseValidator');
+
+/**
+ * TRangeValidator class
+ *
+ * TRangeValidator tests whether an input value is within a specified range.
+ *
+ * TRangeValidator uses three key properties to perform its validation.
+ * The {@link setMinValue MinValue} and {@link setMaxValue MaxValue}
+ * properties specify the minimum and maximum values of the valid range.
+ * The {@link setDataType DataType} property is used to specify the
+ * data type of the value and the minimum and maximum range values.
+ * These values are converted to this data type before the validation
+ * operation is performed. The following value types are supported:
+ * - <b>Integer</b> A 32-bit signed integer data type.
+ * - <b>Float</b> A double-precision floating point number data type.
+ * - <b>Date</b> A date data type. The date format can be specified by
+ * setting {@link setDateFormat DateFormat} property, which must be recognizable
+ * by {@link TSimpleDateFormatter}. If the property is not set,
+ * the GNU date syntax is assumed.
+ * - <b>String</b> A string data type.
+ * - <b>StringLength</b> check for string length.
+ *
+ * If {@link setStrictComparison StrictComparison} is true, then the ranges
+ * are compared as strictly less than the max value and/or strictly greater than the min value.
+ *
+ * The TRangeValidator allows a special DataType "StringLength" that
+ * can be used to verify minimum and maximum string length. The
+ * {@link setCharset Charset} property can be used to force a particular
+ * charset for comparison. Otherwise, the application charset is used and is
+ * defaulted as UTF-8.
+ *
+ * @author Qiang Xue <qiang.xue@gmail.com>
+ * @version $Id$
+ * @package System.Web.UI.WebControls
+ * @since 3.0
+ */
+class TRangeValidator extends TBaseValidator
+{
+ /**
+ * Gets the name of the javascript class responsible for performing validation for this control.
+ * This method overrides the parent implementation.
+ * @return string the javascript class name
+ */
+ protected function getClientClassName()
+ {
+ return 'Prado.WebUI.TRangeValidator';
+ }
+
+ /**
+ * @return string the minimum value of the validation range.
+ */
+ public function getMinValue()
+ {
+ return $this->getViewState('MinValue','');
+ }
+
+ /**
+ * Sets the minimum value of the validation range.
+ * @param string the minimum value
+ */
+ public function setMinValue($value)
+ {
+ $this->setViewState('MinValue',TPropertyValue::ensureString($value),'');
+ }
+
+ /**
+ * @return string the maximum value of the validation range.
+ */
+ public function getMaxValue()
+ {
+ return $this->getViewState('MaxValue','');
+ }
+
+ /**
+ * Sets the maximum value of the validation range.
+ * @param string the maximum value
+ */
+ public function setMaxValue($value)
+ {
+ $this->setViewState('MaxValue',TPropertyValue::ensureString($value),'');
+ }
+
+ /**
+ * @param boolean true to perform strict comparison (i.e. strictly less than max and/or strictly greater than min).
+ */
+ public function setStrictComparison($value)
+ {
+ $this->setViewState('StrictComparison', TPropertyValue::ensureBoolean($value),false);
+ }
+
+ /**
+ * @return boolean true to perform strict comparison.
+ */
+ public function getStrictComparison()
+ {
+ return $this->getViewState('StrictComparison', false);
+ }
+
+ /**
+ * @return TRangeValidationDataType the data type that the values being compared are
+ * converted to before the comparison is made. Defaults to TRangeValidationDataType::String.
+ */
+ public function getDataType()
+ {
+ return $this->getViewState('DataType',TRangeValidationDataType::String);
+ }
+
+ /**
+ * Sets the data type that the values being compared are converted to before the comparison is made.
+ * @param TRangeValidationDataType the data type
+ */
+ public function setDataType($value)
+ {
+ $this->setViewState('DataType',TPropertyValue::ensureEnum($value,'TRangeValidationDataType'),TRangeValidationDataType::String);
+ }
+
+ /**
+ * Sets the date format for a date validation
+ * @param string the date format value
+ */
+ public function setDateFormat($value)
+ {
+ $this->setViewState('DateFormat', $value, '');
+ }
+
+ /**
+ * @return string the date validation date format if any
+ */
+ public function getDateFormat()
+ {
+ return $this->getViewState('DateFormat', '');
+ }
+
+ /**
+ * @param string charset for string length comparison.
+ */
+ public function setCharset($value)
+ {
+ $this->setViewState('Charset', $value, '');
+ }
+
+ /**
+ * @return string charset for string length comparison.
+ */
+ public function getCharset()
+ {
+ return $this->getViewState('Charset', '');
+ }
+
+ /**
+ * This method overrides the parent's implementation.
+ * The validation succeeds if the input data is within the range.
+ * The validation always succeeds if the input data is empty.
+ * @return boolean whether the validation succeeds
+ */
+ protected function evaluateIsValid()
+ {
+ $value=$this->getValidationValue($this->getValidationTarget());
+ if($value==='')
+ return true;
+
+ switch($this->getDataType())
+ {
+ case TRangeValidationDataType::Integer:
+ return $this->isValidInteger($value);
+ case TRangeValidationDataType::Float:
+ return $this->isValidFloat($value);
+ case TRangeValidationDataType::Date:
+ return $this->isValidDate($value);
+ case TRangeValidationDataType::StringLength:
+ return $this->isValidStringLength($value);
+ default:
+ return $this->isValidString($value);
+ }
+ }
+
+ /**
+ * Determine if the value is within the integer range.
+ * @param string value to validate true
+ * @return boolean true if within integer range.
+ */
+ protected function isValidInteger($value)
+ {
+ $minValue=$this->getMinValue();
+ $maxValue=$this->getMaxValue();
+
$valid=preg_match('/^[-+]?[0-9]+$/',trim($value));
- $value=intval($value);
- if($minValue!=='')
- $valid=$valid && $this->isGreaterThan($value, intval($minValue));
- if($maxValue!=='')
- $valid=$valid && $this->isLessThan($value,intval($maxValue));
- return $valid;
- }
-
- protected function isLessThan($left,$right)
- {
- return $this->getStrictComparison() ? $left < $right : $left <= $right;
- }
-
- protected function isGreaterThan($left, $right)
- {
- return $this->getStrictComparison() ? $left > $right : $left >= $right;
- }
-
- /**
- * Determine if the value is within the specified float range.
- * @param string value to validate
- * @return boolean true if within range.
- */
- protected function isValidFloat($value)
- {
- $minValue=$this->getMinValue();
- $maxValue=$this->getMaxValue();
-
- $valid=preg_match('/^[-+]?([0-9]*\.)?[0-9]+([eE][-+]?[0-9]+)?$/',trim($value));
- $value=floatval($value);
- if($minValue!=='')
- $valid=$valid && $this->isGreaterThan($value,floatval($minValue));
- if($maxValue!=='')
- $valid=$valid && $this->isLessThan($value,floatval($maxValue));
- return $valid;
- }
-
- /**
- * Determine if the date is within the specified range.
- * Uses pradoParseDate and strtotime to get the date from string.
- * @param string date as string to validate
- * @return boolean true if within range.
- */
- protected function isValidDate($value)
- {
- $minValue=$this->getMinValue();
- $maxValue=$this->getMaxValue();
-
- $valid=true;
-
- $dateFormat = $this->getDateFormat();
- if($dateFormat!=='')
- {
- $formatter=Prado::createComponent('System.Util.TSimpleDateFormatter', $dateFormat);
- $value = $formatter->parse($value, $dateFormat);
- if($minValue!=='')
- $valid=$valid && $this->isGreaterThan($value,$formatter->parse($minValue));
- if($maxValue!=='')
- $valid=$valid && $this->isLessThan($value,$formatter->parse($maxValue));
- return $valid;
- }
- else
- {
- $value=strtotime($value);
- if($minValue!=='')
- $valid=$valid && $this->isGreaterThan($value,strtotime($minValue));
- if($maxValue!=='')
- $valid=$valid && $this->isLessThan($value,strtotime($maxValue));
- return $valid;
- }
- }
-
- /**
- * Compare the string with a minimum and a maxiumum value.
- * Uses strcmp for comparision.
- * @param string value to compare with.
- * @return boolean true if the string is within range.
- */
- protected function isValidString($value)
- {
- $minValue=$this->getMinValue();
- $maxValue=$this->getMaxValue();
-
- $valid=true;
- if($minValue!=='')
- $valid=$valid && $this->isGreaterThan(strcmp($value,$minValue),0);
- if($maxValue!=='')
- $valid=$valid && $this->isLessThan(strcmp($value,$maxValue),0);
- return $valid;
- }
-
- /**
- * @param string string for comparision
- * @return boolean true if min and max string length are satisfied.
- */
- protected function isValidStringLength($value)
- {
- $minValue=$this->getMinValue();
- $maxValue=$this->getMaxValue();
-
- $valid=true;
- $charset = $this->getCharset();
- if($charset==='')
- {
- $app= $this->getApplication()->getGlobalization();
- $charset = $app ? $app->getCharset() : null;
- if(!$charset)
- $charset = 'UTF-8';
- }
-
- $length = iconv_strlen($value, $charset);
- if($minValue!=='')
- $valid = $valid && $this->isGreaterThan($length,intval($minValue));
- if($maxValue!=='')
- $valid = $valid && $this->isLessThan($length,intval($maxValue));
- return $valid;
- }
-
- /**
- * Returns an array of javascript validator options.
- * @return array javascript validator options.
- */
- protected function getClientScriptOptions()
- {
- $options=parent::getClientScriptOptions();
- $options['MinValue']=$this->getMinValue();
- $options['MaxValue']=$this->getMaxValue();
- $options['DataType']=$this->getDataType();
- $options['StrictComparison']=$this->getStrictComparison();
- if(($dateFormat=$this->getDateFormat())!=='')
- $options['DateFormat']=$dateFormat;
- return $options;
- }
-}
-
-
-/**
- * TRangeValidationDataType class.
- * TRangeValidationDataType defines the enumerable type for the possible data types that
- * a range validator can validate upon.
- *
- * The following enumerable values are defined:
- * - Integer
- * - Float
- * - Date
- * - String
- * - StringLength
- *
- * @author Qiang Xue <qiang.xue@gmail.com>
- * @version $Id$
- * @package System.Web.UI.WebControls
- * @since 3.0.4
- */
-class TRangeValidationDataType extends TValidationDataType
-{
- const StringLength='StringLength';
-}
+ $value=intval($value);
+ if($minValue!=='')
+ $valid=$valid && $this->isGreaterThan($value, intval($minValue));
+ if($maxValue!=='')
+ $valid=$valid && $this->isLessThan($value,intval($maxValue));
+ return $valid;
+ }
+
+ protected function isLessThan($left,$right)
+ {
+ return $this->getStrictComparison() ? $left < $right : $left <= $right;
+ }
+
+ protected function isGreaterThan($left, $right)
+ {
+ return $this->getStrictComparison() ? $left > $right : $left >= $right;
+ }
+
+ /**
+ * Determine if the value is within the specified float range.
+ * @param string value to validate
+ * @return boolean true if within range.
+ */
+ protected function isValidFloat($value)
+ {
+ $minValue=$this->getMinValue();
+ $maxValue=$this->getMaxValue();
+
+ $valid=preg_match('/^[-+]?([0-9]*\.)?[0-9]+([eE][-+]?[0-9]+)?$/',trim($value));
+ $value=floatval($value);
+ if($minValue!=='')
+ $valid=$valid && $this->isGreaterThan($value,floatval($minValue));
+ if($maxValue!=='')
+ $valid=$valid && $this->isLessThan($value,floatval($maxValue));
+ return $valid;
+ }
+
+ /**
+ * Determine if the date is within the specified range.
+ * Uses pradoParseDate and strtotime to get the date from string.
+ * @param string date as string to validate
+ * @return boolean true if within range.
+ */
+ protected function isValidDate($value)
+ {
+ $minValue=$this->getMinValue();
+ $maxValue=$this->getMaxValue();
+
+ $valid=true;
+
+ $dateFormat = $this->getDateFormat();
+ if($dateFormat!=='')
+ {
+ $formatter=Prado::createComponent('System.Util.TSimpleDateFormatter', $dateFormat);
+ $value = $formatter->parse($value, $dateFormat);
+ if($minValue!=='')
+ $valid=$valid && $this->isGreaterThan($value,$formatter->parse($minValue));
+ if($maxValue!=='')
+ $valid=$valid && $this->isLessThan($value,$formatter->parse($maxValue));
+ return $valid;
+ }
+ else
+ {
+ $value=strtotime($value);
+ if($minValue!=='')
+ $valid=$valid && $this->isGreaterThan($value,strtotime($minValue));
+ if($maxValue!=='')
+ $valid=$valid && $this->isLessThan($value,strtotime($maxValue));
+ return $valid;
+ }
+ }
+
+ /**
+ * Compare the string with a minimum and a maxiumum value.
+ * Uses strcmp for comparision.
+ * @param string value to compare with.
+ * @return boolean true if the string is within range.
+ */
+ protected function isValidString($value)
+ {
+ $minValue=$this->getMinValue();
+ $maxValue=$this->getMaxValue();
+
+ $valid=true;
+ if($minValue!=='')
+ $valid=$valid && $this->isGreaterThan(strcmp($value,$minValue),0);
+ if($maxValue!=='')
+ $valid=$valid && $this->isLessThan(strcmp($value,$maxValue),0);
+ return $valid;
+ }
+
+ /**
+ * @param string string for comparision
+ * @return boolean true if min and max string length are satisfied.
+ */
+ protected function isValidStringLength($value)
+ {
+ $minValue=$this->getMinValue();
+ $maxValue=$this->getMaxValue();
+
+ $valid=true;
+ $charset = $this->getCharset();
+ if($charset==='')
+ {
+ $app= $this->getApplication()->getGlobalization();
+ $charset = $app ? $app->getCharset() : null;
+ if(!$charset)
+ $charset = 'UTF-8';
+ }
+
+ $length = iconv_strlen($value, $charset);
+ if($minValue!=='')
+ $valid = $valid && $this->isGreaterThan($length,intval($minValue));
+ if($maxValue!=='')
+ $valid = $valid && $this->isLessThan($length,intval($maxValue));
+ return $valid;
+ }
+
+ /**
+ * Returns an array of javascript validator options.
+ * @return array javascript validator options.
+ */
+ protected function getClientScriptOptions()
+ {
+ $options=parent::getClientScriptOptions();
+ $options['MinValue']=$this->getMinValue();
+ $options['MaxValue']=$this->getMaxValue();
+ $options['DataType']=$this->getDataType();
+ $options['StrictComparison']=$this->getStrictComparison();
+ if(($dateFormat=$this->getDateFormat())!=='')
+ $options['DateFormat']=$dateFormat;
+ return $options;
+ }
+}
+
+
+/**
+ * TRangeValidationDataType class.
+ * TRangeValidationDataType defines the enumerable type for the possible data types that
+ * a range validator can validate upon.
+ *
+ * The following enumerable values are defined:
+ * - Integer
+ * - Float
+ * - Date
+ * - String
+ * - StringLength
+ *
+ * @author Qiang Xue <qiang.xue@gmail.com>
+ * @version $Id$
+ * @package System.Web.UI.WebControls
+ * @since 3.0.4
+ */
+class TRangeValidationDataType extends TValidationDataType
+{
+ const StringLength='StringLength';
+}
diff --git a/framework/Web/UI/WebControls/TRatingList.php b/framework/Web/UI/WebControls/TRatingList.php
index dfb11371..cc813755 100644
--- a/framework/Web/UI/WebControls/TRatingList.php
+++ b/framework/Web/UI/WebControls/TRatingList.php
@@ -1,359 +1,359 @@
-<?php
-/**
- * TRatingList class file.
- *
- * @author Wei Zhuo <weizhuo[at]gmail[dot]com>
- * @link http://www.pradosoft.com/
- * @copyright Copyright &copy; 2005-2012 PradoSoft
- * @license http://www.pradosoft.com/license/
- * @version $Id$
- * @package System.Web.UI.WebControls
- */
-
-/**
- * Includes TRadioButtonList class
- */
-Prado::using('System.Web.UI.WebControls.TRadioButtonList');
-
-/**
- * TRatingList class.
- *
- * This class is EXPERIMENTAL.
- *
- * @author Wei Zhuo <weizhuo[at]gmail[dot]com>
- * @author Bradley Booms <bradley[dot]booms[at]gmail[dot]com>
- * @version $Id$
- * @package System.Web.UI.WebControls
- * @since 3.0
- */
-class TRatingList extends TRadioButtonList
-{
- /**
- * Script path relative to the TClientScriptManager::SCRIPT_PATH
- */
- const SCRIPT_PATH='prado/ratings';
-
- /**
- * @var array list of published rating images.
- */
- private $_ratingImages = array();
-
- /**
- * Sets the default repeat direction to horizontal.
- */
- public function __construct()
- {
- parent::__construct();
- $this->setRepeatDirection(TRepeatDirection::Horizontal);
- }
-
- /**
- * @return boolean whether the items in the column can be edited. Defaults to false.
- */
- public function getReadOnly()
- {
- return $this->getViewState('ReadOnly',false);
- }
-
- /**
- * @param boolean whether the items in the column can be edited
- */
- public function setReadOnly($value)
- {
- $this->setViewState('ReadOnly',TPropertyValue::ensureBoolean($value),false);
- }
-
- /**
- * Wrapper for {@link setReadOnly ReadOnly} property.
- * @return boolean whether the rating list can be edited. Defaults to true.
- */
- public function getAllowInput()
- {
- return !$this->getReadOnly();
- }
-
- /**
- * Wrapper for {@link setReadOnly ReadOnly} property.
- * @param boolean whether the rating list can be edited
- */
- public function setAllowInput($value)
- {
- $this->setReadOnly(!TPropertyValue::ensureBoolean($value));
- }
-
- /**
- * Wrapper for {@link setReadOnly ReadOnly} property.
- * @param boolean whether the rating list can be edited
- */
- public function setEnabled($value)
- {
- $this->setReadOnly(!TPropertyValue::ensureBoolean($value));
- }
-
- /**
- * The repeat layout must be Table.
- * @param string repeat layout type
- * @throws TInvaliddataValueException when repeat layout is not Table.
- */
- public function setRepeatLayout($value)
- {
- if($value!==TRepeatLayout::Table)
- throw new TInvalidDataValueException('ratinglist_table_layout_only');
- else
- parent::setRepeatLayout($value);
- }
-
- /**
- * @return float rating value.
- */
- public function getRating()
- {
- $rating = $this->getViewState('Rating', null);
- if ($rating === null)
- return $this->getSelectedIndex()+1;
- else
- return $rating;
- }
-
- /**
- * @param float rating value, also sets the selected Index
- */
- public function setRating($value)
- {
- $value = TPropertyValue::ensureFloat($value);
- $this->setViewState('Rating', $value, null);
- $index = $this->getRatingIndex($value);
- parent::setSelectedIndex($index);
- }
-
- public function setSelectedIndex($value)
- {
- $this->setRating($value+1);
- parent::setSelectedIndex($value);
- }
-
- /**
- * @param float rating value
- * @return int rating as integer
- */
- protected function getRatingIndex($rating)
- {
- $interval = $this->getHalfRatingInterval();
- $base = intval($rating)-1;
- $remainder = $rating-$base-1;
- return $remainder > $interval[1] ? $base+1 : $base;
- }
-
- /**
- * @param int change the rating selection index
- */
- public function onSelectedIndexChanged($param)
- {
- $value = $this->getRating();
- $value = TPropertyValue::ensureInteger($value);
- $this->setRating($value);
- parent::onSelectedIndexChanged($param);
- }
-
- /**
- * @return string control or html element ID for displaying a caption.
- */
- public function getCaptionID()
- {
- return $this->getViewState('CaptionID', '');
- }
-
- /**
- * @param string control or html element ID for displaying a caption.
- */
- public function setCaptionID($value)
- {
- $this->setViewState('CaptionID', $value, '');
- }
-
- protected function getCaptionControl()
- {
- if(($id=$this->getCaptionID())!=='')
- {
- if($control=$this->getParent()->findControl($id))
- return $control;
- }
- throw new TInvalidDataValueException(
- 'ratinglist_invalid_caption_id',$id,$this->getID());
- }
-
- /**
- * @return string caption text. Default is "Rate It:".
- */
- public function getCaption()
- {
- return $this->getCaptionControl()->getText();
- }
-
- /**
- * @return TRatingListStyle current rating style
- */
- public function setCaption($value)
- {
- $this->getCaptionControl()->setText($value);
- }
-
- /**
- * @param string set the rating style, default is "default"
- */
- public function setRatingStyle($value)
- {
- $this->setViewState('RatingStyle', $value, 'default');
- }
-
- /**
- * @return TRatingListStyle current rating style
- */
- public function getRatingStyle()
- {
- return $this->getViewState('RatingStyle', 'default');
- }
-
- /**
- * @return string rating style css class name.
- */
- protected function getRatingStyleCssClass()
- {
- return 'TRatingList_'.$this->getRatingStyle();
- }
-
- /**
- * Sets the interval such that those rating values within the interval
- * will be considered as a half star rating.
- * @param array rating display half value interval, default is array(0.3, 0.7);
- */
- public function setHalfRatingInterval($value)
- {
- $this->setViewState('HalfRating',
- TPropertyValue::ensureArray($value), array(0.3, 0.7));
- }
-
- /**
- * @return array rating display half value interval, default is array(0.3, 0.7);
- */
- public function getHalfRatingInterval()
- {
- return $this->getViewState('HalfRating', array(0.3, 0.7));
- }
-
- /**
- * @return array list of post back options.
- */
- protected function getPostBackOptions()
- {
- $options = parent::getPostBackOptions();
- $options['AutoPostBack'] = $this->getAutoPostBack();
- $options['ReadOnly'] = $this->getReadOnly();
- $options['Style'] = $this->getRatingStyleCssClass();
- $options['CaptionID'] = $this->getCaptionControlID();
- $options['SelectedIndex'] = $this->getSelectedIndex();
- $options['Rating'] = $this->getRating();
- $options['HalfRating'] = $this->getHalfRatingInterval();
- return $options;
- }
-
- /**
- * @return string find the client ID of the caption control.
- */
- protected function getCaptionControlID()
- {
- if(($id=$this->getCaptionID())!=='')
- {
- if($control=$this->getParent()->findControl($id))
- {
- if($control->getVisible(true))
- return $control->getClientID();
- }
- else
- return $id;
- }
- return '';
- }
-
- /**
- * Publish the the rating style css file and rating image files.
- */
- public function onPreRender($param)
- {
- parent::onPreRender($param);
- $this->publishStyle($this->getRatingStyle());
- $this->_ratingImages = $this->publishImages($this->getRatingStyle());
- $this->registerClientScript();
- }
-
- /**
- * @param string rating style name
- * @return string URL of the css style file
- */
- protected function publishStyle($style)
- {
- $cs = $this->getPage()->getClientScript();
- $url = $this->getAssetUrl($style.'.css');
- if(!$cs->isStyleSheetFileRegistered($url))
- $cs->registerStyleSheetFile($url, $url);
- return $url;
- }
-
- /**
- * @param string rating style name
- * @param string rating image file extension, default is '.gif'
- * @return array URL of publish the rating images
- */
- protected function publishImages($style, $fileExt='.gif')
- {
- $types = array('blank', 'selected', 'half', 'combined');
- $files = array();
- foreach($types as $type)
- $files[$type] = $this->getAssetUrl("{$style}_{$type}{$fileExt}");
- return $files;
- }
-
- /**
- * Registers the relevant JavaScript.
- */
- protected function registerClientScript()
- {
- $cs=$this->getPage()->getClientScript();
- $cs->registerPradoScript('ratings');
- }
-
- /**
- * @param string asset file in the self::SCRIPT_PATH directory.
- * @return string asset file url.
- */
- protected function getAssetUrl($file='')
- {
- $base = $this->getPage()->getClientScript()->getPradoScriptAssetUrl();
- return $base.'/'.self::SCRIPT_PATH.'/'.$file;
- }
-
- /**
- * Add rating style class name to the class attribute
- * when {@link setReadOnly ReadOnly} property is true and when the
- * {@link setCssClass CssClass} property is empty.
- * @param THtmlWriter renderer
- */
- public function render($writer)
- {
- $writer->addAttribute('id',$this->getClientID());
- $this->getPage()->getClientScript()->registerPostBackControl(
- $this->getClientClassName(), $this->getPostBackOptions());
- parent::render($writer);
- }
-
- /**
- * Gets the name of the javascript class responsible for performing postback for this control.
- * This method overrides the parent implementation.
- * @return string the javascript class name
- */
- protected function getClientClassName()
- {
- return 'Prado.WebUI.TRatingList';
- }
-}
-
+<?php
+/**
+ * TRatingList class file.
+ *
+ * @author Wei Zhuo <weizhuo[at]gmail[dot]com>
+ * @link http://www.pradosoft.com/
+ * @copyright Copyright &copy; 2005-2012 PradoSoft
+ * @license http://www.pradosoft.com/license/
+ * @version $Id$
+ * @package System.Web.UI.WebControls
+ */
+
+/**
+ * Includes TRadioButtonList class
+ */
+Prado::using('System.Web.UI.WebControls.TRadioButtonList');
+
+/**
+ * TRatingList class.
+ *
+ * This class is EXPERIMENTAL.
+ *
+ * @author Wei Zhuo <weizhuo[at]gmail[dot]com>
+ * @author Bradley Booms <bradley[dot]booms[at]gmail[dot]com>
+ * @version $Id$
+ * @package System.Web.UI.WebControls
+ * @since 3.0
+ */
+class TRatingList extends TRadioButtonList
+{
+ /**
+ * Script path relative to the TClientScriptManager::SCRIPT_PATH
+ */
+ const SCRIPT_PATH='prado/ratings';
+
+ /**
+ * @var array list of published rating images.
+ */
+ private $_ratingImages = array();
+
+ /**
+ * Sets the default repeat direction to horizontal.
+ */
+ public function __construct()
+ {
+ parent::__construct();
+ $this->setRepeatDirection(TRepeatDirection::Horizontal);
+ }
+
+ /**
+ * @return boolean whether the items in the column can be edited. Defaults to false.
+ */
+ public function getReadOnly()
+ {
+ return $this->getViewState('ReadOnly',false);
+ }
+
+ /**
+ * @param boolean whether the items in the column can be edited
+ */
+ public function setReadOnly($value)
+ {
+ $this->setViewState('ReadOnly',TPropertyValue::ensureBoolean($value),false);
+ }
+
+ /**
+ * Wrapper for {@link setReadOnly ReadOnly} property.
+ * @return boolean whether the rating list can be edited. Defaults to true.
+ */
+ public function getAllowInput()
+ {
+ return !$this->getReadOnly();
+ }
+
+ /**
+ * Wrapper for {@link setReadOnly ReadOnly} property.
+ * @param boolean whether the rating list can be edited
+ */
+ public function setAllowInput($value)
+ {
+ $this->setReadOnly(!TPropertyValue::ensureBoolean($value));
+ }
+
+ /**
+ * Wrapper for {@link setReadOnly ReadOnly} property.
+ * @param boolean whether the rating list can be edited
+ */
+ public function setEnabled($value)
+ {
+ $this->setReadOnly(!TPropertyValue::ensureBoolean($value));
+ }
+
+ /**
+ * The repeat layout must be Table.
+ * @param string repeat layout type
+ * @throws TInvaliddataValueException when repeat layout is not Table.
+ */
+ public function setRepeatLayout($value)
+ {
+ if($value!==TRepeatLayout::Table)
+ throw new TInvalidDataValueException('ratinglist_table_layout_only');
+ else
+ parent::setRepeatLayout($value);
+ }
+
+ /**
+ * @return float rating value.
+ */
+ public function getRating()
+ {
+ $rating = $this->getViewState('Rating', null);
+ if ($rating === null)
+ return $this->getSelectedIndex()+1;
+ else
+ return $rating;
+ }
+
+ /**
+ * @param float rating value, also sets the selected Index
+ */
+ public function setRating($value)
+ {
+ $value = TPropertyValue::ensureFloat($value);
+ $this->setViewState('Rating', $value, null);
+ $index = $this->getRatingIndex($value);
+ parent::setSelectedIndex($index);
+ }
+
+ public function setSelectedIndex($value)
+ {
+ $this->setRating($value+1);
+ parent::setSelectedIndex($value);
+ }
+
+ /**
+ * @param float rating value
+ * @return int rating as integer
+ */
+ protected function getRatingIndex($rating)
+ {
+ $interval = $this->getHalfRatingInterval();
+ $base = intval($rating)-1;
+ $remainder = $rating-$base-1;
+ return $remainder > $interval[1] ? $base+1 : $base;
+ }
+
+ /**
+ * @param int change the rating selection index
+ */
+ public function onSelectedIndexChanged($param)
+ {
+ $value = $this->getRating();
+ $value = TPropertyValue::ensureInteger($value);
+ $this->setRating($value);
+ parent::onSelectedIndexChanged($param);
+ }
+
+ /**
+ * @return string control or html element ID for displaying a caption.
+ */
+ public function getCaptionID()
+ {
+ return $this->getViewState('CaptionID', '');
+ }
+
+ /**
+ * @param string control or html element ID for displaying a caption.
+ */
+ public function setCaptionID($value)
+ {
+ $this->setViewState('CaptionID', $value, '');
+ }
+
+ protected function getCaptionControl()
+ {
+ if(($id=$this->getCaptionID())!=='')
+ {
+ if($control=$this->getParent()->findControl($id))
+ return $control;
+ }
+ throw new TInvalidDataValueException(
+ 'ratinglist_invalid_caption_id',$id,$this->getID());
+ }
+
+ /**
+ * @return string caption text. Default is "Rate It:".
+ */
+ public function getCaption()
+ {
+ return $this->getCaptionControl()->getText();
+ }
+
+ /**
+ * @return TRatingListStyle current rating style
+ */
+ public function setCaption($value)
+ {
+ $this->getCaptionControl()->setText($value);
+ }
+
+ /**
+ * @param string set the rating style, default is "default"
+ */
+ public function setRatingStyle($value)
+ {
+ $this->setViewState('RatingStyle', $value, 'default');
+ }
+
+ /**
+ * @return TRatingListStyle current rating style
+ */
+ public function getRatingStyle()
+ {
+ return $this->getViewState('RatingStyle', 'default');
+ }
+
+ /**
+ * @return string rating style css class name.
+ */
+ protected function getRatingStyleCssClass()
+ {
+ return 'TRatingList_'.$this->getRatingStyle();
+ }
+
+ /**
+ * Sets the interval such that those rating values within the interval
+ * will be considered as a half star rating.
+ * @param array rating display half value interval, default is array(0.3, 0.7);
+ */
+ public function setHalfRatingInterval($value)
+ {
+ $this->setViewState('HalfRating',
+ TPropertyValue::ensureArray($value), array(0.3, 0.7));
+ }
+
+ /**
+ * @return array rating display half value interval, default is array(0.3, 0.7);
+ */
+ public function getHalfRatingInterval()
+ {
+ return $this->getViewState('HalfRating', array(0.3, 0.7));
+ }
+
+ /**
+ * @return array list of post back options.
+ */
+ protected function getPostBackOptions()
+ {
+ $options = parent::getPostBackOptions();
+ $options['AutoPostBack'] = $this->getAutoPostBack();
+ $options['ReadOnly'] = $this->getReadOnly();
+ $options['Style'] = $this->getRatingStyleCssClass();
+ $options['CaptionID'] = $this->getCaptionControlID();
+ $options['SelectedIndex'] = $this->getSelectedIndex();
+ $options['Rating'] = $this->getRating();
+ $options['HalfRating'] = $this->getHalfRatingInterval();
+ return $options;
+ }
+
+ /**
+ * @return string find the client ID of the caption control.
+ */
+ protected function getCaptionControlID()
+ {
+ if(($id=$this->getCaptionID())!=='')
+ {
+ if($control=$this->getParent()->findControl($id))
+ {
+ if($control->getVisible(true))
+ return $control->getClientID();
+ }
+ else
+ return $id;
+ }
+ return '';
+ }
+
+ /**
+ * Publish the the rating style css file and rating image files.
+ */
+ public function onPreRender($param)
+ {
+ parent::onPreRender($param);
+ $this->publishStyle($this->getRatingStyle());
+ $this->_ratingImages = $this->publishImages($this->getRatingStyle());
+ $this->registerClientScript();
+ }
+
+ /**
+ * @param string rating style name
+ * @return string URL of the css style file
+ */
+ protected function publishStyle($style)
+ {
+ $cs = $this->getPage()->getClientScript();
+ $url = $this->getAssetUrl($style.'.css');
+ if(!$cs->isStyleSheetFileRegistered($url))
+ $cs->registerStyleSheetFile($url, $url);
+ return $url;
+ }
+
+ /**
+ * @param string rating style name
+ * @param string rating image file extension, default is '.gif'
+ * @return array URL of publish the rating images
+ */
+ protected function publishImages($style, $fileExt='.gif')
+ {
+ $types = array('blank', 'selected', 'half', 'combined');
+ $files = array();
+ foreach($types as $type)
+ $files[$type] = $this->getAssetUrl("{$style}_{$type}{$fileExt}");
+ return $files;
+ }
+
+ /**
+ * Registers the relevant JavaScript.
+ */
+ protected function registerClientScript()
+ {
+ $cs=$this->getPage()->getClientScript();
+ $cs->registerPradoScript('ratings');
+ }
+
+ /**
+ * @param string asset file in the self::SCRIPT_PATH directory.
+ * @return string asset file url.
+ */
+ protected function getAssetUrl($file='')
+ {
+ $base = $this->getPage()->getClientScript()->getPradoScriptAssetUrl();
+ return $base.'/'.self::SCRIPT_PATH.'/'.$file;
+ }
+
+ /**
+ * Add rating style class name to the class attribute
+ * when {@link setReadOnly ReadOnly} property is true and when the
+ * {@link setCssClass CssClass} property is empty.
+ * @param THtmlWriter renderer
+ */
+ public function render($writer)
+ {
+ $writer->addAttribute('id',$this->getClientID());
+ $this->getPage()->getClientScript()->registerPostBackControl(
+ $this->getClientClassName(), $this->getPostBackOptions());
+ parent::render($writer);
+ }
+
+ /**
+ * Gets the name of the javascript class responsible for performing postback for this control.
+ * This method overrides the parent implementation.
+ * @return string the javascript class name
+ */
+ protected function getClientClassName()
+ {
+ return 'Prado.WebUI.TRatingList';
+ }
+}
+
diff --git a/framework/Web/UI/WebControls/TReCaptcha.php b/framework/Web/UI/WebControls/TReCaptcha.php
index b9ba0070..cbdc2e36 100644
--- a/framework/Web/UI/WebControls/TReCaptcha.php
+++ b/framework/Web/UI/WebControls/TReCaptcha.php
@@ -1,233 +1,233 @@
-<?php
-
-/**
- * TReCaptcha class file
- *
- * @author Bérczi Gábor <gabor.berczi@devworx.hu>
- * @link http://www.devworx.hu/
- * @copyright Copyright &copy; 2011 DevWorx
- * @license http://www.pradosoft.com/license/
- * @package System.Web.UI.WebControls
- */
-
- Prado::using('System.3rdParty.ReCaptcha.recaptchalib');
-
-/**
- * TReCaptcha class.
- *
- * TReCaptcha displays a reCAPTCHA (a token displayed as an image) that can be used
- * to determine if the input is entered by a real user instead of some program. It can
- * also prevent multiple submits of the same form either by accident, or on purpose (ie. spamming).
- *
- * The reCAPTCHA to solve (a string consisting of two separate words) displayed is automatically
- * generated by the reCAPTCHA system at recaptcha.net. However, in order to use the services
- * of the site you will need to register and get a public and a private API key pair, and
- * supply those to the reCAPTCHA control through setting the {@link setPrivateKey PrivateKey}
- * and {@link setPublicKey PublicKey} properties.
- *
- * Currently the reCAPTCHA API supports only one reCAPTCHA field per page, so you MUST make sure that all
- * your input is protected and validated by a single reCAPTCHA control. Placing more than one reCAPTCHA
- * control on the page will lead to unpredictable results, and the user will most likely unable to solve
- * any of them successfully.
- *
- * Upon postback, user input can be validated by calling {@link validate()}.
- * The {@link TReCaptchaValidator} control can also be used to do validation, which provides
- * server-side validation. Calling (@link validate()) will invalidate the token supplied, so all consecutive
- * calls to the method - without solving a new captcha - will return false. Therefore if implementing a multi-stage
- * input process, you must make sure that you call validate() only once, either at the end of the input process, or
- * you store the result till the end of the processing.
- *
- * The following template shows a typical use of TReCaptcha control:
- * <code>
- * <com:TReCaptcha ID="Captcha"
- * PublicKey="..."
- * PrivateKey="..."
- * />
- * <com:TReCaptchaValidator ControlToValidate="Captcha"
- * ErrorMessage="You are challenged!" />
- * </code>
- *
- * @author Bérczi Gábor <gabor.berczi@devworx.hu>
- * @package System.Web.UI.WebControls
- * @since 3.2
- */
-class TReCaptcha extends TWebControl implements IValidatable
-{
- private $_isValid=true;
-
- const ChallengeFieldName = 'recaptcha_challenge_field';
- const ResponseFieldName = 'recaptcha_response_field';
-
- public function getTagName()
- {
- return 'span';
- }
-
- /**
- * Returns true if this control validated successfully.
- * Defaults to true.
- * @return bool wether this control validated successfully.
- */
- public function getIsValid()
- {
- return $this->_isValid;
- }
- /**
- * @param bool wether this control is valid.
- */
- public function setIsValid($value)
- {
- $this->_isValid=TPropertyValue::ensureBoolean($value);
- }
-
- public function getValidationPropertyValue()
- {
- return $this->Request[$this->getChallengeFieldName()];
- }
-
- public function getPublicKey()
- {
- return $this->getViewState('PublicKey');
- }
-
- public function setPublicKey($value)
- {
- return $this->setViewState('PublicKey', TPropertyValue::ensureString($value));
- }
-
- public function getPrivateKey()
- {
- return $this->getViewState('PrivateKey');
- }
-
- public function setPrivateKey($value)
- {
- return $this->setViewState('PrivateKey', TPropertyValue::ensureString($value));
- }
-
- public function getThemeName()
- {
- return $this->getViewState('ThemeName');
- }
-
- public function setThemeName($value)
- {
- return $this->setViewState('ThemeName', TPropertyValue::ensureString($value));
- }
-
- public function getCustomTranslations()
- {
- return TPropertyValue::ensureArray($this->getViewState('CustomTranslations'));
- }
-
- public function setCustomTranslations($value)
- {
- return $this->setViewState('CustomTranslations', TPropertyValue::ensureArray($value));
- }
-
- public function getLanguage()
- {
- return $this->getViewState('Language');
- }
-
- public function setLanguage($value)
- {
- return $this->setViewState('Language', TPropertyValue::ensureString($value));
- }
-
- protected function getChallengeFieldName()
- {
- return /*$this->ClientID.'_'.*/self::ChallengeFieldName;
- }
-
- public function getResponseFieldName()
- {
- return /*$this->ClientID.'_'.*/self::ResponseFieldName;
- }
-
- public function getClientSideOptions()
- {
- $options = array();
- if ($theme = $this->getThemeName())
- $options['theme'] = $theme;
- if ($lang = $this->getLanguage())
- $options['lang'] = $lang;
- if ($trans = $this->getCustomTranslations())
- $options['custom_translations'] = $trans;
- return $options;
- }
-
- public function validate()
- {
- if (!
- (
- ($challenge = @$_POST[$this->getChallengeFieldName()])
- and
- ($response = @$_POST[$this->getResponseFieldName()])
- )
- )
- return false;
-
- $resp = recaptcha_check_answer(
- $this->getPrivateKey(),
- $_SERVER["REMOTE_ADDR"],
- $challenge,
- $response
- );
- return ($resp->is_valid==1);
- }
-
- /**
- * Checks for API keys
- * @param mixed event parameter
- */
- public function onPreRender($param)
- {
- parent::onPreRender($param);
-
- if("" == $this->getPublicKey())
- throw new TConfigurationException('recaptcha_publickey_unknown');
- if("" == $this->getPrivateKey())
- throw new TConfigurationException('recaptcha_privatekey_unknown');
-
- // need to register captcha fields so they will be sent back also in callbacks
- $page = $this->getPage();
- $page->registerRequiresPostData($this->getChallengeFieldName());
- $page->registerRequiresPostData($this->getResponseFieldName());
- }
-
- protected function addAttributesToRender($writer)
- {
- parent::addAttributesToRender($writer);
- $writer->addAttribute('id',$this->getClientID());
- }
-
- public function regenerateToken()
- {
- // if we're in a callback, then schedule re-rendering of the control
- // if not, don't do anything, because a new challenge will be rendered anyway
- if ($this->Page->IsCallback)
- $this->Page->ClientScript->registerEndScript($this->getClientID().'::refresh','Recaptcha.reload();');
- }
-
- public function renderContents($writer)
- {
- $writer->write(TJavaScript::renderScriptBlock(
- 'var RecaptchaOptions = '.TJavaScript::jsonEncode($this->getClientSideOptions()).';'
- ));
-
- $html = recaptcha_get_html($this->getPublicKey());
- /*
- reCAPTCHA currently does not support multiple validations per page
- $html = str_replace(
- array(self::ChallengeFieldName,self::ResponseFieldName),
- array($this->getChallengeFieldName(),$this->getResponseFieldName()),
- $html
- );
- */
- $writer->write($html);
- }
-
-}
-
+<?php
+
+/**
+ * TReCaptcha class file
+ *
+ * @author Bérczi Gábor <gabor.berczi@devworx.hu>
+ * @link http://www.devworx.hu/
+ * @copyright Copyright &copy; 2011 DevWorx
+ * @license http://www.pradosoft.com/license/
+ * @package System.Web.UI.WebControls
+ */
+
+ Prado::using('System.3rdParty.ReCaptcha.recaptchalib');
+
+/**
+ * TReCaptcha class.
+ *
+ * TReCaptcha displays a reCAPTCHA (a token displayed as an image) that can be used
+ * to determine if the input is entered by a real user instead of some program. It can
+ * also prevent multiple submits of the same form either by accident, or on purpose (ie. spamming).
+ *
+ * The reCAPTCHA to solve (a string consisting of two separate words) displayed is automatically
+ * generated by the reCAPTCHA system at recaptcha.net. However, in order to use the services
+ * of the site you will need to register and get a public and a private API key pair, and
+ * supply those to the reCAPTCHA control through setting the {@link setPrivateKey PrivateKey}
+ * and {@link setPublicKey PublicKey} properties.
+ *
+ * Currently the reCAPTCHA API supports only one reCAPTCHA field per page, so you MUST make sure that all
+ * your input is protected and validated by a single reCAPTCHA control. Placing more than one reCAPTCHA
+ * control on the page will lead to unpredictable results, and the user will most likely unable to solve
+ * any of them successfully.
+ *
+ * Upon postback, user input can be validated by calling {@link validate()}.
+ * The {@link TReCaptchaValidator} control can also be used to do validation, which provides
+ * server-side validation. Calling (@link validate()) will invalidate the token supplied, so all consecutive
+ * calls to the method - without solving a new captcha - will return false. Therefore if implementing a multi-stage
+ * input process, you must make sure that you call validate() only once, either at the end of the input process, or
+ * you store the result till the end of the processing.
+ *
+ * The following template shows a typical use of TReCaptcha control:
+ * <code>
+ * <com:TReCaptcha ID="Captcha"
+ * PublicKey="..."
+ * PrivateKey="..."
+ * />
+ * <com:TReCaptchaValidator ControlToValidate="Captcha"
+ * ErrorMessage="You are challenged!" />
+ * </code>
+ *
+ * @author Bérczi Gábor <gabor.berczi@devworx.hu>
+ * @package System.Web.UI.WebControls
+ * @since 3.2
+ */
+class TReCaptcha extends TWebControl implements IValidatable
+{
+ private $_isValid=true;
+
+ const ChallengeFieldName = 'recaptcha_challenge_field';
+ const ResponseFieldName = 'recaptcha_response_field';
+
+ public function getTagName()
+ {
+ return 'span';
+ }
+
+ /**
+ * Returns true if this control validated successfully.
+ * Defaults to true.
+ * @return bool wether this control validated successfully.
+ */
+ public function getIsValid()
+ {
+ return $this->_isValid;
+ }
+ /**
+ * @param bool wether this control is valid.
+ */
+ public function setIsValid($value)
+ {
+ $this->_isValid=TPropertyValue::ensureBoolean($value);
+ }
+
+ public function getValidationPropertyValue()
+ {
+ return $this->Request[$this->getChallengeFieldName()];
+ }
+
+ public function getPublicKey()
+ {
+ return $this->getViewState('PublicKey');
+ }
+
+ public function setPublicKey($value)
+ {
+ return $this->setViewState('PublicKey', TPropertyValue::ensureString($value));
+ }
+
+ public function getPrivateKey()
+ {
+ return $this->getViewState('PrivateKey');
+ }
+
+ public function setPrivateKey($value)
+ {
+ return $this->setViewState('PrivateKey', TPropertyValue::ensureString($value));
+ }
+
+ public function getThemeName()
+ {
+ return $this->getViewState('ThemeName');
+ }
+
+ public function setThemeName($value)
+ {
+ return $this->setViewState('ThemeName', TPropertyValue::ensureString($value));
+ }
+
+ public function getCustomTranslations()
+ {
+ return TPropertyValue::ensureArray($this->getViewState('CustomTranslations'));
+ }
+
+ public function setCustomTranslations($value)
+ {
+ return $this->setViewState('CustomTranslations', TPropertyValue::ensureArray($value));
+ }
+
+ public function getLanguage()
+ {
+ return $this->getViewState('Language');
+ }
+
+ public function setLanguage($value)
+ {
+ return $this->setViewState('Language', TPropertyValue::ensureString($value));
+ }
+
+ protected function getChallengeFieldName()
+ {
+ return /*$this->ClientID.'_'.*/self::ChallengeFieldName;
+ }
+
+ public function getResponseFieldName()
+ {
+ return /*$this->ClientID.'_'.*/self::ResponseFieldName;
+ }
+
+ public function getClientSideOptions()
+ {
+ $options = array();
+ if ($theme = $this->getThemeName())
+ $options['theme'] = $theme;
+ if ($lang = $this->getLanguage())
+ $options['lang'] = $lang;
+ if ($trans = $this->getCustomTranslations())
+ $options['custom_translations'] = $trans;
+ return $options;
+ }
+
+ public function validate()
+ {
+ if (!
+ (
+ ($challenge = @$_POST[$this->getChallengeFieldName()])
+ and
+ ($response = @$_POST[$this->getResponseFieldName()])
+ )
+ )
+ return false;
+
+ $resp = recaptcha_check_answer(
+ $this->getPrivateKey(),
+ $_SERVER["REMOTE_ADDR"],
+ $challenge,
+ $response
+ );
+ return ($resp->is_valid==1);
+ }
+
+ /**
+ * Checks for API keys
+ * @param mixed event parameter
+ */
+ public function onPreRender($param)
+ {
+ parent::onPreRender($param);
+
+ if("" == $this->getPublicKey())
+ throw new TConfigurationException('recaptcha_publickey_unknown');
+ if("" == $this->getPrivateKey())
+ throw new TConfigurationException('recaptcha_privatekey_unknown');
+
+ // need to register captcha fields so they will be sent back also in callbacks
+ $page = $this->getPage();
+ $page->registerRequiresPostData($this->getChallengeFieldName());
+ $page->registerRequiresPostData($this->getResponseFieldName());
+ }
+
+ protected function addAttributesToRender($writer)
+ {
+ parent::addAttributesToRender($writer);
+ $writer->addAttribute('id',$this->getClientID());
+ }
+
+ public function regenerateToken()
+ {
+ // if we're in a callback, then schedule re-rendering of the control
+ // if not, don't do anything, because a new challenge will be rendered anyway
+ if ($this->Page->IsCallback)
+ $this->Page->ClientScript->registerEndScript($this->getClientID().'::refresh','Recaptcha.reload();');
+ }
+
+ public function renderContents($writer)
+ {
+ $writer->write(TJavaScript::renderScriptBlock(
+ 'var RecaptchaOptions = '.TJavaScript::jsonEncode($this->getClientSideOptions()).';'
+ ));
+
+ $html = recaptcha_get_html($this->getPublicKey());
+ /*
+ reCAPTCHA currently does not support multiple validations per page
+ $html = str_replace(
+ array(self::ChallengeFieldName,self::ResponseFieldName),
+ array($this->getChallengeFieldName(),$this->getResponseFieldName()),
+ $html
+ );
+ */
+ $writer->write($html);
+ }
+
+}
+
?> \ No newline at end of file
diff --git a/framework/Web/UI/WebControls/TReCaptchaValidator.php b/framework/Web/UI/WebControls/TReCaptchaValidator.php
index 7199e401..41abbc5a 100644
--- a/framework/Web/UI/WebControls/TReCaptchaValidator.php
+++ b/framework/Web/UI/WebControls/TReCaptchaValidator.php
@@ -1,123 +1,123 @@
-<?php
-
-/**
- * TReCaptchaValidator class file
- *
- * @author Bérczi Gábor <gabor.berczi@devworx.hu>
- * @link http://www.devworx.hu/
- * @copyright Copyright &copy; 2011 DevWorx
- * @license http://www.pradosoft.com/license/
- * @package System.Web.UI.WebControls
- */
-
-Prado::using('System.Web.UI.WebControls.TBaseValidator');
-Prado::using('System.Web.UI.WebControls.TReCaptcha');
-
-/**
- * TReCaptchaValidator class
- *
- * TReCaptchaValidator validates user input against a reCAPTCHA represented by
- * a {@link TReCaptcha} control. The input control fails validation if its value
- * is not the same as the token displayed in reCAPTCHA. Note, if the user does
- * not enter any thing, it is still considered as failing the validation.
- *
- * To use TReCaptchaValidator, specify the {@link setControlToValidate ControlToValidate}
- * to be the ID path of the {@link TReCaptcha} control.
- *
- * @author Bérczi Gábor <gabor.berczi@devworx.hu>
- * @package System.Web.UI.WebControls
- * @since 3.2
- */
-class TReCaptchaValidator extends TBaseValidator
-{
- protected $_isvalid = null;
-
- /**
- * Gets the name of the javascript class responsible for performing validation for this control.
- * This method overrides the parent implementation.
- * @return string the javascript class name
- */
- protected function getClientClassName()
- {
- return 'Prado.WebUI.TReCaptchaValidator';
- }
-
- public function getEnableClientScript()
- {
- return true;
- }
-
- protected function getCaptchaControl()
- {
- $control = $this->getValidationTarget();
- if (!$control)
- throw new Exception('No target control specified for TReCaptchaValidator');
- if (!($control instanceof TReCaptcha))
- throw new Exception('TReCaptchaValidator only works with TReCaptcha controls');
- return $control;
- }
-
- public function getClientScriptOptions()
- {
- $options = parent::getClientScriptOptions();
- $options['ResponseFieldName'] = $this->getCaptchaControl()->getResponseFieldName();
- return $options;
- }
-
- /**
- * This method overrides the parent's implementation.
- * The validation succeeds if the input control has the same value
- * as the one displayed in the corresponding RECAPTCHA control.
- *
- * @return boolean whether the validation succeeds
- */
- protected function evaluateIsValid()
- {
- // check validity only once (if trying to evaulate multiple times, all redundant checks would fail)
- if (is_null($this->_isvalid))
- {
- $control = $this->getCaptchaControl();
- $this->_isvalid = $control->validate();
- }
- return ($this->_isvalid==true);
- }
-
- public function onPreRender($param)
- {
- parent::onPreRender($param);
-
- $cs = $this->Page->getClientScript();
-
- // communicate validation status to the client side
- $value = $this->_isvalid===false ? '0' : '1';
- $cs->registerHiddenField($this->getClientID().'_1',$value);
-
- // check if we need to request a new captcha too
- if ($this->Page->IsCallback)
- {
- // force update of validator display
- if ($control = $this->getValidationTarget())
- {
- $cs->registerEndScript(
- $this->getClientID().'::validate',
- '$('.TJavaScript::quoteString($this->getClientID().'_1').').value = '.TJavaScript::quoteString($value).';'.
- 'Prado.Validation.validateControl('.TJavaScript::quoteString($control->ClientID).');'
- );
-
- if ($control->getVisible(true))
- if ($this->_isvalid)
- {
- // if the challenge has been solved + we're in a callback and we still reach prerender phase,
- // that means that some other validator failed and the user will be sent back to the page/form with
- // the captcha control. in this case we need to force re-rendering of the control, because once
- // solved, the old challenge won't validate anymore anyway
-
- $control->regenerateToken();
- }
- }
- }
- }
-
-}
-
+<?php
+
+/**
+ * TReCaptchaValidator class file
+ *
+ * @author Bérczi Gábor <gabor.berczi@devworx.hu>
+ * @link http://www.devworx.hu/
+ * @copyright Copyright &copy; 2011 DevWorx
+ * @license http://www.pradosoft.com/license/
+ * @package System.Web.UI.WebControls
+ */
+
+Prado::using('System.Web.UI.WebControls.TBaseValidator');
+Prado::using('System.Web.UI.WebControls.TReCaptcha');
+
+/**
+ * TReCaptchaValidator class
+ *
+ * TReCaptchaValidator validates user input against a reCAPTCHA represented by
+ * a {@link TReCaptcha} control. The input control fails validation if its value
+ * is not the same as the token displayed in reCAPTCHA. Note, if the user does
+ * not enter any thing, it is still considered as failing the validation.
+ *
+ * To use TReCaptchaValidator, specify the {@link setControlToValidate ControlToValidate}
+ * to be the ID path of the {@link TReCaptcha} control.
+ *
+ * @author Bérczi Gábor <gabor.berczi@devworx.hu>
+ * @package System.Web.UI.WebControls
+ * @since 3.2
+ */
+class TReCaptchaValidator extends TBaseValidator
+{
+ protected $_isvalid = null;
+
+ /**
+ * Gets the name of the javascript class responsible for performing validation for this control.
+ * This method overrides the parent implementation.
+ * @return string the javascript class name
+ */
+ protected function getClientClassName()
+ {
+ return 'Prado.WebUI.TReCaptchaValidator';
+ }
+
+ public function getEnableClientScript()
+ {
+ return true;
+ }
+
+ protected function getCaptchaControl()
+ {
+ $control = $this->getValidationTarget();
+ if (!$control)
+ throw new Exception('No target control specified for TReCaptchaValidator');
+ if (!($control instanceof TReCaptcha))
+ throw new Exception('TReCaptchaValidator only works with TReCaptcha controls');
+ return $control;
+ }
+
+ public function getClientScriptOptions()
+ {
+ $options = parent::getClientScriptOptions();
+ $options['ResponseFieldName'] = $this->getCaptchaControl()->getResponseFieldName();
+ return $options;
+ }
+
+ /**
+ * This method overrides the parent's implementation.
+ * The validation succeeds if the input control has the same value
+ * as the one displayed in the corresponding RECAPTCHA control.
+ *
+ * @return boolean whether the validation succeeds
+ */
+ protected function evaluateIsValid()
+ {
+ // check validity only once (if trying to evaulate multiple times, all redundant checks would fail)
+ if (is_null($this->_isvalid))
+ {
+ $control = $this->getCaptchaControl();
+ $this->_isvalid = $control->validate();
+ }
+ return ($this->_isvalid==true);
+ }
+
+ public function onPreRender($param)
+ {
+ parent::onPreRender($param);
+
+ $cs = $this->Page->getClientScript();
+
+ // communicate validation status to the client side
+ $value = $this->_isvalid===false ? '0' : '1';
+ $cs->registerHiddenField($this->getClientID().'_1',$value);
+
+ // check if we need to request a new captcha too
+ if ($this->Page->IsCallback)
+ {
+ // force update of validator display
+ if ($control = $this->getValidationTarget())
+ {
+ $cs->registerEndScript(
+ $this->getClientID().'::validate',
+ '$('.TJavaScript::quoteString($this->getClientID().'_1').').value = '.TJavaScript::quoteString($value).';'.
+ 'Prado.Validation.validateControl('.TJavaScript::quoteString($control->ClientID).');'
+ );
+
+ if ($control->getVisible(true))
+ if ($this->_isvalid)
+ {
+ // if the challenge has been solved + we're in a callback and we still reach prerender phase,
+ // that means that some other validator failed and the user will be sent back to the page/form with
+ // the captcha control. in this case we need to force re-rendering of the control, because once
+ // solved, the old challenge won't validate anymore anyway
+
+ $control->regenerateToken();
+ }
+ }
+ }
+ }
+
+}
+
?> \ No newline at end of file
diff --git a/framework/Web/UI/WebControls/TRegularExpressionValidator.php b/framework/Web/UI/WebControls/TRegularExpressionValidator.php
index a2a5bc64..0e85907a 100644
--- a/framework/Web/UI/WebControls/TRegularExpressionValidator.php
+++ b/framework/Web/UI/WebControls/TRegularExpressionValidator.php
@@ -1,144 +1,144 @@
-<?php
-/**
- * TRequiredFieldValidator class file
- *
- * @author Qiang Xue <qiang.xue@gmail.com>
- * @link http://www.pradosoft.com/
- * @copyright Copyright &copy; 2005-2012 PradoSoft
- * @license http://www.pradosoft.com/license/
- * @version $Id$
- * @package System.Web.UI.WebControls
- */
-
-/**
- * Using TBaseValidator class
- */
-Prado::using('System.Web.UI.WebControls.TBaseValidator');
-
-/**
- * TRegularExpressionValidator class
- *
- * TRegularExpressionValidator validates whether the value of an associated
- * input component matches the pattern specified by a regular expression.
- *
- * You can specify the regular expression by setting the {@link setRegularExpression RegularExpression}
- * property. Some commonly used regular expressions include:
- * <pre>
- * French Phone Number: (0( \d|\d ))?\d\d \d\d(\d \d| \d\d )\d\d
- * French Postal Code: \d{5}
- * German Phone Number: ((\(0\d\d\) |(\(0\d{3}\) )?\d )?\d\d \d\d \d\d|\(0\d{4}\) \d \d\d-\d\d?)
- * German Postal Code: (D-)?\d{5}
- * Email Address: \w+([-+.]\w+)*@\w+([-.]\w+)*\.\w+([-.]\w+)*
- * Japanese Phone Number: (0\d{1,4}-|\(0\d{1,4}\) ?)?\d{1,4}-\d{4}
- * Japanese Postal Code: \d{3}(-(\d{4}|\d{2}))?
- * P.R.C. Phone Number: (\(\d{3}\)|\d{3}-)?\d{8}
- * P.R.C. Postal Code: \d{6}
- * P.R.C. Social Security Number: \d{18}|\d{15}
- * U.S. Phone Number: ((\(\d{3}\) ?)|(\d{3}-))?\d{3}-\d{4}
- * U.S. ZIP Code: \d{5}(-\d{4})?
- * U.S. Social Security Number: \d{3}-\d{2}-\d{4}
- * </pre>
- *
- * Note, the validation succeeds if the associated input control contains empty input.
- * Use a {@link TRequiredFieldValidator} to ensure the input is not empty.
- *
- * @author Qiang Xue <qiang.xue@gmail.com>
- * @version $Id$
- * @package System.Web.UI.WebControls
- * @since 3.0
- */
-class TRegularExpressionValidator extends TBaseValidator
-{
- /**
- * Gets the name of the javascript class responsible for performing validation for this control.
- * This method overrides the parent implementation.
- * @return string the javascript class name
- */
- protected function getClientClassName()
- {
- return 'Prado.WebUI.TRegularExpressionValidator';
- }
-
- /**
- * @return string the regular expression that determines the pattern used to validate a field.
- */
- public function getRegularExpression()
- {
- return $this->getViewState('RegularExpression','');
- }
-
- /**
- * @param string the regular expression that determines the pattern used to validate a field.
- */
- public function setRegularExpression($value)
- {
- $this->setViewState('RegularExpression',$value,'');
- }
-
- /**
- * This method overrides the parent's implementation.
- * The validation succeeds if the input data matches the regular expression.
- * The validation always succeeds if ControlToValidate is not specified
- * or the regular expression is empty, or the input data is empty.
- * @return boolean whether the validation succeeds
- */
- public function evaluateIsValid()
- {
- if(($value=$this->getValidationValue($this->getValidationTarget()))==='')
- return true;
- if(($expression=addcslashes($this->getRegularExpression(),"/"))!=='')
- {
- $mods = $this->getPatternModifiers();
- return preg_match("/^$expression\$/{$mods}",$value);
- }
- else
- return true;
- }
-
- /**
- * @param string pattern modifiers for server side validation,
- * see http://www.php.net/manual/en/reference.pcre.pattern.modifiers.php
- */
- public function setPatternModifiers($value)
- {
- $this->setViewState('PatternModifiers', $value);
- }
-
- /**
- * @return string pattern modifiers, no modifiers by default.
- */
- public function getPatternModifiers()
- {
- return $this->getViewState('PatternModifiers', '');
- }
-
- /**
- * @param string pattern modifiers for clientside.
- * (Only 'g','i' and 'm' are available.)
- */
- public function setClientSidePatternModifiers($value)
- {
- $this->setViewState('ClientSidePatternModifiers', $value);
- }
-
- /**
- * @return string clientside pattern modifiers, no modifiers by default.
- */
- public function getClientSidePatternModifiers()
- {
- return $this->getViewState('ClientSidePatternModifiers', '');
- }
-
- /**
- * Returns an array of javascript validator options.
- * @return array javascript validator options.
- */
- protected function getClientScriptOptions()
- {
- $options = parent::getClientScriptOptions();
- $options['ValidationExpression']=$this->getRegularExpression();
- $options['PatternModifiers']=$this->getClientSidePatternModifiers();
- return $options;
- }
-}
-
+<?php
+/**
+ * TRequiredFieldValidator class file
+ *
+ * @author Qiang Xue <qiang.xue@gmail.com>
+ * @link http://www.pradosoft.com/
+ * @copyright Copyright &copy; 2005-2012 PradoSoft
+ * @license http://www.pradosoft.com/license/
+ * @version $Id$
+ * @package System.Web.UI.WebControls
+ */
+
+/**
+ * Using TBaseValidator class
+ */
+Prado::using('System.Web.UI.WebControls.TBaseValidator');
+
+/**
+ * TRegularExpressionValidator class
+ *
+ * TRegularExpressionValidator validates whether the value of an associated
+ * input component matches the pattern specified by a regular expression.
+ *
+ * You can specify the regular expression by setting the {@link setRegularExpression RegularExpression}
+ * property. Some commonly used regular expressions include:
+ * <pre>
+ * French Phone Number: (0( \d|\d ))?\d\d \d\d(\d \d| \d\d )\d\d
+ * French Postal Code: \d{5}
+ * German Phone Number: ((\(0\d\d\) |(\(0\d{3}\) )?\d )?\d\d \d\d \d\d|\(0\d{4}\) \d \d\d-\d\d?)
+ * German Postal Code: (D-)?\d{5}
+ * Email Address: \w+([-+.]\w+)*@\w+([-.]\w+)*\.\w+([-.]\w+)*
+ * Japanese Phone Number: (0\d{1,4}-|\(0\d{1,4}\) ?)?\d{1,4}-\d{4}
+ * Japanese Postal Code: \d{3}(-(\d{4}|\d{2}))?
+ * P.R.C. Phone Number: (\(\d{3}\)|\d{3}-)?\d{8}
+ * P.R.C. Postal Code: \d{6}
+ * P.R.C. Social Security Number: \d{18}|\d{15}
+ * U.S. Phone Number: ((\(\d{3}\) ?)|(\d{3}-))?\d{3}-\d{4}
+ * U.S. ZIP Code: \d{5}(-\d{4})?
+ * U.S. Social Security Number: \d{3}-\d{2}-\d{4}
+ * </pre>
+ *
+ * Note, the validation succeeds if the associated input control contains empty input.
+ * Use a {@link TRequiredFieldValidator} to ensure the input is not empty.
+ *
+ * @author Qiang Xue <qiang.xue@gmail.com>
+ * @version $Id$
+ * @package System.Web.UI.WebControls
+ * @since 3.0
+ */
+class TRegularExpressionValidator extends TBaseValidator
+{
+ /**
+ * Gets the name of the javascript class responsible for performing validation for this control.
+ * This method overrides the parent implementation.
+ * @return string the javascript class name
+ */
+ protected function getClientClassName()
+ {
+ return 'Prado.WebUI.TRegularExpressionValidator';
+ }
+
+ /**
+ * @return string the regular expression that determines the pattern used to validate a field.
+ */
+ public function getRegularExpression()
+ {
+ return $this->getViewState('RegularExpression','');
+ }
+
+ /**
+ * @param string the regular expression that determines the pattern used to validate a field.
+ */
+ public function setRegularExpression($value)
+ {
+ $this->setViewState('RegularExpression',$value,'');
+ }
+
+ /**
+ * This method overrides the parent's implementation.
+ * The validation succeeds if the input data matches the regular expression.
+ * The validation always succeeds if ControlToValidate is not specified
+ * or the regular expression is empty, or the input data is empty.
+ * @return boolean whether the validation succeeds
+ */
+ public function evaluateIsValid()
+ {
+ if(($value=$this->getValidationValue($this->getValidationTarget()))==='')
+ return true;
+ if(($expression=addcslashes($this->getRegularExpression(),"/"))!=='')
+ {
+ $mods = $this->getPatternModifiers();
+ return preg_match("/^$expression\$/{$mods}",$value);
+ }
+ else
+ return true;
+ }
+
+ /**
+ * @param string pattern modifiers for server side validation,
+ * see http://www.php.net/manual/en/reference.pcre.pattern.modifiers.php
+ */
+ public function setPatternModifiers($value)
+ {
+ $this->setViewState('PatternModifiers', $value);
+ }
+
+ /**
+ * @return string pattern modifiers, no modifiers by default.
+ */
+ public function getPatternModifiers()
+ {
+ return $this->getViewState('PatternModifiers', '');
+ }
+
+ /**
+ * @param string pattern modifiers for clientside.
+ * (Only 'g','i' and 'm' are available.)
+ */
+ public function setClientSidePatternModifiers($value)
+ {
+ $this->setViewState('ClientSidePatternModifiers', $value);
+ }
+
+ /**
+ * @return string clientside pattern modifiers, no modifiers by default.
+ */
+ public function getClientSidePatternModifiers()
+ {
+ return $this->getViewState('ClientSidePatternModifiers', '');
+ }
+
+ /**
+ * Returns an array of javascript validator options.
+ * @return array javascript validator options.
+ */
+ protected function getClientScriptOptions()
+ {
+ $options = parent::getClientScriptOptions();
+ $options['ValidationExpression']=$this->getRegularExpression();
+ $options['PatternModifiers']=$this->getClientSidePatternModifiers();
+ return $options;
+ }
+}
+
diff --git a/framework/Web/UI/WebControls/TRepeatInfo.php b/framework/Web/UI/WebControls/TRepeatInfo.php
index d7c6f0b6..2604e645 100644
--- a/framework/Web/UI/WebControls/TRepeatInfo.php
+++ b/framework/Web/UI/WebControls/TRepeatInfo.php
@@ -1,560 +1,560 @@
-<?php
-/**
- * IRepeatInfoUser, TRepeatInfo class file
- *
- * @author Qiang Xue <qiang.xue@gmail.com>
- * @link http://www.pradosoft.com/
+<?php
+/**
+ * IRepeatInfoUser, TRepeatInfo class file
+ *
+ * @author Qiang Xue <qiang.xue@gmail.com>
+ * @link http://www.pradosoft.com/
* @copyright Copyright &copy; 2005-2012 PradoSoft
- * @license http://www.pradosoft.com/license/
- * @version $Id$
- * @package System.Web.UI.WebControls
- */
-
-Prado::using('System.Web.UI.WebControls.TTable');
-
-/**
- * IRepeatInfoUser interface.
- * This interface must be implemented by classes who want to use {@link TRepeatInfo}.
- *
- * @author Qiang Xue <qiang.xue@gmail.com>
- * @version $Id$
- * @package System.Web.UI.WebControls
- * @since 3.0
- */
-interface IRepeatInfoUser
-{
- /**
- * @return boolean whether the repeat user contains footer
- */
- public function getHasFooter();
- /**
- * @return boolean whether the repeat user contains header
- */
- public function getHasHeader();
- /**
- * @return boolean whether the repeat user contains separators
- */
- public function getHasSeparators();
- /**
- * @return integer number of items to be rendered (excluding header, footer and separators)
- */
- public function getItemCount();
- /**
- * @param string item type (Header,Footer,Item,AlternatingItem,SelectedItem,EditItem,Separator,Pager)
- * @param integer zero-based index of the current rendering item.
- * @return TStyle CSS style used for rendering items (including header, footer and separators)
- */
- public function generateItemStyle($itemType,$index);
- /**
- * Renders an item.
- * @param THtmlWriter writer for the rendering purpose
- * @param TRepeatInfo repeat information
- * @param string item type
- * @param integer zero-based index of the item being rendered
- */
- public function renderItem($writer,$repeatInfo,$itemType,$index);
-}
-
-/**
- * TRepeatInfo class.
- * TRepeatInfo represents repeat information for controls like {@link TCheckBoxList}.
- * The layout of the repeated items is specified via {@link setRepeatLayout RepeatLayout},
- * which can be either Table (default), Flow or Raw.
- * A table layout uses HTML table cells to organize the items while
- * a flow layout uses line breaks to organize the items.
- * The number of columns used to display the items is specified via
- * {@link setRepeatColumns RepeatColumns} property, while the {@link setRepeatDirection RepeatDirection}
- * governs the order of the items being rendered.
- *
- * Note, the Raw layout does not contain any formatting tags and thus ignores
- * the column and repeat direction settings.
- *
- * @author Qiang Xue <qiang.xue@gmail.com>
- * @version $Id$
- * @package System.Web.UI.WebControls
- * @since 3.0
- */
-class TRepeatInfo extends TComponent
-{
- /**
- * @var string caption of the table used to organize the repeated items
- */
- private $_caption='';
- /**
- * @var TTableCaptionAlign alignment of the caption of the table used to organize the repeated items
- */
- private $_captionAlign=TTableCaptionAlign::NotSet;
- /**
- * @var integer number of columns that the items should be arranged in
- */
- private $_repeatColumns=0;
- /**
- * @var TRepeatDirection direction of the repetition
- */
- private $_repeatDirection=TRepeatDirection::Vertical;
- /**
- * @var TRepeatLayout layout of the repeated items
- */
- private $_repeatLayout=TRepeatLayout::Table;
-
- /**
- * @return string caption of the table layout
- */
- public function getCaption()
- {
- return $this->_caption;
- }
-
- /**
- * @param string caption of the table layout
- */
- public function setCaption($value)
- {
- $this->_caption=$value;
- }
-
- /**
- * @return TTableCaptionAlign alignment of the caption of the table layout. Defaults to TTableCaptionAlign::NotSet.
- */
- public function getCaptionAlign()
- {
- return $this->_captionAlign;
- }
-
- /**
- * @return TTableCaptionAlign alignment of the caption of the table layout.
- */
- public function setCaptionAlign($value)
- {
- $this->_captionAlign=TPropertyValue::ensureEnum($value,'TTableCaptionAlign');
- }
-
- /**
- * @return integer the number of columns that the repeated items should be displayed in. Defaults to 0, meaning not set.
- */
- public function getRepeatColumns()
- {
- return $this->_repeatColumns;
- }
-
- /**
- * @param integer the number of columns that the repeated items should be displayed in.
- */
- public function setRepeatColumns($value)
- {
- if(($value=TPropertyValue::ensureInteger($value))<0)
- throw new TInvalidDataValueException('repeatinfo_repeatcolumns_invalid');
- $this->_repeatColumns=$value;
- }
-
- /**
- * @return TRepeatDirection the direction of traversing the repeated items, defaults to TRepeatDirection::Vertical
- */
- public function getRepeatDirection()
- {
- return $this->_repeatDirection;
- }
-
- /**
- * @param TRepeatDirection the direction of traversing the repeated items
- */
- public function setRepeatDirection($value)
- {
- $this->_repeatDirection=TPropertyValue::ensureEnum($value,'TRepeatDirection');
- }
-
- /**
- * @return TRepeatLayout how the repeated items should be displayed, using table or using line breaks. Defaults to TRepeatLayout::Table.
- */
- public function getRepeatLayout()
- {
- return $this->_repeatLayout;
- }
-
- /**
- * @param TRepeatLayout how the repeated items should be displayed, using table or using line breaks.
- */
- public function setRepeatLayout($value)
- {
- $this->_repeatLayout=TPropertyValue::ensureEnum($value,'TRepeatLayout');
- }
-
- /**
- * Renders the repeated items.
- * @param THtmlWriter writer for the rendering purpose
- * @param IRepeatInfoUser repeat information user
- */
- public function renderRepeater($writer, IRepeatInfoUser $user)
- {
- if($this->_repeatLayout===TRepeatLayout::Table)
- {
- $control=new TTable;
- if($this->_caption!=='')
- {
- $control->setCaption($this->_caption);
- $control->setCaptionAlign($this->_captionAlign);
- }
- }
- else if($this->_repeatLayout===TRepeatLayout::Raw)
- {
- $this->renderRawContents($writer,$user);
- return;
- }
- else
- $control=new TWebControl;
- $control->setID($user->getClientID());
- $control->copyBaseAttributes($user);
- if($user->getHasStyle())
- $control->getStyle()->copyFrom($user->getStyle());
- $control->renderBeginTag($writer);
- $writer->writeLine();
-
- if($this->_repeatDirection===TRepeatDirection::Vertical)
- $this->renderVerticalContents($writer,$user);
- else
- $this->renderHorizontalContents($writer,$user);
-
- $control->renderEndTag($writer);
- }
-
- /**
- * Renders contents in raw format.
- * @param THtmlWriter writer for the rendering purpose
- * @param IRepeatInfoUser repeat information user
- */
- protected function renderRawContents($writer,$user)
- {
- if($user->getHasHeader())
- $user->renderItem($writer,$this,'Header',-1);
-
- // render items
- $hasSeparators=$user->getHasSeparators();
- $itemCount=$user->getItemCount();
- for($i=0;$i<$itemCount;++$i)
- {
- $user->renderItem($writer,$this,'Item',$i);
- if($hasSeparators && $i!=$itemCount-1)
- $user->renderItem($writer,$this,'Separator',$i);
- }
- if($user->getHasFooter())
- $user->renderItem($writer,$this,'Footer',-1);
- }
-
- /**
- * Renders contents in horizontal repeat direction.
- * @param THtmlWriter writer for the rendering purpose
- * @param IRepeatInfoUser repeat information user
- */
- protected function renderHorizontalContents($writer,$user)
- {
- $tableLayout=($this->_repeatLayout===TRepeatLayout::Table);
- $hasSeparators=$user->getHasSeparators();
- $itemCount=$user->getItemCount();
- $columns=$this->_repeatColumns===0?$itemCount:$this->_repeatColumns;
- $totalColumns=$hasSeparators?$columns+$columns:$columns;
- $needBreak=$columns<$itemCount;
-
- if($user->getHasHeader())
- $this->renderHeader($writer,$user,$tableLayout,$totalColumns,$needBreak);
-
- // render items
- if($tableLayout)
- {
- $writer->renderBeginTag('tbody');
- $column=0;
- for($i=0;$i<$itemCount;++$i)
- {
- if($column==0)
- $writer->renderBeginTag('tr');
- if(($style=$user->generateItemStyle('Item',$i))!==null)
- $style->addAttributesToRender($writer);
- $writer->renderBeginTag('td');
- $user->renderItem($writer,$this,'Item',$i);
- $writer->renderEndTag();
- $writer->writeLine();
- if($hasSeparators && $i!=$itemCount-1)
- {
- if(($style=$user->generateItemStyle('Separator',$i))!==null)
- $style->addAttributesToRender($writer);
- $writer->renderBeginTag('td');
- $user->renderItem($writer,$this,'Separator',$i);
- $writer->renderEndTag();
- $writer->writeLine();
- }
- $column++;
- if($i==$itemCount-1)
- {
- $restColumns=$columns-$column;
- if($hasSeparators)
- $restColumns=$restColumns?$restColumns+$restColumns+1:1;
- for($j=0;$j<$restColumns;++$j)
- $writer->write("<td></td>\n");
- }
- if($column==$columns || $i==$itemCount-1)
- {
- $writer->renderEndTag();
- $writer->writeLine();
- $column=0;
- }
- }
- $writer->renderEndTag();
- }
- else
- {
- $column=0;
- for($i=0;$i<$itemCount;++$i)
- {
- $user->renderItem($writer,$this,'Item',$i);
- if($hasSeparators && $i!=$itemCount-1)
- $user->renderItem($writer,$this,'Separator',$i);
- $column++;
- if($column==$columns || $i==$itemCount-1)
- {
- if($needBreak)
- $writer->writeBreak();
- $column=0;
- }
- $writer->writeLine();
- }
- }
-
- if($user->getHasFooter())
- $this->renderFooter($writer,$user,$tableLayout,$totalColumns,$needBreak);
- }
-
- /**
- * Renders contents in veritcal repeat direction.
- * @param THtmlWriter writer for the rendering purpose
- * @param IRepeatInfoUser repeat information user
- */
- protected function renderVerticalContents($writer,$user)
- {
- $tableLayout=($this->_repeatLayout===TRepeatLayout::Table);
- $hasSeparators=$user->getHasSeparators();
- $itemCount=$user->getItemCount();
- if($this->_repeatColumns<=1)
- {
- $rows=$itemCount;
- $columns=1;
- $lastColumns=1;
- }
- else
- {
- $columns=$this->_repeatColumns;
- $rows=(int)(($itemCount+$columns-1)/$columns);
- if($rows==0 && $itemCount>0)
- $rows=1;
- if(($lastColumns=$itemCount%$columns)==0)
- $lastColumns=$columns;
- }
- $totalColumns=$hasSeparators?$columns+$columns:$columns;
-
- if($user->getHasHeader())
- $this->renderHeader($writer,$user,$tableLayout,$totalColumns,false);
-
- if($tableLayout)
- {
- $writer->renderBeginTag('tbody');
- $renderedItems=0;
- for($row=0;$row<$rows;++$row)
- {
- $index=$row;
- $writer->renderBeginTag('tr');
- for($col=0;$col<$columns;++$col)
- {
- if($renderedItems>=$itemCount)
- break;
- if($col>0)
- {
- $index+=$rows;
- if($col-1>=$lastColumns)
- $index--;
- }
- if($index>=$itemCount)
- continue;
- $renderedItems++;
- if(($style=$user->generateItemStyle('Item',$index))!==null)
- $style->addAttributesToRender($writer);
- $writer->renderBeginTag('td');
- $user->renderItem($writer,$this,'Item',$index);
- $writer->renderEndTag();
- $writer->writeLine();
- if(!$hasSeparators)
- continue;
- if($renderedItems<$itemCount-1)
- {
- if($columns==1)
- {
- $writer->renderEndTag();
- $writer->renderBeginTag('tr');
- }
- if(($style=$user->generateItemStyle('Separator',$index))!==null)
- $style->addAttributesToRender($writer);
- $writer->renderBeginTag('td');
- $user->renderItem($writer,$this,'Separator',$index);
- $writer->renderEndTag();
- $writer->writeLine();
- }
- else if($columns>1)
- $writer->write("<td></td>\n");
- }
- if($row==$rows-1)
- {
- $restColumns=$columns-$lastColumns;
- if($hasSeparators)
- $restColumns+=$restColumns;
- for($col=0;$col<$restColumns;++$col)
- $writer->write("<td></td>\n");
- }
- $writer->renderEndTag();
- $writer->writeLine();
- }
- $writer->renderEndTag();
- }
- else
- {
- $renderedItems=0;
- for($row=0;$row<$rows;++$row)
- {
- $index=$row;
- for($col=0;$col<$columns;++$col)
- {
- if($renderedItems>=$itemCount)
- break;
- if($col>0)
- {
- $index+=$rows;
- if($col-1>=$lastColumns)
- $index--;
- }
- if($index>=$itemCount)
- continue;
- $renderedItems++;
- $user->renderItem($writer,$this,'Item',$index);
- $writer->writeLine();
- if(!$hasSeparators)
- continue;
- if($renderedItems<$itemCount-1)
- {
- if($columns==1)
- $writer->writeBreak();
- $user->renderItem($writer,$this,'Separator',$index);
- }
- $writer->writeLine();
- }
- if($row<$rows-1 || $user->getHasFooter())
- $writer->writeBreak();
- }
- }
-
- if($user->getHasFooter())
- $this->renderFooter($writer,$user,$tableLayout,$totalColumns,false);
-
- }
-
- /**
- * Renders header.
- * @param THtmlWriter writer for the rendering purpose
- * @param IRepeatInfoUser repeat information user
- * @param boolean whether to render using table layout
- * @param integer number of columns to be rendered
- * @param boolean if a line break is needed at the end
- */
- protected function renderHeader($writer,$user,$tableLayout,$columns,$needBreak)
- {
- if($tableLayout)
- {
- $writer->renderBeginTag('thead');
- $writer->renderBeginTag('tr');
- if($columns>1)
- $writer->addAttribute('colspan',"$columns");
- $writer->addAttribute('scope','col');
- if(($style=$user->generateItemStyle('Header',-1))!==null)
- $style->addAttributesToRender($writer);
- $writer->renderBeginTag('th');
- $user->renderItem($writer,$this,'Header',-1);
- $writer->renderEndTag();
- $writer->renderEndTag();
- $writer->renderEndTag();
- }
- else
- {
- $user->renderItem($writer,$this,'Header',-1);
- if($needBreak)
- $writer->writeBreak();
- }
- $writer->writeLine();
- }
-
- /**
- * Renders footer.
- * @param THtmlWriter writer for the rendering purpose
- * @param IRepeatInfoUser repeat information user
- * @param boolean whether to render using table layout
- * @param integer number of columns to be rendered
- */
- protected function renderFooter($writer,$user,$tableLayout,$columns)
- {
- if($tableLayout)
- {
- $writer->renderBeginTag('tfoot');
- $writer->renderBeginTag('tr');
- if($columns>1)
- $writer->addAttribute('colspan',"$columns");
- if(($style=$user->generateItemStyle('Footer',-1))!==null)
- $style->addAttributesToRender($writer);
- $writer->renderBeginTag('td');
- $user->renderItem($writer,$this,'Footer',-1);
- $writer->renderEndTag();
- $writer->renderEndTag();
- $writer->renderEndTag();
- }
- else
- $user->renderItem($writer,$this,'Footer',-1);
- $writer->writeLine();
- }
-}
-
-
-/**
- * TRepeatDirection class.
- * TRepeatDirection defines the enumerable type for the possible directions
- * that repeated contents can repeat along
- *
- * The following enumerable values are defined:
- * - Vertical
- * - Horizontal
- *
- * @author Qiang Xue <qiang.xue@gmail.com>
- * @version $Id$
- * @package System.Web.UI.WebControls
- * @since 3.0.4
- */
-class TRepeatDirection extends TEnumerable
-{
- const Vertical='Vertical';
- const Horizontal='Horizontal';
-}
-
-/**
- * TRepeatLayout class.
- * TRepeatLayout defines the enumerable type for the possible layouts
- * that repeated contents can take.
- *
- * The following enumerable values are defined:
- * - Table: the repeated contents are organized using an HTML table
- * - Flow: the repeated contents are organized using HTML spans and breaks
- * - Raw: the repeated contents are stacked together without any additional decorations
- *
- * @author Qiang Xue <qiang.xue@gmail.com>
- * @version $Id$
- * @package System.Web.UI.WebControls
- * @since 3.0.4
- */
-class TRepeatLayout extends TEnumerable
-{
- const Table='Table';
- const Flow='Flow';
- const Raw='Raw';
-}
-
+ * @license http://www.pradosoft.com/license/
+ * @version $Id$
+ * @package System.Web.UI.WebControls
+ */
+
+Prado::using('System.Web.UI.WebControls.TTable');
+
+/**
+ * IRepeatInfoUser interface.
+ * This interface must be implemented by classes who want to use {@link TRepeatInfo}.
+ *
+ * @author Qiang Xue <qiang.xue@gmail.com>
+ * @version $Id$
+ * @package System.Web.UI.WebControls
+ * @since 3.0
+ */
+interface IRepeatInfoUser
+{
+ /**
+ * @return boolean whether the repeat user contains footer
+ */
+ public function getHasFooter();
+ /**
+ * @return boolean whether the repeat user contains header
+ */
+ public function getHasHeader();
+ /**
+ * @return boolean whether the repeat user contains separators
+ */
+ public function getHasSeparators();
+ /**
+ * @return integer number of items to be rendered (excluding header, footer and separators)
+ */
+ public function getItemCount();
+ /**
+ * @param string item type (Header,Footer,Item,AlternatingItem,SelectedItem,EditItem,Separator,Pager)
+ * @param integer zero-based index of the current rendering item.
+ * @return TStyle CSS style used for rendering items (including header, footer and separators)
+ */
+ public function generateItemStyle($itemType,$index);
+ /**
+ * Renders an item.
+ * @param THtmlWriter writer for the rendering purpose
+ * @param TRepeatInfo repeat information
+ * @param string item type
+ * @param integer zero-based index of the item being rendered
+ */
+ public function renderItem($writer,$repeatInfo,$itemType,$index);
+}
+
+/**
+ * TRepeatInfo class.
+ * TRepeatInfo represents repeat information for controls like {@link TCheckBoxList}.
+ * The layout of the repeated items is specified via {@link setRepeatLayout RepeatLayout},
+ * which can be either Table (default), Flow or Raw.
+ * A table layout uses HTML table cells to organize the items while
+ * a flow layout uses line breaks to organize the items.
+ * The number of columns used to display the items is specified via
+ * {@link setRepeatColumns RepeatColumns} property, while the {@link setRepeatDirection RepeatDirection}
+ * governs the order of the items being rendered.
+ *
+ * Note, the Raw layout does not contain any formatting tags and thus ignores
+ * the column and repeat direction settings.
+ *
+ * @author Qiang Xue <qiang.xue@gmail.com>
+ * @version $Id$
+ * @package System.Web.UI.WebControls
+ * @since 3.0
+ */
+class TRepeatInfo extends TComponent
+{
+ /**
+ * @var string caption of the table used to organize the repeated items
+ */
+ private $_caption='';
+ /**
+ * @var TTableCaptionAlign alignment of the caption of the table used to organize the repeated items
+ */
+ private $_captionAlign=TTableCaptionAlign::NotSet;
+ /**
+ * @var integer number of columns that the items should be arranged in
+ */
+ private $_repeatColumns=0;
+ /**
+ * @var TRepeatDirection direction of the repetition
+ */
+ private $_repeatDirection=TRepeatDirection::Vertical;
+ /**
+ * @var TRepeatLayout layout of the repeated items
+ */
+ private $_repeatLayout=TRepeatLayout::Table;
+
+ /**
+ * @return string caption of the table layout
+ */
+ public function getCaption()
+ {
+ return $this->_caption;
+ }
+
+ /**
+ * @param string caption of the table layout
+ */
+ public function setCaption($value)
+ {
+ $this->_caption=$value;
+ }
+
+ /**
+ * @return TTableCaptionAlign alignment of the caption of the table layout. Defaults to TTableCaptionAlign::NotSet.
+ */
+ public function getCaptionAlign()
+ {
+ return $this->_captionAlign;
+ }
+
+ /**
+ * @return TTableCaptionAlign alignment of the caption of the table layout.
+ */
+ public function setCaptionAlign($value)
+ {
+ $this->_captionAlign=TPropertyValue::ensureEnum($value,'TTableCaptionAlign');
+ }
+
+ /**
+ * @return integer the number of columns that the repeated items should be displayed in. Defaults to 0, meaning not set.
+ */
+ public function getRepeatColumns()
+ {
+ return $this->_repeatColumns;
+ }
+
+ /**
+ * @param integer the number of columns that the repeated items should be displayed in.
+ */
+ public function setRepeatColumns($value)
+ {
+ if(($value=TPropertyValue::ensureInteger($value))<0)
+ throw new TInvalidDataValueException('repeatinfo_repeatcolumns_invalid');
+ $this->_repeatColumns=$value;
+ }
+
+ /**
+ * @return TRepeatDirection the direction of traversing the repeated items, defaults to TRepeatDirection::Vertical
+ */
+ public function getRepeatDirection()
+ {
+ return $this->_repeatDirection;
+ }
+
+ /**
+ * @param TRepeatDirection the direction of traversing the repeated items
+ */
+ public function setRepeatDirection($value)
+ {
+ $this->_repeatDirection=TPropertyValue::ensureEnum($value,'TRepeatDirection');
+ }
+
+ /**
+ * @return TRepeatLayout how the repeated items should be displayed, using table or using line breaks. Defaults to TRepeatLayout::Table.
+ */
+ public function getRepeatLayout()
+ {
+ return $this->_repeatLayout;
+ }
+
+ /**
+ * @param TRepeatLayout how the repeated items should be displayed, using table or using line breaks.
+ */
+ public function setRepeatLayout($value)
+ {
+ $this->_repeatLayout=TPropertyValue::ensureEnum($value,'TRepeatLayout');
+ }
+
+ /**
+ * Renders the repeated items.
+ * @param THtmlWriter writer for the rendering purpose
+ * @param IRepeatInfoUser repeat information user
+ */
+ public function renderRepeater($writer, IRepeatInfoUser $user)
+ {
+ if($this->_repeatLayout===TRepeatLayout::Table)
+ {
+ $control=new TTable;
+ if($this->_caption!=='')
+ {
+ $control->setCaption($this->_caption);
+ $control->setCaptionAlign($this->_captionAlign);
+ }
+ }
+ else if($this->_repeatLayout===TRepeatLayout::Raw)
+ {
+ $this->renderRawContents($writer,$user);
+ return;
+ }
+ else
+ $control=new TWebControl;
+ $control->setID($user->getClientID());
+ $control->copyBaseAttributes($user);
+ if($user->getHasStyle())
+ $control->getStyle()->copyFrom($user->getStyle());
+ $control->renderBeginTag($writer);
+ $writer->writeLine();
+
+ if($this->_repeatDirection===TRepeatDirection::Vertical)
+ $this->renderVerticalContents($writer,$user);
+ else
+ $this->renderHorizontalContents($writer,$user);
+
+ $control->renderEndTag($writer);
+ }
+
+ /**
+ * Renders contents in raw format.
+ * @param THtmlWriter writer for the rendering purpose
+ * @param IRepeatInfoUser repeat information user
+ */
+ protected function renderRawContents($writer,$user)
+ {
+ if($user->getHasHeader())
+ $user->renderItem($writer,$this,'Header',-1);
+
+ // render items
+ $hasSeparators=$user->getHasSeparators();
+ $itemCount=$user->getItemCount();
+ for($i=0;$i<$itemCount;++$i)
+ {
+ $user->renderItem($writer,$this,'Item',$i);
+ if($hasSeparators && $i!=$itemCount-1)
+ $user->renderItem($writer,$this,'Separator',$i);
+ }
+ if($user->getHasFooter())
+ $user->renderItem($writer,$this,'Footer',-1);
+ }
+
+ /**
+ * Renders contents in horizontal repeat direction.
+ * @param THtmlWriter writer for the rendering purpose
+ * @param IRepeatInfoUser repeat information user
+ */
+ protected function renderHorizontalContents($writer,$user)
+ {
+ $tableLayout=($this->_repeatLayout===TRepeatLayout::Table);
+ $hasSeparators=$user->getHasSeparators();
+ $itemCount=$user->getItemCount();
+ $columns=$this->_repeatColumns===0?$itemCount:$this->_repeatColumns;
+ $totalColumns=$hasSeparators?$columns+$columns:$columns;
+ $needBreak=$columns<$itemCount;
+
+ if($user->getHasHeader())
+ $this->renderHeader($writer,$user,$tableLayout,$totalColumns,$needBreak);
+
+ // render items
+ if($tableLayout)
+ {
+ $writer->renderBeginTag('tbody');
+ $column=0;
+ for($i=0;$i<$itemCount;++$i)
+ {
+ if($column==0)
+ $writer->renderBeginTag('tr');
+ if(($style=$user->generateItemStyle('Item',$i))!==null)
+ $style->addAttributesToRender($writer);
+ $writer->renderBeginTag('td');
+ $user->renderItem($writer,$this,'Item',$i);
+ $writer->renderEndTag();
+ $writer->writeLine();
+ if($hasSeparators && $i!=$itemCount-1)
+ {
+ if(($style=$user->generateItemStyle('Separator',$i))!==null)
+ $style->addAttributesToRender($writer);
+ $writer->renderBeginTag('td');
+ $user->renderItem($writer,$this,'Separator',$i);
+ $writer->renderEndTag();
+ $writer->writeLine();
+ }
+ $column++;
+ if($i==$itemCount-1)
+ {
+ $restColumns=$columns-$column;
+ if($hasSeparators)
+ $restColumns=$restColumns?$restColumns+$restColumns+1:1;
+ for($j=0;$j<$restColumns;++$j)
+ $writer->write("<td></td>\n");
+ }
+ if($column==$columns || $i==$itemCount-1)
+ {
+ $writer->renderEndTag();
+ $writer->writeLine();
+ $column=0;
+ }
+ }
+ $writer->renderEndTag();
+ }
+ else
+ {
+ $column=0;
+ for($i=0;$i<$itemCount;++$i)
+ {
+ $user->renderItem($writer,$this,'Item',$i);
+ if($hasSeparators && $i!=$itemCount-1)
+ $user->renderItem($writer,$this,'Separator',$i);
+ $column++;
+ if($column==$columns || $i==$itemCount-1)
+ {
+ if($needBreak)
+ $writer->writeBreak();
+ $column=0;
+ }
+ $writer->writeLine();
+ }
+ }
+
+ if($user->getHasFooter())
+ $this->renderFooter($writer,$user,$tableLayout,$totalColumns,$needBreak);
+ }
+
+ /**
+ * Renders contents in veritcal repeat direction.
+ * @param THtmlWriter writer for the rendering purpose
+ * @param IRepeatInfoUser repeat information user
+ */
+ protected function renderVerticalContents($writer,$user)
+ {
+ $tableLayout=($this->_repeatLayout===TRepeatLayout::Table);
+ $hasSeparators=$user->getHasSeparators();
+ $itemCount=$user->getItemCount();
+ if($this->_repeatColumns<=1)
+ {
+ $rows=$itemCount;
+ $columns=1;
+ $lastColumns=1;
+ }
+ else
+ {
+ $columns=$this->_repeatColumns;
+ $rows=(int)(($itemCount+$columns-1)/$columns);
+ if($rows==0 && $itemCount>0)
+ $rows=1;
+ if(($lastColumns=$itemCount%$columns)==0)
+ $lastColumns=$columns;
+ }
+ $totalColumns=$hasSeparators?$columns+$columns:$columns;
+
+ if($user->getHasHeader())
+ $this->renderHeader($writer,$user,$tableLayout,$totalColumns,false);
+
+ if($tableLayout)
+ {
+ $writer->renderBeginTag('tbody');
+ $renderedItems=0;
+ for($row=0;$row<$rows;++$row)
+ {
+ $index=$row;
+ $writer->renderBeginTag('tr');
+ for($col=0;$col<$columns;++$col)
+ {
+ if($renderedItems>=$itemCount)
+ break;
+ if($col>0)
+ {
+ $index+=$rows;
+ if($col-1>=$lastColumns)
+ $index--;
+ }
+ if($index>=$itemCount)
+ continue;
+ $renderedItems++;
+ if(($style=$user->generateItemStyle('Item',$index))!==null)
+ $style->addAttributesToRender($writer);
+ $writer->renderBeginTag('td');
+ $user->renderItem($writer,$this,'Item',$index);
+ $writer->renderEndTag();
+ $writer->writeLine();
+ if(!$hasSeparators)
+ continue;
+ if($renderedItems<$itemCount-1)
+ {
+ if($columns==1)
+ {
+ $writer->renderEndTag();
+ $writer->renderBeginTag('tr');
+ }
+ if(($style=$user->generateItemStyle('Separator',$index))!==null)
+ $style->addAttributesToRender($writer);
+ $writer->renderBeginTag('td');
+ $user->renderItem($writer,$this,'Separator',$index);
+ $writer->renderEndTag();
+ $writer->writeLine();
+ }
+ else if($columns>1)
+ $writer->write("<td></td>\n");
+ }
+ if($row==$rows-1)
+ {
+ $restColumns=$columns-$lastColumns;
+ if($hasSeparators)
+ $restColumns+=$restColumns;
+ for($col=0;$col<$restColumns;++$col)
+ $writer->write("<td></td>\n");
+ }
+ $writer->renderEndTag();
+ $writer->writeLine();
+ }
+ $writer->renderEndTag();
+ }
+ else
+ {
+ $renderedItems=0;
+ for($row=0;$row<$rows;++$row)
+ {
+ $index=$row;
+ for($col=0;$col<$columns;++$col)
+ {
+ if($renderedItems>=$itemCount)
+ break;
+ if($col>0)
+ {
+ $index+=$rows;
+ if($col-1>=$lastColumns)
+ $index--;
+ }
+ if($index>=$itemCount)
+ continue;
+ $renderedItems++;
+ $user->renderItem($writer,$this,'Item',$index);
+ $writer->writeLine();
+ if(!$hasSeparators)
+ continue;
+ if($renderedItems<$itemCount-1)
+ {
+ if($columns==1)
+ $writer->writeBreak();
+ $user->renderItem($writer,$this,'Separator',$index);
+ }
+ $writer->writeLine();
+ }
+ if($row<$rows-1 || $user->getHasFooter())
+ $writer->writeBreak();
+ }
+ }
+
+ if($user->getHasFooter())
+ $this->renderFooter($writer,$user,$tableLayout,$totalColumns,false);
+
+ }
+
+ /**
+ * Renders header.
+ * @param THtmlWriter writer for the rendering purpose
+ * @param IRepeatInfoUser repeat information user
+ * @param boolean whether to render using table layout
+ * @param integer number of columns to be rendered
+ * @param boolean if a line break is needed at the end
+ */
+ protected function renderHeader($writer,$user,$tableLayout,$columns,$needBreak)
+ {
+ if($tableLayout)
+ {
+ $writer->renderBeginTag('thead');
+ $writer->renderBeginTag('tr');
+ if($columns>1)
+ $writer->addAttribute('colspan',"$columns");
+ $writer->addAttribute('scope','col');
+ if(($style=$user->generateItemStyle('Header',-1))!==null)
+ $style->addAttributesToRender($writer);
+ $writer->renderBeginTag('th');
+ $user->renderItem($writer,$this,'Header',-1);
+ $writer->renderEndTag();
+ $writer->renderEndTag();
+ $writer->renderEndTag();
+ }
+ else
+ {
+ $user->renderItem($writer,$this,'Header',-1);
+ if($needBreak)
+ $writer->writeBreak();
+ }
+ $writer->writeLine();
+ }
+
+ /**
+ * Renders footer.
+ * @param THtmlWriter writer for the rendering purpose
+ * @param IRepeatInfoUser repeat information user
+ * @param boolean whether to render using table layout
+ * @param integer number of columns to be rendered
+ */
+ protected function renderFooter($writer,$user,$tableLayout,$columns)
+ {
+ if($tableLayout)
+ {
+ $writer->renderBeginTag('tfoot');
+ $writer->renderBeginTag('tr');
+ if($columns>1)
+ $writer->addAttribute('colspan',"$columns");
+ if(($style=$user->generateItemStyle('Footer',-1))!==null)
+ $style->addAttributesToRender($writer);
+ $writer->renderBeginTag('td');
+ $user->renderItem($writer,$this,'Footer',-1);
+ $writer->renderEndTag();
+ $writer->renderEndTag();
+ $writer->renderEndTag();
+ }
+ else
+ $user->renderItem($writer,$this,'Footer',-1);
+ $writer->writeLine();
+ }
+}
+
+
+/**
+ * TRepeatDirection class.
+ * TRepeatDirection defines the enumerable type for the possible directions
+ * that repeated contents can repeat along
+ *
+ * The following enumerable values are defined:
+ * - Vertical
+ * - Horizontal
+ *
+ * @author Qiang Xue <qiang.xue@gmail.com>
+ * @version $Id$
+ * @package System.Web.UI.WebControls
+ * @since 3.0.4
+ */
+class TRepeatDirection extends TEnumerable
+{
+ const Vertical='Vertical';
+ const Horizontal='Horizontal';
+}
+
+/**
+ * TRepeatLayout class.
+ * TRepeatLayout defines the enumerable type for the possible layouts
+ * that repeated contents can take.
+ *
+ * The following enumerable values are defined:
+ * - Table: the repeated contents are organized using an HTML table
+ * - Flow: the repeated contents are organized using HTML spans and breaks
+ * - Raw: the repeated contents are stacked together without any additional decorations
+ *
+ * @author Qiang Xue <qiang.xue@gmail.com>
+ * @version $Id$
+ * @package System.Web.UI.WebControls
+ * @since 3.0.4
+ */
+class TRepeatLayout extends TEnumerable
+{
+ const Table='Table';
+ const Flow='Flow';
+ const Raw='Raw';
+}
+
diff --git a/framework/Web/UI/WebControls/TRepeater.php b/framework/Web/UI/WebControls/TRepeater.php
index 6a59cbab..944b3a17 100644
--- a/framework/Web/UI/WebControls/TRepeater.php
+++ b/framework/Web/UI/WebControls/TRepeater.php
@@ -1,1025 +1,1025 @@
-<?php
-/**
- * TRepeater class file
- *
- * @author Qiang Xue <qiang.xue@gmail.com>
- * @link http://www.pradosoft.com/
+<?php
+/**
+ * TRepeater class file
+ *
+ * @author Qiang Xue <qiang.xue@gmail.com>
+ * @link http://www.pradosoft.com/
* @copyright Copyright &copy; 2005-2012 PradoSoft
- * @license http://www.pradosoft.com/license/
- * @version $Id$
- * @package System.Web.UI.WebControls
- */
-
-/**
- * Using TDataBoundControl and TDataFieldAccessor cass
- */
-Prado::using('System.Web.UI.WebControls.TDataBoundControl');
-Prado::using('System.Util.TDataFieldAccessor');
-
-/**
- * TRepeater class.
- *
- * TRepeater displays its content repeatedly based on the data fetched from
- * {@link setDataSource DataSource}.
- * The repeated contents in TRepeater are called items, which are controls and
- * can be accessed through {@link getItems Items}. When {@link dataBind()} is invoked,
- * TRepeater creates an item for each row of data and binds the data row to the item.
- * Optionally, a repeater can have a header, a footer and/or separators between items.
- *
- * The layout of the repeated contents are specified by inline templates.
- * Repeater items, header, footer, etc. are being instantiated with the corresponding
- * templates when data is being bound to the repeater.
- *
- * Since v3.1.0, the layout can also be specified by renderers. A renderer is a control class
- * that can be instantiated as repeater items, header, etc. A renderer can thus be viewed
- * as an external template (in fact, it can also be non-templated controls).
- *
- * A renderer can be any control class.
- * - If the class implements {@link IDataRenderer}, the <b>Data</b>
- * property will be set as the data row during databinding. Many PRADO controls
- * implement this interface, such as {@link TLabel}, {@link TTextBox}, etc.
- * - If the class implements {@link IItemDataRenderer}, the <b>ItemIndex</b> property will be set
- * as the zero-based index of the item in the repeater item collection, and
- * the <b>ItemType</b> property as the item's type (such as TListItemType::Item).
- * {@link TRepeaterItemRenderer} may be used as the convenient base class which
- * already implements {@link IDataItemRenderer}.
- *
- * The following properties are used to specify different types of template and renderer
- * for a repeater:
- * - {@link setItemTemplate ItemTemplate}, {@link setItemRenderer ItemRenderer}:
- * for each repeated row of data
- * - {@link setAlternatingItemTemplate AlternatingItemTemplate}, {@link setAlternatingItemRenderer AlternatingItemRenderer}:
- * for each alternating row of data. If not set, {@link setItemTemplate ItemTemplate} or {@link setItemRenderer ItemRenderer}
- * will be used instead.
- * - {@link setHeaderTemplate HeaderTemplate}, {@link setHeaderRenderer HeaderRenderer}:
- * for the repeater header.
- * - {@link setFooterTemplate FooterTemplate}, {@link setFooterRenderer FooterRenderer}:
- * for the repeater footer.
- * - {@link setSeparatorTemplate SeparatorTemplate}, {@link setSeparatorRenderer SeparatorRenderer}:
- * for content to be displayed between items.
- * - {@link setEmptyTemplate EmptyTemplate}, {@link setEmptyRenderer EmptyRenderer}:
- * used when data bound to the repeater is empty.
- *
- * If a content type is defined with both a template and a renderer, the latter takes precedence.
- *
- * When {@link dataBind()} is being called, TRepeater undergoes the following lifecycles for each row of data:
- * - create item based on templates or renderers
- * - set the row of data to the item
- * - raise {@link onItemCreated OnItemCreated}:
- * - add the item as a child control
- * - call dataBind() of the item
- * - raise {@link onItemDataBound OnItemDataBound}:
- *
- * TRepeater raises an {@link onItemCommand OnItemCommand} whenever a button control
- * within some repeater item raises a <b>OnCommand</b> event. Therefore,
- * you can handle all sorts of <b>OnCommand</b> event in a central place by
- * writing an event handler for {@link onItemCommand OnItemCommand}.
- *
- * When a page containing a repeater is post back, the repeater will restore automatically
- * all its contents, including items, header, footer and separators.
- * However, the data row associated with each item will not be recovered and become null.
- * To access the data, use one of the following ways:
- * - Use {@link getDataKeys DataKeys} to obtain the data key associated with
- * the specified repeater item and use the key to fetch the corresponding data
- * from some persistent storage such as DB.
- * - Save the whole dataset in viewstate, which will restore the dataset automatically upon postback.
- * Be aware though, if the size of your dataset is big, your page size will become big. Some
- * complex data may also have serializing problem if saved in viewstate.
- *
- * @author Qiang Xue <qiang.xue@gmail.com>
- * @version $Id$
- * @package System.Web.UI.WebControls
- * @since 3.0
- */
-class TRepeater extends TDataBoundControl implements INamingContainer
-{
- /**
- * Repeater item types
- * @deprecated deprecated since version 3.0.4. Use TListItemType constants instead.
- */
- const IT_HEADER='Header';
- const IT_FOOTER='Footer';
- const IT_ITEM='Item';
- const IT_SEPARATOR='Separator';
- const IT_ALTERNATINGITEM='AlternatingItem';
-
- /**
- * @var ITemplate template for repeater items
- */
- private $_itemTemplate=null;
- /**
- * @var ITemplate template for each alternating item
- */
- private $_alternatingItemTemplate=null;
- /**
- * @var ITemplate template for header
- */
- private $_headerTemplate=null;
- /**
- * @var ITemplate template for footer
- */
- private $_footerTemplate=null;
- /**
- * @var ITemplate template used for repeater when no data is bound
- */
- private $_emptyTemplate=null;
- /**
- * @var ITemplate template for separator
- */
- private $_separatorTemplate=null;
- /**
- * @var TRepeaterItemCollection list of repeater items
- */
- private $_items=null;
- /**
- * @var TControl header item
- */
- private $_header=null;
- /**
- * @var TControl footer item
- */
- private $_footer=null;
-
-
- /**
- * @return string the class name for repeater items. Defaults to empty, meaning not set.
- * @since 3.1.0
- */
- public function getItemRenderer()
- {
- return $this->getViewState('ItemRenderer','');
- }
-
- /**
- * Sets the item renderer class.
- *
- * If not empty, the class will be used to instantiate as repeater items.
- * This property takes precedence over {@link getItemTemplate ItemTemplate}.
- *
- * @param string the renderer class name in namespace format.
- * @see setItemTemplate
- * @since 3.1.0
- */
- public function setItemRenderer($value)
- {
- $this->setViewState('ItemRenderer',$value,'');
- }
-
- /**
- * @return string the class name for alternative repeater items. Defaults to empty, meaning not set.
- * @since 3.1.0
- */
- public function getAlternatingItemRenderer()
- {
- return $this->getViewState('AlternatingItemRenderer','');
- }
-
- /**
- * Sets the alternative item renderer class.
- *
- * If not empty, the class will be used to instantiate as alternative repeater items.
- * This property takes precedence over {@link getAlternatingItemTemplate AlternatingItemTemplate}.
- *
- * @param string the renderer class name in namespace format.
- * @see setAlternatingItemTemplate
- * @since 3.1.0
- */
- public function setAlternatingItemRenderer($value)
- {
- $this->setViewState('AlternatingItemRenderer',$value,'');
- }
-
- /**
- * @return string the class name for repeater item separators. Defaults to empty, meaning not set.
- * @since 3.1.0
- */
- public function getSeparatorRenderer()
- {
- return $this->getViewState('SeparatorRenderer','');
- }
-
- /**
- * Sets the repeater item separator renderer class.
- *
- * If not empty, the class will be used to instantiate as repeater item separators.
- * This property takes precedence over {@link getSeparatorTemplate SeparatorTemplate}.
- *
- * @param string the renderer class name in namespace format.
- * @see setSeparatorTemplate
- * @since 3.1.0
- */
- public function setSeparatorRenderer($value)
- {
- $this->setViewState('SeparatorRenderer',$value,'');
- }
-
- /**
- * @return string the class name for repeater header item. Defaults to empty, meaning not set.
- * @since 3.1.0
- */
- public function getHeaderRenderer()
- {
- return $this->getViewState('HeaderRenderer','');
- }
-
- /**
- * Sets the repeater header renderer class.
- *
- * If not empty, the class will be used to instantiate as repeater header item.
- * This property takes precedence over {@link getHeaderTemplate HeaderTemplate}.
- *
- * @param string the renderer class name in namespace format.
- * @see setHeaderTemplate
- * @since 3.1.0
- */
- public function setHeaderRenderer($value)
- {
- $this->setViewState('HeaderRenderer',$value,'');
- }
-
- /**
- * @return string the class name for repeater footer item. Defaults to empty, meaning not set.
- * @since 3.1.0
- */
- public function getFooterRenderer()
- {
- return $this->getViewState('FooterRenderer','');
- }
-
- /**
- * Sets the repeater footer renderer class.
- *
- * If not empty, the class will be used to instantiate as repeater footer item.
- * This property takes precedence over {@link getFooterTemplate FooterTemplate}.
- *
- * @param string the renderer class name in namespace format.
- * @see setFooterTemplate
- * @since 3.1.0
- */
- public function setFooterRenderer($value)
- {
- $this->setViewState('FooterRenderer',$value,'');
- }
-
- /**
- * @return string the class name for empty repeater item. Defaults to empty, meaning not set.
- * @since 3.1.0
- */
- public function getEmptyRenderer()
- {
- return $this->getViewState('EmptyRenderer','');
- }
-
- /**
- * Sets the repeater empty renderer class.
- *
- * The empty renderer is created as the child of the repeater
- * if data bound to the repeater is empty.
- * This property takes precedence over {@link getEmptyTemplate EmptyTemplate}.
- *
- * @param string the renderer class name in namespace format.
- * @see setEmptyTemplate
- * @since 3.1.0
- */
- public function setEmptyRenderer($value)
- {
- $this->setViewState('EmptyRenderer',$value,'');
- }
-
- /**
- * @return ITemplate the template for repeater items
- */
- public function getItemTemplate()
- {
- return $this->_itemTemplate;
- }
-
- /**
- * @param ITemplate the template for repeater items
- * @throws TInvalidDataTypeException if the input is not an {@link ITemplate} or not null.
- */
- public function setItemTemplate($value)
- {
- if($value instanceof ITemplate || $value===null)
- $this->_itemTemplate=$value;
- else
- throw new TInvalidDataTypeException('repeater_template_required','ItemTemplate');
- }
-
- /**
- * @return ITemplate the alternative template string for the item
- */
- public function getAlternatingItemTemplate()
- {
- return $this->_alternatingItemTemplate;
- }
-
- /**
- * @param ITemplate the alternative item template
- * @throws TInvalidDataTypeException if the input is not an {@link ITemplate} or not null.
- */
- public function setAlternatingItemTemplate($value)
- {
- if($value instanceof ITemplate || $value===null)
- $this->_alternatingItemTemplate=$value;
- else
- throw new TInvalidDataTypeException('repeater_template_required','AlternatingItemTemplate');
- }
-
- /**
- * @return ITemplate the header template
- */
- public function getHeaderTemplate()
- {
- return $this->_headerTemplate;
- }
-
- /**
- * @param ITemplate the header template
- * @throws TInvalidDataTypeException if the input is not an {@link ITemplate} or not null.
- */
- public function setHeaderTemplate($value)
- {
- if($value instanceof ITemplate || $value===null)
- $this->_headerTemplate=$value;
- else
- throw new TInvalidDataTypeException('repeater_template_required','HeaderTemplate');
- }
-
- /**
- * @return ITemplate the footer template
- */
- public function getFooterTemplate()
- {
- return $this->_footerTemplate;
- }
-
- /**
- * @param ITemplate the footer template
- * @throws TInvalidDataTypeException if the input is not an {@link ITemplate} or not null.
- */
- public function setFooterTemplate($value)
- {
- if($value instanceof ITemplate || $value===null)
- $this->_footerTemplate=$value;
- else
- throw new TInvalidDataTypeException('repeater_template_required','FooterTemplate');
- }
-
- /**
- * @return ITemplate the template applied when no data is bound to the repeater
- */
- public function getEmptyTemplate()
- {
- return $this->_emptyTemplate;
- }
-
- /**
- * @param ITemplate the template applied when no data is bound to the repeater
- * @throws TInvalidDataTypeException if the input is not an {@link ITemplate} or not null.
- */
- public function setEmptyTemplate($value)
- {
- if($value instanceof ITemplate || $value===null)
- $this->_emptyTemplate=$value;
- else
- throw new TInvalidDataTypeException('repeater_template_required','EmptyTemplate');
- }
-
- /**
- * @return ITemplate the separator template
- */
- public function getSeparatorTemplate()
- {
- return $this->_separatorTemplate;
- }
-
- /**
- * @param ITemplate the separator template
- * @throws TInvalidDataTypeException if the input is not an {@link ITemplate} or not null.
- */
- public function setSeparatorTemplate($value)
- {
- if($value instanceof ITemplate || $value===null)
- $this->_separatorTemplate=$value;
- else
- throw new TInvalidDataTypeException('repeater_template_required','SeparatorTemplate');
- }
-
- /**
- * @return TControl the header item
- */
- public function getHeader()
- {
- return $this->_header;
- }
-
- /**
- * @return TControl the footer item
- */
- public function getFooter()
- {
- return $this->_footer;
- }
-
- /**
- * @return TRepeaterItemCollection list of repeater item controls
- */
- public function getItems()
- {
- if(!$this->_items)
- $this->_items=new TRepeaterItemCollection;
- return $this->_items;
- }
-
- /**
- * @return string the field of the data source that provides the keys of the list items.
- */
- public function getDataKeyField()
- {
- return $this->getViewState('DataKeyField','');
- }
-
- /**
- * @param string the field of the data source that provides the keys of the list items.
- */
- public function setDataKeyField($value)
- {
- $this->setViewState('DataKeyField',$value,'');
- }
-
- /**
- * @return TList the keys used in the data listing control.
- */
- public function getDataKeys()
- {
- if(($dataKeys=$this->getViewState('DataKeys',null))===null)
- {
- $dataKeys=new TList;
- $this->setViewState('DataKeys',$dataKeys,null);
- }
- return $dataKeys;
- }
-
- /**
- * Creates a repeater item.
- * This method invokes {@link createItem} to create a new repeater item.
- * @param integer zero-based item index.
- * @param TListItemType item type
- * @return TControl the created item, null if item is not created
- */
- private function createItemInternal($itemIndex,$itemType)
- {
- if(($item=$this->createItem($itemIndex,$itemType))!==null)
- {
- $param=new TRepeaterItemEventParameter($item);
- $this->onItemCreated($param);
- $this->getControls()->add($item);
- return $item;
- }
- else
- return null;
- }
-
- /**
- * Creates a repeater item and performs databinding.
- * This method invokes {@link createItem} to create a new repeater item.
- * @param integer zero-based item index.
- * @param TListItemType item type
- * @param mixed data to be associated with the item
- * @return TControl the created item, null if item is not created
- */
- private function createItemWithDataInternal($itemIndex,$itemType,$dataItem)
- {
- if(($item=$this->createItem($itemIndex,$itemType))!==null)
- {
- $param=new TRepeaterItemEventParameter($item);
- if($item instanceof IDataRenderer)
- $item->setData($dataItem);
- $this->onItemCreated($param);
- $this->getControls()->add($item);
- $item->dataBind();
- $this->onItemDataBound($param);
- return $item;
- }
- else
- return null;
- }
-
- /**
- * Creates a repeater item instance based on the item type and index.
- * @param integer zero-based item index
- * @param TListItemType item type
- * @return TControl created repeater item
- */
- protected function createItem($itemIndex,$itemType)
- {
- $template=null;
- $classPath=null;
- switch($itemType)
- {
- case TListItemType::Item :
- $classPath=$this->getItemRenderer();
- $template=$this->_itemTemplate;
- break;
- case TListItemType::AlternatingItem :
- if(($classPath=$this->getAlternatingItemRenderer())==='' && ($template=$this->_alternatingItemTemplate)===null)
- {
- $classPath=$this->getItemRenderer();
- $template=$this->_itemTemplate;
- }
- break;
- case TListItemType::Header :
- $classPath=$this->getHeaderRenderer();
- $template=$this->_headerTemplate;
- break;
- case TListItemType::Footer :
- $classPath=$this->getFooterRenderer();
- $template=$this->_footerTemplate;
- break;
- case TListItemType::Separator :
- $classPath=$this->getSeparatorRenderer();
- $template=$this->_separatorTemplate;
- break;
- default:
- throw new TInvalidDataValueException('repeater_itemtype_unknown',$itemType);
- }
- if($classPath!=='')
- {
- $item=Prado::createComponent($classPath);
- if($item instanceof IItemDataRenderer)
- {
- $item->setItemIndex($itemIndex);
- $item->setItemType($itemType);
- }
- }
- else if($template!==null)
- {
- $item=new TRepeaterItem;
- $item->setItemIndex($itemIndex);
- $item->setItemType($itemType);
- $template->instantiateIn($item);
- }
- else
- $item=null;
-
- return $item;
- }
-
- /**
- * Creates empty repeater content.
- */
- protected function createEmptyContent()
- {
- if(($classPath=$this->getEmptyRenderer())!=='')
- $this->getControls()->add(Prado::createComponent($classPath));
- else if($this->_emptyTemplate!==null)
- $this->_emptyTemplate->instantiateIn($this);
- }
-
- /**
- * Renders the repeater.
- * This method overrides the parent implementation by rendering the body
- * content as the whole presentation of the repeater. Outer tag is not rendered.
- * @param THtmlWriter writer
- */
- public function render($writer)
- {
- if($this->_items && $this->_items->getCount() || $this->_emptyTemplate!==null || $this->getEmptyRenderer()!=='')
- $this->renderContents($writer);
- }
-
- /**
- * Saves item count in viewstate.
- * This method is invoked right before control state is to be saved.
- */
- public function saveState()
- {
- parent::saveState();
- if($this->_items)
- $this->setViewState('ItemCount',$this->_items->getCount(),0);
- else
- $this->clearViewState('ItemCount');
- }
-
- /**
- * Loads item count information from viewstate.
- * This method is invoked right after control state is loaded.
- */
- public function loadState()
- {
- parent::loadState();
- if(!$this->getIsDataBound())
- $this->restoreItemsFromViewState();
- $this->clearViewState('ItemCount');
- }
-
- /**
- * Clears up all items in the repeater.
- */
- public function reset()
- {
- $this->getControls()->clear();
- $this->getItems()->clear();
- $this->_header=null;
- $this->_footer=null;
- }
-
- /**
- * Creates repeater items based on viewstate information.
- */
- protected function restoreItemsFromViewState()
- {
- $this->reset();
- if(($itemCount=$this->getViewState('ItemCount',0))>0)
- {
- $items=$this->getItems();
- $hasSeparator=$this->_separatorTemplate!==null || $this->getSeparatorRenderer()!=='';
- $this->_header=$this->createItemInternal(-1,TListItemType::Header);
- for($i=0;$i<$itemCount;++$i)
- {
- if($hasSeparator && $i>0)
- $this->createItemInternal($i-1,TListItemType::Separator);
- $itemType=$i%2==0?TListItemType::Item : TListItemType::AlternatingItem;
- $items->add($this->createItemInternal($i,$itemType,false,null));
- }
- $this->_footer=$this->createItemInternal(-1,TListItemType::Footer);
- }
- else
- $this->createEmptyContent();
- $this->clearChildState();
- }
-
- /**
- * Performs databinding to populate repeater items from data source.
- * This method is invoked by dataBind().
- * You may override this function to provide your own way of data population.
- * @param Traversable the data
- */
- protected function performDataBinding($data)
- {
- $this->reset();
-
- $keys=$this->getDataKeys();
- $keys->clear();
- $keyField=$this->getDataKeyField();
-
- $items=$this->getItems();
- $itemIndex=0;
- $hasSeparator=$this->_separatorTemplate!==null || $this->getSeparatorRenderer()!=='';
- foreach($data as $key=>$dataItem)
- {
- if($keyField!=='')
- $keys->add($this->getDataFieldValue($dataItem,$keyField));
- else
- $keys->add($key);
- if($itemIndex===0)
- $this->_header=$this->createItemWithDataInternal(-1,TListItemType::Header,null);
- if($hasSeparator && $itemIndex>0)
- $this->createItemWithDataInternal($itemIndex-1,TListItemType::Separator,null);
- $itemType=$itemIndex%2==0?TListItemType::Item : TListItemType::AlternatingItem;
- $items->add($this->createItemWithDataInternal($itemIndex,$itemType,$dataItem));
- $itemIndex++;
- }
- if($itemIndex>0)
- $this->_footer=$this->createItemWithDataInternal(-1,TListItemType::Footer,null);
- else
- {
- $this->createEmptyContent();
- $this->dataBindChildren();
- }
- $this->setViewState('ItemCount',$itemIndex,0);
- }
-
- /**
- * This method overrides parent's implementation to handle
- * {@link onItemCommand OnItemCommand} event which is bubbled from
- * repeater items and their child controls.
- * This method should only be used by control developers.
- * @param TControl the sender of the event
- * @param TEventParameter event parameter
- * @return boolean whether the event bubbling should stop here.
- */
- public function bubbleEvent($sender,$param)
- {
- if($param instanceof TRepeaterCommandEventParameter)
- {
- $this->onItemCommand($param);
- return true;
- }
- else
- return false;
- }
-
- /**
- * Raises <b>OnItemCreated</b> event.
- * This method is invoked after a repeater item is created and instantiated with
- * template, but before added to the page hierarchy.
- * The repeater item control responsible for the event
- * can be determined from the event parameter.
- * If you override this method, be sure to call parent's implementation
- * so that event handlers have chance to respond to the event.
- * @param TRepeaterItemEventParameter event parameter
- */
- public function onItemCreated($param)
- {
- $this->raiseEvent('OnItemCreated',$this,$param);
- }
-
- /**
- * Raises <b>OnItemDataBound</b> event.
- * This method is invoked right after an item is data bound.
- * The repeater item control responsible for the event
- * can be determined from the event parameter.
- * If you override this method, be sure to call parent's implementation
- * so that event handlers have chance to respond to the event.
- * @param TRepeaterItemEventParameter event parameter
- */
- public function onItemDataBound($param)
- {
- $this->raiseEvent('OnItemDataBound',$this,$param);
- }
-
- /**
- * Raises <b>OnItemCommand</b> event.
- * This method is invoked after a button control in
- * a template raises <b>OnCommand</b> event.
- * The repeater control responsible for the event
- * can be determined from the event parameter.
- * The event parameter also contains the information about
- * the initial sender of the <b>OnCommand</b> event, command name
- * and command parameter.
- * You may override this method to provide customized event handling.
- * Be sure to call parent's implementation so that
- * event handlers have chance to respond to the event.
- * @param TRepeaterCommandEventParameter event parameter
- */
- public function onItemCommand($param)
- {
- $this->raiseEvent('OnItemCommand',$this,$param);
- }
-
- /**
- * Returns the value of the data at the specified field.
- * If data is an array, TMap or TList, the value will be returned at the index
- * of the specified field. If the data is a component with a property named
- * as the field name, the property value will be returned.
- * Otherwise, an exception will be raised.
- * @param mixed data item
- * @param mixed field name
- * @return mixed data value at the specified field
- * @throws TInvalidDataValueException if the data is invalid
- */
- protected function getDataFieldValue($data,$field)
- {
- return TDataFieldAccessor::getDataFieldValue($data,$field);
- }
-}
-
-/**
- * TRepeaterItemEventParameter class
- *
- * TRepeaterItemEventParameter encapsulates the parameter data for
- * {@link TRepeater::onItemCreated ItemCreated} event of {@link TRepeater} controls.
- * The {@link getItem Item} property indicates the repeater item related with the event.
- *
- * @author Qiang Xue <qiang.xue@gmail.com>
- * @version $Id$
- * @package System.Web.UI.WebControls
- * @since 3.0
- */
-class TRepeaterItemEventParameter extends TEventParameter
-{
- /**
- * The repeater item control responsible for the event.
- * @var TControl
- */
- private $_item=null;
-
- /**
- * Constructor.
- * @param TControl repeater item related with the corresponding event
- */
- public function __construct($item)
- {
- $this->_item=$item;
- }
-
- /**
- * @return TControl repeater item related with the corresponding event
- */
- public function getItem()
- {
- return $this->_item;
- }
-}
-
-/**
- * TRepeaterCommandEventParameter class
- *
- * TRepeaterCommandEventParameter encapsulates the parameter data for
- * {@link TRepeater::onItemCommand ItemCommand} event of {@link TRepeater} controls.
- *
- * The {@link getItem Item} property indicates the repeater item related with the event.
- * The {@link getCommandSource CommandSource} refers to the control that originally
- * raises the Command event.
- *
- * @author Qiang Xue <qiang.xue@gmail.com>
- * @version $Id$
- * @package System.Web.UI.WebControls
- * @since 3.0
- */
-class TRepeaterCommandEventParameter extends TCommandEventParameter
-{
- /**
- * @var TControl the repeater item control responsible for the event.
- */
- private $_item=null;
- /**
- * @var TControl the control originally raises the <b>OnCommand</b> event.
- */
- private $_source=null;
-
- /**
- * Constructor.
- * @param TControl repeater item responsible for the event
- * @param TControl original event sender
- * @param TCommandEventParameter original event parameter
- */
- public function __construct($item,$source,TCommandEventParameter $param)
- {
- $this->_item=$item;
- $this->_source=$source;
- parent::__construct($param->getCommandName(),$param->getCommandParameter());
- }
-
- /**
- * @return TControl the repeater item control responsible for the event.
- */
- public function getItem()
- {
- return $this->_item;
- }
-
- /**
- * @return TControl the control originally raises the <b>OnCommand</b> event.
- */
- public function getCommandSource()
- {
- return $this->_source;
- }
-}
-
-/**
- * TRepeaterItem class
- *
- * A TRepeaterItem control represents an item in the {@link TRepeater} control,
- * such as heading section, footer section, or a data item.
- * The index and data value of the item can be accessed via {@link getItemIndex ItemIndex}>
- * and {@link getDataItem DataItem} properties, respectively. The type of the item
- * is given by {@link getItemType ItemType} property.
- *
- * @author Qiang Xue <qiang.xue@gmail.com>
- * @version $Id$
- * @package System.Web.UI.WebControls
- * @since 3.0
- */
-class TRepeaterItem extends TControl implements INamingContainer, IItemDataRenderer
-{
- /**
- * index of the data item in the Items collection of repeater
- */
- private $_itemIndex;
- /**
- * type of the TRepeaterItem
- * @var TListItemType
- */
- private $_itemType;
- /**
- * data associated with this item
- * @var mixed
- */
- private $_data;
-
- /**
- * @return TListItemType item type
- */
- public function getItemType()
- {
- return $this->_itemType;
- }
-
- /**
- * @param TListItemType item type.
- */
- public function setItemType($value)
- {
- $this->_itemType=TPropertyValue::ensureEnum($value,'TListItemType');
- }
-
- /**
- * Returns a value indicating the zero-based index of the item in the corresponding data control's item collection.
- * If the item is not in the collection (e.g. it is a header item), it returns -1.
- * @return integer zero-based index of the item.
- */
- public function getItemIndex()
- {
- return $this->_itemIndex;
- }
-
- /**
- * Sets the zero-based index for the item.
- * If the item is not in the item collection (e.g. it is a header item), -1 should be used.
- * @param integer zero-based index of the item.
- */
- public function setItemIndex($value)
- {
- $this->_itemIndex=TPropertyValue::ensureInteger($value);
- }
-
- /**
- * @return mixed data associated with the item
- * @since 3.1.0
- */
- public function getData()
- {
- return $this->_data;
- }
-
- /**
- * @param mixed data to be associated with the item
- * @since 3.1.0
- */
- public function setData($value)
- {
- $this->_data=$value;
- }
-
- /**
- * This property is deprecated since v3.1.0.
- * @return mixed data associated with the item
- * @deprecated deprecated since v3.1.0. Use {@link getData} instead.
- */
- public function getDataItem()
- {
- return $this->getData();
- }
-
- /**
- * This property is deprecated since v3.1.0.
- * @param mixed data to be associated with the item
- * @deprecated deprecated since version 3.1.0. Use {@link setData} instead.
- */
- public function setDataItem($value)
- {
- return $this->setData($value);
- }
-
- /**
- * This method overrides parent's implementation by wrapping event parameter
- * for <b>OnCommand</b> event with item information.
- * @param TControl the sender of the event
- * @param TEventParameter event parameter
- * @return boolean whether the event bubbling should stop here.
- */
- public function bubbleEvent($sender,$param)
- {
- if($param instanceof TCommandEventParameter)
- {
- $this->raiseBubbleEvent($this,new TRepeaterCommandEventParameter($this,$sender,$param));
- return true;
- }
- else
- return false;
- }
-}
-
-
-/**
- * TRepeaterItemCollection class.
- *
- * TRepeaterItemCollection represents a collection of repeater items.
- *
- * @author Qiang Xue <qiang.xue@gmail.com>
- * @version $Id$
- * @package System.Web.UI.WebControls
- * @since 3.0
- */
-class TRepeaterItemCollection extends TList
-{
- /**
- * Inserts an item at the specified position.
- * This overrides the parent implementation by inserting only objects that are descendant of {@link TControl}.
- * @param integer the speicified position.
- * @param TControl new item
- * @throws TInvalidDataTypeException if the item to be inserted is not a control.
- */
- public function insertAt($index,$item)
- {
- if($item instanceof TControl)
- parent::insertAt($index,$item);
- else
- throw new TInvalidDataTypeException('repeateritemcollection_item_invalid');
- }
-}
-
+ * @license http://www.pradosoft.com/license/
+ * @version $Id$
+ * @package System.Web.UI.WebControls
+ */
+
+/**
+ * Using TDataBoundControl and TDataFieldAccessor cass
+ */
+Prado::using('System.Web.UI.WebControls.TDataBoundControl');
+Prado::using('System.Util.TDataFieldAccessor');
+
+/**
+ * TRepeater class.
+ *
+ * TRepeater displays its content repeatedly based on the data fetched from
+ * {@link setDataSource DataSource}.
+ * The repeated contents in TRepeater are called items, which are controls and
+ * can be accessed through {@link getItems Items}. When {@link dataBind()} is invoked,
+ * TRepeater creates an item for each row of data and binds the data row to the item.
+ * Optionally, a repeater can have a header, a footer and/or separators between items.
+ *
+ * The layout of the repeated contents are specified by inline templates.
+ * Repeater items, header, footer, etc. are being instantiated with the corresponding
+ * templates when data is being bound to the repeater.
+ *
+ * Since v3.1.0, the layout can also be specified by renderers. A renderer is a control class
+ * that can be instantiated as repeater items, header, etc. A renderer can thus be viewed
+ * as an external template (in fact, it can also be non-templated controls).
+ *
+ * A renderer can be any control class.
+ * - If the class implements {@link IDataRenderer}, the <b>Data</b>
+ * property will be set as the data row during databinding. Many PRADO controls
+ * implement this interface, such as {@link TLabel}, {@link TTextBox}, etc.
+ * - If the class implements {@link IItemDataRenderer}, the <b>ItemIndex</b> property will be set
+ * as the zero-based index of the item in the repeater item collection, and
+ * the <b>ItemType</b> property as the item's type (such as TListItemType::Item).
+ * {@link TRepeaterItemRenderer} may be used as the convenient base class which
+ * already implements {@link IDataItemRenderer}.
+ *
+ * The following properties are used to specify different types of template and renderer
+ * for a repeater:
+ * - {@link setItemTemplate ItemTemplate}, {@link setItemRenderer ItemRenderer}:
+ * for each repeated row of data
+ * - {@link setAlternatingItemTemplate AlternatingItemTemplate}, {@link setAlternatingItemRenderer AlternatingItemRenderer}:
+ * for each alternating row of data. If not set, {@link setItemTemplate ItemTemplate} or {@link setItemRenderer ItemRenderer}
+ * will be used instead.
+ * - {@link setHeaderTemplate HeaderTemplate}, {@link setHeaderRenderer HeaderRenderer}:
+ * for the repeater header.
+ * - {@link setFooterTemplate FooterTemplate}, {@link setFooterRenderer FooterRenderer}:
+ * for the repeater footer.
+ * - {@link setSeparatorTemplate SeparatorTemplate}, {@link setSeparatorRenderer SeparatorRenderer}:
+ * for content to be displayed between items.
+ * - {@link setEmptyTemplate EmptyTemplate}, {@link setEmptyRenderer EmptyRenderer}:
+ * used when data bound to the repeater is empty.
+ *
+ * If a content type is defined with both a template and a renderer, the latter takes precedence.
+ *
+ * When {@link dataBind()} is being called, TRepeater undergoes the following lifecycles for each row of data:
+ * - create item based on templates or renderers
+ * - set the row of data to the item
+ * - raise {@link onItemCreated OnItemCreated}:
+ * - add the item as a child control
+ * - call dataBind() of the item
+ * - raise {@link onItemDataBound OnItemDataBound}:
+ *
+ * TRepeater raises an {@link onItemCommand OnItemCommand} whenever a button control
+ * within some repeater item raises a <b>OnCommand</b> event. Therefore,
+ * you can handle all sorts of <b>OnCommand</b> event in a central place by
+ * writing an event handler for {@link onItemCommand OnItemCommand}.
+ *
+ * When a page containing a repeater is post back, the repeater will restore automatically
+ * all its contents, including items, header, footer and separators.
+ * However, the data row associated with each item will not be recovered and become null.
+ * To access the data, use one of the following ways:
+ * - Use {@link getDataKeys DataKeys} to obtain the data key associated with
+ * the specified repeater item and use the key to fetch the corresponding data
+ * from some persistent storage such as DB.
+ * - Save the whole dataset in viewstate, which will restore the dataset automatically upon postback.
+ * Be aware though, if the size of your dataset is big, your page size will become big. Some
+ * complex data may also have serializing problem if saved in viewstate.
+ *
+ * @author Qiang Xue <qiang.xue@gmail.com>
+ * @version $Id$
+ * @package System.Web.UI.WebControls
+ * @since 3.0
+ */
+class TRepeater extends TDataBoundControl implements INamingContainer
+{
+ /**
+ * Repeater item types
+ * @deprecated deprecated since version 3.0.4. Use TListItemType constants instead.
+ */
+ const IT_HEADER='Header';
+ const IT_FOOTER='Footer';
+ const IT_ITEM='Item';
+ const IT_SEPARATOR='Separator';
+ const IT_ALTERNATINGITEM='AlternatingItem';
+
+ /**
+ * @var ITemplate template for repeater items
+ */
+ private $_itemTemplate=null;
+ /**
+ * @var ITemplate template for each alternating item
+ */
+ private $_alternatingItemTemplate=null;
+ /**
+ * @var ITemplate template for header
+ */
+ private $_headerTemplate=null;
+ /**
+ * @var ITemplate template for footer
+ */
+ private $_footerTemplate=null;
+ /**
+ * @var ITemplate template used for repeater when no data is bound
+ */
+ private $_emptyTemplate=null;
+ /**
+ * @var ITemplate template for separator
+ */
+ private $_separatorTemplate=null;
+ /**
+ * @var TRepeaterItemCollection list of repeater items
+ */
+ private $_items=null;
+ /**
+ * @var TControl header item
+ */
+ private $_header=null;
+ /**
+ * @var TControl footer item
+ */
+ private $_footer=null;
+
+
+ /**
+ * @return string the class name for repeater items. Defaults to empty, meaning not set.
+ * @since 3.1.0
+ */
+ public function getItemRenderer()
+ {
+ return $this->getViewState('ItemRenderer','');
+ }
+
+ /**
+ * Sets the item renderer class.
+ *
+ * If not empty, the class will be used to instantiate as repeater items.
+ * This property takes precedence over {@link getItemTemplate ItemTemplate}.
+ *
+ * @param string the renderer class name in namespace format.
+ * @see setItemTemplate
+ * @since 3.1.0
+ */
+ public function setItemRenderer($value)
+ {
+ $this->setViewState('ItemRenderer',$value,'');
+ }
+
+ /**
+ * @return string the class name for alternative repeater items. Defaults to empty, meaning not set.
+ * @since 3.1.0
+ */
+ public function getAlternatingItemRenderer()
+ {
+ return $this->getViewState('AlternatingItemRenderer','');
+ }
+
+ /**
+ * Sets the alternative item renderer class.
+ *
+ * If not empty, the class will be used to instantiate as alternative repeater items.
+ * This property takes precedence over {@link getAlternatingItemTemplate AlternatingItemTemplate}.
+ *
+ * @param string the renderer class name in namespace format.
+ * @see setAlternatingItemTemplate
+ * @since 3.1.0
+ */
+ public function setAlternatingItemRenderer($value)
+ {
+ $this->setViewState('AlternatingItemRenderer',$value,'');
+ }
+
+ /**
+ * @return string the class name for repeater item separators. Defaults to empty, meaning not set.
+ * @since 3.1.0
+ */
+ public function getSeparatorRenderer()
+ {
+ return $this->getViewState('SeparatorRenderer','');
+ }
+
+ /**
+ * Sets the repeater item separator renderer class.
+ *
+ * If not empty, the class will be used to instantiate as repeater item separators.
+ * This property takes precedence over {@link getSeparatorTemplate SeparatorTemplate}.
+ *
+ * @param string the renderer class name in namespace format.
+ * @see setSeparatorTemplate
+ * @since 3.1.0
+ */
+ public function setSeparatorRenderer($value)
+ {
+ $this->setViewState('SeparatorRenderer',$value,'');
+ }
+
+ /**
+ * @return string the class name for repeater header item. Defaults to empty, meaning not set.
+ * @since 3.1.0
+ */
+ public function getHeaderRenderer()
+ {
+ return $this->getViewState('HeaderRenderer','');
+ }
+
+ /**
+ * Sets the repeater header renderer class.
+ *
+ * If not empty, the class will be used to instantiate as repeater header item.
+ * This property takes precedence over {@link getHeaderTemplate HeaderTemplate}.
+ *
+ * @param string the renderer class name in namespace format.
+ * @see setHeaderTemplate
+ * @since 3.1.0
+ */
+ public function setHeaderRenderer($value)
+ {
+ $this->setViewState('HeaderRenderer',$value,'');
+ }
+
+ /**
+ * @return string the class name for repeater footer item. Defaults to empty, meaning not set.
+ * @since 3.1.0
+ */
+ public function getFooterRenderer()
+ {
+ return $this->getViewState('FooterRenderer','');
+ }
+
+ /**
+ * Sets the repeater footer renderer class.
+ *
+ * If not empty, the class will be used to instantiate as repeater footer item.
+ * This property takes precedence over {@link getFooterTemplate FooterTemplate}.
+ *
+ * @param string the renderer class name in namespace format.
+ * @see setFooterTemplate
+ * @since 3.1.0
+ */
+ public function setFooterRenderer($value)
+ {
+ $this->setViewState('FooterRenderer',$value,'');
+ }
+
+ /**
+ * @return string the class name for empty repeater item. Defaults to empty, meaning not set.
+ * @since 3.1.0
+ */
+ public function getEmptyRenderer()
+ {
+ return $this->getViewState('EmptyRenderer','');
+ }
+
+ /**
+ * Sets the repeater empty renderer class.
+ *
+ * The empty renderer is created as the child of the repeater
+ * if data bound to the repeater is empty.
+ * This property takes precedence over {@link getEmptyTemplate EmptyTemplate}.
+ *
+ * @param string the renderer class name in namespace format.
+ * @see setEmptyTemplate
+ * @since 3.1.0
+ */
+ public function setEmptyRenderer($value)
+ {
+ $this->setViewState('EmptyRenderer',$value,'');
+ }
+
+ /**
+ * @return ITemplate the template for repeater items
+ */
+ public function getItemTemplate()
+ {
+ return $this->_itemTemplate;
+ }
+
+ /**
+ * @param ITemplate the template for repeater items
+ * @throws TInvalidDataTypeException if the input is not an {@link ITemplate} or not null.
+ */
+ public function setItemTemplate($value)
+ {
+ if($value instanceof ITemplate || $value===null)
+ $this->_itemTemplate=$value;
+ else
+ throw new TInvalidDataTypeException('repeater_template_required','ItemTemplate');
+ }
+
+ /**
+ * @return ITemplate the alternative template string for the item
+ */
+ public function getAlternatingItemTemplate()
+ {
+ return $this->_alternatingItemTemplate;
+ }
+
+ /**
+ * @param ITemplate the alternative item template
+ * @throws TInvalidDataTypeException if the input is not an {@link ITemplate} or not null.
+ */
+ public function setAlternatingItemTemplate($value)
+ {
+ if($value instanceof ITemplate || $value===null)
+ $this->_alternatingItemTemplate=$value;
+ else
+ throw new TInvalidDataTypeException('repeater_template_required','AlternatingItemTemplate');
+ }
+
+ /**
+ * @return ITemplate the header template
+ */
+ public function getHeaderTemplate()
+ {
+ return $this->_headerTemplate;
+ }
+
+ /**
+ * @param ITemplate the header template
+ * @throws TInvalidDataTypeException if the input is not an {@link ITemplate} or not null.
+ */
+ public function setHeaderTemplate($value)
+ {
+ if($value instanceof ITemplate || $value===null)
+ $this->_headerTemplate=$value;
+ else
+ throw new TInvalidDataTypeException('repeater_template_required','HeaderTemplate');
+ }
+
+ /**
+ * @return ITemplate the footer template
+ */
+ public function getFooterTemplate()
+ {
+ return $this->_footerTemplate;
+ }
+
+ /**
+ * @param ITemplate the footer template
+ * @throws TInvalidDataTypeException if the input is not an {@link ITemplate} or not null.
+ */
+ public function setFooterTemplate($value)
+ {
+ if($value instanceof ITemplate || $value===null)
+ $this->_footerTemplate=$value;
+ else
+ throw new TInvalidDataTypeException('repeater_template_required','FooterTemplate');
+ }
+
+ /**
+ * @return ITemplate the template applied when no data is bound to the repeater
+ */
+ public function getEmptyTemplate()
+ {
+ return $this->_emptyTemplate;
+ }
+
+ /**
+ * @param ITemplate the template applied when no data is bound to the repeater
+ * @throws TInvalidDataTypeException if the input is not an {@link ITemplate} or not null.
+ */
+ public function setEmptyTemplate($value)
+ {
+ if($value instanceof ITemplate || $value===null)
+ $this->_emptyTemplate=$value;
+ else
+ throw new TInvalidDataTypeException('repeater_template_required','EmptyTemplate');
+ }
+
+ /**
+ * @return ITemplate the separator template
+ */
+ public function getSeparatorTemplate()
+ {
+ return $this->_separatorTemplate;
+ }
+
+ /**
+ * @param ITemplate the separator template
+ * @throws TInvalidDataTypeException if the input is not an {@link ITemplate} or not null.
+ */
+ public function setSeparatorTemplate($value)
+ {
+ if($value instanceof ITemplate || $value===null)
+ $this->_separatorTemplate=$value;
+ else
+ throw new TInvalidDataTypeException('repeater_template_required','SeparatorTemplate');
+ }
+
+ /**
+ * @return TControl the header item
+ */
+ public function getHeader()
+ {
+ return $this->_header;
+ }
+
+ /**
+ * @return TControl the footer item
+ */
+ public function getFooter()
+ {
+ return $this->_footer;
+ }
+
+ /**
+ * @return TRepeaterItemCollection list of repeater item controls
+ */
+ public function getItems()
+ {
+ if(!$this->_items)
+ $this->_items=new TRepeaterItemCollection;
+ return $this->_items;
+ }
+
+ /**
+ * @return string the field of the data source that provides the keys of the list items.
+ */
+ public function getDataKeyField()
+ {
+ return $this->getViewState('DataKeyField','');
+ }
+
+ /**
+ * @param string the field of the data source that provides the keys of the list items.
+ */
+ public function setDataKeyField($value)
+ {
+ $this->setViewState('DataKeyField',$value,'');
+ }
+
+ /**
+ * @return TList the keys used in the data listing control.
+ */
+ public function getDataKeys()
+ {
+ if(($dataKeys=$this->getViewState('DataKeys',null))===null)
+ {
+ $dataKeys=new TList;
+ $this->setViewState('DataKeys',$dataKeys,null);
+ }
+ return $dataKeys;
+ }
+
+ /**
+ * Creates a repeater item.
+ * This method invokes {@link createItem} to create a new repeater item.
+ * @param integer zero-based item index.
+ * @param TListItemType item type
+ * @return TControl the created item, null if item is not created
+ */
+ private function createItemInternal($itemIndex,$itemType)
+ {
+ if(($item=$this->createItem($itemIndex,$itemType))!==null)
+ {
+ $param=new TRepeaterItemEventParameter($item);
+ $this->onItemCreated($param);
+ $this->getControls()->add($item);
+ return $item;
+ }
+ else
+ return null;
+ }
+
+ /**
+ * Creates a repeater item and performs databinding.
+ * This method invokes {@link createItem} to create a new repeater item.
+ * @param integer zero-based item index.
+ * @param TListItemType item type
+ * @param mixed data to be associated with the item
+ * @return TControl the created item, null if item is not created
+ */
+ private function createItemWithDataInternal($itemIndex,$itemType,$dataItem)
+ {
+ if(($item=$this->createItem($itemIndex,$itemType))!==null)
+ {
+ $param=new TRepeaterItemEventParameter($item);
+ if($item instanceof IDataRenderer)
+ $item->setData($dataItem);
+ $this->onItemCreated($param);
+ $this->getControls()->add($item);
+ $item->dataBind();
+ $this->onItemDataBound($param);
+ return $item;
+ }
+ else
+ return null;
+ }
+
+ /**
+ * Creates a repeater item instance based on the item type and index.
+ * @param integer zero-based item index
+ * @param TListItemType item type
+ * @return TControl created repeater item
+ */
+ protected function createItem($itemIndex,$itemType)
+ {
+ $template=null;
+ $classPath=null;
+ switch($itemType)
+ {
+ case TListItemType::Item :
+ $classPath=$this->getItemRenderer();
+ $template=$this->_itemTemplate;
+ break;
+ case TListItemType::AlternatingItem :
+ if(($classPath=$this->getAlternatingItemRenderer())==='' && ($template=$this->_alternatingItemTemplate)===null)
+ {
+ $classPath=$this->getItemRenderer();
+ $template=$this->_itemTemplate;
+ }
+ break;
+ case TListItemType::Header :
+ $classPath=$this->getHeaderRenderer();
+ $template=$this->_headerTemplate;
+ break;
+ case TListItemType::Footer :
+ $classPath=$this->getFooterRenderer();
+ $template=$this->_footerTemplate;
+ break;
+ case TListItemType::Separator :
+ $classPath=$this->getSeparatorRenderer();
+ $template=$this->_separatorTemplate;
+ break;
+ default:
+ throw new TInvalidDataValueException('repeater_itemtype_unknown',$itemType);
+ }
+ if($classPath!=='')
+ {
+ $item=Prado::createComponent($classPath);
+ if($item instanceof IItemDataRenderer)
+ {
+ $item->setItemIndex($itemIndex);
+ $item->setItemType($itemType);
+ }
+ }
+ else if($template!==null)
+ {
+ $item=new TRepeaterItem;
+ $item->setItemIndex($itemIndex);
+ $item->setItemType($itemType);
+ $template->instantiateIn($item);
+ }
+ else
+ $item=null;
+
+ return $item;
+ }
+
+ /**
+ * Creates empty repeater content.
+ */
+ protected function createEmptyContent()
+ {
+ if(($classPath=$this->getEmptyRenderer())!=='')
+ $this->getControls()->add(Prado::createComponent($classPath));
+ else if($this->_emptyTemplate!==null)
+ $this->_emptyTemplate->instantiateIn($this);
+ }
+
+ /**
+ * Renders the repeater.
+ * This method overrides the parent implementation by rendering the body
+ * content as the whole presentation of the repeater. Outer tag is not rendered.
+ * @param THtmlWriter writer
+ */
+ public function render($writer)
+ {
+ if($this->_items && $this->_items->getCount() || $this->_emptyTemplate!==null || $this->getEmptyRenderer()!=='')
+ $this->renderContents($writer);
+ }
+
+ /**
+ * Saves item count in viewstate.
+ * This method is invoked right before control state is to be saved.
+ */
+ public function saveState()
+ {
+ parent::saveState();
+ if($this->_items)
+ $this->setViewState('ItemCount',$this->_items->getCount(),0);
+ else
+ $this->clearViewState('ItemCount');
+ }
+
+ /**
+ * Loads item count information from viewstate.
+ * This method is invoked right after control state is loaded.
+ */
+ public function loadState()
+ {
+ parent::loadState();
+ if(!$this->getIsDataBound())
+ $this->restoreItemsFromViewState();
+ $this->clearViewState('ItemCount');
+ }
+
+ /**
+ * Clears up all items in the repeater.
+ */
+ public function reset()
+ {
+ $this->getControls()->clear();
+ $this->getItems()->clear();
+ $this->_header=null;
+ $this->_footer=null;
+ }
+
+ /**
+ * Creates repeater items based on viewstate information.
+ */
+ protected function restoreItemsFromViewState()
+ {
+ $this->reset();
+ if(($itemCount=$this->getViewState('ItemCount',0))>0)
+ {
+ $items=$this->getItems();
+ $hasSeparator=$this->_separatorTemplate!==null || $this->getSeparatorRenderer()!=='';
+ $this->_header=$this->createItemInternal(-1,TListItemType::Header);
+ for($i=0;$i<$itemCount;++$i)
+ {
+ if($hasSeparator && $i>0)
+ $this->createItemInternal($i-1,TListItemType::Separator);
+ $itemType=$i%2==0?TListItemType::Item : TListItemType::AlternatingItem;
+ $items->add($this->createItemInternal($i,$itemType,false,null));
+ }
+ $this->_footer=$this->createItemInternal(-1,TListItemType::Footer);
+ }
+ else
+ $this->createEmptyContent();
+ $this->clearChildState();
+ }
+
+ /**
+ * Performs databinding to populate repeater items from data source.
+ * This method is invoked by dataBind().
+ * You may override this function to provide your own way of data population.
+ * @param Traversable the data
+ */
+ protected function performDataBinding($data)
+ {
+ $this->reset();
+
+ $keys=$this->getDataKeys();
+ $keys->clear();
+ $keyField=$this->getDataKeyField();
+
+ $items=$this->getItems();
+ $itemIndex=0;
+ $hasSeparator=$this->_separatorTemplate!==null || $this->getSeparatorRenderer()!=='';
+ foreach($data as $key=>$dataItem)
+ {
+ if($keyField!=='')
+ $keys->add($this->getDataFieldValue($dataItem,$keyField));
+ else
+ $keys->add($key);
+ if($itemIndex===0)
+ $this->_header=$this->createItemWithDataInternal(-1,TListItemType::Header,null);
+ if($hasSeparator && $itemIndex>0)
+ $this->createItemWithDataInternal($itemIndex-1,TListItemType::Separator,null);
+ $itemType=$itemIndex%2==0?TListItemType::Item : TListItemType::AlternatingItem;
+ $items->add($this->createItemWithDataInternal($itemIndex,$itemType,$dataItem));
+ $itemIndex++;
+ }
+ if($itemIndex>0)
+ $this->_footer=$this->createItemWithDataInternal(-1,TListItemType::Footer,null);
+ else
+ {
+ $this->createEmptyContent();
+ $this->dataBindChildren();
+ }
+ $this->setViewState('ItemCount',$itemIndex,0);
+ }
+
+ /**
+ * This method overrides parent's implementation to handle
+ * {@link onItemCommand OnItemCommand} event which is bubbled from
+ * repeater items and their child controls.
+ * This method should only be used by control developers.
+ * @param TControl the sender of the event
+ * @param TEventParameter event parameter
+ * @return boolean whether the event bubbling should stop here.
+ */
+ public function bubbleEvent($sender,$param)
+ {
+ if($param instanceof TRepeaterCommandEventParameter)
+ {
+ $this->onItemCommand($param);
+ return true;
+ }
+ else
+ return false;
+ }
+
+ /**
+ * Raises <b>OnItemCreated</b> event.
+ * This method is invoked after a repeater item is created and instantiated with
+ * template, but before added to the page hierarchy.
+ * The repeater item control responsible for the event
+ * can be determined from the event parameter.
+ * If you override this method, be sure to call parent's implementation
+ * so that event handlers have chance to respond to the event.
+ * @param TRepeaterItemEventParameter event parameter
+ */
+ public function onItemCreated($param)
+ {
+ $this->raiseEvent('OnItemCreated',$this,$param);
+ }
+
+ /**
+ * Raises <b>OnItemDataBound</b> event.
+ * This method is invoked right after an item is data bound.
+ * The repeater item control responsible for the event
+ * can be determined from the event parameter.
+ * If you override this method, be sure to call parent's implementation
+ * so that event handlers have chance to respond to the event.
+ * @param TRepeaterItemEventParameter event parameter
+ */
+ public function onItemDataBound($param)
+ {
+ $this->raiseEvent('OnItemDataBound',$this,$param);
+ }
+
+ /**
+ * Raises <b>OnItemCommand</b> event.
+ * This method is invoked after a button control in
+ * a template raises <b>OnCommand</b> event.
+ * The repeater control responsible for the event
+ * can be determined from the event parameter.
+ * The event parameter also contains the information about
+ * the initial sender of the <b>OnCommand</b> event, command name
+ * and command parameter.
+ * You may override this method to provide customized event handling.
+ * Be sure to call parent's implementation so that
+ * event handlers have chance to respond to the event.
+ * @param TRepeaterCommandEventParameter event parameter
+ */
+ public function onItemCommand($param)
+ {
+ $this->raiseEvent('OnItemCommand',$this,$param);
+ }
+
+ /**
+ * Returns the value of the data at the specified field.
+ * If data is an array, TMap or TList, the value will be returned at the index
+ * of the specified field. If the data is a component with a property named
+ * as the field name, the property value will be returned.
+ * Otherwise, an exception will be raised.
+ * @param mixed data item
+ * @param mixed field name
+ * @return mixed data value at the specified field
+ * @throws TInvalidDataValueException if the data is invalid
+ */
+ protected function getDataFieldValue($data,$field)
+ {
+ return TDataFieldAccessor::getDataFieldValue($data,$field);
+ }
+}
+
+/**
+ * TRepeaterItemEventParameter class
+ *
+ * TRepeaterItemEventParameter encapsulates the parameter data for
+ * {@link TRepeater::onItemCreated ItemCreated} event of {@link TRepeater} controls.
+ * The {@link getItem Item} property indicates the repeater item related with the event.
+ *
+ * @author Qiang Xue <qiang.xue@gmail.com>
+ * @version $Id$
+ * @package System.Web.UI.WebControls
+ * @since 3.0
+ */
+class TRepeaterItemEventParameter extends TEventParameter
+{
+ /**
+ * The repeater item control responsible for the event.
+ * @var TControl
+ */
+ private $_item=null;
+
+ /**
+ * Constructor.
+ * @param TControl repeater item related with the corresponding event
+ */
+ public function __construct($item)
+ {
+ $this->_item=$item;
+ }
+
+ /**
+ * @return TControl repeater item related with the corresponding event
+ */
+ public function getItem()
+ {
+ return $this->_item;
+ }
+}
+
+/**
+ * TRepeaterCommandEventParameter class
+ *
+ * TRepeaterCommandEventParameter encapsulates the parameter data for
+ * {@link TRepeater::onItemCommand ItemCommand} event of {@link TRepeater} controls.
+ *
+ * The {@link getItem Item} property indicates the repeater item related with the event.
+ * The {@link getCommandSource CommandSource} refers to the control that originally
+ * raises the Command event.
+ *
+ * @author Qiang Xue <qiang.xue@gmail.com>
+ * @version $Id$
+ * @package System.Web.UI.WebControls
+ * @since 3.0
+ */
+class TRepeaterCommandEventParameter extends TCommandEventParameter
+{
+ /**
+ * @var TControl the repeater item control responsible for the event.
+ */
+ private $_item=null;
+ /**
+ * @var TControl the control originally raises the <b>OnCommand</b> event.
+ */
+ private $_source=null;
+
+ /**
+ * Constructor.
+ * @param TControl repeater item responsible for the event
+ * @param TControl original event sender
+ * @param TCommandEventParameter original event parameter
+ */
+ public function __construct($item,$source,TCommandEventParameter $param)
+ {
+ $this->_item=$item;
+ $this->_source=$source;
+ parent::__construct($param->getCommandName(),$param->getCommandParameter());
+ }
+
+ /**
+ * @return TControl the repeater item control responsible for the event.
+ */
+ public function getItem()
+ {
+ return $this->_item;
+ }
+
+ /**
+ * @return TControl the control originally raises the <b>OnCommand</b> event.
+ */
+ public function getCommandSource()
+ {
+ return $this->_source;
+ }
+}
+
+/**
+ * TRepeaterItem class
+ *
+ * A TRepeaterItem control represents an item in the {@link TRepeater} control,
+ * such as heading section, footer section, or a data item.
+ * The index and data value of the item can be accessed via {@link getItemIndex ItemIndex}>
+ * and {@link getDataItem DataItem} properties, respectively. The type of the item
+ * is given by {@link getItemType ItemType} property.
+ *
+ * @author Qiang Xue <qiang.xue@gmail.com>
+ * @version $Id$
+ * @package System.Web.UI.WebControls
+ * @since 3.0
+ */
+class TRepeaterItem extends TControl implements INamingContainer, IItemDataRenderer
+{
+ /**
+ * index of the data item in the Items collection of repeater
+ */
+ private $_itemIndex;
+ /**
+ * type of the TRepeaterItem
+ * @var TListItemType
+ */
+ private $_itemType;
+ /**
+ * data associated with this item
+ * @var mixed
+ */
+ private $_data;
+
+ /**
+ * @return TListItemType item type
+ */
+ public function getItemType()
+ {
+ return $this->_itemType;
+ }
+
+ /**
+ * @param TListItemType item type.
+ */
+ public function setItemType($value)
+ {
+ $this->_itemType=TPropertyValue::ensureEnum($value,'TListItemType');
+ }
+
+ /**
+ * Returns a value indicating the zero-based index of the item in the corresponding data control's item collection.
+ * If the item is not in the collection (e.g. it is a header item), it returns -1.
+ * @return integer zero-based index of the item.
+ */
+ public function getItemIndex()
+ {
+ return $this->_itemIndex;
+ }
+
+ /**
+ * Sets the zero-based index for the item.
+ * If the item is not in the item collection (e.g. it is a header item), -1 should be used.
+ * @param integer zero-based index of the item.
+ */
+ public function setItemIndex($value)
+ {
+ $this->_itemIndex=TPropertyValue::ensureInteger($value);
+ }
+
+ /**
+ * @return mixed data associated with the item
+ * @since 3.1.0
+ */
+ public function getData()
+ {
+ return $this->_data;
+ }
+
+ /**
+ * @param mixed data to be associated with the item
+ * @since 3.1.0
+ */
+ public function setData($value)
+ {
+ $this->_data=$value;
+ }
+
+ /**
+ * This property is deprecated since v3.1.0.
+ * @return mixed data associated with the item
+ * @deprecated deprecated since v3.1.0. Use {@link getData} instead.
+ */
+ public function getDataItem()
+ {
+ return $this->getData();
+ }
+
+ /**
+ * This property is deprecated since v3.1.0.
+ * @param mixed data to be associated with the item
+ * @deprecated deprecated since version 3.1.0. Use {@link setData} instead.
+ */
+ public function setDataItem($value)
+ {
+ return $this->setData($value);
+ }
+
+ /**
+ * This method overrides parent's implementation by wrapping event parameter
+ * for <b>OnCommand</b> event with item information.
+ * @param TControl the sender of the event
+ * @param TEventParameter event parameter
+ * @return boolean whether the event bubbling should stop here.
+ */
+ public function bubbleEvent($sender,$param)
+ {
+ if($param instanceof TCommandEventParameter)
+ {
+ $this->raiseBubbleEvent($this,new TRepeaterCommandEventParameter($this,$sender,$param));
+ return true;
+ }
+ else
+ return false;
+ }
+}
+
+
+/**
+ * TRepeaterItemCollection class.
+ *
+ * TRepeaterItemCollection represents a collection of repeater items.
+ *
+ * @author Qiang Xue <qiang.xue@gmail.com>
+ * @version $Id$
+ * @package System.Web.UI.WebControls
+ * @since 3.0
+ */
+class TRepeaterItemCollection extends TList
+{
+ /**
+ * Inserts an item at the specified position.
+ * This overrides the parent implementation by inserting only objects that are descendant of {@link TControl}.
+ * @param integer the speicified position.
+ * @param TControl new item
+ * @throws TInvalidDataTypeException if the item to be inserted is not a control.
+ */
+ public function insertAt($index,$item)
+ {
+ if($item instanceof TControl)
+ parent::insertAt($index,$item);
+ else
+ throw new TInvalidDataTypeException('repeateritemcollection_item_invalid');
+ }
+}
+
diff --git a/framework/Web/UI/WebControls/TRepeaterItemRenderer.php b/framework/Web/UI/WebControls/TRepeaterItemRenderer.php
index 85991b38..fe5171ad 100644
--- a/framework/Web/UI/WebControls/TRepeaterItemRenderer.php
+++ b/framework/Web/UI/WebControls/TRepeaterItemRenderer.php
@@ -1,50 +1,50 @@
-<?php
-/**
- * TRepeaterItemRenderer class file
- *
- * @author Qiang Xue <qiang.xue@gmail.com>
- * @link http://www.pradosoft.com/
+<?php
+/**
+ * TRepeaterItemRenderer class file
+ *
+ * @author Qiang Xue <qiang.xue@gmail.com>
+ * @link http://www.pradosoft.com/
* @copyright Copyright &copy; 2005-2012 PradoSoft
- * @license http://www.pradosoft.com/license/
- * @version $Id$
- * @package System.Web.UI.WebControls
- */
-
-Prado::using('System.Web.UI.WebControls.TRepeater');
-Prado::using('System.Web.UI.WebControls.TItemDataRenderer');
-
-/**
- * TRepeaterItemRenderer class
- *
- * TRepeaterItemRenderer can be used as a convenient base class to
- * define an item renderer class specific for {@link TRepeater}.
- *
- * TRepeaterItemRenderer extends {@link TItemDataRenderer} and implements
- * the bubbling scheme for the OnCommand event of repeater items.
- *
- * @author Qiang Xue <qiang.xue@gmail.com>
- * @version $Id$
- * @package System.Web.UI.WebControls
- * @since 3.1.0
- */
-class TRepeaterItemRenderer extends TItemDataRenderer
-{
- /**
- * This method overrides parent's implementation by wrapping event parameter
- * for <b>OnCommand</b> event with item information.
- * @param TControl the sender of the event
- * @param TEventParameter event parameter
- * @return boolean whether the event bubbling should stop here.
- */
- public function bubbleEvent($sender,$param)
- {
- if($param instanceof TCommandEventParameter)
- {
- $this->raiseBubbleEvent($this,new TRepeaterCommandEventParameter($this,$sender,$param));
- return true;
- }
- else
- return false;
- }
-}
-
+ * @license http://www.pradosoft.com/license/
+ * @version $Id$
+ * @package System.Web.UI.WebControls
+ */
+
+Prado::using('System.Web.UI.WebControls.TRepeater');
+Prado::using('System.Web.UI.WebControls.TItemDataRenderer');
+
+/**
+ * TRepeaterItemRenderer class
+ *
+ * TRepeaterItemRenderer can be used as a convenient base class to
+ * define an item renderer class specific for {@link TRepeater}.
+ *
+ * TRepeaterItemRenderer extends {@link TItemDataRenderer} and implements
+ * the bubbling scheme for the OnCommand event of repeater items.
+ *
+ * @author Qiang Xue <qiang.xue@gmail.com>
+ * @version $Id$
+ * @package System.Web.UI.WebControls
+ * @since 3.1.0
+ */
+class TRepeaterItemRenderer extends TItemDataRenderer
+{
+ /**
+ * This method overrides parent's implementation by wrapping event parameter
+ * for <b>OnCommand</b> event with item information.
+ * @param TControl the sender of the event
+ * @param TEventParameter event parameter
+ * @return boolean whether the event bubbling should stop here.
+ */
+ public function bubbleEvent($sender,$param)
+ {
+ if($param instanceof TCommandEventParameter)
+ {
+ $this->raiseBubbleEvent($this,new TRepeaterCommandEventParameter($this,$sender,$param));
+ return true;
+ }
+ else
+ return false;
+ }
+}
+
diff --git a/framework/Web/UI/WebControls/TRequiredFieldValidator.php b/framework/Web/UI/WebControls/TRequiredFieldValidator.php
index 97555b82..89b142bf 100644
--- a/framework/Web/UI/WebControls/TRequiredFieldValidator.php
+++ b/framework/Web/UI/WebControls/TRequiredFieldValidator.php
@@ -1,138 +1,138 @@
-<?php
-/**
- * TRequiredFieldValidator class file
- *
- * @author Qiang Xue <qiang.xue@gmail.com>
- * @link http://www.pradosoft.com/
+<?php
+/**
+ * TRequiredFieldValidator class file
+ *
+ * @author Qiang Xue <qiang.xue@gmail.com>
+ * @link http://www.pradosoft.com/
* @copyright Copyright &copy; 2005-2012 PradoSoft
- * @license http://www.pradosoft.com/license/
- * @version $Id$
- * @package System.Web.UI.WebControls
- */
-
-/**
- * Using TBaseValidator class
- */
-Prado::using('System.Web.UI.WebControls.TBaseValidator');
-
-/**
- * TRequiredFieldValidator class
- *
- * TRequiredFieldValidator makes the associated input control a required field.
- * The input control fails validation if its value does not change from
- * the {@link setInitialValue InitialValue} property upon losing focus.
- *
- * Validation will also succeed if input is of TListControl type and the number
- * of selected values different from the initial value is greater than zero.
- *
- * @author Qiang Xue <qiang.xue@gmail.com>
- * @version $Id$
- * @package System.Web.UI.WebControls
- * @since 3.0
- */
-class TRequiredFieldValidator extends TBaseValidator
-{
- /**
- * Gets the name of the javascript class responsible for performing validation for this control.
- * This method overrides the parent implementation.
- * @return string the javascript class name
- */
- protected function getClientClassName()
- {
- return 'Prado.WebUI.TRequiredFieldValidator';
- }
-
- /**
- * @return string the initial value of the associated input control. Defaults to empty string.
- * If the associated input control does not change from this initial value
- * upon postback, the validation fails.
- */
- public function getInitialValue()
- {
- return $this->getViewState('InitialValue','');
- }
-
- /**
- * @param string the initial value of the associated input control.
- * If the associated input control does not change from this initial value
- * upon postback, the validation fails.
- */
- public function setInitialValue($value)
- {
- $this->setViewState('InitialValue',TPropertyValue::ensureString($value),'');
- }
-
- /**
- * This method overrides the parent's implementation.
- * The validation succeeds if the input component changes its data
- * from the {@link getInitialValue InitialValue} or the input control is not given.
- *
- * Validation will also succeed if input is of TListControl type and the
- * number of selected values different from the initial value is greater
- * than zero.
- *
- * @return boolean whether the validation succeeds
- */
- protected function evaluateIsValid()
- {
- $control = $this->getValidationTarget();
- if($control instanceof TListControl)
- return $this->validateListControl($control);
- else if($control instanceof TRadioButton && strlen($control->getGroupName()) > 0)
- return $this->validateRadioButtonGroup($control);
- else
- return $this->validateStandardControl($control);
- }
-
- private function validateListControl($control)
- {
- $initial = trim($this->getInitialValue());
- $count = 0;
- foreach($control->getItems() as $item)
- {
- if($item->getSelected() && $item->getValue() != $initial)
- $count++;
- }
- return $count > 0;
- }
-
- private function validateRadioButtonGroup($control)
- {
- $initial = trim($this->getInitialValue());
- foreach($control->getRadioButtonsInGroup() as $radio)
- {
- if($radio->getChecked())
- {
- if(strlen($value = $radio->getValue()) > 0)
- return $value !== $initial;
- else
- return true;
- }
- }
- return false;
- }
-
- private function validateStandardControl($control)
- {
- $initial = trim($this->getInitialValue());
- $value=$this->getValidationValue($control);
- return (is_bool($value) && $value) || trim($value)!==$initial;
- }
-
- /**
- * Returns an array of javascript validator options.
- * @return array javascript validator options.
- */
- protected function getClientScriptOptions()
- {
- $options = parent::getClientScriptOptions();
- $options['InitialValue']=$this->getInitialValue();
- $control = $this->getValidationTarget();
- if($control instanceof TListControl)
- $options['TotalItems'] = $control->getItemCount();
- if($control instanceof TRadioButton && strlen($control->getGroupName()) > 0)
- $options['GroupName'] = $control->getGroupName();
- return $options;
- }
-}
-
+ * @license http://www.pradosoft.com/license/
+ * @version $Id$
+ * @package System.Web.UI.WebControls
+ */
+
+/**
+ * Using TBaseValidator class
+ */
+Prado::using('System.Web.UI.WebControls.TBaseValidator');
+
+/**
+ * TRequiredFieldValidator class
+ *
+ * TRequiredFieldValidator makes the associated input control a required field.
+ * The input control fails validation if its value does not change from
+ * the {@link setInitialValue InitialValue} property upon losing focus.
+ *
+ * Validation will also succeed if input is of TListControl type and the number
+ * of selected values different from the initial value is greater than zero.
+ *
+ * @author Qiang Xue <qiang.xue@gmail.com>
+ * @version $Id$
+ * @package System.Web.UI.WebControls
+ * @since 3.0
+ */
+class TRequiredFieldValidator extends TBaseValidator
+{
+ /**
+ * Gets the name of the javascript class responsible for performing validation for this control.
+ * This method overrides the parent implementation.
+ * @return string the javascript class name
+ */
+ protected function getClientClassName()
+ {
+ return 'Prado.WebUI.TRequiredFieldValidator';
+ }
+
+ /**
+ * @return string the initial value of the associated input control. Defaults to empty string.
+ * If the associated input control does not change from this initial value
+ * upon postback, the validation fails.
+ */
+ public function getInitialValue()
+ {
+ return $this->getViewState('InitialValue','');
+ }
+
+ /**
+ * @param string the initial value of the associated input control.
+ * If the associated input control does not change from this initial value
+ * upon postback, the validation fails.
+ */
+ public function setInitialValue($value)
+ {
+ $this->setViewState('InitialValue',TPropertyValue::ensureString($value),'');
+ }
+
+ /**
+ * This method overrides the parent's implementation.
+ * The validation succeeds if the input component changes its data
+ * from the {@link getInitialValue InitialValue} or the input control is not given.
+ *
+ * Validation will also succeed if input is of TListControl type and the
+ * number of selected values different from the initial value is greater
+ * than zero.
+ *
+ * @return boolean whether the validation succeeds
+ */
+ protected function evaluateIsValid()
+ {
+ $control = $this->getValidationTarget();
+ if($control instanceof TListControl)
+ return $this->validateListControl($control);
+ else if($control instanceof TRadioButton && strlen($control->getGroupName()) > 0)
+ return $this->validateRadioButtonGroup($control);
+ else
+ return $this->validateStandardControl($control);
+ }
+
+ private function validateListControl($control)
+ {
+ $initial = trim($this->getInitialValue());
+ $count = 0;
+ foreach($control->getItems() as $item)
+ {
+ if($item->getSelected() && $item->getValue() != $initial)
+ $count++;
+ }
+ return $count > 0;
+ }
+
+ private function validateRadioButtonGroup($control)
+ {
+ $initial = trim($this->getInitialValue());
+ foreach($control->getRadioButtonsInGroup() as $radio)
+ {
+ if($radio->getChecked())
+ {
+ if(strlen($value = $radio->getValue()) > 0)
+ return $value !== $initial;
+ else
+ return true;
+ }
+ }
+ return false;
+ }
+
+ private function validateStandardControl($control)
+ {
+ $initial = trim($this->getInitialValue());
+ $value=$this->getValidationValue($control);
+ return (is_bool($value) && $value) || trim($value)!==$initial;
+ }
+
+ /**
+ * Returns an array of javascript validator options.
+ * @return array javascript validator options.
+ */
+ protected function getClientScriptOptions()
+ {
+ $options = parent::getClientScriptOptions();
+ $options['InitialValue']=$this->getInitialValue();
+ $control = $this->getValidationTarget();
+ if($control instanceof TListControl)
+ $options['TotalItems'] = $control->getItemCount();
+ if($control instanceof TRadioButton && strlen($control->getGroupName()) > 0)
+ $options['GroupName'] = $control->getGroupName();
+ return $options;
+ }
+}
+
diff --git a/framework/Web/UI/WebControls/TSafeHtml.php b/framework/Web/UI/WebControls/TSafeHtml.php
index e88277d4..1cd0a597 100644
--- a/framework/Web/UI/WebControls/TSafeHtml.php
+++ b/framework/Web/UI/WebControls/TSafeHtml.php
@@ -1,85 +1,85 @@
-<?php
-/**
- * TSafeHtml class file
- *
- * @author Wei Zhuo <weizhuo[at]gmail[dot]com>
- * @link http://www.pradosoft.com/
- * @copyright Copyright &copy; 2005-2012 PradoSoft
- * @license http://www.pradosoft.com/license/
- * @version $Id$
- * @package System.Web.UI.WebControls
- */
-
-/**
- * TSafeHtml class
- *
- * TSafeHtml is a control that strips down all potentially dangerous
- * HTML content. It is mainly a wrapper of {@link http://pear.php.net/package/SafeHTML SafeHTML}
- * project. According to the SafeHTML project, it tries to safeguard
- * the following situations when the string is to be displayed to end-users,
- * - Opening tag without its closing tag
- * - closing tag without its opening tag
- * - any of these tags: base, basefont, head, html, body, applet, object,
- * iframe, frame, frameset, script, layer, ilayer, embed, bgsound, link,
- * meta, style, title, blink, xml, etc.
- * - any of these attributes: on*, data*, dynsrc
- * - javascript:/vbscript:/about: etc. protocols
- * - expression/behavior etc. in styles
- * - any other active content.
- *
- * To use TSafeHtml, simply enclose the content to be secured within
- * the body of TSafeHtml in a template.
- *
- * If the content is encoded in UTF-7, you'll need to enable the {@link setRepackUTF7 RepackUTF7} property
- * to ensure the contents gets parsed correctly.
- *
- * @author Wei Zhuo <weizhuo[at]gmail[dot]com>
- * @version $Id$
- * @package System.Web.UI.WebControls
- * @since 3.0
- */
-class TSafeHtml extends TControl
-{
- /**
- * Sets whether to parse the contents as UTF-7. This property enables a routine
- * that repacks the content as UTF-7 before parsing it. Defaults to false.
- * @param boolean whether to parse the contents as UTF-7
- */
- public function setRepackUTF7($value)
- {
- $this->setViewState('RepackUTF7',TPropertyValue::ensureBoolean($value),false);
- }
-
- /**
- * @return boolean whether to parse the contents as UTF-7. Defaults to false.
- */
- public function getRepackUTF7()
- {
- return $this->getViewState('RepackUTF7',false);
- }
-
- /**
- * Renders body content.
- * This method overrides parent implementation by removing
- * malicious javascript code from the body content
- * @param THtmlWriter writer
- */
- public function render($writer)
- {
- $htmlWriter = Prado::createComponent($this->GetResponse()->getHtmlWriterType(), new TTextWriter());
- parent::render($htmlWriter);
- $writer->write($this->parseSafeHtml($htmlWriter->flush()));
- }
-
- /**
- * Use SafeHTML to remove malicous javascript from the HTML content.
- * @param string HTML content
- * @return string safer HTML content
- */
- protected function parseSafeHtml($text)
- {
- $renderer = Prado::createComponent('System.3rdParty.SafeHtml.TSafeHtmlParser');
- return $renderer->parse($text, $this->getRepackUTF7());
- }
-}
-
+<?php
+/**
+ * TSafeHtml class file
+ *
+ * @author Wei Zhuo <weizhuo[at]gmail[dot]com>
+ * @link http://www.pradosoft.com/
+ * @copyright Copyright &copy; 2005-2012 PradoSoft
+ * @license http://www.pradosoft.com/license/
+ * @version $Id$
+ * @package System.Web.UI.WebControls
+ */
+
+/**
+ * TSafeHtml class
+ *
+ * TSafeHtml is a control that strips down all potentially dangerous
+ * HTML content. It is mainly a wrapper of {@link http://pear.php.net/package/SafeHTML SafeHTML}
+ * project. According to the SafeHTML project, it tries to safeguard
+ * the following situations when the string is to be displayed to end-users,
+ * - Opening tag without its closing tag
+ * - closing tag without its opening tag
+ * - any of these tags: base, basefont, head, html, body, applet, object,
+ * iframe, frame, frameset, script, layer, ilayer, embed, bgsound, link,
+ * meta, style, title, blink, xml, etc.
+ * - any of these attributes: on*, data*, dynsrc
+ * - javascript:/vbscript:/about: etc. protocols
+ * - expression/behavior etc. in styles
+ * - any other active content.
+ *
+ * To use TSafeHtml, simply enclose the content to be secured within
+ * the body of TSafeHtml in a template.
+ *
+ * If the content is encoded in UTF-7, you'll need to enable the {@link setRepackUTF7 RepackUTF7} property
+ * to ensure the contents gets parsed correctly.
+ *
+ * @author Wei Zhuo <weizhuo[at]gmail[dot]com>
+ * @version $Id$
+ * @package System.Web.UI.WebControls
+ * @since 3.0
+ */
+class TSafeHtml extends TControl
+{
+ /**
+ * Sets whether to parse the contents as UTF-7. This property enables a routine
+ * that repacks the content as UTF-7 before parsing it. Defaults to false.
+ * @param boolean whether to parse the contents as UTF-7
+ */
+ public function setRepackUTF7($value)
+ {
+ $this->setViewState('RepackUTF7',TPropertyValue::ensureBoolean($value),false);
+ }
+
+ /**
+ * @return boolean whether to parse the contents as UTF-7. Defaults to false.
+ */
+ public function getRepackUTF7()
+ {
+ return $this->getViewState('RepackUTF7',false);
+ }
+
+ /**
+ * Renders body content.
+ * This method overrides parent implementation by removing
+ * malicious javascript code from the body content
+ * @param THtmlWriter writer
+ */
+ public function render($writer)
+ {
+ $htmlWriter = Prado::createComponent($this->GetResponse()->getHtmlWriterType(), new TTextWriter());
+ parent::render($htmlWriter);
+ $writer->write($this->parseSafeHtml($htmlWriter->flush()));
+ }
+
+ /**
+ * Use SafeHTML to remove malicous javascript from the HTML content.
+ * @param string HTML content
+ * @return string safer HTML content
+ */
+ protected function parseSafeHtml($text)
+ {
+ $renderer = Prado::createComponent('System.3rdParty.SafeHtml.TSafeHtmlParser');
+ return $renderer->parse($text, $this->getRepackUTF7());
+ }
+}
+
diff --git a/framework/Web/UI/WebControls/TSlider.php b/framework/Web/UI/WebControls/TSlider.php
index ce080f5f..06df52b6 100644
--- a/framework/Web/UI/WebControls/TSlider.php
+++ b/framework/Web/UI/WebControls/TSlider.php
@@ -1,574 +1,574 @@
-<?php
-/**
- * TSlider class file.
- *
- * @author Christophe Boulain <Christophe.Boulain@gmail.com>
- * @link http://www.pradosoft.com/
- * @copyright Copyright &copy; 2005-2012 PradoSoft
- * @license http://www.pradosoft.com/license/
- * @version $Id$
- * @package System.Web.UI.WebControls
- * @since 3.1.1
- */
-
-/**
- * TSlider class
- *
- * TSlider displays a slider for numeric input purpose. A slider consists of a 'track',
- * which define the range of possible value, and a 'handle' which can slide on the track, to select
- * a value in the range. The track can be either Horizontal or Vertical, depending of the {@link SetDirection Direction}
- * property. By default, it's horizontal.
- *
- * The range boundaries are defined by {@link SetMinValue MinValue} and {@link SetMaxValue MaxValue} properties.
- * The default range is from 0 to 100.
- * The {@link SetStepSize StepSize} property can be used to define the <b>step</b> between 2 values inside the range.
- * Notice that this step will be recomputed if there is more than 200 values between the range boundaries.
- * You can also provide the allowed values by setting the {@link SetValues Values} array.
- *
- * A 'Progress Indicator' can be displayed within the track with the {@link SetProgressIndicator ProgressIndicator} property.
- *
- * The TSlider control can be easily customized using CssClasses. You can provide your own css file, using the
- * {@link SetCssUrl CssUrl} property.
- * The css class for TSlider can be set by the {@link setCssClass CssClass} property. Default value is "Slider HorizontalSlider"
- * for an horizontal slider, and "Slider VerticalSlider" for a vertical one.
- *
- * If {@link SetAutoPostBack AutoPostBack} property is true, postback is sent as soon as the value changed.
- *
- * TSlider raises the {@link onValueChanged} event when the value of the slider has changed during postback.
- *
- * You can also attach ClientSide javascript events handler to the slider :
- * - ClientSide.onSlide is called when the handle is slided on the track. You can get the current value in the <b>value</b>
- * javascript variable. You can use this event to update on client side a label with the current value
- * - ClientSide.onChange is called when the slider value has changed (at the end of a move).
- *
- * @author Christophe Boulain <Christophe.Boulain@gmail.com>
- * @version $Id$
- * @package System.Web.UI.WebControls
- * @since 3.1.1
- */
-class TSlider extends TWebControl implements IPostBackDataHandler, IDataRenderer
-{
- const MAX_STEPS=200;
- /**
- * @var TSliderHandle handle component
- */
- private $_handle;
- /*
- * @var boolean Wether the data has changed during postback
- */
- private $_dataChanged=false;
- /**
- * @var TSliderClientScript Clients side javascripts
- */
- private $_clientScript=null;
-
- /**
- * @return TSliderDirection Direction of slider (Horizontal or Vertical). Defaults to Horizontal.
- */
- public function getDirection()
- {
- return $this->getViewState('Direction', TSliderDirection::Horizontal);
- }
-
- /**
- * @param TSliderDirection Direction of slider (Horizontal or Vertical)
- */
- public function setDirection($value)
- {
- $this->setViewState('Direction', TPropertyValue::ensureEnum($value,'TSliderDirection'),TSliderDirection::Horizontal);
- }
-
- /**
- * @return string URL for the CSS file including all relevant CSS class definitions. Defaults to '' (a default CSS file will be applied in this case.)
- */
- public function getCssUrl()
- {
- return $this->getViewState('CssUrl','');
- }
-
- /**
- * @param string URL for the CSS file including all relevant CSS class definitions.
- */
- public function setCssUrl($value)
- {
- $this->setViewState('CssUrl',TPropertyValue::ensureString($value),'');
- }
-
- /**
- * @return float Maximum value for the slider. Defaults to 100.0.
- */
- public function getMaxValue()
- {
- return $this->getViewState('MaxValue',100.0);
- }
-
- /**
- * @param float Maximum value for slider
- */
- public function setMaxValue($value)
- {
- $this->setViewState('MaxValue', TPropertyValue::ensureFloat($value),100.0);
- }
-
- /**
- * @return float Minimum value for slider. Defaults to 0.0.
- */
- public function getMinValue()
- {
- return $this->getViewState('MinValue',0.0);
- }
-
- /**
- * @param float Minimum value for slider
- */
- public function setMinValue($value)
- {
- $this->setViewState('MinValue', TPropertyValue::ensureFloat($value),0.0);
- }
-
- /**
- * @return float Step size. Defaults to 1.0.
- */
- public function getStepSize()
- {
- return $this->getViewState('StepSize', 1.0);
- }
-
- /**
- * Sets the step size used to determine the places where the slider handle can stop at.
- * An evenly distributed stop marks will be generated according to
- * {@link getMinValue MinValue}, {@link getMaxValue MaxValue} and StepSize.
- * To use uneven stop marks, set {@link setValues Values}.
- * @param float Step size.
- */
- public function setStepSize($value)
- {
- $this->setViewState('StepSize', $value, 1.0);
- }
-
- /**
- * @return boolean wether to display a progress indicator or not. Defaults to true.
- */
- public function getProgressIndicator ()
- {
- return $this->getViewState('ProgressIndicator', true);
- }
-
- /**
- * @param boolean wether to display a progress indicator or not. Defaults to true.
- */
- public function setProgressIndicator ($value)
- {
- $this->setViewState('ProgressIndicator', TPropertyValue::ensureBoolean($value), true);
- }
- /**
- * @return float current value of slider
- */
- public function getValue()
- {
- return $this->getViewState('Value',0.0);
- }
-
- /**
- * @param float current value of slider
- */
- public function setValue($value)
- {
- $this->setViewState('Value', TPropertyValue::ensureFloat($value),0.0);
- }
-
- /**
- * Returns the value of the TSlider control.
- * This method is required by {@link IDataRenderer}.
- * It is the same as {@link getValue()}.
- * @return string the value of the TSlider control.
- * @see getValue
- */
- public function getData()
- {
- return $this->getValue();
- }
-
- /**
- * Sets the value of the TSlider control.
- * This method is required by {@link IDataRenderer}.
- * It is the same as {@link setValue()}.
- * @param string the value of the TSlider control.
- * @see setValue
- */
- public function setData($value)
- {
- $this->setValue($value);
- }
-
- /**
- * @return array list of allowed values the slider can take. Defaults to an empty array.
- */
- public function getValues()
- {
- return $this->getViewState('Values', array());
- }
-
- /**
- * Sets the possible values that the slider can take.
- * If this is set, {@link setStepSize StepSize} will be ignored. The latter
- * generates a set of evenly distributed candidate values.
- * @param array list of allowed values the slider can take
- */
- public function setValues($value)
- {
- $this->setViewState('Values', TPropertyValue::ensureArray($value), array());
- }
-
- /**
- * @return boolean a value indicating whether an automatic postback to the server
- * will occur whenever the user modifies the slider value. Defaults to false.
- */
- public function getAutoPostBack()
- {
- return $this->getViewState('AutoPostBack',false);
- }
-
- /**
- * Sets the value indicating if postback automatically.
- * An automatic postback to the server will occur whenever the user
- * modifies the slider value.
- * @param boolean the value indicating if postback automatically
- */
- public function setAutoPostBack($value)
- {
- $this->setViewState('AutoPostBack',TPropertyValue::ensureBoolean($value),false);
- }
-
- /**
- * Gets the name of the javascript class responsible for performing postback for this control.
- * This method overrides the parent implementation.
- * @return string the javascript class name
- */
- protected function getClientClassName()
- {
- return 'Prado.WebUI.TSlider';
- }
-
- /**
- * Returns a value indicating whether postback has caused the control data change.
- * This method is required by the IPostBackDataHandler interface.
- * @return boolean whether postback has caused the control data change. False if the page is not in postback mode.
- */
- public function getDataChanged()
- {
- return $this->_dataChanged;
- }
-
- /**
- * Raises postdata changed event.
- * This method is required by {@link IPostBackDataHandler} interface.
- * It is invoked by the framework when {@link getValue Value} property
- * is changed on postback.
- * This method is primarly used by framework developers.
- */
- public function raisePostDataChangedEvent()
- {
- $this->onValueChanged(null);
- }
-
- /**
- * Raises <b>OnValueChanged</b> event.
- * This method is invoked when the {@link getValue Value}
- * property changes on postback.
- * If you override this method, be sure to call the parent implementation to ensure
- * the invocation of the attached event handlers.
- * @param TEventParameter event parameter to be passed to the event handlers
- */
- public function onValueChanged($param)
- {
- $this->raiseEvent('OnValueChanged',$this,$param);
- }
-
- /**
- * Loads user input data.
- * This method is primarly used by framework developers.
- * @param string the key that can be used to retrieve data from the input data collection
- * @param array the input data collection
- * @return boolean whether the data of the component has been changed
- */
- public function loadPostData($key,$values)
- {
- $value=(float)$values[$this->getClientID().'_1'];
- if($this->getValue()!==$value)
- {
- $this->setValue($value);
- return $this->_dataChanged=true;
- }
- else
- return false;
- }
-
- /**
- * Gets the TSliderClientScript to set the TSlider event handlers.
- *
- * The slider on the client-side supports the following events.
- * # <tt>OnSliderMove</tt> -- raised when the slider is moved.
- * # <tt>OnSliderChanged</tt> -- raised when the slider value is changed
- *
- * You can attach custom javascript code to each of these events
- *
- * @return TSliderClientScript javascript validator event options.
- */
- public function getClientSide()
- {
- if($this->_clientScript===null)
- $this->_clientScript = $this->createClientScript();
- return $this->_clientScript;
- }
-
- /**
- * @return TSliderClientScript javascript event options.
- */
- protected function createClientScript()
- {
- return new TSliderClientScript;
- }
-
- /**
- * @return string the HTML tag name for slider. Defaults to div.
- */
- public function getTagName ()
- {
- return "div";
- }
-
- /**
- * Add the specified css classes to the track
- * @param THtmlWriter writer
- */
- protected function addAttributesToRender($writer)
- {
- parent::addAttributesToRender($writer);
- $writer->addAttribute('id',$this->getClientID());
- if ($this->getCssClass()==='')
- {
- $class=($this->getDirection()==TSliderDirection::Horizontal)?'HorizontalSlider':'VerticalSlider';
- $writer->addAttribute('class', 'Slider '.$class);
- }
-
- }
-
- /**
- * Render the body content
- */
- public function renderContents($writer)
- {
- // Render the 'Track'
- $writer->addAttribute('class', 'Track');
- $writer->addAttribute('id', $this->getClientID().'_track');
- $writer->renderBeginTag('div');
- // Render the 'Progress Indicator'
- if ($this->getProgressIndicator())
- {
- $writer->addAttribute('class', 'Progress');
- $writer->addAttribute('id', $this->getClientID().'_progress');
- $writer->renderBeginTag('div');
- $writer->renderEndTag();
- }
- // Render the 'Ruler'
- /*
- * Removing for now
- $writer->addAttribute('class', 'RuleContainer');
- $writer->addAttribute('id', $this->getClientID()."_rule");
- $writer->renderBeginTag('div');
- for ($i=0;$i<=100;$i+=10)
- {
- $writer->addAttribute('class', 'RuleMark');
- $attr=($this->getDirection()===TSliderDirection::Horizontal)?"left":"top";
- $writer->addStyleAttribute($attr, $i.'%');
- $writer->renderBeginTag('div');
- $writer->renderEndTag();
- }
- $writer->renderEndTag();
- */
-
- $writer->renderEndTag();
-
- // Render the 'Handle'
- $writer->addAttribute('class', 'Handle');
- $writer->addAttribute('id', $this->getClientID().'_handle');
- $writer->renderBeginTag('div');
- $writer->renderEndTag();
- }
- /**
- * Registers CSS and JS.
- * This method is invoked right before the control rendering, if the control is visible.
- * @param mixed event parameter
- */
- public function onPreRender ($param)
- {
- parent::onPreRender($param);
- $this->registerStyleSheet();
- $this->registerSliderClientScript();
-
- }
-
- /**
- * Registers the CSS relevant to the TSlider.
- * It will register the CSS file specified by {@link getCssUrl CssUrl}.
- * If that is not set, it will use the default CSS.
- */
- protected function registerStyleSheet()
- {
- if(($url=$this->getCssUrl())==='')
- {
- $manager=$this->getApplication()->getAssetManager();
- // publish the assets
- $url=$manager->publishFilePath(dirname(__FILE__).DIRECTORY_SEPARATOR.'assets'.DIRECTORY_SEPARATOR.'TSlider');
- $url.='/TSlider.css';
- }
- $this->getPage()->getClientScript()->registerStyleSheetFile($url,$url);
- }
-
- /**
- * Registers the javascript code to initialize the slider.
- */
- protected function registerSliderClientScript()
- {
- $page=$this->getPage();
- $cs = $page->getClientScript();
- $cs->registerPradoScript("slider");
- $id=$this->getClientID();
- $cs->registerHiddenField($id.'_1',$this->getValue());
- $page->registerRequiresPostData($this);
- $cs->registerPostBackControl($this->getClientClassName(),$this->getSliderOptions());
- }
-
- /**
- * Get javascript sliderr options.
- * @return array slider client-side options
- */
- protected function getSliderOptions()
- {
- // PostBack Options :
- $options['ID'] = $this->getClientID();
- $options['EventTarget'] = $this->getUniqueID();
- $options['AutoPostBack'] = $this->getAutoPostBack();
-
- // Slider Control options
- $minValue=$this->getMinValue();
- $maxValue=$this->getMaxValue();
- $options['axis'] = strtolower($this->getDirection());
- $options['maximum'] = $maxValue;
- $options['minimum'] = $minValue;
- $options['range'] = TJavascript::quoteJsLiteral('$R('.$minValue.",".$maxValue.")");
- $options['sliderValue'] = $this->getValue();
- $options['disabled'] = !$this->getEnabled();
- $values=$this->getValues();
- if (!empty($values))
- {
- // Values are provided. Check if min/max are present in them
- if (!in_array($minValue, $values)) $values[]=$minValue;
- if (!in_array($maxValue, $values)) $values[]=$maxValue;
- // Remove all values outsize the range [min..max]
- foreach ($values as $idx=>$value)
- {
- if ($value < $minValue) unset ($values[$idx]);
- if ($value > $maxValue) unset ($values[$idx]);
- }
- }
- else
- {
- // Values are not provided, generate automatically using stepsize
- $step=$this->getStepSize();
- // We want at most self::MAX_STEPS values, so, change the step if necessary
- if (($maxValue-$minValue)/$step > self::MAX_STEPS)
- {
- $step=($maxValue-$minValue)/self::MAX_STEPS;
- }
- $values=array();
- for ($i=$minValue;$i<=$maxValue;$i+=$step)
- $values[]=$i;
- // Add max if it's not in the array because of step
- if (!in_array($maxValue, $values)) $values[]=$maxValue;
- }
- $options['values'] = $values;
- if($this->_clientScript!==null)
- $options = array_merge($options,$this->_clientScript->getOptions()->toArray());
- return $options;
- }
-}
-
-/**
- * TSliderClientScript class.
- *
- * Client-side slider events {@link setOnChange OnChange} and {@line setOnMove OnMove}
- * can be modified through the {@link TSlider:: getClientSide ClientSide}
- * property of a slider.
- *
- * The current value of the slider can be get in the 'value' js variable
- *
- * The <tt>OnMove</tt> event is raised when the slider moves
- * The <tt>OnChange</tt> event is raised when the slider value is changed (or at the end of a move)
- *
- * @author Christophe Boulain <Christophe.Boulain@gmail.com>
- * @version $Id$
- * @package System.Web.UI.WebControls
- * @since 3.1.1
- */
-class TSliderClientScript extends TClientSideOptions
-{
- /**
- * Javascript code to execute when the slider value is changed.
- * @param string javascript code
- */
- public function setOnChange($javascript)
- {
- $code=TJavascript::quoteJsLiteral("function (value) { {$javascript} }");
- $this->setFunction('onChange', $code);
- }
-
- /**
- * @return string javascript code to execute when the slider value is changed.
- */
- public function getOnChange()
- {
- return $this->getOption('onChange');
- }
-
- /* Javascript code to execute when the slider moves.
- * @param string javascript code
- */
- public function setOnSlide($javascript)
- {
- $code=TJavascript::quoteJsLiteral("function (value) { {$javascript} }");
- $this->setFunction('onSlide', $code);
- }
-
- /**
- * @return string javascript code to execute when the slider moves.
- */
- public function getOnSlide()
- {
- return $this->getOption('onSlide');
- }
-}
-
-
-/**
- * TSliderDirection class.
- *
- * TSliderDirection defines the enumerable type for the possible direction that can be used in a {@link TSlider}
- *
- * The following enumerable values are defined :
- * - Horizontal : Horizontal slider
- * - Vertical : Vertical slider
- *
- * @author Christophe Boulain <Christophe.Boulain@gmail.com>
- * @version $Id$
- * @package System.Web.UI.WebControls
- * @since 3.1.1
- */
-class TSliderDirection extends TEnumerable
-{
- const Horizontal='Horizontal';
- const Vertical='Vertical';
-}
-
-
+<?php
+/**
+ * TSlider class file.
+ *
+ * @author Christophe Boulain <Christophe.Boulain@gmail.com>
+ * @link http://www.pradosoft.com/
+ * @copyright Copyright &copy; 2005-2012 PradoSoft
+ * @license http://www.pradosoft.com/license/
+ * @version $Id$
+ * @package System.Web.UI.WebControls
+ * @since 3.1.1
+ */
+
+/**
+ * TSlider class
+ *
+ * TSlider displays a slider for numeric input purpose. A slider consists of a 'track',
+ * which define the range of possible value, and a 'handle' which can slide on the track, to select
+ * a value in the range. The track can be either Horizontal or Vertical, depending of the {@link SetDirection Direction}
+ * property. By default, it's horizontal.
+ *
+ * The range boundaries are defined by {@link SetMinValue MinValue} and {@link SetMaxValue MaxValue} properties.
+ * The default range is from 0 to 100.
+ * The {@link SetStepSize StepSize} property can be used to define the <b>step</b> between 2 values inside the range.
+ * Notice that this step will be recomputed if there is more than 200 values between the range boundaries.
+ * You can also provide the allowed values by setting the {@link SetValues Values} array.
+ *
+ * A 'Progress Indicator' can be displayed within the track with the {@link SetProgressIndicator ProgressIndicator} property.
+ *
+ * The TSlider control can be easily customized using CssClasses. You can provide your own css file, using the
+ * {@link SetCssUrl CssUrl} property.
+ * The css class for TSlider can be set by the {@link setCssClass CssClass} property. Default value is "Slider HorizontalSlider"
+ * for an horizontal slider, and "Slider VerticalSlider" for a vertical one.
+ *
+ * If {@link SetAutoPostBack AutoPostBack} property is true, postback is sent as soon as the value changed.
+ *
+ * TSlider raises the {@link onValueChanged} event when the value of the slider has changed during postback.
+ *
+ * You can also attach ClientSide javascript events handler to the slider :
+ * - ClientSide.onSlide is called when the handle is slided on the track. You can get the current value in the <b>value</b>
+ * javascript variable. You can use this event to update on client side a label with the current value
+ * - ClientSide.onChange is called when the slider value has changed (at the end of a move).
+ *
+ * @author Christophe Boulain <Christophe.Boulain@gmail.com>
+ * @version $Id$
+ * @package System.Web.UI.WebControls
+ * @since 3.1.1
+ */
+class TSlider extends TWebControl implements IPostBackDataHandler, IDataRenderer
+{
+ const MAX_STEPS=200;
+ /**
+ * @var TSliderHandle handle component
+ */
+ private $_handle;
+ /*
+ * @var boolean Wether the data has changed during postback
+ */
+ private $_dataChanged=false;
+ /**
+ * @var TSliderClientScript Clients side javascripts
+ */
+ private $_clientScript=null;
+
+ /**
+ * @return TSliderDirection Direction of slider (Horizontal or Vertical). Defaults to Horizontal.
+ */
+ public function getDirection()
+ {
+ return $this->getViewState('Direction', TSliderDirection::Horizontal);
+ }
+
+ /**
+ * @param TSliderDirection Direction of slider (Horizontal or Vertical)
+ */
+ public function setDirection($value)
+ {
+ $this->setViewState('Direction', TPropertyValue::ensureEnum($value,'TSliderDirection'),TSliderDirection::Horizontal);
+ }
+
+ /**
+ * @return string URL for the CSS file including all relevant CSS class definitions. Defaults to '' (a default CSS file will be applied in this case.)
+ */
+ public function getCssUrl()
+ {
+ return $this->getViewState('CssUrl','');
+ }
+
+ /**
+ * @param string URL for the CSS file including all relevant CSS class definitions.
+ */
+ public function setCssUrl($value)
+ {
+ $this->setViewState('CssUrl',TPropertyValue::ensureString($value),'');
+ }
+
+ /**
+ * @return float Maximum value for the slider. Defaults to 100.0.
+ */
+ public function getMaxValue()
+ {
+ return $this->getViewState('MaxValue',100.0);
+ }
+
+ /**
+ * @param float Maximum value for slider
+ */
+ public function setMaxValue($value)
+ {
+ $this->setViewState('MaxValue', TPropertyValue::ensureFloat($value),100.0);
+ }
+
+ /**
+ * @return float Minimum value for slider. Defaults to 0.0.
+ */
+ public function getMinValue()
+ {
+ return $this->getViewState('MinValue',0.0);
+ }
+
+ /**
+ * @param float Minimum value for slider
+ */
+ public function setMinValue($value)
+ {
+ $this->setViewState('MinValue', TPropertyValue::ensureFloat($value),0.0);
+ }
+
+ /**
+ * @return float Step size. Defaults to 1.0.
+ */
+ public function getStepSize()
+ {
+ return $this->getViewState('StepSize', 1.0);
+ }
+
+ /**
+ * Sets the step size used to determine the places where the slider handle can stop at.
+ * An evenly distributed stop marks will be generated according to
+ * {@link getMinValue MinValue}, {@link getMaxValue MaxValue} and StepSize.
+ * To use uneven stop marks, set {@link setValues Values}.
+ * @param float Step size.
+ */
+ public function setStepSize($value)
+ {
+ $this->setViewState('StepSize', $value, 1.0);
+ }
+
+ /**
+ * @return boolean wether to display a progress indicator or not. Defaults to true.
+ */
+ public function getProgressIndicator ()
+ {
+ return $this->getViewState('ProgressIndicator', true);
+ }
+
+ /**
+ * @param boolean wether to display a progress indicator or not. Defaults to true.
+ */
+ public function setProgressIndicator ($value)
+ {
+ $this->setViewState('ProgressIndicator', TPropertyValue::ensureBoolean($value), true);
+ }
+ /**
+ * @return float current value of slider
+ */
+ public function getValue()
+ {
+ return $this->getViewState('Value',0.0);
+ }
+
+ /**
+ * @param float current value of slider
+ */
+ public function setValue($value)
+ {
+ $this->setViewState('Value', TPropertyValue::ensureFloat($value),0.0);
+ }
+
+ /**
+ * Returns the value of the TSlider control.
+ * This method is required by {@link IDataRenderer}.
+ * It is the same as {@link getValue()}.
+ * @return string the value of the TSlider control.
+ * @see getValue
+ */
+ public function getData()
+ {
+ return $this->getValue();
+ }
+
+ /**
+ * Sets the value of the TSlider control.
+ * This method is required by {@link IDataRenderer}.
+ * It is the same as {@link setValue()}.
+ * @param string the value of the TSlider control.
+ * @see setValue
+ */
+ public function setData($value)
+ {
+ $this->setValue($value);
+ }
+
+ /**
+ * @return array list of allowed values the slider can take. Defaults to an empty array.
+ */
+ public function getValues()
+ {
+ return $this->getViewState('Values', array());
+ }
+
+ /**
+ * Sets the possible values that the slider can take.
+ * If this is set, {@link setStepSize StepSize} will be ignored. The latter
+ * generates a set of evenly distributed candidate values.
+ * @param array list of allowed values the slider can take
+ */
+ public function setValues($value)
+ {
+ $this->setViewState('Values', TPropertyValue::ensureArray($value), array());
+ }
+
+ /**
+ * @return boolean a value indicating whether an automatic postback to the server
+ * will occur whenever the user modifies the slider value. Defaults to false.
+ */
+ public function getAutoPostBack()
+ {
+ return $this->getViewState('AutoPostBack',false);
+ }
+
+ /**
+ * Sets the value indicating if postback automatically.
+ * An automatic postback to the server will occur whenever the user
+ * modifies the slider value.
+ * @param boolean the value indicating if postback automatically
+ */
+ public function setAutoPostBack($value)
+ {
+ $this->setViewState('AutoPostBack',TPropertyValue::ensureBoolean($value),false);
+ }
+
+ /**
+ * Gets the name of the javascript class responsible for performing postback for this control.
+ * This method overrides the parent implementation.
+ * @return string the javascript class name
+ */
+ protected function getClientClassName()
+ {
+ return 'Prado.WebUI.TSlider';
+ }
+
+ /**
+ * Returns a value indicating whether postback has caused the control data change.
+ * This method is required by the IPostBackDataHandler interface.
+ * @return boolean whether postback has caused the control data change. False if the page is not in postback mode.
+ */
+ public function getDataChanged()
+ {
+ return $this->_dataChanged;
+ }
+
+ /**
+ * Raises postdata changed event.
+ * This method is required by {@link IPostBackDataHandler} interface.
+ * It is invoked by the framework when {@link getValue Value} property
+ * is changed on postback.
+ * This method is primarly used by framework developers.
+ */
+ public function raisePostDataChangedEvent()
+ {
+ $this->onValueChanged(null);
+ }
+
+ /**
+ * Raises <b>OnValueChanged</b> event.
+ * This method is invoked when the {@link getValue Value}
+ * property changes on postback.
+ * If you override this method, be sure to call the parent implementation to ensure
+ * the invocation of the attached event handlers.
+ * @param TEventParameter event parameter to be passed to the event handlers
+ */
+ public function onValueChanged($param)
+ {
+ $this->raiseEvent('OnValueChanged',$this,$param);
+ }
+
+ /**
+ * Loads user input data.
+ * This method is primarly used by framework developers.
+ * @param string the key that can be used to retrieve data from the input data collection
+ * @param array the input data collection
+ * @return boolean whether the data of the component has been changed
+ */
+ public function loadPostData($key,$values)
+ {
+ $value=(float)$values[$this->getClientID().'_1'];
+ if($this->getValue()!==$value)
+ {
+ $this->setValue($value);
+ return $this->_dataChanged=true;
+ }
+ else
+ return false;
+ }
+
+ /**
+ * Gets the TSliderClientScript to set the TSlider event handlers.
+ *
+ * The slider on the client-side supports the following events.
+ * # <tt>OnSliderMove</tt> -- raised when the slider is moved.
+ * # <tt>OnSliderChanged</tt> -- raised when the slider value is changed
+ *
+ * You can attach custom javascript code to each of these events
+ *
+ * @return TSliderClientScript javascript validator event options.
+ */
+ public function getClientSide()
+ {
+ if($this->_clientScript===null)
+ $this->_clientScript = $this->createClientScript();
+ return $this->_clientScript;
+ }
+
+ /**
+ * @return TSliderClientScript javascript event options.
+ */
+ protected function createClientScript()
+ {
+ return new TSliderClientScript;
+ }
+
+ /**
+ * @return string the HTML tag name for slider. Defaults to div.
+ */
+ public function getTagName ()
+ {
+ return "div";
+ }
+
+ /**
+ * Add the specified css classes to the track
+ * @param THtmlWriter writer
+ */
+ protected function addAttributesToRender($writer)
+ {
+ parent::addAttributesToRender($writer);
+ $writer->addAttribute('id',$this->getClientID());
+ if ($this->getCssClass()==='')
+ {
+ $class=($this->getDirection()==TSliderDirection::Horizontal)?'HorizontalSlider':'VerticalSlider';
+ $writer->addAttribute('class', 'Slider '.$class);
+ }
+
+ }
+
+ /**
+ * Render the body content
+ */
+ public function renderContents($writer)
+ {
+ // Render the 'Track'
+ $writer->addAttribute('class', 'Track');
+ $writer->addAttribute('id', $this->getClientID().'_track');
+ $writer->renderBeginTag('div');
+ // Render the 'Progress Indicator'
+ if ($this->getProgressIndicator())
+ {
+ $writer->addAttribute('class', 'Progress');
+ $writer->addAttribute('id', $this->getClientID().'_progress');
+ $writer->renderBeginTag('div');
+ $writer->renderEndTag();
+ }
+ // Render the 'Ruler'
+ /*
+ * Removing for now
+ $writer->addAttribute('class', 'RuleContainer');
+ $writer->addAttribute('id', $this->getClientID()."_rule");
+ $writer->renderBeginTag('div');
+ for ($i=0;$i<=100;$i+=10)
+ {
+ $writer->addAttribute('class', 'RuleMark');
+ $attr=($this->getDirection()===TSliderDirection::Horizontal)?"left":"top";
+ $writer->addStyleAttribute($attr, $i.'%');
+ $writer->renderBeginTag('div');
+ $writer->renderEndTag();
+ }
+ $writer->renderEndTag();
+ */
+
+ $writer->renderEndTag();
+
+ // Render the 'Handle'
+ $writer->addAttribute('class', 'Handle');
+ $writer->addAttribute('id', $this->getClientID().'_handle');
+ $writer->renderBeginTag('div');
+ $writer->renderEndTag();
+ }
+ /**
+ * Registers CSS and JS.
+ * This method is invoked right before the control rendering, if the control is visible.
+ * @param mixed event parameter
+ */
+ public function onPreRender ($param)
+ {
+ parent::onPreRender($param);
+ $this->registerStyleSheet();
+ $this->registerSliderClientScript();
+
+ }
+
+ /**
+ * Registers the CSS relevant to the TSlider.
+ * It will register the CSS file specified by {@link getCssUrl CssUrl}.
+ * If that is not set, it will use the default CSS.
+ */
+ protected function registerStyleSheet()
+ {
+ if(($url=$this->getCssUrl())==='')
+ {
+ $manager=$this->getApplication()->getAssetManager();
+ // publish the assets
+ $url=$manager->publishFilePath(dirname(__FILE__).DIRECTORY_SEPARATOR.'assets'.DIRECTORY_SEPARATOR.'TSlider');
+ $url.='/TSlider.css';
+ }
+ $this->getPage()->getClientScript()->registerStyleSheetFile($url,$url);
+ }
+
+ /**
+ * Registers the javascript code to initialize the slider.
+ */
+ protected function registerSliderClientScript()
+ {
+ $page=$this->getPage();
+ $cs = $page->getClientScript();
+ $cs->registerPradoScript("slider");
+ $id=$this->getClientID();
+ $cs->registerHiddenField($id.'_1',$this->getValue());
+ $page->registerRequiresPostData($this);
+ $cs->registerPostBackControl($this->getClientClassName(),$this->getSliderOptions());
+ }
+
+ /**
+ * Get javascript sliderr options.
+ * @return array slider client-side options
+ */
+ protected function getSliderOptions()
+ {
+ // PostBack Options :
+ $options['ID'] = $this->getClientID();
+ $options['EventTarget'] = $this->getUniqueID();
+ $options['AutoPostBack'] = $this->getAutoPostBack();
+
+ // Slider Control options
+ $minValue=$this->getMinValue();
+ $maxValue=$this->getMaxValue();
+ $options['axis'] = strtolower($this->getDirection());
+ $options['maximum'] = $maxValue;
+ $options['minimum'] = $minValue;
+ $options['range'] = TJavascript::quoteJsLiteral('$R('.$minValue.",".$maxValue.")");
+ $options['sliderValue'] = $this->getValue();
+ $options['disabled'] = !$this->getEnabled();
+ $values=$this->getValues();
+ if (!empty($values))
+ {
+ // Values are provided. Check if min/max are present in them
+ if (!in_array($minValue, $values)) $values[]=$minValue;
+ if (!in_array($maxValue, $values)) $values[]=$maxValue;
+ // Remove all values outsize the range [min..max]
+ foreach ($values as $idx=>$value)
+ {
+ if ($value < $minValue) unset ($values[$idx]);
+ if ($value > $maxValue) unset ($values[$idx]);
+ }
+ }
+ else
+ {
+ // Values are not provided, generate automatically using stepsize
+ $step=$this->getStepSize();
+ // We want at most self::MAX_STEPS values, so, change the step if necessary
+ if (($maxValue-$minValue)/$step > self::MAX_STEPS)
+ {
+ $step=($maxValue-$minValue)/self::MAX_STEPS;
+ }
+ $values=array();
+ for ($i=$minValue;$i<=$maxValue;$i+=$step)
+ $values[]=$i;
+ // Add max if it's not in the array because of step
+ if (!in_array($maxValue, $values)) $values[]=$maxValue;
+ }
+ $options['values'] = $values;
+ if($this->_clientScript!==null)
+ $options = array_merge($options,$this->_clientScript->getOptions()->toArray());
+ return $options;
+ }
+}
+
+/**
+ * TSliderClientScript class.
+ *
+ * Client-side slider events {@link setOnChange OnChange} and {@line setOnMove OnMove}
+ * can be modified through the {@link TSlider:: getClientSide ClientSide}
+ * property of a slider.
+ *
+ * The current value of the slider can be get in the 'value' js variable
+ *
+ * The <tt>OnMove</tt> event is raised when the slider moves
+ * The <tt>OnChange</tt> event is raised when the slider value is changed (or at the end of a move)
+ *
+ * @author Christophe Boulain <Christophe.Boulain@gmail.com>
+ * @version $Id$
+ * @package System.Web.UI.WebControls
+ * @since 3.1.1
+ */
+class TSliderClientScript extends TClientSideOptions
+{
+ /**
+ * Javascript code to execute when the slider value is changed.
+ * @param string javascript code
+ */
+ public function setOnChange($javascript)
+ {
+ $code=TJavascript::quoteJsLiteral("function (value) { {$javascript} }");
+ $this->setFunction('onChange', $code);
+ }
+
+ /**
+ * @return string javascript code to execute when the slider value is changed.
+ */
+ public function getOnChange()
+ {
+ return $this->getOption('onChange');
+ }
+
+ /* Javascript code to execute when the slider moves.
+ * @param string javascript code
+ */
+ public function setOnSlide($javascript)
+ {
+ $code=TJavascript::quoteJsLiteral("function (value) { {$javascript} }");
+ $this->setFunction('onSlide', $code);
+ }
+
+ /**
+ * @return string javascript code to execute when the slider moves.
+ */
+ public function getOnSlide()
+ {
+ return $this->getOption('onSlide');
+ }
+}
+
+
+/**
+ * TSliderDirection class.
+ *
+ * TSliderDirection defines the enumerable type for the possible direction that can be used in a {@link TSlider}
+ *
+ * The following enumerable values are defined :
+ * - Horizontal : Horizontal slider
+ * - Vertical : Vertical slider
+ *
+ * @author Christophe Boulain <Christophe.Boulain@gmail.com>
+ * @version $Id$
+ * @package System.Web.UI.WebControls
+ * @since 3.1.1
+ */
+class TSliderDirection extends TEnumerable
+{
+ const Horizontal='Horizontal';
+ const Vertical='Vertical';
+}
+
+
diff --git a/framework/Web/UI/WebControls/TStatements.php b/framework/Web/UI/WebControls/TStatements.php
index c3f43278..dd7631e2 100644
--- a/framework/Web/UI/WebControls/TStatements.php
+++ b/framework/Web/UI/WebControls/TStatements.php
@@ -1,63 +1,63 @@
-<?php
-/**
- * TStatements class file
- *
- * @author Qiang Xue <qiang.xue@gmail.com>
- * @link http://www.pradosoft.com/
+<?php
+/**
+ * TStatements class file
+ *
+ * @author Qiang Xue <qiang.xue@gmail.com>
+ * @link http://www.pradosoft.com/
* @copyright Copyright &copy; 2005-2012 PradoSoft
- * @license http://www.pradosoft.com/license/
- * @version $Id$
- * @package System.Web.UI.WebControls
- */
-
-/**
- * TStatements class
- *
- * TStatements executes one or several PHP statements and renders the display
- * generated during the execution. The execution happens during the rendering stage.
- * The PHP statements being executed can be set via the property
- * {@link setStatements Statements}. The context of the statemenets executed
- * is the TStatements object itself.
- *
- * Note, since TStatements allows execution of arbitrary PHP statements,
- * make sure {@link setStatements Statements} does not come directly from user input.
- *
- * @author Qiang Xue <qiang.xue@gmail.com>
- * @version $Id$
- * @package System.Web.UI.WebControls
- * @since 3.0
- */
-class TStatements extends TControl
-{
- /**
- * @var string PHP statements
- */
- private $_s='';
-
- /**
- * @return string the statements to be executed
- */
- public function getStatements()
- {
- return $this->_s;
- }
-
- /**
- * @param string the PHP statements to be executed
- */
- public function setStatements($value)
- {
- $this->_s=$value;
- }
-
- /**
- * Renders the evaluation result of the statements.
- * @param THtmlWriter the writer used for the rendering purpose
- */
- public function render($writer)
- {
- if($this->_s!=='')
- $writer->write($this->evaluateStatements($this->_s));
- }
-}
-
+ * @license http://www.pradosoft.com/license/
+ * @version $Id$
+ * @package System.Web.UI.WebControls
+ */
+
+/**
+ * TStatements class
+ *
+ * TStatements executes one or several PHP statements and renders the display
+ * generated during the execution. The execution happens during the rendering stage.
+ * The PHP statements being executed can be set via the property
+ * {@link setStatements Statements}. The context of the statemenets executed
+ * is the TStatements object itself.
+ *
+ * Note, since TStatements allows execution of arbitrary PHP statements,
+ * make sure {@link setStatements Statements} does not come directly from user input.
+ *
+ * @author Qiang Xue <qiang.xue@gmail.com>
+ * @version $Id$
+ * @package System.Web.UI.WebControls
+ * @since 3.0
+ */
+class TStatements extends TControl
+{
+ /**
+ * @var string PHP statements
+ */
+ private $_s='';
+
+ /**
+ * @return string the statements to be executed
+ */
+ public function getStatements()
+ {
+ return $this->_s;
+ }
+
+ /**
+ * @param string the PHP statements to be executed
+ */
+ public function setStatements($value)
+ {
+ $this->_s=$value;
+ }
+
+ /**
+ * Renders the evaluation result of the statements.
+ * @param THtmlWriter the writer used for the rendering purpose
+ */
+ public function render($writer)
+ {
+ if($this->_s!=='')
+ $writer->write($this->evaluateStatements($this->_s));
+ }
+}
+
diff --git a/framework/Web/UI/WebControls/TStyle.php b/framework/Web/UI/WebControls/TStyle.php
index 58be223a..93f7d45d 100644
--- a/framework/Web/UI/WebControls/TStyle.php
+++ b/framework/Web/UI/WebControls/TStyle.php
@@ -1,893 +1,893 @@
-<?php
-/**
- * TStyle class file.
- *
- * @author Qiang Xue <qiang.xue@gmail.com>
- * @link http://www.pradosoft.com/
- * @copyright Copyright &copy; 2005-2012 PradoSoft
- * @license http://www.pradosoft.com/license/
- * @version $Id$
- * @package System.Web.UI.WebControls
- */
-
-/**
- * Includes TFont definition
- */
-Prado::using('System.Web.UI.WebControls.TFont');
-
-/**
- * TStyle class
- *
- * TStyle encapsulates the CSS style applied to a control.
- *
- * @author Qiang Xue <qiang.xue@gmail.com>
- * @version $Id$
- * @package System.Web.UI.WebControls
- * @since 3.0
- */
-class TStyle extends TComponent
-{
- /**
- * @var array storage of CSS fields
- */
- private $_fields=array();
- /**
- * @var TFont font object
- */
- private $_font=null;
- /**
- * @var string CSS class name
- */
- private $_class=null;
- /**
- * @var string CSS style string (those not represented by specific fields of TStyle)
- */
- private $_customStyle=null;
- /**
- * @var string display style
- */
- private $_displayStyle='Fixed';
-
- /**
- * Constructor.
- * @param TStyle style to copy from
- */
- public function __construct($style=null)
- {
- if($style!==null)
- $this->copyFrom($style);
- }
-
- /**
- * Need to clone the font object.
- */
- public function __clone()
- {
- if($this->_font!==null)
- $this->_font = clone($this->_font);
- }
-
- /**
- * @return string the background color of the control
- */
- public function getBackColor()
- {
- return isset($this->_fields['background-color'])?$this->_fields['background-color']:'';
- }
-
- /**
- * @param string the background color of the control
- */
- public function setBackColor($value)
- {
- if(trim($value)==='')
- unset($this->_fields['background-color']);
- else
- $this->_fields['background-color']=$value;
- }
-
- /**
- * @return string the border color of the control
- */
- public function getBorderColor()
- {
- return isset($this->_fields['border-color'])?$this->_fields['border-color']:'';
- }
-
- /**
- * @param string the border color of the control
- */
- public function setBorderColor($value)
- {
- if(trim($value)==='')
- unset($this->_fields['border-color']);
- else
- $this->_fields['border-color']=$value;
- }
-
- /**
- * @return string the border style of the control
- */
- public function getBorderStyle()
- {
- return isset($this->_fields['border-style'])?$this->_fields['border-style']:'';
- }
-
- /**
- * Sets the border style of the control.
- * @param string the border style of the control
- */
- public function setBorderStyle($value)
- {
- if(trim($value)==='')
- unset($this->_fields['border-style']);
- else
- $this->_fields['border-style']=$value;
- }
-
- /**
- * @return string the border width of the control
- */
- public function getBorderWidth()
- {
- return isset($this->_fields['border-width'])?$this->_fields['border-width']:'';
- }
-
- /**
- * @param string the border width of the control
- */
- public function setBorderWidth($value)
- {
- if(trim($value)==='')
- unset($this->_fields['border-width']);
- else
- $this->_fields['border-width']=$value;
- }
-
- /**
- * @return string the CSS class of the control
- */
- public function getCssClass()
- {
- return $this->_class===null?'':$this->_class;
- }
-
- /**
- * @return boolean true if CSS is set or empty.
- */
- public function hasCssClass()
- {
- return ($this->_class!==null);
- }
-
- /**
- * @param string the name of the CSS class of the control
- */
- public function setCssClass($value)
- {
- $this->_class=$value;
- }
-
- /**
- * @return TFont the font of the control
- */
- public function getFont()
- {
- if($this->_font===null)
- $this->_font=new TFont;
- return $this->_font;
- }
-
- /**
- * @return boolean true if font is set.
- */
- public function hasFont()
- {
- return $this->_font !== null;
- }
-
- /**
- * @param TDisplayStyle control display style, default is TDisplayStyle::Fixed
- */
- public function setDisplayStyle($value)
- {
- $this->_displayStyle = TPropertyValue::ensureEnum($value, 'TDisplayStyle');
- switch($this->_displayStyle)
- {
- case TDisplayStyle::None:
- $this->_fields['display'] = 'none';
- break;
- case TDisplayStyle::Dynamic:
- $this->_fields['display'] = ''; //remove the display property
- break;
- case TDisplayStyle::Fixed:
- $this->_fields['visibility'] = 'visible';
- break;
- case TDisplayStyle::Hidden:
- $this->_fields['visibility'] = 'hidden';
- break;
- }
- }
-
- /**
- * @return TDisplayStyle display style
- */
- public function getDisplayStyle()
- {
- return $this->_displayStyle;
- }
-
- /**
- * @return string the foreground color of the control
- */
- public function getForeColor()
- {
- return isset($this->_fields['color'])?$this->_fields['color']:'';
- }
-
- /**
- * @param string the foreground color of the control
- */
- public function setForeColor($value)
- {
- if(trim($value)==='')
- unset($this->_fields['color']);
- else
- $this->_fields['color']=$value;
- }
-
- /**
- * @return string the height of the control
- */
- public function getHeight()
- {
- return isset($this->_fields['height'])?$this->_fields['height']:'';
- }
-
- /**
- * @param string the height of the control
- */
- public function setHeight($value)
- {
- if(trim($value)==='')
- unset($this->_fields['height']);
- else
- $this->_fields['height']=$value;
- }
-
- /**
- * @return string the custom style of the control
- */
- public function getCustomStyle()
- {
- return $this->_customStyle===null?'':$this->_customStyle;
- }
-
- /**
- * Sets custom style fields from a string.
- * Custom style fields will be overwritten by style fields explicitly defined.
- * @param string the custom style of the control
- */
- public function setCustomStyle($value)
- {
- $this->_customStyle=$value;
- }
-
- /**
- * @return string a single style field value set via {@link setStyleField}. Defaults to empty string.
- */
- public function getStyleField($name)
- {
- return isset($this->_fields[$name])?$this->_fields[$name]:'';
- }
-
- /**
- * Sets a single style field value.
- * Style fields set by this method will overwrite those set by {@link setCustomStyle}.
- * @param string style field name
- * @param string style field value
- */
- public function setStyleField($name,$value)
- {
- $this->_fields[$name]=$value;
- }
-
- /**
- * Clears a single style field value;
- * @param string style field name
- */
- public function clearStyleField($name)
- {
- unset($this->_fields[$name]);
- }
-
- /**
- * @return boolean whether a style field has been defined by {@link setStyleField}
- */
- public function hasStyleField($name)
- {
- return isset($this->_fields[$name]);
- }
-
- /**
- * @return string the width of the control
- */
- public function getWidth()
- {
- return isset($this->_fields['width'])?$this->_fields['width']:'';
- }
-
- /**
- * @param string the width of the control
- */
- public function setWidth($value)
- {
- $this->_fields['width']=$value;
- }
-
- /**
- * Resets the style to the original empty state.
- */
- public function reset()
- {
- $this->_fields=array();
- $this->_font=null;
- $this->_class=null;
- $this->_customStyle=null;
- }
-
- /**
- * Copies the fields in a new style to this style.
- * If a style field is set in the new style, the corresponding field
- * in this style will be overwritten.
- * @param TStyle the new style
- */
- public function copyFrom($style)
- {
- if($style instanceof TStyle)
- {
- $this->_fields=array_merge($this->_fields,$style->_fields);
- if($style->_class!==null)
- $this->_class=$style->_class;
- if($style->_customStyle!==null)
- $this->_customStyle=$style->_customStyle;
- if($style->_font!==null)
- $this->getFont()->copyFrom($style->_font);
- }
- }
-
- /**
- * Merges the style with a new one.
- * If a style field is not set in this style, it will be overwritten by
- * the new one.
- * @param TStyle the new style
- */
- public function mergeWith($style)
- {
- if($style instanceof TStyle)
- {
- $this->_fields=array_merge($style->_fields,$this->_fields);
- if($this->_class===null)
- $this->_class=$style->_class;
- if($this->_customStyle===null)
- $this->_customStyle=$style->_customStyle;
- if($style->_font!==null)
- $this->getFont()->mergeWith($style->_font);
- }
- }
-
- /**
- * Adds attributes related to CSS styles to renderer.
- * @param THtmlWriter the writer used for the rendering purpose
- */
- public function addAttributesToRender($writer)
- {
- if($this->_customStyle!==null)
- {
- foreach(explode(';',$this->_customStyle) as $style)
- {
- $arr=explode(':',$style,2);
- if(isset($arr[1]) && trim($arr[0])!=='')
- $writer->addStyleAttribute(trim($arr[0]),trim($arr[1]));
- }
- }
- $writer->addStyleAttributes($this->_fields);
- if($this->_font!==null)
- $this->_font->addAttributesToRender($writer);
- if($this->_class!==null)
- $writer->addAttribute('class',$this->_class);
- }
-
- /**
- * @return array list of style fields.
- */
- public function getStyleFields()
- {
- return $this->_fields;
- }
-}
-
-/**
- * TDisplayStyle defines the enumerable type for the possible styles
- * that a web control can display.
- *
- * The following enumerable values are defined:
- * - None: the control is not displayed and not included in the layout.
- * - Dynamic: the control is displayed and included in the layout, the layout flow is dependent on the control (equivalent to display:'' in css).
- * - Fixed: Similar to Dynamic with CSS "visibility" set "shown".
- * - Hidden: the control is not displayed and is included in the layout.
- *
- * @author Wei Zhuo <weizhuo[at]gmail[dot]com>
- * @version $Id$
- * @package System.Web.UI.WebControls
- * @since 3.1
- */
-class TDisplayStyle extends TEnumerable
-{
- const None='None';
- const Dynamic='Dynamic';
- const Fixed='Fixed';
- const Hidden='Hidden';
-}
-
-/**
- * TTableStyle class.
- * TTableStyle represents the CSS style specific for HTML table.
- *
- * @author Qiang Xue <qiang.xue@gmail.com>
- * @version $Id$
- * @package System.Web.UI.WebControls
- * @since 3.0
- */
-class TTableStyle extends TStyle
-{
- /**
- * @var TVerticalAlign the URL of the background image for the table
- */
- private $_backImageUrl=null;
- /**
- * @var THorizontalAlign horizontal alignment of the contents within the table
- */
- private $_horizontalAlign=null;
- /**
- * @var integer cellpadding of the table
- */
- private $_cellPadding=null;
- /**
- * @var integer cellspacing of the table
- */
- private $_cellSpacing=null;
- /**
- * @var TTableGridLines grid line setting of the table
- */
- private $_gridLines=null;
- /**
- * @var boolean whether the table border should be collapsed
- */
- private $_borderCollapse=null;
-
- /**
- * Sets the style attributes to default values.
- * This method overrides the parent implementation by
- * resetting additional TTableStyle specific attributes.
- */
- public function reset()
- {
- $this->_backImageUrl=null;
- $this->_horizontalAlign=null;
- $this->_cellPadding=null;
- $this->_cellSpacing=null;
- $this->_gridLines=null;
- $this->_borderCollapse=null;
- }
-
- /**
- * Copies the fields in a new style to this style.
- * If a style field is set in the new style, the corresponding field
- * in this style will be overwritten.
- * @param TStyle the new style
- */
- public function copyFrom($style)
- {
- parent::copyFrom($style);
- if($style instanceof TTableStyle)
- {
- if($style->_backImageUrl!==null)
- $this->_backImageUrl=$style->_backImageUrl;
- if($style->_horizontalAlign!==null)
- $this->_horizontalAlign=$style->_horizontalAlign;
- if($style->_cellPadding!==null)
- $this->_cellPadding=$style->_cellPadding;
- if($style->_cellSpacing!==null)
- $this->_cellSpacing=$style->_cellSpacing;
- if($style->_gridLines!==null)
- $this->_gridLines=$style->_gridLines;
- if($style->_borderCollapse!==null)
- $this->_borderCollapse=$style->_borderCollapse;
- }
- }
-
- /**
- * Merges the style with a new one.
- * If a style field is not set in this style, it will be overwritten by
- * the new one.
- * @param TStyle the new style
- */
- public function mergeWith($style)
- {
- parent::mergeWith($style);
- if($style instanceof TTableStyle)
- {
- if($this->_backImageUrl===null && $style->_backImageUrl!==null)
- $this->_backImageUrl=$style->_backImageUrl;
- if($this->_horizontalAlign===null && $style->_horizontalAlign!==null)
- $this->_horizontalAlign=$style->_horizontalAlign;
- if($this->_cellPadding===null && $style->_cellPadding!==null)
- $this->_cellPadding=$style->_cellPadding;
- if($this->_cellSpacing===null && $style->_cellSpacing!==null)
- $this->_cellSpacing=$style->_cellSpacing;
- if($this->_gridLines===null && $style->_gridLines!==null)
- $this->_gridLines=$style->_gridLines;
- if($this->_borderCollapse===null && $style->_borderCollapse!==null)
- $this->_borderCollapse=$style->_borderCollapse;
- }
- }
-
-
- /**
- * Adds attributes related to CSS styles to renderer.
- * This method overrides the parent implementation.
- * @param THtmlWriter the writer used for the rendering purpose
- */
- public function addAttributesToRender($writer)
- {
- if(($url=trim($this->getBackImageUrl()))!=='')
- $writer->addStyleAttribute('background-image','url('.$url.')');
-
- if(($horizontalAlign=$this->getHorizontalAlign())!==THorizontalAlign::NotSet)
- $writer->addStyleAttribute('text-align',strtolower($horizontalAlign));
-
- if(($cellPadding=$this->getCellPadding())>=0)
- $writer->addAttribute('cellpadding',"$cellPadding");
-
- if(($cellSpacing=$this->getCellSpacing())>=0)
- $writer->addAttribute('cellspacing',"$cellSpacing");
-
- if($this->getBorderCollapse())
- $writer->addStyleAttribute('border-collapse','collapse');
-
- switch($this->getGridLines())
- {
- case TTableGridLines::Horizontal : $writer->addAttribute('rules','rows'); break;
- case TTableGridLines::Vertical : $writer->addAttribute('rules','cols'); break;
- case TTableGridLines::Both : $writer->addAttribute('rules','all'); break;
- }
-
- parent::addAttributesToRender($writer);
- }
-
- /**
- * @return string the URL of the background image for the table
- */
- public function getBackImageUrl()
- {
- return $this->_backImageUrl===null?'':$this->_backImageUrl;
- }
-
- /**
- * Sets the URL of the background image for the table
- * @param string the URL
- */
- public function setBackImageUrl($value)
- {
- $this->_backImageUrl=$value;
- }
-
- /**
- * @return THorizontalAlign the horizontal alignment of the contents within the table, defaults to THorizontalAlign::NotSet.
- */
- public function getHorizontalAlign()
- {
- return $this->_horizontalAlign===null?THorizontalAlign::NotSet:$this->_horizontalAlign;
- }
-
- /**
- * Sets the horizontal alignment of the contents within the table.
- * @param THorizontalAlign the horizontal alignment
- */
- public function setHorizontalAlign($value)
- {
- $this->_horizontalAlign=TPropertyValue::ensureEnum($value,'THorizontalAlign');
- }
-
- /**
- * @return integer cellpadding of the table. Defaults to -1, meaning not set.
- */
- public function getCellPadding()
- {
- return $this->_cellPadding===null?-1:$this->_cellPadding;
- }
-
- /**
- * @param integer cellpadding of the table. A value equal to -1 clears up the setting.
- * @throws TInvalidDataValueException if the value is less than -1.
- */
- public function setCellPadding($value)
- {
- if(($this->_cellPadding=TPropertyValue::ensureInteger($value))<-1)
- throw new TInvalidDataValueException('tablestyle_cellpadding_invalid');
- }
-
- /**
- * @return integer cellspacing of the table. Defaults to -1, meaning not set.
- */
- public function getCellSpacing()
- {
- return $this->_cellSpacing===null?-1:$this->_cellSpacing;
- }
-
- /**
- * @param integer cellspacing of the table. A value equal to -1 clears up the setting.
- * @throws TInvalidDataValueException if the value is less than -1.
- */
- public function setCellSpacing($value)
- {
- if(($this->_cellSpacing=TPropertyValue::ensureInteger($value))<-1)
- throw new TInvalidDataValueException('tablestyle_cellspacing_invalid');
- }
-
- /**
- * @return TTableGridLines the grid line setting of the table. Defaults to TTableGridLines::None.
- */
- public function getGridLines()
- {
- return $this->_gridLines===null?TTableGridLines::None:$this->_gridLines;
- }
-
- /**
- * Sets the grid line style of the table.
- * @param TTableGridLines the grid line setting of the table
- */
- public function setGridLines($value)
- {
- $this->_gridLines=TPropertyValue::ensureEnum($value,'TTableGridLines');
- }
-
-
- /**
- * @return boolean whether the table borders should be collapsed. Defaults to false.
- */
- public function getBorderCollapse()
- {
- return $this->_borderCollapse===null?false:$this->_borderCollapse;
- }
-
- /**
- * @param boolean whether the table borders should be collapsed.
- */
- public function setBorderCollapse($value)
- {
- $this->_borderCollapse=TPropertyValue::ensureBoolean($value);
- }
-}
-
-/**
- * TTableItemStyle class.
- * TTableItemStyle represents the CSS style specific for HTML table item.
- *
- * @author Qiang Xue <qiang.xue@gmail.com>
- * @version $Id$
- * @package System.Web.UI.WebControls
- * @since 3.0
- */
-class TTableItemStyle extends TStyle
-{
- /**
- * @var THorizontalAlign horizontal alignment of the contents within the table item
- */
- private $_horizontalAlign=null;
- /**
- * @var TVerticalAlign vertical alignment of the contents within the table item
- */
- private $_verticalAlign=null;
- /**
- * @var boolean whether the content wraps within the table item
- */
- private $_wrap=null;
-
- /**
- * Sets the style attributes to default values.
- * This method overrides the parent implementation by
- * resetting additional TTableItemStyle specific attributes.
- */
- public function reset()
- {
- parent::reset();
- $this->_verticalAlign=null;
- $this->_horizontalAlign=null;
- $this->_wrap=null;
- }
-
- /**
- * Copies the fields in a new style to this style.
- * If a style field is set in the new style, the corresponding field
- * in this style will be overwritten.
- * @param TStyle the new style
- */
- public function copyFrom($style)
- {
- parent::copyFrom($style);
- if($style instanceof TTableItemStyle)
- {
- if($this->_verticalAlign===null && $style->_verticalAlign!==null)
- $this->_verticalAlign=$style->_verticalAlign;
- if($this->_horizontalAlign===null && $style->_horizontalAlign!==null)
- $this->_horizontalAlign=$style->_horizontalAlign;
- if($this->_wrap===null && $style->_wrap!==null)
- $this->_wrap=$style->_wrap;
- }
- }
-
- /**
- * Merges the style with a new one.
- * If a style field is not set in this style, it will be overwritten by
- * the new one.
- * @param TStyle the new style
- */
- public function mergeWith($style)
- {
- parent::mergeWith($style);
- if($style instanceof TTableItemStyle)
- {
- if($style->_verticalAlign!==null)
- $this->_verticalAlign=$style->_verticalAlign;
- if($style->_horizontalAlign!==null)
- $this->_horizontalAlign=$style->_horizontalAlign;
- if($style->_wrap!==null)
- $this->_wrap=$style->_wrap;
- }
- }
-
- /**
- * Adds attributes related to CSS styles to renderer.
- * This method overrides the parent implementation.
- * @param THtmlWriter the writer used for the rendering purpose
- */
- public function addAttributesToRender($writer)
- {
- if(!$this->getWrap())
- $writer->addStyleAttribute('white-space','nowrap');
-
- if(($horizontalAlign=$this->getHorizontalAlign())!==THorizontalAlign::NotSet)
- $writer->addAttribute('align',strtolower($horizontalAlign));
-
- if(($verticalAlign=$this->getVerticalAlign())!==TVerticalAlign::NotSet)
- $writer->addAttribute('valign',strtolower($verticalAlign));
-
- parent::addAttributesToRender($writer);
- }
-
- /**
- * @return THorizontalAlign the horizontal alignment of the contents within the table item, defaults to THorizontalAlign::NotSet.
- */
- public function getHorizontalAlign()
- {
- return $this->_horizontalAlign===null?THorizontalAlign::NotSet:$this->_horizontalAlign;
- }
-
- /**
- * Sets the horizontal alignment of the contents within the table item.
- * @param THorizontalAlign the horizontal alignment
- */
- public function setHorizontalAlign($value)
- {
- $this->_horizontalAlign=TPropertyValue::ensureEnum($value,'THorizontalAlign');
- }
-
- /**
- * @return TVerticalAlign the vertical alignment of the contents within the table item, defaults to TVerticalAlign::NotSet.
- */
- public function getVerticalAlign()
- {
- return $this->_verticalAlign===null?TVerticalAlign::NotSet:$this->_verticalAlign;
- }
-
- /**
- * Sets the vertical alignment of the contents within the table item.
- * @param TVerticalAlign the horizontal alignment
- */
- public function setVerticalAlign($value)
- {
- $this->_verticalAlign=TPropertyValue::ensureEnum($value,'TVerticalAlign');
- }
-
- /**
- * @return boolean whether the content wraps within the table item. Defaults to true.
- */
- public function getWrap()
- {
- return $this->_wrap===null?true:$this->_wrap;
- }
-
- /**
- * Sets the value indicating whether the content wraps within the table item.
- * @param boolean whether the content wraps within the panel.
- */
- public function setWrap($value)
- {
- $this->_wrap=TPropertyValue::ensureBoolean($value);
- }
-}
-
-/**
- * THorizontalAlign class.
- * THorizontalAlign defines the enumerable type for the possible horizontal alignments in a CSS style.
- *
- * The following enumerable values are defined:
- * - NotSet: the alignment is not specified.
- * - Left: left aligned
- * - Right: right aligned
- * - Center: center aligned
- * - Justify: the begin and end are justified
- *
- * @author Qiang Xue <qiang.xue@gmail.com>
- * @version $Id$
- * @package System.Web.UI.WebControls
- * @since 3.0.4
- */
-class THorizontalAlign extends TEnumerable
-{
- const NotSet='NotSet';
- const Left='Left';
- const Right='Right';
- const Center='Center';
- const Justify='Justify';
-}
-
-/**
- * TVerticalAlign class.
- * TVerticalAlign defines the enumerable type for the possible vertical alignments in a CSS style.
- *
- * The following enumerable values are defined:
- * - NotSet: the alignment is not specified.
- * - Top: top aligned
- * - Bottom: bottom aligned
- * - Middle: middle aligned
- *
- * @author Qiang Xue <qiang.xue@gmail.com>
- * @version $Id$
- * @package System.Web.UI.WebControls
- * @since 3.0.4
- */
-class TVerticalAlign extends TEnumerable
-{
- const NotSet='NotSet';
- const Top='Top';
- const Bottom='Bottom';
- const Middle='Middle';
-}
-
-
-/**
- * TTableGridLines class.
- * TTableGridLines defines the enumerable type for the possible grid line types of an HTML table.
- *
- * The following enumerable values are defined:
- * - None: no grid lines
- * - Horizontal: horizontal grid lines only
- * - Vertical: vertical grid lines only
- * - Both: both horizontal and vertical grid lines are shown
- *
- * @author Qiang Xue <qiang.xue@gmail.com>
- * @version $Id$
- * @package System.Web.UI.WebControls
- * @since 3.0.4
- */
-class TTableGridLines extends TEnumerable
-{
- const None='None';
- const Horizontal='Horizontal';
- const Vertical='Vertical';
- const Both='Both';
-}
-
+<?php
+/**
+ * TStyle class file.
+ *
+ * @author Qiang Xue <qiang.xue@gmail.com>
+ * @link http://www.pradosoft.com/
+ * @copyright Copyright &copy; 2005-2012 PradoSoft
+ * @license http://www.pradosoft.com/license/
+ * @version $Id$
+ * @package System.Web.UI.WebControls
+ */
+
+/**
+ * Includes TFont definition
+ */
+Prado::using('System.Web.UI.WebControls.TFont');
+
+/**
+ * TStyle class
+ *
+ * TStyle encapsulates the CSS style applied to a control.
+ *
+ * @author Qiang Xue <qiang.xue@gmail.com>
+ * @version $Id$
+ * @package System.Web.UI.WebControls
+ * @since 3.0
+ */
+class TStyle extends TComponent
+{
+ /**
+ * @var array storage of CSS fields
+ */
+ private $_fields=array();
+ /**
+ * @var TFont font object
+ */
+ private $_font=null;
+ /**
+ * @var string CSS class name
+ */
+ private $_class=null;
+ /**
+ * @var string CSS style string (those not represented by specific fields of TStyle)
+ */
+ private $_customStyle=null;
+ /**
+ * @var string display style
+ */
+ private $_displayStyle='Fixed';
+
+ /**
+ * Constructor.
+ * @param TStyle style to copy from
+ */
+ public function __construct($style=null)
+ {
+ if($style!==null)
+ $this->copyFrom($style);
+ }
+
+ /**
+ * Need to clone the font object.
+ */
+ public function __clone()
+ {
+ if($this->_font!==null)
+ $this->_font = clone($this->_font);
+ }
+
+ /**
+ * @return string the background color of the control
+ */
+ public function getBackColor()
+ {
+ return isset($this->_fields['background-color'])?$this->_fields['background-color']:'';
+ }
+
+ /**
+ * @param string the background color of the control
+ */
+ public function setBackColor($value)
+ {
+ if(trim($value)==='')
+ unset($this->_fields['background-color']);
+ else
+ $this->_fields['background-color']=$value;
+ }
+
+ /**
+ * @return string the border color of the control
+ */
+ public function getBorderColor()
+ {
+ return isset($this->_fields['border-color'])?$this->_fields['border-color']:'';
+ }
+
+ /**
+ * @param string the border color of the control
+ */
+ public function setBorderColor($value)
+ {
+ if(trim($value)==='')
+ unset($this->_fields['border-color']);
+ else
+ $this->_fields['border-color']=$value;
+ }
+
+ /**
+ * @return string the border style of the control
+ */
+ public function getBorderStyle()
+ {
+ return isset($this->_fields['border-style'])?$this->_fields['border-style']:'';
+ }
+
+ /**
+ * Sets the border style of the control.
+ * @param string the border style of the control
+ */
+ public function setBorderStyle($value)
+ {
+ if(trim($value)==='')
+ unset($this->_fields['border-style']);
+ else
+ $this->_fields['border-style']=$value;
+ }
+
+ /**
+ * @return string the border width of the control
+ */
+ public function getBorderWidth()
+ {
+ return isset($this->_fields['border-width'])?$this->_fields['border-width']:'';
+ }
+
+ /**
+ * @param string the border width of the control
+ */
+ public function setBorderWidth($value)
+ {
+ if(trim($value)==='')
+ unset($this->_fields['border-width']);
+ else
+ $this->_fields['border-width']=$value;
+ }
+
+ /**
+ * @return string the CSS class of the control
+ */
+ public function getCssClass()
+ {
+ return $this->_class===null?'':$this->_class;
+ }
+
+ /**
+ * @return boolean true if CSS is set or empty.
+ */
+ public function hasCssClass()
+ {
+ return ($this->_class!==null);
+ }
+
+ /**
+ * @param string the name of the CSS class of the control
+ */
+ public function setCssClass($value)
+ {
+ $this->_class=$value;
+ }
+
+ /**
+ * @return TFont the font of the control
+ */
+ public function getFont()
+ {
+ if($this->_font===null)
+ $this->_font=new TFont;
+ return $this->_font;
+ }
+
+ /**
+ * @return boolean true if font is set.
+ */
+ public function hasFont()
+ {
+ return $this->_font !== null;
+ }
+
+ /**
+ * @param TDisplayStyle control display style, default is TDisplayStyle::Fixed
+ */
+ public function setDisplayStyle($value)
+ {
+ $this->_displayStyle = TPropertyValue::ensureEnum($value, 'TDisplayStyle');
+ switch($this->_displayStyle)
+ {
+ case TDisplayStyle::None:
+ $this->_fields['display'] = 'none';
+ break;
+ case TDisplayStyle::Dynamic:
+ $this->_fields['display'] = ''; //remove the display property
+ break;
+ case TDisplayStyle::Fixed:
+ $this->_fields['visibility'] = 'visible';
+ break;
+ case TDisplayStyle::Hidden:
+ $this->_fields['visibility'] = 'hidden';
+ break;
+ }
+ }
+
+ /**
+ * @return TDisplayStyle display style
+ */
+ public function getDisplayStyle()
+ {
+ return $this->_displayStyle;
+ }
+
+ /**
+ * @return string the foreground color of the control
+ */
+ public function getForeColor()
+ {
+ return isset($this->_fields['color'])?$this->_fields['color']:'';
+ }
+
+ /**
+ * @param string the foreground color of the control
+ */
+ public function setForeColor($value)
+ {
+ if(trim($value)==='')
+ unset($this->_fields['color']);
+ else
+ $this->_fields['color']=$value;
+ }
+
+ /**
+ * @return string the height of the control
+ */
+ public function getHeight()
+ {
+ return isset($this->_fields['height'])?$this->_fields['height']:'';
+ }
+
+ /**
+ * @param string the height of the control
+ */
+ public function setHeight($value)
+ {
+ if(trim($value)==='')
+ unset($this->_fields['height']);
+ else
+ $this->_fields['height']=$value;
+ }
+
+ /**
+ * @return string the custom style of the control
+ */
+ public function getCustomStyle()
+ {
+ return $this->_customStyle===null?'':$this->_customStyle;
+ }
+
+ /**
+ * Sets custom style fields from a string.
+ * Custom style fields will be overwritten by style fields explicitly defined.
+ * @param string the custom style of the control
+ */
+ public function setCustomStyle($value)
+ {
+ $this->_customStyle=$value;
+ }
+
+ /**
+ * @return string a single style field value set via {@link setStyleField}. Defaults to empty string.
+ */
+ public function getStyleField($name)
+ {
+ return isset($this->_fields[$name])?$this->_fields[$name]:'';
+ }
+
+ /**
+ * Sets a single style field value.
+ * Style fields set by this method will overwrite those set by {@link setCustomStyle}.
+ * @param string style field name
+ * @param string style field value
+ */
+ public function setStyleField($name,$value)
+ {
+ $this->_fields[$name]=$value;
+ }
+
+ /**
+ * Clears a single style field value;
+ * @param string style field name
+ */
+ public function clearStyleField($name)
+ {
+ unset($this->_fields[$name]);
+ }
+
+ /**
+ * @return boolean whether a style field has been defined by {@link setStyleField}
+ */
+ public function hasStyleField($name)
+ {
+ return isset($this->_fields[$name]);
+ }
+
+ /**
+ * @return string the width of the control
+ */
+ public function getWidth()
+ {
+ return isset($this->_fields['width'])?$this->_fields['width']:'';
+ }
+
+ /**
+ * @param string the width of the control
+ */
+ public function setWidth($value)
+ {
+ $this->_fields['width']=$value;
+ }
+
+ /**
+ * Resets the style to the original empty state.
+ */
+ public function reset()
+ {
+ $this->_fields=array();
+ $this->_font=null;
+ $this->_class=null;
+ $this->_customStyle=null;
+ }
+
+ /**
+ * Copies the fields in a new style to this style.
+ * If a style field is set in the new style, the corresponding field
+ * in this style will be overwritten.
+ * @param TStyle the new style
+ */
+ public function copyFrom($style)
+ {
+ if($style instanceof TStyle)
+ {
+ $this->_fields=array_merge($this->_fields,$style->_fields);
+ if($style->_class!==null)
+ $this->_class=$style->_class;
+ if($style->_customStyle!==null)
+ $this->_customStyle=$style->_customStyle;
+ if($style->_font!==null)
+ $this->getFont()->copyFrom($style->_font);
+ }
+ }
+
+ /**
+ * Merges the style with a new one.
+ * If a style field is not set in this style, it will be overwritten by
+ * the new one.
+ * @param TStyle the new style
+ */
+ public function mergeWith($style)
+ {
+ if($style instanceof TStyle)
+ {
+ $this->_fields=array_merge($style->_fields,$this->_fields);
+ if($this->_class===null)
+ $this->_class=$style->_class;
+ if($this->_customStyle===null)
+ $this->_customStyle=$style->_customStyle;
+ if($style->_font!==null)
+ $this->getFont()->mergeWith($style->_font);
+ }
+ }
+
+ /**
+ * Adds attributes related to CSS styles to renderer.
+ * @param THtmlWriter the writer used for the rendering purpose
+ */
+ public function addAttributesToRender($writer)
+ {
+ if($this->_customStyle!==null)
+ {
+ foreach(explode(';',$this->_customStyle) as $style)
+ {
+ $arr=explode(':',$style,2);
+ if(isset($arr[1]) && trim($arr[0])!=='')
+ $writer->addStyleAttribute(trim($arr[0]),trim($arr[1]));
+ }
+ }
+ $writer->addStyleAttributes($this->_fields);
+ if($this->_font!==null)
+ $this->_font->addAttributesToRender($writer);
+ if($this->_class!==null)
+ $writer->addAttribute('class',$this->_class);
+ }
+
+ /**
+ * @return array list of style fields.
+ */
+ public function getStyleFields()
+ {
+ return $this->_fields;
+ }
+}
+
+/**
+ * TDisplayStyle defines the enumerable type for the possible styles
+ * that a web control can display.
+ *
+ * The following enumerable values are defined:
+ * - None: the control is not displayed and not included in the layout.
+ * - Dynamic: the control is displayed and included in the layout, the layout flow is dependent on the control (equivalent to display:'' in css).
+ * - Fixed: Similar to Dynamic with CSS "visibility" set "shown".
+ * - Hidden: the control is not displayed and is included in the layout.
+ *
+ * @author Wei Zhuo <weizhuo[at]gmail[dot]com>
+ * @version $Id$
+ * @package System.Web.UI.WebControls
+ * @since 3.1
+ */
+class TDisplayStyle extends TEnumerable
+{
+ const None='None';
+ const Dynamic='Dynamic';
+ const Fixed='Fixed';
+ const Hidden='Hidden';
+}
+
+/**
+ * TTableStyle class.
+ * TTableStyle represents the CSS style specific for HTML table.
+ *
+ * @author Qiang Xue <qiang.xue@gmail.com>
+ * @version $Id$
+ * @package System.Web.UI.WebControls
+ * @since 3.0
+ */
+class TTableStyle extends TStyle
+{
+ /**
+ * @var TVerticalAlign the URL of the background image for the table
+ */
+ private $_backImageUrl=null;
+ /**
+ * @var THorizontalAlign horizontal alignment of the contents within the table
+ */
+ private $_horizontalAlign=null;
+ /**
+ * @var integer cellpadding of the table
+ */
+ private $_cellPadding=null;
+ /**
+ * @var integer cellspacing of the table
+ */
+ private $_cellSpacing=null;
+ /**
+ * @var TTableGridLines grid line setting of the table
+ */
+ private $_gridLines=null;
+ /**
+ * @var boolean whether the table border should be collapsed
+ */
+ private $_borderCollapse=null;
+
+ /**
+ * Sets the style attributes to default values.
+ * This method overrides the parent implementation by
+ * resetting additional TTableStyle specific attributes.
+ */
+ public function reset()
+ {
+ $this->_backImageUrl=null;
+ $this->_horizontalAlign=null;
+ $this->_cellPadding=null;
+ $this->_cellSpacing=null;
+ $this->_gridLines=null;
+ $this->_borderCollapse=null;
+ }
+
+ /**
+ * Copies the fields in a new style to this style.
+ * If a style field is set in the new style, the corresponding field
+ * in this style will be overwritten.
+ * @param TStyle the new style
+ */
+ public function copyFrom($style)
+ {
+ parent::copyFrom($style);
+ if($style instanceof TTableStyle)
+ {
+ if($style->_backImageUrl!==null)
+ $this->_backImageUrl=$style->_backImageUrl;
+ if($style->_horizontalAlign!==null)
+ $this->_horizontalAlign=$style->_horizontalAlign;
+ if($style->_cellPadding!==null)
+ $this->_cellPadding=$style->_cellPadding;
+ if($style->_cellSpacing!==null)
+ $this->_cellSpacing=$style->_cellSpacing;
+ if($style->_gridLines!==null)
+ $this->_gridLines=$style->_gridLines;
+ if($style->_borderCollapse!==null)
+ $this->_borderCollapse=$style->_borderCollapse;
+ }
+ }
+
+ /**
+ * Merges the style with a new one.
+ * If a style field is not set in this style, it will be overwritten by
+ * the new one.
+ * @param TStyle the new style
+ */
+ public function mergeWith($style)
+ {
+ parent::mergeWith($style);
+ if($style instanceof TTableStyle)
+ {
+ if($this->_backImageUrl===null && $style->_backImageUrl!==null)
+ $this->_backImageUrl=$style->_backImageUrl;
+ if($this->_horizontalAlign===null && $style->_horizontalAlign!==null)
+ $this->_horizontalAlign=$style->_horizontalAlign;
+ if($this->_cellPadding===null && $style->_cellPadding!==null)
+ $this->_cellPadding=$style->_cellPadding;
+ if($this->_cellSpacing===null && $style->_cellSpacing!==null)
+ $this->_cellSpacing=$style->_cellSpacing;
+ if($this->_gridLines===null && $style->_gridLines!==null)
+ $this->_gridLines=$style->_gridLines;
+ if($this->_borderCollapse===null && $style->_borderCollapse!==null)
+ $this->_borderCollapse=$style->_borderCollapse;
+ }
+ }
+
+
+ /**
+ * Adds attributes related to CSS styles to renderer.
+ * This method overrides the parent implementation.
+ * @param THtmlWriter the writer used for the rendering purpose
+ */
+ public function addAttributesToRender($writer)
+ {
+ if(($url=trim($this->getBackImageUrl()))!=='')
+ $writer->addStyleAttribute('background-image','url('.$url.')');
+
+ if(($horizontalAlign=$this->getHorizontalAlign())!==THorizontalAlign::NotSet)
+ $writer->addStyleAttribute('text-align',strtolower($horizontalAlign));
+
+ if(($cellPadding=$this->getCellPadding())>=0)
+ $writer->addAttribute('cellpadding',"$cellPadding");
+
+ if(($cellSpacing=$this->getCellSpacing())>=0)
+ $writer->addAttribute('cellspacing',"$cellSpacing");
+
+ if($this->getBorderCollapse())
+ $writer->addStyleAttribute('border-collapse','collapse');
+
+ switch($this->getGridLines())
+ {
+ case TTableGridLines::Horizontal : $writer->addAttribute('rules','rows'); break;
+ case TTableGridLines::Vertical : $writer->addAttribute('rules','cols'); break;
+ case TTableGridLines::Both : $writer->addAttribute('rules','all'); break;
+ }
+
+ parent::addAttributesToRender($writer);
+ }
+
+ /**
+ * @return string the URL of the background image for the table
+ */
+ public function getBackImageUrl()
+ {
+ return $this->_backImageUrl===null?'':$this->_backImageUrl;
+ }
+
+ /**
+ * Sets the URL of the background image for the table
+ * @param string the URL
+ */
+ public function setBackImageUrl($value)
+ {
+ $this->_backImageUrl=$value;
+ }
+
+ /**
+ * @return THorizontalAlign the horizontal alignment of the contents within the table, defaults to THorizontalAlign::NotSet.
+ */
+ public function getHorizontalAlign()
+ {
+ return $this->_horizontalAlign===null?THorizontalAlign::NotSet:$this->_horizontalAlign;
+ }
+
+ /**
+ * Sets the horizontal alignment of the contents within the table.
+ * @param THorizontalAlign the horizontal alignment
+ */
+ public function setHorizontalAlign($value)
+ {
+ $this->_horizontalAlign=TPropertyValue::ensureEnum($value,'THorizontalAlign');
+ }
+
+ /**
+ * @return integer cellpadding of the table. Defaults to -1, meaning not set.
+ */
+ public function getCellPadding()
+ {
+ return $this->_cellPadding===null?-1:$this->_cellPadding;
+ }
+
+ /**
+ * @param integer cellpadding of the table. A value equal to -1 clears up the setting.
+ * @throws TInvalidDataValueException if the value is less than -1.
+ */
+ public function setCellPadding($value)
+ {
+ if(($this->_cellPadding=TPropertyValue::ensureInteger($value))<-1)
+ throw new TInvalidDataValueException('tablestyle_cellpadding_invalid');
+ }
+
+ /**
+ * @return integer cellspacing of the table. Defaults to -1, meaning not set.
+ */
+ public function getCellSpacing()
+ {
+ return $this->_cellSpacing===null?-1:$this->_cellSpacing;
+ }
+
+ /**
+ * @param integer cellspacing of the table. A value equal to -1 clears up the setting.
+ * @throws TInvalidDataValueException if the value is less than -1.
+ */
+ public function setCellSpacing($value)
+ {
+ if(($this->_cellSpacing=TPropertyValue::ensureInteger($value))<-1)
+ throw new TInvalidDataValueException('tablestyle_cellspacing_invalid');
+ }
+
+ /**
+ * @return TTableGridLines the grid line setting of the table. Defaults to TTableGridLines::None.
+ */
+ public function getGridLines()
+ {
+ return $this->_gridLines===null?TTableGridLines::None:$this->_gridLines;
+ }
+
+ /**
+ * Sets the grid line style of the table.
+ * @param TTableGridLines the grid line setting of the table
+ */
+ public function setGridLines($value)
+ {
+ $this->_gridLines=TPropertyValue::ensureEnum($value,'TTableGridLines');
+ }
+
+
+ /**
+ * @return boolean whether the table borders should be collapsed. Defaults to false.
+ */
+ public function getBorderCollapse()
+ {
+ return $this->_borderCollapse===null?false:$this->_borderCollapse;
+ }
+
+ /**
+ * @param boolean whether the table borders should be collapsed.
+ */
+ public function setBorderCollapse($value)
+ {
+ $this->_borderCollapse=TPropertyValue::ensureBoolean($value);
+ }
+}
+
+/**
+ * TTableItemStyle class.
+ * TTableItemStyle represents the CSS style specific for HTML table item.
+ *
+ * @author Qiang Xue <qiang.xue@gmail.com>
+ * @version $Id$
+ * @package System.Web.UI.WebControls
+ * @since 3.0
+ */
+class TTableItemStyle extends TStyle
+{
+ /**
+ * @var THorizontalAlign horizontal alignment of the contents within the table item
+ */
+ private $_horizontalAlign=null;
+ /**
+ * @var TVerticalAlign vertical alignment of the contents within the table item
+ */
+ private $_verticalAlign=null;
+ /**
+ * @var boolean whether the content wraps within the table item
+ */
+ private $_wrap=null;
+
+ /**
+ * Sets the style attributes to default values.
+ * This method overrides the parent implementation by
+ * resetting additional TTableItemStyle specific attributes.
+ */
+ public function reset()
+ {
+ parent::reset();
+ $this->_verticalAlign=null;
+ $this->_horizontalAlign=null;
+ $this->_wrap=null;
+ }
+
+ /**
+ * Copies the fields in a new style to this style.
+ * If a style field is set in the new style, the corresponding field
+ * in this style will be overwritten.
+ * @param TStyle the new style
+ */
+ public function copyFrom($style)
+ {
+ parent::copyFrom($style);
+ if($style instanceof TTableItemStyle)
+ {
+ if($this->_verticalAlign===null && $style->_verticalAlign!==null)
+ $this->_verticalAlign=$style->_verticalAlign;
+ if($this->_horizontalAlign===null && $style->_horizontalAlign!==null)
+ $this->_horizontalAlign=$style->_horizontalAlign;
+ if($this->_wrap===null && $style->_wrap!==null)
+ $this->_wrap=$style->_wrap;
+ }
+ }
+
+ /**
+ * Merges the style with a new one.
+ * If a style field is not set in this style, it will be overwritten by
+ * the new one.
+ * @param TStyle the new style
+ */
+ public function mergeWith($style)
+ {
+ parent::mergeWith($style);
+ if($style instanceof TTableItemStyle)
+ {
+ if($style->_verticalAlign!==null)
+ $this->_verticalAlign=$style->_verticalAlign;
+ if($style->_horizontalAlign!==null)
+ $this->_horizontalAlign=$style->_horizontalAlign;
+ if($style->_wrap!==null)
+ $this->_wrap=$style->_wrap;
+ }
+ }
+
+ /**
+ * Adds attributes related to CSS styles to renderer.
+ * This method overrides the parent implementation.
+ * @param THtmlWriter the writer used for the rendering purpose
+ */
+ public function addAttributesToRender($writer)
+ {
+ if(!$this->getWrap())
+ $writer->addStyleAttribute('white-space','nowrap');
+
+ if(($horizontalAlign=$this->getHorizontalAlign())!==THorizontalAlign::NotSet)
+ $writer->addAttribute('align',strtolower($horizontalAlign));
+
+ if(($verticalAlign=$this->getVerticalAlign())!==TVerticalAlign::NotSet)
+ $writer->addAttribute('valign',strtolower($verticalAlign));
+
+ parent::addAttributesToRender($writer);
+ }
+
+ /**
+ * @return THorizontalAlign the horizontal alignment of the contents within the table item, defaults to THorizontalAlign::NotSet.
+ */
+ public function getHorizontalAlign()
+ {
+ return $this->_horizontalAlign===null?THorizontalAlign::NotSet:$this->_horizontalAlign;
+ }
+
+ /**
+ * Sets the horizontal alignment of the contents within the table item.
+ * @param THorizontalAlign the horizontal alignment
+ */
+ public function setHorizontalAlign($value)
+ {
+ $this->_horizontalAlign=TPropertyValue::ensureEnum($value,'THorizontalAlign');
+ }
+
+ /**
+ * @return TVerticalAlign the vertical alignment of the contents within the table item, defaults to TVerticalAlign::NotSet.
+ */
+ public function getVerticalAlign()
+ {
+ return $this->_verticalAlign===null?TVerticalAlign::NotSet:$this->_verticalAlign;
+ }
+
+ /**
+ * Sets the vertical alignment of the contents within the table item.
+ * @param TVerticalAlign the horizontal alignment
+ */
+ public function setVerticalAlign($value)
+ {
+ $this->_verticalAlign=TPropertyValue::ensureEnum($value,'TVerticalAlign');
+ }
+
+ /**
+ * @return boolean whether the content wraps within the table item. Defaults to true.
+ */
+ public function getWrap()
+ {
+ return $this->_wrap===null?true:$this->_wrap;
+ }
+
+ /**
+ * Sets the value indicating whether the content wraps within the table item.
+ * @param boolean whether the content wraps within the panel.
+ */
+ public function setWrap($value)
+ {
+ $this->_wrap=TPropertyValue::ensureBoolean($value);
+ }
+}
+
+/**
+ * THorizontalAlign class.
+ * THorizontalAlign defines the enumerable type for the possible horizontal alignments in a CSS style.
+ *
+ * The following enumerable values are defined:
+ * - NotSet: the alignment is not specified.
+ * - Left: left aligned
+ * - Right: right aligned
+ * - Center: center aligned
+ * - Justify: the begin and end are justified
+ *
+ * @author Qiang Xue <qiang.xue@gmail.com>
+ * @version $Id$
+ * @package System.Web.UI.WebControls
+ * @since 3.0.4
+ */
+class THorizontalAlign extends TEnumerable
+{
+ const NotSet='NotSet';
+ const Left='Left';
+ const Right='Right';
+ const Center='Center';
+ const Justify='Justify';
+}
+
+/**
+ * TVerticalAlign class.
+ * TVerticalAlign defines the enumerable type for the possible vertical alignments in a CSS style.
+ *
+ * The following enumerable values are defined:
+ * - NotSet: the alignment is not specified.
+ * - Top: top aligned
+ * - Bottom: bottom aligned
+ * - Middle: middle aligned
+ *
+ * @author Qiang Xue <qiang.xue@gmail.com>
+ * @version $Id$
+ * @package System.Web.UI.WebControls
+ * @since 3.0.4
+ */
+class TVerticalAlign extends TEnumerable
+{
+ const NotSet='NotSet';
+ const Top='Top';
+ const Bottom='Bottom';
+ const Middle='Middle';
+}
+
+
+/**
+ * TTableGridLines class.
+ * TTableGridLines defines the enumerable type for the possible grid line types of an HTML table.
+ *
+ * The following enumerable values are defined:
+ * - None: no grid lines
+ * - Horizontal: horizontal grid lines only
+ * - Vertical: vertical grid lines only
+ * - Both: both horizontal and vertical grid lines are shown
+ *
+ * @author Qiang Xue <qiang.xue@gmail.com>
+ * @version $Id$
+ * @package System.Web.UI.WebControls
+ * @since 3.0.4
+ */
+class TTableGridLines extends TEnumerable
+{
+ const None='None';
+ const Horizontal='Horizontal';
+ const Vertical='Vertical';
+ const Both='Both';
+}
+
diff --git a/framework/Web/UI/WebControls/TTable.php b/framework/Web/UI/WebControls/TTable.php
index a333bf09..b7a774ae 100644
--- a/framework/Web/UI/WebControls/TTable.php
+++ b/framework/Web/UI/WebControls/TTable.php
@@ -1,410 +1,410 @@
-<?php
-/**
- * TTable and TTableRowCollection class file
- *
- * @author Qiang Xue <qiang.xue@gmail.com>
- * @link http://www.pradosoft.com/
+<?php
+/**
+ * TTable and TTableRowCollection class file
+ *
+ * @author Qiang Xue <qiang.xue@gmail.com>
+ * @link http://www.pradosoft.com/
* @copyright Copyright &copy; 2005-2012 PradoSoft
- * @license http://www.pradosoft.com/license/
- * @version $Id$
- * @package System.Web.UI.WebControls
- */
-
-/**
- * Includes TTableRow class
- */
-Prado::using('System.Web.UI.WebControls.TTableRow');
-
-/**
- * TTable class
- *
- * TTable displays an HTML table on a Web page.
- *
- * A table may have {@link setCaption Caption}, whose alignment is specified
- * via {@link setCaptionAlign CaptionAlign}. The table cellpadding and cellspacing
- * are specified via {@link setCellPadding CellPadding} and {@link setCellSpacing CellSpacing}
- * properties, respectively. The {@link setGridLines GridLines} specifies how
- * the table should display its borders. The horizontal alignment of the table
- * content can be specified via {@link setHorizontalAlign HorizontalAlign},
- * and {@link setBackImageUrl BackImageUrl} can assign a background image to the table.
- *
- * A TTable maintains a list of {@link TTableRow} controls in its
- * {@link getRows Rows} property. Each {@link TTableRow} represents
- * an HTML table row.
- *
- * To populate the table {@link getRows Rows}, you may either use control template
- * or dynamically create {@link TTableRow} in code.
- * In template, do as follows to create the table rows and cells,
- * <code>
- * <com:TTable>
- * <com:TTableRow>
- * <com:TTableCell Text="content" />
- * <com:TTableCell Text="content" />
- * </com:TTableRow>
- * <com:TTableRow>
- * <com:TTableCell Text="content" />
- * <com:TTableCell Text="content" />
- * </com:TTableRow>
- * </com:TTable>
- * </code>
- * The above can also be accomplished in code as follows,
- * <code>
- * $table=new TTable;
- * $row=new TTableRow;
- * $cell=new TTableCell; $cell->Text="content"; $row->Cells->add($cell);
- * $cell=new TTableCell; $cell->Text="content"; $row->Cells->add($cell);
- * $table->Rows->add($row);
- * $row=new TTableRow;
- * $cell=new TTableCell; $cell->Text="content"; $row->Cells->add($cell);
- * $cell=new TTableCell; $cell->Text="content"; $row->Cells->add($cell);
- * $table->Rows->add($row);
- * </code>
- *
- * @author Qiang Xue <qiang.xue@gmail.com>
- * @version $Id$
- * @package System.Web.UI.WebControls
- * @since 3.0
- */
-class TTable extends TWebControl
-{
- /**
- * @return string tag name for the table
- */
- protected function getTagName()
- {
- return 'table';
- }
-
- /**
- * Adds object parsed from template to the control.
- * This method adds only {@link TTableRow} objects into the {@link getRows Rows} collection.
- * All other objects are ignored.
- * @param mixed object parsed from template
- */
- public function addParsedObject($object)
- {
- if($object instanceof TTableRow)
- $this->getRows()->add($object);
- }
-
- /**
- * Creates a style object for the control.
- * This method creates a {@link TTableStyle} to be used by the table.
- * @return TTableStyle control style to be used
- */
- protected function createStyle()
- {
- return new TTableStyle;
- }
-
- /**
- * Adds attributes to renderer.
- * @param THtmlWriter the renderer
- */
- protected function addAttributesToRender($writer)
- {
- parent::addAttributesToRender($writer);
- $border=0;
- if($this->getHasStyle())
- {
- if($this->getGridLines()!==TTableGridLines::None)
- {
- if(($border=$this->getBorderWidth())==='')
- $border=1;
- else
- $border=(int)$border;
- }
- }
- $writer->addAttribute('border',"$border");
- }
-
- /**
- * Creates a control collection object that is to be used to hold child controls
- * @return TTableRowCollection control collection
- * @see getControls
- */
- protected function createControlCollection()
- {
- return new TTableRowCollection($this);
- }
-
- /**
- * @return TTableRowCollection list of {@link TTableRow} controls
- */
- public function getRows()
- {
- return $this->getControls();
- }
-
- /**
- * @return string table caption
- */
- public function getCaption()
- {
- return $this->getViewState('Caption','');
- }
-
- /**
- * @param string table caption
- */
- public function setCaption($value)
- {
- $this->setViewState('Caption',$value,'');
- }
-
- /**
- * @return TTableCaptionAlign table caption alignment. Defaults to TTableCaptionAlign::NotSet.
- */
- public function getCaptionAlign()
- {
- return $this->getViewState('CaptionAlign',TTableCaptionAlign::NotSet);
- }
-
- /**
- * @param TTableCaptionAlign table caption alignment.
- */
- public function setCaptionAlign($value)
- {
- $this->setViewState('CaptionAlign',TPropertyValue::ensureEnum($value,'TTableCaptionAlign'),TTableCaptionAlign::NotSet);
- }
-
- /**
- * @return integer the cellspacing for the table. Defaults to -1, meaning not set.
- */
- public function getCellSpacing()
- {
- if($this->getHasStyle())
- return $this->getStyle()->getCellSpacing();
- else
- return -1;
- }
-
- /**
- * @param integer the cellspacing for the table. Defaults to -1, meaning not set.
- */
- public function setCellSpacing($value)
- {
- $this->getStyle()->setCellSpacing($value);
- }
-
- /**
- * @return integer the cellpadding for the table. Defaults to -1, meaning not set.
- */
- public function getCellPadding()
- {
- if($this->getHasStyle())
- return $this->getStyle()->getCellPadding();
- else
- return -1;
- }
-
- /**
- * @param integer the cellpadding for the table. Defaults to -1, meaning not set.
- */
- public function setCellPadding($value)
- {
- $this->getStyle()->setCellPadding($value);
- }
-
- /**
- * @return THorizontalAlign the horizontal alignment of the table content. Defaults to THorizontalAlign::NotSet.
- */
- public function getHorizontalAlign()
- {
- if($this->getHasStyle())
- return $this->getStyle()->getHorizontalAlign();
- else
- return THorizontalAlign::NotSet;
- }
-
- /**
- * @param THorizontalAlign the horizontal alignment of the table content.
- */
- public function setHorizontalAlign($value)
- {
- $this->getStyle()->setHorizontalAlign($value);
- }
-
- /**
- * @return TTableGridLines the grid line setting of the table. Defaults to TTableGridLines::None.
- */
- public function getGridLines()
- {
- if($this->getHasStyle())
- return $this->getStyle()->getGridLines();
- else
- return TTableGridLines::None;
- }
-
- /**
- * @param TTableGridLines the grid line setting of the table
- */
- public function setGridLines($value)
- {
- $this->getStyle()->setGridLines($value);
- }
-
- /**
- * @return string the URL of the background image for the table
- */
- public function getBackImageUrl()
- {
- if($this->getHasStyle())
- return $this->getStyle()->getBackImageUrl();
- else
- return '';
- }
-
- /**
- * Sets the URL of the background image for the table
- * @param string the URL
- */
- public function setBackImageUrl($value)
- {
- $this->getStyle()->setBackImageUrl($value);
- }
-
- /**
- * Renders the openning tag for the table control which will render table caption if present.
- * @param THtmlWriter the writer used for the rendering purpose
- */
- public function renderBeginTag($writer)
- {
- parent::renderBeginTag($writer);
- if(($caption=$this->getCaption())!=='')
- {
- if(($align=$this->getCaptionAlign())!==TTableCaptionAlign::NotSet)
- $writer->addAttribute('align',strtolower($align));
- $writer->renderBeginTag('caption');
- $writer->write($caption);
- $writer->renderEndTag();
- }
- }
-
- /**
- * Renders body contents of the table.
- * @param THtmlWriter the writer used for the rendering purpose.
- */
- public function renderContents($writer)
- {
- if($this->getHasControls())
- {
- $renderTableSection=false;
- foreach($this->getControls() as $row)
- {
- if($row->getTableSection()!==TTableRowSection::Body)
- {
- $renderTableSection=true;
- break;
- }
- }
- if($renderTableSection)
- {
- $currentSection=TTableRowSection::Header;
- $writer->writeLine();
- foreach($this->getControls() as $index=>$row)
- {
- if(($section=$row->getTableSection())===$currentSection)
- {
- if($index===0 && $currentSection===TTableRowSection::Header)
- $writer->renderBeginTag('thead');
- }
- else
- {
- if($currentSection===TTableRowSection::Header)
- {
- if($index>0)
- $writer->renderEndTag();
- if($section===TTableRowSection::Body)
- $writer->renderBeginTag('tbody');
- else
- $writer->renderBeginTag('tfoot');
- $currentSection=$section;
- }
- else if($currentSection===TTableRowSection::Body)
- {
- $writer->renderEndTag();
- if($section===TTableRowSection::Footer)
- $writer->renderBeginTag('tfoot');
- else
- throw new TConfigurationException('table_tablesection_outoforder');
- $currentSection=$section;
- }
- else // Footer
- throw new TConfigurationException('table_tablesection_outoforder');
- }
- $row->renderControl($writer);
- $writer->writeLine();
- }
- $writer->renderEndTag();
- }
- else
- {
- $writer->writeLine();
- foreach($this->getControls() as $row)
- {
- $row->renderControl($writer);
- $writer->writeLine();
- }
- }
- }
- }
-}
-
-
-/**
- * TTableRowCollection class.
- *
- * TTableRowCollection is used to maintain a list of rows belong to a table.
- *
- * @author Qiang Xue <qiang.xue@gmail.com>
- * @version $Id$
- * @package System.Web.UI.WebControls
- * @since 3.0
- */
-class TTableRowCollection extends TControlCollection
-{
- /**
- * Inserts an item at the specified position.
- * This overrides the parent implementation by performing additional
- * operations for each newly added table row.
- * @param integer the speicified position.
- * @param mixed new item
- * @throws TInvalidDataTypeException if the item to be inserted is not a TTableRow object.
- */
- public function insertAt($index,$item)
- {
- if($item instanceof TTableRow)
- parent::insertAt($index,$item);
- else
- throw new TInvalidDataTypeException('tablerowcollection_tablerow_required');
- }
-}
-
-
-/**
- * TTableCaptionAlign class.
- * TTableCaptionAlign defines the enumerable type for the possible alignments
- * that a table caption can take.
- *
- * The following enumerable values are defined:
- * - NotSet: alignment not specified
- * - Top: top aligned
- * - Bottom: bottom aligned
- * - Left: left aligned
- * - Right: right aligned
- *
- * @author Qiang Xue <qiang.xue@gmail.com>
- * @version $Id$
- * @package System.Web.UI.WebControls
- * @since 3.0.4
- */
-class TTableCaptionAlign extends TEnumerable
-{
- const NotSet='NotSet';
- const Top='Top';
- const Bottom='Bottom';
- const Left='Left';
- const Right='Right';
-}
-
+ * @license http://www.pradosoft.com/license/
+ * @version $Id$
+ * @package System.Web.UI.WebControls
+ */
+
+/**
+ * Includes TTableRow class
+ */
+Prado::using('System.Web.UI.WebControls.TTableRow');
+
+/**
+ * TTable class
+ *
+ * TTable displays an HTML table on a Web page.
+ *
+ * A table may have {@link setCaption Caption}, whose alignment is specified
+ * via {@link setCaptionAlign CaptionAlign}. The table cellpadding and cellspacing
+ * are specified via {@link setCellPadding CellPadding} and {@link setCellSpacing CellSpacing}
+ * properties, respectively. The {@link setGridLines GridLines} specifies how
+ * the table should display its borders. The horizontal alignment of the table
+ * content can be specified via {@link setHorizontalAlign HorizontalAlign},
+ * and {@link setBackImageUrl BackImageUrl} can assign a background image to the table.
+ *
+ * A TTable maintains a list of {@link TTableRow} controls in its
+ * {@link getRows Rows} property. Each {@link TTableRow} represents
+ * an HTML table row.
+ *
+ * To populate the table {@link getRows Rows}, you may either use control template
+ * or dynamically create {@link TTableRow} in code.
+ * In template, do as follows to create the table rows and cells,
+ * <code>
+ * <com:TTable>
+ * <com:TTableRow>
+ * <com:TTableCell Text="content" />
+ * <com:TTableCell Text="content" />
+ * </com:TTableRow>
+ * <com:TTableRow>
+ * <com:TTableCell Text="content" />
+ * <com:TTableCell Text="content" />
+ * </com:TTableRow>
+ * </com:TTable>
+ * </code>
+ * The above can also be accomplished in code as follows,
+ * <code>
+ * $table=new TTable;
+ * $row=new TTableRow;
+ * $cell=new TTableCell; $cell->Text="content"; $row->Cells->add($cell);
+ * $cell=new TTableCell; $cell->Text="content"; $row->Cells->add($cell);
+ * $table->Rows->add($row);
+ * $row=new TTableRow;
+ * $cell=new TTableCell; $cell->Text="content"; $row->Cells->add($cell);
+ * $cell=new TTableCell; $cell->Text="content"; $row->Cells->add($cell);
+ * $table->Rows->add($row);
+ * </code>
+ *
+ * @author Qiang Xue <qiang.xue@gmail.com>
+ * @version $Id$
+ * @package System.Web.UI.WebControls
+ * @since 3.0
+ */
+class TTable extends TWebControl
+{
+ /**
+ * @return string tag name for the table
+ */
+ protected function getTagName()
+ {
+ return 'table';
+ }
+
+ /**
+ * Adds object parsed from template to the control.
+ * This method adds only {@link TTableRow} objects into the {@link getRows Rows} collection.
+ * All other objects are ignored.
+ * @param mixed object parsed from template
+ */
+ public function addParsedObject($object)
+ {
+ if($object instanceof TTableRow)
+ $this->getRows()->add($object);
+ }
+
+ /**
+ * Creates a style object for the control.
+ * This method creates a {@link TTableStyle} to be used by the table.
+ * @return TTableStyle control style to be used
+ */
+ protected function createStyle()
+ {
+ return new TTableStyle;
+ }
+
+ /**
+ * Adds attributes to renderer.
+ * @param THtmlWriter the renderer
+ */
+ protected function addAttributesToRender($writer)
+ {
+ parent::addAttributesToRender($writer);
+ $border=0;
+ if($this->getHasStyle())
+ {
+ if($this->getGridLines()!==TTableGridLines::None)
+ {
+ if(($border=$this->getBorderWidth())==='')
+ $border=1;
+ else
+ $border=(int)$border;
+ }
+ }
+ $writer->addAttribute('border',"$border");
+ }
+
+ /**
+ * Creates a control collection object that is to be used to hold child controls
+ * @return TTableRowCollection control collection
+ * @see getControls
+ */
+ protected function createControlCollection()
+ {
+ return new TTableRowCollection($this);
+ }
+
+ /**
+ * @return TTableRowCollection list of {@link TTableRow} controls
+ */
+ public function getRows()
+ {
+ return $this->getControls();
+ }
+
+ /**
+ * @return string table caption
+ */
+ public function getCaption()
+ {
+ return $this->getViewState('Caption','');
+ }
+
+ /**
+ * @param string table caption
+ */
+ public function setCaption($value)
+ {
+ $this->setViewState('Caption',$value,'');
+ }
+
+ /**
+ * @return TTableCaptionAlign table caption alignment. Defaults to TTableCaptionAlign::NotSet.
+ */
+ public function getCaptionAlign()
+ {
+ return $this->getViewState('CaptionAlign',TTableCaptionAlign::NotSet);
+ }
+
+ /**
+ * @param TTableCaptionAlign table caption alignment.
+ */
+ public function setCaptionAlign($value)
+ {
+ $this->setViewState('CaptionAlign',TPropertyValue::ensureEnum($value,'TTableCaptionAlign'),TTableCaptionAlign::NotSet);
+ }
+
+ /**
+ * @return integer the cellspacing for the table. Defaults to -1, meaning not set.
+ */
+ public function getCellSpacing()
+ {
+ if($this->getHasStyle())
+ return $this->getStyle()->getCellSpacing();
+ else
+ return -1;
+ }
+
+ /**
+ * @param integer the cellspacing for the table. Defaults to -1, meaning not set.
+ */
+ public function setCellSpacing($value)
+ {
+ $this->getStyle()->setCellSpacing($value);
+ }
+
+ /**
+ * @return integer the cellpadding for the table. Defaults to -1, meaning not set.
+ */
+ public function getCellPadding()
+ {
+ if($this->getHasStyle())
+ return $this->getStyle()->getCellPadding();
+ else
+ return -1;
+ }
+
+ /**
+ * @param integer the cellpadding for the table. Defaults to -1, meaning not set.
+ */
+ public function setCellPadding($value)
+ {
+ $this->getStyle()->setCellPadding($value);
+ }
+
+ /**
+ * @return THorizontalAlign the horizontal alignment of the table content. Defaults to THorizontalAlign::NotSet.
+ */
+ public function getHorizontalAlign()
+ {
+ if($this->getHasStyle())
+ return $this->getStyle()->getHorizontalAlign();
+ else
+ return THorizontalAlign::NotSet;
+ }
+
+ /**
+ * @param THorizontalAlign the horizontal alignment of the table content.
+ */
+ public function setHorizontalAlign($value)
+ {
+ $this->getStyle()->setHorizontalAlign($value);
+ }
+
+ /**
+ * @return TTableGridLines the grid line setting of the table. Defaults to TTableGridLines::None.
+ */
+ public function getGridLines()
+ {
+ if($this->getHasStyle())
+ return $this->getStyle()->getGridLines();
+ else
+ return TTableGridLines::None;
+ }
+
+ /**
+ * @param TTableGridLines the grid line setting of the table
+ */
+ public function setGridLines($value)
+ {
+ $this->getStyle()->setGridLines($value);
+ }
+
+ /**
+ * @return string the URL of the background image for the table
+ */
+ public function getBackImageUrl()
+ {
+ if($this->getHasStyle())
+ return $this->getStyle()->getBackImageUrl();
+ else
+ return '';
+ }
+
+ /**
+ * Sets the URL of the background image for the table
+ * @param string the URL
+ */
+ public function setBackImageUrl($value)
+ {
+ $this->getStyle()->setBackImageUrl($value);
+ }
+
+ /**
+ * Renders the openning tag for the table control which will render table caption if present.
+ * @param THtmlWriter the writer used for the rendering purpose
+ */
+ public function renderBeginTag($writer)
+ {
+ parent::renderBeginTag($writer);
+ if(($caption=$this->getCaption())!=='')
+ {
+ if(($align=$this->getCaptionAlign())!==TTableCaptionAlign::NotSet)
+ $writer->addAttribute('align',strtolower($align));
+ $writer->renderBeginTag('caption');
+ $writer->write($caption);
+ $writer->renderEndTag();
+ }
+ }
+
+ /**
+ * Renders body contents of the table.
+ * @param THtmlWriter the writer used for the rendering purpose.
+ */
+ public function renderContents($writer)
+ {
+ if($this->getHasControls())
+ {
+ $renderTableSection=false;
+ foreach($this->getControls() as $row)
+ {
+ if($row->getTableSection()!==TTableRowSection::Body)
+ {
+ $renderTableSection=true;
+ break;
+ }
+ }
+ if($renderTableSection)
+ {
+ $currentSection=TTableRowSection::Header;
+ $writer->writeLine();
+ foreach($this->getControls() as $index=>$row)
+ {
+ if(($section=$row->getTableSection())===$currentSection)
+ {
+ if($index===0 && $currentSection===TTableRowSection::Header)
+ $writer->renderBeginTag('thead');
+ }
+ else
+ {
+ if($currentSection===TTableRowSection::Header)
+ {
+ if($index>0)
+ $writer->renderEndTag();
+ if($section===TTableRowSection::Body)
+ $writer->renderBeginTag('tbody');
+ else
+ $writer->renderBeginTag('tfoot');
+ $currentSection=$section;
+ }
+ else if($currentSection===TTableRowSection::Body)
+ {
+ $writer->renderEndTag();
+ if($section===TTableRowSection::Footer)
+ $writer->renderBeginTag('tfoot');
+ else
+ throw new TConfigurationException('table_tablesection_outoforder');
+ $currentSection=$section;
+ }
+ else // Footer
+ throw new TConfigurationException('table_tablesection_outoforder');
+ }
+ $row->renderControl($writer);
+ $writer->writeLine();
+ }
+ $writer->renderEndTag();
+ }
+ else
+ {
+ $writer->writeLine();
+ foreach($this->getControls() as $row)
+ {
+ $row->renderControl($writer);
+ $writer->writeLine();
+ }
+ }
+ }
+ }
+}
+
+
+/**
+ * TTableRowCollection class.
+ *
+ * TTableRowCollection is used to maintain a list of rows belong to a table.
+ *
+ * @author Qiang Xue <qiang.xue@gmail.com>
+ * @version $Id$
+ * @package System.Web.UI.WebControls
+ * @since 3.0
+ */
+class TTableRowCollection extends TControlCollection
+{
+ /**
+ * Inserts an item at the specified position.
+ * This overrides the parent implementation by performing additional
+ * operations for each newly added table row.
+ * @param integer the speicified position.
+ * @param mixed new item
+ * @throws TInvalidDataTypeException if the item to be inserted is not a TTableRow object.
+ */
+ public function insertAt($index,$item)
+ {
+ if($item instanceof TTableRow)
+ parent::insertAt($index,$item);
+ else
+ throw new TInvalidDataTypeException('tablerowcollection_tablerow_required');
+ }
+}
+
+
+/**
+ * TTableCaptionAlign class.
+ * TTableCaptionAlign defines the enumerable type for the possible alignments
+ * that a table caption can take.
+ *
+ * The following enumerable values are defined:
+ * - NotSet: alignment not specified
+ * - Top: top aligned
+ * - Bottom: bottom aligned
+ * - Left: left aligned
+ * - Right: right aligned
+ *
+ * @author Qiang Xue <qiang.xue@gmail.com>
+ * @version $Id$
+ * @package System.Web.UI.WebControls
+ * @since 3.0.4
+ */
+class TTableCaptionAlign extends TEnumerable
+{
+ const NotSet='NotSet';
+ const Top='Top';
+ const Bottom='Bottom';
+ const Left='Left';
+ const Right='Right';
+}
+
diff --git a/framework/Web/UI/WebControls/TTableCell.php b/framework/Web/UI/WebControls/TTableCell.php
index 6b43990b..70ff573f 100644
--- a/framework/Web/UI/WebControls/TTableCell.php
+++ b/framework/Web/UI/WebControls/TTableCell.php
@@ -1,222 +1,222 @@
-<?php
-/**
- * TTableCell class file
- *
- * @author Qiang Xue <qiang.xue@gmail.com>
- * @link http://www.pradosoft.com/
+<?php
+/**
+ * TTableCell class file
+ *
+ * @author Qiang Xue <qiang.xue@gmail.com>
+ * @link http://www.pradosoft.com/
* @copyright Copyright &copy; 2005-2012 PradoSoft
- * @license http://www.pradosoft.com/license/
- * @version $Id$
- * @package System.Web.UI.WebControls
- */
-
-/**
- * TTableCell class.
- *
- * TTableCell displays a table cell on a Web page. Content of the table cell
- * is specified by the {@link setText Text} property. If {@link setText Text}
- * is empty, the body contents enclosed by the table cell component tag are rendered.
- * Note, {@link setText Text} is not HTML-encoded when displayed. So make sure
- * it does not contain dangerous characters.
- *
- * The horizontal and vertical alignments of the contents in the cell
- * are specified via {@link setHorizontalAlign HorizontalAlign} and
- * {@link setVerticalAlign VerticalAlign} properties, respectively.
- *
- * The colspan and rowspan of the cell are specified via {@link setColumnSpan ColumnSpan}
- * and {@link setRowSpan RowSpan} properties. And the {@link setWrap Wrap} property
- * indicates whether the contents in the cell should be wrapped.
- *
- * @author Qiang Xue <qiang.xue@gmail.com>
- * @version $Id$
- * @package System.Web.UI.WebControls
- * @since 3.0
- */
-class TTableCell extends TWebControl implements IDataRenderer
-{
- /**
- * @return string tag name for the table cell
- */
- protected function getTagName()
- {
- return 'td';
- }
-
- /**
- * Creates a style object for the control.
- * This method creates a {@link TTableItemStyle} to be used by the table cell.
- * @return TStyle control style to be used
- */
- protected function createStyle()
- {
- return new TTableItemStyle;
- }
-
- /**
- * @return string the horizontal alignment of the contents within the table item, defaults to 'NotSet'.
- */
- public function getHorizontalAlign()
- {
- if($this->getHasStyle())
- return $this->getStyle()->getHorizontalAlign();
- else
- return 'NotSet';
- }
-
- /**
- * Sets the horizontal alignment of the contents within the table item.
- * Valid values include 'NotSet', 'Justify', 'Left', 'Right', 'Center'
- * @param string the horizontal alignment
- */
- public function setHorizontalAlign($value)
- {
- $this->getStyle()->setHorizontalAlign($value);
- }
-
- /**
- * @return string the vertical alignment of the contents within the table item, defaults to 'NotSet'.
- */
- public function getVerticalAlign()
- {
- if($this->getHasStyle())
- return $this->getStyle()->getVerticalAlign();
- else
- return 'NotSet';
- }
-
- /**
- * Sets the vertical alignment of the contents within the table item.
- * Valid values include 'NotSet','Top','Bottom','Middle'
- * @param string the horizontal alignment
- */
- public function setVerticalAlign($value)
- {
- $this->getStyle()->setVerticalAlign($value);
- }
-
- /**
- * @return integer the columnspan for the table cell, 0 if not set.
- */
- public function getColumnSpan()
- {
- return $this->getViewState('ColumnSpan', 0);
- }
-
- /**
- * Sets the columnspan for the table cell.
- * @param integer the columnspan for the table cell, 0 if not set.
- */
- public function setColumnSpan($value)
- {
- $this->setViewState('ColumnSpan', TPropertyValue::ensureInteger($value), 0);
- }
-
- /**
- * @return integer the rowspan for the table cell, 0 if not set.
- */
- public function getRowSpan()
- {
- return $this->getViewState('RowSpan', 0);
- }
-
- /**
- * Sets the rowspan for the table cell.
- * @param integer the rowspan for the table cell, 0 if not set.
- */
- public function setRowSpan($value)
- {
- $this->setViewState('RowSpan', TPropertyValue::ensureInteger($value), 0);
- }
-
- /**
- * @return boolean whether the text content wraps within a table cell. Defaults to true.
- */
- public function getWrap()
- {
- if($this->getHasStyle())
- return $this->getStyle()->getWrap();
- else
- return true;
- }
-
- /**
- * Sets the value indicating whether the text content wraps within a table cell.
- * @param boolean whether the text content wraps within a table cell.
- */
- public function setWrap($value)
- {
- $this->getStyle()->setWrap($value);
- }
-
- /**
- * @return string the text content of the table cell.
- */
- public function getText()
- {
- return $this->getViewState('Text','');
- }
-
- /**
- * Sets the text content of the table cell.
- * If the text content is empty, body content (child controls) of the cell will be rendered.
- * @param string the text content
- */
- public function setText($value)
- {
- $this->setViewState('Text',$value,'');
- }
-
- /**
- * Returns the text content of the table cell.
- * This method is required by {@link IDataRenderer}.
- * It is the same as {@link getText()}.
- * @return string the text content of the table cell.
- * @see getText
- * @since 3.1.0
- */
- public function getData()
- {
- return $this->getText();
- }
-
- /**
- * Sets the text content of the table cell.
- * This method is required by {@link IDataRenderer}.
- * It is the same as {@link setText()}.
- * @param string the text content of the table cell.
- * @see setText
- * @since 3.1.0
- */
- public function setData($value)
- {
- $this->setText($value);
- }
-
- /**
- * Adds attributes to renderer.
- * @param THtmlWriter the renderer
- */
- protected function addAttributesToRender($writer)
- {
- parent::addAttributesToRender($writer);
- if(($colspan=$this->getColumnSpan())>0)
- $writer->addAttribute('colspan',"$colspan");
- if(($rowspan=$this->getRowSpan())>0)
- $writer->addAttribute('rowspan',"$rowspan");
- }
-
- /**
- * Renders body contents of the table cell.
- * @param THtmlWriter the writer used for the rendering purpose.
- */
- public function renderContents($writer)
- {
- if(($text=$this->getText())!=='')
- $writer->write($text);
- else if($this->getHasControls())
- parent::renderContents($writer);
- else
- $writer->write('&nbsp;');
- }
-}
-
+ * @license http://www.pradosoft.com/license/
+ * @version $Id$
+ * @package System.Web.UI.WebControls
+ */
+
+/**
+ * TTableCell class.
+ *
+ * TTableCell displays a table cell on a Web page. Content of the table cell
+ * is specified by the {@link setText Text} property. If {@link setText Text}
+ * is empty, the body contents enclosed by the table cell component tag are rendered.
+ * Note, {@link setText Text} is not HTML-encoded when displayed. So make sure
+ * it does not contain dangerous characters.
+ *
+ * The horizontal and vertical alignments of the contents in the cell
+ * are specified via {@link setHorizontalAlign HorizontalAlign} and
+ * {@link setVerticalAlign VerticalAlign} properties, respectively.
+ *
+ * The colspan and rowspan of the cell are specified via {@link setColumnSpan ColumnSpan}
+ * and {@link setRowSpan RowSpan} properties. And the {@link setWrap Wrap} property
+ * indicates whether the contents in the cell should be wrapped.
+ *
+ * @author Qiang Xue <qiang.xue@gmail.com>
+ * @version $Id$
+ * @package System.Web.UI.WebControls
+ * @since 3.0
+ */
+class TTableCell extends TWebControl implements IDataRenderer
+{
+ /**
+ * @return string tag name for the table cell
+ */
+ protected function getTagName()
+ {
+ return 'td';
+ }
+
+ /**
+ * Creates a style object for the control.
+ * This method creates a {@link TTableItemStyle} to be used by the table cell.
+ * @return TStyle control style to be used
+ */
+ protected function createStyle()
+ {
+ return new TTableItemStyle;
+ }
+
+ /**
+ * @return string the horizontal alignment of the contents within the table item, defaults to 'NotSet'.
+ */
+ public function getHorizontalAlign()
+ {
+ if($this->getHasStyle())
+ return $this->getStyle()->getHorizontalAlign();
+ else
+ return 'NotSet';
+ }
+
+ /**
+ * Sets the horizontal alignment of the contents within the table item.
+ * Valid values include 'NotSet', 'Justify', 'Left', 'Right', 'Center'
+ * @param string the horizontal alignment
+ */
+ public function setHorizontalAlign($value)
+ {
+ $this->getStyle()->setHorizontalAlign($value);
+ }
+
+ /**
+ * @return string the vertical alignment of the contents within the table item, defaults to 'NotSet'.
+ */
+ public function getVerticalAlign()
+ {
+ if($this->getHasStyle())
+ return $this->getStyle()->getVerticalAlign();
+ else
+ return 'NotSet';
+ }
+
+ /**
+ * Sets the vertical alignment of the contents within the table item.
+ * Valid values include 'NotSet','Top','Bottom','Middle'
+ * @param string the horizontal alignment
+ */
+ public function setVerticalAlign($value)
+ {
+ $this->getStyle()->setVerticalAlign($value);
+ }
+
+ /**
+ * @return integer the columnspan for the table cell, 0 if not set.
+ */
+ public function getColumnSpan()
+ {
+ return $this->getViewState('ColumnSpan', 0);
+ }
+
+ /**
+ * Sets the columnspan for the table cell.
+ * @param integer the columnspan for the table cell, 0 if not set.
+ */
+ public function setColumnSpan($value)
+ {
+ $this->setViewState('ColumnSpan', TPropertyValue::ensureInteger($value), 0);
+ }
+
+ /**
+ * @return integer the rowspan for the table cell, 0 if not set.
+ */
+ public function getRowSpan()
+ {
+ return $this->getViewState('RowSpan', 0);
+ }
+
+ /**
+ * Sets the rowspan for the table cell.
+ * @param integer the rowspan for the table cell, 0 if not set.
+ */
+ public function setRowSpan($value)
+ {
+ $this->setViewState('RowSpan', TPropertyValue::ensureInteger($value), 0);
+ }
+
+ /**
+ * @return boolean whether the text content wraps within a table cell. Defaults to true.
+ */
+ public function getWrap()
+ {
+ if($this->getHasStyle())
+ return $this->getStyle()->getWrap();
+ else
+ return true;
+ }
+
+ /**
+ * Sets the value indicating whether the text content wraps within a table cell.
+ * @param boolean whether the text content wraps within a table cell.
+ */
+ public function setWrap($value)
+ {
+ $this->getStyle()->setWrap($value);
+ }
+
+ /**
+ * @return string the text content of the table cell.
+ */
+ public function getText()
+ {
+ return $this->getViewState('Text','');
+ }
+
+ /**
+ * Sets the text content of the table cell.
+ * If the text content is empty, body content (child controls) of the cell will be rendered.
+ * @param string the text content
+ */
+ public function setText($value)
+ {
+ $this->setViewState('Text',$value,'');
+ }
+
+ /**
+ * Returns the text content of the table cell.
+ * This method is required by {@link IDataRenderer}.
+ * It is the same as {@link getText()}.
+ * @return string the text content of the table cell.
+ * @see getText
+ * @since 3.1.0
+ */
+ public function getData()
+ {
+ return $this->getText();
+ }
+
+ /**
+ * Sets the text content of the table cell.
+ * This method is required by {@link IDataRenderer}.
+ * It is the same as {@link setText()}.
+ * @param string the text content of the table cell.
+ * @see setText
+ * @since 3.1.0
+ */
+ public function setData($value)
+ {
+ $this->setText($value);
+ }
+
+ /**
+ * Adds attributes to renderer.
+ * @param THtmlWriter the renderer
+ */
+ protected function addAttributesToRender($writer)
+ {
+ parent::addAttributesToRender($writer);
+ if(($colspan=$this->getColumnSpan())>0)
+ $writer->addAttribute('colspan',"$colspan");
+ if(($rowspan=$this->getRowSpan())>0)
+ $writer->addAttribute('rowspan',"$rowspan");
+ }
+
+ /**
+ * Renders body contents of the table cell.
+ * @param THtmlWriter the writer used for the rendering purpose.
+ */
+ public function renderContents($writer)
+ {
+ if(($text=$this->getText())!=='')
+ $writer->write($text);
+ else if($this->getHasControls())
+ parent::renderContents($writer);
+ else
+ $writer->write('&nbsp;');
+ }
+}
+
diff --git a/framework/Web/UI/WebControls/TTableFooterRow.php b/framework/Web/UI/WebControls/TTableFooterRow.php
index 84bc29f1..1387c385 100644
--- a/framework/Web/UI/WebControls/TTableFooterRow.php
+++ b/framework/Web/UI/WebControls/TTableFooterRow.php
@@ -1,47 +1,47 @@
-<?php
-/**
- * TTableFooterRow class file
- *
- * @author Qiang Xue <qiang.xue@gmail.com>
- * @link http://www.pradosoft.com/
+<?php
+/**
+ * TTableFooterRow class file
+ *
+ * @author Qiang Xue <qiang.xue@gmail.com>
+ * @link http://www.pradosoft.com/
* @copyright Copyright &copy; 2005-2012 PradoSoft
- * @license http://www.pradosoft.com/license/
- * @version $Id$
- * @package System.Web.UI.WebControls
- */
-
-/**
- * Includes TTableRow class.
- */
-Prado::using('System.Web.UI.WebControls.TTableRow');
-
-/**
- * TTableFooterRow class.
- *
- * TTableFooterRow displays a table footer row.
- *
- * @author Qiang Xue <qiang.xue@gmail.com>
- * @version $Id$
- * @package System.Web.UI.WebControls
- * @since 3.0.1
- */
-class TTableFooterRow extends TTableRow
-{
- /**
- * @return string location of a row in a table. Always returns 'Footer'.
- */
- public function getTableSection()
- {
- return 'Footer';
- }
-
- /**
- * @param string location of a row in a table.
- * @throws TInvalidOperationException if this method is invoked
- */
- public function setTableSection($value)
- {
- throw new TInvalidOperationException('tablefooterrow_tablesection_readonly');
- }
-}
-
+ * @license http://www.pradosoft.com/license/
+ * @version $Id$
+ * @package System.Web.UI.WebControls
+ */
+
+/**
+ * Includes TTableRow class.
+ */
+Prado::using('System.Web.UI.WebControls.TTableRow');
+
+/**
+ * TTableFooterRow class.
+ *
+ * TTableFooterRow displays a table footer row.
+ *
+ * @author Qiang Xue <qiang.xue@gmail.com>
+ * @version $Id$
+ * @package System.Web.UI.WebControls
+ * @since 3.0.1
+ */
+class TTableFooterRow extends TTableRow
+{
+ /**
+ * @return string location of a row in a table. Always returns 'Footer'.
+ */
+ public function getTableSection()
+ {
+ return 'Footer';
+ }
+
+ /**
+ * @param string location of a row in a table.
+ * @throws TInvalidOperationException if this method is invoked
+ */
+ public function setTableSection($value)
+ {
+ throw new TInvalidOperationException('tablefooterrow_tablesection_readonly');
+ }
+}
+
diff --git a/framework/Web/UI/WebControls/TTableHeaderCell.php b/framework/Web/UI/WebControls/TTableHeaderCell.php
index bbf3e58a..72eae44e 100644
--- a/framework/Web/UI/WebControls/TTableHeaderCell.php
+++ b/framework/Web/UI/WebControls/TTableHeaderCell.php
@@ -1,124 +1,124 @@
-<?php
-/**
- * TTableHeaderCell class file
- *
- * @author Qiang Xue <qiang.xue@gmail.com>
- * @link http://www.pradosoft.com/
+<?php
+/**
+ * TTableHeaderCell class file
+ *
+ * @author Qiang Xue <qiang.xue@gmail.com>
+ * @link http://www.pradosoft.com/
* @copyright Copyright &copy; 2005-2012 PradoSoft
- * @license http://www.pradosoft.com/license/
- * @version $Id$
- * @package System.Web.UI.WebControls
- */
-
-/**
- * Includes TTableCell class
- */
-Prado::using('System.Web.UI.WebControls.TTableCell');
-
-
-/**
- * TTableHeaderCell class.
- *
- * TTableHeaderCell displays a table header cell on a Web page.
- *
- * @author Qiang Xue <qiang.xue@gmail.com>
- * @version $Id$
- * @package System.Web.UI.WebControls
- * @since 3.0
- */
-class TTableHeaderCell extends TTableCell
-{
- /**
- * @return string tag name for the table header cell
- */
- protected function getTagName()
- {
- return 'th';
- }
-
- /**
- * Adds attributes to renderer.
- * @param THtmlWriter the renderer
- */
- protected function addAttributesToRender($writer)
- {
- parent::addAttributesToRender($writer);
- if(($scope=$this->getScope())!==TTableHeaderScope::NotSet)
- $writer->addAttribute('scope',$scope===TTableHeaderScope::Row?'row':'col');
- if(($text=$this->getAbbreviatedText())!=='')
- $writer->addAttribute('abbr',$text);
- if(($text=$this->getCategoryText())!=='')
- $writer->addAttribute('axis',$text);
- }
-
- /**
- * @return TTableHeaderScope the scope of the cells that the header cell applies to. Defaults to TTableHeaderScope::NotSet.
- */
- public function getScope()
- {
- return $this->getViewState('Scope',TTableHeaderScope::NotSet);
- }
-
- /**
- * @param TTableHeaderScope the scope of the cells that the header cell applies to.
- */
- public function setScope($value)
- {
- $this->setViewState('Scope',TPropertyValue::ensureEnum($value,'TTableHeaderScope'),TTableHeaderScope::NotSet);
- }
-
- /**
- * @return string the abbr attribute of the HTML th element
- */
- public function getAbbreviatedText()
- {
- return $this->getViewState('AbbreviatedText','');
- }
-
- /**
- * @param string the abbr attribute of the HTML th element
- */
- public function setAbbreviatedText($value)
- {
- $this->setViewState('AbbreviatedText',$value,'');
- }
-
- /**
- * @return string the axis attribute of the HTML th element
- */
- public function getCategoryText()
- {
- return $this->getViewState('CategoryText','');
- }
-
- /**
- * @param string the axis attribute of the HTML th element
- */
- public function setCategoryText($value)
- {
- $this->setViewState('CategoryText',$value,'');
- }
-}
-
-
-/**
- * TTableHeaderScope class.
- * TTableHeaderScope defines the enumerable type for the possible table scopes that a table header is associated with.
- *
- * The following enumerable values are defined:
- * - NotSet: the scope is not specified
- * - Row: the scope is row-wise
- * - Column: the scope is column-wise
- *
- * @author Qiang Xue <qiang.xue@gmail.com>
- * @version $Id$
- * @package System.Web.UI.WebControls
- * @since 3.0.4
- */
-class TTableHeaderScope extends TEnumerable
-{
- const NotSet='NotSet';
- const Row='Row';
- const Column='Column';
-}
-
+ * @license http://www.pradosoft.com/license/
+ * @version $Id$
+ * @package System.Web.UI.WebControls
+ */
+
+/**
+ * Includes TTableCell class
+ */
+Prado::using('System.Web.UI.WebControls.TTableCell');
+
+
+/**
+ * TTableHeaderCell class.
+ *
+ * TTableHeaderCell displays a table header cell on a Web page.
+ *
+ * @author Qiang Xue <qiang.xue@gmail.com>
+ * @version $Id$
+ * @package System.Web.UI.WebControls
+ * @since 3.0
+ */
+class TTableHeaderCell extends TTableCell
+{
+ /**
+ * @return string tag name for the table header cell
+ */
+ protected function getTagName()
+ {
+ return 'th';
+ }
+
+ /**
+ * Adds attributes to renderer.
+ * @param THtmlWriter the renderer
+ */
+ protected function addAttributesToRender($writer)
+ {
+ parent::addAttributesToRender($writer);
+ if(($scope=$this->getScope())!==TTableHeaderScope::NotSet)
+ $writer->addAttribute('scope',$scope===TTableHeaderScope::Row?'row':'col');
+ if(($text=$this->getAbbreviatedText())!=='')
+ $writer->addAttribute('abbr',$text);
+ if(($text=$this->getCategoryText())!=='')
+ $writer->addAttribute('axis',$text);
+ }
+
+ /**
+ * @return TTableHeaderScope the scope of the cells that the header cell applies to. Defaults to TTableHeaderScope::NotSet.
+ */
+ public function getScope()
+ {
+ return $this->getViewState('Scope',TTableHeaderScope::NotSet);
+ }
+
+ /**
+ * @param TTableHeaderScope the scope of the cells that the header cell applies to.
+ */
+ public function setScope($value)
+ {
+ $this->setViewState('Scope',TPropertyValue::ensureEnum($value,'TTableHeaderScope'),TTableHeaderScope::NotSet);
+ }
+
+ /**
+ * @return string the abbr attribute of the HTML th element
+ */
+ public function getAbbreviatedText()
+ {
+ return $this->getViewState('AbbreviatedText','');
+ }
+
+ /**
+ * @param string the abbr attribute of the HTML th element
+ */
+ public function setAbbreviatedText($value)
+ {
+ $this->setViewState('AbbreviatedText',$value,'');
+ }
+
+ /**
+ * @return string the axis attribute of the HTML th element
+ */
+ public function getCategoryText()
+ {
+ return $this->getViewState('CategoryText','');
+ }
+
+ /**
+ * @param string the axis attribute of the HTML th element
+ */
+ public function setCategoryText($value)
+ {
+ $this->setViewState('CategoryText',$value,'');
+ }
+}
+
+
+/**
+ * TTableHeaderScope class.
+ * TTableHeaderScope defines the enumerable type for the possible table scopes that a table header is associated with.
+ *
+ * The following enumerable values are defined:
+ * - NotSet: the scope is not specified
+ * - Row: the scope is row-wise
+ * - Column: the scope is column-wise
+ *
+ * @author Qiang Xue <qiang.xue@gmail.com>
+ * @version $Id$
+ * @package System.Web.UI.WebControls
+ * @since 3.0.4
+ */
+class TTableHeaderScope extends TEnumerable
+{
+ const NotSet='NotSet';
+ const Row='Row';
+ const Column='Column';
+}
+
diff --git a/framework/Web/UI/WebControls/TTableHeaderRow.php b/framework/Web/UI/WebControls/TTableHeaderRow.php
index 448902dc..2c05b94d 100644
--- a/framework/Web/UI/WebControls/TTableHeaderRow.php
+++ b/framework/Web/UI/WebControls/TTableHeaderRow.php
@@ -1,47 +1,47 @@
-<?php
-/**
- * TTableHeaderRow class file
- *
- * @author Qiang Xue <qiang.xue@gmail.com>
- * @link http://www.pradosoft.com/
+<?php
+/**
+ * TTableHeaderRow class file
+ *
+ * @author Qiang Xue <qiang.xue@gmail.com>
+ * @link http://www.pradosoft.com/
* @copyright Copyright &copy; 2005-2012 PradoSoft
- * @license http://www.pradosoft.com/license/
- * @version $Id$
- * @package System.Web.UI.WebControls
- */
-
-/**
- * Includes TTableRow class.
- */
-Prado::using('System.Web.UI.WebControls.TTableRow');
-
-/**
- * TTableHeaderRow class.
- *
- * TTableHeaderRow displays a table header row.
- *
- * @author Qiang Xue <qiang.xue@gmail.com>
- * @version $Id$
- * @package System.Web.UI.WebControls
- * @since 3.0.1
- */
-class TTableHeaderRow extends TTableRow
-{
- /**
- * @return string location of a row in a table. Always returns 'Header'.
- */
- public function getTableSection()
- {
- return 'Header';
- }
-
- /**
- * @param string location of a row in a table.
- * @throws TInvalidOperationException if this method is invoked
- */
- public function setTableSection($value)
- {
- throw new TInvalidOperationException('tableheaderrow_tablesection_readonly');
- }
-}
-
+ * @license http://www.pradosoft.com/license/
+ * @version $Id$
+ * @package System.Web.UI.WebControls
+ */
+
+/**
+ * Includes TTableRow class.
+ */
+Prado::using('System.Web.UI.WebControls.TTableRow');
+
+/**
+ * TTableHeaderRow class.
+ *
+ * TTableHeaderRow displays a table header row.
+ *
+ * @author Qiang Xue <qiang.xue@gmail.com>
+ * @version $Id$
+ * @package System.Web.UI.WebControls
+ * @since 3.0.1
+ */
+class TTableHeaderRow extends TTableRow
+{
+ /**
+ * @return string location of a row in a table. Always returns 'Header'.
+ */
+ public function getTableSection()
+ {
+ return 'Header';
+ }
+
+ /**
+ * @param string location of a row in a table.
+ * @throws TInvalidOperationException if this method is invoked
+ */
+ public function setTableSection($value)
+ {
+ throw new TInvalidOperationException('tableheaderrow_tablesection_readonly');
+ }
+}
+
diff --git a/framework/Web/UI/WebControls/TTableRow.php b/framework/Web/UI/WebControls/TTableRow.php
index e50099bf..3cfc82d0 100644
--- a/framework/Web/UI/WebControls/TTableRow.php
+++ b/framework/Web/UI/WebControls/TTableRow.php
@@ -1,208 +1,208 @@
-<?php
-/**
- * TTableRow and TTableCellCollection class file
- *
- * @author Qiang Xue <qiang.xue@gmail.com>
- * @link http://www.pradosoft.com/
+<?php
+/**
+ * TTableRow and TTableCellCollection class file
+ *
+ * @author Qiang Xue <qiang.xue@gmail.com>
+ * @link http://www.pradosoft.com/
* @copyright Copyright &copy; 2005-2012 PradoSoft
- * @license http://www.pradosoft.com/license/
- * @version $Id$
- * @package System.Web.UI.WebControls
- */
-
-/**
- * Includes TTableCell class
- */
-Prado::using('System.Web.UI.WebControls.TTableCell');
-
-/**
- * TTableRow class.
- *
- * TTableRow displays a table row. The table cells in the row can be accessed
- * via {@link getCells Cells}. The horizontal and vertical alignments of the row
- * are specified via {@link setHorizontalAlign HorizontalAlign} and
- * {@link setVerticalAlign VerticalAlign} properties, respectively.
- *
- * @author Qiang Xue <qiang.xue@gmail.com>
- * @version $Id$
- * @package System.Web.UI.WebControls
- * @since 3.0
- */
-class TTableRow extends TWebControl
-{
- /**
- * @return string tag name for the table
- */
- protected function getTagName()
- {
- return 'tr';
- }
-
- /**
- * Adds object parsed from template to the control.
- * This method adds only {@link TTableCell} objects into the {@link getCells Cells} collection.
- * All other objects are ignored.
- * @param mixed object parsed from template
- */
- public function addParsedObject($object)
- {
- if($object instanceof TTableCell)
- $this->getCells()->add($object);
- }
-
- /**
- * Creates a style object for the control.
- * This method creates a {@link TTableItemStyle} to be used by the table row.
- * @return TStyle control style to be used
- */
- protected function createStyle()
- {
- return new TTableItemStyle;
- }
-
- /**
- * Creates a control collection object that is to be used to hold child controls
- * @return TTableCellCollection control collection
- * @see getControls
- */
- protected function createControlCollection()
- {
- return new TTableCellCollection($this);
- }
-
- /**
- * @return TTableCellCollection list of {@link TTableCell} controls
- */
- public function getCells()
- {
- return $this->getControls();
- }
-
- /**
- * @return string the horizontal alignment of the contents within the table item, defaults to 'NotSet'.
- */
- public function getHorizontalAlign()
- {
- if($this->getHasStyle())
- return $this->getStyle()->getHorizontalAlign();
- else
- return 'NotSet';
- }
-
- /**
- * Sets the horizontal alignment of the contents within the table item.
- * Valid values include 'NotSet', 'Justify', 'Left', 'Right', 'Center'
- * @param string the horizontal alignment
- */
- public function setHorizontalAlign($value)
- {
- $this->getStyle()->setHorizontalAlign($value);
- }
-
- /**
- * @return string the vertical alignment of the contents within the table item, defaults to 'NotSet'.
- */
- public function getVerticalAlign()
- {
- if($this->getHasStyle())
- return $this->getStyle()->getVerticalAlign();
- else
- return 'NotSet';
- }
-
- /**
- * Sets the vertical alignment of the contents within the table item.
- * Valid values include 'NotSet','Top','Bottom','Middle'
- * @param string the horizontal alignment
- */
- public function setVerticalAlign($value)
- {
- $this->getStyle()->setVerticalAlign($value);
- }
-
- /**
- * @return TTableRowSection location of a row in a table. Defaults to TTableRowSection::Body.
- */
- public function getTableSection()
- {
- return $this->getViewState('TableSection',TTableRowSection::Body);
- }
-
- /**
- * @param TTableRowSection location of a row in a table.
- */
- public function setTableSection($value)
- {
- $this->setViewState('TableSection',TPropertyValue::ensureEnum($value,'TTableRowSection'),TTableRowSection::Body);
- }
-
- /**
- * Renders body contents of the table row
- * @param THtmlWriter writer for the rendering purpose
- */
- public function renderContents($writer)
- {
- if($this->getHasControls())
- {
- $writer->writeLine();
- foreach($this->getControls() as $cell)
- {
- $cell->renderControl($writer);
- $writer->writeLine();
- }
- }
- }
-}
-
-/**
- * TTableCellCollection class.
- *
- * TTableCellCollection is used to maintain a list of cells belong to a table row.
- *
- * @author Qiang Xue <qiang.xue@gmail.com>
- * @version $Id$
- * @package System.Web.UI.WebControls
- * @since 3.0
- */
-class TTableCellCollection extends TControlCollection
-{
- /**
- * Inserts an item at the specified position.
- * This overrides the parent implementation by performing additional
- * operations for each newly added table cell.
- * @param integer the speicified position.
- * @param mixed new item
- * @throws TInvalidDataTypeException if the item to be inserted is not a TTableCell object.
- */
- public function insertAt($index,$item)
- {
- if($item instanceof TTableCell)
- parent::insertAt($index,$item);
- else
- throw new TInvalidDataTypeException('tablecellcollection_tablecell_required');
- }
-}
-
-
-/**
- * TTableRowSection class.
- * TTableRowSection defines the enumerable type for the possible table sections
- * that a {@link TTableRow} can be within.
- *
- * The following enumerable values are defined:
- * - Header: in table header
- * - Body: in table body
- * - Footer: in table footer
- *
- * @author Qiang Xue <qiang.xue@gmail.com>
- * @version $Id$
- * @package System.Web.UI.WebControls
- * @since 3.0.4
- */
-class TTableRowSection extends TEnumerable
-{
- const Header='Header';
- const Body='Body';
- const Footer='Footer';
-}
-
+ * @license http://www.pradosoft.com/license/
+ * @version $Id$
+ * @package System.Web.UI.WebControls
+ */
+
+/**
+ * Includes TTableCell class
+ */
+Prado::using('System.Web.UI.WebControls.TTableCell');
+
+/**
+ * TTableRow class.
+ *
+ * TTableRow displays a table row. The table cells in the row can be accessed
+ * via {@link getCells Cells}. The horizontal and vertical alignments of the row
+ * are specified via {@link setHorizontalAlign HorizontalAlign} and
+ * {@link setVerticalAlign VerticalAlign} properties, respectively.
+ *
+ * @author Qiang Xue <qiang.xue@gmail.com>
+ * @version $Id$
+ * @package System.Web.UI.WebControls
+ * @since 3.0
+ */
+class TTableRow extends TWebControl
+{
+ /**
+ * @return string tag name for the table
+ */
+ protected function getTagName()
+ {
+ return 'tr';
+ }
+
+ /**
+ * Adds object parsed from template to the control.
+ * This method adds only {@link TTableCell} objects into the {@link getCells Cells} collection.
+ * All other objects are ignored.
+ * @param mixed object parsed from template
+ */
+ public function addParsedObject($object)
+ {
+ if($object instanceof TTableCell)
+ $this->getCells()->add($object);
+ }
+
+ /**
+ * Creates a style object for the control.
+ * This method creates a {@link TTableItemStyle} to be used by the table row.
+ * @return TStyle control style to be used
+ */
+ protected function createStyle()
+ {
+ return new TTableItemStyle;
+ }
+
+ /**
+ * Creates a control collection object that is to be used to hold child controls
+ * @return TTableCellCollection control collection
+ * @see getControls
+ */
+ protected function createControlCollection()
+ {
+ return new TTableCellCollection($this);
+ }
+
+ /**
+ * @return TTableCellCollection list of {@link TTableCell} controls
+ */
+ public function getCells()
+ {
+ return $this->getControls();
+ }
+
+ /**
+ * @return string the horizontal alignment of the contents within the table item, defaults to 'NotSet'.
+ */
+ public function getHorizontalAlign()
+ {
+ if($this->getHasStyle())
+ return $this->getStyle()->getHorizontalAlign();
+ else
+ return 'NotSet';
+ }
+
+ /**
+ * Sets the horizontal alignment of the contents within the table item.
+ * Valid values include 'NotSet', 'Justify', 'Left', 'Right', 'Center'
+ * @param string the horizontal alignment
+ */
+ public function setHorizontalAlign($value)
+ {
+ $this->getStyle()->setHorizontalAlign($value);
+ }
+
+ /**
+ * @return string the vertical alignment of the contents within the table item, defaults to 'NotSet'.
+ */
+ public function getVerticalAlign()
+ {
+ if($this->getHasStyle())
+ return $this->getStyle()->getVerticalAlign();
+ else
+ return 'NotSet';
+ }
+
+ /**
+ * Sets the vertical alignment of the contents within the table item.
+ * Valid values include 'NotSet','Top','Bottom','Middle'
+ * @param string the horizontal alignment
+ */
+ public function setVerticalAlign($value)
+ {
+ $this->getStyle()->setVerticalAlign($value);
+ }
+
+ /**
+ * @return TTableRowSection location of a row in a table. Defaults to TTableRowSection::Body.
+ */
+ public function getTableSection()
+ {
+ return $this->getViewState('TableSection',TTableRowSection::Body);
+ }
+
+ /**
+ * @param TTableRowSection location of a row in a table.
+ */
+ public function setTableSection($value)
+ {
+ $this->setViewState('TableSection',TPropertyValue::ensureEnum($value,'TTableRowSection'),TTableRowSection::Body);
+ }
+
+ /**
+ * Renders body contents of the table row
+ * @param THtmlWriter writer for the rendering purpose
+ */
+ public function renderContents($writer)
+ {
+ if($this->getHasControls())
+ {
+ $writer->writeLine();
+ foreach($this->getControls() as $cell)
+ {
+ $cell->renderControl($writer);
+ $writer->writeLine();
+ }
+ }
+ }
+}
+
+/**
+ * TTableCellCollection class.
+ *
+ * TTableCellCollection is used to maintain a list of cells belong to a table row.
+ *
+ * @author Qiang Xue <qiang.xue@gmail.com>
+ * @version $Id$
+ * @package System.Web.UI.WebControls
+ * @since 3.0
+ */
+class TTableCellCollection extends TControlCollection
+{
+ /**
+ * Inserts an item at the specified position.
+ * This overrides the parent implementation by performing additional
+ * operations for each newly added table cell.
+ * @param integer the speicified position.
+ * @param mixed new item
+ * @throws TInvalidDataTypeException if the item to be inserted is not a TTableCell object.
+ */
+ public function insertAt($index,$item)
+ {
+ if($item instanceof TTableCell)
+ parent::insertAt($index,$item);
+ else
+ throw new TInvalidDataTypeException('tablecellcollection_tablecell_required');
+ }
+}
+
+
+/**
+ * TTableRowSection class.
+ * TTableRowSection defines the enumerable type for the possible table sections
+ * that a {@link TTableRow} can be within.
+ *
+ * The following enumerable values are defined:
+ * - Header: in table header
+ * - Body: in table body
+ * - Footer: in table footer
+ *
+ * @author Qiang Xue <qiang.xue@gmail.com>
+ * @version $Id$
+ * @package System.Web.UI.WebControls
+ * @since 3.0.4
+ */
+class TTableRowSection extends TEnumerable
+{
+ const Header='Header';
+ const Body='Body';
+ const Footer='Footer';
+}
+
diff --git a/framework/Web/UI/WebControls/TTemplateColumn.php b/framework/Web/UI/WebControls/TTemplateColumn.php
index f2bf02d7..34c9bbaf 100644
--- a/framework/Web/UI/WebControls/TTemplateColumn.php
+++ b/framework/Web/UI/WebControls/TTemplateColumn.php
@@ -1,256 +1,256 @@
-<?php
-/**
- * TTemplateColumn class file
- *
- * @author Qiang Xue <qiang.xue@gmail.com>
- * @link http://www.pradosoft.com/
+<?php
+/**
+ * TTemplateColumn class file
+ *
+ * @author Qiang Xue <qiang.xue@gmail.com>
+ * @link http://www.pradosoft.com/
* @copyright Copyright &copy; 2005-2012 PradoSoft
- * @license http://www.pradosoft.com/license/
- * @version $Id$
- * @package System.Web.UI.WebControls
- */
-
-/**
- * TDataGridColumn class file
- */
-Prado::using('System.Web.UI.WebControls.TDataGridColumn');
-
-/**
- * TTemplateColumn class
- *
- * TTemplateColumn customizes the layout of controls in the column with templates.
- * In particular, you can specify {@link setItemTemplate ItemTemplate},
- * {@link setEditItemTemplate EditItemTemplate}, {@link setHeaderTemplate HeaderTemplate}
- * and {@link setFooterTemplate FooterTemplate} to customize specific
- * type of cells in the column.
- *
- * Since v3.1.0, TTemplateColumn has introduced two new properties {@link setItemRenderer ItemRenderer}
- * and {@link setEditItemRenderer EditItemRenderer} which can be used to specify
- * the layout of the datagrid cells in browsing and editing mode.
- * A renderer refers to a control class that is to be instantiated as a control.
- * For more details, see {@link TRepeater} and {@link TDataList}.
- *
- * When a renderer and a template are both defined for a type of item, the former
- * takes precedence.
- *
- * @author Qiang Xue <qiang.xue@gmail.com>
- * @version $Id$
- * @package System.Web.UI.WebControls
- * @since 3.0
- */
-class TTemplateColumn extends TDataGridColumn
-{
- /**
- * Various item templates
- * @var string
- */
- private $_itemTemplate=null;
- private $_editItemTemplate=null;
- private $_headerTemplate=null;
- private $_footerTemplate=null;
-
- /**
- * @return string the class name for the item cell renderer. Defaults to empty, meaning not set.
- * @since 3.1.0
- */
- public function getItemRenderer()
- {
- return $this->getViewState('ItemRenderer','');
- }
-
- /**
- * Sets the item cell renderer class.
- *
- * If not empty, the class will be used to instantiate as a child control in the item cells of the column.
- *
- * If the class implements {@link IDataRenderer}, the <b>Data</b> property
- * will be set as the row of the data associated with the datagrid item that this cell resides in.
- *
- * @param string the renderer class name in namespace format.
- * @since 3.1.0
- */
- public function setItemRenderer($value)
- {
- $this->setViewState('ItemRenderer',$value,'');
- }
-
- /**
- * @return string the class name for the edit item cell renderer. Defaults to empty, meaning not set.
- * @since 3.1.0
- */
- public function getEditItemRenderer()
- {
- return $this->getViewState('EditItemRenderer','');
- }
-
- /**
- * Sets the edit item cell renderer class.
- *
- * If not empty, the class will be used to instantiate as a child control in the item cell that is in edit mode.
- *
- * If the class implements {@link IDataRenderer}, the <b>Data</b> property
- * will be set as the row of the data associated with the datagrid item that this cell resides in.
- *
- * @param string the renderer class name in namespace format.
- * @since 3.1.0
- */
- public function setEditItemRenderer($value)
- {
- $this->setViewState('EditItemRenderer',$value,'');
- }
-
- /**
- * @return ITemplate the edit item template
- */
- public function getEditItemTemplate()
- {
- return $this->_editItemTemplate;
- }
-
- /**
- * @param ITemplate the edit item template
- * @throws TInvalidDataTypeException if the input is not an {@link ITemplate} or not null.
- */
- public function setEditItemTemplate($value)
- {
- if($value instanceof ITemplate || $value===null)
- $this->_editItemTemplate=$value;
- else
- throw new TInvalidDataTypeException('templatecolumn_template_required','EditItemTemplate');
- }
-
- /**
- * @return ITemplate the item template
- */
- public function getItemTemplate()
- {
- return $this->_itemTemplate;
- }
-
- /**
- * @param ITemplate the item template
- * @throws TInvalidDataTypeException if the input is not an {@link ITemplate} or not null.
- */
- public function setItemTemplate($value)
- {
- if($value instanceof ITemplate || $value===null)
- $this->_itemTemplate=$value;
- else
- throw new TInvalidDataTypeException('templatecolumn_template_required','ItemTemplate');
- }
-
- /**
- * @return ITemplate the header template
- */
- public function getHeaderTemplate()
- {
- return $this->_headerTemplate;
- }
-
- /**
- * @param ITemplate the header template.
- * @throws TInvalidDataTypeException if the input is not an {@link ITemplate} or not null.
- */
- public function setHeaderTemplate($value)
- {
- if($value instanceof ITemplate || $value===null)
- $this->_headerTemplate=$value;
- else
- throw new TInvalidDataTypeException('templatecolumn_template_required','HeaderTemplate');
- }
-
- /**
- * @return ITemplate the footer template
- */
- public function getFooterTemplate()
- {
- return $this->_footerTemplate;
- }
-
- /**
- * @param ITemplate the footer template
- * @throws TInvalidDataTypeException if the input is not an {@link ITemplate} or not null.
- */
- public function setFooterTemplate($value)
- {
- if($value instanceof ITemplate || $value===null)
- $this->_footerTemplate=$value;
- else
- throw new TInvalidDataTypeException('templatecolumn_template_required','FooterTemplate');
- }
-
- /**
- * Initializes the specified cell to its initial values.
- * This method overrides the parent implementation.
- * It initializes the cell based on different templates
- * (ItemTemplate, EditItemTemplate, HeaderTemplate, FooterTemplate).
- * @param TTableCell the cell to be initialized.
- * @param integer the index to the Columns property that the cell resides in.
- * @param string the type of cell (Header,Footer,Item,AlternatingItem,EditItem,SelectedItem)
- */
- public function initializeCell($cell,$columnIndex,$itemType)
- {
- if($itemType===TListItemType::Item || $itemType===TListItemType::AlternatingItem || $itemType===TListItemType::SelectedItem || $itemType===TListItemType::EditItem)
- {
- if($itemType===TListItemType::EditItem)
- {
- if(($classPath=$this->getEditItemRenderer())==='' && ($template=$this->_editItemTemplate)===null)
- {
- $classPath=$this->getItemRenderer();
- $template=$this->_itemTemplate;
- }
- }
- else
- {
- $template=$this->_itemTemplate;
- $classPath=$this->getItemRenderer();
- }
- if($classPath!=='')
- {
- $control=Prado::createComponent($classPath);
- $cell->getControls()->add($control);
- if($control instanceof IItemDataRenderer)
- {
- $control->setItemIndex($cell->getParent()->getItemIndex());
- $control->setItemType($itemType);
- }
- if($control instanceof IDataRenderer)
- $control->attachEventHandler('OnDataBinding',array($this,'dataBindColumn'));
- }
- else if($template!==null)
- $template->instantiateIn($cell);
- else if($itemType!==TListItemType::EditItem)
- $cell->setText('&nbsp;');
- }
- else if($itemType===TListItemType::Header)
- {
- if(($classPath=$this->getHeaderRenderer())!=='')
- $this->initializeHeaderCell($cell,$columnIndex);
- else if($this->_headerTemplate!==null)
- $this->_headerTemplate->instantiateIn($cell);
- else
- $this->initializeHeaderCell($cell,$columnIndex);
- }
- else if($itemType===TListItemType::Footer)
- {
- if(($classPath=$this->getFooterRenderer())!=='')
- $this->initializeFooterCell($cell,$columnIndex);
- else if($this->_footerTemplate!==null)
- $this->_footerTemplate->instantiateIn($cell);
- else
- $this->initializeFooterCell($cell,$columnIndex);
- }
- }
-
- /**
- * Databinds a cell in the column.
- * This method is invoked when datagrid performs databinding.
- * It populates the content of the cell with the relevant data from data source.
- */
- public function dataBindColumn($sender,$param)
- {
- $item=$sender->getNamingContainer();
- $sender->setData($item->getData());
- }
-}
-
+ * @license http://www.pradosoft.com/license/
+ * @version $Id$
+ * @package System.Web.UI.WebControls
+ */
+
+/**
+ * TDataGridColumn class file
+ */
+Prado::using('System.Web.UI.WebControls.TDataGridColumn');
+
+/**
+ * TTemplateColumn class
+ *
+ * TTemplateColumn customizes the layout of controls in the column with templates.
+ * In particular, you can specify {@link setItemTemplate ItemTemplate},
+ * {@link setEditItemTemplate EditItemTemplate}, {@link setHeaderTemplate HeaderTemplate}
+ * and {@link setFooterTemplate FooterTemplate} to customize specific
+ * type of cells in the column.
+ *
+ * Since v3.1.0, TTemplateColumn has introduced two new properties {@link setItemRenderer ItemRenderer}
+ * and {@link setEditItemRenderer EditItemRenderer} which can be used to specify
+ * the layout of the datagrid cells in browsing and editing mode.
+ * A renderer refers to a control class that is to be instantiated as a control.
+ * For more details, see {@link TRepeater} and {@link TDataList}.
+ *
+ * When a renderer and a template are both defined for a type of item, the former
+ * takes precedence.
+ *
+ * @author Qiang Xue <qiang.xue@gmail.com>
+ * @version $Id$
+ * @package System.Web.UI.WebControls
+ * @since 3.0
+ */
+class TTemplateColumn extends TDataGridColumn
+{
+ /**
+ * Various item templates
+ * @var string
+ */
+ private $_itemTemplate=null;
+ private $_editItemTemplate=null;
+ private $_headerTemplate=null;
+ private $_footerTemplate=null;
+
+ /**
+ * @return string the class name for the item cell renderer. Defaults to empty, meaning not set.
+ * @since 3.1.0
+ */
+ public function getItemRenderer()
+ {
+ return $this->getViewState('ItemRenderer','');
+ }
+
+ /**
+ * Sets the item cell renderer class.
+ *
+ * If not empty, the class will be used to instantiate as a child control in the item cells of the column.
+ *
+ * If the class implements {@link IDataRenderer}, the <b>Data</b> property
+ * will be set as the row of the data associated with the datagrid item that this cell resides in.
+ *
+ * @param string the renderer class name in namespace format.
+ * @since 3.1.0
+ */
+ public function setItemRenderer($value)
+ {
+ $this->setViewState('ItemRenderer',$value,'');
+ }
+
+ /**
+ * @return string the class name for the edit item cell renderer. Defaults to empty, meaning not set.
+ * @since 3.1.0
+ */
+ public function getEditItemRenderer()
+ {
+ return $this->getViewState('EditItemRenderer','');
+ }
+
+ /**
+ * Sets the edit item cell renderer class.
+ *
+ * If not empty, the class will be used to instantiate as a child control in the item cell that is in edit mode.
+ *
+ * If the class implements {@link IDataRenderer}, the <b>Data</b> property
+ * will be set as the row of the data associated with the datagrid item that this cell resides in.
+ *
+ * @param string the renderer class name in namespace format.
+ * @since 3.1.0
+ */
+ public function setEditItemRenderer($value)
+ {
+ $this->setViewState('EditItemRenderer',$value,'');
+ }
+
+ /**
+ * @return ITemplate the edit item template
+ */
+ public function getEditItemTemplate()
+ {
+ return $this->_editItemTemplate;
+ }
+
+ /**
+ * @param ITemplate the edit item template
+ * @throws TInvalidDataTypeException if the input is not an {@link ITemplate} or not null.
+ */
+ public function setEditItemTemplate($value)
+ {
+ if($value instanceof ITemplate || $value===null)
+ $this->_editItemTemplate=$value;
+ else
+ throw new TInvalidDataTypeException('templatecolumn_template_required','EditItemTemplate');
+ }
+
+ /**
+ * @return ITemplate the item template
+ */
+ public function getItemTemplate()
+ {
+ return $this->_itemTemplate;
+ }
+
+ /**
+ * @param ITemplate the item template
+ * @throws TInvalidDataTypeException if the input is not an {@link ITemplate} or not null.
+ */
+ public function setItemTemplate($value)
+ {
+ if($value instanceof ITemplate || $value===null)
+ $this->_itemTemplate=$value;
+ else
+ throw new TInvalidDataTypeException('templatecolumn_template_required','ItemTemplate');
+ }
+
+ /**
+ * @return ITemplate the header template
+ */
+ public function getHeaderTemplate()
+ {
+ return $this->_headerTemplate;
+ }
+
+ /**
+ * @param ITemplate the header template.
+ * @throws TInvalidDataTypeException if the input is not an {@link ITemplate} or not null.
+ */
+ public function setHeaderTemplate($value)
+ {
+ if($value instanceof ITemplate || $value===null)
+ $this->_headerTemplate=$value;
+ else
+ throw new TInvalidDataTypeException('templatecolumn_template_required','HeaderTemplate');
+ }
+
+ /**
+ * @return ITemplate the footer template
+ */
+ public function getFooterTemplate()
+ {
+ return $this->_footerTemplate;
+ }
+
+ /**
+ * @param ITemplate the footer template
+ * @throws TInvalidDataTypeException if the input is not an {@link ITemplate} or not null.
+ */
+ public function setFooterTemplate($value)
+ {
+ if($value instanceof ITemplate || $value===null)
+ $this->_footerTemplate=$value;
+ else
+ throw new TInvalidDataTypeException('templatecolumn_template_required','FooterTemplate');
+ }
+
+ /**
+ * Initializes the specified cell to its initial values.
+ * This method overrides the parent implementation.
+ * It initializes the cell based on different templates
+ * (ItemTemplate, EditItemTemplate, HeaderTemplate, FooterTemplate).
+ * @param TTableCell the cell to be initialized.
+ * @param integer the index to the Columns property that the cell resides in.
+ * @param string the type of cell (Header,Footer,Item,AlternatingItem,EditItem,SelectedItem)
+ */
+ public function initializeCell($cell,$columnIndex,$itemType)
+ {
+ if($itemType===TListItemType::Item || $itemType===TListItemType::AlternatingItem || $itemType===TListItemType::SelectedItem || $itemType===TListItemType::EditItem)
+ {
+ if($itemType===TListItemType::EditItem)
+ {
+ if(($classPath=$this->getEditItemRenderer())==='' && ($template=$this->_editItemTemplate)===null)
+ {
+ $classPath=$this->getItemRenderer();
+ $template=$this->_itemTemplate;
+ }
+ }
+ else
+ {
+ $template=$this->_itemTemplate;
+ $classPath=$this->getItemRenderer();
+ }
+ if($classPath!=='')
+ {
+ $control=Prado::createComponent($classPath);
+ $cell->getControls()->add($control);
+ if($control instanceof IItemDataRenderer)
+ {
+ $control->setItemIndex($cell->getParent()->getItemIndex());
+ $control->setItemType($itemType);
+ }
+ if($control instanceof IDataRenderer)
+ $control->attachEventHandler('OnDataBinding',array($this,'dataBindColumn'));
+ }
+ else if($template!==null)
+ $template->instantiateIn($cell);
+ else if($itemType!==TListItemType::EditItem)
+ $cell->setText('&nbsp;');
+ }
+ else if($itemType===TListItemType::Header)
+ {
+ if(($classPath=$this->getHeaderRenderer())!=='')
+ $this->initializeHeaderCell($cell,$columnIndex);
+ else if($this->_headerTemplate!==null)
+ $this->_headerTemplate->instantiateIn($cell);
+ else
+ $this->initializeHeaderCell($cell,$columnIndex);
+ }
+ else if($itemType===TListItemType::Footer)
+ {
+ if(($classPath=$this->getFooterRenderer())!=='')
+ $this->initializeFooterCell($cell,$columnIndex);
+ else if($this->_footerTemplate!==null)
+ $this->_footerTemplate->instantiateIn($cell);
+ else
+ $this->initializeFooterCell($cell,$columnIndex);
+ }
+ }
+
+ /**
+ * Databinds a cell in the column.
+ * This method is invoked when datagrid performs databinding.
+ * It populates the content of the cell with the relevant data from data source.
+ */
+ public function dataBindColumn($sender,$param)
+ {
+ $item=$sender->getNamingContainer();
+ $sender->setData($item->getData());
+ }
+}
+
diff --git a/framework/Web/UI/WebControls/TTextBox.php b/framework/Web/UI/WebControls/TTextBox.php
index 7a9f0445..5cd1149a 100644
--- a/framework/Web/UI/WebControls/TTextBox.php
+++ b/framework/Web/UI/WebControls/TTextBox.php
@@ -1,652 +1,652 @@
-<?php
-/**
- * TTextBox class file.
- *
- * @author Qiang Xue <qiang.xue@gmail.com>
- * @link http://www.pradosoft.com/
- * @copyright Copyright &copy; 2005-2012 PradoSoft
- * @license http://www.pradosoft.com/license/
- * @version $Id$
- * @package System.Web.UI.WebControls
- */
-
-/**
- * TTextBox class
- *
- * TTextBox displays a text box on the Web page for user input.
- * The text displayed in the TTextBox control is determined by the
- * {@link setText Text} property. You can create a <b>SingleLine</b>,
- * a <b>MultiLine</b>, or a <b>Password</b> text box by setting
- * the {@link setTextMode TextMode} property. If the TTextBox control
- * is a multiline text box, the number of rows it displays is determined
- * by the {@link setRows Rows} property, and the {@link setWrap Wrap} property
- * can be used to determine whether to wrap the text in the component.
- *
- * To specify the display width of the text box, in characters, set
- * the {@link setColumns Columns} property. To prevent the text displayed
- * in the component from being modified, set the {@link setReadOnly ReadOnly}
- * property to true. If you want to limit the user input to a specified number
- * of characters, set the {@link setMaxLength MaxLength} property.
- * To use AutoComplete feature, set the {@link setAutoCompleteType AutoCompleteType} property.
- *
- * If {@link setAutoPostBack AutoPostBack} is set true, updating the text box
- * and then changing the focus out of it will cause postback action.
- * And if {@link setCausesValidation CausesValidation} is true, validation will
- * also be processed, which can be further restricted within
- * a {@link setValidationGroup ValidationGroup}.
- *
- * WARNING: Be careful if you want to display the text collected via TTextBox.
- * Malicious cross-site script may be injected in. You may use {@link getSafeText SafeText}
- * to prevent this problem.
- *
- * NOTE: If you set {@link setWrap Wrap} to false or use {@link setAutoCompleteType AutoCompleteType},
- * the generated HTML output for the textbox will not be XHTML-compatible.
- * Currently, no alternatives are available.
- *
- * @author Qiang Xue <qiang.xue@gmail.com>
- * @version $Id$
- * @package System.Web.UI.WebControls
- * @since 3.0
- */
-class TTextBox extends TWebControl implements IPostBackDataHandler, IValidatable, IDataRenderer
-{
- /**
- * Default number of rows (for MultiLine text box)
- */
- const DEFAULT_ROWS=4;
- /**
- * Default number of columns (for MultiLine text box)
- */
- const DEFAULT_COLUMNS=20;
- /**
- * @var mixed safe text parser
- */
- private static $_safeTextParser=null;
- /**
- * @var string safe textbox content with javascript stripped off
- */
- private $_safeText;
- private $_dataChanged=false;
- private $_isValid=true;
-
- /**
- * @return string tag name of the textbox
- */
- protected function getTagName()
- {
- return ($this->getTextMode()==='MultiLine')?'textarea':'input';
- }
-
- /**
- * @return boolean whether to render javascript.
- */
- public function getEnableClientScript()
- {
- return $this->getViewState('EnableClientScript',true);
- }
-
- /**
- * @param boolean whether to render javascript.
- */
- public function setEnableClientScript($value)
- {
- $this->setViewState('EnableClientScript',TPropertyValue::ensureBoolean($value),true);
- }
-
- /**
- * Adds attribute name-value pairs to renderer.
- * This method overrides the parent implementation with additional textbox specific attributes.
- * @param THtmlWriter the writer used for the rendering purpose
- */
- protected function addAttributesToRender($writer)
- {
- $page=$this->getPage();
- $page->ensureRenderInForm($this);
- if(($uid=$this->getUniqueID())!=='')
- $writer->addAttribute('name',$uid);
- if(($textMode=$this->getTextMode())===TTextBoxMode::MultiLine)
- {
- if(($rows=$this->getRows())<=0)
- $rows=self::DEFAULT_ROWS;
- if(($cols=$this->getColumns())<=0)
- $cols=self::DEFAULT_COLUMNS;
- $writer->addAttribute('rows',"$rows");
- $writer->addAttribute('cols',"$cols");
- if(!$this->getWrap())
- $writer->addAttribute('wrap','off');
- }
- else
- {
- if($textMode===TTextBoxMode::SingleLine)
- {
- $writer->addAttribute('type','text');
- if(($text=$this->getText())!=='')
- $writer->addAttribute('value',$text);
- }
- else
- {
- if($this->getPersistPassword() && ($text=$this->getText())!=='')
- $writer->addAttribute('value',$text);
- $writer->addAttribute('type','password');
- }
-
- if(($act=$this->getAutoCompleteType())!=='None')
- {
- if($act==='Disabled')
- $writer->addAttribute('autocomplete','off');
- else if($act==='Search')
- $writer->addAttribute('vcard_name','search');
- else if($act==='HomeCountryRegion')
- $writer->addAttribute('vcard_name','HomeCountry');
- else if($act==='BusinessCountryRegion')
- $writer->addAttribute('vcard_name','BusinessCountry');
- else
- {
- if(strpos($act,'Business')===0)
- $act='Business'.'.'.substr($act,8);
- else if(strpos($act,'Home')===0)
- $act='Home'.'.'.substr($act,4);
- $writer->addAttribute('vcard_name','vCard.'.$act);
- }
- }
-
- if(($cols=$this->getColumns())>0)
- $writer->addAttribute('size',"$cols");
- if(($maxLength=$this->getMaxLength())>0)
- $writer->addAttribute('maxlength',"$maxLength");
- }
- if($this->getReadOnly())
- $writer->addAttribute('readonly','readonly');
- $isEnabled=$this->getEnabled(true);
- if(!$isEnabled && $this->getEnabled()) // in this case parent will not render 'disabled'
- $writer->addAttribute('disabled','disabled');
- if($isEnabled
- && $this->getEnableClientScript()
- && ( $this->getAutoPostBack() || $textMode===TTextBoxMode::SingleLine)
- && $page->getClientSupportsJavaScript())
- {
- $this->renderClientControlScript($writer);
- }
- parent::addAttributesToRender($writer);
- }
-
- /**
- * Renders the javascript for textbox.
- */
- protected function renderClientControlScript($writer)
- {
- $writer->addAttribute('id',$this->getClientID());
- $cs = $this->getPage()->getClientScript();
- $cs->registerPostBackControl($this->getClientClassName(),$this->getPostBackOptions());
- }
-
- /**
- * Gets the name of the javascript class responsible for performing postback for this control.
- * This method overrides the parent implementation.
- * @return string the javascript class name
- */
- protected function getClientClassName()
- {
- return 'Prado.WebUI.TTextBox';
- }
-
- /**
- * Gets the post back options for this textbox.
- * @return array
- */
- protected function getPostBackOptions()
- {
- $options['ID'] = $this->getClientID();
- $options['EventTarget'] = $this->getUniqueID();
- $options['AutoPostBack'] = $this->getAutoPostBack();
- $options['CausesValidation'] = $this->getCausesValidation();
- $options['ValidationGroup'] = $this->getValidationGroup();
- $options['TextMode'] = $this->getTextMode();
- return $options;
- }
-
- /**
- * Loads user input data.
- * This method is primarly used by framework developers.
- * @param string the key that can be used to retrieve data from the input data collection
- * @param array the input data collection
- * @return boolean whether the data of the component has been changed
- */
- public function loadPostData($key,$values)
- {
- $value=$values[$key];
- if($this->getAutoTrim())
- $value=trim($value);
- if(!$this->getReadOnly() && $this->getText()!==$value)
- {
- $this->setText($value);
- return $this->_dataChanged=true;
- }
- else
- return false;
- }
-
- /**
- * Returns a value indicating whether postback has caused the control data change.
- * This method is required by the IPostBackDataHandler interface.
- * @return boolean whether postback has caused the control data change. False if the page is not in postback mode.
- */
- public function getDataChanged()
- {
- return $this->_dataChanged;
- }
-
- /**
- * Returns the value to be validated.
- * This methid is required by IValidatable interface.
- * @return mixed the value of the property to be validated.
- */
- public function getValidationPropertyValue()
- {
- return $this->getText();
- }
-
- /**
- * Returns true if this control validated successfully.
- * Defaults to true.
- * @return bool wether this control validated successfully.
- */
- public function getIsValid()
- {
- return $this->_isValid;
- }
- /**
- * @param bool wether this control is valid.
- */
- public function setIsValid($value)
- {
- $this->_isValid=TPropertyValue::ensureBoolean($value);
- }
-
- /**
- * Raises <b>OnTextChanged</b> event.
- * This method is invoked when the value of the {@link getText Text}
- * property changes on postback.
- * If you override this method, be sure to call the parent implementation to ensure
- * the invocation of the attached event handlers.
- * @param TEventParameter event parameter to be passed to the event handlers
- */
- public function onTextChanged($param)
- {
- $this->raiseEvent('OnTextChanged',$this,$param);
- }
-
- /**
- * Raises postdata changed event.
- * This method is required by {@link IPostBackDataHandler} interface.
- * It is invoked by the framework when {@link getText Text} property
- * is changed on postback.
- * This method is primarly used by framework developers.
- */
- public function raisePostDataChangedEvent()
- {
- if($this->getAutoPostBack() && $this->getCausesValidation())
- $this->getPage()->validate($this->getValidationGroup());
- $this->onTextChanged(null);
- }
-
- /**
- * Renders the body content of the textbox when it is in MultiLine text mode.
- * @param THtmlWriter the writer for rendering
- */
- public function renderContents($writer)
- {
- if($this->getTextMode()==='MultiLine')
- $writer->write(THttpUtility::htmlEncode($this->getText()));
- }
-
- /**
- * Renders an additional line-break after the opening tag when it
- * is in MultiLine text mode.
- * @param THtmlWriter the writer used for the rendering purpose^M
- */
- public function renderBeginTag($writer)
- {
- parent::renderBeginTag($writer);
- if($this->getTextMode()==='MultiLine')
- $writer->write("\n");
- }
-
- /**
- * @return TTextBoxAutoCompleteType the AutoComplete type of the textbox
- */
- public function getAutoCompleteType()
- {
- return $this->getViewState('AutoCompleteType',TTextBoxAutoCompleteType::None);
- }
-
- /**
- * @param TTextBoxAutoCompleteType the AutoComplete type of the textbox, default value is TTextBoxAutoCompleteType::None.
- * @throws TInvalidDataValueException if the input parameter is not a valid AutoComplete type
- */
- public function setAutoCompleteType($value)
- {
- $this->setViewState('AutoCompleteType',TPropertyValue::ensureEnum($value,'TTextBoxAutoCompleteType'),TTextBoxAutoCompleteType::None);
- }
-
- /**
- * @return boolean a value indicating whether an automatic postback to the server
- * will occur whenever the user modifies the text in the TTextBox control and
- * then tabs out of the component. Defaults to false.
- */
- public function getAutoPostBack()
- {
- return $this->getViewState('AutoPostBack',false);
- }
-
- /**
- * Sets the value indicating if postback automatically.
- * An automatic postback to the server will occur whenever the user
- * modifies the text in the TTextBox control and then tabs out of the component.
- * @param boolean the value indicating if postback automatically
- */
- public function setAutoPostBack($value)
- {
- $this->setViewState('AutoPostBack',TPropertyValue::ensureBoolean($value),false);
- }
-
- /**
- * @return boolean a value indicating whether the input text should be trimmed spaces. Defaults to false.
- */
- public function getAutoTrim()
- {
- return $this->getViewState('AutoTrim',false);
- }
-
- /**
- * Sets the value indicating if the input text should be trimmed spaces
- * @param boolean the value indicating if the input text should be trimmed spaces
- */
- public function setAutoTrim($value)
- {
- $this->setViewState('AutoTrim',TPropertyValue::ensureBoolean($value),false);
- }
-
- /**
- * @return boolean whether postback event trigger by this text box will cause input validation, default is true.
- */
- public function getCausesValidation()
- {
- return $this->getViewState('CausesValidation',true);
- }
-
- /**
- * @param boolean whether postback event trigger by this text box will cause input validation.
- */
- public function setCausesValidation($value)
- {
- $this->setViewState('CausesValidation',TPropertyValue::ensureBoolean($value),true);
- }
-
- /**
- * @return integer the display width of the text box in characters, default is 0 meaning not set.
- */
- public function getColumns()
- {
- return $this->getViewState('Columns',0);
- }
-
- /**
- * Sets the display width of the text box in characters.
- * @param integer the display width, set it 0 to clear the setting
- */
- public function setColumns($value)
- {
- $this->setViewState('Columns',TPropertyValue::ensureInteger($value),0);
- }
-
- /**
- * @return integer the maximum number of characters allowed in the text box, default is 0 meaning not set.
- */
- public function getMaxLength()
- {
- return $this->getViewState('MaxLength',0);
- }
-
- /**
- * Sets the maximum number of characters allowed in the text box.
- * @param integer the maximum length, set it 0 to clear the setting
- */
- public function setMaxLength($value)
- {
- $this->setViewState('MaxLength',TPropertyValue::ensureInteger($value),0);
- }
-
- /**
- * @return boolean whether the textbox is read only, default is false.
- */
- public function getReadOnly()
- {
- return $this->getViewState('ReadOnly',false);
- }
-
- /**
- * @param boolean whether the textbox is read only
- */
- public function setReadOnly($value)
- {
- $this->setViewState('ReadOnly',TPropertyValue::ensureBoolean($value),false);
- }
-
- /**
- * @return integer the number of rows displayed in a multiline text box, default is 4
- */
- public function getRows()
- {
- return $this->getViewState('Rows',self::DEFAULT_ROWS);
- }
-
- /**
- * Sets the number of rows displayed in a multiline text box.
- * @param integer the number of rows
- */
- public function setRows($value)
- {
- $this->setViewState('Rows',TPropertyValue::ensureInteger($value),self::DEFAULT_ROWS);
- }
-
- /**
- * @return boolean whether password should be displayed in the textbox during postback. Defaults to false. This property only applies when TextMode='Password'.
- */
- public function getPersistPassword()
- {
- return $this->getViewState('PersistPassword',false);
- }
-
- /**
- * @param boolean whether password should be displayed in the textbox during postback. This property only applies when TextMode='Password'.
- */
- public function setPersistPassword($value)
- {
- $this->setViewState('PersistPassword',TPropertyValue::ensureBoolean($value),false);
- }
-
- /**
- * @return string the text content of the TTextBox control.
- */
- public function getText()
- {
- return $this->getViewState('Text','');
- }
-
- /**
- * Sets the text content of the TTextBox control.
- * @param string the text content
- */
- public function setText($value)
- {
- $this->setViewState('Text',$value,'');
- $this->_safeText = null;
- }
-
- /**
- * Returns the text content of the TTextBox control.
- * This method is required by {@link IDataRenderer}.
- * It is the same as {@link getText()}.
- * @return string the text content of the TTextBox control.
- * @see getText
- * @since 3.1.0
- */
- public function getData()
- {
- return $this->getText();
- }
-
- /**
- * Sets the text content of the TTextBox control.
- * This method is required by {@link IDataRenderer}.
- * It is the same as {@link setText()}.
- * @param string the text content of the TTextBox control.
- * @see setText
- * @since 3.1.0
- */
- public function setData($value)
- {
- $this->setText($value);
- }
-
- /**
- * @return string safe text content with javascript stripped off
- */
- public function getSafeText()
- {
- if($this->_safeText===null)
- $this->_safeText=$this->getSafeTextParser()->parse($this->getText());
- return $this->_safeText;
- }
-
- /**
- * @return mixed safe text parser
- */
- protected function getSafeTextParser()
- {
- if(!self::$_safeTextParser)
- self::$_safeTextParser=Prado::createComponent('System.3rdParty.SafeHtml.TSafeHtmlParser');
- return self::$_safeTextParser;
- }
-
- /**
- * @return TTextBoxMode the behavior mode of the TTextBox component. Defaults to TTextBoxMode::SingleLine.
- */
- public function getTextMode()
- {
- return $this->getViewState('TextMode',TTextBoxMode::SingleLine);
- }
-
- /**
- * Sets the behavior mode of the TTextBox component.
- * @param TTextBoxMode the text mode
- * @throws TInvalidDataValueException if the input value is not a valid text mode.
- */
- public function setTextMode($value)
- {
- $this->setViewState('TextMode',TPropertyValue::ensureEnum($value,'TTextBoxMode'),TTextBoxMode::SingleLine);
- }
-
- /**
- * @return string the group of validators which the text box causes validation upon postback
- */
- public function getValidationGroup()
- {
- return $this->getViewState('ValidationGroup','');
- }
-
- /**
- * @param string the group of validators which the text box causes validation upon postback
- */
- public function setValidationGroup($value)
- {
- $this->setViewState('ValidationGroup',$value,'');
- }
-
- /**
- * @return boolean whether the text content wraps within a multiline text box. Defaults to true.
- */
- public function getWrap()
- {
- return $this->getViewState('Wrap',true);
- }
-
- /**
- * Sets the value indicating whether the text content wraps within a multiline text box.
- * @param boolean whether the text content wraps within a multiline text box.
- */
- public function setWrap($value)
- {
- $this->setViewState('Wrap',TPropertyValue::ensureBoolean($value),true);
- }
-}
-
-/**
- * TTextBoxMode class.
- * TTextBoxMode defines the enumerable type for the possible mode
- * that a {@link TTextBox} control could be at.
- *
- * The following enumerable values are defined:
- * - SingleLine: the textbox will be a regular single line input
- * - MultiLine: the textbox will be a textarea allowing multiple line input
- * - Password: the textbox will hide user input like a password input box
- *
- * @author Qiang Xue <qiang.xue@gmail.com>
- * @version $Id$
- * @package System.Web.UI.WebControls
- * @since 3.0.4
- */
-class TTextBoxMode extends TEnumerable
-{
- const SingleLine='SingleLine';
- const MultiLine='MultiLine';
- const Password='Password';
-}
-
-/**
- * TTextBoxAutoCompleteType class.
- * TTextBoxAutoCompleteType defines the possible AutoComplete type that is supported
- * by a {@link TTextBox} control.
- *
- * @author Qiang Xue <qiang.xue@gmail.com>
- * @version $Id$
- * @package System.Web.UI.WebControls
- * @since 3.0.4
- */
-class TTextBoxAutoCompleteType extends TEnumerable
-{
- const BusinessCity='BusinessCity';
- const BusinessCountryRegion='BusinessCountryRegion';
- const BusinessFax='BusinessFax';
- const BusinessPhone='BusinessPhone';
- const BusinessState='BusinessState';
- const BusinessStreetAddress='BusinessStreetAddress';
- const BusinessUrl='BusinessUrl';
- const BusinessZipCode='BusinessZipCode';
- const Cellular='Cellular';
- const Company='Company';
- const Department='Department';
- const Disabled='Disabled';
- const DisplayName='DisplayName';
- const Email='Email';
- const FirstName='FirstName';
- const Gender='Gender';
- const HomeCity='HomeCity';
- const HomeCountryRegion='HomeCountryRegion';
- const HomeFax='HomeFax';
- const Homepage='Homepage';
- const HomePhone='HomePhone';
- const HomeState='HomeState';
- const HomeStreetAddress='HomeStreetAddress';
- const HomeZipCode='HomeZipCode';
- const JobTitle='JobTitle';
- const LastName='LastName';
- const MiddleName='MiddleName';
- const None='None';
- const Notes='Notes';
- const Office='Office';
- const Pager='Pager';
- const Search='Search';
-}
-
+<?php
+/**
+ * TTextBox class file.
+ *
+ * @author Qiang Xue <qiang.xue@gmail.com>
+ * @link http://www.pradosoft.com/
+ * @copyright Copyright &copy; 2005-2012 PradoSoft
+ * @license http://www.pradosoft.com/license/
+ * @version $Id$
+ * @package System.Web.UI.WebControls
+ */
+
+/**
+ * TTextBox class
+ *
+ * TTextBox displays a text box on the Web page for user input.
+ * The text displayed in the TTextBox control is determined by the
+ * {@link setText Text} property. You can create a <b>SingleLine</b>,
+ * a <b>MultiLine</b>, or a <b>Password</b> text box by setting
+ * the {@link setTextMode TextMode} property. If the TTextBox control
+ * is a multiline text box, the number of rows it displays is determined
+ * by the {@link setRows Rows} property, and the {@link setWrap Wrap} property
+ * can be used to determine whether to wrap the text in the component.
+ *
+ * To specify the display width of the text box, in characters, set
+ * the {@link setColumns Columns} property. To prevent the text displayed
+ * in the component from being modified, set the {@link setReadOnly ReadOnly}
+ * property to true. If you want to limit the user input to a specified number
+ * of characters, set the {@link setMaxLength MaxLength} property.
+ * To use AutoComplete feature, set the {@link setAutoCompleteType AutoCompleteType} property.
+ *
+ * If {@link setAutoPostBack AutoPostBack} is set true, updating the text box
+ * and then changing the focus out of it will cause postback action.
+ * And if {@link setCausesValidation CausesValidation} is true, validation will
+ * also be processed, which can be further restricted within
+ * a {@link setValidationGroup ValidationGroup}.
+ *
+ * WARNING: Be careful if you want to display the text collected via TTextBox.
+ * Malicious cross-site script may be injected in. You may use {@link getSafeText SafeText}
+ * to prevent this problem.
+ *
+ * NOTE: If you set {@link setWrap Wrap} to false or use {@link setAutoCompleteType AutoCompleteType},
+ * the generated HTML output for the textbox will not be XHTML-compatible.
+ * Currently, no alternatives are available.
+ *
+ * @author Qiang Xue <qiang.xue@gmail.com>
+ * @version $Id$
+ * @package System.Web.UI.WebControls
+ * @since 3.0
+ */
+class TTextBox extends TWebControl implements IPostBackDataHandler, IValidatable, IDataRenderer
+{
+ /**
+ * Default number of rows (for MultiLine text box)
+ */
+ const DEFAULT_ROWS=4;
+ /**
+ * Default number of columns (for MultiLine text box)
+ */
+ const DEFAULT_COLUMNS=20;
+ /**
+ * @var mixed safe text parser
+ */
+ private static $_safeTextParser=null;
+ /**
+ * @var string safe textbox content with javascript stripped off
+ */
+ private $_safeText;
+ private $_dataChanged=false;
+ private $_isValid=true;
+
+ /**
+ * @return string tag name of the textbox
+ */
+ protected function getTagName()
+ {
+ return ($this->getTextMode()==='MultiLine')?'textarea':'input';
+ }
+
+ /**
+ * @return boolean whether to render javascript.
+ */
+ public function getEnableClientScript()
+ {
+ return $this->getViewState('EnableClientScript',true);
+ }
+
+ /**
+ * @param boolean whether to render javascript.
+ */
+ public function setEnableClientScript($value)
+ {
+ $this->setViewState('EnableClientScript',TPropertyValue::ensureBoolean($value),true);
+ }
+
+ /**
+ * Adds attribute name-value pairs to renderer.
+ * This method overrides the parent implementation with additional textbox specific attributes.
+ * @param THtmlWriter the writer used for the rendering purpose
+ */
+ protected function addAttributesToRender($writer)
+ {
+ $page=$this->getPage();
+ $page->ensureRenderInForm($this);
+ if(($uid=$this->getUniqueID())!=='')
+ $writer->addAttribute('name',$uid);
+ if(($textMode=$this->getTextMode())===TTextBoxMode::MultiLine)
+ {
+ if(($rows=$this->getRows())<=0)
+ $rows=self::DEFAULT_ROWS;
+ if(($cols=$this->getColumns())<=0)
+ $cols=self::DEFAULT_COLUMNS;
+ $writer->addAttribute('rows',"$rows");
+ $writer->addAttribute('cols',"$cols");
+ if(!$this->getWrap())
+ $writer->addAttribute('wrap','off');
+ }
+ else
+ {
+ if($textMode===TTextBoxMode::SingleLine)
+ {
+ $writer->addAttribute('type','text');
+ if(($text=$this->getText())!=='')
+ $writer->addAttribute('value',$text);
+ }
+ else
+ {
+ if($this->getPersistPassword() && ($text=$this->getText())!=='')
+ $writer->addAttribute('value',$text);
+ $writer->addAttribute('type','password');
+ }
+
+ if(($act=$this->getAutoCompleteType())!=='None')
+ {
+ if($act==='Disabled')
+ $writer->addAttribute('autocomplete','off');
+ else if($act==='Search')
+ $writer->addAttribute('vcard_name','search');
+ else if($act==='HomeCountryRegion')
+ $writer->addAttribute('vcard_name','HomeCountry');
+ else if($act==='BusinessCountryRegion')
+ $writer->addAttribute('vcard_name','BusinessCountry');
+ else
+ {
+ if(strpos($act,'Business')===0)
+ $act='Business'.'.'.substr($act,8);
+ else if(strpos($act,'Home')===0)
+ $act='Home'.'.'.substr($act,4);
+ $writer->addAttribute('vcard_name','vCard.'.$act);
+ }
+ }
+
+ if(($cols=$this->getColumns())>0)
+ $writer->addAttribute('size',"$cols");
+ if(($maxLength=$this->getMaxLength())>0)
+ $writer->addAttribute('maxlength',"$maxLength");
+ }
+ if($this->getReadOnly())
+ $writer->addAttribute('readonly','readonly');
+ $isEnabled=$this->getEnabled(true);
+ if(!$isEnabled && $this->getEnabled()) // in this case parent will not render 'disabled'
+ $writer->addAttribute('disabled','disabled');
+ if($isEnabled
+ && $this->getEnableClientScript()
+ && ( $this->getAutoPostBack() || $textMode===TTextBoxMode::SingleLine)
+ && $page->getClientSupportsJavaScript())
+ {
+ $this->renderClientControlScript($writer);
+ }
+ parent::addAttributesToRender($writer);
+ }
+
+ /**
+ * Renders the javascript for textbox.
+ */
+ protected function renderClientControlScript($writer)
+ {
+ $writer->addAttribute('id',$this->getClientID());
+ $cs = $this->getPage()->getClientScript();
+ $cs->registerPostBackControl($this->getClientClassName(),$this->getPostBackOptions());
+ }
+
+ /**
+ * Gets the name of the javascript class responsible for performing postback for this control.
+ * This method overrides the parent implementation.
+ * @return string the javascript class name
+ */
+ protected function getClientClassName()
+ {
+ return 'Prado.WebUI.TTextBox';
+ }
+
+ /**
+ * Gets the post back options for this textbox.
+ * @return array
+ */
+ protected function getPostBackOptions()
+ {
+ $options['ID'] = $this->getClientID();
+ $options['EventTarget'] = $this->getUniqueID();
+ $options['AutoPostBack'] = $this->getAutoPostBack();
+ $options['CausesValidation'] = $this->getCausesValidation();
+ $options['ValidationGroup'] = $this->getValidationGroup();
+ $options['TextMode'] = $this->getTextMode();
+ return $options;
+ }
+
+ /**
+ * Loads user input data.
+ * This method is primarly used by framework developers.
+ * @param string the key that can be used to retrieve data from the input data collection
+ * @param array the input data collection
+ * @return boolean whether the data of the component has been changed
+ */
+ public function loadPostData($key,$values)
+ {
+ $value=$values[$key];
+ if($this->getAutoTrim())
+ $value=trim($value);
+ if(!$this->getReadOnly() && $this->getText()!==$value)
+ {
+ $this->setText($value);
+ return $this->_dataChanged=true;
+ }
+ else
+ return false;
+ }
+
+ /**
+ * Returns a value indicating whether postback has caused the control data change.
+ * This method is required by the IPostBackDataHandler interface.
+ * @return boolean whether postback has caused the control data change. False if the page is not in postback mode.
+ */
+ public function getDataChanged()
+ {
+ return $this->_dataChanged;
+ }
+
+ /**
+ * Returns the value to be validated.
+ * This methid is required by IValidatable interface.
+ * @return mixed the value of the property to be validated.
+ */
+ public function getValidationPropertyValue()
+ {
+ return $this->getText();
+ }
+
+ /**
+ * Returns true if this control validated successfully.
+ * Defaults to true.
+ * @return bool wether this control validated successfully.
+ */
+ public function getIsValid()
+ {
+ return $this->_isValid;
+ }
+ /**
+ * @param bool wether this control is valid.
+ */
+ public function setIsValid($value)
+ {
+ $this->_isValid=TPropertyValue::ensureBoolean($value);
+ }
+
+ /**
+ * Raises <b>OnTextChanged</b> event.
+ * This method is invoked when the value of the {@link getText Text}
+ * property changes on postback.
+ * If you override this method, be sure to call the parent implementation to ensure
+ * the invocation of the attached event handlers.
+ * @param TEventParameter event parameter to be passed to the event handlers
+ */
+ public function onTextChanged($param)
+ {
+ $this->raiseEvent('OnTextChanged',$this,$param);
+ }
+
+ /**
+ * Raises postdata changed event.
+ * This method is required by {@link IPostBackDataHandler} interface.
+ * It is invoked by the framework when {@link getText Text} property
+ * is changed on postback.
+ * This method is primarly used by framework developers.
+ */
+ public function raisePostDataChangedEvent()
+ {
+ if($this->getAutoPostBack() && $this->getCausesValidation())
+ $this->getPage()->validate($this->getValidationGroup());
+ $this->onTextChanged(null);
+ }
+
+ /**
+ * Renders the body content of the textbox when it is in MultiLine text mode.
+ * @param THtmlWriter the writer for rendering
+ */
+ public function renderContents($writer)
+ {
+ if($this->getTextMode()==='MultiLine')
+ $writer->write(THttpUtility::htmlEncode($this->getText()));
+ }
+
+ /**
+ * Renders an additional line-break after the opening tag when it
+ * is in MultiLine text mode.
+ * @param THtmlWriter the writer used for the rendering purpose^M
+ */
+ public function renderBeginTag($writer)
+ {
+ parent::renderBeginTag($writer);
+ if($this->getTextMode()==='MultiLine')
+ $writer->write("\n");
+ }
+
+ /**
+ * @return TTextBoxAutoCompleteType the AutoComplete type of the textbox
+ */
+ public function getAutoCompleteType()
+ {
+ return $this->getViewState('AutoCompleteType',TTextBoxAutoCompleteType::None);
+ }
+
+ /**
+ * @param TTextBoxAutoCompleteType the AutoComplete type of the textbox, default value is TTextBoxAutoCompleteType::None.
+ * @throws TInvalidDataValueException if the input parameter is not a valid AutoComplete type
+ */
+ public function setAutoCompleteType($value)
+ {
+ $this->setViewState('AutoCompleteType',TPropertyValue::ensureEnum($value,'TTextBoxAutoCompleteType'),TTextBoxAutoCompleteType::None);
+ }
+
+ /**
+ * @return boolean a value indicating whether an automatic postback to the server
+ * will occur whenever the user modifies the text in the TTextBox control and
+ * then tabs out of the component. Defaults to false.
+ */
+ public function getAutoPostBack()
+ {
+ return $this->getViewState('AutoPostBack',false);
+ }
+
+ /**
+ * Sets the value indicating if postback automatically.
+ * An automatic postback to the server will occur whenever the user
+ * modifies the text in the TTextBox control and then tabs out of the component.
+ * @param boolean the value indicating if postback automatically
+ */
+ public function setAutoPostBack($value)
+ {
+ $this->setViewState('AutoPostBack',TPropertyValue::ensureBoolean($value),false);
+ }
+
+ /**
+ * @return boolean a value indicating whether the input text should be trimmed spaces. Defaults to false.
+ */
+ public function getAutoTrim()
+ {
+ return $this->getViewState('AutoTrim',false);
+ }
+
+ /**
+ * Sets the value indicating if the input text should be trimmed spaces
+ * @param boolean the value indicating if the input text should be trimmed spaces
+ */
+ public function setAutoTrim($value)
+ {
+ $this->setViewState('AutoTrim',TPropertyValue::ensureBoolean($value),false);
+ }
+
+ /**
+ * @return boolean whether postback event trigger by this text box will cause input validation, default is true.
+ */
+ public function getCausesValidation()
+ {
+ return $this->getViewState('CausesValidation',true);
+ }
+
+ /**
+ * @param boolean whether postback event trigger by this text box will cause input validation.
+ */
+ public function setCausesValidation($value)
+ {
+ $this->setViewState('CausesValidation',TPropertyValue::ensureBoolean($value),true);
+ }
+
+ /**
+ * @return integer the display width of the text box in characters, default is 0 meaning not set.
+ */
+ public function getColumns()
+ {
+ return $this->getViewState('Columns',0);
+ }
+
+ /**
+ * Sets the display width of the text box in characters.
+ * @param integer the display width, set it 0 to clear the setting
+ */
+ public function setColumns($value)
+ {
+ $this->setViewState('Columns',TPropertyValue::ensureInteger($value),0);
+ }
+
+ /**
+ * @return integer the maximum number of characters allowed in the text box, default is 0 meaning not set.
+ */
+ public function getMaxLength()
+ {
+ return $this->getViewState('MaxLength',0);
+ }
+
+ /**
+ * Sets the maximum number of characters allowed in the text box.
+ * @param integer the maximum length, set it 0 to clear the setting
+ */
+ public function setMaxLength($value)
+ {
+ $this->setViewState('MaxLength',TPropertyValue::ensureInteger($value),0);
+ }
+
+ /**
+ * @return boolean whether the textbox is read only, default is false.
+ */
+ public function getReadOnly()
+ {
+ return $this->getViewState('ReadOnly',false);
+ }
+
+ /**
+ * @param boolean whether the textbox is read only
+ */
+ public function setReadOnly($value)
+ {
+ $this->setViewState('ReadOnly',TPropertyValue::ensureBoolean($value),false);
+ }
+
+ /**
+ * @return integer the number of rows displayed in a multiline text box, default is 4
+ */
+ public function getRows()
+ {
+ return $this->getViewState('Rows',self::DEFAULT_ROWS);
+ }
+
+ /**
+ * Sets the number of rows displayed in a multiline text box.
+ * @param integer the number of rows
+ */
+ public function setRows($value)
+ {
+ $this->setViewState('Rows',TPropertyValue::ensureInteger($value),self::DEFAULT_ROWS);
+ }
+
+ /**
+ * @return boolean whether password should be displayed in the textbox during postback. Defaults to false. This property only applies when TextMode='Password'.
+ */
+ public function getPersistPassword()
+ {
+ return $this->getViewState('PersistPassword',false);
+ }
+
+ /**
+ * @param boolean whether password should be displayed in the textbox during postback. This property only applies when TextMode='Password'.
+ */
+ public function setPersistPassword($value)
+ {
+ $this->setViewState('PersistPassword',TPropertyValue::ensureBoolean($value),false);
+ }
+
+ /**
+ * @return string the text content of the TTextBox control.
+ */
+ public function getText()
+ {
+ return $this->getViewState('Text','');
+ }
+
+ /**
+ * Sets the text content of the TTextBox control.
+ * @param string the text content
+ */
+ public function setText($value)
+ {
+ $this->setViewState('Text',$value,'');
+ $this->_safeText = null;
+ }
+
+ /**
+ * Returns the text content of the TTextBox control.
+ * This method is required by {@link IDataRenderer}.
+ * It is the same as {@link getText()}.
+ * @return string the text content of the TTextBox control.
+ * @see getText
+ * @since 3.1.0
+ */
+ public function getData()
+ {
+ return $this->getText();
+ }
+
+ /**
+ * Sets the text content of the TTextBox control.
+ * This method is required by {@link IDataRenderer}.
+ * It is the same as {@link setText()}.
+ * @param string the text content of the TTextBox control.
+ * @see setText
+ * @since 3.1.0
+ */
+ public function setData($value)
+ {
+ $this->setText($value);
+ }
+
+ /**
+ * @return string safe text content with javascript stripped off
+ */
+ public function getSafeText()
+ {
+ if($this->_safeText===null)
+ $this->_safeText=$this->getSafeTextParser()->parse($this->getText());
+ return $this->_safeText;
+ }
+
+ /**
+ * @return mixed safe text parser
+ */
+ protected function getSafeTextParser()
+ {
+ if(!self::$_safeTextParser)
+ self::$_safeTextParser=Prado::createComponent('System.3rdParty.SafeHtml.TSafeHtmlParser');
+ return self::$_safeTextParser;
+ }
+
+ /**
+ * @return TTextBoxMode the behavior mode of the TTextBox component. Defaults to TTextBoxMode::SingleLine.
+ */
+ public function getTextMode()
+ {
+ return $this->getViewState('TextMode',TTextBoxMode::SingleLine);
+ }
+
+ /**
+ * Sets the behavior mode of the TTextBox component.
+ * @param TTextBoxMode the text mode
+ * @throws TInvalidDataValueException if the input value is not a valid text mode.
+ */
+ public function setTextMode($value)
+ {
+ $this->setViewState('TextMode',TPropertyValue::ensureEnum($value,'TTextBoxMode'),TTextBoxMode::SingleLine);
+ }
+
+ /**
+ * @return string the group of validators which the text box causes validation upon postback
+ */
+ public function getValidationGroup()
+ {
+ return $this->getViewState('ValidationGroup','');
+ }
+
+ /**
+ * @param string the group of validators which the text box causes validation upon postback
+ */
+ public function setValidationGroup($value)
+ {
+ $this->setViewState('ValidationGroup',$value,'');
+ }
+
+ /**
+ * @return boolean whether the text content wraps within a multiline text box. Defaults to true.
+ */
+ public function getWrap()
+ {
+ return $this->getViewState('Wrap',true);
+ }
+
+ /**
+ * Sets the value indicating whether the text content wraps within a multiline text box.
+ * @param boolean whether the text content wraps within a multiline text box.
+ */
+ public function setWrap($value)
+ {
+ $this->setViewState('Wrap',TPropertyValue::ensureBoolean($value),true);
+ }
+}
+
+/**
+ * TTextBoxMode class.
+ * TTextBoxMode defines the enumerable type for the possible mode
+ * that a {@link TTextBox} control could be at.
+ *
+ * The following enumerable values are defined:
+ * - SingleLine: the textbox will be a regular single line input
+ * - MultiLine: the textbox will be a textarea allowing multiple line input
+ * - Password: the textbox will hide user input like a password input box
+ *
+ * @author Qiang Xue <qiang.xue@gmail.com>
+ * @version $Id$
+ * @package System.Web.UI.WebControls
+ * @since 3.0.4
+ */
+class TTextBoxMode extends TEnumerable
+{
+ const SingleLine='SingleLine';
+ const MultiLine='MultiLine';
+ const Password='Password';
+}
+
+/**
+ * TTextBoxAutoCompleteType class.
+ * TTextBoxAutoCompleteType defines the possible AutoComplete type that is supported
+ * by a {@link TTextBox} control.
+ *
+ * @author Qiang Xue <qiang.xue@gmail.com>
+ * @version $Id$
+ * @package System.Web.UI.WebControls
+ * @since 3.0.4
+ */
+class TTextBoxAutoCompleteType extends TEnumerable
+{
+ const BusinessCity='BusinessCity';
+ const BusinessCountryRegion='BusinessCountryRegion';
+ const BusinessFax='BusinessFax';
+ const BusinessPhone='BusinessPhone';
+ const BusinessState='BusinessState';
+ const BusinessStreetAddress='BusinessStreetAddress';
+ const BusinessUrl='BusinessUrl';
+ const BusinessZipCode='BusinessZipCode';
+ const Cellular='Cellular';
+ const Company='Company';
+ const Department='Department';
+ const Disabled='Disabled';
+ const DisplayName='DisplayName';
+ const Email='Email';
+ const FirstName='FirstName';
+ const Gender='Gender';
+ const HomeCity='HomeCity';
+ const HomeCountryRegion='HomeCountryRegion';
+ const HomeFax='HomeFax';
+ const Homepage='Homepage';
+ const HomePhone='HomePhone';
+ const HomeState='HomeState';
+ const HomeStreetAddress='HomeStreetAddress';
+ const HomeZipCode='HomeZipCode';
+ const JobTitle='JobTitle';
+ const LastName='LastName';
+ const MiddleName='MiddleName';
+ const None='None';
+ const Notes='Notes';
+ const Office='Office';
+ const Pager='Pager';
+ const Search='Search';
+}
+
diff --git a/framework/Web/UI/WebControls/TTextProcessor.php b/framework/Web/UI/WebControls/TTextProcessor.php
index 6d95a482..60d047fe 100644
--- a/framework/Web/UI/WebControls/TTextProcessor.php
+++ b/framework/Web/UI/WebControls/TTextProcessor.php
@@ -1,86 +1,86 @@
-<?php
-/**
- * TTextProcessor class file
- *
- * @author Qiang Xue <qiang.xue@gmail.com>
- * @link http://www.pradosoft.com/
+<?php
+/**
+ * TTextProcessor class file
+ *
+ * @author Qiang Xue <qiang.xue@gmail.com>
+ * @link http://www.pradosoft.com/
* @copyright Copyright &copy; 2005-2012 PradoSoft
- * @license http://www.pradosoft.com/license/
- * @version $Id$
- * @package System.Web.UI.WebControls
- */
-
-/**
- * TTextProcessor class.
- *
- * TTextProcessor is the base class for classes that process or transform
- * text content into different forms. The text content to be processed
- * is specified by {@link setText Text} property. If it is not set, the body
- * content enclosed within the processor control will be processed and rendered.
- * The body content includes static text strings and the rendering result
- * of child controls.
- *
- * Note, all child classes must implement {@link processText} method.
- *
- * @author Qiang Xue <qiang.xue@gmail.com>
- * @version $Id$
- * @package System.Web.UI
- * @since 3.0.1
- */
-abstract class TTextProcessor extends TWebControl
-{
- /**
- * Processes a text string.
- * This method must be implemented by child classes.
- * @param string text string to be processed
- * @return string the processed text result
- */
- abstract public function processText($text);
-
- /**
- * HTML-decodes static text.
- * This method overrides parent implementation.
- * @param mixed object to be added as body content
- */
- public function addParsedObject($object)
- {
- if(is_string($object))
- $object=html_entity_decode($object,ENT_QUOTES,'UTF-8');
- parent::addParsedObject($object);
- }
-
- /**
- * @return string text to be processed
- */
- public function getText()
- {
- return $this->getViewState('Text','');
- }
-
- /**
- * @param string text to be processed
- */
- public function setText($value)
- {
- $this->setViewState('Text',$value);
- }
-
- /**
- * Renders body content.
- * This method overrides the parent implementation by replacing
- * the body content with the processed text content.
- * @param THtmlWriter writer
- */
- public function renderContents($writer)
- {
- if(($text=$this->getText())==='' && $this->getHasControls())
- {
- $htmlWriter = Prado::createComponent($this->GetResponse()->getHtmlWriterType(), new TTextWriter());
- parent::renderContents($htmlWriter);
- $text=$htmlWriter->flush();
- }
- if($text!=='')
- $writer->write($this->processText($text));
- }
-
-}
+ * @license http://www.pradosoft.com/license/
+ * @version $Id$
+ * @package System.Web.UI.WebControls
+ */
+
+/**
+ * TTextProcessor class.
+ *
+ * TTextProcessor is the base class for classes that process or transform
+ * text content into different forms. The text content to be processed
+ * is specified by {@link setText Text} property. If it is not set, the body
+ * content enclosed within the processor control will be processed and rendered.
+ * The body content includes static text strings and the rendering result
+ * of child controls.
+ *
+ * Note, all child classes must implement {@link processText} method.
+ *
+ * @author Qiang Xue <qiang.xue@gmail.com>
+ * @version $Id$
+ * @package System.Web.UI
+ * @since 3.0.1
+ */
+abstract class TTextProcessor extends TWebControl
+{
+ /**
+ * Processes a text string.
+ * This method must be implemented by child classes.
+ * @param string text string to be processed
+ * @return string the processed text result
+ */
+ abstract public function processText($text);
+
+ /**
+ * HTML-decodes static text.
+ * This method overrides parent implementation.
+ * @param mixed object to be added as body content
+ */
+ public function addParsedObject($object)
+ {
+ if(is_string($object))
+ $object=html_entity_decode($object,ENT_QUOTES,'UTF-8');
+ parent::addParsedObject($object);
+ }
+
+ /**
+ * @return string text to be processed
+ */
+ public function getText()
+ {
+ return $this->getViewState('Text','');
+ }
+
+ /**
+ * @param string text to be processed
+ */
+ public function setText($value)
+ {
+ $this->setViewState('Text',$value);
+ }
+
+ /**
+ * Renders body content.
+ * This method overrides the parent implementation by replacing
+ * the body content with the processed text content.
+ * @param THtmlWriter writer
+ */
+ public function renderContents($writer)
+ {
+ if(($text=$this->getText())==='' && $this->getHasControls())
+ {
+ $htmlWriter = Prado::createComponent($this->GetResponse()->getHtmlWriterType(), new TTextWriter());
+ parent::renderContents($htmlWriter);
+ $text=$htmlWriter->flush();
+ }
+ if($text!=='')
+ $writer->write($this->processText($text));
+ }
+
+}
diff --git a/framework/Web/UI/WebControls/TValidationSummary.php b/framework/Web/UI/WebControls/TValidationSummary.php
index 6c258927..c915d163 100644
--- a/framework/Web/UI/WebControls/TValidationSummary.php
+++ b/framework/Web/UI/WebControls/TValidationSummary.php
@@ -1,536 +1,536 @@
-<?php
-/**
- * TValidationSummary class file
- *
- * @author Qiang Xue <qiang.xue@gmail.com>
- * @link http://www.pradosoft.com/
- * @copyright Copyright &copy; 2005-2012 PradoSoft
- * @license http://www.pradosoft.com/license/
- * @version $Id$
- * @package System.Web.UI.WebControls
- */
-
-/**
- * TValidationSummary class
- *
- * TValidationSummary displays a summary of validation errors inline on a Web page,
- * in a message box, or both. By default, a validation summary will collect
- * {@link TBaseValidator::getErrorMessage ErrorMessage} of all failed validators
- * on the page. If {@link getValidationGroup ValidationGroup} is not
- * empty, only those validators who belong to the group will show their error messages
- * in the summary.
- *
- * The summary can be displayed as a list, as a bulleted list, or as a single
- * paragraph based on the {@link setDisplayMode DisplayMode} property.
- * The messages shown can be prefixed with {@link setHeaderText HeaderText}.
- *
- * The summary can be displayed on the Web page and in a message box by setting
- * the {@link setShowSummary ShowSummary} and {@link setShowMessageBox ShowMessageBox}
- * properties, respectively. Note, the latter is only effective when
- * {@link setEnableClientScript EnableClientScript} is true.
- *
- * @author Qiang Xue <qiang.xue@gmail.com>
- * @version $Id$
- * @package System.Web.UI.WebControls
- * @since 3.0
- */
-class TValidationSummary extends TWebControl
-{
- /**
- * @var TClientSideValidationSummaryOptions validation client side options.
- */
- private $_clientSide;
-
- /**
- * Constructor.
- * This method sets the foreground color to red.
- */
- public function __construct()
- {
- parent::__construct();
- $this->setForeColor('red');
- }
-
- /**
- * @return TValidationSummaryDisplayStyle the style of displaying the error messages. Defaults to TValidationSummaryDisplayStyle::Fixed.
- */
- public function getDisplay()
- {
- return $this->getViewState('Display',TValidationSummaryDisplayStyle::Fixed);
- }
-
- /**
- * @param TValidationSummaryDisplayStyle the style of displaying the error messages
- */
- public function setDisplay($value)
- {
- $this->setViewState('Display',TPropertyValue::ensureEnum($value,'TValidationSummaryDisplayStyle'),TValidationSummaryDisplayStyle::Fixed);
- }
-
- /**
- * @return string the header text displayed at the top of the summary
- */
- public function getHeaderText()
- {
- return $this->getViewState('HeaderText','');
- }
-
- /**
- * Sets the header text to be displayed at the top of the summary
- * @param string the header text
- */
- public function setHeaderText($value)
- {
- $this->setViewState('HeaderText',$value,'');
- }
-
- /**
- * @return TValidationSummaryDisplayMode the mode of displaying error messages. Defaults to TValidationSummaryDisplayMode::BulletList.
- */
- public function getDisplayMode()
- {
- return $this->getViewState('DisplayMode',TValidationSummaryDisplayMode::BulletList);
- }
-
- /**
- * @param TValidationSummaryDisplayMode the mode of displaying error messages
- */
- public function setDisplayMode($value)
- {
- $this->setViewState('DisplayMode',TPropertyValue::ensureEnum($value,'TValidationSummaryDisplayMode'),TValidationSummaryDisplayMode::BulletList);
- }
-
- /**
- * @return boolean whether the TValidationSummary component updates itself using client-side script. Defaults to true.
- */
- public function getEnableClientScript()
- {
- return $this->getViewState('EnableClientScript',true);
- }
-
- /**
- * @param boolean whether the TValidationSummary component updates itself using client-side script.
- */
- public function setEnableClientScript($value)
- {
- $this->setViewState('EnableClientScript',TPropertyValue::ensureBoolean($value),true);
- }
-
- /**
- * @return boolean whether the validation summary is displayed in a message box. Defaults to false.
- */
- public function getShowMessageBox()
- {
- return $this->getViewState('ShowMessageBox',false);
- }
-
- /**
- * @param boolean whether the validation summary is displayed in a message box.
- */
- public function setShowMessageBox($value)
- {
- $this->setViewState('ShowMessageBox',TPropertyValue::ensureBoolean($value),false);
- }
-
- /**
- * @return boolean whether the validation summary is displayed inline. Defaults to true.
- */
- public function getShowSummary()
- {
- return $this->getViewState('ShowSummary',true);
- }
-
- /**
- * @param boolean whether the validation summary is displayed inline.
- */
- public function setShowSummary($value)
- {
- $this->setViewState('ShowSummary',TPropertyValue::ensureBoolean($value),true);
- }
-
- /**
- * @return boolean whether scroll summary into viewport or not. Defaults to true.
- */
- public function getScrollToSummary()
- {
- return $this->getViewState('ScrollToSummary',true);
- }
-
- /**
- * @param boolean whether scroll summary into viewport or not.
- */
- public function setScrollToSummary($value)
- {
- $this->setViewState('ScrollToSummary',TPropertyValue::ensureBoolean($value),true);
- }
-
- /**
- * @return boolean whether the validation summary should be anchored. Defaults to false.
- */
- public function getShowAnchor()
- {
- return $this->getViewState('ShowAnchor',false);
- }
-
- /**
- * @param boolean whether the validation summary should be anchored.
- */
- public function setShowAnchor($value)
- {
- $this->setViewState('ShowAnchor',TPropertyValue::ensureBoolean($value),false);
- }
-
- /**
- * Gets the auto-update for this summary.
- * @return boolean automatic client-side summary updates. Defaults to true.
- */
- public function getAutoUpdate()
- {
- return $this->getViewState('AutoUpdate', true);
- }
-
- /**
- * Sets the summary to auto-update on the client-side
- * @param boolean true for automatic summary updates.
- */
- public function setAutoUpdate($value)
- {
- $this->setViewState('AutoUpdate', TPropertyValue::ensureBoolean($value), true);
- }
-
- /**
- * @return string the group which this validator belongs to
- */
- public function getValidationGroup()
- {
- return $this->getViewState('ValidationGroup','');
- }
-
- /**
- * @param string the group which this validator belongs to
- */
- public function setValidationGroup($value)
- {
- $this->setViewState('ValidationGroup',$value,'');
- }
-
- protected function addAttributesToRender($writer)
- {
- $display=$this->getDisplay();
- $visible=$this->getEnabled(true) && count($this->getErrorMessages()) > 0;
- if(!$visible)
- {
- if($display===TValidationSummaryDisplayStyle::None || $display===TValidationSummaryDisplayStyle::Dynamic)
- $writer->addStyleAttribute('display','none');
- else
- $writer->addStyleAttribute('visibility','hidden');
- }
- $writer->addAttribute('id',$this->getClientID());
- parent::addAttributesToRender($writer);
- }
-
- /**
- * Render the javascript for validation summary.
- * @param array list of options for validation summary.
- */
- protected function renderJsSummary()
- {
- if(!$this->getEnabled(true) || !$this->getEnableClientScript())
- return;
- $cs = $this->getPage()->getClientScript();
- $cs->registerPradoScript('validator');
-
- //need to register the validation manager is validation summary is alone.
- $formID=$this->getPage()->getForm()->getClientID();
- $scriptKey = "TBaseValidator:$formID";
- if($this->getEnableClientScript() && !$cs->isEndScriptRegistered($scriptKey))
- {
- $manager['FormID'] = $formID;
- $options = TJavaScript::encode($manager);
- $cs->registerPradoScript('validator');
- $cs->registerEndScript($scriptKey, "new Prado.ValidationManager({$options});");
- }
-
-
- $options=TJavaScript::encode($this->getClientScriptOptions());
- $script = "new Prado.WebUI.TValidationSummary({$options});";
- $cs->registerEndScript($this->getClientID(), $script);
- }
-
- /**
- * Get a list of options for the client-side javascript validation summary.
- * @return array list of options for the summary
- */
- protected function getClientScriptOptions()
- {
- $options['ID'] = $this->getClientID();
- $options['FormID'] = $this->getPage()->getForm()->getClientID();
- if($this->getShowMessageBox())
- $options['ShowMessageBox']=true;
- if(!$this->getShowSummary())
- $options['ShowSummary']=false;
-
- $options['ScrollToSummary']=$this->getScrollToSummary();
- $options['HeaderText']=$this->getHeaderText();
- $options['DisplayMode']=$this->getDisplayMode();
-
- $options['Refresh'] = $this->getAutoUpdate();
- $options['ValidationGroup'] = $this->getValidationGroup();
- $options['Display'] = $this->getDisplay();
-
- if($this->_clientSide!==null)
- $options = array_merge($options,$this->_clientSide->getOptions()->toArray());
-
- return $options;
- }
-
- /**
- * @return TClientSideValidationSummaryOptions client-side validation summary
- * event options.
- */
- public function getClientSide()
- {
- if($this->_clientSide===null)
- $this->_clientSide = $this->createClientScript();
- return $this->_clientSide;
- }
-
- /**
- * @return TClientSideValidationSummaryOptions javascript validation summary
- * event options.
- */
- protected function createClientScript()
- {
- return new TClientSideValidationSummaryOptions;
- }
- /**
- * Get the list of validation error messages.
- * @return array list of validator error messages.
- */
- protected function getErrorMessages()
- {
- $validators=$this->getPage()->getValidators($this->getValidationGroup());
- $messages = array();
- foreach($validators as $validator)
- {
- if(!$validator->getIsValid() && ($msg=$validator->getErrorMessage())!=='')
- //$messages[] = $validator->getAnchoredMessage($msg);
- $messages[] = $msg;
- }
- return $messages;
- }
-
- /**
- * Overrides parent implementation by rendering TValidationSummary-specific presentation.
- * @return string the rendering result
- */
- public function renderContents($writer)
- {
- $this->renderJsSummary();
- if($this->getShowSummary())
- {
-// $this->setStyle('display:block');
- switch($this->getDisplayMode())
- {
- case TValidationSummaryDisplayMode::SimpleList:
- $this->renderList($writer);
- break;
- case TValidationSummaryDisplayMode::SingleParagraph:
- $this->renderSingleParagraph($writer);
- break;
- case TValidationSummaryDisplayMode::BulletList:
- $this->renderBulletList($writer);
- break;
- case TValidationSummaryDisplayMode::HeaderOnly:
- $this->renderHeaderOnly($writer);
- break;
- }
- }
- }
-
- /**
- * Render the validation summary as a simple list.
- * @param array list of messages
- * @param string the header text
- * @return string summary list
- */
- protected function renderList($writer)
- {
- $header=$this->getHeaderText();
- $messages=$this->getErrorMessages();
- $content = '';
- if(strlen($header))
- $content.= $header."<br/>\n";
- foreach($messages as $message)
- $content.="$message<br/>\n";
- $writer->write($content);
- }
-
- /**
- * Render the validation summary as a paragraph.
- * @param array list of messages
- * @param string the header text
- * @return string summary paragraph
- */
- protected function renderSingleParagraph($writer)
- {
- $header=$this->getHeaderText();
- $messages=$this->getErrorMessages();
- $content = $header;
- foreach($messages as $message)
- $content.= ' '.$message;
- $writer->write($content);
- }
-
- /**
- * Render the validation summary as a bullet list.
- * @param array list of messages
- * @param string the header text
- * @return string summary bullet list
- */
- protected function renderBulletList($writer)
- {
- $header=$this->getHeaderText();
- $messages=$this->getErrorMessages();
- $content = $header;
- if(count($messages)>0)
- {
- $content .= "<ul>\n";
- foreach($messages as $message)
- $content.= '<li>'.$message."</li>\n";
- $content .= "</ul>\n";
- }
- $writer->write($content);
- }
-
- /**
- * Render the validation summary header text only.
- * @param THtmlWriter the writer used for the rendering purpose
- */
- protected function renderHeaderOnly($writer)
- {
- $writer->write($this->getHeaderText());
- }
-}
-
-/**
- * TClientSideValidationSummaryOptions class.
- *
- * Client-side validation summary events such as {@link setOnHideSummary
- * OnHideSummary} and {@link setOnShowSummary OnShowSummary} can be modified
- * through the {@link TBaseValidator:: getClientSide ClientSide} property of a
- * validation summary.
- *
- * The <tt>OnHideSummary</tt> event is raise when the validation summary
- * requests to hide the messages.
- *
- * The <tt>OnShowSummary</tt> event is raised when the validation summary
- * requests to show the messages.
- *
- * See the quickstart documentation for further details.
- *
- * @author Wei Zhuo <weizhuo[at]gmail[dot]com>
- * @version $Id$
- * @package System.Web.UI.WebControls
- * @since 3.0
- */
-class TClientSideValidationSummaryOptions extends TClientSideOptions
-{
- /**
- * @return string javascript code for client-side OnHideSummary event.
- */
- public function getOnHideSummary()
- {
- return $this->getOption('OnHideSummary');
- }
-
- /**
- * Client-side OnHideSummary validation summary event is raise when all the
- * validators are valid. This will override the default client-side
- * validation summary behaviour.
- * @param string javascript code for client-side OnHideSummary event.
- */
- public function setOnHideSummary($javascript)
- {
- $this->setFunction('OnHideSummary', $javascript);
- }
-
- /**
- * Client-side OnShowSummary event is raise when one or more validators are
- * not valid. This will override the default client-side validation summary
- * behaviour.
- * @param string javascript code for client-side OnShowSummary event.
- */
- public function setOnShowSummary($javascript)
- {
- $this->setFunction('OnShowSummary', $javascript);
- }
-
- /**
- * @return string javascript code for client-side OnShowSummary event.
- */
- public function getOnShowSummary()
- {
- return $this->getOption('OnShowSummary');
- }
-
- /**
- * Ensure the string is a valid javascript function. The code block
- * is enclosed with "function(summary, validators){ }" block.
- * @param string javascript code.
- * @return string javascript function code.
- */
- protected function ensureFunction($javascript)
- {
- return "function(summary, validators){ {$javascript} }";
- }
-}
-
-
-/**
- * TValidationSummaryDisplayMode class.
- * TValidationSummaryDisplayMode defines the enumerable type for the possible modes
- * that a {@link TValidationSummary} can organize and display the collected error messages.
- *
- * The following enumerable values are defined:
- * - SimpleList: the error messages are displayed as a list without any decorations.
- * - SingleParagraph: the error messages are concatenated together into a paragraph.
- * - BulletList: the error messages are displayed as a bulleted list.
- * - HeaderOnly: only the HeaderText will be display.
- *
- * @author Qiang Xue <qiang.xue@gmail.com>
- * @version $Id$
- * @package System.Web.UI.WebControls
- * @since 3.0.4
- */
-class TValidationSummaryDisplayMode extends TEnumerable
-{
- const SimpleList='SimpleList';
- const SingleParagraph='SingleParagraph';
- const BulletList='BulletList';
- const HeaderOnly='HeaderOnly';
-}
-
-
-/**
- * TValidationSummaryDisplay class.
- * TValidationSummaryDisplay defines the enumerable type for the possible styles
- * that a {@link TValidationSummary} can display the collected error messages.
- *
- * The following enumerable values are defined:
- * - None: the error messages are not displayed
- * - Dynamic: the error messages are dynamically added to display as the corresponding validators fail
- * - Fixed: Similar to Dynamic except that the error messages physically occupy the page layout (even though they may not be visible)
- *
- * @author Qiang Xue <qiang.xue@gmail.com>
- * @version $Id$
- * @package System.Web.UI.WebControls
- * @since 3.0.4
- */
-class TValidationSummaryDisplayStyle extends TEnumerable
-{
- const None='None';
- const Dynamic='Dynamic';
- const Fixed='Fixed';
-}
-
+<?php
+/**
+ * TValidationSummary class file
+ *
+ * @author Qiang Xue <qiang.xue@gmail.com>
+ * @link http://www.pradosoft.com/
+ * @copyright Copyright &copy; 2005-2012 PradoSoft
+ * @license http://www.pradosoft.com/license/
+ * @version $Id$
+ * @package System.Web.UI.WebControls
+ */
+
+/**
+ * TValidationSummary class
+ *
+ * TValidationSummary displays a summary of validation errors inline on a Web page,
+ * in a message box, or both. By default, a validation summary will collect
+ * {@link TBaseValidator::getErrorMessage ErrorMessage} of all failed validators
+ * on the page. If {@link getValidationGroup ValidationGroup} is not
+ * empty, only those validators who belong to the group will show their error messages
+ * in the summary.
+ *
+ * The summary can be displayed as a list, as a bulleted list, or as a single
+ * paragraph based on the {@link setDisplayMode DisplayMode} property.
+ * The messages shown can be prefixed with {@link setHeaderText HeaderText}.
+ *
+ * The summary can be displayed on the Web page and in a message box by setting
+ * the {@link setShowSummary ShowSummary} and {@link setShowMessageBox ShowMessageBox}
+ * properties, respectively. Note, the latter is only effective when
+ * {@link setEnableClientScript EnableClientScript} is true.
+ *
+ * @author Qiang Xue <qiang.xue@gmail.com>
+ * @version $Id$
+ * @package System.Web.UI.WebControls
+ * @since 3.0
+ */
+class TValidationSummary extends TWebControl
+{
+ /**
+ * @var TClientSideValidationSummaryOptions validation client side options.
+ */
+ private $_clientSide;
+
+ /**
+ * Constructor.
+ * This method sets the foreground color to red.
+ */
+ public function __construct()
+ {
+ parent::__construct();
+ $this->setForeColor('red');
+ }
+
+ /**
+ * @return TValidationSummaryDisplayStyle the style of displaying the error messages. Defaults to TValidationSummaryDisplayStyle::Fixed.
+ */
+ public function getDisplay()
+ {
+ return $this->getViewState('Display',TValidationSummaryDisplayStyle::Fixed);
+ }
+
+ /**
+ * @param TValidationSummaryDisplayStyle the style of displaying the error messages
+ */
+ public function setDisplay($value)
+ {
+ $this->setViewState('Display',TPropertyValue::ensureEnum($value,'TValidationSummaryDisplayStyle'),TValidationSummaryDisplayStyle::Fixed);
+ }
+
+ /**
+ * @return string the header text displayed at the top of the summary
+ */
+ public function getHeaderText()
+ {
+ return $this->getViewState('HeaderText','');
+ }
+
+ /**
+ * Sets the header text to be displayed at the top of the summary
+ * @param string the header text
+ */
+ public function setHeaderText($value)
+ {
+ $this->setViewState('HeaderText',$value,'');
+ }
+
+ /**
+ * @return TValidationSummaryDisplayMode the mode of displaying error messages. Defaults to TValidationSummaryDisplayMode::BulletList.
+ */
+ public function getDisplayMode()
+ {
+ return $this->getViewState('DisplayMode',TValidationSummaryDisplayMode::BulletList);
+ }
+
+ /**
+ * @param TValidationSummaryDisplayMode the mode of displaying error messages
+ */
+ public function setDisplayMode($value)
+ {
+ $this->setViewState('DisplayMode',TPropertyValue::ensureEnum($value,'TValidationSummaryDisplayMode'),TValidationSummaryDisplayMode::BulletList);
+ }
+
+ /**
+ * @return boolean whether the TValidationSummary component updates itself using client-side script. Defaults to true.
+ */
+ public function getEnableClientScript()
+ {
+ return $this->getViewState('EnableClientScript',true);
+ }
+
+ /**
+ * @param boolean whether the TValidationSummary component updates itself using client-side script.
+ */
+ public function setEnableClientScript($value)
+ {
+ $this->setViewState('EnableClientScript',TPropertyValue::ensureBoolean($value),true);
+ }
+
+ /**
+ * @return boolean whether the validation summary is displayed in a message box. Defaults to false.
+ */
+ public function getShowMessageBox()
+ {
+ return $this->getViewState('ShowMessageBox',false);
+ }
+
+ /**
+ * @param boolean whether the validation summary is displayed in a message box.
+ */
+ public function setShowMessageBox($value)
+ {
+ $this->setViewState('ShowMessageBox',TPropertyValue::ensureBoolean($value),false);
+ }
+
+ /**
+ * @return boolean whether the validation summary is displayed inline. Defaults to true.
+ */
+ public function getShowSummary()
+ {
+ return $this->getViewState('ShowSummary',true);
+ }
+
+ /**
+ * @param boolean whether the validation summary is displayed inline.
+ */
+ public function setShowSummary($value)
+ {
+ $this->setViewState('ShowSummary',TPropertyValue::ensureBoolean($value),true);
+ }
+
+ /**
+ * @return boolean whether scroll summary into viewport or not. Defaults to true.
+ */
+ public function getScrollToSummary()
+ {
+ return $this->getViewState('ScrollToSummary',true);
+ }
+
+ /**
+ * @param boolean whether scroll summary into viewport or not.
+ */
+ public function setScrollToSummary($value)
+ {
+ $this->setViewState('ScrollToSummary',TPropertyValue::ensureBoolean($value),true);
+ }
+
+ /**
+ * @return boolean whether the validation summary should be anchored. Defaults to false.
+ */
+ public function getShowAnchor()
+ {
+ return $this->getViewState('ShowAnchor',false);
+ }
+
+ /**
+ * @param boolean whether the validation summary should be anchored.
+ */
+ public function setShowAnchor($value)
+ {
+ $this->setViewState('ShowAnchor',TPropertyValue::ensureBoolean($value),false);
+ }
+
+ /**
+ * Gets the auto-update for this summary.
+ * @return boolean automatic client-side summary updates. Defaults to true.
+ */
+ public function getAutoUpdate()
+ {
+ return $this->getViewState('AutoUpdate', true);
+ }
+
+ /**
+ * Sets the summary to auto-update on the client-side
+ * @param boolean true for automatic summary updates.
+ */
+ public function setAutoUpdate($value)
+ {
+ $this->setViewState('AutoUpdate', TPropertyValue::ensureBoolean($value), true);
+ }
+
+ /**
+ * @return string the group which this validator belongs to
+ */
+ public function getValidationGroup()
+ {
+ return $this->getViewState('ValidationGroup','');
+ }
+
+ /**
+ * @param string the group which this validator belongs to
+ */
+ public function setValidationGroup($value)
+ {
+ $this->setViewState('ValidationGroup',$value,'');
+ }
+
+ protected function addAttributesToRender($writer)
+ {
+ $display=$this->getDisplay();
+ $visible=$this->getEnabled(true) && count($this->getErrorMessages()) > 0;
+ if(!$visible)
+ {
+ if($display===TValidationSummaryDisplayStyle::None || $display===TValidationSummaryDisplayStyle::Dynamic)
+ $writer->addStyleAttribute('display','none');
+ else
+ $writer->addStyleAttribute('visibility','hidden');
+ }
+ $writer->addAttribute('id',$this->getClientID());
+ parent::addAttributesToRender($writer);
+ }
+
+ /**
+ * Render the javascript for validation summary.
+ * @param array list of options for validation summary.
+ */
+ protected function renderJsSummary()
+ {
+ if(!$this->getEnabled(true) || !$this->getEnableClientScript())
+ return;
+ $cs = $this->getPage()->getClientScript();
+ $cs->registerPradoScript('validator');
+
+ //need to register the validation manager is validation summary is alone.
+ $formID=$this->getPage()->getForm()->getClientID();
+ $scriptKey = "TBaseValidator:$formID";
+ if($this->getEnableClientScript() && !$cs->isEndScriptRegistered($scriptKey))
+ {
+ $manager['FormID'] = $formID;
+ $options = TJavaScript::encode($manager);
+ $cs->registerPradoScript('validator');
+ $cs->registerEndScript($scriptKey, "new Prado.ValidationManager({$options});");
+ }
+
+
+ $options=TJavaScript::encode($this->getClientScriptOptions());
+ $script = "new Prado.WebUI.TValidationSummary({$options});";
+ $cs->registerEndScript($this->getClientID(), $script);
+ }
+
+ /**
+ * Get a list of options for the client-side javascript validation summary.
+ * @return array list of options for the summary
+ */
+ protected function getClientScriptOptions()
+ {
+ $options['ID'] = $this->getClientID();
+ $options['FormID'] = $this->getPage()->getForm()->getClientID();
+ if($this->getShowMessageBox())
+ $options['ShowMessageBox']=true;
+ if(!$this->getShowSummary())
+ $options['ShowSummary']=false;
+
+ $options['ScrollToSummary']=$this->getScrollToSummary();
+ $options['HeaderText']=$this->getHeaderText();
+ $options['DisplayMode']=$this->getDisplayMode();
+
+ $options['Refresh'] = $this->getAutoUpdate();
+ $options['ValidationGroup'] = $this->getValidationGroup();
+ $options['Display'] = $this->getDisplay();
+
+ if($this->_clientSide!==null)
+ $options = array_merge($options,$this->_clientSide->getOptions()->toArray());
+
+ return $options;
+ }
+
+ /**
+ * @return TClientSideValidationSummaryOptions client-side validation summary
+ * event options.
+ */
+ public function getClientSide()
+ {
+ if($this->_clientSide===null)
+ $this->_clientSide = $this->createClientScript();
+ return $this->_clientSide;
+ }
+
+ /**
+ * @return TClientSideValidationSummaryOptions javascript validation summary
+ * event options.
+ */
+ protected function createClientScript()
+ {
+ return new TClientSideValidationSummaryOptions;
+ }
+ /**
+ * Get the list of validation error messages.
+ * @return array list of validator error messages.
+ */
+ protected function getErrorMessages()
+ {
+ $validators=$this->getPage()->getValidators($this->getValidationGroup());
+ $messages = array();
+ foreach($validators as $validator)
+ {
+ if(!$validator->getIsValid() && ($msg=$validator->getErrorMessage())!=='')
+ //$messages[] = $validator->getAnchoredMessage($msg);
+ $messages[] = $msg;
+ }
+ return $messages;
+ }
+
+ /**
+ * Overrides parent implementation by rendering TValidationSummary-specific presentation.
+ * @return string the rendering result
+ */
+ public function renderContents($writer)
+ {
+ $this->renderJsSummary();
+ if($this->getShowSummary())
+ {
+// $this->setStyle('display:block');
+ switch($this->getDisplayMode())
+ {
+ case TValidationSummaryDisplayMode::SimpleList:
+ $this->renderList($writer);
+ break;
+ case TValidationSummaryDisplayMode::SingleParagraph:
+ $this->renderSingleParagraph($writer);
+ break;
+ case TValidationSummaryDisplayMode::BulletList:
+ $this->renderBulletList($writer);
+ break;
+ case TValidationSummaryDisplayMode::HeaderOnly:
+ $this->renderHeaderOnly($writer);
+ break;
+ }
+ }
+ }
+
+ /**
+ * Render the validation summary as a simple list.
+ * @param array list of messages
+ * @param string the header text
+ * @return string summary list
+ */
+ protected function renderList($writer)
+ {
+ $header=$this->getHeaderText();
+ $messages=$this->getErrorMessages();
+ $content = '';
+ if(strlen($header))
+ $content.= $header."<br/>\n";
+ foreach($messages as $message)
+ $content.="$message<br/>\n";
+ $writer->write($content);
+ }
+
+ /**
+ * Render the validation summary as a paragraph.
+ * @param array list of messages
+ * @param string the header text
+ * @return string summary paragraph
+ */
+ protected function renderSingleParagraph($writer)
+ {
+ $header=$this->getHeaderText();
+ $messages=$this->getErrorMessages();
+ $content = $header;
+ foreach($messages as $message)
+ $content.= ' '.$message;
+ $writer->write($content);
+ }
+
+ /**
+ * Render the validation summary as a bullet list.
+ * @param array list of messages
+ * @param string the header text
+ * @return string summary bullet list
+ */
+ protected function renderBulletList($writer)
+ {
+ $header=$this->getHeaderText();
+ $messages=$this->getErrorMessages();
+ $content = $header;
+ if(count($messages)>0)
+ {
+ $content .= "<ul>\n";
+ foreach($messages as $message)
+ $content.= '<li>'.$message."</li>\n";
+ $content .= "</ul>\n";
+ }
+ $writer->write($content);
+ }
+
+ /**
+ * Render the validation summary header text only.
+ * @param THtmlWriter the writer used for the rendering purpose
+ */
+ protected function renderHeaderOnly($writer)
+ {
+ $writer->write($this->getHeaderText());
+ }
+}
+
+/**
+ * TClientSideValidationSummaryOptions class.
+ *
+ * Client-side validation summary events such as {@link setOnHideSummary
+ * OnHideSummary} and {@link setOnShowSummary OnShowSummary} can be modified
+ * through the {@link TBaseValidator:: getClientSide ClientSide} property of a
+ * validation summary.
+ *
+ * The <tt>OnHideSummary</tt> event is raise when the validation summary
+ * requests to hide the messages.
+ *
+ * The <tt>OnShowSummary</tt> event is raised when the validation summary
+ * requests to show the messages.
+ *
+ * See the quickstart documentation for further details.
+ *
+ * @author Wei Zhuo <weizhuo[at]gmail[dot]com>
+ * @version $Id$
+ * @package System.Web.UI.WebControls
+ * @since 3.0
+ */
+class TClientSideValidationSummaryOptions extends TClientSideOptions
+{
+ /**
+ * @return string javascript code for client-side OnHideSummary event.
+ */
+ public function getOnHideSummary()
+ {
+ return $this->getOption('OnHideSummary');
+ }
+
+ /**
+ * Client-side OnHideSummary validation summary event is raise when all the
+ * validators are valid. This will override the default client-side
+ * validation summary behaviour.
+ * @param string javascript code for client-side OnHideSummary event.
+ */
+ public function setOnHideSummary($javascript)
+ {
+ $this->setFunction('OnHideSummary', $javascript);
+ }
+
+ /**
+ * Client-side OnShowSummary event is raise when one or more validators are
+ * not valid. This will override the default client-side validation summary
+ * behaviour.
+ * @param string javascript code for client-side OnShowSummary event.
+ */
+ public function setOnShowSummary($javascript)
+ {
+ $this->setFunction('OnShowSummary', $javascript);
+ }
+
+ /**
+ * @return string javascript code for client-side OnShowSummary event.
+ */
+ public function getOnShowSummary()
+ {
+ return $this->getOption('OnShowSummary');
+ }
+
+ /**
+ * Ensure the string is a valid javascript function. The code block
+ * is enclosed with "function(summary, validators){ }" block.
+ * @param string javascript code.
+ * @return string javascript function code.
+ */
+ protected function ensureFunction($javascript)
+ {
+ return "function(summary, validators){ {$javascript} }";
+ }
+}
+
+
+/**
+ * TValidationSummaryDisplayMode class.
+ * TValidationSummaryDisplayMode defines the enumerable type for the possible modes
+ * that a {@link TValidationSummary} can organize and display the collected error messages.
+ *
+ * The following enumerable values are defined:
+ * - SimpleList: the error messages are displayed as a list without any decorations.
+ * - SingleParagraph: the error messages are concatenated together into a paragraph.
+ * - BulletList: the error messages are displayed as a bulleted list.
+ * - HeaderOnly: only the HeaderText will be display.
+ *
+ * @author Qiang Xue <qiang.xue@gmail.com>
+ * @version $Id$
+ * @package System.Web.UI.WebControls
+ * @since 3.0.4
+ */
+class TValidationSummaryDisplayMode extends TEnumerable
+{
+ const SimpleList='SimpleList';
+ const SingleParagraph='SingleParagraph';
+ const BulletList='BulletList';
+ const HeaderOnly='HeaderOnly';
+}
+
+
+/**
+ * TValidationSummaryDisplay class.
+ * TValidationSummaryDisplay defines the enumerable type for the possible styles
+ * that a {@link TValidationSummary} can display the collected error messages.
+ *
+ * The following enumerable values are defined:
+ * - None: the error messages are not displayed
+ * - Dynamic: the error messages are dynamically added to display as the corresponding validators fail
+ * - Fixed: Similar to Dynamic except that the error messages physically occupy the page layout (even though they may not be visible)
+ *
+ * @author Qiang Xue <qiang.xue@gmail.com>
+ * @version $Id$
+ * @package System.Web.UI.WebControls
+ * @since 3.0.4
+ */
+class TValidationSummaryDisplayStyle extends TEnumerable
+{
+ const None='None';
+ const Dynamic='Dynamic';
+ const Fixed='Fixed';
+}
+
diff --git a/framework/Web/UI/WebControls/TWebControlAdapter.php b/framework/Web/UI/WebControls/TWebControlAdapter.php
index 68fecf1c..ad1e1642 100644
--- a/framework/Web/UI/WebControls/TWebControlAdapter.php
+++ b/framework/Web/UI/WebControls/TWebControlAdapter.php
@@ -1,71 +1,71 @@
-<?php
-/**
- * TWebControlAdapter class file.
- *
- * @author Qiang Xue <qiang.xue@gmail.com>
- * @link http://www.pradosoft.com/
+<?php
+/**
+ * TWebControlAdapter class file.
+ *
+ * @author Qiang Xue <qiang.xue@gmail.com>
+ * @link http://www.pradosoft.com/
* @copyright Copyright &copy; 2005-2012 PradoSoft
- * @license http://www.pradosoft.com/license/
- * @version $Id$
- * @package System.Web.UI.WebControls
- */
-
-/**
- * TWebControlAdapter class
- *
- * TWebControlAdapter is the base class for adapters that customize
- * rendering for the Web control to which the adapter is attached.
- * It may be used to modify the default markup or behavior for specific
- * browsers.
- *
- * @author Qiang Xue <qiang.xue@gmail.com>
- * @version $Id$
- * @package System.Web.UI.WebControls
- * @since 3.0
- */
-class TWebControlAdapter extends TControlAdapter
-{
- /**
- * Renders the control to which the adapter is attached.
- * It calls {@link renderBeginTag}, {@link renderContents} and
- * {@link renderEndTag} in order.
- * @param THtmlWriter writer for the rendering purpose
- */
- public function render($writer)
- {
- $this->renderBeginTag($writer);
- $this->renderContents($writer);
- $this->renderEndTag($writer);
- }
-
- /**
- * Renders the openning tag for the attached control.
- * Default implementation calls the attached control's corresponding method.
- * @param THtmlWriter writer for the rendering purpose
- */
- public function renderBeginTag($writer)
- {
- $this->getControl()->renderBeginTag($writer);
- }
-
- /**
- * Renders the body contents within the attached control tag.
- * Default implementation calls the attached control's corresponding method.
- * @param THtmlWriter writer for the rendering purpose
- */
- public function renderContents($writer)
- {
- $this->getControl()->renderContents($writer);
- }
-
- /**
- * Renders the closing tag for the attached control.
- * Default implementation calls the attached control's corresponding method.
- * @param THtmlWriter writer for the rendering purpose
- */
- public function renderEndTag($writer)
- {
- $this->getControl()->renderEndTag($writer);
- }
-}
-
+ * @license http://www.pradosoft.com/license/
+ * @version $Id$
+ * @package System.Web.UI.WebControls
+ */
+
+/**
+ * TWebControlAdapter class
+ *
+ * TWebControlAdapter is the base class for adapters that customize
+ * rendering for the Web control to which the adapter is attached.
+ * It may be used to modify the default markup or behavior for specific
+ * browsers.
+ *
+ * @author Qiang Xue <qiang.xue@gmail.com>
+ * @version $Id$
+ * @package System.Web.UI.WebControls
+ * @since 3.0
+ */
+class TWebControlAdapter extends TControlAdapter
+{
+ /**
+ * Renders the control to which the adapter is attached.
+ * It calls {@link renderBeginTag}, {@link renderContents} and
+ * {@link renderEndTag} in order.
+ * @param THtmlWriter writer for the rendering purpose
+ */
+ public function render($writer)
+ {
+ $this->renderBeginTag($writer);
+ $this->renderContents($writer);
+ $this->renderEndTag($writer);
+ }
+
+ /**
+ * Renders the openning tag for the attached control.
+ * Default implementation calls the attached control's corresponding method.
+ * @param THtmlWriter writer for the rendering purpose
+ */
+ public function renderBeginTag($writer)
+ {
+ $this->getControl()->renderBeginTag($writer);
+ }
+
+ /**
+ * Renders the body contents within the attached control tag.
+ * Default implementation calls the attached control's corresponding method.
+ * @param THtmlWriter writer for the rendering purpose
+ */
+ public function renderContents($writer)
+ {
+ $this->getControl()->renderContents($writer);
+ }
+
+ /**
+ * Renders the closing tag for the attached control.
+ * Default implementation calls the attached control's corresponding method.
+ * @param THtmlWriter writer for the rendering purpose
+ */
+ public function renderEndTag($writer)
+ {
+ $this->getControl()->renderEndTag($writer);
+ }
+}
+
diff --git a/framework/Web/UI/WebControls/TWizard.php b/framework/Web/UI/WebControls/TWizard.php
index 25d3a41b..b497d719 100644
--- a/framework/Web/UI/WebControls/TWizard.php
+++ b/framework/Web/UI/WebControls/TWizard.php
@@ -1,1402 +1,1402 @@
-<?php
-/**
- * TWizard and the relevant class definitions.
- *
- * @author Qiang Xue <qiang.xue@gmail.com>
- * @link http://www.pradosoft.com/
+<?php
+/**
+ * TWizard and the relevant class definitions.
+ *
+ * @author Qiang Xue <qiang.xue@gmail.com>
+ * @link http://www.pradosoft.com/
* @copyright Copyright &copy; 2005-2012 PradoSoft
- * @license http://www.pradosoft.com/license/
- * @version $Id$
- * @package System.Web.UI.WebControls
- */
-
-Prado::using('System.Web.UI.WebControls.TMultiView');
-Prado::using('System.Web.UI.WebControls.TPanel');
-Prado::using('System.Web.UI.WebControls.TButton');
-Prado::using('System.Web.UI.WebControls.TLinkButton');
-Prado::using('System.Web.UI.WebControls.TImageButton');
-Prado::using('System.Web.UI.WebControls.TDataList');
-Prado::using('System.Web.UI.WebControls.TWizardNavigationButtonStyle');
-
-/**
- * Class TWizard.
- *
- * TWizard splits a large form and presents the user with a series of smaller
- * forms to complete. TWizard is analogous to the installation wizard commonly
- * used to install software in Windows.
- *
- * The smaller forms are called wizard steps ({@link TWizardStep}, which can be accessed via
- * {@link getWizardSteps WizardSteps}. In template, wizard steps can be added
- * into a wizard using the following syntax,
- * <code>
- * <com:TWizard>
- * <com:TWizardStep Title="step 1">
- * content in step 1, may contain other controls
- * </com:TWizardStep>
- * <com:TWizardStep Title="step 2">
- * content in step 2, may contain other controls
- * </com:TWizardStep>
- * </com:TWizard>
- * </code>
- *
- * Each wizard step can be one of the following types:
- * - Start : the first step in the wizard.
- * - Step : the internal steps in the wizard.
- * - Finish : the last step that allows user interaction.
- * - Complete : the step that shows a summary to user (no interaction is allowed).
- * - Auto : the step type is determined by wizard automatically.
- * At any time, only one step is visible to end-users, which can be obtained
- * by {@link getActiveStep ActiveStep}. Its index in the step collection is given by
- * {@link getActiveStepIndex ActiveStepIndex}.
- *
- * Wizard content can be customized in many ways.
- *
- * The layout of a wizard consists of four parts: header, step content, navigation
- * and side bar. Their content are affected by the following properties, respectively,
- * - header: {@link setHeaderText HeaderText} and {@link setHeaderTemplate HeaderTemplate}.
- * If both are present, the latter takes precedence.
- * - step: {@link getWizardSteps WizardSteps}.
- * - navigation: {@link setStartNavigationTemplate StartNavigationTemplate},
- * {@link setStepNavigationTemplate StepNavigationTemplate},
- * {@link setFinishNavigationTemplate FinishNavigationTemplate}.
- * Default templates will be used if above templates are not set.
- * - side bar: {@link setSideBarTemplate SideBarTemplate}.
- * A default template will be used if this template is not set.
- * Its visibility is toggled by {@link setShowSideBar ShowSideBar}.
- *
- * The style of these wizard layout components can be customized via the following style properties,
- * - header: {@link getHeaderStyle HeaderStyle}.
- * - step: {@link getStepStyle StepStyle}.
- * - navigation: {@link getNavigationStyle NavigationStyle},
- * {@link getStartNextButtonStyle StartNextButtonStyle},
- * {@link getStepNextButtonStyle StepNextButtonStyle},
- * {@link getStepPreviousButtonStyle StepPreviousButtonStyle},
- * {@link getFinishPreviousButtonStyle FinishPreviousButtonStyle},
- * {@link getFinishCompleteButtonStyle FinishCompleteButtonStyle},
- * {@link getCancelButtonStyle CancelButtonStyle}.
- * - side bar: {@link getSideBarStyle SideBarStyle} and {@link getSideBarButtonStyle SideBarButtonStyle}.
- *
- * @author Qiang Xue <qiang.xue@gmail.com>
- * @version $Id$
- * @package System.Web.UI.WebControls
- * @since 3.0
- */
-class TWizard extends TWebControl implements INamingContainer
-{
- /**
- * Wizard step types.
- * @deprecated deprecated since version 3.0.4 (use TWizardStepType constants instead)
- */
- const ST_AUTO='Auto';
- const ST_START='Start';
- const ST_STEP='Step';
- const ST_FINISH='Finish';
- const ST_COMPLETE='Complete';
- /**
- * Navigation commands.
- */
- const CMD_PREVIOUS='PreviousStep';
- const CMD_NEXT='NextStep';
- const CMD_CANCEL='Cancel';
- const CMD_COMPLETE='Complete';
- const CMD_MOVETO='MoveTo';
- /**
- * Side bar button ID
- */
- const ID_SIDEBAR_BUTTON='SideBarButton';
- /**
- * Side bar data list
- */
- const ID_SIDEBAR_LIST='SideBarList';
-
- /**
- * @var TMultiView multiview that contains the wizard steps
- */
- private $_multiView=null;
- /**
- * @var mixed navigation template for the start step.
- */
- private $_startNavigationTemplate=null;
- /**
- * @var mixed navigation template for internal steps.
- */
- private $_stepNavigationTemplate=null;
- /**
- * @var mixed navigation template for the finish step.
- */
- private $_finishNavigationTemplate=null;
- /**
- * @var mixed template for wizard header.
- */
- private $_headerTemplate=null;
- /**
- * @var mixed template for the side bar.
- */
- private $_sideBarTemplate=null;
- /**
- * @var TWizardStepCollection
- */
- private $_wizardSteps=null;
- /**
- * @var TPanel container of the wizard header
- */
- private $_header;
- /**
- * @var TPanel container of the wizard step content
- */
- private $_stepContent;
- /**
- * @var TPanel container of the wizard side bar
- */
- private $_sideBar;
- /**
- * @var TPanel navigation panel
- */
- private $_navigation;
- /**
- * @var TWizardNavigationContainer container of the start navigation
- */
- private $_startNavigation;
- /**
- * @var TWizardNavigationContainer container of the step navigation
- */
- private $_stepNavigation;
- /**
- * @var TWizardNavigationContainer container of the finish navigation
- */
- private $_finishNavigation;
- /**
- * @var boolean whether ActiveStepIndex was already set
- */
- private $_activeStepIndexSet=false;
- /**
- * @var TDataList side bar data list.
- */
- private $_sideBarDataList;
- /**
- * @var boolean whether navigation should be cancelled (a status set in OnSideBarButtonClick)
- */
- private $_cancelNavigation=false;
-
- /**
- * @return string tag name for the wizard
- */
- protected function getTagName()
- {
- return 'div';
- }
-
- /**
- * Adds {@link TWizardStep} objects into step collection.
- * This method overrides the parent implementation and is
- * invoked when template is being instantiated.
- * @param mixed object instantiated in template
- */
- public function addParsedObject($object)
- {
- if($object instanceof TWizardStep)
- $this->getWizardSteps()->add($object);
- }
-
- /**
- * @return TWizardStep the currently active wizard step
- */
- public function getActiveStep()
- {
- return $this->getMultiView()->getActiveView();
- }
-
- /**
- * @param TWizardStep step to be activated
- * @throws TInvalidOperationException if the step is not in the wizard step collection
- */
- public function setActiveStep($step)
- {
- if(($index=$this->getWizardSteps()->indexOf($step))<0)
- throw new TInvalidOperationException('wizard_step_invalid');
- $this->setActiveStepIndex($index);
- }
-
- /**
- * @return integer the zero-based index of the active wizard step
- */
- public function getActiveStepIndex()
- {
- return $this->getMultiView()->getActiveViewIndex();
- }
-
- /**
- * @param integer the zero-based index of the wizard step to be activated
- */
- public function setActiveStepIndex($value)
- {
- $value=TPropertyValue::ensureInteger($value);
- $multiView=$this->getMultiView();
- if($multiView->getActiveViewIndex()!==$value)
- {
- $multiView->setActiveViewIndex($value);
- $this->_activeStepIndexSet=true;
- if($this->_sideBarDataList!==null && $this->getSideBarTemplate()!==null)
- {
- $this->_sideBarDataList->setSelectedItemIndex($this->getActiveStepIndex());
- $this->_sideBarDataList->dataBind();
- }
- }
- }
-
- /**
- * @return TWizardStepCollection collection of wizard steps
- */
- public function getWizardSteps()
- {
- if($this->_wizardSteps===null)
- $this->_wizardSteps=new TWizardStepCollection($this);
- return $this->_wizardSteps;
- }
-
- /**
- * @return boolean whether to display a cancel button in each wizard step. Defaults to false.
- */
- public function getShowCancelButton()
- {
- return $this->getViewState('ShowCancelButton',false);
- }
-
- /**
- * @param boolean whether to display a cancel button in each wizard step.
- */
- public function setShowCancelButton($value)
- {
- $this->setViewState('ShowCancelButton',TPropertyValue::ensureBoolean($value),false);
- }
-
- /**
- * @return boolean whether to display a side bar that contains links to wizard steps. Defaults to true.
- */
- public function getShowSideBar()
- {
- return $this->getViewState('ShowSideBar',true);
- }
-
- /**
- * @param boolean whether to display a side bar that contains links to wizard steps.
- */
- public function setShowSideBar($value)
- {
- $this->setViewState('ShowSideBar',TPropertyValue::ensureBoolean($value),true);
- $this->requiresControlsRecreation();
- }
-
- /**
- * @return ITemplate navigation template for the start step. Defaults to null.
- */
- public function getStartNavigationTemplate()
- {
- return $this->_startNavigationTemplate;
- }
-
- /**
- * @param ITemplate navigation template for the start step.
- */
- public function setStartNavigationTemplate($value)
- {
- $this->_startNavigationTemplate=$value;
- $this->requiresControlsRecreation();
- }
-
- /**
- * @return ITemplate navigation template for internal steps. Defaults to null.
- */
- public function getStepNavigationTemplate()
- {
- return $this->_stepNavigationTemplate;
- }
-
- /**
- * @param ITemplate navigation template for internal steps.
- */
- public function setStepNavigationTemplate($value)
- {
- $this->_stepNavigationTemplate=$value;
- $this->requiresControlsRecreation();
- }
-
- /**
- * @return ITemplate navigation template for the finish step. Defaults to null.
- */
- public function getFinishNavigationTemplate()
- {
- return $this->_finishNavigationTemplate;
- }
-
- /**
- * @param ITemplate navigation template for the finish step.
- */
- public function setFinishNavigationTemplate($value)
- {
- $this->_finishNavigationTemplate=$value;
- $this->requiresControlsRecreation();
- }
-
- /**
- * @return ITemplate template for wizard header. Defaults to null.
- */
- public function getHeaderTemplate()
- {
- return $this->_headerTemplate;
- }
-
- /**
- * @param ITemplate template for wizard header.
- */
- public function setHeaderTemplate($value)
- {
- $this->_headerTemplate=$value;
- $this->requiresControlsRecreation();
- }
-
- /**
- * @return ITemplate template for the side bar. Defaults to null.
- */
- public function getSideBarTemplate()
- {
- return $this->_sideBarTemplate;
- }
-
- /**
- * @param ITemplate template for the side bar.
- */
- public function setSideBarTemplate($value)
- {
- $this->_sideBarTemplate=$value;
- $this->requiresControlsRecreation();
- }
-
- /**
- * @return string header text. Defaults to ''.
- */
- public function getHeaderText()
- {
- return $this->getViewState('HeaderText','');
- }
-
- /**
- * @param string header text.
- */
- public function setHeaderText($value)
- {
- $this->setViewState('HeaderText',TPropertyValue::ensureString($value),'');
- }
-
- /**
- * @return string the URL that the browser will be redirected to if the cancel button in the
- * wizard is clicked. Defaults to ''.
- */
- public function getCancelDestinationUrl()
- {
- return $this->getViewState('CancelDestinationUrl','');
- }
-
- /**
- * @param string the URL that the browser will be redirected to if the cancel button in the
- * wizard is clicked.
- */
- public function setCancelDestinationUrl($value)
- {
- $this->setViewState('CancelDestinationUrl',TPropertyValue::ensureString($value),'');
- }
-
- /**
- * @return string the URL that the browser will be redirected to if the wizard finishes.
- * Defaults to ''.
- */
- public function getFinishDestinationUrl()
- {
- return $this->getViewState('FinishDestinationUrl','');
- }
-
- /**
- * @param string the URL that the browser will be redirected to if the wizard finishes.
- */
- public function setFinishDestinationUrl($value)
- {
- $this->setViewState('FinishDestinationUrl',TPropertyValue::ensureString($value),'');
- }
-
- /**
- * @return TStyle the style for the buttons displayed in the side bar.
- */
- public function getSideBarButtonStyle()
- {
- if(($style=$this->getViewState('SideBarButtonStyle',null))===null)
- {
- $style=new TStyle;
- $this->setViewState('SideBarButtonStyle',$style,null);
- }
- return $style;
- }
-
- /**
- * @return TStyle the style common for all navigation buttons.
- */
- public function getNavigationButtonStyle()
- {
- if(($style=$this->getViewState('NavigationButtonStyle',null))===null)
- {
- $style=new TStyle;
- $this->setViewState('NavigationButtonStyle',$style,null);
- }
- return $style;
- }
-
- /**
- * @return TWizardNavigationButtonStyle the style for the next button in the start wizard step.
- */
- public function getStartNextButtonStyle()
- {
- if(($style=$this->getViewState('StartNextButtonStyle',null))===null)
- {
- $style=new TWizardNavigationButtonStyle;
- $style->setButtonText('Next');
- $this->setViewState('StartNextButtonStyle',$style,null);
- }
- return $style;
- }
-
- /**
- * @return TWizardNavigationButtonStyle the style for the next button in each internal wizard step.
- */
- public function getStepNextButtonStyle()
- {
- if(($style=$this->getViewState('StepNextButtonStyle',null))===null)
- {
- $style=new TWizardNavigationButtonStyle;
- $style->setButtonText('Next');
- $this->setViewState('StepNextButtonStyle',$style,null);
- }
- return $style;
- }
-
- /**
- * @return TWizardNavigationButtonStyle the style for the previous button in the start wizard step.
- */
- public function getStepPreviousButtonStyle()
- {
- if(($style=$this->getViewState('StepPreviousButtonStyle',null))===null)
- {
- $style=new TWizardNavigationButtonStyle;
- $style->setButtonText('Previous');
- $this->setViewState('StepPreviousButtonStyle',$style,null);
- }
- return $style;
- }
-
- /**
- * @return TWizardNavigationButtonStyle the style for the complete button in the finish wizard step.
- */
- public function getFinishCompleteButtonStyle()
- {
- if(($style=$this->getViewState('FinishCompleteButtonStyle',null))===null)
- {
- $style=new TWizardNavigationButtonStyle;
- $style->setButtonText('Complete');
- $this->setViewState('FinishCompleteButtonStyle',$style,null);
- }
- return $style;
- }
-
- /**
- * @return TWizardNavigationButtonStyle the style for the previous button in the start wizard step.
- */
- public function getFinishPreviousButtonStyle()
- {
- if(($style=$this->getViewState('FinishPreviousButtonStyle',null))===null)
- {
- $style=new TWizardNavigationButtonStyle;
- $style->setButtonText('Previous');
- $this->setViewState('FinishPreviousButtonStyle',$style,null);
- }
- return $style;
- }
-
- /**
- * @return TWizardNavigationButtonStyle the style for the cancel button
- */
- public function getCancelButtonStyle()
- {
- if(($style=$this->getViewState('CancelButtonStyle',null))===null)
- {
- $style=new TWizardNavigationButtonStyle;
- $style->setButtonText('Cancel');
- $this->setViewState('CancelButtonStyle',$style,null);
- }
- return $style;
- }
-
- /**
- * @return TPanelStyle the style for the side bar.
- */
- public function getSideBarStyle()
- {
- if(($style=$this->getViewState('SideBarStyle',null))===null)
- {
- $style=new TPanelStyle;
- $this->setViewState('SideBarStyle',$style,null);
- }
- return $style;
- }
-
- /**
- * @return TPanelStyle the style for the header.
- */
- public function getHeaderStyle()
- {
- if(($style=$this->getViewState('HeaderStyle',null))===null)
- {
- $style=new TPanelStyle;
- $this->setViewState('HeaderStyle',$style,null);
- }
- return $style;
- }
-
- /**
- * @return TPanelStyle the style for each internal wizard step.
- */
- public function getStepStyle()
- {
- if(($style=$this->getViewState('StepStyle',null))===null)
- {
- $style=new TPanelStyle;
- $this->setViewState('StepStyle',$style,null);
- }
- return $style;
- }
-
- /**
- * @return TPanelStyle the style for the navigation panel.
- */
- public function getNavigationStyle()
- {
- if(($style=$this->getViewState('NavigationStyle',null))===null)
- {
- $style=new TPanelStyle;
- $this->setViewState('NavigationStyle',$style,null);
- }
- return $style;
- }
-
- /**
- * @return boolean whether to use default layout to arrange side bar and the rest wizard components. Defaults to true.
- */
- public function getUseDefaultLayout()
- {
- return $this->getViewState('UseDefaultLayout',true);
- }
-
- /**
- * @param boolean whether to use default layout to arrange side bar and the rest wizard components.
- * If true, an HTML table will be used which places the side bar in the left cell
- * while the rest components in the right cell.
- */
- public function setUseDefaultLayout($value)
- {
- $this->setViewState('UseDefaultLayout',TPropertyValue::ensureBoolean($value),true);
- }
-
- /**
- * @return TPanel container of the wizard header
- */
- public function getHeader()
- {
- return $this->_header;
- }
-
- /**
- * @return TPanel container of the wizard step content
- */
- public function getStepContent()
- {
- return $this->_stepContent;
- }
-
- /**
- * @return TPanel container of the wizard side bar
- */
- public function getSideBar()
- {
- return $this->_sideBar;
- }
-
- /**
- * @return TWizardNavigationContainer container of the start navigation
- */
- public function getStartNavigation()
- {
- return $this->_startNavigation;
- }
-
- /**
- * @return TWizardNavigationContainer container of the step navigation
- */
- public function getStepNavigation()
- {
- return $this->_stepNavigation;
- }
-
- /**
- * @return TWizardNavigationContainer container of the finish navigation
- */
- public function getFinishNavigation()
- {
- return $this->_finishNavigation;
- }
-
- /**
- * Raises <b>OnActiveStepChanged</b> event.
- * This event is raised when the current visible step is changed in the
- * wizard.
- * @param TEventParameter event parameter
- */
- public function onActiveStepChanged($param)
- {
- $this->raiseEvent('OnActiveStepChanged',$this,$param);
- }
-
- /**
- * Raises <b>OnCancelButtonClick</b> event.
- * This event is raised when a cancel navigation button is clicked in the
- * current active step.
- * @param TEventParameter event parameter
- */
- public function onCancelButtonClick($param)
- {
- $this->raiseEvent('OnCancelButtonClick',$this,$param);
- if(($url=$this->getCancelDestinationUrl())!=='')
- $this->getResponse()->redirect($url);
- }
-
- /**
- * Raises <b>OnCompleteButtonClick</b> event.
- * This event is raised when a finish navigation button is clicked in the
- * current active step.
- * @param TWizardNavigationEventParameter event parameter
- */
- public function onCompleteButtonClick($param)
- {
- $this->raiseEvent('OnCompleteButtonClick',$this,$param);
- if(($url=$this->getFinishDestinationUrl())!=='')
- $this->getResponse()->redirect($url);
- }
-
- /**
- * Raises <b>OnNextButtonClick</b> event.
- * This event is raised when a next navigation button is clicked in the
- * current active step.
- * @param TWizardNavigationEventParameter event parameter
- */
- public function onNextButtonClick($param)
- {
- $this->raiseEvent('OnNextButtonClick',$this,$param);
- }
-
- /**
- * Raises <b>OnPreviousButtonClick</b> event.
- * This event is raised when a previous navigation button is clicked in the
- * current active step.
- * @param TWizardNavigationEventParameter event parameter
- */
- public function onPreviousButtonClick($param)
- {
- $this->raiseEvent('OnPreviousButtonClick',$this,$param);
- }
-
- /**
- * Raises <b>OnSideBarButtonClick</b> event.
- * This event is raised when a link button in the side bar is clicked.
- * @param TWizardNavigationEventParameter event parameter
- */
- public function onSideBarButtonClick($param)
- {
- $this->raiseEvent('OnSideBarButtonClick',$this,$param);
- }
-
- /**
- * Returns the multiview that holds the wizard steps.
- * This method should only be used by control developers.
- * @return TMultiView the multiview holding wizard steps
- */
- public function getMultiView()
- {
- if($this->_multiView===null)
- {
- $this->_multiView=new TMultiView;
- $this->_multiView->setID('WizardMultiView');
- $this->_multiView->attachEventHandler('OnActiveViewChanged',array($this,'onActiveStepChanged'));
- $this->_multiView->ignoreBubbleEvents();
- }
- return $this->_multiView;
- }
-
- /**
- * Adds a wizard step to the multiview.
- * This method should only be used by control developers.
- * It is invoked when a step is added into the step collection of the wizard.
- * @param TWizardStep wizard step to be added into multiview.
- */
- public function addedWizardStep($step)
- {
- if(($wizard=$step->getWizard())!==null)
- $wizard->getWizardSteps()->remove($step);
- $step->setWizard($this);
- $this->wizardStepsChanged();
- }
-
- /**
- * Removes a wizard step from the multiview.
- * This method should only be used by control developers.
- * It is invoked when a step is removed from the step collection of the wizard.
- * @param TWizardStep wizard step to be removed from multiview.
- */
- public function removedWizardStep($step)
- {
- $step->setWizard(null);
- $this->wizardStepsChanged();
- }
-
- /**
- * Creates the child controls of the wizard.
- * This method overrides the parent implementation.
- * @param TEventParameter event parameter
- */
- public function onInit($param)
- {
- parent::onInit($param);
- $this->ensureChildControls();
- if($this->getActiveStepIndex()<0 && $this->getWizardSteps()->getCount()>0)
- $this->setActiveStepIndex(0);
- }
-
- /**
- * Saves the current active step index into history.
- * This method is invoked by the framework when the control state is being saved.
- */
- public function saveState()
- {
- $index=$this->getActiveStepIndex();
- $history=$this->getHistory();
- if(!$history->getCount() || $history->peek()!==$index)
- $history->push($index);
- }
-
- /**
- * Indicates the wizard needs to recreate all child controls.
- */
- protected function requiresControlsRecreation()
- {
- if($this->getChildControlsCreated())
- $this->setChildControlsCreated(false);
- }
-
- /**
- * Renders the wizard.
- * @param THtmlWriter
- */
- public function render($writer)
- {
- $this->ensureChildControls();
- if($this->getHasControls())
- {
- if($this->getUseDefaultLayout())
- {
- $this->applyControlProperties();
- $this->renderBeginTag($writer);
- $writer->write("\n<table border=\"0\" cellpadding=\"0\" cellspacing=\"0\" height=\"100%\" width=\"100%\">\n<tr><td width=\"1\" valign=\"top\">\n");
- $this->_sideBar->renderControl($writer);
- $writer->write("\n</td><td valign=\"top\">\n");
- $this->_header->renderControl($writer);
- $this->_stepContent->renderControl($writer);
- $this->_navigation->renderControl($writer);
- $writer->write("\n</td></tr></table>\n");
- $this->renderEndTag($writer);
- }
- else
- {
- $this->applyControlProperties();
- $this->renderBeginTag($writer);
- $this->_sideBar->renderControl($writer);
- $this->_header->renderControl($writer);
- $this->_stepContent->renderControl($writer);
- $this->_navigation->renderControl($writer);
- $this->renderEndTag($writer);
- }
- }
- }
-
- /**
- * Applies various properties to the components of wizard
- */
- protected function applyControlProperties()
- {
- $this->applyHeaderProperties();
- $this->applySideBarProperties();
- $this->applyStepContentProperties();
- $this->applyNavigationProperties();
- }
-
- /**
- * Applies properties to the wizard header
- */
- protected function applyHeaderProperties()
- {
- if(($style=$this->getViewState('HeaderStyle',null))!==null)
- $this->_header->getStyle()->mergeWith($style);
- if($this->getHeaderTemplate()===null)
- {
- $this->_header->getControls()->clear();
- $this->_header->getControls()->add($this->getHeaderText());
- }
- }
-
- /**
- * Applies properties to the wizard sidebar
- */
- protected function applySideBarProperties()
- {
- $this->_sideBar->setVisible($this->getShowSideBar());
- if($this->_sideBarDataList!==null && $this->getShowSideBar())
- {
- $this->_sideBarDataList->setDataSource($this->getWizardSteps());
- $this->_sideBarDataList->setSelectedItemIndex($this->getActiveStepIndex());
- $this->_sideBarDataList->dataBind();
- if(($style=$this->getViewState('SideBarButtonStyle',null))!==null)
- {
- foreach($this->_sideBarDataList->getItems() as $item)
- {
- if(($button=$item->findControl('SideBarButton'))!==null)
- $button->getStyle()->mergeWith($style);
- }
- }
- }
- if(($style=$this->getViewState('SideBarStyle',null))!==null)
- $this->_sideBar->getStyle()->mergeWith($style);
- }
-
- /**
- * Applies properties to the wizard step content
- */
- protected function applyStepContentProperties()
- {
- if(($style=$this->getViewState('StepStyle',null))!==null)
- $this->_stepContent->getStyle()->mergeWith($style);
- }
-
- /**
- * Apply properties to various navigation panels.
- */
- protected function applyNavigationProperties()
- {
- $wizardSteps=$this->getWizardSteps();
- $activeStep=$this->getActiveStep();
- $activeStepIndex=$this->getActiveStepIndex();
-
- if(!$this->_navigation)
- return;
- else if($activeStepIndex<0 || $activeStepIndex>=$wizardSteps->getCount())
- {
- $this->_navigation->setVisible(false);
- return;
- }
-
- // set visibility of different types of navigation panel
- $showStandard=true;
- foreach($wizardSteps as $step)
- {
- if(($step instanceof TTemplatedWizardStep) && ($container=$step->getNavigationContainer())!==null)
- {
- if($activeStep===$step)
- {
- $container->setVisible(true);
- $showStandard=false;
- }
- else
- $container->setVisible(false);
- }
- }
- $activeStepType=$this->getStepType($activeStep);
- if($activeStepType===TWizardStepType::Complete)
- {
- $this->_sideBar->setVisible(false);
- $this->_header->setVisible(false);
- }
- $this->_startNavigation->setVisible($showStandard && $activeStepType===self::ST_START);
- $this->_stepNavigation->setVisible($showStandard && $activeStepType===self::ST_STEP);
- $this->_finishNavigation->setVisible($showStandard && $activeStepType===self::ST_FINISH);
-
- if(($navigationStyle=$this->getViewState('NavigationStyle',null))!==null)
- $this->_navigation->getStyle()->mergeWith($navigationStyle);
-
- $displayCancelButton=$this->getShowCancelButton();
- $cancelButtonStyle=$this->getCancelButtonStyle();
- $buttonStyle=$this->getViewState('NavigationButtonStyle',null);
- if($buttonStyle!==null)
- $cancelButtonStyle->mergeWith($buttonStyle);
-
- // apply styles to start navigation buttons
- if(($cancelButton=$this->_startNavigation->getCancelButton())!==null)
- {
- $cancelButton->setVisible($displayCancelButton);
- $cancelButtonStyle->apply($cancelButton);
- }
- if(($button=$this->_startNavigation->getNextButton())!==null)
- {
- $button->setVisible(true);
- $style=$this->getStartNextButtonStyle();
- if($buttonStyle!==null)
- $style->mergeWith($buttonStyle);
- $style->apply($button);
- if($activeStepType===TWizardStepType::Start)
- $this->getPage()->getClientScript()->registerDefaultButton($this, $button);
- }
-
- // apply styles to finish navigation buttons
- if(($cancelButton=$this->_finishNavigation->getCancelButton())!==null)
- {
- $cancelButton->setVisible($displayCancelButton);
- $cancelButtonStyle->apply($cancelButton);
- }
- if(($button=$this->_finishNavigation->getPreviousButton())!==null)
- {
- $button->setVisible($this->allowNavigationToPreviousStep());
- $style=$this->getFinishPreviousButtonStyle();
- if($buttonStyle!==null)
- $style->mergeWith($buttonStyle);
- $style->apply($button);
- }
- if(($button=$this->_finishNavigation->getCompleteButton())!==null)
- {
- $button->setVisible(true);
- $style=$this->getFinishCompleteButtonStyle();
- if($buttonStyle!==null)
- $style->mergeWith($buttonStyle);
- $style->apply($button);
- if($activeStepType===TWizardStepType::Finish)
- $this->getPage()->getClientScript()->registerDefaultButton($this, $button);
- }
-
- // apply styles to step navigation buttons
- if(($cancelButton=$this->_stepNavigation->getCancelButton())!==null)
- {
- $cancelButton->setVisible($displayCancelButton);
- $cancelButtonStyle->apply($cancelButton);
- }
- if(($button=$this->_stepNavigation->getPreviousButton())!==null)
- {
- $button->setVisible($this->allowNavigationToPreviousStep());
- $style=$this->getStepPreviousButtonStyle();
- if($buttonStyle!==null)
- $style->mergeWith($buttonStyle);
- $style->apply($button);
- }
- if(($button=$this->_stepNavigation->getNextButton())!==null)
- {
- $button->setVisible(true);
- $style=$this->getStepNextButtonStyle();
- if($buttonStyle!==null)
- $style->mergeWith($buttonStyle);
- $style->apply($button);
- if($activeStepType===TWizardStepType::Step)
- $this->getPage()->getClientScript()->registerDefaultButton($this, $button);
- }
- }
-
- /**
- * @return TStack history containing step indexes that were navigated before
- */
- protected function getHistory()
- {
- if(($history=$this->getControlState('History',null))===null)
- {
- $history=new TStack;
- $this->setControlState('History',$history);
- }
- return $history;
- }
-
- /**
- * Determines the type of the specified wizard step.
- * @param TWizardStep
- * @return TWizardStepType type of the step
- */
- protected function getStepType($wizardStep)
- {
- if(($type=$wizardStep->getStepType())===TWizardStepType::Auto)
- {
- $steps=$this->getWizardSteps();
- if(($index=$steps->indexOf($wizardStep))>=0)
- {
- $stepCount=$steps->getCount();
- if($stepCount===1 || ($index<$stepCount-1 && $steps->itemAt($index+1)->getStepType()===TWizardStepType::Complete))
- return TWizardStepType::Finish;
- else if($index===0)
- return TWizardStepType::Start;
- else if($index===$stepCount-1)
- return TWizardStepType::Finish;
- else
- return TWizardStepType::Step;
- }
- else
- return $type;
- }
- else
- return $type;
- }
-
- /**
- * Clears up everything within the wizard.
- */
- protected function reset()
- {
- $this->getControls()->clear();
- $this->_header=null;
- $this->_stepContent=null;
- $this->_sideBar=null;
- $this->_sideBarDataList=null;
- $this->_navigation=null;
- $this->_startNavigation=null;
- $this->_stepNavigation=null;
- $this->_finishNavigation=null;
- }
-
- /**
- * Creates child controls within the wizard
- */
- public function createChildControls()
- {
- $this->reset();
- $this->createSideBar();
- $this->createHeader();
- $this->createStepContent();
- $this->createNavigation();
-// $this->clearChildState();
- }
-
- /**
- * Creates the wizard header.
- */
- protected function createHeader()
- {
- $this->_header=new TPanel;
- if(($template=$this->getHeaderTemplate())!==null)
- $template->instantiateIn($this->_header);
- else
- $this->_header->getControls()->add($this->getHeaderText());
- $this->getControls()->add($this->_header);
- }
-
- /**
- * Creates the wizard side bar
- */
- protected function createSideBar()
- {
- if($this->getShowSideBar())
- {
- if(($template=$this->getSideBarTemplate())===null)
- $template=new TWizardSideBarTemplate;
- $this->_sideBar=new TPanel;
- $template->instantiateIn($this->_sideBar);
- $this->getControls()->add($this->_sideBar);
-
- if(($this->_sideBarDataList=$this->_sideBar->findControl(self::ID_SIDEBAR_LIST))!==null)
- {
- $this->_sideBarDataList->attachEventHandler('OnItemCommand',array($this,'dataListItemCommand'));
- $this->_sideBarDataList->attachEventHandler('OnItemDataBound',array($this,'dataListItemDataBound'));
- $this->_sideBarDataList->setDataSource($this->getWizardSteps());
- $this->_sideBarDataList->setSelectedItemIndex($this->getActiveStepIndex());
- $this->_sideBarDataList->dataBind();
- }
- }
- else
- {
- $this->_sideBar=new TPanel;
- $this->getControls()->add($this->_sideBar);
- }
- }
-
- /**
- * Event handler for sidebar datalist's OnItemCommand event.
- * This method is used internally by wizard. It mainly
- * sets the active step index according to the button clicked in the sidebar.
- * @param mixed sender of the event
- * @param TDataListCommandEventParameter
- */
- public function dataListItemCommand($sender,$param)
- {
- $item=$param->getItem();
- if($param->getCommandName()===self::CMD_MOVETO)
- {
- $stepIndex=$this->getActiveStepIndex();
- $newStepIndex=TPropertyValue::ensureInteger($param->getCommandParameter());
- $navParam=new TWizardNavigationEventParameter($stepIndex);
- $navParam->setNextStepIndex($newStepIndex);
-
- // if the button clicked causes validation which fails,
- // by default we will cancel navigation to the new step
- $button=$param->getCommandSource();
- if(($button instanceof IButtonControl) && $button->getCausesValidation() && ($page=$this->getPage())!==null && !$page->getIsValid())
- $navParam->setCancelNavigation(true);
-
- $this->_activeStepIndexSet=false;
- $this->onSideBarButtonClick($navParam);
- $this->_cancelNavigation=$navParam->getCancelNavigation();
- if(!$this->_cancelNavigation)
- {
- if(!$this->_activeStepIndexSet && $this->allowNavigationToStep($newStepIndex))
- $this->setActiveStepIndex($newStepIndex);
- }
- else
- $this->setActiveStepIndex($stepIndex);
- }
- }
-
- /**
- * Event handler for sidebar datalist's OnItemDataBound event.
- * This method is used internally by wizard. It mainly configures
- * the buttons in the sidebar datalist.
- * @param mixed sender of the event
- * @param TDataListItemEventParameter
- */
- public function dataListItemDataBound($sender,$param)
- {
- $item=$param->getItem();
- $itemType=$item->getItemType();
- if($itemType==='Item' || $itemType==='AlternatingItem' || $itemType==='SelectedItem' || $itemType==='EditItem')
- {
- if(($button=$item->findControl(self::ID_SIDEBAR_BUTTON))!==null)
- {
- $step=$item->getData();
- if(($this->getStepType($step)===TWizardStepType::Complete))
- $button->setEnabled(false);
- if(($title=$step->getTitle())!=='')
- $button->setText($title);
- else
- $button->setText($step->getID(false));
- $index=$this->getWizardSteps()->indexOf($step);
- $button->setCommandName(self::CMD_MOVETO);
- $button->setCommandParameter("$index");
- }
- }
- }
-
- /**
- * Creates wizard step content.
- */
- protected function createStepContent()
- {
- foreach($this->getWizardSteps() as $step)
- {
- if($step instanceof TTemplatedWizardStep)
- $step->ensureChildControls();
- }
- $multiView=$this->getMultiView();
- $this->_stepContent=new TPanel;
- $this->_stepContent->getControls()->add($multiView);
- $this->getControls()->add($this->_stepContent);
- if($multiView->getViews()->getCount())
- $multiView->setActiveViewIndex(0);
- }
-
- /**
- * Creates navigation panel.
- */
- protected function createNavigation()
- {
- $this->_navigation=new TPanel;
- $this->getControls()->add($this->_navigation);
- $controls=$this->_navigation->getControls();
- foreach($this->getWizardSteps() as $step)
- {
- if($step instanceof TTemplatedWizardStep)
- {
- $step->instantiateNavigationTemplate();
- if(($panel=$step->getNavigationContainer())!==null)
- $controls->add($panel);
- }
- }
- $this->_startNavigation=$this->createStartNavigation();
- $controls->add($this->_startNavigation);
- $this->_stepNavigation=$this->createStepNavigation();
- $controls->add($this->_stepNavigation);
- $this->_finishNavigation=$this->createFinishNavigation();
- $controls->add($this->_finishNavigation);
- }
-
- /**
- * Creates start navigation panel.
- */
- protected function createStartNavigation()
- {
- if(($template=$this->getStartNavigationTemplate())===null)
- $template=new TWizardStartNavigationTemplate($this);
- $navigation=new TWizardNavigationContainer;
- $template->instantiateIn($navigation);
- return $navigation;
- }
-
- /**
- * Creates step navigation panel.
- */
- protected function createStepNavigation()
- {
- if(($template=$this->getStepNavigationTemplate())===null)
- $template=new TWizardStepNavigationTemplate($this);
- $navigation=new TWizardNavigationContainer;
- $template->instantiateIn($navigation);
- return $navigation;
- }
-
- /**
- * Creates finish navigation panel.
- */
- protected function createFinishNavigation()
- {
- if(($template=$this->getFinishNavigationTemplate())===null)
- $template=new TWizardFinishNavigationTemplate($this);
- $navigation=new TWizardNavigationContainer;
- $template->instantiateIn($navigation);
- return $navigation;
- }
-
- /**
- * Updates the sidebar datalist if any.
- * This method is invoked when any wizard step is changed.
- */
- public function wizardStepsChanged()
- {
- if($this->_sideBarDataList!==null)
- {
- $this->_sideBarDataList->setDataSource($this->getWizardSteps());
- $this->_sideBarDataList->setSelectedItemIndex($this->getActiveStepIndex());
- $this->_sideBarDataList->dataBind();
- }
- }
-
- /**
- * Determines the index of the previous step based on history.
- * @param boolean whether the first item in the history stack should be popped
- * up after calling this method.
- */
- protected function getPreviousStepIndex($popStack)
- {
- $history=$this->getHistory();
- if($history->getCount()>=0)
- {
- $activeStepIndex=$this->getActiveStepIndex();
- $previousStepIndex=-1;
- if($popStack)
- {
- $previousStepIndex=$history->pop();
- if($activeStepIndex===$previousStepIndex && $history->getCount()>0)
- $previousStepIndex=$history->pop();
- }
- else
- {
- $previousStepIndex=$history->peek();
- if($activeStepIndex===$previousStepIndex && $history->getCount()>1)
- {
- $saveIndex=$history->pop();
- $previousStepIndex=$history->peek();
- $history->push($saveIndex);
- }
- }
- return $activeStepIndex===$previousStepIndex ? -1 : $previousStepIndex;
- }
- else
- return -1;
- }
-
- /**
- * @return boolean whether navigation to the previous step is allowed
- */
- protected function allowNavigationToPreviousStep()
- {
- if(($index=$this->getPreviousStepIndex(false))!==-1)
- return $this->getWizardSteps()->itemAt($index)->getAllowReturn();
- else
- return false;
- }
-
- /**
- * @param integer index of the step
- * @return boolean whether navigation to the specified step is allowed
- */
- protected function allowNavigationToStep($index)
- {
- if($this->getHistory()->contains($index))
- return $this->getWizardSteps()->itemAt($index)->getAllowReturn();
- else
- return true;
- }
-
- /**
- * Handles bubbled events.
- * This method mainly translate certain command events into
- * wizard-specific events.
- * @param mixed sender of the original command event
- * @param TEventParameter event parameter
- * @throws TInvalidDataValueException if a navigation command is associated with an invalid parameter
- */
- public function bubbleEvent($sender,$param)
- {
- if($param instanceof TCommandEventParameter)
- {
- $command=$param->getCommandName();
- if(strcasecmp($command,self::CMD_CANCEL)===0)
- {
- $this->onCancelButtonClick($param);
- return true;
- }
-
- $type=$this->getStepType($this->getActiveStep());
- $index=$this->getActiveStepIndex();
- $navParam=new TWizardNavigationEventParameter($index);
- if(($sender instanceof IButtonControl) && $sender->getCausesValidation() && ($page=$this->getPage())!==null && !$page->getIsValid())
- $navParam->setCancelNavigation(true);
-
- $handled=false;
- $movePrev=false;
- $this->_activeStepIndexSet=false;
-
- if(strcasecmp($command,self::CMD_NEXT)===0)
- {
- if($type!==self::ST_START && $type!==self::ST_STEP)
- throw new TInvalidDataValueException('wizard_command_invalid',self::CMD_NEXT);
- if($index<$this->getWizardSteps()->getCount()-1)
- $navParam->setNextStepIndex($index+1);
- $this->onNextButtonClick($navParam);
- $handled=true;
- }
- else if(strcasecmp($command,self::CMD_PREVIOUS)===0)
- {
- if($type!==self::ST_FINISH && $type!==self::ST_STEP)
- throw new TInvalidDataValueException('wizard_command_invalid',self::CMD_PREVIOUS);
- $movePrev=true;
- if(($prevIndex=$this->getPreviousStepIndex(false))>=0)
- $navParam->setNextStepIndex($prevIndex);
- $this->onPreviousButtonClick($navParam);
- $handled=true;
- }
- else if(strcasecmp($command,self::CMD_COMPLETE)===0)
- {
- if($type!==self::ST_FINISH)
- throw new TInvalidDataValueException('wizard_command_invalid',self::CMD_COMPLETE);
- if($index<$this->getWizardSteps()->getCount()-1)
- $navParam->setNextStepIndex($index+1);
- $this->onCompleteButtonClick($navParam);
- $handled=true;
- }
- else if(strcasecmp($command,self::CMD_MOVETO)===0)
- {
- if($this->_cancelNavigation) // may be set in onSideBarButtonClick
+ * @license http://www.pradosoft.com/license/
+ * @version $Id$
+ * @package System.Web.UI.WebControls
+ */
+
+Prado::using('System.Web.UI.WebControls.TMultiView');
+Prado::using('System.Web.UI.WebControls.TPanel');
+Prado::using('System.Web.UI.WebControls.TButton');
+Prado::using('System.Web.UI.WebControls.TLinkButton');
+Prado::using('System.Web.UI.WebControls.TImageButton');
+Prado::using('System.Web.UI.WebControls.TDataList');
+Prado::using('System.Web.UI.WebControls.TWizardNavigationButtonStyle');
+
+/**
+ * Class TWizard.
+ *
+ * TWizard splits a large form and presents the user with a series of smaller
+ * forms to complete. TWizard is analogous to the installation wizard commonly
+ * used to install software in Windows.
+ *
+ * The smaller forms are called wizard steps ({@link TWizardStep}, which can be accessed via
+ * {@link getWizardSteps WizardSteps}. In template, wizard steps can be added
+ * into a wizard using the following syntax,
+ * <code>
+ * <com:TWizard>
+ * <com:TWizardStep Title="step 1">
+ * content in step 1, may contain other controls
+ * </com:TWizardStep>
+ * <com:TWizardStep Title="step 2">
+ * content in step 2, may contain other controls
+ * </com:TWizardStep>
+ * </com:TWizard>
+ * </code>
+ *
+ * Each wizard step can be one of the following types:
+ * - Start : the first step in the wizard.
+ * - Step : the internal steps in the wizard.
+ * - Finish : the last step that allows user interaction.
+ * - Complete : the step that shows a summary to user (no interaction is allowed).
+ * - Auto : the step type is determined by wizard automatically.
+ * At any time, only one step is visible to end-users, which can be obtained
+ * by {@link getActiveStep ActiveStep}. Its index in the step collection is given by
+ * {@link getActiveStepIndex ActiveStepIndex}.
+ *
+ * Wizard content can be customized in many ways.
+ *
+ * The layout of a wizard consists of four parts: header, step content, navigation
+ * and side bar. Their content are affected by the following properties, respectively,
+ * - header: {@link setHeaderText HeaderText} and {@link setHeaderTemplate HeaderTemplate}.
+ * If both are present, the latter takes precedence.
+ * - step: {@link getWizardSteps WizardSteps}.
+ * - navigation: {@link setStartNavigationTemplate StartNavigationTemplate},
+ * {@link setStepNavigationTemplate StepNavigationTemplate},
+ * {@link setFinishNavigationTemplate FinishNavigationTemplate}.
+ * Default templates will be used if above templates are not set.
+ * - side bar: {@link setSideBarTemplate SideBarTemplate}.
+ * A default template will be used if this template is not set.
+ * Its visibility is toggled by {@link setShowSideBar ShowSideBar}.
+ *
+ * The style of these wizard layout components can be customized via the following style properties,
+ * - header: {@link getHeaderStyle HeaderStyle}.
+ * - step: {@link getStepStyle StepStyle}.
+ * - navigation: {@link getNavigationStyle NavigationStyle},
+ * {@link getStartNextButtonStyle StartNextButtonStyle},
+ * {@link getStepNextButtonStyle StepNextButtonStyle},
+ * {@link getStepPreviousButtonStyle StepPreviousButtonStyle},
+ * {@link getFinishPreviousButtonStyle FinishPreviousButtonStyle},
+ * {@link getFinishCompleteButtonStyle FinishCompleteButtonStyle},
+ * {@link getCancelButtonStyle CancelButtonStyle}.
+ * - side bar: {@link getSideBarStyle SideBarStyle} and {@link getSideBarButtonStyle SideBarButtonStyle}.
+ *
+ * @author Qiang Xue <qiang.xue@gmail.com>
+ * @version $Id$
+ * @package System.Web.UI.WebControls
+ * @since 3.0
+ */
+class TWizard extends TWebControl implements INamingContainer
+{
+ /**
+ * Wizard step types.
+ * @deprecated deprecated since version 3.0.4 (use TWizardStepType constants instead)
+ */
+ const ST_AUTO='Auto';
+ const ST_START='Start';
+ const ST_STEP='Step';
+ const ST_FINISH='Finish';
+ const ST_COMPLETE='Complete';
+ /**
+ * Navigation commands.
+ */
+ const CMD_PREVIOUS='PreviousStep';
+ const CMD_NEXT='NextStep';
+ const CMD_CANCEL='Cancel';
+ const CMD_COMPLETE='Complete';
+ const CMD_MOVETO='MoveTo';
+ /**
+ * Side bar button ID
+ */
+ const ID_SIDEBAR_BUTTON='SideBarButton';
+ /**
+ * Side bar data list
+ */
+ const ID_SIDEBAR_LIST='SideBarList';
+
+ /**
+ * @var TMultiView multiview that contains the wizard steps
+ */
+ private $_multiView=null;
+ /**
+ * @var mixed navigation template for the start step.
+ */
+ private $_startNavigationTemplate=null;
+ /**
+ * @var mixed navigation template for internal steps.
+ */
+ private $_stepNavigationTemplate=null;
+ /**
+ * @var mixed navigation template for the finish step.
+ */
+ private $_finishNavigationTemplate=null;
+ /**
+ * @var mixed template for wizard header.
+ */
+ private $_headerTemplate=null;
+ /**
+ * @var mixed template for the side bar.
+ */
+ private $_sideBarTemplate=null;
+ /**
+ * @var TWizardStepCollection
+ */
+ private $_wizardSteps=null;
+ /**
+ * @var TPanel container of the wizard header
+ */
+ private $_header;
+ /**
+ * @var TPanel container of the wizard step content
+ */
+ private $_stepContent;
+ /**
+ * @var TPanel container of the wizard side bar
+ */
+ private $_sideBar;
+ /**
+ * @var TPanel navigation panel
+ */
+ private $_navigation;
+ /**
+ * @var TWizardNavigationContainer container of the start navigation
+ */
+ private $_startNavigation;
+ /**
+ * @var TWizardNavigationContainer container of the step navigation
+ */
+ private $_stepNavigation;
+ /**
+ * @var TWizardNavigationContainer container of the finish navigation
+ */
+ private $_finishNavigation;
+ /**
+ * @var boolean whether ActiveStepIndex was already set
+ */
+ private $_activeStepIndexSet=false;
+ /**
+ * @var TDataList side bar data list.
+ */
+ private $_sideBarDataList;
+ /**
+ * @var boolean whether navigation should be cancelled (a status set in OnSideBarButtonClick)
+ */
+ private $_cancelNavigation=false;
+
+ /**
+ * @return string tag name for the wizard
+ */
+ protected function getTagName()
+ {
+ return 'div';
+ }
+
+ /**
+ * Adds {@link TWizardStep} objects into step collection.
+ * This method overrides the parent implementation and is
+ * invoked when template is being instantiated.
+ * @param mixed object instantiated in template
+ */
+ public function addParsedObject($object)
+ {
+ if($object instanceof TWizardStep)
+ $this->getWizardSteps()->add($object);
+ }
+
+ /**
+ * @return TWizardStep the currently active wizard step
+ */
+ public function getActiveStep()
+ {
+ return $this->getMultiView()->getActiveView();
+ }
+
+ /**
+ * @param TWizardStep step to be activated
+ * @throws TInvalidOperationException if the step is not in the wizard step collection
+ */
+ public function setActiveStep($step)
+ {
+ if(($index=$this->getWizardSteps()->indexOf($step))<0)
+ throw new TInvalidOperationException('wizard_step_invalid');
+ $this->setActiveStepIndex($index);
+ }
+
+ /**
+ * @return integer the zero-based index of the active wizard step
+ */
+ public function getActiveStepIndex()
+ {
+ return $this->getMultiView()->getActiveViewIndex();
+ }
+
+ /**
+ * @param integer the zero-based index of the wizard step to be activated
+ */
+ public function setActiveStepIndex($value)
+ {
+ $value=TPropertyValue::ensureInteger($value);
+ $multiView=$this->getMultiView();
+ if($multiView->getActiveViewIndex()!==$value)
+ {
+ $multiView->setActiveViewIndex($value);
+ $this->_activeStepIndexSet=true;
+ if($this->_sideBarDataList!==null && $this->getSideBarTemplate()!==null)
+ {
+ $this->_sideBarDataList->setSelectedItemIndex($this->getActiveStepIndex());
+ $this->_sideBarDataList->dataBind();
+ }
+ }
+ }
+
+ /**
+ * @return TWizardStepCollection collection of wizard steps
+ */
+ public function getWizardSteps()
+ {
+ if($this->_wizardSteps===null)
+ $this->_wizardSteps=new TWizardStepCollection($this);
+ return $this->_wizardSteps;
+ }
+
+ /**
+ * @return boolean whether to display a cancel button in each wizard step. Defaults to false.
+ */
+ public function getShowCancelButton()
+ {
+ return $this->getViewState('ShowCancelButton',false);
+ }
+
+ /**
+ * @param boolean whether to display a cancel button in each wizard step.
+ */
+ public function setShowCancelButton($value)
+ {
+ $this->setViewState('ShowCancelButton',TPropertyValue::ensureBoolean($value),false);
+ }
+
+ /**
+ * @return boolean whether to display a side bar that contains links to wizard steps. Defaults to true.
+ */
+ public function getShowSideBar()
+ {
+ return $this->getViewState('ShowSideBar',true);
+ }
+
+ /**
+ * @param boolean whether to display a side bar that contains links to wizard steps.
+ */
+ public function setShowSideBar($value)
+ {
+ $this->setViewState('ShowSideBar',TPropertyValue::ensureBoolean($value),true);
+ $this->requiresControlsRecreation();
+ }
+
+ /**
+ * @return ITemplate navigation template for the start step. Defaults to null.
+ */
+ public function getStartNavigationTemplate()
+ {
+ return $this->_startNavigationTemplate;
+ }
+
+ /**
+ * @param ITemplate navigation template for the start step.
+ */
+ public function setStartNavigationTemplate($value)
+ {
+ $this->_startNavigationTemplate=$value;
+ $this->requiresControlsRecreation();
+ }
+
+ /**
+ * @return ITemplate navigation template for internal steps. Defaults to null.
+ */
+ public function getStepNavigationTemplate()
+ {
+ return $this->_stepNavigationTemplate;
+ }
+
+ /**
+ * @param ITemplate navigation template for internal steps.
+ */
+ public function setStepNavigationTemplate($value)
+ {
+ $this->_stepNavigationTemplate=$value;
+ $this->requiresControlsRecreation();
+ }
+
+ /**
+ * @return ITemplate navigation template for the finish step. Defaults to null.
+ */
+ public function getFinishNavigationTemplate()
+ {
+ return $this->_finishNavigationTemplate;
+ }
+
+ /**
+ * @param ITemplate navigation template for the finish step.
+ */
+ public function setFinishNavigationTemplate($value)
+ {
+ $this->_finishNavigationTemplate=$value;
+ $this->requiresControlsRecreation();
+ }
+
+ /**
+ * @return ITemplate template for wizard header. Defaults to null.
+ */
+ public function getHeaderTemplate()
+ {
+ return $this->_headerTemplate;
+ }
+
+ /**
+ * @param ITemplate template for wizard header.
+ */
+ public function setHeaderTemplate($value)
+ {
+ $this->_headerTemplate=$value;
+ $this->requiresControlsRecreation();
+ }
+
+ /**
+ * @return ITemplate template for the side bar. Defaults to null.
+ */
+ public function getSideBarTemplate()
+ {
+ return $this->_sideBarTemplate;
+ }
+
+ /**
+ * @param ITemplate template for the side bar.
+ */
+ public function setSideBarTemplate($value)
+ {
+ $this->_sideBarTemplate=$value;
+ $this->requiresControlsRecreation();
+ }
+
+ /**
+ * @return string header text. Defaults to ''.
+ */
+ public function getHeaderText()
+ {
+ return $this->getViewState('HeaderText','');
+ }
+
+ /**
+ * @param string header text.
+ */
+ public function setHeaderText($value)
+ {
+ $this->setViewState('HeaderText',TPropertyValue::ensureString($value),'');
+ }
+
+ /**
+ * @return string the URL that the browser will be redirected to if the cancel button in the
+ * wizard is clicked. Defaults to ''.
+ */
+ public function getCancelDestinationUrl()
+ {
+ return $this->getViewState('CancelDestinationUrl','');
+ }
+
+ /**
+ * @param string the URL that the browser will be redirected to if the cancel button in the
+ * wizard is clicked.
+ */
+ public function setCancelDestinationUrl($value)
+ {
+ $this->setViewState('CancelDestinationUrl',TPropertyValue::ensureString($value),'');
+ }
+
+ /**
+ * @return string the URL that the browser will be redirected to if the wizard finishes.
+ * Defaults to ''.
+ */
+ public function getFinishDestinationUrl()
+ {
+ return $this->getViewState('FinishDestinationUrl','');
+ }
+
+ /**
+ * @param string the URL that the browser will be redirected to if the wizard finishes.
+ */
+ public function setFinishDestinationUrl($value)
+ {
+ $this->setViewState('FinishDestinationUrl',TPropertyValue::ensureString($value),'');
+ }
+
+ /**
+ * @return TStyle the style for the buttons displayed in the side bar.
+ */
+ public function getSideBarButtonStyle()
+ {
+ if(($style=$this->getViewState('SideBarButtonStyle',null))===null)
+ {
+ $style=new TStyle;
+ $this->setViewState('SideBarButtonStyle',$style,null);
+ }
+ return $style;
+ }
+
+ /**
+ * @return TStyle the style common for all navigation buttons.
+ */
+ public function getNavigationButtonStyle()
+ {
+ if(($style=$this->getViewState('NavigationButtonStyle',null))===null)
+ {
+ $style=new TStyle;
+ $this->setViewState('NavigationButtonStyle',$style,null);
+ }
+ return $style;
+ }
+
+ /**
+ * @return TWizardNavigationButtonStyle the style for the next button in the start wizard step.
+ */
+ public function getStartNextButtonStyle()
+ {
+ if(($style=$this->getViewState('StartNextButtonStyle',null))===null)
+ {
+ $style=new TWizardNavigationButtonStyle;
+ $style->setButtonText('Next');
+ $this->setViewState('StartNextButtonStyle',$style,null);
+ }
+ return $style;
+ }
+
+ /**
+ * @return TWizardNavigationButtonStyle the style for the next button in each internal wizard step.
+ */
+ public function getStepNextButtonStyle()
+ {
+ if(($style=$this->getViewState('StepNextButtonStyle',null))===null)
+ {
+ $style=new TWizardNavigationButtonStyle;
+ $style->setButtonText('Next');
+ $this->setViewState('StepNextButtonStyle',$style,null);
+ }
+ return $style;
+ }
+
+ /**
+ * @return TWizardNavigationButtonStyle the style for the previous button in the start wizard step.
+ */
+ public function getStepPreviousButtonStyle()
+ {
+ if(($style=$this->getViewState('StepPreviousButtonStyle',null))===null)
+ {
+ $style=new TWizardNavigationButtonStyle;
+ $style->setButtonText('Previous');
+ $this->setViewState('StepPreviousButtonStyle',$style,null);
+ }
+ return $style;
+ }
+
+ /**
+ * @return TWizardNavigationButtonStyle the style for the complete button in the finish wizard step.
+ */
+ public function getFinishCompleteButtonStyle()
+ {
+ if(($style=$this->getViewState('FinishCompleteButtonStyle',null))===null)
+ {
+ $style=new TWizardNavigationButtonStyle;
+ $style->setButtonText('Complete');
+ $this->setViewState('FinishCompleteButtonStyle',$style,null);
+ }
+ return $style;
+ }
+
+ /**
+ * @return TWizardNavigationButtonStyle the style for the previous button in the start wizard step.
+ */
+ public function getFinishPreviousButtonStyle()
+ {
+ if(($style=$this->getViewState('FinishPreviousButtonStyle',null))===null)
+ {
+ $style=new TWizardNavigationButtonStyle;
+ $style->setButtonText('Previous');
+ $this->setViewState('FinishPreviousButtonStyle',$style,null);
+ }
+ return $style;
+ }
+
+ /**
+ * @return TWizardNavigationButtonStyle the style for the cancel button
+ */
+ public function getCancelButtonStyle()
+ {
+ if(($style=$this->getViewState('CancelButtonStyle',null))===null)
+ {
+ $style=new TWizardNavigationButtonStyle;
+ $style->setButtonText('Cancel');
+ $this->setViewState('CancelButtonStyle',$style,null);
+ }
+ return $style;
+ }
+
+ /**
+ * @return TPanelStyle the style for the side bar.
+ */
+ public function getSideBarStyle()
+ {
+ if(($style=$this->getViewState('SideBarStyle',null))===null)
+ {
+ $style=new TPanelStyle;
+ $this->setViewState('SideBarStyle',$style,null);
+ }
+ return $style;
+ }
+
+ /**
+ * @return TPanelStyle the style for the header.
+ */
+ public function getHeaderStyle()
+ {
+ if(($style=$this->getViewState('HeaderStyle',null))===null)
+ {
+ $style=new TPanelStyle;
+ $this->setViewState('HeaderStyle',$style,null);
+ }
+ return $style;
+ }
+
+ /**
+ * @return TPanelStyle the style for each internal wizard step.
+ */
+ public function getStepStyle()
+ {
+ if(($style=$this->getViewState('StepStyle',null))===null)
+ {
+ $style=new TPanelStyle;
+ $this->setViewState('StepStyle',$style,null);
+ }
+ return $style;
+ }
+
+ /**
+ * @return TPanelStyle the style for the navigation panel.
+ */
+ public function getNavigationStyle()
+ {
+ if(($style=$this->getViewState('NavigationStyle',null))===null)
+ {
+ $style=new TPanelStyle;
+ $this->setViewState('NavigationStyle',$style,null);
+ }
+ return $style;
+ }
+
+ /**
+ * @return boolean whether to use default layout to arrange side bar and the rest wizard components. Defaults to true.
+ */
+ public function getUseDefaultLayout()
+ {
+ return $this->getViewState('UseDefaultLayout',true);
+ }
+
+ /**
+ * @param boolean whether to use default layout to arrange side bar and the rest wizard components.
+ * If true, an HTML table will be used which places the side bar in the left cell
+ * while the rest components in the right cell.
+ */
+ public function setUseDefaultLayout($value)
+ {
+ $this->setViewState('UseDefaultLayout',TPropertyValue::ensureBoolean($value),true);
+ }
+
+ /**
+ * @return TPanel container of the wizard header
+ */
+ public function getHeader()
+ {
+ return $this->_header;
+ }
+
+ /**
+ * @return TPanel container of the wizard step content
+ */
+ public function getStepContent()
+ {
+ return $this->_stepContent;
+ }
+
+ /**
+ * @return TPanel container of the wizard side bar
+ */
+ public function getSideBar()
+ {
+ return $this->_sideBar;
+ }
+
+ /**
+ * @return TWizardNavigationContainer container of the start navigation
+ */
+ public function getStartNavigation()
+ {
+ return $this->_startNavigation;
+ }
+
+ /**
+ * @return TWizardNavigationContainer container of the step navigation
+ */
+ public function getStepNavigation()
+ {
+ return $this->_stepNavigation;
+ }
+
+ /**
+ * @return TWizardNavigationContainer container of the finish navigation
+ */
+ public function getFinishNavigation()
+ {
+ return $this->_finishNavigation;
+ }
+
+ /**
+ * Raises <b>OnActiveStepChanged</b> event.
+ * This event is raised when the current visible step is changed in the
+ * wizard.
+ * @param TEventParameter event parameter
+ */
+ public function onActiveStepChanged($param)
+ {
+ $this->raiseEvent('OnActiveStepChanged',$this,$param);
+ }
+
+ /**
+ * Raises <b>OnCancelButtonClick</b> event.
+ * This event is raised when a cancel navigation button is clicked in the
+ * current active step.
+ * @param TEventParameter event parameter
+ */
+ public function onCancelButtonClick($param)
+ {
+ $this->raiseEvent('OnCancelButtonClick',$this,$param);
+ if(($url=$this->getCancelDestinationUrl())!=='')
+ $this->getResponse()->redirect($url);
+ }
+
+ /**
+ * Raises <b>OnCompleteButtonClick</b> event.
+ * This event is raised when a finish navigation button is clicked in the
+ * current active step.
+ * @param TWizardNavigationEventParameter event parameter
+ */
+ public function onCompleteButtonClick($param)
+ {
+ $this->raiseEvent('OnCompleteButtonClick',$this,$param);
+ if(($url=$this->getFinishDestinationUrl())!=='')
+ $this->getResponse()->redirect($url);
+ }
+
+ /**
+ * Raises <b>OnNextButtonClick</b> event.
+ * This event is raised when a next navigation button is clicked in the
+ * current active step.
+ * @param TWizardNavigationEventParameter event parameter
+ */
+ public function onNextButtonClick($param)
+ {
+ $this->raiseEvent('OnNextButtonClick',$this,$param);
+ }
+
+ /**
+ * Raises <b>OnPreviousButtonClick</b> event.
+ * This event is raised when a previous navigation button is clicked in the
+ * current active step.
+ * @param TWizardNavigationEventParameter event parameter
+ */
+ public function onPreviousButtonClick($param)
+ {
+ $this->raiseEvent('OnPreviousButtonClick',$this,$param);
+ }
+
+ /**
+ * Raises <b>OnSideBarButtonClick</b> event.
+ * This event is raised when a link button in the side bar is clicked.
+ * @param TWizardNavigationEventParameter event parameter
+ */
+ public function onSideBarButtonClick($param)
+ {
+ $this->raiseEvent('OnSideBarButtonClick',$this,$param);
+ }
+
+ /**
+ * Returns the multiview that holds the wizard steps.
+ * This method should only be used by control developers.
+ * @return TMultiView the multiview holding wizard steps
+ */
+ public function getMultiView()
+ {
+ if($this->_multiView===null)
+ {
+ $this->_multiView=new TMultiView;
+ $this->_multiView->setID('WizardMultiView');
+ $this->_multiView->attachEventHandler('OnActiveViewChanged',array($this,'onActiveStepChanged'));
+ $this->_multiView->ignoreBubbleEvents();
+ }
+ return $this->_multiView;
+ }
+
+ /**
+ * Adds a wizard step to the multiview.
+ * This method should only be used by control developers.
+ * It is invoked when a step is added into the step collection of the wizard.
+ * @param TWizardStep wizard step to be added into multiview.
+ */
+ public function addedWizardStep($step)
+ {
+ if(($wizard=$step->getWizard())!==null)
+ $wizard->getWizardSteps()->remove($step);
+ $step->setWizard($this);
+ $this->wizardStepsChanged();
+ }
+
+ /**
+ * Removes a wizard step from the multiview.
+ * This method should only be used by control developers.
+ * It is invoked when a step is removed from the step collection of the wizard.
+ * @param TWizardStep wizard step to be removed from multiview.
+ */
+ public function removedWizardStep($step)
+ {
+ $step->setWizard(null);
+ $this->wizardStepsChanged();
+ }
+
+ /**
+ * Creates the child controls of the wizard.
+ * This method overrides the parent implementation.
+ * @param TEventParameter event parameter
+ */
+ public function onInit($param)
+ {
+ parent::onInit($param);
+ $this->ensureChildControls();
+ if($this->getActiveStepIndex()<0 && $this->getWizardSteps()->getCount()>0)
+ $this->setActiveStepIndex(0);
+ }
+
+ /**
+ * Saves the current active step index into history.
+ * This method is invoked by the framework when the control state is being saved.
+ */
+ public function saveState()
+ {
+ $index=$this->getActiveStepIndex();
+ $history=$this->getHistory();
+ if(!$history->getCount() || $history->peek()!==$index)
+ $history->push($index);
+ }
+
+ /**
+ * Indicates the wizard needs to recreate all child controls.
+ */
+ protected function requiresControlsRecreation()
+ {
+ if($this->getChildControlsCreated())
+ $this->setChildControlsCreated(false);
+ }
+
+ /**
+ * Renders the wizard.
+ * @param THtmlWriter
+ */
+ public function render($writer)
+ {
+ $this->ensureChildControls();
+ if($this->getHasControls())
+ {
+ if($this->getUseDefaultLayout())
+ {
+ $this->applyControlProperties();
+ $this->renderBeginTag($writer);
+ $writer->write("\n<table border=\"0\" cellpadding=\"0\" cellspacing=\"0\" height=\"100%\" width=\"100%\">\n<tr><td width=\"1\" valign=\"top\">\n");
+ $this->_sideBar->renderControl($writer);
+ $writer->write("\n</td><td valign=\"top\">\n");
+ $this->_header->renderControl($writer);
+ $this->_stepContent->renderControl($writer);
+ $this->_navigation->renderControl($writer);
+ $writer->write("\n</td></tr></table>\n");
+ $this->renderEndTag($writer);
+ }
+ else
+ {
+ $this->applyControlProperties();
+ $this->renderBeginTag($writer);
+ $this->_sideBar->renderControl($writer);
+ $this->_header->renderControl($writer);
+ $this->_stepContent->renderControl($writer);
+ $this->_navigation->renderControl($writer);
+ $this->renderEndTag($writer);
+ }
+ }
+ }
+
+ /**
+ * Applies various properties to the components of wizard
+ */
+ protected function applyControlProperties()
+ {
+ $this->applyHeaderProperties();
+ $this->applySideBarProperties();
+ $this->applyStepContentProperties();
+ $this->applyNavigationProperties();
+ }
+
+ /**
+ * Applies properties to the wizard header
+ */
+ protected function applyHeaderProperties()
+ {
+ if(($style=$this->getViewState('HeaderStyle',null))!==null)
+ $this->_header->getStyle()->mergeWith($style);
+ if($this->getHeaderTemplate()===null)
+ {
+ $this->_header->getControls()->clear();
+ $this->_header->getControls()->add($this->getHeaderText());
+ }
+ }
+
+ /**
+ * Applies properties to the wizard sidebar
+ */
+ protected function applySideBarProperties()
+ {
+ $this->_sideBar->setVisible($this->getShowSideBar());
+ if($this->_sideBarDataList!==null && $this->getShowSideBar())
+ {
+ $this->_sideBarDataList->setDataSource($this->getWizardSteps());
+ $this->_sideBarDataList->setSelectedItemIndex($this->getActiveStepIndex());
+ $this->_sideBarDataList->dataBind();
+ if(($style=$this->getViewState('SideBarButtonStyle',null))!==null)
+ {
+ foreach($this->_sideBarDataList->getItems() as $item)
+ {
+ if(($button=$item->findControl('SideBarButton'))!==null)
+ $button->getStyle()->mergeWith($style);
+ }
+ }
+ }
+ if(($style=$this->getViewState('SideBarStyle',null))!==null)
+ $this->_sideBar->getStyle()->mergeWith($style);
+ }
+
+ /**
+ * Applies properties to the wizard step content
+ */
+ protected function applyStepContentProperties()
+ {
+ if(($style=$this->getViewState('StepStyle',null))!==null)
+ $this->_stepContent->getStyle()->mergeWith($style);
+ }
+
+ /**
+ * Apply properties to various navigation panels.
+ */
+ protected function applyNavigationProperties()
+ {
+ $wizardSteps=$this->getWizardSteps();
+ $activeStep=$this->getActiveStep();
+ $activeStepIndex=$this->getActiveStepIndex();
+
+ if(!$this->_navigation)
+ return;
+ else if($activeStepIndex<0 || $activeStepIndex>=$wizardSteps->getCount())
+ {
+ $this->_navigation->setVisible(false);
+ return;
+ }
+
+ // set visibility of different types of navigation panel
+ $showStandard=true;
+ foreach($wizardSteps as $step)
+ {
+ if(($step instanceof TTemplatedWizardStep) && ($container=$step->getNavigationContainer())!==null)
+ {
+ if($activeStep===$step)
+ {
+ $container->setVisible(true);
+ $showStandard=false;
+ }
+ else
+ $container->setVisible(false);
+ }
+ }
+ $activeStepType=$this->getStepType($activeStep);
+ if($activeStepType===TWizardStepType::Complete)
+ {
+ $this->_sideBar->setVisible(false);
+ $this->_header->setVisible(false);
+ }
+ $this->_startNavigation->setVisible($showStandard && $activeStepType===self::ST_START);
+ $this->_stepNavigation->setVisible($showStandard && $activeStepType===self::ST_STEP);
+ $this->_finishNavigation->setVisible($showStandard && $activeStepType===self::ST_FINISH);
+
+ if(($navigationStyle=$this->getViewState('NavigationStyle',null))!==null)
+ $this->_navigation->getStyle()->mergeWith($navigationStyle);
+
+ $displayCancelButton=$this->getShowCancelButton();
+ $cancelButtonStyle=$this->getCancelButtonStyle();
+ $buttonStyle=$this->getViewState('NavigationButtonStyle',null);
+ if($buttonStyle!==null)
+ $cancelButtonStyle->mergeWith($buttonStyle);
+
+ // apply styles to start navigation buttons
+ if(($cancelButton=$this->_startNavigation->getCancelButton())!==null)
+ {
+ $cancelButton->setVisible($displayCancelButton);
+ $cancelButtonStyle->apply($cancelButton);
+ }
+ if(($button=$this->_startNavigation->getNextButton())!==null)
+ {
+ $button->setVisible(true);
+ $style=$this->getStartNextButtonStyle();
+ if($buttonStyle!==null)
+ $style->mergeWith($buttonStyle);
+ $style->apply($button);
+ if($activeStepType===TWizardStepType::Start)
+ $this->getPage()->getClientScript()->registerDefaultButton($this, $button);
+ }
+
+ // apply styles to finish navigation buttons
+ if(($cancelButton=$this->_finishNavigation->getCancelButton())!==null)
+ {
+ $cancelButton->setVisible($displayCancelButton);
+ $cancelButtonStyle->apply($cancelButton);
+ }
+ if(($button=$this->_finishNavigation->getPreviousButton())!==null)
+ {
+ $button->setVisible($this->allowNavigationToPreviousStep());
+ $style=$this->getFinishPreviousButtonStyle();
+ if($buttonStyle!==null)
+ $style->mergeWith($buttonStyle);
+ $style->apply($button);
+ }
+ if(($button=$this->_finishNavigation->getCompleteButton())!==null)
+ {
+ $button->setVisible(true);
+ $style=$this->getFinishCompleteButtonStyle();
+ if($buttonStyle!==null)
+ $style->mergeWith($buttonStyle);
+ $style->apply($button);
+ if($activeStepType===TWizardStepType::Finish)
+ $this->getPage()->getClientScript()->registerDefaultButton($this, $button);
+ }
+
+ // apply styles to step navigation buttons
+ if(($cancelButton=$this->_stepNavigation->getCancelButton())!==null)
+ {
+ $cancelButton->setVisible($displayCancelButton);
+ $cancelButtonStyle->apply($cancelButton);
+ }
+ if(($button=$this->_stepNavigation->getPreviousButton())!==null)
+ {
+ $button->setVisible($this->allowNavigationToPreviousStep());
+ $style=$this->getStepPreviousButtonStyle();
+ if($buttonStyle!==null)
+ $style->mergeWith($buttonStyle);
+ $style->apply($button);
+ }
+ if(($button=$this->_stepNavigation->getNextButton())!==null)
+ {
+ $button->setVisible(true);
+ $style=$this->getStepNextButtonStyle();
+ if($buttonStyle!==null)
+ $style->mergeWith($buttonStyle);
+ $style->apply($button);
+ if($activeStepType===TWizardStepType::Step)
+ $this->getPage()->getClientScript()->registerDefaultButton($this, $button);
+ }
+ }
+
+ /**
+ * @return TStack history containing step indexes that were navigated before
+ */
+ protected function getHistory()
+ {
+ if(($history=$this->getControlState('History',null))===null)
+ {
+ $history=new TStack;
+ $this->setControlState('History',$history);
+ }
+ return $history;
+ }
+
+ /**
+ * Determines the type of the specified wizard step.
+ * @param TWizardStep
+ * @return TWizardStepType type of the step
+ */
+ protected function getStepType($wizardStep)
+ {
+ if(($type=$wizardStep->getStepType())===TWizardStepType::Auto)
+ {
+ $steps=$this->getWizardSteps();
+ if(($index=$steps->indexOf($wizardStep))>=0)
+ {
+ $stepCount=$steps->getCount();
+ if($stepCount===1 || ($index<$stepCount-1 && $steps->itemAt($index+1)->getStepType()===TWizardStepType::Complete))
+ return TWizardStepType::Finish;
+ else if($index===0)
+ return TWizardStepType::Start;
+ else if($index===$stepCount-1)
+ return TWizardStepType::Finish;
+ else
+ return TWizardStepType::Step;
+ }
+ else
+ return $type;
+ }
+ else
+ return $type;
+ }
+
+ /**
+ * Clears up everything within the wizard.
+ */
+ protected function reset()
+ {
+ $this->getControls()->clear();
+ $this->_header=null;
+ $this->_stepContent=null;
+ $this->_sideBar=null;
+ $this->_sideBarDataList=null;
+ $this->_navigation=null;
+ $this->_startNavigation=null;
+ $this->_stepNavigation=null;
+ $this->_finishNavigation=null;
+ }
+
+ /**
+ * Creates child controls within the wizard
+ */
+ public function createChildControls()
+ {
+ $this->reset();
+ $this->createSideBar();
+ $this->createHeader();
+ $this->createStepContent();
+ $this->createNavigation();
+// $this->clearChildState();
+ }
+
+ /**
+ * Creates the wizard header.
+ */
+ protected function createHeader()
+ {
+ $this->_header=new TPanel;
+ if(($template=$this->getHeaderTemplate())!==null)
+ $template->instantiateIn($this->_header);
+ else
+ $this->_header->getControls()->add($this->getHeaderText());
+ $this->getControls()->add($this->_header);
+ }
+
+ /**
+ * Creates the wizard side bar
+ */
+ protected function createSideBar()
+ {
+ if($this->getShowSideBar())
+ {
+ if(($template=$this->getSideBarTemplate())===null)
+ $template=new TWizardSideBarTemplate;
+ $this->_sideBar=new TPanel;
+ $template->instantiateIn($this->_sideBar);
+ $this->getControls()->add($this->_sideBar);
+
+ if(($this->_sideBarDataList=$this->_sideBar->findControl(self::ID_SIDEBAR_LIST))!==null)
+ {
+ $this->_sideBarDataList->attachEventHandler('OnItemCommand',array($this,'dataListItemCommand'));
+ $this->_sideBarDataList->attachEventHandler('OnItemDataBound',array($this,'dataListItemDataBound'));
+ $this->_sideBarDataList->setDataSource($this->getWizardSteps());
+ $this->_sideBarDataList->setSelectedItemIndex($this->getActiveStepIndex());
+ $this->_sideBarDataList->dataBind();
+ }
+ }
+ else
+ {
+ $this->_sideBar=new TPanel;
+ $this->getControls()->add($this->_sideBar);
+ }
+ }
+
+ /**
+ * Event handler for sidebar datalist's OnItemCommand event.
+ * This method is used internally by wizard. It mainly
+ * sets the active step index according to the button clicked in the sidebar.
+ * @param mixed sender of the event
+ * @param TDataListCommandEventParameter
+ */
+ public function dataListItemCommand($sender,$param)
+ {
+ $item=$param->getItem();
+ if($param->getCommandName()===self::CMD_MOVETO)
+ {
+ $stepIndex=$this->getActiveStepIndex();
+ $newStepIndex=TPropertyValue::ensureInteger($param->getCommandParameter());
+ $navParam=new TWizardNavigationEventParameter($stepIndex);
+ $navParam->setNextStepIndex($newStepIndex);
+
+ // if the button clicked causes validation which fails,
+ // by default we will cancel navigation to the new step
+ $button=$param->getCommandSource();
+ if(($button instanceof IButtonControl) && $button->getCausesValidation() && ($page=$this->getPage())!==null && !$page->getIsValid())
+ $navParam->setCancelNavigation(true);
+
+ $this->_activeStepIndexSet=false;
+ $this->onSideBarButtonClick($navParam);
+ $this->_cancelNavigation=$navParam->getCancelNavigation();
+ if(!$this->_cancelNavigation)
+ {
+ if(!$this->_activeStepIndexSet && $this->allowNavigationToStep($newStepIndex))
+ $this->setActiveStepIndex($newStepIndex);
+ }
+ else
+ $this->setActiveStepIndex($stepIndex);
+ }
+ }
+
+ /**
+ * Event handler for sidebar datalist's OnItemDataBound event.
+ * This method is used internally by wizard. It mainly configures
+ * the buttons in the sidebar datalist.
+ * @param mixed sender of the event
+ * @param TDataListItemEventParameter
+ */
+ public function dataListItemDataBound($sender,$param)
+ {
+ $item=$param->getItem();
+ $itemType=$item->getItemType();
+ if($itemType==='Item' || $itemType==='AlternatingItem' || $itemType==='SelectedItem' || $itemType==='EditItem')
+ {
+ if(($button=$item->findControl(self::ID_SIDEBAR_BUTTON))!==null)
+ {
+ $step=$item->getData();
+ if(($this->getStepType($step)===TWizardStepType::Complete))
+ $button->setEnabled(false);
+ if(($title=$step->getTitle())!=='')
+ $button->setText($title);
+ else
+ $button->setText($step->getID(false));
+ $index=$this->getWizardSteps()->indexOf($step);
+ $button->setCommandName(self::CMD_MOVETO);
+ $button->setCommandParameter("$index");
+ }
+ }
+ }
+
+ /**
+ * Creates wizard step content.
+ */
+ protected function createStepContent()
+ {
+ foreach($this->getWizardSteps() as $step)
+ {
+ if($step instanceof TTemplatedWizardStep)
+ $step->ensureChildControls();
+ }
+ $multiView=$this->getMultiView();
+ $this->_stepContent=new TPanel;
+ $this->_stepContent->getControls()->add($multiView);
+ $this->getControls()->add($this->_stepContent);
+ if($multiView->getViews()->getCount())
+ $multiView->setActiveViewIndex(0);
+ }
+
+ /**
+ * Creates navigation panel.
+ */
+ protected function createNavigation()
+ {
+ $this->_navigation=new TPanel;
+ $this->getControls()->add($this->_navigation);
+ $controls=$this->_navigation->getControls();
+ foreach($this->getWizardSteps() as $step)
+ {
+ if($step instanceof TTemplatedWizardStep)
+ {
+ $step->instantiateNavigationTemplate();
+ if(($panel=$step->getNavigationContainer())!==null)
+ $controls->add($panel);
+ }
+ }
+ $this->_startNavigation=$this->createStartNavigation();
+ $controls->add($this->_startNavigation);
+ $this->_stepNavigation=$this->createStepNavigation();
+ $controls->add($this->_stepNavigation);
+ $this->_finishNavigation=$this->createFinishNavigation();
+ $controls->add($this->_finishNavigation);
+ }
+
+ /**
+ * Creates start navigation panel.
+ */
+ protected function createStartNavigation()
+ {
+ if(($template=$this->getStartNavigationTemplate())===null)
+ $template=new TWizardStartNavigationTemplate($this);
+ $navigation=new TWizardNavigationContainer;
+ $template->instantiateIn($navigation);
+ return $navigation;
+ }
+
+ /**
+ * Creates step navigation panel.
+ */
+ protected function createStepNavigation()
+ {
+ if(($template=$this->getStepNavigationTemplate())===null)
+ $template=new TWizardStepNavigationTemplate($this);
+ $navigation=new TWizardNavigationContainer;
+ $template->instantiateIn($navigation);
+ return $navigation;
+ }
+
+ /**
+ * Creates finish navigation panel.
+ */
+ protected function createFinishNavigation()
+ {
+ if(($template=$this->getFinishNavigationTemplate())===null)
+ $template=new TWizardFinishNavigationTemplate($this);
+ $navigation=new TWizardNavigationContainer;
+ $template->instantiateIn($navigation);
+ return $navigation;
+ }
+
+ /**
+ * Updates the sidebar datalist if any.
+ * This method is invoked when any wizard step is changed.
+ */
+ public function wizardStepsChanged()
+ {
+ if($this->_sideBarDataList!==null)
+ {
+ $this->_sideBarDataList->setDataSource($this->getWizardSteps());
+ $this->_sideBarDataList->setSelectedItemIndex($this->getActiveStepIndex());
+ $this->_sideBarDataList->dataBind();
+ }
+ }
+
+ /**
+ * Determines the index of the previous step based on history.
+ * @param boolean whether the first item in the history stack should be popped
+ * up after calling this method.
+ */
+ protected function getPreviousStepIndex($popStack)
+ {
+ $history=$this->getHistory();
+ if($history->getCount()>=0)
+ {
+ $activeStepIndex=$this->getActiveStepIndex();
+ $previousStepIndex=-1;
+ if($popStack)
+ {
+ $previousStepIndex=$history->pop();
+ if($activeStepIndex===$previousStepIndex && $history->getCount()>0)
+ $previousStepIndex=$history->pop();
+ }
+ else
+ {
+ $previousStepIndex=$history->peek();
+ if($activeStepIndex===$previousStepIndex && $history->getCount()>1)
+ {
+ $saveIndex=$history->pop();
+ $previousStepIndex=$history->peek();
+ $history->push($saveIndex);
+ }
+ }
+ return $activeStepIndex===$previousStepIndex ? -1 : $previousStepIndex;
+ }
+ else
+ return -1;
+ }
+
+ /**
+ * @return boolean whether navigation to the previous step is allowed
+ */
+ protected function allowNavigationToPreviousStep()
+ {
+ if(($index=$this->getPreviousStepIndex(false))!==-1)
+ return $this->getWizardSteps()->itemAt($index)->getAllowReturn();
+ else
+ return false;
+ }
+
+ /**
+ * @param integer index of the step
+ * @return boolean whether navigation to the specified step is allowed
+ */
+ protected function allowNavigationToStep($index)
+ {
+ if($this->getHistory()->contains($index))
+ return $this->getWizardSteps()->itemAt($index)->getAllowReturn();
+ else
+ return true;
+ }
+
+ /**
+ * Handles bubbled events.
+ * This method mainly translate certain command events into
+ * wizard-specific events.
+ * @param mixed sender of the original command event
+ * @param TEventParameter event parameter
+ * @throws TInvalidDataValueException if a navigation command is associated with an invalid parameter
+ */
+ public function bubbleEvent($sender,$param)
+ {
+ if($param instanceof TCommandEventParameter)
+ {
+ $command=$param->getCommandName();
+ if(strcasecmp($command,self::CMD_CANCEL)===0)
+ {
+ $this->onCancelButtonClick($param);
+ return true;
+ }
+
+ $type=$this->getStepType($this->getActiveStep());
+ $index=$this->getActiveStepIndex();
+ $navParam=new TWizardNavigationEventParameter($index);
+ if(($sender instanceof IButtonControl) && $sender->getCausesValidation() && ($page=$this->getPage())!==null && !$page->getIsValid())
+ $navParam->setCancelNavigation(true);
+
+ $handled=false;
+ $movePrev=false;
+ $this->_activeStepIndexSet=false;
+
+ if(strcasecmp($command,self::CMD_NEXT)===0)
+ {
+ if($type!==self::ST_START && $type!==self::ST_STEP)
+ throw new TInvalidDataValueException('wizard_command_invalid',self::CMD_NEXT);
+ if($index<$this->getWizardSteps()->getCount()-1)
+ $navParam->setNextStepIndex($index+1);
+ $this->onNextButtonClick($navParam);
+ $handled=true;
+ }
+ else if(strcasecmp($command,self::CMD_PREVIOUS)===0)
+ {
+ if($type!==self::ST_FINISH && $type!==self::ST_STEP)
+ throw new TInvalidDataValueException('wizard_command_invalid',self::CMD_PREVIOUS);
+ $movePrev=true;
+ if(($prevIndex=$this->getPreviousStepIndex(false))>=0)
+ $navParam->setNextStepIndex($prevIndex);
+ $this->onPreviousButtonClick($navParam);
+ $handled=true;
+ }
+ else if(strcasecmp($command,self::CMD_COMPLETE)===0)
+ {
+ if($type!==self::ST_FINISH)
+ throw new TInvalidDataValueException('wizard_command_invalid',self::CMD_COMPLETE);
+ if($index<$this->getWizardSteps()->getCount()-1)
+ $navParam->setNextStepIndex($index+1);
+ $this->onCompleteButtonClick($navParam);
+ $handled=true;
+ }
+ else if(strcasecmp($command,self::CMD_MOVETO)===0)
+ {
+ if($this->_cancelNavigation) // may be set in onSideBarButtonClick
$navParam->setCancelNavigation(true);
$requestedStep=$param->getCommandParameter();
if (!is_numeric($requestedStep))
@@ -1412,750 +1412,750 @@ class TWizard extends TWebControl implements INamingContainer
throw new TConfigurationException('wizard_step_invalid');
}
else
- $requestedIndex=TPropertyValue::ensureInteger($requestedStep);
- $navParam->setNextStepIndex($requestedIndex);
- $handled=true;
- }
-
- if($handled)
- {
- if(!$navParam->getCancelNavigation())
- {
- $nextStepIndex=$navParam->getNextStepIndex();
- if(!$this->_activeStepIndexSet && $this->allowNavigationToStep($nextStepIndex))
- {
- if($movePrev)
- $this->getPreviousStepIndex(true); // pop out the previous move from history
- $this->setActiveStepIndex($nextStepIndex);
- }
- }
- else
- $this->setActiveStepIndex($index);
- return true;
- }
- }
- return false;
- }
-}
-
-
-/**
- * TWizardStep class.
- *
- * TWizardStep represents a wizard step. The wizard owning the step
- * can be obtained by {@link getWizard Wizard}.
- * To specify the type of the step, set {@link setStepType StepType};
- * For step title, set {@link setTitle Title}. If a step can be re-visited,
- * set {@link setAllowReturn AllowReturn} to true.
- *
- * @author Qiang Xue <qiang.xue@gmail.com>
- * @version $Id$
- * @package System.Web.UI.WebControls
- * @since 3.0
- */
-class TWizardStep extends TView
-{
- private $_wizard;
-
- /**
- * @return TWizard the wizard owning this step
- */
- public function getWizard()
- {
- return $this->_wizard;
- }
-
- /**
- * Sets the wizard owning this step.
- * This method is used internally by {@link TWizard}.
- * @param TWizard the wizard owning this step
- */
- public function setWizard($wizard)
- {
- $this->_wizard=$wizard;
- }
-
- /**
- * @return string the title for this step.
- */
- public function getTitle()
- {
- return $this->getViewState('Title','');
- }
-
- /**
- * @param string the title for this step.
- */
- public function setTitle($value)
- {
- $this->setViewState('Title',$value,'');
- if($this->_wizard)
- $this->_wizard->wizardStepsChanged();
- }
-
- /**
- * @return boolean whether this step can be re-visited. Default to true.
- */
- public function getAllowReturn()
- {
- return $this->getViewState('AllowReturn',true);
- }
-
- /**
- * @param boolean whether this step can be re-visited.
- */
- public function setAllowReturn($value)
- {
- $this->setViewState('AllowReturn',TPropertyValue::ensureBoolean($value),true);
- }
-
- /**
- * @return TWizardStepType the wizard step type. Defaults to TWizardStepType::Auto.
- */
- public function getStepType()
- {
- return $this->getViewState('StepType',TWizardStepType::Auto);
- }
-
- /**
- * @param TWizardStepType the wizard step type.
- */
- public function setStepType($type)
- {
- $type=TPropertyValue::ensureEnum($type,'TWizardStepType');
- if($type!==$this->getStepType())
- {
- $this->setViewState('StepType',$type,TWizardStepType::Auto);
- if($this->_wizard)
- $this->_wizard->wizardStepsChanged();
- }
- }
-}
-
-
-/**
- * TCompleteWizardStep class.
- *
- * TCompleteWizardStep represents a wizard step of type TWizardStepType::Complete.
- *
- * @author Qiang Xue <qiang.xue@gmail.com>
- * @version $Id$
- * @package System.Web.UI.WebControls
- * @since 3.0
- */
-class TCompleteWizardStep extends TWizardStep
-{
- /**
- * @return TWizardStepType the wizard step type. Always TWizardStepType::Complete.
- */
- public function getStepType()
- {
- return TWizardStepType::Complete;
- }
-
- /**
- * @param string the wizard step type.
- * @throws TInvalidOperationException whenever this method is invoked.
- */
- public function setStepType($value)
- {
- throw new TInvalidOperationException('completewizardstep_steptype_readonly');
- }
-}
-
-
-/**
- * TTemplatedWizardStep class.
- *
- * TTemplatedWizardStep represents a wizard step whose content and navigation
- * can be customized using templates. To customize the step content, specify
- * {@link setContentTemplate ContentTemplate}. To customize navigation specific
- * to the step, specify {@link setNavigationTemplate NavigationTemplate}. Note,
- * if the navigation template is not specified, default navigation will be used.
- *
- * @author Qiang Xue <qiang.xue@gmail.com>
- * @version $Id$
- * @package System.Web.UI.WebControls
- * @since 3.0
- */
-class TTemplatedWizardStep extends TWizardStep implements INamingContainer
-{
- /**
- * @var ITemplate the template for displaying the navigation UI of a wizard step.
- */
- private $_navigationTemplate=null;
- /**
- * @var ITemplate the template for displaying the content within the wizard step.
- */
- private $_contentTemplate=null;
- /**
- * @var TWizardNavigationContainer
- */
- private $_navigationContainer=null;
-
- /**
- * Creates child controls.
- * This method mainly instantiates the content template, if any.
- */
- public function createChildControls()
- {
- $this->getControls()->clear();
- if($this->_contentTemplate)
- $this->_contentTemplate->instantiateIn($this);
- }
-
- /**
- * Ensures child controls are created.
- * @param mixed event parameter
- */
- public function onInit($param)
- {
- parent::onInit($param);
- $this->ensureChildControls();
- }
-
- /**
- * @return ITemplate the template for the content of the wizard step.
- */
- public function getContentTemplate()
- {
- return $this->_contentTemplate;
- }
-
- /**
- * @param ITemplate the template for the content of the wizard step.
- */
- public function setContentTemplate($value)
- {
- $this->_contentTemplate=$value;
- }
-
- /**
- * @return ITemplate the template for displaying the navigation UI of a wizard step. Defaults to null.
- */
- public function getNavigationTemplate()
- {
- return $this->_navigationTemplate;
- }
-
- /**
- * @param ITemplate the template for displaying the navigation UI of a wizard step.
- */
- public function setNavigationTemplate($value)
- {
- $this->_navigationTemplate=$value;
- }
-
- /**
- * @return TWizardNavigationContainer the control containing the navigation.
- * It could be null if no navigation template is specified.
- */
- public function getNavigationContainer()
- {
- return $this->_navigationContainer;
- }
-
- /**
- * Instantiates the navigation template if any
- */
- public function instantiateNavigationTemplate()
- {
- if(!$this->_navigationContainer && $this->_navigationTemplate)
- {
- $this->_navigationContainer=new TWizardNavigationContainer;
- $this->_navigationTemplate->instantiateIn($this->_navigationContainer);
- }
- }
-}
-
-
-/**
- * TWizardStepCollection class.
- *
- * TWizardStepCollection represents the collection of wizard steps owned
- * by a {@link TWizard}.
- *
- * @author Qiang Xue <qiang.xue@gmail.com>
- * @version $Id$
- * @package System.Web.UI.WebControls
- * @since 3.0
- */
-class TWizardStepCollection extends TList
-{
- /**
- * @var TWizard
- */
- private $_wizard;
-
- /**
- * Constructor.
- * @param TWizard wizard that owns this collection
- */
- public function __construct(TWizard $wizard)
- {
- $this->_wizard=$wizard;
- }
-
- /**
- * Inserts an item at the specified position.
- * This method overrides the parent implementation by checking if
- * the item being added is a {@link TWizardStep}.
- * @param integer the speicified position.
- * @param mixed new item
- * @throws TInvalidDataTypeException if the item being added is not TWizardStep.
- */
- public function insertAt($index,$item)
- {
- if($item instanceof TWizardStep)
- {
- parent::insertAt($index,$item);
- $this->_wizard->getMultiView()->getViews()->insertAt($index,$item);
- $this->_wizard->addedWizardStep($item);
- }
- else
- throw new TInvalidDataTypeException('wizardstepcollection_wizardstep_required');
- }
-
- /**
- * Removes an item at the specified position.
- * @param integer the index of the item to be removed.
- * @return mixed the removed item.
- */
- public function removeAt($index)
- {
- $step=parent::removeAt($index);
- $this->_wizard->getMultiView()->getViews()->remove($step);
- $this->_wizard->removedWizardStep($step);
- return $step;
- }
-}
-
-
-/**
- * TWizardNavigationContainer class.
- *
- * TWizardNavigationContainer represents a control containing
- * a wizard navigation. The navigation may contain a few buttons, including
- * {@link getPreviousButton PreviousButton}, {@link getNextButton NextButton},
- * {@link getCancelButton CancelButton}, {@link getCompleteButton CompleteButton}.
- *
- * @author Qiang Xue <qiang.xue@gmail.com>
- * @version $Id$
- * @package System.Web.UI.WebControls
- * @since 3.0
- */
-class TWizardNavigationContainer extends TControl implements INamingContainer
-{
- private $_previousButton=null;
- private $_nextButton=null;
- private $_cancelButton=null;
- private $_completeButton=null;
-
- /**
- * @return mixed the previous button
- */
- public function getPreviousButton()
- {
- return $this->_previousButton;
- }
-
- /**
- * @param mixed the previous button
- */
- public function setPreviousButton($value)
- {
- $this->_previousButton=$value;
- }
-
- /**
- * @return mixed the next button
- */
- public function getNextButton()
- {
- return $this->_nextButton;
- }
-
- /**
- * @param mixed the next button
- */
- public function setNextButton($value)
- {
- $this->_nextButton=$value;
- }
-
- /**
- * @return mixed the cancel button
- */
- public function getCancelButton()
- {
- return $this->_cancelButton;
- }
-
- /**
- * @param mixed the cancel button
- */
- public function setCancelButton($value)
- {
- $this->_cancelButton=$value;
- }
-
- /**
- * @return mixed the complete button
- */
- public function getCompleteButton()
- {
- return $this->_completeButton;
- }
-
- /**
- * @param mixed the complete button
- */
- public function setCompleteButton($value)
- {
- $this->_completeButton=$value;
- }
-}
-
-
-/**
- * TWizardNavigationEventParameter class.
- *
- * TWizardNavigationEventParameter represents the parameter for
- * {@link TWizard}'s navigation events.
- *
- * The index of the currently active step can be obtained from
- * {@link getCurrentStepIndex CurrentStepIndex}, while the index
- * of the candidate new step is in {@link getNextStepIndex NextStepIndex}.
- * By modifying {@link setNextStepIndex NextStepIndex}, the new step
- * can be changed to another one. If there is anything wrong with
- * the navigation and it is not wanted, set {@link setCancelNavigation CancelNavigation}
- * to true.
- *
- * @author Qiang Xue <qiang.xue@gmail.com>
- * @version $Id$
- * @package System.Web.UI.WebControls
- * @since 3.0
- */
-class TWizardNavigationEventParameter extends TEventParameter
-{
- private $_cancel=false;
- private $_currentStep;
- private $_nextStep;
-
- /**
- * Constructor.
- * @param integer current step index
- */
- public function __construct($currentStep)
- {
- $this->_currentStep=$currentStep;
- $this->_nextStep=$currentStep;
- }
-
- /**
- * @return integer the zero-based index of the currently active step.
- */
- public function getCurrentStepIndex()
- {
- return $this->_currentStep;
- }
-
- /**
- * @return integer the zero-based index of the next step. Default to {@link getCurrentStepIndex CurrentStepIndex}.
- */
- public function getNextStepIndex()
- {
- return $this->_nextStep;
- }
-
- /**
- * @param integer the zero-based index of the next step.
- */
- public function setNextStepIndex($index)
- {
- $this->_nextStep=TPropertyValue::ensureInteger($index);
- }
-
- /**
- * @return boolean whether navigation to the next step should be canceled. Default to false.
- */
- public function getCancelNavigation()
- {
- return $this->_cancel;
- }
-
- /**
- * @param boolean whether navigation to the next step should be canceled.
- */
- public function setCancelNavigation($value)
- {
- $this->_cancel=TPropertyValue::ensureBoolean($value);
- }
-}
-
-/**
- * TWizardSideBarTemplate class.
- * TWizardSideBarTemplate is the default template for wizard sidebar.
- * @author Qiang Xue <qiang.xue@gmail.com>
- * @version $Id$
- * @package System.Web.UI.WebControls
- * @since 3.0
- */
-class TWizardSideBarTemplate extends TComponent implements ITemplate
-{
- /**
- * Instantiates the template.
- * It creates a {@link TDataList} control.
- * @param TControl parent to hold the content within the template
- */
- public function instantiateIn($parent)
- {
- $dataList=new TDataList;
- $dataList->setID(TWizard::ID_SIDEBAR_LIST);
- $dataList->getSelectedItemStyle()->getFont()->setBold(true);
- $dataList->setItemTemplate(new TWizardSideBarListItemTemplate);
- $parent->getControls()->add($dataList);
- }
-}
-
-/**
- * TWizardSideBarListItemTemplate class.
- * TWizardSideBarListItemTemplate is the default template for each item in the sidebar datalist.
- * @author Qiang Xue <qiang.xue@gmail.com>
- * @version $Id$
- * @package System.Web.UI.WebControls
- * @since 3.0
- */
-class TWizardSideBarListItemTemplate extends TComponent implements ITemplate
-{
- /**
- * Instantiates the template.
- * It creates a {@link TLinkButton}.
- * @param TControl parent to hold the content within the template
- */
- public function instantiateIn($parent)
- {
- $button=new TLinkButton;
- $button->setID(TWizard::ID_SIDEBAR_BUTTON);
- $parent->getControls()->add($button);
- }
-}
-
-/**
- * TWizardNavigationTemplate class.
- * TWizardNavigationTemplate is the base class for various navigation templates.
- * @author Qiang Xue <qiang.xue@gmail.com>
- * @version $Id$
- * @package System.Web.UI.WebControls
- * @since 3.0
- */
-class TWizardNavigationTemplate extends TComponent implements ITemplate
-{
- private $_wizard;
-
- /**
- * Constructor.
- * @param TWizard the wizard owning this template
- */
- public function __construct($wizard)
- {
- $this->_wizard=$wizard;
- }
-
- /**
- * @return TWizard the wizard owning this template
- */
- public function getWizard()
- {
- return $this->_wizard;
- }
-
- /**
- * Instantiates the template.
- * Derived classes should override this method.
- * @param TControl parent to hold the content within the template
- */
- public function instantiateIn($parent)
- {
- }
-
- /**
- * Creates a navigation button.
- * It creates a {@link TButton}, {@link TLinkButton}, or {@link TImageButton},
- * depending on the given parameters.
- * @param TWizardNavigationButtonStyle button style
- * @param boolean whether the button should cause validation
- * @param string command name for the button's OnCommand event
- * @throws TInvalidDataValueException if the button type is not recognized
- */
- protected function createNavigationButton($buttonStyle,$causesValidation,$commandName)
- {
- switch($buttonStyle->getButtonType())
- {
- case TWizardNavigationButtonType::Button:
- $button=new TButton;
- break;
- case TWizardNavigationButtonType::Link:
- $button=new TLinkButton;
- break;
- case TWizardNavigationButtonType::Image:
- $button=new TImageButton;
- $button->setImageUrl($buttonStyle->getImageUrl());
- break;
- default:
- throw new TInvalidDataValueException('wizard_buttontype_unknown',$buttonStyle->getButtonType());
- }
- $button->setText($buttonStyle->getButtonText());
- $button->setCausesValidation($causesValidation);
- $button->setCommandName($commandName);
- return $button;
- }
-}
-
-/**
- * TWizardStartNavigationTemplate class.
- * TWizardStartNavigationTemplate is the template used as default wizard start navigation panel.
- * It consists of two buttons, Next and Cancel.
- * @author Qiang Xue <qiang.xue@gmail.com>
- * @version $Id$
- * @package System.Web.UI.WebControls
- * @since 3.0
- */
-class TWizardStartNavigationTemplate extends TWizardNavigationTemplate
-{
- /**
- * Instantiates the template.
- * @param TControl parent to hold the content within the template
- */
- public function instantiateIn($parent)
- {
- $nextButton=$this->createNavigationButton($this->getWizard()->getStartNextButtonStyle(),true,TWizard::CMD_NEXT);
- $cancelButton=$this->createNavigationButton($this->getWizard()->getCancelButtonStyle(),false,TWizard::CMD_CANCEL);
-
- $controls=$parent->getControls();
- $controls->add($nextButton);
- $controls->add("\n");
- $controls->add($cancelButton);
-
- $parent->setNextButton($nextButton);
- $parent->setCancelButton($cancelButton);
- }
-}
-
-/**
- * TWizardFinishNavigationTemplate class.
- * TWizardFinishNavigationTemplate is the template used as default wizard finish navigation panel.
- * It consists of three buttons, Previous, Complete and Cancel.
- * @author Qiang Xue <qiang.xue@gmail.com>
- * @version $Id$
- * @package System.Web.UI.WebControls
- * @since 3.0
- */
-class TWizardFinishNavigationTemplate extends TWizardNavigationTemplate
-{
- /**
- * Instantiates the template.
- * @param TControl parent to hold the content within the template
- */
- public function instantiateIn($parent)
- {
- $previousButton=$this->createNavigationButton($this->getWizard()->getFinishPreviousButtonStyle(),false,TWizard::CMD_PREVIOUS);
- $completeButton=$this->createNavigationButton($this->getWizard()->getFinishCompleteButtonStyle(),true,TWizard::CMD_COMPLETE);
- $cancelButton=$this->createNavigationButton($this->getWizard()->getCancelButtonStyle(),false,TWizard::CMD_CANCEL);
-
- $controls=$parent->getControls();
- $controls->add($previousButton);
- $controls->add("\n");
- $controls->add($completeButton);
- $controls->add("\n");
- $controls->add($cancelButton);
-
- $parent->setPreviousButton($previousButton);
- $parent->setCompleteButton($completeButton);
- $parent->setCancelButton($cancelButton);
- }
-}
-
-/**
- * TWizardStepNavigationTemplate class.
- * TWizardStepNavigationTemplate is the template used as default wizard step navigation panel.
- * It consists of three buttons, Previous, Next and Cancel.
- * @author Qiang Xue <qiang.xue@gmail.com>
- * @version $Id$
- * @package System.Web.UI.WebControls
- * @since 3.0
- */
-class TWizardStepNavigationTemplate extends TWizardNavigationTemplate
-{
- /**
- * Instantiates the template.
- * @param TControl parent to hold the content within the template
- */
- public function instantiateIn($parent)
- {
- $previousButton=$this->createNavigationButton($this->getWizard()->getStepPreviousButtonStyle(),false,TWizard::CMD_PREVIOUS);
- $nextButton=$this->createNavigationButton($this->getWizard()->getStepNextButtonStyle(),true,TWizard::CMD_NEXT);
- $cancelButton=$this->createNavigationButton($this->getWizard()->getCancelButtonStyle(),false,TWizard::CMD_CANCEL);
-
- $controls=$parent->getControls();
- $controls->add($previousButton);
- $controls->add("\n");
- $controls->add($nextButton);
- $controls->add("\n");
- $controls->add($cancelButton);
-
- $parent->setPreviousButton($previousButton);
- $parent->setNextButton($nextButton);
- $parent->setCancelButton($cancelButton);
- }
-}
-
-
-/**
- * TWizardNavigationButtonType class.
- * TWizardNavigationButtonType defines the enumerable type for the possible types of buttons
- * that can be used in the navigation part of a {@link TWizard}.
- *
- * The following enumerable values are defined:
- * - Button: a regular click button
- * - Image: an image button
- * - Link: a hyperlink button
- *
- * @author Qiang Xue <qiang.xue@gmail.com>
- * @version $Id$
- * @package System.Web.UI.WebControls
- * @since 3.0.4
- */
-class TWizardNavigationButtonType extends TEnumerable
-{
- const Button='Button';
- const Image='Image';
- const Link='Link';
-}
-
-
-/**
- * TWizardStepType class.
- * TWizardStepType defines the enumerable type for the possible types of {@link TWizard wizard} steps.
- *
- * The following enumerable values are defined:
- * - Auto: the type is automatically determined based on the location of the wizard step in the whole step collection.
- * - Complete: the step is the last summary step.
- * - Start: the step is the first step
- * - Step: the step is between the begin and the end steps.
- * - Finish: the last step before the Complete step.
- *
- * @author Qiang Xue <qiang.xue@gmail.com>
- * @version $Id$
- * @package System.Web.UI.WebControls
- * @since 3.0.4
- */
-class TWizardStepType extends TEnumerable
-{
- const Auto='Auto';
- const Complete='Complete';
- const Start='Start';
- const Step='Step';
- const Finish='Finish';
-}
-
+ $requestedIndex=TPropertyValue::ensureInteger($requestedStep);
+ $navParam->setNextStepIndex($requestedIndex);
+ $handled=true;
+ }
+
+ if($handled)
+ {
+ if(!$navParam->getCancelNavigation())
+ {
+ $nextStepIndex=$navParam->getNextStepIndex();
+ if(!$this->_activeStepIndexSet && $this->allowNavigationToStep($nextStepIndex))
+ {
+ if($movePrev)
+ $this->getPreviousStepIndex(true); // pop out the previous move from history
+ $this->setActiveStepIndex($nextStepIndex);
+ }
+ }
+ else
+ $this->setActiveStepIndex($index);
+ return true;
+ }
+ }
+ return false;
+ }
+}
+
+
+/**
+ * TWizardStep class.
+ *
+ * TWizardStep represents a wizard step. The wizard owning the step
+ * can be obtained by {@link getWizard Wizard}.
+ * To specify the type of the step, set {@link setStepType StepType};
+ * For step title, set {@link setTitle Title}. If a step can be re-visited,
+ * set {@link setAllowReturn AllowReturn} to true.
+ *
+ * @author Qiang Xue <qiang.xue@gmail.com>
+ * @version $Id$
+ * @package System.Web.UI.WebControls
+ * @since 3.0
+ */
+class TWizardStep extends TView
+{
+ private $_wizard;
+
+ /**
+ * @return TWizard the wizard owning this step
+ */
+ public function getWizard()
+ {
+ return $this->_wizard;
+ }
+
+ /**
+ * Sets the wizard owning this step.
+ * This method is used internally by {@link TWizard}.
+ * @param TWizard the wizard owning this step
+ */
+ public function setWizard($wizard)
+ {
+ $this->_wizard=$wizard;
+ }
+
+ /**
+ * @return string the title for this step.
+ */
+ public function getTitle()
+ {
+ return $this->getViewState('Title','');
+ }
+
+ /**
+ * @param string the title for this step.
+ */
+ public function setTitle($value)
+ {
+ $this->setViewState('Title',$value,'');
+ if($this->_wizard)
+ $this->_wizard->wizardStepsChanged();
+ }
+
+ /**
+ * @return boolean whether this step can be re-visited. Default to true.
+ */
+ public function getAllowReturn()
+ {
+ return $this->getViewState('AllowReturn',true);
+ }
+
+ /**
+ * @param boolean whether this step can be re-visited.
+ */
+ public function setAllowReturn($value)
+ {
+ $this->setViewState('AllowReturn',TPropertyValue::ensureBoolean($value),true);
+ }
+
+ /**
+ * @return TWizardStepType the wizard step type. Defaults to TWizardStepType::Auto.
+ */
+ public function getStepType()
+ {
+ return $this->getViewState('StepType',TWizardStepType::Auto);
+ }
+
+ /**
+ * @param TWizardStepType the wizard step type.
+ */
+ public function setStepType($type)
+ {
+ $type=TPropertyValue::ensureEnum($type,'TWizardStepType');
+ if($type!==$this->getStepType())
+ {
+ $this->setViewState('StepType',$type,TWizardStepType::Auto);
+ if($this->_wizard)
+ $this->_wizard->wizardStepsChanged();
+ }
+ }
+}
+
+
+/**
+ * TCompleteWizardStep class.
+ *
+ * TCompleteWizardStep represents a wizard step of type TWizardStepType::Complete.
+ *
+ * @author Qiang Xue <qiang.xue@gmail.com>
+ * @version $Id$
+ * @package System.Web.UI.WebControls
+ * @since 3.0
+ */
+class TCompleteWizardStep extends TWizardStep
+{
+ /**
+ * @return TWizardStepType the wizard step type. Always TWizardStepType::Complete.
+ */
+ public function getStepType()
+ {
+ return TWizardStepType::Complete;
+ }
+
+ /**
+ * @param string the wizard step type.
+ * @throws TInvalidOperationException whenever this method is invoked.
+ */
+ public function setStepType($value)
+ {
+ throw new TInvalidOperationException('completewizardstep_steptype_readonly');
+ }
+}
+
+
+/**
+ * TTemplatedWizardStep class.
+ *
+ * TTemplatedWizardStep represents a wizard step whose content and navigation
+ * can be customized using templates. To customize the step content, specify
+ * {@link setContentTemplate ContentTemplate}. To customize navigation specific
+ * to the step, specify {@link setNavigationTemplate NavigationTemplate}. Note,
+ * if the navigation template is not specified, default navigation will be used.
+ *
+ * @author Qiang Xue <qiang.xue@gmail.com>
+ * @version $Id$
+ * @package System.Web.UI.WebControls
+ * @since 3.0
+ */
+class TTemplatedWizardStep extends TWizardStep implements INamingContainer
+{
+ /**
+ * @var ITemplate the template for displaying the navigation UI of a wizard step.
+ */
+ private $_navigationTemplate=null;
+ /**
+ * @var ITemplate the template for displaying the content within the wizard step.
+ */
+ private $_contentTemplate=null;
+ /**
+ * @var TWizardNavigationContainer
+ */
+ private $_navigationContainer=null;
+
+ /**
+ * Creates child controls.
+ * This method mainly instantiates the content template, if any.
+ */
+ public function createChildControls()
+ {
+ $this->getControls()->clear();
+ if($this->_contentTemplate)
+ $this->_contentTemplate->instantiateIn($this);
+ }
+
+ /**
+ * Ensures child controls are created.
+ * @param mixed event parameter
+ */
+ public function onInit($param)
+ {
+ parent::onInit($param);
+ $this->ensureChildControls();
+ }
+
+ /**
+ * @return ITemplate the template for the content of the wizard step.
+ */
+ public function getContentTemplate()
+ {
+ return $this->_contentTemplate;
+ }
+
+ /**
+ * @param ITemplate the template for the content of the wizard step.
+ */
+ public function setContentTemplate($value)
+ {
+ $this->_contentTemplate=$value;
+ }
+
+ /**
+ * @return ITemplate the template for displaying the navigation UI of a wizard step. Defaults to null.
+ */
+ public function getNavigationTemplate()
+ {
+ return $this->_navigationTemplate;
+ }
+
+ /**
+ * @param ITemplate the template for displaying the navigation UI of a wizard step.
+ */
+ public function setNavigationTemplate($value)
+ {
+ $this->_navigationTemplate=$value;
+ }
+
+ /**
+ * @return TWizardNavigationContainer the control containing the navigation.
+ * It could be null if no navigation template is specified.
+ */
+ public function getNavigationContainer()
+ {
+ return $this->_navigationContainer;
+ }
+
+ /**
+ * Instantiates the navigation template if any
+ */
+ public function instantiateNavigationTemplate()
+ {
+ if(!$this->_navigationContainer && $this->_navigationTemplate)
+ {
+ $this->_navigationContainer=new TWizardNavigationContainer;
+ $this->_navigationTemplate->instantiateIn($this->_navigationContainer);
+ }
+ }
+}
+
+
+/**
+ * TWizardStepCollection class.
+ *
+ * TWizardStepCollection represents the collection of wizard steps owned
+ * by a {@link TWizard}.
+ *
+ * @author Qiang Xue <qiang.xue@gmail.com>
+ * @version $Id$
+ * @package System.Web.UI.WebControls
+ * @since 3.0
+ */
+class TWizardStepCollection extends TList
+{
+ /**
+ * @var TWizard
+ */
+ private $_wizard;
+
+ /**
+ * Constructor.
+ * @param TWizard wizard that owns this collection
+ */
+ public function __construct(TWizard $wizard)
+ {
+ $this->_wizard=$wizard;
+ }
+
+ /**
+ * Inserts an item at the specified position.
+ * This method overrides the parent implementation by checking if
+ * the item being added is a {@link TWizardStep}.
+ * @param integer the speicified position.
+ * @param mixed new item
+ * @throws TInvalidDataTypeException if the item being added is not TWizardStep.
+ */
+ public function insertAt($index,$item)
+ {
+ if($item instanceof TWizardStep)
+ {
+ parent::insertAt($index,$item);
+ $this->_wizard->getMultiView()->getViews()->insertAt($index,$item);
+ $this->_wizard->addedWizardStep($item);
+ }
+ else
+ throw new TInvalidDataTypeException('wizardstepcollection_wizardstep_required');
+ }
+
+ /**
+ * Removes an item at the specified position.
+ * @param integer the index of the item to be removed.
+ * @return mixed the removed item.
+ */
+ public function removeAt($index)
+ {
+ $step=parent::removeAt($index);
+ $this->_wizard->getMultiView()->getViews()->remove($step);
+ $this->_wizard->removedWizardStep($step);
+ return $step;
+ }
+}
+
+
+/**
+ * TWizardNavigationContainer class.
+ *
+ * TWizardNavigationContainer represents a control containing
+ * a wizard navigation. The navigation may contain a few buttons, including
+ * {@link getPreviousButton PreviousButton}, {@link getNextButton NextButton},
+ * {@link getCancelButton CancelButton}, {@link getCompleteButton CompleteButton}.
+ *
+ * @author Qiang Xue <qiang.xue@gmail.com>
+ * @version $Id$
+ * @package System.Web.UI.WebControls
+ * @since 3.0
+ */
+class TWizardNavigationContainer extends TControl implements INamingContainer
+{
+ private $_previousButton=null;
+ private $_nextButton=null;
+ private $_cancelButton=null;
+ private $_completeButton=null;
+
+ /**
+ * @return mixed the previous button
+ */
+ public function getPreviousButton()
+ {
+ return $this->_previousButton;
+ }
+
+ /**
+ * @param mixed the previous button
+ */
+ public function setPreviousButton($value)
+ {
+ $this->_previousButton=$value;
+ }
+
+ /**
+ * @return mixed the next button
+ */
+ public function getNextButton()
+ {
+ return $this->_nextButton;
+ }
+
+ /**
+ * @param mixed the next button
+ */
+ public function setNextButton($value)
+ {
+ $this->_nextButton=$value;
+ }
+
+ /**
+ * @return mixed the cancel button
+ */
+ public function getCancelButton()
+ {
+ return $this->_cancelButton;
+ }
+
+ /**
+ * @param mixed the cancel button
+ */
+ public function setCancelButton($value)
+ {
+ $this->_cancelButton=$value;
+ }
+
+ /**
+ * @return mixed the complete button
+ */
+ public function getCompleteButton()
+ {
+ return $this->_completeButton;
+ }
+
+ /**
+ * @param mixed the complete button
+ */
+ public function setCompleteButton($value)
+ {
+ $this->_completeButton=$value;
+ }
+}
+
+
+/**
+ * TWizardNavigationEventParameter class.
+ *
+ * TWizardNavigationEventParameter represents the parameter for
+ * {@link TWizard}'s navigation events.
+ *
+ * The index of the currently active step can be obtained from
+ * {@link getCurrentStepIndex CurrentStepIndex}, while the index
+ * of the candidate new step is in {@link getNextStepIndex NextStepIndex}.
+ * By modifying {@link setNextStepIndex NextStepIndex}, the new step
+ * can be changed to another one. If there is anything wrong with
+ * the navigation and it is not wanted, set {@link setCancelNavigation CancelNavigation}
+ * to true.
+ *
+ * @author Qiang Xue <qiang.xue@gmail.com>
+ * @version $Id$
+ * @package System.Web.UI.WebControls
+ * @since 3.0
+ */
+class TWizardNavigationEventParameter extends TEventParameter
+{
+ private $_cancel=false;
+ private $_currentStep;
+ private $_nextStep;
+
+ /**
+ * Constructor.
+ * @param integer current step index
+ */
+ public function __construct($currentStep)
+ {
+ $this->_currentStep=$currentStep;
+ $this->_nextStep=$currentStep;
+ }
+
+ /**
+ * @return integer the zero-based index of the currently active step.
+ */
+ public function getCurrentStepIndex()
+ {
+ return $this->_currentStep;
+ }
+
+ /**
+ * @return integer the zero-based index of the next step. Default to {@link getCurrentStepIndex CurrentStepIndex}.
+ */
+ public function getNextStepIndex()
+ {
+ return $this->_nextStep;
+ }
+
+ /**
+ * @param integer the zero-based index of the next step.
+ */
+ public function setNextStepIndex($index)
+ {
+ $this->_nextStep=TPropertyValue::ensureInteger($index);
+ }
+
+ /**
+ * @return boolean whether navigation to the next step should be canceled. Default to false.
+ */
+ public function getCancelNavigation()
+ {
+ return $this->_cancel;
+ }
+
+ /**
+ * @param boolean whether navigation to the next step should be canceled.
+ */
+ public function setCancelNavigation($value)
+ {
+ $this->_cancel=TPropertyValue::ensureBoolean($value);
+ }
+}
+
+/**
+ * TWizardSideBarTemplate class.
+ * TWizardSideBarTemplate is the default template for wizard sidebar.
+ * @author Qiang Xue <qiang.xue@gmail.com>
+ * @version $Id$
+ * @package System.Web.UI.WebControls
+ * @since 3.0
+ */
+class TWizardSideBarTemplate extends TComponent implements ITemplate
+{
+ /**
+ * Instantiates the template.
+ * It creates a {@link TDataList} control.
+ * @param TControl parent to hold the content within the template
+ */
+ public function instantiateIn($parent)
+ {
+ $dataList=new TDataList;
+ $dataList->setID(TWizard::ID_SIDEBAR_LIST);
+ $dataList->getSelectedItemStyle()->getFont()->setBold(true);
+ $dataList->setItemTemplate(new TWizardSideBarListItemTemplate);
+ $parent->getControls()->add($dataList);
+ }
+}
+
+/**
+ * TWizardSideBarListItemTemplate class.
+ * TWizardSideBarListItemTemplate is the default template for each item in the sidebar datalist.
+ * @author Qiang Xue <qiang.xue@gmail.com>
+ * @version $Id$
+ * @package System.Web.UI.WebControls
+ * @since 3.0
+ */
+class TWizardSideBarListItemTemplate extends TComponent implements ITemplate
+{
+ /**
+ * Instantiates the template.
+ * It creates a {@link TLinkButton}.
+ * @param TControl parent to hold the content within the template
+ */
+ public function instantiateIn($parent)
+ {
+ $button=new TLinkButton;
+ $button->setID(TWizard::ID_SIDEBAR_BUTTON);
+ $parent->getControls()->add($button);
+ }
+}
+
+/**
+ * TWizardNavigationTemplate class.
+ * TWizardNavigationTemplate is the base class for various navigation templates.
+ * @author Qiang Xue <qiang.xue@gmail.com>
+ * @version $Id$
+ * @package System.Web.UI.WebControls
+ * @since 3.0
+ */
+class TWizardNavigationTemplate extends TComponent implements ITemplate
+{
+ private $_wizard;
+
+ /**
+ * Constructor.
+ * @param TWizard the wizard owning this template
+ */
+ public function __construct($wizard)
+ {
+ $this->_wizard=$wizard;
+ }
+
+ /**
+ * @return TWizard the wizard owning this template
+ */
+ public function getWizard()
+ {
+ return $this->_wizard;
+ }
+
+ /**
+ * Instantiates the template.
+ * Derived classes should override this method.
+ * @param TControl parent to hold the content within the template
+ */
+ public function instantiateIn($parent)
+ {
+ }
+
+ /**
+ * Creates a navigation button.
+ * It creates a {@link TButton}, {@link TLinkButton}, or {@link TImageButton},
+ * depending on the given parameters.
+ * @param TWizardNavigationButtonStyle button style
+ * @param boolean whether the button should cause validation
+ * @param string command name for the button's OnCommand event
+ * @throws TInvalidDataValueException if the button type is not recognized
+ */
+ protected function createNavigationButton($buttonStyle,$causesValidation,$commandName)
+ {
+ switch($buttonStyle->getButtonType())
+ {
+ case TWizardNavigationButtonType::Button:
+ $button=new TButton;
+ break;
+ case TWizardNavigationButtonType::Link:
+ $button=new TLinkButton;
+ break;
+ case TWizardNavigationButtonType::Image:
+ $button=new TImageButton;
+ $button->setImageUrl($buttonStyle->getImageUrl());
+ break;
+ default:
+ throw new TInvalidDataValueException('wizard_buttontype_unknown',$buttonStyle->getButtonType());
+ }
+ $button->setText($buttonStyle->getButtonText());
+ $button->setCausesValidation($causesValidation);
+ $button->setCommandName($commandName);
+ return $button;
+ }
+}
+
+/**
+ * TWizardStartNavigationTemplate class.
+ * TWizardStartNavigationTemplate is the template used as default wizard start navigation panel.
+ * It consists of two buttons, Next and Cancel.
+ * @author Qiang Xue <qiang.xue@gmail.com>
+ * @version $Id$
+ * @package System.Web.UI.WebControls
+ * @since 3.0
+ */
+class TWizardStartNavigationTemplate extends TWizardNavigationTemplate
+{
+ /**
+ * Instantiates the template.
+ * @param TControl parent to hold the content within the template
+ */
+ public function instantiateIn($parent)
+ {
+ $nextButton=$this->createNavigationButton($this->getWizard()->getStartNextButtonStyle(),true,TWizard::CMD_NEXT);
+ $cancelButton=$this->createNavigationButton($this->getWizard()->getCancelButtonStyle(),false,TWizard::CMD_CANCEL);
+
+ $controls=$parent->getControls();
+ $controls->add($nextButton);
+ $controls->add("\n");
+ $controls->add($cancelButton);
+
+ $parent->setNextButton($nextButton);
+ $parent->setCancelButton($cancelButton);
+ }
+}
+
+/**
+ * TWizardFinishNavigationTemplate class.
+ * TWizardFinishNavigationTemplate is the template used as default wizard finish navigation panel.
+ * It consists of three buttons, Previous, Complete and Cancel.
+ * @author Qiang Xue <qiang.xue@gmail.com>
+ * @version $Id$
+ * @package System.Web.UI.WebControls
+ * @since 3.0
+ */
+class TWizardFinishNavigationTemplate extends TWizardNavigationTemplate
+{
+ /**
+ * Instantiates the template.
+ * @param TControl parent to hold the content within the template
+ */
+ public function instantiateIn($parent)
+ {
+ $previousButton=$this->createNavigationButton($this->getWizard()->getFinishPreviousButtonStyle(),false,TWizard::CMD_PREVIOUS);
+ $completeButton=$this->createNavigationButton($this->getWizard()->getFinishCompleteButtonStyle(),true,TWizard::CMD_COMPLETE);
+ $cancelButton=$this->createNavigationButton($this->getWizard()->getCancelButtonStyle(),false,TWizard::CMD_CANCEL);
+
+ $controls=$parent->getControls();
+ $controls->add($previousButton);
+ $controls->add("\n");
+ $controls->add($completeButton);
+ $controls->add("\n");
+ $controls->add($cancelButton);
+
+ $parent->setPreviousButton($previousButton);
+ $parent->setCompleteButton($completeButton);
+ $parent->setCancelButton($cancelButton);
+ }
+}
+
+/**
+ * TWizardStepNavigationTemplate class.
+ * TWizardStepNavigationTemplate is the template used as default wizard step navigation panel.
+ * It consists of three buttons, Previous, Next and Cancel.
+ * @author Qiang Xue <qiang.xue@gmail.com>
+ * @version $Id$
+ * @package System.Web.UI.WebControls
+ * @since 3.0
+ */
+class TWizardStepNavigationTemplate extends TWizardNavigationTemplate
+{
+ /**
+ * Instantiates the template.
+ * @param TControl parent to hold the content within the template
+ */
+ public function instantiateIn($parent)
+ {
+ $previousButton=$this->createNavigationButton($this->getWizard()->getStepPreviousButtonStyle(),false,TWizard::CMD_PREVIOUS);
+ $nextButton=$this->createNavigationButton($this->getWizard()->getStepNextButtonStyle(),true,TWizard::CMD_NEXT);
+ $cancelButton=$this->createNavigationButton($this->getWizard()->getCancelButtonStyle(),false,TWizard::CMD_CANCEL);
+
+ $controls=$parent->getControls();
+ $controls->add($previousButton);
+ $controls->add("\n");
+ $controls->add($nextButton);
+ $controls->add("\n");
+ $controls->add($cancelButton);
+
+ $parent->setPreviousButton($previousButton);
+ $parent->setNextButton($nextButton);
+ $parent->setCancelButton($cancelButton);
+ }
+}
+
+
+/**
+ * TWizardNavigationButtonType class.
+ * TWizardNavigationButtonType defines the enumerable type for the possible types of buttons
+ * that can be used in the navigation part of a {@link TWizard}.
+ *
+ * The following enumerable values are defined:
+ * - Button: a regular click button
+ * - Image: an image button
+ * - Link: a hyperlink button
+ *
+ * @author Qiang Xue <qiang.xue@gmail.com>
+ * @version $Id$
+ * @package System.Web.UI.WebControls
+ * @since 3.0.4
+ */
+class TWizardNavigationButtonType extends TEnumerable
+{
+ const Button='Button';
+ const Image='Image';
+ const Link='Link';
+}
+
+
+/**
+ * TWizardStepType class.
+ * TWizardStepType defines the enumerable type for the possible types of {@link TWizard wizard} steps.
+ *
+ * The following enumerable values are defined:
+ * - Auto: the type is automatically determined based on the location of the wizard step in the whole step collection.
+ * - Complete: the step is the last summary step.
+ * - Start: the step is the first step
+ * - Step: the step is between the begin and the end steps.
+ * - Finish: the last step before the Complete step.
+ *
+ * @author Qiang Xue <qiang.xue@gmail.com>
+ * @version $Id$
+ * @package System.Web.UI.WebControls
+ * @since 3.0.4
+ */
+class TWizardStepType extends TEnumerable
+{
+ const Auto='Auto';
+ const Complete='Complete';
+ const Start='Start';
+ const Step='Step';
+ const Finish='Finish';
+}
+
diff --git a/framework/Web/UI/WebControls/TWizardNavigationButtonStyle.php b/framework/Web/UI/WebControls/TWizardNavigationButtonStyle.php
index 0e05c556..c3b4b603 100644
--- a/framework/Web/UI/WebControls/TWizardNavigationButtonStyle.php
+++ b/framework/Web/UI/WebControls/TWizardNavigationButtonStyle.php
@@ -1,155 +1,155 @@
-<?php
-/**
- * TWizardNavigationButtonStyle class file.
- *
- * @author Qiang Xue <qiang.xue@gmail.com>
- * @link http://www.pradosoft.com/
+<?php
+/**
+ * TWizardNavigationButtonStyle class file.
+ *
+ * @author Qiang Xue <qiang.xue@gmail.com>
+ * @link http://www.pradosoft.com/
* @copyright Copyright &copy; 2005-2012 PradoSoft
- * @license http://www.pradosoft.com/license/
- * @version $Id $
- * @package System.Web.UI.WebControls
- */
-
-/**
- * Includes TStyle class file
- */
-Prado::using('System.Web.UI.WebControls.TStyle');
-
-/**
- * TWizardNavigationButtonStyle class.
- * TWizardNavigationButtonStyle defines the style applied to a wizard navigation button.
- * The button type can be specified via {@link setButtonType ButtonType}, which
- * can be 'Button', 'Image' or 'Link'.
- * If the button is an image button, {@link setImageUrl ImageUrl} will be
- * used to load the image for the button.
- * Otherwise, {@link setButtonText ButtonText} will be displayed as the button caption.
- *
- * @author Qiang Xue <qiang.xue@gmail.com>
- * @version $Id$
- * @package System.Web.UI.WebControls
- * @since 3.0
- */
-class TWizardNavigationButtonStyle extends TStyle
-{
- private $_imageUrl=null;
- private $_buttonText=null;
- private $_buttonType=null;
-
- /**
- * Sets the style attributes to default values.
- * This method overrides the parent implementation by
- * resetting additional TWizardNavigationButtonStyle specific attributes.
- */
- public function reset()
- {
- parent::reset();
- $this->_imageUrl=null;
- $this->_buttonText=null;
- $this->_buttonType=null;
- }
-
- /**
- * Copies the fields in a new style to this style.
- * If a style field is set in the new style, the corresponding field
- * in this style will be overwritten.
- * @param TStyle the new style
- */
- public function copyFrom($style)
- {
- parent::copyFrom($style);
- if($style instanceof TWizardNavigationButtonStyle)
- {
- if($this->_imageUrl===null && $style->_imageUrl!==null)
- $this->_imageUrl=$style->_imageUrl;
- if($this->_buttonText===null && $style->_buttonText!==null)
- $this->_buttonText=$style->_buttonText;
- if($this->_buttonType===null && $style->_buttonType!==null)
- $this->_buttonType=$style->_buttonType;
- }
- }
-
- /**
- * Merges the style with a new one.
- * If a style field is not set in this style, it will be overwritten by
- * the new one.
- * @param TStyle the new style
- */
- public function mergeWith($style)
- {
- parent::mergeWith($style);
- if($style instanceof TWizardNavigationButtonStyle)
- {
- if($style->_imageUrl!==null)
- $this->_imageUrl=$style->_imageUrl;
- if($style->_buttonText!==null)
- $this->_buttonText=$style->_buttonText;
- if($style->_buttonType!==null)
- $this->_buttonType=$style->_buttonType;
- }
- }
-
- /**
- * @return string image URL for the image button
- */
- public function getImageUrl()
- {
- return $this->_imageUrl===null?'':$this->_imageUrl;
- }
-
- /**
- * @param string image URL for the image button
- */
- public function setImageUrl($value)
- {
- $this->_imageUrl=$value;
- }
-
- /**
- * @return string button caption
- */
- public function getButtonText()
- {
- return $this->_buttonText===null?'':$this->_buttonText;
- }
-
- /**
- * @param string button caption
- */
- public function setButtonText($value)
- {
- $this->_buttonText=$value;
- }
-
- /**
- * @return TWizardNavigationButtonType button type. Default to TWizardNavigationButtonType::Button.
- */
- public function getButtonType()
- {
- return $this->_buttonType===null? TWizardNavigationButtonType::Button :$this->_buttonType;
- }
-
- /**
- * @param TWizardNavigationButtonType button type.
- */
- public function setButtonType($value)
- {
- $this->_buttonType=TPropertyValue::ensureEnum($value,'TWizardNavigationButtonType');
- }
-
- /**
- * Applies this style to the specified button
- * @param mixed button to be applied with this style
- */
- public function apply($button)
- {
- if($button instanceof TImageButton)
- {
- if($button->getImageUrl()==='')
- $button->setImageUrl($this->getImageUrl());
- }
- if($button->getText()==='')
- $button->setText($this->getButtonText());
- $button->getStyle()->mergeWith($this);
- }
-}
-
+ * @license http://www.pradosoft.com/license/
+ * @version $Id $
+ * @package System.Web.UI.WebControls
+ */
+
+/**
+ * Includes TStyle class file
+ */
+Prado::using('System.Web.UI.WebControls.TStyle');
+
+/**
+ * TWizardNavigationButtonStyle class.
+ * TWizardNavigationButtonStyle defines the style applied to a wizard navigation button.
+ * The button type can be specified via {@link setButtonType ButtonType}, which
+ * can be 'Button', 'Image' or 'Link'.
+ * If the button is an image button, {@link setImageUrl ImageUrl} will be
+ * used to load the image for the button.
+ * Otherwise, {@link setButtonText ButtonText} will be displayed as the button caption.
+ *
+ * @author Qiang Xue <qiang.xue@gmail.com>
+ * @version $Id$
+ * @package System.Web.UI.WebControls
+ * @since 3.0
+ */
+class TWizardNavigationButtonStyle extends TStyle
+{
+ private $_imageUrl=null;
+ private $_buttonText=null;
+ private $_buttonType=null;
+
+ /**
+ * Sets the style attributes to default values.
+ * This method overrides the parent implementation by
+ * resetting additional TWizardNavigationButtonStyle specific attributes.
+ */
+ public function reset()
+ {
+ parent::reset();
+ $this->_imageUrl=null;
+ $this->_buttonText=null;
+ $this->_buttonType=null;
+ }
+
+ /**
+ * Copies the fields in a new style to this style.
+ * If a style field is set in the new style, the corresponding field
+ * in this style will be overwritten.
+ * @param TStyle the new style
+ */
+ public function copyFrom($style)
+ {
+ parent::copyFrom($style);
+ if($style instanceof TWizardNavigationButtonStyle)
+ {
+ if($this->_imageUrl===null && $style->_imageUrl!==null)
+ $this->_imageUrl=$style->_imageUrl;
+ if($this->_buttonText===null && $style->_buttonText!==null)
+ $this->_buttonText=$style->_buttonText;
+ if($this->_buttonType===null && $style->_buttonType!==null)
+ $this->_buttonType=$style->_buttonType;
+ }
+ }
+
+ /**
+ * Merges the style with a new one.
+ * If a style field is not set in this style, it will be overwritten by
+ * the new one.
+ * @param TStyle the new style
+ */
+ public function mergeWith($style)
+ {
+ parent::mergeWith($style);
+ if($style instanceof TWizardNavigationButtonStyle)
+ {
+ if($style->_imageUrl!==null)
+ $this->_imageUrl=$style->_imageUrl;
+ if($style->_buttonText!==null)
+ $this->_buttonText=$style->_buttonText;
+ if($style->_buttonType!==null)
+ $this->_buttonType=$style->_buttonType;
+ }
+ }
+
+ /**
+ * @return string image URL for the image button
+ */
+ public function getImageUrl()
+ {
+ return $this->_imageUrl===null?'':$this->_imageUrl;
+ }
+
+ /**
+ * @param string image URL for the image button
+ */
+ public function setImageUrl($value)
+ {
+ $this->_imageUrl=$value;
+ }
+
+ /**
+ * @return string button caption
+ */
+ public function getButtonText()
+ {
+ return $this->_buttonText===null?'':$this->_buttonText;
+ }
+
+ /**
+ * @param string button caption
+ */
+ public function setButtonText($value)
+ {
+ $this->_buttonText=$value;
+ }
+
+ /**
+ * @return TWizardNavigationButtonType button type. Default to TWizardNavigationButtonType::Button.
+ */
+ public function getButtonType()
+ {
+ return $this->_buttonType===null? TWizardNavigationButtonType::Button :$this->_buttonType;
+ }
+
+ /**
+ * @param TWizardNavigationButtonType button type.
+ */
+ public function setButtonType($value)
+ {
+ $this->_buttonType=TPropertyValue::ensureEnum($value,'TWizardNavigationButtonType');
+ }
+
+ /**
+ * Applies this style to the specified button
+ * @param mixed button to be applied with this style
+ */
+ public function apply($button)
+ {
+ if($button instanceof TImageButton)
+ {
+ if($button->getImageUrl()==='')
+ $button->setImageUrl($this->getImageUrl());
+ }
+ if($button->getText()==='')
+ $button->setText($this->getButtonText());
+ $button->getStyle()->mergeWith($this);
+ }
+}
+
diff --git a/framework/Web/UI/WebControls/assets/captcha.php b/framework/Web/UI/WebControls/assets/captcha.php
index b26df895..08a857b5 100644
--- a/framework/Web/UI/WebControls/assets/captcha.php
+++ b/framework/Web/UI/WebControls/assets/captcha.php
@@ -1,224 +1,224 @@
-<?php
-/**
- * CAPTCHA generator script.
- *
- * @author Qiang Xue <qiang.xue@gmail.com>
- * @link http://www.pradosoft.com/
- * @copyright Copyright &copy; 2005-2012 PradoSoft
- * @license http://www.pradosoft.com/license/
- * @version $Id$
- * @package System.Web.UI.WebControls.assets
- */
-
-define('THEME_OPAQUE_BACKGROUND',0x0001);
-define('THEME_NOISY_BACKGROUND',0x0002);
-define('THEME_HAS_GRID',0x0004);
-define('THEME_HAS_SCRIBBLE',0x0008);
-define('THEME_MORPH_BACKGROUND',0x0010);
-define('THEME_SHADOWED_TEXT',0x0020);
-
-require_once(dirname(__FILE__).'/captcha_key.php');
-
-$token='error';
-$theme=0;
-
-if(isset($_GET['options']))
-{
- $str=base64_decode($_GET['options']);
- if(strlen($str)>32)
- {
- $hash=substr($str,0,32);
- $str=substr($str,32);
- if(md5($privateKey.$str)===$hash)
- {
- $options=unserialize($str);
- $publicKey=$options['publicKey'];
- $tokenLength=$options['tokenLength'];
- $caseSensitive=$options['caseSensitive'];
- $alphabet=$options['alphabet'];
- $fontSize=$options['fontSize'];
- $theme=$options['theme'];
- if(($randomSeed=$options['randomSeed'])>0)
- srand($randomSeed);
- else
- srand((int)(microtime()*1000000));
- $token=generateToken($publicKey,$privateKey,$alphabet,$tokenLength,$caseSensitive);
- }
- }
-}
-
-displayToken($token,$fontSize,$theme);
-
-function generateToken($publicKey,$privateKey,$alphabet,$tokenLength,$caseSensitive)
-{
- $token=substr(hash2string(md5($publicKey.$privateKey),$alphabet).hash2string(md5($privateKey.$publicKey),$alphabet),0,$tokenLength);
- return $caseSensitive?$token:strtoupper($token);
-}
-
-function hash2string($hex,$alphabet)
-{
- if(strlen($alphabet)<2)
- $alphabet='234578adefhijmnrtABDEFGHJLMNRT';
- $hexLength=strlen($hex);
- $base=strlen($alphabet);
- $result='';
- for($i=0;$i<$hexLength;$i+=6)
- {
- $number=hexdec(substr($hex,$i,6));
- while($number)
- {
- $result.=$alphabet[$number%$base];
- $number=floor($number/$base);
- }
- }
- return $result;
-}
-
-function displayToken($token,$fontSize,$theme)
-{
- if(($fontSize=(int)$fontSize)<22)
- $fontSize=22;
- if($fontSize>100)
- $fontSize=100;
- $length=strlen($token);
- $padding=10;
- $fontWidth=$fontSize;
- $fontHeight=floor($fontWidth*1.5);
- $width=$fontWidth*$length+$padding*2;
- $height=$fontHeight;
- $image=imagecreatetruecolor($width,$height);
-
- addBackground
- (
- $image, $width, $height,
- $theme&THEME_OPAQUE_BACKGROUND,
- $theme&THEME_NOISY_BACKGROUND,
- $theme&THEME_HAS_GRID,
- $theme&THEME_HAS_SCRIBBLE,
- $theme&THEME_MORPH_BACKGROUND
- );
-
- $font=dirname(__FILE__).DIRECTORY_SEPARATOR.'verase.ttf';
-
- if(function_exists('imagefilter'))
- imagefilter($image,IMG_FILTER_GAUSSIAN_BLUR);
-
- $hasShadow=($theme&THEME_SHADOWED_TEXT);
- for($i=0;$i<$length;$i++)
- {
- $color=imagecolorallocate($image,rand(150,220),rand(150,220),rand(150,220));
- $size=rand($fontWidth-10,$fontWidth);
- $angle=rand(-30,30);
- $x=$padding+$i*$fontWidth;
- $y=rand($fontHeight-15,$fontHeight-10);
- imagettftext($image,$size,$angle,$x,$y,$color,$font,$token[$i]);
- if($hasShadow)
- imagettftext($image,$size,$angle,$x+2,$y+2,$color,$font,$token[$i]);
- imagecolordeallocate($image,$color);
- }
-
- header('Content-Type: image/png');
- imagepng($image);
- imagedestroy($image);
-}
-
-function addBackground($image,$width,$height,$opaque,$noisy,$hasGrid,$hasScribble,$morph)
-{
- $background=imagecreatetruecolor($width*2,$height*2);
- $white=imagecolorallocate($background,255,255,255);
- imagefill($background,0,0,$white);
-
- if($opaque)
- imagefill($background,0,0,imagecolorallocate($background,100,100,100));
-
- if($noisy)
- addNoise($background,$width*2,$height*2);
-
- if($hasGrid)
- addGrid($background,$width*2,$height*2);
-
- if($hasScribble)
- addScribble($background,$width*2,$height*2);
-
- if($morph)
- morphImage($background,$width*2,$height*2);
-
- imagecopy($image,$background,0,0,30,30,$width,$height);
-
- if(!$opaque)
- imagecolortransparent($image,$white);
-}
-
-function addNoise($image,$width,$height)
-{
- for($x=0;$x<$width;++$x)
- {
- for($y=0;$y<$height;++$y)
- {
- if(rand(0,100)<25)
- {
- $color=imagecolorallocate($image,rand(150,220),rand(150,220),rand(150,220));
- imagesetpixel($image,$x,$y,$color);
- imagecolordeallocate($image,$color);
- }
- }
- }
-}
-
-function addGrid($image,$width,$height)
-{
- for($i=0;$i<$width;$i+=rand(15,25))
- {
- imagesetthickness($image,rand(2,6));
- $color=imagecolorallocate($image,rand(100,180),rand(100,180),rand(100,180));
- imageline($image,$i+rand(-10,20),0,$i+rand(-10,20),$height,$color);
- imagecolordeallocate($image,$color);
- }
- for($i=0;$i<$height;$i+=rand(15,25))
- {
- imagesetthickness($image,rand(2,6));
- $color=imagecolorallocate($image,rand(100,180),rand(100,180),rand(100,180));
- imageline($image,0,$i+rand(-10,20),$width,$i+rand(-10,20),$color);
- imagecolordeallocate($image,$color);
- }
-}
-
-function addScribble($image,$width,$height)
-{
- for($i=0;$i<8;$i++)
- {
- $color=imagecolorallocate($image,rand(100,180),rand(100,180),rand(100,180));
- $points=array();
- for($j=1;$j<rand(5,10);$j++)
- {
- $points[]=rand(2*(20*($i+1)),2*(50*($i+1)));
- $points[]=rand(30,$height+30);
- }
- imagesetthickness($image,rand(2,6));
- imagepolygon($image,$points,intval(sizeof($points)/2),$color);
- imagecolordeallocate($image,$color);
- }
-}
-
-function morphImage($image,$width,$height)
-{
- $tempImage=imagecreatetruecolor($width,$height);
- $chunk=rand(1,5);
- for($x=$y=0;$x<$width;$x+=$chunk)
- {
- $chunk=rand(1,5);
- $y+=rand(-1,1);
- if($y>=$height) $y=$height-5;
- if($y<0) $y=5;
- imagecopy($tempImage,$image,$x,0,$x,$y,$chunk,$height);
- }
- for($x=$y=0;$y<$height;$y+=$chunk)
- {
- $chunk=rand(1,5);
- $x+=rand(-1,1);
- if($x>=$width) $x=$width-5;
- if($x<0) $x=5;
- imagecopy($image,$tempImage,$x,$y,0,$y,$width,$chunk);
- }
-}
-
+<?php
+/**
+ * CAPTCHA generator script.
+ *
+ * @author Qiang Xue <qiang.xue@gmail.com>
+ * @link http://www.pradosoft.com/
+ * @copyright Copyright &copy; 2005-2012 PradoSoft
+ * @license http://www.pradosoft.com/license/
+ * @version $Id$
+ * @package System.Web.UI.WebControls.assets
+ */
+
+define('THEME_OPAQUE_BACKGROUND',0x0001);
+define('THEME_NOISY_BACKGROUND',0x0002);
+define('THEME_HAS_GRID',0x0004);
+define('THEME_HAS_SCRIBBLE',0x0008);
+define('THEME_MORPH_BACKGROUND',0x0010);
+define('THEME_SHADOWED_TEXT',0x0020);
+
+require_once(dirname(__FILE__).'/captcha_key.php');
+
+$token='error';
+$theme=0;
+
+if(isset($_GET['options']))
+{
+ $str=base64_decode($_GET['options']);
+ if(strlen($str)>32)
+ {
+ $hash=substr($str,0,32);
+ $str=substr($str,32);
+ if(md5($privateKey.$str)===$hash)
+ {
+ $options=unserialize($str);
+ $publicKey=$options['publicKey'];
+ $tokenLength=$options['tokenLength'];
+ $caseSensitive=$options['caseSensitive'];
+ $alphabet=$options['alphabet'];
+ $fontSize=$options['fontSize'];
+ $theme=$options['theme'];
+ if(($randomSeed=$options['randomSeed'])>0)
+ srand($randomSeed);
+ else
+ srand((int)(microtime()*1000000));
+ $token=generateToken($publicKey,$privateKey,$alphabet,$tokenLength,$caseSensitive);
+ }
+ }
+}
+
+displayToken($token,$fontSize,$theme);
+
+function generateToken($publicKey,$privateKey,$alphabet,$tokenLength,$caseSensitive)
+{
+ $token=substr(hash2string(md5($publicKey.$privateKey),$alphabet).hash2string(md5($privateKey.$publicKey),$alphabet),0,$tokenLength);
+ return $caseSensitive?$token:strtoupper($token);
+}
+
+function hash2string($hex,$alphabet)
+{
+ if(strlen($alphabet)<2)
+ $alphabet='234578adefhijmnrtABDEFGHJLMNRT';
+ $hexLength=strlen($hex);
+ $base=strlen($alphabet);
+ $result='';
+ for($i=0;$i<$hexLength;$i+=6)
+ {
+ $number=hexdec(substr($hex,$i,6));
+ while($number)
+ {
+ $result.=$alphabet[$number%$base];
+ $number=floor($number/$base);
+ }
+ }
+ return $result;
+}
+
+function displayToken($token,$fontSize,$theme)
+{
+ if(($fontSize=(int)$fontSize)<22)
+ $fontSize=22;
+ if($fontSize>100)
+ $fontSize=100;
+ $length=strlen($token);
+ $padding=10;
+ $fontWidth=$fontSize;
+ $fontHeight=floor($fontWidth*1.5);
+ $width=$fontWidth*$length+$padding*2;
+ $height=$fontHeight;
+ $image=imagecreatetruecolor($width,$height);
+
+ addBackground
+ (
+ $image, $width, $height,
+ $theme&THEME_OPAQUE_BACKGROUND,
+ $theme&THEME_NOISY_BACKGROUND,
+ $theme&THEME_HAS_GRID,
+ $theme&THEME_HAS_SCRIBBLE,
+ $theme&THEME_MORPH_BACKGROUND
+ );
+
+ $font=dirname(__FILE__).DIRECTORY_SEPARATOR.'verase.ttf';
+
+ if(function_exists('imagefilter'))
+ imagefilter($image,IMG_FILTER_GAUSSIAN_BLUR);
+
+ $hasShadow=($theme&THEME_SHADOWED_TEXT);
+ for($i=0;$i<$length;$i++)
+ {
+ $color=imagecolorallocate($image,rand(150,220),rand(150,220),rand(150,220));
+ $size=rand($fontWidth-10,$fontWidth);
+ $angle=rand(-30,30);
+ $x=$padding+$i*$fontWidth;
+ $y=rand($fontHeight-15,$fontHeight-10);
+ imagettftext($image,$size,$angle,$x,$y,$color,$font,$token[$i]);
+ if($hasShadow)
+ imagettftext($image,$size,$angle,$x+2,$y+2,$color,$font,$token[$i]);
+ imagecolordeallocate($image,$color);
+ }
+
+ header('Content-Type: image/png');
+ imagepng($image);
+ imagedestroy($image);
+}
+
+function addBackground($image,$width,$height,$opaque,$noisy,$hasGrid,$hasScribble,$morph)
+{
+ $background=imagecreatetruecolor($width*2,$height*2);
+ $white=imagecolorallocate($background,255,255,255);
+ imagefill($background,0,0,$white);
+
+ if($opaque)
+ imagefill($background,0,0,imagecolorallocate($background,100,100,100));
+
+ if($noisy)
+ addNoise($background,$width*2,$height*2);
+
+ if($hasGrid)
+ addGrid($background,$width*2,$height*2);
+
+ if($hasScribble)
+ addScribble($background,$width*2,$height*2);
+
+ if($morph)
+ morphImage($background,$width*2,$height*2);
+
+ imagecopy($image,$background,0,0,30,30,$width,$height);
+
+ if(!$opaque)
+ imagecolortransparent($image,$white);
+}
+
+function addNoise($image,$width,$height)
+{
+ for($x=0;$x<$width;++$x)
+ {
+ for($y=0;$y<$height;++$y)
+ {
+ if(rand(0,100)<25)
+ {
+ $color=imagecolorallocate($image,rand(150,220),rand(150,220),rand(150,220));
+ imagesetpixel($image,$x,$y,$color);
+ imagecolordeallocate($image,$color);
+ }
+ }
+ }
+}
+
+function addGrid($image,$width,$height)
+{
+ for($i=0;$i<$width;$i+=rand(15,25))
+ {
+ imagesetthickness($image,rand(2,6));
+ $color=imagecolorallocate($image,rand(100,180),rand(100,180),rand(100,180));
+ imageline($image,$i+rand(-10,20),0,$i+rand(-10,20),$height,$color);
+ imagecolordeallocate($image,$color);
+ }
+ for($i=0;$i<$height;$i+=rand(15,25))
+ {
+ imagesetthickness($image,rand(2,6));
+ $color=imagecolorallocate($image,rand(100,180),rand(100,180),rand(100,180));
+ imageline($image,0,$i+rand(-10,20),$width,$i+rand(-10,20),$color);
+ imagecolordeallocate($image,$color);
+ }
+}
+
+function addScribble($image,$width,$height)
+{
+ for($i=0;$i<8;$i++)
+ {
+ $color=imagecolorallocate($image,rand(100,180),rand(100,180),rand(100,180));
+ $points=array();
+ for($j=1;$j<rand(5,10);$j++)
+ {
+ $points[]=rand(2*(20*($i+1)),2*(50*($i+1)));
+ $points[]=rand(30,$height+30);
+ }
+ imagesetthickness($image,rand(2,6));
+ imagepolygon($image,$points,intval(sizeof($points)/2),$color);
+ imagecolordeallocate($image,$color);
+ }
+}
+
+function morphImage($image,$width,$height)
+{
+ $tempImage=imagecreatetruecolor($width,$height);
+ $chunk=rand(1,5);
+ for($x=$y=0;$x<$width;$x+=$chunk)
+ {
+ $chunk=rand(1,5);
+ $y+=rand(-1,1);
+ if($y>=$height) $y=$height-5;
+ if($y<0) $y=5;
+ imagecopy($tempImage,$image,$x,0,$x,$y,$chunk,$height);
+ }
+ for($x=$y=0;$y<$height;$y+=$chunk)
+ {
+ $chunk=rand(1,5);
+ $x+=rand(-1,1);
+ if($x>=$width) $x=$width-5;
+ if($x<0) $x=5;
+ imagecopy($image,$tempImage,$x,$y,0,$y,$width,$chunk);
+ }
+}
+
diff --git a/framework/interfaces.php b/framework/interfaces.php
index 2f0b4f27..52bf3d72 100644
--- a/framework/interfaces.php
+++ b/framework/interfaces.php
@@ -1,381 +1,381 @@
-<?php
-/**
- * Core interfaces essential for TApplication class.
- *
- * @author Qiang Xue <qiang.xue@gmail.com>
- * @link http://www.pradosoft.com/
+<?php
+/**
+ * Core interfaces essential for TApplication class.
+ *
+ * @author Qiang Xue <qiang.xue@gmail.com>
+ * @link http://www.pradosoft.com/
* @copyright Copyright &copy; 2005-2012 PradoSoft
- * @license http://www.pradosoft.com/license/
- * @version $Id$
- * @package System
- */
-
-/**
- * IModule interface.
- *
- * This interface must be implemented by application modules.
- *
- * @author Qiang Xue <qiang.xue@gmail.com>
- * @version $Id$
- * @package System
- * @since 3.0
- */
-interface IModule
-{
- /**
- * Initializes the module.
- * @param TXmlElement the configuration for the module
- */
- public function init($config);
- /**
- * @return string ID of the module
- */
- public function getID();
- /**
- * @param string ID of the module
- */
- public function setID($id);
-}
-
-/**
- * IService interface.
- *
- * This interface must be implemented by services.
- *
- * @author Qiang Xue <qiang.xue@gmail.com>
- * @version $Id$
- * @package System
- * @since 3.0
- */
-interface IService
-{
- /**
- * Initializes the service.
- * @param TXmlElement the configuration for the service
- */
- public function init($config);
- /**
- * @return string ID of the service
- */
- public function getID();
- /**
- * @param string ID of the service
- */
- public function setID($id);
- /**
- * @return boolean whether the service is enabled
- */
- public function getEnabled();
- /**
- * @param boolean whether the service is enabled
- */
- public function setEnabled($value);
- /**
- * Runs the service.
- */
- public function run();
-}
-
-/**
- * ITextWriter interface.
- *
- * This interface must be implemented by writers.
- *
- * @author Qiang Xue <qiang.xue@gmail.com>
- * @version $Id$
- * @package System
- * @since 3.0
- */
-interface ITextWriter
-{
- /**
- * Writes a string.
- * @param string string to be written
- */
- public function write($str);
- /**
- * Flushes the content that has been written.
- */
- public function flush();
-}
-
-
-/**
- * IUser interface.
- *
- * This interface must be implemented by user objects.
- *
- * @author Qiang Xue <qiang.xue@gmail.com>
- * @version $Id$
- * @package System
- * @since 3.0
- */
-interface IUser
-{
- /**
- * @return string username
- */
- public function getName();
- /**
- * @param string username
- */
- public function setName($value);
- /**
- * @return boolean if the user is a guest
- */
- public function getIsGuest();
- /**
- * @param boolean if the user is a guest
- */
- public function setIsGuest($value);
- /**
- * @return array list of roles that the user is of
- */
- public function getRoles();
- /**
- * @return array|string list of roles that the user is of. If it is a string, roles are assumed by separated by comma
- */
- public function setRoles($value);
- /**
- * @param string role to be tested
- * @return boolean whether the user is of this role
- */
- public function isInRole($role);
- /**
- * @return string user data that is serialized and will be stored in session
- */
- public function saveToString();
- /**
- * @param string user data that is serialized and restored from session
- * @return IUser the user object
- */
- public function loadFromString($string);
-}
-
-/**
- * IStatePersister class.
- *
- * This interface must be implemented by all state persister classes (such as
- * {@link TPageStatePersister}, {@link TApplicationStatePersister}.
- *
- * @author Qiang Xue <qiang.xue@gmail.com>
- * @version $Id$
- * @package System
- * @since 3.0
- */
-interface IStatePersister
-{
- /**
- * Loads state from a persistent storage.
- * @return mixed the state
- */
- public function load();
- /**
- * Saves state into a persistent storage.
- * @param mixed the state to be saved
- */
- public function save($state);
-}
-
-
-/**
- * ICache interface.
- *
- * This interface must be implemented by cache managers.
- *
- * @author Qiang Xue <qiang.xue@gmail.com>
- * @version $Id$
- * @package System
- * @since 3.0
- */
-interface ICache
-{
- /**
- * Retrieves a value from cache with a specified key.
- * @param string a key identifying the cached value
- * @return mixed the value stored in cache, false if the value is not in the cache or expired.
- */
- public function get($id);
- /**
- * Stores a value identified by a key into cache.
- * If the cache already contains such a key, the existing value and
- * expiration time will be replaced with the new ones.
- *
- * @param string the key identifying the value to be cached
- * @param mixed the value to be cached
- * @param integer the number of seconds in which the cached value will expire. 0 means never expire.
- * @param ICacheDependency dependency of the cached item. If the dependency changes, the item is labelled invalid.
- * @return boolean true if the value is successfully stored into cache, false otherwise
- */
- public function set($id,$value,$expire=0,$dependency=null);
- /**
- * Stores a value identified by a key into cache if the cache does not contain this key.
- * Nothing will be done if the cache already contains the key.
- * @param string the key identifying the value to be cached
- * @param mixed the value to be cached
- * @param integer the number of seconds in which the cached value will expire. 0 means never expire.
- * @param ICacheDependency dependency of the cached item. If the dependency changes, the item is labelled invalid.
- * @return boolean true if the value is successfully stored into cache, false otherwise
- */
- public function add($id,$value,$expire=0,$dependency=null);
- /**
- * Deletes a value with the specified key from cache
- * @param string the key of the value to be deleted
- * @return boolean if no error happens during deletion
- */
- public function delete($id);
- /**
- * Deletes all values from cache.
- * Be careful of performing this operation if the cache is shared by multiple applications.
- */
- public function flush();
-}
-
-/**
- * ICacheDependency interface.
- *
- * This interface must be implemented by classes meant to be used as
- * cache dependencies.
- *
- * Classes implementing this interface must support serialization and unserialization.
- *
- * @author Qiang Xue <qiang.xue@gmail.com>
- * @version $Id$
- * @package System
- * @since 3.0
- */
-interface ICacheDependency
-{
- /**
- * @return boolean whether the dependency has changed. Defaults to false.
- */
- public function getHasChanged();
-}
-
-/**
- * IRenderable interface.
- *
- * This interface must be implemented by classes that can be rendered
- * to end-users.
- *
- * @author Qiang Xue <qiang.xue@gmail.com>
- * @version $Id$
- * @package System
- * @since 3.0
- */
-interface IRenderable
-{
- /**
- * Renders the component to end-users.
- * @param ITextWriter writer for the rendering purpose
- */
- public function render($writer);
-}
-
-/**
- * IBindable interface.
- *
- * This interface must be implemented by classes that are capable of performing databinding.
- *
- * @author Qiang Xue <qiang.xue@gmail.com>
- * @version $Id$
- * @package System
- * @since 3.0
- */
-interface IBindable
-{
- /**
- * Performs databinding.
- */
- public function dataBind();
-}
-
-/**
- * IStyleable interface.
- *
- * This interface should be implemented by classes that support CSS styles.
- *
- * @author Qiang Xue <qiang.xue@gmail.com>
- * @version $Id$
- * @package System
- * @since 3.1.0
- */
-interface IStyleable
-{
- /**
- * @return boolean whether the object has defined any style information
- */
- public function getHasStyle();
- /**
- * @return TStyle the object representing the css style of the object
- */
- public function getStyle();
- /**
- * Removes all styles associated with the object
- */
- public function clearStyle();
-}
-
-/**
- * IActiveControl interface.
- *
- * Active controls must implement IActiveControl interface.
- *
- * @author Wei Zhuo <weizhuo[at]gamil[dot]com>
- * @version $Id$
- * @package System
- * @since 3.1
- */
-interface IActiveControl
-{
- /**
- * @return TBaseActiveControl Active control properties.
- */
- public function getActiveControl();
-}
-
-/**
- * ICallbackEventHandler interface.
- *
- * If a control wants to respond to callback event, it must implement this
- * interface.
- *
- * @author Wei Zhuo <weizhuo[at]gamil[dot]com>
- * @version $Id$
- * @package System
- * @since 3.1
- */
-interface ICallbackEventHandler
-{
- /**
- * Raises callback event. The implementation of this function should raise
- * appropriate event(s) (e.g. OnClick, OnCommand) indicating the component
- * is responsible for the callback event.
- * @param TCallbackEventParameter the parameter associated with the callback event
- */
- public function raiseCallbackEvent($eventArgument);
-}
-
-/**
- * IDataRenderer interface.
- *
- * If a control wants to be used a renderer for another data-bound control,
- * this interface must be implemented.
- *
- * @author Qiang Xue <qiang.xue@gmail.com>
- * @version $Id$
- * @package System
- * @since 3.1
- */
-interface IDataRenderer
-{
- /**
- * @return mixed the data bound to this object
- */
- public function getData();
-
- /**
- * @param mixed the data to be bound to this object
- */
- public function setData($value);
-}
+ * @license http://www.pradosoft.com/license/
+ * @version $Id$
+ * @package System
+ */
+
+/**
+ * IModule interface.
+ *
+ * This interface must be implemented by application modules.
+ *
+ * @author Qiang Xue <qiang.xue@gmail.com>
+ * @version $Id$
+ * @package System
+ * @since 3.0
+ */
+interface IModule
+{
+ /**
+ * Initializes the module.
+ * @param TXmlElement the configuration for the module
+ */
+ public function init($config);
+ /**
+ * @return string ID of the module
+ */
+ public function getID();
+ /**
+ * @param string ID of the module
+ */
+ public function setID($id);
+}
+
+/**
+ * IService interface.
+ *
+ * This interface must be implemented by services.
+ *
+ * @author Qiang Xue <qiang.xue@gmail.com>
+ * @version $Id$
+ * @package System
+ * @since 3.0
+ */
+interface IService
+{
+ /**
+ * Initializes the service.
+ * @param TXmlElement the configuration for the service
+ */
+ public function init($config);
+ /**
+ * @return string ID of the service
+ */
+ public function getID();
+ /**
+ * @param string ID of the service
+ */
+ public function setID($id);
+ /**
+ * @return boolean whether the service is enabled
+ */
+ public function getEnabled();
+ /**
+ * @param boolean whether the service is enabled
+ */
+ public function setEnabled($value);
+ /**
+ * Runs the service.
+ */
+ public function run();
+}
+
+/**
+ * ITextWriter interface.
+ *
+ * This interface must be implemented by writers.
+ *
+ * @author Qiang Xue <qiang.xue@gmail.com>
+ * @version $Id$
+ * @package System
+ * @since 3.0
+ */
+interface ITextWriter
+{
+ /**
+ * Writes a string.
+ * @param string string to be written
+ */
+ public function write($str);
+ /**
+ * Flushes the content that has been written.
+ */
+ public function flush();
+}
+
+
+/**
+ * IUser interface.
+ *
+ * This interface must be implemented by user objects.
+ *
+ * @author Qiang Xue <qiang.xue@gmail.com>
+ * @version $Id$
+ * @package System
+ * @since 3.0
+ */
+interface IUser
+{
+ /**
+ * @return string username
+ */
+ public function getName();
+ /**
+ * @param string username
+ */
+ public function setName($value);
+ /**
+ * @return boolean if the user is a guest
+ */
+ public function getIsGuest();
+ /**
+ * @param boolean if the user is a guest
+ */
+ public function setIsGuest($value);
+ /**
+ * @return array list of roles that the user is of
+ */
+ public function getRoles();
+ /**
+ * @return array|string list of roles that the user is of. If it is a string, roles are assumed by separated by comma
+ */
+ public function setRoles($value);
+ /**
+ * @param string role to be tested
+ * @return boolean whether the user is of this role
+ */
+ public function isInRole($role);
+ /**
+ * @return string user data that is serialized and will be stored in session
+ */
+ public function saveToString();
+ /**
+ * @param string user data that is serialized and restored from session
+ * @return IUser the user object
+ */
+ public function loadFromString($string);
+}
+
+/**
+ * IStatePersister class.
+ *
+ * This interface must be implemented by all state persister classes (such as
+ * {@link TPageStatePersister}, {@link TApplicationStatePersister}.
+ *
+ * @author Qiang Xue <qiang.xue@gmail.com>
+ * @version $Id$
+ * @package System
+ * @since 3.0
+ */
+interface IStatePersister
+{
+ /**
+ * Loads state from a persistent storage.
+ * @return mixed the state
+ */
+ public function load();
+ /**
+ * Saves state into a persistent storage.
+ * @param mixed the state to be saved
+ */
+ public function save($state);
+}
+
+
+/**
+ * ICache interface.
+ *
+ * This interface must be implemented by cache managers.
+ *
+ * @author Qiang Xue <qiang.xue@gmail.com>
+ * @version $Id$
+ * @package System
+ * @since 3.0
+ */
+interface ICache
+{
+ /**
+ * Retrieves a value from cache with a specified key.
+ * @param string a key identifying the cached value
+ * @return mixed the value stored in cache, false if the value is not in the cache or expired.
+ */
+ public function get($id);
+ /**
+ * Stores a value identified by a key into cache.
+ * If the cache already contains such a key, the existing value and
+ * expiration time will be replaced with the new ones.
+ *
+ * @param string the key identifying the value to be cached
+ * @param mixed the value to be cached
+ * @param integer the number of seconds in which the cached value will expire. 0 means never expire.
+ * @param ICacheDependency dependency of the cached item. If the dependency changes, the item is labelled invalid.
+ * @return boolean true if the value is successfully stored into cache, false otherwise
+ */
+ public function set($id,$value,$expire=0,$dependency=null);
+ /**
+ * Stores a value identified by a key into cache if the cache does not contain this key.
+ * Nothing will be done if the cache already contains the key.
+ * @param string the key identifying the value to be cached
+ * @param mixed the value to be cached
+ * @param integer the number of seconds in which the cached value will expire. 0 means never expire.
+ * @param ICacheDependency dependency of the cached item. If the dependency changes, the item is labelled invalid.
+ * @return boolean true if the value is successfully stored into cache, false otherwise
+ */
+ public function add($id,$value,$expire=0,$dependency=null);
+ /**
+ * Deletes a value with the specified key from cache
+ * @param string the key of the value to be deleted
+ * @return boolean if no error happens during deletion
+ */
+ public function delete($id);
+ /**
+ * Deletes all values from cache.
+ * Be careful of performing this operation if the cache is shared by multiple applications.
+ */
+ public function flush();
+}
+
+/**
+ * ICacheDependency interface.
+ *
+ * This interface must be implemented by classes meant to be used as
+ * cache dependencies.
+ *
+ * Classes implementing this interface must support serialization and unserialization.
+ *
+ * @author Qiang Xue <qiang.xue@gmail.com>
+ * @version $Id$
+ * @package System
+ * @since 3.0
+ */
+interface ICacheDependency
+{
+ /**
+ * @return boolean whether the dependency has changed. Defaults to false.
+ */
+ public function getHasChanged();
+}
+
+/**
+ * IRenderable interface.
+ *
+ * This interface must be implemented by classes that can be rendered
+ * to end-users.
+ *
+ * @author Qiang Xue <qiang.xue@gmail.com>
+ * @version $Id$
+ * @package System
+ * @since 3.0
+ */
+interface IRenderable
+{
+ /**
+ * Renders the component to end-users.
+ * @param ITextWriter writer for the rendering purpose
+ */
+ public function render($writer);
+}
+
+/**
+ * IBindable interface.
+ *
+ * This interface must be implemented by classes that are capable of performing databinding.
+ *
+ * @author Qiang Xue <qiang.xue@gmail.com>
+ * @version $Id$
+ * @package System
+ * @since 3.0
+ */
+interface IBindable
+{
+ /**
+ * Performs databinding.
+ */
+ public function dataBind();
+}
+
+/**
+ * IStyleable interface.
+ *
+ * This interface should be implemented by classes that support CSS styles.
+ *
+ * @author Qiang Xue <qiang.xue@gmail.com>
+ * @version $Id$
+ * @package System
+ * @since 3.1.0
+ */
+interface IStyleable
+{
+ /**
+ * @return boolean whether the object has defined any style information
+ */
+ public function getHasStyle();
+ /**
+ * @return TStyle the object representing the css style of the object
+ */
+ public function getStyle();
+ /**
+ * Removes all styles associated with the object
+ */
+ public function clearStyle();
+}
+
+/**
+ * IActiveControl interface.
+ *
+ * Active controls must implement IActiveControl interface.
+ *
+ * @author Wei Zhuo <weizhuo[at]gamil[dot]com>
+ * @version $Id$
+ * @package System
+ * @since 3.1
+ */
+interface IActiveControl
+{
+ /**
+ * @return TBaseActiveControl Active control properties.
+ */
+ public function getActiveControl();
+}
+
+/**
+ * ICallbackEventHandler interface.
+ *
+ * If a control wants to respond to callback event, it must implement this
+ * interface.
+ *
+ * @author Wei Zhuo <weizhuo[at]gamil[dot]com>
+ * @version $Id$
+ * @package System
+ * @since 3.1
+ */
+interface ICallbackEventHandler
+{
+ /**
+ * Raises callback event. The implementation of this function should raise
+ * appropriate event(s) (e.g. OnClick, OnCommand) indicating the component
+ * is responsible for the callback event.
+ * @param TCallbackEventParameter the parameter associated with the callback event
+ */
+ public function raiseCallbackEvent($eventArgument);
+}
+
+/**
+ * IDataRenderer interface.
+ *
+ * If a control wants to be used a renderer for another data-bound control,
+ * this interface must be implemented.
+ *
+ * @author Qiang Xue <qiang.xue@gmail.com>
+ * @version $Id$
+ * @package System
+ * @since 3.1
+ */
+interface IDataRenderer
+{
+ /**
+ * @return mixed the data bound to this object
+ */
+ public function getData();
+
+ /**
+ * @param mixed the data to be bound to this object
+ */
+ public function setData($value);
+}
diff --git a/framework/prado.php b/framework/prado.php
index 3655782c..f9cd20ad 100644
--- a/framework/prado.php
+++ b/framework/prado.php
@@ -1,66 +1,66 @@
-<?php
-/**
- * Prado bootstrap file.
- *
- * This file is intended to be included in the entry script of Prado applications.
- * It defines Prado class by extending PradoBase, a static class providing globally
- * available functionalities that enable PRADO component model and error handling mechanism.
- *
- * By including this file, the PHP error and exception handlers are set as
- * PRADO handlers, and an __autoload function is provided that automatically
- * loads a class file if the class is not defined.
- *
- * @author Qiang Xue <qiang.xue@gmail.com>
- * @link http://www.pradosoft.com/
- * @copyright Copyright &copy; 2005-2012 PradoSoft
- * @license http://www.pradosoft.com/license/
- * @version $Id$
- * @package System
- */
-
-/**
- * Includes the PradoBase class file
- */
-require_once(dirname(__FILE__).'/PradoBase.php');
-
-/**
- * Defines Prado class if not defined.
- */
-if(!class_exists('Prado',false))
-{
- /**
- * Prado class.
- *
- * @author Qiang Xue <qiang.xue@gmail.com>
- * @version $Id$
- * @package System
- * @since 3.0
- */
- class Prado extends PradoBase
- {
- }
-}
-
-/**
- * Registers the autoload function.
- * Since Prado::autoload will report a fatal error if the class file
- * cannot be found, if you have multiple autoloaders, Prado::autoload
- * should be registered in the last.
- */
-spl_autoload_register(array('Prado','autoload'));
-
-/**
- * Initializes error and exception handlers
- */
-Prado::initErrorHandlers();
-
-/**
- * Includes TApplication class file
- */
-require_once(dirname(__FILE__).'/TApplication.php');
-
-/**
- * Includes TShellApplication class file
- */
-require_once(dirname(__FILE__).'/TShellApplication.php');
-
+<?php
+/**
+ * Prado bootstrap file.
+ *
+ * This file is intended to be included in the entry script of Prado applications.
+ * It defines Prado class by extending PradoBase, a static class providing globally
+ * available functionalities that enable PRADO component model and error handling mechanism.
+ *
+ * By including this file, the PHP error and exception handlers are set as
+ * PRADO handlers, and an __autoload function is provided that automatically
+ * loads a class file if the class is not defined.
+ *
+ * @author Qiang Xue <qiang.xue@gmail.com>
+ * @link http://www.pradosoft.com/
+ * @copyright Copyright &copy; 2005-2012 PradoSoft
+ * @license http://www.pradosoft.com/license/
+ * @version $Id$
+ * @package System
+ */
+
+/**
+ * Includes the PradoBase class file
+ */
+require_once(dirname(__FILE__).'/PradoBase.php');
+
+/**
+ * Defines Prado class if not defined.
+ */
+if(!class_exists('Prado',false))
+{
+ /**
+ * Prado class.
+ *
+ * @author Qiang Xue <qiang.xue@gmail.com>
+ * @version $Id$
+ * @package System
+ * @since 3.0
+ */
+ class Prado extends PradoBase
+ {
+ }
+}
+
+/**
+ * Registers the autoload function.
+ * Since Prado::autoload will report a fatal error if the class file
+ * cannot be found, if you have multiple autoloaders, Prado::autoload
+ * should be registered in the last.
+ */
+spl_autoload_register(array('Prado','autoload'));
+
+/**
+ * Initializes error and exception handlers
+ */
+Prado::initErrorHandlers();
+
+/**
+ * Includes TApplication class file
+ */
+require_once(dirname(__FILE__).'/TApplication.php');
+
+/**
+ * Includes TShellApplication class file
+ */
+require_once(dirname(__FILE__).'/TShellApplication.php');
+